Charj: handling for reference types, scoping, and new/delete calls
authorAaron Becker <akbecker@gmail.com>
Tue, 25 May 2010 21:01:13 +0000 (16:01 -0500)
committerAaron Becker <akbecker@gmail.com>
Tue, 25 May 2010 21:01:13 +0000 (16:01 -0500)
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/Charj.stg
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g

index 7324fa3aa77d51b8283654f69738b70fd2bfaabf..8920b3df480078b0b890c3f28b6195d11284552a 100644 (file)
@@ -454,6 +454,8 @@ statement
         ->  ^('continue' IDENT?)
     |   IDENT ':' statement
         ->  ^(LABELED_STATEMENT IDENT statement)
+    |   'delete' qualifiedIdentifier ';'
+        -> ^('delete' qualifiedIdentifier)
     |   'embed' STRING_LITERAL EMBED_BLOCK
         ->  ^('embed' STRING_LITERAL EMBED_BLOCK)
     |   expression ';'!
@@ -708,6 +710,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)
         )
     ;
     
index 57a13c7b89e7d95e763737c558d0ac657dec48e3..51cdf6320c2f196cd0ed0ad29d0d658fec70fa58 100644 (file)
@@ -295,6 +295,12 @@ type(typeID, arrDeclList) ::=
 >>
 
 
+obj_type(typeID, arrDeclList) ::=
+<<
+<typeID>*<arrDeclList>
+>>
+
+
 typeIdent(typeID, generics) ::=
 <<
 <typeID><generics>
index 25914bcc1856f6d25ca1ee2a2226f57064bf9b6c..012d6bb3cff08c4a58b55c89f4ff7fc7205e2b33 100644 (file)
@@ -199,7 +199,7 @@ classScopeDeclaration
         -> {emitCC()}? funcMethodDecl_cc(
                 modl={modList}, 
                 gtpl={$g.st}, 
-                ty={$ty.text},
+                ty={$ty.st},
                 id={$IDENT.text}, 
                 fpl={$f.st}, 
                 adl={$a.st},
@@ -207,7 +207,7 @@ classScopeDeclaration
         -> {emitH()}? funcMethodDecl_h(
                 modl={modList}, 
                 gtpl={$g.st}, 
-                ty={$ty.text},
+                ty={$ty.st},
                 id={$IDENT.text}, 
                 fpl={$f.st}, 
                 adl={$a.st},
@@ -215,7 +215,7 @@ classScopeDeclaration
         -> {(emitCI() && entry)}? funcMethodDecl_ci(
                 modl={$m.st}, 
                 gtpl={$g.st}, 
-                ty={$ty.text},
+                ty={$ty.st},
                 id={$IDENT.text}, 
                 fpl={$f.st}, 
                 adl={$a.st},
@@ -367,6 +367,7 @@ type
     |   objectType 
         -> {$objectType.st}
     |   'void'
+        -> {$st = %{$start.getText()};}
     ;
 
 simpleType
@@ -376,12 +377,12 @@ simpleType
 
 objectType
     :   ^(TYPE qualifiedTypeIdent arrayDeclaratorList?)
-        -> type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
+        -> obj_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
     ;
 
 qualifiedTypeIdent
     :   ^(QUALIFIED_TYPE_IDENT (t+=typeIdent)+) 
-        -> template(types={$t}) "<types; separator=\".\">"
+        -> template(types={$t}) "<types; separator=\"::\">"
     ;
 
 typeIdent
@@ -499,6 +500,8 @@ statement
         -> label(text={$i.text}, stmt={$s.st})
     |   expression
         -> template(expr={$expression.st}) "<expr>;"
+    |   ^('delete' qualifiedIdentifier)
+        -> template(t={$qualifiedIdentifier.st}) "delete <t>;"
     |   ^('embed' STRING_LITERAL EMBED_BLOCK)
         ->  embed_cc(str={$STRING_LITERAL.text}, blk={$EMBED_BLOCK.text})
     |   ';' // Empty statement.
@@ -619,14 +622,14 @@ expr
     |   primaryExpression
         -> {$primaryExpression.st}
     ;
-    
+
 primaryExpression
-    :   ^('.' prim=primaryExpression IDENT)
-        -> template(id={$IDENT}, prim={$prim.st}) "<prim>.<id>"
-    |   ^('.' prim=primaryExpression 'this')
-        -> template(prim={$prim.st}) "<prim>.this"
-    |   ^('.' prim=primaryExpression 'super')
-        -> template(prim={$prim.st}) "<prim>.super"
+    :   ^('.' prim=primaryExpression
+            ( IDENT     -> template(id={$IDENT}, prim={$prim.st}) "<prim>-><id>"
+            | 'this'    -> template(prim={$prim.st}) "<prim>->this"
+            | 'super'   -> template(prim={$prim.st}) "<prim>->super"
+            )
+        )
     |   parenthesizedExpression
         -> {$parenthesizedExpression.st}
     |   IDENT
@@ -668,6 +671,8 @@ newExpression
             )
         )
         -> template(t={$text}) "<t>"
+    |   ^('new' qualifiedTypeIdent arguments)
+        -> template(q={$qualifiedTypeIdent.st}, a={$arguments.st}) "new <q>(<a>)"
     ;
 
 newArrayConstruction
index b826afd98c6165ec650fe12870689e7d45f2f11c..c1545a9cd230775c1430790a16f518c4e7c411f1 100644 (file)
@@ -347,6 +347,7 @@ statement
         }
     |   ^(LABELED_STATEMENT IDENT statement)
     |   expression
+    |   ^('delete' qualifiedIdentifier)
     |   ^('embed' STRING_LITERAL EMBED_BLOCK)
     |   ';' // Empty statement.
     ;
@@ -451,6 +452,7 @@ newExpression
             |   genericTypeArgumentList? qualifiedTypeIdent newArrayConstruction
             )
         )
+    |   ^('new' qualifiedTypeIdent arguments)
     ;
 
 newArrayConstruction