blockstatements.add(bsn);
}
+ public void addFirstBlockStatement(BlockStatementNode bsn) {
+ blockstatements.insertElementAt(bsn,0);
+ }
+
public void setStyle(int style) {
printStyle=style;
}
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);
}
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);
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 {
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);
}
}
// 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;
:}
;
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);
:}
| 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
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 ::=