diff -uNr dmd-0.133/dmd/src/dmd/doc.c dmd-0.134/dmd/src/dmd/doc.c --- dmd-0.133/dmd/src/dmd/doc.c 2005-09-24 15:28:12.000000000 +0200 +++ dmd-0.134/dmd/src/dmd/doc.c 2005-09-28 16:38:04.000000000 +0200 @@ -38,12 +38,17 @@ int nooutput; - virtual void write(Scope *sc, Dsymbol *s, OutBuffer *buf); + virtual void write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf); }; struct ParamSection : Section { - void write(Scope *sc, Dsymbol *s, OutBuffer *buf); + void write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf); +}; + +struct MacroSection : Section +{ + void write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf); }; struct DocComment @@ -52,7 +57,7 @@ Section *summary; Section *copyright; - Section *macros; + Macro **pmacrotable; DocComment(); @@ -98,6 +103,7 @@ \n\

$(TITLE)

\n\ $(BODY)\n\ +
$(SMALL Page generated by $(LINK2 http://www.digitalmars.com/d/ddoc.html, Ddoc).)\n\ \n\ \n\ B = $0\n\ @@ -117,6 +123,8 @@ BIG = $0\n\ SMALL = $0\n\ BR =
\n\ +LINK = $0\n\ +LINK2 = $+\n\ \n\ RED = $0\n\ BLUE = $0\n\ @@ -130,12 +138,25 @@ DDOC_DECL = $(DT $(BIG $0))\n\ DDOC_DECL_DD = $(DD $0)\n\ DDOC_SECTIONS = $0\n\ -DDOC_SUMMARY = $0\n\ -DDOC_DESCRIPTION = $0\n\ -DDOC_SECTION_H = $(P $(B $0))\n\ -DDOC_SECTION = $0\n\ +DDOC_SUMMARY = $0$(BR)$(BR)\n\ +DDOC_DESCRIPTION = $0$(BR)$(BR)\n\ +DDOC_AUTHORS = $(B Authors:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_BUGS = $(RED BUGS:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_COPYRIGHT = $(B Copyright:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_DATE = $(B Date:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_DEPRECATED = $(RED Deprecated:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_EXAMPLES = $(B Examples:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_HISTORY = $(B History:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_LICENSE = $(B License:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_RETURNS = $(B Returns:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_SEE_ALSO = $(B See Also:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_STANDARDS = $(B Standards:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_THROWS = $(B Throws:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_VERSION = $(B Version:)$(BR)\n$0$(BR)$(BR)\n\ +DDOC_SECTION_H = $(B $0)$(BR)$(BR)\n\ +DDOC_SECTION = $0$(BR)$(BR)\n\ DDOC_MEMBERS = $(DL $0)\n\ -DDOC_PARAMS = $(P $(TABLE $0))\n\ +DDOC_PARAMS = $(TABLE $0)$(BR)$(BR)\n\ DDOC_PARAM_ROW = $(TR $0)\n\ DDOC_PARAM_ID = $(TD $0)\n\ DDOC_PARAM_DESC = $(TD $0)\n\ @@ -193,20 +214,7 @@ sc->docbuf = &buf; DocComment *dc = DocComment::parse(sc, this, comment); - - if (dc->copyright) - { - dc->copyright->nooutput = 1; - Macro::define(¯otable, (unsigned char *)"COPYRIGHT", 9, dc->copyright->body, dc->copyright->bodylen); - } - - if (dc->macros) - DocComment::parseMacros(¯otable, dc->macros->body, dc->macros->bodylen); - - buf.printf("\n", srcfile->toChars()); - - dc->writeSections(sc, this, sc->docbuf); - emitMemberComments(sc); + dc->pmacrotable = ¯otable; // Generate predefined macros @@ -215,8 +223,6 @@ Macro::define(¯otable, (unsigned char *)"TITLE", 5, (unsigned char *)p, strlen(p)); } - Macro::define(¯otable, (unsigned char *)"BODY", 4, buf.data, buf.offset); - time_t t; time(&t); char *p = ctime(&t); @@ -225,12 +231,60 @@ Macro::define(¯otable, (unsigned char *)"YEAR", 4, (unsigned char *)p + 20, 4); + if (dc->copyright) + { + dc->copyright->nooutput = 1; + Macro::define(¯otable, (unsigned char *)"COPYRIGHT", 9, dc->copyright->body, dc->copyright->bodylen); + } + + buf.printf("\n", srcfile->toChars()); + + dc->writeSections(sc, this, sc->docbuf); + emitMemberComments(sc); + + Macro::define(¯otable, (unsigned char *)"BODY", 4, buf.data, buf.offset); + OutBuffer buf2; buf2.writestring("$(DDOC)\n"); unsigned end = buf2.offset; macrotable->expand(&buf2, 0, &end, NULL, 0); #if 1 + /* Remove all the escape sequences from buf2, + * and make CR-LF the newline. + */ + { + buf.setsize(0); + buf.reserve(buf2.offset); + unsigned char *p = buf2.data; + for (unsigned j = 0; j < buf2.offset; j++) + { + unsigned char c = p[j]; + if (c == 0xFF && j + 1 < buf2.offset) + { + j++; + continue; + } + if (c == '\n') + buf.writeByte('\r'); + else if (c == '\r') + { + buf.writestring("\r\n"); + if (j + 1 < buf2.offset && p[j + 1] == '\n') + { + j++; + } + continue; + } + buf.writeByte(c); + } + } + + // Transfer image to file + docfile->setbuffer(buf.data, buf.offset); + docfile->ref = 1; + docfile->writev(); +#else /* Remove all the escape sequences from buf2 */ { unsigned i = 0; @@ -247,12 +301,12 @@ } buf2.setsize(i); } -#endif // Transfer image to file docfile->setbuffer(buf2.data, buf2.offset); docfile->ref = 1; docfile->writev(); +#endif } /******************************* emitComment **********************************/ @@ -653,12 +707,6 @@ { dc->copyright = s; } - - if (icmp("macros", s->name, s->namelen) == 0) - { - dc->macros = s; - s->nooutput = 1; - } } sc->lastdc = dc; @@ -735,23 +783,28 @@ } L1: - Section *s; - if (icmp("Params", name, namelen) == 0) - s = new ParamSection(); - else - s = new Section(); - s->name = name; - s->namelen = namelen; - s->body = pstart; - s->bodylen = pend - pstart; - s->nooutput = 0; + if (namelen || pstart < pend) + { + Section *s; + if (icmp("Params", name, namelen) == 0) + s = new ParamSection(); + else if (icmp("Macros", name, namelen) == 0) + s = new MacroSection(); + else + s = new Section(); + s->name = name; + s->namelen = namelen; + s->body = pstart; + s->bodylen = pend - pstart; + s->nooutput = 0; - //printf("Section: '%.*s' = '%.*s'\n", s->namelen, s->name, s->bodylen, s->body); + //printf("Section: '%.*s' = '%.*s'\n", s->namelen, s->name, s->bodylen, s->body); - sections.push(s); + sections.push(s); - if (!summary && !namelen) - summary = s; + if (!summary && !namelen) + summary = s; + } if (idlen) { name = idstart; @@ -778,52 +831,71 @@ if (sec->nooutput) continue; //printf("Section: '%.*s' = '%.*s'\n", sec->namelen, sec->name, sec->bodylen, sec->body); - if (sec->namelen) - { - // Replace _ characters with spaces - buf->writestring("$(DDOC_SECTION_H "); - for (unsigned u = 0; u < sec->namelen; u++) - { unsigned char c = sec->name[u]; - buf->writeByte((c == '_') ? ' ' : c); - } - buf->writestring(":)"); - buf->writestring("$(DDOC_SECTION "); - sec->write(sc, s, buf); - buf->writestring(")\n"); - } - else if (i == 0) - { - buf->writestring("$(DDOC_SUMMARY "); - sec->write(sc, s, buf); - buf->writestring(")\n"); - } + if (sec->namelen || i) + sec->write(this, sc, s, buf); else { - buf->writestring("$(DDOC_DESCRIPTION "); - sec->write(sc, s, buf); + buf->writestring("$(DDOC_SUMMARY "); + unsigned o = buf->offset; + buf->write(sec->body, sec->bodylen); + highlightText(sc, s, buf, o); buf->writestring(")\n"); } } buf->writestring(")\n"); } else + { buf->writestring("$(BR)$(BR)\n"); + } } /*************************************************** */ -void Section::write(Scope *sc, Dsymbol *s, OutBuffer *buf) +void Section::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf) { + if (namelen) + { + static char *table[] = + { "AUTHORS", "BUGS", "COPYRIGHT", "DATE", + "DEPRECATED", "EXAMPLES", "HISTORY", "LICENSE", + "RETURNS", "SEE_ALSO", "STANDARDS", "THROWS", + "VERSION" }; + + for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++) + { + if (icmp(table[i], name, namelen) == 0) + { + buf->printf("$(DDOC_%s ", table[i]); + goto L1; + } + } + + buf->writestring("$(DDOC_SECTION "); + // Replace _ characters with spaces + buf->writestring("$(DDOC_SECTION_H "); + for (unsigned u = 0; u < namelen; u++) + { unsigned char c = name[u]; + buf->writeByte((c == '_') ? ' ' : c); + } + buf->writestring(":)\n"); + } + else + { + buf->writestring("$(DDOC_DESCRIPTION "); + } + L1: unsigned o = buf->offset; buf->write(body, bodylen); highlightText(sc, s, buf, o); + buf->writestring(")\n"); } /*************************************************** */ -void ParamSection::write(Scope *sc, Dsymbol *s, OutBuffer *buf) +void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf) { unsigned char *p = body; unsigned len = bodylen; @@ -938,6 +1010,15 @@ buf->writestring(")\n"); } +/*************************************************** + */ + +void MacroSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf) +{ + //printf("MacroSection::write()\n"); + DocComment::parseMacros(dc->pmacrotable, body, bodylen); +} + /************************************************ * Parse macros out of Macros: section. * Macros are of the form: @@ -966,6 +1047,8 @@ // Skip to start of macro for (; 1; p++) { + if (p >= pend) + goto Ldone; switch (*p) { case ' ': @@ -989,12 +1072,24 @@ } tempstart = p; - while (isalnum(*p) || *p == '_') + while (1) + { + if (p >= pend) + goto Ldone; + if (!(isalnum(*p) || *p == '_')) + break; p++; + } templen = p - tempstart; - while (*p == ' ' || *p == '\t') + while (1) + { + if (p >= pend) + goto Ldone; + if (!(*p == ' ' || *p == '\t')) + break; p++; + } if (*p != '=') { if (namelen) @@ -1002,6 +1097,8 @@ goto Lskipline; } p++; + if (p >= pend) + goto Ldone; if (namelen) { // Output existing macro @@ -1016,12 +1113,12 @@ namestart = tempstart; namelen = templen; - while (*p == ' ' || *p == '\t') + while (p < pend && (*p == ' ' || *p == '\t')) p++; textstart = p; Ltext: - while (*p != '\n') + while (p < pend && *p != '\n') p++; textlen = p - textstart; @@ -1033,9 +1130,10 @@ Lskipline: // Ignore this line - while (*p++ != '\n') + while (p < pend && *p++ != '\n') ; } +Ldone: if (namelen) goto L1; // write out last one } @@ -1196,9 +1294,6 @@ int inComment = 0; // in comment unsigned iCodeStart; // start of code section - buf->insert(offset, "$(P ", 4); - offset += 4; - unsigned iLineStart = offset; for (unsigned i = offset; i < buf->offset; i++) @@ -1213,8 +1308,14 @@ case '\n': if (i == iLineStart) // if "\n\n" - { buf->insert(i, ")\n$(P ", 6); + { +#if 1 + buf->insert(i, "$(BR)$(BR)\n", 11); + i += 11; // point at last '>' +#else + buf->insert(i, ")\n$(P ", 6); i += 6; // point at last '>' +#endif } leadingBlank = 1; iLineStart = i + 1; @@ -1303,18 +1404,21 @@ while (1) { ++i; - assert(i < buf->offset); + if (i >= buf->offset) + break; c = buf->data[i]; - if (c != '-') + if (c == '\n') break; + if (c != '-') + goto Lcont; } - if (c != '\n' || i - istart < 3) + if (i - istart < 3) goto Lcont; // We have the start/end of a code section // Remove the entire --- line, including blanks and \n - buf->remove(iLineStart, i - iLineStart + 1); // remove '-----\n' + buf->remove(iLineStart, i - iLineStart + (c == '\n')); i = iLineStart; if (inCode) @@ -1385,7 +1489,6 @@ } Ldone: ; - buf->writestring(")\n"); } /************************************************** diff -uNr dmd-0.133/dmd/src/dmd/macro.c dmd-0.134/dmd/src/dmd/macro.c --- dmd-0.133/dmd/src/dmd/macro.c 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.134/dmd/src/dmd/macro.c 2005-09-27 02:07:16.000000000 +0200 @@ -0,0 +1,451 @@ + +// Copyright (c) 1999-2005 by Digital Mars +// All Rights Reserved +// written by Walter Bright +// www.digitalmars.com +// License for redistribution is by either the Artistic License +// in artistic.txt, or the GNU General Public License in gnu.txt. +// See the included readme.txt for details. + +/* Simple macro text processor. + */ + +#include +#include +#include +#include + +#if _WIN32 +#include "..\root\mem.h" +#elif linux +#include "../root/mem.h" +#else +#error "fix this" +#endif + +#include "root.h" +#include "macro.h" + +#define isidstart(c) (isalpha(c) || (c) == '_') +#define isidchar(c) (isalnum(c) || (c) == '_') + +unsigned char *memdup(unsigned char *p, size_t len) +{ + return (unsigned char *)memcpy(mem.malloc(len), p, len); +} + +Macro::Macro(unsigned char *name, size_t namelen, unsigned char *text, size_t textlen) +{ + next = NULL; + +#if 1 + this->name = name; + this->namelen = namelen; + + this->text = text; + this->textlen = textlen; +#else + this->name = name; + this->namelen = namelen; + + this->text = text; + this->textlen = textlen; +#endif + inuse = 0; +} + + +Macro *Macro::search(unsigned char *name, size_t namelen) +{ Macro *table; + + //printf("Macro::search(%.*s)\n", namelen, name); + for (table = this; table; table = table->next) + { + if (table->namelen == namelen && + memcmp(table->name, name, namelen) == 0) + { + //printf("\tfound %d\n", table->textlen); + break; + } + } + return table; +} + +Macro *Macro::define(Macro **ptable, unsigned char *name, size_t namelen, unsigned char *text, size_t textlen) +{ + //printf("Macro::define('%.*s' = '%.*s')\n", namelen, name, textlen, text); + + Macro *table; + + for (table = *ptable; table; table = table->next) + { + if (table->namelen == namelen && + memcmp(table->name, name, namelen) == 0) + { + table->text = text; + table->textlen = textlen; + return table; + } + } + table = new Macro(name, namelen, text, textlen); + table->next = *ptable; + *ptable = table; + return table; +} + +/********************************************************** + * Given buffer p[0..end], extract argument marg[0..marglen]. + * Params: + * n 0: get entire argument + * 1..9: get nth argument + * -1: get 2nd through end + */ + +unsigned extractArgN(unsigned char *p, unsigned end, unsigned char **pmarg, unsigned *pmarglen, int n) +{ + /* Scan forward for matching right parenthesis. + * Nest parentheses. + * Skip over $( and $) + * Skip over "..." and '...' strings inside HTML tags. + * Skip over comments. + * Skip over previous macro insertions + * Set marglen. + */ + unsigned parens = 1; + unsigned char instring = 0; + unsigned incomment = 0; + unsigned intag = 0; + unsigned inexp = 0; + unsigned argn = 0; + + unsigned v = 0; + + Largstart: +#if 1 + // Skip first space, if any, to find the start of the macro argument + if (v < end && isspace(p[v])) + v++; +#else + // Skip past spaces to find the start of the macro argument + for (; v < end && isspace(p[v]); v++) + ; +#endif + *pmarg = p + v; + + for (; v < end; v++) + { unsigned char c = p[v]; + + switch (c) + { + case ',': + if (!inexp && !instring && !incomment && parens == 1) + { + argn++; + if (argn == 1 && n == -1) + { v++; + goto Largstart; + } + if (argn == n) + break; + if (argn + 1 == n) + { v++; + goto Largstart; + } + } + continue; + + case '(': + if (!inexp && !instring && !incomment) + parens++; + continue; + + case ')': + if (!inexp && !instring && !incomment && --parens == 0) + { + break; + } + continue; + + case '"': + case '\'': + if (!inexp && !incomment && intag) + { + if (c == instring) + instring = 0; + else + instring = c; + } + continue; + + case '<': + if (!inexp && !instring && !incomment) + { + if (v + 6 < end && + p[v + 1] == '!' && + p[v + 2] == '-' && + p[v + 3] == '-') + { + incomment = 1; + v += 3; + } + else if (v + 2 < end && + isalpha(p[v + 1])) + intag = 1; + } + continue; + + case '>': + if (!inexp) + intag = 0; + continue; + + case '-': + if (!inexp && + !instring && + incomment && + v + 2 < end && + p[v + 1] == '-' && + p[v + 2] == '>') + { + incomment = 0; + v += 2; + } + continue; + + case 0xFF: + if (v + 1 < end) + { + if (p[v + 1] == '{') + inexp++; + else if (p[v + 1] == '}') + inexp--; + } + continue; + + default: + continue; + } + break; + } + if (argn == 0 && n == -1) + *pmarg = p + v; + *pmarglen = p + v - *pmarg; + //printf("extractArg%d('%.*s') = '%.*s'\n", n, end, p, *pmarglen, *pmarg); + return v; +} + + +/***************************************************** + * Expand macro in place in buf. + * Only look at the text in buf from start to end. + */ + +void Macro::expand(OutBuffer *buf, unsigned start, unsigned *pend, + unsigned char *arg, unsigned arglen) +{ +#if 0 + printf("Macro::expand(buf[%d..%d], arg = '%.*s')\n", start, *pend, arglen, arg); + printf("Buf is: '%.*s'\n", *pend - start, buf->data + start); +#endif + + static int nest; + if (nest > 100) // limit recursive expansion + return; + nest++; + + unsigned end = *pend; + assert(start <= end); + assert(end <= buf->offset); + + /* First pass - replace $0 + */ + arg = memdup(arg, arglen); + for (unsigned u = start; u + 1 < end; ) + { + unsigned char *p = buf->data; // buf->data is not loop invariant + + /* Look for $0, but not $$0, and replace it with arg. + */ + if (p[u] == '$' && (isdigit(p[u + 1]) || p[u + 1] == '+')) + { + if (u > start && p[u - 1] == '$') + { // Don't expand $$0, but replace it with $0 + buf->remove(u - 1, 1); + end--; + u += 1; // now u is one past the closing '1' + continue; + } + + unsigned char c = p[u + 1]; + int n = (c == '+') ? -1 : c - '0'; + + unsigned char *marg; + unsigned marglen; + extractArgN(arg, arglen, &marg, &marglen, n); + if (marglen == 0) + { // Just remove macro invocation + //printf("Replacing '$%c' with '%.*s'\n", p[u + 1], marglen, marg); + buf->remove(u, 2); + end -= 2; + } + else if (c == '+') + { + // Replace '$+' with 'arg' + //printf("Replacing '$%c' with '%.*s'\n", p[u + 1], marglen, marg); + buf->remove(u, 2); + buf->insert(u, marg, marglen); + end += marglen - 2; + + // Scan replaced text for further expansion + unsigned mend = u + marglen; + expand(buf, u, &mend, NULL, 0); + end += mend - (u + marglen); + u = mend; + } + else + { + // Replace '$1' with '\xFF{arg\xFF}' + //printf("Replacing '$%c' with '\xFF{%.*s\xFF}'\n", p[u + 1], marglen, marg); + buf->data[u] = 0xFF; + buf->data[u + 1] = '{'; + buf->insert(u + 2, marg, marglen); + buf->insert(u + 2 + marglen, "\xFF}", 2); + end += -2 + 2 + marglen + 2; + + // Scan replaced text for further expansion + unsigned mend = u + 2 + marglen; + expand(buf, u + 2, &mend, NULL, 0); + end += mend - (u + 2 + marglen); + u = mend; + } + //printf("u = %d, end = %d\n", u, end); + //printf("#%.*s#\n", end, &buf->data[0]); + continue; + } + + u++; + } + mem.free(arg); + + /* Second pass - replace other macros + */ + for (unsigned u = start; u + 4 < end; ) + { + unsigned char *p = buf->data; // buf->data is not loop invariant + + /* A valid start of macro expansion is $(c, where c is + * an id start character, and not $$(c. + */ + if (p[u] == '$' && p[u + 1] == '(' && isidstart(p[u + 2])) + { + //printf("\tfound macro start '%c'\n", p[u + 2]); + unsigned char *name = p + u + 2; + unsigned namelen = 0; + + unsigned char *marg; + unsigned marglen; + + unsigned v; + /* Scan forward to find end of macro name and + * beginning of macro argument (marg). + */ + for (v = u + 2; v < end; v++) + { unsigned char c = p[v]; + + if (!isidchar(c)) + { // We've gone past the end of the macro name. + namelen = v - (u + 2); + break; + } + } + + v += extractArgN(p + v, end - v, &marg, &marglen, 0); + assert(v <= end); + + if (v < end) + { // v is on the closing ')' + if (u > start && p[u - 1] == '$') + { // Don't expand $$(NAME), but replace it with $(NAME) + buf->remove(u - 1, 1); + end--; + u = v; // now u is one past the closing ')' + continue; + } + + Macro *m = search(name, namelen); + if (m) + { +#if 0 + if (m->textlen && m->text[0] == ' ') + { m->text++; + m->textlen--; + } +#endif + if (m->inuse && marglen == 0) + { // Remove macro invocation + buf->remove(u, v + 1 - u); + end -= v + 1 - u; + } + else if (m->inuse && arglen == marglen && memcmp(arg, marg, arglen) == 0) + { // Recursive expansion; just leave in place + + } + else + { + //printf("\tmacro '%.*s'(%.*s) = '%.*s'\n", m->namelen, m->name, marglen, marg, m->textlen, m->text); +#if 1 + // Insert replacement text + buf->spread(v + 1, 2 + m->textlen + 2); + buf->data[v + 1] = 0xFF; + buf->data[v + 2] = '{'; + memcpy(buf->data + v + 3, m->text, m->textlen); + buf->data[v + 3 + m->textlen] = 0xFF; + buf->data[v + 3 + m->textlen + 1] = '}'; + + end += 2 + m->textlen + 2; + + // Scan replaced text for further expansion + m->inuse++; + unsigned mend = v + 1 + 2+m->textlen+2; + expand(buf, v + 1, &mend, marg, marglen); + end += mend - (v + 1 + 2+m->textlen+2); + m->inuse--; + + buf->remove(u, v + 1 - u); + end -= v + 1 - u; + u += mend - (v + 1); +#else + // Insert replacement text + buf->insert(v + 1, m->text, m->textlen); + end += m->textlen; + + // Scan replaced text for further expansion + m->inuse++; + unsigned mend = v + 1 + m->textlen; + expand(buf, v + 1, &mend, marg, marglen); + end += mend - (v + 1 + m->textlen); + m->inuse--; + + buf->remove(u, v + 1 - u); + end -= v + 1 - u; + u += mend - (v + 1); +#endif + //printf("u = %d, end = %d\n", u, end); + //printf("#%.*s#\n", end - u, &buf->data[u]); + continue; + } + } + else + { + // Replace $(NAME) with nothing + buf->remove(u, v + 1 - u); + end -= (v + 1 - u); + continue; + } + } + } + u++; + } + *pend = end; + nest--; +} diff -uNr dmd-0.133/dmd/src/dmd/macro.h dmd-0.134/dmd/src/dmd/macro.h --- dmd-0.133/dmd/src/dmd/macro.h 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.134/dmd/src/dmd/macro.h 2005-09-21 19:31:14.000000000 +0200 @@ -0,0 +1,42 @@ +// Copyright (c) 1999-2005 by Digital Mars +// All Rights Reserved +// written by Walter Bright +// www.digitalmars.com +// License for redistribution is by either the Artistic License +// in artistic.txt, or the GNU General Public License in gnu.txt. +// See the included readme.txt for details. + +#ifndef DMD_MACRO_H +#define DMD_MACRO_H 1 + +#include +#include +#include +#include + +#include "root.h" + + +class Macro +{ + Macro *next; // next in list + + unsigned char *name; // macro name + size_t namelen; // length of macro name + + unsigned char *text; // macro replacement text + size_t textlen; // length of replacement text + + int inuse; // macro is in use (don't expand) + + Macro(unsigned char *name, size_t namelen, unsigned char *text, size_t textlen); + Macro *Macro::search(unsigned char *name, size_t namelen); + + public: + static Macro *define(Macro **ptable, unsigned char *name, size_t namelen, unsigned char *text, size_t textlen); + + void expand(OutBuffer *buf, unsigned start, unsigned *pend, + unsigned char *arg, unsigned arglen); +}; + +#endif diff -uNr dmd-0.133/dmd/src/dmd/mars.c dmd-0.134/dmd/src/dmd/mars.c --- dmd-0.133/dmd/src/dmd/mars.c 2005-09-21 17:22:58.000000000 +0200 +++ dmd-0.134/dmd/src/dmd/mars.c 2005-09-25 12:47:26.000000000 +0200 @@ -51,7 +51,7 @@ copyright = "Copyright (c) 1999-2005 by Digital Mars"; written = "written by Walter Bright"; - version = "v0.133"; + version = "v0.134"; global.structalign = 8; memset(¶ms, 0, sizeof(Param)); diff -uNr dmd-0.133/dmd/src/dmd/mtype.c dmd-0.134/dmd/src/dmd/mtype.c --- dmd-0.133/dmd/src/dmd/mtype.c 2005-09-13 16:03:12.000000000 +0200 +++ dmd-0.134/dmd/src/dmd/mtype.c 2005-09-27 13:36:36.000000000 +0200 @@ -1391,6 +1391,7 @@ buf->prependstring(buf2.toChars()); if (ident) { + buf->writeByte(' '); buf->writestring(ident->toChars()); } next->toCBuffer2(buf, NULL); @@ -2011,6 +2012,7 @@ buf->prependstring("*"); if (ident) { + buf->writeByte(' '); buf->writestring(ident->toChars()); } next->toCBuffer2(buf, NULL); @@ -2305,7 +2307,7 @@ { Argument *arg; if (i) - buf->writeByte(','); + buf->writestring(", "); arg = (Argument *)arguments->data[i]; if (arg->inout == Out) buf->writestring("out "); @@ -2530,6 +2532,7 @@ buf->prependstring(" delegate"); if (ident) { + buf->writeByte(' '); buf->writestring(ident->toChars()); } next->next->toCBuffer2(buf, NULL); @@ -3205,10 +3208,11 @@ void TypeEnum::toCBuffer2(OutBuffer *buf, Identifier *ident) { - buf->prependbyte(' '); buf->prependstring(sym->toChars()); if (ident) + { buf->writeByte(' '); buf->writestring(ident->toChars()); + } } Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident) @@ -3543,7 +3547,9 @@ buf->prependbyte(' '); buf->prependstring(sym->toChars()); if (ident) + { buf->writeByte(' '); buf->writestring(ident->toChars()); + } } Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident) @@ -3747,10 +3753,11 @@ void TypeClass::toCBuffer2(OutBuffer *buf, Identifier *ident) { - buf->prependbyte(' '); buf->prependstring(sym->toChars()); if (ident) + { buf->writeByte(' '); buf->writestring(ident->toChars()); + } } Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident) diff -uNr dmd-0.133/dmd/src/phobos/internal/object.d dmd-0.134/dmd/src/phobos/internal/object.d --- dmd-0.133/dmd/src/phobos/internal/object.d 2005-09-24 17:25:30.000000000 +0200 +++ dmd-0.134/dmd/src/phobos/internal/object.d 2005-09-28 23:21:34.000000000 +0200 @@ -1,3 +1,13 @@ + +/** + * Forms the symbols available to all D programs. Includes + * Object, which is the root of the class object heirarchy. + * + * This module is implicitly imported. + * Macros: + * WIKI = Object + */ + /* * Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com * Written by Walter Bright @@ -25,16 +35,32 @@ module object; extern (C) -{ int printf(char *, ...); +{ /// C's printf function. + int printf(char *, ...); + int memcmp(void *, void *, size_t); void* memcpy(void *, void *, size_t); } +/// Standard boolean type. Implemented as a $(B bit) type. alias bit bool; version (X86_64) { + /** + * An unsigned integral type large enough to span the memory space. Use for + * array indices and pointer offsets for maximal portability to + * architectures that have different memory address ranges. This is + * analogous to C's size_t. + */ alias ulong size_t; + + /** + * A signed integral type large enough to span the memory space. Use for + * pointer differences and for size_t differences for maximal portability to + * architectures that have different memory address ranges. This is + * analogous to C's ptrdiff_t. + */ alias long ptrdiff_t; } else @@ -43,6 +69,9 @@ alias int ptrdiff_t; } +/****************** + * All D class objects inherit from Object. + */ class Object { void print() @@ -50,43 +79,70 @@ printf("%.*s\n", toString()); } + /** + * Convert Object to a human readable string. + */ char[] toString() { return this.classinfo.name; } + /** + * Compute hash function for Object. + */ uint toHash() { // BUG: this prevents a compacting GC from working, needs to be fixed return cast(uint)cast(void *)this; } + /** + * Compare with another Object obj. + * Returns: + * $(TABLE + * $(TR $(TD this < obj) $(TD < 0)) + * $(TR $(TD this == obj) $(TD 0)) + * $(TR $(TD this > obj) $(TD > 0)) + * ) + */ int opCmp(Object o) { // BUG: this prevents a compacting GC from working, needs to be fixed return cast(int)cast(void *)this - cast(int)cast(void *)o; } + /** + * Returns !=0 if this object does have the same contents as obj. + */ int opEquals(Object o) { return this is o; } } +/** + * Information about an interface. + */ struct Interface { - ClassInfo classinfo; + ClassInfo classinfo; /// .classinfo for this interface void *[] vtbl; int offset; // offset to Interface 'this' from Object 'this' } +/** + * Runtime type information about a class. Can be retrieved for any class type + * or instance by using the .classinfo property. + */ class ClassInfo : Object { - byte[] init; // class static initializer - char[] name; // class name - void *[] vtbl; // virtual function pointer table - Interface[] interfaces; - ClassInfo base; + byte[] init; /** class static initializer + * (init.length gives size in bytes of class) + */ + char[] name; /// class name + void *[] vtbl; /// virtual function pointer table + Interface[] interfaces; /// interfaces this class implements + ClassInfo base; /// base class void *destructor; void (*classInvariant)(Object); uint flags; @@ -96,6 +152,11 @@ private import std.string; +/** + * Runtime type information about a type. + * Can be retrieved for any type using a + * TypeidExpression. + */ class TypeInfo { uint toHash() @@ -120,10 +181,19 @@ return this is o || this.classinfo.name == o.classinfo.name; } + /// Returns a hash of the instance of a type. uint getHash(void *p) { return cast(uint)p; } + + /// Compares two instances for equality. int equals(void *p1, void *p2) { return p1 == p2; } + + /// Compares two instances for <, ==, or >. int compare(void *p1, void *p2) { return 0; } + + /// Returns size of the type. size_t tsize() { return 0; } + + /// Swaps two instances of the type. void swap(void *p1, void *p2) { size_t n = tsize(); @@ -495,10 +565,16 @@ int function(void*,void*) xopCmp; } +/** + * All recoverable exceptions should be derived from class Exception. + */ class Exception : Object { char[] msg; + /** + * Constructor; msg is a descriptive message for the exception. + */ this(char[] msg) { this.msg = msg; @@ -512,10 +588,16 @@ char[] toString() { return msg; } } +/** + * All irrecoverable exceptions should be derived from class Error. + */ class Error : Exception { Error next; + /** + * Constructor; msg is a descriptive message for the exception. + */ this(char[] msg) { super(msg); diff -uNr dmd-0.133/dmd/src/phobos/std/base64.d dmd-0.134/dmd/src/phobos/std/base64.d --- dmd-0.133/dmd/src/phobos/std/base64.d 2005-09-24 17:25:30.000000000 +0200 +++ dmd-0.134/dmd/src/phobos/std/base64.d 2005-09-28 23:21:32.000000000 +0200 @@ -1,3 +1,14 @@ +/** + * Encodes/decodes MIME base64 data. + * + * Macros: + * WIKI=StdBase64 + * References: + * Wikipedia Base64$(BR) + * RFC 2045$(BR) + */ + + /* base64.d * Modified from C. Miller's version, his copyright is below. */ @@ -24,6 +35,9 @@ module std.base64; +/** + */ + class Base64Exception: Exception { this(char[] msg) @@ -33,6 +47,9 @@ } +/** + */ + class Base64CharException: Base64Exception { this(char[] msg) @@ -45,7 +62,11 @@ const char[] array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -uint encodeLength(uint slen) //returns the number of bytes needed to encode a string of this length +/** + * Returns the number of bytes needed to encode a string of length slen. + */ + +uint encodeLength(uint slen) { uint result; result = slen / 3; @@ -54,8 +75,16 @@ return result * 4; } +/** + * Encodes str[] and places the result in buf[]. + * Params: + * str = string to encode + * buf = destination buffer, must be large enough for the result. + * Returns: + * slice into buf[] representing encoded result + */ -char[] encode(char[] str, char[] buf) //buf must be large enough +char[] encode(char[] str, char[] buf) in { assert(buf.length >= encodeLength(str.length)); @@ -110,6 +139,10 @@ } +/** + * Encodes str[] and returns the result. + */ + char[] encode(char[] str) { return encode(str, new char[encodeLength(str.length)]); @@ -126,13 +159,28 @@ } -uint decodeLength(uint elen) //returns the number of bytes needed to decode an encoded string of this length +/** + * Returns the number of bytes needed to decode an encoded string of this + * length. + */ +uint decodeLength(uint elen) { return elen / 4 * 3; } -char[] decode(char[] estr, char[] buf) //buf must be large enough to store decoded string +/** + * Decodes str[] and places the result in buf[]. + * Params: + * str = string to encode + * buf = destination buffer, must be large enough for the result. + * Returns: + * slice into buf[] representing encoded result + * Errors: + * Throws Base64Exception on invalid base64 encoding in estr[]. + * Throws Base64CharException on invalid base64 character in estr[]. + */ +char[] decode(char[] estr, char[] buf) in { assert(buf.length + 2 >= decodeLength(estr.length)); //account for '=' padding @@ -212,6 +260,12 @@ return buf[0 .. (bp - &buf[0])]; } +/** + * Decodes estr[] and returns the result. + * Errors: + * Throws Base64Exception on invalid base64 encoding in estr[]. + * Throws Base64CharException on invalid base64 character in estr[]. + */ char[] decode(char[] estr) { diff -uNr dmd-0.133/dmd/src/phobos/std/compiler.d dmd-0.134/dmd/src/phobos/std/compiler.d --- dmd-0.133/dmd/src/phobos/std/compiler.d 2005-09-24 17:25:30.000000000 +0200 +++ dmd-0.134/dmd/src/phobos/std/compiler.d 2005-09-28 23:21:32.000000000 +0200 @@ -1,4 +1,9 @@ +/** + * Macros: + * WIKI = StdCompiler + */ + /* Written by Walter Bright * www.digitalmars.com * Placed into Public Domain @@ -10,27 +15,31 @@ const { - // Vendor specific string naming the compiler + /// Vendor specific string naming the compiler, for example: "Digital Mars D". char[] name = "Digital Mars D"; - // Master list of D compiler vendors + /// Master list of D compiler vendors. enum Vendor { - DigitalMars = 1 + DigitalMars = 1, /// Digital Mars } - // Which vendor we are + /// Which vendor produced this compiler. Vendor vendor = Vendor.DigitalMars; - // The vendor specific version number, as in - // version_major.version_minor + /** + * The vendor specific version number, as in + * version_major.version_minor + */ uint version_major = 0; - uint version_minor = 0; + uint version_minor = 0; /// ditto - // The version of the D Programming Language Specification - // Supported by the compiler + /** + * The version of the D Programming Language Specification + * supported by the compiler. + */ uint D_major = 0; - uint D_minor = 0; + uint D_minor = 134; } diff -uNr dmd-0.133/dmd/src/phobos/std/math.d dmd-0.134/dmd/src/phobos/std/math.d --- dmd-0.133/dmd/src/phobos/std/math.d 2005-09-24 17:25:30.000000000 +0200 +++ dmd-0.134/dmd/src/phobos/std/math.d 2005-09-28 23:21:32.000000000 +0200 @@ -8,7 +8,8 @@ * Special Values * $0 * - * NAN = NAN + * NAN = $(RED NAN) + * SUP = $0 */ /* @@ -386,7 +387,7 @@ } /********************** - * Calculates ex. + * Calculates e$(SUP x). * * $(TABLE_SV * x exp(x) @@ -397,7 +398,7 @@ real exp(real x) { return std.c.math.expl(x); } /********************** - * Calculates 2x. + * Calculates 2$(SUP x). * * $(TABLE_SV * x exp2(x) @@ -415,7 +416,7 @@ * than exp(x)-1. * * $(TABLE_SV - * x ex-1 + * x e$(SUP x)-1 * ±0.0 ±0.0 * +∞ +∞ * -∞ -1.0 @@ -429,8 +430,8 @@ * Separate floating point value into significand and exponent. * * Returns: - *
Calculate and return x and exp such that - * value =x*2exp and + * Calculate and return x and exp such that + * value =x*2$(SUP exp) and * .5 <= |x| < 1.0
* x has same sign as value. * @@ -556,7 +557,7 @@ /******************************************* - * Compute n * 2exp + * Compute n * 2$(SUP exp) * References: frexp */ @@ -625,7 +626,7 @@ * For a positive, finite x: * *
- *	1 <= x * FLT_RADIX-logb(x) < FLT_RADIX 
+ *	1 <= x * FLT_RADIX$(SUP -logb(x)) < FLT_RADIX 
  *	
* * $(TABLE_SV @@ -653,7 +654,7 @@ real modf(real x, inout real y) { return std.c.math.modfl(x,&y); } /************************************* - * Efficiently calculates x * 2n. + * Efficiently calculates x * 2$(SUP n). * * scalbn handles underflow and overflow in * the same fashion as the basic arithmetic operators. @@ -1289,7 +1290,7 @@ } /********************************************* - * Calculates xy. + * Calculates x$(SUP y). * * $(TABLE_SV * diff -uNr dmd-0.133/dmd/src/phobos/std/string.d dmd-0.134/dmd/src/phobos/std/string.d --- dmd-0.133/dmd/src/phobos/std/string.d 2005-09-24 17:25:30.000000000 +0200 +++ dmd-0.134/dmd/src/phobos/std/string.d 2005-09-28 23:21:32.000000000 +0200 @@ -510,29 +510,32 @@ if (sublength == 0) return 0; - char c = sub[0]; - if (sublength == 1) - { - char *p = memchr(s, c, s.length); - if (p) - return p - &s[0]; - } - else + if (s.length >= sublength) { - size_t imax = s.length - sublength + 1; + char c = sub[0]; + if (sublength == 1) + { + char *p = memchr(s, c, s.length); + if (p) + return p - &s[0]; + } + else + { + size_t imax = s.length - sublength + 1; - // Remainder of sub[] - char *q = &sub[1]; - sublength--; + // Remainder of sub[] + char *q = &sub[1]; + sublength--; - for (size_t i = 0; i < imax; i++) - { - char *p = memchr(&s[i], c, imax - i); - if (!p) - break; - i = p - &s[0]; - if (memcmp(p + 1, q, sublength) == 0) - return i; + for (size_t i = 0; i < imax; i++) + { + char *p = memchr(&s[i], c, imax - i); + if (!p) + break; + i = p - &s[0]; + if (memcmp(p + 1, q, sublength) == 0) + return i; + } } } return -1; @@ -1486,7 +1489,7 @@ return s[i .. s.length]; } -char[] stripr(char[] s) +char[] stripr(char[] s) /// ditto { uint i; @@ -1498,7 +1501,7 @@ return s[0 .. i]; } -char[] strip(char[] s) +char[] strip(char[] s) /// ditto { return stripr(stripl(s)); } diff -uNr dmd-0.133/dmd/src/phobos/std.ddoc dmd-0.134/dmd/src/phobos/std.ddoc --- dmd-0.133/dmd/src/phobos/std.ddoc 2005-09-24 17:25:30.000000000 +0200 +++ dmd-0.134/dmd/src/phobos/std.ddoc 2005-09-28 23:21:32.000000000 +0200 @@ -15,13 +15,12 @@ - - + www.digitalmars.com Home | Search -| D +| $(RED D) | Comments
@@ -29,7 +28,7 @@
-
+
@@ -112,7 +111,9 @@ page.
-Copyright © 1999-$(YEAR) by Digital Mars, All Rights Reserved

+$(SMALL Copyright © 1999-$(YEAR) by Digital Mars, All Rights Reserved
+Page generated by $(LINK2 http://www.digitalmars.com/d/ddoc.html, Ddoc).) +