support a bit more java
authorbdemsky <bdemsky>
Sat, 3 Nov 2007 07:16:28 +0000 (07:16 +0000)
committerbdemsky <bdemsky>
Sat, 3 Nov 2007 07:16:28 +0000 (07:16 +0000)
Robust/src/IR/Tree/BlockNode.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeUtil.java
Robust/src/Parse/java14.cup

index 62b3b67df89df2533fce7e75ad7e9d2ffc2331d3..47ebb1f5245ff2b52771f7813202e209916928b7 100644 (file)
@@ -24,6 +24,10 @@ public class BlockNode extends TreeNode {
        blockstatements.add(bsn);
     }
 
+    public void addFirstBlockStatement(BlockStatementNode bsn) {
+       blockstatements.insertElementAt(bsn,0);
+    }
+
     public void setStyle(int style) {
        printStyle=style;
     }
index 08c113d2009640c4d4cc5f7de589ee4d6a8d2435..f307880df6b3081a8abb1e0d40cf4957a1e325ce 100644 (file)
@@ -540,7 +540,22 @@ public class BuildIR {
        ParseNode bodyn0=pn.getChild("body");
        ParseNode bodyn=bodyn0.getChild("constructor_body");
        cn.addMethod(md);
-       BlockNode bn=parseBlock(bodyn);
+       BlockNode bn=null;
+       if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
+           bn=parseBlock(bodyn);
+       else
+           bn=new BlockNode();
+       if (bodyn!=null&&bodyn.getChild("superinvoke")!=null) {
+           ParseNode sin=bodyn.getChild("superinvoke");
+           NameDescriptor nd=new NameDescriptor("super");
+           Vector args=parseArgumentList(sin);
+           MethodInvokeNode min=new MethodInvokeNode(nd);
+           for(int i=0;i<args.size();i++) {
+               min.addArgument((ExpressionNode)args.get(i));
+           }
+           BlockExpressionNode ben=new BlockExpressionNode(min);
+           bn.addFirstBlockStatement(ben);
+       }
        state.addTreeCode(md,bn);
     }
 
index 84e18d9b3da8cbe43bf81a974a382a923c0b8e3f..7680db3d7ab64a5757c69a0bb047260c53e472a3 100644 (file)
@@ -677,7 +677,10 @@ public class SemanticCheck {
            typetolookin=min.getExpression().getType();
        } else if (min.getBaseName()!=null) {
            String rootname=min.getBaseName().getRoot();
-           if (nametable.get(rootname)!=null) {
+           if (rootname.equals("super")) {
+               ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
+               typetolookin=new TypeDescriptor(supercd);
+           } else if (nametable.get(rootname)!=null) {
                //we have an expression
                min.setExpression(translateNameDescriptorintoExpression(min.getBaseName()));
                checkExpressionNode(md, nametable, min.getExpression(), null);
@@ -689,6 +692,10 @@ public class SemanticCheck {
                    throw new Error(min.getBaseName()+" undefined");
                typetolookin=new TypeDescriptor(cd);
            }
+       } else if ((md instanceof MethodDescriptor)&&min.getMethodName().equals("super")) {
+           ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
+           min.methodid=supercd.getSymbol();
+           typetolookin=new TypeDescriptor(supercd);
        } else if (md instanceof MethodDescriptor) {
            typetolookin=new TypeDescriptor(((MethodDescriptor)md).getClassDesc());
        } else {
index dae65785924414ee91e8a8b5d1cd89bd5f177b7e..9471925c8fdb7cc1ac7d25047e6797e79f208c51 100644 (file)
@@ -30,6 +30,9 @@ public class TypeUtil {
            String superc=cd.getSuper();
            if (superc!=null) {
                ClassDescriptor cd_super=getClass(superc);
+               if (cd_super==null) {
+                   throw new Error("Couldn't find class:"+superc);
+               }
                supertable.put(cd,cd_super);
            }
        }
index d071f337550d10eb570363c2cfd73e69730c35b2..92665a47c53a94a2ce3dd10dfaa16f7a12a03a6b 100644 (file)
@@ -152,7 +152,7 @@ non terminal ParseNode method_body;
 // 19.8.5) Constructor Declarations
 non terminal ParseNode constructor_declaration, constructor_declarator;
 non terminal ParseNode constructor_body;
-//non terminal ParseNode explicit_constructor_invocation;
+non terminal ParseNode explicit_constructor_invocation;
 // 19.9.1) Interface Declarations
 //non terminal ParseNode interface_declaration;
 //non terminal ParseNode extends_interfaces_opt, extends_interfaces;
@@ -983,8 +983,17 @@ constructor_declarator ::=
        :}
        ;
 constructor_body ::=
-//             LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE |
-//             LBRACE explicit_constructor_invocation RBRACE |
+               LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {: 
+                       ParseNode pn=new ParseNode("constructor_body");
+                       pn.addChild(eci);
+                       pn.addChild(bs);
+                       RESULT=pn;
+       :} |
+               LBRACE explicit_constructor_invocation:eci RBRACE {: 
+                       ParseNode pn=new ParseNode("constructor_body");
+                       pn.addChild(eci);
+                       RESULT=pn;
+       :} |
                LBRACE block_statements:block RBRACE {: 
                ParseNode pn=new ParseNode("constructor_body");
                pn.addChild(block);
@@ -992,12 +1001,17 @@ constructor_body ::=
        :}
        |       LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
        ;
-//explicit_constructor_invocation ::=
+explicit_constructor_invocation ::=
 //             THIS LPAREN argument_list_opt RPAREN SEMICOLON
-//     |       SUPER LPAREN argument_list_opt RPAREN SEMICOLON
+//     |       
+SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {: 
+       ParseNode pn=new ParseNode("superinvoke");
+       pn.addChild(alo);
+       RESULT=pn;
+:}
 //     |       primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
 //     |       primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
-//     ;
+       ;
 
 // 19.9) Interfaces
 
@@ -1530,7 +1544,15 @@ method_invocation ::=
                pn.addChild(args);
                RESULT=pn;
        :}
-//     |       SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
+       |       SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {: 
+               ParseNode name=new ParseNode("name");
+               name.addChild("base").addChild("name").addChild("identifier").addChild("super");
+               name.addChild("identifier").addChild(id);
+               ParseNode pn=new ParseNode("methodinvoke1");
+               pn.addChild(name);
+               pn.addChild(args);
+               RESULT=pn;
+       :}
 //     |       name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
        ;
 array_access ::=