Charj: add framework for detecting necessary module externs
authorAaron Becker <akbecker@gmail.com>
Tue, 1 Jun 2010 23:36:16 +0000 (18:36 -0500)
committerAaron Becker <akbecker@gmail.com>
Tue, 1 Jun 2010 23:36:16 +0000 (18:36 -0500)
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/src/charj/translator/ClassSymbol.java

index 1906b4f612fc0e712df2424a2528529933d65e0d..59dc01037b5993714a2e111af33f373b5e1b473f 100644 (file)
@@ -197,6 +197,10 @@ scope ScopeStack;
             ^(VAR_DECLARATOR_LIST field[$simpleType.type]+))
     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType
             ^(VAR_DECLARATOR_LIST field[$objectType.type]+))
             ^(VAR_DECLARATOR_LIST field[$simpleType.type]+))
     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType
             ^(VAR_DECLARATOR_LIST field[$objectType.type]+))
+        {
+            ClassSymbol type = $objectType.type;
+            if (type.isChare) currentClass.addExtern(type.getName());
+        }
     |   ^(CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList 
             b=block)
         {
     |   ^(CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList 
             b=block)
         {
@@ -341,10 +345,10 @@ String name = "";
     :   ^(QUALIFIED_TYPE_IDENT (typeIdent {name += $typeIdent.name;})+) 
         {
             $type = null;
     :   ^(QUALIFIED_TYPE_IDENT (typeIdent {name += $typeIdent.name;})+) 
         {
             $type = null;
-            //System.out.println("trying to resolve type " + name + " in type " + currentClass);
+            System.out.println("trying to resolve type " + name + " in type " + currentClass);
             if (currentClass != null) $type = currentClass.resolveType(name);
             if (currentClass != null) $type = currentClass.resolveType(name);
-            //System.out.println("got " + $type);
-            //if ($type == null) $type = symtab.resolveBuiltinType(name);
+            System.out.println("got " + $type);
+            if ($type == null) $type = symtab.resolveBuiltinType(name);
             $QUALIFIED_TYPE_IDENT.symbol = $type;
         }
     ;
             $QUALIFIED_TYPE_IDENT.symbol = $type;
         }
     ;
@@ -405,6 +409,11 @@ blockStatement
 localVariableDeclaration
     :   ^(PRIMITIVE_VAR_DECLARATION localModifierList? simpleType variableDeclaratorList)
     |   ^(OBJECT_VAR_DECLARATION localModifierList? objectType variableDeclaratorList)
 localVariableDeclaration
     :   ^(PRIMITIVE_VAR_DECLARATION localModifierList? simpleType variableDeclaratorList)
     |   ^(OBJECT_VAR_DECLARATION localModifierList? objectType variableDeclaratorList)
+        {
+            ClassSymbol type = $objectType.type;
+            System.out.println("looked up type " + type + " for declaration " + $objectType.text);
+            if (type != null && type.isChare && currentClass != null) currentClass.addExtern(type.getName());
+        }
     ;
 
 statement
     ;
 
 statement
index 509bdd9a089c54aab5e232e992a899f0f8f717c4..a19d0e4e63fd43b6207fe0b4fb3c936991aef85c 100644 (file)
@@ -12,6 +12,7 @@ public class ClassSymbol extends SymbolWithScope implements Scope {
         new LinkedHashMap<String, PackageScope>();
     List<String> includes = new ArrayList<String>();
     List<String> usings = new ArrayList<String>();
         new LinkedHashMap<String, PackageScope>();
     List<String> includes = new ArrayList<String>();
     List<String> usings = new ArrayList<String>();
+    List<String> externs = new ArrayList<String>();
 
     /** Record of all fields and methods */
     public Map<String, Symbol> members = new LinkedHashMap<String, Symbol>();
 
     /** Record of all fields and methods */
     public Map<String, Symbol> members = new LinkedHashMap<String, Symbol>();
@@ -224,6 +225,10 @@ public class ClassSymbol extends SymbolWithScope implements Scope {
         includes.add(includeName);
     }
 
         includes.add(includeName);
     }
 
+    public void addExtern(String externName) {
+        externs.add(externName);
+    }
+
     public void getUsings(String usingName) {
         usings.add(usingName);
     }
     public void getUsings(String usingName) {
         usings.add(usingName);
     }
@@ -238,6 +243,11 @@ public class ClassSymbol extends SymbolWithScope implements Scope {
         return usings;
     }
 
         return usings;
     }
 
+    public List<String> getExterns()
+    {
+        return externs;
+    }
+
     public List<String> getPackageNames()
     {
         List<String> list = new LinkedList<String>();
     public List<String> getPackageNames()
     {
         List<String> list = new LinkedList<String>();