changeset 564:3c867a683258

Fixed VariableDeclaration.semantic().
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 28 Dec 2007 22:32:32 +0100
parents c838ed7f2ac9
children 184a8d8bad2e
files trunk/src/dil/Declarations.d trunk/src/dil/Location.d trunk/src/dil/Module.d trunk/src/dil/Scope.d trunk/src/dil/SymbolTable.d trunk/src/main.d
diffstat 6 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Declarations.d	Fri Dec 28 20:11:58 2007 +0100
+++ b/trunk/src/dil/Declarations.d	Fri Dec 28 22:32:32 2007 +0100
@@ -15,6 +15,7 @@
 import dil.Semantics;
 import dil.Symbols;
 import dil.TypeSystem;
+import common;
 
 abstract class Declaration : Node
 {
@@ -31,8 +32,11 @@
   void semantic(Scope sc)
   {
     foreach (node; this.children)
+    {
+      assert(node !is null);
       if (node.category == NodeCategory.Declaration)
         (cast(Declaration)cast(void*)node).semantic(sc);
+    }
   }
 
   final bool isStatic()
@@ -463,7 +467,8 @@
     foreach (i, ident; idents)
     {
       // Perform semantic analysis on value.
-      values[i] = values[i].semantic(scop);
+      if (values[i])
+        values[i] = values[i].semantic(scop);
       // Create a new variable symbol.
       auto variable = new Variable(stc, linkageType, type, ident, this);
       variables ~= variable;
--- a/trunk/src/dil/Location.d	Fri Dec 28 20:11:58 2007 +0100
+++ b/trunk/src/dil/Location.d	Fri Dec 28 22:32:32 2007 +0100
@@ -4,6 +4,7 @@
 +/
 module dil.Location;
 import dil.LexerFuncs;
+import dil.Unicode;
 import common;
 
 final class Location
@@ -40,7 +41,6 @@
 
   void set(size_t lineNum, char* lineBegin, char* to)
   {
-    assert(lineBegin !is null && to !is null);
     assert(lineBegin <= to);
     this.lineNum   = lineNum;
     this.lineBegin = lineBegin;
@@ -61,13 +61,15 @@
   {
     uint col;
     auto p = lineBegin;
+    if (!p)
+      return 0;
     for (; p <= to; ++p)
     {
       assert(delegate ()
         {
           // Check that there is no newline between p and to.
           // But 'to' may point to a newline.
-          if (p != to && (*p == '\n' || *p == '\r'))
+          if (p != to && isNewline(*p))
             return false;
           if (to-p >= 2 && isUnicodeNewline(p))
             return false;
@@ -76,7 +78,7 @@
       );
 
       // Skip this byte if it is a trail byte of a UTF-8 sequence.
-      if ((*p & 0xC0) == 0x80)
+      if (isTrailByte(*p))
         continue; // *p == 0b10xx_xxxx
       // Only count ASCII characters and the first byte of a UTF-8 sequence.
       ++col;
--- a/trunk/src/dil/Module.d	Fri Dec 28 20:11:58 2007 +0100
+++ b/trunk/src/dil/Module.d	Fri Dec 28 22:32:32 2007 +0100
@@ -91,6 +91,7 @@
     // Create module scope.
     auto scop = new Scope();
     scop.symbol = this; // Set this module as the scope's symbol.
+    scop.infoMan = this.infoMan;
     this.root.semantic(scop);
   }
 
--- a/trunk/src/dil/Scope.d	Fri Dec 28 20:11:58 2007 +0100
+++ b/trunk/src/dil/Scope.d	Fri Dec 28 22:32:32 2007 +0100
@@ -55,6 +55,7 @@
   {
     auto sc = new Scope();
     sc.parent = this;
+    sc.infoMan = this.infoMan;
     return sc;
   }
 
--- a/trunk/src/dil/SymbolTable.d	Fri Dec 28 20:11:58 2007 +0100
+++ b/trunk/src/dil/SymbolTable.d	Fri Dec 28 22:32:32 2007 +0100
@@ -13,7 +13,7 @@
 +/
 struct SymbolTable
 {
-  protected Symbol[char[]] table;
+  Symbol[char[]] table;
 
   /// Look up ident in the table.
   Symbol lookup(Identifier* ident)
--- a/trunk/src/main.d	Fri Dec 28 20:11:58 2007 +0100
+++ b/trunk/src/main.d	Fri Dec 28 22:32:32 2007 +0100
@@ -44,7 +44,10 @@
     foreach (filePath; filePaths)
     {
       auto mod = new Module(filePath, infoMan);
+      // Parse the file.
       mod.parse();
+      // Start semantic analysis.
+      mod.semantic();
     }
 
     foreach (info; infoMan.info)