Merge branch 'charm' of charmgit:charm into charm
authorAaron Becker <akbecker@gmail.com>
Fri, 29 Oct 2010 20:19:13 +0000 (15:19 -0500)
committerAaron Becker <akbecker@gmail.com>
Fri, 29 Oct 2010 20:19:13 +0000 (15:19 -0500)
src/langs/charj/build.xml
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/CharjASTModifier2.g
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/src/charj/translator/SymbolDefiner.g
src/langs/charj/src/charj/translator/SymbolResolver.g

index 3e49553dd7d65a2c349be88afd3c84a52c2257d8..e11481bfca6010f62fb01b230766c4f745648e78 100644 (file)
@@ -30,8 +30,9 @@
     <target name="compile"
         description="compile">
         <javac debug="true" srcdir="${buildsrc}" destdir="${classes}"
-               target="1.5" listfiles="Yes" deprecation="Yes">
-               <classpath refid="${classpath}"/>
+            target="1.5" listfiles="Yes" deprecation="Yes"
+            includeantruntime="false">
+            <classpath refid="${classpath}"/>
         </javac>
     </target>
 
index 9da829872543e5b1410889b6225d719c8555f18d..0b3bc40c4bc2868232be1ed34df37218e16e3355 100644 (file)
@@ -268,6 +268,7 @@ compilationUnit
 topLevelDeclaration
     :   importDeclaration
     |   readonlyDeclaration
+    |   externDeclaration
     |   typeDeclaration
     ;
 
@@ -284,6 +285,10 @@ readonlyDeclaration
     :   READONLY^ localVariableDeclaration ';'!
     ;
 
+externDeclaration
+    :   EXTERN^ qualifiedIdentifier ';'!
+    ;
+
 typeDeclaration
     :   classDefinition
     |   templateDeclaration
index c0c395feacb88328c22b767be75a6c92501690a4..fcc78d3d9f0448974a4b55480aaf047133b28807 100644 (file)
@@ -42,8 +42,9 @@ charjSource
     :   ^(CHARJ_SOURCE 
         packageDeclaration?
         importDeclaration*
-        readonlyDeclaration*
-        typeDeclaration*)
+        (externDeclaration
+        |readonlyDeclaration
+        |typeDeclaration)*)
     ;
 
 packageDeclaration
@@ -58,6 +59,10 @@ readonlyDeclaration
     :   ^(READONLY localVariableDeclaration)
     ;
 
+externDeclaration
+    :   ^(EXTERN qualifiedIdentifier)
+    ;
+
 typeOfType returns [boolean array_type]
     : CLASS 
     | chareType 
index 3eb4d8264b591b7eb0926ae3470aa49980b51517..a5b00e9f2206358b7d97694c05bb380ab72ed462 100644 (file)
@@ -65,6 +65,7 @@ charjSource[SymbolTable _symtab] returns [ClassSymbol cs]
         (packageDeclaration)? 
         (importDeclaration
         | typeDeclaration { $cs = $typeDeclaration.sym; }
+        | externDeclaration
         | readonlyDeclaration)*)
     ;
 
@@ -81,6 +82,10 @@ readonlyDeclaration
     :   ^(READONLY localVariableDeclaration)
     ;
 
+externDeclaration
+    :   ^(EXTERN qualifiedIdentifier)
+    ;
+
 typeDeclaration returns [ClassSymbol sym]
     :   ^(TYPE classType IDENT { currentClass = (ClassSymbol) $IDENT.def.type; }
             (^('extends' parent=type))? (^('implements' type+))?
index f491a118a08dcdb960b3fe7b383e5dbce6110cee..3c0a80f2672b92e789cd35dd0720cfbd7cc4c767 100644 (file)
@@ -84,9 +84,10 @@ charjSource[SymbolTable symtab, OutputMode m]
     this.mode_ = m;
 }
     :   ^(CHARJ_SOURCE (p=packageDeclaration)? 
-        (i+=importDeclaration)*
-        (r+=readonlyDeclaration)*
-        (t+=typeDeclaration)*)
+        ((i+=importDeclaration)
+        |(r+=readonlyDeclaration)
+        |externDeclaration
+        |(t+=typeDeclaration))*)
         -> {emitCC()}? charjSource_cc(basename={basename()}, pd={$p.names}, imports={$i}, types={$t}, ros={$r}, debug={debug()})
         -> {emitCI()}? charjSource_ci(basename={basename()}, pd={$p.names}, imports={$i}, types={$t}, ros={$r}, debug={debug()})
         -> {emitH()}? charjSource_h(basename={basename()}, pd={$p.names}, imports={$i}, types={$t}, ros={$r}, debug={debug()})
@@ -113,6 +114,11 @@ readonlyDeclaration
         -> {emitCC()}? {$lvd.st;}
         ->
     ;
+
+externDeclaration
+    :   ^(EXTERN qualifiedIdentifier)
+        ->
+    ;
     
 importDeclaration
 @init {
index bdc3da6ea33fb8ee15286c41d0376e2d14ed0793..a1d56b00145f7058e173eaf7478970470cdea3f8 100644 (file)
@@ -91,6 +91,7 @@ scope ScopeStack; // default scope
         (packageDeclaration)? 
         (importDeclaration
         | typeDeclaration { $cs = $typeDeclaration.sym; }
+        | externDeclaration
         | readonlyDeclaration)*)
     ;
 
@@ -122,6 +123,10 @@ readonlyDeclaration
     :   ^(READONLY localVariableDeclaration)
     ;
 
