changeset 787:47c5099562c7

Added two semantic error messages.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 24 Feb 2008 03:11:39 +0100
parents 3b34f6a95a27
children 139c9a6a39a8
files trunk/src/dil/Messages.d trunk/src/dil/semantic/Pass1.d
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Messages.d	Sun Feb 24 02:41:11 2008 +0100
+++ b/trunk/src/dil/Messages.d	Sun Feb 24 03:11:39 2008 +0100
@@ -150,4 +150,6 @@
   auto VariableConflictsWithDecl = "variable '{}' conflicts with declaration @{}";
   auto InterfaceCantHaveVariables = "an interface can't have member variables";
   auto MixinArgumentMustBeString = "the mixin argument must evaluate to a string";
+  auto DebugSpecModuleLevel = "debug={} must be a module level";
+  auto VersionSpecModuleLevel = "version={} must be a module level";
 }
--- a/trunk/src/dil/semantic/Pass1.d	Sun Feb 24 02:41:11 2008 +0100
+++ b/trunk/src/dil/semantic/Pass1.d	Sun Feb 24 03:11:39 2008 +0100
@@ -72,6 +72,12 @@
     scop = scop.exit();
   }
 
+  /// Returns true if this is the module scope.
+  bool isModuleScope()
+  {
+    return scop.symbol.isModule();
+  }
+
   /// Insert a symbol into the current scope.
   void insert(Symbol symbol, Identifier* name)
   {
@@ -352,7 +358,9 @@
   {
     if (d.isSpecification)
     {
-      if (d.spec.kind == TOK.Identifier)
+      if (!isModuleScope())
+        error(d.begin, MSG.DebugSpecModuleLevel, d.spec.srcText);
+      else if (d.spec.kind == TOK.Identifier)
         context.addDebugId(d.spec.ident.str);
       else
         context.debugLevel = d.spec.uint_;
@@ -372,7 +380,9 @@
   {
     if (d.isSpecification)
     {
-      if (d.spec.kind == TOK.Identifier)
+      if (!isModuleScope())
+        error(d.begin, MSG.VersionSpecModuleLevel, d.spec.srcText);
+      else if (d.spec.kind == TOK.Identifier)
         context.addVersionId(d.spec.ident.str);
       else
         context.versionLevel = d.spec.uint_;