Mercurial > projects > ddmd
diff dmd/Parser.d @ 79:43073c7c7769
updated to 2.035
also implemented a few missing functions
still crashes in Import.importAll though
author | Trass3r |
---|---|
date | Mon, 30 Aug 2010 03:57:51 +0200 |
parents | ad4792a1cfd6 |
children | be2ab491772e |
line wrap: on
line diff
--- a/dmd/Parser.d Sun Aug 29 14:39:08 2010 +0100 +++ b/dmd/Parser.d Mon Aug 30 03:57:51 2010 +0200 @@ -139,6 +139,7 @@ import dmd.CompoundDeclarationStatement; import dmd.Argument; import dmd.ParseStatementFlags; +import dmd.TypeNewArray; import dmd.TypeNext; import dmd.TypeInstance; import dmd.TypePointer; @@ -229,7 +230,7 @@ // ModuleDeclation leads off if (token.value == TOK.TOKmodule) { - ubyte* comment = token.blockComment; + string comment = token.blockComment; bool safe = false; nextToken(); @@ -312,7 +313,7 @@ STC stc; STC storageClass; Condition condition; - ubyte* comment; + string comment; //printf("Parser.parseDeclDefs()\n"); decldefs = new Dsymbols(); @@ -747,8 +748,9 @@ * Starts with token on the first ident. * Ends with scanner past closing ';' */ -version (DMDV2) { - Dsymbols parseAutoDeclarations(STC storageClass, ubyte* comment) +version (DMDV2) +{ + Dsymbols parseAutoDeclarations(STC storageClass, const(char)[] comment) { auto a = new Dsymbols; @@ -1904,7 +1906,7 @@ //printf("enum definition\n"); e.members = new Dsymbols(); nextToken(); - ubyte* comment = token.blockComment; + string comment = token.blockComment; while (token.value != TOK.TOKrcurly) { /* Can take the following forms: @@ -2413,89 +2415,95 @@ Type parseBasicType2(Type t) { - //printf("parseBasicType2()\n"); + //writef("parseBasicType2()\n"); while (1) { - switch (token.value) - { - case TOK.TOKmul: - t = new TypePointer(t); - nextToken(); - continue; - - case TOK.TOKlbracket: - // Handle []. Make sure things like - // int[3][1] a; - // is (array[1] of array[3] of int) - nextToken(); - if (token.value == TOK.TOKrbracket) + switch (token.value) { - t = new TypeDArray(t); // [] + case TOK.TOKmul: + t = new TypePointer(t); + nextToken(); + continue; + + case TOK.TOKlbracket: + // Handle []. Make sure things like + // int[3][1] a; + // is (array[1] of array[3] of int) nextToken(); - } - else if (isDeclaration(&token, 0, TOK.TOKrbracket, null)) - { // It's an associative array declaration - - //printf("it's an associative array\n"); - Type index = parseType(); // [ type ] - t = new TypeAArray(t, index); - check(TOK.TOKrbracket); - } - else - { - //printf("it's type[expression]\n"); - inBrackets++; - Expression e = parseExpression(); // [ expression ] - if (token.value == TOK.TOKslice) + if (token.value == TOK.TOKrbracket) + { + t = new TypeDArray(t); // [] + nextToken(); + } + else if (token.value == TOKnew && peekNext() == TOKrbracket) { - nextToken(); - Expression e2 = parseExpression(); // [ exp .. exp ] - t = new TypeSlice(t, e, e2); + t = new TypeNewArray(t); // [new] + nextToken(); + nextToken(); + } + else if (isDeclaration(&token, 0, TOK.TOKrbracket, null)) + { // It's an associative array declaration + + //printf("it's an associative array\n"); + Type index = parseType(); // [ type ] + t = new TypeAArray(t, index); + check(TOK.TOKrbracket); } else - t = new TypeSArray(t,e); - inBrackets--; - check(TOK.TOKrbracket); - } - continue; - - case TOK.TOKdelegate: - case TOK.TOKfunction: - { // Handle delegate declaration: - // t delegate(parameter list) nothrow pure - // t function(parameter list) nothrow pure - Arguments arguments; - int varargs; - bool ispure = false; - bool isnothrow = false; - TOK save = token.value; - - nextToken(); - arguments = parseParameters(&varargs); - while (1) - { // Postfixes - if (token.value == TOK.TOKpure) - ispure = true; - else if (token.value == TOK.TOKnothrow) - isnothrow = true; + { + //printf("it's type[expression]\n"); + inBrackets++; + Expression e = parseExpression(); // [ expression ] + if (token.value == TOK.TOKslice) + { + nextToken(); + Expression e2 = parseExpression(); // [ exp .. exp ] + t = new TypeSlice(t, e, e2); + } + else + t = new TypeSArray(t,e); + inBrackets--; + check(TOK.TOKrbracket); + } + continue; + + case TOK.TOKdelegate: + case TOK.TOKfunction: + { // Handle delegate declaration: + // t delegate(parameter list) nothrow pure + // t function(parameter list) nothrow pure + Arguments arguments; + int varargs; + bool ispure = false; + bool isnothrow = false; + TOK save = token.value; + + nextToken(); + arguments = parseParameters(&varargs); + while (1) + { // Postfixes + if (token.value == TOK.TOKpure) + ispure = true; + else if (token.value == TOK.TOKnothrow) + isnothrow = true; + else + break; + nextToken(); + } + TypeFunction tf = new TypeFunction(arguments, t, varargs, linkage); + tf.ispure = ispure; + tf.isnothrow = isnothrow; + if (save == TOK.TOKdelegate) + t = new TypeDelegate(tf); else - break; - nextToken(); - } - TypeFunction tf = new TypeFunction(arguments, t, varargs, linkage); - tf.ispure = ispure; - tf.isnothrow = isnothrow; - if (save == TOK.TOKdelegate) - t = new TypeDelegate(tf); - else - t = new TypePointer(tf); // pointer to function - continue; - } - - default: - return t; - } - assert(0); + t = new TypePointer(tf); // pointer to function + continue; + } + + default: + return t; + } + assert(0); } assert(0); return null; @@ -2556,6 +2564,12 @@ ta = new TypeDArray(t); // [] nextToken(); } + else if (token.value == TOKnew && peekNext() == TOKrbracket) + { + t = new TypeNewArray(t); // [new] + nextToken(); + nextToken(); + } else if (isDeclaration(&token, 0, TOK.TOKrbracket, null)) { // It's an associative array @@ -2694,7 +2708,7 @@ Identifier ident; Dsymbols a; TOK tok = TOK.TOKreserved; - ubyte* comment = token.blockComment; + string comment = token.blockComment; LINK link = linkage; //printf("parseDeclarations() %s\n", token.toChars()); @@ -3289,11 +3303,10 @@ } case TOK.TOKlcurly: - { Statements statements; - - nextToken(); - statements = new Statements(); - while (token.value != TOK.TOKrcurly) + { + nextToken(); + Statements statements = new Statements(); + while (token.value != TOK.TOKrcurly && token.value != TOKeof) { statements.push(cast(void*)parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope)); } @@ -3644,6 +3657,7 @@ statements = new Statements(); while (token.value != TOK.TOKcase && token.value != TOK.TOKdefault && + token.value != TOKeof && token.value != TOK.TOKrcurly) { statements.push(cast(void*)parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope)); @@ -3679,6 +3693,7 @@ statements = new Statements(); while (token.value != TOK.TOKcase && token.value != TOK.TOKdefault && + token.value != TOKeof && token.value != TOK.TOKrcurly) { statements.push(cast(void*)parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope)); @@ -4464,6 +4479,11 @@ { t = peek(t); } + else if (t.value == TOKnew && peek(t).value == TOKrbracket) + { + t = peek(t); + t = peek(t); + } else if (isDeclaration(t, 0, TOK.TOKrbracket, &t)) { // It's an associative array declaration @@ -6101,7 +6121,7 @@ return e; } - void addComment(Dsymbol s, ubyte* blockComment) + void addComment(Dsymbol s, const(char)[] blockComment) { s.addComment(combineComments(blockComment, token.lineComment)); token.lineComment = null;