changeset 145:a14ac9e5c858

Changes Scope to use char[]'s insted of Identifiers for lookup.
author Anders Johnsen <skabet@gmail.com>
date Mon, 21 Jul 2008 17:56:33 +0200
parents 6e6355fb5f0f
children 8c09fdaa724e
files ast/Decl.d ast/Exp.d sema/Scope.d sema/ScopeBuilder.d sema/ScopeCheck.d
diffstat 5 files changed, 38 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/ast/Decl.d	Mon Jul 21 17:41:40 2008 +0200
+++ b/ast/Decl.d	Mon Jul 21 17:56:33 2008 +0200
@@ -86,7 +86,7 @@
 
     override DType type()
     {
-        return env.findType(varType);
+        return env.findType(varType.get);
     }
 
     Identifier varType, identifier;
@@ -177,7 +177,7 @@
             return myType;
 
         auto t = new DFunction(identifier);
-        t.returnType = env.findType(returnType);
+        t.returnType = env.findType(returnType.get);
         SmallArray!(DType) array;
         foreach (a; funcArgs)
             array ~= a.type();
@@ -214,7 +214,7 @@
 
     override DType type()
     {
-        return env.findType(identifier);
+        return env.findType(identifier.get);
     }
 
     Identifier identifier;
@@ -246,7 +246,7 @@
 
     override DType type()
     {
-        return env.findType(identifier);
+        return env.findType(identifier.get);
     }
 
     Identifier identifier;
@@ -279,7 +279,7 @@
 
     override DType type()
     {
-        return env.findType(identifier);
+        return env.findType(identifier.get);
     }
 
     Identifier identifier;
--- a/ast/Exp.d	Mon Jul 21 17:41:40 2008 +0200
+++ b/ast/Exp.d	Mon Jul 21 17:56:33 2008 +0200
@@ -457,7 +457,7 @@
 
     override DType type()
     {
-        return env.findType(this.castType);
+        return env.findType(this.castType.get);
     }
 
     override CastExp simplify()
@@ -571,7 +571,7 @@
 
     override Symbol getSymbol()
     {
-        if (auto decl = env.find(this))
+        if (auto decl = env.find(this.get))
             return decl.sym;
         else
             return null;
--- a/sema/Scope.d	Mon Jul 21 17:41:40 2008 +0200
+++ b/sema/Scope.d	Mon Jul 21 17:56:33 2008 +0200
@@ -29,12 +29,12 @@
 
     ImportDecl[] imports;
 
-    void put(Identifier id, Decl d)
+    void put(char[] id, Decl d)
     {
         symbols[id] = d;
     }
 
-    Decl find(Identifier id)
+    Decl find(char[] id)
     {
         if(id is null)
             return null;
@@ -57,9 +57,9 @@
         return imports;
     }
 
-    DType findType(Identifier id)
+    DType findType(char[] id)
     {
-        if (auto type = id.get in types)
+        if (auto type = id in types)
             return *type;
         if (enclosing !is null)
         {
@@ -125,7 +125,7 @@
     DType[char[]] types;
     int currentStmtIndex = -1;
 private:
-    Decl[Identifier] symbols;
+    Decl[char[]] symbols;
     FuncDecl func;
 }
 
@@ -141,7 +141,7 @@
         add(m);
     }
 
-    DType findType(ImportDecl[] imports, Identifier type)
+    DType findType(ImportDecl[] imports, char[] type)
     {
         foreach(i ; imports)
             if(i.get in modules)
@@ -153,7 +153,7 @@
         return null;
     }
 
-    Decl find(ImportDecl[] imports, Identifier id)
+    Decl find(ImportDecl[] imports, char[] id)
     {
         foreach(i ; imports)
             if(i.get in modules)
--- a/sema/ScopeBuilder.d	Mon Jul 21 17:41:40 2008 +0200
+++ b/sema/ScopeBuilder.d	Mon Jul 21 17:56:33 2008 +0200
@@ -43,7 +43,7 @@
         d.sym = current.symbol.createMember(
                 d.identifier.get, 
                 d.type, 
-                d.env.find(d.identifier));
+                d.env.find(d.identifier.get));
     }
 
     override void visitVarDecl(VarDecl d)
@@ -57,8 +57,8 @@
         DType t = typeOf(d.varType, d.env);
         d.sym = current.symbol.createAlias(
                 d.identifier.get,
-                d.env.find(d.varType).sym,
-                d.env.find(d.identifier));
+                d.env.find(d.varType.get).sym,
+                d.env.find(d.identifier.get));
         d.sym.type = t;
     }
 
@@ -98,7 +98,7 @@
             return (typeOf(i.pointerOf, sc)).getPointerTo();
         else if(auto i = cast(StaticArrayIdentifier)id)
             return typeOf(i.arrayOf, sc).getAsStaticArray(i.size);
-        return sc.findType(id);
+        return sc.findType(id.get);
     }
 
     Module[] modules;