+externDeclaration
+    :   ^(EXTERN qualifiedIdentifier)
+    ;
+
 typeDeclaration returns [ClassSymbol sym]
 scope ScopeStack; // top-level type scope
     :   ^(TYPE classType IDENT
index 9d5b521c527df89540861d75e1a9980d24fd4736..509b16fa9b46e02bda9deabcd7ffc09038647882 100644 (file)
@@ -28,6 +28,7 @@ package charj.translator;
 
 topdown
     :   enterPackage
+    |   externDeclaration
     |   enterClass
     |   enterMethod
     |   enterBlock
@@ -59,6 +60,13 @@ enterPackage
         }
     ;
 
+externDeclaration
+    :   ^(EXTERN IDENT) {
+            ExternalSymbol sym = new ExternalSymbol(symtab, $IDENT.text);
+            currentScope.define(sym.name, sym);
+        }
+    ;
+
 enterBlock
     :   BLOCK {
             $BLOCK.scope = new LocalScope(symtab, currentScope);
index e799fa1da3de1e0265fa1c54326b2ac851b0693c..b761d794a9467db967501e1f6378aaf208196438 100644 (file)
@@ -218,7 +218,11 @@ primaryExpression returns [Type type]
                 $IDENT.symbolType = $type;
                 //System.out.println("Resolved type of " + $IDENT.text + ": " + $type + ", symbol is " + $IDENT.def);
             } else {
-                System.out.println("Couldn't resolve IDENT type: " + $IDENT.text);
+                if (!$IDENT.text.equals("thishandle") &&
+                        !$IDENT.text.equals("thisIndex") &&
+                        !$IDENT.text.equals("thisProxy")) {
+                    System.out.println("ERROR: Couldn't resolve IDENT type: " + $IDENT.text);
+                }
             }
         }
     |   THIS {
@@ -258,7 +262,7 @@ primaryExpression returns [Type type]
                 memberNode.symbolType = $type;
                 parentNode.def = s;
                 parentNode.symbolType = $type;
-            } else {
+            } else if (!(et instanceof ExternalSymbol)) {
                 System.out.println("Couldn't resolve access " + memberText);
             }
         }
@@ -366,14 +370,16 @@ type returns [Type sym]
 }
 @after {
     $start.symbolType = scope.resolveType(typeText);
-    //System.out.println("\ntype string: " + typeText);
-    //System.out.println("direct scope: " + scope);
-    //System.out.println("symbolType: " + $start.symbolType);
     if (proxy && $start.symbolType != null) $start.symbolType = new ProxyType(symtab, $start.symbolType);
     if (pointer && $start.symbolType != null) $start.symbolType = new PointerType(symtab, $start.symbolType);
        if (proxySection && $start.symbolType != null) $start.symbolType = new ProxySectionType(symtab, $start.symbolType);
     $sym = $start.symbolType;
-    if ($sym == null) System.out.println("Couldn't resolve type: " + typeText);
+    if ($sym == null) {
+        //System.out.println("type string: " + typeText);
+        //System.out.println("direct scope: " + scope);
+        //System.out.println("symbolType: " + $start.symbolType);
+        System.out.println("ERROR: Couldn't resolve type " + typeText);
+    }
 }
     :   VOID {
             scope = $VOID.scope;
@@ -386,17 +392,18 @@ type returns [Type sym]
     |   ^(OBJECT_TYPE { scope = $OBJECT_TYPE.scope; }
             ^(QUALIFIED_TYPE_IDENT (^(IDENT (^(TEMPLATE_INST
                 (t1=type {tparams.add($t1.sym);} | lit1=literalVal {tparams.add($lit1.type);} )*))?
-                {typeText.add(new TypeName($IDENT.text, tparams));}))+) .*)
+                {typeText.add(new TypeName($IDENT.text, tparams)); }))+) .*)
     |   ^(REFERENCE_TYPE { scope = $REFERENCE_TYPE.scope; }
-            ^(QUALIFIED_TYPE_IDENT (^(IDENT  {typeText.add(new TypeName($IDENT.text));} .*))+) .*)
+            ^(QUALIFIED_TYPE_IDENT (^(IDENT {typeText.add(new TypeName($IDENT.text));} .*))+) .*)
     |   ^(PROXY_TYPE { scope = $PROXY_TYPE.scope; proxy = true; }
             ^(QUALIFIED_TYPE_IDENT (^(IDENT {typeText.add(new TypeName($IDENT.text));} .*))+) .*)
        |       ^(ARRAY_SECTION_TYPE { scope = $ARRAY_SECTION_TYPE.scope; proxySection = true; }
                        ^(QUALIFIED_TYPE_IDENT (^(IDENT {typeText.add(new TypeName($IDENT.text));} .*))+) .*)
     |   ^(POINTER_TYPE { scope = $POINTER_TYPE.scope; pointer = true; }
             ^(QUALIFIED_TYPE_IDENT (^(IDENT (^(TEMPLATE_INST
-            (t1=type {tparams.add($t1.sym);} | lit1=literalVal {tparams.add($lit1.type);} )*))?
-            {typeText.add(new TypeName($IDENT.text, tparams));}))+) .*)
+                        (t1=type {tparams.add($t1.sym);}
+                        |lit1=literalVal {tparams.add($lit1.type);} )*))?)
+            {typeText.add(new TypeName($IDENT.text, tparams));})+) .*)
     ;
 
 classType