# HG changeset patch # User trass3r # Date 1284593650 -7200 # Node ID b7b61140701d0030f3a44915eebf69e746705d8c # Parent 0c8cc2a10f9960e252834a4c25f268f87256d240 * added all missing default cases in switch statements + Lexer.getDocComment + Lexer.combineComments diff -r 0c8cc2a10f99 -r b7b61140701d commands.linux.txt --- a/commands.linux.txt Wed Sep 15 18:24:39 2010 +0200 +++ b/commands.linux.txt Thu Sep 16 01:34:10 2010 +0200 @@ -1,4 +1,3 @@ --w -version=Bug3602 -version=Bug4054 -version=Bug4059 diff -r 0c8cc2a10f99 -r b7b61140701d commands.txt --- a/commands.txt Wed Sep 15 18:24:39 2010 +0200 +++ b/commands.txt Thu Sep 16 01:34:10 2010 +0200 @@ -1,4 +1,3 @@ --w -version=DMDV2 -version=TX86 -version=MARS diff -r 0c8cc2a10f99 -r b7b61140701d dmd/AddExp.d --- a/dmd/AddExp.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/AddExp.d Thu Sep 16 01:34:10 2010 +0200 @@ -84,6 +84,7 @@ case TY.Timaginary80: type = Type.tcomplex80; break; + default: } } e = this; diff -r 0c8cc2a10f99 -r b7b61140701d dmd/FuncDeclaration.d --- a/dmd/FuncDeclaration.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/FuncDeclaration.d Thu Sep 16 01:34:10 2010 +0200 @@ -1793,6 +1793,10 @@ case 3: return -2; // forward references + + default: + writef("cov = %d\n", cov); + assert(false); } } } diff -r 0c8cc2a10f99 -r b7b61140701d dmd/Lexer.d --- a/dmd/Lexer.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/Lexer.d Thu Sep 16 01:34:10 2010 +0200 @@ -957,7 +957,7 @@ t.value = TOK.TOKcomment; return; } - if (doDocComment && t.ptr[2] == '/') + if (doDocComment && t.ptr[2] == '/' || t.ptr[2] == '!') // '///' or '//!' getDocComment(t, lastLine == linnum); p = end; t.value = TOK.TOKeof; @@ -981,7 +981,7 @@ t.value = TOK.TOKcomment; return; } - if (doDocComment && t.ptr[2] == '/') + if (doDocComment && t.ptr[2] == '/' || t.ptr[2] == '!') // '///' or '//!' getDocComment(t, lastLine == linnum); p++; @@ -2711,6 +2711,7 @@ case TOKfloat80v: result = TOKimaginary80v; break; + default: } } @@ -2782,9 +2783,156 @@ return u; } - void getDocComment(Token* t, uint lineComment) + /*************************************************** + * Parse doc comment embedded between t.ptr and p. + * Remove trailing blanks and tabs from lines. + * Replace all newlines with \n. + * Remove leading comment character from each line. + * Decide if it's a lineComment or a blockComment. + * Append to previous one for this token. + */ + void getDocComment(Token* t, uint lineComment) { - assert(false); + /* ct tells us which kind of comment it is: '!', '/', '*', or '+' + */ + ubyte ct = t.ptr[2]; + + /* Start of comment text skips over / * *, / + +, or / / / + */ + ubyte* q = t.ptr + 3; // start of comment text + + ubyte* qend = p; + if (ct == '*' || ct == '+') + qend -= 2; + + /* Scan over initial row of ****'s or ++++'s or ////'s + */ + for (; q < qend; q++) + { + if (*q != ct) + break; + } + + /* Remove trailing row of ****'s or ++++'s + */ + if (ct != '/' && ct != '!') + { + for (; q < qend; qend--) + { + if (qend[-1] != ct) + break; + } + } + + /* Comment is now [q .. qend]. + * Canonicalize it into buf[]. + */ + OutBuffer buf = new OutBuffer; + int linestart = 0; + + for (; q < qend; q++) + { + ubyte c = *q; + + switch (c) + { + case '*': + case '+': + if (linestart && c == ct) + { linestart = 0; + /* Trim preceding whitespace up to preceding \n + */ + while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t')) + buf.offset--; + continue; + } + break; + + case ' ': + case '\t': + break; + + case '\r': + if (q[1] == '\n') + continue; // skip the \r + goto Lnewline; + + default: + if (c == 226) + { + // If LS or PS + if (q[1] == 128 && + (q[2] == 168 || q[2] == 169)) + { + q += 2; + goto Lnewline; + } + } + linestart = 0; + break; + + Lnewline: + c = '\n'; // replace all newlines with \n + case '\n': + linestart = 1; + + /* Trim trailing whitespace + */ + while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t')) + buf.offset--; + + break; + } + buf.writeByte(c); + } + + // Always end with a newline + if (!buf.offset || buf.data[buf.offset - 1] != '\n') + buf.writeByte('\n'); + + buf.writeByte(0); + + // It's a line comment if the start of the doc comment comes + // after other non-whitespace on the same line. + string* dc = (lineComment && anyToken) + ? &t.lineComment + : &t.blockComment; + + // Combine with previous doc comment, if any + if (*dc) + *dc = combineComments(*dc, cast(string) buf.data[0 .. buf.size]); // TODO: utf decode etc? + else + { + auto bufsize = buf.size; + *dc = cast(string) buf.extractData()[0..bufsize]; + } + } + + /******************************************** + * Combine two document comments into one, + * separated by a newline. + */ + static string combineComments(string c1, string c2) + { + //printf("Lexer::combineComments('%s', '%s')\n", c1, c2); + + string c = c2; + + if (c1) + { + c = c1; + if (c2) + { + size_t len1 = c1.length; + size_t len2 = c2.length; + + c = c1.idup; + if (len1 && c1[$-1] != '\n') + c ~= '\n'; + c ~= c2; + } + } + return c; } static bool isValidIdentifier(string p) diff -r 0c8cc2a10f99 -r b7b61140701d dmd/RealExp.d --- a/dmd/RealExp.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/RealExp.d Thu Sep 16 01:34:10 2010 +0200 @@ -227,7 +227,6 @@ writef("%s\n", toChars()); ///type.print(); assert(0); - break; } return pdt; } diff -r 0c8cc2a10f99 -r b7b61140701d dmd/Type.d --- a/dmd/Type.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/Type.d Thu Sep 16 01:34:10 2010 +0200 @@ -89,15 +89,15 @@ * REALALIGNSIZE = alignment for reals */ version (TARGET_OSX) { - extern(C++) int REALSIZE = 16; + extern(C++) __gshared int REALSIZE = 16; int REALPAD = 6; int REALALIGNSIZE = 16; } else version (POSIX) { /// TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS - extern(C++) int REALSIZE = 12; + extern(C++) __gshared int REALSIZE = 12; int REALPAD = 2; int REALALIGNSIZE = 4; } else { - extern(C++) int REALSIZE = 10; + extern(C++) __gshared int REALSIZE = 10; int REALPAD = 0; int REALALIGNSIZE = 2; } diff -r 0c8cc2a10f99 -r b7b61140701d dmd/TypeBasic.d --- a/dmd/TypeBasic.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/TypeBasic.d Thu Sep 16 01:34:10 2010 +0200 @@ -130,6 +130,7 @@ case TY.Tdchar: d = Token.toChars(TOK.TOKdchar); flags |= TFLAGSintegral | TFLAGSunsigned; break; + default: } this.dstring = d; @@ -193,7 +194,6 @@ default: assert(0); - break; } //printf("TypeBasic.size() = %d\n", size); @@ -263,6 +263,7 @@ case TY.Tcomplex80: case TY.Timaginary80: case TY.Tfloat80: fvalue = real.max; goto Lfvalue; + default: } } else if (ident is Id.min) @@ -329,6 +330,7 @@ fvalue = real.nan; goto Lfvalue; } + default: } } else if (ident is Id.infinity) @@ -346,6 +348,7 @@ case TY.Tfloat80: fvalue = real.infinity; goto Lfvalue; + default: } } else if (ident is Id.dig) @@ -361,6 +364,7 @@ case TY.Tcomplex80: case TY.Timaginary80: case TY.Tfloat80: ivalue = real.dig; goto Lint; + default: } } else if (ident is Id.epsilon) @@ -376,6 +380,7 @@ case TY.Tcomplex80: case TY.Timaginary80: case TY.Tfloat80: fvalue = real.epsilon; goto Lfvalue; + default: } } else if (ident is Id.mant_dig) @@ -391,6 +396,7 @@ case TY.Tcomplex80: case TY.Timaginary80: case TY.Tfloat80: ivalue = real.mant_dig; goto Lint; + default: } } else if (ident is Id.max_10_exp) @@ -406,6 +412,7 @@ case TY.Tcomplex80: case TY.Timaginary80: case TY.Tfloat80: ivalue = real.max_10_exp; goto Lint; + default: } } else if (ident is Id.max_exp) @@ -421,6 +428,7 @@ case TY.Tcomplex80: case TY.Timaginary80: case TY.Tfloat80: ivalue = real.max_exp; goto Lint; + default: } } else if (ident is Id.min_10_exp) @@ -436,6 +444,7 @@ case TY.Tcomplex80: case TY.Timaginary80: case TY.Tfloat80: ivalue = real.min_10_exp; goto Lint; + default: } } else if (ident is Id.min_exp) @@ -451,6 +460,7 @@ case TY.Tcomplex80: case TY.Timaginary80: case TY.Tfloat80: ivalue = real.min_exp; goto Lint; + default: } } diff -r 0c8cc2a10f99 -r b7b61140701d dmd/TypeFunction.d --- a/dmd/TypeFunction.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/TypeFunction.d Thu Sep 16 01:34:10 2010 +0200 @@ -353,6 +353,9 @@ case LINK.LINKwindows: mc = 'W'; break; case LINK.LINKpascal: mc = 'V'; break; case LINK.LINKcpp: mc = 'R'; break; + default: + writef("linkage: %d\n", linkage); + assert(false, "ICE: undefined linkage occured"); } buf.writeByte(mc); if (ispure || isnothrow || isproperty || isref || trust) diff -r 0c8cc2a10f99 -r b7b61140701d dmd/VarDeclaration.d --- a/dmd/VarDeclaration.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/VarDeclaration.d Thu Sep 16 01:34:10 2010 +0200 @@ -196,7 +196,7 @@ */ int inferred = 0; if (!type) - { + { inuse++; ArrayInitializer ai = init.isArrayInitializer(); diff -r 0c8cc2a10f99 -r b7b61140701d dmd/codegen/linkhelper.d --- a/dmd/codegen/linkhelper.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/codegen/linkhelper.d Thu Sep 16 01:34:10 2010 +0200 @@ -12,7 +12,7 @@ { // msc.c wants to access global from out_config_init(), but it should never be called struct Global {} - Global global; + __gshared Global global; void error(const char *filename, uint linnum, const char *format, ...) { diff -r 0c8cc2a10f99 -r b7b61140701d dmd/expression/Min.d --- a/dmd/expression/Min.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/expression/Min.d Thu Sep 16 01:34:10 2010 +0200 @@ -81,6 +81,7 @@ case 6+0: v = Complex!(real)(c1.re - r2, c1.im); break; case 6+1: v = Complex!(real)(c1.re, c1.im - i2); break; case 6+2: v = Complex!(real)(c1.re - c2.re, c1.im - c2.im); break; + default: } e = new ComplexExp(loc, v, type); } diff -r 0c8cc2a10f99 -r b7b61140701d dmd/expression/Shr.d --- a/dmd/expression/Shr.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/expression/Shr.d Thu Sep 16 01:34:10 2010 +0200 @@ -47,6 +47,9 @@ case TY.Tuns64: value = cast(ulong)(value) >> count; break; + + default: + assert(0); } return new IntegerExp(loc, value, type); diff -r 0c8cc2a10f99 -r b7b61140701d dmd/expression/Util.d --- a/dmd/expression/Util.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/expression/Util.d Thu Sep 16 01:34:10 2010 +0200 @@ -187,8 +187,9 @@ * If there are no overloads of function f, return that function, * otherwise return NULL. */ -static int fpunique(void *param, FuncDeclaration f) -{ FuncDeclaration *pf = cast(FuncDeclaration *)param; +static int fpunique(void* param, FuncDeclaration f) +{ + FuncDeclaration* pf = cast(FuncDeclaration *)param; if (*pf) { *pf is null; diff -r 0c8cc2a10f99 -r b7b61140701d dmd/type/Util.d --- a/dmd/type/Util.d Wed Sep 15 18:24:39 2010 +0200 +++ b/dmd/type/Util.d Thu Sep 16 01:34:10 2010 +0200 @@ -32,6 +32,7 @@ return exp; } +//! ditto Expression semanticLength(Scope sc, TupleDeclaration s, Expression exp) { assert(false);