Merge branch 'minas' into abecker/charj-main
[charm.git] / src / langs / charj / src / charj / translator / CharjSemantics.g
index e51d637ac96aaa723ea3d82f656e8dbac8dab231..2ec7de47f4b2c9ddf1977a99ca7da9ae1e3cfc73 100644 (file)
@@ -172,11 +172,25 @@ scope ScopeStack;
             currentClass.define($IDENT.text, sym);
             $FUNCTION_METHOD_DECL.symbol = sym;
         }
-    |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList)
-    |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList)
+    |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType
+            ^(VAR_DECLARATOR_LIST field[$simpleType.type]+))
+    |   ^(OBJECT_VAR_DECLARATION modifierList? objectType
+            ^(VAR_DECLARATOR_LIST field[$objectType.type]+))
     |   ^(CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList 
             b=block)
     ;
+
+field [ClassSymbol type]
+    :   ^(VAR_DECLARATOR ^(IDENT arrayDeclaratorList?) variableInitializer?)
+    {
+            //System.out.println("Found variable: " + $type + " " + $IDENT.text);
+            //VariableSymbol sym = new VariableSymbol(symtab, $IDENT.text, $type);
+            //sym.definition = $field.start;
+            //sym.definitionTokenStream = input.getTokenStream();
+            //$VAR_DECLARATOR.symbol = sym;
+            //currentClass.define($IDENT.text, sym);
+    }
+    ;
     
 interfaceScopeDeclaration
     :   ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? 
@@ -193,7 +207,8 @@ variableDeclaratorList
     ;
 
 variableDeclarator
-    :   ^(VAR_DECLARATOR variableDeclaratorId variableInitializer?)
+    :   ^(VAR_DECLARATOR ^(IDENT arrayDeclaratorList?) variableInitializer?)
+
     ;
     
 variableDeclaratorId
@@ -255,22 +270,36 @@ type
     |   VOID
     ;
 
-simpleType
+simpleType returns [ClassSymbol type]
     :   ^(SIMPLE_TYPE primitiveType arrayDeclaratorList?)
+        {
+            $type = symtab.resolveBuiltinType($primitiveType.text);
+        }
     ;
     
-objectType
+objectType returns [ClassSymbol type]
     :   ^(OBJECT_TYPE qualifiedTypeIdent arrayDeclaratorList?)
     |   ^(REFERENCE_TYPE qualifiedTypeIdent arrayDeclaratorList?)
     |   ^(POINTER_TYPE qualifiedTypeIdent arrayDeclaratorList?)
+        {
+            /*
+            System.out.println("Resolving type: " + $qualifiedTypeIdent.name);
+            $type = currentClass.resolveType($qualifiedTypeIdent.name);
+            if ($type == null) $type = symtab.resolveBuiltinType($qualifiedTypeIdent.name);
+            */
+        }
     ;
 
-qualifiedTypeIdent
-    :   ^(QUALIFIED_TYPE_IDENT typeIdent+) 
+qualifiedTypeIdent returns [String name]
+@init {
+$name = "";
+}
+    :   ^(QUALIFIED_TYPE_IDENT (typeIdent {$name += $typeIdent.name;})+) 
     ;
 
-typeIdent
+typeIdent returns [String name]
     :   ^(IDENT genericTypeArgumentList?)
+        { $name = $IDENT.text; }
     ;
 
 primitiveType