@@ -120,11 +120,11 @@
 
     override void visitStructDecl(StructDecl s)
     {
-        auto st = s.env.findType(s.identifier).asStruct;
+        auto st = s.env.findType(s.identifier.get).asStruct;
         s.sym = current.symbol.createMember(
                 s.identifier.get, 
                 st,
-                s.env.find(s.identifier));
+                s.env.find(s.identifier.get));
 
         foreach (decl; s.decls)
         {
@@ -146,11 +146,11 @@
 
     override void visitClassDecl(ClassDecl s)
     {
-        auto st = s.env.findType(s.identifier).asClass;
+        auto st = s.env.findType(s.identifier.get).asClass;
         s.sym = current.symbol.createMember(
                 s.identifier.get, 
                 st,
-                s.env.find(s.identifier));
+                s.env.find(s.identifier.get));
 
         foreach (decl; s.decls)
         {
@@ -172,11 +172,11 @@
 
     override void visitInterfaceDecl(InterfaceDecl s)
     {
-        auto st = s.env.findType(s.identifier).asInterface;
+        auto st = s.env.findType(s.identifier.get).asInterface;
         s.sym = current.symbol.createMember(
                 s.identifier.get, 
                 st,
-                s.env.find(s.identifier));
+                s.env.find(s.identifier.get));
 
         foreach (decl; s.decls)
         {
@@ -203,7 +203,7 @@
             return (typeOf(i.pointerOf, sc)).getPointerTo();
         else if(auto i = cast(StaticArrayIdentifier)id)
             return typeOf(i.arrayOf, sc).getAsStaticArray(i.size);
-        return sc.findType(id);
+        return sc.findType(id.get);
     }
 
     Module current;
@@ -247,7 +247,7 @@
         sym.decl = decl;
         decl.sym = sym;
         decl.env = sc;
-        sc.put(id, decl);
+        sc.put(id.get, decl);
     }
 
     override void visitModule(Module m)
@@ -311,7 +311,7 @@
 
     override void visitFuncDecl(FuncDecl d)
     {
-        current().put(d.identifier, d);
+        current().put(d.identifier.get, d);
         d.env = current();
         auto sc = push();
 
@@ -339,7 +339,7 @@
         }
 
         auto sc = current();
-        sc.put(d.identifier, d);
+        sc.put(d.identifier.get, d);
         d.env = sc;
         visitExp(d.varType);
         visitExp(d.identifier);
@@ -348,7 +348,7 @@
     override void visitStructDecl(StructDecl s)
     {
         auto sc = current();
-        sc.put(s.identifier, s);
+        sc.put(s.identifier.get, s);
         s.env = sc;
         auto type = new DStruct(s.identifier);
 
@@ -362,7 +362,7 @@
     override void visitClassDecl(ClassDecl s)
     {
         auto sc = current();
-        sc.put(s.identifier, s);
+        sc.put(s.identifier.get, s);
         s.env = sc;
         auto type = new DClass(s.identifier);
 
@@ -376,7 +376,7 @@
     override void visitInterfaceDecl(InterfaceDecl s)
     {
         auto sc = current();
-        sc.put(s.identifier, s);
+        sc.put(s.identifier.get, s);
         s.env = sc;
         auto type = new DInterface(s.identifier);
 
--- a/sema/ScopeCheck.d	Mon Jul 21 17:41:40 2008 +0200
+++ b/sema/ScopeCheck.d	Mon Jul 21 17:56:33 2008 +0200
@@ -20,7 +20,7 @@
 
     override void visitIdentifier(Identifier i)
     {
-        auto symbol = i.env.find(i);
+        auto symbol = i.env.find(i.get);
 
         if(symbol is null)
             messages.report(UndefinedIdentifier, i.loc)
@@ -29,17 +29,17 @@
 
     override void visitVarDecl(VarDecl d)
     {
-        if(!d.env.findType(d.varType))
+        if(!d.env.findType(d.varType.get))
             messages.report(UndefinedType, d.varType.loc)
                 .arg(d.varType.get);
 
         auto env = d.env;
         if (d.env.enclosing)
-            if (d.env.enclosing.find(d.identifier) !is null)
+            if (d.env.enclosing.find(d.identifier.get) !is null)
                 if (d.env.parentFunction !is null)
                     while( d.env.parentFunction.env !is env)
                     {
-                        if (d.env.enclosing.find(d.identifier).env == env)
+                        if (d.env.enclosing.find(d.identifier.get).env == env)
                             messages.report(CannotRedeclare, d.identifier.loc)
                                 .arg(d.identifier.get);
                         env = env.enclosing;
@@ -114,11 +114,11 @@
     override void visitExp(Exp exp)
     {
         if (exp.expType == ExpType.Identifier && inFunction
-            && exp.env.find(cast(Identifier)exp) !is null)
+            && exp.env.find((cast(Identifier)exp).get) !is null)
         {
-            if (exp.env.findType(cast(Identifier)exp) is null)
+            if (exp.env.findType((cast(Identifier)exp).get) is null)
                 internalCheckProtection(
-                    exp.env.find(cast(Identifier)exp).sym, 
+                    exp.env.find((cast(Identifier)exp).get).sym, 
                     cast(Identifier)exp);
         }