diff --git a/src/doc.c b/src/doc.c index 51c9d9c0912c..efa0d7272e9b 100644 --- a/src/doc.c +++ b/src/doc.c @@ -38,8 +38,6 @@ struct Escape { const char *strings[256]; - - static const char *escapeChar(unsigned c); }; struct Section @@ -185,7 +183,7 @@ DDOC_PARAM_ID = $(TD $0)\n\ DDOC_PARAM_DESC = $(TD $0)\n\ DDOC_BLANKLINE = $(BR)$(BR)\n\ \n\ -DDOC_PSYMBOL = $(U $0)\n\ +DDOC_PSYMBOL = $(U $1)\n\ DDOC_KEYWORD = $(B $0)\n\ DDOC_PARAM = $(I $0)\n\ \n\ @@ -288,12 +286,36 @@ void Module::gendocfile() emitMemberComments(sc); } - //printf("BODY= '%.*s'\n", buf.offset, buf.data); - Macro::define(¯otable, (unsigned char *)"BODY", 4, buf.data, buf.offset); + // if I did the character encoding right here, I think we'd be in business + OutBuffer bufEncoded; + if(escapetable != NULL) + { + bufEncoded.reserve(buf.offset); + for(unsigned where = 0; where < buf.offset; where++) + { + unsigned char c = buf.data[where]; + const char* replacement = escapetable->strings[c]; + if (replacement == NULL) + bufEncoded.writeByte(c); + else + bufEncoded.writestring(replacement); + } + } + else + { + bufEncoded.reserve(buf.offset); + for(unsigned where = 0; where < buf.offset; where++) + bufEncoded.writeByte(buf.data[where]); + } + + // printf("BODY= '%.*s'\n", bufEncoded.offset, bufEncoded.data); + // printf("BODY= '%.*s'\n", buf.offset, buf.data); + Macro::define(¯otable, (unsigned char *)"BODY", 4, bufEncoded.data, bufEncoded.offset); OutBuffer buf2; buf2.writestring("$(DDOC)\n"); unsigned end = buf2.offset; + macrotable->expand(&buf2, 0, &end, NULL, 0); #if 1 @@ -907,7 +929,7 @@ void AggregateDeclaration::toDocBuffer(OutBuffer *buf) #if 0 emitProtection(buf, protection); #endif - buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars()); + buf->printf("%s $(DDOC_PSYMBOL %s, %s)", kind(), toChars(), toPrettyChars() + strlen(this->getModule()->toChars()) + 1); buf->writestring(";\n"); } } @@ -931,7 +953,7 @@ void StructDeclaration::toDocBuffer(OutBuffer *buf) } else { - buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars()); + buf->printf("%s $(DDOC_PSYMBOL %s, %s)", kind(), toChars(), toPrettyChars() + strlen(this->getModule()->toChars()) + 1); } buf->writestring(";\n"); } @@ -958,7 +980,7 @@ void ClassDeclaration::toDocBuffer(OutBuffer *buf) { if (isAbstract()) buf->writestring("abstract "); - buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars()); + buf->printf("%s $(DDOC_PSYMBOL %s, %s)", kind(), toChars(), toPrettyChars() + strlen(this->getModule()->toChars()) + 1); } int any = 0; for (size_t i = 0; i < baseclasses->dim; i++) @@ -995,7 +1017,7 @@ void EnumDeclaration::toDocBuffer(OutBuffer *buf) { if (ident) { - buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars()); + buf->printf("%s $(DDOC_PSYMBOL %s, %s)", kind(), toChars(), toPrettyChars() + strlen(this->getModule()->toChars()) + 1 ); buf->writestring(";\n"); } } @@ -1515,6 +1537,9 @@ void DocComment::parseEscapes(Escape **pescapetable, unsigned char *textstart, u unsigned char *p = textstart; unsigned char *pend = p + textlen; + // By default, set null everywhere so no character is escaped. + memset(escapetable, 0, sizeof(*escapetable)); + while (1) { while (1) @@ -1803,73 +1828,7 @@ void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset) iLineStart = i + 1; break; - case '<': - leadingBlank = 0; - if (inCode) - break; - p = &buf->data[i]; - - // Skip over comments - if (p[1] == '!' && p[2] == '-' && p[3] == '-') - { unsigned j = i + 4; - p += 4; - while (1) - { - if (j == buf->offset) - goto L1; - if (p[0] == '-' && p[1] == '-' && p[2] == '>') - { - i = j + 2; // place on closing '>' - break; - } - j++; - p++; - } - break; - } - - // Skip over HTML tag - if (isalpha(p[1]) || (p[1] == '/' && isalpha(p[2]))) - { unsigned j = i + 2; - p += 2; - while (1) - { - if (j == buf->offset) - goto L1; - if (p[0] == '>') - { - i = j; // place on closing '>' - break; - } - j++; - p++; - } - break; - } - L1: - // Replace '<' with '<' character entity - se = Escape::escapeChar('<'); - if (se) - { size_t len = strlen(se); - buf->remove(i, 1); - i = buf->insert(i, se, len); - i--; // point to ';' - } - break; - - case '>': - leadingBlank = 0; - if (inCode) - break; - // Replace '>' with '>' character entity - se = Escape::escapeChar('>'); - if (se) - { size_t len = strlen(se); - buf->remove(i, 1); - i = buf->insert(i, se, len); - i--; // point to ';' - } break; case '&': @@ -1879,14 +1838,6 @@ void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset) p = &buf->data[i]; if (p[1] == '#' || isalpha(p[1])) break; // already a character entity - // Replace '&' with '&' character entity - se = Escape::escapeChar('&'); - if (se) - { size_t len = strlen(se); - buf->remove(i, 1); - i = buf->insert(i, se, len); - i--; // point to ';' - } break; case '-': @@ -2024,20 +1975,21 @@ void highlightCode(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset) char *sid = s->ident->toChars(); FuncDeclaration *f = s->isFuncDeclaration(); + const char *fullyQualifiedName = s->toPrettyChars() + strlen(s->getModule()->toChars()) + 1; + int total = strlen(fullyQualifiedName); + char *terminator = (char*) malloc(total + 3); + terminator[0] = ','; // end the first argument + strncpy(terminator + 1, fullyQualifiedName, total); + ++total; // because of the comma + terminator[total] = ')'; // to close the DDOC_PSYMBOL macro + terminator[total + 1] = 0; // terminate the string + //printf("highlightCode(s = '%s', kind = %s)\n", sid, s->kind()); for (unsigned i = offset; i < buf->offset; i++) { unsigned char c = buf->data[i]; const char *se; - se = Escape::escapeChar(c); - if (se) - { - size_t len = strlen(se); - buf->remove(i, 1); - i = buf->insert(i, se, len); - i--; // point to ';' - } - else if (isIdStart(&buf->data[i])) + if (isIdStart(&buf->data[i])) { unsigned j; j = skippastident(buf, i); @@ -2045,7 +1997,7 @@ void highlightCode(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset) { if (cmp(sid, buf->data + i, j - i) == 0) { - i = buf->bracket(i, "$(DDOC_PSYMBOL ", j, ")") - 1; + i = buf->bracket(i, "$(DDOC_PSYMBOL ", j, terminator) - 1; continue; } else if (f) @@ -2061,6 +2013,8 @@ void highlightCode(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset) } } } + + free(terminator); } /**************************************** @@ -2069,10 +2023,7 @@ void highlightCode(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset) void highlightCode3(OutBuffer *buf, unsigned char *p, unsigned char *pend) { for (; p < pend; p++) - { const char *s = Escape::escapeChar(*p); - if (s) - buf->writestring(s); - else + { buf->writeByte(*p); } } @@ -2148,31 +2099,6 @@ void highlightCode2(Scope *sc, Dsymbol *s, OutBuffer *buf, unsigned offset) global.errors = errorsave; } -/*************************************** - * Find character string to replace c with. - */ - -const char *Escape::escapeChar(unsigned c) -{ const char *s; - - switch (c) - { - case '<': - s = "<"; - break; - case '>': - s = ">"; - break; - case '&': - s = "&"; - break; - default: - s = NULL; - break; - } - return s; -} - /**************************************** * Determine if p points to the start of an identifier. */