diff trunk/src/dil/semantic/Analysis.d @ 778:78be32e3e157

Implemented conditional compilation.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Wed, 20 Feb 2008 22:09:29 +0100
parents 10b314bf37e3
children
line wrap: on
line diff
--- a/trunk/src/dil/semantic/Analysis.d	Wed Feb 20 01:24:19 2008 +0100
+++ b/trunk/src/dil/semantic/Analysis.d	Wed Feb 20 22:09:29 2008 +0100
@@ -8,6 +8,7 @@
 import dil.ast.Expressions;
 import dil.semantic.Scope;
 import dil.lexer.IdTable;
+import dil.Compilation;
 import common;
 
 /// Common semantics for pragma declarations and statements.
@@ -69,3 +70,37 @@
     // scop.error(e.begin, "expression must evaluate to a string");
   }
 }
+
+/// Returns true if the first branch (of a debug declaration/statement) or
+/// false if the else-branch should be compiled in.
+bool debugBranchChoice(Token* cond, CompilationContext context)
+{
+  if (cond)
+  {
+    if (cond.kind == TOK.Identifier)
+    {
+      if (context.findDebugId(cond.ident.str))
+        return true;
+    }
+    else if (cond.uint_ <= context.debugLevel)
+      return true;
+  }
+  else if (1 <= context.debugLevel)
+    return true;
+  return false;
+}
+
+/// Returns true if the first branch (of a version declaration/statement) or
+/// false if the else-branch should be compiled in.
+bool versionBranchChoice(Token* cond, CompilationContext context)
+{
+  assert(cond);
+  if (cond.kind == TOK.Identifier)
+  {
+    if (context.findVersionId(cond.ident.str))
+      return true;
+  }
+  else if (cond.uint_ >= context.versionLevel)
+    return true;
+  return false;
+}