Charj: improved error message and added pupping for proxy types
authorAaron Becker <akbecker@gmail.com>
Sat, 29 May 2010 00:04:29 +0000 (19:04 -0500)
committerAaron Becker <akbecker@gmail.com>
Sat, 29 May 2010 00:04:29 +0000 (19:04 -0500)
src/langs/charj/src/charj/translator/ClassSymbol.java
src/langs/charj/src/charj/translator/PupRoutineCreator.java

index 3c31254593c25d407a70abb11482bc5e3c0d2e3b..5a1637f585aa13c11577817d5433a1afb2f14de6 100644 (file)
@@ -189,6 +189,9 @@ public class ClassSymbol extends SymbolWithScope implements Scope {
     public Symbol define(
             String name,
             Symbol sym) {
+        if (sym == null) {
+            System.out.println("ClassSymbol.define: Uh oh, defining null symbol");
+        }
         members.put(name, sym);
         if (sym instanceof MethodSymbol) {
             methods.put(name, (MethodSymbol)sym);
@@ -246,20 +249,20 @@ public class ClassSymbol extends SymbolWithScope implements Scope {
     {
         Set<ClassSymbol> types = new HashSet<ClassSymbol>();
         for (Map.Entry<String, VariableSymbol> entry : fields.entrySet()) {
-            types.add(((VariableSymbol)entry.getValue()).type);
+            // note: type info may be null for unknown types, but this might
+            // need to be changed at some point.
+            ClassSymbol type = ((VariableSymbol)entry.getValue()).type;
+            if (type != null) types.add(type);
         }
         return types;
     }
 
     public List<String> getMemberTypeNames()
     {
-        if (debug()) System.out.println("Looking for type names...");
-        if (debug()) System.out.println("Found " + fields.size() + " fields...");
         List<String> names = new ArrayList<String>();
         for (ClassSymbol c : getMemberTypes()) {
             if (c.isPrimitive) continue;
             names.add(c.getName());
-            if (debug()) System.out.println("Found type " + c.getFullyQualifiedName());
         }
         return names;
     }
index 73231b5bcd74d894387566f8c7245ad52371bee0..272289509ddf30e52c3b98db3740b6a9d078bac2 100644 (file)
@@ -73,7 +73,6 @@ class PupRoutineCreator
 
     protected void varPup(CharjAST idNode)
     {
-        System.out.println("in var pup: " + idNode.getText());
         int type = -1;
 
         for(CharjAST p = idNode.getParent(); p != null; p = p.getParent())
@@ -81,37 +80,37 @@ class PupRoutineCreator
             switch(p.getType())
             {
                 case CharjParser.PRIMITIVE_VAR_DECLARATION:
-                    System.out.println("got the type, it's primitive");
                     type = p.getType();
                     break;
                 case CharjParser.OBJECT_VAR_DECLARATION:
-                    System.out.println("got the type, it's an object!");
                     type = p.getChild(0).getType();
                     break;
                 case CharjParser.FUNCTION_METHOD_DECL:
                 case CharjParser.BLOCK:
                 case CharjParser.FORMAL_PARAM_LIST:
-                    System.out.println("local var, not puping...");
                     return;
                 case CharjParser.TYPE:
-                    System.out.println("class member var, puping... type " + type);
                     switch(type)
                     {
-                        case CharjParser.REFERENCE_TYPE: System.out.println("found ref");
-                        case CharjParser.PRIMITIVE_VAR_DECLARATION: System.out.println("found simple or ref");
+                        case CharjParser.REFERENCE_TYPE:
+                            break;
+                        case CharjParser.PRIMITIVE_VAR_DECLARATION:
                             primitiveVarPup(idNode);
                             break;
-                        case CharjParser.POINTER_TYPE: System.out.println("found pointer");
+                        case CharjParser.POINTER_TYPE:
                             pointerVarPup(idNode);
                             break;
+                        case CharjParser.PROXY_TYPE:
+                            proxyVarPup(idNode);
+                            break;
                         default:
-                            System.out.println("unknown type -- THIS IS AN ERROR in method varPup, in PupRoutineCreator.java");
+                            System.out.println("PupRoutineCreator.varPup: unknown type " + idNode);
                             break;
                     }
                     return;
             }
         }
-        System.out.println("THIS IS AN ERROR in method varPup, in PupRoutineCreator.java");
+        System.out.println("PupRoutineCreator.varPup: could not pup variable " + idNode);
     }
 
     protected void primitiveVarPup(CharjAST idNode)
@@ -124,6 +123,12 @@ class PupRoutineCreator
         pupNode.getChild(4).getChild(index).getChild(0).addChild(createNode(CharjParser.IDENT, "p"));
         pupNode.getChild(4).getChild(index).getChild(0).addChild(idNode.dupNode());
     }
+
+    protected void proxyVarPup(CharjAST idNode)
+    {
+        // For now, just do a basic PUP. More complex handling may be needed later.
+        primitiveVarPup(idNode);
+    }
     
     private boolean generatedIf = false;