# HG changeset patch # User Aziz K?ksal # Date 1206381195 -3600 # Node ID fde064aca67301f3012390a02192d38f5e8aa535 # Parent fd52beaaa94afdc0073712e9736fd7fdba449098 Added support for version(unittest). diff -r fd52beaaa94a -r fde064aca673 src/cmd/Statistics.d --- a/src/cmd/Statistics.d Fri Mar 14 11:03:11 2008 -0400 +++ b/src/cmd/Statistics.d Mon Mar 24 18:53:15 2008 +0100 @@ -183,8 +183,9 @@ stats.tokensTable[TOK.HEAD] = 1; stats.tokensTable[TOK.Newline] = 1; } + // Traverse linked list. - while (1) + for (; token.next; token = token.next) { stats.tokenCount += 1; @@ -216,10 +217,6 @@ else if (token.isWhitespace) stats.wsTokenCount++; } - - if (token.next is null) - break; - token = token.next; } assert(token.kind == TOK.EOF); return stats; diff -r fd52beaaa94a -r fde064aca673 src/dil/parser/Parser.d --- a/src/dil/parser/Parser.d Fri Mar 14 11:03:11 2008 -0400 +++ b/src/dil/parser/Parser.d Mon Mar 24 18:53:15 2008 +0100 @@ -1234,6 +1234,16 @@ return null; } + Token* parseVersionCondition() + { + version(D2) + { + if (consumed(T.Unittest)) + return this.prevToken; + } + return parseIdentOrInt(); + } + Declaration parseDebugDeclaration() { skip(T.Debug); @@ -1283,7 +1293,7 @@ else { // ( Condition ) require(T.LParen); - cond = parseIdentOrInt(); + cond = parseVersionCondition(); require(T.RParen); // version ( Condition ) DeclarationsBlock decls = parseDeclarationsBlock(); @@ -2225,7 +2235,7 @@ // ( Condition ) require(T.LParen); - cond = parseIdentOrInt(); + cond = parseVersionCondition(); require(T.RParen); // version ( Condition ) Statement versionBody = parseNoScopeStatement(); diff -r fd52beaaa94a -r fde064aca673 src/dil/semantic/Analysis.d --- a/src/dil/semantic/Analysis.d Fri Mar 14 11:03:11 2008 -0400 +++ b/src/dil/semantic/Analysis.d Mon Mar 24 18:53:15 2008 +0100 @@ -95,7 +95,7 @@ bool versionBranchChoice(Token* cond, CompilationContext context) { assert(cond); - if (cond.kind == TOK.Identifier) + if (cond.kind == TOK.Identifier || cond.kind == TOK.Unittest) { if (context.findVersionId(cond.ident.str)) return true; diff -r fd52beaaa94a -r fde064aca673 src/dil/semantic/Pass1.d --- a/src/dil/semantic/Pass1.d Fri Mar 14 11:03:11 2008 -0400 +++ b/src/dil/semantic/Pass1.d Mon Mar 24 18:53:15 2008 +0100 @@ -415,7 +415,7 @@ D visit(DebugDeclaration d) { if (d.isSpecification) - { // debug = Id|Int + { // debug = Id | Int if (!isModuleScope()) error(d.begin, MSG.DebugSpecModuleLevel, d.spec.srcText); else if (d.spec.kind == TOK.Identifier) @@ -424,7 +424,7 @@ context.debugLevel = d.spec.uint_; } else - { + { // debug ( Condition ) if (debugBranchChoice(d.cond, context)) d.compiledDecls = d.decls; else @@ -437,7 +437,7 @@ D visit(VersionDeclaration d) { if (d.isSpecification) - { // version = Id|Int + { // version = Id | Int if (!isModuleScope()) error(d.begin, MSG.VersionSpecModuleLevel, d.spec.srcText); else if (d.spec.kind == TOK.Identifier) @@ -446,7 +446,7 @@ context.versionLevel = d.spec.uint_; } else - { + { // version ( Condition ) if (versionBranchChoice(d.cond, context)) d.compiledDecls = d.decls; else