changeset 713:1bfae3480fdc

Added new predefined IDs and code to SemanticPass1.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Wed, 30 Jan 2008 23:23:58 +0100
parents f8875ef9a66d
children 140469ecb90e
files trunk/src/dil/lexer/IdentsGenerator.d trunk/src/dil/semantic/Pass1.d
diffstat 2 files changed, 81 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/lexer/IdentsGenerator.d	Wed Jan 30 18:29:23 2008 +0100
+++ b/trunk/src/dil/lexer/IdentsGenerator.d	Wed Jan 30 23:23:58 2008 +0100
@@ -26,6 +26,12 @@
   {"msg"}, {"lib"},
   // Linkage:
   {"C"}, {"D"}, {"Windows"}, {"Pascal"}, {"System"},
+  // Con-/Destructor:
+  {"__ctor"}, {"__dtor"},
+  // new() and delete() methods.
+  {"__new"}, {"__delete"},
+  // Unittest and invariant.
+  {"__unittest"}, {"__invariant"},
   // Operator methods:
   {"opNeg"},
   {"opPos"},
@@ -74,16 +80,15 @@
   ]
   ---
 +/
-char[] generateIdentMembers(char[] private_members = "")
+char[] generateIdentMembers()
 {
-  private_members = "private struct Ids {static const:";
+  char[] private_members = "private struct Ids {static const:";
 
   char[] public_members = "";
   char[] array = "private Identifier*[] __allIds = [";
   foreach (pair; identPairs)
   {
-    // NB: conditional makes function uneligible for CTE.
-    // char[] idString = pair.idStr ? pair.idStr : pair.str;
+    // N.B.: Compiler cries for some reason when trying to access pair.idStr.
     // Identifier _str = {"str", TOK.Identifier, ID.str};
     private_members ~= "Identifier _"~pair.str~` = {"`~pair.str~`", TOK.Identifier, ID.`~pair.str~"};\n";
     // Identifier* str = &_str;
@@ -98,8 +103,9 @@
 }
 
 /// CTF for generating the members of the enum ID.
-char[] generateIDMembers(char[] members = "")
+char[] generateIDMembers()
 {
+  char[] members;
   foreach (pair; identPairs)
     members ~= pair.str ~ ",\n";
   return members;
--- a/trunk/src/dil/semantic/Pass1.d	Wed Jan 30 18:29:23 2008 +0100
+++ b/trunk/src/dil/semantic/Pass1.d	Wed Jan 30 23:23:58 2008 +0100
@@ -142,7 +142,7 @@
     uint alignSize;
   }
 
-  // List of mixin, static if and pragma(msg,...) declarations.
+  // List of mixin, static if, static assert and pragma(msg,...) declarations.
   // Their analysis must be deferred because they entail
   // evaluation of expressions.
   Deferred[] deferred;
@@ -297,16 +297,40 @@
     return d;
   }
 
-  D visit(ConstructorDeclaration)
-  { return null; }
-  D visit(StaticConstructorDeclaration)
-  { return null; }
-  D visit(DestructorDeclaration)
-  { return null; }
-  D visit(StaticDestructorDeclaration)
-  { return null; }
-  D visit(FunctionDeclaration)
-  { return null; }
+  D visit(ConstructorDeclaration d)
+  {
+    auto func = new Function(Ident.__ctor, d);
+    insertOverload(func, func.name);
+    return d;
+  }
+
+  D visit(StaticConstructorDeclaration d)
+  {
+    auto func = new Function(Ident.__ctor, d);
+    insertOverload(func, func.name);
+    return d;
+  }
+
+  D visit(DestructorDeclaration d)
+  {
+    auto func = new Function(Ident.__dtor, d);
+    insertOverload(func, func.name);
+    return d;
+  }
+
+  D visit(StaticDestructorDeclaration d)
+  {
+    auto func = new Function(Ident.__dtor, d);
+    insertOverload(func, func.name);
+    return d;
+  }
+
+  D visit(FunctionDeclaration d)
+  {
+    auto func = new Function(d.name, d);
+    insertOverload(func, func.name);
+    return d;
+  }
 
   D visit(VariablesDeclaration vd)
   {
@@ -324,18 +348,25 @@
     return vd;
   }
 
-  D visit(InvariantDeclaration)
-  { return null; }
-  D visit(UnittestDeclaration)
-  { return null; }
+  D visit(InvariantDeclaration d)
+  {
+    auto func = new Function(Ident.__invariant, d);
+    insert(func, func.name);
+    return d;
+  }
+
+  D visit(UnittestDeclaration d)
+  {
+    auto func = new Function(Ident.__unittest, d);
+    insertOverload(func, func.name);
+    return d;
+  }
+
   D visit(DebugDeclaration)
   { return null; }
   D visit(VersionDeclaration)
   { return null; }
 
-  D visit(StaticAssertDeclaration)
-  { return null; }
-
   D visit(TemplateDeclaration d)
   {
     if (d.symbol)
@@ -350,10 +381,19 @@
     return d;
   }
 
-  D visit(NewDeclaration)
-  { /*add id to env*/return null; }
-  D visit(DeleteDeclaration)
-  { /*add id to env*/return null; }
+  D visit(NewDeclaration d)
+  {
+    auto func = new Function(Ident.__new, d);
+    insert(func, func.name);
+    return d;
+  }
+
+  D visit(DeleteDeclaration d)
+  {
+    auto func = new Function(Ident.__delete, d);
+    insert(func, func.name);
+    return d;
+  }
 
   D visit(ProtectionDeclaration d)
   {
@@ -391,6 +431,14 @@
     return d;
   }
 
+  // Deferred declarations:
+
+  D visit(StaticAssertDeclaration d)
+  {
+    addDeferred(d);
+    return d;
+  }
+
   D visit(StaticIfDeclaration d)
   {
     addDeferred(d);