Added the this() explicit constructor invocation which is very similar to super(...
authorjjenista <jjenista>
Mon, 10 May 2010 22:22:17 +0000 (22:22 +0000)
committerjjenista <jjenista>
Mon, 10 May 2010 22:22:17 +0000 (22:22 +0000)
Robust/src/IR/Tree/BuildIR.java
Robust/src/Parse/java14.cup
Robust/src/Tests/explicitConstrInvok/makefile [new file with mode: 0644]
Robust/src/Tests/explicitConstrInvok/test.java [new file with mode: 0644]

index e9176923549279c3c4d800eebf261dd1c7b08f0c..d57a406850fb64a4459fd924f977d7c758debb19 100644 (file)
@@ -623,6 +623,17 @@ public class BuildIR {
       }
       BlockExpressionNode ben=new BlockExpressionNode(min);
       bn.addFirstBlockStatement(ben);
+
+    } else if (bodyn!=null&&bodyn.getChild("explconstrinv")!=null) {
+      ParseNode eci=bodyn.getChild("explconstrinv");
+      NameDescriptor nd=new NameDescriptor(cn.getSymbol());
+      Vector args=parseArgumentList(eci);
+      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 80c2f59304023bc2f9d66efbc64cde4318e3b5ea..dbe8dda0cd3d77f3cd638fc0d9d48cb73b1173f0 100644 (file)
@@ -1019,8 +1019,12 @@ constructor_body ::=
        |       LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
        ;
 explicit_constructor_invocation ::=
-//             THIS LPAREN argument_list_opt RPAREN SEMICOLON
-//     |       
+       THIS LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
+            ParseNode pn=new ParseNode("explconstrinv");
+            pn.addChild(alo);
+            RESULT=pn;
+       :}
+       |       
 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {: 
        ParseNode pn=new ParseNode("superinvoke");
        pn.addChild(alo);
diff --git a/Robust/src/Tests/explicitConstrInvok/makefile b/Robust/src/Tests/explicitConstrInvok/makefile
new file mode 100644 (file)
index 0000000..459733b
--- /dev/null
@@ -0,0 +1,32 @@
+PROGRAM=test
+
+SOURCE_FILES=$(PROGRAM).java
+
+BUILDSCRIPT=~/research/Robust/src/buildscript
+
+BSFLAGS= -mainclass Test 
+
+all: $(PROGRAM).bin
+
+view: PNGs
+       eog *.png &
+
+PNGs: DOTs
+       d2p *COMPLETE*.dot
+
+DOTs: $(PROGRAM).bin
+
+$(PROGRAM).bin: $(SOURCE_FILES)
+       $(BUILDSCRIPT) $(BSFLAGS) $(DEBUGFLAGS) -o $(PROGRAM) $(SOURCE_FILES)
+
+OLDBSFLAGS= -mainclass Test -justanalyze -ownership -ownallocdepth 1 -ownwritedots final -enable-assertions
+old: $(SOURCE_FILES)
+       $(BUILDSCRIPT) $(OLDBSFLAGS) $(SOURCE_FILES) -o $(PROGRAM)
+
+clean:
+       rm -f  $(PROGRAM).bin
+       rm -fr tmpbuilddirectory
+       rm -f  *~
+       rm -f  *.dot
+       rm -f  *.png
+       rm -f  aliases.txt
diff --git a/Robust/src/Tests/explicitConstrInvok/test.java b/Robust/src/Tests/explicitConstrInvok/test.java
new file mode 100644 (file)
index 0000000..62cd501
--- /dev/null
@@ -0,0 +1,29 @@
+public class Bar {
+  public Bar() {
+    System.out.println( "1. I'm the super" );
+  }
+}
+
+public class Foo extends Bar {
+
+  public Foo( int i ) {    
+    this();
+    System.out.println( "3. I see the number "+i );
+  }
+
+  public Foo() {
+    super();
+    System.out.println( "2. I see nothing" );
+  }
+
+  public Foo f;
+}
+
+
+public class Test {
+
+  static public void main( String[] args ) {
+    Foo f = new Foo( 7 );
+  }   
+
+}