Charj: use ckNew when allocating for proxy types
authorAaron Becker <akbecker@gmail.com>
Tue, 1 Jun 2010 07:06:08 +0000 (02:06 -0500)
committerAaron Becker <akbecker@gmail.com>
Tue, 1 Jun 2010 07:06:08 +0000 (02:06 -0500)
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/src/charj/translator/ClassSymbol.java

index 8e5c93c0d2067c1f4c66aa4fb851afd16a758ede..186bd782aad186fa1cec2ebc1897fc71e49e9b31 100644 (file)
@@ -809,8 +809,8 @@ newExpression
         |   genericTypeArgumentList? qualifiedTypeIdent
                 newArrayConstruction                // new static array of object type reference elements
             ->  ^(STATIC_ARRAY_CREATOR[$n, "STATIC_ARRAY_CREATOR"] genericTypeArgumentList? qualifiedTypeIdent newArrayConstruction)
-        |   qualifiedTypeIdent arguments
-            -> ^(NEW qualifiedTypeIdent arguments)
+        |   type arguments
+            -> ^(NEW type arguments)
         )
     ;
     
index d1fe39684a9d39c0b8ea21093bf4c82fbd7538a6..5bde6d6fd0b0cab1fcd3c09a264727bc314c2215 100644 (file)
@@ -384,7 +384,7 @@ newExpression
             |   genericTypeArgumentList? qualifiedTypeIdent newArrayConstruction
             )
         )
-    |   ^(NEW qualifiedTypeIdent arguments)
+    |   ^(NEW type arguments)
     ;
 
 newArrayConstruction
index b6a342d5475d24f6d8bc945644bb7ace622e9c50..ede00ee836a021faf15676e70df60d7913123f52 100644 (file)
@@ -92,8 +92,7 @@ charjSource[SymbolTable symtab, OutputMode m]
         ->
     ;
 
-packageDeclaration
-returns [List names]
+packageDeclaration returns [List names]
     :   ^('package' (ids+=IDENT)+)
         {
             $names = $ids;
@@ -330,8 +329,7 @@ throwsClause
         -> template(t={$text}) "/* throwsClause-not implemented */ <t>"
     ;
 
-modifierList
-returns [List<String> names]
+modifierList returns [List<String> names]
     :   ^(MODIFIER_LIST (m+=modifier)+)
         {
           $names = new ArrayList<String>();
@@ -386,18 +384,27 @@ simpleType
     ;
 
 objectType
+    : proxyType -> {$proxyType.st;}
+    | nonProxyType -> {$nonProxyType.st}
+    ;
+
+nonProxyType
     :   ^(OBJECT_TYPE qualifiedTypeIdent arrayDeclaratorList?)
         -> obj_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
-    |   ^(PROXY_TYPE qualifiedTypeIdent arrayDeclaratorList?)
-        -> proxy_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
     |   ^(POINTER_TYPE qualifiedTypeIdent arrayDeclaratorList?)
         -> pointer_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
     |   ^(REFERENCE_TYPE qualifiedTypeIdent arrayDeclaratorList?)
         -> reference_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
     ;
 
-qualifiedTypeIdent
-    :   ^(QUALIFIED_TYPE_IDENT (t+=typeIdent)+) 
+proxyType
+    :   ^(PROXY_TYPE qualifiedTypeIdent arrayDeclaratorList?)
+        -> proxy_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
+    ;
+
+qualifiedTypeIdent returns [ClassSymbol type]
+    :   ^(QUALIFIED_TYPE_IDENT (t+=typeIdent)+)
+        {$type = (ClassSymbol)$QUALIFIED_TYPE_IDENT.symbol;}
         -> template(types={$t}) "<types; separator=\"::\">"
     ;
 
@@ -700,8 +707,10 @@ newExpression
             )
         )
         -> template(t={$text}) "<t>"
-    |   ^(NEW qualifiedTypeIdent arguments)
-        -> template(q={$qualifiedTypeIdent.st}, a={$arguments.st}) "new <q>(<a>)"
+    |   ^(NEW proxyType arguments)
+        -> template(t={$proxyType.st}, a={$arguments.st}) "<t>::ckNew(<a>)"
+    |   ^(NEW nonProxyType arguments)
+        -> template(q={$nonProxyType.st}, a={$arguments.st}) "new <q>(<a>)"
     ;
 
 newArrayConstruction
index c8aaa256a83b5f880c7bc5a79bb544761838074c..840be95674171f5b2a50c6deef15cc354573e0d4 100644 (file)
@@ -299,16 +299,23 @@ objectType returns [ClassSymbol type]
     |   ^(PROXY_TYPE qualifiedTypeIdent arrayDeclaratorList?)
     |   ^(POINTER_TYPE qualifiedTypeIdent arrayDeclaratorList?)
         {
-            $type = currentClass.resolveType($qualifiedTypeIdent.name);
-            if ($type == null) $type = symtab.resolveBuiltinType($qualifiedTypeIdent.name);
+            $type = $qualifiedTypeIdent.type;
         }
     ;
 
-qualifiedTypeIdent returns [String name]
+qualifiedTypeIdent returns [ClassSymbol type]
 @init {
-$name = "";
+String name = "";
 }
-    :   ^(QUALIFIED_TYPE_IDENT (typeIdent {$name += $typeIdent.name;})+) 
+    :   ^(QUALIFIED_TYPE_IDENT (typeIdent {name += $typeIdent.name;})+) 
+        {
+            $type = null;
+            //System.out.println("trying to resolve type " + name + " in type " + currentClass);
+            $type = currentClass.resolveType(name);
+            //System.out.println("got " + $type);
+            //if ($type == null) $type = symtab.resolveBuiltinType(name);
+            $QUALIFIED_TYPE_IDENT.symbol = $type;
+        }
     ;
 
 typeIdent returns [String name]
@@ -508,7 +515,7 @@ newExpression
             |   genericTypeArgumentList? qualifiedTypeIdent newArrayConstruction
             )
         )
-    |   ^(NEW qualifiedTypeIdent arguments)
+    |   ^(NEW type arguments)
     ;
 
 newArrayConstruction
index d4baa9d4e8f7ee930e36019e12ba55c026d27dee..7710caa23c51438b6636bfe3df8b00f2a7a2198d 100644 (file)
@@ -148,19 +148,19 @@ public class ClassSymbol extends SymbolWithScope implements Scope {
         }
 
         // not already seen in one of the imported packages, look on disk
-        for (String packageName : imports.keySet()) {
-            PackageScope pkg = resolvePackage(packageName);
-            ClassSymbol cs = symtab.translator.loadType(
-                    pkg.getFullyQualifiedName(), type);
-            if ( cs!=null ) {
-                pkg.define(type, cs); // add to symbol table
-                if ( debug() ) System.out.println(
-                        "ClassSymbol.resolveType(" + type +
-                        "): found after loading in context " + name +
-                        ":" + members.keySet());
-                return cs;
-            }
-        }
+        //for (String packageName : imports.keySet()) {
+        //    PackageScope pkg = resolvePackage(packageName);
+        //    ClassSymbol cs = symtab.translator.loadType(
+        //            pkg.getFullyQualifiedName(), type);
+        //    if ( cs!=null ) {
+        //        pkg.define(type, cs); // add to symbol table
+        //        if ( debug() ) System.out.println(
+        //                "ClassSymbol.resolveType(" + type +
+        //                "): found after loading in context " + name +
+        //                ":" + members.keySet());
+        //        return cs;
+        //    }
+        //}
 
         if ( debug() ) System.out.println(
                 "ClassSymbol.resolveType(" + type +