changeset 823:fde064aca673

Added support for version(unittest).
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Mon, 24 Mar 2008 18:53:15 +0100
parents fd52beaaa94a
children a8b3de006554
files src/cmd/Statistics.d src/dil/parser/Parser.d src/dil/semantic/Analysis.d src/dil/semantic/Pass1.d
diffstat 4 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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();
--- 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;
--- 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