diff trunk/src/dil/semantic/Pass2.d @ 707:efa5fcb9aa14

Added semantic code related to enums. Added member symbol to EnumMemberDeclaration. Added genAnonEnumID() to IdTable. Added class EnumMember. Wrote code for SemanticPass2.visit(EnumDeclaration). Revised code in SemanticPass1.visit(EnumDeclaration).
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 29 Jan 2008 01:07:39 +0100
parents ff4643a4a97c
children 3a4c7d444467
line wrap: on
line diff
--- a/trunk/src/dil/semantic/Pass2.d	Mon Jan 28 21:39:08 2008 +0100
+++ b/trunk/src/dil/semantic/Pass2.d	Tue Jan 29 01:07:39 2008 +0100
@@ -68,6 +68,11 @@
   private alias Statement S;
   private alias TypeNode T;
 
+  /// The scope symbol to use in identifier or template instance expressions.
+  /// E.g.: object.method(); // After 'object' has been visited, dotIdScope is
+  ///                        // set, and 'method' will be looked up there.
+  ScopeSymbol dotIdScope;
+
 override
 {
   D visit(CompoundDeclaration d)
@@ -75,6 +80,31 @@
     return super.visit(d);
   }
 
+  D visit(EnumDeclaration d)
+  {
+    Type type = Types.Int; // Default to int.
+    if (d.baseType)
+      type = visitT(d.baseType).type;
+    d.symbol.type = new TypeEnum(d.symbol, type);
+    enterScope(d.symbol);
+    foreach (member; d.members)
+    {
+      Expression finalValue;
+      if (member.value)
+      {
+        member.value = visitE(member.value);
+        finalValue = Interpreter.interpret(member.value, modul.infoMan, scop);
+        if (finalValue is Interpreter.NAR)
+          continue;
+      }
+      //else
+        // TODO: increment a number variable and assign that to value.
+      member.symbol.value = finalValue;
+    }
+    exitScope();
+    return d;
+  }
+
   D visit(MixinDeclaration md)
   {
     if (md.decls)