commit 64c652da711539d5d86ed48099d754a4529eb0e3 Author: JanUlrich Date: Fri Oct 18 13:33:46 2013 +0200 Java und jav files diff --git a/bin/mycompiler/test/blocks/TestForStmt.jav b/bin/mycompiler/test/blocks/TestForStmt.jav new file mode 100755 index 000000000..a12ba6c8e --- /dev/null +++ b/bin/mycompiler/test/blocks/TestForStmt.jav @@ -0,0 +1,32 @@ + +public class TestForStmt { + + public void m1() { + + i; + for (i=0;i<5;i++) { + + } + } + + public void m2() { + i; + for (i=0;i<5;i++) { + j; + j="abc"; + } + j; + j=3; + } + + public m3() { + i; + for (i=0;i<5;i++) { + j; + for (j=0;j<5;j++) { + return i==j; + } + } + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/blocks/TestIfStmt.jav b/bin/mycompiler/test/blocks/TestIfStmt.jav new file mode 100755 index 000000000..a59a4c0f8 --- /dev/null +++ b/bin/mycompiler/test/blocks/TestIfStmt.jav @@ -0,0 +1,27 @@ +import java.util.Vector; + +public class TestIfStmt { + + public m1() { + a; + if (a) { + return a; + } + else + return false; + } + + public m2() { + a; + c; + a = new Vector(); + if (a.isEmpty()) { + c="empty"; + } + else if (a.size()==1) { + c="almost empty"; + } + else + return a; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/blocks/TestInferenceAcrossBlocks.jav b/bin/mycompiler/test/blocks/TestInferenceAcrossBlocks.jav new file mode 100755 index 000000000..508f0aaff --- /dev/null +++ b/bin/mycompiler/test/blocks/TestInferenceAcrossBlocks.jav @@ -0,0 +1,12 @@ +public class TestInferenceAcrossBlocks{ + + public m(a){ + if(a==true){ + return 3; + } + else { + x; + return x; + } + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/blocks/TestSimpleBlocks.jav b/bin/mycompiler/test/blocks/TestSimpleBlocks.jav new file mode 100755 index 000000000..25d97b971 --- /dev/null +++ b/bin/mycompiler/test/blocks/TestSimpleBlocks.jav @@ -0,0 +1,18 @@ +public class TestSimpleBlocks{ + + public m(a){ + { + d; + d = 'a'; + { + c; + c = d; + } + { + c; + c = d==a; + } + } + return a; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/blocks/TestSimpleVariable.jav b/bin/mycompiler/test/blocks/TestSimpleVariable.jav new file mode 100755 index 000000000..b3d3ba248 --- /dev/null +++ b/bin/mycompiler/test/blocks/TestSimpleVariable.jav @@ -0,0 +1,7 @@ +public class TestSimpleVariable { + + public m() { + c; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/blocks/TestSwitchStmt.jav b/bin/mycompiler/test/blocks/TestSwitchStmt.jav new file mode 100755 index 000000000..1b9f689bc --- /dev/null +++ b/bin/mycompiler/test/blocks/TestSwitchStmt.jav @@ -0,0 +1,11 @@ +public class TestSwitchStmt { + + public m(a) { + switch (a) { + case 1: return a++; break; + case 2: return a--; break; + default: return a; + } + + +} \ No newline at end of file diff --git a/bin/mycompiler/test/blocks/TestTryCatchBlock.jav b/bin/mycompiler/test/blocks/TestTryCatchBlock.jav new file mode 100755 index 000000000..59951045a --- /dev/null +++ b/bin/mycompiler/test/blocks/TestTryCatchBlock.jav @@ -0,0 +1,14 @@ +public class TestTryCatchBlock { + + public m() { + + try { + return new TestTryCatchBlock(); + } + catch (e) { + return null; + } + + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/blocks/TestUndeterminedReturnNegative.jav b/bin/mycompiler/test/blocks/TestUndeterminedReturnNegative.jav new file mode 100755 index 000000000..166cd9739 --- /dev/null +++ b/bin/mycompiler/test/blocks/TestUndeterminedReturnNegative.jav @@ -0,0 +1,12 @@ + +public class TestUndeterminedReturnNegative { + + public m1(a) { + if (a) { + a=false; + } + else + return false; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/blocks/TestUninitializedVariable.jav b/bin/mycompiler/test/blocks/TestUninitializedVariable.jav new file mode 100755 index 000000000..793bbbe8c --- /dev/null +++ b/bin/mycompiler/test/blocks/TestUninitializedVariable.jav @@ -0,0 +1,11 @@ +public class TestUninitializedVariable { + + public void m1() { + a; + a++; + } + + void m2(T a) { + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/blocks/TestWhileStmt.jav b/bin/mycompiler/test/blocks/TestWhileStmt.jav new file mode 100755 index 000000000..1debca80b --- /dev/null +++ b/bin/mycompiler/test/blocks/TestWhileStmt.jav @@ -0,0 +1,9 @@ +public class TestWhileStmt { + + public m1() { + i; + while (true) + i++; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/complexTypes/TestOwnClassMember.jav b/bin/mycompiler/test/complexTypes/TestOwnClassMember.jav new file mode 100755 index 000000000..fa73127e8 --- /dev/null +++ b/bin/mycompiler/test/complexTypes/TestOwnClassMember.jav @@ -0,0 +1,9 @@ +public class TestOwnClassMember { + + Integer a; + + public void m1(b) { + b += a; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/complexTypes/TestOwnClassMethod.jav b/bin/mycompiler/test/complexTypes/TestOwnClassMethod.jav new file mode 100755 index 000000000..e3d2a9255 --- /dev/null +++ b/bin/mycompiler/test/complexTypes/TestOwnClassMethod.jav @@ -0,0 +1,12 @@ +public class TestOwnClassMethod { + + Integer a; + + public void m1(b) { + a += b; + } + + public void m2(c, d) { + c.m1(d); + } + } \ No newline at end of file diff --git a/bin/mycompiler/test/complexTypes/TestStandardLibInheritanceInference.jav b/bin/mycompiler/test/complexTypes/TestStandardLibInheritanceInference.jav new file mode 100755 index 000000000..deafc13a6 --- /dev/null +++ b/bin/mycompiler/test/complexTypes/TestStandardLibInheritanceInference.jav @@ -0,0 +1,12 @@ +import java.io.OutputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.BufferedOutputStream; +import java.sql.Connection; + + +class TestStandardLibInheritanceInference{ + foo(x){ + x.close(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/complexTypes/TestStandardLibMember.jav b/bin/mycompiler/test/complexTypes/TestStandardLibMember.jav new file mode 100755 index 000000000..c54b0b142 --- /dev/null +++ b/bin/mycompiler/test/complexTypes/TestStandardLibMember.jav @@ -0,0 +1,11 @@ +import java.lang.System; +import java.io.PrintStream; + +public class TestStandardLibMember { + + public m1() { + a; + a=System.out; + a.println(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/complexTypes/TestStandardLibMethod.jav b/bin/mycompiler/test/complexTypes/TestStandardLibMethod.jav new file mode 100755 index 000000000..aef62902f --- /dev/null +++ b/bin/mycompiler/test/complexTypes/TestStandardLibMethod.jav @@ -0,0 +1,20 @@ +import java.util.HashMap; +import java.util.Vector; + +public class TestStandardLibMethod { + + public m1() { + a; + a = new HashMap(); + a.put("2",-1); + } + + public m2(Vector> m){ + k; + k = 0; + ret; + ret = m.elementAt(k).elementAt(k).intValue(); + return ret; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestAssignmentTwoGenericTypesNegative.jav b/bin/mycompiler/test/generics/TestAssignmentTwoGenericTypesNegative.jav new file mode 100755 index 000000000..160126b58 --- /dev/null +++ b/bin/mycompiler/test/generics/TestAssignmentTwoGenericTypesNegative.jav @@ -0,0 +1,12 @@ +import java.util.ArrayList; + +public class TestAssignmentTwoGenericTypesNegative { + + public void m() { + + ArrayList ls; + ls = new ArrayList(); + ArrayList lo; + lo = ls; /*<-- compile error*/ + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestClassesWithBoundedGenericsOfTwoTypes.jav b/bin/mycompiler/test/generics/TestClassesWithBoundedGenericsOfTwoTypes.jav new file mode 100755 index 000000000..aec3e2351 --- /dev/null +++ b/bin/mycompiler/test/generics/TestClassesWithBoundedGenericsOfTwoTypes.jav @@ -0,0 +1,17 @@ +interface I1 {} + +interface I2 {} + +class Implementation implements I1 {} + +class Implementation2 implements I2 {} + +class A {} + +class B{} + +class C{} + +class D{} + +class E{} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestClassesWithBoundedGenericsUsedInMethods.jav b/bin/mycompiler/test/generics/TestClassesWithBoundedGenericsUsedInMethods.jav new file mode 100755 index 000000000..b5a53fc73 --- /dev/null +++ b/bin/mycompiler/test/generics/TestClassesWithBoundedGenericsUsedInMethods.jav @@ -0,0 +1,21 @@ +interface I1 { + public m1(); +} + +class Implementation implements I1 { + public m1() { + } +} + +class TestClassesWithBoundedGenericsUsedInMethods { + + /*since S is at least of Type I1, call m1() should work*/ + public void m3 (S x) { + x.m1(); + } + + /*T is bounded by class generics, thus always at least of type I1*/ + public m2(T x) { + x.m1(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestExtendedClassesWithBoundedGenerics.jav b/bin/mycompiler/test/generics/TestExtendedClassesWithBoundedGenerics.jav new file mode 100755 index 000000000..9e98bb177 --- /dev/null +++ b/bin/mycompiler/test/generics/TestExtendedClassesWithBoundedGenerics.jav @@ -0,0 +1,34 @@ +interface I1 { + public m1(); +} + +interface I2 { + public m2(); +} + +class Implementation implements I1, I2 { + public m1() {} + + public m2() {} +} + +class Tester { + + public m3(T x) { + x.m1(); + x.m2(); + } +} + +public class TestExtendedClassesWithBoundedGenerics { + + public m() { + x; + /*can only be of Type Implementation*/ + x= new Implementation(); + y; + /*could be of Type: Tester, Tester*/ + y= new Tester(); + y.m3(x); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestNestedGenerics.jav b/bin/mycompiler/test/generics/TestNestedGenerics.jav new file mode 100755 index 000000000..1b34d70c4 --- /dev/null +++ b/bin/mycompiler/test/generics/TestNestedGenerics.jav @@ -0,0 +1,14 @@ +class A{ + +} + +public class TestNestedGenerics{ + ,C> void foo(T a,C b){} + + void m(){ + TestNestedGenerics t = new TestNestedGenerics(); + String str = new String(); + A a = new A(); + t.foo(a,str); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestNestedGenericsNonExistingType.jav b/bin/mycompiler/test/generics/TestNestedGenericsNonExistingType.jav new file mode 100755 index 000000000..428cdda4c --- /dev/null +++ b/bin/mycompiler/test/generics/TestNestedGenericsNonExistingType.jav @@ -0,0 +1,6 @@ + +public class TestNestedGenerics{ + + ,C> void foo(T a,C b){} + +} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestSimpleClassesWithBoundedGenerics.jav b/bin/mycompiler/test/generics/TestSimpleClassesWithBoundedGenerics.jav new file mode 100755 index 000000000..622a50079 --- /dev/null +++ b/bin/mycompiler/test/generics/TestSimpleClassesWithBoundedGenerics.jav @@ -0,0 +1,30 @@ +import java.util.Vector; +import java.util.HashMap; + +public class TestSimpleClassesWithBoundedGenerics { + + public ma(T x) { + return x; + } +} + +class A { + + public m1() { + x; + x= new TestSimpleClassesWithBoundedGenerics(); + return x.ma(3); + } + + public m2() { + x; + x = new TestSimpleClassesWithBoundedGenerics(); + } +/* + public m2() { + x; + x= new TestSimpleClassesWithBoundedGenerics(); + return x.m(new Double(3.)); + } +*/ +} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestSimpleClassesWithBoundedGenericsNegative.jav b/bin/mycompiler/test/generics/TestSimpleClassesWithBoundedGenericsNegative.jav new file mode 100755 index 000000000..19ef124c3 --- /dev/null +++ b/bin/mycompiler/test/generics/TestSimpleClassesWithBoundedGenericsNegative.jav @@ -0,0 +1,17 @@ + +public class TestSimpleClassesWithBoundedGenericsNegative { + + public m(T x) { + return x; + } + +} + +class A { + public m1() { + x; + x = new TestSimpleClassesWithBoundedGenericsNegative(); + return x.m("abc"); + + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestSimpleClassesWithGenerics.jav b/bin/mycompiler/test/generics/TestSimpleClassesWithGenerics.jav new file mode 100755 index 000000000..359b9a522 --- /dev/null +++ b/bin/mycompiler/test/generics/TestSimpleClassesWithGenerics.jav @@ -0,0 +1,17 @@ +public class TestSimpleClassesWithGenerics { + + public m(T x) { + return x; + } + +} + +class A { + + public method() { + x; + x= new TestSimpleClassesWithGenerics(); + return x.m(3); + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/generics/TestSimpleClassesWithGenericsNegative.jav b/bin/mycompiler/test/generics/TestSimpleClassesWithGenericsNegative.jav new file mode 100755 index 000000000..938ea5044 --- /dev/null +++ b/bin/mycompiler/test/generics/TestSimpleClassesWithGenericsNegative.jav @@ -0,0 +1,17 @@ +public class TestSimpleClassesWithGenericsNegative { + + public m(T x) { + return x; + } + +} + +class A { + + public method() { + x; + x= new TestSimpleClassesWithGenerics(); + return x.m("abc"); + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMember.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMember.jav new file mode 100755 index 000000000..d6b39b878 --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMember.jav @@ -0,0 +1,16 @@ +public class TestInferenceOwnTypeByMember { + + Float a; + + public void m1(b) { + a += b; + } + + public void m2(a) { + this.a=a; + } + + public m3() { + return a; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMemberAcrossClasses.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMemberAcrossClasses.jav new file mode 100755 index 000000000..c595b224b --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMemberAcrossClasses.jav @@ -0,0 +1,14 @@ +class A { + + public Character c; + +} + +public class TestInferenceOwnTypeByMemberAcrossClasses { + + public m1(a) { + x; + x = new A(); + a=x.c; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.jav new file mode 100755 index 000000000..fc3ca3d2e --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.jav @@ -0,0 +1,32 @@ +public class TestInferenceOwnTypeByMethodCall{ + + public m1(a) { + return a; + } + + public Integer m2(a) { + return a; + } + + public m3(a) { + return a; + } + + + + public void m01(d) { + e; + e=m1(d); + } + + public void m02(d) { + e; + e=m2(d); + } + + public void m03(c,Character d) { + e; + e=c.m3(d); + } + + } \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCallAcrossClasses.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCallAcrossClasses.jav new file mode 100755 index 000000000..4bb4bcce8 --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCallAcrossClasses.jav @@ -0,0 +1,18 @@ +class A{ + public mA(x){ + return(x); + } +} + +class TestInferenceOwnTypeByMethodCallAcrossClasses{ + + public m(Integer a, String b){ + x; + x=new A(); + c; + c=x.mA(a); + d; + d=x.mA(b); + + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodParameter.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodParameter.jav new file mode 100755 index 000000000..0970988fc --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodParameter.jav @@ -0,0 +1,19 @@ +class A { + static void m() {} +} + +public class TestInferenceOwnTypeByMethodParameter { + + m1(a,b) { + return a+b; + } + + m2(java.lang.String a) { + return a; + } + + m3(a) { + return a.m(); + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodReturnTypeMixed1.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodReturnTypeMixed1.jav new file mode 100755 index 000000000..b6e341d3f --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodReturnTypeMixed1.jav @@ -0,0 +1,20 @@ +class A1{ + void foo(java.lang.String x){} +} +class A2{ + void foo(java.lang.Integer y){} +} +class B1{ + java.lang.String bar(){return("");} +} +class B2{ + java.lang.Integer bar(){return(1);} +} +public class TestInferenceOwnTypeByMethodReturnTypeMixed1{ + method1(a,b){ + a.foo(b.bar()); + } + method2(a,B2 b) { + a.foo(b.bar()); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnType.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnType.jav new file mode 100755 index 000000000..559fde50a --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnType.jav @@ -0,0 +1,18 @@ +public class TestInferenceOwnTypeByReturnType { + + public java.lang.Integer m1(a) { + return a; + } + + public String m2() { + return "abc"; + } + + public void m3(a) { + a=m2(); + } + + public java.lang.Integer m4(a,b) { + return a+b; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnTypeAcrossClasses.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnTypeAcrossClasses.jav new file mode 100755 index 000000000..243df6d9a --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnTypeAcrossClasses.jav @@ -0,0 +1,23 @@ +class A{ + public String m() { + return "abc"; + } +} + +class B{ + public Integer m() { + return 1; + } +} + +public class TestInferenceOwnTypeByReturnTypeAcrossClasses { + + public main1(java.lang.Integer i, x){ + i=x.m(); + } + + public main2(i,x) { + i=x.m(); + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByMember.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByMember.jav new file mode 100755 index 000000000..a2c370f4b --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByMember.jav @@ -0,0 +1,9 @@ +import java.lang.System; + +public class TestInferenceStdTypeByMember { + + public m1(a) { + a=System.out; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByOperation.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByOperation.jav new file mode 100755 index 000000000..955a14783 --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByOperation.jav @@ -0,0 +1,13 @@ +import java.util.HashMap; +import java.lang.Object; + +public class TestInferenceStdTypeByOperation { + + public m1(a) { + a.put("1","1"); + } + + public m2(b) { + b.toString(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByReturnType.jav b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByReturnType.jav new file mode 100755 index 000000000..9317cd986 --- /dev/null +++ b/bin/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByReturnType.jav @@ -0,0 +1,18 @@ +import java.util.Vector; +import java.util.ArrayList; + +public class TestInferenceStdTypeByReturnType { + + public void m1(a) { + b; + b= new Vector(); + a = b.size(); + } + + public void m2(a) { + b; + b= new ArrayList(); + a = b.get(0); + + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceAcrossLevel.jav b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceAcrossLevel.jav new file mode 100755 index 000000000..053275681 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceAcrossLevel.jav @@ -0,0 +1,56 @@ +/* + A + B C +D E + +*/ + +class A { + fooA() {} +} + +class B extends A { + fooB() {} +} + +class C extends A { + fooC(){} +} + +class D extends B { + fooD() {} +} + +class E extends B { + fooE() {} +} + + + +public class TestInheritanceAcrossLevel { + + public m1(x) { + x.fooA(); + return x; + } + + public m2(x) { + x.fooB(); + /*return x;*/ + } + + public m3(x) { + x.fooC(); + /*return x;*/ + } + + public m4(x) { + x.fooD(); + /*return x;*/ + } + + public m5(B x) { + x.fooA(); + return x; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceCircle.jav b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceCircle.jav new file mode 100755 index 000000000..354e09f54 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceCircle.jav @@ -0,0 +1,41 @@ +/* + + A + B C + D +*/ + +interface A{ + fooA(); +} + +interface B extends A{ + fooB(); +} + +interface C extends A{} + +class D implements B,C { + fooA() { + } + fooB() { + } +} + +public class TestInheritanceCircle{ + + public m1(x) { + x.fooA(); + /*return x;*/ + } + + public m2(x) { + x.fooB(); + /*return x;*/ + } + public m3(D x) { + x.fooA(); + return x; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceConstructor.jav b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceConstructor.jav new file mode 100755 index 000000000..11073ccf8 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceConstructor.jav @@ -0,0 +1,27 @@ +class A { + public Integer memberInteger; + + public A(i) { + member=i; + } + +} + +class B extends A { + public String memberString; + public B(i,s) { + super(i); + memberString=s; + } +} + +public class TestInheritanceConstructor { + + public static main() { + x; + x=new B(3,"abc"); + y; + y=x.memberInteger; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultiple.jav b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultiple.jav new file mode 100755 index 000000000..63b6a1998 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultiple.jav @@ -0,0 +1,22 @@ +interface A{ +} +interface B{} + +class Tester implements A,B{ + m(){ + } +} + +public class TestInheritanceMultiple{ + + /*should return either of Type Intf1, Intf2, or Tester*/ + public m1(x){ + x.m(); + return(x); + } + + public m2(Tester x){ + x.m(); + return x; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultipleClasses.jav b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultipleClasses.jav new file mode 100755 index 000000000..70241b36f --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultipleClasses.jav @@ -0,0 +1,8 @@ + +class A {} + +class B {} + +public class TestInheritanceMultipleClasses extends A, B { + +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceOverriding.jav b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceOverriding.jav new file mode 100755 index 000000000..7690516b3 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceOverriding.jav @@ -0,0 +1,27 @@ +class A{ + public m() { + return new A(); + } +} + +class B extends A{ + + public m() { + return new B(); + } + public m(java.lang.Integer a) { + return a; + } +} + +public class TestInheritanceOverriding { + + public main1(x,A y) { + y = new B(); + x = y.m(); + } + /*public main2(x) { + y; + y=x.m(2); + }*/ +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceTwoHierarchies.jav b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceTwoHierarchies.jav new file mode 100755 index 000000000..df2f7dca8 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/inheritance/TestInheritanceTwoHierarchies.jav @@ -0,0 +1,37 @@ + +/* + + A I + B C D +E F + +*/ +interface I{ + void fooA(); +} +class A{ + void fooA() {} +} +class B extends A{} + +class C extends A implements I{} + +class D implements I{ + fooD() {} +} +class E extends B {} + +class F extends C{} + +public class TestInheritanceTwoHierarchies { + + public m1(x) { + x.fooA(); + return x; + } + + public m2(x) { + x.fooD(); + return x; + } +} diff --git a/bin/mycompiler/test/javaConcepts/inheritance/TestSimpleInheritance.jav b/bin/mycompiler/test/javaConcepts/inheritance/TestSimpleInheritance.jav new file mode 100755 index 000000000..3a0c0639c --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/inheritance/TestSimpleInheritance.jav @@ -0,0 +1,13 @@ + +class A { + + public m1() { + } +} + +public class TestSimpleInheritance extends A { + + public m(x) { + x.m1(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParameters.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParameters.jav new file mode 100755 index 000000000..27139295d --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParameters.jav @@ -0,0 +1,6 @@ +class OverloadingDifferentNumberOfParameters{ + void foo(){} + void foo(Integer a){} + void foo(Integer a, Double b){} + void foo(Integer a, Double b, Long c){} +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParametersAndDifferentTypes.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParametersAndDifferentTypes.jav new file mode 100755 index 000000000..5cc96afcc --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParametersAndDifferentTypes.jav @@ -0,0 +1,9 @@ +class OverloadingDifferentNumberOfParametersAndDifferentTypes{ + void foo(){} + void foo(Integer a){} + void foo(Integer a, Double b){} + void foo(Integer a, Double b, Long c){} + void foo(String a){} + void foo(String a, Integer b){} + void foo(String a, Integer b, Long c){} +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericNotSameHierarchy.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericNotSameHierarchy.jav new file mode 100755 index 000000000..cc8b080f1 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericNotSameHierarchy.jav @@ -0,0 +1,13 @@ +/* +Diese Klasse ueberlaed eine Methoden bei total Typverschiedenen generischen parametern (nicht gleiche Vererbungshierarchie +*/ +class OverloadingGenericNotSameHierarchy{ + + void foo(){} + void foo(T n){} + void foo(T v){} + +/* + void foo(T n){} + */ +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericSameHierarchy.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericSameHierarchy.jav new file mode 100755 index 000000000..7db406522 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericSameHierarchy.jav @@ -0,0 +1,8 @@ +/* +Diese Klasse ueberlaedt eine Methoden bei verschiedenen generischen Typen von Parametern welche in der gleichen Vererbungshierarchie liegen*/ + +class OverloadingGenericSameHierarchy { + void foo(T o){} + void foo(T n){} + void foo(T i){} +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceNotSameHierarchy.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceNotSameHierarchy.jav new file mode 100755 index 000000000..cc0ff01ab --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceNotSameHierarchy.jav @@ -0,0 +1,19 @@ +/* +Diese Klasse ueberlaedt eine Methode durch Typinferenz erkannte generische typverschiedenen Tarametern (nicht gleiche Vererbungshierarchie) +*/ + +import java.util.Vector; + +class A { + +} + +class OverloadingGenericTypeInferenceNotSameHierarchy{ + foo(){} + foo(i){ + i = new A(); + } + foo(s){ + s = new Vector(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceSameHierarchy.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceSameHierarchy.jav new file mode 100755 index 000000000..e4af92395 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceSameHierarchy.jav @@ -0,0 +1,20 @@ +/* +Diese Klasse ueberlaedt eine Methoden durch typeinferenz erkannte generische Typverschiedenen parametern welche in der selben Typhierarchie sind*/ +class B{ +} +class C extends B{ +} +class D extends C{ +} +class OverloadingGenericTypeInferenceSameHierarchy{ + foo(i){ + i = new B(); + } + foo(n){ + n = new C(); + } + + foo(o){ + o = new D(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingNotSameHierarchy.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingNotSameHierarchy.jav new file mode 100755 index 000000000..2b2e635e0 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingNotSameHierarchy.jav @@ -0,0 +1,8 @@ +/* +Diese Klasse ueberlaed eine Methoden bei total Typverschiedenen parametern (nicht gleiche Vererbungshierarchie +*/ +class OverloadingNotSameHierarchy{ + void foo(){} + void foo(String s){} + void foo(Integer i){} +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameHierarchy.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameHierarchy.jav new file mode 100755 index 000000000..d622462f3 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameHierarchy.jav @@ -0,0 +1,7 @@ +/* +Diese Klasse ueberlaedt eine Methoden bei verschiedenen Typen von Parametern welche in der gleichen Vererbungshierarchie liegen*/ +class OverloadingSameHierarchy{ + void foo(java.lang.Number n){} + void foo(java.lang.Integer i){} + void foo(java.lang.Object o){} +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameSignature.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameSignature.jav new file mode 100755 index 000000000..ff58ff0a7 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameSignature.jav @@ -0,0 +1,6 @@ +class OverloadingSameSignature{ + void foo(){ + } + void foo(){ + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureDifferentReturnTypes.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureDifferentReturnTypes.jav new file mode 100755 index 000000000..2668cd06e --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureDifferentReturnTypes.jav @@ -0,0 +1,7 @@ +class OverloadingSameSignatureDifferentReturnTypes{ + void foo(){ + } + String foo(){ + return "abcd"; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureGenerics.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureGenerics.jav new file mode 100755 index 000000000..de6ebda2d --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureGenerics.jav @@ -0,0 +1,8 @@ +class OverloadingSameSignatureGenerics{ + T foo(T a){ + return a; + } + void foo(T a){ + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceNotSameHierarchy.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceNotSameHierarchy.jav new file mode 100755 index 000000000..317fc85c1 --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceNotSameHierarchy.jav @@ -0,0 +1,12 @@ +/* +Diese Klasse ueberlaed eine Methoden durch typeinferenz erkannte Typverschiedenen parametern (nicht gleiche Vererbungshierarchie +*/ +class OverloadingTypeInferenceNotSameHierarchy{ + foo(){} + foo(i){ + i = new java.lang.Integer(); + } + foo(s){ + s = "String"; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceSameHierarchy.jav b/bin/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceSameHierarchy.jav new file mode 100755 index 000000000..dc83554cb --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceSameHierarchy.jav @@ -0,0 +1,16 @@ +/* +Diese Klasse ueberlaed eine Methoden durch typeinferenz erkannte Typverschiedenen parametern welche in der selben Typhierarchie sind*/ +class OverloadingTypeInferenceSameHierarchy{ + /*i = Integer*/ + foo(i){ + i = new java.lang.Integer(); + } + /*n = Number*/ + foo(n){ + n = new java.lang.Number(); + } + /*o = Object*/ + foo(o){ + o = new java.lang.Object(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/staticAccess/TestNonStaticAccess.jav b/bin/mycompiler/test/javaConcepts/staticAccess/TestNonStaticAccess.jav new file mode 100755 index 000000000..717d5ed3b --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/staticAccess/TestNonStaticAccess.jav @@ -0,0 +1,19 @@ +public class Access{ + + public String nonStaticMember="abc"; + + public nonStaticMethod() { + return "def"; + } + +} + +class TestNonStaticAccess { + + public method1(a,b) { + x; + x = new Access(); + a=x.nonStaticMember; + b=x.nonStaticMethod(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/javaConcepts/staticAccess/TestStaticAccess.jav b/bin/mycompiler/test/javaConcepts/staticAccess/TestStaticAccess.jav new file mode 100755 index 000000000..b00c2e8ef --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/staticAccess/TestStaticAccess.jav @@ -0,0 +1,18 @@ +public class Access{ + + public static String staticMember="def"; + + public static staticMethod() { + return "abc"; + } + +} + +class TestStaticAccess { + + public method1(a,b) { + x; + a=x.staticMember; + b=x.staticMethod(); + } +} diff --git a/bin/mycompiler/test/javaConcepts/staticAccess/TestStaticAccessError.jav b/bin/mycompiler/test/javaConcepts/staticAccess/TestStaticAccessError.jav new file mode 100755 index 000000000..e7445702f --- /dev/null +++ b/bin/mycompiler/test/javaConcepts/staticAccess/TestStaticAccessError.jav @@ -0,0 +1,17 @@ +public class Access{ + public String nonStaticMember="abc"; + + public nonStaticMethod() { + return "def"; + } + +} + +class TestStaticAccessError { + + public methodError1(a,b) { + x; + a=x.nonStaticMember; + b=x.nonStaticMethod(); + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/BasicAssumptions.jav b/bin/mycompiler/test/lambda/BasicAssumptions.jav new file mode 100644 index 000000000..f9da2d184 --- /dev/null +++ b/bin/mycompiler/test/lambda/BasicAssumptions.jav @@ -0,0 +1,10 @@ +class BasicAssumptionsTest{ + +varString; +var = 2; + +void methode(){ + var = 1; + varString = varString.toString(); +} +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/ConstructorTestFile1.jav b/bin/mycompiler/test/lambda/ConstructorTestFile1.jav new file mode 100644 index 000000000..1b26e2bb4 --- /dev/null +++ b/bin/mycompiler/test/lambda/ConstructorTestFile1.jav @@ -0,0 +1,8 @@ +class ConstructorTest1{ + +ConstructorTest1(){ +var; +var = 1; +} + +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/ConstructorTestFile2.jav b/bin/mycompiler/test/lambda/ConstructorTestFile2.jav new file mode 100644 index 000000000..d2ce318e8 --- /dev/null +++ b/bin/mycompiler/test/lambda/ConstructorTestFile2.jav @@ -0,0 +1,7 @@ +class ConstructorTest2{ +var; + void method(){ + var = new ConstructorTest1(); + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/GenericVarTest.jav b/bin/mycompiler/test/lambda/GenericVarTest.jav new file mode 100644 index 000000000..6e6db51b8 --- /dev/null +++ b/bin/mycompiler/test/lambda/GenericVarTest.jav @@ -0,0 +1,7 @@ +class GenericVarTest{ + test; + method(){ + test = test; + return 1; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/LambdaTest1.jav b/bin/mycompiler/test/lambda/LambdaTest1.jav new file mode 100644 index 000000000..09076b3c5 --- /dev/null +++ b/bin/mycompiler/test/lambda/LambdaTest1.jav @@ -0,0 +1,7 @@ +class LambdaTest1{ + var = "test"; + + method(String toAppend){ + return (String text) -> { return text;}; + } +} diff --git a/bin/mycompiler/test/lambda/OverloadingTest.jav b/bin/mycompiler/test/lambda/OverloadingTest.jav new file mode 100644 index 000000000..bed6f9604 --- /dev/null +++ b/bin/mycompiler/test/lambda/OverloadingTest.jav @@ -0,0 +1,21 @@ +class OverloadingTest{ + + var; + + public Object clone(){ + return this; + } + + public testMethode(){ + return var.clone(); + } + +} + +class OverloadingTest2{ + + public Object clone(){ + return this; + } + +} diff --git a/bin/mycompiler/test/lambda/TestAssign.jav b/bin/mycompiler/test/lambda/TestAssign.jav new file mode 100644 index 000000000..17117f182 --- /dev/null +++ b/bin/mycompiler/test/lambda/TestAssign.jav @@ -0,0 +1,3 @@ +class Assign{ +stringVar = "String"; +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/TestFunN.jav b/bin/mycompiler/test/lambda/TestFunN.jav new file mode 100644 index 000000000..b810f636b --- /dev/null +++ b/bin/mycompiler/test/lambda/TestFunN.jav @@ -0,0 +1,2 @@ +class Matrix extends Vector> { +op = (m) -> (f) -> f.apply(this, m); } \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/TestIfStmt.jav b/bin/mycompiler/test/lambda/TestIfStmt.jav new file mode 100644 index 000000000..b4a244d46 --- /dev/null +++ b/bin/mycompiler/test/lambda/TestIfStmt.jav @@ -0,0 +1,13 @@ +class TestIfStmt { + +methode(){ + var; + if(true){ + var=this; + }else{ + var=this; + } + return 1; +} + +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/TestLambda.jav b/bin/mycompiler/test/lambda/TestLambda.jav new file mode 100644 index 000000000..36f107343 --- /dev/null +++ b/bin/mycompiler/test/lambda/TestLambda.jav @@ -0,0 +1,3 @@ +class TestLambda{ +op = (test) -> test = "string"; +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/TestMethodCall.jav b/bin/mycompiler/test/lambda/TestMethodCall.jav new file mode 100644 index 000000000..8abb035be --- /dev/null +++ b/bin/mycompiler/test/lambda/TestMethodCall.jav @@ -0,0 +1,17 @@ +class TestMethodCall { + +var; + +getSomething(){ + return this; +} + +getSomethingMore(){ + return getSomething(); +} + +void setVar(){ + var = getSomethingMore(); +} + +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/TestWhile.jav b/bin/mycompiler/test/lambda/TestWhile.jav new file mode 100644 index 000000000..019bf8f4e --- /dev/null +++ b/bin/mycompiler/test/lambda/TestWhile.jav @@ -0,0 +1,10 @@ +class WhileTest{ + + public method(){ + var; + while(true){ + var = "String"; + } + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/ThisTest.jav b/bin/mycompiler/test/lambda/ThisTest.jav new file mode 100644 index 000000000..0ca725581 --- /dev/null +++ b/bin/mycompiler/test/lambda/ThisTest.jav @@ -0,0 +1,5 @@ +class ThisTest{ + +thisVar = this; + +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/parseMultipleFilesFile1.jav b/bin/mycompiler/test/lambda/parseMultipleFilesFile1.jav new file mode 100644 index 000000000..79a5554a5 --- /dev/null +++ b/bin/mycompiler/test/lambda/parseMultipleFilesFile1.jav @@ -0,0 +1,10 @@ +class Klasse2 { + +var1; + +testMethode(){ + var1 = new Klasse1(); + return var1.getVar1(); +} + +} \ No newline at end of file diff --git a/bin/mycompiler/test/lambda/parseMultipleFilesFile2.jav b/bin/mycompiler/test/lambda/parseMultipleFilesFile2.jav new file mode 100644 index 000000000..47def1950 --- /dev/null +++ b/bin/mycompiler/test/lambda/parseMultipleFilesFile2.jav @@ -0,0 +1,7 @@ +class Klasse1 { + var1; + + int getVar1(){ + return var1; + } +} diff --git a/bin/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.jav b/bin/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.jav new file mode 100755 index 000000000..df5e707fc --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.jav @@ -0,0 +1,20 @@ + +class TestAbstractInferenceTest { + + public foo(a, b) { + c; + d; + d = a+ b; + { + i; + i=5; + } + { + i; + i="abc"; + } + c = new TestAbstractInferenceTest(); + return a+b; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest2.jav b/bin/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest2.jav new file mode 100755 index 000000000..1f4cef494 --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest2.jav @@ -0,0 +1,21 @@ + +public class TestAbstractInferenceTest2 { + + method(Integer a, String s) { + } +} + +class TestAbstractInferenceTest3 extends TestAbstractInferenceTest2 { +/* + method(Integer a) { + c; + }*/ + method2(String s) { + c; + c = new TestAbstractInferenceTest2(); + c.method(2,"abc"); + method(3,"abc"); + } + + +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestClassMemberWithoutType.jav b/bin/mycompiler/test/notUsedAnymore/TestClassMemberWithoutType.jav new file mode 100755 index 000000000..249e1d57d --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestClassMemberWithoutType.jav @@ -0,0 +1,5 @@ + +public class TestClassMemberWithoutType { + + member; +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestConstantsWithoutType.jav b/bin/mycompiler/test/notUsedAnymore/TestConstantsWithoutType.jav new file mode 100755 index 000000000..e61a2feb8 --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestConstantsWithoutType.jav @@ -0,0 +1,6 @@ +public class TestConstantsWithoutType { + public final static B = true; + public final static I = 1; + public final static C = 'A'; + public final static S = "Hello World!"; +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestGenerics.jav b/bin/mycompiler/test/notUsedAnymore/TestGenerics.jav new file mode 100755 index 000000000..337a16164 --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestGenerics.jav @@ -0,0 +1,8 @@ + + +public class TestGenerics { + + > void foo(T n) {} + void foo(T i) {} + +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterface.jav b/bin/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterface.jav new file mode 100755 index 000000000..127ed26eb --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterface.jav @@ -0,0 +1,7 @@ +interface A{ + public m(); +} +class TestInheritanceCheckValidImplementationFromInterface implements A{ + + public void m(){} +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative.jav b/bin/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative.jav new file mode 100755 index 000000000..e05fdae65 --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative.jav @@ -0,0 +1,7 @@ +interface A{ + public m(); +} +class TestInheritanceCheckValidImplementationFromInterfaceNegative implements A{ + + public void m1(){} +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative2.jav b/bin/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative2.jav new file mode 100755 index 000000000..0dd2a73e1 --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative2.jav @@ -0,0 +1,14 @@ +interface TestInheritanceCheckValidImplementationFromInterfaceNegative2{ + public m(); +} +class A implements TestInheritanceCheckValidImplementationFromInterfaceNegative2{ + + public void m(){} +} + +class B implements TestInheritanceCheckValidImplementationFromInterfaceNegative2 { + + public m() { + return 1; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestMethodReturnType.jav b/bin/mycompiler/test/notUsedAnymore/TestMethodReturnType.jav new file mode 100755 index 000000000..ae4d9c9be --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestMethodReturnType.jav @@ -0,0 +1,21 @@ + +public class TestMethodReturnType { + +/* methodReturnType1(a) { + return a; + } + */ + methodReturnType2(a,b) { + return a+b; + } + + methodReturnType3(String a) { + return a; + } + + Integer methodReturnType4(a) { + return a; + } + + +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestMethodReturnTypeGeneric.jav b/bin/mycompiler/test/notUsedAnymore/TestMethodReturnTypeGeneric.jav new file mode 100755 index 000000000..c33e753b2 --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestMethodReturnTypeGeneric.jav @@ -0,0 +1,15 @@ + +public class TestMethodReturnTypeGeneric { + + testMethodReturnTypeGeneric() { + return new TestMethodReturnTypeGeneric(); + } + + testMethodReturnTypeGeneric2(T a) { + return a; + } + + + + +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative.jav b/bin/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative.jav new file mode 100755 index 000000000..10b5f1087 --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative.jav @@ -0,0 +1,8 @@ + +public class TestMethodReturnTypeNegative { + + /*returned String, but must be Integer*/ + Integer m1(String a) { + return a; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative2.jav b/bin/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative2.jav new file mode 100755 index 000000000..15f21075d --- /dev/null +++ b/bin/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative2.jav @@ -0,0 +1,11 @@ + +public class TestMethodReturnTypeNegative2 { + + /*not always boolean returned*/ + public m1() { + a; + if (a) { + return a; + } + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/operators/TestOperatorArithmetic.jav b/bin/mycompiler/test/operators/TestOperatorArithmetic.jav new file mode 100755 index 000000000..7c346c58f --- /dev/null +++ b/bin/mycompiler/test/operators/TestOperatorArithmetic.jav @@ -0,0 +1,40 @@ +public class TestOperatorArithmetic { + + public m1(i,j) { + return i+j; + } + + public m2(i,java.lang.Double j) { + return i-j; + } + + public m3(java.lang.Integer i,j) { + return i*j; + } + + public java.lang.Double m4(i,j) { + return i/j; + } + + public m5(i,j) { + return i%j; + } + + public m6(i) { + return -i; + } + + public m7 (i,j) { + i+=j; + return i; + } + + public m8(i, java.lang.Float j) { + return i/j; + } + + /*public java.lang.Long m9(i, j) { + return i+j; + }*/ + +} \ No newline at end of file diff --git a/bin/mycompiler/test/operators/TestOperatorBitwise.jav b/bin/mycompiler/test/operators/TestOperatorBitwise.jav new file mode 100755 index 000000000..7c7026cc0 --- /dev/null +++ b/bin/mycompiler/test/operators/TestOperatorBitwise.jav @@ -0,0 +1,45 @@ +public class TestOperatorBitwise { + + public m1(a,b) { + return a & b; + } + + public m2(a,b) { + return a ^ b; + } + + public m3(a,b) { + return a | b; + } + + public m4(Integer a, b) { + return a & b; + } + + public m5(a, Long b) { + return a & b; + } + + public Integer m6(a,b) { + return a & b; + } + + /* bit-shift not accepted by parser + + public m7(a,b) { + return x << y; + } + + public m8(a,b) { + return x >> y; + } + + public m9(a,b) { + return x >>> y; + } + + public m10(a) { + return ~a; + } + */ +} \ No newline at end of file diff --git a/bin/mycompiler/test/operators/TestOperatorBool.jav b/bin/mycompiler/test/operators/TestOperatorBool.jav new file mode 100755 index 000000000..33c002b12 --- /dev/null +++ b/bin/mycompiler/test/operators/TestOperatorBool.jav @@ -0,0 +1,19 @@ +public class TestOperatorBool { + + public m1(a,b) { + return a && b; + } + + public m2(a,b) { + return a || b; + } + + public m3(a) { + return !a; + } + + public m4( a, b) { + return a==b; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/operators/TestOperatorComparison.jav b/bin/mycompiler/test/operators/TestOperatorComparison.jav new file mode 100755 index 000000000..62aaee58f --- /dev/null +++ b/bin/mycompiler/test/operators/TestOperatorComparison.jav @@ -0,0 +1,22 @@ +public class TestOperatorComparison { + +/* public m1(a,b) { + return a < b; + } + + public m2(a, b) { + return a >= b; + } + */ + public m3(a, b) { + return a==b; + } + + public java.lang.Boolean m4(a,b) { + return a!=b; + } + + public m5(Integer a, b) { + return a { + +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestClassMember.jav b/bin/mycompiler/test/trivial/TestClassMember.jav new file mode 100755 index 000000000..89a4b51dc --- /dev/null +++ b/bin/mycompiler/test/trivial/TestClassMember.jav @@ -0,0 +1,6 @@ +import java.util.Vector; +public class TestClassMember { + + Integer member; + Vector member2; +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestClassMemberAssignment.jav b/bin/mycompiler/test/trivial/TestClassMemberAssignment.jav new file mode 100755 index 000000000..771ea288a --- /dev/null +++ b/bin/mycompiler/test/trivial/TestClassMemberAssignment.jav @@ -0,0 +1,22 @@ + +public class TestClassMemberAssignment { + + Integer member; + + public m1() { + member=1; + } + + public m2() { + this.member=2; + } + + public m3(a) { + member=a; + } + + public void m(a) { + this.a=a; + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestConstants.jav b/bin/mycompiler/test/trivial/TestConstants.jav new file mode 100755 index 000000000..f9d293ac5 --- /dev/null +++ b/bin/mycompiler/test/trivial/TestConstants.jav @@ -0,0 +1,6 @@ +public class TestConstants { + public final static Boolean B = true; + public final static Integer I = 1; + public final static Character C = 'A'; + public final static String S = "Hello World!"; +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestConstructor.jav b/bin/mycompiler/test/trivial/TestConstructor.jav new file mode 100755 index 000000000..f07566b45 --- /dev/null +++ b/bin/mycompiler/test/trivial/TestConstructor.jav @@ -0,0 +1,20 @@ +import java.util.Stack; + +public class TestConstructor { + Integer i; + Stack s; + + public TestConstructor() { + i=3; + s=new Stack(); + } + + public TestConstructor(a) { + a=4; + } + + public TestConstructor(java.lang.Integer a, Stack b) { + i=a; + s=b; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestConstructorNegative.jav b/bin/mycompiler/test/trivial/TestConstructorNegative.jav new file mode 100755 index 000000000..b4bfcf903 --- /dev/null +++ b/bin/mycompiler/test/trivial/TestConstructorNegative.jav @@ -0,0 +1,8 @@ + +public class TestConstructorNegative { + + /*should throw error*/ + public TestConstructorNegative(java.lang.Integer a, String b) { + return a; + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestInterfaceEmpty.jav b/bin/mycompiler/test/trivial/TestInterfaceEmpty.jav new file mode 100755 index 000000000..52bfca29f --- /dev/null +++ b/bin/mycompiler/test/trivial/TestInterfaceEmpty.jav @@ -0,0 +1,4 @@ + +interface TestInterfaceEmpty { + +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestInterfaceMember.jav b/bin/mycompiler/test/trivial/TestInterfaceMember.jav new file mode 100755 index 000000000..5e60eb603 --- /dev/null +++ b/bin/mycompiler/test/trivial/TestInterfaceMember.jav @@ -0,0 +1,5 @@ +interface TestInterfaceMember { + + Integer member=3; + +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestInterfaceMethod.jav b/bin/mycompiler/test/trivial/TestInterfaceMethod.jav new file mode 100755 index 000000000..1b416fd08 --- /dev/null +++ b/bin/mycompiler/test/trivial/TestInterfaceMethod.jav @@ -0,0 +1,10 @@ +interface TestInterfaceMethod { + + empty1(); + + void empty2(); + + empty3(Integer a); + + empty4(String a, Integer b); +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestInterfaceNotInferenced.jav b/bin/mycompiler/test/trivial/TestInterfaceNotInferenced.jav new file mode 100755 index 000000000..f03d6b181 --- /dev/null +++ b/bin/mycompiler/test/trivial/TestInterfaceNotInferenced.jav @@ -0,0 +1,10 @@ +public interface TestInterfaceNotInferenced { + + public Integer m1(); + + /*should throw error, because not all Types defined*/ + public m2(); + + public void m3(a); + +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestMethodEmpty.jav b/bin/mycompiler/test/trivial/TestMethodEmpty.jav new file mode 100755 index 000000000..c9c21cd5c --- /dev/null +++ b/bin/mycompiler/test/trivial/TestMethodEmpty.jav @@ -0,0 +1,6 @@ + +public class TestMethodEmpty { + + emptyMethod() { + } +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestMethodEmptyGeneric.jav b/bin/mycompiler/test/trivial/TestMethodEmptyGeneric.jav new file mode 100755 index 000000000..c7043f018 --- /dev/null +++ b/bin/mycompiler/test/trivial/TestMethodEmptyGeneric.jav @@ -0,0 +1,10 @@ + +public class TestMethodEmptyGeneric{ + + emptyMethodGeneric() { + } + + emptyMethodGeneric2() { + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestMethodEmptyParameter.jav b/bin/mycompiler/test/trivial/TestMethodEmptyParameter.jav new file mode 100755 index 000000000..7b5b47ac0 --- /dev/null +++ b/bin/mycompiler/test/trivial/TestMethodEmptyParameter.jav @@ -0,0 +1,16 @@ + +public class TestMethodEmptyParameter{ + + + emptyMethodParameter(Integer a) { + } + + + emptyMethodParameter2(Boolean a, Integer b) { + + } + + emptyMethodParameter3(a,b) { + } + +} \ No newline at end of file diff --git a/bin/mycompiler/test/trivial/TestMethodEmptyParameterGenericExtends.jav b/bin/mycompiler/test/trivial/TestMethodEmptyParameterGenericExtends.jav new file mode 100755 index 000000000..369661ac9 --- /dev/null +++ b/bin/mycompiler/test/trivial/TestMethodEmptyParameterGenericExtends.jav @@ -0,0 +1,9 @@ + +public class TestMethodEmptyParameterGenericExtends{ + + emptyMethodGenericExtends2(T a) { + } + + emptyMethodGenericExtends3(T a, S b) { + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/Add.jav b/examples/OldExamples/hama/Add.jav new file mode 100755 index 000000000..2836a30eb --- /dev/null +++ b/examples/OldExamples/hama/Add.jav @@ -0,0 +1,7 @@ +class Add +{ + int add(int a, int b) + { + return a + b; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/AddMain.jav b/examples/OldExamples/hama/AddMain.jav new file mode 100755 index 000000000..ec994b648 --- /dev/null +++ b/examples/OldExamples/hama/AddMain.jav @@ -0,0 +1,8 @@ +class AddMain +{ + public static void main(String[] args) + { + Add a = new Add(); + System.out.println("Addition: 3+4= " + a.add(3, 4)); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/Empty.jav b/examples/OldExamples/hama/Empty.jav new file mode 100755 index 000000000..518f97690 --- /dev/null +++ b/examples/OldExamples/hama/Empty.jav @@ -0,0 +1,4 @@ +class Empty +{ + +} \ No newline at end of file diff --git a/examples/OldExamples/hama/EmptyMain.jav b/examples/OldExamples/hama/EmptyMain.jav new file mode 100755 index 000000000..a183eefee --- /dev/null +++ b/examples/OldExamples/hama/EmptyMain.jav @@ -0,0 +1,8 @@ +public class EmptyMain +{ + public static void main(String[] args) + { + Empty e = new Empty(); + System.out.println("finished"); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/Ergebnis.jav b/examples/OldExamples/hama/Ergebnis.jav new file mode 100755 index 000000000..5a12e67a7 --- /dev/null +++ b/examples/OldExamples/hama/Ergebnis.jav @@ -0,0 +1,18 @@ +class Ergebnis +{ + int zahl1; + int zahl2; + int erg; + + void berechne(int a, int b) + { + zahl1 = a; + zahl2 = b; + erg = zahl1 + zahl2; + } + + int ergebnis() + { + return erg; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/ErgebnisMain.jav b/examples/OldExamples/hama/ErgebnisMain.jav new file mode 100755 index 000000000..3639afcc6 --- /dev/null +++ b/examples/OldExamples/hama/ErgebnisMain.jav @@ -0,0 +1,9 @@ +public class ErgebnisMain +{ + public static void main(String[] args) + { + Ergebnis e = new Ergebnis(); + e.berechne(2, 3); + System.out.println("Addition: 2+3= " + e.ergebnis()); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/Setze.jav b/examples/OldExamples/hama/Setze.jav new file mode 100755 index 000000000..74312dd1e --- /dev/null +++ b/examples/OldExamples/hama/Setze.jav @@ -0,0 +1,9 @@ +class Setze +{ + int zahl; + + void setze() + { + zahl = 555; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/SetzeMain.jav b/examples/OldExamples/hama/SetzeMain.jav new file mode 100755 index 000000000..4198bd63c --- /dev/null +++ b/examples/OldExamples/hama/SetzeMain.jav @@ -0,0 +1,9 @@ +public class SetzeMain +{ + public static void main(String[] args) + { + Setze s = new Setze(); + s.setze(); + System.out.println("finished"); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingObj.jav b/examples/OldExamples/hama/StoreSomethingObj.jav new file mode 100755 index 000000000..83a47a395 --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingObj.jav @@ -0,0 +1,14 @@ +class StoreSomethingObj +{ + Object something; + + Object get() + { + return something; + } + + void set(Object some) + { + something = some; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingObjCon.jav b/examples/OldExamples/hama/StoreSomethingObjCon.jav new file mode 100755 index 000000000..07ca94f83 --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingObjCon.jav @@ -0,0 +1,19 @@ +class StoreSomethingObjCon +{ + Object something; + + StoreSomethingObjCon(Object some) + { + something = some; + } + + Object get() + { + return something; + } + + void set(Object some) + { + something = some; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingObjMain.jav b/examples/OldExamples/hama/StoreSomethingObjMain.jav new file mode 100755 index 000000000..747a404a0 --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingObjMain.jav @@ -0,0 +1,15 @@ +public class StoreSomethingObjMain +{ + public static void main(String[] args) + { + StoreSomethingObjCon a = new StoreSomethingObjCon("I'm a String"); + System.out.println(a.get()); + a.set("new String"); + System.out.println(a.get()); + StoreSomethingObj b = new StoreSomethingObj(); + b.set("I'm var b"); + System.out.println(b.get()); + b.set("new b"); + System.out.println(b.get()); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingPar.jav b/examples/OldExamples/hama/StoreSomethingPar.jav new file mode 100755 index 000000000..a5c453f45 --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingPar.jav @@ -0,0 +1,14 @@ +class StoreSomethingPar +{ + A something; + + A get() + { + return something; + } + + void set(A some) + { + something = some; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingParCon.jav b/examples/OldExamples/hama/StoreSomethingParCon.jav new file mode 100755 index 000000000..47b58a44f --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingParCon.jav @@ -0,0 +1,19 @@ +class StoreSomethingParCon +{ + A something; + + StoreSomethingParCon(A some) + { + something = some; + } + + A get() + { + return something; + } + + void set(A some) + { + something = some; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingParMain.jav b/examples/OldExamples/hama/StoreSomethingParMain.jav new file mode 100755 index 000000000..b633055f0 --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingParMain.jav @@ -0,0 +1,15 @@ +public class MStoreSomethingParMain +{ + public static void main(String[] args) + { + StoreSomethingParCon a = new StoreSomethingParCon("I'm a String"); + System.out.println(a.get()); + a.set("new String"); + System.out.println(a.get()); + StoreSomethingPar b = new StoreSomethingPar(); + b.set("I'm var b"); + System.out.println(b.get()); + b.set("new b"); + System.out.println(b.get()); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingParMainTrick.jav b/examples/OldExamples/hama/StoreSomethingParMainTrick.jav new file mode 100755 index 000000000..b87435234 --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingParMainTrick.jav @@ -0,0 +1,15 @@ +public class StoreSomethingParMainTrick +{ + public static void main(String[] args) + { + StoreSomethingParCon a = new StoreSomethingParCon("I'm a String"); + System.out.println(a.get()); + a.set("new String"); + System.out.println(a.get()); + StoreSomethingPar b = new StoreSomethingPar(); + b.set("I'm var b"); + System.out.println(b.get()); + b.set("new b"); + System.out.println(b.get()); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingStr.jav b/examples/OldExamples/hama/StoreSomethingStr.jav new file mode 100755 index 000000000..20a600fe5 --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingStr.jav @@ -0,0 +1,14 @@ +class StoreSomethingStr +{ + String something; + + String get() + { + return something; + } + + void set(String some) + { + something = some; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingStrCon.jav b/examples/OldExamples/hama/StoreSomethingStrCon.jav new file mode 100755 index 000000000..e3b90155a --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingStrCon.jav @@ -0,0 +1,19 @@ +class StoreSomethingStrCon +{ + String something; + + StoreSomethingStrCon(String some) + { + something = some; + } + + String get() + { + return something; + } + + void set(String some) + { + something = some; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/StoreSomethingStrMain.jav b/examples/OldExamples/hama/StoreSomethingStrMain.jav new file mode 100755 index 000000000..05b258d1f --- /dev/null +++ b/examples/OldExamples/hama/StoreSomethingStrMain.jav @@ -0,0 +1,15 @@ +public class StoreSomethingStrMain +{ + public static void main(String[] args) + { + StoreSomethingStrCon a = new StoreSomethingStrCon("I'm a String"); + System.out.println(a.get()); + a.set("new String"); + System.out.println(a.get()); + StoreSomethingStr b = new StoreSomethingStr(); + b.set("I'm var b"); + System.out.println(b.get()); + b.set("new b"); + System.out.println(b.get()); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/Toggle1.jav b/examples/OldExamples/hama/Toggle1.jav new file mode 100755 index 000000000..01bd0d959 --- /dev/null +++ b/examples/OldExamples/hama/Toggle1.jav @@ -0,0 +1,16 @@ +class Toggle1 +{ + boolean toggle(boolean b) + { + if(b) + { + b = false; + return b; + } + else + { + b = true; + return b; + } + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/Toggle2.jav b/examples/OldExamples/hama/Toggle2.jav new file mode 100755 index 000000000..f66d824c2 --- /dev/null +++ b/examples/OldExamples/hama/Toggle2.jav @@ -0,0 +1,15 @@ +class Toggle2 +{ + boolean toggle(boolean b) + { + if(b) + { + b = false; + } + else + { + b = true; + } + return b; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/Toggle3.jav b/examples/OldExamples/hama/Toggle3.jav new file mode 100755 index 000000000..c437e6b3e --- /dev/null +++ b/examples/OldExamples/hama/Toggle3.jav @@ -0,0 +1,25 @@ +public class Toggle3 +{ + boolean toggle(boolean b) + { + if(b) + { + b = false; + if(true) + { + return b; + } + b = false; + } + else + { + b = true; + if(true) + { + return b; + } + b = true; + } + return b; + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/ToggleMain.jav b/examples/OldExamples/hama/ToggleMain.jav new file mode 100755 index 000000000..8b24c5eea --- /dev/null +++ b/examples/OldExamples/hama/ToggleMain.jav @@ -0,0 +1,18 @@ +public class ToggleMain +{ + public static void main(String[] args) + { + Toggle1 t1 = new Toggle1(); + boolean b1 = false; + System.out.println("b1: " + b1); + System.out.println("b1 getoggelt: " + t1.toggle(b1)); + Toggle2 t2 = new Toggle2(); + boolean b2 = false; + System.out.println("b2: " + b2); + System.out.println("b2 getoggelt: " + t2.toggle(b2)); + Toggle3 t3 = new Toggle3(); + boolean b3 = false; + System.out.println("b3: " + b3); + System.out.println("b3 getoggelt: " + t3.toggle(b3)); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/test1.jav b/examples/OldExamples/hama/test1.jav new file mode 100755 index 000000000..74c0dacf1 --- /dev/null +++ b/examples/OldExamples/hama/test1.jav @@ -0,0 +1,37 @@ +class Test +{ +} + + + +class List1 +{ + A ab; + C da; + + B bu() + { + } +} + + + +class Listst2 +{ + A object = null; + Listst2 next = new Listst2(); +} + + + +class MainKlasse extends List1, List1> +{ + x ra; + List1 li = new List1(); + + void main() + { + List1> si = new List1(); + si.bu(); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/test11.jav b/examples/OldExamples/hama/test11.jav new file mode 100755 index 000000000..bc9051d11 --- /dev/null +++ b/examples/OldExamples/hama/test11.jav @@ -0,0 +1,37 @@ +class Test +{ +} + + + +class List1 +{ + A ab; + C da; + + B bu() + { + } +} + + + +class Listst2 +{ + A object = null; + Listst2 next = new Listst2(); +} + + + +class MainKlasse extends List1, List1> +{ + x ra; + List1 li = new List1(); + + void main() + { + List1> si = new List1(); + si.bu(); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/test1o.jav b/examples/OldExamples/hama/test1o.jav new file mode 100755 index 000000000..824d88a1d --- /dev/null +++ b/examples/OldExamples/hama/test1o.jav @@ -0,0 +1,20 @@ +class test{} +class list{ + A a; + B b(){} + C d; +} + +class main extends list,list> { + x r; + list l = new list(); + void main(){ + list>s= new list(); + s.b(); + } +} + +class List{ + List next = new List(); + A object = null; +} diff --git a/examples/OldExamples/hama/test2.jav b/examples/OldExamples/hama/test2.jav new file mode 100755 index 000000000..834363c00 --- /dev/null +++ b/examples/OldExamples/hama/test2.jav @@ -0,0 +1,42 @@ +class Inte +{ +} + + + +class Liststst3 +{ + A ab = null; + Liststst3 next = new Liststst3(); + + void insert(A elem) + { + if(ab = null) + { + ab = elem; + } + else + { + next.insert(elem); + } + } + + void get(A elem) + { + System.out.println(elem); + next.get(elem); + } +} + + + +class MainClass extends Liststst3> +{ + Liststst3 li = new Liststst3(); + + void main() + { + Liststst3 sa = new Liststst3(), li = new Liststst3(); + Inte in = new Inte(); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/test22.jav b/examples/OldExamples/hama/test22.jav new file mode 100755 index 000000000..863f80bba --- /dev/null +++ b/examples/OldExamples/hama/test22.jav @@ -0,0 +1,42 @@ +class Inte +{ +} + + + +class Liststst3 +{ + A ab = null; + Liststst3 next = new Liststst3(); + + void insert(A elem) + { + if(ab == null) + { + ab = elem; + } + else + { + next.insert(elem); + } + } + + void get(A elem) + { + System.out.println(elem); + next.get(elem); + } +} + + + +class MainClass extends Liststst3> +{ + Liststst3 li = new Liststst3(); + + void main() + { + Liststst3 sa = new Liststst3(), li = new Liststst3(); + Inte in = new Inte(); + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/test2o.jav b/examples/OldExamples/hama/test2o.jav new file mode 100755 index 000000000..41be95a16 --- /dev/null +++ b/examples/OldExamples/hama/test2o.jav @@ -0,0 +1,32 @@ +class INT{} +class list{ + A a = null; + listnext = new list(); + void insert(A elem){ + if(a = null){ + a=elem; + } + else{ + next.insert(elem); + } + } + void get(A elem){ + + System.out.println(elem); + + next.get(elem); + + } +} + +class main extends list> { + + list l = new list(); + void main(){ + lists= new list(), l = new list(); + INT i = new INT(); + } +} + + + diff --git a/examples/OldExamples/hama/test3.jav b/examples/OldExamples/hama/test3.jav new file mode 100755 index 000000000..854523d1a --- /dev/null +++ b/examples/OldExamples/hama/test3.jav @@ -0,0 +1,29 @@ +class Listststst4 +{ + A objec = null; + Listststst4 next = new Listststst4(); + + void insert(A obj) + { + if(this.objec == null) + { + this.objec = obj; + } + else + { + this.next.insert(obj); + } + } + + A getObjectAt(int n) + { + if(n == 0) + { + return this.objec; + } + else + { + return this.next.getObjectAt(n-1); + } + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/test33.jav b/examples/OldExamples/hama/test33.jav new file mode 100755 index 000000000..0253886de --- /dev/null +++ b/examples/OldExamples/hama/test33.jav @@ -0,0 +1,29 @@ +class Listststst4 +{ + A objec = null; + Listststst4 next = new Listststst4(); + + void insert(A obj) + { + if(objec = null) + { + objec = obj; + } + else + { + next.insert(obj); + } + } + + A getObjectAt(int n) + { + if(n = 0) + { + return objec; + } + else + { + return next.getObjectAt(n-1); + } + } +} \ No newline at end of file diff --git a/examples/OldExamples/hama/test3o.jav b/examples/OldExamples/hama/test3o.jav new file mode 100755 index 000000000..3fe316db7 --- /dev/null +++ b/examples/OldExamples/hama/test3o.jav @@ -0,0 +1,20 @@ +class List{ + List next = new List(); + A object = null; + A getObjectAt(int n){ + if(n==0){ + return object; + } + else{ + return this.next.getObjectAt(n-1); + } + } + void insert(A object){ + if(this. Object == null){ + this.object = object; + } + else{ + this.next.insert(object); + } + } +} diff --git a/examples/OldExamples/otth/otth10.jav b/examples/OldExamples/otth/otth10.jav new file mode 100755 index 000000000..435f3a933 --- /dev/null +++ b/examples/OldExamples/otth/otth10.jav @@ -0,0 +1,22 @@ +class otth10 +{ + f1( a, int b ) + { + } + + int f3( X test ) + { + } + + otth10( int b, c, d ) + { + } + +} + +class Test +{ + f5() + { + } +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth11.jav b/examples/OldExamples/otth/otth11.jav new file mode 100755 index 000000000..dcc091ef0 --- /dev/null +++ b/examples/OldExamples/otth/otth11.jav @@ -0,0 +1,10 @@ +class otth11 +{ + f1( a, int b ) + { + } + + void f2( TYPEA VA, TYPEB VB) + { + } +} diff --git a/examples/OldExamples/otth/otth12.jav b/examples/OldExamples/otth/otth12.jav new file mode 100755 index 000000000..2491fd15d --- /dev/null +++ b/examples/OldExamples/otth/otth12.jav @@ -0,0 +1,26 @@ +class AbstractList +{ + A a = null; +} + +class Vektor extends AbstractList +{ + B a = null; +} + +class Stapel extends Vektor +{ + A a = null; +} + +class IntZahl +{ +} + +class Bool +{ +} + +class Main +{ +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth13.jav b/examples/OldExamples/otth/otth13.jav new file mode 100755 index 000000000..90f1104d3 --- /dev/null +++ b/examples/OldExamples/otth/otth13.jav @@ -0,0 +1,13 @@ +class AbstractList +{ + A a = null; + B b = null; +} + + +class Vektor extends AbstractList +{ + A a = null; + B b = null; + C c = null; +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth14.jav b/examples/OldExamples/otth/otth14.jav new file mode 100755 index 000000000..fcb267559 --- /dev/null +++ b/examples/OldExamples/otth/otth14.jav @@ -0,0 +1,11 @@ +class X +{ + B a = null; +} + +class otth14 +{ + void f1( X a ) + { + } +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth15.jav b/examples/OldExamples/otth/otth15.jav new file mode 100755 index 000000000..74036c937 --- /dev/null +++ b/examples/OldExamples/otth/otth15.jav @@ -0,0 +1,43 @@ +class List +{ + A a = null; +} + +class Vektor extends List +{ + A a = null; +} + +class Stack extends Vektor +{ + A a = null; +} + +class ClassB +{ + A a = null; + B b = null; + C c = null; +} + +class ClassA extends ClassB +{ + A a = null; + B b = null; + C c = null; +} + +class Int +{ +} + +class Bool +{ +} + +class otth15 +{ + void f1( X a ) + { + } +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth16.jav b/examples/OldExamples/otth/otth16.jav new file mode 100755 index 000000000..409b607e0 --- /dev/null +++ b/examples/OldExamples/otth/otth16.jav @@ -0,0 +1,38 @@ +class List +{ + A a = null; +} + +class AbstractList extends List +{ + A a = null; +} + +class Vektor extends AbstractList +{ + A a = null; +} + +class Stack extends Vektor +{ + A a = null; +} + +class Objekt +{ +} + +class Int +{ +} + +class Paar +{ + A a = null; + B b = null; +} + + +class otth16 +{ +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth17.jav b/examples/OldExamples/otth/otth17.jav new file mode 100755 index 000000000..77e0d56ab --- /dev/null +++ b/examples/OldExamples/otth/otth17.jav @@ -0,0 +1,25 @@ +class DD +{ + A a = null; + B b = null; +} + +class CC +{ + A a = null; +} + +class BB< A > extends CC +{ + A a = null; +} + +class AA extends BB< DD > +{ + A a = null; + B b = null; +} + +class otth17 +{ +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth18.jav b/examples/OldExamples/otth/otth18.jav new file mode 100755 index 000000000..0519ecba6 --- /dev/null +++ b/examples/OldExamples/otth/otth18.jav @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/OldExamples/otth/otth19.jav b/examples/OldExamples/otth/otth19.jav new file mode 100755 index 000000000..883ea900e --- /dev/null +++ b/examples/OldExamples/otth/otth19.jav @@ -0,0 +1,17 @@ +class List +{ + A a; +} + +class Objekt +{ +} + +class AbstractList { A a; } +class Vektor extends AbstractList { A a; } +class Matrix extends Vektor> { A a; } +class ExtMatrix extends Matrix { A a; } + +class otth19 +{ +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth20.jav b/examples/OldExamples/otth/otth20.jav new file mode 100755 index 000000000..03f233744 --- /dev/null +++ b/examples/OldExamples/otth/otth20.jav @@ -0,0 +1,10 @@ +class otth20 +{ + f1( a, b ) + { + } + + f2( a, int b, c ) + { + } +} diff --git a/examples/OldExamples/otth/otth21.jav b/examples/OldExamples/otth/otth21.jav new file mode 100755 index 000000000..6e2bc6691 --- /dev/null +++ b/examples/OldExamples/otth/otth21.jav @@ -0,0 +1,24 @@ +class T1 +{ +} + +class T0 +{ +} + +class BB< W, X, Y > +{ + X a = null; + Y b = null; + W c = null; +} + +class AA extends BB< T0, CC, T1 > +{ + A a = null; + B b = null; +} + +class otth21 +{ +} diff --git a/examples/OldExamples/otth/otth22.jav b/examples/OldExamples/otth/otth22.jav new file mode 100755 index 000000000..b2b4035a6 --- /dev/null +++ b/examples/OldExamples/otth/otth22.jav @@ -0,0 +1,23 @@ +class AbstractList +{ + A a = null; +} + +class Vektor extends AbstractList +{ + A a = null; +} + +class Matrix extends Vektor> +{ + A a = null; +} + +class ExMatrix extends Matrix +{ + A a = null; +} + +class otth22 +{ +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth23.jav b/examples/OldExamples/otth/otth23.jav new file mode 100755 index 000000000..f936c99be --- /dev/null +++ b/examples/OldExamples/otth/otth23.jav @@ -0,0 +1,16 @@ +class BB +{ + A a = null; +} + +class CC +{ + C c = null; + D d = null; +} + +class XX extends CC>>, BB>> +{ + A a = null; + X b = null; +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth24.jav b/examples/OldExamples/otth/otth24.jav new file mode 100755 index 000000000..1b7dd33e2 --- /dev/null +++ b/examples/OldExamples/otth/otth24.jav @@ -0,0 +1,16 @@ +class BB +{ + A a = null; +} + +class CC +{ + C c = null; + D d = null; +} + +class XX extends CC>>, BB>> +{ + A a = null; + X b = null; +} \ No newline at end of file diff --git a/examples/OldExamples/otth/otth8.jav b/examples/OldExamples/otth/otth8.jav new file mode 100755 index 000000000..bbe343211 --- /dev/null +++ b/examples/OldExamples/otth/otth8.jav @@ -0,0 +1,12 @@ +class otth8 +{ + int add( int x, int y ) + { + return x + y; + } + + int mul( int x, int y ) + { + return x * y; + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/Class1.java b/examples/OldExamples/test/Class1.java new file mode 100755 index 000000000..52bd8c020 --- /dev/null +++ b/examples/OldExamples/test/Class1.java @@ -0,0 +1,8 @@ +package test; + + + +public class Class1 +{ + int testwert; +} \ No newline at end of file diff --git a/examples/OldExamples/test/Class2.java b/examples/OldExamples/test/Class2.java new file mode 100755 index 000000000..a12baf138 --- /dev/null +++ b/examples/OldExamples/test/Class2.java @@ -0,0 +1,8 @@ +package test; + + + +public class Class2 +{ + Class1 class1var; +} \ No newline at end of file diff --git a/examples/OldExamples/test/Class3.java b/examples/OldExamples/test/Class3.java new file mode 100755 index 000000000..102a36ef5 --- /dev/null +++ b/examples/OldExamples/test/Class3.java @@ -0,0 +1,8 @@ +package test; + + + +public class Class3 +{ + Class2 class2var; +} \ No newline at end of file diff --git a/examples/OldExamples/test/Eins.java b/examples/OldExamples/test/Eins.java new file mode 100755 index 000000000..444efd0e0 --- /dev/null +++ b/examples/OldExamples/test/Eins.java @@ -0,0 +1,27 @@ +package test; + + + +public class Eins +{ + int a; + char b = 'a'; + boolean c = false; + String s = "Hallo"; + + public static void Methode() + { + int g = 34; + char h = 'c'; + String bla = "Haus"; + boolean bo = true; + } + + private int Methode2() + { + Zwei testklasse = new Zwei(); + int d; + int f = d = 5; + return 14; + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/ExtendTest.java b/examples/OldExamples/test/ExtendTest.java new file mode 100755 index 000000000..eba0a4127 --- /dev/null +++ b/examples/OldExamples/test/ExtendTest.java @@ -0,0 +1,8 @@ +package test; + + + +public class ExtendTest +{ + int testwert; +} \ No newline at end of file diff --git a/examples/OldExamples/test/Main.java b/examples/OldExamples/test/Main.java new file mode 100755 index 000000000..3c4bdd144 --- /dev/null +++ b/examples/OldExamples/test/Main.java @@ -0,0 +1,21 @@ +package test; + + + +public class Main +{ + int i = 10; + + public static void main(String[] args) + { + Main2 m = new Main2(); + m.print(); + + /* + int i = 0; + i = Integer.parseInt(args[0]); + test_code x = new test_code(); + x.main(i); + */ + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/Main2.java b/examples/OldExamples/test/Main2.java new file mode 100755 index 000000000..cdb316083 --- /dev/null +++ b/examples/OldExamples/test/Main2.java @@ -0,0 +1,11 @@ +package test; + + + +public class Main2 extends Main +{ + public void print() + { + System.out.println(i); + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/MethTestBasis.java b/examples/OldExamples/test/MethTestBasis.java new file mode 100755 index 000000000..9fd2a4ec8 --- /dev/null +++ b/examples/OldExamples/test/MethTestBasis.java @@ -0,0 +1,12 @@ +package test; + + + +public class MethTestBasis +{ + int test; + int testen() + { + return test; + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/MethTestInherit.java b/examples/OldExamples/test/MethTestInherit.java new file mode 100755 index 000000000..a815204ac --- /dev/null +++ b/examples/OldExamples/test/MethTestInherit.java @@ -0,0 +1,12 @@ +package test; + + + +public class MethTestInherit extends MethTestBasis +{ + int testen(int a,int b) + { + a=b; + return test; + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/SCTest.java b/examples/OldExamples/test/SCTest.java new file mode 100755 index 000000000..a7a41c396 --- /dev/null +++ b/examples/OldExamples/test/SCTest.java @@ -0,0 +1,314 @@ +package test; + + + +import SourceFile; +import Class; +import ClassBody; +import InstVarDecl; +import DeclId; +import Method; +import Return; +import ParameterList; +import FormalParameter; +import Block; +import Assign; +import Receiver; +import MethodCall; +import LocalOrFieldVar; +import ClassDeclId; +import UsedId; +import Type; +import SCException; + + + + +public class SCTest +{ + public SourceFile source=new SourceFile(); + + private boolean extendedsc; + + public void build_tree() + { + Class a=new Class(); + Class class1=new Class(); + Class class2=new Class(); + Class class3 =new Class(); + Class b=new Class(); + Class c=new Class(); + Class dc=new Class(); + ClassBody ab=new ClassBody(); + ClassBody b1=new ClassBody(); + ClassBody b2=new ClassBody(); + ClassBody b3=new ClassBody(); + ClassBody bb=new ClassBody(); + ClassBody cb=new ClassBody(); + ClassBody dcb=new ClassBody(); + InstVarDecl i=new InstVarDecl(); + InstVarDecl j=new InstVarDecl(); + InstVarDecl ij=new InstVarDecl(); + InstVarDecl inst1=new InstVarDecl(); + InstVarDecl inst2=new InstVarDecl(); + InstVarDecl inst3=new InstVarDecl(); + InstVarDecl binstvar1=new InstVarDecl(); + InstVarDecl binstvar2=new InstVarDecl(); + InstVarDecl aformeth=new InstVarDecl(); + InstVarDecl aformeth2=new InstVarDecl(); + DeclId adeclformeth=new DeclId(); + DeclId decl1=new DeclId(); + DeclId decl2=new DeclId(); + DeclId decl3=new DeclId(); + DeclId decl=new DeclId(); + DeclId d=new DeclId(); + DeclId d1=new DeclId(); + DeclId d2=new DeclId(); + DeclId d3=new DeclId(); + DeclId bd1=new DeclId(); + DeclId bd2=new DeclId(); + DeclId amd1=new DeclId(); + DeclId amd2=new DeclId(); + DeclId dcmd1=new DeclId(); + DeclId dcmd2=new DeclId(); + DeclId adc=new DeclId(); + DeclId cmname=new DeclId(); + DeclId dcmname=new DeclId(); + Method m=new Method(); + Method bm=new Method(); + Method cm=new Method(); + Method dcm=new Method(); + Return amr=new Return(); + ParameterList amp=new ParameterList(); + ParameterList dcmp=new ParameterList(); + FormalParameter dcmpf=new FormalParameter(); + FormalParameter ampf1=new FormalParameter(); + FormalParameter ampf2=new FormalParameter(); + FormalParameter dcmpf1=new FormalParameter(); + FormalParameter dcmpf2=new FormalParameter(); + Block bl=new Block(); + Block bbl=new Block(); + Block dcmb=new Block(); + Block cmb=new Block(); + Assign as=new Assign(); + Receiver amrcv=new Receiver(); + Receiver amrcv2=new Receiver(); + MethodCall ammc=new MethodCall(); + MethodCall ammc2=new MethodCall(); + LocalOrFieldVar lf=new LocalOrFieldVar(); + LocalOrFieldVar lf2=new LocalOrFieldVar(); + LocalOrFieldVar amerst=new LocalOrFieldVar(); + LocalOrFieldVar amzwei=new LocalOrFieldVar(); + LocalOrFieldVar am2=new LocalOrFieldVar(); + ClassDeclId cdi=new ClassDeclId(); + ClassDeclId cdi1=new ClassDeclId(); + ClassDeclId cdi2=new ClassDeclId(); + ClassDeclId cdi3=new ClassDeclId(); + ClassDeclId bcd=new ClassDeclId(); + ClassDeclId ccd=new ClassDeclId(); + ClassDeclId dccd=new ClassDeclId(); + UsedId u1=new UsedId(); + UsedId u2=new UsedId(); + UsedId text=new UsedId(); + UsedId dccdsclass=new UsedId(); + UsedId ausedformeth=new UsedId(); + UsedId ausedformeth2=new UsedId(); + UsedId ausedinmeth=new UsedId(); + UsedId ausedinmeth2=new UsedId(); + Type t=new Type(); + Type t1=new Type(); + Type t2=new Type(); + Type t3=new Type(); + Type t4=new Type(); + Type t5=new Type(); + Type t6=new Type(); + + cdi.set_classname("test"); + cdi1.set_classname("class1"); + cdi2.set_classname("class2"); + cdi3.set_classname("class3"); + bcd.set_classname("extendtest"); + ccd.set_classname("methtestbasis"); + dccd.set_classname("methtestinherit"); + + text.set_Name("extendtest"); + dccdsclass.set_Name("methtestbasis"); + a.set_ClassDeclId(cdi); + a.set_UsedId(text); + class1.set_ClassDeclId(cdi1); + class2.set_ClassDeclId(cdi2); + class3.set_ClassDeclId(cdi3); + b.set_ClassDeclId(bcd); + c.set_ClassDeclId(ccd); + dc.set_ClassDeclId(dccd); + dc.set_UsedId(dccdsclass); + + d1.set_Name("testint1"); + d2.set_Name("testint2"); + d3.set_Name("class1var"); + decl1.set_Name("class2var"); + decl2.set_Name("class3var"); + decl3.set_Name("inttest"); + bd1.set_Name("externesint1"); + bd2.set_Name("externesint2"); + adeclformeth.set_Name("klassenvariable"); + adc.set_Name("klassenvariabledc"); + + t.set_Type("int"); + t1.set_Type("class2"); + t2.set_Type("class3"); + t3.set_Type("int"); + t4.set_Type("class1"); + t5.set_Type("extendtest"); + t6.set_Type("methtestinherit"); + + inst1.set_Type(t1); + inst2.set_Type(t2); + inst3.set_Type(t3); + ij.set_Type(t4); + i.set_Type(t); + j.set_Type(t); + aformeth.set_Type(t5); + binstvar1.set_Type(t); + binstvar2.set_Type(t); + aformeth2.set_Type(t6); + + i.set_DeclId(d1); + j.set_DeclId(d2); + ij.set_DeclId(d3); + aformeth.set_DeclId(adeclformeth); + inst1.set_DeclId(decl1); + inst2.set_DeclId(decl2); + inst3.set_DeclId(decl3); + binstvar1.set_DeclId(bd1); + binstvar2.set_DeclId(bd2); + aformeth2.set_DeclId(adc); + + ab.set_FieldDecl(i); + ab.set_FieldDecl(j); + ab.set_FieldDecl(ij); + ab.set_FieldDecl(aformeth); + b1.set_FieldDecl(inst1); + b2.set_FieldDecl(inst2); + b3.set_FieldDecl(inst3); + bb.set_FieldDecl(binstvar1); + bb.set_FieldDecl(binstvar2); + ab.set_FieldDecl(aformeth2); + + u1.set_Name("class1var"); + u1.set_Name("class2var"); + u1.set_Name("class3var"); + u1.set_Name("inttest"); + u2.set_Name("testint2"); + ausedformeth.set_Name("testfkt"); + ausedinmeth.set_Name("klassenvariable"); + ausedformeth2.set_Name("klassenvariabledc"); + ausedformeth2.set_Name("testen"); + + lf.set_UsedId(u1); + lf2.set_UsedId(u2); + amerst.set_UsedId(u1); + amzwei.set_UsedId(ausedinmeth); + + as.set_Expr(lf,lf2); + amr.set_ReturnExpr(lf2); + + amrcv.set_Expr(lf); + ammc.set_Receiver(amrcv); + ammc.set_UsedId(ausedformeth); + ammc.add_Expr(amerst); + ammc.add_Expr(amzwei); + ammc2.set_Receiver(amrcv); + ammc2.set_UsedId(ausedformeth2); + + bl.set_Statement(as); + bl.set_Statement(ammc); + bl.set_Statement(ammc2); + bl.set_Statement(amr); + + amd1.set_Name("intwert"); + amd2.set_Name("extendtest"); + dcmd1.set_Name("intwert"); + dcmd2.set_Name("intwert"); + + ampf1.set_Type(t); + ampf2.set_Type(t5); + ampf1.set_DeclId(amd1); + ampf2.set_DeclId(amd2); + dcmpf1.set_Type(t); + dcmpf2.set_Type(t); + dcmpf1.set_DeclId(dcmd1); + dcmpf2.set_DeclId(dcmd2); + + amp.set_AddParameter(ampf1); + amp.set_AddParameter(ampf2); + dcmp.set_AddParameter(dcmpf1); + dcmp.set_AddParameter(dcmpf2); + + dcm.set_ParaList(dcmp); + m.set_ParaList(amp); + + dcm.set_Block(dcmb); + m.set_Block(bl); + cm.set_Block(cmb); + + d.set_Name("testfkt"); + cmname.set_Name("testen"); + dcmname.set_Name("testen"); + + m.set_ReturnType(t); + cm.set_ReturnType(t); + dcm.set_ReturnType(t); + + m.set_DeclId(d); + cm.set_DeclId(cmname); + dcm.set_DeclId(dcmname); + + ab.set_FieldDecl(m); + cb.set_FieldDecl(cm); + dcb.set_FieldDecl(dcm); + + a.set_ClassBody(ab); + class1.set_ClassBody(b1); + class2.set_ClassBody(b2); + class3.set_ClassBody(b3); + b.set_ClassBody(bb); + c.set_ClassBody(cb); + dc.set_ClassBody(dcb); + + source.set_Class(c); + source.set_Class(dc); + source.set_Class(b); + source.set_Class(class3); + source.set_Class(class2); + source.set_Class(class1); + source.set_Class(a); + try + { + source.sc_check(extendedsc); + } + catch (SCException ex) + { + ex.fehlerausgabe(); + } + } + + public void set_ext(boolean ext) + { + extendedsc=ext; + } + + public static void main(String args[]) + { + SCTest test=new SCTest(); + if(args!=null) + { + if(args[0].equals("fullinfo")) + test.set_ext(true); + else + test.set_ext(false); + } + test.build_tree(); + + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/Test.java b/examples/OldExamples/test/Test.java new file mode 100755 index 000000000..4a7f0452a --- /dev/null +++ b/examples/OldExamples/test/Test.java @@ -0,0 +1,16 @@ +package test; + + + +public class Test extends ExtendTest +{ + Class3 testclass; + MethTestInherit mctest; + int versuch; + int testfkt() + { + testclass.class2var.class1var.testwert=testwert; + versuch=mctest.testen(); + return testwert; + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/TestCode.java b/examples/OldExamples/test/TestCode.java new file mode 100755 index 000000000..74ebff15f --- /dev/null +++ b/examples/OldExamples/test/TestCode.java @@ -0,0 +1,49 @@ +package test; + + + +public class TestCode +{ + + TestSemantic sem = new TestSemantic(); + Vererbung vererb = new Vererbung(); + + void print_String(String s) { + System.out.println(s); + } + + void main(int a) { + if(a == 0) { + int i = 0; + while(i < 20) { + int k = 0; + while(k < i) { + System.out.print(" "); + k++; + } + + System.out.println("Hello World"); + i++; + } + vererb.print_Hello_World(); + vererb.print_Hello_World(); + + System.out.println(""); + } + else { + print_String(""); + print_String(""); + print_String(""); + print_String(" Dies war ein erfolgreicher Versuch der Gruppe 2: "); + print_String(""); + + sem.sem_test(); + + int i = 0; + while(i < 7) { + print_String(""); + i++; + } + } + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/TestSemantic.java b/examples/OldExamples/test/TestSemantic.java new file mode 100755 index 000000000..eae83e23b --- /dev/null +++ b/examples/OldExamples/test/TestSemantic.java @@ -0,0 +1,35 @@ +package test; + + + +public class TestSemantic +{ + + void print_Hello_World() { + System.out.println("Hello World"); + } + + void sem_test() { + System.out.println(" Parser:"); + System.out.println(""); + System.out.println(" Jochen Schlachter"); + System.out.println(" Thomas Schaumann"); + System.out.println(" Christian Riess"); + System.out.println(" Matthias Eichholz"); + System.out.println(""); + + System.out.println(" Sematicchecker:"); + System.out.println(""); + System.out.println(" Felix Reichenbach"); + System.out.println(" Stephan Lachenmaier"); + System.out.println(" Sabine Dawidowski"); + System.out.println(" "); + + System.out.println(" CodierSchweinchens:"); + System.out.println(""); + System.out.println(" Matthias Benesch"); + System.out.println(" Michael Henninger"); + System.out.println(" Volker Straub"); + System.out.println(" Stefan Teutsch"); + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/Vererbung.java b/examples/OldExamples/test/Vererbung.java new file mode 100755 index 000000000..4f1405bd5 --- /dev/null +++ b/examples/OldExamples/test/Vererbung.java @@ -0,0 +1,8 @@ +package test; + + + +public class Vererbung extends TestSemantic +{ + +} \ No newline at end of file diff --git a/examples/OldExamples/test/X.java b/examples/OldExamples/test/X.java new file mode 100755 index 000000000..316bc12f7 --- /dev/null +++ b/examples/OldExamples/test/X.java @@ -0,0 +1,21 @@ +package test; + + + +import java.io.FileOutputStream; +import CPInfo; +import ClassFile; + + + +public class X extends CPInfo +{ + byte tag; + short class_index; + short name_and_type_index; + + public void codegen(ClassFile classfile, FileOutputStream f) + { + + } +} \ No newline at end of file diff --git a/examples/OldExamples/test/Zwei.java b/examples/OldExamples/test/Zwei.java new file mode 100755 index 000000000..61555acb2 --- /dev/null +++ b/examples/OldExamples/test/Zwei.java @@ -0,0 +1,27 @@ +package test; + + + +public class Zwei +{ + int i,a; + + private void schleifen() + { + if( i <= 10) + { + i--; + } + else + { + i++; + a *= 2; + a = i+22; + } + int r = 0; + while (r !=10) + { + r++; + } + } +} \ No newline at end of file diff --git a/examples/achim/Abstract.jav b/examples/achim/Abstract.jav new file mode 100755 index 000000000..448e188df --- /dev/null +++ b/examples/achim/Abstract.jav @@ -0,0 +1,12 @@ +static class Abstract{ + abstract test(){ + i; + i=0; + } + + final test2(){ + b; + b = true; + b = false; + } +} \ No newline at end of file diff --git a/examples/achim/Add.jav b/examples/achim/Add.jav new file mode 100755 index 000000000..e512e2e46 --- /dev/null +++ b/examples/achim/Add.jav @@ -0,0 +1,6 @@ +class Add{ + test(i,j){ + a; + a=i+j; + } +} diff --git a/examples/achim/Assert.jav b/examples/achim/Assert.jav new file mode 100755 index 000000000..c13faafc6 --- /dev/null +++ b/examples/achim/Assert.jav @@ -0,0 +1,13 @@ +public class Assert +{ + div( divident, divisor ) + { + assert divisor != 0 : "Oh bitte keine Zahl durch null teilen."; + return divident/divisor; + } + public static void main( args ) + { + println( "Quotient ist " + div(10, 2) ); + println( "Quotient ist " + div(10, 0) ); + } +} \ No newline at end of file diff --git a/examples/achim/Continue.jav b/examples/achim/Continue.jav new file mode 100755 index 000000000..0979d0566 --- /dev/null +++ b/examples/achim/Continue.jav @@ -0,0 +1,17 @@ +class Continue{ + public static main(args){ + w1; + w2; + w1 = 13; + + while(w1>0){ + if(w1<5){ + for(w1=0;w1<5;w1=w1+1){ + w2=w1; + y; + y=1; + } + } + } + } +} diff --git a/examples/achim/ElseIf.jav b/examples/achim/ElseIf.jav new file mode 100755 index 000000000..81fb15e85 --- /dev/null +++ b/examples/achim/ElseIf.jav @@ -0,0 +1,20 @@ +class ElseIf{ + public static void main(args){ + s; + i; + s = args; + e; + if(s < 10){ + e = s + 10; + } + else if(s > 10 && s < 20){ + e = s + 20; + } + else if(s > 20){ + e = s + 30; + } + else{ + e = s + 30; + } + } +} \ No newline at end of file diff --git a/examples/achim/Exceptions.jav b/examples/achim/Exceptions.jav new file mode 100755 index 000000000..9e218c4b9 --- /dev/null +++ b/examples/achim/Exceptions.jav @@ -0,0 +1,9 @@ +class Exceptions{ + funktion(){ + i; + if(true){ + a; + } + + } +} \ No newline at end of file diff --git a/examples/achim/ForTest.jav b/examples/achim/ForTest.jav new file mode 100755 index 000000000..8962de468 --- /dev/null +++ b/examples/achim/ForTest.jav @@ -0,0 +1,10 @@ +class ForTest{ + methode(){ + i; + /*i=0;*/ + b; + for(;i+1;){ + /*i=1;*/ + } + } +} diff --git a/examples/achim/Implements.jav b/examples/achim/Implements.jav new file mode 100755 index 000000000..abe024a7a --- /dev/null +++ b/examples/achim/Implements.jav @@ -0,0 +1,18 @@ +class Implements extends Types implements Modifier{ + method(){ + i; + println(i); + } + + println(i){ + d; + d = i; + } +} + +class Implements2 extends Types{ + method2(){ + n; + n = 4; + } +} \ No newline at end of file diff --git a/examples/achim/Instanceof.jav b/examples/achim/Instanceof.jav new file mode 100755 index 000000000..14a6e7916 --- /dev/null +++ b/examples/achim/Instanceof.jav @@ -0,0 +1,10 @@ +class Instanceof{ + method(mitgift){ + i; + i = new Integer(); + if(mitgift == Instanceof){ + return mitgift; + } + else return null; + } +} \ No newline at end of file diff --git a/examples/achim/Interface.jav b/examples/achim/Interface.jav new file mode 100755 index 000000000..d63ad974b --- /dev/null +++ b/examples/achim/Interface.jav @@ -0,0 +1,4 @@ +interface Unterhaltend +{ + int unterhaltungswert(); +} \ No newline at end of file diff --git a/examples/achim/Modifier.jav b/examples/achim/Modifier.jav new file mode 100755 index 000000000..ffb986026 --- /dev/null +++ b/examples/achim/Modifier.jav @@ -0,0 +1,53 @@ +package examples.achim; + +class Modifier{ + + void test2(){ + i; + i = "hallo2"; + } + + public test3(){ + text; + text = "text"; + return text; + } + + public test31(){ + text; + text = "text"; + } + + static test4(){ + buchstabe; + buchstabe = 'a'; + return buchstabe; + } + + static test41(){ + buchstabe; + buchstabe = 'a'; + } + + protected test5(){ + zahl; + zahl = 10; + return zahl; + } + + protected test51(){ + zahl; + zahl = 10; + } + + private test6(){ + zahl; + zahl = 10; + return zahl; + } + + private test61(){ + zahl; + zahl = 10; + } +} \ No newline at end of file diff --git a/examples/achim/Modifier2.jav b/examples/achim/Modifier2.jav new file mode 100755 index 000000000..c852d389c --- /dev/null +++ b/examples/achim/Modifier2.jav @@ -0,0 +1,30 @@ +package examples.achim; +import java.lang.Math; +class Modifier2{ + + void test2(){ + int s; + i; + i = 42; + s; + s = "string"; + d; + } + + public test3(){ + text; + text = "text"; + return text; + } + + public test31(){ + text; + text = "text"; + } + + static test4(){ + buchstabe; + buchstabe = 'a'; + return buchstabe; + } +} \ No newline at end of file diff --git a/examples/achim/Super.jav b/examples/achim/Super.jav new file mode 100755 index 000000000..d918a33d6 --- /dev/null +++ b/examples/achim/Super.jav @@ -0,0 +1,13 @@ +import javax.swing.JFrame; + +class Super extends JFrame{ + method(mitgift){ + super("Fenster"); + i; + i = new Integer(); + if(mitgift == Instanceof){ + return mitgift; + } + else return null; + } +} \ No newline at end of file diff --git a/examples/achim/SwitchCase.jav b/examples/achim/SwitchCase.jav new file mode 100755 index 000000000..8723eeb6c --- /dev/null +++ b/examples/achim/SwitchCase.jav @@ -0,0 +1,24 @@ +class SwitchCase{ + test(){ + i; + i=3; + switch (i){ + case 1: + case 3: + case 5: + case 7: + case 9: + System.out.println("ungerade"); + break; + case 2: + case 4: + case 6: + case 8: + System.out.println("gerade"); + break; + default: + System.out.println("nicht im wertebereich"); + break; + } + } +} \ No newline at end of file diff --git a/examples/achim/Synchronized.jav b/examples/achim/Synchronized.jav new file mode 100755 index 000000000..4ffb1af0a --- /dev/null +++ b/examples/achim/Synchronized.jav @@ -0,0 +1,8 @@ +class Synchronized{ + method(){ + i; + synchronized(i){ + + } + } +} \ No newline at end of file diff --git a/examples/achim/This.jav b/examples/achim/This.jav new file mode 100755 index 000000000..59455ce6a --- /dev/null +++ b/examples/achim/This.jav @@ -0,0 +1,10 @@ +class This{ + public This(i){ + i; + } + + methode(){ + i; + this.i = 0; + } +} \ No newline at end of file diff --git a/examples/achim/TryCatch.jav b/examples/achim/TryCatch.jav new file mode 100755 index 000000000..dc23cce14 --- /dev/null +++ b/examples/achim/TryCatch.jav @@ -0,0 +1,10 @@ +class TryCatch{ + test(){ + try{ + i; + i=0; + }catch(e){ + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/examples/achim/Types.jav b/examples/achim/Types.jav new file mode 100755 index 000000000..200bca8d5 --- /dev/null +++ b/examples/achim/Types.jav @@ -0,0 +1,31 @@ +class Types{ + test(b, c, d, f, i, l, s){ + b; + b2; + c; + d; + f; + i; + l; + s; + + b = true; + if(b){ + b=false; + } + if(true) + b2 = b; + i = 65; + c = 'a'; + f = i/2; + d = "hallo"; + s = -3; + l = d.substring(2,1); + + boolean bo; + char c; + int i; + + return i; + } +} \ No newline at end of file diff --git a/examples/achim/Vector.jav b/examples/achim/Vector.jav new file mode 100755 index 000000000..6325fba5b --- /dev/null +++ b/examples/achim/Vector.jav @@ -0,0 +1,8 @@ +class Vector{ + method(){ + v; + v = new Vector(); + v.add((new Integer(9)); + ((String)v.get(5)) + "hallo"; + } +} \ No newline at end of file diff --git a/examples/achim/While.jav b/examples/achim/While.jav new file mode 100755 index 000000000..b9c1b0a38 --- /dev/null +++ b/examples/achim/While.jav @@ -0,0 +1,19 @@ +class While{ + method(){ + i; + i = 0; + while(i < 10) { + i++; + } + + while(true){ + s; + s = "zweiundvierzig"; + } + + while(false){ + t; + t = 42; + } + } +} diff --git a/examples/achim/WhileTest.jav b/examples/achim/WhileTest.jav new file mode 100755 index 000000000..e69de29bb diff --git a/examples/bajo1/Martin.jav b/examples/bajo1/Martin.jav new file mode 100755 index 000000000..ea9bdeb79 --- /dev/null +++ b/examples/bajo1/Martin.jav @@ -0,0 +1,6 @@ +class Martin{ + + void TalkTo(String person){ + + } +} \ No newline at end of file diff --git a/examples/bajo1/Matrix.jav b/examples/bajo1/Matrix.jav new file mode 100755 index 000000000..9c9f989e1 --- /dev/null +++ b/examples/bajo1/Matrix.jav @@ -0,0 +1,26 @@ +class Matrix extends Vector> { + + mul(m){ + ret = new Matrix(); + i = 0; + while(i (); + j = 0; + while(j < v1.size()) { + erg = 0; + k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k).intValue() * m.elmentAt(k).elementAt(j).intValue(); + k++; + } + v2.addElement(new Integer(erg); + j++; + } + ret.addElement(v2); + i++; + } + return ret; + } + +} \ No newline at end of file diff --git a/examples/bajo1/SchorschTest.jav b/examples/bajo1/SchorschTest.jav new file mode 100755 index 000000000..4132c169b --- /dev/null +++ b/examples/bajo1/SchorschTest.jav @@ -0,0 +1,11 @@ +class SchorschTest{ + int iMember; + String hallo; + + SchorschTest(int i){ + iMember = i; + } + + void tuWas(){ + } +} \ No newline at end of file diff --git a/examples/bajo1/Simple.jav b/examples/bajo1/Simple.jav new file mode 100755 index 000000000..aa0d83636 --- /dev/null +++ b/examples/bajo1/Simple.jav @@ -0,0 +1,7 @@ +class Simple{ + int x; + + simple(){ + return 5; + } +} \ No newline at end of file diff --git a/examples/bajo1/Test.jav b/examples/bajo1/Test.jav new file mode 100755 index 000000000..71fbe9615 --- /dev/null +++ b/examples/bajo1/Test.jav @@ -0,0 +1,3 @@ +class Bla extends Blub{ + Vector v = null; +} \ No newline at end of file diff --git a/examples/bajo1_usecases/BlockIDTest.jav b/examples/bajo1_usecases/BlockIDTest.jav new file mode 100755 index 000000000..0d319866f --- /dev/null +++ b/examples/bajo1_usecases/BlockIDTest.jav @@ -0,0 +1,12 @@ +class BlockIDTest{ + + void foo(Stack bar){ + { + umu; + umu = bar; + } + { + Integer x; + } + } +} \ No newline at end of file diff --git a/examples/bajo1_usecases/Matrix.jav b/examples/bajo1_usecases/Matrix.jav new file mode 100755 index 000000000..87f28a6fd --- /dev/null +++ b/examples/bajo1_usecases/Matrix.jav @@ -0,0 +1,35 @@ +import java.util.Vector; + +class Matrix extends Vector> { + + mul(m){ + Vector> ret; + ret = new Matrix(); + i; + i = 0; + while(i (); + j; + j = 0; + while(j < v1.size()) { + erg; + erg = 0; + k; + k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k).intValue() * m.elementAt(k).elementAt(j).intValue(); + k++; + } + v2.addElement(new Integer(erg)); + j++; + } + ret.addElement(v2); + i++; + } + return ret; + } + +} diff --git a/examples/bajo1_usecases/Matrix1.jav b/examples/bajo1_usecases/Matrix1.jav new file mode 100755 index 000000000..60262844a --- /dev/null +++ b/examples/bajo1_usecases/Matrix1.jav @@ -0,0 +1,21 @@ +class Matrix extends Vector> { + + mul(m){ + Vector> ret; + ret = new Matrix(); + i; + i = 0; + while(i (); + j; + j = 0; + ret.addElement(v2); + i++; + } + return ret; + } + +} diff --git a/examples/bajo1_usecases/Matrix2.jav b/examples/bajo1_usecases/Matrix2.jav new file mode 100755 index 000000000..ec5f6131f --- /dev/null +++ b/examples/bajo1_usecases/Matrix2.jav @@ -0,0 +1,11 @@ +class Matrix extends Vector> { + + mul(m){ + k; + k = 0; + ret; + ret = m.elementAt(k).elementAt(k).intValue(); + return ret; + } + +} diff --git a/examples/bajo1_usecases/Test.jav b/examples/bajo1_usecases/Test.jav new file mode 100755 index 000000000..864afb82c --- /dev/null +++ b/examples/bajo1_usecases/Test.jav @@ -0,0 +1,11 @@ +class Test{ + Character foo(Character bar){ + return bar; + } + + bla(blub, umu, lala){ + blub = this.foo(umu); + return blub; + } + +} \ No newline at end of file diff --git a/examples/bajo1_usecases/UsecaseFive.jav b/examples/bajo1_usecases/UsecaseFive.jav new file mode 100755 index 000000000..59edc47bc --- /dev/null +++ b/examples/bajo1_usecases/UsecaseFive.jav @@ -0,0 +1,15 @@ +class UsecaseFive{ + + foo(bar){ + if(bar==true){ + umu; + umu = bar; + return new Integer(3); + } + else { + x; + return x; + } + } + +} \ No newline at end of file diff --git a/examples/bajo1_usecases/UsecaseFour.jav b/examples/bajo1_usecases/UsecaseFour.jav new file mode 100755 index 000000000..68cb7eba1 --- /dev/null +++ b/examples/bajo1_usecases/UsecaseFour.jav @@ -0,0 +1,11 @@ +class UsecaseFour{ + + foo(bla){ + while(bla==true){ + Integer x; + x = 5; + } + return bla; + } + +} \ No newline at end of file diff --git a/examples/bajo1_usecases/UsecaseOne.jav b/examples/bajo1_usecases/UsecaseOne.jav new file mode 100755 index 000000000..845d7bc92 --- /dev/null +++ b/examples/bajo1_usecases/UsecaseOne.jav @@ -0,0 +1,5 @@ +class UsecaseOne{ + foo(){ + return (4*(3-2))>2; + } +} \ No newline at end of file diff --git a/examples/bajo1_usecases/UsecaseSix.jav b/examples/bajo1_usecases/UsecaseSix.jav new file mode 100755 index 000000000..88594c1b9 --- /dev/null +++ b/examples/bajo1_usecases/UsecaseSix.jav @@ -0,0 +1,14 @@ +class UsecaseSix{ + + umu(Character c){ + x; + return x; + } + + void foo(bar){ + y; + y = 5; + y = this.umu(bar); + } + +} \ No newline at end of file diff --git a/examples/bajo1_usecases/UsecaseThree.jav b/examples/bajo1_usecases/UsecaseThree.jav new file mode 100755 index 000000000..248964e44 --- /dev/null +++ b/examples/bajo1_usecases/UsecaseThree.jav @@ -0,0 +1,20 @@ +class UsecaseThree{ + Boolean m_Zulu; + + foo(bar, umu, Stack lala, num){ + ret; + { + bar = 5; + { + myTestVar; + myTestVar = lala; + } + { + myTestVar; + myTestVar = m_Zulu && true; + } + } + ret = (num+3)==8; + return ret; + } +} \ No newline at end of file diff --git a/examples/bajo1_usecases/UsecaseTwo.jav b/examples/bajo1_usecases/UsecaseTwo.jav new file mode 100755 index 000000000..2712c16d5 --- /dev/null +++ b/examples/bajo1_usecases/UsecaseTwo.jav @@ -0,0 +1,6 @@ +class UsecaseTwo{ + foo(bar){ + bar = new Integer(3); + return bar!=2; + } +} \ No newline at end of file diff --git a/examples/feda/feda.jav b/examples/feda/feda.jav new file mode 100755 index 000000000..8afc79fdb --- /dev/null +++ b/examples/feda/feda.jav @@ -0,0 +1,25 @@ +package none; + +import java.util.Vector; +import java.util.Stack; + +interface GeomObjektTrans { + void verschieben(); + void strecken(); +} + +public class Hello { + public static void main(String[] args) { + + } +} + +public class Quadrat implements GeomObjektTrans { + public strecken(a,b){ + return a*b; + } + public void verschieben(){ + + } + +} \ No newline at end of file diff --git a/examples/feda/feda2.jav b/examples/feda/feda2.jav new file mode 100755 index 000000000..c20f7245b --- /dev/null +++ b/examples/feda/feda2.jav @@ -0,0 +1,8 @@ +class Daniel { + static void drinkCoffee() { + + } + public void soso() { + Daniel.drinkCoffee(); + } +} \ No newline at end of file diff --git a/examples/feda/feda3.jav b/examples/feda/feda3.jav new file mode 100755 index 000000000..720050264 --- /dev/null +++ b/examples/feda/feda3.jav @@ -0,0 +1,4 @@ +interface GeomObjektTrans { + void verschieben(); + void strecken(); + } \ No newline at end of file diff --git a/examples/feda/feda4.jav b/examples/feda/feda4.jav new file mode 100755 index 000000000..99ce821c2 --- /dev/null +++ b/examples/feda/feda4.jav @@ -0,0 +1,17 @@ +public class Auto { + + tachoStand; + + public void fahren(distanz) { + tachoStand = tachoStand + distanz; + } + + public void abschleppen(auto, distanz) { + auto.fahren(distanz); + } + public static void main(String[] args) { + meinPKW.fahren(100); + bmw.fahren(100); + bmw.fahren(100); + } + } \ No newline at end of file diff --git a/examples/feda/quadrat.jav b/examples/feda/quadrat.jav new file mode 100755 index 000000000..11a26c39d --- /dev/null +++ b/examples/feda/quadrat.jav @@ -0,0 +1,20 @@ +public class Quadrat { + public machwas(){ + + return " Daniel" ; + } + + public static drinken(){ + return " Daniel drinkt was"; + } + +} + +public class Sohalt { + + public machwas2(){ + + + return Quadrat.drinken(); + } +} \ No newline at end of file diff --git a/examples/hoth/Test.jav b/examples/hoth/Test.jav new file mode 100755 index 000000000..d43d919c2 --- /dev/null +++ b/examples/hoth/Test.jav @@ -0,0 +1,15 @@ +class Test { + + public getValue(a){ + String x; + + Stack s = new Stack(); + a=s; + d; + d.addElement("33"); + x=x; + + +return x; + } } + diff --git a/examples/hoth/Test2.jav b/examples/hoth/Test2.jav new file mode 100755 index 000000000..6dc6bbce0 --- /dev/null +++ b/examples/hoth/Test2.jav @@ -0,0 +1,23 @@ +class Test2{ + String b="33"; + + foo(){ + ret; + String g="w"; + { + ret = 5; + g="5"; + } + ret = 3+4; + b="22"; + return ret; + } + + int neufoo(a) + { + tt; + tt=foo(); + a="ww"; + return 3; + } +} \ No newline at end of file diff --git a/examples/hoti/BoundedClassPara.jav b/examples/hoti/BoundedClassPara.jav new file mode 100755 index 000000000..d0595ee34 --- /dev/null +++ b/examples/hoti/BoundedClassPara.jav @@ -0,0 +1,10 @@ +class Gen { + public doSomething(X num){ + } +} + +class Test{ + public void test(x){ + x.doSomething(""); + } +} \ No newline at end of file diff --git a/examples/hoti/Constr.jav b/examples/hoti/Constr.jav new file mode 100755 index 000000000..c878748fb --- /dev/null +++ b/examples/hoti/Constr.jav @@ -0,0 +1,18 @@ +public class Constr{ + String name; + public Constr(x){ + name=x; + } + +} + + +public class Test{ + + public void test(){ + a; + Constr x; + x=new Constr(a); + } + +} \ No newline at end of file diff --git a/examples/hoti/EmptyResultProblem.jav b/examples/hoti/EmptyResultProblem.jav new file mode 100755 index 000000000..a181746bd --- /dev/null +++ b/examples/hoti/EmptyResultProblem.jav @@ -0,0 +1,9 @@ +class Empty{ + hasenfuss(){ + } +} +class User{ + testProblem(x){ + x.hasenfuss(); + } +} \ No newline at end of file diff --git a/examples/hoti/ErrorTest.jav b/examples/hoti/ErrorTest.jav new file mode 100755 index 000000000..31cb3b9af --- /dev/null +++ b/examples/hoti/ErrorTest.jav @@ -0,0 +1,13 @@ + public class MyInterface { + public String convert(String x, Integer mode){ + return(""); + } +} + +public class Test{ + public void test(x){ + y; + z; + y=x.convert(z,1); + } +} diff --git a/examples/hoti/Generic.jav b/examples/hoti/Generic.jav new file mode 100755 index 000000000..cb55e9fdb --- /dev/null +++ b/examples/hoti/Generic.jav @@ -0,0 +1,22 @@ +public class Generic extends Tester +{ + + X elem; + + public setElement(e){ + elem=e; + } + + public X getElement(){ + return elem; + } + +} + +public class Tester{ + public meth(String e){ + x; + x.setElement(""); + return(x.getElement()); + } +} \ No newline at end of file diff --git a/examples/hoti/GenericMethod.jav b/examples/hoti/GenericMethod.jav new file mode 100755 index 000000000..270da7903 --- /dev/null +++ b/examples/hoti/GenericMethod.jav @@ -0,0 +1,8 @@ +class Test { + addElement2(E elem){ + return(elem); + } + test(x){ + x.addElement2(new Number()); + } +} \ No newline at end of file diff --git a/examples/hoti/GenericsTest.jav b/examples/hoti/GenericsTest.jav new file mode 100755 index 000000000..b015c17a9 --- /dev/null +++ b/examples/hoti/GenericsTest.jav @@ -0,0 +1,15 @@ +import java.util.Vector; + +public class Test{ + + public X method(a){ + return(a); + } + +} + +public class Inst{ + public inst(b){ + return(b.method("HALLO")); + } +} \ No newline at end of file diff --git a/examples/hoti/Id.jav b/examples/hoti/Id.jav new file mode 100755 index 000000000..e338d04b9 --- /dev/null +++ b/examples/hoti/Id.jav @@ -0,0 +1,17 @@ +class Helper{ + public id(x){ + return(x); + } +} + +class User{ + public test(Integer input1, String input2){ + x; + x=new Helper(); + a; + a=x.id(input1); + b; + b=x.id(input2); + + } +} \ No newline at end of file diff --git a/examples/hoti/ImplClass.jav b/examples/hoti/ImplClass.jav new file mode 100755 index 000000000..7099d5020 --- /dev/null +++ b/examples/hoti/ImplClass.jav @@ -0,0 +1,5 @@ +public class ImplClass implements Test{ + + + +} \ No newline at end of file diff --git a/examples/hoti/Import.jav b/examples/hoti/Import.jav new file mode 100755 index 000000000..d79b1871d --- /dev/null +++ b/examples/hoti/Import.jav @@ -0,0 +1,10 @@ +package none; + +import java.util.Vector; +import java.util.Stack; + +public class Test{ + test(Vector x){ + x.addElement(""); + } +} \ No newline at end of file diff --git a/examples/hoti/Intf.jav b/examples/hoti/Intf.jav new file mode 100755 index 000000000..5fe463636 --- /dev/null +++ b/examples/hoti/Intf.jav @@ -0,0 +1,18 @@ +/*interface Intf { + E test2(E para1); +} +class Test{ + public test(String x){ + a; + return(a.test2(x)); + } +}*/ + +interface Intf{ + doSomething(); +} +class Test{ + public test(x){ + x.doSomething(); + } +} \ No newline at end of file diff --git a/examples/hoti/IntfTest.jav b/examples/hoti/IntfTest.jav new file mode 100755 index 000000000..a4993a34c --- /dev/null +++ b/examples/hoti/IntfTest.jav @@ -0,0 +1,15 @@ +interface Intf1{ +} +interface Intf2{ +} +class Gesucht implements Intf1, Intf2{ + doSomething(){ + } +} + +class Test{ + public test(x){ + x.doSomething(); + return(x); + } +} \ No newline at end of file diff --git a/examples/hoti/Matrix.jav b/examples/hoti/Matrix.jav new file mode 100755 index 000000000..87f28a6fd --- /dev/null +++ b/examples/hoti/Matrix.jav @@ -0,0 +1,35 @@ +import java.util.Vector; + +class Matrix extends Vector> { + + mul(m){ + Vector> ret; + ret = new Matrix(); + i; + i = 0; + while(i (); + j; + j = 0; + while(j < v1.size()) { + erg; + erg = 0; + k; + k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k).intValue() * m.elementAt(k).elementAt(j).intValue(); + k++; + } + v2.addElement(new Integer(erg)); + j++; + } + ret.addElement(v2); + i++; + } + return ret; + } + +} diff --git a/examples/hoti/Mehrfachvererbung.jav b/examples/hoti/Mehrfachvererbung.jav new file mode 100755 index 000000000..f6b5943ea --- /dev/null +++ b/examples/hoti/Mehrfachvererbung.jav @@ -0,0 +1,14 @@ +interface Intf1{ +} +interface Intf2{ +} +class Gesucht implements Intf1, Intf2{ + +} + +class Test{ + public test(x){ + x=new Intf1(); + x=new Intf2(); + } +} diff --git a/examples/hoti/Multiclass.jav b/examples/hoti/Multiclass.jav new file mode 100755 index 000000000..f3d2fff52 --- /dev/null +++ b/examples/hoti/Multiclass.jav @@ -0,0 +1,11 @@ +public class Blubb extends Timo {} + +public class Timo extends Holzherr { + public test2( ){ + + x; + x = "blubb"; + x = 10; + + } +} diff --git a/examples/hoti/Overl.jav b/examples/hoti/Overl.jav new file mode 100755 index 000000000..ad0df64e4 --- /dev/null +++ b/examples/hoti/Overl.jav @@ -0,0 +1,24 @@ +class Overl{ + + public Integer overloaded(a){ + return(a); + } + public String overloaded(b){ + return(b); + } + +} + +class OverlMaster extends Overl{ + public X overloaded(a){ + return(a); + } +} + +class Test{ + public Boolean test(Boolean b){ + c; + return(c.overloaded(b)); + } + +} \ No newline at end of file diff --git a/examples/hoti/ReturnTypeProblem.jav b/examples/hoti/ReturnTypeProblem.jav new file mode 100755 index 000000000..4fccddfa1 --- /dev/null +++ b/examples/hoti/ReturnTypeProblem.jav @@ -0,0 +1,7 @@ +class Test{ + public Boolean test(Boolean b,c){ + c=b; + return(c); + } + +} \ No newline at end of file diff --git a/examples/hoti/Simple.jav b/examples/hoti/Simple.jav new file mode 100755 index 000000000..af04c73f8 --- /dev/null +++ b/examples/hoti/Simple.jav @@ -0,0 +1,5 @@ +public class Timo { + public E getElement(E x){ + return(x); + } +} \ No newline at end of file diff --git a/examples/hoti/Simple2.jav b/examples/hoti/Simple2.jav new file mode 100755 index 000000000..ae86be6cc --- /dev/null +++ b/examples/hoti/Simple2.jav @@ -0,0 +1,10 @@ +import java.util.Stack; + +class Simple2{ + Vector test(Boolean first){ + x; + x=new Vector(); + x=new Stack(); + return(x); + } +} \ No newline at end of file diff --git a/examples/hoti/Test.jav b/examples/hoti/Test.jav new file mode 100755 index 000000000..314aa2122 --- /dev/null +++ b/examples/hoti/Test.jav @@ -0,0 +1,14 @@ +interface AA {} + +interface BB {} + +class CC implements AA, BB {} + +class BoundedTypeVar { + CC c; + & BB> m(T x) { + m(new CC()); + x = new CC(); + } +} + diff --git a/examples/hoti/Test2.jav b/examples/hoti/Test2.jav new file mode 100755 index 000000000..5930c3b80 --- /dev/null +++ b/examples/hoti/Test2.jav @@ -0,0 +1,9 @@ +class Test2 { + public meth(){ + if(true) { + return(1); + }else{ + return(2); + } + } +} \ No newline at end of file diff --git a/examples/hoti/Test3.jav b/examples/hoti/Test3.jav new file mode 100755 index 000000000..eb04b0788 --- /dev/null +++ b/examples/hoti/Test3.jav @@ -0,0 +1,9 @@ +import java.util.Vector; + +public class Test3 { + + public getValue(a,String y){ + a.addElement(y); + return(y); + } +} \ No newline at end of file diff --git a/examples/hoti/VectorStack.jav b/examples/hoti/VectorStack.jav new file mode 100755 index 000000000..f4f8e80b6 --- /dev/null +++ b/examples/hoti/VectorStack.jav @@ -0,0 +1,10 @@ +import java.util.Vector; + +public class VectorStack { + + public test(x,y){ + x.addElement("TEST"); + return(x.elementAt(y)); + } + +} \ No newline at end of file diff --git a/examples/hoti/VectorTest.jav b/examples/hoti/VectorTest.jav new file mode 100755 index 000000000..9ce42f9b3 --- /dev/null +++ b/examples/hoti/VectorTest.jav @@ -0,0 +1,13 @@ +import java.util.Stack; +import java.util.Hashtable; + +public class VectorTest{ + + public test(x){ + b; + b=1; + a; + a=x+b; + } + +} \ No newline at end of file diff --git a/examples/hoti/VererbProb.jav b/examples/hoti/VererbProb.jav new file mode 100755 index 000000000..e504fc42a --- /dev/null +++ b/examples/hoti/VererbProb.jav @@ -0,0 +1,23 @@ +public class M1{} + +public class M2 extends M1 {} + +public class Test { + + public doSomething(Boolean big){ + M2 ret; + + ret1; + ret2; + + ret1=new M2(); + ret2=new M2(); + + if(big){ + ret=ret1; + }else{ + ret=ret2; + } + return(ret); + } +} \ No newline at end of file diff --git a/examples/hoti/WorkerExample.jav b/examples/hoti/WorkerExample.jav new file mode 100755 index 000000000..1e7073939 --- /dev/null +++ b/examples/hoti/WorkerExample.jav @@ -0,0 +1,17 @@ +class Worker1{ + void doSomething(String x){} + } + class Worker2{ + void doSomething(Integer y){} + } + class Content1{ + String getElem(){return("");} + } + class Content2{ + Integer getElem(){return(1);} + } + class User{ + meth(worker,content){ + worker.doSomething(content.getElem()); + } + } \ No newline at end of file diff --git a/examples/hoti/arne.jav b/examples/hoti/arne.jav new file mode 100755 index 000000000..9b564ca8f --- /dev/null +++ b/examples/hoti/arne.jav @@ -0,0 +1,10 @@ +import java.util.Stack; + +class Arne { + +drinkCoffee(x) { + x.push("Hallo"); + String y = x.pop(); +} + +} \ No newline at end of file diff --git a/examples/hoti/hothtest.jav b/examples/hoti/hothtest.jav new file mode 100755 index 000000000..f89221ff5 --- /dev/null +++ b/examples/hoti/hothtest.jav @@ -0,0 +1,9 @@ +public class Test{ + public test(y){ + c; + c=5; + d; + d=5; + y=c+d; + } +} \ No newline at end of file diff --git a/examples/lambda/general.jav b/examples/lambda/general.jav new file mode 100644 index 000000000..754ed70cd --- /dev/null +++ b/examples/lambda/general.jav @@ -0,0 +1,23 @@ +//package LampdaExpressions; + +import java.util.concurrent.Callable; + +public class general extends Vector> { + + + + public String test(String c) throws Exception { + Callable halloLambda; + a; + a = () -> {return "hallo";}; + a = a + 1; + return a.call(); + } + + + + public String test2(){ + return "hallo"; + } + +} diff --git a/examples/lambda/test1.jav b/examples/lambda/test1.jav new file mode 100644 index 000000000..0db0e868f --- /dev/null +++ b/examples/lambda/test1.jav @@ -0,0 +1,6 @@ +class Matrix extends Vector> { + method(){ + op; + op = "test"; + } +} \ No newline at end of file diff --git a/examples/lambda/test2.jav b/examples/lambda/test2.jav new file mode 100644 index 000000000..cba63ff1f --- /dev/null +++ b/examples/lambda/test2.jav @@ -0,0 +1,3 @@ +class Matrix extends Vector> { + op = (m) -> (f) -> f.apply(this, m); +} \ No newline at end of file diff --git a/examples/luar/TestSmall.jav b/examples/luar/TestSmall.jav new file mode 100755 index 000000000..d3213a1f0 --- /dev/null +++ b/examples/luar/TestSmall.jav @@ -0,0 +1,12 @@ +class TestSmall +{ + void test() + { + x; + x = "Hallo"; + i; + i = 17; + j; + j = i; + } +} \ No newline at end of file diff --git a/examples/luar/WCParseTest.jav b/examples/luar/WCParseTest.jav new file mode 100755 index 000000000..50a5de5b0 --- /dev/null +++ b/examples/luar/WCParseTest.jav @@ -0,0 +1,20 @@ +import java.util.Vector; + +class WCTest{ + + void test() + { + Vector> v1 = new Vector>(); + } + +} + +class Sub1 {} + +class Sub2 extends Sub1 {} + +class Sub3 extends Sub2 {} + +class N {} + +class Test extends N> {} \ No newline at end of file diff --git a/examples/luar/WCTest1.jav b/examples/luar/WCTest1.jav new file mode 100755 index 000000000..e3f1f4413 --- /dev/null +++ b/examples/luar/WCTest1.jav @@ -0,0 +1,23 @@ + +Vector Vector> + + +Vector Vector> + +class A { } +class B extends A { } +class D { } +class E extends D,b> { } + +class Number {} +class Integer extends Number {} + +class AbstractList extends List {} +class List {} +class Vector extends List {} +class Stack extends Vector {} +class Test extends Vector {} + +/*D, ? extends A> Test,A>*/ +/*D, D> D, ? super E>*/ +/*Stack Vector AbstractList List*/ \ No newline at end of file diff --git a/examples/luar/WCTest10.jav b/examples/luar/WCTest10.jav new file mode 100755 index 000000000..d801732ef --- /dev/null +++ b/examples/luar/WCTest10.jav @@ -0,0 +1,17 @@ +/* Vector> Vector> */ + +/* FUNKTIONIERT!! */ + +Big2,d,e,f> BigBig2 + +/* Funktioniert auch!!! */ + +class Big extends BigBig {} +class BigBig {} + +class Big2 extends BigBig2 {} +class BigBig2 {} + +class Vector {} +class Integer extends Number {} +class Number {} \ No newline at end of file diff --git a/examples/luar/WCTest11.jav b/examples/luar/WCTest11.jav new file mode 100755 index 000000000..cb4c9082a --- /dev/null +++ b/examples/luar/WCTest11.jav @@ -0,0 +1,47 @@ +Vector Vector +/* Vector Vector> */ +/* Erg.: +[[(TPH a = Vector< Integer >), (TPH b = Matrix)], + [(TPH a = Vector< Integer >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< Integer >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< Integer >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< ? extends Integer >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< ? extends Integer >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< ? extends Number >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< ? extends Number >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< ? extends Object >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< ? extends Object >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< ? super Integer >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< ? super Integer >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Object), (TPH b = Matrix)], + [(TPH a = ? extends Object), (TPH b = ? extends Matrix)], + [(TPH a = ? super Vector< Integer >), (TPH b = Matrix)], + [(TPH a = ? super Vector< Integer >), (TPH b = ? extends Matrix)], + [(TPH a = Vector< Integer >), (TPH b = ExtMatrix)], + [(TPH a = Vector< Integer >), (TPH b = ? extends ExtMatrix)], + [(TPH a = ? extends Vector< Integer >), (TPH b = ExtMatrix)], + [(TPH a = ? extends Vector< Integer >), (TPH b = ? extends ExtMatrix)], + [(TPH a = ? extends Vector< ? extends Integer >), (TPH b = ExtMatrix)], + [(TPH a = ? extends Vector< ? extends Integer >), (TPH b = ? extends ExtMatrix)], + [(TPH a = ? extends Vector< ? extends Number >), (TPH b = ExtMatrix)], + [(TPH a = ? extends Vector< ? extends Number >), (TPH b = ? extends ExtMatrix)], + [(TPH a = ? extends Vector< ? extends Object >), (TPH b = ExtMatrix)], + [(TPH a = ? extends Vector< ? extends Object >), (TPH b = ? extends ExtMatrix)], + [(TPH a = ? extends Vector< ? super Integer >), (TPH b = ExtMatrix)], + [(TPH a = ? extends Vector< ? super Integer >), (TPH b = ? extends ExtMatrix)], + [(TPH a = ? extends Object), (TPH b = ExtMatrix)], + [(TPH a = ? extends Object), (TPH b = ? extends ExtMatrix)], + [(TPH a = ? super Vector< Integer >), (TPH b = ExtMatrix)], + [(TPH a = ? super Vector< Integer >), (TPH b = ? extends ExtMatrix)], + [(TPH b = Vector< TPH a >)], + [(TPH b = ? extends Vector< TPH a >)]] +*/ + +class Number {} +class Integer extends Number {} + +class Vector { } + +class Matrix extends Vector> { } + +class ExtMatrix extends Matrix { } \ No newline at end of file diff --git a/examples/luar/WCTest2.jav b/examples/luar/WCTest2.jav new file mode 100755 index 000000000..4aae3f01e --- /dev/null +++ b/examples/luar/WCTest2.jav @@ -0,0 +1,12 @@ +Stack Vector +AbstractList List + +/* funktioniert */ + +class Number {} +class Integer extends Number {} + +class AbstractList extends List {} +class List {} +class Vector extends List {} +class Stack extends Vector {} \ No newline at end of file diff --git a/examples/luar/WCTest3.jav b/examples/luar/WCTest3.jav new file mode 100755 index 000000000..42525f114 --- /dev/null +++ b/examples/luar/WCTest3.jav @@ -0,0 +1,9 @@ +List List> + +/* funktioniert */ + +class Number {} +class Integer extends Number {} + +class myLi extends List {} +class List {} \ No newline at end of file diff --git a/examples/luar/WCTest4.jav b/examples/luar/WCTest4.jav new file mode 100755 index 000000000..a9eca71e5 --- /dev/null +++ b/examples/luar/WCTest4.jav @@ -0,0 +1,11 @@ +Matrix Vector + +/* Fehler behoben. Korrekt? + sieht gut aus PL 07-07-09 */ + +class Number {} +class Integer extends Number {} + +class Vector { } + +class Matrix extends Vector> { } \ No newline at end of file diff --git a/examples/luar/WCTest5.jav b/examples/luar/WCTest5.jav new file mode 100755 index 000000000..a6d1a73d0 --- /dev/null +++ b/examples/luar/WCTest5.jav @@ -0,0 +1,71 @@ +/* Vector Vector> */ +/* Erg: +[[(TPH a = Vector< Integer >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< Integer >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< ? extends Integer >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< ? extends Number >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< ? extends Object >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Vector< ? super Integer >), (TPH b = ? extends Matrix)], + [(TPH a = ? extends Object), (TPH b = ? extends Matrix)], + [(TPH a = ? super Vector< Integer >), (TPH b = ? extends Matrix)], + [(TPH a = Vector< Integer >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< Integer >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< ? extends Integer >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< ? extends Number >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< ? extends Object >), (TPH b = Matrix)], + [(TPH a = ? extends Vector< ? super Integer >), (TPH b = Matrix)], + [(TPH a = ? extends Object), (TPH b = Matrix)], + [(TPH a = ? super Vector< Integer >), (TPH b = Matrix)], + [(TPH b = ? extends Vector< TPH a >)], + [(TPH b = Vector< TPH a >)]] + */ +/* FUNKTIONIERT !!! */ + + +/* Fehler bei b : + Reflexivitaet fehlt: b = Vec bzw. b = ? ext Vec wird nicht berechnet + isRXSimilarRY ist wahrscheinlich die falsche Methode, hier wird geprueft, + ob RY instance von RFC ist. Das ist bei RY = Vec und RFC = Vec> + nicht der Fall. Moeglicherweise statt isRXSimilarRY match benutzen ??? + + PL 07-07-04: isRXSimilarRY scheint jetzt zu funktionieren. + Reflexivitaet fehlt noch + */ + +/* Fehler behoben. Korrekt? */ + + + /* Vector> Vector */ + + /* FUNKTIONIERT !!! nochmals ueberpruefen 07-07-29 */ + +/* Vector Vector> */ +/* Test der 3. Menge. FUNKTIONIERT !!! nochmals ueberpruefen 07-07-29 */ + +/* Vector Vector */ +/* Test der 4. Menge. FUNKTIONIERT !!! nochmals ueberpruefen 07-07-29 */ + +Vector Vector>> +/* funktioniert. Ergebnis: +[[(TPH b = Integer), (TPH a = ? extends Matrix)], + [(TPH b = Integer), (TPH a = Matrix)], + [(TPH b = ? extends Integer), (TPH a = ? extends Matrix)], + [(TPH b = ? extends Integer), (TPH a = Matrix)], + [(TPH b = ? extends Number), (TPH a = ? extends Matrix)], + [(TPH b = ? extends Number), (TPH a = Matrix)], + [(TPH b = ? extends Object), (TPH a = ? extends Matrix)], + [(TPH b = ? extends Object), (TPH a = Matrix)], + [(TPH b = ? super Integer), (TPH a = ? extends Matrix)], + [(TPH b = ? super Integer), (TPH a = Matrix)], + [(TPH a = ? extends Vector< ? extends Vector< TPH b > >)], + [(TPH a = Vector< ? extends Vector< TPH b > >)], + [(TPH a = ? extends Vector< Vector< TPH b > >)], + [(TPH a = Vector< Vector< TPH b > >)]] */ + + +class Number {} +class Integer extends Number {} + +class Vector { } + +class Matrix extends Vector> { } \ No newline at end of file diff --git a/examples/luar/WCTest6.jav b/examples/luar/WCTest6.jav new file mode 100755 index 000000000..307654709 --- /dev/null +++ b/examples/luar/WCTest6.jav @@ -0,0 +1,13 @@ +Vector Vector> + +/* Nach Sub_unify + FUNKTIONIERT !!! */ + +/* muss noch nac der 2. Menge angepasst werden PL 07-08-03 + +class Number {} +class Integer extends Number {} + +class Vector { } + +class Matrix extends Vector> { } \ No newline at end of file diff --git a/examples/luar/WCTest7.jav b/examples/luar/WCTest7.jav new file mode 100755 index 000000000..c14975d56 --- /dev/null +++ b/examples/luar/WCTest7.jav @@ -0,0 +1,120 @@ +/* VecPair Vector> */ +/* Funktioniert !!! +*/ + +/* VecPair Vector> */ +/* Funktioniert !!! + */ + +/* VecPair Vector> */ +/* Funktioniert !!! */ + +/* Vector> Vector */ +/* Funktioniert !!! nochmals ueberpruefen 07-07-29 */ + +/* VecPair Vector> */ +/* Funktioniert kein Unifier!!! */ + +/* VecPair Vector> */ +/* Funktioniert!!! */ + + +/* Vector Vector>> */ +/* funktioniert */ +/* Erg.: +[[(TPH a = TPH A), (TPH c = Integer), (TPH b = ? extends VecPair< TPH A, TPH B >)], + [(TPH a = TPH A), (TPH c = Integer), (TPH b = VecPair< TPH A, TPH B >)], + [(TPH b = ? extends Vector< Pair< TPH a, TPH c > >)], + [(TPH b = Vector< Pair< TPH a, TPH c > >)]] +*/ + +/* Vector Vector>> */ +/* Erg: +[[(TPH c = Integer), (TPH b = VecPair< Number, TPH B >)], + [(TPH c = Integer), (TPH b = ? extends VecPair< Number, TPH B >)], + [(TPH b = Vector< Pair< Number, TPH c > >)], + [(TPH b = ? extends Vector< Pair< Number, TPH c > >)]] +*/ + +/* Vector Vector> */ +/* Erg.: +[[(TPH a = Pair< TPH A, Integer >), (TPH b = ? extends VecPair< TPH A, TPH B >)], + [(TPH a = Pair< TPH A, Integer >), (TPH b = VecPair< TPH A, TPH B >)], + [(TPH a = ? extends Pair< TPH A, Integer >), (TPH b = ? extends VecPair< TPH A, TPH C >)], + [(TPH a = ? extends Pair< TPH A, Integer >), (TPH b = VecPair< TPH A, TPH C >)], + [(TPH a = ? extends Pair< TPH A, ? extends Integer >), (TPH b = ? extends VecPair< TPH A, TPH D >)], + [(TPH a = ? extends Pair< TPH A, ? extends Integer >), (TPH b = VecPair< TPH A, TPH D >)], + [(TPH a = ? extends Pair< TPH A, ? extends Number >), (TPH b = ? extends VecPair< TPH A, TPH E >)], + [(TPH a = ? extends Pair< TPH A, ? extends Number >), (TPH b = VecPair< TPH A, TPH E >)], + [(TPH a = ? extends Pair< TPH A, ? extends Object >), (TPH b = ? extends VecPair< TPH A, TPH F >)], + [(TPH a = ? extends Pair< TPH A, ? extends Object >), (TPH b = VecPair< TPH A, TPH F >)], + [(TPH a = ? extends Pair< TPH A, ? super Integer >), (TPH b = ? extends VecPair< TPH A, TPH G >)], + [(TPH a = ? extends Pair< TPH A, ? super Integer >), (TPH b = VecPair< TPH A, TPH G >)], + [(TPH a = ? extends Object), (TPH b = ? extends VecPair< TPH A, TPH H >)], + [(TPH a = ? extends Object), (TPH b = VecPair< TPH A, TPH H >)], + [(TPH a = ? super Pair< TPH A, Integer >), (TPH b = ? extends VecPair< TPH A, TPH I >)], + [(TPH a = ? super Pair< TPH A, Integer >), (TPH b = VecPair< TPH A, TPH I >)], + [(TPH b = ? extends Vector< TPH a >)], + [(TPH b = Vector< TPH a >)]] +*/ + + +/* Vector> Vector> */ +/* funktioniert */ +/* Erg. +[[(TPH a = Pair< Number, Integer >)], + [(TPH a = ? extends Pair< Number, Integer >)], + [(TPH a = ? extends Pair< Number, ? extends Integer >)], + [(TPH a = ? extends Pair< Number, ? extends Number >)], + [(TPH a = ? extends Pair< Number, ? extends Object >)], + [(TPH a = ? extends Pair< Number, ? super Integer >)], + [(TPH a = ? extends Pair< ? extends Number, Integer >)], + [(TPH a = ? extends Pair< ? extends Number, ? extends Integer >)], + [(TPH a = ? extends Pair< ? extends Number, ? extends Number >)], + [(TPH a = ? extends Pair< ? extends Number, ? extends Object >)], + [(TPH a = ? extends Pair< ? extends Number, ? super Integer >)], + [(TPH a = ? extends Pair< ? extends Object, Integer >)], + [(TPH a = ? extends Pair< ? extends Object, ? extends Integer >)], + [(TPH a = ? extends Pair< ? extends Object, ? extends Number >)], + [(TPH a = ? extends Pair< ? extends Object, ? extends Object >)], + [(TPH a = ? extends Pair< ? extends Object, ? super Integer >)], + [(TPH a = ? extends Pair< ? super Number, Integer >)], + [(TPH a = ? extends Pair< ? super Number, ? extends Integer >)], + [(TPH a = ? extends Pair< ? super Number, ? extends Number >)], + [(TPH a = ? extends Pair< ? super Number, ? extends Object >)], + [(TPH a = ? extends Pair< ? super Number, ? super Integer >)], + [(TPH a = ? extends Pair< ? super Integer, Integer >)], + [(TPH a = ? extends Pair< ? super Integer, ? extends Integer >)], + [(TPH a = ? extends Pair< ? super Integer, ? extends Number >)], + [(TPH a = ? extends Pair< ? super Integer, ? extends Object >)], + [(TPH a = ? extends Pair< ? super Integer, ? super Integer >)], + [(TPH a = ? extends Object)], + [(TPH a = ? super Pair< Number, Integer >)]] + */ + +/* Vector Vector>> */ + /* Erg. stimmt + [[[(TPH c = Integer), (TPH b = ? extends VecPair< Number, TPH B >)], + [(TPH c = Integer), (TPH b = VecPair< Number, TPH B >)], + [(TPH c = ? extends Integer), (TPH b = ? extends VecPair< Number, TPH C >)], + [(TPH c = ? extends Integer), (TPH b = VecPair< Number, TPH C >)], + [(TPH c = ? extends Number), (TPH b = ? extends VecPair< Number, TPH D >)], + [(TPH c = ? extends Number), (TPH b = VecPair< Number, TPH D >)], + [(TPH c = ? extends Object), (TPH b = ? extends VecPair< Number, TPH E >)], + [(TPH c = ? extends Object), (TPH b = VecPair< Number, TPH E >)], + [(TPH c = ? super Integer), (TPH b = ? extends VecPair< Number, TPH F >)], + [(TPH c = ? super Integer), (TPH b = VecPair< Number, TPH F >)], + [(TPH b = ? extends Vector< ? extends Pair< Number, TPH c > >)], + [(TPH b = Vector< ? extends Pair< Number, TPH c > >)], + [(TPH b = ? extends Vector< Pair< Number, TPH c > >)], + [(TPH b = Vector< Pair< Number, TPH c > >)]] + */ + +class Number {} +class Integer extends Number {} + +class Vector { } + +class Pair { } + +class VecPair extends Vector> { } \ No newline at end of file diff --git a/examples/luar/WCTest8.jav b/examples/luar/WCTest8.jav new file mode 100755 index 000000000..bb186800e --- /dev/null +++ b/examples/luar/WCTest8.jav @@ -0,0 +1,25 @@ +/* Subtype Vector> OK */ + +/* Subtype Vector> */ + +/* Korrekt */ + +/* Vector> Vector>> */ + +/* Super, FUNKTIONIERT!!! */ + +/* Vector> Vector> */ + +/* redureSup Test: FUNKTIONIERT!!! */ + +class Number {} +class Integer extends Number {} + +class List { } + +class Vector extends List { } + +class Pair { } + + +class Subtype extends Vector> { } \ No newline at end of file diff --git a/examples/luar/WCTest9.jav b/examples/luar/WCTest9.jav new file mode 100755 index 000000000..939a129e9 --- /dev/null +++ b/examples/luar/WCTest9.jav @@ -0,0 +1,14 @@ + + +Subtype Pair + +/* nochmals pruefen koennte aber stimmen */ + +class Number {} +class Integer extends Number {} + +class Vector { } + +class Pair { } + +class Subtype extends Pair { } \ No newline at end of file diff --git a/examples/mema_usecases/UsecaseFive.jav b/examples/mema_usecases/UsecaseFive.jav new file mode 100755 index 000000000..9078f0dd5 --- /dev/null +++ b/examples/mema_usecases/UsecaseFive.jav @@ -0,0 +1,8 @@ +class UsecaseFive{ + + foo(bar){ + bar.addElement(new Integer()); + return bar; + } + +} \ No newline at end of file diff --git a/examples/mema_usecases/UsecaseFour.jav b/examples/mema_usecases/UsecaseFour.jav new file mode 100755 index 000000000..b4319c97b --- /dev/null +++ b/examples/mema_usecases/UsecaseFour.jav @@ -0,0 +1,10 @@ +class UsecaseFour{ + foo(bla, Stack blub){ + return (1!=2) && true; + } + + bar(dipsy, Stack laalaa, po){ + dipsy = this.foo(laalaa, po); + return dipsy; + } +} \ No newline at end of file diff --git a/examples/mema_usecases/UsecaseOne.jav b/examples/mema_usecases/UsecaseOne.jav new file mode 100755 index 000000000..26ab4e50b --- /dev/null +++ b/examples/mema_usecases/UsecaseOne.jav @@ -0,0 +1,6 @@ +class UsecaseOne extends Vector{ + foo(bar){ + SchorschKlasse x; + return 3; + } +} \ No newline at end of file diff --git a/examples/mema_usecases/UsecaseThree.jav b/examples/mema_usecases/UsecaseThree.jav new file mode 100755 index 000000000..248964e44 --- /dev/null +++ b/examples/mema_usecases/UsecaseThree.jav @@ -0,0 +1,20 @@ +class UsecaseThree{ + Boolean m_Zulu; + + foo(bar, umu, Stack lala, num){ + ret; + { + bar = 5; + { + myTestVar; + myTestVar = lala; + } + { + myTestVar; + myTestVar = m_Zulu && true; + } + } + ret = (num+3)==8; + return ret; + } +} \ No newline at end of file diff --git a/examples/mema_usecases/UsecaseTwo.jav b/examples/mema_usecases/UsecaseTwo.jav new file mode 100755 index 000000000..eb954cba6 --- /dev/null +++ b/examples/mema_usecases/UsecaseTwo.jav @@ -0,0 +1,6 @@ +class UsecaseTwo{ + foo(bar){ + bar = 3; + return bar!=2; + } +} \ No newline at end of file diff --git a/examples/mema_usecases/UsecaseZero.jav b/examples/mema_usecases/UsecaseZero.jav new file mode 100755 index 000000000..b7f0eec06 --- /dev/null +++ b/examples/mema_usecases/UsecaseZero.jav @@ -0,0 +1,5 @@ +class UsecaseZero{ + foo(bar){ + return (4*(3-2))>2; + } +} \ No newline at end of file diff --git a/examples/pl_usecases/AchimTest1.jav b/examples/pl_usecases/AchimTest1.jav new file mode 100755 index 000000000..35d7739d5 --- /dev/null +++ b/examples/pl_usecases/AchimTest1.jav @@ -0,0 +1,9 @@ +class Test{ + test(){ + return 1; + } + test2(){ + i; + i = test(); + } +} diff --git a/examples/pl_usecases/BoundedType.jav b/examples/pl_usecases/BoundedType.jav new file mode 100755 index 000000000..ca33735a7 --- /dev/null +++ b/examples/pl_usecases/BoundedType.jav @@ -0,0 +1,12 @@ +class BoundedType { + + m(T x) { + return x; + } + + m1(x) { + T y; + x = y; + return y; + } +} \ No newline at end of file diff --git a/examples/pl_usecases/BoundedType1.jav b/examples/pl_usecases/BoundedType1.jav new file mode 100755 index 000000000..af71bfa73 --- /dev/null +++ b/examples/pl_usecases/BoundedType1.jav @@ -0,0 +1,16 @@ +interface BB { } +interface AA extends BB { + AAm(BB x); + } + +interface RR extends BB { + } + +class BoundedType1 { + + + m1(AA a) { + T1 b; + a.AAm(b); + } +} \ No newline at end of file diff --git a/examples/pl_usecases/BoundedType2.jav b/examples/pl_usecases/BoundedType2.jav new file mode 100755 index 000000000..47602aba5 --- /dev/null +++ b/examples/pl_usecases/BoundedType2.jav @@ -0,0 +1,15 @@ +class BoundedType { + m(T x) { + r; + r=x; + return r; + } + m1(b) { return b; } + +} + +class Id { + BoundedType bb; + m(x) { return bb.m1(x); } + } + \ No newline at end of file diff --git a/examples/pl_usecases/OL.jav b/examples/pl_usecases/OL.jav new file mode 100755 index 000000000..66e95aeb3 --- /dev/null +++ b/examples/pl_usecases/OL.jav @@ -0,0 +1,16 @@ +class OL { + + Integer m(Integer x) { return x + x; } + + Boolean m(Boolean x) {return x || x; } +} + +class Main { + + main(x) { + ol; + ol = new OL(); + return ol.m(x); + } + +} diff --git a/examples/pl_usecases/OL2.jav b/examples/pl_usecases/OL2.jav new file mode 100755 index 000000000..8a2c485b8 --- /dev/null +++ b/examples/pl_usecases/OL2.jav @@ -0,0 +1,20 @@ +import java.util.Vector; + +class OL2 { + + Integer m(Integer x) { return x + x; } + + Boolean m(Boolean x) {return x || x; } +} + +class Main { + + main(x) { + ol; + ol = new OL2(); + y; + /* y = new Vector(); */ + y.addElement(ol.m(x)); + } + +} diff --git a/examples/pl_usecases/SMatrix.jav b/examples/pl_usecases/SMatrix.jav new file mode 100755 index 000000000..80dd631ab --- /dev/null +++ b/examples/pl_usecases/SMatrix.jav @@ -0,0 +1,11 @@ +import java.util.Vector; + +class Matrix extends Vector> { + + mul(){ + Vector> ret1; + Vector ret; + return ret; + } + +} diff --git a/examples/pl_usecases/Simple.jav b/examples/pl_usecases/Simple.jav new file mode 100755 index 000000000..312e8a885 --- /dev/null +++ b/examples/pl_usecases/Simple.jav @@ -0,0 +1,10 @@ +class Simple { + + simple(a) { + return 1; + } + + main(a) { + return a; + } +} \ No newline at end of file diff --git a/examples/pl_usecases/UnifyTest1.jav b/examples/pl_usecases/UnifyTest1.jav new file mode 100755 index 000000000..abb8580be --- /dev/null +++ b/examples/pl_usecases/UnifyTest1.jav @@ -0,0 +1,11 @@ +import java.util.Vector; +import java.util.Stack; + + +class Test { + public getValue(a){ + String x; + a.addElement(x); + } + +} diff --git a/examples/pl_usecases/UsecaseEight_pl.jav b/examples/pl_usecases/UsecaseEight_pl.jav new file mode 100755 index 000000000..f2395352f --- /dev/null +++ b/examples/pl_usecases/UsecaseEight_pl.jav @@ -0,0 +1,10 @@ +class UsecaseEight_pl { + + foo1() { + a; + b; + a = b.foo1(); + return 1; + } + +} \ No newline at end of file diff --git a/examples/pl_usecases/UsecaseFive_pl.jav b/examples/pl_usecases/UsecaseFive_pl.jav new file mode 100755 index 000000000..1ccfddbdf --- /dev/null +++ b/examples/pl_usecases/UsecaseFive_pl.jav @@ -0,0 +1,9 @@ +class UsecaseFive_pl { + + foo() { + Vector c; + c = new Vector() ; + return c; + } + +} \ No newline at end of file diff --git a/examples/pl_usecases/UsecaseFour_pl.jav b/examples/pl_usecases/UsecaseFour_pl.jav new file mode 100755 index 000000000..b40233f6d --- /dev/null +++ b/examples/pl_usecases/UsecaseFour_pl.jav @@ -0,0 +1,9 @@ +class UsecaseFour_pl { + + foo() { + c; + c = new Vector() ; + return c; + } + +} \ No newline at end of file diff --git a/examples/pl_usecases/UsecaseNine_pl.jav b/examples/pl_usecases/UsecaseNine_pl.jav new file mode 100755 index 000000000..979b2baad --- /dev/null +++ b/examples/pl_usecases/UsecaseNine_pl.jav @@ -0,0 +1,12 @@ +class UsecaseNine_pl { + + Integer c; + + foo1() { + a; + b; + a = b.c; + return 1; + } + +} \ No newline at end of file diff --git a/examples/pl_usecases/UsecaseOne_pl.jav b/examples/pl_usecases/UsecaseOne_pl.jav new file mode 100755 index 000000000..cf614cbe7 --- /dev/null +++ b/examples/pl_usecases/UsecaseOne_pl.jav @@ -0,0 +1,20 @@ +import java.util.Vector; + +class UsecaseOne_pl { + + A x; + + foo(bar){ + bar = true; + return 1; + } +/* + foo1(a) { + c; + c = new Vector(); + b; + b = new UsecaseOne_pl(); + return c.addElement(a); + } +*/ +} diff --git a/examples/pl_usecases/UsecaseSeven_pl.jav b/examples/pl_usecases/UsecaseSeven_pl.jav new file mode 100755 index 000000000..9833b49be --- /dev/null +++ b/examples/pl_usecases/UsecaseSeven_pl.jav @@ -0,0 +1,18 @@ +import java.util.Vector; + +class UsecaseSeven_pl { + + foo(bar){ + bar = true; + return 1; + } + + foo1(a) { + c; + c = new Vector(); + b; + b = new UsecaseSeven_pl(); + return c.addElement(a); + } + +} \ No newline at end of file diff --git a/examples/pl_usecases/UsecaseSix_pl.jav b/examples/pl_usecases/UsecaseSix_pl.jav new file mode 100755 index 000000000..e6a1a5cc2 --- /dev/null +++ b/examples/pl_usecases/UsecaseSix_pl.jav @@ -0,0 +1,5 @@ +class uuu {} +class vvv {} +class UsecaseSix_pl extends Vector> { + +} \ No newline at end of file diff --git a/examples/pl_usecases/UsecaseTen_pl.jav b/examples/pl_usecases/UsecaseTen_pl.jav new file mode 100755 index 000000000..3a679aa94 --- /dev/null +++ b/examples/pl_usecases/UsecaseTen_pl.jav @@ -0,0 +1,14 @@ +import java.util.Vector; + +class UsecaseTen_pl { + + Vector c; + + foo1() { + a; + b; + a = b.c.elementAt(1); + return b; + } + +} \ No newline at end of file diff --git a/examples/pl_usecases/UsecaseThree_pl.jav b/examples/pl_usecases/UsecaseThree_pl.jav new file mode 100755 index 000000000..7ce53593a --- /dev/null +++ b/examples/pl_usecases/UsecaseThree_pl.jav @@ -0,0 +1,9 @@ +class UsecaseThree_pl { + + foo() { + c; + c = new Vector(); + return c; + } + +} \ No newline at end of file diff --git a/examples/pl_usecases/UsecaseThree_pl.orig.java b/examples/pl_usecases/UsecaseThree_pl.orig.java new file mode 100755 index 000000000..074acc31f --- /dev/null +++ b/examples/pl_usecases/UsecaseThree_pl.orig.java @@ -0,0 +1,11 @@ +import java.util.Vector; + +class UsecaseThree_pl_org { + + Vector foo() { + Vector c; + c = new Vector(); + return c; + } + +} diff --git a/examples/pl_usecases/UsecaseTwo_pl.jav b/examples/pl_usecases/UsecaseTwo_pl.jav new file mode 100755 index 000000000..8fbb75e16 --- /dev/null +++ b/examples/pl_usecases/UsecaseTwo_pl.jav @@ -0,0 +1,11 @@ +class UsecaseTwo_pl { + + foo() { + d; + d = new UsecaseTwo_pl (); + e; + e = d.foo(); + return d; + } + +} \ No newline at end of file diff --git a/examples/pl_usecases/Usecase_MUBTest.jav b/examples/pl_usecases/Usecase_MUBTest.jav new file mode 100755 index 000000000..bda38eb28 --- /dev/null +++ b/examples/pl_usecases/Usecase_MUBTest.jav @@ -0,0 +1,12 @@ +class A { } + +class B extends A { + f(Boolean x) { + if (x) { + return new B(); } + else { + return new A(); } + } +} + +class C extends B> {} diff --git a/examples/pl_usecases/Usecase_MUBTest1.jav b/examples/pl_usecases/Usecase_MUBTest1.jav new file mode 100755 index 000000000..cfe0e30e8 --- /dev/null +++ b/examples/pl_usecases/Usecase_MUBTest1.jav @@ -0,0 +1,17 @@ + + +class A { } + +class B extends A { + f(Boolean x) { + if (x) { + return new B(); } + else { + return new A(); } + } +} + +class C extends B> {} + + + diff --git a/examples/pl_usecases/Usecase_MUBTest2.jav b/examples/pl_usecases/Usecase_MUBTest2.jav new file mode 100755 index 000000000..08e66aed6 --- /dev/null +++ b/examples/pl_usecases/Usecase_MUBTest2.jav @@ -0,0 +1,13 @@ +class A { } + +class B extends A { + f(x) { + a; + if (x) { + return new C(); } + else { + return a; } + } +} + +class C extends B> {} diff --git a/examples/pl_usecases/Usecase_MUBTest3.jav b/examples/pl_usecases/Usecase_MUBTest3.jav new file mode 100755 index 000000000..fc7a33cd3 --- /dev/null +++ b/examples/pl_usecases/Usecase_MUBTest3.jav @@ -0,0 +1,14 @@ +class A { } + +class B extends A { + f(x) { + a; + b; + if (x) { + return a; } + else { + return b; } + } +} + +class C extends B> {} diff --git a/examples/pl_usecases/Usecase_MUBTest4.jav b/examples/pl_usecases/Usecase_MUBTest4.jav new file mode 100755 index 000000000..0325a6008 --- /dev/null +++ b/examples/pl_usecases/Usecase_MUBTest4.jav @@ -0,0 +1,12 @@ +class A { } + +class B extends A { + f(Boolean x) { + if (x) { + return new B(); } + else { + return new C(); } + } +} + +class C extends B> {} diff --git a/examples/pl_usecases/Usecase_MUBTest5.jav b/examples/pl_usecases/Usecase_MUBTest5.jav new file mode 100755 index 000000000..c1b2b19b6 --- /dev/null +++ b/examples/pl_usecases/Usecase_MUBTest5.jav @@ -0,0 +1,12 @@ +class A { } + +class B extends A { + f(Boolean x) { + if (x) { + return new B(); } + else { + return new C(); } + } +} + +class C extends B> {} diff --git a/examples/pl_usecases/Usecase_MUBTest6.jav b/examples/pl_usecases/Usecase_MUBTest6.jav new file mode 100755 index 000000000..2d494563d --- /dev/null +++ b/examples/pl_usecases/Usecase_MUBTest6.jav @@ -0,0 +1,9 @@ +class Test2 { + public meth(){ + if(true) { + return(1); + }else{ + return(2); + } + } +} diff --git a/examples/pl_usecases/ZweiKlassen.jav b/examples/pl_usecases/ZweiKlassen.jav new file mode 100755 index 000000000..2e3968848 --- /dev/null +++ b/examples/pl_usecases/ZweiKlassen.jav @@ -0,0 +1,17 @@ +import java.util.Vector; + +class ZweiKlassen { + + foo() { + c; + c = new Vector() ; + return c; + } + +} + +class X { + ZweiKlassen bb; + + foo2() { return bb.foo();} +} \ No newline at end of file diff --git a/examples/scju/Boxing.jav b/examples/scju/Boxing.jav new file mode 100755 index 000000000..edff055f7 --- /dev/null +++ b/examples/scju/Boxing.jav @@ -0,0 +1,26 @@ +import java.util.Vector; + +public class Boxing { + + public BoxingTest() { + a; + a= new Integer(12); + + v; + v = new Vector(); + + + v.addElement(a); + + b; + b = 0; + + c; + + c = v.elementAt(b); + + v.addElement(c); + + return v; + } +} \ No newline at end of file diff --git a/examples/scju/ClassGenerics.jav b/examples/scju/ClassGenerics.jav new file mode 100755 index 000000000..4b327cc62 --- /dev/null +++ b/examples/scju/ClassGenerics.jav @@ -0,0 +1,12 @@ +import java.util.Vector; +import java.lang.Comparable; + +public class ClassGenerics extends Vector implements Comparable{ + public typ1 variable1; + protected typ2 variable2; + + public Integer compareTo(String s) { + return null; + } + +} \ No newline at end of file diff --git a/examples/scju/ClassKonstanten.jav b/examples/scju/ClassKonstanten.jav new file mode 100755 index 000000000..059110ea1 --- /dev/null +++ b/examples/scju/ClassKonstanten.jav @@ -0,0 +1,6 @@ +public class ClassKonstanten { + public final static boolean testcase = true; + public final static int variable = 32; + public final static char testchar = 'A'; + public final static String var2 = "Hallo Welt!"; +} \ No newline at end of file diff --git a/examples/scju/FieldGenerics.jav b/examples/scju/FieldGenerics.jav new file mode 100755 index 000000000..357b4f9af --- /dev/null +++ b/examples/scju/FieldGenerics.jav @@ -0,0 +1,11 @@ +import java.util.Vector; +import java.util.Hashtable; + +public class FieldGenerics { + public Vector StringVec; + public Hashtable ht; + + public Vector TestMethode(Hashtable para1) { + return null; + } +} \ No newline at end of file diff --git a/examples/scju/InterfaceGenerics.jav b/examples/scju/InterfaceGenerics.jav new file mode 100755 index 000000000..371d1e1bf --- /dev/null +++ b/examples/scju/InterfaceGenerics.jav @@ -0,0 +1,9 @@ +import java.util.Vector; +import java.lang.Comparable; +import java.io.Serializable; + +public interface InterfaceGenerics extends Comparable, Serializable{ + + public typ1 compareTo(typ2 s); + +} \ No newline at end of file diff --git a/examples/scju/InterfaceTest.jav b/examples/scju/InterfaceTest.jav new file mode 100755 index 000000000..83c9d788a --- /dev/null +++ b/examples/scju/InterfaceTest.jav @@ -0,0 +1,10 @@ +public interface InterfaceTest extends Interface1, Interface2 { + public final static boolean testcase = true; + public final static int variable = 32; + public final static char testchar = 'A'; + public final static String var2 = "Hallo Welt!"; + + public void TestProzedur(); + public void TestProzedur2(String wert1, int wert2); + public int TestProzedur3(int wert2); +} \ No newline at end of file diff --git a/examples/scju/MethodGenerics.jav b/examples/scju/MethodGenerics.jav new file mode 100755 index 000000000..d965c96ae --- /dev/null +++ b/examples/scju/MethodGenerics.jav @@ -0,0 +1,18 @@ +import java.util.Vector; +import java.io.Serializable; +import java.lang.Comparable; + +public class MethodGenerics { + + public typ1 TestMethode(String wert1, typ1 that, String wert2) { + return null; + } + + t TestMethode2() { + return null; + } + + u TestMethode3() { + return null; + } +} \ No newline at end of file diff --git a/examples/scju/SimpleMethodCall.jav b/examples/scju/SimpleMethodCall.jav new file mode 100755 index 000000000..a9eb482be --- /dev/null +++ b/examples/scju/SimpleMethodCall.jav @@ -0,0 +1,15 @@ +import java.util.Vector; + +public class SimpleMethodCall { + + public TestProzedur() { + v; + v = new Vector(); + x; + x = "Hallo Welt!"; + + v.addElement(x); + + return v; + } +} \ No newline at end of file diff --git a/examples/scju/testPackage/Test.jav b/examples/scju/testPackage/Test.jav new file mode 100755 index 000000000..ad68828e5 --- /dev/null +++ b/examples/scju/testPackage/Test.jav @@ -0,0 +1,15 @@ +package testPackage.second.third; + +import java.util.Vector; + +class PackageTest { + + public final String variable = "Hallo Welt!"; + + TestProzedur() { + c; + c = new Vector(); + return c; + } + +} \ No newline at end of file diff --git a/src/myJvmDisassembler/GenericsTest.java b/src/myJvmDisassembler/GenericsTest.java new file mode 100755 index 000000000..954fad1f7 --- /dev/null +++ b/src/myJvmDisassembler/GenericsTest.java @@ -0,0 +1,18 @@ +package myJvmDisassembler; + + + +class GenericsTest { + + Integer k; + GenericsTest pp; + Object j; + + a meth(a arg) { + return arg; + } + + t meth2(b arg, t arg2) { + return arg2; + } +} diff --git a/src/myJvmDisassembler/jvmDisassembler.java b/src/myJvmDisassembler/jvmDisassembler.java new file mode 100755 index 000000000..19bb41ba3 --- /dev/null +++ b/src/myJvmDisassembler/jvmDisassembler.java @@ -0,0 +1,229 @@ +package myJvmDisassembler; + +import java.util.*; +import java.io.*; + +//GenricsTest.java Testfile fuer jvmDisassembler +class jvmDisassembler { + + static int makePosByte(int code) { + return (code & 0x7f | code & 0x80); + } + + static int makePosShort(int code) { + return (code & 0x7fff | code & 0x8000); + } + + static long makePosInt(long code) { + return (code & 0x7fffffff | code & 0x80000000); + } + + static void parse_attribute(DataInputStream d, Vector const_pool) throws IOException, Exception { + int attribut_count = d.readShort(); + System.out.println("attribut_count = " + attribut_count); + if (attribut_count == 0) System.out.println("attributes = {}"); + else { + for (int j = 0; j < attribut_count; j++) { + System.out.println("attribut[" + j + "] =\n{"); + int attribut_name_index = d.readShort(); + System.out.println("attribut_name_index = " + attribut_name_index + + " //" + const_pool.elementAt(makePosShort(attribut_name_index))); + + if (const_pool.elementAt(makePosShort(attribut_name_index)).equals("Code")) { + parse_code(d, const_pool); + int exception_table_length = d.readShort(); + System.out.println("exception_table_length = " + exception_table_length); + if (exception_table_length == 0) System.out.println("exception_table = {}"); + else throw new Exception("exceptiones not implemented"); + + parse_attribute(d, const_pool); + + } else { + if ((const_pool.elementAt(makePosShort(attribut_name_index)).equals("Signature"))) { + long attribut_length = d.readInt(); + System.out.println("attribut_length = " + attribut_length); + + int sigdescriptor_index = d.readShort(); + System.out.println("descriptor_index = " + sigdescriptor_index + + " //" + const_pool.elementAt(makePosShort(sigdescriptor_index))); + } else { + long attribut_length = d.readInt(); + System.out.println("attribut_length = " + attribut_length); + + for(int ll = 0; ll < attribut_length; ll++) { + System.out.println(Integer.toHexString(makePosByte(d.readByte()))); + } + System.out.println("}"); + } + } + System.out.println("}"); + } + } + + } + + static void parse_code(DataInputStream d, Vector const_pool) throws IOException { + long attribut_length = d.readInt(); + System.out.println("attribut_length = " + attribut_length); + + int max_stack = d.readShort(); + System.out.println("max_stack = " + max_stack); + + int max_locals = d.readShort(); + System.out.println("max_locals = " + max_locals); + + long code_length = makePosInt(d.readInt()); + System.out.println("code_length = " + code_length); + System.out.println("code =\n{"); + + int code; + int codenr = 1; + for(; codenr <= code_length;) { + //CODE VERVOLLSTAENDIGEN PL 06-04-01 + code = makePosByte(d.readByte()); + //System.out.println("DEBUG: " + Integer.toHexString(code)); + switch(code) { + case 0x4: System.out.println(" " + codenr + " iconst_1"); + codenr++; + break; + case 0x2a: System.out.println(" " + codenr + " aload_0"); + codenr++; + break; + case 0x2b: System.out.println(" " + codenr + " aload_1"); + codenr++; + break; + case 0x2c: System.out.println(" " + codenr + " aload_2"); + codenr++; + break; + case 0xac: System.out.println(" " + codenr + " ireturn"); + codenr++; + break; + case 0xb0: System.out.println(" " + codenr + " areturn"); + codenr++; + break; + case 0xb1: System.out.println(" " + codenr + " return"); + codenr++; + break; + case 0xb7: System.out.println(" " + codenr + " invokespecial " + + d.readShort()); + codenr+=3; + break; + default: System.out.println(" " + Integer.toHexString(code)); + codenr++; + break; + } + } + System.out.println("}"); + } + + + public static void main (String[] args) throws FileNotFoundException, IOException, Exception { + + DataInputStream d = new DataInputStream(new FileInputStream(new File (args[0]))); + + int magic = d.readInt(); + System.out.println("magic = 0x " + Integer.toHexString(magic)); + + int minor = d.readShort(); + System.out.println("minor_version = " + minor); + int major = d.readShort(); + System.out.println("major_version = " + major); + + //CONSTANT POOL START + int constant_pool_count = makePosShort(d.readShort()); + System.out.println("constant_pool_count = " + constant_pool_count); + + Vector const_pool = new Vector(constant_pool_count); + const_pool.addElement(""); // Konstatenpool beginnt bei 1, Stelle 0 auffuellen + + System.out.println("constant_pool =\n{"); + short constant_pool_tag; + for (int i = 1; i < constant_pool_count; i++) { + constant_pool_tag = d.readByte(); + switch(constant_pool_tag) { + //Tags vervollstaendigen PL 06-04-01 + case 1: System.out.print(i + "| tag = CONSTANT_Utf8, length = "); + int length = makePosShort(d.readShort()); + System.out.print(length + ", "); + byte[] bytes = new byte[length]; + d.read(bytes, 0, length); + System.out.println(new String(bytes)); + const_pool.addElement(new String(bytes)); + break; + case 7: System.out.println(i + "| tag = CONSTANT_Class, name_index = " + d.readShort()); + const_pool.addElement(""); + break; + case 10: System.out.println(i + "| tag = CONSTANT_Methodref, class_index = " + + d.readShort() + ", name_and_type_index = " + d.readShort()); + const_pool.addElement(""); + break; + case 12:System.out.println(i + "| tag = CONSTANT_NameAndType, name_index = " + + d.readShort() + ", descriptor_index = " + d.readShort()); + const_pool.addElement(""); + break; + } + } + //CONSTANT POOL END + + int access_flags = d.readShort(); + System.out.println("access_flags = " + access_flags); + int this_class = d.readShort(); + System.out.println("this_class = " + this_class); + int super_class = d.readShort(); + System.out.println("super_class = " + super_class); + + //INTERFACE START + int interface_count = d.readShort(); + System.out.println("interface_count = " + interface_count); + if (interface_count == 0) System.out.println("interfaces ={}"); + else + //Interface implementieren PL 06-04-01 + throw new Exception("no interfaces implemented"); + //INTERFACE END + + //FIELD START + int field_count = d.readShort(); + System.out.println("field_count = " + field_count); + if (field_count == 0) System.out.println("fields = {}"); + else { + for(int o = 1; o <= field_count; o++) { + System.out.println("field[" + o + "] =\n{"); + int faccess_flags = d.readShort(); + System.out.println("access_flags = " + faccess_flags); + int fname_index = d.readShort(); + System.out.println("name_index = " + fname_index); + int fdescriptor_index = d.readShort(); + System.out.println("descriptor_index = " + fdescriptor_index); + + parse_attribute(d, const_pool); + System.out.println("}"); + } + } + //FIELD END + + //METHOD START + int method_count = makePosShort(d.readShort()); + System.out.println("method_count = " + method_count); + if (method_count == 0) System.out.println("methods ={}"); + else { + for(int i = 1; i <= method_count; i++) { + System.out.println("method[" + i + "] =\n{"); + int maccess_flags = d.readShort(); + System.out.println("access_flags = " + maccess_flags); + int mname_index = d.readShort(); + System.out.println("name_index = " + mname_index); + int descriptor_index = d.readShort(); + System.out.println("descriptor_index = " + descriptor_index); + + parse_attribute(d, const_pool); + + System.out.println("}"); + } + } + //METHOD END + + //FILE ATTRIBUTES START + parse_attribute(d, const_pool); + //FILE ATTRIBUTES END + } +} diff --git a/src/mycompiler/AClassOrInterface.java b/src/mycompiler/AClassOrInterface.java new file mode 100755 index 000000000..8328c3767 --- /dev/null +++ b/src/mycompiler/AClassOrInterface.java @@ -0,0 +1,201 @@ + +// ino.module.AClassOrInterface.8526.package +package mycompiler; +// ino.end + +// ino.module.AClassOrInterface.8526.import +import java.util.Vector; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mymodifier.Modifiers; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.AClassOrInterface.21186.description type=javadoc +/** + * Superklasse von Class und Interface. Beinhaltet gemeinsame Attribute + * der beiden Objekte. + * + * @author Juergen Schmiing + * + */ +// ino.end +// ino.class.AClassOrInterface.21186.declaration +public abstract class AClassOrInterface +// ino.end +// ino.class.AClassOrInterface.21186.body +{ + // ino.attribute.inferencelog.21189.decldescription type=javadoc + /** + * Log4j - Loggerinstanzen + */ + // ino.end + // ino.attribute.inferencelog.21189.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + // ino.attribute.codegenlog.21192.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + // ino.attribute.parserlog.21195.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.attribute.pkgName.21198.decldescription type=line + // Package-Name + // ino.end + // ino.attribute.pkgName.21198.declaration + protected UsedId pkgName; + // ino.end + + // ino.attribute.modifiers.21201.decldescription type=line + // Class/Interface-Name und Access-Modifiers + // ino.end + // ino.attribute.modifiers.21201.declaration + protected Modifiers modifiers; + // ino.end + // ino.attribute.name.21204.declaration + protected String name; + // ino.end + + // ino.attribute.superif.21207.decldescription type=line + // Superinterfaces. Interfaces erweitern die Liste, + // Klassen implementieren die Liste. + // ino.end + // ino.attribute.superif.21207.declaration + private Vector superif = new Vector(); + // ino.end + + // ino.method.AClassOrInterface.21210.defdescription type=line + // Konstruktoren + // ino.end + // ino.method.AClassOrInterface.21210.definition + public AClassOrInterface() + // ino.end + // ino.method.AClassOrInterface.21210.body + {} + // ino.end + + // ino.method.AClassOrInterface.21213.definition + public AClassOrInterface(String strName) + // ino.end + // ino.method.AClassOrInterface.21213.body + { + name = strName; + } + // ino.end + // ino.method.AClassOrInterface.21216.definition + public AClassOrInterface(String strName, Modifiers mod) + // ino.end + // ino.method.AClassOrInterface.21216.body + { + name = strName; + this.modifiers = mod; + } + // ino.end + + // ino.method.getPackageName.21219.defdescription type=line + // Handling fuer Packages + // ino.end + // ino.method.getPackageName.21219.definition + public UsedId getPackageName() + // ino.end + // ino.method.getPackageName.21219.body + { + return pkgName; + } + // ino.end + + // ino.method.setPackageName.21222.definition + public void setPackageName(UsedId pkgName) + // ino.end + // ino.method.setPackageName.21222.body + { + this.pkgName = pkgName; + } + // ino.end + + // ino.method.getName.21225.definition + public String getName() + // ino.end + // ino.method.getName.21225.body + { + return name; + } + // ino.end + + // ino.method.setName.21228.definition + public void setName(String strName) + // ino.end + // ino.method.setName.21228.body + { + name = strName; + } + // ino.end + + // ino.method.setModifiers.21231.definition + public void setModifiers(Modifiers mod) + // ino.end + // ino.method.setModifiers.21231.body + { + this.modifiers = mod; + } + // ino.end + + // ino.method.getModifiers.21234.definition + public Modifiers getModifiers() + // ino.end + // ino.method.getModifiers.21234.body + { + return this.modifiers; + } + // ino.end + + // ino.method.getAccessFlags.21237.defdescription type=javadoc + /** + * Liefert die AccessFlags fuer den Bytecode zurueck. + */ + // ino.end + // ino.method.getAccessFlags.21237.definition + public short getAccessFlags() + // ino.end + // ino.method.getAccessFlags.21237.body + { + short ret = 0; + if (modifiers != null) { + ret = modifiers.calculate_access_flags(); + } + //if (ret != 0) + // return ret; + //else + // return (short) 32; + + //feda 04.07.07 wird bei der Codegenerierung des Class File beachtet. + + return ret; + } + // ino.end + + // ino.method.getSuperInterfaces.21240.definition + public Vector getSuperInterfaces() + // ino.end + // ino.method.getSuperInterfaces.21240.body + { + return superif; + } + // ino.end + + // ino.method.setSuperInterfaces.21243.definition + public void setSuperInterfaces(Vector superif) + // ino.end + // ino.method.setSuperInterfaces.21243.body + { + this.superif = superif; + } + // ino.end + + // ino.method.codegen.21246.declaration + public abstract void codegen(SourceFile sf) + throws JVMCodeException; + // ino.end +} +// ino.end diff --git a/src/mycompiler/IItemWithOffset.java b/src/mycompiler/IItemWithOffset.java new file mode 100755 index 000000000..e199fd8c4 --- /dev/null +++ b/src/mycompiler/IItemWithOffset.java @@ -0,0 +1,17 @@ +// ino.module.IItemWithOffset.8527.package +package mycompiler; +// ino.end + +// ino.class.IItemWithOffset.21249.declaration +public interface IItemWithOffset +// ino.end +// ino.class.IItemWithOffset.21249.body +{ + // ino.method.getOffset.21252.declaration + public int getOffset(); + // ino.end + // ino.method.getVariableLength.21255.declaration + public int getVariableLength(); + // ino.end +} +// ino.end diff --git a/src/mycompiler/MyCompiler.java b/src/mycompiler/MyCompiler.java new file mode 100755 index 000000000..717113bd4 --- /dev/null +++ b/src/mycompiler/MyCompiler.java @@ -0,0 +1,815 @@ +// ino.module.MyCompiler.8569.package +package mycompiler; +// ino.end + + +// ino.module.MyCompiler.8569.import +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.util.Vector; + +import mycompiler.myclass.Class; +import mycompiler.myclass.ClassBody; +import mycompiler.myclass.Constructor; +import mycompiler.myclass.DeclId; +import mycompiler.myclass.FieldDecl; +import mycompiler.myclass.FormalParameter; +import mycompiler.myclass.ImportDeclarations; +import mycompiler.myclass.InstVarDecl; +import mycompiler.myclass.Method; +import mycompiler.myclass.ParameterList; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myparser.JavaParser; +import mycompiler.myparser.Scanner; +import mycompiler.myparser.JavaParser.yyException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.IMatchable; +import mycompiler.mytype.ITypeContainer; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; + +import org.apache.log4j.Logger; +import org.apache.log4j.xml.DOMConfigurator; + +import typinferenz.TypinferenzException; +// ino.end + + + +// ino.class.MyCompiler.21258.declaration +public class MyCompiler implements MyCompilerAPI +// ino.end +// ino.class.MyCompiler.21258.body +{ + // ino.attribute.NO_LINENUMBER.21262.decldescription type=line + // PL: Der Zusammenhang zwischen paralist und vParaOrg muesste + // noch geklaert werden 05-01-07 + // ino.end + + // ino.attribute.NO_LINENUMBER.21262.declaration + public static final int NO_LINENUMBER = -1; + // ino.end + + // ino.attribute.codegenlog.21265.decldescription type=line + // Logger + // ino.end + // ino.attribute.codegenlog.21265.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + // ino.attribute.inferencelog.21268.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + // ino.attribute.parserlog.21271.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.attribute.OutputDir.21274.declaration + protected String OutputDir = ""; + // ino.end + + // ino.attribute.m_Singleton.21277.decldescription type=javadoc + /** + * Die Singleton-Instanz f�r den Compiler + *
Autor: J�rg B�uerle + */ + // ino.end + // ino.attribute.m_Singleton.21277.declaration + private static MyCompiler m_Singleton = null; + // ino.end + + // ino.attribute.m_AbstractSyntaxTree.21280.decldescription type=javadoc + /** + * Der abstrake Syntaxbaum + *
Autor: J�rg B�uerle + */ + // ino.end + // ino.attribute.m_AbstractSyntaxTree.21280.declaration + private SourceFile m_AbstractSyntaxTree; + // ino.end + + // ino.method.MyCompiler.21283.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * Der private Konstruktor. Es soll von au�en kein Compiler angelegt werden + * k�nnen, sondern nur eine API zur Verf�gung gestellt werden. + */ + // ino.end + // ino.method.MyCompiler.21283.definition + private MyCompiler() + // ino.end + // ino.method.MyCompiler.21283.body + { + this.init(); + } + // ino.end + + // ino.method.getAPI.21286.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * Stellt eine neue Instanz der CompilerAPI zur Verf�gung. + * Diese Methode sollte von der IDE aus aufgerufen werden, + * um eine Quellcode-Datei zu kompilieren. + * @return Die Compiler-API + */ + // ino.end + // ino.method.getAPI.21286.definition + public static MyCompilerAPI getAPI() + // ino.end + // ino.method.getAPI.21286.body + { + if(m_Singleton==null){ + m_Singleton = new MyCompiler(); + } + return m_Singleton; + } + // ino.end + + public Vector testPair = null; + + // ino.method.wandleGeneric2RefType.21289.defdescription type=javadoc + /** + * Author: Thomas Ott
+ * Ersetzt in der Superklassenparameterliste einer Klasse, diejenigen + * GenericTypeVars, zu denen es eine Klasse gibt, die gleich hei�t. + * Beim Parsen werden n�mlich vom Jay nur GenericTypeVars erzeugt und keine + * RefTypes. Dies wird durch diese Methode nachgeholt.
+ * Bsp.: class JoergsTolleKlasse
extends MartinsSuperklasse + *
Wie man an diesem Beispiel sieht, kann nur eine Superklasse instantiierte + * Typvariablen zwischen den eckigen Klammern stehen haben, nicht jedoch die + * abgeleitete Klasse. + * + * @param className Klassenname der aktuell betrachteten Klasse + * @param Parameter Parameter der Superklasse + * @param KlassenVektor + */ + // ino.end + // ino.method.wandleGeneric2RefType.21289.definition + public static void wandleGeneric2RefType(Vector Parameter, Vector KlassenVektor ) + // ino.end + // ino.method.wandleGeneric2RefType.21289.body + { + //wandleGeneric2RefType SOLLTE NICHT NUR FUER LISTEN + //VON TYPEN FUNKTIONIEREN PL 05-01-19 + // otth: GenericTypeVar in Superklassenparameterlisten in RefTypes mit Parameterlsite = NULL umwandeln, + // falls: f�r GenericTypeVar existiert eine gleichnamige Klasse + if(Parameter == null) return; + + for( int i = 0; i < Parameter.size(); i++) + { + Type TempParameter = Parameter.elementAt(i); + inferencelog.debug("Nr. des Parameters: " + i); + + // an dieser Stelle: Parametername + if ( TempParameter instanceof GenericTypeVar) + { + inferencelog.debug("Generic, WANDLE: " + TempParameter.getName()); + // existiert f�r GenericTypeVar eine deklarierte Klasse + for( int k = 0; k < KlassenVektor.size(); k++) + { + if( KlassenVektor.elementAt(k).getSimpleName().equals(TempParameter.getSimpleName()) ) + { + // Klasse existiert, darf aber keine Parameterliste in der Definition haben + if( KlassenVektor.elementAt(k).get_ParaList().size() == 0 ) + { + RefType RNeu = new RefType( TempParameter.getName(), null,TempParameter.getOffset()); + inferencelog.debug( "Vorher: " + Parameter ); + // i-te Stelle ersetzen + Parameter.set( i, RNeu ); + inferencelog.debug( "GenericTypeVar " + TempParameter.getName() + " umwandeln..." ); + inferencelog.debug( "Nachher: " + Parameter ); + } + else + { + parserlog.error( "SEMANTIK-CHECK-FEHLER: Parameter " + TempParameter.getName() + " muss weitere Parameter besitzen (laut Klassendefinition)" ); + //FIXME Throw exception instead of simple exit + System.exit( 1 ); + } + } + else { + inferencelog.debug("Ist echter Generic, wird nicht ersetzt!"); + } + } // end for + } // end if + else + { + inferencelog.debug("Nicht Generic, WANDLE nicht: " + TempParameter.getName()); + // RefType --> u.U. rekursiv weiterwandeln + if(TempParameter instanceof RefType) + { + RefType R = (RefType)TempParameter; + if( R.get_ParaList() != null ) + wandleGeneric2RefType( R.get_ParaList(), KlassenVektor ); + } + else if(TempParameter instanceof ITypeContainer) + { + Type T = ((ITypeContainer)TempParameter).getContainedType(); + if(T instanceof RefType) + { + RefType R = (RefType)T; + if( R.get_ParaList() != null ) + wandleGeneric2RefType( R.get_ParaList(), KlassenVektor ); + } + } + else + { + inferencelog.error("Internal Error"); + System.exit( 1 ); + } + } + } //end for + } //end wandleGeneric2RefType + // ino.end + + + + // ino.method.parse.21292.defdescription type=javadoc + /** + * Parst den Quellcode und baut den abstrakten Syntaxbaum auf. Danach wird + * automatisch der von Thomas Ott implementierte Algorithmus + * NewTVar(jclass) (siehe Algorithmus 5.17 TRProg, Martin Pl�micke) + * aufgerufen. + *
Author: J�rg B�uerle + * @param reader + * @throws IOException + * @throws JavaParser.yyException + */ + // ino.end + // ino.method.parse.21292.definition + private void parse(Reader reader) + throws IOException, JavaParser.yyException + // ino.end + // ino.method.parse.21292.body + { + parserlog.info("#########################################"); + parserlog.info("# Parsen - START #"); + parserlog.info("#########################################\n"); + + ////////////////////////////////////// + // Alte Daten l�schen: + ////////////////////////////////////// + m_AbstractSyntaxTree = null; + + ////////////////////////////////////// + // Scanner und Parser erzeugen: + ////////////////////////////////////// + Scanner scanner = new Scanner(reader); + JavaParser parser = new JavaParser(); + + ////////////////////////////////////// + // Parsen ==> Ergebnis: srcFile = Abstrakter Syntaxbaum + ////////////////////////////////////// + SourceFile srcFile = (SourceFile) parser.yyparse( scanner ); + this.testPair = parser.testPair; + + parserlog.info( "Parsen war erfolgreich!\n"); + + //PL 05-07-31 verschoben nach SourceFile.java in Methode typeReconstruction + // otth: TypePlaceholders in Superklassenparameterlisten in RefTypes mit Parameterlsite = NULL umwandeln, + // falls: f�r TypePlaceholder existiert eine gleichnamige Klasse + // Superklasse suchen + //for( int i = 0; i < srcFile.KlassenVektor.size(); i++ ) + //{ + //Class tempKlasse = (Class)srcFile.KlassenVektor.elementAt( i ); + + //PL 05-07-30 ausgetauscht um alle Typedeklarationen zu wandeln + // if( tempKlasse.superclassid != null && tempKlasse.get_ParaList() != null ) + // { + // // aktuelle Klasse hat Superklasse und Parameter + // Vector Parameter = tempKlasse.superclassid.get_ParaList(); + // this.wandleGeneric2RefType(Parameter, srcFile.KlassenVektor ); + // } + //wandleGeneric2RefType(tempKlasse.getContainedTypes(), srcFile.KlassenVektor ); + + //} + + // otth: echte Konstruktoren von Methodendeklarationen ohne Typen unterscheiden + if ( srcFile != null ) + { + Class tempKlasse = null; + ClassBody tempKlassBody = null; + Vector tempVectorFieldDecl; + FieldDecl tempFieldDecl = null; + String strKlasse; + + for( int i = 0; i < srcFile.KlassenVektor.size(); i++ ) + { + + // Unterscheidung zwischen Class und Interfaces + if (srcFile.KlassenVektor.elementAt(i) instanceof Class) { + tempKlasse = (Class)srcFile.KlassenVektor.elementAt( i ); + tempKlassBody = tempKlasse.get_ClassBody(); + } else { + tempKlasse = null; + tempKlassBody = null; + } + + if ( tempKlassBody != null ) + { + strKlasse = tempKlasse.getName(); + parserlog.debug("T->Felddeklarationen f�r die Klasse:" + strKlasse); + parserlog.debug( "------------------------------------"); + + // Schleife �ber alle fielddeclarations + tempVectorFieldDecl = tempKlassBody.get_FieldDeclVector(); + for( int k = 0; k < tempVectorFieldDecl.size(); k++ ) + { + tempFieldDecl = tempVectorFieldDecl.elementAt(k); + if( tempFieldDecl instanceof Constructor ) + { + parserlog.debug("T->Konstruktor: " + ((DeclId)tempFieldDecl.get_Name().elementAt(0)).get_Name() + " - ReturnType: " + tempFieldDecl.getTypeName()); + + // pr�fen, ob Construktorname == Klassenname - falls nein: Construktor in Methode umwandeln !!! + String strConstName = ((DeclId)tempFieldDecl.get_Name().elementAt(0)).get_Name(); // Konstruktorname + if ( !strConstName.equals( strKlasse ) ) + { + // Element k durch neues ersetzen! + + Method Methode = new Method(); + Method Konstruktor = (Constructor)tempFieldDecl; + + // Elementweise vom Konstruktor in die Methode kopieren + Methode.set_Block( Konstruktor.get_Block() ); + Methode.setParameterList( Konstruktor.getParameterList() ); + Methode.set_ExceptionList( Konstruktor.get_ExceptionList() ); + Methode.setReturnType( Konstruktor.getReturnType() ); + Methode.setDeclIdVector( Konstruktor.getDeclIdVector() ); + // types_in_parameterlist wird wohl erst sp�ter und intern gef�llt + + // R�ckgabetyp = Objekt der Klasse 'TypePlaceholder' + + // #JB# 31.03.2005 + // ########################################################### + Methode.setReturnType(TypePlaceholder.fresh()); + //Methode.setReturnType( new TypePlaceholder("###NEU###") ); + // ########################################################### + + // Element an der Position k durch neues ersetzen! + tempVectorFieldDecl.setElementAt( Methode, k ); + } + } + if( tempFieldDecl instanceof Method && !(tempFieldDecl instanceof Constructor) ) + { + parserlog.debug("T->Methode: " + ((DeclId)tempFieldDecl.get_Name().elementAt(0)).get_Name() + " - ReturnType: " + tempFieldDecl.getTypeName()); + } + if( tempFieldDecl instanceof InstVarDecl ) + { + parserlog.debug("T->Instanzv.: " + ((DeclId)tempFieldDecl.get_Name().elementAt(0)).get_Name() + " - ReturnType: " + tempFieldDecl.getTypeName()); + } + } + + // Debugg-Infos + parserlog.debug(""); + parserlog.debug("T->NEUE Felddeklarationen f�r die Klasse:" + strKlasse); + parserlog.debug( "-----------------------------------------"); + for( int k = 0; k < tempVectorFieldDecl.size(); k++ ) + { + tempFieldDecl = tempVectorFieldDecl.elementAt(k); + //parserlog.debug("T->" + ((DeclId)tempFieldDecl.get_Name().elementAt(0)).get_Name() + " - Typ: " + tempFieldDecl + " - ReturnType: " + tempFieldDecl.getTypeName()); + } + + // otth: TypePlaceholders durchnummerieren mit A, B, ... + parserlog.debug(""); + parserlog.debug(""); + parserlog.debug("Suche TypePlaceholders in den FieldDecls:"); + parserlog.debug( "------------------------------------------"); + + ParameterList tempParameterList; + Vector tempVFktPara; + FormalParameter tempFP; + Method tempMethod; + Type tempReturn; + Type tempType; + for( int k = 0; k < tempVectorFieldDecl.size(); k++ ) + { + tempFieldDecl = tempVectorFieldDecl.elementAt(k); + tempMethod = null; + + if( tempFieldDecl instanceof Method ) + { + tempMethod = (Method)tempFieldDecl; + tempReturn = tempMethod.getReturnType(); + + // Funktionen ohne definierten R�ckgabetyp suchen!!! + if( tempReturn instanceof TypePlaceholder ) + { + // Methode mit nicht-definiertem R�ckgabetyp gefunden! + + // #JB# 31.03.2005 + // ########################################################### + // Wird bereits �ber fresh() gemacht!! + //tempReturn.setName( TypePlaceholder.makeNewName() ); + // ########################################################### + parserlog.debug(""); + parserlog.debug("Methode ohne Rueckgabetyp: " + tempMethod.get_Method_Name() + " --> " + tempReturn.getName()); + } + else + { + parserlog.debug(""); + parserlog.debug("Methode mit Rueckgabetyp / Konstruktor: " + tempMethod.get_Method_Name()); + } + + // Methoden-Funktionsparameter durchsuchen + tempParameterList = tempMethod.getParameterList(); + if ( tempParameterList != null ) + { + tempVFktPara = tempParameterList.sc_get_Formalparalist(); + for( int l = 0; l < tempVFktPara.size(); l++ ) + { + tempFP = tempVFktPara.elementAt(l); + tempType = tempFP.getType(); + if( tempType instanceof TypePlaceholder ) + { + if( tempType != null ) + { + // neuer Name berechnen + + // #JB# 31.03.2005 + // ########################################################### + // Wird bereits �ber fresh() gemacht!! + //tempType.setName( TypePlaceholder.makeNewName() ); + // ########################################################### + } + } + parserlog.debug(""); + parserlog.debug(" Parameter: " + tempFP.get_Name() + " --> " + tempType.getName()); + } + } + else + { + parserlog.debug(""); + parserlog.debug(" Methode hat keine Parameter!"); + } + } + } + } //end if + } //end for + } //end if + m_AbstractSyntaxTree = srcFile; + + parserlog.info("#########################################"); + parserlog.info("# Parsen - ENDE #"); + parserlog.info("#########################################\n"); + } // end Methode parse() + // ino.end + +///////////////////////////////////////////////////////////////////////////////////////////////// +// Implementierte API-Methoden: +///////////////////////////////////////////////////////////////////////////////////////////////// + // ino.method.init.21295.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * Initialisiert den Compiler + */ + // ino.end + // ino.method.init.21295.definition + public void init() + // ino.end + // ino.method.init.21295.body + { + m_AbstractSyntaxTree = null; + TypePlaceholder.deleteRegistry(); + + // Log4J fuer die Ausgabe vorbereiten + //DOMConfigurator.configure("log4j.xml"); + } + // ino.end + + // ino.method.parse.21298.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * Ruft die Parse-Methode. + * @param file Die Quellcode-Datei + * @throws FileNotFoundException Wenn die Quellcode-Datei nicht existiert. + * @throws IOException Wenn was schief l�uft. + * @throws JavaParser.yyException Wenn ein Fehler beim Parsen auftritt. + */ + // ino.end + // ino.method.parse.21298.definition + public void parse(File file) + throws FileNotFoundException, IOException, JavaParser.yyException + // ino.end + // ino.method.parse.21298.body + { + FileReader fr = new FileReader(file); + this.parse(fr); + fr.close(); + } + // ino.end + + // ino.method.parse.21301.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * Ruft die Parse-Methode. + * @param srcCode Der zu parsende Quellcode + * @throws IOException Wenn was schief l�uft. + * @throws JavaParser.yyException Wenn ein Fehler beim Parsen auftritt. + */ + // ino.end + // ino.method.parse.21301.definition + public void parse(String srcCode) + throws IOException, yyException + // ino.end + // ino.method.parse.21301.body + { + StringReader sr = new StringReader(srcCode); + this.parse(sr); + sr.close(); + } + // ino.end + + // ino.method.typeReconstruction.21304.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * Ruft den Typrekonstruktionsalgorithmus auf. + * @return Die Menge aller m�glichen Typkombinationen + * @throws NullPointerException Wenn noch kein abstrakter Syntaxbaum vorhanden + * ist. @throws CTypeReconstructionException Wenn ein Fehler bei der + * Typrekonstruktion auftritt. + */ + // ino.end + // ino.method.typeReconstruction.21304.definition + public Vector typeReconstruction() + throws NullPointerException, CTypeReconstructionException + // ino.end + // ino.method.typeReconstruction.21304.body + { + if(m_AbstractSyntaxTree==null){ + throw new NullPointerException("Es wurde noch kein Abstrakter Syntaxbaum erstellt!"); + } + inferencelog.info("##########################################"); + inferencelog.info("# TypeReconstruction-Algorithmus - START #"); + inferencelog.info("##########################################\n"); + + Vector result = m_AbstractSyntaxTree.typeReconstruction(); + + inferencelog.info("#########################################"); + inferencelog.info("# TypeReconstruction-Algorithmus - ENDE #"); + inferencelog.info("#########################################\n"); + + return result; + } + // ino.end + + // ino.method.getSyntaxTree.21307.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * Liefert den geparsten Syntaxbaume zur�ck. + * @return Die Syntaxb�ume + * @throws NullPointerException Wenn noch keine Syntaxb�ume berechnet worden sind. + */ + // ino.end + // ino.method.getSyntaxTree.21307.definition + public SourceFile getSyntaxTree() + throws NullPointerException + // ino.end + // ino.method.getSyntaxTree.21307.body + { + return m_AbstractSyntaxTree; + } + // ino.end + + // ino.method.codeGeneration.21310.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * Generiert den Bytecode und das Class-File f�r den Syntaxbaum. + * @throws NullPointerException Wenn noch kein abstrakter Syntaxbaum vorhanden + * ist. + */ + // ino.end + // ino.method.codeGeneration.21310.definition + public void codeGeneration() + throws NullPointerException, JVMCodeException + // ino.end + // ino.method.codeGeneration.21310.body + { + if(m_AbstractSyntaxTree==null){ + throw new NullPointerException("Es wurde noch kein Abstrakter Syntaxbaum erstellt!"); + } + codegenlog.info("Beginn der Codegenerierung ..."); + + m_AbstractSyntaxTree.codegen(); + + codegenlog.info("Codegenerierung beendet!"); + } + // ino.end + + // ino.method.main.21313.defdescription type=javadoc + /** + * Die Main-Funktion, �ber die der Compiler auch per Konsole gestartet + * werden kann. + * @param args Klassendatei + */ + // ino.end + // ino.method.main.21313.definition + public static void main(String[] args) + // ino.end + // ino.method.main.21313.body + { + MyCompilerAPI compiler = MyCompiler.getAPI(); + + // Hier koennten ggf. Aenderungen der Ausgabeeinstellungen + // (Debuginfos) vorgenommen werden -> LOG4J + + try { + compiler.parse(new File(args[0])); + } catch (FileNotFoundException e) { + System.err.println("Die Datei \""+args[0]+"\" konnte nicht gefunden werden."); + System.exit(0); + } catch (IOException e) { + System.err.println("Fehler beim Parsen:"); + System.err.println(e); + System.exit(0); + } catch (yyException e) { + System.err.println("Fehler beim Parsen:"); + System.err.println(e); + System.exit(0); + } + + ///////////////////////// + // Semantik-Check: + ///////////////////////// + // try { + // compiler.semanticCheck(); + // } catch (NullPointerException e) { + // System.out.println("Fehler beim Aufrufen des Semantik-Checks:"); + // System.out.println(e); + // System.exit(0); + // } catch (SCException e) { + // e.fehlerausgabe(); + // System.exit(0); + // } + + ///////////////////////// + // Code-Generierung: + ///////////////////////// + //compiler.codeGeneration(); + } + // ino.end + + // ino.method.setOutputDir.21316.definition + public void setOutputDir(String dir) + // ino.end + // ino.method.setOutputDir.21316.body + { + char c = dir.charAt(dir.length()-1); + if (c != '/' & c != '\\') dir = dir + "/"; + OutputDir = dir; + + // Verzeichnis(se) ggf. anlegen + File f = new File(dir); + f.mkdirs(); + } + // ino.end + + // ino.method.getOutputDir.21319.definition + public String getOutputDir() + // ino.end + // ino.method.getOutputDir.21319.body + { + return OutputDir; + } + // ino.end + + // ino.method.getFullyQualifiedNameFromClassname.21322.definition + public static String getFullyQualifiedNameFromClassname(String typ, ImportDeclarations declarations) + // ino.end + // ino.method.getFullyQualifiedNameFromClassname.21322.body + { + String ret=null; + // Es ist kein FullyQualifiedName => In den Imports die Klasse suchen + for(int j=0;j java.util.Vector x; + * @param containedTypes Alle Typen, die die Klasse beinhaltet + * @param name Alle Klassen, die es in den BasicAssumptions und im + * AbstractSyntaxTree gibt @param declarations Alle Import-Declarations + */ + // ino.end + // ino.method.makeRefTypesFullyQualified.21325.definition + public static void makeRefTypesFullyQualified(Vector containedTypes, ImportDeclarations declarations) + // ino.end + // ino.method.makeRefTypesFullyQualified.21325.body + { + // HOTI 8.5.06 Anhand der ContainedTypes alle Variablen aendern + for( int i = 0; i < containedTypes.size(); i++) + { + Type tempParameter = (Type)(containedTypes.elementAt(i)); + // Nat�rlich nur RefTypes updaten + if(tempParameter instanceof RefType){ + RefType typ=(RefType)tempParameter; + UsedId fullyQualifiedName=UsedId.createFromQualifiedName(typ.getTypeName(),typ.getOffset()); + // Kein FullyQualifiedName + if(fullyQualifiedName.name.size()==1){ + String newType=getFullyQualifiedNameFromClassname(typ.getSimpleName(),declarations); + if(newType!=null){ + typ.setName(newType); + } + + } + if(typ.get_ParaList()!=null){ + makeRefTypesFullyQualified(typ.get_ParaList(),declarations); + } + } + } + } + // ino.end + + /** + * @author Arne Lüdtke + * Ersetzt alle GTVs durch TPHs mit gleichem Namen. Arbeitet Rekursiv. + * ACHTUNG: BACKDOOR CREATE!!! Nur für Testzwecke verwenden. + * @param T - Typ, bei welchem die GTVs ersetzt werden sollen. + */ + public static Type makeGenericTypeVars2TypePlaceHolders(Type T) + { + if(T instanceof RefType) + { + RefType refT = (RefType)T; + if(refT.get_ParaList() != null) + { + Vector paras = refT.get_ParaList(); + for(int i = 0; i filenames) { + String gesamterSrc = ""; + //Hier werden alle übergebenen Dateinamen abgearbeitet: + for(String filename : filenames){ + try { + StringBuffer fileData = new StringBuffer(); + BufferedReader reader = new BufferedReader( + new FileReader(filename)); + char[] buf = new char[1024]; + int numRead=0; + while((numRead=reader.read(buf)) != -1){ + String readData = String.valueOf(buf, 0, numRead); + fileData.append(readData); + } + reader.close(); + gesamterSrc += fileData.toString() + "\n"; // Alle Dateien nacheinander hintereinander anhängen... + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new TypinferenzException("Die übergebenen Dateien konnten nicht zum Parsen eingelesen werden."); + } + } + + try { + // und anschließend zum Parsen übergeben. + this.parse(gesamterSrc.toString()); + } catch (Exception e) { + e.printStackTrace(); + //throw new TypinferenzException("Fehler beim Parsen"); + } + + } + +} +// ino.end diff --git a/src/mycompiler/MyCompilerAPI.java b/src/mycompiler/MyCompilerAPI.java new file mode 100755 index 000000000..61fee931b --- /dev/null +++ b/src/mycompiler/MyCompilerAPI.java @@ -0,0 +1,140 @@ +// ino.module.MyCompilerAPI.8570.package +package mycompiler; +// ino.end + +// ino.module.MyCompilerAPI.8570.import +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Vector; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myparser.JavaParser; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +// ino.end + +// ino.class.MyCompilerAPI.21328.description type=javadoc +/** + * Schnittstellen-Klasse zum Compiler. Diese Klasse soll der + * IDE als Compiler-API zum Kompilieren einer Quellcode-Datei + * dienen und stellt somit die Schnittstelle zur Studienarbeit + * von Markus Melzer (Eclipse-Plugin) dar. + * @author Jörg Bäuerle + * @version $Date: 2013/09/09 11:04:24 $ + */ +// ino.end +// ino.class.MyCompilerAPI.21328.declaration +public interface MyCompilerAPI +// ino.end +// ino.class.MyCompilerAPI.21328.body +{ + + // ino.method.init.21331.decldescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * Initialisiert den Compiler + */ + // ino.end + // ino.method.init.21331.declaration + public void init(); + // ino.end + + // ino.method.parse.21334.decldescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * Parst eine Quellcodedatei und baut den abstrakten Syntaxbaum auf. + * @param file Die Quellcode-Datei + * @throws FileNotFoundException Wenn die Quellcode-Datei nicht existiert. + * @throws IOException Wenn was schief läuft. + * @throws JavaParser.yyException Wenn ein Fehler beim Parsen auftritt. + */ + // ino.end + // ino.method.parse.21334.declaration + public void parse(File file) + throws FileNotFoundException, IOException, JavaParser.yyException; + // ino.end + + // ino.method.parse.21337.decldescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * Parst einen String und baut den abstrakten Syntaxbaum auf. + * @param srcCode Der zu parsende Quellcode + * @throws IOException Wenn was schief läuft. + * @throws JavaParser.yyException Wenn ein Fehler beim Parsen auftritt. + */ + // ino.end + // ino.method.parse.21337.declaration + public void parse(String srcCode) + throws IOException, JavaParser.yyException; + // ino.end + + // ino.method.typeReconstruction.21340.decldescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * Ruft den Typrekonstruktionsalgorithmus auf. + * @return Die Menge aller möglichen Typkombinationen + * @throws NullPointerException Wenn noch kein abstrakter Syntaxbaum vorhanden + * ist. @throws CTypeReconstructionException Wenn ein Fehler bei der + * Typrekonstruktion auftritt. + */ + // ino.end + // ino.method.typeReconstruction.21340.declaration + public Vector typeReconstruction() + throws NullPointerException, CTypeReconstructionException; + // ino.end + + // ino.method.getSyntaxTree.21343.decldescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * Liefert den geparsten Syntaxbaum zurück. + * @return Die Syntaxbäume + * @throws NullPointerException Wenn noch kein Syntaxbaum berechnet worden ist. + */ + // ino.end + // ino.method.getSyntaxTree.21343.declaration + public SourceFile getSyntaxTree() + throws NullPointerException; + // ino.end + + // ino.method.codeGeneration.21346.decldescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * Generiert den Bytecode und das Class-File für den Syntaxbaum. + * @param syntaxTree Der Syntaxbaum + * @throws NullPointerException Wenn noch kein abstrakter Syntaxbaum vorhanden + * ist. @throws JVMCodeException + */ + // ino.end + // ino.method.codeGeneration.21346.declaration + public void codeGeneration() + throws NullPointerException, JVMCodeException; + // ino.end + + // ino.method.setOutputDir.21349.decldescription type=javadoc + /** + * Author: Juergen Schmiing
+ * Legt das Ausgabeverzeichnis fuer die class-Files fest. + */ + // ino.end + // ino.method.setOutputDir.21349.declaration + public void setOutputDir(String dir); + // ino.end + + // ino.method.getOutputDir.21352.decldescription type=javadoc + /** + * Author: Juergen Schmiing
+ * Gibt das Ausgabeverzeichnis fuer die class-Files zurueck. + */ + // ino.end + // ino.method.getOutputDir.21352.declaration + public String getOutputDir(); + // ino.end + + /** + * Parst zusammenhängende JavaKlassen in verschiedenen Dateien. + * @param filenames - Eine Liste von Quellcodedateien, welche gseparst werden sollen + */ + public void parse(Vector filenames); + +} +// ino.end diff --git a/src/mycompiler/SourceFile.java b/src/mycompiler/SourceFile.java new file mode 100755 index 000000000..821448365 --- /dev/null +++ b/src/mycompiler/SourceFile.java @@ -0,0 +1,1426 @@ +// ino.module.SourceFile.8722.package +package mycompiler; +// ino.end + +// ino.module.SourceFile.8722.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.myclass.BasicAssumptionClass; +import mycompiler.myclass.Class; +import mycompiler.myclass.ImportDeclarations; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCClassException; +import mycompiler.myexception.SCException; +import mycompiler.myinterface.Interface; +import mycompiler.mymodifier.Modifiers; +import mycompiler.mymodifier.Public; +import mycompiler.mytype.BooleanType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CIntersectionType; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.FC_TTO; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import sun.reflect.generics.reflectiveObjects.TypeVariableImpl; +import typinferenz.TypeAssumptions; +// ino.end + + + + +// ino.class.SourceFile.21355.declaration +public class SourceFile +// ino.end +// ino.class.SourceFile.21355.body +{ + // ino.attribute.LOAD_BASIC_ASSUMPTIONS_FROM_JRE.21358.decldescription type=javadoc + /** + * @autor HOTI + * Dieses Flag bestimmt, ob die basicAssumptions (Integer, Vector, ...) direkt von + * der Java-Laufzeitumgebung anhand der Imports oder von den "Fixed Hacks" geladen + * werden (Mit Fixed Hacks sind die von Hand eingetragene Basetypes gemeint) + */ + // ino.end + // ino.attribute.LOAD_BASIC_ASSUMPTIONS_FROM_JRE.21358.declaration + private static final boolean LOAD_BASIC_ASSUMPTIONS_FROM_JRE = true; + // ino.end + + // ino.attribute.READ_OBJECT_SUPERCLASSES_FROM_JRE.21361.decldescription type=javadoc + /** + * @autor HOTI + * Wenn dieses Flag auf true gesetzt ist, wird immer als Superklasse Object + * mit rein geladen. Dies hat natürlich zur Folge, dass man in der GUI jeden Typ + * auswählen muss, weil ALLES in Java von Object erbt. Sobald die GUI das über eine + * Checkbox o.ä. ausblendbar macht kann es aktiviert werden. Ebenso beeinflusst es + * die superclass von allen Class-Objekten. (Wenn true ist jede Class automatisch + * wenn nicht anders eingegeben Subclass von Object (Wie es sein muss)) + */ + // ino.end + // ino.attribute.READ_OBJECT_SUPERCLASSES_FROM_JRE.21361.declaration + public static final boolean READ_OBJECT_SUPERCLASSES_FROM_JRE = false; + // ino.end + + // ino.attribute.READ_BASE_TYPE_SUPERCLASSES_FROM_JRE.21364.decldescription type=javadoc + /** + * Wenn dieses Flag auf false ist, werden für alle Basisklassen (definiert + * durch die Hashtable baseTypeTranslationTable) KEINE Superklassen geladen. D.h. + * Integer hat bspw. nicht die Superklasse Number sondern OBJECT. + * Dies verursacht bei den Int-Operationen ein Problem + * (+,-,*,/,<,>,...) + */ + // ino.end + // ino.attribute.READ_BASE_TYPE_SUPERCLASSES_FROM_JRE.21364.declaration + private static final boolean READ_BASE_TYPE_SUPERCLASSES_FROM_JRE = false; + // ino.end + + /** + * @autor PL + * Wenn dieses Flag auf false ist, werden für alle importierten Klassen + * KEINE Superklassen geladen. + */ + private static final boolean READ_IMPORTED_SUPERCLASSES_FROM_JRE = false; + + // ino.attribute.codegenlog.21367.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.21367.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + // ino.attribute.inferencelog.21370.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + + // ino.attribute.pkgName.21373.declaration + private UsedId pkgName; + // ino.end + + // ino.attribute.KlassenVektor.21376.declaration + public Vector KlassenVektor = new Vector(); + // ino.end + + // ino.attribute.InterfaceVektor.21379.declaration + public Vector InterfaceVektor = new Vector(); + // ino.end + + // ino.attribute.imports.21382.decldescription type=javadoc + /** + * HOTI 4.5.06 + * Beinhaltet alle Imports des aktuell geparsten Files + * in Form einer UsedId + */ + // ino.end + // ino.attribute.imports.21382.declaration + private ImportDeclarations imports=new ImportDeclarations(); + // ino.end + // ino.attribute.baseTypeTranslationTable.21385.decldescription type=javadoc + /** + * Table zum Übersetzen der nicht implementierten Base-Types: + * Überall im Compiler wird statt bspw. int Integer verwendet + * d.h. 1+2 liefert ein Integer + * Deshalb benötigen wir hier eine Tabelle, mit der man die von + * der JRE gelieferten Base-Typen (int,char, etc) und die Objekt- + * Typen umwandeln können + */ + // ino.end + // ino.attribute.baseTypeTranslationTable.21385.declaration + private Hashtable baseTypeTranslationTable; + // ino.end + + // ino.method.SourceFile.21388.definition + public SourceFile() + // ino.end + // ino.method.SourceFile.21388.body + { + // HOTI 4.5.06 + // Base-Type-Translations anlegen (siehe kommentar BaseTypeTranslationTable) + baseTypeTranslationTable=new Hashtable(); + baseTypeTranslationTable.put("int","java.lang.Integer"); + baseTypeTranslationTable.put("char","java.lang.Character"); + baseTypeTranslationTable.put("boolean","java.lang.Boolean"); + baseTypeTranslationTable.put("double","java.lang.Double"); + baseTypeTranslationTable.put("long","java.lang.Long"); + baseTypeTranslationTable.put("float","java.lang.Float"); + //baseTypeTranslationTable.put("this.is.a.temporary.entry","java.util.Vector"); auskommentiert PL 07-08-11 + + + this.imports=new ImportDeclarations(); + + this.imports.add(UsedId.createFromQualifiedName("java.lang.Integer",-1)); + this.imports.add(UsedId.createFromQualifiedName("java.lang.String",-1)); + this.imports.add(UsedId.createFromQualifiedName("java.lang.Character",-1)); + this.imports.add(UsedId.createFromQualifiedName("java.lang.Boolean",-1)); + this.imports.add(UsedId.createFromQualifiedName("java.lang.Double",-1)); + this.imports.add(UsedId.createFromQualifiedName("java.lang.Float",-1)); + this.imports.add(UsedId.createFromQualifiedName("java.lang.Long",-1)); + //this.imports.add(UsedId.createFromQualifiedName("java.lang.Byte")); + + // HOTI 4.5.06 Wenn die Klassen immer als "Daddy" Object haben, + // muss das der JCC auch kennen + if(READ_OBJECT_SUPERCLASSES_FROM_JRE){ + this.imports.add(UsedId.createFromQualifiedName("java.lang.Object",-1)); + } + } + // ino.end + + + // ino.method.sc_check.21391.defdescription type=javadoc + /** + * DEPRECATED. Wird nicht mehr benutzt, TypeReconstruction uebernimmt + * diese Aufgabe. + */ + // ino.end + // ino.method.sc_check.21391.definition + public void sc_check(boolean ext) + throws SCException // Semantikcheck + // ino.end + // ino.method.sc_check.21391.body + { + SCException except=null; + + for( Enumeration el = KlassenVektor.elements(); el.hasMoreElements(); ) + { + Class sc_class = el.nextElement(); + try + { + sc_class.sc_check( KlassenVektor, ext ); + } + catch (SCClassException ex) + { + ex.printStackTrace(); + if(except==null) + except=new SCException(); + except.add_classexceptions(ex); + } + } + + if(except!=null) + throw except; + } + // ino.end + + // ino.method.addElement.21394.defdescription type=javadoc + /** + * Fuegt ein neues Element (Interface oder Klasse) hinzu. + * @param c + */ + // ino.end + // ino.method.addElement.21394.definition + public void addElement(AClassOrInterface e) + // ino.end + // ino.method.addElement.21394.body + { + if (e instanceof Class) { + KlassenVektor.addElement((Class) e); + } else if (e instanceof Interface) { + InterfaceVektor.addElement((Interface) e); + } + } + // ino.end + + + + // ino.method.codegen.21397.defdescription type=javadoc + /** + * Startet die Bytecodegenerierung fuer alle in der Datei + * enthaltenen Klassen und Interfaces. + * + */ + // ino.end + // ino.method.codegen.21397.definition + public void codegen() + throws JVMCodeException + // ino.end + // ino.method.codegen.21397.body + { + codegenlog.info("Anzahl der Interfaces: " + + Integer.toString(InterfaceVektor.size())); + for(int i = 0; i < InterfaceVektor.size(); i++) { + InterfaceVektor.elementAt(i).codegen(this); + } + + codegenlog.info("Anzahl der Klassen: " + + Integer.toString(KlassenVektor.size())); + for(int i = 0; i < KlassenVektor.size(); i++) { + KlassenVektor.elementAt(i).codegen(this); + } + } + // ino.end + + // ino.method.createPairFromClassAndSuperclass.21400.defdescription type=javadoc + /** + * Erstellt ein Typ-Paar, welches im 1. Durchlauf in die Menge der Finite Closure + * aufgenommen wird Input: Klassenname, Name der Superklasse, ParameterDerKlasse, + * Parameter der Superklasse + * @return + */ + // ino.end + // ino.method.createPairFromClassAndSuperclass.21400.definition + private Pair createPairFromClassAndSuperclass(String className, String superclassName, Vector classParaOrg, Vector superclassParaOrg) + // ino.end + // ino.method.createPairFromClassAndSuperclass.21400.body + { + // Paar erstellen + if(classParaOrg!=null && classParaOrg.size()==0){ + classParaOrg=null; + } + if(superclassParaOrg!=null && superclassParaOrg.size()==0){ + superclassParaOrg=null; + } + Pair P = new Pair( + new RefType( className, classParaOrg,-1), + new RefType( superclassName, superclassParaOrg,-1) + ); + //PL 04-12-29 freshe Variablen ANFANG + RefType r1 = (RefType)P.getTA1Copy(); + RefType r2 = (RefType)P.getTA2Copy(); + // #JB# 05.04.2005 + // ########################################################### + Hashtable substHash = new Hashtable(); //fuer jedes Paar komplett neue Variablen + Unify.varSubst(r1, substHash); + Unify.varSubst(r2, substHash); + // ########################################################### + P = new Pair(r1, r2); + //PL 04-12-29 freshe Variablen ENDE + + //HIER AUSKOMMENTIERT, SOLLTE MAN AM ENDE WIEDER DAZU NEHMEN PL 04-12-28 + // gleiches Paar aufnehmen + //vFC.add( new Pair( P.getTA1Copy(), P.getTA1Copy() ) ); + + return(P); + + } + // ino.end + // ino.method.makeFC.21403.defdescription type=javadoc + /** + * Erstellt die Finite Closure + * @return FC_TTO-Object, welches die Finite Closure repräsentiert + */ + // ino.end + // ino.method.makeFC.21403.definition + public FC_TTO makeFC( ) + // ino.end + // ino.method.makeFC.21403.body + { + + // Menge FC bilden + + Vector vFC = new Vector(); // Menge FC + + // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen + + for( int i = 0; i < KlassenVektor.size(); i++ ) + { + Class tempKlasse = KlassenVektor.elementAt(i); + inferencelog.debug("Verarbeite "+tempKlasse.getName()); + + if( tempKlasse.superclassid != null ) { // Klasse hat Superklasse + Pair P=createPairFromClassAndSuperclass(tempKlasse.getName(),tempKlasse.get_Superclass_Name(),tempKlasse.get_ParaList(),tempKlasse.superclassid.get_ParaList()); + vFC.add( P ); + } + if(tempKlasse.getSuperInterfaces()!=null){ + Iterator interfaceIterator=tempKlasse.getSuperInterfaces().iterator(); + while(interfaceIterator.hasNext()){ + UsedId intf=interfaceIterator.next(); + String interfaceName=intf.getQualifiedName(); + Pair P=createPairFromClassAndSuperclass(tempKlasse.getName(),interfaceName,tempKlasse.get_ParaList(),intf.get_ParaList()); + vFC.add( P ); + + } + } + } // Schleifenende durch Klassenvektor + + for(int i=0; i interfaceIterator=intf.getSuperInterfaces().iterator(); + while(interfaceIterator.hasNext()){ + UsedId superintf=interfaceIterator.next(); + String superinterfaceName=superintf.getQualifiedName(); + Pair P=createPairFromClassAndSuperclass(intf.getName(),superinterfaceName,intf. getParaList(), superintf.get_ParaList()); + vFC.add( P ); + + } + } + } + + Vector tto = (Vector)vFC.clone(); + + Unify.printMenge( "FC", vFC, 6 ); + /* z.B. + ******************************* + Menge FC = { + (Vektor< A >, Vektor< A >), + (Vektor< A >, AbstractList< A >), + (Matrix< A >, Matrix< A >), + (Matrix< A >, Vektor< Vektor< A > >), + (ExMatrix< A >, ExMatrix< A >), + (ExMatrix< A >, Matrix< A >) } + ******************************* + + ODER + + ******************************* + Menge FC = { + (BB< A >, BB< A >), + (BB< A >, CC< A >), + (AA< A, B >, AA< A, B >), + (AA< A, B >, BB< DD< B, A > >) } + ******************************* + + */ + + // 2. Regel 2 der Huellendefinition "eingeschraenkt" anwenden + // d.h. sinnvolle Substitutionen suchen (nicht alle) + + boolean bPaarHinzu = true; + while( bPaarHinzu ) + { + bPaarHinzu = false; //PL 04-12-29 nur wenn hinzugefuegt auf true setzen + // konkret: rechte Seite von FC nach Typkonstruktoren in der Parameterliste durchsuchen + for( int n = 0; n < vFC.size(); n++ ) + { + // Elemente in FC k�nnen nur Pair's sein --> Cast ohne Abfrage + Pair PTypKonst = vFC.elementAt(n); + + // Parameter des rechten Typausdrucks des betrachteten Paars extrahieren + Vector vPara = ((RefType)(PTypKonst.TA2)).get_ParaList(); + RefType Subst = null; // Substitution + int nSubstStelle = 0; + inferencelog.debug("nSubstStelleStart" + nSubstStelle + " " + n); + + // Parameter durchlaufen und nach Typkonstruktor suchen + // #JB# 17.05.2005 + // ########################################################### + if(vPara!=null){ + // ########################################################### + for( ; nSubstStelle < vPara.size(); nSubstStelle++ ) + { + inferencelog.debug("nSubstStelle" + nSubstStelle); + if( vPara.elementAt(nSubstStelle) instanceof RefType && ((RefType)vPara.elementAt(nSubstStelle)).get_ParaList() != null ) + { + // Typkonstruktor gefunden -> wird nun als Substitution verwendet + Subst = new RefType( (RefType)vPara.elementAt(nSubstStelle) ,-1); + inferencelog.debug( "Ausgangstyp:" + ((RefType)PTypKonst.TA2).getName() ); + inferencelog.debug( "RefType = " + ((RefType)vPara.elementAt(nSubstStelle)).getName() ); + break; // Einschraenkung - nur fuer ein RefType wird eine Substitution gesucht + } + } + // ########################################################### + } + // ########################################################### + if( Subst != null ) + { + // Rechter Typ hat einen Typkonstruktor --> sinvolles neues Paar bilden + // d.h. Rechter Typ auf linker Paarseite suchen + // System.out.println("Subststelle = " + nSubstStelle ); + + for( int t = 0; t < vFC.size(); t++ ) + { + Pair PSuchen = vFC.elementAt(t); + if( ((RefType)(PTypKonst.TA2)).getTypeName().equals( ((RefType)PSuchen.TA1).getTypeName() ) ) + { + inferencelog.debug(" gefundener Typ links: " + ((RefType)(PSuchen.TA1)).getName() ); + inferencelog.debug(" gefundener Typ rechts: " + ((RefType)(PSuchen.TA2)).getName() ); + // Paar gefunden, das als linken Typ den gleichen Typen enth�lt, der als Parameter einen Typkonstruktor hat + // Substitution + //Pair P = new Pair( PSuchen.getTA1Copy( ), PSuchen.getTA2Copy( ) ); + //linker Typterm bleibt gleich + //rechter Typterm wird aussen auf den Supertyp gesetzt. + //restliches FC erfolgt ueber die Transitivitaet + //siehe im unteren Teil + Pair P = new Pair( PTypKonst.getTA1Copy( ), PSuchen.getTA2Copy( ) ); + // System.out.println(" Subst " + Subst.getName() ); + // System.out.println(" Vor: P = " + P.toString() + P.TA1 ); + // System.out.println(" Vor: PSuchen = " + PSuchen.toString() + PSuchen.TA1 ); + + // Parameter, der substituiert wird, sollte TV sein ??? + //TypePlaceholder TV = null; + // if( ((RefType)P.TA1).isTV( nSubstStelle ) ) + // try + // { + // TV = new TypePlaceholder( ((RefType)P.TA1).getParaN( nSubstStelle ) ); + // } + // catch( Exception E ) + // { + // continue; + // } + // else + // continue; + + //es werden alle Parameter in einem Typeterm, der + //der Argumente hat ersetzt PL 04-12-28 + Hashtable hts = new Hashtable(); + //for(int u = nSubstStelle; u < vPara.size(); u++) { + for(int u = 0; u < vPara.size(); u++) { + try { + // #JB# 05.04.2005 + // ########################################################### + //TV = new TypePlaceholder( ((RefType)PSuchen.TA1).getParaN(u) ); + //System.out.println("TV_Name: " + u + TV.Type2String()); + // ########################################################### + inferencelog.debug("Typterm_Name: " + vPara.elementAt(u)); + inferencelog.debug("Typterm_Name: " + ((Type)vPara.elementAt(u)).Type2String()); + hts.put(((RefType)PSuchen.TA1).getParaN(u), vPara.elementAt(u)); + } + catch( Exception E ) { + inferencelog.error(E.getMessage()); + //FIXME Throw Exception or Error instead of exiting! + System.exit(0); + } + + // Subst( P, + // 2, + // TV, + // new RefType( (RefType)vPara.elementAt(u) ), + // false ); // rechte Seite substituieren + //Es genuegt die rechte Seite zu substituieren, da + //die linke Seite ein Typterm ausschlie�lich mit + //Typvariablen ist + } + //Unify.SubstHashtableGeneric(((RefType)P.TA1), hts); //funktioniert nicht + Unify.SubstHashtableGeneric(((RefType)P.TA2), hts); //funktioniert nicht + // System.out.println(" TV!!!= " + TV.getName() ); + //Subst( P, 1, TV, Subst, false ); // linke Seite substituieren + //Subst( P, 2, TV, Subst, false ); // rechte Seite substituieren + // System.out.println(" nach Subst: P = " + P.toString() ); + // System.out.println(" Nach: PSuchen = " + PSuchen.toString() ); + // System.out.println(" Nach: " + P.toString() ); + + // Paar einfuegen, falls noch nicht vorhanden + // System.out.println("Paar alt:" + PSuchen.toString() ); + // System.out.println("Paar neu:" + P.toString() ); + if( !P.isInVector( vFC ) ) + { + vFC.add( P ); + Unify.printMenge( "FC", vFC, 6 ); + bPaarHinzu = true; + } + //PL 04-12-29 + // else //unnoetig, da am Anfang bereits false gesetzt + // { + // bPaarHinzu = false; + // } + + } + } + } // end if: Substitution gefunden??? + } // end for: Typkonstruktor suchen + + + // Transitivitaet berechnen + for( int u = 0; u < vFC.size(); u++ ) + { + Pair PTemp = vFC.elementAt(u); + + // falls rechtes Paar = RefType + if( PTemp.TA2 instanceof RefType ) + { + RefType R = (RefType)PTemp.TA2; + + // rechte Seite auf linker Seite suchen + for( int e = 0; e < vFC.size(); e++ ) + { + Pair PSuch = vFC.elementAt(e); + // als linke Paarseite theortisch nur RefType's moeglich --> Cast + RefType RSuch = (RefType)PSuch.TA1; + + //if( R.getName().equals(RSuch.getName()) ) + if (R.is_Equiv(RSuch, new Hashtable())) //eingefuegt PL 05-01-07 + { + // Paar einfuegen, falls noch nicht vorhanden + RefType L1 = (RefType)PTemp.getTA1Copy(); + RefType L2 = (RefType)PTemp.getTA2Copy(); + RefType R1 = (RefType)PSuch.getTA1Copy(); + RefType R2 = (RefType)PSuch.getTA2Copy(); + + //zunaechst Variablen disjunkt machen ANFANG + // #JB# 05.04.2005 + // ########################################################### + Hashtable substHash1 = new Hashtable(); + Unify.varSubst(L1, substHash1); + Unify.varSubst(L2, substHash1); + Hashtable substHash2 = new Hashtable(); + Unify.varSubst(R1, substHash2); + Unify.varSubst(R2, substHash2); + // ########################################################### + //zunaechst Variablen disjunkt machen ENDE + + //Variablen so umbennen, dass transitiver Abschluss richtige + //Namen hat ANFANG + + // #JB# 05.04.2005 + // ########################################################### + Hashtable h = new Hashtable(); + L2.Equiv2Equal(R1, h); + Hashtable substHash3 = h; + Unify.varSubst(L1, substHash3); + Unify.varSubst(R2, substHash3); + // ########################################################### + //Variablen so umbennen, dass transitiver Abschluss richitge + //Namen hat ENDE + + //Pair P = new Pair( (RefType)PTemp.TA1, (RefType)PSuch.TA2 ); + Pair P = new Pair(L1, R2); + if( !P.isInVector( vFC ) ) + { + vFC.add( P ); + bPaarHinzu = true; + } + else + { + bPaarHinzu = false; + } + } + } // end for: linke Seite suchen + } // end if: Element ist RefType + } // end for: Transitivit�ten berechnen + //PL HIER REFLEXIVE HUELLE EINFUEGEN + // 05-01-07 + + } // Ende WHILE + + /* z.B. + ******************************* + Menge nach trans: FC = { + (Vektor< A >, Vektor< A >), + (Vektor< A >, AbstractList< A >), + (Matrix< A >, Matrix< A >), + (Matrix< A >, Vektor< Vektor< A > >), + (ExMatrix< A >, ExMatrix< A >), + (ExMatrix< A >, Matrix< A >), + (Vektor< Vektor< A > >, Vektor< Vektor< A > >), + (Vektor< Vektor< A > >, AbstractList< Vektor< A > >), + (Matrix< A >, AbstractList< Vektor< A > >), + (ExMatrix< A >, Vektor< Vektor< A > >), + (ExMatrix< A >, AbstractList< Vektor< A > >) } + + ODER + + ******************************* + Menge nach trans: FC = { + (BB< A >, BB< A >), + (BB< A >, CC< A >), + (AA< A, B >, AA< A, B >), + (AA< A, B >, BB< DD< B, A > >), + (BB< DD< B, A > >, BB< DD< B, A > >), + (BB< DD< B, A > >, CC< DD< B, A > >), + (AA< A, B >, CC< DD< B, A > >) } + ******************************* + + ******************************* */ + + + // printMenge( "nach trans: FC", vFC, 6 ); + + FC_TTO fctto = new FC_TTO(vFC, tto,KlassenVektor); + return fctto; + } + // ino.end + + ///////////////////////////////////////////////////////////////////////// + // TypeReconstructionAlgorithmus + ///////////////////////////////////////////////////////////////////////// + // ino.method.typeReconstruction.21406.defdescription type=javadoc + /** + * Tyrekonstruktionsalgorithmus: ruft f�r jede Klasse den Algorithmus TRProg auf. + * Dessen Ergebnismenge A, die Menge aller Typannahmen, f�r eine Klasse dient als + * Eingabe f�r TRProg der n�chsten Klasse. Am Ende enth�lt A alle m�glichen + * Typkombinationen f�r alle Klassen zusammen. + *
Author: J�rg B�uerle + * @return Liste aller m�glichen Typkombinationen + * @throws CTypeReconstructionException Wenn was schief l�uft + */ + // ino.end + // ino.method.typeReconstruction.21406.definition + public Vector typeReconstruction() + throws CTypeReconstructionException + // ino.end +// ino.method.typeReconstruction.21406.body +{ + + // HOTI: Nur zur Info.Ich habe den Loglevel auf Info geschaltet, damit + // in der GUI (Eclipse-Plugin) die Console nicht zugemüllt wird. + // Wers braucht kanns natürlich ausschalten + + // inferencelog.setLevel(Level.INFO); + + Vector A = new Vector(); + + CTypeReconstructionResult basics; + + basics = this.makeBasicAssumptions(); //TODO: Diese Funktion ändern, dass nur noch TypeAssumptions zurückgegeben werden. Diese sind wichtig, da hier die Standard-Library von Java als Assumptions generiert wird. + + //A.addElement(basics); //auskommentiert von Andreas Stadelmeier + + // PL 05-07-31 alle GenericTypeVars werden ueberprueft, ob sie nicht + // deklarierte Classen sind und dann ggfs. gewandelt. + for (int i = 0; i < this.KlassenVektor.size(); i++) { + Class tempKlasse = this.KlassenVektor.elementAt(i); + MyCompiler.wandleGeneric2RefType(tempKlasse.getContainedTypes(), + this.KlassenVektor); + if(tempKlasse.getSuperInterfaces()!=null){ + for(int k=0;k0){ + for(int j=0;j intf_it = InterfaceVektor.iterator(); + while (intf_it.hasNext()) { + Interface intf = intf_it.next(); + + // HOTI In diesem Moment gibt es nur _eine_ potentielle CTypeReconstructionResult, d.h. + // dort können die Definitionen der Interfaces (Methodintersectiontypes, FieldDecls) abgelegt werden + + + intf.addThisToAssumptions(basics); + } + + // Fuer jede Klasse die Assumptions der öffentlichen Felder zusammentragen: + TypeAssumptions publicFieldsAssumptions = new TypeAssumptions(); + for(Class cl : KlassenVektor){ + publicFieldsAssumptions.add(cl.getPublicFieldAssumptions()); + } + + // Die BasicAssumptions anfügen: + publicFieldsAssumptions.add(this.getBasicAssumptions()); + + // Fuer jede Klasse separat den TRA aufrufen + Iterator class_it = KlassenVektor.iterator(); + while (class_it.hasNext()) { + Class cl = class_it.next(); + CSupportData supportData = new CSupportData(finiteClosure, A, cl.getName(), cl.get_ParaList()); + inferencelog.info("Rufe " + cl.getName() + ".TRProg()..."); + A.addAll(cl.TRProg(supportData, publicFieldsAssumptions)); + } + + return A; + } +// ino.end + + /** + * Erstellt die Basic Assumptions (siehe MakeBasicAssumptions) als AssumptionSet + * @return + */ + private TypeAssumptions getBasicAssumptions() { + TypeAssumptions ret = new TypeAssumptions(); + + // AB hier der Teil aus makeBasicAssumptionsFromJRE: + Vector doneImports=new Vector(); + + //CTypeReconstructionResult basicAssumptions = new CTypeReconstructionResult(null); + + Modifiers mod = new Modifiers(); + mod.addModifier(new Public()); + + + // Für jede einzelne Klasse + while (imports.size()>0) { + UsedId importDecl = imports.get(0); + + // Properties laden + java.lang.Class x; + try { + x = java.lang.Class.forName(importDecl.getQualifiedName()); + } catch (ClassNotFoundException e) { + throw new CTypeReconstructionException("Fehlerhafte Import-Declaration: "+e.getMessage(),importDecl); + } + + java.lang.reflect.Field[] fields=x.getDeclaredFields(); + java.lang.reflect.Method[] methods=x.getDeclaredMethods(); + java.lang.reflect.Constructor[] constructors=x.getConstructors(); + java.lang.reflect.TypeVariable[] tvs=x.getTypeParameters(); + //String className=x.getSimpleName(); + String className=x.getName(); + + // Generische Typen erzeugen + + + Hashtable jreSpiderRegistry=new Hashtable(); + Vector typeGenPara = new Vector(); + for(int j=0;j0){ + //basicAssumptions.addGenericTypeVars(className, typeGenPara); + //myCl.set_ParaList((Vector)typeGenPara); + } + + + if(x.getSuperclass()!=null){ + //boolean isObject=x.getSuperclass().getSimpleName().equalsIgnoreCase("Object"); + boolean isObject=x.getSuperclass().getName().equalsIgnoreCase("java.lang.Object"); + boolean isBaseType=isBaseType(className); + + //if((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && (!isBaseType|| READ_BASE_TYPE_SUPERCLASSES_FROM_JRE)) + if (((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && READ_IMPORTED_SUPERCLASSES_FROM_JRE) //eingefuegt 07-08-11 + || (isBaseType && READ_BASE_TYPE_SUPERCLASSES_FROM_JRE)) + { + String superclassFullyQualifiedName = x.getSuperclass().getCanonicalName(); + //Andere Methode, da Vector.contains bei Strings nicht richtig vergleicht. + if(!containsString(imports,superclassFullyQualifiedName) && !containsString(doneImports,superclassFullyQualifiedName)){ + imports.addElement(UsedId.createFromQualifiedName(superclassFullyQualifiedName,-1)); + } + //UsedId ui = new UsedId(); + //ui.set_Name(x.getSuperclass().getSimpleName()); + UsedId ui=UsedId.createFromQualifiedName(x.getSuperclass().getName(),-1); + java.lang.Class superClass=x.getSuperclass(); + java.lang.reflect.TypeVariable[] superclassTVS=superClass.getTypeParameters(); + Vector supertypeGenPara = new Vector(); + for(int tvi=0;tvi()); + CInstVarTypeAssumption instVar = new CInstVarTypeAssumption(className, fields[j].getName(), new RefType(fields[j].getType().getName(),-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector()); + //basicAssumptions.addFieldOrLocalVarAssumption(instVar); + ret.add(instVar); + } + } + for(int j=0;j(),null); + + + for(int k=0;k())); + } + //basicAssumptions.addMethodIntersectionType(new CIntersectionType(method)); + ret.add(method); + } + } + + for(int j=0;j(),null); + for(int k=0;k())); + } + //basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor)); + ret.add(constructor); + } + } + + imports.removeElement(importDecl); + doneImports.addElement(importDecl); + + } + + imports.addAll(doneImports); + + return ret; + } + + // ino.method.makeBasicAssumptionsFromJRE.21409.definition + @Deprecated //angefügt von Andreas Stadelmeier. Grund: Die Funktion wurde neu als getBasicAssumptions angelegt + private CTypeReconstructionResult makeBasicAssumptionsFromJRE(Vector imports) + // ino.end + // ino.method.makeBasicAssumptionsFromJRE.21409.body + { + + Vector doneImports=new Vector(); + + CTypeReconstructionResult basicAssumptions = new CTypeReconstructionResult(null); + + Modifiers mod = new Modifiers(); + mod.addModifier(new Public()); + + + // Für jede einzelne Klasse + while (imports.size()>0) { + UsedId importDecl = imports.get(0); + + // Properties laden + java.lang.Class x; + try { + x = java.lang.Class.forName(importDecl.getQualifiedName()); + } catch (ClassNotFoundException e) { + throw new CTypeReconstructionException("Fehlerhafte Import-Declaration: "+e.getMessage(),importDecl); + } + + java.lang.reflect.Field[] fields=x.getDeclaredFields(); + java.lang.reflect.Method[] methods=x.getDeclaredMethods(); + java.lang.reflect.Constructor[] constructors=x.getConstructors(); + java.lang.reflect.TypeVariable[] tvs=x.getTypeParameters(); + //String className=x.getSimpleName(); + String className=x.getName(); + + // Generische Typen erzeugen + + + Hashtable jreSpiderRegistry=new Hashtable(); + Vector typeGenPara = new Vector(); + for(int j=0;j0){ + basicAssumptions.addGenericTypeVars(className, typeGenPara); + myCl.set_ParaList((Vector)typeGenPara); + } + + + if(x.getSuperclass()!=null){ + //boolean isObject=x.getSuperclass().getSimpleName().equalsIgnoreCase("Object"); + boolean isObject=x.getSuperclass().getName().equalsIgnoreCase("java.lang.Object"); + boolean isBaseType=isBaseType(className); + + //if((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && (!isBaseType|| READ_BASE_TYPE_SUPERCLASSES_FROM_JRE)) + if (((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && READ_IMPORTED_SUPERCLASSES_FROM_JRE) //eingefuegt 07-08-11 + || (isBaseType && READ_BASE_TYPE_SUPERCLASSES_FROM_JRE)) + { + String superclassFullyQualifiedName = x.getSuperclass().getCanonicalName(); + //Andere Methode, da Vector.contains bei Strings nicht richtig vergleicht. + if(!containsString(imports,superclassFullyQualifiedName) && !containsString(doneImports,superclassFullyQualifiedName)){ + imports.addElement(UsedId.createFromQualifiedName(superclassFullyQualifiedName,-1)); + } + //UsedId ui = new UsedId(); + //ui.set_Name(x.getSuperclass().getSimpleName()); + UsedId ui=UsedId.createFromQualifiedName(x.getSuperclass().getName(),-1); + java.lang.Class superClass=x.getSuperclass(); + java.lang.reflect.TypeVariable[] superclassTVS=superClass.getTypeParameters(); + Vector supertypeGenPara = new Vector(); + for(int tvi=0;tvi()); + CInstVarTypeAssumption instVar = new CInstVarTypeAssumption(className, fields[j].getName(), new RefType(fields[j].getType().getName(),-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector()); + basicAssumptions.addFieldOrLocalVarAssumption(instVar); + } + } + for(int j=0;j(),null); + + + for(int k=0;k())); + } + basicAssumptions.addMethodIntersectionType(new CIntersectionType(method)); + } + } + + for(int j=0;j(),null); + for(int k=0;k())); + } + basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor)); + } + } + + imports.removeElement(importDecl); + doneImports.addElement(importDecl); + + } + + imports.addAll(doneImports); + return basicAssumptions; + } + // ino.end + + + + // ino.method.isBaseType.21412.definition + private boolean isBaseType(String type) + // ino.end + // ino.method.isBaseType.21412.body + { + return baseTypeTranslationTable.containsValue(type); + } + // ino.end + + /*Die contains Methode des Vectors vergleicht bei Strings nicht korrekt, + * da zwei Strings mit dem gleichen Inhalt unterschiedliche Instanzen sind. + * Deshalb diese Methode 07-01-20 luar*/ + private boolean containsString(Vector searchVector, String searchString) + { + boolean found = false; + for(UsedId id : searchVector) + { + String s = id.getQualifiedName(); + found |= s.equals(searchString); + } + return found; + } + + + // ino.method.createTypeFromJavaGenericType.21415.definition + private Type createTypeFromJavaGenericType(java.lang.reflect.Type type, java.lang.Class cl, HashtablejreSpiderRegistry) + // ino.end + // ino.method.createTypeFromJavaGenericType.21415.body + { + if(type instanceof TypeVariableImpl){ + TypeVariableImpl tvi=((TypeVariableImpl)type); + return(new GenericTypeVar(jreSpiderRegistry.get(tvi.getName()).getName(),-1)); + }else{ + //String jccNameForClass=baseTypeTranslationTable.get(cl.getSimpleName()); + String jccNameForClass=baseTypeTranslationTable.get(cl.getName()); + if(cl.getSimpleName().equalsIgnoreCase("void")){ + return(new Void(-1)); + }else if(jccNameForClass!=null){ + RefType rt=new RefType(jccNameForClass,-1); + rt.setPrimitiveFlag(true); + return(rt); + }else{ + //return(new RefType(cl.getSimpleName())); + return(new RefType(cl.getName(),-1)); + } + } + } + // ino.end + + + // ino.method.makeBasicAssumptions.21418.defdescription type=javadoc + /** + * Erzeugt die Anfangsinformationen �ber bereits bekannte Klassen. + *
Achtung Workaround: Die RefTypes m�ssen sp�ter noch durch BaseTypes + * ersetzt werden.
+ * Author: J�rg B�uerle + * + * @return A priori Typinformationen + * @throws ClassNotFoundException + */ + // ino.end + // ino.method.makeBasicAssumptions.21418.definition + private CTypeReconstructionResult makeBasicAssumptions() + // ino.end + // ino.method.makeBasicAssumptions.21418.body + { + + if(LOAD_BASIC_ASSUMPTIONS_FROM_JRE){ + + Vector strImports=new Vector(); + ImportDeclarations usedIdImports=getImports(); + for(int i=0;i()); + foo.addFieldOrLocalVarAssumption(instVar); + + meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "", new RefType("java.lang.Integer",-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + meth.addParaAssumption(new CParaTypeAssumption("java.lang.Integer", "", 1, 0,"value", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector())); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "intValue", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + + + c = new BasicAssumptionClass("java.lang.Integer", mod); + + // ui = new UsedId(); + // ui.set_Name("Super-Class-Blub"); + // c.set_UsedId(ui); + // pl = new Vector(); + // pl.addElement(new GenericTypeVar("bla")); + // c.set_ParaList(pl); + this.addElement(c); + + //------------------------ + // Boolean bauen: + //------------------------ + foo.addClassName("java.lang.Boolean"); //PL 05-08-01 eingefuegt + meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "", new RefType("java.lang.Boolean",-1),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "", new RefType("java.lang.Boolean",-1), 1,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + meth.addParaAssumption(new CParaTypeAssumption("java.lang.Boolean", "", 1, 0, "value", new RefType("java.lang.Boolean",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector())); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "booleanValue", new RefType("java.lang.Boolean",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + c = new BasicAssumptionClass("java.lang.Boolean", mod); + + // ui = new UsedId(); + // ui.set_Name("Super-Class-Blub"); + // c.set_UsedId(ui); + // pl = new Vector(); + // pl.addElement(new GenericTypeVar("bla")); + // c.set_ParaList(pl); + this.addElement(c); + + //------------------------ + // Character bauen: + //------------------------ + foo.addClassName("java.lang.Character"); //PL 05-08-01 eingefuegt + meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "", new RefType("java.lang.Character",-1),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "", new RefType("java.lang.Character",-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + meth.addParaAssumption(new CParaTypeAssumption("java.lang.Character", "", 1, 0,"value", new RefType("java.lang.Character",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector())); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "charValue", new BooleanType(),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + c = new BasicAssumptionClass("java.lang.Character", mod); + + // ui = new UsedId(); + // ui.set_Name("Super-Class-Blub"); + // c.set_UsedId(ui); + // pl = new Vector(); + // pl.addElement(new GenericTypeVar("bla")); + // c.set_ParaList(pl); + this.addElement(c); + + //------------------------ + // Vector bauen: + //------------------------ + foo.addClassName("java.lang.Vector"); //PL 05-08-01 eingefuegt + TypePlaceholder E = TypePlaceholder.fresh(); // Sp�ter ersetzen durch GenericTypeVar + Vector typeGenPara = new Vector(); + typeGenPara.addElement(new GenericTypeVar(E.getName(),-1)); + foo.addGenericTypeVars("java.lang.Vector", typeGenPara); + meth = new CMethodTypeAssumption(new RefType("java.lang.Vector", 0), "elementAt", new GenericTypeVar(E.getName(),-1), 1,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + meth.addParaAssumption(new CParaTypeAssumption("java.lang.Vector", "elementAt", 1, 0, "index", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector())); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + meth = new CMethodTypeAssumption(new RefType("java.lang.Vector", 0), "addElement", new Void(-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + meth.addParaAssumption(new CParaTypeAssumption("java.lang.Vector", "addElement", 1, 0,"element", new GenericTypeVar(E.getName(),-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector())); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + meth = new CMethodTypeAssumption(new RefType("java.lang.Vector", 0), "size", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector(),null); + foo.addMethodIntersectionType(new CIntersectionType(meth)); + + c = new BasicAssumptionClass("java.lang.Vector", mod); + + // ui = new UsedId(); + // ui.set_Name("Super-Class-Blub"); + // c.set_UsedId(ui); + // pl = new Vector(); + // pl.addElement(E); + // c.set_ParaList(pl); + this.addElement(c); + + //------------------------ + // Stack bauen: + //------------------------ + foo.addClassName("java.lang.Stack"); //PL 05-08-01 eingefuegt + c = new BasicAssumptionClass("java.lang.Stack", mod); + ui = new UsedId(-1); + ui.set_Name("java.lang.Vector"); + c.set_UsedId(ui); + // pl = new Vector(); + // pl.addElement(E); + // c.set_ParaList(pl); + this.addElement(c); + + return foo; + } + // ino.end + + // ino.method.setImports.21421.definition + private void setImports(ImportDeclarations newImports) + // ino.end + // ino.method.setImports.21421.body + { + this.imports=newImports; + + } + // ino.end + + + // ino.method.removeBasicAssumptions.21424.defdescription type=javadoc + /** + * L�scht die Anfangsinformation wieder aus dem Klassenvektor + *
Author: J�rg B�uerle + */ + // ino.end + // ino.method.removeBasicAssumptions.21424.definition + private void removeBasicAssumptions() + // ino.end + // ino.method.removeBasicAssumptions.21424.body + { + for(int i=0; iAuthor: J�rg B�uerle + * @param res + * / + * /*private void addClassNamesAndGenericsToRR(CTypeReconstructionResult res){ + * Iterator it = this.getClassIterator(); + * while(it.hasNext()){ + * Class cl = it.next(); + * res.addClassName(cl.get_classname()); + * Vector genericsList = new Vector(); + * + * for(int i =0; i getClassIterator() + // ino.end + // ino.method.getClassIterator.21439.body + { + return KlassenVektor.iterator(); + } + // ino.end + + // ino.method.getInterfaceIterator.21442.definition + public Iterator getInterfaceIterator() + // ino.end + // ino.method.getInterfaceIterator.21442.body + { + return InterfaceVektor.iterator(); + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mybytecode/Attribute.java b/src/mycompiler/mybytecode/Attribute.java new file mode 100755 index 000000000..f89b5c8ca --- /dev/null +++ b/src/mycompiler/mybytecode/Attribute.java @@ -0,0 +1,56 @@ +// ino.module.Attribute.8529.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.Attribute.8529.import +import java.io.FileOutputStream; +import java.io.IOException; +import mycompiler.myexception.JVMCodeException; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.Attribute.21446.declaration +public abstract class Attribute +// ino.end +// ino.class.Attribute.21446.body +{ + // ino.attribute.codegenlog.21449.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.21449.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + + // ino.attribute.attribute_name_index.21452.declaration + private short attribute_name_index; + // ino.end + + // ino.method.get_attribute_name_index.21455.definition + public short get_attribute_name_index() + // ino.end + // ino.method.get_attribute_name_index.21455.body + { + return this.attribute_name_index; + } + // ino.end + + // ino.method.set_attribute_name_index.21458.definition + public void set_attribute_name_index(short t) + // ino.end + // ino.method.set_attribute_name_index.21458.body + { + this.attribute_name_index = t; + } + // ino.end + + // ino.method.codegen.21461.declaration + public abstract void codegen(ClassFile classfile, FileOutputStream f) + throws JVMCodeException, IOException; + // ino.end + + // ino.method.get_attributes_length.21464.declaration + public abstract int get_attributes_length(); + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mybytecode/AttributeInfo.java b/src/mycompiler/mybytecode/AttributeInfo.java new file mode 100755 index 000000000..405e75815 --- /dev/null +++ b/src/mycompiler/mybytecode/AttributeInfo.java @@ -0,0 +1,89 @@ +// ino.module.AttributeInfo.8530.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.AttributeInfo.8530.import +import java.io.FileOutputStream; +import java.lang.reflect.Array; +import java.util.Vector; +import mycompiler.myexception.JVMCodeException; +// ino.end + +// ino.class.AttributeInfo.21467.declaration +public class AttributeInfo extends Attribute +// ino.end +// ino.class.AttributeInfo.21467.body +{ + // ino.attribute.info.21471.declaration + private byte[] info = {}; + // ino.end + + // ino.method.get_info.21474.definition + public byte[] get_info() + // ino.end + // ino.method.get_info.21474.body + { + return this.info; + } + // ino.end + + // ino.method.get_info_Vector.21477.definition + public Vector get_info_Vector() + // ino.end + // ino.method.get_info_Vector.21477.body + { + Vector ret = new Vector(); + for (int i = 0; i < Array.getLength(info); i++) + ret.addElement(new Byte(info[i])); + return ret; + } + // ino.end + + // ino.method.get_attributes_length.21480.definition + public int get_attributes_length() + // ino.end + // ino.method.get_attributes_length.21480.body + { + return Array.getLength(info); + } + // ino.end + + // ino.method.set_info.21483.definition + public void set_info(byte[] t) + // ino.end + // ino.method.set_info.21483.body + { + this.info = t; + } + // ino.end + + // ino.method.set_info.21486.definition + public void set_info(Vector t) + // ino.end + // ino.method.set_info.21486.body + { + byte[] set = new byte[t.size()]; + for (int i = 0; i < t.size(); i++) + Array.setByte(set, i, ((Byte) t.elementAt(i)).byteValue()); + this.info = set; + } + // ino.end + + // ino.method.codegen.21489.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws JVMCodeException, java.io.IOException + // ino.end +// ino.method.codegen.21489.body +{ + + classfile.writeShort(f, get_attribute_name_index()); + classfile.writeInt(f, Array.getLength(info)); + if (info != null) classfile.writeByteArray(f, info); + + codegenlog.debug("Attribute_Name_Index= " + get_attribute_name_index() + + ", Length= " + Array.getLength(info) + " "); + } +// ino.end + +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_Class_info.java b/src/mycompiler/mybytecode/CONSTANT_Class_info.java new file mode 100755 index 000000000..b54c6d7f7 --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_Class_info.java @@ -0,0 +1,58 @@ +// ino.module.CONSTANT_Class_info.8533.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CONSTANT_Class_info.8533.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + +// ino.class.CONSTANT_Class_info.21763.declaration +public class CONSTANT_Class_info extends CPInfo +// ino.end +// ino.class.CONSTANT_Class_info.21763.body +{ + // ino.attribute.name_index.21767.declaration + private short name_index; + // ino.end + + // ino.method.get_name_index.21770.definition + public short get_name_index() + // ino.end + // ino.method.get_name_index.21770.body + { + return this.name_index; + } + // ino.end + + // ino.method.set_name_index.21773.definition + public void set_name_index(short i) + // ino.end + // ino.method.set_name_index.21773.body + { + this.name_index = i; + } + // ino.end + + // ino.method.codegen.21776.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.21776.body + { + classfile.writeByte(f, get_tag()); + classfile.writeShort(f, name_index); + } + // ino.end + + // ino.method.toString.21779.definition + public String toString() + // ino.end + // ino.method.toString.21779.body + { + return "ClassInfo: name_index=" + name_index; + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_Double_info.java b/src/mycompiler/mybytecode/CONSTANT_Double_info.java new file mode 100755 index 000000000..a720799e4 --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_Double_info.java @@ -0,0 +1,69 @@ +// ino.module.CONSTANT_Double_info.8534.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CONSTANT_Double_info.8534.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + +// ino.class.CONSTANT_Double_info.21782.declaration +public class CONSTANT_Double_info extends CPInfo +// ino.end +// ino.class.CONSTANT_Double_info.21782.body +{ + // ino.attribute.high_bytes.21786.declaration + private int high_bytes; + // ino.end + // ino.attribute.low_bytes.21789.declaration + private int low_bytes; + // ino.end + + // ino.method.get_high_bytes.21792.definition + public int get_high_bytes() + // ino.end + // ino.method.get_high_bytes.21792.body + { return this.high_bytes; } + // ino.end + // ino.method.get_low_bytes.21795.definition + public int get_low_bytes() + // ino.end + // ino.method.get_low_bytes.21795.body + { return this.low_bytes; } + // ino.end + + // ino.method.set_high_bytes.21798.definition + public void set_high_bytes(int t) + // ino.end + // ino.method.set_high_bytes.21798.body + { this.high_bytes = t; } + // ino.end + // ino.method.set_low_bytes.21801.definition + public void set_low_bytes(int t) + // ino.end + // ino.method.set_low_bytes.21801.body + { this.low_bytes = t; } + // ino.end + + // ino.method.codegen.21804.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.21804.body + { + classfile.writeByte(f, get_tag()); + classfile.writeInt(f, high_bytes); + classfile.writeInt(f, low_bytes); + } + // ino.end + + // ino.method.toString.21807.definition + public String toString() + // ino.end + // ino.method.toString.21807.body + { + return "Double_Info: high_bytes=" + high_bytes + ", low_bytes=" + low_bytes; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_Fieldref_info.java b/src/mycompiler/mybytecode/CONSTANT_Fieldref_info.java new file mode 100755 index 000000000..fca75546d --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_Fieldref_info.java @@ -0,0 +1,81 @@ +// ino.module.CONSTANT_Fieldref_info.8535.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CONSTANT_Fieldref_info.8535.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + +// ino.class.CONSTANT_Fieldref_info.21810.declaration +public class CONSTANT_Fieldref_info extends CPInfo +// ino.end +// ino.class.CONSTANT_Fieldref_info.21810.body +{ + // ino.attribute.class_index.21814.declaration + private short class_index; + // ino.end + + // ino.attribute.name_and_type_index.21817.declaration + private short name_and_type_index; + // ino.end + + // ino.method.get_class_index.21820.definition + public short get_class_index() + // ino.end + // ino.method.get_class_index.21820.body + { + return this.class_index; + } + // ino.end + + // ino.method.get_name_and_type_index.21823.definition + public short get_name_and_type_index() + // ino.end + // ino.method.get_name_and_type_index.21823.body + { + return this.name_and_type_index; + } + // ino.end + + // ino.method.set_class_index.21826.definition + public void set_class_index(short i) + // ino.end + // ino.method.set_class_index.21826.body + { + this.class_index = i; + } + // ino.end + + // ino.method.set_name_and_type_index.21829.definition + public void set_name_and_type_index(short i) + // ino.end + // ino.method.set_name_and_type_index.21829.body + { + this.name_and_type_index = i; + } + // ino.end + + // ino.method.codegen.21832.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.21832.body + { + classfile.writeByte(f, get_tag()); + classfile.writeShort(f, class_index); + classfile.writeShort(f, name_and_type_index); + } + // ino.end + + // ino.method.toString.21835.definition + public String toString() + // ino.end + // ino.method.toString.21835.body + { + return "Fieldref_info: Class_index="+ class_index + + ", Name_and_type_index=" + name_and_type_index; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_Float_info.java b/src/mycompiler/mybytecode/CONSTANT_Float_info.java new file mode 100755 index 000000000..95317a506 --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_Float_info.java @@ -0,0 +1,51 @@ +// ino.module.CONSTANT_Float_info.8536.package +package mycompiler.mybytecode; +// ino.end +// ino.module.CONSTANT_Float_info.8536.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + +// ino.class.CONSTANT_Float_info.21838.declaration +public class CONSTANT_Float_info extends CPInfo +// ino.end +// ino.class.CONSTANT_Float_info.21838.body +{ + // ino.attribute.bytes.21842.declaration + private int bytes; + // ino.end + + // ino.method.get_bytes.21845.definition + public int get_bytes() + // ino.end + // ino.method.get_bytes.21845.body + { return this.bytes; } + // ino.end + // ino.method.set_bytes.21848.definition + public void set_bytes(int t) + // ino.end + // ino.method.set_bytes.21848.body + { this.bytes = t; } + // ino.end + + // ino.method.codegen.21851.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.21851.body + { + classfile.writeByte(f, get_tag()); + classfile.writeInt(f, bytes); + } + // ino.end + + // ino.method.toString.21854.definition + public String toString() + // ino.end + // ino.method.toString.21854.body + { + return "Float_Info: size=" + bytes; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_Integer_info.java b/src/mycompiler/mybytecode/CONSTANT_Integer_info.java new file mode 100755 index 000000000..7150cc6eb --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_Integer_info.java @@ -0,0 +1,54 @@ +// ino.module.CONSTANT_Integer_info.8537.package +package mycompiler.mybytecode; +// ino.end +// ino.module.CONSTANT_Integer_info.8537.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + + + + +// ino.class.CONSTANT_Integer_info.21857.declaration +public class CONSTANT_Integer_info extends CPInfo +// ino.end +// ino.class.CONSTANT_Integer_info.21857.body +{ + // ino.attribute.bytes.21861.declaration + private int bytes; + // ino.end + + // ino.method.get_bytes.21864.definition + public int get_bytes() + // ino.end + // ino.method.get_bytes.21864.body + { return this.bytes; } + // ino.end + // ino.method.set_bytes.21867.definition + public void set_bytes(int t) + // ino.end + // ino.method.set_bytes.21867.body + { this.bytes = t; } + // ino.end + + // ino.method.codegen.21870.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.21870.body + { + classfile.writeByte(f, get_tag()); + classfile.writeInt(f, bytes); + } + // ino.end + + // ino.method.toString.21873.definition + public String toString() + // ino.end + // ino.method.toString.21873.body + { + return "Integer_Info: bytes=" + bytes; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_InterfaceMethodref_info.java b/src/mycompiler/mybytecode/CONSTANT_InterfaceMethodref_info.java new file mode 100755 index 000000000..c00288e6b --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_InterfaceMethodref_info.java @@ -0,0 +1,82 @@ +// ino.module.CONSTANT_InterfaceMethodref_info.8538.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CONSTANT_InterfaceMethodref_info.8538.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + +// ino.class.CONSTANT_InterfaceMethodref_info.21876.declaration +public class CONSTANT_InterfaceMethodref_info extends CPInfo +// ino.end +// ino.class.CONSTANT_InterfaceMethodref_info.21876.body +{ + // ino.attribute.class_index.21880.declaration + private short class_index; + // ino.end + + // ino.attribute.name_and_type_index.21883.declaration + private short name_and_type_index; + // ino.end + + // ino.method.get_class_index.21886.definition + public short get_class_index() + // ino.end + // ino.method.get_class_index.21886.body + { + return this.class_index; + } + // ino.end + + // ino.method.get_name_and_type_index.21889.definition + public short get_name_and_type_index() + // ino.end + // ino.method.get_name_and_type_index.21889.body + { + return this.name_and_type_index; + } + // ino.end + + // ino.method.set_class_index.21892.definition + public void set_class_index(short t) + // ino.end + // ino.method.set_class_index.21892.body + { + this.class_index = t; + } + // ino.end + + // ino.method.set_name_and_type_index.21895.definition + public void set_name_and_type_index(short t) + // ino.end + // ino.method.set_name_and_type_index.21895.body + { + this.name_and_type_index = t; + } + // ino.end + + // ino.method.codegen.21898.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.21898.body + { + classfile.writeByte(f, get_tag()); + classfile.writeShort(f, class_index); + classfile.writeShort(f, name_and_type_index); + } + // ino.end + + @Override + // ino.method.toString.21901.definition + public String toString() + // ino.end + // ino.method.toString.21901.body + { + return "InterfaceMethodRef_info: class_index=" + class_index + + ", name_and_type_index=" + name_and_type_index; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_Long_info.java b/src/mycompiler/mybytecode/CONSTANT_Long_info.java new file mode 100755 index 000000000..76b2719c4 --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_Long_info.java @@ -0,0 +1,81 @@ +// ino.module.CONSTANT_Long_info.8539.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CONSTANT_Long_info.8539.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + +// ino.class.CONSTANT_Long_info.21904.declaration +public class CONSTANT_Long_info extends CPInfo +// ino.end +// ino.class.CONSTANT_Long_info.21904.body +{ + // ino.attribute.high_bytes.21908.declaration + private int high_bytes; + // ino.end + + // ino.attribute.low_bytes.21911.declaration + private int low_bytes; + // ino.end + + // ino.method.get_high_bytes.21914.definition + public int get_high_bytes() + // ino.end + // ino.method.get_high_bytes.21914.body + { + return this.high_bytes; + } + // ino.end + + // ino.method.get_low_bytes.21917.definition + public int get_low_bytes() + // ino.end + // ino.method.get_low_bytes.21917.body + { + return this.low_bytes; + } + // ino.end + + // ino.method.set_high_bytes.21920.definition + public void set_high_bytes(int t) + // ino.end + // ino.method.set_high_bytes.21920.body + { + this.high_bytes = t; + } + // ino.end + + // ino.method.set_low_bytes.21923.definition + public void set_low_bytes(int t) + // ino.end + // ino.method.set_low_bytes.21923.body + { + this.low_bytes = t; + } + // ino.end + + // ino.method.codegen.21926.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.21926.body + { + classfile.writeByte(f, get_tag()); + classfile.writeInt(f, high_bytes); + classfile.writeInt(f, low_bytes); + } + // ino.end + + // ino.method.toString.21929.definition + public String toString() + // ino.end + // ino.method.toString.21929.body + { + return "Long_Info: high_bytes=" + high_bytes + + ", low_bytes=" + low_bytes; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_Methodref_info.java b/src/mycompiler/mybytecode/CONSTANT_Methodref_info.java new file mode 100755 index 000000000..692ef0d94 --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_Methodref_info.java @@ -0,0 +1,81 @@ +// ino.module.CONSTANT_Methodref_info.8540.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CONSTANT_Methodref_info.8540.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + +// ino.class.CONSTANT_Methodref_info.21932.declaration +public class CONSTANT_Methodref_info extends CPInfo +// ino.end +// ino.class.CONSTANT_Methodref_info.21932.body +{ + // ino.attribute.class_index.21936.declaration + private short class_index; + // ino.end + + // ino.attribute.name_and_type_index.21939.declaration + private short name_and_type_index; + // ino.end + + // ino.method.get_class_index.21942.definition + public short get_class_index() + // ino.end + // ino.method.get_class_index.21942.body + { + return this.class_index; + } + // ino.end + + // ino.method.get_name_and_type_index.21945.definition + public short get_name_and_type_index() + // ino.end + // ino.method.get_name_and_type_index.21945.body + { + return this.name_and_type_index; + } + // ino.end + + // ino.method.set_class_index.21948.definition + public void set_class_index(short t) + // ino.end + // ino.method.set_class_index.21948.body + { + this.class_index = t; + } + // ino.end + + // ino.method.set_name_and_type_index.21951.definition + public void set_name_and_type_index(short t) + // ino.end + // ino.method.set_name_and_type_index.21951.body + { + this.name_and_type_index = t; + } + // ino.end + + // ino.method.codegen.21954.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.21954.body + { + classfile.writeByte(f, get_tag()); + classfile.writeShort(f, class_index); + classfile.writeShort(f, name_and_type_index); + } + // ino.end + + // ino.method.toString.21957.definition + public String toString() + // ino.end + // ino.method.toString.21957.body + { + return "MethodRef_Info: class_index=" + class_index + + ", name_and_type_index=" + name_and_type_index; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_NameAndType_info.java b/src/mycompiler/mybytecode/CONSTANT_NameAndType_info.java new file mode 100755 index 000000000..2bd63b58d --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_NameAndType_info.java @@ -0,0 +1,81 @@ +// ino.module.CONSTANT_NameAndType_info.8541.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CONSTANT_NameAndType_info.8541.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + +// ino.class.CONSTANT_NameAndType_info.21960.declaration +public class CONSTANT_NameAndType_info extends CPInfo +// ino.end +// ino.class.CONSTANT_NameAndType_info.21960.body +{ + // ino.attribute.name_index.21964.declaration + private short name_index; + // ino.end + + // ino.attribute.descriptor_index.21967.declaration + private short descriptor_index; + // ino.end + + // ino.method.get_name_index.21970.definition + public short get_name_index() + // ino.end + // ino.method.get_name_index.21970.body + { + return this.name_index; + } + // ino.end + + // ino.method.get_descriptor_index.21973.definition + public short get_descriptor_index() + // ino.end + // ino.method.get_descriptor_index.21973.body + { + return this.descriptor_index; + } + // ino.end + + // ino.method.set_name_index.21976.definition + public void set_name_index(short t) + // ino.end + // ino.method.set_name_index.21976.body + { + this.name_index = t; + } + // ino.end + + // ino.method.set_descriptor_index.21979.definition + public void set_descriptor_index(short t) + // ino.end + // ino.method.set_descriptor_index.21979.body + { + this.descriptor_index = t; + } + // ino.end + + // ino.method.codegen.21982.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.21982.body + { + classfile.writeByte(f, get_tag()); + classfile.writeShort(f, name_index); + classfile.writeShort(f, descriptor_index); + } + // ino.end + + // ino.method.toString.21985.definition + public String toString() + // ino.end + // ino.method.toString.21985.body + { + return "NameAndType_Info: name_index=" + name_index + + ", descriptor_index=" + descriptor_index; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_String_info.java b/src/mycompiler/mybytecode/CONSTANT_String_info.java new file mode 100755 index 000000000..1c36bfac2 --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_String_info.java @@ -0,0 +1,57 @@ +// ino.module.CONSTANT_String_info.8542.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CONSTANT_String_info.8542.import +import java.io.FileOutputStream; +import java.io.IOException; +// ino.end + +// ino.class.CONSTANT_String_info.21988.declaration +public class CONSTANT_String_info extends CPInfo +// ino.end +// ino.class.CONSTANT_String_info.21988.body +{ + // ino.attribute.string_index.21992.declaration + private short string_index; + // ino.end + + // ino.method.get_string_index.21995.definition + public short get_string_index() + // ino.end + // ino.method.get_string_index.21995.body + { + return this.string_index; + } + // ino.end + + // ino.method.set_string_index.21998.definition + public void set_string_index(short t) + // ino.end + // ino.method.set_string_index.21998.body + { + this.string_index = t; + } + // ino.end + + // ino.method.codegen.22001.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.22001.body + { + classfile.writeByte(f, get_tag()); + classfile.writeShort(f, string_index); + } + // ino.end + + // ino.method.toString.22004.definition + public String toString() + // ino.end + // ino.method.toString.22004.body + { + return "StringInfo: string_index="+ string_index; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CONSTANT_Utf8_info.java b/src/mycompiler/mybytecode/CONSTANT_Utf8_info.java new file mode 100755 index 000000000..8425249c9 --- /dev/null +++ b/src/mycompiler/mybytecode/CONSTANT_Utf8_info.java @@ -0,0 +1,63 @@ +// ino.module.CONSTANT_Utf8_info.8543.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CONSTANT_Utf8_info.8543.import +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Array; +// ino.end + +// ino.class.CONSTANT_Utf8_info.22007.declaration +public class CONSTANT_Utf8_info extends CPInfo +// ino.end +// ino.class.CONSTANT_Utf8_info.22007.body +{ + // ino.attribute.bytes.22011.declaration + private byte[] bytes; + // ino.end + + // ino.method.get_bytes.22014.definition + public byte[] get_bytes() + // ino.end + // ino.method.get_bytes.22014.body + { + return this.bytes; + } + // ino.end + + // ino.method.set_bytes.22017.definition + public void set_bytes(byte[] t) + // ino.end + // ino.method.set_bytes.22017.body + { + this.bytes = t; + } + // ino.end + + // ino.method.codegen.22020.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.22020.body + { + classfile.writeByte(f, get_tag()); + classfile.writeShort(f, (short) Array.getLength(bytes)); + if (bytes != null) classfile.writeByteArray(f, bytes); + + } + // ino.end + + // ino.method.toString.22023.definition + public String toString() + // ino.end + // ino.method.toString.22023.body + { + if (bytes == null) + return "UTF-8 Konstante: size="+ Array.getLength(bytes) ; + else + return "UTF-8 Konstante: " + new String(bytes); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/CPInfo.java b/src/mycompiler/mybytecode/CPInfo.java new file mode 100755 index 000000000..de91ff93c --- /dev/null +++ b/src/mycompiler/mybytecode/CPInfo.java @@ -0,0 +1,54 @@ +// ino.module.CPInfo.8544.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CPInfo.8544.import +import java.io.FileOutputStream; +import java.io.IOException; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.CPInfo.22026.declaration +public abstract class CPInfo +// ino.end +// ino.class.CPInfo.22026.body +{ + // ino.attribute.codegenlog.22029.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.22029.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + + // ino.attribute.tag.22032.declaration + private byte tag; + // ino.end + + // ino.method.get_tag.22035.definition + public byte get_tag() + // ino.end + // ino.method.get_tag.22035.body + { + return this.tag; + } + // ino.end + + // ino.method.set_tag.22038.definition + public void set_tag(byte t) + // ino.end + // ino.method.set_tag.22038.body + { + this.tag = t; + } + // ino.end + + // ino.method.codegen.22041.declaration + public abstract void codegen(ClassFile classfile, FileOutputStream f) + throws IOException; + // ino.end + + // ino.method.toString.22044.declaration + public abstract String toString(); + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/ClassFile.java b/src/mycompiler/mybytecode/ClassFile.java new file mode 100755 index 000000000..90136ede9 --- /dev/null +++ b/src/mycompiler/mybytecode/ClassFile.java @@ -0,0 +1,841 @@ +// ino.module.ClassFile.8531.package +package mycompiler.mybytecode; +// ino.end +// ino.module.ClassFile.8531.import +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Array; +import java.util.Vector; +import mycompiler.myclass.ParameterList; +import mycompiler.myclass.UsedId; +import mycompiler.MyCompiler; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myinterface.Interface; +import mycompiler.mystatement.Assign; +import mycompiler.mystatement.Block; +import mycompiler.mytype.Type; +import mycompiler.SourceFile; +import org.apache.log4j.Logger; +// ino.end + + +// ino.class.ClassFile.21492.description type=javadoc +/** + * Darstellung einer Klassendatei aus Sicht fuer die JVM. + * Generiert bei der Bytegenerierung Header, Constantenpool, usw. + * + * @author hama, scju + * + */ +// ino.end +// ino.class.ClassFile.21492.declaration +public class ClassFile +// ino.end +// ino.class.ClassFile.21492.body +{ + public boolean hamaAload0 = false; //hama: f�gt in Konstruktor und set Methode ein aload_0 ein wird f�r StoreSomethingParmCon ben�tigt + + // ino.attribute.codegenlog.21495.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.21495.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + + // ino.attribute.magic.21498.decldescription type=line + // Header fuer Java Version 1.5.0_05 + // ino.end + // ino.attribute.magic.21498.declaration + private static int magic = 0xcafebabe; + // ino.end + // ino.attribute.minor_version.21501.declaration + private static short minor_version = 0; + // ino.end + // ino.attribute.major_version.21504.declaration + private static short major_version = 0x31; + // ino.end + + // ino.attribute.constant_pool.21507.declaration + private Vector constant_pool = new Vector(); + // ino.end + // ino.attribute.access_flags.21510.declaration + private short access_flags; + // ino.end + // ino.attribute.this_class.21513.declaration + private short this_class; + // ino.end + // ino.attribute.super_class.21516.declaration + private short super_class; + // ino.end + // ino.attribute.fields.21519.declaration + private Vector fields = new Vector(); + // ino.end + // ino.attribute.methods.21522.declaration + private Vector methods = new Vector(); + // ino.end + // ino.attribute.attributes.21525.declaration + private Vector attributes = new Vector(); + // ino.end + // ino.attribute.interfaces.21528.declaration + private Vector interfaces = new Vector(); + // ino.end + // ino.attribute.key_vector.21531.declaration + private Vector key_vector = new Vector(); + // ino.end + // ino.attribute.class_block.21534.declaration + private Vector class_block = new Vector(); + // ino.end + // ino.attribute.class_name.21537.declaration + private String class_name = new String(); + // ino.end + // ino.attribute.super_class_name.21540.declaration + private String super_class_name = new String(); + // ino.end + // ino.attribute.constructor_founded.21543.declaration + private boolean constructor_founded = false; + // ino.end + + // ino.attribute.ConstantValueID.21546.decldescription type=line + // Wird fuer Konstante benoetigt (UTF-8 Eintrag mit + // "ConstantValue"), lediglich ein Mal pro Klasse + // ino.end + // ino.attribute.ConstantValueID.21546.declaration + private short ConstantValueID = 0; + // ino.end + + // ino.attribute.SignatureID.21549.decldescription type=line + // Wird fuer Signaturen (Generics) benoetigt + // Wiederrum nur ein UTF-8 Eintrag in der + // Konstantentabelle ("Signature") + // ino.end + // ino.attribute.SignatureID.21549.declaration + private short SignatureID = 0; + // ino.end + + + // ino.method.ClassFile.21552.defdescription type=javadoc + /** + * Default Konstruktor + */ + // ino.end + // ino.method.ClassFile.21552.definition + public ClassFile() + // ino.end + // ino.method.ClassFile.21552.body + { + + } + // ino.end + + // ino.method.ClassFile.21555.defdescription type=javadoc + /** + * Konstruktor, um Klasseninfos direkt aus dem Interface zu laden + */ + // ino.end + // ino.method.ClassFile.21555.definition + public ClassFile(Interface ic, SourceFile sf) + // ino.end + // ino.method.ClassFile.21555.body + { + // Modifier wird auf den Wert 0x601 festgelegt (INTERFACE+ABSTRACT+PUBLIC) + // Andere Werte machen hier keinen Sinn! + String pkgName = ""; + + if (sf.getPackageName() != null) { + pkgName = sf.getPackageName().get_codegen_UsedId() + "/"; + } + + this.add_interface(ic.getName(), pkgName, "java/lang/Object", (short) 0x601); + } + // ino.end + + // ino.method.add_CONSTANT_Utf8_info.21558.definition + public int add_CONSTANT_Utf8_info(String name) + // ino.end + // ino.method.add_CONSTANT_Utf8_info.21558.body + { + Key utf8_key = new Key(JVMCode.CONSTANT_Utf8, name); + if(!this.key_vector.contains(utf8_key)) { + CONSTANT_Utf8_info utf8_info = new CONSTANT_Utf8_info(); + utf8_info.set_tag(JVMCode.CONSTANT_Utf8); + utf8_info.set_bytes(name.getBytes()); + this.key_vector.addElement(utf8_key); + this.constant_pool.addElement(utf8_info); + } + return (this.key_vector.indexOf(utf8_key)+1); + } + // ino.end + + // ino.method.add_CONSTANT_Class_info.21561.definition + public int add_CONSTANT_Class_info(String name) + // ino.end + // ino.method.add_CONSTANT_Class_info.21561.body + { + Key class_key = new Key(JVMCode.CONSTANT_Class, name); + if(!this.key_vector.contains(class_key)) { + CONSTANT_Class_info class_info = new CONSTANT_Class_info(); + class_info.set_tag(JVMCode.CONSTANT_Class); + class_info.set_name_index((short)this.add_CONSTANT_Utf8_info(name)); + this.key_vector.addElement(class_key); + this.constant_pool.addElement(class_info); + } + return (this.key_vector.indexOf(class_key)+1); + } + // ino.end + + // ino.method.add_CONSTANT_NameAndType_info.21564.definition + public int add_CONSTANT_NameAndType_info(String name, String param_type) + // ino.end + // ino.method.add_CONSTANT_NameAndType_info.21564.body + { + Key name_type_key = new Key(JVMCode.CONSTANT_NameAndType, name + param_type); + if(!this.key_vector.contains(name_type_key)) + { + CONSTANT_NameAndType_info name_type = new CONSTANT_NameAndType_info(); + name_type.set_tag(JVMCode.CONSTANT_NameAndType); + name_type.set_name_index((short)this.add_CONSTANT_Utf8_info(name)); + name_type.set_descriptor_index((short)this.add_CONSTANT_Utf8_info(param_type)); + this.key_vector.addElement(name_type_key); + this.constant_pool.addElement(name_type); + } + return this.key_vector.indexOf(name_type_key) + 1; + } + // ino.end + + // ino.method.add_CONSTANT_Integer_info.21567.definition + public int add_CONSTANT_Integer_info(int i) + // ino.end + // ino.method.add_CONSTANT_Integer_info.21567.body + { + Key key = new Key(JVMCode.CONSTANT_Integer, "" + i); + if(!this.key_vector.contains(key)) { + CONSTANT_Integer_info info = new CONSTANT_Integer_info(); + info.set_tag(JVMCode.CONSTANT_Integer); + info.set_bytes(i); + this.key_vector.addElement(key); + this.constant_pool.addElement(info); + } + return (this.key_vector.indexOf(key)+1); + } + // ino.end + + // ino.method.add_CONSTANT_String_info.21570.definition + public int add_CONSTANT_String_info(String s) + // ino.end + // ino.method.add_CONSTANT_String_info.21570.body + { + Key key = new Key(JVMCode.CONSTANT_String, s); + if(!this.key_vector.contains(key)) { + CONSTANT_String_info info = new CONSTANT_String_info(); + info.set_tag(JVMCode.CONSTANT_String); + info.set_string_index((short)this.add_CONSTANT_Utf8_info(s)); + this.key_vector.addElement(key); + this.constant_pool.addElement(info); + } + return (this.key_vector.indexOf(key)+1); + } + // ino.end + + // ino.method.add_class.21573.defdescription type=javadoc + /** + * Fuegt Informationen ueber eine neue Klasse ein. Gleichzeitig + * wird ein Default-Konstruktor angelegt. + */ + // ino.end + // ino.method.add_class.21573.definition + public void add_class(String name, String pkgName, String super_name, short acc_flag) + // ino.end + // ino.method.add_class.21573.body + { + codegenlog.debug("Klasse hinzugefuegt: " + name + ", Package: " + pkgName + + ", Superklasse: " + super_name + ", Accessflags: " + acc_flag); + addClassInfo(name, pkgName, super_name, acc_flag); + this.add_method_ref(super_name, "", "()V"); + } + // ino.end + + // ino.method.add_interface.21576.defdescription type=javadoc + /** + * Fuegt Informationen ueber ein neues Interface ein. + */ + // ino.end + // ino.method.add_interface.21576.definition + public void add_interface(String name, String pkgName, String super_name, short acc_flag) + // ino.end + // ino.method.add_interface.21576.body + { + codegenlog.debug("Interface hinzugefuegt: " + name + ", Package: " + pkgName + + ", Superklasse: " + super_name + ", Accessflags: " + acc_flag); + addClassInfo(name, pkgName, super_name, acc_flag); + } + // ino.end + + // ino.method.addClassInfo.21579.defdescription type=javadoc + /** + * Fuegt Informationen ueber Access-Flags, Superklasse usw. ein + */ + // ino.end + // ino.method.addClassInfo.21579.definition + private void addClassInfo(String name, String pkgName, String super_name, short acc_flag) + // ino.end + // ino.method.addClassInfo.21579.body + { + //feda 15.05.2007 + //Eine Klasse hat immer den Access Modifier Super 0x0020 + short tempAcc_super = 32; + acc_flag +=tempAcc_super; + + access_flags = acc_flag; + class_name = name; + super_class_name = super_name; + this.this_class = (short)add_CONSTANT_Class_info(pkgName+name); + this.super_class = (short)add_CONSTANT_Class_info(super_name); + } + // ino.end + + // ino.method.addSuperInterfaces.21582.defdescription type=javadoc + /** + * Fuegt die erweiterten (bei Interfaces) implementierten (bei Klassen) + * Interfaces ein. + */ + // ino.end + // ino.method.addSuperInterfaces.21582.definition + public void addSuperInterfaces(Vector superif) + // ino.end + // ino.method.addSuperInterfaces.21582.body + { + if (superif == null) return; + + for (int i=0; i< superif.size(); i++) { + UsedId uid = superif.elementAt(i); + + interfaces.addElement((short) add_CONSTANT_Class_info(uid.get_codegen_UsedId())); + } + } + // ino.end + + // ino.method.addGenerics.21585.defdescription type=javadoc + /** + * Fuegt ggf. Generics in den Klassendefintion selbst + * hinzu. + */ + // ino.end + // ino.method.addGenerics.21585.definition + public void addGenerics(Vector para, UsedId superClass, Vector superIf) + // ino.end + // ino.method.addGenerics.21585.body + { + if (para == null || para.size() == 0) return; + + SignatureInfo si = new SignatureInfo(para, superClass, superIf, this); + + attributes.addElement(si); + + } + // ino.end + + + // ino.method.add_method.21588.definition + public void add_method(String name, String param_type, ParameterList param, + Type type, Block block, short acc_flag, Vector paralist, boolean isAbstract) + throws JVMCodeException + // ino.end + // ino.method.add_method.21588.body + { + Vector method_attributes = new Vector(); + + + + // Sofern eine Signatur (Generic) in der Beschreibung der Methode vorkommt, + // Signatur generieren. + if(SignatureInfo.needsSignature( param, type)) + method_attributes.addElement(new SignatureInfo(param, type, this)); + + + codegenlog.debug("Methode hinzugefuegt: " + name + ", Parameter-Typ: " + param_type + + ", Accessflags: " + acc_flag); + + + CodeAttribute code = new CodeAttribute(class_name, acc_flag); + code.set_attribute_name_index((short)this.add_CONSTANT_Utf8_info("Code")); + if(name.equals("")) + { + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.invokespecial); + //hama: habe die obere original Zeile auskommentiert. + //Ich bekomme mit der obigen Zeile ein Fehler in der Verlinkung des + //ConstantPool (mit der unteren Zeile nicht) + //code.add_code_short(this.add_method_ref(super_class_name, name, param_type)); + code.add_code_short(this.add_method_ref(super_class_name, name, "()V")); + for(int i = 0; i < class_block.size(); i++) + { + class_block.elementAt(i).codegen(this, code, paralist); + } + if(param != null) param.codegen(this, code); + //hama: in dem Use Case StoreSomething wird vom Compiler ein + //aload_0 zuwening im Konstruktor erzeugt. Deshalb schreibe ich + //es hier hard rein. + //Test Workaround: Das eigentliche Problem: "Warum fehlt das aload_0" ist + //noch nicht behoben. Au�erdem stimmt das hier nur f�r den einen Use Case + //in allen anderen F�llen wird f�lschlicher Weise das aload_0 einef�gt. + if(this.hamaAload0 == true) + { + byte b2 = 42; + Byte b1 = new Byte(b2); + code.add_code(b1); + + codegenlog.warn("hama: Class ClassFile: !!!!!!!!!!!!!!!!!!!!ACHTUNG experimentell aload_0 in Konstrukor eingef�gt!!!"); + } + //hama: bis hier experimentell + if(block != null) + { + block.codegen(this, code, paralist); + } + code.add_code(JVMCode.return_); + } + else + { + if(param != null) + { + param.codegen(this, code); + } + //hama: in dem Use Case StoreSomething wird vom Compiler ein + //aload_0 zuwening in der set Methode erzeugt. Deshalb schreibe ich + //es hier hard rein. + //Test Workaround: Das eigentliche Problem: "Warum fehlt das aload_0" ist + //noch nicht behoben. Au�erdem stimmt das hier nur f�r den einen Use Case + //in allen anderen F�llen einer Set Methode wird f�lschlicher Weise das + //aload_0 einef�gt. + if(this.hamaAload0 == true) + { + if(name.equals("set")) + { + byte b2 = 42; + Byte b1 = new Byte(b2); + code.add_code(b1); + + codegenlog.warn("hama: Class ClassFile: !!!!!!!!!!!!!!!!!!!!ACHTUNG experimentell aload_0 in die set Methode eingef�gt!!!"); + } + } + //hama: bis hier experimentell. + if(block != null) + { + block.codegen(this, code, paralist); + } + if(type != null && type.getName().equals("void")) + { + code.add_code(JVMCode.return_); + } + } + + // Code nur hinzufuegen, wenn nicht abstract (Interface!) + if (!isAbstract) method_attributes.addElement(code); + + // Methodeninformationen zusammenstellen + MethodInfo method = new MethodInfo(); + + //feda Accessflag muss beim 1 = Public sein. + if(name.equals("")) + { + acc_flag = 1; + } + method.set_access_flags(acc_flag); + method.set_name_index((short)add_CONSTANT_Utf8_info(name)); + method.set_descriptor_index((short)add_CONSTANT_Utf8_info(param_type)); + method.set_attributes(method_attributes); + + if(!this.methods.contains(method)) + { + methods.addElement(method); + } + } + // ino.end + + + + // ino.method.add_method_ref.21591.definition + public int add_method_ref(String cl_name, String name, String param_type) + // ino.end + // ino.method.add_method_ref.21591.body + { + + // Bei fully qualified names wichtig! + if (cl_name.contains(".")) cl_name = cl_name.replace(".", "/"); + + + codegenlog.debug("Methodenreferenz hinzugefuegt: " + name + ", Klasse: " + cl_name + + ", Paramter-Typ: " + param_type); + Key methodref_key = new Key(JVMCode.CONSTANT_Methodref, cl_name + name + param_type); + if(!this.key_vector.contains(methodref_key)) + { + CONSTANT_Methodref_info methodref = new CONSTANT_Methodref_info(); + methodref.set_tag(JVMCode.CONSTANT_Methodref); + methodref.set_class_index((short)this.add_CONSTANT_Class_info(cl_name)); + methodref.set_name_and_type_index((short)this.add_CONSTANT_NameAndType_info(name, param_type)); + this.key_vector.addElement(methodref_key); + this.constant_pool.addElement(methodref); + } + return this.key_vector.indexOf(methodref_key)+1; + } + // ino.end + + // ino.method.getConstantValueID.21594.defdescription type=javadoc + /** + * Gibt den NameIndex auf die UTF-8 Konstante "ConstantValue" zurueck, + * der fuer die Definition von Konstanten benoetigt wird. + */ + // ino.end + // ino.method.getConstantValueID.21594.definition + public short getConstantValueID() + // ino.end + // ino.method.getConstantValueID.21594.body + { + if (ConstantValueID == 0) { + ConstantValueID = (short) add_CONSTANT_Utf8_info("ConstantValue"); + } + + return ConstantValueID; + } + // ino.end + + // ino.method.getSignatureID.21597.defdescription type=javadoc + /** + * Gibt den NameIndex auf die UTF-8 Konstante "Signature" zurueck, + * der fuer die Definition von Konstanten benoetigt wird. + */ + // ino.end + // ino.method.getSignatureID.21597.definition + public short getSignatureID() + // ino.end + // ino.method.getSignatureID.21597.body + { + if (SignatureID == 0) { + SignatureID = (short) add_CONSTANT_Utf8_info("Signature"); + } + + return SignatureID; + } + // ino.end + + + + // ino.method.add_field.21600.definition + public void add_field(String name, String type, short acc_flag, Attribute attr) + // ino.end + // ino.method.add_field.21600.body + { + codegenlog.debug("Field hinzugefuegt: " + name + ", Typ: " + type + " ," + + "Accessflags: " + acc_flag); + FieldInfo field = new FieldInfo(); + field.set_Name(name); + field.set_Type(type); + field.set_Class_Name(class_name); + field.set_access_flags(acc_flag); + field.set_name_index((short)this.add_CONSTANT_Utf8_info(name)); + field.set_descriptor_index((short)this.add_CONSTANT_Utf8_info(type)); + if (attr != null) { + Vector vec = new Vector(); + vec.addElement(attr); + field.set_attributes(vec); + } + fields.addElement(field); + } + // ino.end + + // ino.method.add_field_ref.21603.definition + public int add_field_ref(String name, String cl_name, String type) + throws JVMCodeException + // ino.end + // ino.method.add_field_ref.21603.body + { + if(cl_name==null) cl_name = class_name; + if(type==null) { + int index = -1; + for(int i=0; i < fields.size();i++) + if(name.equals(fields.elementAt(i).get_Name())) { index = i; break; } + + if(index == -1) throw new JVMCodeException("JVMCodeException: ClassFile: int add_field_ref(String name, String cla_name, String atype)"); + + FieldInfo field = fields.elementAt(index); + type = field.get_Type(); + cl_name = field.get_Class_Name(); + + codegenlog.debug("Fieldref hinzugefuegt: " + name + ", Klassenname: " + cl_name + + ", Accessflags: " + field.get_access_flags()); + Key fieldref_key = new Key(JVMCode.CONSTANT_Fieldref, cl_name + name + type); + if(!this.key_vector.contains(fieldref_key)) { + CONSTANT_Fieldref_info fieldref = new CONSTANT_Fieldref_info(); + fieldref.set_tag(JVMCode.CONSTANT_Fieldref); + fieldref.set_class_index((short)this.add_CONSTANT_Class_info(cl_name)); + fieldref.set_name_and_type_index((short)this.add_CONSTANT_NameAndType_info(name, type)); + this.key_vector.addElement(fieldref_key); + this.constant_pool.addElement(fieldref); + } + return (this.key_vector.indexOf(fieldref_key)+1); + } + else { + codegenlog.debug("Fieldref hinzugefuegt: " + name + ", Klassenname: " + cl_name + + ", Typ: " + type); + Key fieldref_key = new Key(JVMCode.CONSTANT_Fieldref, cl_name + name + type); + if(!this.key_vector.contains(fieldref_key)) { + CONSTANT_Fieldref_info fieldref = new CONSTANT_Fieldref_info(); + fieldref.set_tag(JVMCode.CONSTANT_Fieldref); + fieldref.set_class_index((short)this.add_CONSTANT_Class_info(cl_name)); + fieldref.set_name_and_type_index((short)this.add_CONSTANT_NameAndType_info(name, type)); + this.key_vector.addElement(fieldref_key); + this.constant_pool.addElement(fieldref); + } + return (this.key_vector.indexOf(fieldref_key)+1); + } + } + // ino.end + + // ino.method.set_constant_pool.21606.definition + public void set_constant_pool(Vector t) + // ino.end + // ino.method.set_constant_pool.21606.body + { this.constant_pool = t; } + // ino.end + // ino.method.set_access_flags.21609.definition + public void set_access_flags(short t) + // ino.end + // ino.method.set_access_flags.21609.body + { this.access_flags = t; } + // ino.end + // ino.method.set_this_class.21612.definition + public void set_this_class(short t) + // ino.end + // ino.method.set_this_class.21612.body + { this.this_class = t; } + // ino.end + // ino.method.set_super_class.21615.definition + public void set_super_class(short t) + // ino.end + // ino.method.set_super_class.21615.body + { this.super_class = t; } + // ino.end + // ino.method.set_fields.21618.definition + public void set_fields(Vector t) + // ino.end + // ino.method.set_fields.21618.body + { this.fields = t; } + // ino.end + // ino.method.set_methods.21621.definition + public void set_methods(Vector t) + // ino.end + // ino.method.set_methods.21621.body + { this.methods = t; } + // ino.end + // ino.method.set_attributes.21624.definition + public void set_attributes(Vector t) + // ino.end + // ino.method.set_attributes.21624.body + { this.attributes = t; } + // ino.end + // ino.method.set_constructor_founded.21627.definition + public void set_constructor_founded(boolean t) + // ino.end + // ino.method.set_constructor_founded.21627.body + { this.constructor_founded = t; } + // ino.end + // ino.method.add_classblock_Element.21630.definition + public void add_classblock_Element(Assign a) + // ino.end + // ino.method.add_classblock_Element.21630.body + { class_block.addElement(a); } + // ino.end + + // ino.method.get_constant_pool.21633.definition + public Vector get_constant_pool() + // ino.end + // ino.method.get_constant_pool.21633.body + { return this.constant_pool; } + // ino.end + // ino.method.get_access_flags.21636.definition + public short get_access_flags() + // ino.end + // ino.method.get_access_flags.21636.body + { return this.access_flags; } + // ino.end + // ino.method.get_this_class.21639.definition + public short get_this_class() + // ino.end + // ino.method.get_this_class.21639.body + { return this.this_class; } + // ino.end + // ino.method.get_super_class.21642.definition + public short get_super_class() + // ino.end + // ino.method.get_super_class.21642.body + { return this.super_class; } + // ino.end + // ino.method.get_fields.21645.definition + public Vector get_fields() + // ino.end + // ino.method.get_fields.21645.body + { return this.fields; } + // ino.end + // ino.method.get_methods.21648.definition + public Vector get_methods() + // ino.end + // ino.method.get_methods.21648.body + { return this.methods; } + // ino.end + // ino.method.get_attributes.21651.definition + public Vector get_attributes() + // ino.end + // ino.method.get_attributes.21651.body + { return this.attributes; } + // ino.end + // ino.method.get_key_vector.21654.definition + public Vector get_key_vector() + // ino.end + // ino.method.get_key_vector.21654.body + { return this.key_vector; } + // ino.end + // ino.method.get_constructor_founded.21657.definition + public boolean get_constructor_founded() + // ino.end + // ino.method.get_constructor_founded.21657.body + { return this.constructor_founded; } + // ino.end + // ino.method.get_constant_pool_element.21660.definition + public short get_constant_pool_element(byte b, String id) + // ino.end + // ino.method.get_constant_pool_element.21660.body + { return (short)this.key_vector.indexOf(new Key(b, id)); } + // ino.end + // ino.method.get_class_block.21663.definition + public Vector get_class_block() + // ino.end + // ino.method.get_class_block.21663.body + { return this.class_block; } + // ino.end + + // ino.method.codegen.21666.definition + public void codegen() + throws JVMCodeException + // ino.end + // ino.method.codegen.21666.body + { + try + { + codegenlog.info("Generieren der Klasse: " + class_name); + + // Datei vorbereiten + File file = new File(MyCompiler.getAPI().getOutputDir() + + class_name + ".class"); + FileOutputStream f = new FileOutputStream(file); + + // Schreiben der Header-Infos + writeInt(f, magic); + writeShort(f, minor_version); + writeShort(f, major_version); + codegenlog.debug("Header: magic=" + Integer.toHexString(magic)); + codegenlog.debug("Header: minor_version=" + minor_version); + codegenlog.debug("Header: major_version=" + major_version); + codegenlog.info("Verarbeite Konstanten-Pool: " + (constant_pool.size()+1)); + + // Constant-Pool verarbeiten + writeShort(f, (short)(constant_pool.size() + 1)); + for(int i = 0; i < constant_pool.size(); i++) + { + codegenlog.debug((i+1) +". " + + constant_pool.elementAt(i).toString()); + constant_pool.elementAt(i).codegen(this, f); + } + + // Informationen ueber die Klasse selbst verarbeiten + writeShort(f, access_flags); + writeShort(f, this_class); + writeShort(f, super_class); + codegenlog.debug("Klasseninfos: access_flags=" + access_flags); + codegenlog.debug("Klasseninfos: this_class=" + this_class); + codegenlog.debug("Klasseninfos: super_class=" + super_class); + + // Interfaces verarbeiten + codegenlog.info("Verarbeite Interfaces: " + interfaces.size()); + writeShort(f, (short)interfaces.size()); + for (int i=0; i>> 24) & 255)); + f.write(((i >>> 16) & 255)); + f.write(((i >>> 8) & 255)); + f.write((i & 255)); + } + // ino.end + + // ino.method.writeShort.21672.definition + public void writeShort(FileOutputStream f, short i) + throws IOException + // ino.end + // ino.method.writeShort.21672.body + { + f.write((i >>> 8) & 255); + f.write(i & 255); + } + // ino.end + + // ino.method.writeByte.21675.definition + public void writeByte(FileOutputStream f, byte i) + throws IOException + // ino.end + // ino.method.writeByte.21675.body + { + f.write(i); + } + // ino.end + + // ino.method.writeByteArray.21678.definition + public void writeByteArray(FileOutputStream f, byte[] b) + throws IOException + // ino.end + // ino.method.writeByteArray.21678.body + { + for(int i = 0; i < Array.getLength(b); i++) f.write(b[i]); + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mybytecode/CodeAttribute.java b/src/mycompiler/mybytecode/CodeAttribute.java new file mode 100755 index 000000000..71d64a4e9 --- /dev/null +++ b/src/mycompiler/mybytecode/CodeAttribute.java @@ -0,0 +1,1071 @@ +// ino.module.CodeAttribute.8532.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.CodeAttribute.8532.import +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Array; +import java.util.Vector; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.Type; +// ino.end + +// ino.class.CodeAttribute.21681.declaration +public class CodeAttribute extends Attribute +// ino.end +// ino.class.CodeAttribute.21681.body +{ + // ino.attribute.code_vector.21685.declaration + private Vector code_vector = new Vector(); + // ino.end + // ino.attribute.exception_tables.21688.declaration + private Vector exception_tables = new Vector(); + // ino.end + // ino.attribute.attributes.21691.declaration + private Vector attributes = new Vector(); + // ino.end + // ino.attribute.local_name_vector.21694.declaration + private Vector local_name_vector = new Vector(); + // ino.end + // ino.attribute.local_type_vector.21697.declaration + private Vector local_type_vector = new Vector(); + // ino.end + + // ino.method.CodeAttribute.21700.definition + public CodeAttribute(String class_name, short acc_flags) + // ino.end + // ino.method.CodeAttribute.21700.body + { + if ((acc_flags & 8) == 0) + add_local(class_name, new Type("void",-1)); + } + // ino.end + + // ino.method.get_code_Vector.21703.definition + public Vector get_code_Vector() + // ino.end + // ino.method.get_code_Vector.21703.body + { + return this.code_vector; + } + // ino.end + + // ino.method.get_exception_table_Vector.21706.definition + public Vector get_exception_table_Vector() + // ino.end + // ino.method.get_exception_table_Vector.21706.body + { + return this.exception_tables; + } + // ino.end + + // ino.method.get_attributes_Vector.21709.definition + public Vector get_attributes_Vector() + // ino.end + // ino.method.get_attributes_Vector.21709.body + { + return this.attributes; + } + // ino.end + + // ino.method.get_local_Vector.21712.definition + public Vector get_local_Vector() + // ino.end + // ino.method.get_local_Vector.21712.body + { + return this.local_name_vector; + } + // ino.end + + // ino.method.get_code_length.21715.definition + public int get_code_length() + // ino.end + // ino.method.get_code_length.21715.body + { + return this.code_vector.size(); + } + // ino.end + + // ino.method.add_local.21718.definition + public void add_local(String s, Type t) + // ino.end + // ino.method.add_local.21718.body + { + local_name_vector.addElement(s); + local_type_vector.addElement(t); + String type = t.getName(); + if (type.equals("double") || type.equals("long")) { + local_name_vector.addElement(s); + local_type_vector.addElement(t); + } + } + // ino.end + + // ino.method.add_code.21721.definition + public void add_code(Byte b) + // ino.end + // ino.method.add_code.21721.body + { + code_vector.addElement(b); + } + // ino.end + + // ino.method.set_code.21724.definition + public void set_code(Byte b, int i) + // ino.end + // ino.method.set_code.21724.body + { + code_vector.setElementAt(b, i); + } + // ino.end + + // ino.method.add_code_int.21727.definition + public void add_code_int(int i) + // ino.end + // ino.method.add_code_int.21727.body + { + code_vector.addElement(new Byte((byte) ((i >> 24) & 255))); + code_vector.addElement(new Byte((byte) ((i >> 16) & 255))); + code_vector.addElement(new Byte((byte) ((i >> 8) & 255))); + code_vector.addElement(new Byte((byte) (i & 255))); + } + // ino.end + + // ino.method.add_code_short.21730.definition + public void add_code_short(int s) + // ino.end + // ino.method.add_code_short.21730.body + { + code_vector.addElement(new Byte((byte) ((s >> 8) & 255))); + code_vector.addElement(new Byte((byte) (s & 255))); + } + // ino.end + + // ino.method.set_code_short.21733.definition + public void set_code_short(int s, int i) + // ino.end + // ino.method.set_code_short.21733.body + { + code_vector.setElementAt(new Byte((byte) ((s >> 8) & 255)), i); + code_vector.setElementAt(new Byte((byte) (s & 255)), i + 1); + } + // ino.end + + // ino.method.add_code_byte.21736.definition + public void add_code_byte(int b) + // ino.end + // ino.method.add_code_byte.21736.body + { + code_vector.addElement(new Byte((byte) (b & 255))); + } + // ino.end + + // ino.method.add_code_byte_array.21739.definition + public void add_code_byte_array(byte[] b) + // ino.end + // ino.method.add_code_byte_array.21739.body + { + for (int i = 0; i < Array.getLength(b); i++) + code_vector.addElement(new Byte(b[i])); + } + // ino.end + + // ino.method.get_indexOf_Var.21742.definition + public int get_indexOf_Var(String name) + // ino.end + // ino.method.get_indexOf_Var.21742.body + { + for (int i = 0; i < local_name_vector.size(); i++) + if (name.equals((String) local_name_vector.elementAt(i))) + return i; + return -1; + } + // ino.end + + // ino.method.get_TypeOf_Var.21745.definition + public Type get_TypeOf_Var(String name) + throws JVMCodeException + // ino.end + // ino.method.get_TypeOf_Var.21745.body + { + int index = get_indexOf_Var(name); + if (index != -1) + return (Type) local_type_vector.elementAt(index); + throw new JVMCodeException( + "JVMCodeException: Code_attribute: Type get_TypeOf_Var(String name)"); + } + // ino.end + + // ino.method.get_attributes_length.21748.definition + public int get_attributes_length() + // ino.end + // ino.method.get_attributes_length.21748.body + { + int ret = 12; + ret += code_vector.size(); + ret += (exception_tables.size() * 8); + for (int i = 0; i < attributes.size(); i++) + ret += attributes.elementAt(i) + .get_attributes_length(); + return ret; + } + // ino.end + + // ino.method.set_exception_table_Vector.21751.definition + public void set_exception_table_Vector(Vector t) + // ino.end + // ino.method.set_exception_table_Vector.21751.body + { + this.exception_tables = t; + } + // ino.end + + // ino.method.set_attributes_Vector.21754.definition + public void set_attributes_Vector(Vector t) + // ino.end + // ino.method.set_attributes_Vector.21754.body + { + this.attributes = t; + } + // ino.end + + // ino.method.codegen.21757.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws JVMCodeException, IOException + // ino.end + // ino.method.codegen.21757.body + { + int attributes_length = this.get_attributes_length(); + short max_stack = calculate_max_stack(); + classfile.writeShort(f, get_attribute_name_index()); + classfile.writeInt(f, attributes_length); + classfile.writeShort(f, max_stack); + classfile.writeShort(f, (short) local_name_vector.size()); + classfile.writeInt(f, code_vector.size()); + + codegenlog.debug("Code_attribute_name_index=" + get_attribute_name_index() + + ", Length=" + attributes_length + ", Max_Stack=" + max_stack + + ", Max_Locals=" + (short) local_name_vector.size() + + ", Code_Length=" + code_vector.size()); + + for (int i = 0; i < code_vector.size(); i++) { // code_vector + classfile.writeByte(f, (code_vector.elementAt(i)).byteValue()); + } + + // Verarbeitung der Exception-Table + JVMCode.get_Command(code_vector); + codegenlog.debug("Groesse der Exception-Table: " + exception_tables.size()); + classfile.writeShort(f, (short) exception_tables.size()); + for (int i = 0; i < exception_tables.size(); i++) { + exception_tables.elementAt(i).codegen(classfile,f); + } + + // Verarbeitung der Attribute + codegenlog.debug("Anzahl der Attribute: " + attributes.size()); + classfile.writeShort(f, (short) attributes.size()); + for (int i = 0; i < attributes.size(); i++) { // attributes + attributes.elementAt(i).codegen(classfile, f); + } + /* + * if(classfile.get_system_out()) { System.out.println(" locals:"); + * for(int i = 0; i < local_name_vector.size(); i++) // locals + * System.out.println(" " + i +" " + + * (String)local_name_vector.elementAt(i) + + * ((Type)local_type_vector.elementAt(i)).get_Type()); } + */ + } + // ino.end + + // ino.method.calculate_max_stack.21760.definition + private short calculate_max_stack() + throws JVMCodeException + // ino.end + // ino.method.calculate_max_stack.21760.body + { + short max_stack = 0; + short stack = 0; + for (int y = 0; y < code_vector.size(); y++) { + int x = JVMCode.bytes_to_int(code_vector.elementAt(y)); + switch (x) { + case 0: { + break; + } + case 1: { + stack++; + break; + } + case 2: { + stack++; + break; + } + case 3: { + stack++; + break; + } + case 4: { + stack++; + break; + } + case 5: { + stack++; + break; + } + case 6: { + stack++; + break; + } + case 7: { + stack++; + break; + } + case 8: { + stack++; + break; + } + case 9: { + stack++; + break; + } + case 10: { + stack++; + break; + } + case 11: { + stack++; + break; + } + case 12: { + stack++; + break; + } + case 13: { + stack++; + break; + } + case 14: { + stack++; + break; + } + case 15: { + stack++; + break; + } + case 16: { + stack++; + y++; + break; + } + case 17: { + stack++; + y += 2; + break; + } + case 18: { + stack++; + y++; + break; + } + case 19: { + stack++; + y += 2; + break; + } + case 20: { + stack++; + y += 2; + break; + } + case 21: { + stack++; + y++; + break; + } + case 22: { + stack++; + y++; + break; + } + case 23: { + stack++; + y++; + break; + } + case 24: { + stack++; + y++; + break; + } + case 25: { + stack++; + y++; + break; + } + case 26: { + stack++; + break; + } + case 27: { + stack++; + break; + } + case 28: { + stack++; + break; + } + case 29: { + stack++; + break; + } + case 30: { + stack++; + break; + } + case 31: { + stack++; + break; + } + case 32: { + stack++; + break; + } + case 33: { + stack++; + break; + } + case 34: { + stack++; + break; + } + case 35: { + stack++; + break; + } + case 36: { + stack++; + break; + } + case 37: { + stack++; + break; + } + case 38: { + stack++; + break; + } + case 39: { + stack++; + break; + } + case 40: { + stack++; + break; + } + case 41: { + stack++; + break; + } + case 42: { + stack++; + break; + } + case 43: { + stack++; + break; + } + case 44: { + stack++; + break; + } + case 45: { + stack++; + break; + } + /* + * case 46: { System.out.print("iaload"); break; } case 47: { + * System.out.print("laload"); break; } case 48: { + * System.out.print("faload"); break; } case 49: { + * System.out.print("daload"); break; } case 50: { + * System.out.print("aaload"); break; } case 51: { + * System.out.print("baload"); break; } case 52: { + * System.out.print("caload"); break; } case 53: { + * System.out.print("saload"); break; } + */ + case 54: { + stack--; + y++; + break; + } + case 55: { + stack--; + y++; + break; + } + case 56: { + stack--; + y++; + break; + } + case 57: { + stack--; + y++; + break; + } + case 58: { + stack--; + y++; + break; + } + case 59: { + stack--; + break; + } + case 60: { + stack--; + break; + } + case 61: { + stack--; + break; + } + case 62: { + stack--; + break; + } + case 63: { + stack--; + break; + } + case 64: { + stack--; + break; + } + case 65: { + stack--; + break; + } + case 66: { + stack--; + break; + } + case 67: { + stack--; + break; + } + case 68: { + stack--; + break; + } + case 69: { + stack--; + break; + } + case 70: { + stack--; + break; + } + case 71: { + stack--; + break; + } + case 72: { + stack--; + break; + } + case 73: { + stack--; + break; + } + case 74: { + stack--; + break; + } + case 75: { + stack--; + break; + } + case 76: { + stack--; + break; + } + case 77: { + stack--; + break; + } + case 78: { + stack--; + break; + } + /* + * case 79: { System.out.print("iastore"); break; } case 80: { + * System.out.print("lastore"); break; } case 81: { + * System.out.print("fastore"); break; } case 82: { + * System.out.print("dastore"); break; } case 83: { + * System.out.print("aastore"); break; } case 84: { + * System.out.print("bastore"); break; } case 85: { + * System.out.print("castore"); break; } case 86: { + * System.out.print("sastore"); break; } + */ + case 87: { + stack--; + break; + } + case 88: { + stack -= 2; + break; + } + case 89: { + stack++; + break; + } + case 90: { + stack++; + break; + } + case 91: { + stack++; + break; + } + case 92: { + stack += 2; + break; + } + case 93: { + stack += 2; + break; + } + case 94: { + stack += 2; + break; + } + case 95: { + break; + } + case 96: { + stack--; + break; + } + case 97: { + stack--; + break; + } + case 98: { + stack--; + break; + } + case 99: { + stack--; + break; + } + case 100: { + stack--; + break; + } + case 101: { + stack--; + break; + } + case 102: { + stack--; + break; + } + case 103: { + stack--; + break; + } + case 104: { + stack--; + break; + } + case 105: { + stack--; + break; + } + case 106: { + stack--; + break; + } + case 107: { + stack--; + break; + } + case 108: { + stack--; + break; + } + case 109: { + stack--; + break; + } + case 110: { + stack--; + break; + } + case 111: { + stack--; + break; + } + case 112: { + stack--; + break; + } + case 113: { + stack--; + break; + } + case 114: { + stack--; + break; + } + case 115: { + stack--; + break; + } + case 116: { + break; + } + case 117: { + break; + } + case 118: { + break; + } + case 119: { + break; + } + case 120: { + stack--; + break; + } + case 121: { + stack--; + break; + } + case 122: { + stack--; + break; + } + case 123: { + stack--; + break; + } + case 124: { + stack--; + break; + } + case 125: { + stack--; + break; + } + case 126: { + stack--; + break; + } + case 127: { + stack--; + break; + } + case 128: { + stack--; + break; + } + case 129: { + stack--; + break; + } + case 130: { + stack--; + break; + } + case 131: { + stack--; + break; + } + case 132: { + y += 2; + break; + } + case 133: { + break; + } + case 134: { + break; + } + case 135: { + break; + } + case 136: { + break; + } + case 137: { + break; + } + case 138: { + break; + } + case 139: { + break; + } + case 140: { + break; + } + case 141: { + break; + } + case 142: { + break; + } + case 143: { + break; + } + case 144: { + break; + } + case 145: { + break; + } + case 146: { + break; + } + case 147: { + break; + } + case 148: { + stack--; + break; + } + case 149: { + stack--; + break; + } + case 150: { + stack--; + break; + } + case 151: { + stack--; + break; + } + case 152: { + stack--; + break; + } + case 153: { + stack--; + y += 2; + break; + } + case 154: { + stack--; + y += 2; + break; + } + case 155: { + stack--; + y += 2; + break; + } + case 156: { + stack--; + y += 2; + break; + } + case 157: { + stack--; + y += 2; + break; + } + case 158: { + stack--; + y += 2; + break; + } + case 159: { + stack -= 2; + y += 2; + break; + } + case 160: { + stack -= 2; + y += 2; + break; + } + case 161: { + stack -= 2; + y += 2; + break; + } + case 162: { + stack -= 2; + y += 2; + break; + } + case 163: { + stack -= 2; + y += 2; + break; + } + case 164: { + stack -= 2; + y += 2; + break; + } + case 165: { + stack -= 2; + y += 2; + break; + } + case 166: { + stack -= 2; + y += 2; + break; + } + case 167: { + y += 2; + break; + } + case 168: { + stack++; + y += 2; + break; + } + case 169: { + y++; + break; + } + // case 170: { System.out.print("tableswitch"); break; } + // case 171: { System.out.print("lookupswitch"); break; } + case 172: { + stack = 0; + break; + } + case 173: { + stack = 0; + break; + } + case 174: { + stack = 0; + break; + } + case 175: { + stack = 0; + break; + } + case 176: { + stack = 0; + break; + } + case 177: { + stack = 0; + break; + } + case 178: { + stack++; + y += 2; + break; + } + case 179: { + stack++; + y += 2; + break; + } + case 180: { + y += 2; + break; + } + case 181: { + stack += 2; + y += 2; + break; + } + case 182: { + y += 2; + stack = 0; + break; + } // invokevirtual + case 183: { + y += 2; + stack = 0; + break; + } // invokespecial + case 184: { + y += 2; + stack = 0; + break; + } // invokestatic + // case 185: { System.out.print("invokeinterface"); y+=4; break; } + case 187: { + stack++; + y += 2; + break; + } + case 188: { + y++; + break; + } + case 189: { + y += 2; + break; + } + case 190: { + break; + } + case 191: { + break; + } + case 192: { + y += 2; + break; + } + case 193: { + y += 2; + break; + } + case 194: { + stack--; + break; + } + case 195: { + stack--; + break; + } + // case 196: { System.out.print("wide"); break; } + case 197: { + y += 3; + break; + } + case 198: { + stack--; + y += 2; + break; + } + case 199: { + stack--; + y += 2; + break; + } + case 200: { + y += 4; + break; + } + case 201: { + stack++; + y += 4; + break; + } + // case 202: { System.out.print("breakpoint"); break; } + // case 254: { System.out.print("impdep1"); break; } + default: { + throw new JVMCodeException( + "JVMCodeException: Code_attribute: short calculate_max_stack()"); + } + } + if (stack > max_stack) + max_stack = stack; + } + return max_stack; + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mybytecode/ExceptionTable.java b/src/mycompiler/mybytecode/ExceptionTable.java new file mode 100755 index 000000000..a2545007e --- /dev/null +++ b/src/mycompiler/mybytecode/ExceptionTable.java @@ -0,0 +1,55 @@ +// ino.module.ExceptionTable.8545.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.ExceptionTable.8545.import +import java.io.FileOutputStream; +import java.io.IOException; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.ExceptionTable.22047.declaration +public class ExceptionTable +// ino.end +// ino.class.ExceptionTable.22047.body +{ + // ino.attribute.codegenlog.22050.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.22050.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + // ino.attribute.start_pc.22053.declaration + private short start_pc; + // ino.end + + // ino.attribute.end_pc.22056.declaration + private short end_pc; + // ino.end + + // ino.attribute.handler_pc.22059.declaration + private short handler_pc; + // ino.end + + // ino.attribute.catch_type.22062.declaration + private short catch_type; + // ino.end + + // ino.method.codegen.22065.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException + // ino.end + // ino.method.codegen.22065.body + { + classfile.writeShort(f, start_pc); + classfile.writeShort(f, end_pc); + classfile.writeShort(f, handler_pc); + classfile.writeShort(f, catch_type); + codegenlog.debug("Exception-Table: start_pc=" + start_pc + + ", end_pc=" + end_pc + ", handler_pc=" + handler_pc + + ", catch_type=" + catch_type); + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mybytecode/FieldInfo.java b/src/mycompiler/mybytecode/FieldInfo.java new file mode 100755 index 000000000..250e8609b --- /dev/null +++ b/src/mycompiler/mybytecode/FieldInfo.java @@ -0,0 +1,199 @@ +// ino.module.FieldInfo.8546.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.FieldInfo.8546.import +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Vector; +import mycompiler.myexception.JVMCodeException; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.FieldInfo.22068.declaration +public class FieldInfo +// ino.end +// ino.class.FieldInfo.22068.body +{ + // ino.attribute.codegenlog.22071.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.22071.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + + // ino.attribute.name.22074.declaration + private String name; + // ino.end + + // ino.attribute.type.22077.declaration + private String type; + // ino.end + + // ino.attribute.class_name.22080.declaration + private String class_name; + // ino.end + + // ino.attribute.access_flags.22083.declaration + private short access_flags; + // ino.end + + // ino.attribute.name_index.22086.declaration + private short name_index; + // ino.end + + // ino.attribute.descriptor_index.22089.declaration + private short descriptor_index; + // ino.end + + // ino.attribute.attributes.22092.declaration + private Vector attributes = new Vector(); // attribute + // ino.end + + // ino.method.get_Name.22095.definition + public String get_Name() + // ino.end + // ino.method.get_Name.22095.body + { + return this.name; + } + // ino.end + + // ino.method.get_Type.22098.definition + public String get_Type() + // ino.end + // ino.method.get_Type.22098.body + { + return this.type; + } + // ino.end + + // ino.method.get_Class_Name.22101.definition + public String get_Class_Name() + // ino.end + // ino.method.get_Class_Name.22101.body + { + return this.class_name; + } + // ino.end + + // ino.method.get_access_flags.22104.definition + public short get_access_flags() + // ino.end + // ino.method.get_access_flags.22104.body + { + return this.access_flags; + } + // ino.end + + // ino.method.get_name_index.22107.definition + public short get_name_index() + // ino.end + // ino.method.get_name_index.22107.body + { + return this.name_index; + } + // ino.end + + // ino.method.get_descriptor_index.22110.definition + public short get_descriptor_index() + // ino.end + // ino.method.get_descriptor_index.22110.body + { + return this.descriptor_index; + } + // ino.end + + // ino.method.get_attributes.22113.definition + public Vector get_attributes() + // ino.end + // ino.method.get_attributes.22113.body + { + return this.attributes; + } + // ino.end + + // ino.method.set_Name.22116.definition + public void set_Name(String t) + // ino.end + // ino.method.set_Name.22116.body + { + this.name = t; + } + // ino.end + + // ino.method.set_Type.22119.definition + public void set_Type(String t) + // ino.end + // ino.method.set_Type.22119.body + { + this.type = t; + } + // ino.end + + // ino.method.set_Class_Name.22122.definition + public void set_Class_Name(String t) + // ino.end + // ino.method.set_Class_Name.22122.body + { + this.class_name = t; + } + // ino.end + + // ino.method.set_access_flags.22125.definition + public void set_access_flags(short t) + // ino.end + // ino.method.set_access_flags.22125.body + { + this.access_flags = t; + } + // ino.end + + // ino.method.set_name_index.22128.definition + public void set_name_index(short t) + // ino.end + // ino.method.set_name_index.22128.body + { + this.name_index = t; + } + // ino.end + + // ino.method.set_descriptor_index.22131.definition + public void set_descriptor_index(short t) + // ino.end + // ino.method.set_descriptor_index.22131.body + { + this.descriptor_index = t; + } + // ino.end + + // ino.method.set_attributes.22134.definition + public void set_attributes(Vector t) + // ino.end + // ino.method.set_attributes.22134.body + { + this.attributes = t; + } + // ino.end + + // ino.method.codegen.22137.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws IOException, JVMCodeException + // ino.end + // ino.method.codegen.22137.body + { + classfile.writeShort(f, access_flags); + classfile.writeShort(f, name_index); + classfile.writeShort(f, descriptor_index); + codegenlog.debug("FieldInfo: acc_flag=" + access_flags + + ", name_index=" + name_index + ", descriptor_index=" + + descriptor_index + ", attributes_count=" + attributes.size()); + + classfile.writeShort(f, (short) attributes.size()); // attributes_count=0 + for (int i = 0; i < attributes.size(); i++) { // attributes + attributes.elementAt(i).codegen(classfile, f); + } + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/JVMCode.java b/src/mycompiler/mybytecode/JVMCode.java new file mode 100755 index 000000000..aaa0392b6 --- /dev/null +++ b/src/mycompiler/mybytecode/JVMCode.java @@ -0,0 +1,1389 @@ +// ino.module.JVMCode.8547.package +package mycompiler.mybytecode; +// ino.end +// ino.module.JVMCode.8547.import +import java.util.Vector; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.GenericTypeVar; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.JVMCode.22140.description type=javadoc +/** + * Enthaelt die Befehle fuer die Umsetzung in JVM-Code und + * Konstantendefinitionen. + */ +// ino.end +// ino.class.JVMCode.22140.declaration +public class JVMCode +// ino.end +// ino.class.JVMCode.22140.body +{ + // ino.attribute.codegenlog.22143.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.22143.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + // ino.attribute.bytecodelog.22146.decldescription type=line + // Logger fuer JVM Befehle + // ino.end + // ino.attribute.bytecodelog.22146.declaration + protected static Logger bytecodelog = Logger.getLogger("bytecode"); + // ino.end + + // ino.attribute.CONSTANT_Utf8.22149.decldescription type=line + // Konstanten fuer Items im Konstantenpool + // ino.end + // ino.attribute.CONSTANT_Utf8.22149.declaration + public static byte CONSTANT_Utf8 = 1; + // ino.end + // ino.attribute.CONSTANT_Integer.22152.declaration + public static byte CONSTANT_Integer = 3; + // ino.end + // ino.attribute.CONSTANT_Float.22155.declaration + public static byte CONSTANT_Float = 4; + // ino.end + // ino.attribute.CONSTANT_Long.22158.declaration + public static byte CONSTANT_Long = 5; + // ino.end + // ino.attribute.CONSTANT_Double.22161.declaration + public static byte CONSTANT_Double = 6; + // ino.end + // ino.attribute.CONSTANT_Class.22164.declaration + public static byte CONSTANT_Class = 7; + // ino.end + // ino.attribute.CONSTANT_String.22167.declaration + public static byte CONSTANT_String = 8; + // ino.end + // ino.attribute.CONSTANT_Fieldref.22170.declaration + public static byte CONSTANT_Fieldref = 9; + // ino.end + // ino.attribute.CONSTANT_Methodref.22173.declaration + public static byte CONSTANT_Methodref = 10; + // ino.end + // ino.attribute.CONSTANT_InterfaceMethodref.22176.declaration + public static byte CONSTANT_InterfaceMethodref = 11; + // ino.end + // ino.attribute.CONSTANT_NameAndType.22179.declaration + public static byte CONSTANT_NameAndType = 12; + // ino.end + + // ino.attribute.nop.22182.decldescription type=line + // Opcodes + // ino.end + // ino.attribute.nop.22182.declaration + public static Byte nop = new Byte((byte)0); + // ino.end + // ino.attribute.aconst_null.22185.declaration + public static Byte aconst_null = new Byte((byte)1); + // ino.end + // ino.attribute.iconst_m1.22188.declaration + public static Byte iconst_m1 = new Byte((byte)2); + // ino.end + // ino.attribute.iconst_0.22191.declaration + public static Byte iconst_0 = new Byte((byte)3); + // ino.end + // ino.attribute.iconst_1.22194.declaration + public static Byte iconst_1 = new Byte((byte)4); + // ino.end + // ino.attribute.iconst_2.22197.declaration + public static Byte iconst_2 = new Byte((byte)5); + // ino.end + // ino.attribute.iconst_3.22200.declaration + public static Byte iconst_3 = new Byte((byte)6); + // ino.end + // ino.attribute.iconst_4.22203.declaration + public static Byte iconst_4 = new Byte((byte)7); + // ino.end + // ino.attribute.iconst_5.22206.declaration + public static Byte iconst_5 = new Byte((byte)8); + // ino.end + // ino.attribute.lconst_0.22209.declaration + public static Byte lconst_0 = new Byte((byte)9); + // ino.end + // ino.attribute.lconst_1.22212.declaration + public static Byte lconst_1 = new Byte((byte)10); + // ino.end + // ino.attribute.fconst_0.22215.declaration + public static Byte fconst_0 = new Byte((byte)11); + // ino.end + // ino.attribute.fconst_1.22218.declaration + public static Byte fconst_1 = new Byte((byte)12); + // ino.end + // ino.attribute.fconst_2.22221.declaration + public static Byte fconst_2 = new Byte((byte)13); + // ino.end + // ino.attribute.dconst_0.22224.declaration + public static Byte dconst_0 = new Byte((byte)14); + // ino.end + // ino.attribute.dconst_1.22227.declaration + public static Byte dconst_1 = new Byte((byte)15); + // ino.end + // ino.attribute.bipush.22230.declaration + public static Byte bipush = new Byte((byte)16); + // ino.end + // ino.attribute.sipush.22233.declaration + public static Byte sipush = new Byte((byte)17); + // ino.end + // ino.attribute.ldc.22236.declaration + public static Byte ldc = new Byte((byte)18); + // ino.end + // ino.attribute.ldc_w.22239.declaration + public static Byte ldc_w = new Byte((byte)19); + // ino.end + // ino.attribute.ldc2_w.22242.declaration + public static Byte ldc2_w = new Byte((byte)20); + // ino.end + // ino.attribute.iload.22245.declaration + public static Byte iload = new Byte((byte)21); + // ino.end + // ino.attribute.lload.22248.declaration + public static Byte lload = new Byte((byte)22); + // ino.end + // ino.attribute.fload.22251.declaration + public static Byte fload = new Byte((byte)23); + // ino.end + // ino.attribute.dload.22254.declaration + public static Byte dload = new Byte((byte)24); + // ino.end + // ino.attribute.aload.22257.declaration + public static Byte aload = new Byte((byte)25); + // ino.end + // ino.attribute.iload_0.22260.declaration + public static Byte iload_0 = new Byte((byte)26); + // ino.end + // ino.attribute.iload_1.22263.declaration + public static Byte iload_1 = new Byte((byte)27); + // ino.end + // ino.attribute.iload_2.22266.declaration + public static Byte iload_2 = new Byte((byte)28); + // ino.end + // ino.attribute.iload_3.22269.declaration + public static Byte iload_3 = new Byte((byte)29); + // ino.end + // ino.attribute.lload_0.22272.declaration + public static Byte lload_0 = new Byte((byte)30); + // ino.end + // ino.attribute.lload_1.22275.declaration + public static Byte lload_1 = new Byte((byte)31); + // ino.end + // ino.attribute.lload_2.22278.declaration + public static Byte lload_2 = new Byte((byte)32); + // ino.end + // ino.attribute.lload_3.22281.declaration + public static Byte lload_3 = new Byte((byte)33); + // ino.end + // ino.attribute.fload_0.22284.declaration + public static Byte fload_0 = new Byte((byte)34); + // ino.end + // ino.attribute.fload_1.22287.declaration + public static Byte fload_1 = new Byte((byte)35); + // ino.end + // ino.attribute.fload_2.22290.declaration + public static Byte fload_2 = new Byte((byte)36); + // ino.end + // ino.attribute.fload_3.22293.declaration + public static Byte fload_3 = new Byte((byte)37); + // ino.end + // ino.attribute.dload_0.22296.declaration + public static Byte dload_0 = new Byte((byte)38); + // ino.end + // ino.attribute.dload_1.22299.declaration + public static Byte dload_1 = new Byte((byte)39); + // ino.end + // ino.attribute.dload_2.22302.declaration + public static Byte dload_2 = new Byte((byte)40); + // ino.end + // ino.attribute.dload_3.22305.declaration + public static Byte dload_3 = new Byte((byte)41); + // ino.end + // ino.attribute.aload_0.22308.declaration + public static Byte aload_0 = new Byte((byte)42); + // ino.end + // ino.attribute.aload_1.22311.declaration + public static Byte aload_1 = new Byte((byte)43); + // ino.end + // ino.attribute.aload_2.22314.declaration + public static Byte aload_2 = new Byte((byte)44); + // ino.end + // ino.attribute.aload_3.22317.declaration + public static Byte aload_3 = new Byte((byte)45); + // ino.end + // ino.attribute.iaload.22320.declaration + public static Byte iaload = new Byte((byte)46); + // ino.end + // ino.attribute.laload.22323.declaration + public static Byte laload = new Byte((byte)47); + // ino.end + // ino.attribute.faload.22326.declaration + public static Byte faload = new Byte((byte)48); + // ino.end + // ino.attribute.daload.22329.declaration + public static Byte daload = new Byte((byte)49); + // ino.end + // ino.attribute.aaload.22332.declaration + public static Byte aaload = new Byte((byte)50); + // ino.end + // ino.attribute.baload.22335.declaration + public static Byte baload = new Byte((byte)51); + // ino.end + // ino.attribute.caload.22338.declaration + public static Byte caload = new Byte((byte)52); + // ino.end + // ino.attribute.saload.22341.declaration + public static Byte saload = new Byte((byte)53); + // ino.end + // ino.attribute.istore.22344.declaration + public static Byte istore = new Byte((byte)54); + // ino.end + // ino.attribute.lstore.22347.declaration + public static Byte lstore = new Byte((byte)55); + // ino.end + // ino.attribute.fstore.22350.declaration + public static Byte fstore = new Byte((byte)56); + // ino.end + // ino.attribute.dstore.22353.declaration + public static Byte dstore = new Byte((byte)57); + // ino.end + // ino.attribute.astore.22356.declaration + public static Byte astore = new Byte((byte)58); + // ino.end + // ino.attribute.istore_0.22359.declaration + public static Byte istore_0 = new Byte((byte)59); + // ino.end + // ino.attribute.istore_1.22362.declaration + public static Byte istore_1 = new Byte((byte)60); + // ino.end + // ino.attribute.istore_2.22365.declaration + public static Byte istore_2 = new Byte((byte)61); + // ino.end + // ino.attribute.istore_3.22368.declaration + public static Byte istore_3 = new Byte((byte)62); + // ino.end + // ino.attribute.lstore_0.22371.declaration + public static Byte lstore_0 = new Byte((byte)63); + // ino.end + // ino.attribute.lstore_1.22374.declaration + public static Byte lstore_1 = new Byte((byte)64); + // ino.end + // ino.attribute.lstore_2.22377.declaration + public static Byte lstore_2 = new Byte((byte)65); + // ino.end + // ino.attribute.lstore_3.22380.declaration + public static Byte lstore_3 = new Byte((byte)66); + // ino.end + // ino.attribute.fstore_0.22383.declaration + public static Byte fstore_0 = new Byte((byte)67); + // ino.end + // ino.attribute.fstore_1.22386.declaration + public static Byte fstore_1 = new Byte((byte)68); + // ino.end + // ino.attribute.fstore_2.22389.declaration + public static Byte fstore_2 = new Byte((byte)69); + // ino.end + // ino.attribute.fstore_3.22392.declaration + public static Byte fstore_3 = new Byte((byte)70); + // ino.end + // ino.attribute.dstore_0.22395.declaration + public static Byte dstore_0 = new Byte((byte)71); + // ino.end + // ino.attribute.dstore_1.22398.declaration + public static Byte dstore_1 = new Byte((byte)72); + // ino.end + // ino.attribute.dstore_2.22401.declaration + public static Byte dstore_2 = new Byte((byte)73); + // ino.end + // ino.attribute.dstore_3.22404.declaration + public static Byte dstore_3 = new Byte((byte)74); + // ino.end + // ino.attribute.astore_0.22407.declaration + public static Byte astore_0 = new Byte((byte)75); + // ino.end + // ino.attribute.astore_1.22410.declaration + public static Byte astore_1 = new Byte((byte)76); + // ino.end + // ino.attribute.astore_2.22413.declaration + public static Byte astore_2 = new Byte((byte)77); + // ino.end + // ino.attribute.astore_3.22416.declaration + public static Byte astore_3 = new Byte((byte)78); + // ino.end + // ino.attribute.iastore.22419.declaration + public static Byte iastore = new Byte((byte)79); + // ino.end + // ino.attribute.lastore.22422.declaration + public static Byte lastore = new Byte((byte)80); + // ino.end + // ino.attribute.fastore.22425.declaration + public static Byte fastore = new Byte((byte)81); + // ino.end + // ino.attribute.dastore.22428.declaration + public static Byte dastore = new Byte((byte)82); + // ino.end + // ino.attribute.aastore.22431.declaration + public static Byte aastore = new Byte((byte)83); + // ino.end + // ino.attribute.bastore.22434.declaration + public static Byte bastore = new Byte((byte)84); + // ino.end + // ino.attribute.castore.22437.declaration + public static Byte castore = new Byte((byte)85); + // ino.end + // ino.attribute.sastore.22440.declaration + public static Byte sastore = new Byte((byte)86); + // ino.end + // ino.attribute.pop.22443.declaration + public static Byte pop = new Byte((byte)87); + // ino.end + // ino.attribute.pop2.22446.declaration + public static Byte pop2 = new Byte((byte)88); + // ino.end + // ino.attribute.dup.22449.declaration + public static Byte dup = new Byte((byte)89); + // ino.end + // ino.attribute.dup_x1.22452.declaration + public static Byte dup_x1 = new Byte((byte)90); + // ino.end + // ino.attribute.dup_x2.22455.declaration + public static Byte dup_x2 = new Byte((byte)91); + // ino.end + // ino.attribute.dup2.22458.declaration + public static Byte dup2 = new Byte((byte)92); + // ino.end + // ino.attribute.dup2_x1.22461.declaration + public static Byte dup2_x1 = new Byte((byte)93); + // ino.end + // ino.attribute.dup2_x2.22464.declaration + public static Byte dup2_x2 = new Byte((byte)94); + // ino.end + // ino.attribute.swap.22467.declaration + public static Byte swap = new Byte((byte)95); + // ino.end + // ino.attribute.iadd.22470.declaration + public static Byte iadd = new Byte((byte)96); + // ino.end + // ino.attribute.ladd.22473.declaration + public static Byte ladd = new Byte((byte)97); + // ino.end + // ino.attribute.fadd.22476.declaration + public static Byte fadd = new Byte((byte)98); + // ino.end + // ino.attribute.dadd.22479.declaration + public static Byte dadd = new Byte((byte)99); + // ino.end + // ino.attribute.isub.22482.declaration + public static Byte isub = new Byte((byte)100); + // ino.end + // ino.attribute.lsub.22485.declaration + public static Byte lsub = new Byte((byte)101); + // ino.end + // ino.attribute.fsub.22488.declaration + public static Byte fsub = new Byte((byte)102); + // ino.end + // ino.attribute.dsub.22491.declaration + public static Byte dsub = new Byte((byte)103); + // ino.end + // ino.attribute.imul.22494.declaration + public static Byte imul = new Byte((byte)104); + // ino.end + // ino.attribute.lmul.22497.declaration + public static Byte lmul = new Byte((byte)105); + // ino.end + // ino.attribute.fmul.22500.declaration + public static Byte fmul = new Byte((byte)106); + // ino.end + // ino.attribute.dmul.22503.declaration + public static Byte dmul = new Byte((byte)107); + // ino.end + // ino.attribute.idiv.22506.declaration + public static Byte idiv = new Byte((byte)108); + // ino.end + // ino.attribute.ldiv.22509.declaration + public static Byte ldiv = new Byte((byte)109); + // ino.end + // ino.attribute.fdiv.22512.declaration + public static Byte fdiv = new Byte((byte)110); + // ino.end + // ino.attribute.ddiv.22515.declaration + public static Byte ddiv = new Byte((byte)111); + // ino.end + // ino.attribute.irem.22518.declaration + public static Byte irem = new Byte((byte)112); + // ino.end + // ino.attribute.lrem.22521.declaration + public static Byte lrem = new Byte((byte)113); + // ino.end + // ino.attribute.frem.22524.declaration + public static Byte frem = new Byte((byte)114); + // ino.end + // ino.attribute.drem.22527.declaration + public static Byte drem = new Byte((byte)115); + // ino.end + // ino.attribute.ineg.22530.declaration + public static Byte ineg = new Byte((byte)116); + // ino.end + // ino.attribute.lneg.22533.declaration + public static Byte lneg = new Byte((byte)117); + // ino.end + // ino.attribute.fneg.22536.declaration + public static Byte fneg = new Byte((byte)118); + // ino.end + // ino.attribute.dneg.22539.declaration + public static Byte dneg = new Byte((byte)119); + // ino.end + // ino.attribute.ishl.22542.declaration + public static Byte ishl = new Byte((byte)120); + // ino.end + // ino.attribute.lshl.22545.declaration + public static Byte lshl = new Byte((byte)121); + // ino.end + // ino.attribute.ishr.22548.declaration + public static Byte ishr = new Byte((byte)122); + // ino.end + // ino.attribute.lshr.22551.declaration + public static Byte lshr = new Byte((byte)123); + // ino.end + // ino.attribute.iushr.22554.declaration + public static Byte iushr = new Byte((byte)124); + // ino.end + // ino.attribute.lushr.22557.declaration + public static Byte lushr = new Byte((byte)125); + // ino.end + // ino.attribute.iand.22560.declaration + public static Byte iand = new Byte((byte)126); + // ino.end + // ino.attribute.land.22563.declaration + public static Byte land = new Byte((byte)127); + // ino.end + // ino.attribute.ior.22566.declaration + public static Byte ior = new Byte((byte)128); + // ino.end + // ino.attribute.lor.22569.declaration + public static Byte lor = new Byte((byte)129); + // ino.end + // ino.attribute.ixor.22572.declaration + public static Byte ixor = new Byte((byte)130); + // ino.end + // ino.attribute.lxor.22575.declaration + public static Byte lxor = new Byte((byte)131); + // ino.end + // ino.attribute.iinc.22578.declaration + public static Byte iinc = new Byte((byte)132); + // ino.end + // ino.attribute.i2l.22581.declaration + public static Byte i2l = new Byte((byte)133); + // ino.end + // ino.attribute.i2f.22584.declaration + public static Byte i2f = new Byte((byte)134); + // ino.end + // ino.attribute.i2d.22587.declaration + public static Byte i2d = new Byte((byte)135); + // ino.end + // ino.attribute.l2i.22590.declaration + public static Byte l2i = new Byte((byte)136); + // ino.end + // ino.attribute.l2f.22593.declaration + public static Byte l2f = new Byte((byte)137); + // ino.end + // ino.attribute.l2d.22596.declaration + public static Byte l2d = new Byte((byte)138); + // ino.end + // ino.attribute.f2i.22599.declaration + public static Byte f2i = new Byte((byte)139); + // ino.end + // ino.attribute.f2l.22602.declaration + public static Byte f2l = new Byte((byte)140); + // ino.end + // ino.attribute.f2d.22605.declaration + public static Byte f2d = new Byte((byte)141); + // ino.end + // ino.attribute.d2i.22608.declaration + public static Byte d2i = new Byte((byte)142); + // ino.end + // ino.attribute.d2l.22611.declaration + public static Byte d2l = new Byte((byte)143); + // ino.end + // ino.attribute.d2f.22614.declaration + public static Byte d2f = new Byte((byte)144); + // ino.end + // ino.attribute.i2b.22617.declaration + public static Byte i2b = new Byte((byte)145); + // ino.end + // ino.attribute.i2c.22620.declaration + public static Byte i2c = new Byte((byte)146); + // ino.end + // ino.attribute.i2s.22623.declaration + public static Byte i2s = new Byte((byte)147); + // ino.end + // ino.attribute.lcmp.22626.declaration + public static Byte lcmp = new Byte((byte)148); + // ino.end + // ino.attribute.fcmpl.22629.declaration + public static Byte fcmpl = new Byte((byte)149); + // ino.end + // ino.attribute.fcmpg.22632.declaration + public static Byte fcmpg = new Byte((byte)150); + // ino.end + // ino.attribute.dcmpl.22635.declaration + public static Byte dcmpl = new Byte((byte)151); + // ino.end + // ino.attribute.dcmpg.22638.declaration + public static Byte dcmpg = new Byte((byte)152); + // ino.end + // ino.attribute.ifeq.22641.declaration + public static Byte ifeq = new Byte((byte)153); + // ino.end + // ino.attribute.ifne.22644.declaration + public static Byte ifne = new Byte((byte)154); + // ino.end + // ino.attribute.iflt.22647.declaration + public static Byte iflt = new Byte((byte)155); + // ino.end + // ino.attribute.ifge.22650.declaration + public static Byte ifge = new Byte((byte)156); + // ino.end + // ino.attribute.ifgt.22653.declaration + public static Byte ifgt = new Byte((byte)157); + // ino.end + // ino.attribute.ifle.22656.declaration + public static Byte ifle = new Byte((byte)158); + // ino.end + // ino.attribute.if_icmpeq.22659.declaration + public static Byte if_icmpeq = new Byte((byte)159); + // ino.end + // ino.attribute.if_icmpne.22662.declaration + public static Byte if_icmpne = new Byte((byte)160); + // ino.end + // ino.attribute.if_icmplt.22665.declaration + public static Byte if_icmplt = new Byte((byte)161); + // ino.end + // ino.attribute.if_icmpge.22668.declaration + public static Byte if_icmpge = new Byte((byte)162); + // ino.end + // ino.attribute.if_icmpgt.22671.declaration + public static Byte if_icmpgt = new Byte((byte)163); + // ino.end + // ino.attribute.if_icmple.22674.declaration + public static Byte if_icmple = new Byte((byte)164); + // ino.end + // ino.attribute.if_acmpeq.22677.declaration + public static Byte if_acmpeq = new Byte((byte)165); + // ino.end + // ino.attribute.if_acmpne.22680.declaration + public static Byte if_acmpne = new Byte((byte)166); + // ino.end + // ino.attribute.goto_.22683.declaration + public static Byte goto_ = new Byte((byte)167); + // ino.end + // ino.attribute.jsr.22686.declaration + public static Byte jsr = new Byte((byte)168); + // ino.end + // ino.attribute.ret.22689.declaration + public static Byte ret = new Byte((byte)169); + // ino.end + // ino.attribute.tableswitch.22692.declaration + public static Byte tableswitch = new Byte((byte)170); + // ino.end + // ino.attribute.lookupswitch.22695.declaration + public static Byte lookupswitch = new Byte((byte)171); + // ino.end + // ino.attribute.ireturn.22698.declaration + public static Byte ireturn = new Byte((byte)172); + // ino.end + // ino.attribute.lreturn.22701.declaration + public static Byte lreturn = new Byte((byte)173); + // ino.end + // ino.attribute.freturn.22704.declaration + public static Byte freturn = new Byte((byte)174); + // ino.end + // ino.attribute.dreturn.22707.declaration + public static Byte dreturn = new Byte((byte)175); + // ino.end + // ino.attribute.areturn.22710.declaration + public static Byte areturn = new Byte((byte)176); + // ino.end + // ino.attribute.return_.22713.declaration + public static Byte return_ = new Byte((byte)177); + // ino.end + // ino.attribute.getstatic.22716.declaration + public static Byte getstatic = new Byte((byte)178); + // ino.end + // ino.attribute.putstatic.22719.declaration + public static Byte putstatic = new Byte((byte)179); + // ino.end + // ino.attribute.getfield.22722.declaration + public static Byte getfield = new Byte((byte)180); + // ino.end + // ino.attribute.putfield.22725.declaration + public static Byte putfield = new Byte((byte)181); + // ino.end + // ino.attribute.invokevirtual.22728.declaration + public static Byte invokevirtual = new Byte((byte)182); + // ino.end + // ino.attribute.invokespecial.22731.declaration + public static Byte invokespecial = new Byte((byte)183); + // ino.end + // ino.attribute.invokestatic.22734.declaration + public static Byte invokestatic = new Byte((byte)184); + // ino.end + // ino.attribute.invokeinterface.22737.declaration + public static Byte invokeinterface = new Byte((byte)185); + // ino.end + // ino.attribute.new_.22740.declaration + public static Byte new_ = new Byte((byte)187); + // ino.end + // ino.attribute.newarray.22743.declaration + public static Byte newarray = new Byte((byte)188); + // ino.end + // ino.attribute.anewarray.22746.declaration + public static Byte anewarray = new Byte((byte)189); + // ino.end + // ino.attribute.arraylength.22749.declaration + public static Byte arraylength = new Byte((byte)190); + // ino.end + // ino.attribute.athrow.22752.declaration + public static Byte athrow = new Byte((byte)191); + // ino.end + // ino.attribute.checkcast.22755.declaration + public static Byte checkcast = new Byte((byte)192); + // ino.end + // ino.attribute.instanceof_.22758.declaration + public static Byte instanceof_ = new Byte((byte)193); + // ino.end + // ino.attribute.monitorenter.22761.declaration + public static Byte monitorenter = new Byte((byte)194); + // ino.end + // ino.attribute.monitorexit.22764.declaration + public static Byte monitorexit = new Byte((byte)195); + // ino.end + // ino.attribute.wide.22767.declaration + public static Byte wide = new Byte((byte)196); + // ino.end + // ino.attribute.multianewarray.22770.declaration + public static Byte multianewarray = new Byte((byte)197); + // ino.end + // ino.attribute.ifnull.22773.declaration + public static Byte ifnull = new Byte((byte)198); + // ino.end + // ino.attribute.ifnonnull.22776.declaration + public static Byte ifnonnull = new Byte((byte)199); + // ino.end + // ino.attribute.goto_w.22779.declaration + public static Byte goto_w = new Byte((byte)200); + // ino.end + // ino.attribute.jsr_w.22782.declaration + public static Byte jsr_w = new Byte((byte)201); + // ino.end + // ino.attribute.breakpoint.22785.declaration + public static Byte breakpoint = new Byte((byte)202); + // ino.end + // ino.attribute.impdep1.22788.declaration + public static Byte impdep1 = new Byte((byte)254); + // ino.end + // ino.attribute.impdep2.22791.declaration + public static Byte impdep2 = new Byte((byte)255); + // ino.end + + + + // ino.method.nconst_n.22794.definition + public static Byte nconst_n(String s1, int n2) + throws JVMCodeException + // ino.end + // ino.method.nconst_n.22794.body + { + int n1 = get_nType(s1); + switch(n1) { + case 0: { + if (n2 >= 0 && n2 <= 5) return new Byte((byte)(3 + n2)); + else break; + } + case 1: { + if (n2 >= 0 && n2 <= 2) return new Byte((byte)(9 + n2)); + else break; + } + case 2: { + if (n2 >= 0 && n2 <= 3) return new Byte((byte)(11 + n2)); + else break; + } + case 3: { + if (n2 >= 0 && n2 <= 2) return new Byte((byte)(14 + n2)); + else break; + } + } + throw new JVMCodeException("JVMCodeException: jvmCode: Byte nconst_n(String s1, int n2)"); + } + // ino.end + + // ino.method.nload.22797.definition + public static Byte nload(String s) + // ino.end + // ino.method.nload.22797.body + { + int n = get_nType(s); + if (n >= 0 && n <= 4) return new Byte((byte)(21 + n)); + else return new Byte((byte)21); + } + // ino.end + + // ino.method.nload_n.22800.definition + public static Byte nload_n(String s1, int n2) + throws JVMCodeException + // ino.end + // ino.method.nload_n.22800.body + { + int n1 = get_nType(s1); + if(n2 >= 0 && n2 <= 3) { + if (n1 >= 0 && n1 <= 4) return new Byte((byte)(26 + (n1*4) + n2)); + else return new Byte((byte)(26 + n2)); + } + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nload_n(String s1, int n2)"); + } + // ino.end + + // ino.method.naload.22803.definition + public static Byte naload(String s) + throws JVMCodeException + // ino.end + // ino.method.naload.22803.body + { + int n = get_nType(s); + if (n >= 0 && n <= 7) return new Byte((byte)(46 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte naload(String s)"); + } + // ino.end + + // ino.method.nstore.22806.definition + public static Byte nstore(String s) + // ino.end + // ino.method.nstore.22806.body + { + int n = get_nType(s); + if (n >= 0 && n <= 4) return new Byte((byte)(54 + n)); + else return new Byte((byte)54); + } + // ino.end + + // ino.method.nstore_n.22809.definition + public static Byte nstore_n(String s1, int n2) + throws JVMCodeException + // ino.end + // ino.method.nstore_n.22809.body + { + int n1 = get_nType(s1); + if(n2 >= 0 && n2 <= 3) { + if (n1 >= 0 && n1 <= 4) return new Byte((byte)(59 + (n1*4) + n2)); + else return new Byte((byte)(59 + n2)); + } + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nstore_n(String s1, int n2)"); + } + // ino.end + + // ino.method.nastore.22812.definition + public static Byte nastore(String s) + throws JVMCodeException + // ino.end + // ino.method.nastore.22812.body + { + int n = get_nType(s); + if (n >= 0 && n <= 7) return new Byte((byte)(79 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nastore(String s)"); + } + // ino.end + + // ino.method.nadd.22815.definition + public static Byte nadd(String s) + throws JVMCodeException + // ino.end + // ino.method.nadd.22815.body + { + int n = get_nType(s); + if (n >= 0 && n <= 3) return new Byte((byte)(96 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nadd(String s)"); + } + // ino.end + + // ino.method.nsub.22818.definition + public static Byte nsub(String s) + throws JVMCodeException + // ino.end + // ino.method.nsub.22818.body + { + int n = get_nType(s); + if (n >= 0 && n <= 3) return new Byte((byte)(100 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nsub(String s)"); + } + // ino.end + + // ino.method.nmul.22821.definition + public static Byte nmul(String s) + throws JVMCodeException + // ino.end + // ino.method.nmul.22821.body + { + int n = get_nType(s); + if (n >= 0 && n <= 3) return new Byte((byte)(104 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nmul(String s)"); + } + // ino.end + + // ino.method.ndiv.22824.definition + public static Byte ndiv(String s) + throws JVMCodeException + // ino.end + // ino.method.ndiv.22824.body + { + int n = get_nType(s); + if (n >= 0 && n <= 3) return new Byte((byte)(108 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte ndiv(String s)"); + } + // ino.end + + // ino.method.nrem.22827.definition + public static Byte nrem(String s) + throws JVMCodeException + // ino.end + // ino.method.nrem.22827.body + { + int n = get_nType(s); + if (n >= 0 && n <= 3) return new Byte((byte)(112 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nrem(String s)"); + } + // ino.end + + // ino.method.nneg.22830.definition + public static Byte nneg(String s) + throws JVMCodeException + // ino.end + // ino.method.nneg.22830.body + { + int n = get_nType(s); + if (n >= 0 && n <= 3) return new Byte((byte)(116 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nneg(String s)"); + } + // ino.end + + // ino.method.nshl.22833.definition + public static Byte nshl(String s) + throws JVMCodeException + // ino.end + // ino.method.nshl.22833.body + { + int n = get_nType(s); + if (n == 0 || n == 1) return new Byte((byte)(120 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nshl(String s)"); + } + // ino.end + + // ino.method.nshr.22836.definition + public static Byte nshr(String s) + throws JVMCodeException + // ino.end + // ino.method.nshr.22836.body + { + int n = get_nType(s); + if (n == 0 || n == 1) return new Byte((byte)(122 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nshr(String s)"); + } + // ino.end + + // ino.method.nushr.22839.definition + public static Byte nushr(String s) + throws JVMCodeException + // ino.end + // ino.method.nushr.22839.body + { + int n = get_nType(s); + if (n == 0 || n == 1) return new Byte((byte)(124 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nushr(String s)"); + } + // ino.end + + // ino.method.nand.22842.definition + public static Byte nand(String s) + throws JVMCodeException + // ino.end + // ino.method.nand.22842.body + { + int n = get_nType(s); + if (n == 0 || n == 1) return new Byte((byte)(126 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nand(String s)"); + } + // ino.end + + // ino.method.nor.22845.definition + public static Byte nor(String s) + throws JVMCodeException + // ino.end + // ino.method.nor.22845.body + { + int n = get_nType(s); + if (n == 0 || n == 1) return new Byte((byte)(128 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte nor(String s)"); + } + // ino.end + + // ino.method.nxor.22848.definition + public static Byte nxor(String s) + throws JVMCodeException + // ino.end + // ino.method.nxor.22848.body + { + int n = get_nType(s); + if (n == 0 || n == 1) return new Byte((byte)(130 + n)); + else throw new JVMCodeException("JVMCodeException: jvmCode: nxor(String s)"); + } + // ino.end + + // ino.method.n2n.22851.definition + public static Byte n2n(String s1, String s2) + throws JVMCodeException + // ino.end + // ino.method.n2n.22851.body + { + int n1 = get_nType(s1); + int n2 = get_nType(s2); + switch(n1) { + case 0: { + if (n2 >= 1 && n2 <= 3) return new Byte((byte)(132 + n2)); + if (n2 >= 5 && n2 <= 7) return new Byte((byte)(140 + n2)); + else break; + } + case 1: { + if (n2 == 0) return new Byte((byte)136); + else if (n2 == 2) return new Byte((byte)137); + else if (n2 == 3) return new Byte((byte)138); + else break; + } + case 2: { + if (n2 == 0) return new Byte((byte)139); + else if (n2 == 1) return new Byte((byte)140); + else if (n2 == 3) return new Byte((byte)141); + else break; + } + case 3: { + if (n2 >= 0 && n2 <= 2) return new Byte((byte)(142 + n2)); + else break; + } + } + throw new JVMCodeException("JVMCodeException: jvmCode: Byte n2n(String s1, String s2)"); + } + // ino.end + + // ino.method.ncmpl.22854.definition + public static Byte ncmpl(String s) + throws JVMCodeException + // ino.end + // ino.method.ncmpl.22854.body + { + int n = get_nType(s); + if (n == 2) return new Byte((byte)149); + else if (n == 3) return new Byte((byte)151); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte ncmpl(String s)"); + } + // ino.end + + // ino.method.ncmpg.22857.definition + public static Byte ncmpg(String s) + throws JVMCodeException + // ino.end + // ino.method.ncmpg.22857.body + { + int n = get_nType(s); + if (n == 2) return new Byte((byte)150); + else if (n == 3) return new Byte((byte)152); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte ncmpg(String s)"); + } + // ino.end + + // ino.method.if_ncmpeq.22860.definition + public static Byte if_ncmpeq(String s) + throws JVMCodeException + // ino.end + // ino.method.if_ncmpeq.22860.body + { + int n = get_nType(s); + if (n == 0) return new Byte((byte)159); + else if (n == 4) return new Byte((byte)165); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte if_ncmpeq(String s)"); + } + // ino.end + + // ino.method.if_ncmpne.22863.definition + public static Byte if_ncmpne(String s) + throws JVMCodeException + // ino.end + // ino.method.if_ncmpne.22863.body + { + int n = get_nType(s); + if (n == 0) return new Byte((byte)160); + else if (n == 4) return new Byte((byte)166); + else throw new JVMCodeException("JVMCodeException: jvmCode: Byte if_ncmpne(String s)"); + } + // ino.end + + // ino.method.nreturn.22866.definition + public static Byte nreturn(String s) + // ino.end + // ino.method.nreturn.22866.body + { + int n = get_nType(s); + if (n >= 0 && n <= 4) return new Byte((byte)(172 + n)); + else return new Byte((byte)(177)); + } + // ino.end + + // ino.method.get_nType.22869.definition + public static int get_nType(String type) + // ino.end + // ino.method.get_nType.22869.body + { + if(type.equals("void")) return 8; + else if(type.equals("int") || type.equals("boolean")) return 0; + else if(type.equals("long")) return 1; + else if(type.equals("float")) return 2; + else if(type.equals("double")) return 3; + else if(type.equals("byte")) return 5; + else if(type.equals("char")) return 6; + else if(type.equals("short")) return 7; + else return 4; + } + // ino.end + + + + // ino.method.get_codegen_Type.22872.defdescription type=javadoc + /** + * Liefert zu dem angegebenen Typ die entsprechende Repraesentation + * im Bytecode zurueck. Fuer integer bspw. I, fuer String Ljava/lang/String;. + * Wird im Vector paralist ein Objekt mit gleichen Namen gefunden, + * wird der Typ in Objekt geaendert (Typisierbare Klassen, hama). + */ + // ino.end + // ino.method.get_codegen_Type.22872.definition + public static String get_codegen_Type(String type, Vector paralist) + // ino.end + // ino.method.get_codegen_Type.22872.body + { + //hama: Hier wird geschaut, ob es im Vector paralist + //einen Eintrag mit gleichem Namen wie in dem type String gibt. + //Wenn dies der Fall ist, bedeute es, dass es sich um einen Typparameter + //handelt (bzw. handeln kann). Dann wird in type + //anstatt dem alten Namen - Object hineingeschieben. + //Dies ist fuer Codeerzeugung bei Typparametern erforderlich. + + if(paralist != null && !paralist.isEmpty()) + { + for(int i=0 ; i b) + throws JVMCodeException + // ino.end + // ino.method.get_Command.22875.body + { + StringBuffer sb = new StringBuffer(); + + sb.append(" {\n"); + for(int i=0; i < b.size(); i++) { + int x = bytes_to_int(b.elementAt(i)); + sb.append(" " + i + " "); + switch(x) { + case 0: { sb.append("nop"); break; } + case 1: { sb.append("aconst_null"); break; } + case 2: { sb.append("iconst_m1"); break; } + case 3: { sb.append("iconst_0"); break; } + case 4: { sb.append("iconst_1"); break; } + case 5: { sb.append("iconst_2"); break; } + case 6: { sb.append("iconst_3"); break; } + case 7: { sb.append("iconst_4"); break; } + case 8: { sb.append("iconst_5"); break; } + case 9: { sb.append("lconst_0"); break; } + case 10: { sb.append("lconst_1"); break; } + case 11: { sb.append("fconst_0"); break; } + case 12: { sb.append("fconst_1"); break; } + case 13: { sb.append("fconst_2"); break; } + case 14: { sb.append("dconst_0"); break; } + case 15: { sb.append("dconst_1"); break; } + case 16: { sb.append("bipush " + bytes_to_int(b.elementAt(++i))); break; } + case 17: { sb.append("sipush #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 18: { sb.append("ldc " + bytes_to_int(b.elementAt(++i))); break; } + case 19: { sb.append("ldc_w #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 20: { sb.append("ldc2_w #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 21: { sb.append("iload " + bytes_to_int(b.elementAt(++i))); break; } + case 22: { sb.append("lload " + bytes_to_int(b.elementAt(++i))); break; } + case 23: { sb.append("fload " + bytes_to_int(b.elementAt(++i))); break; } + case 24: { sb.append("dload " + bytes_to_int(b.elementAt(++i))); break; } + case 25: { sb.append("aload " + bytes_to_int(b.elementAt(++i))); break; } + case 26: { sb.append("iload_0"); break; } + case 27: { sb.append("iload_1"); break; } + case 28: { sb.append("iload_2"); break; } + case 29: { sb.append("iload_3"); break; } + case 30: { sb.append("lload_0"); break; } + case 31: { sb.append("lload_1"); break; } + case 32: { sb.append("lload_2"); break; } + case 33: { sb.append("lload_3"); break; } + case 34: { sb.append("fload_0"); break; } + case 35: { sb.append("fload_1"); break; } + case 36: { sb.append("fload_2"); break; } + case 37: { sb.append("fload_3"); break; } + case 38: { sb.append("dload_0"); break; } + case 39: { sb.append("dload_1"); break; } + case 40: { sb.append("dload_2"); break; } + case 41: { sb.append("dload_3"); break; } + case 42: { sb.append("aload_0"); break; } + case 43: { sb.append("aload_1"); break; } + case 44: { sb.append("aload_2"); break; } + case 45: { sb.append("aload_3"); break; } + case 46: { sb.append("iaload"); break; } + case 47: { sb.append("laload"); break; } + case 48: { sb.append("faload"); break; } + case 49: { sb.append("daload"); break; } + case 50: { sb.append("aaload"); break; } + case 51: { sb.append("baload"); break; } + case 52: { sb.append("caload"); break; } + case 53: { sb.append("saload"); break; } + case 54: { sb.append("istore " + bytes_to_int(b.elementAt(++i))); break; } + case 55: { sb.append("lstore " + bytes_to_int(b.elementAt(++i))); break; } + case 56: { sb.append("fstore " + bytes_to_int(b.elementAt(++i))); break; } + case 57: { sb.append("dstore " + bytes_to_int(b.elementAt(++i))); break; } + case 58: { sb.append("astore " + bytes_to_int(b.elementAt(++i))); break; } + case 59: { sb.append("istore_0"); break; } + case 60: { sb.append("istore_1"); break; } + case 61: { sb.append("istore_2"); break; } + case 62: { sb.append("istore_3"); break; } + case 63: { sb.append("lstore_0"); break; } + case 64: { sb.append("lstore_1"); break; } + case 65: { sb.append("lstore_2"); break; } + case 66: { sb.append("lstore_3"); break; } + case 67: { sb.append("fstore_0"); break; } + case 68: { sb.append("fstore_1"); break; } + case 69: { sb.append("fstore_2"); break; } + case 70: { sb.append("fstore_3"); break; } + case 71: { sb.append("dstore_0"); break; } + case 72: { sb.append("dstore_1"); break; } + case 73: { sb.append("dstore_2"); break; } + case 74: { sb.append("dstore_3"); break; } + case 75: { sb.append("astore_0"); break; } + case 76: { sb.append("astore_1"); break; } + case 77: { sb.append("astore_2"); break; } + case 78: { sb.append("astore_3"); break; } + case 79: { sb.append("iastore"); break; } + case 80: { sb.append("lastore"); break; } + case 81: { sb.append("fastore"); break; } + case 82: { sb.append("dastore"); break; } + case 83: { sb.append("aastore"); break; } + case 84: { sb.append("bastore"); break; } + case 85: { sb.append("castore"); break; } + case 86: { sb.append("sastore"); break; } + case 87: { sb.append("pop"); break; } + case 88: { sb.append("pop2"); break; } + case 89: { sb.append("dup"); break; } + case 90: { sb.append("dup_x1"); break; } + case 91: { sb.append("dup_x2"); break; } + case 92: { sb.append("dup2"); break; } + case 93: { sb.append("dup2_x1"); break; } + case 94: { sb.append("dup2_x2"); break; } + case 95: { sb.append("swap"); break; } + case 96: { sb.append("iadd"); break; } + case 97: { sb.append("ladd"); break; } + case 98: { sb.append("fadd"); break; } + case 99: { sb.append("dadd"); break; } + case 100: { sb.append("isub"); break; } + case 101: { sb.append("lsub"); break; } + case 102: { sb.append("fsub"); break; } + case 103: { sb.append("dsub"); break; } + case 104: { sb.append("imul"); break; } + case 105: { sb.append("lmul"); break; } + case 106: { sb.append("fmul"); break; } + case 107: { sb.append("dmul"); break; } + case 108: { sb.append("idiv"); break; } + case 109: { sb.append("ldiv"); break; } + case 110: { sb.append("fdiv"); break; } + case 111: { sb.append("ddiv"); break; } + case 112: { sb.append("irem"); break; } + case 113: { sb.append("lrem"); break; } + case 114: { sb.append("frem"); break; } + case 115: { sb.append("drem"); break; } + case 116: { sb.append("ineg"); break; } + case 117: { sb.append("lneg"); break; } + case 118: { sb.append("fneg"); break; } + case 119: { sb.append("dneg"); break; } + case 120: { sb.append("ishl"); break; } + case 121: { sb.append("lshl"); break; } + case 122: { sb.append("ishr"); break; } + case 123: { sb.append("lshr"); break; } + case 124: { sb.append("iushr"); break; } + case 125: { sb.append("lushr"); break; } + case 126: { sb.append("iand"); break; } + case 127: { sb.append("land"); break; } + case 128: { sb.append("ior"); break; } + case 129: { sb.append("lor"); break; } + case 130: { sb.append("ixor"); break; } + case 131: { sb.append("lxor"); break; } + case 132: { sb.append("iinc " + bytes_to_int(b.elementAt(++i)) + " " + bytes_to_int(b.elementAt(++i))); break; } + case 133: { sb.append("i2l"); break; } + case 134: { sb.append("i2f"); break; } + case 135: { sb.append("i2d"); break; } + case 136: { sb.append("l2i"); break; } + case 137: { sb.append("l2f"); break; } + case 138: { sb.append("l2d"); break; } + case 139: { sb.append("f2i"); break; } + case 140: { sb.append("f2l"); break; } + case 141: { sb.append("f2d"); break; } + case 142: { sb.append("d2i"); break; } + case 143: { sb.append("d2l"); break; } + case 144: { sb.append("d2f"); break; } + case 145: { sb.append("i2b"); break; } + case 146: { sb.append("i2c"); break; } + case 147: { sb.append("i2s"); break; } + case 148: { sb.append("lcmp"); break; } + case 149: { sb.append("fcmpl"); break; } + case 150: { sb.append("fcmpg"); break; } + case 151: { sb.append("dcmpl"); break; } + case 152: { sb.append("dcmpg"); break; } + case 153: { sb.append("ifeq #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 154: { sb.append("ifne #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 155: { sb.append("iflt #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 156: { sb.append("ifge #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 157: { sb.append("ifgt #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 158: { sb.append("ifle #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 159: { sb.append("if_icmpeq #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 160: { sb.append("if_icmpne #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 161: { sb.append("if_icmplt #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 162: { sb.append("if_icmpge #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 163: { sb.append("if_icmpgt #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 164: { sb.append("if_icmple #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 165: { sb.append("if_acmpeq #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 166: { sb.append("if_acmpne #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 167: { sb.append("goto #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 168: { sb.append("jsr #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 169: { sb.append("ret " + bytes_to_int(b.elementAt(++i))); break; } + // case 170: { sb.append("tableswitch"); break; } + // case 171: { sb.append("lookupswitch"); break; } + case 172: { sb.append("ireturn"); break; } + case 173: { sb.append("lreturn"); break; } + case 174: { sb.append("freturn"); break; } + case 175: { sb.append("dreturn"); break; } + case 176: { sb.append("areturn"); break; } + case 177: { sb.append("return"); break; } + case 178: { sb.append("getstatic #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 179: { sb.append("putstatic #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 180: { sb.append("getfield #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 181: { sb.append("putfield #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 182: { sb.append("invokevirtual #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 183: { sb.append("invokespecial #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 184: { sb.append("invokestatic #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 185: { sb.append("invokeinterface #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i)) + " " + bytes_to_int(b.elementAt(++i)) + " " + bytes_to_int(b.elementAt(++i))); break; } + case 187: { sb.append("new " + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 188: { sb.append("newarray " + bytes_to_int(b.elementAt(++i))); break; } + case 189: { sb.append("anewarray #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 190: { sb.append("arraylength"); break; } + case 191: { sb.append("athrow"); break; } + case 192: { sb.append("checkcast #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 193: { sb.append("instanceof #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 194: { sb.append("monitorenter"); break; } + case 195: { sb.append("monitorexit"); break; } + // case 196: { sb.append("wide"); break; } + case 197: { sb.append("multianewarray #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i)) + " " + bytes_to_int(b.elementAt(++i))); break; } + case 198: { sb.append("ifnull #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 199: { sb.append("ifnonnull #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i))); break; } + case 200: { sb.append("goto_w #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i), b.elementAt(++i), b.elementAt(++i))); break; } + case 201: { sb.append("jsr_w #" + bytes_to_int(b.elementAt(++i), b.elementAt(++i), b.elementAt(++i), b.elementAt(++i))); break; } + case 202: { sb.append("breakpoint"); break; } + case 254: { sb.append("impdep1"); break; } + default: { throw new JVMCodeException("JVMCodeException: jvmCode: void get_Command(Vector b)"); } + } + sb.append("\n"); + } + sb.append(" }"); + bytecodelog.debug("Bytecode der Methode: \n" + sb.toString()); + } + // ino.end + + // ino.method.bytes_to_int.22878.definition + public static int bytes_to_int(Byte b3, Byte b2, Byte b1, Byte b0) + // ino.end + // ino.method.bytes_to_int.22878.body + { + int x3 = b3.intValue(); if(x3 < 0) x3 = 256 + x3; + int x2 = b2.intValue(); if(x2 < 0) x2 = 256 + x2; + int x1 = b1.intValue(); if(x1 < 0) x1 = 256 + x1; + int x0 = b0.intValue(); if(x0 < 0) x0 = 256 + x0; + return (x3 << 24) + (x2 << 16) + (x1 << 8) + x0; + } + // ino.end + + // ino.method.bytes_to_int.22881.definition + public static int bytes_to_int(Byte b1, Byte b0) + // ino.end + // ino.method.bytes_to_int.22881.body + { + int x1 = b1.intValue(); if(x1 < 0) x1 = 256 + x1; + int x0 = b0.intValue(); if(x0 < 0) x0 = 256 + x0; + return (x1 << 8) + x0; + } + // ino.end + + // ino.method.bytes_to_int.22884.definition + public static int bytes_to_int(Byte b) + // ino.end + // ino.method.bytes_to_int.22884.body + { + int x = b.intValue(); if(x < 0) x = 256 + x; + return x; + } + // ino.end + + // ino.method.shortToBytes.22887.definition + public static byte[] shortToBytes(short i) + // ino.end + // ino.method.shortToBytes.22887.body + { + byte[] wert = new byte[2]; + wert[0] = (byte) ((i >>> 8) & 255); + wert[1] = (byte) ((i & 255)); + + return wert; + } + // ino.end + + + +} +// ino.end diff --git a/src/mycompiler/mybytecode/Key.java b/src/mycompiler/mybytecode/Key.java new file mode 100755 index 000000000..d2c41e4c7 --- /dev/null +++ b/src/mycompiler/mybytecode/Key.java @@ -0,0 +1,122 @@ +// ino.module.Key.8548.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.Key.8548.import +import java.io.FileOutputStream; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.Key.22890.declaration +public class Key +// ino.end +// ino.class.Key.22890.body +{ + // ino.attribute.tag.22893.declaration + private byte tag; + // ino.end + // ino.attribute.a.22896.declaration + private String a; + // ino.end + // ino.attribute.codegenlog.22899.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.22899.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + + // ino.method.Key.22902.definition + public Key(byte t, String a) + // ino.end + // ino.method.Key.22902.body + { + this.tag = t; + this.a = a; + } + // ino.end + + // ino.method.equals.22905.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.22905.body + { + if (obj instanceof Key) { + Key key_object = (Key) obj; + if (this.tag == key_object.get_tag() + && this.a.equals(key_object.get_a())) + return true; + } + return false; + } + // ino.end + + // ino.method.get_tag.22908.definition + public byte get_tag() + // ino.end + // ino.method.get_tag.22908.body + { + return tag; + } + // ino.end + + // ino.method.get_a.22911.definition + public String get_a() + // ino.end + // ino.method.get_a.22911.body + { + return a; + } + // ino.end + + // ino.method.set_tag.22914.definition + public void set_tag(byte t) + // ino.end + // ino.method.set_tag.22914.body + { + this.tag = t; + } + // ino.end + + // ino.method.set_a.22917.definition + public void set_a(String s) + // ino.end + // ino.method.set_a.22917.body + { + this.a = s; + } + // ino.end + + // ino.method.codegen.22920.definition + public void codegen(ClassFile classfile, FileOutputStream f) + // ino.end + // ino.method.codegen.22920.body + { + String tag_string = new String(); + if (tag == (byte) 1) + tag_string = "CONSTANT_Utf8"; + else if (tag == JVMCode.CONSTANT_Integer) + tag_string = "CONSTANT_Integer"; + else if (tag == JVMCode.CONSTANT_Float) + tag_string = "CONSTANT_Float"; + else if (tag == JVMCode.CONSTANT_Long) + tag_string = "CONSTANT_Long"; + else if (tag == JVMCode.CONSTANT_Double) + tag_string = "CONSTANT_Double"; + else if (tag == JVMCode.CONSTANT_Class) + tag_string = "CONSTANT_Class"; + else if (tag == JVMCode.CONSTANT_String) + tag_string = "CONSTANT_String"; + else if (tag == JVMCode.CONSTANT_Fieldref) + tag_string = "CONSTANT_Fieldref"; + else if (tag == JVMCode.CONSTANT_Methodref) + tag_string = "CONSTANT_Methodref"; + else if (tag == JVMCode.CONSTANT_InterfaceMethodref) + tag_string = "CONSTANT_InterfaceMethodref"; + else if (tag == JVMCode.CONSTANT_NameAndType) + tag_string = "CONSTANT_NameAndType"; + + codegenlog.debug(tag_string + " " + a); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/MethodInfo.java b/src/mycompiler/mybytecode/MethodInfo.java new file mode 100755 index 000000000..a0775b684 --- /dev/null +++ b/src/mycompiler/mybytecode/MethodInfo.java @@ -0,0 +1,135 @@ +// ino.module.MethodInfo.8549.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.MethodInfo.8549.import +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Vector; +import mycompiler.myexception.JVMCodeException; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.MethodInfo.22923.declaration +public class MethodInfo +// ino.end +// ino.class.MethodInfo.22923.body +{ + // ino.attribute.codegenlog.22926.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.22926.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + + // ino.attribute.access_flags.22929.declaration + private short access_flags; + // ino.end + + // ino.attribute.name_index.22932.declaration + private short name_index; + // ino.end + + // ino.attribute.descriptor_index.22935.declaration + private short descriptor_index; + // ino.end + + // ino.attribute.attributes.22938.declaration + private Vector attributes = new Vector(); + // ino.end + + // ino.method.get_access_flags.22941.definition + public short get_access_flags() + // ino.end + // ino.method.get_access_flags.22941.body + { + return this.access_flags; + } + // ino.end + + // ino.method.get_name_index.22944.definition + public short get_name_index() + // ino.end + // ino.method.get_name_index.22944.body + { + return this.name_index; + } + // ino.end + + // ino.method.get_descriptor_index.22947.definition + public short get_descriptor_index() + // ino.end + // ino.method.get_descriptor_index.22947.body + { + return this.descriptor_index; + } + // ino.end + + // ino.method.get_attributes.22950.definition + public Vector get_attributes() + // ino.end + // ino.method.get_attributes.22950.body + { + return this.attributes; + } + // ino.end + + // ino.method.set_access_flags.22953.definition + public void set_access_flags(short t) + // ino.end + // ino.method.set_access_flags.22953.body + { + this.access_flags = t; + } + // ino.end + + // ino.method.set_name_index.22956.definition + public void set_name_index(short t) + // ino.end + // ino.method.set_name_index.22956.body + { + this.name_index = t; + } + // ino.end + + // ino.method.set_descriptor_index.22959.definition + public void set_descriptor_index(short t) + // ino.end + // ino.method.set_descriptor_index.22959.body + { + this.descriptor_index = t; + } + // ino.end + + // ino.method.set_attributes.22962.definition + public void set_attributes(Vector t) + // ino.end + // ino.method.set_attributes.22962.body + { + this.attributes = t; + } + // ino.end + + // ino.method.codegen.22965.definition + public void codegen(ClassFile classfile, FileOutputStream f) + throws JVMCodeException, IOException + // ino.end +// ino.method.codegen.22965.body +{ + classfile.writeShort(f, access_flags); + classfile.writeShort(f, name_index); + classfile.writeShort(f, descriptor_index); + classfile.writeShort(f, (short) attributes.size()); + + codegenlog.debug("MethodInfo: acc_flag=" + access_flags + + ", name_index=" + name_index + ", descriptor_index=" + + descriptor_index + ", attributes_count=" + attributes.size()); + + if (attributes != null) + for (int i = 0; i < attributes.size(); i++) { + attributes.elementAt(i).codegen(classfile, f); + } + } +// ino.end +} +// ino.end diff --git a/src/mycompiler/mybytecode/SignatureInfo.java b/src/mycompiler/mybytecode/SignatureInfo.java new file mode 100755 index 000000000..a428e0486 --- /dev/null +++ b/src/mycompiler/mybytecode/SignatureInfo.java @@ -0,0 +1,259 @@ +// ino.module.SignatureInfo.8550.package +package mycompiler.mybytecode; +// ino.end + +// ino.module.SignatureInfo.8550.import +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Vector; +import mycompiler.myclass.ParameterList; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.SignatureInfo.22968.description type=javadoc +/** + * Generiert die Attribute eines Fields, einer Methode oder einer Klasse/Interface + * zur Integration der Signatur (Generics). + * @author SCJU + */ +// ino.end +// ino.class.SignatureInfo.22968.declaration +public class SignatureInfo extends Attribute +// ino.end +// ino.class.SignatureInfo.22968.body +{ + // ino.attribute.signatureID.22972.decldescription type=line + // UTF-8 Konstante mit der Signatur selbst + // ino.end + // ino.attribute.signatureID.22972.declaration + private short signatureID = 0; + // ino.end + + // ino.attribute.codegenlog.22975.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.22975.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + + + // ino.method.SignatureInfo.22978.defdescription type=javadoc + /** + * Konstruktor fuer die Signatur einer Klasse bzw. eines Interfaces. + */ + // ino.end + // ino.method.SignatureInfo.22978.definition + public SignatureInfo(Vector vec, UsedId superclass, Vector superIf, ClassFile cf) + // ino.end + // ino.method.SignatureInfo.22978.body + { + StringBuffer sb = new StringBuffer(); + sb.append("<"); + set_attribute_name_index(cf.getSignatureID()); + + // Parameterliste verarbeiten, falls vorhanden + Type type; + for (int i=0; i"); + + + if (superclass == null && (superIf == null || superIf.size() == 0)) { + // Falls keine Superclassen oder Interfaces angegeben wurden, + // wird per Definition wird nochmals "Ljava/lang/Object;" angehaengt + sb.append(JVMCode.get_codegen_Type("Object", null)); + } else { + if (superclass != null) sb.append(superclass.getSignatureUsedId()); + + if (superIf != null && superIf.size() > 0) { + for (int i=0; i"); + } + + sig.append("("); + + // Parameterliste verarbeiten, falls vorhanden + if (param != null) { + for (int i=0; i paralist = new Vector(); // Parameterliste 'class xy{}' wird gespeichert + // ino.end + // ino.attribute.parahash.23026.declaration + private Hashtable parahash = new Hashtable(); // parametrisierten Attrib. werden mit den Paramet.aus paralist verk. + // ino.end + // ino.attribute.isFirstLocalVarDecl.23029.declaration + public static boolean isFirstLocalVarDecl; //Hilfsvariable fuer Offsets, hoth + // ino.end + + private Vector genericClassParameters=new Vector(); + + // ino.attribute.containedTypes.23032.decldescription type=line + // PL 05-07-30 eingefuegt. Vektor aller Typdeklarationen, die in der Klasse + // vorkommen. Wird in der Studienarbeit von Andreas Stadelmeier nur für Verifizierung der Tests eingesetzt. + // ino.end + // ino.attribute.containedTypes.23032.declaration + private Vector containedTypes = new Vector(); + // ino.end + // ino.attribute.usedIdsToCheck.23035.declaration + private Vector usedIdsToCheck = new Vector(); + // ino.end + + private TypeAssumptions typeAssumptions = null;//muss mit null Initialisiert werden. Darf nur über getTypeAssumptions abgerufen werden. + private Vector methodList = null; // gleich wie typeAssumptions + + // ino.attribute.parserlog.23038.declaration + protected Logger parselog = Logger.getLogger("parser"); + // ino.end + protected Logger typinferenzLog = Logger.getLogger("Typeinference"); + + + // ino.method.Class.23041.definition + public Class(String name) + // ino.end + // ino.method.Class.23041.body + { + super(name); + if(name.equals("java.lang.Object")){ + superclassid=null; + } + } + // ino.end + + // ino.method.Class.23044.definition + public Class(String name, Modifiers mod) + // ino.end + // ino.method.Class.23044.body + { + super(name, mod); + if(name.equals("java.lang.Object")){ + superclassid=null; + } + } + // ino.end + + // ino.method.Class.23047.defdescription type=javadoc + /** + * Konstruktor, der die Angabe aller Parameter ermoeglicht. + * Zur Uebersichtlichkeit in der Grammatik. + */ + // ino.end + // ino.method.Class.23047.definition + public Class(String name, Modifiers mod, ClassBody cb, Vector ct, Vector usedIdsToCheck, + UsedId superclass, Vector superif, Vector paralist) + // ino.end +// ino.method.Class.23047.body +{ + super(name, mod); + if (cb != null) set_ClassBody(cb); + if (ct != null) setContainedTypes(ct); + if (superclass != null) set_UsedId(superclass); + if (superif != null) setSuperInterfaces(superif); + if (paralist != null) this.set_ParaList(paralist); + if(usedIdsToCheck!=null) this.usedIdsToCheck=usedIdsToCheck; + + // HOTI 10.5.06 + // Object darf natuerlich nicht Object als Superklasse haben + // Sonst gibt es eine endlosaufloesung + if(name.equals("java.lang.Object")){ + superclassid=null; + } + + parserlog.debug("Neue Klasse: " + name); + + + } +// ino.end + + // ino.method.getUsedIdsToCheck.23050.definition + public Vector getUsedIdsToCheck() + // ino.end + // ino.method.getUsedIdsToCheck.23050.body + { + return usedIdsToCheck; + } + // ino.end + // ino.method.setContainedTypes.23053.definition + public void setContainedTypes(Vector containedTypes) + // ino.end + // ino.method.setContainedTypes.23053.body + { + this.containedTypes = containedTypes; + } + // ino.end + + // ino.method.getContainedTypes.23056.definition + public Vector getContainedTypes() + // ino.end + // ino.method.getContainedTypes.23056.body + { + return containedTypes; + } + // ino.end + + // ino.method.para_check.23059.definition + public void para_check(Vector classlist, boolean ext) + throws SCClassException + // ino.end + // ino.method.para_check.23059.body + { + //pr�ft, ob jeder Key in der parahash-Tabelle auch im Vector paralist steht bzw. umgekehrt. + + parahash = body.init_parahashtable(paralist,ext); + // Para_check erstellt Hashtabelle der Klasse this.get_classname + parahash.toString()+paralist.toString()); + + for(Enumeration el = paralist.elements(); el.hasMoreElements();) + { + Type typ = (Type)el.nextElement(); + if(!parahash.contains(typ.getName())) + { + parserlog.error(""); + parserlog.error("Fehler: unbekannter Parameter: "+ typ.getName()); + + SCExcept neu=new SCExcept(); + neu.set_error("Fehler: unbekannter Parameter: "+ typ.getName()); + neu.set_statement("Class"); + SCClassException except = new SCClassException(); + Vector v = new Vector(); + v.add(neu); + except.addException(v); + except.addClassname(getName()); + throw except; + } + } + + if(superclassid != null) + { + String superclassname; + Vector superclass = superclassid.get_Name(); + + // superclass darf nur ein Element haben, da es in Java keine Mehrfachvererbung gibt! + for(Enumeration el = superclass.elements();el.hasMoreElements();) + { + superclassname = (String) el.nextElement(); + // Alle Klassen in der Klassenliste (enth�lt alle definierten Klassen) durchgehen + for ( Enumeration e2 = classlist.elements(); e2.hasMoreElements(); ) + { + Class basis =e2.nextElement(); + // Klasse im Vektor == Superklasse + if( basis.getName().equals(superclassname) ) + { + if( basis.paralist != null && superclassid!=null && superclassid.get_ParaList()!=null) + { + // System/.out.println( "Basis: " + basis.get_ParaList() ); + // if( basis.get_ParaList().size() > 0 ) System/.out.println( "0: " + ((TypePlaceholder)basis.get_ParaList().elementAt(0)).get_Type() ); + // if( basis.get_ParaList().size() > 1 ) System/.out.println( "1: " + ((TypePlaceholder)basis.get_ParaList().elementAt(1)).get_Type() ); + // otth: geaender auf vParaOrg + if(basis.paralist.size() != this.superclassid.get_ParaList().size()) + { + SCExcept neu = new SCExcept(); + neu.set_error("Parameterlisten von Basis und Child unterscheiden sich in der L�nge!"); + neu.set_classname(getName()); + neu.set_statement("Class"); + SCClassException except = new SCClassException(); + Vector v = new Vector(); + v.add(neu); + except.addException(v); + except.addClassname(getName()); + // Exceptions werfen aufgrund vom eingestellten + // Debug-Level??? + // if( MyCompiler.DebugLevel != MyCompiler.UNIFICATION_INFO) + // throw except; + parserlog.debug("Parameterlistenl�ngenpr�fung von Basis- u. Superkl. tempor�r ausgeschalten! - otth"); + } + } + } + } + } + + try + { + parahash = body.complete_parahashtable(classlist, superclassid,parahash, ext); + } + catch(SCClassBodyException ex){ + SCClassException except = new SCClassException(); + except.addException(ex.get_exlist()); + except.addClassname(getName()); + throw except; + } + + paralist = complete_paralist(ext); //Parameterliste wird um die Eintr�ge der Basisklasse erg�nzt + // vParaOrg wird hier nicht veraendert + } + + else + { + // typinferenzLog.debug("\tkeine Vererbung gefunden!"); + } + + /* + if(ext) + { + string_rec("++ ParaCheck Globale Parameterliste: ",paralist);typinferenzLog.debug(); + string_rec("++ ParaCheck Globale ParaHashtabelle: ", parahash);typinferenzLog.debug(); + } + */ + } + // ino.end + + // ino.method.complete_paralist.23062.definition + public Vector complete_paralist(boolean ext) + // ino.end + // ino.method.complete_paralist.23062.body + { + + //Diese Funktion vervollt�ndigt die Parameterliste f�r vererbte Klassen + Vector child = paralist; + + paralist = (Vector)superclassid.get_ParaList(); + + for(Enumeration e = child.elements();e.hasMoreElements();){ + paralist.addElement(e.nextElement()); + } + + return this.paralist; + } + // ino.end + + // ino.method.sc_check.23065.definition + public void sc_check(Vector classlist, boolean ext) + throws SCClassException + // ino.end + // ino.method.sc_check.23065.body + { + + // Der normale Semantik-Check - Aufgabe: Initialisierung der Class-Hashtable und Aufruf des Semantik-Checks + // otth: Diese Funktion wird f�r alle Objekte vom Typ 'Class`, + // otth: die im Vector Sourcefile.classes gespeichert sind, im Sourcefile aufgerufen. + + // PARAMETRISIERTE TYPEN + try + { + para_check(classlist,ext); + } + catch(SCClassException ex) + { + throw ex; + } + + // Initialisierung der Hash-Tabelle! + // erbt die Klasse von einer anderen??? + String strSuperKlassenName = null; + if( superclassid != null ) + { + Vector superclass = superclassid.get_Name(); // 'superclass'-nur ein Element, da in Java keine Mehrfachver. + for( Enumeration el = superclass.elements(); el.hasMoreElements(); ) + { + strSuperKlassenName = (String) el.nextElement(); + } + } + + // Hash-Tabelle aufrufen! + try + { + body.sc_init_hashtable( classlist, strSuperKlassenName, getName(), ext ); + } + catch (SCClassBodyException ex) + { + SCClassException except = new SCClassException(); + except.addException(ex.get_exlist()); + except.addClassname(getName()); + throw except; + } + + // Semantik-Check aufrufen + + try + { + body.sc_check( classlist,ext ); + } + catch (SCClassBodyException ex) + { + SCClassException except = new SCClassException(); + except.addException( ex.get_exlist() ); + except.addClassname( getName() ); + throw except; + } + + } + // ino.end + + // ino.method.sc_check_for_extended_classes.23068.definition + public void sc_check_for_extended_classes(Vector classlist, Hashtable childhash,boolean ext) + // ino.end + // ino.method.sc_check_for_extended_classes.23068.body + { + // Der Semantik-Check f�r Basis-Klassen - Aufgabe: In der mit �bergegeben Hashtable childhash sollen + // die geerbten Funktionen und Methoden mit ihren zugeh�rigen Typen eingetragen werden + + String strSuperKlassenName = null; + + // otth: Hat diese Klasse wieder eine Supperklasse? + if( superclassid != null) + { + Vector superclass = superclassid.get_Name(); + for(Enumeration el = superclass.elements();el.hasMoreElements();) //superclass darf nur ein Element haben!!! + { + strSuperKlassenName = (String) el.nextElement(); + } + } + + // otth: Hashtabelle f�r Superklasse erestellen + body.sc_init_hashtable_for_extended_classes(classlist, strSuperKlassenName, childhash, paralist, parahash, body.kill, ext); + } + // ino.end + + + + // ino.method.codegen.23071.definition + public void codegen(SourceFile sf) + throws JVMCodeException + // ino.end + // ino.method.codegen.23071.body + { + ClassFile classfile = new ClassFile(); + String superClass; + + // Handling der Superklasse + if(superclassid != null) { + superClass = superclassid.get_codegen_UsedId(); + } else { + superClass = "java/lang/Object"; + } + + // Handling der Package + String pkgName = ""; + if (sf.getPackageName() != null) { + pkgName = sf.getPackageName().get_codegen_UsedId() + "/"; + } + + classfile.add_class(getName(), pkgName, superClass, getAccessFlags()); + + // Handling fuer Superinterfaces + classfile.addSuperInterfaces(getSuperInterfaces()); + + // Generics hinzufuegen - falls erforderlich + classfile.addGenerics(this.paralist,superclassid, this.getSuperInterfaces()); + + // Body der Classfile generieren + if(body != null) { + body.codegen(classfile, this.paralist); + } + + // Ueberpruefung, ob Konstruktor generiert + // Falls nicht, default-Konstruktor erzeugen + if(!classfile.get_constructor_founded()) { + classfile.add_method("", "()V", null, null, null, (short)0, this.paralist, false); + } + + classfile.codegen(); + + codegenlog.info("Compilierung erfolgreich abgeschlossen, "+ getName() + ".class erstellt."); + } + // ino.end + + // ino.method.set_UsedId.23074.definition + public void set_UsedId (UsedId uid) + // ino.end + // ino.method.set_UsedId.23074.body + { + this.superclassid = uid; + } + // ino.end + + // ino.method.set_ClassBody.23077.definition + public void set_ClassBody(ClassBody body) + // ino.end + // ino.method.set_ClassBody.23077.body + { + this.body = body; + } + // ino.end + + // ino.method.set_class_block.23080.definition + public void set_class_block(Block block) + // ino.end + // ino.method.set_class_block.23080.body + { + this.class_block = block; + } + // ino.end + + // ino.method.is_member.23083.definition + public String is_member(String var) + // ino.end + // ino.method.is_member.23083.body + { + Hashtable h; + h=body.get_hash(); + return (String)h.get(var); + } + // ino.end + + // ino.method.get_Superclass_Name.23086.definition + public String get_Superclass_Name() + // ino.end + // ino.method.get_Superclass_Name.23086.body + { + if(superclassid!=null) + return superclassid.getQualifiedName(); + else + return null; + } + // ino.end + + // ino.method.get_ClassBody.23089.definition + public ClassBody get_ClassBody() + // ino.end + // ino.method.get_ClassBody.23089.body + { + return body; + } + // ino.end + + // ino.method.get_class_block.23092.definition + public Block get_class_block() + // ino.end + // ino.method.get_class_block.23092.body + { + return class_block; + } + // ino.end + + // ino.method.does_Class_extend.23095.definition + public boolean does_Class_extend() + // ino.end + // ino.method.does_Class_extend.23095.body + { + if(superclassid==null) + return false; + else + return true; + } + // ino.end + + // ino.method.set_ParaList.23098.definition + public void set_ParaList(Vector para) + // ino.end + // ino.method.set_ParaList.23098.body + { + this.paralist = para; + } + // ino.end + + // ino.method.get_ParaList.23101.definition + public Vector get_ParaList() + // ino.end + // ino.method.get_ParaList.23101.body + { + return this.paralist; + } + // ino.end + + // ino.method.set_ParaHash.23104.definition + public void set_ParaHash(Hashtable hash) + // ino.end + // ino.method.set_ParaHash.23104.body + { + this.parahash = hash; + } + // ino.end + + // ino.method.get_ParaHash.23107.definition + public Hashtable get_ParaHash() + // ino.end + // ino.method.get_ParaHash.23107.body + { + return this.parahash; + } + // ino.end + + + +/*static void string_rec(Hashtable ht){ + String record=""; + boolean isError=false; + record=record.concat("["); + for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){ + String s = (String)k.nextElement(); + Object o = e.nextElement(); + + record=record.concat(" "+s); + + if(o instanceof Type){ + record=record.concat(" = "+((Type)o).getName()); + } else if(o instanceof Hashtable){ + record=record.concat("= "); + string_rec((Hashtable)o); + if(e.hasMoreElements()) + record=record.concat(", "); + } else if(o instanceof String){ + record=record.concat(" = "+o); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else { + record=("[FEHLER: string_rec: unbekannter Typ!!!!!!"); + isError=true; + } + } + record=record.concat("]"); + if(isError){ + parserlog.error(record); + }else{ + parserlog.debug(record); + } + }*/ + + /*static void string_rec(Vector v){ + String record=("{"); + for(Enumeration e=v.elements();e.hasMoreElements();){ + Type t = (Type)e.nextElement(); + record=record.concat(" "+t.getName()); + + if(e.hasMoreElements()) + record=record.concat(","); + } + record=record.concat("}"); + parserlog.debug(record); + }*/ + /*static void string_rec(String st, Hashtable ht){ + String record=(st); + boolean isError=false; + record=record.concat("["); + for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){ + String s = (String)k.nextElement(); + Object o = e.nextElement(); + + record=record.concat(" "+s); + + if(o instanceof Type){ + record=record.concat(" = "+((Type)o).getName()); + } + + else if(o instanceof Hashtable){ + record=record.concat("= "); + string_rec((Hashtable)o); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else if(o instanceof String){ + record=record.concat(" = "+o); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else { + record=("[FEHLER: string_rec: unbekannter Typ!!!!!! " +o); + isError = true; + } + } + record=record.concat("]"); + if(isError){ + parserlog.error(record); + }else{ + parserlog.debug(record); + } + }*/ + + /*static void string_rec(String st,Vector v) + { + String record=(st); + record=record.concat("{"); + for(Enumeration e=v.elements();e.hasMoreElements();) + { + Type t = (Type)e.nextElement(); + record=record.concat(" "+t.getName()); + if(e.hasMoreElements()) + { + record=record.concat(", "); + } + } + record=record.concat("}"); + parserlog.debug(record); + }*/ + + + ///////////////////////////////////////////////////////////////////////// + // TypeReconstructionAlgorithmus + ///////////////////////////////////////////////////////////////////////// + // ino.method.TRProg.23110.defdescription type=javadoc + /** + * Ausgangspunkt f�r den Typrekonstruktionsalgorithmus. Hier werden zun�chst + * die Mengen von Typannahmen V_fields_methods und V_i erstellt, die als Eingabe + * f�r den Algorithmus dienen.
+ * (siehe Algorithmus 5.17 TRProg, Martin Pl�micke) + *
Author: J�rg B�uerle + * @param supportData + * @param globalAssumptions + * @return Liste aller bisher berechneten, m�glichen Typkombinationen + * @throws CTypeReconstructionException + */ + // ino.end + // ino.method.TRProg.23110.definition + public Vector TRProg(CSupportData supportData, TypeAssumptions globalAssumptions) + throws CTypeReconstructionException + // ino.end + // ino.method.TRProg.23110.body + { + /* + + */ + ////////////////////////////// + // Und los geht's: + ////////////////////////////// + inferencelog.info("Rufe TRStart()..."); + ////////////////////////////// + // Ab hier ... + // @author A10023 - Andreas Stadelmeier: + ////////////////////////////// + //Erzeuge Assumptions: + TypeAssumptions assumptions = this.getTypeAssumptions(); + //-- + assumptions.add(globalAssumptions); + + //Generiere Liste mit Expressions, welche zur Initialisierung von Feldern verwendet werden. + Vector fieldInitializers = new Vector(); + for(FieldInitialization field : body.getFieldInitializations()){ + Assign fieldAssign = new Assign(0,0); + Expr expr1 = new LocalOrFieldVar(field.getName(), 0); + Expr expr2 = field.getWert(); + fieldAssign.set_Expr(expr1, expr2); + fieldInitializers.add(fieldAssign); + } + + ConstraintsSet oderConstraints = this.TYPE(this.getMethodList(), fieldInitializers, assumptions); + typinferenzLog.debug("Erstellte Constraints: "+oderConstraints); + + //Die Constraints in Pair's umwandeln: + Vector> xConstraints = new Vector>();// = oderConstraints.getConstraints(); + for(Vector uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt. + Vector cons = new Vector(); + for(UndConstraint undCons:uC){ + cons.addAll(undCons.getConstraintPairs()); + } + xConstraints.add(cons); + } + typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints); + + ////////////////////////////// + // Unifizierung der Constraints: + ////////////////////////////// + Vector ret = new Vector(); //Generiere das Result-Set + for(Vector constraints : xConstraints){ + //Alle durch das Karthesische Produkt entstandenen Möglichkeiten durchgehen: + Vector> result = new Vector>(); + //Erst die Unifizierung erstellen: + result.addAll(Unify.unify(constraints, supportData.getFiniteClosure())); + + // Debugoutput:Vector> + typinferenzLog.debug("Unifiziertes Ergebnis: "+result); + + /* + // Prüfe ob eindeutige Lösung: + if(result.size()>1 && !Unify.hasSolvedForm(result.elementAt(0))){ + + typinferenzLog.debug("Keine eindeutige Lösung!"); + + }else if(result.size()>1){ + + //Replace TPH: + for(Pair res : result.elementAt(0)){ + if(res.OperatorEqual()){ + if(res.TA1 instanceof TypePlaceholder)((TypePlaceholder)res.TA1).fireReplaceTypeEvent(new CReplaceTypeEvent(res.TA1, res.TA2)); + } + } + } + */ + //typinferenzLog.debug(); + //typinferenzLog.debug(supportData.getFiniteClosure()); + typinferenzLog.debug("Typinformationen: \n"+this.getTypeInformation(this.getMethodList(), fieldInitializers)); + + typinferenzLog.debug("\nJavaFiles:\n"); + + //typinferenzLog.debug(this.printJavaCode(new ResultSet(new Vector()))); + + + //Der Unifikationsalgorithmus kann wiederum auch mehrere Lösungen errechnen, diese werden im folgenden durchlaufen: + for(Vector resultSet : result){ + //Add Result set as a new ReconstructionResult to ret: + CTypeReconstructionResult reconstructionResult = new CTypeReconstructionResult(this); + reconstructionResult.setConstraints(constraints); + reconstructionResult.setUnifiedConstraints(resultSet); + ret.add(reconstructionResult); + + //ResultSet res = new ResultSet(resultSet); + typinferenzLog.debug("JavaFile für ResultSet "+reconstructionResult+"\n"); + typinferenzLog.debug(this.printJavaCode(reconstructionResult)); + + } + + } + return ret; + /* + CReconstructionTupleSet retTupleSet = this.TRStart(methodList, V, V_fields_methods, supportData); + inferencelog.debug("Bin aus TRStart() zur�ck in TRProg()."); + ////////////////////////////// + // Neu Ergebnismenge A aller + // Typannahmen erzeugen: + ////////////////////////////// + inferencelog.debug("Erstelle Ergebnismenge..."); + Vector newA = new Vector(); + + // Alle bisherigen M�glichkeiten an Typkombinationen durchgehen: + Vector oldA = supportData.getA(); + for(int i=0; i retTupleIt = retTupleSet.getIterator(); + while(retTupleIt.hasNext()){ + CReconstructionTuple possibleTuple = retTupleIt.next(); + this.clear(possibleTuple.getAssumSet(), rememberLocals); + + // Neue Typinformationen mit alten Typinformationen vereinigen: + CTypeReconstructionResult newReconResult = oneReconResult.shallowCopy(); + newReconResult.addDataFromTupel(possibleTuple); + + + //PL 05-08-02 eingefuegt + //Fuegt Klassen und GenericTypeVars zu A hinzu + newReconResult.addClassName(this.getName()); + Vector genericsList = new Vector(); + for(int ii =0; ii getMethodList() { + if(this.methodList != null) return this.methodList; + //TODO: Unnötige Berechnungen im folgenden Code rauskürzen: + ////////////////////////////// + // Die Eingabedaten bauen: + ////////////////////////////// + inferencelog.debug("Baue Eingabedaten..."); + TypeAssumptions V_fields_methods = new TypeAssumptions(this.getName()); + Vector methodList = new Vector(); + Vector V = new Vector(); + Vector rememberLocals = new Vector(); + + ////////////////////////////// + // Alle Felder durchgehen: + // Zuerst alle Attribute, dann Methoden + // ge�ndert: hoth 06.04.2006 + + ////////////////////////////// + for(FieldDecl field : body.get_FieldDeclVector()) + { + ////////////////////////////// + // Attribut: + ////////////////////////////// + if(field instanceof InstVarDecl){ + InstVarDecl instVar = (InstVarDecl)field; + ////////////////////////////// + // Alle Variablendeklarationen (int a, b, c) durchgehen: + ////////////////////////////// + for(int i=0; i()); // Typannahme bauen... + V_fields_methods.add(assum); // ...und hinzuf�gen. + } + } + } + + for(FieldDecl field : body.get_FieldDeclVector()) + { + ////////////////////////////// + // Methode: + ////////////////////////////// + if(field instanceof Method){ + Method method = (Method)field; + //if(method.get_Method_Name().equals(this.getName()) && ((method.getReturnType().equals(new mycompiler.mytype.Void(0))) || method.getReturnType() instanceof TypePlaceholder)){ + if(method.get_Method_Name().equals(this.getName()) ){ + method.set_Method_Name(""); + } + //hoth: 06.04.2006 + //durchlaufe Block und suche nach Objektvariablen fuer Offset-Markierung + Iterator fieldVarIterator = V_fields_methods.iterator(); + while (fieldVarIterator.hasNext()) + { + //Wenn ObjektVariable + CTypeAssumption dieAssum = fieldVarIterator.next(); + if(dieAssum instanceof CInstVarTypeAssumption) + { + Class.isFirstLocalVarDecl=false; + if(method.get_Block() != null) + method.get_Block().addOffsetsToAssumption(dieAssum,dieAssum.getIdentifier(),true); + } + } + + methodList.addElement(method); + + // F�r V_fields_methods: + CMethodTypeAssumption methodAssum = new CMethodTypeAssumption(this.getType(), method.get_Method_Name(), method.getReturnType(), method.getParameterCount(),method.getLineNumber(),method.getOffset(),new Vector(),method.getGenericMethodParameters()); // Typannahme bauen... + + + // Methode in V_Fields_methods ablegen + // Dabei wird die OverloadedMethodID ermittelt !! + // => Method setzenuct + + + V_fields_methods.add(methodAssum); + method.setOverloadedID(methodAssum.getHashSetKey().getOverloadedMethodID()); + + + // F�r die V_i: + CTypeAssumptionSet localAssum = new CTypeAssumptionSet(); + + // Bauen... + ParameterList parameterList = method.getParameterList(); + if(parameterList!=null){ + for(int i=0; i()); + //fuege Offsets fuer Parameter hinzu, hoth: 06.04.2006 + Class.isFirstLocalVarDecl=false; + + if(method.get_Block() != null) + method.get_Block().addOffsetsToAssumption(paraAssum,paraAssum.getIdentifier(),true); + + methodAssum.addParaAssumption(paraAssum); + + + + + // F�r die V_i: + CLocalVarTypeAssumption varAssum = new CLocalVarTypeAssumption(this.getName(), method.get_Method_Name(), method.getParameterCount(), method.getOverloadedID(),"1", para.get_Name(),para.getType(), para.getLineNumber(),para.getOffset(),new Vector()); + localAssum.addElement(varAssum); + rememberLocals.addElement(varAssum); + } + } + // ...und hinzuf�gen: + + V.addElement(localAssum); + } + } + + this.methodList = methodList; + return methodList; + } + + /** + * Die Funktion ist erst nach dem Aufruf von getMethodList() nutzbar. + * Ermittelt alle Felder und Methoden der Klasse und Erstellt eine Assumption für diese. + * @return Die erstellten TypeAssumptions + */ + private TypeAssumptions getTypeAssumptions() { + if(this.typeAssumptions != null)return this.typeAssumptions; //Das sorgt dafür, dass die Assumptions nur einmalig generiert werden. + TypeAssumptions assumptions = new TypeAssumptions(this.getName()); + this.getMethodList(); //Diese Funktion muss zuerst ausgeführt werden. + //Assumption für this, also die aktuelle Klasse: (ist nicht mehr nötig, da jedes AssumptionSet einer Klasse (dem namen einer Klasse) zugewiesen ist. + //CLocalVarTypeAssumption thisAssumption = new CLocalVarTypeAssumption(this.name, name, 0, 0, name, "this", new RefType(name,0), 0, 0, null); + //assumptions.setThisV(thisAssumption); + + for(FieldDecl field : body.get_FieldDeclVector()){ + assumptions.add(field.createTypeAssumptions(this)); + } + + //Eine Assumption für den Standardkonstruktor: + // (Ein Standardkonstruktor wird immer angefügt, da es momentan keine statischen Klassen gibt) + if(assumptions.getMethodAssumptions(this.getName(), "").size()==0){ //Falls kein Konstruktor für diese Klasse definiert wurde: + assumptions.addMethodAssumption(new RefType(this.getName(),0), "", new RefType(this.getName(),0), new Vector()); + } + + + typinferenzLog.debug("Erstellte Assumptions: "+assumptions); + + this.typeAssumptions = assumptions; //Diese müssen anschließend nicht wieder generiert werden. + return assumptions; +} + + public ConstraintsSet TYPE(Vector methodList, Vector fielddeclarationList, TypeAssumptions assumptions){ + ConstraintsSet ret = new ConstraintsSet(); + // Die Felddeklarationen werden zu den Assumptions hinzugefügt und gelten danach für jede Methode. + //TypeAssumptions assumptionsPlusFieldAssumptions = new TypeAssumptions(assumptions); + for(Expr expr : fielddeclarationList){ + //ret.add(expr.TYPEStmt(assumptionsPlusFieldAssumptions)); + ret.add(expr.TYPEStmt(assumptions)); + } + for(Method methode : methodList){ + //ret.add(methode.TYPE(assumptionsPlusFieldAssumptions)); + ret.add(methode.TYPE(assumptions)); + } + return ret; + } + + // ino.method.clear.23113.defdescription type=javadoc + /** + * Entfernt Annahmen f�r lokale Variablen, die f�r Methodenparameter erzeugt + * worden sind. (siehe Algorithmus 5.17 TRProg, Martin Pl�micke) + *
Author: J�rg B�uerle + * @param V + * @param locals + */ + // ino.end + // ino.method.clear.23113.definition + void clear(CTypeAssumptionSet V, Vector locals) + // ino.end + // ino.method.clear.23113.body + { + Iterator localsIt = locals.iterator(); + while(localsIt.hasNext()){ + CTypeAssumption local = localsIt.next(); + CTypeAssumption assum = V.getElement(local.getHashSetKey()); + if(assum!=null){ + V.removeElement(local.getHashSetKey()); + } + } + } + // ino.end + + // ino.method.TRStart.23116.defdescription type=javadoc + /** + * Zentrale Methode des Typrekonstruktionsalgorithmus zur Steuerung des Ablaufs + * zwischen den einzelnen Methoden und Konstruktion der Ergebnismengen.
+ * (siehe Algorithmus 5.18 TRStart, Martin Pl�micke) + *
Author: J�rg B�uerle + * @param methodList + * @param V + * @param V_fields_methods + * @param supportData + * @return Menge aller neu berechneter, m�glichen Typkombinationen in Form von + * 2-Tupeln aus einer Menge von Unifiern und einer Menge von Typannahmen ==> + * (sigma, V) + * @throws CTypeReconstructionException + */ + // ino.end + // ino.method.TRStart.23116.definition + private CReconstructionTupleSet TRStart(Vector methodList, Vector V, CTypeAssumptionSet V_fields_methods, CSupportData supportData) + throws CTypeReconstructionException + // ino.end + // ino.method.TRStart.23116.body + { + // -------------------------- + // Startdaten vorbereiten: + // -------------------------- + inferencelog.debug("Bereite Startdaten vor..."); + V.insertElementAt(new CTypeAssumptionSet(), 0); // V_0 + CReconstructionTupleSet ret = new CReconstructionTupleSet(); // ret_0 + ret.addElement(new CReconstructionTuple(new CSubstitutionSet(), V_fields_methods)); + // -------------------------- + // Alle n Methoden durchgehen: + // -------------------------- + for(int i=1; i it = triples.getIterator(); + + // HOTI 14.5.06 + // HadAChance gibt an, ob überhaupt eine Typannahme vom Inferieren zurückkam + // Wenn false, dann ausgeben, dass keine zurück kam + // Wenn true, nachschauen, ob diese Typannahme(n) mit dem Returntyp unifizierbar sind! + // Die unifizierbaren zählt successfulls + // Wenn successfulls nachher==0 ausgeben, dass kein Returntyp passt. Ansonsten ist alles o.k. + boolean hadAChance=it.hasNext(); + int successfulls=0; + Vector exceptions=new Vector(); + while(it.hasNext()){ + CTriple triple = it.next(); + // -------------------------- + // Typannahme f�r R�ckgabewert der Methode extrahieren: + // -------------------------- + CTypeAssumptionSet V_j = triple.getAssumptionSet(); + Type theta = this.RetType(currentMethod, V_j); + // -------------------------- + // Extrahierte Typannahme mit zur�ckgelieferter Typannahme + // des Blocks unifizieren: + // -------------------------- + inferencelog.debug("Rufe Unify() f�r ReturnType..."); + Iterator> unifierPossibilities = Unify.unify(triple.getResultType(), theta, supportData.getFiniteClosure()).iterator(); + inferencelog.debug("Wende Unifier an..."); + CReconstructionTuple resultTuple = null; + // -------------------------- + // Wenn Unifier vorhanden, dann anwenden: + // -------------------------- + if(unifierPossibilities.hasNext()){ + // -------------------------- + // Alle m�glichen Unifier auf V_j anwenden: + // -------------------------- + successfulls++; + while(unifierPossibilities.hasNext()){ + CSubstitutionSet unifier = new CSubstitutionSet(unifierPossibilities.next()); + // -------------------------- + // Typannahmen bauen: + // -------------------------- + CTypeAssumptionSet V_j_substituted = V_j.deepCopy(); + V_j_substituted.sub(unifier); + // -------------------------- + // Substitutionen bauen: + // -------------------------- + CSubstitutionSet substSet = triple.getSubstitutions().deepCopy(); + substSet.applyUnifier(unifier); + substSet.unite(unifier); + // -------------------------- + + + + + resultTuple = new CReconstructionTuple(substSet, V_j_substituted); + // -------------------------- + // Tuple zu R�ckgabemenge hinzuf�gen + // (entspricht der Vereinigung in Algorithmus 5.18, Martin Pl�micke): + // -------------------------- + inferencelog.warn("##########################################"); + inferencelog.warn("F�ge neues passendes Ergebnis-Tuple hinzu:"); + inferencelog.warn("##########################################"); + inferencelog.warn(resultTuple.toString()); + inferencelog.warn("##########################################\n"); + ret.addElement(resultTuple); + } + } + // -------------------------- + // Ansonsten ohne Unifier hinzuf�gen: + // -------------------------- + else{ + exceptions.addElement(new CTypeReconstructionException("Der berechnete Return-Typ("+triple.getResultType()+") laesst sich nicht mit dem Return-Typ der Methode ("+this.RetType(currentMethod, V_j)+") unifizieren.",currentMethod)); + //resultTuple = new CReconstructionTuple(triple.getSubstitutions(), V_j); + //inferencelog.warn(""); + //inferencelog.warn("#########################################"); + //inferencelog.warn("Fuege neues unpassendes Ergebnis-Tuple hinzu:"); + //inferencelog.warn("##########################################"); + //inferencelog.warn(resultTuple.toString()); + //inferencelog.warn("##########################################\n"); + //ret.addElement(resultTuple); + } + } + if(hadAChance && successfulls==0 && exceptions.size()>0) { + if(exceptions.size()==1){ + throw exceptions.elementAt(0); + } + throw new CTypeReconstructionException("Die berechneten Return-Typen lassen sich nicht mit dem Return-Typ der Methode unifizieren.",exceptions,currentMethod); + } + // -------------------------- + // TupleSet "ret" geht als Eingabewert bzw. Vorkenntnis + // in den n�chsten Schleifendurchlauf, d.h. in TRNextMeth + // f�r die n�chste Methode, ein... + // -------------------------- + } + // -------------------------- + // Nach dem letzten Schleifendurchlauf + // TupleSet "ret" als Ergebnis zur�ckgeben: + // -------------------------- + + for(int i=0;i typePlaceholderHasMethod=new Hashtable(); + + Vector tphs=new Vector(); + Hashtable data = V_j_substituted.getHashtable(); + Collection values=data.values(); + Iterator myit=values.iterator(); + while(myit.hasNext()){ + CTypeAssumption myassum=myit.next(); + if(myassum instanceof CMethodTypeAssumption){ + CMethodTypeAssumption mAssum=(CMethodTypeAssumption)myassum; + Type aT=mAssum.getAssumedType(); + if(aT instanceof TypePlaceholder && !tphs.contains(aT)){ + tphs.addElement((TypePlaceholder)aT); + typePlaceholderHasMethod.put((TypePlaceholder)aT,mAssum); + } + Vector paras=mAssum.getParaAssumptions(); + if(paras!=null){ + for(int j=0;j + * (siehe Algorithmus RetType, Martin Pl�micke) + *
Author: J�rg B�uerle + * @param me + * @param V + * @return + */ + // ino.end + // ino.method.RetType.23119.definition + private Type RetType(Method me, CTypeAssumptionSet V) + // ino.end + // ino.method.RetType.23119.body + { + CTypeAssumption assum = V.getElement(new CMethodKey(this.getName(), me.get_Method_Name(), me.getParameterCount(),me.getOverloadedID())); + if(assum instanceof CMethodTypeAssumption){ + return ((CMethodTypeAssumption)assum).getAssumedType(); + } + else return null; + } + // ino.end + + // ino.method.TRNextMeth.23122.defdescription type=javadoc + /** + * Erweitert die bisherigen Teilergebnisse um weitere Informationen aus dem + * �bergebenen Block der aktuellen Methode.
+ * (siehe Algorithmus TRNextMeth, Martin Pl�micke) + *
Author: J�rg B�uerle + * @param V_last + * @param V_next + * @param tupleSet + * @param nextMethod + * @param supportData + * @return + * @throws CTypeReconstructionException + */ + // ino.end + // ino.method.TRNextMeth.23122.definition + private CTripleSet TRNextMeth(CTypeAssumptionSet V_last, CTypeAssumptionSet V_next, CReconstructionTupleSet tupleSet, Method nextMethod, CSupportData supportData) + throws CTypeReconstructionException + // ino.end + // ino.method.TRNextMeth.23122.body + { + Block Bl = nextMethod.get_Block(); + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // Alle Tupel durchgehen: + // -------------------------- + Vector exceptions=new Vector(); + int successfulls=0; + Iterator tuples = tupleSet.getIterator(); + while(tuples.hasNext()){ + CReconstructionTuple currentTuple = tuples.next(); + CTypeAssumptionSet V_i = currentTuple.getAssumSet().shallowCopy(); + CSubstitutionSet sigma_i = currentTuple.getSubSet().shallowCopy(); + V_next = V_next.deepCopy(); + V_next.sub(sigma_i); + //this.removeOldLocalVars(V_i, V_last); // Wird ganz am Ende �ber clear() in TRProg() gemacht --> hier nicht mehr n�tig + V_i.unite(V_next); + + supportData.setCurrentMethod(nextMethod.get_Method_Name()); + supportData.setCurrentMethodParaCount(nextMethod.getParameterCount()); + supportData.setCurrentMethodOverloadedID(nextMethod.getOverloadedID()); + supportData.resetBlockId(); + + try{ + CTripleSet tripleSet = Bl.TRStatement(sigma_i, V_i, supportData); + returnSet.unite(tripleSet); + successfulls++; + }catch(CTypeReconstructionException tre){ + exceptions.addElement(tre); + } + } + + if(successfulls==0&& exceptions.size()>0){ + if(exceptions.size()==1){ + throw exceptions.elementAt(0); + } + throw new CTypeReconstructionException("Class: Es konnte keine Assumption gefunden werden, die auf die Anforderung passt.",exceptions,null); + } + + return returnSet; + } + // ino.end + + // ino.method.toString.23125.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.23125.definition + public String toString() + // ino.end + // ino.method.toString.23125.body + { + //return superclassid.toString() + body.toString(); + //geaendert PL 07-07-28 + return name + body.toString(); + } + // ino.end + + + // ino.method.wandleRefTypeAttributes2GenericAttributes.23128.defdescription type=javadoc + /** + * Alle Methoden der Klassen überprüfen, ob sie als + * RefType deklarierte Attribute haben, die aber GenericTypeVars sind + * und ggf. ersetzen + * + * Bsp.: + * bei public E elementAt(i){...} wird E vorerst als RefType erkannt + * + */ + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.23128.definition + public void wandleRefTypeAttributes2GenericAttributes() + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.23128.body + { + + // Klassen ohne Body werden hier nicht durchsucht + // (p.ex. BaseTypes) + if(body==null) + return; + + Vector fieldsAndMethods=body.get_FieldDeclVector(); + + // Alle Methoden und Instanzvariablen durchgehen + for(int i=0;i enumer = V_last.getHashtable().keys(); +// while(enumer.hasMoreElements()){ +// CTypeAssumption currentAssum = V_last.getElement(enumer.nextElement()); +// if(currentAssum instanceof CLocalVarTypeAssumption){ +// V_i.removeElement(currentAssum); +// } +// } +// +// } + + // ino.method.addOffsetsToAssumption.23131.defdescription type=javadoc + /** + * Methode f�gt zu einer CTypeAssumption alle + * Offsets hinzu, wo die Variable benutzt wird. + *
Author: Thomas Hornberger 07.04.2006 + *
Author: Arne Lüdtke 20.01.2007, Auf Polymorphie erweitert. + * Wird nicht mehr verwendet. In Block ausgelagert. + * @return + */ + // ino.end + // ino.method.addOffsetsToAssumption.23131.definition + public static void addOffsetsToAssumption(CTypeAssumption localAssumption, Block localBlock,String NameVariable,boolean isMemberVariable) + // ino.end + // ino.method.addOffsetsToAssumption.23131.body + { + /*if(localBlock!=null){ + for(Object vectorObjekt : localBlock.statements) //durchlaufe alle Statements dieses Blocks + { + if(vectorObjekt instanceof Block) //Bei Block + { + Block b = (Block)vectorObjekt; + addOffsetsToAssumption(localAssumption,b,NameVariable,isMemberVariable);//rekursiver Aufruf + } + else + { + String Name_Superklasse = vectorObjekt.getClass().getSuperclass().getSimpleName(); + if(Name_Superklasse.equals("Statement")) //Bei Statement + { + Statement s = (Statement)vectorObjekt; + try{ + if(addOffsetsToStatement(localAssumption,s,NameVariable,isMemberVariable)==false) + {break;}} + catch(NullPointerException NPE){} + } + else if(Name_Superklasse.equals("Expr") || Name_Superklasse.equals("BinaryExpr") || Name_Superklasse.equals("UnaryExpr")) //Bei Expression + { + Expr e = (Expr)vectorObjekt; + try{ + addOffsetsToExpression(localAssumption,e,NameVariable,isMemberVariable);} + catch(NullPointerException NPE){} + } + } + + }}*/ + } + // ino.end + + // ino.method.addOffsetsToStatement.23134.defdescription type=javadoc + /** + * Hilfs-Methode f�r die Offset-Zuweisung + * durchsucht ein Statement rekursiv + *
Author: Thomas Hornberger 08.04.2006 + *
Author: Arne Lüdtke 20.10.2007, Auf Polymorphie umgebaut. + * @return + */ + // ino.end + // ino.method.addOffsetsToStatement.23134.definition + public static boolean addOffsetsToStatement(CTypeAssumption localAssumption,Statement statement, String NameVariable, boolean isMemberVariable) + // ino.end + // ino.method.addOffsetsToStatement.23134.body + { + return statement.addOffsetsToStatement(localAssumption,NameVariable,isMemberVariable); + /*if(statement instanceof Block) //Wenn Block + { + Block b = (Block)statement; + addOffsetsToAssumption(localAssumption,b,NameVariable,isMemberVariable); + } + else if(statement instanceof IfStmt)//Wenn if + { + IfStmt i = (IfStmt)statement; + addOffsetsToExpression(localAssumption,i.expr,NameVariable,isMemberVariable); + addOffsetsToStatement(localAssumption,i.else_block,NameVariable,isMemberVariable); + addOffsetsToStatement(localAssumption,i.then_block,NameVariable,isMemberVariable); + } + else if(statement instanceof Return)//Wenn Return + { + Return r = (Return)statement; + addOffsetsToExpression(localAssumption,r.retexpr,NameVariable,isMemberVariable); + } + else if(statement instanceof WhileStmt)//Wenn While + { + WhileStmt w = (WhileStmt)statement; + addOffsetsToExpression(localAssumption,w.expr,NameVariable,isMemberVariable); + addOffsetsToStatement(localAssumption,w.loop_block,NameVariable,isMemberVariable); + } + else if(statement instanceof LocalVarDecl)//Wenn Lokale-Variable-Deklaration + { + isMemberVariable=true;//hoth 02.05.06 + if(isMemberVariable)//Wenn Objektvariable + { + LocalVarDecl l = (LocalVarDecl)statement; + if(l.get_Name().equals(NameVariable)) + { + if(isFirstLocalVarDecl==false) + {return false;}//Wenn jetzt lokale Variable kommt, dann springe raus + else + {isFirstLocalVarDecl=false;} + } + } + } + return true;*/ + } + // ino.end + + // ino.method.addOffsetsToExpression.23137.defdescription type=javadoc + /** + * Hilfs-Methode f�r die Offset-Zuweisung + * durchsucht eine Expression rekursiv + *
Author: Thomas Hornberger 07.04.2006 + *
Authos: Arne Lüdtke 20.01.2007, Auf Polymorphie umgebaut. + * @return + */ + // ino.end + // ino.method.addOffsetsToExpression.23137.definition + public static void addOffsetsToExpression(CTypeAssumption localAssumption,Expr expression, String NameVariable,boolean isMemberVariable) + // ino.end + // ino.method.addOffsetsToExpression.23137.body + { + expression.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + // ino.end + + // ino.method.getSimpleName.23140.defdescription type=javadoc + /** + * HOTI + * Liefert bei Klassen die fullyQualified angegeben wurden + * nur den schlussendlichen Bezeichner + * p.ex. java.util.Vector => Vector + * @return + */ + // ino.end + // ino.method.getSimpleName.23140.definition + public String getSimpleName() + // ino.end + // ino.method.getSimpleName.23140.body + { + return UsedId.createFromQualifiedName(getName(),-1).getSimpleName(); + } + // ino.end + + public String getTypeInformation(Vector methodList, Vector fieldList){ + String ret = this.name+": "; + for(Expr field : fieldList){ + ret+=field.getTypeInformation()+"\n"; + } + for(Method m : methodList){ + ret+=m.getTypeInformation()+"\n"; + } + return ret; + } + + + /** + * Generiert den JavaCode dieser Klasse im Falle für das übergebene resultSet. + * Dem ResultSet entsprechend werden in diesem Java-Code die TypePlaceholder durch die in ResultSet stehenden Typen ersetzt. + * @return Java-Sourcefile + */ + public String printJavaCode(CTypeReconstructionResult reconstructionResult){ + JavaCodeResult ret = new JavaCodeResult("class "); + + + + + //Generiere JavaCode der extends-Typen: + /* + String containedTypesJavaCode = ""; + for(Type containedType : containedTypes){ + containedTypesJavaCode += containedType.printJavaCode(resultSet)+ ", "; + } + if(containedTypesJavaCode.length()>1)containedTypesJavaCode = containedTypesJavaCode.substring(0, containedTypesJavaCode.length() -2); + */ + + JavaCodeResult classBodyCode = new JavaCodeResult(); + if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" "); + + if(superclassid == null || superclassid.get_Name().size()<1){ + int superclassidOffset = superclassid == null ? 0 : superclassid.getOffset(); + superclassid = new UsedId("Object", superclassidOffset); + } + + classBodyCode.attach(this.name + " extends ").attach(superclassid.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach("\n"); + JavaCodeResult bodyString = this.body.printJavaCode(reconstructionResult.getUnifiedConstraints()).attach("\n"); + classBodyCode.attach(bodyString); + + //Zuerst die generischen Parameter für diese Klasse berechnen: + this.createGenericTypeVars(classBodyCode.getUnresolvedTPH()); + + if(this.genericClassParameters != null && this.genericClassParameters.size()>0){ + ret.attach("<"); + + Iterator it = this.genericClassParameters.iterator(); + while(it.hasNext()){ + GenericTypeVar tph = it.next(); + ret.attach(tph.printJavaCode(reconstructionResult.getUnifiedConstraints())); + if(it.hasNext())ret.attach(", "); + } + ret.attach(">"); + } + + String stringReturn = ret.attach(classBodyCode).toString(); + + return stringReturn; + } + + /** + * Errechnet die Generischen Parameter der Klasse für diese Klasse. + * Die berechneten Variablen werden anschließend in die this.genericTypeVars eingesetzt. Dabei werden alte genericTypeVars überschrieben. + * @param tphs : Alle übriggebliebenen TypePLaceholder + */ + public void createGenericTypeVars(Vector tphs){ + this.genericClassParameters = new Vector(); + for(TypePlaceholder tph : tphs){ + GenericTypeVar toAdd = new GenericTypeVar(tph); + if(!this.genericClassParameters.contains(toAdd))this.genericClassParameters.add(toAdd); + } + } + + /** + * Errechnet die Generischen Parameter der Klasse für diese Klasse. + * Die berechneten Variablen werden anschließend in die this.genericTypeVars eingesetzt. Dabei werden alte genericTypeVars überschrieben. + * @param reconstructionResult + */ + public void createGenericTypeVars(CTypeReconstructionResult reconstructionResult){ + this.genericClassParameters = new Vector(); + for(Pair pair : reconstructionResult.getUnifiedConstraints()){ + if(pair.TA2 instanceof TypePlaceholder && pair.TA1 instanceof TypePlaceholder){// if(pair.OperatorSmallerExtends() || pair.OperatorSmaller()){ + Type ta1=reconstructionResult.getUnifiedConstraints().getTypeEqualTo(pair.TA1); + Type ta2=reconstructionResult.getUnifiedConstraints().getTypeEqualTo(pair.TA2); + this.genericClassParameters.add(new GenericTypeVar(new Pair(ta1,ta2))); + } + /* + // Auf SuperWildcardTypes überprüfen: + ArrayList wildcardTypes = pair.TA2.getSuperWildcardTypes(); + wildcardTypes.addAll(pair.TA1.getSuperWildcardTypes()); + for(SuperWildcardType wildcardType : wildcardTypes){ + this.genericClassParameters.add(new GenericTypeVar(new Pair(TypePlaceholder.fresh(), wildcardType.getContainedType()))); + } + */ + } + + for(Pair pair : reconstructionResult.getConstraints()){ + if( ! reconstructionResult.getUnifiedConstraints().contains(pair.TA1)){ + this.genericClassParameters.add(new GenericTypeVar(pair.TA1)); + } + if( ! reconstructionResult.getUnifiedConstraints().contains(pair.TA2)){ + this.genericClassParameters.add(new GenericTypeVar(pair.TA2)); + } + } + } + + /** + * Erstellt einen RefType, welcher auf diese Klasse verweist + * @return + */ + public RefType getType() { + return new RefType(this.getName(), this.get_ParaList(), 0); + } + + + /** + * Ermittelt die Sichtbaren Felder und Methoden der Klasse. + * (Momentan sind im Projekt alle Felder und Methoden "package private", da der Parser keine Access-Modifier einlesen kann. + * @return + */ + public TypeAssumptions getPublicFieldAssumptions() { + TypeAssumptions ret = this.getTypeAssumptions(); + return ret; + } + +} +// ino.end diff --git a/src/mycompiler/myclass/ClassBody.java b/src/mycompiler/myclass/ClassBody.java new file mode 100755 index 000000000..223b6bca4 --- /dev/null +++ b/src/mycompiler/myclass/ClassBody.java @@ -0,0 +1,803 @@ +// ino.module.ClassBody.8554.package +package mycompiler.myclass; +// ino.end +// ino.module.ClassBody.8554.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCClassBodyException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCMethodException; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + + + + +// ino.class.ClassBody.23143.declaration +public class ClassBody +// ino.end +// ino.class.ClassBody.23143.body +{ + // ino.attribute.fielddecl.23146.declaration + private Vector fielddecl = new Vector(); + // ino.end + // ino.attribute.hash.23149.declaration + private Hashtable hash = new Hashtable(); // otth: Speichert folgende Paare: --> + // ino.end + // ino.attribute.paraclasshash.23152.declaration + private Hashtable paraclasshash = new Hashtable(); + // ino.end + // ino.attribute.kill.23155.declaration + public Hashtable kill = new Hashtable(); + // ino.end + + // ino.attribute.parserlog.23158.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.sc_init_hashtable.23161.definition + public void sc_init_hashtable( Vector KlassenVektor, String strSuperKlassenName, String classname, boolean ext ) + throws SCClassBodyException + // ino.end + // ino.method.sc_init_hashtable.23161.body + { + // Methoden und Vardeclarationen werden in die Hashtabelle eingefuegt + // KlassenVektor: Vektor mit allen Klassen im Sourcefile + // strSuperKlassenName: Name der Superklasse, Klasse ohne Vererbung <--> strSuperKlassenName = null + + SCClassBodyException ex = null; + + // otth: Vektor mit den Felddeklarationen durchgehen und Hashtabelle f�r Felddeklarationen aufbauen + for( Enumeration el = fielddecl.elements(); el.hasMoreElements(); ) + { + FieldDecl field = el.nextElement(); // Felddeklaration, also Instanzvariable oder Mehtode + Vector v = field.get_Name(); // verschiedene DeclId's, f�r int a, b, c z.B 3 + DeclId hilf; + Method init; + String name; // enth�lt den Namen des Identifiers, also ein Instanzvariablenname oder ein Methodennamen + + // otth: bei Funktionen: Parameterliste erstellen! + if( field instanceof Method ) + { + init=(Method) field; + init.sc_init_parameterlist(ext); + } + + // otth: Vektor einer Felddeklaration mit ver. DeclIds durchgehen - + // otth: hier wird z.B. folgende Liste durchlaufen: a, b, c bei int a, b, c; + for ( Enumeration el1 = v.elements(); el1.hasMoreElements(); ) + { + hilf = (DeclId)el1.nextElement(); + name = hilf.get_Name(); + + // otth: pr�fen, ob Identifier bereits vorhanden ??? + if( hash.containsKey( name ) ) + { + parserlog.error("SEMANTIK-CHECK-Fehler: '" + name + "' ist bereits definiert!\n"); + //FIXME Throw Exception or Error instead of simple exit the program + System.exit(1); + + /* otth: Wenn dieser Code vorhanden ist, wird ... int a; int a; akkzeptiert! + String typedervar; + typedervar = (String)hash.get(name); + if ( !typedervar.equals(field.get_Type()) ) + // otth: abstrakte Methode, z.B. von InstVarDecl gibt den Typ zur�ck + { + SCExcept neu=new SCExcept(); + neu.set_error("Es kann nicht noch eine Variable mit dem Namen "+name+" angelegt werden."); + neu.set_statement("ClassBody"); + if(ex==null) + { + System.out.println("neue classbodyexception anlegen"); + ex=new SCClassBodyException(); + } + ex.addException(neu); + if(ext) + System.out.println("Exception wurde angelegt!"); + continue; + } + */ + } + + // otth: Aufnahme in die Hash-Tabelle! + // otth: Typen pr�fen, field.get_Type() z.B. = int oder void, bei null --> Konstruktor + if( field.getTypeName() == null ) + hash.put(name,"__CONSTRUCTOR__"); + else + hash.put(name, field.getTypeName()); // Name & Typ, z.B. "a" --> "int" + } // Ende: Schleife �ber alle Feldvariablendeklarationen + } + + // otth: Klassenname in Hash-Tabelle einfuegen + hash.put("###_classname", classname); + + // otth: Ist Klasse eine Subklasse? + if( strSuperKlassenName != null ) // 'strSuperKlassenName' = �bergebener Parameter von 'Class' + { + Class tempKlasse; + String strTempKlassenName; + hash.put( "###_class_is_extended", "yes" ); + + // otth: Basisklasse wird im Vektor aller Klassen 'KlassenVektor` gesucht! + + // �nderung von otth: Falls Klasse nicht gefunden wurde --> Superklasse ist undefiniert --> Fehler! + boolean bSuperKlasseGefunden = false; + + for ( Enumeration el2 = KlassenVektor.elements(); el2.hasMoreElements(); ) + { + tempKlasse = el2.nextElement(); + strTempKlassenName = tempKlasse.getName(); + if( strTempKlassenName.equals( strSuperKlassenName ) ) + { + // otth: Die Hashtabelle wird um die Attribute / Methoden der Superklasse(n) ergaenzt + // otth: Funktion 'ClassBody.sc_init_hashtable_for_extended_classes' wird (indirekt) aufgerufen + bSuperKlasseGefunden = true; + tempKlasse.sc_check_for_extended_classes( KlassenVektor, hash, ext ); + } + } + + + // otth: Superklasse mu� existieren + if ( !bSuperKlasseGefunden ) + { + parserlog.error("SEMANTIK-CHECK-Fehler [otth]: Symbol '" + strSuperKlassenName + "' kann nicht aufgel�st werden (Location: class " + classname + ").\n" ); + System.exit( 1 ); + } + + } + + // Fehler erkennen und werfen!!! + if( ex != null ) + { + parserlog.error("SEMANTIK-CHECK-Fehler: Fehler beim Aufbau der Hash-Tabelle!"); + throw ex; + } + + // Ersetzen von vordefinierten Parametern bei der Vererbung + if( this.kill.size() > 0 ) + { + for(Enumeration e1=this.kill.elements(),e2=this.kill.keys();e1.hasMoreElements();){ + Type value = (Type)e1.nextElement(), key=(Type)e2.nextElement(); + for(Enumeration e3=hash.elements(),e4=hash.keys();e3.hasMoreElements();){ + String v = (String)e3.nextElement(),k=(String)e4.nextElement(); + if(v.equals(key.getName())){ + parserlog.debug(v+ " wird durch "+value.getName()+" ersetzt"); + hash.put(k,value.getName()); + } + } + } + } + + parserlog.debug( "SC --> '" + classname + "' --> Hashtabelle (ClassBody.hash):\n" + hash); + } + // ino.end + + // ino.method.sc_init_hashtable_for_extended_classes.23164.definition + public void sc_init_hashtable_for_extended_classes( Vector classlist, String strSuperKlassenName, Hashtable childhash,Vector paralist, Hashtable parahash,Hashtable kill, boolean ext ) + // ino.end + // ino.method.sc_init_hashtable_for_extended_classes.23164.body + { + // Hier werden in die �bergegebene Hashtable die Attribute und Methoden ergaenzt, die vererbt werden. + // otth: Struktur �hnlich wie in 'sc_init_hashtable' + + for( Enumeration el = fielddecl.elements(); el.hasMoreElements(); ) + { + FieldDecl field = el.nextElement(); + Vector v = field.get_Name(); + DeclId hilf; + String name; + + // Hashtabelle erg�nzen + for ( Enumeration el1 = v.elements(); el1.hasMoreElements(); ) + { + hilf=(DeclId)el1.nextElement(); + name=hilf.get_Name(); + if(field.getTypeName()==null) + childhash.put(name,"__Constructor__"); //Name & Typ + else + { + //string_rec("paralist: ", paralist);System.out.println(); + childhash.put(name, field.getTypeName()); + } + } + } + + // Sollte die Basis-Klasse zus�tzlich erben muss folgendes getan werden: + if( strSuperKlassenName != null ) + { + Class hilfe; + String hilfsstr; + for ( Enumeration el2=classlist.elements(); el2.hasMoreElements(); ) + { + hilfe=el2.nextElement(); + hilfsstr=hilfe.getName(); + if( hilfsstr.equals( strSuperKlassenName ) ) + hilfe.sc_check_for_extended_classes(classlist,childhash,ext); + } + } + } + // ino.end + + // ino.method.sc_check.23167.definition + public void sc_check(Vector classlist, boolean ext) + throws SCClassBodyException + // ino.end + // ino.method.sc_check.23167.body + { + // In den Methoden der Klasse wird der Semantik-Check aufgerufen + + SCClassBodyException except = null; + SCExcept hilfex; + Vector v; + + // otth: Schleife �ber alle Felddeklarationen - wenn Methode gefunden wird --> Semantik-Check dort aufrufen!!! + for( Enumeration el = fielddecl.elements(); el.hasMoreElements(); ) + { + Object tempObjekt = el.nextElement();; + Method tempMethod = null; + if( tempObjekt instanceof Method ) + { + tempMethod = (Method)tempObjekt; + try + { + // Semantikcheck f�r die Methode aufrufen! + tempMethod.call_sc_check( classlist, this.hash, ext, this.paraclasshash ); + } + catch (SCMethodException ex) + { + if(except==null) + except=new SCClassBodyException(); + v=ex.get_exlist(); + for (Enumeration el2=v.elements(); el2.hasMoreElements();) + { + hilfex=el2.nextElement(); + hilfex.set_function( tempMethod.get_Method_Name() ); + except.addException(hilfex); + } + } + } + } + + // Fehler werfen + if( except != null ) + throw except; + } + // ino.end + + + // ino.method.init_parahashtable.23170.defdescription type=line + // + // ***NEU***************************************************************************** + // + // ino.end + // ino.method.init_parahashtable.23170.definition + public Hashtable init_parahashtable(Vector paralist,boolean ext) + // ino.end + // ino.method.init_parahashtable.23170.body + { + //hier wird die Hashtabelle erzeugt, die s�mtliche zuordnungen der parametrisierbaren Variablen enth�lt. + Hashtable parahash = new Hashtable(); + FieldDecl decl; + + for(Enumeration e = fielddecl.elements(); e.hasMoreElements();) + { + //Auslesen aller Fielddecl's + decl = e.nextElement(); + + for(Enumeration el = decl.get_Name().elements(); el.hasMoreElements();) + { //Auslesen der Vectoren der Fielddecl's + String key, value; + key = ((DeclId)el.nextElement()).get_Name(); + value = decl.getTypeName(); + if ( value == null ) value = "###CONSTRUCTOR###"; // otth: eingef�gt, sonst NULLPOINTEREXCEPTION + parahash.put(key, value); + } + } + + // entfernt ung�ltige Eintr�ge in der ParaHashtabelle + for(Enumeration e = parahash.elements(), ee=parahash.keys(); e.hasMoreElements();) + { + String para = (String)e.nextElement(); + String key = (String)ee.nextElement(); + Enumeration e1 = paralist.elements(); + do + { + if(e1.hasMoreElements()) + { + String typ = ((Type)e1.nextElement()).getName(); + if(para.equals(typ)) + { + break; + } + } + if(!e1.hasMoreElements()) + { + parahash.remove(key); + } + } + while(e1.hasMoreElements()); + } + return parahash; + } + // ino.end + +// ino.method.complete_parahashtable.23173.defdescription type=block +/* public void set_paratype(Vector classlist, UsedId superclass, Vector +pl,Hashtable ph,boolean ext){ DeclId decl; + FieldDecl field; + System.out.println("++ ParaCheck: Fielddecl's: "+fielddecl.toString()); + + for(Enumeration e=fielddecl.elements();e.hasMoreElements();){ + field = (FieldDecl)e.nextElement(); + for(Enumeration e1=field.get_Name().elements();e1.hasMoreElements();){ + decl=(DeclId)e1.nextElement(); + + if(superclass != null){ + System.out.println("superclass.get_ParaList: " ++superclass.get_ParaList().toString()); + for(Enumeration e2 = +superclass.get_ParaList().elements();e2.hasMoreElements();){ +System.out.println("paralist.elements:: "+((Type)e2.nextElement()).get_Type()); + } + } + if(decl.get_Paratyp()!=null){ + System.out.println("++ ParaCheck: Name: +"+decl.get_Name()+"\tParatyp: "+decl.get_Paratyp()); } + else System.out.println("++ ParaCheck: Name: "+decl.get_Name()+"\tkein +Paratyp gesetzt."); } + } + } +*/ +// ino.end + + // ino.method.complete_parahashtable.23173.definition + public Hashtable complete_parahashtable(Vector classlist,UsedId superclassid,Hashtable childhash,boolean ext) + throws SCClassBodyException + // ino.end + // ino.method.complete_parahashtable.23173.body + { + // vervolltaendigt die ParaHashtabelle bei Vererbung + Hashtable parahash = new Hashtable(); + String superhilf,superclass = (String)superclassid.get_Name_1Element(); + Class supercl; + if(ext) + parserlog.debug("++ Para_check hat Vererbung gefunden!"); + + for(Enumeration e=classlist.elements();e.hasMoreElements();) + { + supercl = e.nextElement(); + superhilf = supercl.getName(); + + if(superhilf.equals(superclass)) + { + parahash = (Hashtable) supercl.get_ParaHash().clone(); + + // otth: Pruefung: Ist ein Parameter, der keine TypePlaceholder ist + // (also RefType mit [=Typkonstruktor] oder ohne Parameter eine bereits definierte Klasse und + // stimmt die Anzahl der Parameter eines Typkonstruktors mit der zugeh�rigen Klassendefinition �berein? + + // folgende Funktion bricht ab, falls Parameter fehlerhaft + istParameterOK( superclassid.get_ParaList(), classlist ); + // end otth; + + + if(ext){ + parserlog.debug(string_rec("++ PC\tParaHash der Basisklasse: ", parahash)); + parserlog.debug(string_rec("++ PC\tParaList der Basisklasse: ", supercl.get_ParaList())); + parserlog.debug(string_rec("++ PC\tParaList der cb - klasse: ", superclassid.get_ParaList())); + parserlog.debug(string_rec("++ PC\tchildhash : ", childhash)); + } + + // falls bei Vererbung ein Parameter bereits festgelegt ist, so wird er hier aus dem ParaList-Vector entfernt + Vector rm = new Vector(); /* container f�r zu entfendende Typen */ + + for( Enumeration e2=classlist.elements(); e2.hasMoreElements(); ) + { + Class c = e2.nextElement(); + for(Enumeration e1=superclassid.get_ParaList().elements();e1.hasMoreElements();) + { + Type t=(Type)e1.nextElement(); + + if(c.getName().equals(t.getName())) + { + int i = superclassid.get_ParaList().indexOf(t); + + // refe ... + if ( t instanceof RefType ) + { + if( ((RefType)t).get_ParaList() != null) + { + if( ((RefType)t).get_ParaList().size()>0) + { + /* auf existenz der Parameter pr�fen */ + for(Enumeration e11 = ((RefType)t).get_ParaList().elements();e11.hasMoreElements();) + { + Type ty = (Type)e11.nextElement(); + try + { + is_declared(ty,classlist); + } + catch(SCClassBodyException ex) + { + // otth: auskommentiert, den Parameter muessen nicht unbedingt bereits definierte Klassen sein + // throw ex; + } + } + } + } + } + + rm.add(t); + Type removetype = (Type)supercl.get_ParaList().elementAt(i); + + kill.put(removetype,t); + + for(Enumeration e3=parahash.keys(),e4=parahash.elements();e3.hasMoreElements();) + { + String key = (String)e3.nextElement(); + String ele = (String)e4.nextElement(); + if(ele.equals(removetype.getName())) + { + parahash.remove(key); + } + } + } + } + } + if(rm.size()>0) + { + for(Enumeration e4 = rm.elements();e4.hasMoreElements();) + { + Type t=(Type)e4.nextElement(); + superclassid.get_ParaList().remove(t); + parserlog.debug(string_rec("Typ \""+t.getName()+"\" aus ParaList entfernt! ", superclassid.get_ParaList())); + } + } + } + } + + for(Enumeration e=childhash.keys();e.hasMoreElements();){ + String key = (String)e.nextElement(); + parahash.put(key,(String)childhash.get(key)); + } + return parahash; + } + // ino.end + + + + // ino.method.codegen.23176.definition + public void codegen(ClassFile classfile, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.23176.body + { + for(int i=0 ; i < fielddecl.size() ; i++) + { + if(this.fielddecl.elementAt(i) instanceof InstVarDecl) + { + ((InstVarDecl)this.fielddecl.elementAt(i)).codegen(classfile, paralist); + } + else + { + this.fielddecl.elementAt(i).codegen(classfile, paralist); + } + } + } + // ino.end + + + + // ino.method.get_hash.23179.definition + public Hashtable get_hash() + // ino.end + // ino.method.get_hash.23179.body + { + return hash; + } + // ino.end + + // ino.method.get_FieldDeclVector.23182.definition + public Vector get_FieldDeclVector() + // ino.end + // ino.method.get_FieldDeclVector.23182.body + { + return fielddecl; + } + // ino.end + + // ino.method.set_FieldDecl.23185.definition + public void set_FieldDecl(FieldDecl i) + // ino.end + // ino.method.set_FieldDecl.23185.body + { + fielddecl.addElement(i); + } + // ino.end + +// ino.method.is_declared.23188.defdescription type=line +// +// ******************************************************************************************** +// +// ino.end + +// ino.method.is_declared.23188.definition +public boolean is_declared(Type t, Vector classlist) +throws SCClassBodyException +// ino.end +// ino.method.is_declared.23188.body +{ + boolean flag=false; + for(Enumeration e = classlist.elements();e.hasMoreElements();) + { + flag = false; + Class c = e.nextElement(); + +// System.out.println("is_init: vergleiche "+t.get_Type_()+" mit "+c.getName()); + if(c.getName().equals(t.getName())){ +// System.out.println("Klasse "+t.get_Type()+"im Vector classlist gefunden."); + flag = true; + break; + } + } + + if( t instanceof RefType && ((RefType)t).get_ParaList()!=null) + { + if( ((RefType)t).get_ParaList().size() > 0 ) + { + for(Enumeration e1 = ((RefType)t).get_ParaList().elements(); e1.hasMoreElements(); ) + { + try + { + is_declared((Type)e1.nextElement(),classlist); + } + catch(SCClassBodyException ex) + { + throw ex; + } + } + } + } + + if(flag) + return true; + else + { + SCClassBodyException ex = new SCClassBodyException(); + SCExcept e = new SCExcept(); + e.set_error("unbekannte Klasse "+t.getName()+"."); + e.set_function("complete_parahashtable() --> is_declared()"); + e.set_statement(t.getName()); + ex.addException(e); + throw ex; + } +} +// ino.end + +// ino.method.string_rec.23191.definition +static String string_rec(Hashtable ht) +// ino.end +// ino.method.string_rec.23191.body +{ + String record=("["); + for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){ + String s = (String)k.nextElement(); + Object o = e.nextElement(); + + record=record.concat(" "+s); + + if(o instanceof Type){ + record=record.concat(" = "+((Type)o).getName()); + } + + else if(o instanceof Hashtable){ + record=record.concat("= "); + record=record.concat(string_rec((Hashtable)o)); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else if(o instanceof String){ + record=record.concat(" = "+o); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else { + record=("[FEHLER: string_rec: unbekannter Typ!!!!!!"); + } + } + record=record.concat("]"); + return(record); + } +// ino.end + + // ino.method.string_rec.23194.defdescription type=block + /*static void string_rec(Vector v){ + String record=("{"); + for(Enumeration e=v.elements();e.hasMoreElements();){ + Type t = (Type)e.nextElement(); + record=record.concat(" "+t.getName()); + + if(e.hasMoreElements()) + record=record.concat(","); + } + record=record.concat("}"); + parserlog.debug(record); + }*/ + // ino.end + // ino.method.string_rec.23194.definition + static String string_rec(String st, Hashtable ht) + // ino.end + // ino.method.string_rec.23194.body + { + String record=(st); + record=record.concat("["); + for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){ + String s = (String)k.nextElement(); + Object o = e.nextElement(); + + record=record.concat(" "+s); + + if(o instanceof Type){ + record=record.concat(" = "+((Type)o).getName()); + } + + else if(o instanceof Hashtable){ + record=record.concat("= "); + record=record.concat(string_rec((Hashtable)o)); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else if(o instanceof String){ + record=record.concat(" = "+o); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else { + record=("FEHLER: string_rec: unbekannter Typ!!!!!! " +o); + } + } + record=record.concat("]"); + return(record); + } + // ino.end + +// ino.method.string_rec.23197.definition +static String string_rec(String st,Vector v) +// ino.end +// ino.method.string_rec.23197.body +{ + String record=(st); + record=record.concat("{"); + for(Enumeration e=v.elements();e.hasMoreElements();){ + Type t = (Type)e.nextElement(); + record=record.concat(" "+t.getName()); + if(e.hasMoreElements()) + record=record.concat(", "); + } + record=record.concat("}"); + return(record); + } +// ino.end +// ino.method.istParameterOK.23200.defdescription type=line +// +// ******************************************************************************************** +// +// ino.end + +// ino.method.istParameterOK.23200.definition +public void istParameterOK( Vector Parameter, Vector KlassenVektor ) +// ino.end +// ino.method.istParameterOK.23200.body +{ + // otth: prueft rekursiv, ob Parameter im Klassenvektor vorkommt, falls RefType, oder ob TypePlaceholder nicht vorkommt + + for( int i = 0; i < Parameter.size(); i++) + { + Type TempParameter = (Type)(Parameter.elementAt(i)); + + // an dieser Stelle: Parametername + if ( TempParameter instanceof RefType ) + { + // t im Klassenvektor suchen --> muss deklariert sein + boolean bGefunden = false; + for( int k = 0; k < KlassenVektor.size(); k++) + { + if( KlassenVektor.elementAt(k).getName().equals(((RefType)TempParameter).getTypeName()) ) + { + // Namen gleich --> Parameterliste rekursiv pruefen + if( ((RefType)TempParameter).get_ParaList() != null ) + { + if( ((RefType)TempParameter).get_ParaList().size() != KlassenVektor.elementAt(k).get_ParaList().size() ) + { + parserlog.error( "SEMANTIK-CHECK-FEHLER: Parameteranzahl von\n" + TempParameter.getName() + " stimmt mit der Klassendefinition\n" + KlassenVektor.elementAt(k).getName() + " nicht �berein." ); + System.exit( 1 ); + } + else + { + istParameterOK( ((RefType)TempParameter).get_ParaList(), KlassenVektor ); + bGefunden = true; + break; + } + } + else + { + // OK ... + bGefunden = true; + break; + } + } + } + // Parameter wurde nicht gefunden: + if( !bGefunden ) + { + parserlog.error( "SEMANTIK-CHECK-FEHLER: Parameter " + TempParameter.getName() + " ist noch nicht als Klasse definiert." ); + System.exit( 1 ); + } + } + else + { + // Tylose Variablen d�rfen nicht deklariert sein + for( int k = 0; k < KlassenVektor.size(); k++) + { + if( KlassenVektor.elementAt(k).getName().equals(TempParameter.getName()) ) + { + parserlog.error( "SEMANTIK-CHECK-FEHLER: Parameter " + TempParameter.getName() + " ist bereits als Klasse definiert." ); + System.exit( 1 ); + } + } + // nicht gefunden + } + } // end otth; end if: t = RefType +} +// ino.end + + + // ino.method.toString.23203.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.23203.definition + public String toString() + // ino.end + // ino.method.toString.23203.body + { + return fielddecl.toString(); + } + // ino.end + + private Vector fieldInitialisations = new Vector(); + + /** + * @author Andreas Stadelmeier, a10023 + * Fügt der Klasse eine Feldinitialisation hinzu. + * Eine Feldinitialisation steht für eine Felddeklaration mit gleichzeitiger Wertzuweisung + * Beispiel: 'public Feld FeldVar = FeldWert;' + * @param feld + */ + public void addFieldInitialization(FieldInitialization feld) { + this.fieldInitialisations.add(feld); + } + public Vector getFieldInitializations(){ + return this.fieldInitialisations; + } + + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult("{\n"); + for(FieldDecl field : this.fielddecl)ret.attach( field.printJavaCode(resultSet) ).attach( "\n" ); + return ret.attach("}\n"); + + } + +} +// ino.end diff --git a/src/mycompiler/myclass/ClassHelper.java b/src/mycompiler/myclass/ClassHelper.java new file mode 100755 index 000000000..a4d97f542 --- /dev/null +++ b/src/mycompiler/myclass/ClassHelper.java @@ -0,0 +1,58 @@ +// ino.module.ClassHelper.8555.package +package mycompiler.myclass; +// ino.end + +// ino.module.ClassHelper.8555.import +import java.util.Vector; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +// ino.end + +// ino.class.ClassHelper.23206.declaration +public class ClassHelper +// ino.end +// ino.class.ClassHelper.23206.body +{ + // ino.method.findGenericType.23209.defdescription type=javadoc + /** + * HOTI + * Diese Methode sucht in der Klassendefinition nach einen GTV, die + * so heißt wie die im RefType definierte Variable. Wenn sie diese gefunden + * hat, wird sie zurückgeben. Wenn dies nicht der Fall war, schaut sie, falls + * angegeben in den Methodenparametern nach. Findet sie dort auch nichts, liefert + * die Methode null. + * @param type + * @return + */ + // ino.end + // ino.method.findGenericType.23209.definition + public static GenericTypeVar findGenericType(Type type, Vector paralist, Vector methodParaList) + // ino.end + // ino.method.findGenericType.23209.body + { + if(!(type instanceof RefType)){ + return null; + } + for(int i=0;i"); + this.set_DeclId(decl); + // ########################################################### + } + // ino.end + + + + // ino.method.get_codegen_Param_Type.23274.definition + public String get_codegen_Param_Type(Vector paralist) + // ino.end + // ino.method.get_codegen_Param_Type.23274.body + { + String ret = new String(); + if(this.getParameterList() == null) + { + ret += "()"; + } + else + { + ret += this.getParameterList().get_codegen_ParameterList(paralist); + } + ret += "V"; + return ret; + } + // ino.end + + + + // ino.method.codegen.23277.definition + public void codegen(ClassFile classfile, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.23277.body + { + classfile.set_constructor_founded(true); + classfile.add_method("", this.get_codegen_Param_Type(paralist), this.getParameterList(), null, get_Block(), declid.firstElement().get_access_flags(), paralist, false); + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/myclass/DeclId.java b/src/mycompiler/myclass/DeclId.java new file mode 100755 index 000000000..96ef68ad3 --- /dev/null +++ b/src/mycompiler/myclass/DeclId.java @@ -0,0 +1,310 @@ +// ino.module.DeclId.8558.package +package mycompiler.myclass; +// ino.end +// ino.module.DeclId.8558.import +import java.util.Vector; +import mycompiler.mybytecode.Attribute; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.mybytecode.SignatureInfo; +import mycompiler.MyCompiler; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mymodifier.Final; +import mycompiler.mymodifier.Modifiers; +import mycompiler.mystatement.Assign; +import mycompiler.mystatement.Expr; +import mycompiler.mystatement.ExprStmt; +import mycompiler.mystatement.InstVar; +import mycompiler.mystatement.LocalOrFieldVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import org.apache.log4j.Logger; +// ino.end + + + + +// ino.class.DeclId.23280.declaration +public class DeclId +// ino.end +// ino.class.DeclId.23280.body +{ + // ino.attribute.modifiers.23283.declaration + public Modifiers modifiers; + // ino.end + // ino.attribute.name.23286.declaration + public String name; + // ino.end + // ino.attribute.wert.23289.declaration + private ExprStmt wert; + // ino.end + // ino.attribute.paratyp.23292.declaration + public Vector paratyp = null; // hier wird die Parameterzuordnung gespeichert ... 'test t = new test();' + // ino.end + // ino.attribute.m_LineNumber.23295.declaration + private int m_LineNumber = MyCompiler.NO_LINENUMBER; + // ino.end + private int m_Offset = -1; //hinzugef�gt hoth: 07.04.2006 + // ino.attribute.codegenlog.23298.decldescription type=line + // Logger fuer Code-Gen + // ino.end + // ino.attribute.codegenlog.23298.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + + // ino.method.DeclId.23301.definition + public DeclId() + // ino.end + // ino.method.DeclId.23301.body + { + + } + // ino.end + + + + // ino.method.DeclId.23304.definition + public DeclId(String name) + // ino.end + // ino.method.DeclId.23304.body + { + this.name = name; + } + // ino.end + + // ino.method.set_Paratyp.23307.definition + public void set_Paratyp(Vector p) + // ino.end + // ino.method.set_Paratyp.23307.body + { + this.paratyp = p; + } + // ino.end + + // ino.method.get_Paratyp.23310.definition + public Vector get_Paratyp() + // ino.end + // ino.method.get_Paratyp.23310.body + { + return this.paratyp; + } + // ino.end + + // ino.method.set_Name.23313.definition + public void set_Name(String name) + // ino.end + // ino.method.set_Name.23313.body + { + this.name = name; + } + // ino.end + + // ino.method.set_Wert.23316.definition + public void set_Wert(ExprStmt w) + // ino.end + // ino.method.set_Wert.23316.body + { + this.wert = w; + } + // ino.end + + // ino.method.get_Name.23319.definition + public String get_Name() + // ino.end + // ino.method.get_Name.23319.body + { + return name; + } + // ino.end + + // ino.method.get_Wert.23322.definition + public ExprStmt get_Wert() + // ino.end + // ino.method.get_Wert.23322.body + { + return wert; + } + // ino.end + + // ino.method.set_Modifiers.23325.definition + public void set_Modifiers(Modifiers mod) + // ino.end + // ino.method.set_Modifiers.23325.body + { + this.modifiers = mod; + } + // ino.end + + // ino.method.get_Modifiers.23328.definition + public Modifiers get_Modifiers() + // ino.end + // ino.method.get_Modifiers.23328.body + { + return this.modifiers; + } + // ino.end + + // ino.method.get_access_flags.23331.definition + public short get_access_flags() + // ino.end + // ino.method.get_access_flags.23331.body + { + if(modifiers != null) return modifiers.calculate_access_flags(); + else return (short)0; + } + // ino.end + + + + // ino.method.set_ListType.23334.definition + public void set_ListType(Type t) + // ino.end + // ino.method.set_ListType.23334.body + { + //System.out.println("In Klasse DeclID, Methode set_ListType passiert nix!"); + } + // ino.end + + + + // ino.method.codegen_InstVarDecl.23337.defdescription type=javadoc + /** + * Generieren einer Instanzvariable im Bytecode. + * Fuegt ggf. eine Signatur hinzu (Generics). + */ + // ino.end + // ino.method.codegen_InstVarDecl.23337.definition + public void codegen_InstVarDecl(ClassFile classfile, Type type, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen_InstVarDecl.23337.body + { + String codegen_type; + Attribute attr = null; + + // Spezialbehandlung fuer Konstanten .... + // Eine Unterscheidung im Parser wuerde Konflikte erzeugen + // da die Definition von Fields und Konstanten sehr aehnlich ist. + if (modifiers != null && modifiers.includesModifier(new Final())) { + Constant ct = new Constant(name, modifiers); + ct.setType(type); + if (!(wert instanceof Expr)) + throw new JVMCodeException("Das Generieren einer Konstante dieses Typs wird nicht unterstützt!"); + ct.setValue((Expr) wert); + + ct.codegen( classfile, paralist); + + return; + } + + + // Ueberpruefung auf Generics (Signaturen!) + if (SignatureInfo.needsSignature(type)) attr = new SignatureInfo(type, classfile); + + if (type instanceof RefType) + codegen_type = ((RefType)type).get_codegen_Type(null); + else + codegen_type = JVMCode.get_codegen_Type(type.getName(), paralist); + + + // Instanzvariable genenerieren + classfile.add_field(name, codegen_type, get_access_flags(), attr); + + // Wertzuweisung ggf. hinzufuegen + if(wert != null) { + if(wert instanceof Expr) { + classfile.add_field_ref(name, null, codegen_type); + Assign assign = new Assign(getOffset(),name.length()); + assign.set_Expr(new InstVar(name, type.getName(),getOffset()), (Expr)wert); + classfile.add_classblock_Element(assign); + } + else throw new JVMCodeException("Wertzuweisung der Instanzvariable kann nicht uebersetzt werden!"); + } + } + // ino.end + + + + // ino.method.codegen_LocalVarDecl.23340.definition + public void codegen_LocalVarDecl(ClassFile classfile, CodeAttribute code, Type type, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen_LocalVarDecl.23340.body + { + code.add_local(name, type); + if(wert != null) + { + if(wert instanceof Expr) + { + Assign assign = new Assign(getOffset(),name.length()); + assign.set_Expr(new LocalOrFieldVar(name,getOffset()), (Expr)wert); + assign.codegen(classfile, code, paralist); + } + else + { + throw new JVMCodeException("JVMCodeException: DeclId: void codegen(ClassFile classfile, Type type)"); + } + } + } + // ino.end + + // ino.method.getLineNumber.23343.definition + public int getLineNumber() + // ino.end + // ino.method.getLineNumber.23343.body + { + return m_LineNumber; + } + // ino.end + + // ino.method.setLineNumber.23346.definition + public void setLineNumber(int lineNumber) + // ino.end + // ino.method.setLineNumber.23346.body + { + m_LineNumber = lineNumber; + } + // ino.end + + // ino.method.getOffset.23349.defdescription type=line + // hinzugef�gt hoth: 07.04.2006 + // ino.end + // ino.method.getOffset.23349.definition + public int getOffset() + // ino.end + // ino.method.getOffset.23349.body + { + return m_Offset; + } + // ino.end + + // ino.method.setOffset.23352.defdescription type=line + // hinzugef�gt hoth: 07.04.2006 + // ino.end + // ino.method.setOffset.23352.definition + public void setOffset(int Offset) + // ino.end + // ino.method.setOffset.23352.body + { + m_Offset = Offset; + } + // ino.end + + // ino.method.toString.23355.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.23355.definition + public String toString() + // ino.end + // ino.method.toString.23355.body + { + return name.toString(); + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/myclass/ExceptionList.java b/src/mycompiler/myclass/ExceptionList.java new file mode 100755 index 000000000..a402ec4e4 --- /dev/null +++ b/src/mycompiler/myclass/ExceptionList.java @@ -0,0 +1,35 @@ +// ino.module.ExceptionList.8559.package +package mycompiler.myclass; +// ino.end +// ino.module.ExceptionList.8559.import +import java.util.Vector; +import mycompiler.mytype.RefType; +// ino.end + + + + +// ino.class.ExceptionList.23358.declaration +public class ExceptionList +// ino.end +// ino.class.ExceptionList.23358.body +{ + // ino.attribute.reftype.23361.declaration + private Vector reftype = new Vector(); + // ino.end + + + + // ino.method.set_addElem.23364.definition + public void set_addElem(RefType rety) + // ino.end + // ino.method.set_addElem.23364.body + { + reftype.addElement(rety); + } + // ino.end + + + +} +// ino.end diff --git a/src/mycompiler/myclass/FieldDecl.java b/src/mycompiler/myclass/FieldDecl.java new file mode 100755 index 000000000..fcc6ac80a --- /dev/null +++ b/src/mycompiler/myclass/FieldDecl.java @@ -0,0 +1,92 @@ +// ino.module.FieldDecl.8560.package +package mycompiler.myclass; +// ino.end +// ino.module.FieldDecl.8560.import +import java.util.Vector; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; +import mycompiler.mybytecode.ClassFile; +import mycompiler.myexception.JVMCodeException; +// ino.end +import mycompiler.mystatement.Expr; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +// ino.class.FieldDecl.23367.declaration +public abstract class FieldDecl +// ino.end +// ino.class.FieldDecl.23367.body +{ + // ino.attribute.declid.23370.declaration + protected Vector declid = new Vector(); // Vector, da 'int a, b, c, ...' auch eingeparst werden muss + + // ino.end + // ino.method.getTypeName.23373.declaration + public abstract String getTypeName(); + // ino.end + + + + // ino.method.codegen.23376.declaration + public abstract void codegen(ClassFile classfile, Vector paralist) + throws JVMCodeException; + // ino.end + + + + // ino.method.set_DeclId.23379.definition + public void set_DeclId(DeclId did) + // ino.end + // ino.method.set_DeclId.23379.body + { + this.declid.addElement(did); + } + // ino.end + + + + // ino.method.get_Name.23382.definition + public Vector get_Name() + // ino.end + // ino.method.get_Name.23382.body + { + return declid; + } + // ino.end + + // ino.method.getDeclIdVector.23385.definition + public Vector getDeclIdVector() + // ino.end + // ino.method.getDeclIdVector.23385.body + { + // otth: ganzer Vektor zur�ckgeben, um ihn zu kopieren (vgl. MyCompiler - Konstruktor in Methode umwandeln) + return declid; + } + // ino.end + + // ino.method.setDeclIdVector.23388.definition + public void setDeclIdVector( Vector vDeclId ) + // ino.end + // ino.method.setDeclIdVector.23388.body + { + // otth: kompletter Vektor setzen, um ihn zu kopieren (vgl. MyCompiler - Konstruktor in Methode umwandeln) + declid = vDeclId; + } + // ino.end + + + + + public abstract JavaCodeResult printJavaCode(ResultSet resultSet); + + /** + * Diese Methode generiert die Assumptions für dieses Feld der Klasse classmember + * @param classmember + * @return + */ + public abstract TypeAssumptions createTypeAssumptions(Class classmember); + +} +// ino.end diff --git a/src/mycompiler/myclass/FieldInitialization.java b/src/mycompiler/myclass/FieldInitialization.java new file mode 100644 index 000000000..55d0f60b6 --- /dev/null +++ b/src/mycompiler/myclass/FieldInitialization.java @@ -0,0 +1,87 @@ +package mycompiler.myclass; + +import java.util.Vector; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + +import mycompiler.mybytecode.ClassFile; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mystatement.Expr; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; + +public class FieldInitialization extends InstVarDecl{ + + + private Expr wert; + //private Type type; + + public void setWert(Expr initialExpression){ + this.wert = initialExpression; + } + public Expr getWert(){ + return this.wert; + } + + public String getName(){ + return this.get_Name().elementAt(0).name; + } + + + @Override + public String getTypeName() { + // TODO Auto-generated method stub + return null; + } + + + @Override + public void codegen(ClassFile classfile, Vector paralist) + throws JVMCodeException { + // TODO Auto-generated method stub + + } + /* + public Type getType() { + return this.type; + } + public void setType(Type type) { + this.type = type; + } + */ + + @Override + public String toString() + { + return super.toString() + "=" + getWert().toString(); + } + + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult(); + ret.attach(this.getType().printJavaCode(resultSet)).attach( " ").attach( this.getName()+" = ").attach(this.getWert().printJavaCode(resultSet) ).attach( ";"); + + return ret; + } + + @Override + public TypeAssumptions createTypeAssumptions(Class classmember) { + ////////////////////////////// + //Felder: + ////////////////////////////// + + TypeAssumptions assumptions = new TypeAssumptions(); + /* + * TODO: Der Feld-Assumption muss ein TPH als Typ hinzugefügt werden, falls er Typlos initialisiert wurde. Dies kann auch der Type-Algorithmus der Inst/FieldVar - Klasse machen. + * Wird das Feld mit einem Typ initialisiert so muss dieser auch in die Assumptions. + */ + if(this.getType() == null)this.setType(TypePlaceholder.fresh()); + assumptions.add(TypeAssumptions.createFieldVarAssumption(classmember.getName(), this.getName(), this.getType())); + classmember.get_ClassBody().addFieldInitialization(this); + return assumptions; + } + +} diff --git a/src/mycompiler/myclass/FormalParameter.java b/src/mycompiler/myclass/FormalParameter.java new file mode 100755 index 000000000..5d835149d --- /dev/null +++ b/src/mycompiler/myclass/FormalParameter.java @@ -0,0 +1,208 @@ +// ino.module.FormalParameter.8561.package +package mycompiler.myclass; +// ino.end + +// ino.module.FormalParameter.8561.import +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.Typable; + +// ino.class.FormalParameter.23391.declaration +public class FormalParameter implements ITypeReplacementListener, Typable +// ino.end +// ino.class.FormalParameter.23391.body +{ + // ino.attribute.type.23395.declaration + private Type type; + // ino.end + // ino.attribute.declid.23398.declaration + private DeclId declid; + // ino.end + // ino.attribute.inferencelog.23401.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + + + + // ino.method.setType.23404.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param t + */ + // ino.end + // ino.method.setType.23404.definition + public void setType(Type t) + // ino.end + // ino.method.setType.23404.body + { + if(this.type instanceof TypePlaceholder){ + ((TypePlaceholder)this.type).removeReplacementListener(this); + } + + if(t instanceof TypePlaceholder){ + ((TypePlaceholder)t).addReplacementListener(this); + } + this.type = t; + } + // ino.end + + + + // ino.method.set_DeclId.23407.definition + public void set_DeclId(DeclId did) + // ino.end + // ino.method.set_DeclId.23407.body + { + this.declid = did; + } + // ino.end + + + + // ino.method.get_Name.23410.definition + public String get_Name() + // ino.end + // ino.method.get_Name.23410.body + { + return declid.get_Name(); + } + // ino.end + + + + // ino.method.getType.23413.definition + public Type getType() + // ino.end + // ino.method.getType.23413.body + { + return type; + } + // ino.end + + + + // ino.method.getTypeName.23416.definition + public String getTypeName() + // ino.end + // ino.method.getTypeName.23416.body + { + return this.getType().getName(); + } + // ino.end + + + + // ino.method.codegen.23419.definition + public void codegen(ClassFile classfile, CodeAttribute code) + // ino.end + // ino.method.codegen.23419.body + { + code.add_local(declid.get_Name(), this.getType()); + } + // ino.end + + // ino.method.getOffset.23422.defdescription type=javadoc + /** + *
Author: Thomas Hornberger 09.04.2006 + * @return + */ + // ino.end + // ino.method.getOffset.23422.definition + public int getOffset() + // ino.end + // ino.method.getOffset.23422.body + { + return declid.getOffset(); + } + // ino.end + + // ino.method.getLineNumber.23425.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.getLineNumber.23425.definition + public int getLineNumber() + // ino.end + // ino.method.getLineNumber.23425.body + { + return declid.getLineNumber(); + } + // ino.end + + // ino.method.replaceType.23428.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param e + */ + // ino.end + // ino.method.replaceType.23428.definition + public void replaceType(CReplaceTypeEvent e) + // ino.end + // ino.method.replaceType.23428.body + { + inferencelog.debug("Ersetze Typ in FormalParameter \""+this.get_Name()+"\""); + if(type instanceof TypePlaceholder){ + ((TypePlaceholder)type).removeReplacementListener(this); + } + this.setType(e.getNewType()); + } + // ino.end + + // ino.method.getTypeLineNumber.23431.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.getTypeLineNumber.23431.definition + public int getTypeLineNumber() + // ino.end + // ino.method.getTypeLineNumber.23431.body + { + return this.getLineNumber(); + } + // ino.end + + + //private Type typeVariable; + + public void setTypeVariable(Type typ) { + this.setType(typ); + } + public Type getTypeVariable() { + return this.getType(); + } + + public String getTypeInformation() { + return getTypeVariable().toString() + " " +this.get_Name(); + } + + @Override + public String toString(){ + String ret = ""; + if(this.getTypeVariable() != null)ret += this.getTypeVariable().toString(); + if(this.get_Name() != null)ret += " "+get_Name(); + return ret; + } + + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult(); + if(this.getTypeVariable() != null)ret.attach(this.getTypeVariable().printJavaCode(resultSet)); + if(this.get_Name() != null)ret.attach(" "+get_Name()); + + return ret; + } +} +// ino.end diff --git a/src/mycompiler/myclass/ImportDeclarations.java b/src/mycompiler/myclass/ImportDeclarations.java new file mode 100755 index 000000000..88ac5e1f5 --- /dev/null +++ b/src/mycompiler/myclass/ImportDeclarations.java @@ -0,0 +1,29 @@ +// ino.module.ImportDeclarations.8562.package +package mycompiler.myclass; +// ino.end + +// ino.module.ImportDeclarations.8562.import +import java.util.Vector; +// ino.end + + +// ino.class.ImportDeclarations.23434.description type=javadoc +/** + * HOTI 4.5.06 + * Auch wenn es nicht so aussieht, hat diese Klasse einen Sinn :-) + * Der Parser kann keine Generischen Typen darstellen, damit trotzdem + * an amap Stellen die Typsicherheit gewährleistet ist, hier eine Kapselung... + */ +// ino.end +// ino.class.ImportDeclarations.23434.declaration +public class ImportDeclarations extends Vector +// ino.end +// ino.class.ImportDeclarations.23434.body +{ + + // ino.attribute.serialVersionUID.23438.declaration + private static final long serialVersionUID = -8958366609867768133L; + // ino.end + +} +// ino.end diff --git a/src/mycompiler/myclass/InstVarDecl.java b/src/mycompiler/myclass/InstVarDecl.java new file mode 100755 index 000000000..5f36b37fa --- /dev/null +++ b/src/mycompiler/myclass/InstVarDecl.java @@ -0,0 +1,208 @@ +// ino.module.InstVarDecl.8563.package +package mycompiler.myclass; +// ino.end +// ino.module.InstVarDecl.8563.import +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.MyCompiler; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import typinferenz.JavaCodeResult; + +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.InstVarDecl.23441.declaration +public class InstVarDecl extends FieldDecl implements ITypeReplacementListener +// ino.end +// ino.class.InstVarDecl.23441.body +{ + // ino.attribute.type.23446.declaration + protected Type type; + // ino.end + // ino.attribute.inferencelog.23449.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + // ino.attribute.parserlog.23452.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.setType.23455.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param t + */ + // ino.end + // ino.method.setType.23455.definition + public void setType(Type t) + // ino.end + // ino.method.setType.23455.body + { + if(this.type instanceof TypePlaceholder){ + ((TypePlaceholder)this.type).removeReplacementListener(this); + } + if(t instanceof TypePlaceholder){ + ((TypePlaceholder)t).addReplacementListener(this); + } + this.type = t; + parserlog.debug("T->InstVarDecl->set_Type->type.get_Type: " + t.getName()); + } + // ino.end + + // ino.method.getType.23458.definition + public Type getType() + // ino.end + // ino.method.getType.23458.body + { + return type; + } + // ino.end + + // ino.method.getTypeName.23461.definition + public String getTypeName() + // ino.end + // ino.method.getTypeName.23461.body + { + if(this.getType()==null)return "null"; + return this.getType().getName(); + } + // ino.end + + + + // ino.method.codegen.23464.definition + public void codegen(ClassFile classfile, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.23464.body + { + if(declid != null) + { + for(int i = 0; i < declid.size(); i++) + { + declid.elementAt(i).codegen_InstVarDecl(classfile, this.getType(), paralist); + } + } + } + // ino.end + + // ino.method.getLineNumber.23467.definition + public int getLineNumber() + // ino.end + // ino.method.getLineNumber.23467.body + { + if(declid.size()<=0) + return MyCompiler.NO_LINENUMBER; + else{ + return declid.elementAt(0).getLineNumber(); + } + } + // ino.end + + // ino.method.getOffset.23470.defdescription type=line + // hinzugef�gt: hoth 09.04.2006 + // ino.end + // ino.method.getOffset.23470.definition + public int getOffset() + // ino.end + // ino.method.getOffset.23470.body + { + if(declid.size()<=0) + return MyCompiler.NO_LINENUMBER; + else{ + return declid.elementAt(0).getOffset(); + } + } + // ino.end + + // ino.method.getVariableLength.23473.definition + public int getVariableLength() + // ino.end + // ino.method.getVariableLength.23473.body + { + return declid.elementAt(0).get_Name().length(); + } + // ino.end + + // ino.method.replaceType.23476.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param e + */ + // ino.end + // ino.method.replaceType.23476.definition + public void replaceType(CReplaceTypeEvent e) + // ino.end + // ino.method.replaceType.23476.body + { + inferencelog.debug("Ersetze Typ in InstVarDecl \""+this.get_Name()+"\""); + if(type instanceof TypePlaceholder){ + ((TypePlaceholder)type).removeReplacementListener(this); + } + this.setType(e.getNewType()); + } + // ino.end + + // ino.method.getTypeLineNumber.23479.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.getTypeLineNumber.23479.definition + public int getTypeLineNumber() + // ino.end + // ino.method.getTypeLineNumber.23479.body + { + return this.getLineNumber(); + } + // ino.end + + @Override + public String toString() + { + return this.type + " " + super.getDeclIdVector().firstElement(); + } + + + @Override + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult(); + ret.attach( this.getType().printJavaCode(resultSet)).attach( " " ).attach( super.getDeclIdVector().firstElement() + ";"); + + return ret; + } + + @Override + public TypeAssumptions createTypeAssumptions(Class classmember) { + TypeAssumptions assumptions = new TypeAssumptions(); + ////////////////////////////// + //Alle Variablendeklarationen (int a, b, c) durchgehen: + ////////////////////////////// + for(int i=0; i()); // Typannahme bauen... + assumptions.add(assum); + } + return assumptions; + } +} +// ino.end diff --git a/src/mycompiler/myclass/Method.java b/src/mycompiler/myclass/Method.java new file mode 100755 index 000000000..bcb8f7c8e --- /dev/null +++ b/src/mycompiler/myclass/Method.java @@ -0,0 +1,708 @@ +// ino.module.Method.8564.package +package mycompiler.myclass; +// ino.end +// ino.module.Method.8564.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.IItemWithOffset; +import mycompiler.mybytecode.ClassFile; +import mycompiler.MyCompiler; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCMethodException; +import mycompiler.myexception.SCStatementException; +import mycompiler.mymodifier.Modifiers; +import mycompiler.mystatement.Block; +import mycompiler.mystatement.Return; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; + +import typinferenz.JavaCodeResult; +import typinferenz.SingleConstraint; +import typinferenz.ConstraintsSet; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; +// ino.end + + + + +// ino.class.Method.23482.declaration +public class Method extends FieldDecl implements ITypeReplacementListener, IItemWithOffset +// ino.end +// ino.class.Method.23482.body +{ + // ino.attribute.block.23488.declaration + private Block block; + // ino.end + // ino.attribute.parameterlist.23491.declaration + public ParameterList parameterlist = null; + // ino.end + // ino.attribute.exceptionlist.23494.declaration + private ExceptionList exceptionlist; + // ino.end + // ino.attribute.returntype.23497.declaration + private Type returntype; + // ino.end + + // ino.attribute.genericMethodParameters.23500.decldescription type=javadoc + /** + * HOTI 4.5.06 + * Dieser Vektor beinhaltet alle Generischen Typen und v.a. die + * F-Bounded-Generics, die die Methode besitzt + * size()==0, falls es keine gibt + */ + // ino.end + // ino.attribute.genericMethodParameters.23500.declaration + private Vector genericMethodParameters=new Vector(); + // ino.end + + // ino.attribute.overloadedID.23503.declaration + private int overloadedID; + // ino.end + // ino.attribute.isAbstract.23506.declaration + private boolean isAbstract = false; + // ino.end + // ino.attribute.types_in_parameterlist.23509.declaration + private Vector types_in_parameterlist = new Vector(); + // ino.end + // ino.attribute.m_LineNumber.23512.declaration + private int m_LineNumber = MyCompiler.NO_LINENUMBER; + // ino.end + private int m_Offset = -1; //hinzugef�gt hoth: 07.04.2006 + // ino.attribute.inferencelog.23515.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + // ino.attribute.parserlog.23518.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.setGenericMethodParameters.23521.definition + public void setGenericMethodParameters(Vector genericMethodParameters) + // ino.end + // ino.method.setGenericMethodParameters.23521.body + { + this.genericMethodParameters=genericMethodParameters; + } + // ino.end + // ino.method.getGenericMethodParameters.23524.definition + public Vector getGenericMethodParameters() + // ino.end + // ino.method.getGenericMethodParameters.23524.body + { + return(genericMethodParameters); + } + // ino.end + + // ino.method.call_sc_check.23527.definition + public void call_sc_check(Vector classlist, Hashtable classhash, boolean ext, Hashtable parach) + throws SCMethodException + // ino.end + // ino.method.call_sc_check.23527.body + { + // Semantikcheck fr Methoden + Hashtable blockhash = new Hashtable(); // lokale Hashtabelle, z.B. fr Funktionsparameter + Hashtable parabh = new Hashtable(); + + // otth: Rckgabetyp der Funktion bestimmen und bestimmen ob Konstruktor oder Funktion! + if( getTypeName() == null ) + { + // Hier wird Methoden-Rckgabewert fr's Return-Statement eingetragen last1 + blockhash.put("###_Method_Ret_Type", "__Constructor__"); + } + else + { + blockhash.put("###_Method_Ret_Type", getTypeName() ); + } + parserlog.debug( "Methoden-Rckgabetyp von " + declid.elementAt(0).name + ": " + (String)blockhash.get("###_Method_Ret_Type")); + + // otth: bergebene Parameter in die lokale Hash-Tabelle aufnehmen, falls Parameter vorhanden! + String strDebug = ""; // otth: nur zum Debuggen + if( this.getParameterList() != null ) + { + for( Enumeration en = this.getParameterList().formalparameter.elements(); en.hasMoreElements(); ) + { + FormalParameter tempParameter = (FormalParameter)en.nextElement(); + String type = tempParameter.getTypeName(); + String name = tempParameter.get_Name(); + strDebug = strDebug + type + " --- " + name + " | "; // otth: Debug-Ausgabe + blockhash.put(name, type); + } + } + + // otth: Debug-Ausgabe + if ( strDebug == "" ) strDebug = "---"; + parserlog.debug( "Parameter von " + declid.elementAt(0).name + ": " + strDebug); + + // otth: Semantik-Check fr Block + try + { + parserlog.debug( "Blockhashtabelle (vor Blocksemantikcheck): " + blockhash); + block.sc_check( classlist, classhash, blockhash, ext, parach, parabh ); + } + catch (SCStatementException ex) + { + SCMethodException except = new SCMethodException(); + except.set_exlist(ex.get_exlist()); + throw except; + } + } + // ino.end + + // ino.method.sc_init_parameterlist.23530.definition + public void sc_init_parameterlist(boolean ext) + // ino.end + // ino.method.sc_init_parameterlist.23530.body + { + DeclId hilf=null; + Vector list; + FormalParameter para; + String typeofpara; + int i=1; + if(this.getParameterList()!=null) //es gibt Parameter, dann: + { + hilf=declid.elementAt(0); + if(ext) + parserlog.debug("Semantik-Check hat in Methode "+hilf.get_Name()+" bergabewerte gefunden:"); + list=this.getParameterList().sc_get_Formalparalist(); //Vector Formalparalist aus FormalParameterList wird zwischen gesichert + for(Enumeration el2=list.elements(); el2.hasMoreElements();) + { + para=el2.nextElement(); + typeofpara=para.getTypeName(); + if(ext) + parserlog.debug(" "+i+". Parameter hat Typ "+typeofpara); + types_in_parameterlist.addElement(typeofpara); //Typ der Parameter werden im Vector abgelegt + i++; + } + } + else //keine Parameter vorhanden: + { + if(ext) + { + hilf=declid.elementAt(0); + parserlog.debug("Semantik-Check hat in Methode "+hilf.get_Name()+" keine bergabewerte gefunden."); + } + } + if(ext) + { + parserlog.debug("Semantik-Check hat in Methode "+hilf.get_Name()+" "+ types_in_parameterlist.size()+" bergabeparameter gefunden."); + parserlog.debug(" namentlich: "+types_in_parameterlist.toString()); + } + } + // ino.end + + // ino.method.getTypeName.23533.defdescription type=line + // Eine der beiden Funktionen ist ueberflssig. Wer sich daran strt kann die + // get_ReturnType() auf eigene Gefahr lschen. + // ino.end + + // ino.method.getTypeName.23533.definition + public String getTypeName() + // ino.end + // ino.method.getTypeName.23533.body + { + if( this.getReturnType() == null ) + return null; + else + return this.getReturnType().getName(); + } + // ino.end + + // ino.method.get_Block.23536.definition + public Block get_Block() + // ino.end + // ino.method.get_Block.23536.body + { + return block; + } + // ino.end + + // ino.method.setReturnType.23539.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @param type + */ + // ino.end + // ino.method.setReturnType.23539.definition + public void setReturnType(Type type) + // ino.end + // ino.method.setReturnType.23539.body + { + if(this.returntype instanceof TypePlaceholder){ + ((TypePlaceholder)this.returntype).removeReplacementListener(this); + } + + if(type instanceof TypePlaceholder){ + ((TypePlaceholder)type).addReplacementListener(this); + } + // this.returntype = type; //auskommentiert von Andreas Stadelmeier (a10023) + //Der ReturnType der Methode ist der Returntype des Methodenblocks: + if(block!=null) + this.block.setTypeVariable(type); + this.returntype = type; + } + // ino.end + + // ino.method.set_Block.23542.definition + public void set_Block( Block blo) + // ino.end + // ino.method.set_Block.23542.body + { + if(blo.getTypeVariable() == null)blo.setTypeVariable(this.returntype); + this.block = blo; + } + // ino.end + + // ino.method.set_Modifiers.23545.definition + public void set_Modifiers(Modifiers modif) + // ino.end + // ino.method.set_Modifiers.23545.body + { + declid.firstElement().set_Modifiers(modif); + // this.modi = modif; + } + // ino.end + + // ino.method.set_ExceptionList.23548.definition + public void set_ExceptionList(ExceptionList exlist) + // ino.end + // ino.method.set_ExceptionList.23548.body + { + this.exceptionlist = exlist; + } + // ino.end + + // ino.method.setParameterList.23551.definition + public void setParameterList( ParameterList paralist ) + // ino.end + // ino.method.setParameterList.23551.body + { + this.parameterlist = paralist; + } + // ino.end + + // ino.method.getParameterList.23554.definition + public ParameterList getParameterList( ) + // ino.end + // ino.method.getParameterList.23554.body + { + // otth: gibt die Parameterliste zurueck + return this.parameterlist; + } + // ino.end + + // ino.method.getParameterCount.23557.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @return Die Anzahl der Methoden-Paramater + */ + // ino.end + // ino.method.getParameterCount.23557.definition + public int getParameterCount() + // ino.end + // ino.method.getParameterCount.23557.body + { + if(this.getParameterList() == null) + return 0; + else + return this.getParameterList().getParameterCount(); + } + // ino.end + + // ino.method.get_ExceptionList.23560.definition + public ExceptionList get_ExceptionList() + // ino.end + // ino.method.get_ExceptionList.23560.body + { + // otth: gibt die Exceptionliste zurueck + return this.exceptionlist; + } + // ino.end + + // ino.method.getOverloadedID.23563.definition + public int getOverloadedID() + // ino.end + // ino.method.getOverloadedID.23563.body + { + return(overloadedID); + } + // ino.end + + // ino.method.setOverloadedID.23566.definition + public void setOverloadedID(int overloadedID) + // ino.end + // ino.method.setOverloadedID.23566.body + { + this.overloadedID=overloadedID; + } + // ino.end + + /** + * Liefert den Return Type der Methode. + * Dieser entspricht dem Returntype des Methoden-Block's + * @returnb + */ + // ino.method.getReturnType.23569.definition + public Type getReturnType() + // ino.end + // ino.method.getReturnType.23569.body + { + return this.block.getTypeVariable(); + //return this.returntype; //auskommentiert von Andreas Stadelmeier (a10023) + } + // ino.end + + + + // ino.method.get_codegen_Param_Type.23572.definition + public String get_codegen_Param_Type(Vector paralist) + // ino.end + // ino.method.get_codegen_Param_Type.23572.body + { + String ret = new String(); + if(this.getParameterList() == null) + { + ret += "()"; + } + else + { + ret += this.getParameterList().get_codegen_ParameterList(paralist); + } + if(this.getReturnType() == null) + { + ret += "V"; + } + else + { + ret += this.getReturnType().get_codegen_Type(paralist); + } + return ret; + } + // ino.end + + + + // ino.method.get_Method_Name.23575.definition + public String get_Method_Name() + // ino.end + // ino.method.get_Method_Name.23575.body + { + DeclId hilf=declid.elementAt(0); + return hilf.get_Name(); + } + // ino.end + + // ino.method.get_Type_Paralist.23578.definition + public Vector get_Type_Paralist() + // ino.end + // ino.method.get_Type_Paralist.23578.body + { + return types_in_parameterlist; + } + // ino.end + + + + // ino.method.codegen.23581.definition + public void codegen(ClassFile classfile, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.23581.body + { + classfile.add_method(declid.firstElement().get_Name(), this.get_codegen_Param_Type(paralist), this.getParameterList(), this.getReturnType(), block, declid.firstElement().get_access_flags(), paralist, isAbstract); + } + // ino.end + + // ino.method.getLineNumber.23584.definition + public int getLineNumber() + // ino.end + // ino.method.getLineNumber.23584.body + { + return m_LineNumber; + } + // ino.end + + // ino.method.setLineNumber.23587.definition + public void setLineNumber(int lineNumber) + // ino.end + // ino.method.setLineNumber.23587.body + { + m_LineNumber = lineNumber; + } + // ino.end + + // ino.method.getOffset.23590.defdescription type=line + // hinzugef�gt hoth: 07.04.2006 + // ino.end + // ino.method.getOffset.23590.definition + public int getOffset() + // ino.end + // ino.method.getOffset.23590.body + { + return m_Offset; + } + // ino.end + + // ino.method.getVariableLength.23593.definition + public int getVariableLength() + // ino.end + // ino.method.getVariableLength.23593.body + { + return get_Method_Name().length(); + } + // ino.end + + // ino.method.setOffset.23596.defdescription type=line + // hinzugef�gt hoth: 07.04.2006 + // ino.end + // ino.method.setOffset.23596.definition + public void setOffset(int Offset) + // ino.end + // ino.method.setOffset.23596.body + { + m_Offset = Offset; + } + // ino.end + + // ino.method.replaceType.23599.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @param e + */ + // ino.end + // ino.method.replaceType.23599.definition + public void replaceType(CReplaceTypeEvent e) + // ino.end + // ino.method.replaceType.23599.body + { + inferencelog.debug("Ersetze Typ in Method \""+this.get_Method_Name()+"()\"\n"); + if(returntype instanceof TypePlaceholder){ + ((TypePlaceholder)returntype).removeReplacementListener(this); + } + this.setReturnType(e.getNewType()); + } + // ino.end + + // ino.method.getTypeLineNumber.23602.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @return + */ + // ino.end + // ino.method.getTypeLineNumber.23602.definition + public int getTypeLineNumber() + // ino.end + // ino.method.getTypeLineNumber.23602.body + { + return this.getLineNumber(); + } + // ino.end + + // ino.method.toString.23605.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.23605.definition + public String toString() + // ino.end + // ino.method.toString.23605.body + { + return this.getReturnType() + " " + block.toString(); + } + // ino.end + + // ino.method.setAbstract.23608.defdescription type=javadoc + /** + * Legt fuer die ByteCodeGen fest, ob Bytecode + * innerhalb der Methode generiert wird. + */ + // ino.end + // ino.method.setAbstract.23608.definition + public void setAbstract(boolean b) + // ino.end + // ino.method.setAbstract.23608.body + { + isAbstract = b; + } + // ino.end + + // ino.method.isAbstract.23611.defdescription type=javadoc + /** + * Gibt zurueck, ob ByteCode innerhabl der Methode + * generiert wird. + */ + // ino.end + // ino.method.isAbstract.23611.definition + public boolean isAbstract() + // ino.end + // ino.method.isAbstract.23611.body + { + return isAbstract; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.23614.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.23614.body + { + // Zuerst Returntype untersuchen + Type returnType=getReturnType(); + GenericTypeVar pendantReturnType=ClassHelper.findGenericType(returnType, paralist,genericMethodParameters); + if(pendantReturnType!=null){ //Wenn generisch, dann modifizieren + setReturnType(pendantReturnType); + } + + // Dann parameterlist untersuchen + for(int par=0;par")) && ((this.getReturnType().equals(new mycompiler.mytype.Void(0))) || this.getReturnType() instanceof TypePlaceholder)){ + if((this.get_Method_Name().equals(classmember.getName()) || this.get_Method_Name().equals(""))) { + this.set_Method_Name(""); + this.assumedType = new RefType(classmember.getName(),0); + this.setReturnType(this.assumedType); + this.assumedType = new RefType("void",0); + //Return constructorReturnStatement = new Return(0,0); + //constructorReturnStatement.retexpr = + //this.block.statements.add(constructorReturnStatement); + } + //hoth: 06.04.2006 + //durchlaufe Block und suche nach Objektvariablen fuer Offset-Markierung + Iterator fieldVarIterator = assumptions.iterator(); + while (fieldVarIterator.hasNext()) + { + //Wenn ObjektVariable + CTypeAssumption dieAssum = fieldVarIterator.next(); + if(dieAssum instanceof CInstVarTypeAssumption) + { + Class.isFirstLocalVarDecl=false; + if(this.get_Block() != null) + this.get_Block().addOffsetsToAssumption(dieAssum,dieAssum.getIdentifier(),true); + } + } + + //methodList.addElement(method); + + //F�r V_fields_methods: + CMethodTypeAssumption methodAssum = new CMethodTypeAssumption(classmember.getType(), this.get_Method_Name(), this.getReturnType(), this.getParameterCount(),this.getLineNumber(),this.getOffset(),new Vector(),this.getGenericMethodParameters()); // Typannahme bauen... + + + //Methode in V_Fields_methods ablegen + //Dabei wird die OverloadedMethodID ermittelt !! + //=> Method setzenuct + + + assumptions.add(methodAssum); + this.setOverloadedID(methodAssum.getHashSetKey().getOverloadedMethodID()); + + + //F�r die V_i: + CTypeAssumptionSet localAssum = new CTypeAssumptionSet(); + + //Bauen... + ParameterList parameterList = this.getParameterList(); + if(parameterList!=null){ + for(int i=0; i()); + //fuege Offsets fuer Parameter hinzu, hoth: 06.04.2006 + Class.isFirstLocalVarDecl=false; + + if(this.get_Block() != null) + this.get_Block().addOffsetsToAssumption(paraAssum,paraAssum.getIdentifier(),true); + + methodAssum.addParaAssumption(paraAssum); + + // F�r die V_i: + CLocalVarTypeAssumption varAssum = new CLocalVarTypeAssumption(classmember.getName(), this.get_Method_Name(), this.getParameterCount(), this.getOverloadedID(),"1", para.get_Name(),para.getType(), para.getLineNumber(),para.getOffset(),new Vector()); + localAssum.addElement(varAssum); + //rememberLocals.addElement(varAssum); + } + } + //...und hinzuf�gen: + + assumptions.add(localAssum);//Assumptions für lokale Variablen den Assumptions hinzufügen + + //Hier wird der Typ der als Assumption eingetragen wird in die Variable assumedType dieser Klasse geschrieben: + if(this.assumedType == null) // Falls der Typ nicht schon gesetzt ist. Das ist der Fall, falls die Methode ein Konstruktor ist + this.assumedType = methodAssum.getAssumedType(); + + return assumptions; + } + +} +// ino.end diff --git a/src/mycompiler/myclass/ParameterList.java b/src/mycompiler/myclass/ParameterList.java new file mode 100755 index 000000000..6a7b49528 --- /dev/null +++ b/src/mycompiler/myclass/ParameterList.java @@ -0,0 +1,150 @@ +// ino.module.ParameterList.8565.package +package mycompiler.myclass; +// ino.end +// ino.module.ParameterList.8565.import +import java.util.Vector; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mytype.*; +import java.util.Iterator; + +// ino.end + + + + +// ino.class.ParameterList.23620.declaration +public class ParameterList +// ino.end +// ino.class.ParameterList.23620.body +{ + // ino.attribute.formalparameter.23623.declaration + public Vector formalparameter = new Vector(); + // ino.end + + + + // ino.method.set_AddParameter.23626.definition + public void set_AddParameter(FormalParameter fp) + // ino.end + // ino.method.set_AddParameter.23626.body + { + formalparameter.addElement(fp); + } + // ino.end + + + + // ino.method.get_codegen_ParameterList.23629.definition + public String get_codegen_ParameterList(Vector paralist) + // ino.end + // ino.method.get_codegen_ParameterList.23629.body + { + String ret = "("; + for(int i=0 ; i < this.formalparameter.size() ; i++) + { + //feda 13.06.2007 Array behandlung bei Parametern in Methoden + if (this.formalparameter.elementAt(i).getType() instanceof BaseType) { + BaseType BT = (BaseType)this.formalparameter.elementAt(i).getType(); + if (BT.IsArray() == true) { + ret += "["; + } + } + if (this.formalparameter.elementAt(i).getType() instanceof RefType) { + RefType RT = (RefType)this.formalparameter.elementAt(i).getType(); + if (RT.IsArray() == true) { + ret += "["; + } + } + + ret += this.formalparameter.elementAt(i).getType().get_codegen_Type(paralist); + } + return ret + ")"; + } + // ino.end + + // ino.method.getParameterAt.23632.definition + public FormalParameter getParameterAt(int i) + // ino.end + // ino.method.getParameterAt.23632.body + { + if (i >= formalparameter.size() ) return null; + + return formalparameter.elementAt(i); + } + // ino.end + + + // ino.method.sc_get_Formalparalist.23635.definition + public Vector sc_get_Formalparalist() + // ino.end + // ino.method.sc_get_Formalparalist.23635.body + { + return formalparameter; + } + // ino.end + + // ino.method.codegen.23638.definition + public void codegen(ClassFile classfile, CodeAttribute code) + // ino.end + // ino.method.codegen.23638.body + { + for(int i = 0; i < formalparameter.size(); i++) + formalparameter.elementAt(i).codegen(classfile, code); + } + // ino.end + + // ino.method.getParameterCount.23641.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @return Die Anzahl der Parameter + */ + // ino.end + // ino.method.getParameterCount.23641.definition + public int getParameterCount() + // ino.end + // ino.method.getParameterCount.23641.body + { + return formalparameter.size(); + } + // ino.end + + /** + * @author Andreas Stadelmeier, a10023 + * @return Die Typinformationen der Parameter in der Parameterliste + */ + public String getTypeInformation() { + String ret = ""; + for(FormalParameter param : this.formalparameter){ + ret += param.getTypeInformation(); + } + return ret; + } + + public String toString(){ + if(formalparameter == null)return "[]"; //"Leere Parameterliste"; + //String ret = "ParameterListe, "+formalparameter.size()+" Einträge [ "; + String ret = " [ "; + for(FormalParameter param : this.formalparameter){ + ret += param.toString()+", "; + } + return ret + "]"; + } + + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult(); + Iterator it = this.formalparameter.iterator(); + while(it.hasNext()){ + FormalParameter param = it.next(); + ret.attach(param.printJavaCode(resultSet)); + if(it.hasNext())ret.attach(", "); + } + //if(this.formalparameter.size()>0)ret = ret.substring(0, ret.length() - 2); + return ret; + } + +} +// ino.end diff --git a/src/mycompiler/myclass/Status.java b/src/mycompiler/myclass/Status.java new file mode 100755 index 000000000..f2f46c747 --- /dev/null +++ b/src/mycompiler/myclass/Status.java @@ -0,0 +1,38 @@ +// ino.module.Status.8566.package +package mycompiler.myclass; +// ino.end + +// ino.module.Status.8566.import +import mycompiler.unused.Import; +// ino.end + +// ino.class.Status.23644.declaration +public abstract class Status +// ino.end +// ino.class.Status.23644.body +{ + // ino.attribute.userdef.23647.declaration + protected UserDef userdef; + // ino.end + // ino.attribute.imp.23650.declaration + protected Import imp; + // ino.end + + // ino.method.set_UserDef.23653.definition + public void set_UserDef( UserDef userdef) + // ino.end + // ino.method.set_UserDef.23653.body + { + this.userdef = userdef; + } + // ino.end + // ino.method.set_Import.23656.definition + public void set_Import(Import imp) + // ino.end + // ino.method.set_Import.23656.body + { + this.imp = imp; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myclass/UsedId.java b/src/mycompiler/myclass/UsedId.java new file mode 100755 index 000000000..a16db852a --- /dev/null +++ b/src/mycompiler/myclass/UsedId.java @@ -0,0 +1,332 @@ +// ino.module.UsedId.8567.package +package mycompiler.myclass; +// ino.end +// ino.module.UsedId.8567.import +import java.util.Iterator; +import java.util.Vector; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypinferenzException; +import mycompiler.IItemWithOffset; +import mycompiler.mybytecode.JVMCode; +import mycompiler.mytype.Type; +// ino.end + + +// ino.class.UsedId.23659.declaration +public class UsedId implements IItemWithOffset +// ino.end +// ino.class.UsedId.23659.body +{ + // ino.attribute.name.23663.declaration + public Vector name = new Vector(); // Vector mit Strings + // ino.end + // ino.attribute.typen.23666.declaration + private Vector typen = new Vector(); // Vector mit Typen + // ino.end + // ino.attribute.paralist.23669.declaration + private Vector paralist = null; + // ino.end + // ino.attribute.vParaOrg.23672.declaration + public Vector vParaOrg = null; // otth: originale Parameterliste + // ino.end + private int m_Offset = -1; //hinzugef�gt hoth: 07.04.2006 + + // ino.method.UsedId.23675.definition + public UsedId(int offset) + // ino.end + // ino.method.UsedId.23675.body + { + m_Offset=offset; + } + // ino.end + + public UsedId(String name, int offset) + { + this(offset); + this.set_Name(name); + } + + // ino.method.getOffset.23678.defdescription type=line + // hinzugef�gt hoth: 07.04.2006 + // ino.end + // ino.method.getOffset.23678.definition + public int getOffset() + // ino.end + // ino.method.getOffset.23678.body + { + return m_Offset; + } + // ino.end + + // ino.method.getVariableLength.23681.definition + public int getVariableLength() + // ino.end + // ino.method.getVariableLength.23681.body + { + return get_Name_1Element().length(); + } + // ino.end + + // ino.method.setOffset.23684.defdescription type=line + // hinzugef�gt hoth: 07.04.2006 + // ino.end + // ino.method.setOffset.23684.definition + public void setOffset(int Offset) + // ino.end + // ino.method.setOffset.23684.body + { + m_Offset = Offset; + } + // ino.end + + // ino.method.set_Name.23687.definition + public void set_Name( String name) + // ino.end + // ino.method.set_Name.23687.body + { + this.name.addElement(name); + } + // ino.end + + // ino.method.get_Name.23690.definition + public Vector get_Name() + // ino.end + // ino.method.get_Name.23690.body + { + return name; + } + // ino.end + + // ino.method.get_Name_1Element.23693.definition + public String get_Name_1Element() + // ino.end + // ino.method.get_Name_1Element.23693.body + { + return (String) name.elementAt(0); + } + // ino.end + + // ino.method.set_Typen.23696.definition + public void set_Typen(Vector t) + // ino.end + // ino.method.set_Typen.23696.body + { + typen=t; + } + // ino.end + + // ino.method.set_ParaList.23699.definition + public void set_ParaList(Vector pl) + // ino.end + // ino.method.set_ParaList.23699.body + { + this.paralist = pl; + } + // ino.end + + // ino.method.get_RealParaList.23702.definition + public Vector get_RealParaList() + // ino.end + // ino.method.get_RealParaList.23702.body + { + return this.paralist; + } + // ino.end + + // ino.method.get_ParaList.23705.definition + public Vector get_ParaList() + // ino.end + // ino.method.get_ParaList.23705.body + { + if(this.paralist != null) + return this.paralist; + else return new Vector(); + } + // ino.end + + // ino.method.get_vParaOrg.23708.definition + public Vector get_vParaOrg() + // ino.end + // ino.method.get_vParaOrg.23708.body + { + return this.vParaOrg; + } + // ino.end + + + // ino.method.get_Typen.23711.definition + public Vector get_Typen() + // ino.end + // ino.method.get_Typen.23711.body + { + return typen; + } + // ino.end + + // ino.method.get_codegen_UsedId.23714.definition + public String get_codegen_UsedId() + // ino.end + // ino.method.get_codegen_UsedId.23714.body + { + String name_string = new String(); + name_string += (String)name.elementAt(0); + for(int i = 1; i < name.size(); i++) + name_string += ("/" + (String)name.elementAt(i)); + return name_string; + } + // ino.end + + // ino.method.getSignatureUsedId.23717.definition + public String getSignatureUsedId() + // ino.end + // ino.method.getSignatureUsedId.23717.body + { + String basis = JVMCode.get_codegen_Type(getQualifiedName(),null); + + if (paralist == null || paralist.size() ==0) + return basis; + + StringBuffer sb = new StringBuffer(); + + // Basistyp, ; entfernen + basis = basis.substring(0, basis.length() -1); + sb.append(basis); + + sb.append("<"); + + for(int i = 0; i< paralist.size(); i++) { + + sb.append(paralist.elementAt(i).get_codegen_Type(null)); + } + + sb.append(">;"); + + return sb.toString(); + } + // ino.end + + + // ino.method.removeLast.23720.definition + public void removeLast() + // ino.end + // ino.method.removeLast.23720.body + { + name.removeElementAt(name.size()-1); + } + // ino.end + + // ino.method.toString.23723.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.23723.definition + public String toString() + // ino.end + // ino.method.toString.23723.body + { + return this.get_Name_1Element();//name.toString(); //geändert von Andreas Stadelmeier + /*String s = ""; + for(int i = 0; i(); + for(int i=0;i0){ + return(name.elementAt(name.size()-1).equals("*")); + } + return(false); + } + // ino.end + + // ino.method.getPackageName.23735.definition + public UsedId getPackageName() + // ino.end + // ino.method.getPackageName.23735.body + { + UsedId uid=new UsedId(-1); + uid.name=new Vector(); + for(int i=0;i0) + return name.lastElement(); + else + return null; + } + // ino.end + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + if(this.name.size()>1)throw new TypinferenzException("Es kann maximal nur eine Superklasse pro Klasse geben"); + JavaCodeResult ret = new JavaCodeResult(this.getQualifiedName()); + if(this.paralist != null){ + ret.attach( "<" ); + Iterator it = this.paralist.iterator(); + while(it.hasNext()){ + Type para = it.next(); + ret.attach(para.printJavaCode(resultSet)); + if(it.hasNext())ret.attach(", "); + } + //ret = ret.substring(0, ret.length()-2); + ret.attach(">"); + } + return ret; + } + +} +// ino.end diff --git a/src/mycompiler/myclass/UserDef.java b/src/mycompiler/myclass/UserDef.java new file mode 100755 index 000000000..0550e99de --- /dev/null +++ b/src/mycompiler/myclass/UserDef.java @@ -0,0 +1,11 @@ +// ino.module.UserDef.8568.package +package mycompiler.myclass; +// ino.end +// ino.class.UserDef.23741.declaration +public class UserDef extends Status +// ino.end +// ino.class.UserDef.23741.body +{ + +} +// ino.end diff --git a/src/mycompiler/myexception/CTypeReconstructionException.java b/src/mycompiler/myexception/CTypeReconstructionException.java new file mode 100755 index 000000000..ccb15f67b --- /dev/null +++ b/src/mycompiler/myexception/CTypeReconstructionException.java @@ -0,0 +1,128 @@ +// ino.module.CTypeReconstructionException.8572.package +package mycompiler.myexception; +// ino.end + +// ino.module.CTypeReconstructionException.8572.import +import java.util.Vector; +import mycompiler.IItemWithOffset; +// ino.end + +// ino.class.CTypeReconstructionException.23746.description type=javadoc +/** + * @author J�rg B�uerle + * @version $Date: 2006/06/13 10:37:31 $ + */ +// ino.end +// ino.class.CTypeReconstructionException.23746.declaration +public class CTypeReconstructionException extends RuntimeException +// ino.end +// ino.class.CTypeReconstructionException.23746.body +{ + + + // ino.attribute.serialVersionUID.23750.declaration + private static final long serialVersionUID = -7744106691767607974L; + // ino.end + // ino.attribute.parentExceptions.23753.declaration + public Vector parentExceptions; + // ino.end + + // ino.attribute.problemSource.23756.decldescription type=javadoc + /** + * Das Statement bei dem das Problem aufgetaucht ist + */ + // ino.end + // ino.attribute.problemSource.23756.declaration + private IItemWithOffset problemSource; + // ino.end + // ino.attribute.message.23759.declaration + private String message; + // ino.end + + // ino.method.CTypeReconstructionException.23762.definition + public CTypeReconstructionException(String message, IItemWithOffset problemSource) + // ino.end + // ino.method.CTypeReconstructionException.23762.body + { + super(message); + this.message=message; + this.problemSource=problemSource; + } + // ino.end + + // ino.method.CTypeReconstructionException.23765.definition + public CTypeReconstructionException(String message, Vector parentExceptions, IItemWithOffset problemSource) + // ino.end + // ino.method.CTypeReconstructionException.23765.body + { + super(message+" "+parentExceptions); + this.message=message; + this.parentExceptions=parentExceptions; + this.problemSource=problemSource; + } + // ino.end + + // ino.method.getHighestProblemSources.23768.definition + public Vector getHighestProblemSources() + // ino.end + // ino.method.getHighestProblemSources.23768.body + { + Vector stmts=new Vector(); + if(parentExceptions!=null){ + for(int i=0;i problems = parentExceptions.elementAt(i).getHighestProblemSources(); + for(int j=0;j=0) + stmts.addElement(elem); + } + if(stmts.size()>0) + return stmts; + } + } + if(problemSource!=null && problemSource.getOffset()>=0){ + stmts.addElement(problemSource); + } + + return stmts; + } + // ino.end + + // ino.method.getMessage.23771.defdescription type=block + /*private Vector getProblemLines(){ + Vector problems=getHighestProblemSources(); + Vector lines=new Vector(); + for(int i=0;i exlist=new Vector(); + // ino.end + + // ino.method.addException.23810.definition + public void addException(SCExcept ex) + // ino.end + // ino.method.addException.23810.body + { + exlist.addElement(ex); + } + // ino.end + + // ino.method.get_exlist.23813.definition + public Vector get_exlist() + // ino.end + // ino.method.get_exlist.23813.body + { + return exlist; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myexception/SCClassException.java b/src/mycompiler/myexception/SCClassException.java new file mode 100755 index 000000000..ace83fdc3 --- /dev/null +++ b/src/mycompiler/myexception/SCClassException.java @@ -0,0 +1,69 @@ +// ino.module.SCClassException.8576.package +package mycompiler.myexception; +// ino.end +// ino.module.SCClassException.8576.import +import java.util.Enumeration; +import java.util.Vector; +import org.apache.log4j.Logger; +// ino.end + + + +// ino.class.SCClassException.23816.declaration +public class SCClassException extends Exception +// ino.end +// ino.class.SCClassException.23816.body +{ + + // ino.attribute.serialVersionUID.23820.declaration + private static final long serialVersionUID = 5339857618390360728L; + // ino.end + // ino.attribute.exlist.23823.declaration + private Vector exlist=new Vector(); + // ino.end + // ino.attribute.parserlog.23826.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.addException.23829.definition + public void addException(Vector v) + // ino.end + // ino.method.addException.23829.body + { + exlist=v; + } + // ino.end + + + + // ino.method.addClassname.23832.definition + public void addClassname(String cn) + // ino.end + // ino.method.addClassname.23832.body + { + SCExcept hilf; + for(Enumeration el=exlist.elements();el.hasMoreElements();) + { + hilf=el.nextElement(); + hilf.set_classname(cn); + } + } + // ino.end + + // ino.method.fehlerausgabe.23835.definition + public void fehlerausgabe() + // ino.end + // ino.method.fehlerausgabe.23835.body + { + SCExcept hilfe; + for(Enumeration el=exlist.elements();el.hasMoreElements();) + { + hilfe=el.nextElement(); + hilfe.fehlerausgabe(); + if(el.hasMoreElements()) + parserlog.debug(""); + } + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myexception/SCExcept.java b/src/mycompiler/myexception/SCExcept.java new file mode 100755 index 000000000..1b39c58a4 --- /dev/null +++ b/src/mycompiler/myexception/SCExcept.java @@ -0,0 +1,111 @@ +// ino.module.SCExcept.8577.package +package mycompiler.myexception; +// ino.end + +// ino.module.SCExcept.8577.import +import org.apache.log4j.Logger; +// ino.end + +// ino.class.SCExcept.23838.declaration +public class SCExcept +// ino.end +// ino.class.SCExcept.23838.body +{ + // ino.attribute.classname.23841.declaration + private String classname; + // ino.end + // ino.attribute.error.23844.declaration + private String error; + // ino.end + // ino.attribute.function.23847.declaration + private String function; + // ino.end + // ino.attribute.statement.23850.declaration + private String statement; + // ino.end + // ino.attribute.parserlog.23853.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.set_classname.23856.definition + public void set_classname(String cn) + // ino.end + // ino.method.set_classname.23856.body + { + classname=cn; + } + // ino.end + + // ino.method.set_error.23859.definition + public void set_error(String e) + // ino.end + // ino.method.set_error.23859.body + { + error=e; + } + // ino.end + + // ino.method.set_function.23862.definition + public void set_function(String fct) + // ino.end + // ino.method.set_function.23862.body + { + function=fct; + } + // ino.end + + // ino.method.set_statement.23865.definition + public void set_statement(String s) + // ino.end + // ino.method.set_statement.23865.body + { + statement=s; + } + // ino.end + + // ino.method.fehlerausgabe.23868.definition + public void fehlerausgabe() + // ino.end + // ino.method.fehlerausgabe.23868.body + { + parserlog.error("Semantik-Check hat einen Fehler gefunden!"); + parserlog.error("Fehler "+error); + parserlog.error("wurde in"); + if(classname!=null) + parserlog.error("class "+classname); + if(function!=null) + parserlog.error("in der Funktion "+function); + if(statement!=null) + parserlog.error("im Statement "+statement); + parserlog.error("gefunden."); + } + // ino.end + + // ino.method.get_classname.23871.definition + public String get_classname() + // ino.end + // ino.method.get_classname.23871.body + { + return classname; + } + // ino.end + + // ino.method.get_statement.23874.definition + public String get_statement() + // ino.end + // ino.method.get_statement.23874.body + { + return statement; + } + // ino.end + + // ino.method.get_function.23877.definition + public String get_function() + // ino.end + // ino.method.get_function.23877.body + { + return function; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myexception/SCException.java b/src/mycompiler/myexception/SCException.java new file mode 100755 index 000000000..dc9cb5c53 --- /dev/null +++ b/src/mycompiler/myexception/SCException.java @@ -0,0 +1,52 @@ +// ino.module.SCException.8578.package +package mycompiler.myexception; +// ino.end +// ino.module.SCException.8578.import +import java.util.Enumeration; +import java.util.Vector; +import org.apache.log4j.Logger; +// ino.end + + + +// ino.class.SCException.23880.declaration +public class SCException extends Exception +// ino.end +// ino.class.SCException.23880.body +{ + // ino.attribute.serialVersionUID.23884.declaration + private static final long serialVersionUID = 1L; + // ino.end + // ino.attribute.scerrors.23887.declaration + private Vector scerrors = new Vector(); + // ino.end + // ino.attribute.parserlog.23890.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.add_classexceptions.23893.definition + public void add_classexceptions(SCClassException ex) + // ino.end + // ino.method.add_classexceptions.23893.body + { + scerrors.addElement(ex); + } + // ino.end + + // ino.method.fehlerausgabe.23896.definition + public void fehlerausgabe() + // ino.end + // ino.method.fehlerausgabe.23896.body + { + SCClassException hilf; + for(Enumeration el=scerrors.elements();el.hasMoreElements();) + { + hilf=el.nextElement(); + hilf.fehlerausgabe(); + if(el.hasMoreElements()) + parserlog.debug(""); + } + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myexception/SCMethodException.java b/src/mycompiler/myexception/SCMethodException.java new file mode 100755 index 000000000..045d79559 --- /dev/null +++ b/src/mycompiler/myexception/SCMethodException.java @@ -0,0 +1,41 @@ +// ino.module.SCMethodException.8579.package +package mycompiler.myexception; +// ino.end +// ino.module.SCMethodException.8579.import +import java.util.Vector; +// ino.end + + + +// ino.class.SCMethodException.23899.declaration +public class SCMethodException extends Exception +// ino.end +// ino.class.SCMethodException.23899.body +{ + // ino.attribute.serialVersionUID.23903.declaration + private static final long serialVersionUID = -3060025579851679412L; + // ino.end + + // ino.attribute.exlist.23906.declaration + private Vector exlist; + // ino.end + + // ino.method.get_exlist.23909.definition + public Vector get_exlist() + // ino.end + // ino.method.get_exlist.23909.body + { + return exlist; + } + // ino.end + + // ino.method.set_exlist.23912.definition + public void set_exlist(Vector list) + // ino.end + // ino.method.set_exlist.23912.body + { + exlist=list; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myexception/SCStatementException.java b/src/mycompiler/myexception/SCStatementException.java new file mode 100755 index 000000000..8e7f0da35 --- /dev/null +++ b/src/mycompiler/myexception/SCStatementException.java @@ -0,0 +1,41 @@ +// ino.module.SCStatementException.8580.package +package mycompiler.myexception; +// ino.end +// ino.module.SCStatementException.8580.import +import java.util.Vector; +// ino.end + + + +// ino.class.SCStatementException.23915.declaration +public class SCStatementException extends Exception +// ino.end +// ino.class.SCStatementException.23915.body +{ + // ino.attribute.serialVersionUID.23919.declaration + private static final long serialVersionUID = -5299461034178474235L; + // ino.end + + // ino.attribute.exlist.23922.declaration + private Vector exlist= new Vector(); + // ino.end + + // ino.method.get_exlist.23925.definition + public Vector get_exlist() + // ino.end + // ino.method.get_exlist.23925.body + { + return exlist; + } + // ino.end + + // ino.method.addException.23928.definition + public void addException(SCExcept ex) + // ino.end + // ino.method.addException.23928.body + { + exlist.addElement(ex); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myinterface/Interface.java b/src/mycompiler/myinterface/Interface.java new file mode 100755 index 000000000..e946c4168 --- /dev/null +++ b/src/mycompiler/myinterface/Interface.java @@ -0,0 +1,322 @@ +// ino.module.Interface.8582.package +package mycompiler.myinterface; +// ino.end + +// ino.module.Interface.8582.import +import java.util.Vector; +import mycompiler.AClassOrInterface; +import mycompiler.mybytecode.ClassFile; +import mycompiler.myclass.ClassHelper; +import mycompiler.myclass.Constant; +import mycompiler.myclass.FormalParameter; +import mycompiler.myclass.Method; +import mycompiler.myclass.ParameterList; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mymodifier.Modifiers; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CIntersectionType; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; +import mycompiler.SourceFile; +// ino.end + +// ino.class.Interface.23932.description type=javadoc +/** + * Die Klasse stellt die Definition eines Interfaces dar. + * @author SCJU + * + */ +// ino.end +// ino.class.Interface.23932.declaration +public class Interface extends AClassOrInterface +// ino.end +// ino.class.Interface.23932.body +{ + + // ino.attribute.ib.23936.declaration + private InterfaceBody ib; + // ino.end + + // ino.attribute.paralist.23939.decldescription type=line + // HOTI 29. Apr 06 + // ino.end + // ino.attribute.paralist.23939.declaration + private Vector paralist = new Vector(); // Parameterliste 'interface xy{}' wird gespeichert + // ino.end + + // ino.attribute.containedTypes.23942.declaration + private Vector containedTypes; + // ino.end + + // ino.method.Interface.23945.defdescription type=line + // Konstruktoren + // ino.end + // ino.method.Interface.23945.definition + public Interface() + // ino.end + // ino.method.Interface.23945.body + { + super(); + } + // ino.end + + // ino.method.Interface.23948.definition + public Interface(String name) + // ino.end + // ino.method.Interface.23948.body + { + super(name); + } + // ino.end + + // ino.method.Interface.23951.definition + public Interface(String name, Modifiers mod) + // ino.end + // ino.method.Interface.23951.body + { + super(name, mod); + } + // ino.end + + + // ino.method.getParaList.23954.defdescription type=block + /*public Vector complete_paralist(boolean ext) + { + + Diese Funktion vervollt�ndigt die Parameterliste f�r vererbte Klassen + Vector child = paralist; + + paralist = (Vector)superclassid.get_ParaList(); + + for(Enumeration e = child.elements();e.hasMoreElements();){ + paralist.addElement(e.nextElement()); + } + + return this.paralist; + }*/ + // ino.end + + + + // ino.method.getParaList.23954.definition + public Vector getParaList() + // ino.end + // ino.method.getParaList.23954.body + { + return this.paralist; + } + // ino.end + // ino.method.setParaList.23957.definition + public void setParaList(Vector paralist) + // ino.end + // ino.method.setParaList.23957.body + { + this.paralist=paralist; + } + // ino.end + // ino.method.setContainedTypes.23960.definition + public void setContainedTypes(Vector containedTypes) + // ino.end + // ino.method.setContainedTypes.23960.body + { + this.containedTypes = containedTypes; + } + // ino.end + + // ino.method.getContainedTypes.23963.definition + public Vector getContainedTypes() + // ino.end + // ino.method.getContainedTypes.23963.body + { + return containedTypes; + } + // ino.end + + // ino.method.codegen.23966.definition + public void codegen(SourceFile sf) + throws JVMCodeException + // ino.end + // ino.method.codegen.23966.body + { + codegenlog.info("Definierte Superinterfaces: " + getSuperInterfaces().size()); + codegenlog.debug("Liste der Interfaces: " + getSuperInterfaces().toString()); + codegenlog.info("Definierte Konstanten: " + ib.getConstantVektor().size()); + codegenlog.info("Definierte Methoden: " + ib.getMethodVektor().size()); + + // Erzeugen einer Classfile auf Basis des Interfaces + ClassFile classfile = new ClassFile(this, sf); + + // Handling fuer Generics + classfile.addGenerics(paralist, null, getSuperInterfaces()); + + // Handling fuer Superinterfaces + classfile.addSuperInterfaces(getSuperInterfaces()); + + // Codegen fuer Interface-Body + Vector paralist = new Vector(); + if(ib != null) ib.codegen(classfile, paralist); + + classfile.codegen(); + + codegenlog.info("Compilierung erfolgreich abgeschlossen, "+ getName() + ".class erstellt."); + } + // ino.end + + // ino.method.getInterfaceBody.23969.definition + public InterfaceBody getInterfaceBody() + // ino.end + // ino.method.getInterfaceBody.23969.body + { + return ib; + } + // ino.end + + // ino.method.setInterfaceBody.23972.definition + public void setInterfaceBody(InterfaceBody ib) + // ino.end + // ino.method.setInterfaceBody.23972.body + { + this.ib = ib; + } + // ino.end + + // ino.method.addThisToAssumptions.23975.definition + public void addThisToAssumptions(CTypeReconstructionResult assumption) + // ino.end + // ino.method.addThisToAssumptions.23975.body + { + assumption.addClassName(getName()); + + InterfaceBody body = getInterfaceBody(); + if(body!=null){ + + Vector genericsList = new Vector(); + if(getParaList()!=null){ + for(int ii =0; ii()); // Typannahme bauen... + assumption.addFieldOrLocalVarAssumption(assum); + } + } + + + CTypeAssumptionSet V_fields_methods = new CTypeAssumptionSet(); + + // Methoden in V_fields_methods laden + if(body.getMethodVektor()!=null){ + Vector methodAssumptions=new Vector(); + + for(int mID=0;mID(),method.getGenericMethodParameters()); // Typannahme bauen... + V_fields_methods.addElement(methodAssum); + method.setOverloadedID(methodAssum.getHashSetKey().getOverloadedMethodID()); + + // Parameter hinzufuegen + + ParameterList parameterList = method.getParameterList(); + if(parameterList!=null){ + for(int i=0; i()); + // FIXME HOTI Mit Thomas abklären, was hier getan werden muss! + //Class.addOffsetsToAssumption(paraAssum,method.get_Block(),paraAssum.getIdentifier(),true); + methodAssum.addParaAssumption(paraAssum); + + } + } + methodAssumptions.add(methodAssum); + + } + // Aus den V_fields_methods die Methoden in die BasicAssumption legen + for(int i=0;i methods=ib.MethodVektor; + + // Alle Methoden durchgehen + for(int i=0;i ConstantVektor = new Vector(); + // ino.end + // ino.attribute.MethodVektor.23990.declaration + protected Vector MethodVektor = new Vector(); + // ino.end + + // ino.method.InterfaceBody.23993.defdescription type=line + // Konstruktoren + // ino.end + // ino.method.InterfaceBody.23993.definition + public InterfaceBody() + // ino.end + // ino.method.InterfaceBody.23993.body + { + + } + // ino.end + + // ino.method.addElement.23996.defdescription type=javadoc + /** + * Fuegt ein neues Element (Konstantendefinition oder abstrakte + * Methode) ein. + */ + // ino.end + // ino.method.addElement.23996.definition + public void addElement(FieldDecl fd) + // ino.end + // ino.method.addElement.23996.body + { + if (fd instanceof Constant) { + ConstantVektor.addElement((Constant) fd); + } else if (fd instanceof Method) { + MethodVektor.addElement((Method) fd); + } + + } + // ino.end + + // ino.method.getConstantVektor.23999.definition + public Vector getConstantVektor() + // ino.end + // ino.method.getConstantVektor.23999.body + { + return ConstantVektor; + } + // ino.end + + // ino.method.setConstantVektor.24002.definition + public void setConstantVektor(Vector constantVektor) + // ino.end + // ino.method.setConstantVektor.24002.body + { + ConstantVektor = constantVektor; + } + // ino.end + + // ino.method.getMethodVektor.24005.definition + public Vector getMethodVektor() + // ino.end + // ino.method.getMethodVektor.24005.body + { + return MethodVektor; + } + // ino.end + + // ino.method.setMethodVektor.24008.definition + public void setMethodVektor(Vector methodVektor) + // ino.end + // ino.method.setMethodVektor.24008.body + { + MethodVektor = methodVektor; + } + // ino.end + + // ino.method.codegen.24011.definition + public void codegen(ClassFile cf, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.24011.body + { + + // Constanten verarbeiten + for (int i=0; i < ConstantVektor.size(); i++) { + ConstantVektor.elementAt(i).codegen(cf, paralist); + } + + // Methodenheader verarbeiten + for (int i=0; i < MethodVektor.size(); i++) { + Method m = MethodVektor.elementAt(i); + + Modifiers mod = m.getDeclIdVector().elementAt(0).get_Modifiers(); + + if (mod != null){ + mod.ensureAbstract(); + mod.ensurePublic(); + } else { + mod = new Modifiers(); + mod.ensureAbstract(); + mod.ensurePublic(); + m.getDeclIdVector().elementAt(0).set_Modifiers(mod); + } + + + // Sicherstellen, dass kein Bytecode innerhalb + // der Methode generiert wird. + m.setAbstract(true); + m.codegen(cf, paralist); + } + } + // ino.end + + +} +// ino.end diff --git a/src/mycompiler/mymodifier/Abstract.java b/src/mycompiler/mymodifier/Abstract.java new file mode 100755 index 000000000..17a4c21e1 --- /dev/null +++ b/src/mycompiler/mymodifier/Abstract.java @@ -0,0 +1,36 @@ +// ino.module.Abstract.8585.package +package mycompiler.mymodifier; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +// ino.end + + +// ino.class.Abstract.24015.description type=javadoc +/** + * Stellt den Modifier Abstract dar. + * + */ +// ino.end +// ino.class.Abstract.24015.declaration +public class Abstract extends Modifier +// ino.end +// ino.class.Abstract.24015.body +{ + + // ino.method.getBitmask.24019.definition + public short getBitmask() + // ino.end + // ino.method.getBitmask.24019.body + { + return 0x0400; + } + // ino.end + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("abstract"); + } + +} +// ino.end diff --git a/src/mycompiler/mymodifier/Final.java b/src/mycompiler/mymodifier/Final.java new file mode 100755 index 000000000..487b6424d --- /dev/null +++ b/src/mycompiler/mymodifier/Final.java @@ -0,0 +1,36 @@ +// ino.module.Final.8586.package +package mycompiler.mymodifier; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +// ino.end + + +// ino.class.Final.24022.description type=javadoc +/** + * Stellt den Modifier Final dar. + * + */ +// ino.end +// ino.class.Final.24022.declaration +public class Final extends Modifier +// ino.end +// ino.class.Final.24022.body +{ + + // ino.method.getBitmask.24026.definition + public short getBitmask() + // ino.end + // ino.method.getBitmask.24026.body + { + return 0x10; + } + // ino.end + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("final"); + } + +} +// ino.end diff --git a/src/mycompiler/mymodifier/InterfaceModifier.java b/src/mycompiler/mymodifier/InterfaceModifier.java new file mode 100755 index 000000000..6c38c8c36 --- /dev/null +++ b/src/mycompiler/mymodifier/InterfaceModifier.java @@ -0,0 +1,23 @@ +/** + * + */ +package mycompiler.mymodifier; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +/** + * @author Daniel + * + */ +public class InterfaceModifier extends Modifier { + public short getBitmask() + { + return 0x0200; +} + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("interface"); + } +} diff --git a/src/mycompiler/mymodifier/Modifier.java b/src/mycompiler/mymodifier/Modifier.java new file mode 100755 index 000000000..614308245 --- /dev/null +++ b/src/mycompiler/mymodifier/Modifier.java @@ -0,0 +1,25 @@ +// ino.module.Modifier.8587.package +package mycompiler.mymodifier; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +// ino.end +// ino.class.Modifier.24029.declaration +public abstract class Modifier +// ino.end +// ino.class.Modifier.24029.body +{ + // ino.method.getBitmask.24032.decldescription type=javadoc + /** + * Liefert den Wert des Access-Modifiers fuer die Bytecode-Generierung + * zurueck. + */ + // ino.end + // ino.method.getBitmask.24032.declaration + public abstract short getBitmask(); + // ino.end + + public abstract JavaCodeResult printJavaCode(ResultSet resultSet); +} +// ino.end diff --git a/src/mycompiler/mymodifier/Modifiers.java b/src/mycompiler/mymodifier/Modifiers.java new file mode 100755 index 000000000..7ae00aeb2 --- /dev/null +++ b/src/mycompiler/mymodifier/Modifiers.java @@ -0,0 +1,142 @@ +// ino.module.Modifiers.8588.package +package mycompiler.mymodifier; +// ino.end + +// ino.module.Modifiers.8588.import +import java.util.Vector; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +// ino.end + +import mycompiler.mytype.BaseType; + +// ino.class.Modifiers.24035.description type=javadoc +/** + * Die Klasse beinhaltet die Liste der Access-Modifier fuer eine Klasse, + * Methode usw. + */ +// ino.end +// ino.class.Modifiers.24035.declaration +public class Modifiers +// ino.end +// ino.class.Modifiers.24035.body +{ + // ino.attribute.modifier.24038.declaration + protected Vector modifier = new Vector(); + // ino.end + + // ino.method.getModifiers.24041.definition + public Vector getModifiers() + // ino.end + // ino.method.getModifiers.24041.body + { + return this.modifier; + } + // ino.end + + // ino.method.setModifier.24044.definition + public void setModifier(Vector modifier) + // ino.end + // ino.method.setModifier.24044.body + { + if (modifier != null) this.modifier = modifier; + } + // ino.end + + // ino.method.addModifier.24047.defdescription type=javadoc + /** + * Fuegt den angegebenen Modifier zur Auflistung hinzu. + */ + // ino.end + // ino.method.addModifier.24047.definition + public void addModifier(Modifier mod) + // ino.end + // ino.method.addModifier.24047.body + { + modifier.addElement(mod); + } + // ino.end + + // ino.method.includesModifier.24050.defdescription type=javadoc + /** + * Gibt zurueck, ob der angegebene Modifier enthalten ist. + */ + // ino.end + // ino.method.includesModifier.24050.definition + public boolean includesModifier(Modifier mod) + // ino.end + // ino.method.includesModifier.24050.body + { + String class1 = mod.getClass().toString(); + String class2; + + for (int i=0; i getOperatorTypes() { + Hashtable types = new Hashtable(); + + types.put(new RefType("java.lang.Integer",-1),new RefType("java.lang.Integer",-1)); + types.put(new RefType("java.lang.Double",-1),new RefType("java.lang.Double",-1)); + types.put(new RefType("java.lang.Float",-1), new RefType("java.lang.Float",-1)); + types.put(new RefType("java.lang.Long",-1), new RefType("java.lang.Long",-1)); + types.put(new RefType("java.lang.String",-1), new RefType("java.lang.String",-1)); + + return types; + } + +} +// ino.end diff --git a/src/mycompiler/myoperator/AndOp.java b/src/mycompiler/myoperator/AndOp.java new file mode 100755 index 000000000..ef7b80d9a --- /dev/null +++ b/src/mycompiler/myoperator/AndOp.java @@ -0,0 +1,20 @@ +// ino.module.AndOp.8595.package +package mycompiler.myoperator; +// ino.end + +// ino.class.AndOp.24101.declaration +public class AndOp extends LogOp +// ino.end +// ino.class.AndOp.24101.body +{ + + // ino.method.AndOp.24105.definition + public AndOp(int offset, int variableLength) + // ino.end + // ino.method.AndOp.24105.body + { + super(offset,variableLength); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myoperator/DivideOp.java b/src/mycompiler/myoperator/DivideOp.java new file mode 100755 index 000000000..decfa0526 --- /dev/null +++ b/src/mycompiler/myoperator/DivideOp.java @@ -0,0 +1,48 @@ +// ino.module.DivideOp.8596.package +package mycompiler.myoperator; +// ino.end +// ino.module.DivideOp.8596.import +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mystatement.Binary; +import mycompiler.mystatement.Expr; +// ino.end + + + + +// ino.class.DivideOp.24108.declaration +public class DivideOp extends MulOp +// ino.end +// ino.class.DivideOp.24108.body +{ + // ino.method.DivideOp.24112.definition + public DivideOp(int offset, int variableLength) + // ino.end + // ino.method.DivideOp.24112.body + { + super(offset,variableLength); + } + // ino.end + + // ino.method.codegen.24115.definition + public void codegen(ClassFile classfile, CodeAttribute code, Expr expr, boolean neg, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.24115.body + { + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + expr1.codegen(classfile, code, paralist); + expr2.codegen(classfile, code, paralist); + code.add_code(JVMCode.ndiv(expr1.getTypeName())); + } + // ino.end + + + +} +// ino.end diff --git a/src/mycompiler/myoperator/EqualOp.java b/src/mycompiler/myoperator/EqualOp.java new file mode 100755 index 000000000..d0a3163df --- /dev/null +++ b/src/mycompiler/myoperator/EqualOp.java @@ -0,0 +1,195 @@ +// ino.module.EqualOp.8597.package +package mycompiler.myoperator; +// ino.end +// ino.module.EqualOp.8597.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mystatement.Binary; +import mycompiler.mystatement.Expr; +import mycompiler.mystatement.Null; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.unify.Unify; +// ino.end + + + + +// ino.class.EqualOp.24118.declaration +public class EqualOp extends RelOp +// ino.end +// ino.class.EqualOp.24118.body +{ + // ino.method.EqualOp.24122.definition + public EqualOp(int offset, int variableLength) + // ino.end + // ino.method.EqualOp.24122.body + { + super(offset, variableLength); + } + // ino.end + + // ino.method.codegen.24125.definition + public void codegen(ClassFile classfile, CodeAttribute code, Expr expr, boolean not, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.24125.body + { + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + int type1 = JVMCode.get_nType(expr1.getTypeName()); + int type2 = JVMCode.get_nType(expr2.getTypeName()); + expr1.codegen(classfile, code, paralist); + expr2.codegen(classfile, code, paralist); + if((expr1 instanceof Null) || (expr2 instanceof Null)) + if(type1==4 || type2==4) + if(!not) code.add_code(JVMCode.ifnonnull); + else code.add_code(JVMCode.ifnull); + else throw new JVMCodeException("JVMCodeException: EqualOp: void codegen(ClassFile classfile, Code_attribute code, Expr expr, boolean not)"); + else if(!not) code.add_code(JVMCode.if_ncmpne(expr1.getTypeName())); + else code.add_code(JVMCode.if_ncmpeq(expr1.getTypeName())); + code.add_code_short((short)7); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.goto_); + code.add_code_short((short)4); + code.add_code(JVMCode.iconst_0); + } + // ino.end + + // ino.method.if_codegen.24128.definition + public void if_codegen(ClassFile classfile, CodeAttribute code, String type, boolean not) + throws JVMCodeException + // ino.end + // ino.method.if_codegen.24128.body + { + if(type.equals("null")) + if(!not) code.add_code(JVMCode.ifnonnull); + else code.add_code(JVMCode.ifnull); + else + if(!not) code.add_code(JVMCode.if_ncmpne(type)); + else code.add_code(JVMCode.if_ncmpeq(type)); + } + // ino.end + + // ino.method.TRExp.24131.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.53 von Martin Pl�micke + *
Achtung Workaround: Wenn die BaseTypes endlich korrekt implementiert sind, + * dann sollte der RefType "Boolean" �berall durch den BaseType "BooleanType" + * ersetzt werden!!!
Author: J�rg B�uerle + * @param binary + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.24131.definition + public CTripleSet TRExp(Binary binary, CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.24131.body + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr1 rufen: + // -------------------------- + CTripleSet expr1Set = binary.get_Expr1().TRExp(sigma, V, supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + + // Hier für 2 verschiedene Ebenen abfangen L1= Layer1 + Vector exceptionsL1=new Vector(); + int successfullsL1=0; + + + Iterator expr1It = expr1Set.getIterator(); + while(expr1It.hasNext()){ + CTriple expr1Triple = expr1It.next(); + // -------------------------- + // TRExpr f�r Expr2 rufen: + // -------------------------- + try{ + CTripleSet expr2Set = binary.get_Expr2().TRExp(expr1Triple.getSubstitutions(), expr1Triple.getAssumptionSet(), supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + Iterator expr2It = expr2Set.getIterator(); + while(expr2It.hasNext()){ + CTriple expr2Triple = expr2It.next(); + // -------------------------- + // Beide ReturnTypes unifizieren: + // -------------------------- + // ty_i <=* ty_i,j : + Vector> unifierPossibilities1 = Unify.unify(expr1Triple.getResultType(), expr2Triple.getResultType(), supportData.getFiniteClosure()); + // ty_i,j <=* ty_i : + Vector> unifierPossibilities2 = Unify.unify(expr2Triple.getResultType(), expr1Triple.getResultType(), supportData.getFiniteClosure()); + // Vereinigen: + Vector> unifierPossibilities = unifierPossibilities2; + for(int k=0; k indices = new Vector(); + Operator op = ((Binary)expr).get_Operator(); + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + boolean and; + + if(op instanceof OrOp) and = false; + else if(op instanceof AndOp) and = true; + else throw new JVMCodeException("JVMCodeException: LogOp: void codegen(ClassFile classfile, Code_attribute code, Expr expr, boolean not)"); + + build(classfile, code, expr1, indices, not, false, and, paralist); + build(classfile, code, expr2, indices, not, true, and, paralist); + + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.goto_); + code.add_code_short(4); + code.add_code(JVMCode.iconst_0); + int code_length = code.get_code_length(); + replace_index(code, indices, code_length - 1, code_length - 5); + } + // ino.end + + // ino.method.if_codegen.24196.definition + public void if_codegen(ClassFile classfile, CodeAttribute code, boolean not, Expr expr, Statement then_block, Statement else_block, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.if_codegen.24196.body + { + Vector indices = new Vector(); + Operator op = ((Binary)expr).get_Operator(); + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + boolean and; + + if(op instanceof OrOp) and = false; + else if(op instanceof AndOp) and = true; + else throw new JVMCodeException("JVMCodeException: LogOp: if_codegen(ClassFile classfile, Code_attribute code, boolean not, Expr expr, Statement then_block, Statement else_block)"); + + build(classfile, code, expr1, indices, not, false, and, paralist); + build(classfile, code, expr2, indices, not, true, and, paralist); + + int breakpoint1 = code.get_code_length(); + if(then_block != null) then_block.codegen(classfile, code, paralist); + + int breakpoint2 = code.get_code_length(); + if(else_block != null) { + code.add_code(JVMCode.goto_); + breakpoint2 = code.get_code_length(); + code.add_code_short(0); + else_block.codegen(classfile, code, paralist); + code.set_code_short(code.get_code_length() + 1 - breakpoint2, breakpoint2); + } + replace_index(code, indices, breakpoint2 + 2 , breakpoint1); + } + // ino.end + + // ino.method.loop_codegen.24199.definition + public void loop_codegen(ClassFile classfile, CodeAttribute code, Expr expr, int breakpoint, boolean not, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.loop_codegen.24199.body + { + Vector indices = new Vector(); + Operator op = ((Binary)expr).get_Operator(); + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + boolean and; + + if(op instanceof OrOp) and = false; + else if(op instanceof AndOp) and = true; + else throw new JVMCodeException("JVMCodeException: LogOp: void loop_codegen(ClassFile classfile, Code_attribute code, Expr expr, int breakpoint, boolean not)"); + + build(classfile, code, expr1, indices, not, false, and, paralist); + build(classfile, code, expr2, indices, not, true, and, paralist); + + replace_index(code, indices, breakpoint + 2, code.get_code_length()); + } + // ino.end + + // ino.method.build.24202.definition + public static void build(ClassFile classfile, CodeAttribute code, Expr expr, Vector indices, boolean not, boolean ex2, boolean and, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.build.24202.body + { + if(expr instanceof NotExpr) + build(classfile, code, ((NotExpr)expr).get_Expr(), indices, !not, ex2, and, paralist); + else if(expr instanceof Binary) { + Operator op = ((Binary)expr).get_Operator(); + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + + if(op instanceof LogOp) { + boolean and2; + if(op instanceof OrOp) and2 = false; + else if(op instanceof AndOp) and2 = true; + else throw new JVMCodeException("JVMCodeException: LogOp: void build(ClassFile classfile, Code_attribute code, Expr expr, Vector indices, boolean not, boolean ex2, boolean and)"); + + if((and != and2) && !ex2) { + Vector indices2 = new Vector(); + build(classfile, code, expr1, indices2, not, false, and2, paralist); + build(classfile, code, expr2, indices, not, ex2, and, paralist); + int breakpoint = code.get_code_length(); + replace_index(code, indices2, breakpoint, breakpoint); + } + else { + build(classfile, code, expr1, indices, not, false, and2, paralist); + build(classfile, code, expr2, indices, not, ex2, and, paralist); + } + } + else if(op instanceof RelOp) { + expr1.codegen(classfile, code, paralist); + expr2.codegen(classfile, code, paralist); + + if(expr1 instanceof Null || expr2 instanceof Null) ((RelOp)op).if_codegen(classfile, code, "null", not); + else ((RelOp)op).if_codegen(classfile, code, expr.getTypeName(), not); + + indices.addElement(new Integer(code.get_code_length())); + + if(and) { + if(not && !ex2) code.add_code_short(1); + else code.add_code_short(0); + } + else { + if(not || ex2) code.add_code_short(0); + else code.add_code_short(1); + } + } + else throw new JVMCodeException("JVMCodeException: LogOp: void build(ClassFile classfile, Code_attribute code, Expr expr, Vector indices, boolean not, boolean ex2, boolean and)"); + } + else { + expr.codegen(classfile, code, paralist); + indices.addElement(new Integer(code.get_code_length() + 1)); + if(and) { + if(not && ex2) code.add_code(JVMCode.ifne); + else code.add_code(JVMCode.ifeq); + if(not && !ex2) code.add_code_short(1); + else code.add_code_short(0); + } + else { + if(!not && ex2) code.add_code(JVMCode.ifeq); + else code.add_code(JVMCode.ifne); + if(not || ex2) code.add_code_short(0); + else code.add_code_short(1); + } + } + } + // ino.end + + // ino.method.replace_index.24205.definition + public static void replace_index(CodeAttribute code, Vector indices, int else_index, int then_index) + throws JVMCodeException + // ino.end + // ino.method.replace_index.24205.body + { + Vector b = code.get_code_Vector(); + for(int i = 0; i < indices.size(); i++) { + int y = indices.elementAt(i).intValue(); + int high = JVMCode.bytes_to_int((Byte)b.elementAt(y)); + int low = JVMCode.bytes_to_int((Byte)b.elementAt(y+1)); + int x = (high << 8) + low; + if(x == 0) code.set_code_short(else_index + 1 - y, y); + else if(x == 1) code.set_code_short(then_index + 1 - y, y); + else throw new JVMCodeException("JVMCodeException: LogOp: replace_index(Code_attribute code, Vector indices, int else_index, int then_index)"); + } + } + // ino.end + + @Override + protected Hashtable getOperatorTypes() { + Hashtable types = new Hashtable(); + + types.put(new RefType("java.lang.Boolean",-1), new RefType("java.lang.Boolean",-1)); + + return types; + } + + +} +// ino.end diff --git a/src/mycompiler/myoperator/MinusOp.java b/src/mycompiler/myoperator/MinusOp.java new file mode 100755 index 000000000..e240db973 --- /dev/null +++ b/src/mycompiler/myoperator/MinusOp.java @@ -0,0 +1,46 @@ +// ino.module.MinusOp.8603.package +package mycompiler.myoperator; +// ino.end +// ino.module.MinusOp.8603.import +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mystatement.Binary; +import mycompiler.mystatement.Expr; +// ino.end + + + + +// ino.class.MinusOp.24211.declaration +public class MinusOp extends AddOp +// ino.end +// ino.class.MinusOp.24211.body +{ + // ino.method.MinusOp.24215.definition + public MinusOp(int offset, int variableLength) + // ino.end + // ino.method.MinusOp.24215.body + { + super(offset,variableLength); + } + // ino.end + + // ino.method.codegen.24218.definition + public void codegen(ClassFile classfile, CodeAttribute code, Expr expr, boolean neg, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.24218.body + { + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + expr1.codegen(classfile, code, paralist); + expr2.codegen(classfile, code, paralist); + if(!neg) code.add_code(JVMCode.nsub(expr1.getTypeName())); + else code.add_code(JVMCode.nadd(expr1.getTypeName())); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myoperator/ModuloOp.java b/src/mycompiler/myoperator/ModuloOp.java new file mode 100755 index 000000000..44245b639 --- /dev/null +++ b/src/mycompiler/myoperator/ModuloOp.java @@ -0,0 +1,45 @@ +// ino.module.ModuloOp.8604.package +package mycompiler.myoperator; +// ino.end +// ino.module.ModuloOp.8604.import +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mystatement.Binary; +import mycompiler.mystatement.Expr; +// ino.end + + + + +// ino.class.ModuloOp.24221.declaration +public class ModuloOp extends MulOp +// ino.end +// ino.class.ModuloOp.24221.body +{ + // ino.method.ModuloOp.24225.definition + public ModuloOp(int offset, int variableLength) + // ino.end + // ino.method.ModuloOp.24225.body + { + super(offset,variableLength); + } + // ino.end + + // ino.method.codegen.24228.definition + public void codegen(ClassFile classfile, CodeAttribute code, Expr expr, boolean neg, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.24228.body + { + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + expr1.codegen(classfile, code, paralist); + expr2.codegen(classfile, code, paralist); + code.add_code(JVMCode.nrem(expr1.getTypeName())); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myoperator/MulOp.java b/src/mycompiler/myoperator/MulOp.java new file mode 100755 index 000000000..2007040ee --- /dev/null +++ b/src/mycompiler/myoperator/MulOp.java @@ -0,0 +1,49 @@ +// ino.module.MulOp.8605.package +package mycompiler.myoperator; +// ino.end + +// ino.module.MulOp.8605.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.mystatement.Binary; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.unify.Unify; +// ino.end + +// ino.class.MulOp.24231.declaration +public abstract class MulOp extends Operator +// ino.end +// ino.class.MulOp.24231.body +{ + // ino.method.MulOp.24235.definition + public MulOp(int offset, int variableLength) + // ino.end + // ino.method.MulOp.24235.body + { + super(offset, variableLength); + } + // ino.end + + @Override + protected Hashtable getOperatorTypes() { + Hashtable types = new Hashtable(); + + types.put(new RefType("java.lang.Integer",-1), new RefType("java.lang.Integer",-1)); + types.put(new RefType("java.lang.Double",-1), new RefType("java.lang.Double",-1)); + types.put(new RefType("java.lang.Float",-1), new RefType("java.lang.Float",-1)); + types.put(new RefType("java.lang.Long",-1), new RefType("java.lang.Long",-1)); + + return types; + } + + +} +// ino.end diff --git a/src/mycompiler/myoperator/NotEqualOp.java b/src/mycompiler/myoperator/NotEqualOp.java new file mode 100755 index 000000000..48fb13d0d --- /dev/null +++ b/src/mycompiler/myoperator/NotEqualOp.java @@ -0,0 +1,191 @@ +// ino.module.NotEqualOp.8606.package +package mycompiler.myoperator; +// ino.end +// ino.module.NotEqualOp.8606.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mystatement.Binary; +import mycompiler.mystatement.Expr; +import mycompiler.mystatement.Null; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.unify.Unify; +// ino.end + + + + +// ino.class.NotEqualOp.24241.declaration +public class NotEqualOp extends RelOp +// ino.end +// ino.class.NotEqualOp.24241.body +{ + // ino.method.NotEqualOp.24245.definition + public NotEqualOp(int offset, int variableLength) + // ino.end + // ino.method.NotEqualOp.24245.body + { + super(offset,variableLength); + } + // ino.end + + // ino.method.codegen.24248.definition + public void codegen(ClassFile classfile, CodeAttribute code, Expr expr, boolean not, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.24248.body + { + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + int type1 = JVMCode.get_nType(expr1.getTypeName()); + int type2 = JVMCode.get_nType(expr2.getTypeName()); + expr1.codegen(classfile, code, paralist); + expr2.codegen(classfile, code, paralist); + if((expr1 instanceof Null) || (expr2 instanceof Null)) + if(type1==4 || type2==4) + if(!not) code.add_code(JVMCode.ifnull); + else code.add_code(JVMCode.ifnonnull); + else throw new JVMCodeException("JVMCodeException: NotEqualOp: void codegen(ClassFile classfile, Code_attribute code, Expr expr, boolean not)"); + else if(!not) code.add_code(JVMCode.if_ncmpeq(expr1.getTypeName())); + else code.add_code(JVMCode.if_ncmpne(expr1.getTypeName())); + code.add_code_short((short)7); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.goto_); + code.add_code_short((short)4); + code.add_code(JVMCode.iconst_0); + } + // ino.end + + // ino.method.if_codegen.24251.definition + public void if_codegen(ClassFile classfile, CodeAttribute code, String type, boolean not) + throws JVMCodeException + // ino.end + // ino.method.if_codegen.24251.body + { + if(type.equals("null")) + if(!not) code.add_code(JVMCode.ifnull); + else code.add_code(JVMCode.ifnonnull); + else + if(!not) code.add_code(JVMCode.if_ncmpeq(type)); + else code.add_code(JVMCode.if_ncmpne(type)); + } + // ino.end + + // ino.method.TRExp.24254.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.54 von Martin Pl�micke + *
Achtung Workaround: Wenn die BaseTypes endlich korrekt implementiert sind, + * dann sollte der RefType "Boolean" �berall durch den BaseType "BooleanType" + * ersetzt werden!!!
Author: J�rg B�uerle + * @param binary + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.24254.definition + public CTripleSet TRExp(Binary binary, CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.24254.body + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr1 rufen: + // -------------------------- + CTripleSet expr1Set = binary.get_Expr1().TRExp(sigma, V, supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + Iterator expr1It = expr1Set.getIterator(); + int successfulls=0; + Vector exceptions=new Vector(); + while(expr1It.hasNext()){ + CTriple expr1Triple = expr1It.next(); + // -------------------------- + // TRExpr f�r Expr2 rufen: + // -------------------------- + try{ + CTripleSet expr2Set = binary.get_Expr2().TRExp(expr1Triple.getSubstitutions(), expr1Triple.getAssumptionSet(), supportData); + // -------------------------- + // Alle Boolean-Triple nehmen: + // -------------------------- + Iterator expr2It = expr2Set.getIterator(); + while(expr2It.hasNext()){ + CTriple expr2Triple = expr2It.next(); + // -------------------------- + // Beide ReturnTypes unifizieren: + // -------------------------- + // ty_i <=* ty_i,j : + Vector> unifierPossibilities1 = Unify.unify(expr1Triple.getResultType(), expr2Triple.getResultType(), supportData.getFiniteClosure()); + // ty_i,j <=* ty_i : + Vector> unifierPossibilities2 = Unify.unify(expr2Triple.getResultType(), expr1Triple.getResultType(), supportData.getFiniteClosure()); + // Vereinigen: + Vector> unifierPossibilities = unifierPossibilities2; + for(int k=0; k exceptions = new Vector(); + Hashtable opTypes = getOperatorTypes(); + + Vector sets = new Vector(); + + for (RefType type : opTypes.keySet() ) { + try{ + sets.addElement(TRExpPossibility(binary,sigma,V,supportData, type, opTypes.get(type))); + }catch(CTypeReconstructionException ex) { + exceptions.addElement(ex); + } + } + + if( sets.size() == 0 ) { + throw new CTypeReconstructionException("Keiner der Operatoren konnte auf die Datentypen angewandt werden", exceptions, this); + } + + if( sets.size() == 1 ) { + return sets.elementAt(0); + } + + CTripleSet result = new CTripleSet(); + + for ( CTripleSet sset : sets ) { + result.addAll(sset); + } + + return result; + + } + // ino.end + + /** + * @author timo + * This is cool: + * we call the abstract parent to it him what operator-types he expects. the rest of the algorithm + * is implemented in this class because it's always the same... + * @see Design Pattern: Template Method + */ + protected abstract Hashtable getOperatorTypes( ); + + public CTripleSet TRExpPossibility(Binary binary, CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData, RefType inputType, RefType outputType) + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr1 rufen: + // -------------------------- + CTripleSet expr1Set = binary.get_Expr1().TRExp(sigma, V, supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + Iterator expr1It = expr1Set.getIterator(); + while(expr1It.hasNext()){ + CTriple expr1Triple = expr1It.next(); + // -------------------------- + // ReturnType mit Integer unifizieren: + // -------------------------- + Vector> unifierPossibilities1 = Unify.unify(expr1Triple.getResultType(), inputType, supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann anwenden: + // -------------------------- + if(unifierPossibilities1.size()!=0){ + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + Vector exceptions=new Vector(); + int successfulls=0; + + for(int i=0; i expr2It = expr2Set.getIterator(); + while(expr2It.hasNext()){ + CTriple expr2Triple = expr2It.next(); + // -------------------------- + // ReturnType mit Integer unifizieren: + // -------------------------- + Vector> unifierPossibilities2 = Unify.unify(expr2Triple.getResultType(), inputType, supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann + // anwenden und Triple hinzuf�gen: + // -------------------------- + if(unifierPossibilities2.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + for(int j=0; j getOperatorTypes() { + Hashtable types = new Hashtable(); + + types.put(new RefType("java.lang.Integer",-1), new RefType("java.lang.Boolean",-1)); + types.put(new RefType("java.lang.Double",-1), new RefType("java.lang.Boolean",-1)); + types.put(new RefType("java.lang.Float",-1), new RefType("java.lang.Boolean",-1)); + types.put(new RefType("java.lang.Long",-1), new RefType("java.lang.Boolean",-1)); + + return types; + } + + +} +// ino.end diff --git a/src/mycompiler/myoperator/TimesOp.java b/src/mycompiler/myoperator/TimesOp.java new file mode 100755 index 000000000..723b6b4a2 --- /dev/null +++ b/src/mycompiler/myoperator/TimesOp.java @@ -0,0 +1,55 @@ +// ino.module.TimesOp.8611.package +package mycompiler.myoperator; +// ino.end + +// ino.module.TimesOp.8611.import +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mystatement.Binary; +import mycompiler.mystatement.Expr; +// ino.end + +// ino.class.TimesOp.24312.declaration +public class TimesOp extends MulOp +// ino.end +// ino.class.TimesOp.24312.body +{ + // ino.method.TimesOp.24316.definition + public TimesOp(int offset,int variableLength) + // ino.end + // ino.method.TimesOp.24316.body + { + super(offset,variableLength); + } + // ino.end + + // ino.method.codegen.24319.definition + public void codegen(ClassFile classfile, CodeAttribute code, Expr expr, + boolean neg, Vector paralist) + throws JVMCodeException + // ino.end +// ino.method.codegen.24319.body +{ + Expr expr1 = ((Binary) expr).get_Expr1(); + Expr expr2 = ((Binary) expr).get_Expr2(); + + expr1.codegen(classfile, code, paralist); + // unboxing + makePrimitive( classfile, code); + + expr2.codegen(classfile, code, paralist); + // unboxing + makePrimitive( classfile, code); + + // Die Multiplikation + code.add_code(JVMCode.imul); + + // Boxing des Typs + makeWrapper(classfile, code); + } +// ino.end +} +// ino.end diff --git a/src/mycompiler/myparser/ClassAndParameter.java b/src/mycompiler/myparser/ClassAndParameter.java new file mode 100755 index 000000000..a72acd318 --- /dev/null +++ b/src/mycompiler/myparser/ClassAndParameter.java @@ -0,0 +1,97 @@ +// ino.module.ClassAndParameter.8613.package +package mycompiler.myparser; +// ino.end + +// ino.module.ClassAndParameter.8613.import +import java.util.Vector; +import mycompiler.mytype.ParaList; +import mycompiler.mytype.Type; +// ino.end + +// ino.class.ClassAndParameter.24323.description type=javadoc +/** + * Hilfskonstrukt, um die Grammatik fuer einen Klassenheader + * ueberschaubar zu halten. Klassenname und optionale Generics + * werden hiermit kombiniert und sofort nach dem Parsen in der + * Klasse Class zueruck aufgeloest. + * @author SCJU + * + */ +// ino.end +// ino.class.ClassAndParameter.24323.declaration +public class ClassAndParameter +// ino.end +// ino.class.ClassAndParameter.24323.body +{ + // ino.attribute.name.24326.declaration + private String name; + // ino.end + // ino.attribute.plist.24329.declaration + private ParaList plist; + // ino.end + + // ino.method.ClassAndParameter.24332.definition + public ClassAndParameter(String name) + // ino.end + // ino.method.ClassAndParameter.24332.body + { + this.name = name; + } + // ino.end + + // ino.method.ClassAndParameter.24335.definition + public ClassAndParameter(String name, ParaList plist) + // ino.end + // ino.method.ClassAndParameter.24335.body + { + this.name = name; + this.plist = plist; + } + // ino.end + + // ino.method.getParaVector.24338.definition + public Vector getParaVector() + // ino.end + // ino.method.getParaVector.24338.body + { + if (plist == null) return null; + + return plist.get_ParaList(); + } + // ino.end + + // ino.method.getName.24341.definition + public String getName() + // ino.end + // ino.method.getName.24341.body + { + return name; + } + // ino.end + // ino.method.setName.24344.definition + public void setName(String name) + // ino.end + // ino.method.setName.24344.body + { + this.name = name; + } + // ino.end + // ino.method.getParalist.24347.definition + public ParaList getParalist() + // ino.end + // ino.method.getParalist.24347.body + { + return plist; + } + // ino.end + // ino.method.setParalist.24350.definition + public void setParalist(ParaList plist) + // ino.end + // ino.method.setParalist.24350.body + { + this.plist = plist; + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/myparser/InterfaceAndParameter.java b/src/mycompiler/myparser/InterfaceAndParameter.java new file mode 100755 index 000000000..b003846cf --- /dev/null +++ b/src/mycompiler/myparser/InterfaceAndParameter.java @@ -0,0 +1,98 @@ +// ino.module.InterfaceAndParameter.8614.package +package mycompiler.myparser; +// ino.end + +// ino.module.InterfaceAndParameter.8614.import +import java.util.Vector; +import mycompiler.mytype.ParaList; +import mycompiler.mytype.Type; +// ino.end + +// ino.class.InterfaceAndParameter.24353.description type=javadoc +/** + * Hilfskonstrukt, um die Grammatik fuer einen Interfaceheader + * ueberschaubar zu halten. Interface und optionale Generics + * werden hiermit kombiniert und sofort nach dem Parsen in der + * Klasse Interface zueruck aufgeloest. + * @author HOTI + * + */ +// ino.end +// ino.class.InterfaceAndParameter.24353.declaration +public class InterfaceAndParameter +// ino.end +// ino.class.InterfaceAndParameter.24353.body +{ + // ino.attribute.name.24356.declaration + private String name; + // ino.end + // ino.attribute.plist.24359.declaration + private ParaList plist=new ParaList(); + // ino.end + + // ino.method.InterfaceAndParameter.24362.definition + public InterfaceAndParameter(String name) + // ino.end + // ino.method.InterfaceAndParameter.24362.body + { + this.name = name; + + } + // ino.end + + // ino.method.InterfaceAndParameter.24365.definition + public InterfaceAndParameter(String name, ParaList plist) + // ino.end + // ino.method.InterfaceAndParameter.24365.body + { + this.name = name; + this.plist = plist; + } + // ino.end + + // ino.method.getParaVector.24368.definition + public Vector getParaVector() + // ino.end + // ino.method.getParaVector.24368.body + { + if (plist == null) return null; + + return plist.get_ParaList(); + } + // ino.end + + // ino.method.getName.24371.definition + public String getName() + // ino.end + // ino.method.getName.24371.body + { + return name; + } + // ino.end + // ino.method.setName.24374.definition + public void setName(String name) + // ino.end + // ino.method.setName.24374.body + { + this.name = name; + } + // ino.end + // ino.method.getParalist.24377.definition + public ParaList getParalist() + // ino.end + // ino.method.getParalist.24377.body + { + return plist; + } + // ino.end + // ino.method.setParalist.24380.definition + public void setParalist(ParaList plist) + // ino.end + // ino.method.setParalist.24380.body + { + this.plist = plist; + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/myparser/InterfaceList.java b/src/mycompiler/myparser/InterfaceList.java new file mode 100755 index 000000000..c09a2c55e --- /dev/null +++ b/src/mycompiler/myparser/InterfaceList.java @@ -0,0 +1,47 @@ +// ino.module.InterfaceList.8615.package +package mycompiler.myparser; +// ino.end + +// ino.module.InterfaceList.8615.import +import java.util.Vector; +import mycompiler.myclass.UsedId; +// ino.end + +// ino.class.InterfaceList.24383.description type=javadoc +/** + * Hilfskonstrukt fuer die Grammatik, um ungepruefte + * Typcasts fuer Vectoren zu umgehen. Wird nuer fuer den + * Parser benoetigt. + * @author SCJU + * + */ +// ino.end +// ino.class.InterfaceList.24383.declaration +public class InterfaceList +// ino.end +// ino.class.InterfaceList.24383.body +{ + // ino.attribute.superif.24386.declaration + private Vector superif = new Vector(); + // ino.end + + // ino.method.addInterface.24389.definition + public void addInterface(UsedId uid) + // ino.end + // ino.method.addInterface.24389.body + { + superif.addElement(uid); + } + // ino.end + + // ino.method.getVector.24392.definition + public Vector getVector() + // ino.end + // ino.method.getVector.24392.body + { + return superif; + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/myparser/JavaLexer.java b/src/mycompiler/myparser/JavaLexer.java new file mode 100644 index 000000000..88c7f7cd0 --- /dev/null +++ b/src/mycompiler/myparser/JavaLexer.java @@ -0,0 +1,3674 @@ +/******************************************** + * file: JavaLexer.lex * + * * + * enth�lt die JLex-Spezifikation f�r die * + * Generierung des lexical analyzers * + * * + ********************************************/ +// user code: +package mycompiler.myparser; + + +public class JavaLexer { + private final int YY_BUFFER_SIZE = 512; + private final int YY_F = -1; + private final int YY_NO_STATE = -1; + private final int YY_NOT_ACCEPT = 0; + private final int YY_START = 1; + private final int YY_END = 2; + private final int YY_NO_ANCHOR = 4; + private final int YY_BOL = 128; + private final int YY_EOF = 129; + + Token token; + private java.io.BufferedReader yy_reader; + private int yy_buffer_index; + private int yy_buffer_read; + private int yy_buffer_start; + private int yy_buffer_end; + private char yy_buffer[]; + private int yychar; + private int yyline; + private boolean yy_at_bol; + private int yy_lexical_state; + + public JavaLexer (java.io.Reader reader) { + this (); + if (null == reader) { + throw (new Error("Error: Bad input stream initializer.")); + } + yy_reader = new java.io.BufferedReader(reader); + } + + public JavaLexer (java.io.InputStream instream) { + this (); + if (null == instream) { + throw (new Error("Error: Bad input stream initializer.")); + } + yy_reader = new java.io.BufferedReader(new java.io.InputStreamReader(instream)); + } + + private JavaLexer () { + yy_buffer = new char[YY_BUFFER_SIZE]; + yy_buffer_read = 0; + yy_buffer_index = 0; + yy_buffer_start = 0; + yy_buffer_end = 0; + yychar = 0; + yyline = 0; + yy_at_bol = true; + yy_lexical_state = YYINITIAL; + } + + private boolean yy_eof_done = false; + private final int commentblock = 1; + private final int YYINITIAL = 0; + private final int commentsingleline = 2; + private final int yy_state_dtrans[] = { + 0, + 78, + 187 + }; + private void yybegin (int state) { + yy_lexical_state = state; + } + private int yy_advance () + throws java.io.IOException { + int next_read; + int i; + int j; + + if (yy_buffer_index < yy_buffer_read) { + return yy_buffer[yy_buffer_index++]; + } + + if (0 != yy_buffer_start) { + i = yy_buffer_start; + j = 0; + while (i < yy_buffer_read) { + yy_buffer[j] = yy_buffer[i]; + ++i; + ++j; + } + yy_buffer_end = yy_buffer_end - yy_buffer_start; + yy_buffer_start = 0; + yy_buffer_read = j; + yy_buffer_index = j; + next_read = yy_reader.read(yy_buffer, + yy_buffer_read, + yy_buffer.length - yy_buffer_read); + if (-1 == next_read) { + return YY_EOF; + } + yy_buffer_read = yy_buffer_read + next_read; + } + + while (yy_buffer_index >= yy_buffer_read) { + if (yy_buffer_index >= yy_buffer.length) { + yy_buffer = yy_double(yy_buffer); + } + next_read = yy_reader.read(yy_buffer, + yy_buffer_read, + yy_buffer.length - yy_buffer_read); + if (-1 == next_read) { + return YY_EOF; + } + yy_buffer_read = yy_buffer_read + next_read; + } + return yy_buffer[yy_buffer_index++]; + } + private void yy_move_end () { + if (yy_buffer_end > yy_buffer_start && + '\n' == yy_buffer[yy_buffer_end-1]) + yy_buffer_end--; + if (yy_buffer_end > yy_buffer_start && + '\r' == yy_buffer[yy_buffer_end-1]) + yy_buffer_end--; + } + private boolean yy_last_was_cr=false; + private void yy_mark_start () { + int i; + for (i = yy_buffer_start; i < yy_buffer_index; ++i) { + if ('\n' == yy_buffer[i] && !yy_last_was_cr) { + ++yyline; + } + if ('\r' == yy_buffer[i]) { + ++yyline; + yy_last_was_cr=true; + } else yy_last_was_cr=false; + } + yychar = yychar + + yy_buffer_index - yy_buffer_start; + yy_buffer_start = yy_buffer_index; + } + private void yy_mark_end () { + yy_buffer_end = yy_buffer_index; + } + private void yy_to_mark () { + yy_buffer_index = yy_buffer_end; + yy_at_bol = (yy_buffer_end > yy_buffer_start) && + ('\r' == yy_buffer[yy_buffer_end-1] || + '\n' == yy_buffer[yy_buffer_end-1] || + 2028/*LS*/ == yy_buffer[yy_buffer_end-1] || + 2029/*PS*/ == yy_buffer[yy_buffer_end-1]); + } + private java.lang.String yytext () { + return (new java.lang.String(yy_buffer, + yy_buffer_start, + yy_buffer_end - yy_buffer_start)); + } + private int yylength () { + return yy_buffer_end - yy_buffer_start; + } + private char[] yy_double (char buf[]) { + int i; + char newbuf[]; + newbuf = new char[2*buf.length]; + for (i = 0; i < buf.length; ++i) { + newbuf[i] = buf[i]; + } + return newbuf; + } + private final int YY_E_INTERNAL = 0; + private final int YY_E_MATCH = 1; + private java.lang.String yy_error_string[] = { + "Error: Internal error.\n", + "Error: Unmatched input.\n" + }; + private void yy_error (int code,boolean fatal) { + java.lang.System.out.print(yy_error_string[code]); + java.lang.System.out.flush(); + if (fatal) { + throw new Error("Fatal Error.\n"); + } + } + private int[][] unpackFromString(int size1, int size2, String st) { + int colonIndex = -1; + String lengthString; + int sequenceLength = 0; + int sequenceInteger = 0; + + int commaIndex; + String workString; + + int res[][] = new int[size1][size2]; + for (int i= 0; i < size1; i++) { + for (int j= 0; j < size2; j++) { + if (sequenceLength != 0) { + res[i][j] = sequenceInteger; + sequenceLength--; + continue; + } + commaIndex = st.indexOf(','); + workString = (commaIndex==-1) ? st : + st.substring(0, commaIndex); + st = st.substring(commaIndex+1); + colonIndex = workString.indexOf(':'); + if (colonIndex == -1) { + res[i][j]=Integer.parseInt(workString); + continue; + } + lengthString = + workString.substring(colonIndex+1); + sequenceLength=Integer.parseInt(lengthString); + workString=workString.substring(0,colonIndex); + sequenceInteger=Integer.parseInt(workString); + res[i][j] = sequenceInteger; + sequenceLength--; + } + } + return res; + } + private int yy_acpt[] = { + /* 0 */ YY_NOT_ACCEPT, + /* 1 */ YY_NO_ANCHOR, + /* 2 */ YY_NO_ANCHOR, + /* 3 */ YY_NO_ANCHOR, + /* 4 */ YY_NO_ANCHOR, + /* 5 */ YY_NO_ANCHOR, + /* 6 */ YY_NO_ANCHOR, + /* 7 */ YY_NO_ANCHOR, + /* 8 */ YY_NO_ANCHOR, + /* 9 */ YY_NO_ANCHOR, + /* 10 */ YY_NO_ANCHOR, + /* 11 */ YY_NO_ANCHOR, + /* 12 */ YY_NO_ANCHOR, + /* 13 */ YY_NO_ANCHOR, + /* 14 */ YY_NO_ANCHOR, + /* 15 */ YY_NO_ANCHOR, + /* 16 */ YY_NO_ANCHOR, + /* 17 */ YY_NO_ANCHOR, + /* 18 */ YY_NO_ANCHOR, + /* 19 */ YY_NO_ANCHOR, + /* 20 */ YY_NO_ANCHOR, + /* 21 */ YY_NO_ANCHOR, + /* 22 */ YY_NO_ANCHOR, + /* 23 */ YY_NO_ANCHOR, + /* 24 */ YY_NO_ANCHOR, + /* 25 */ YY_NO_ANCHOR, + /* 26 */ YY_NO_ANCHOR, + /* 27 */ YY_NO_ANCHOR, + /* 28 */ YY_NO_ANCHOR, + /* 29 */ YY_NO_ANCHOR, + /* 30 */ YY_NO_ANCHOR, + /* 31 */ YY_NO_ANCHOR, + /* 32 */ YY_NO_ANCHOR, + /* 33 */ YY_NO_ANCHOR, + /* 34 */ YY_NO_ANCHOR, + /* 35 */ YY_NO_ANCHOR, + /* 36 */ YY_NO_ANCHOR, + /* 37 */ YY_NO_ANCHOR, + /* 38 */ YY_NO_ANCHOR, + /* 39 */ YY_NO_ANCHOR, + /* 40 */ YY_NO_ANCHOR, + /* 41 */ YY_NO_ANCHOR, + /* 42 */ YY_NO_ANCHOR, + /* 43 */ YY_NO_ANCHOR, + /* 44 */ YY_NO_ANCHOR, + /* 45 */ YY_NO_ANCHOR, + /* 46 */ YY_NO_ANCHOR, + /* 47 */ YY_NO_ANCHOR, + /* 48 */ YY_NO_ANCHOR, + /* 49 */ YY_NO_ANCHOR, + /* 50 */ YY_NO_ANCHOR, + /* 51 */ YY_NO_ANCHOR, + /* 52 */ YY_NO_ANCHOR, + /* 53 */ YY_NO_ANCHOR, + /* 54 */ YY_NO_ANCHOR, + /* 55 */ YY_NO_ANCHOR, + /* 56 */ YY_NO_ANCHOR, + /* 57 */ YY_NO_ANCHOR, + /* 58 */ YY_NO_ANCHOR, + /* 59 */ YY_NO_ANCHOR, + /* 60 */ YY_NO_ANCHOR, + /* 61 */ YY_NO_ANCHOR, + /* 62 */ YY_NO_ANCHOR, + /* 63 */ YY_NO_ANCHOR, + /* 64 */ YY_NO_ANCHOR, + /* 65 */ YY_NO_ANCHOR, + /* 66 */ YY_NO_ANCHOR, + /* 67 */ YY_NO_ANCHOR, + /* 68 */ YY_NO_ANCHOR, + /* 69 */ YY_NO_ANCHOR, + /* 70 */ YY_NO_ANCHOR, + /* 71 */ YY_NO_ANCHOR, + /* 72 */ YY_NO_ANCHOR, + /* 73 */ YY_NO_ANCHOR, + /* 74 */ YY_NO_ANCHOR, + /* 75 */ YY_NO_ANCHOR, + /* 76 */ YY_NO_ANCHOR, + /* 77 */ YY_NO_ANCHOR, + /* 78 */ YY_NO_ANCHOR, + /* 79 */ YY_NO_ANCHOR, + /* 80 */ YY_NO_ANCHOR, + /* 81 */ YY_NO_ANCHOR, + /* 82 */ YY_NO_ANCHOR, + /* 83 */ YY_NOT_ACCEPT, + /* 84 */ YY_NO_ANCHOR, + /* 85 */ YY_NO_ANCHOR, + /* 86 */ YY_NO_ANCHOR, + /* 87 */ YY_NO_ANCHOR, + /* 88 */ YY_NO_ANCHOR, + /* 89 */ YY_NO_ANCHOR, + /* 90 */ YY_NO_ANCHOR, + /* 91 */ YY_NO_ANCHOR, + /* 92 */ YY_NO_ANCHOR, + /* 93 */ YY_NO_ANCHOR, + /* 94 */ YY_NO_ANCHOR, + /* 95 */ YY_NO_ANCHOR, + /* 96 */ YY_NO_ANCHOR, + /* 97 */ YY_NO_ANCHOR, + /* 98 */ YY_NO_ANCHOR, + /* 99 */ YY_NO_ANCHOR, + /* 100 */ YY_NO_ANCHOR, + /* 101 */ YY_NO_ANCHOR, + /* 102 */ YY_NO_ANCHOR, + /* 103 */ YY_NO_ANCHOR, + /* 104 */ YY_NO_ANCHOR, + /* 105 */ YY_NO_ANCHOR, + /* 106 */ YY_NO_ANCHOR, + /* 107 */ YY_NO_ANCHOR, + /* 108 */ YY_NO_ANCHOR, + /* 109 */ YY_NO_ANCHOR, + /* 110 */ YY_NO_ANCHOR, + /* 111 */ YY_NO_ANCHOR, + /* 112 */ YY_NO_ANCHOR, + /* 113 */ YY_NO_ANCHOR, + /* 114 */ YY_NO_ANCHOR, + /* 115 */ YY_NO_ANCHOR, + /* 116 */ YY_NO_ANCHOR, + /* 117 */ YY_NO_ANCHOR, + /* 118 */ YY_NO_ANCHOR, + /* 119 */ YY_NO_ANCHOR, + /* 120 */ YY_NO_ANCHOR, + /* 121 */ YY_NO_ANCHOR, + /* 122 */ YY_NO_ANCHOR, + /* 123 */ YY_NO_ANCHOR, + /* 124 */ YY_NO_ANCHOR, + /* 125 */ YY_NO_ANCHOR, + /* 126 */ YY_NO_ANCHOR, + /* 127 */ YY_NO_ANCHOR, + /* 128 */ YY_NO_ANCHOR, + /* 129 */ YY_NO_ANCHOR, + /* 130 */ YY_NO_ANCHOR, + /* 131 */ YY_NOT_ACCEPT, + /* 132 */ YY_NO_ANCHOR, + /* 133 */ YY_NO_ANCHOR, + /* 134 */ YY_NO_ANCHOR, + /* 135 */ YY_NO_ANCHOR, + /* 136 */ YY_NO_ANCHOR, + /* 137 */ YY_NO_ANCHOR, + /* 138 */ YY_NO_ANCHOR, + /* 139 */ YY_NO_ANCHOR, + /* 140 */ YY_NO_ANCHOR, + /* 141 */ YY_NO_ANCHOR, + /* 142 */ YY_NO_ANCHOR, + /* 143 */ YY_NO_ANCHOR, + /* 144 */ YY_NO_ANCHOR, + /* 145 */ YY_NO_ANCHOR, + /* 146 */ YY_NO_ANCHOR, + /* 147 */ YY_NO_ANCHOR, + /* 148 */ YY_NO_ANCHOR, + /* 149 */ YY_NO_ANCHOR, + /* 150 */ YY_NO_ANCHOR, + /* 151 */ YY_NO_ANCHOR, + /* 152 */ YY_NO_ANCHOR, + /* 153 */ YY_NO_ANCHOR, + /* 154 */ YY_NO_ANCHOR, + /* 155 */ YY_NO_ANCHOR, + /* 156 */ YY_NOT_ACCEPT, + /* 157 */ YY_NO_ANCHOR, + /* 158 */ YY_NO_ANCHOR, + /* 159 */ YY_NO_ANCHOR, + /* 160 */ YY_NO_ANCHOR, + /* 161 */ YY_NO_ANCHOR, + /* 162 */ YY_NOT_ACCEPT, + /* 163 */ YY_NO_ANCHOR, + /* 164 */ YY_NO_ANCHOR, + /* 165 */ YY_NO_ANCHOR, + /* 166 */ YY_NO_ANCHOR, + /* 167 */ YY_NO_ANCHOR, + /* 168 */ YY_NOT_ACCEPT, + /* 169 */ YY_NO_ANCHOR, + /* 170 */ YY_NO_ANCHOR, + /* 171 */ YY_NO_ANCHOR, + /* 172 */ YY_NO_ANCHOR, + /* 173 */ YY_NOT_ACCEPT, + /* 174 */ YY_NO_ANCHOR, + /* 175 */ YY_NO_ANCHOR, + /* 176 */ YY_NO_ANCHOR, + /* 177 */ YY_NO_ANCHOR, + /* 178 */ YY_NOT_ACCEPT, + /* 179 */ YY_NO_ANCHOR, + /* 180 */ YY_NO_ANCHOR, + /* 181 */ YY_NO_ANCHOR, + /* 182 */ YY_NO_ANCHOR, + /* 183 */ YY_NOT_ACCEPT, + /* 184 */ YY_NO_ANCHOR, + /* 185 */ YY_NO_ANCHOR, + /* 186 */ YY_NO_ANCHOR, + /* 187 */ YY_NOT_ACCEPT, + /* 188 */ YY_NO_ANCHOR, + /* 189 */ YY_NO_ANCHOR, + /* 190 */ YY_NO_ANCHOR, + /* 191 */ YY_NO_ANCHOR, + /* 192 */ YY_NO_ANCHOR, + /* 193 */ YY_NO_ANCHOR, + /* 194 */ YY_NO_ANCHOR, + /* 195 */ YY_NO_ANCHOR, + /* 196 */ YY_NO_ANCHOR, + /* 197 */ YY_NO_ANCHOR, + /* 198 */ YY_NO_ANCHOR, + /* 199 */ YY_NO_ANCHOR, + /* 200 */ YY_NO_ANCHOR, + /* 201 */ YY_NO_ANCHOR, + /* 202 */ YY_NO_ANCHOR, + /* 203 */ YY_NO_ANCHOR, + /* 204 */ YY_NO_ANCHOR, + /* 205 */ YY_NO_ANCHOR, + /* 206 */ YY_NO_ANCHOR, + /* 207 */ YY_NO_ANCHOR, + /* 208 */ YY_NO_ANCHOR, + /* 209 */ YY_NO_ANCHOR, + /* 210 */ YY_NO_ANCHOR, + /* 211 */ YY_NO_ANCHOR, + /* 212 */ YY_NO_ANCHOR, + /* 213 */ YY_NO_ANCHOR, + /* 214 */ YY_NO_ANCHOR, + /* 215 */ YY_NO_ANCHOR, + /* 216 */ YY_NO_ANCHOR, + /* 217 */ YY_NO_ANCHOR, + /* 218 */ YY_NO_ANCHOR, + /* 219 */ YY_NO_ANCHOR, + /* 220 */ YY_NO_ANCHOR, + /* 221 */ YY_NO_ANCHOR, + /* 222 */ YY_NO_ANCHOR, + /* 223 */ YY_NO_ANCHOR, + /* 224 */ YY_NO_ANCHOR, + /* 225 */ YY_NO_ANCHOR, + /* 226 */ YY_NO_ANCHOR, + /* 227 */ YY_NO_ANCHOR, + /* 228 */ YY_NO_ANCHOR, + /* 229 */ YY_NO_ANCHOR, + /* 230 */ YY_NO_ANCHOR, + /* 231 */ YY_NO_ANCHOR, + /* 232 */ YY_NO_ANCHOR, + /* 233 */ YY_NO_ANCHOR, + /* 234 */ YY_NO_ANCHOR, + /* 235 */ YY_NO_ANCHOR, + /* 236 */ YY_NO_ANCHOR, + /* 237 */ YY_NO_ANCHOR, + /* 238 */ YY_NO_ANCHOR, + /* 239 */ YY_NO_ANCHOR, + /* 240 */ YY_NO_ANCHOR, + /* 241 */ YY_NO_ANCHOR, + /* 242 */ YY_NO_ANCHOR, + /* 243 */ YY_NO_ANCHOR, + /* 244 */ YY_NO_ANCHOR, + /* 245 */ YY_NO_ANCHOR, + /* 246 */ YY_NO_ANCHOR, + /* 247 */ YY_NO_ANCHOR, + /* 248 */ YY_NO_ANCHOR, + /* 249 */ YY_NO_ANCHOR, + /* 250 */ YY_NO_ANCHOR, + /* 251 */ YY_NO_ANCHOR, + /* 252 */ YY_NO_ANCHOR, + /* 253 */ YY_NO_ANCHOR, + /* 254 */ YY_NO_ANCHOR, + /* 255 */ YY_NO_ANCHOR, + /* 256 */ YY_NO_ANCHOR, + /* 257 */ YY_NO_ANCHOR, + /* 258 */ YY_NO_ANCHOR, + /* 259 */ YY_NO_ANCHOR, + /* 260 */ YY_NO_ANCHOR, + /* 261 */ YY_NO_ANCHOR, + /* 262 */ YY_NO_ANCHOR, + /* 263 */ YY_NO_ANCHOR, + /* 264 */ YY_NO_ANCHOR, + /* 265 */ YY_NO_ANCHOR, + /* 266 */ YY_NO_ANCHOR, + /* 267 */ YY_NO_ANCHOR, + /* 268 */ YY_NO_ANCHOR, + /* 269 */ YY_NO_ANCHOR, + /* 270 */ YY_NO_ANCHOR, + /* 271 */ YY_NO_ANCHOR, + /* 272 */ YY_NO_ANCHOR, + /* 273 */ YY_NO_ANCHOR, + /* 274 */ YY_NO_ANCHOR, + /* 275 */ YY_NO_ANCHOR, + /* 276 */ YY_NO_ANCHOR, + /* 277 */ YY_NO_ANCHOR, + /* 278 */ YY_NO_ANCHOR, + /* 279 */ YY_NO_ANCHOR, + /* 280 */ YY_NO_ANCHOR, + /* 281 */ YY_NO_ANCHOR, + /* 282 */ YY_NO_ANCHOR, + /* 283 */ YY_NO_ANCHOR, + /* 284 */ YY_NO_ANCHOR, + /* 285 */ YY_NO_ANCHOR, + /* 286 */ YY_NO_ANCHOR, + /* 287 */ YY_NO_ANCHOR, + /* 288 */ YY_NO_ANCHOR, + /* 289 */ YY_NO_ANCHOR, + /* 290 */ YY_NO_ANCHOR, + /* 291 */ YY_NO_ANCHOR, + /* 292 */ YY_NO_ANCHOR, + /* 293 */ YY_NO_ANCHOR, + /* 294 */ YY_NO_ANCHOR, + /* 295 */ YY_NO_ANCHOR, + /* 296 */ YY_NO_ANCHOR, + /* 297 */ YY_NO_ANCHOR, + /* 298 */ YY_NO_ANCHOR, + /* 299 */ YY_NO_ANCHOR, + /* 300 */ YY_NO_ANCHOR, + /* 301 */ YY_NO_ANCHOR, + /* 302 */ YY_NO_ANCHOR, + /* 303 */ YY_NO_ANCHOR, + /* 304 */ YY_NO_ANCHOR, + /* 305 */ YY_NO_ANCHOR, + /* 306 */ YY_NO_ANCHOR, + /* 307 */ YY_NO_ANCHOR, + /* 308 */ YY_NO_ANCHOR, + /* 309 */ YY_NO_ANCHOR, + /* 310 */ YY_NO_ANCHOR, + /* 311 */ YY_NO_ANCHOR, + /* 312 */ YY_NO_ANCHOR, + /* 313 */ YY_NO_ANCHOR, + /* 314 */ YY_NO_ANCHOR, + /* 315 */ YY_NO_ANCHOR, + /* 316 */ YY_NO_ANCHOR, + /* 317 */ YY_NO_ANCHOR, + /* 318 */ YY_NO_ANCHOR, + /* 319 */ YY_NO_ANCHOR, + /* 320 */ YY_NO_ANCHOR, + /* 321 */ YY_NO_ANCHOR, + /* 322 */ YY_NO_ANCHOR, + /* 323 */ YY_NO_ANCHOR, + /* 324 */ YY_NO_ANCHOR, + /* 325 */ YY_NO_ANCHOR, + /* 326 */ YY_NO_ANCHOR, + /* 327 */ YY_NO_ANCHOR, + /* 328 */ YY_NO_ANCHOR, + /* 329 */ YY_NO_ANCHOR, + /* 330 */ YY_NO_ANCHOR, + /* 331 */ YY_NO_ANCHOR, + /* 332 */ YY_NO_ANCHOR, + /* 333 */ YY_NO_ANCHOR, + /* 334 */ YY_NO_ANCHOR, + /* 335 */ YY_NO_ANCHOR, + /* 336 */ YY_NO_ANCHOR, + /* 337 */ YY_NO_ANCHOR, + /* 338 */ YY_NO_ANCHOR, + /* 339 */ YY_NO_ANCHOR, + /* 340 */ YY_NO_ANCHOR, + /* 341 */ YY_NO_ANCHOR, + /* 342 */ YY_NO_ANCHOR, + /* 343 */ YY_NO_ANCHOR, + /* 344 */ YY_NO_ANCHOR, + /* 345 */ YY_NO_ANCHOR, + /* 346 */ YY_NO_ANCHOR, + /* 347 */ YY_NO_ANCHOR, + /* 348 */ YY_NO_ANCHOR, + /* 349 */ YY_NO_ANCHOR, + /* 350 */ YY_NO_ANCHOR, + /* 351 */ YY_NO_ANCHOR, + /* 352 */ YY_NO_ANCHOR, + /* 353 */ YY_NO_ANCHOR, + /* 354 */ YY_NO_ANCHOR, + /* 355 */ YY_NO_ANCHOR, + /* 356 */ YY_NO_ANCHOR, + /* 357 */ YY_NO_ANCHOR, + /* 358 */ YY_NO_ANCHOR, + /* 359 */ YY_NO_ANCHOR, + /* 360 */ YY_NO_ANCHOR, + /* 361 */ YY_NO_ANCHOR, + /* 362 */ YY_NO_ANCHOR, + /* 363 */ YY_NO_ANCHOR, + /* 364 */ YY_NO_ANCHOR, + /* 365 */ YY_NO_ANCHOR, + /* 366 */ YY_NO_ANCHOR, + /* 367 */ YY_NO_ANCHOR, + /* 368 */ YY_NO_ANCHOR, + /* 369 */ YY_NO_ANCHOR, + /* 370 */ YY_NO_ANCHOR, + /* 371 */ YY_NO_ANCHOR, + /* 372 */ YY_NO_ANCHOR, + /* 373 */ YY_NO_ANCHOR, + /* 374 */ YY_NO_ANCHOR, + /* 375 */ YY_NO_ANCHOR, + /* 376 */ YY_NO_ANCHOR, + /* 377 */ YY_NO_ANCHOR, + /* 378 */ YY_NO_ANCHOR, + /* 379 */ YY_NO_ANCHOR, + /* 380 */ YY_NO_ANCHOR, + /* 381 */ YY_NO_ANCHOR, + /* 382 */ YY_NO_ANCHOR, + /* 383 */ YY_NO_ANCHOR, + /* 384 */ YY_NO_ANCHOR, + /* 385 */ YY_NO_ANCHOR, + /* 386 */ YY_NO_ANCHOR, + /* 387 */ YY_NO_ANCHOR, + /* 388 */ YY_NO_ANCHOR, + /* 389 */ YY_NO_ANCHOR, + /* 390 */ YY_NO_ANCHOR, + /* 391 */ YY_NO_ANCHOR, + /* 392 */ YY_NO_ANCHOR, + /* 393 */ YY_NO_ANCHOR, + /* 394 */ YY_NO_ANCHOR, + /* 395 */ YY_NO_ANCHOR, + /* 396 */ YY_NO_ANCHOR, + /* 397 */ YY_NO_ANCHOR, + /* 398 */ YY_NO_ANCHOR, + /* 399 */ YY_NO_ANCHOR, + /* 400 */ YY_NO_ANCHOR, + /* 401 */ YY_NO_ANCHOR, + /* 402 */ YY_NO_ANCHOR, + /* 403 */ YY_NO_ANCHOR, + /* 404 */ YY_NO_ANCHOR, + /* 405 */ YY_NO_ANCHOR, + /* 406 */ YY_NO_ANCHOR, + /* 407 */ YY_NO_ANCHOR, + /* 408 */ YY_NO_ANCHOR, + /* 409 */ YY_NO_ANCHOR, + /* 410 */ YY_NO_ANCHOR, + /* 411 */ YY_NO_ANCHOR, + /* 412 */ YY_NO_ANCHOR, + /* 413 */ YY_NO_ANCHOR, + /* 414 */ YY_NO_ANCHOR, + /* 415 */ YY_NO_ANCHOR, + /* 416 */ YY_NO_ANCHOR, + /* 417 */ YY_NO_ANCHOR, + /* 418 */ YY_NO_ANCHOR, + /* 419 */ YY_NO_ANCHOR, + /* 420 */ YY_NO_ANCHOR, + /* 421 */ YY_NO_ANCHOR, + /* 422 */ YY_NO_ANCHOR, + /* 423 */ YY_NO_ANCHOR, + /* 424 */ YY_NO_ANCHOR, + /* 425 */ YY_NO_ANCHOR, + /* 426 */ YY_NO_ANCHOR, + /* 427 */ YY_NO_ANCHOR, + /* 428 */ YY_NO_ANCHOR, + /* 429 */ YY_NO_ANCHOR, + /* 430 */ YY_NO_ANCHOR, + /* 431 */ YY_NO_ANCHOR, + /* 432 */ YY_NO_ANCHOR, + /* 433 */ YY_NO_ANCHOR, + /* 434 */ YY_NO_ANCHOR, + /* 435 */ YY_NO_ANCHOR, + /* 436 */ YY_NO_ANCHOR, + /* 437 */ YY_NO_ANCHOR, + /* 438 */ YY_NO_ANCHOR, + /* 439 */ YY_NO_ANCHOR, + /* 440 */ YY_NO_ANCHOR, + /* 441 */ YY_NO_ANCHOR, + /* 442 */ YY_NO_ANCHOR, + /* 443 */ YY_NO_ANCHOR, + /* 444 */ YY_NO_ANCHOR, + /* 445 */ YY_NO_ANCHOR, + /* 446 */ YY_NO_ANCHOR, + /* 447 */ YY_NO_ANCHOR, + /* 448 */ YY_NO_ANCHOR, + /* 449 */ YY_NO_ANCHOR, + /* 450 */ YY_NO_ANCHOR, + /* 451 */ YY_NO_ANCHOR, + /* 452 */ YY_NO_ANCHOR, + /* 453 */ YY_NO_ANCHOR, + /* 454 */ YY_NO_ANCHOR, + /* 455 */ YY_NO_ANCHOR, + /* 456 */ YY_NO_ANCHOR, + /* 457 */ YY_NO_ANCHOR, + /* 458 */ YY_NO_ANCHOR, + /* 459 */ YY_NO_ANCHOR, + /* 460 */ YY_NO_ANCHOR, + /* 461 */ YY_NO_ANCHOR, + /* 462 */ YY_NO_ANCHOR, + /* 463 */ YY_NO_ANCHOR, + /* 464 */ YY_NO_ANCHOR, + /* 465 */ YY_NO_ANCHOR, + /* 466 */ YY_NO_ANCHOR, + /* 467 */ YY_NO_ANCHOR, + /* 468 */ YY_NO_ANCHOR, + /* 469 */ YY_NO_ANCHOR, + /* 470 */ YY_NO_ANCHOR, + /* 471 */ YY_NO_ANCHOR, + /* 472 */ YY_NO_ANCHOR, + /* 473 */ YY_NO_ANCHOR, + /* 474 */ YY_NO_ANCHOR, + /* 475 */ YY_NO_ANCHOR, + /* 476 */ YY_NO_ANCHOR, + /* 477 */ YY_NO_ANCHOR, + /* 478 */ YY_NO_ANCHOR, + /* 479 */ YY_NO_ANCHOR, + /* 480 */ YY_NO_ANCHOR, + /* 481 */ YY_NO_ANCHOR, + /* 482 */ YY_NO_ANCHOR, + /* 483 */ YY_NO_ANCHOR, + /* 484 */ YY_NO_ANCHOR, + /* 485 */ YY_NO_ANCHOR, + /* 486 */ YY_NO_ANCHOR, + /* 487 */ YY_NO_ANCHOR, + /* 488 */ YY_NO_ANCHOR, + /* 489 */ YY_NO_ANCHOR, + /* 490 */ YY_NO_ANCHOR, + /* 491 */ YY_NO_ANCHOR, + /* 492 */ YY_NO_ANCHOR, + /* 493 */ YY_NO_ANCHOR, + /* 494 */ YY_NO_ANCHOR, + /* 495 */ YY_NO_ANCHOR, + /* 496 */ YY_NO_ANCHOR, + /* 497 */ YY_NO_ANCHOR, + /* 498 */ YY_NO_ANCHOR, + /* 499 */ YY_NO_ANCHOR, + /* 500 */ YY_NO_ANCHOR, + /* 501 */ YY_NO_ANCHOR, + /* 502 */ YY_NO_ANCHOR, + /* 503 */ YY_NO_ANCHOR, + /* 504 */ YY_NO_ANCHOR, + /* 505 */ YY_NO_ANCHOR, + /* 506 */ YY_NO_ANCHOR, + /* 507 */ YY_NO_ANCHOR, + /* 508 */ YY_NO_ANCHOR, + /* 509 */ YY_NO_ANCHOR, + /* 510 */ YY_NO_ANCHOR, + /* 511 */ YY_NO_ANCHOR, + /* 512 */ YY_NO_ANCHOR, + /* 513 */ YY_NO_ANCHOR, + /* 514 */ YY_NO_ANCHOR, + /* 515 */ YY_NO_ANCHOR, + /* 516 */ YY_NO_ANCHOR, + /* 517 */ YY_NO_ANCHOR, + /* 518 */ YY_NO_ANCHOR, + /* 519 */ YY_NO_ANCHOR, + /* 520 */ YY_NO_ANCHOR, + /* 521 */ YY_NO_ANCHOR, + /* 522 */ YY_NO_ANCHOR, + /* 523 */ YY_NO_ANCHOR, + /* 524 */ YY_NO_ANCHOR, + /* 525 */ YY_NO_ANCHOR, + /* 526 */ YY_NO_ANCHOR, + /* 527 */ YY_NO_ANCHOR, + /* 528 */ YY_NO_ANCHOR, + /* 529 */ YY_NO_ANCHOR, + /* 530 */ YY_NO_ANCHOR, + /* 531 */ YY_NO_ANCHOR, + /* 532 */ YY_NO_ANCHOR, + /* 533 */ YY_NO_ANCHOR, + /* 534 */ YY_NO_ANCHOR, + /* 535 */ YY_NO_ANCHOR, + /* 536 */ YY_NO_ANCHOR, + /* 537 */ YY_NO_ANCHOR, + /* 538 */ YY_NO_ANCHOR, + /* 539 */ YY_NO_ANCHOR, + /* 540 */ YY_NO_ANCHOR, + /* 541 */ YY_NO_ANCHOR, + /* 542 */ YY_NO_ANCHOR, + /* 543 */ YY_NO_ANCHOR, + /* 544 */ YY_NO_ANCHOR, + /* 545 */ YY_NO_ANCHOR, + /* 546 */ YY_NO_ANCHOR, + /* 547 */ YY_NO_ANCHOR, + /* 548 */ YY_NO_ANCHOR + }; + private int yy_cmap[] = unpackFromString(1,130, +"28:8,58,29,57,28:2,27,28:18,40,50,39,38,41,55,52,37,43:2,25,53,43,54,36,24," + +"31,35:7,30:2,45,43,48,47,49,45,38,34:6,41:5,32,41:11,33,41:2,44,26,44,56,42" + +",28,1,2,6,15,9,16,22,12,13,41,11,8,19,10,7,20,41,5,3,4,14,23,21,17,18,41,44" + +",51,44,46,28,0:2")[0]; + + private int yy_rmap[] = unpackFromString(1,549, +"0,1,2,3,4,5,6,1:2,7:2,8,1:4,9,1:16,7:2,10,7,1,11,1,7:7,12,13,7:2,14,7:2,15," + +"7,1:2,16,7:6,1,7:12,17,18,1,19,20,21,22,23,1,24,25,26:2,27,28,26:2,29,26,1," + +"26:7,30,26:2,31,26:19,32,33,34,35,36,37,1,38,39:2,28,39:9,40,39:5,41,42,43," + +"44,45,46,47,48,49,50,51,52,53,28,54,55,56,57,58,59,60,61,62,63,64,65,66,67," + +"68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92," + +"93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,11" + +"3,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,1" + +"32,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150," + +"151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169" + +",170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,18" + +"8,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,2" + +"07,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225," + +"226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244" + +",245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,26" + +"3,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,2" + +"82,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300," + +"301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319" + +",320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,33" + +"8,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,3" + +"57,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375," + +"376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,39," + +"394,395,39,396,397,398,399,400,401,26,402,403,404,405,406,407,408,409,410,4" + +"11,412,413,414,415,416,417,418,419,420,7,26,421,405,422,423,419,424,425,426" + +",427")[0]; + + private int yy_nxt[][] = unpackFromString(428,59, +"1,2,417,420,267,467,351,538:2,354,271,538:2,84,538,132,274,538:3,471,423,53" + +"8,357,3,85,83,4,-1,4,5,6,538:3,5,7,131,-1,156,4,538:2,7:2,8:2,88,135,159,16" + +"5,133,158,164,170,175,180,4:2,-1:60,538,507,538:21,-1:6,538:6,-1:5,538:2,-1" + +":40,11,12,-1:21,13,-1:38,4,-1,4,-1:10,4,-1:16,4:2,-1:16,15,-1:13,5:2,86,-1:" + +"2,5,16,-1:39,168,-1:13,87,134,168,-1,87,-1:24,538:23,-1:6,538:6,-1:5,538:2," + +"-1:64,178,183,-1:25,15,-1:13,16:2,-1:3,16,-1:24,538:8,496,538:14,-1:6,538:6" + +",-1:5,538:2,-1:17,38:2,-1:3,38,-1:2,38,-1:5,38:2,-1:13,38:2,97,-1,38:2,-1:7" + +"0,56,-1:58,57,-1,58,-1:10,538:2,61,538:20,-1:6,538:6,-1:5,538:2,-1:17,538:7" + +",246,538:15,-1:6,538:6,-1:5,538:2,-1:63,65,-1:11,1,128,419,422,269,469,353," + +"539:2,356,273,539:2,154,539,160,276,539:3,473,425,539,359,166,79,171,539:3," + +"541,543,539:3,541,539,176,539,181,539:7,544:4,545,546,547,548,544:2,539:2,-" + +"1:24,80,-1:22,14,-1:12,508,472,508,538,508:19,167:2,-1:2,167:2,508:6,167:5," + +"508:2,167:14,-1:29,82,-1,82,-1:10,4,-1:16,82:2,-1,162:26,-1,162:29,-1,162,-" + +"1,538:9,169,538:5,9,538:2,435,538:4,-1:6,538:6,-1:5,538:2,-1:63,14,-1:42,87" + +",134,-1:2,87,-1:70,18,-1:12,539:24,-1,539:33,-1,539:24,-1,539:22,531,532,53" + +"9:9,-1,167:3,-1,167:21,-1:2,167:29,-1:3,539:8,498,539:15,-1,539:33,-1,539:2" + +",112,539:21,-1,539:33,-1,539:7,253,539:16,-1,539:33,-1,539,509,539:22,-1,53" + +"9:33,-1,508:3,538,508:5,190,508:5,136,508:2,433,508:4,167:2,-1:2,167:2,508:" + +"6,167:5,508:2,167:14,-1:3,167:3,-1,167:21,-1,82,167,130,167:10,182,167:16,8" + +"2:2,-1,173:25,-1:4,173:7,-1,173,-1:2,173,-1,173,-1,173,-1:2,173:3,-1,173,-1" + +":2,173,-1:4,538:6,10,538,481,538:14,-1:6,538:6,-1:5,538:2,-1:63,22,-1:3,23," + +"-1:54,19,-1:12,508:3,538,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-" + +"1:3,508:3,538,508:3,238,508:15,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1" + +":3,539:9,192,539:5,89,539:2,437,539:5,-1,539:33,-1,508:3,538,508:2,137,508," + +"485,508:14,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,156:25,-1:4,156:7" + +",-1,156,17,156:2,-1,156,-1,156,-1:2,156:3,-1,156,-1:2,156:2,-1:3,538:13,179" + +",538:3,33,538:5,-1:6,538:6,-1:5,538:2,-1:63,24,-1:4,25,-1:53,20,-1:12,539:6" + +",90,539,483,539:15,-1,539:33,-1,167:3,-1,167:19,138,92,-1:2,167:29,-1:59,37" + +",-1:2,538:20,34,538:2,-1:6,538:6,-1:5,538:2,-1:63,26,-1:5,27,-1:52,21,-1:12" + +",539:23,91,12,539:21,518,539:11,-1,38:2,-1:3,38,-1:2,38,-1:5,38:2,-1:13,38:" + +"2,-1:2,38:2,-1:24,538:2,515,35,538:19,-1:6,538:6,-1:5,538:2,-1:63,28,-1,29," + +"-1:4,30,-1:5,520:24,162,520,539,520:29,539,520,-1,167:3,173,167:21,-1:2,167" + +":29,-1:39,39,-1:22,538:4,36,538:18,-1:6,538:6,-1:5,538:2,-1:63,31,-1:12,526" + +":24,173,539:4,526:7,539,526,539:2,526,539,526,539,526,539:2,526:3,539,526,5" + +"39:2,526,539:3,-1,177:3,156,177:21,-1:2,167:2,177:7,167,177,167,177:2,167,1" + +"77,167,177,167:2,177:3,167,177,167:2,177:2,-1:50,47,-1:11,538:8,40,538:14,-" + +"1:6,538:6,-1:5,538:2,-1:63,32,-1:12,181:24,156,539:4,181:7,539,181,518,181:" + +"2,539,181,539,181,539:2,181:3,539,181,539:2,181:2,539:2,-1,167:3,-1,167:21," + +"-1,4,167,182,167:10,182,167:16,4:2,-1:49,48,-1:10,538:2,41,538:20,-1:6,538:" + +"6,-1:5,538:2,-1:17,539:13,527,539:3,93,539:6,-1,539:33,-1,508:3,538,508:16," + +"139,508:2,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:2,1,81,418,421,267,4" + +"24,352,508:2,355,268,508:2,129,508,155,272,508:3,468,427,508,358,161,167,83" + +",82,167,130,167:2,508:3,167:2,172,167,177,182,508:2,167:14,82:2,-1,538:8,42" + +",538:14,-1:6,538:6,-1:5,538:2,-1:17,539:20,94,539:3,-1,539:33,-1,508:2,491," + +"35,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:4,43,538:18,-1" + +":6,538:6,-1:5,538:2,-1:17,539:2,528,95,539:20,-1,539:33,-1,508:3,538,140,50" + +"8:18,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:8,44,538:14,-1:6,53" + +"8:6,-1:5,538:2,-1:17,539:4,96,539:19,-1,539:33,-1,508:3,538,508:4,141,508:1" + +"4,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:7,45,538:15,-1:6,538:6" + +",-1:5,538:2,-1:17,539:2,98,539:21,-1,539:33,-1,508:3,538,142,508:18,167:2,-" + +"1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:14,46,538:8,-1:6,538:6,-1:5,538" + +":2,-1:17,539:8,99,539:15,-1,539:33,-1,508:3,538,508:4,143,508:14,167:2,-1:2" + +",167:2,508:6,167:5,508:2,167:14,-1:3,538:10,49,538:12,-1:6,538:6,-1:5,538:2" + +",-1:17,539:4,100,539:19,-1,539:33,-1,508:3,538,508:10,144,508:8,167:2,-1:2," + +"167:2,508:6,167:5,508:2,167:14,-1:3,538:4,50,538:18,-1:6,538:6,-1:5,538:2,-" + +"1:17,539:8,101,539:15,-1,539:33,-1,508:3,538,508:6,145,508:12,167:2,-1:2,16" + +"7:2,508:6,167:5,508:2,167:14,-1:3,538:20,51,538:2,-1:6,538:6,-1:5,538:2,-1:" + +"17,539:14,102,539:9,-1,539:33,-1,508:3,538,146,508:18,167:2,-1:2,167:2,508:" + +"6,167:5,508:2,167:14,-1:3,538:11,52,538:11,-1:6,538:6,-1:5,538:2,-1:17,539:" + +"10,103,539:13,-1,539:33,-1,508:2,147,538,508:19,167:2,-1:2,167:2,508:6,167:" + +"5,508:2,167:14,-1:3,538:2,53,538:20,-1:6,538:6,-1:5,538:2,-1:17,539:4,104,5" + +"39:19,-1,539:33,-1,508:3,538,508:3,148,508:15,167:2,-1:2,167:2,508:6,167:5," + +"508:2,167:14,-1:3,538:7,54,538:15,-1:6,538:6,-1:5,538:2,-1:17,539:20,105,53" + +"9:3,-1,539:33,-1,508:3,538,508:4,149,508:14,167:2,-1:2,167:2,508:6,167:5,50" + +"8:2,167:14,-1:3,538:8,55,538:14,-1:6,538:6,-1:5,538:2,-1:17,539:11,106,539:" + +"12,-1,539:33,-1,508:3,63,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-" + +"1:3,538:5,59,538:17,-1:6,538:6,-1:5,538:2,-1:17,539:2,107,539:21,-1,539:33," + +"-1,508:3,250,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:11,6" + +"0,538:11,-1:6,538:6,-1:5,538:2,-1:17,539:7,108,539:16,-1,539:33,-1,508:3,53" + +"8,508,150,508:17,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:9,62,53" + +"8:13,-1:6,538:6,-1:5,538:2,-1:17,539:8,109,539:15,-1,539:33,-1,508:3,538,50" + +"8:5,151,508:13,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:3,63,538:" + +"19,-1:6,538:6,-1:5,538:2,-1:17,539:5,110,539:18,-1,539:33,-1,508:3,68,508:1" + +"9,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:5,64,538:17,-1:6,538:6" + +",-1:5,538:2,-1:17,539:11,111,539:12,-1,539:33,-1,508:3,538,508:13,152,508:5" + +",167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:9,66,538:13,-1:6,538:6," + +"-1:5,538:2,-1:17,539:9,113,539:14,-1,539:33,-1,508:3,538,508:4,153,508:14,1" + +"67:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:2,67,538:20,-1:6,538:6,-1" + +":5,538:2,-1:17,539:3,114,539:20,-1,539:33,-1,538:3,68,538:19,-1:6,538:6,-1:" + +"5,538:2,-1:17,539:5,115,539:18,-1,539:33,-1,538:17,69,538:5,-1:6,538:6,-1:5" + +",538:2,-1:17,539:9,116,539:14,-1,539:33,-1,538:8,70,538:14,-1:6,538:6,-1:5," + +"538:2,-1:17,539:2,117,539:21,-1,539:33,-1,538:8,71,538:14,-1:6,538:6,-1:5,5" + +"38:2,-1:17,539:3,118,539:20,-1,539:33,-1,538:3,72,538:19,-1:6,538:6,-1:5,53" + +"8:2,-1:17,539:17,119,539:6,-1,539:33,-1,538:8,73,538:14,-1:6,538:6,-1:5,538" + +":2,-1:17,539:8,120,539:15,-1,539:33,-1,538:8,74,538:14,-1:6,538:6,-1:5,538:" + +"2,-1:17,539:8,121,539:15,-1,539:33,-1,538:14,75,538:8,-1:6,538:6,-1:5,538:2" + +",-1:17,539:3,122,539:20,-1,539:33,-1,538:15,76,538:7,-1:6,538:6,-1:5,538:2," + +"-1:17,539:8,123,539:15,-1,539:33,-1,538:2,77,538:20,-1:6,538:6,-1:5,538:2,-" + +"1:17,539:8,124,539:15,-1,539:33,-1,539:14,125,539:9,-1,539:33,-1,539:15,126" + +",539:8,-1,539:33,-1,539:2,127,539:21,-1,539:33,-1,538:4,157,538:6,277,538:1" + +"1,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:4,186,508:4,482,508:9,167:2,-1:" + +"2,167:2,508:6,167:5,508:2,167:14,-1:3,539:4,185,539:6,279,539:12,-1,539:33," + +"-1,508:3,262,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,538:8,16" + +"3,538:4,289,538:9,-1:6,538:6,-1:5,538:2,-1:17,510,508:2,538,508:2,193,508:5" + +",376,508:10,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:8,189,539:4," + +"516,539:10,-1,539:33,-1,369,538:5,174,538:5,372,538:10,-1:6,538:6,-1:5,538:" + +"2,-1:17,508:2,196,304,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3" + +",540,539:5,195,539:5,371,539:11,-1,539:33,-1,538:4,301,538:7,184,538:10,-1:" + +"6,538:6,-1:5,538:2,-1:17,199,508:2,538,508:19,167:2,-1:2,167:2,508:6,167:5," + +"508:2,167:14,-1:3,539:4,300,539:7,198,539:11,-1,539:33,-1,538:2,188,304,538" + +":19,-1:6,538:6,-1:5,538:2,-1:17,508:2,202,538,508:19,167:2,-1:2,167:2,508:6" + +",167:5,508:2,167:14,-1:3,539:2,201,303,539:20,-1,539:33,-1,191,538:22,-1:6," + +"538:6,-1:5,538:2,-1:17,508:3,538,508:8,205,508:10,167:2,-1:2,167:2,508:6,16" + +"7:5,508:2,167:14,-1:3,204,539:23,-1,539:33,-1,538:2,194,538:20,-1:6,538:6,-" + +"1:5,538:2,-1:17,208,508:2,538,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167" + +":14,-1:3,539:2,207,539:21,-1,539:33,-1,538:7,197,538:15,-1:6,538:6,-1:5,538" + +":2,-1:17,508:3,538,508:4,211,508:14,167:2,-1:2,167:2,508:6,167:5,508:2,167:" + +"14,-1:3,539:12,210,539:11,-1,539:33,-1,538:12,200,538:10,-1:6,538:6,-1:5,53" + +"8:2,-1:17,508:3,322,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,2" + +"13,539:23,-1,539:33,-1,203,538:22,-1:6,538:6,-1:5,538:2,-1:17,508:2,214,538" + +",508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:8,216,539:15,-1," + +"539:33,-1,538:8,206,538:14,-1:6,538:6,-1:5,538:2,-1:17,217,508:2,538,508:19" + +",167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:6,219,539:17,-1,539:33," + +"-1,538:6,209,538:16,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:3,220,508:15," + +"167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:5,222,539:18,-1,539:33,-" + +"1,538:5,212,538:17,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,223,508:18,167:2,-" + +"1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:2,225,539:21,-1,539:33,-1,538:2" + +",215,538:20,-1:6,538:6,-1:5,538:2,-1:17,226,508:2,538,508:19,167:2,-1:2,167" + +":2,508:6,167:5,508:2,167:14,-1:3,228,539:23,-1,539:33,-1,538:2,179,538:20,-" + +"1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:8,229,508:10,167:2,-1:2,167:2,508:" + +"6,167:5,508:2,167:14,-1:3,539:7,231,539:16,-1,539:33,-1,218,538:22,-1:6,538" + +":6,-1:5,538:2,-1:17,232,508:2,538,508:19,167:2,-1:2,167:2,508:6,167:5,508:2" + +",167:14,-1:3,539:12,234,539:11,-1,539:33,-1,538:7,221,538:15,-1:6,538:6,-1:" + +"5,538:2,-1:17,508:3,538,508:3,235,508:15,167:2,-1:2,167:2,508:6,167:5,508:2" + +",167:14,-1:3,539:5,237,539:18,-1,539:33,-1,538:12,224,538:10,-1:6,538:6,-1:" + +"5,538:2,-1:17,508:3,538,508:17,241,508,167:2,-1:2,167:2,508:6,167:5,508:2,1" + +"67:14,-1:3,539:4,240,539:19,-1,539:33,-1,538:5,227,538:17,-1:6,538:6,-1:5,5" + +"38:2,-1:17,508:3,538,508:5,270,508:13,167:2,-1:2,167:2,508:6,167:5,508:2,16" + +"7:14,-1:3,539:4,243,539:19,-1,539:33,-1,538:4,230,538:18,-1:6,538:6,-1:5,53" + +"8:2,-1:17,539:12,245,539:11,-1,539:33,-1,538:4,233,538:18,-1:6,538:6,-1:5,5" + +"38:2,-1:17,247,539:23,-1,539:33,-1,538:12,236,538:10,-1:6,538:6,-1:5,538:2," + +"-1:17,539:14,249,539:9,-1,539:33,-1,239,538:22,-1:6,538:6,-1:5,538:2,-1:17," + +"539:7,251,539:16,-1,539:33,-1,538:14,242,538:8,-1:6,538:6,-1:5,538:2,-1:17," + +"539:21,255,539:2,-1,539:33,-1,538:7,244,538:15,-1:6,538:6,-1:5,538:2,-1:17," + +"539:3,257,539:20,-1,539:33,-1,538:21,248,538,-1:6,538:6,-1:5,538:2,-1:17,53" + +"9:5,259,539:18,-1,539:33,-1,538:3,250,538:19,-1:6,538:6,-1:5,538:2,-1:17,53" + +"9:13,261,539:10,-1,539:33,-1,538:5,252,538:17,-1:6,538:6,-1:5,538:2,-1:17,5" + +"39:5,263,539:18,-1,539:33,-1,538:13,254,538:9,-1:6,538:6,-1:5,538:2,-1:17,5" + +"39:8,264,539:15,-1,539:33,-1,538:5,256,538:17,-1:6,538:6,-1:5,538:2,-1:17,5" + +"39:6,265,539:17,-1,539:33,-1,538:8,258,538:14,-1:6,538:6,-1:5,538:2,-1:17,5" + +"39:3,266,539:20,-1,539:33,-1,538:6,260,538:16,-1:6,538:6,-1:5,538:2,-1:17,5" + +"38:3,262,538:19,-1:6,538:6,-1:5,538:2,-1:17,280,538:5,512,366,538:3,283,538" + +":11,-1:6,538:6,-1:5,538:2,-1:17,275,508:2,538,508:2,479,373,508:3,278,508:1" + +"1,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,282,539:5,513,368,539:3,28" + +"5,539:12,-1,539:33,-1,538:7,286,538:8,478,538:6,-1:6,538:6,-1:5,538:2,-1:17" + +",508:3,538,508:3,281,508:8,430,508:6,167:2,-1:2,167:2,508:6,167:5,508:2,167" + +":14,-1:3,539:7,288,539:8,480,539:7,-1,539:33,-1,538:6,292,538:16,-1:6,538:6" + +",-1:5,538:2,-1:17,508:3,538,508:2,284,508:16,167:2,-1:2,167:2,508:6,167:5,5" + +"08:2,167:14,-1:3,539:6,291,539:17,-1,539:33,-1,538:8,295,538:14,-1:6,538:6," + +"-1:5,538:2,-1:17,508:3,538,508:4,287,508:14,167:2,-1:2,167:2,508:6,167:5,50" + +"8:2,167:14,-1:3,539:8,294,539:15,-1,539:33,-1,538:19,298,538:3,-1:6,538:6,-" + +"1:5,538:2,-1:17,508:3,538,508:15,290,508:3,167:2,-1:2,167:2,508:6,167:5,508" + +":2,167:14,-1:3,539:19,297,539:4,-1,539:33,-1,307,538:22,-1:6,538:6,-1:5,538" + +":2,-1:17,508:3,538,508:8,293,508:10,167:2,-1:2,167:2,508:6,167:5,508:2,167:" + +"14,-1:3,306,539:23,-1,539:33,-1,538:7,310,538:15,-1:6,538:6,-1:5,538:2,-1:1" + +"7,508:3,384,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:9,309" + +",539:14,-1,539:33,-1,538:9,313,538:13,-1:6,538:6,-1:5,538:2,-1:17,296,508:2" + +",538,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:12,312,539:1" + +"1,-1,539:33,-1,538:12,316,538:10,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:" + +"5,299,508:13,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:3,315,539:2" + +"0,-1,539:33,-1,538:3,319,538:19,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:8" + +",302,508:10,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:3,318,539:20" + +",-1,539:33,-1,538:3,322,538:19,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:2," + +"305,500,508:15,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:13,321,53" + +"9:10,-1,539:33,-1,538:13,325,538:9,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,50" + +"8:18,308,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:6,324,535,539:1" + +"6,-1,539:33,-1,538:6,327,521,538:15,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,5" + +"08:3,311,508:15,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:7,326,53" + +"9:16,-1,539:33,-1,538:7,329,538:15,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,50" + +"8:4,314,508:14,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:8,328,539" + +":15,-1,539:33,-1,538:8,331,538:14,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508" + +":9,317,508:9,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:9,330,539:1" + +"4,-1,539:33,-1,538:9,333,538:13,-1:6,538:6,-1:5,538:2,-1:17,320,508:2,538,5" + +"08:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:13,332,539:10,-1,5" + +"39:33,-1,538:13,335,538:9,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:4,323,5" + +"08:14,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,334,539:23,-1,539:33,-" + +"1,337,538:22,-1:6,538:6,-1:5,538:2,-1:17,336,539:23,-1,539:33,-1,339,538:22" + +",-1:6,538:6,-1:5,538:2,-1:17,338,539:23,-1,539:33,-1,341,538:22,-1:6,538:6," + +"-1:5,538:2,-1:17,539:9,340,539:14,-1,539:33,-1,538:9,343,538:13,-1:6,538:6," + +"-1:5,538:2,-1:17,342,539:23,-1,539:33,-1,345,538:22,-1:6,538:6,-1:5,538:2,-" + +"1:17,539:3,344,539:20,-1,539:33,-1,538:3,347,538:19,-1:6,538:6,-1:5,538:2,-" + +"1:17,539:8,346,539:15,-1,539:33,-1,538:8,349,538:14,-1:6,538:6,-1:5,538:2,-" + +"1:17,539:9,348,539:14,-1,539:33,-1,538:9,350,538:13,-1:6,538:6,-1:5,538:2,-" + +"1:17,538:4,360,538,475,538:16,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,361,508" + +",476,508:16,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:4,362,539,47" + +"7,539:17,-1,539:33,-1,538:3,426,538:9,363,538:6,429,538:2,-1:6,538:6,-1:5,5" + +"38:2,-1:17,508:3,426,508:9,364,508:6,367,508:2,167:2,-1:2,167:2,508:6,167:5" + +",508:2,167:14,-1:3,539:3,428,539:9,365,539:6,431,539:3,-1,539:33,-1,538:11," + +"375,538:11,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:4,370,508:14,167:2,-1:" + +"2,167:2,508:6,167:5,508:2,167:14,-1:3,539:11,374,539:12,-1,539:33,-1,378,53" + +"8:22,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:7,379,508:11,167:2,-1:2,167:" + +"2,508:6,167:5,508:2,167:14,-1:3,377,539:23,-1,539:33,-1,538:12,381,538:10,-" + +"1:6,538:6,-1:5,538:2,-1:17,508:3,444,508:19,167:2,-1:2,167:2,508:6,167:5,50" + +"8:2,167:14,-1:3,539:12,380,539:11,-1,539:33,-1,538:3,384,538:19,-1:6,538:6," + +"-1:5,538:2,-1:17,508:3,538,508:15,382,508:3,167:2,-1:2,167:2,508:6,167:5,50" + +"8:2,167:14,-1:3,539:3,383,539:20,-1,539:33,-1,538:19,387,538:3,-1:6,538:6,-" + +"1:5,538:2,-1:17,508:3,538,508:2,497,508:5,385,508:10,167:2,-1:2,167:2,508:6" + +",167:5,508:2,167:14,-1:3,539:19,386,539:4,-1,539:33,-1,538,390,538:21,-1:6," + +"538:6,-1:5,538:2,-1:17,508,388,508,538,508:19,167:2,-1:2,167:2,508:6,167:5," + +"508:2,167:14,-1:3,539,389,539:22,-1,539:33,-1,538:7,393,538:15,-1:6,538:6,-" + +"1:5,538:2,-1:17,508:3,538,508:3,391,508:15,167:2,-1:2,167:2,508:6,167:5,508" + +":2,167:14,-1:3,539:7,392,539:16,-1,539:33,-1,538:8,396,538:14,-1:6,538:6,-1" + +":5,538:2,-1:17,394,508:2,538,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:" + +"14,-1:3,539:8,395,539:15,-1,539:33,-1,399,538:22,-1:6,538:6,-1:5,538:2,-1:1" + +"7,508:3,538,508:6,397,508:12,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3" + +",398,539:23,-1,539:33,-1,538:10,402,538:12,-1:6,538:6,-1:5,538:2,-1:17,508:" + +"3,538,508:14,400,508:4,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:1" + +"0,401,539:13,-1,539:33,-1,538:22,404,-1:6,538:6,-1:5,538:2,-1:17,539:22,403" + +",539,-1,539:33,-1,538:4,406,538:18,-1:6,538:6,-1:5,538:2,-1:17,539:4,405,53" + +"9:19,-1,539:33,-1,538:12,408,538:10,-1:6,538:6,-1:5,538:2,-1:17,539:12,407," + +"539:11,-1,539:33,-1,538:15,410,538:7,-1:6,538:6,-1:5,538:2,-1:17,539:15,409" + +",539:8,-1,539:33,-1,538:5,412,538:17,-1:6,538:6,-1:5,538:2,-1:17,539:5,411," + +"539:18,-1,539:33,-1,538:5,414,538:17,-1:6,538:6,-1:5,538:2,-1:17,539:5,413," + +"539:18,-1,539:33,-1,538:8,416,538:14,-1:6,538:6,-1:5,538:2,-1:17,539:8,415," + +"539:15,-1,539:33,-1,538:8,432,538:14,-1:6,538:6,-1:5,538:2,-1:17,488,508:2," + +"538,436,508:8,439,508:9,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:" + +"8,434,539:15,-1,539:33,-1,508:3,455,508:19,167:2,-1:2,167:2,508:6,167:5,508" + +":2,167:14,-1:3,484,538:3,487,538:8,438,538:9,-1:6,538:6,-1:5,538:2,-1:17,50" + +"8:2,470,538,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,486,539:3" + +",489,539:8,440,539:10,-1,539:33,-1,508:3,457,508:19,167:2,-1:2,167:2,508:6," + +"167:5,508:2,167:14,-1:3,538:6,441,538:16,-1:6,538:6,-1:5,538:2,-1:17,508:3," + +"538,508:2,442,508:16,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:6,4" + +"43,539:17,-1,539:33,-1,538:3,444,538:19,-1:6,538:6,-1:5,538:2,-1:17,508:3,5" + +"38,508:5,474,508:13,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:3,44" + +"6,539:20,-1,539:33,-1,538:15,447,538:7,-1:6,538:6,-1:5,538:2,-1:17,508:3,53" + +"8,508:3,514,508:15,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:15,44" + +"9,539:8,-1,539:33,-1,538:5,450,538:17,-1:6,538:6,-1:5,538:2,-1:17,508:3,538" + +",508:11,445,508:7,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:5,452," + +"539:18,-1,539:33,-1,538:6,517,538:5,453,538:10,-1:6,538:6,-1:5,538:2,-1:17," + +"508:3,538,508,448,508:17,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539" + +":6,530,539:5,454,539:11,-1,539:33,-1,538:3,455,538:19,-1:6,538:6,-1:5,538:2" + +",-1:17,508:3,519,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:" + +"3,456,539:20,-1,539:33,-1,538:3,457,538:19,-1:6,538:6,-1:5,538:2,-1:17,508:" + +"2,503,538,508:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:3,458,5" + +"39:20,-1,539:33,-1,538:4,459,538:18,-1:6,538:6,-1:5,538:2,-1:17,508:3,499,5" + +"08:19,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:4,460,539:19,-1,53" + +"9:33,-1,538:8,461,538:14,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:4,451,50" + +"8:14,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:8,462,539:15,-1,539" + +":33,-1,538:9,463,538:13,-1:6,538:6,-1:5,538:2,-1:17,508:3,538,508:4,511,508" + +":14,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-1:3,539:9,464,539:14,-1,539:" + +"33,-1,538:18,465,538:4,-1:6,538:6,-1:5,538:2,-1:17,539:18,466,539:5,-1,539:" + +"33,-1,538:2,490,538:20,-1:6,538:6,-1:5,538:2,-1:17,539:2,492,539:21,-1,539:" + +"33,-1,508:3,538,508:3,494,508:15,167:2,-1:2,167:2,508:6,167:5,508:2,167:14," + +"-1:3,538:9,493,538:13,-1:6,538:6,-1:5,538:2,-1:17,539:9,495,539:14,-1,539:3" + +"3,-1,508:3,538,508:3,511,508:15,167:2,-1:2,167:2,508:6,167:5,508:2,167:14,-" + +"1:3,538:3,519,538:19,-1:6,538:6,-1:5,538:2,-1:17,539:7,542,539:16,-1,539:33" + +",-1,538:3,499,538:19,-1:6,538:6,-1:5,538:2,-1:17,502,538:22,-1:6,538:6,-1:5" + +",538:2,-1:17,539:24,-1,539:31,518,539,-1,538:8,505,538:14,-1:6,538:6,-1:5,5" + +"38:2,-1:17,539:15,518,539:8,-1,539:4,522:2,518,539:2,522,523,539:22,-1,539:" + +"15,518,539:8,-1,539:4,523:2,539:3,523,539:23,-1,533:2,539:3,533,539:2,533,5" + +"39:5,533:2,539:8,-1,539:4,533:2,539:2,533:2,539:23,-1,539:24,-1,539:5,525,5" + +"18,539:2,525,539:23,-1,539:24,-1,539:11,518,539:21,-1,539:8,518,539:15,-1,5" + +"39:33,-1,539:3,534,539:20,-1,539:33,-1,539:2,527,539:21,-1,539:33,-1,539:3," + +"501,539:20,-1,539:33,-1,539:24,-1,539:22,536,539:10,-1,539:24,-1,539:23,537" + +",539:9,-1,533:2,539:3,533,539:2,533,539:5,533:2,539:8,-1,539:4,533:2,518,53" + +"9,533:2,539:23,-1,504,539:23,-1,539:33,-1,539:8,506,539:15,-1,539:33,-1,539" + +":24,-1,539:21,518,539:11,-1,539:24,-1,539:21,518,539,536,539:9,-1,539:7,529" + +",539:16,-1,539:33,-1,539:7,518,539:16,-1,539:33,-1,539:16,524,539:7,-1,539:" + +"5,525,518,524,539,525,539:23,-1,539:24,-1,539:21,518,539:3,518,539:7,-1,539" + +":24,-1,539:21,518,539:4,518,539:6,-1,539:24,-1,539:21,518,539:5,518,539:5,-" + +"1,539:24,-1,539:21,518,539,518,539:4,518,539:4"); + + public boolean yylex () + throws java.io.IOException { + int yy_lookahead; + int yy_anchor = YY_NO_ANCHOR; + int yy_state = yy_state_dtrans[yy_lexical_state]; + int yy_next_state = YY_NO_STATE; + int yy_last_accept_state = YY_NO_STATE; + boolean yy_initial = true; + int yy_this_accept; + + yy_mark_start(); + yy_this_accept = yy_acpt[yy_state]; + if (YY_NOT_ACCEPT != yy_this_accept) { + yy_last_accept_state = yy_state; + yy_mark_end(); + } + while (true) { + if (yy_initial && yy_at_bol) yy_lookahead = YY_BOL; + else yy_lookahead = yy_advance(); + yy_next_state = YY_F; + yy_next_state = yy_nxt[yy_rmap[yy_state]][yy_cmap[yy_lookahead]]; + if (YY_EOF == yy_lookahead && true == yy_initial) { + + return false; + } + if (YY_F != yy_next_state) { + yy_state = yy_next_state; + yy_initial = false; + yy_this_accept = yy_acpt[yy_state]; + if (YY_NOT_ACCEPT != yy_this_accept) { + yy_last_accept_state = yy_state; + yy_mark_end(); + } + } + else { + if (YY_NO_STATE == yy_last_accept_state) { + throw (new Error("Lexical Error: Unmatched Input.")); + } + else { + yy_anchor = yy_acpt[yy_last_accept_state]; + if (0 != (YY_END & yy_anchor)) { + yy_move_end(); + } + yy_to_mark(); + switch (yy_last_accept_state) { + case 1: + + case -2: + break; + case 2: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -3: + break; + case 3: + { + this.token = new Token(JavaParser.OP, yytext().charAt(0), yyline, yychar);return true; +} + case -4: + break; + case 4: + { /* System.out.print(yytext()); */ } + case -5: + break; + case 5: + { + String lexem = yytext(); + if(lexem.endsWith("L")) + { + lexem = lexem.substring(0, lexem.length() - 1); + this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true; + } + else + { + this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true; + } +} + case -6: + break; + case 6: + { + String lexem = yytext(); + if(lexem.endsWith("L")) + { + lexem = lexem.substring(0, lexem.length() - 1); + this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true; + } + else + { + this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true; + } +} + case -7: + break; + case 7: + { + this.token = new Token(JavaParser.BRACE,yytext().charAt(0), yyline, yychar);return true; +} + case -8: + break; + case 8: + { + this.token = new Token(JavaParser.RELOP,yytext().charAt(0), yyline, yychar);return true; +} + case -9: + break; + case 9: + {this.token = new Token(JavaParser.IF, yytext(), yyline, yychar);return true;} + case -10: + break; + case 10: + {this.token = new Token(JavaParser.DO, yytext(), yyline, yychar);return true;} + case -11: + break; + case 11: + {yybegin(commentsingleline);} + case -12: + break; + case 12: + {yybegin(commentblock);} + case -13: + break; + case 13: + {this.token = new Token(JavaParser.DIVIDEEQUAL, yytext(), yyline, yychar);return true;} + case -14: + break; + case 14: + {this.token = new Token(JavaParser.TIMESEQUAL, yytext(), yyline, yychar);return true;} + case -15: + break; + case 15: + { + this.token = new Token(JavaParser.FLOATLITERAL, yytext(), yyline, yychar);return true; +} + case -16: + break; + case 16: + { + this.token = new Token(JavaParser.DOUBLELITERAL, yytext(), yyline, yychar);return true; +} + case -17: + break; + case 17: + { + this.token = new Token(JavaParser.STRINGLITERAL, yytext(), yyline, yychar);return true; +} + case -18: + break; + case 18: + { this.token = new Token(JavaParser.EQUAL, yytext(), yyline, yychar);return true;} + case -19: + break; + case 19: + { this.token = new Token(JavaParser.LESSEQUAL, yytext(), yyline, yychar);return true;} + case -20: + break; + case 20: + {this.token = new Token(JavaParser.GREATEREQUAL, yytext(), yyline, yychar);return true;} + case -21: + break; + case 21: + {this.token = new Token(JavaParser.NOTEQUAL, yytext(), yyline, yychar);return true;} + case -22: + break; + case 22: + {this.token = new Token(JavaParser.OREQUAL, yytext(), yyline, yychar);return true;} + case -23: + break; + case 23: + {this.token = new Token(JavaParser.LOGICALOR, yytext(), yyline, yychar);return true;} + case -24: + break; + case 24: + {this.token = new Token(JavaParser.ANDEQUAL, yytext(), yyline, yychar);return true;} + case -25: + break; + case 25: + {this.token = new Token(JavaParser.LOGICALAND, yytext(), yyline, yychar);return true;} + case -26: + break; + case 26: + {this.token = new Token(JavaParser.PLUSEQUAL, yytext(), yyline, yychar);return true;} + case -27: + break; + case 27: + {this.token = new Token(JavaParser.INCREMENT, yytext(), yyline, yychar);return true;} + case -28: + break; + case 28: + {this.token = new Token(JavaParser.MINUSEQUAL, yytext(), yyline, yychar);return true;} + case -29: + break; + case 29: + {this.token = new Token(JavaParser.LAMBDAASSIGNMENT, yytext(), yyline, yychar);return true;} + case -30: + break; + case 30: + {this.token = new Token(JavaParser.DECREMENT, yytext(), yyline, yychar);return true;} + case -31: + break; + case 31: + {this.token = new Token(JavaParser.MODULOEQUAL, yytext(), yyline, yychar);return true;} + case -32: + break; + case 32: + {this.token = new Token(JavaParser.XOREQUAL, yytext(), yyline, yychar);return true;} + case -33: + break; + case 33: + {this.token = new Token(JavaParser.TRY, yytext(), yyline, yychar);return true;} + case -34: + break; + case 34: + {this.token = new Token(JavaParser.NEW, yytext(), yyline, yychar);return true;} + case -35: + break; + case 35: + {this.token = new Token(JavaParser.INT, yytext(), yyline, yychar);return true;} + case -36: + break; + case 36: + {this.token = new Token(JavaParser.FOR, yytext(), yyline, yychar);return true;} + case -37: + break; + case 37: + {org.apache.log4j.Logger.getLogger("parser").debug("Kommentar: "+yytext());} + case -38: + break; + case 38: + { + String lexem = yytext(); + if(lexem.endsWith("L")) + { + lexem = lexem.substring(0, lexem.length() - 1); + this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true; + } + else + { + this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true; + } +} + case -39: + break; + case 39: + { + this.token = new Token(JavaParser.CHARLITERAL, yytext(), yyline, yychar);return true; +} + case -40: + break; + case 40: + { + this.token = new Token(JavaParser.BOOLLITERAL, yytext(), yyline, yychar);return true; +} + case -41: + break; + case 41: + {this.token = new Token(JavaParser.THIS, yytext(), yyline,yychar);return true;} + case -42: + break; + case 42: + {this.token = new Token(JavaParser.CASE, yytext(), yyline, yychar);return true;} + case -43: + break; + case 43: + {this.token = new Token(JavaParser.CHAR, yytext(), yyline, yychar);return true;} + case -44: + break; + case 44: + {this.token = new Token(JavaParser.ELSE, yytext(), yyline, yychar);return true;} + case -45: + break; + case 45: + { + this.token = new Token(JavaParser.JNULL, yytext(), yyline, yychar);return true; +} + case -46: + break; + case 46: + {this.token = new Token(JavaParser.VOID, yytext(), yyline, yychar);return true;} + case -47: + break; + case 47: + {this.token = new Token(JavaParser.SHIFTLEFT, yytext(), yyline, yychar);return true;} + case -48: + break; + case 48: + {this.token = new Token(JavaParser.SHIFTRIGHT, yytext(), yyline, yychar);return true;} + case -49: + break; + case 49: + {this.token = new Token(JavaParser.BREAK, yytext(), yyline, yychar);return true;} + case -50: + break; + case 50: + {this.token = new Token(JavaParser.SUPER, yytext(), yyline, yychar);return true;} + case -51: + break; + case 51: + {this.token = new Token(JavaParser.THROW, yytext(), yyline, yychar);return true;} + case -52: + break; + case 52: + {this.token = new Token(JavaParser.CATCH, yytext(), yyline, yychar);return true;} + case -53: + break; + case 53: + {this.token = new Token(JavaParser.CLASS, yytext(), yyline, yychar);return true;} + case -54: + break; + case 54: + {this.token = new Token(JavaParser.FINAL, yytext(), yyline, yychar);return true;} + case -55: + break; + case 55: + {this.token = new Token(JavaParser.WHILE, yytext(), yyline, yychar);return true;} + case -56: + break; + case 56: + {this.token = new Token(JavaParser.SHIFTLEFTEQUAL, yytext(), yyline, yychar);return true;} + case -57: + break; + case 57: + {this.token = new Token(JavaParser.SIGNEDSHIFTRIGHTEQUAL, yytext(), yyline, yychar);return true;} + case -58: + break; + case 58: + {this.token = new Token(JavaParser.UNSIGNEDSHIFTRIGHT, yytext(), yyline, yychar);return true;} + case -59: + break; + case 59: + {this.token = new Token(JavaParser.STATIC, yytext(), yyline, yychar);return true;} + case -60: + break; + case 60: + {this.token = new Token(JavaParser.SWITCH, yytext(), yyline, yychar);return true;} + case -61: + break; + case 61: + {this.token = new Token(JavaParser.THROWS, yytext(), yyline, yychar);return true;} + case -62: + break; + case 62: + {this.token = new Token(JavaParser.RETURN, yytext(), yyline, yychar);return true;} + case -63: + break; + case 63: + {this.token = new Token(JavaParser.IMPORT, yytext(), yyline, yychar);return true;} + case -64: + break; + case 64: + {this.token = new Token(JavaParser.PUBLIC, yytext(), yyline, yychar);return true;} + case -65: + break; + case 65: + {this.token = new Token(JavaParser.UNSIGNEDSHIFTRIGHTEQUAL, yytext(), yyline, yychar);return true;} + case -66: + break; + case 66: + {this.token = new Token(JavaParser.BOOLEAN, yytext(), yyline, yychar);return true;} + case -67: + break; + case 67: + {this.token = new Token(JavaParser.EXTENDS, yytext(), yyline, yychar);return true;} + case -68: + break; + case 68: + {this.token = new Token(JavaParser.DEFAULT, yytext(), yyline, yychar);return true;} + case -69: + break; + case 69: + {this.token = new Token(JavaParser.FINALLY, yytext(), yyline, yychar);return true;} + case -70: + break; + case 70: + {this.token = new Token(JavaParser.PACKAGE, yytext(), yyline, yychar);return true;} + case -71: + break; + case 71: + {this.token = new Token(JavaParser.PRIVATE, yytext(), yyline, yychar);return true;} + case -72: + break; + case 72: + {this.token = new Token(JavaParser.ABSTRACT, yytext(), yyline, yychar);return true;} + case -73: + break; + case 73: + {this.token = new Token(JavaParser.CONTINUE, yytext(), yyline, yychar);return true;} + case -74: + break; + case 74: + {this.token = new Token(JavaParser.INTERFACE, yytext(), yyline, yychar);return true;} + case -75: + break; + case 75: + {this.token = new Token(JavaParser.PROTECTED, yytext(), yyline, yychar);return true;} + case -76: + break; + case 76: + {this.token = new Token(JavaParser.INSTANCEOF, yytext(), yyline, yychar);return true;} + case -77: + break; + case 77: + {this.token = new Token(JavaParser.IMPLEMENTS, yytext(), yyline, yychar);return true;} + case -78: + break; + case 78: + {} + case -79: + break; + case 79: + {} + case -80: + break; + case 80: + {yybegin(YYINITIAL);} + case -81: + break; + case 81: + {} + case -82: + break; + case 82: + {yybegin(YYINITIAL);} + case -83: + break; + case 84: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -84: + break; + case 85: + { + this.token = new Token(JavaParser.OP, yytext().charAt(0), yyline, yychar);return true; +} + case -85: + break; + case 86: + { + String lexem = yytext(); + if(lexem.endsWith("L")) + { + lexem = lexem.substring(0, lexem.length() - 1); + this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true; + } + else + { + this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true; + } +} + case -86: + break; + case 87: + { + String lexem = yytext(); + if(lexem.endsWith("L")) + { + lexem = lexem.substring(0, lexem.length() - 1); + this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true; + } + else + { + this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true; + } +} + case -87: + break; + case 88: + { + this.token = new Token(JavaParser.RELOP,yytext().charAt(0), yyline, yychar);return true; +} + case -88: + break; + case 89: + {this.token = new Token(JavaParser.IF, yytext(), yyline, yychar);return true;} + case -89: + break; + case 90: + {this.token = new Token(JavaParser.DO, yytext(), yyline, yychar);return true;} + case -90: + break; + case 91: + {yybegin(commentsingleline);} + case -91: + break; + case 92: + {yybegin(commentblock);} + case -92: + break; + case 93: + {this.token = new Token(JavaParser.TRY, yytext(), yyline, yychar);return true;} + case -93: + break; + case 94: + {this.token = new Token(JavaParser.NEW, yytext(), yyline, yychar);return true;} + case -94: + break; + case 95: + {this.token = new Token(JavaParser.INT, yytext(), yyline, yychar);return true;} + case -95: + break; + case 96: + {this.token = new Token(JavaParser.FOR, yytext(), yyline, yychar);return true;} + case -96: + break; + case 97: + { + String lexem = yytext(); + if(lexem.endsWith("L")) + { + lexem = lexem.substring(0, lexem.length() - 1); + this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true; + } + else + { + this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true; + } +} + case -97: + break; + case 98: + {this.token = new Token(JavaParser.THIS, yytext(), yyline,yychar);return true;} + case -98: + break; + case 99: + {this.token = new Token(JavaParser.CASE, yytext(), yyline, yychar);return true;} + case -99: + break; + case 100: + {this.token = new Token(JavaParser.CHAR, yytext(), yyline, yychar);return true;} + case -100: + break; + case 101: + {this.token = new Token(JavaParser.ELSE, yytext(), yyline, yychar);return true;} + case -101: + break; + case 102: + {this.token = new Token(JavaParser.VOID, yytext(), yyline, yychar);return true;} + case -102: + break; + case 103: + {this.token = new Token(JavaParser.BREAK, yytext(), yyline, yychar);return true;} + case -103: + break; + case 104: + {this.token = new Token(JavaParser.SUPER, yytext(), yyline, yychar);return true;} + case -104: + break; + case 105: + {this.token = new Token(JavaParser.THROW, yytext(), yyline, yychar);return true;} + case -105: + break; + case 106: + {this.token = new Token(JavaParser.CATCH, yytext(), yyline, yychar);return true;} + case -106: + break; + case 107: + {this.token = new Token(JavaParser.CLASS, yytext(), yyline, yychar);return true;} + case -107: + break; + case 108: + {this.token = new Token(JavaParser.FINAL, yytext(), yyline, yychar);return true;} + case -108: + break; + case 109: + {this.token = new Token(JavaParser.WHILE, yytext(), yyline, yychar);return true;} + case -109: + break; + case 110: + {this.token = new Token(JavaParser.STATIC, yytext(), yyline, yychar);return true;} + case -110: + break; + case 111: + {this.token = new Token(JavaParser.SWITCH, yytext(), yyline, yychar);return true;} + case -111: + break; + case 112: + {this.token = new Token(JavaParser.THROWS, yytext(), yyline, yychar);return true;} + case -112: + break; + case 113: + {this.token = new Token(JavaParser.RETURN, yytext(), yyline, yychar);return true;} + case -113: + break; + case 114: + {this.token = new Token(JavaParser.IMPORT, yytext(), yyline, yychar);return true;} + case -114: + break; + case 115: + {this.token = new Token(JavaParser.PUBLIC, yytext(), yyline, yychar);return true;} + case -115: + break; + case 116: + {this.token = new Token(JavaParser.BOOLEAN, yytext(), yyline, yychar);return true;} + case -116: + break; + case 117: + {this.token = new Token(JavaParser.EXTENDS, yytext(), yyline, yychar);return true;} + case -117: + break; + case 118: + {this.token = new Token(JavaParser.DEFAULT, yytext(), yyline, yychar);return true;} + case -118: + break; + case 119: + {this.token = new Token(JavaParser.FINALLY, yytext(), yyline, yychar);return true;} + case -119: + break; + case 120: + {this.token = new Token(JavaParser.PACKAGE, yytext(), yyline, yychar);return true;} + case -120: + break; + case 121: + {this.token = new Token(JavaParser.PRIVATE, yytext(), yyline, yychar);return true;} + case -121: + break; + case 122: + {this.token = new Token(JavaParser.ABSTRACT, yytext(), yyline, yychar);return true;} + case -122: + break; + case 123: + {this.token = new Token(JavaParser.CONTINUE, yytext(), yyline, yychar);return true;} + case -123: + break; + case 124: + {this.token = new Token(JavaParser.INTERFACE, yytext(), yyline, yychar);return true;} + case -124: + break; + case 125: + {this.token = new Token(JavaParser.PROTECTED, yytext(), yyline, yychar);return true;} + case -125: + break; + case 126: + {this.token = new Token(JavaParser.INSTANCEOF, yytext(), yyline, yychar);return true;} + case -126: + break; + case 127: + {this.token = new Token(JavaParser.IMPLEMENTS, yytext(), yyline, yychar);return true;} + case -127: + break; + case 128: + {} + case -128: + break; + case 129: + {} + case -129: + break; + case 130: + {yybegin(YYINITIAL);} + case -130: + break; + case 132: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -131: + break; + case 133: + { + this.token = new Token(JavaParser.OP, yytext().charAt(0), yyline, yychar);return true; +} + case -132: + break; + case 134: + { + String lexem = yytext(); + if(lexem.endsWith("L")) + { + lexem = lexem.substring(0, lexem.length() - 1); + this.token = new Token(JavaParser.LONGLITERAL, lexem, yyline, yychar);return true; + } + else + { + this.token = new Token(JavaParser.INTLITERAL, lexem, yyline, yychar);return true; + } +} + case -133: + break; + case 135: + { + this.token = new Token(JavaParser.RELOP,yytext().charAt(0), yyline, yychar);return true; +} + case -134: + break; + case 136: + {this.token = new Token(JavaParser.IF, yytext(), yyline, yychar);return true;} + case -135: + break; + case 137: + {this.token = new Token(JavaParser.DO, yytext(), yyline, yychar);return true;} + case -136: + break; + case 138: + {yybegin(commentsingleline);} + case -137: + break; + case 139: + {this.token = new Token(JavaParser.NEW, yytext(), yyline, yychar);return true;} + case -138: + break; + case 140: + {this.token = new Token(JavaParser.FOR, yytext(), yyline, yychar);return true;} + case -139: + break; + case 141: + {this.token = new Token(JavaParser.CASE, yytext(), yyline, yychar);return true;} + case -140: + break; + case 142: + {this.token = new Token(JavaParser.CHAR, yytext(), yyline, yychar);return true;} + case -141: + break; + case 143: + {this.token = new Token(JavaParser.ELSE, yytext(), yyline, yychar);return true;} + case -142: + break; + case 144: + {this.token = new Token(JavaParser.VOID, yytext(), yyline, yychar);return true;} + case -143: + break; + case 145: + {this.token = new Token(JavaParser.BREAK, yytext(), yyline, yychar);return true;} + case -144: + break; + case 146: + {this.token = new Token(JavaParser.SUPER, yytext(), yyline, yychar);return true;} + case -145: + break; + case 147: + {this.token = new Token(JavaParser.CLASS, yytext(), yyline, yychar);return true;} + case -146: + break; + case 148: + {this.token = new Token(JavaParser.FINAL, yytext(), yyline, yychar);return true;} + case -147: + break; + case 149: + {this.token = new Token(JavaParser.WHILE, yytext(), yyline, yychar);return true;} + case -148: + break; + case 150: + {this.token = new Token(JavaParser.PUBLIC, yytext(), yyline, yychar);return true;} + case -149: + break; + case 151: + {this.token = new Token(JavaParser.BOOLEAN, yytext(), yyline, yychar);return true;} + case -150: + break; + case 152: + {this.token = new Token(JavaParser.FINALLY, yytext(), yyline, yychar);return true;} + case -151: + break; + case 153: + {this.token = new Token(JavaParser.PACKAGE, yytext(), yyline, yychar);return true;} + case -152: + break; + case 154: + {} + case -153: + break; + case 155: + {} + case -154: + break; + case 157: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -155: + break; + case 158: + { + this.token = new Token(JavaParser.OP, yytext().charAt(0), yyline, yychar);return true; +} + case -156: + break; + case 159: + { + this.token = new Token(JavaParser.RELOP,yytext().charAt(0), yyline, yychar);return true; +} + case -157: + break; + case 160: + {} + case -158: + break; + case 161: + {} + case -159: + break; + case 163: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -160: + break; + case 164: + { + this.token = new Token(JavaParser.OP, yytext().charAt(0), yyline, yychar);return true; +} + case -161: + break; + case 165: + { + this.token = new Token(JavaParser.RELOP,yytext().charAt(0), yyline, yychar);return true; +} + case -162: + break; + case 166: + {} + case -163: + break; + case 167: + {} + case -164: + break; + case 169: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -165: + break; + case 170: + { + this.token = new Token(JavaParser.OP, yytext().charAt(0), yyline, yychar);return true; +} + case -166: + break; + case 171: + {} + case -167: + break; + case 172: + {} + case -168: + break; + case 174: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -169: + break; + case 175: + { + this.token = new Token(JavaParser.OP, yytext().charAt(0), yyline, yychar);return true; +} + case -170: + break; + case 176: + {} + case -171: + break; + case 177: + {} + case -172: + break; + case 179: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -173: + break; + case 180: + { + this.token = new Token(JavaParser.OP, yytext().charAt(0), yyline, yychar);return true; +} + case -174: + break; + case 181: + {} + case -175: + break; + case 182: + {} + case -176: + break; + case 184: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -177: + break; + case 185: + {} + case -178: + break; + case 186: + {} + case -179: + break; + case 188: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -180: + break; + case 189: + {} + case -181: + break; + case 190: + {} + case -182: + break; + case 191: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -183: + break; + case 192: + {} + case -184: + break; + case 193: + {} + case -185: + break; + case 194: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -186: + break; + case 195: + {} + case -187: + break; + case 196: + {} + case -188: + break; + case 197: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -189: + break; + case 198: + {} + case -190: + break; + case 199: + {} + case -191: + break; + case 200: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -192: + break; + case 201: + {} + case -193: + break; + case 202: + {} + case -194: + break; + case 203: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -195: + break; + case 204: + {} + case -196: + break; + case 205: + {} + case -197: + break; + case 206: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -198: + break; + case 207: + {} + case -199: + break; + case 208: + {} + case -200: + break; + case 209: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -201: + break; + case 210: + {} + case -202: + break; + case 211: + {} + case -203: + break; + case 212: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -204: + break; + case 213: + {} + case -205: + break; + case 214: + {} + case -206: + break; + case 215: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -207: + break; + case 216: + {} + case -208: + break; + case 217: + {} + case -209: + break; + case 218: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -210: + break; + case 219: + {} + case -211: + break; + case 220: + {} + case -212: + break; + case 221: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -213: + break; + case 222: + {} + case -214: + break; + case 223: + {} + case -215: + break; + case 224: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -216: + break; + case 225: + {} + case -217: + break; + case 226: + {} + case -218: + break; + case 227: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -219: + break; + case 228: + {} + case -220: + break; + case 229: + {} + case -221: + break; + case 230: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -222: + break; + case 231: + {} + case -223: + break; + case 232: + {} + case -224: + break; + case 233: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -225: + break; + case 234: + {} + case -226: + break; + case 235: + {} + case -227: + break; + case 236: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -228: + break; + case 237: + {} + case -229: + break; + case 238: + {} + case -230: + break; + case 239: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -231: + break; + case 240: + {} + case -232: + break; + case 241: + {} + case -233: + break; + case 242: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -234: + break; + case 243: + {} + case -235: + break; + case 244: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -236: + break; + case 245: + {} + case -237: + break; + case 246: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -238: + break; + case 247: + {} + case -239: + break; + case 248: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -240: + break; + case 249: + {} + case -241: + break; + case 250: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -242: + break; + case 251: + {} + case -243: + break; + case 252: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -244: + break; + case 253: + {} + case -245: + break; + case 254: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -246: + break; + case 255: + {} + case -247: + break; + case 256: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -248: + break; + case 257: + {} + case -249: + break; + case 258: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -250: + break; + case 259: + {} + case -251: + break; + case 260: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -252: + break; + case 261: + {} + case -253: + break; + case 262: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -254: + break; + case 263: + {} + case -255: + break; + case 264: + {} + case -256: + break; + case 265: + {} + case -257: + break; + case 266: + {} + case -258: + break; + case 267: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -259: + break; + case 268: + {} + case -260: + break; + case 269: + {} + case -261: + break; + case 270: + {} + case -262: + break; + case 271: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -263: + break; + case 272: + {} + case -264: + break; + case 273: + {} + case -265: + break; + case 274: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -266: + break; + case 275: + {} + case -267: + break; + case 276: + {} + case -268: + break; + case 277: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -269: + break; + case 278: + {} + case -270: + break; + case 279: + {} + case -271: + break; + case 280: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -272: + break; + case 281: + {} + case -273: + break; + case 282: + {} + case -274: + break; + case 283: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -275: + break; + case 284: + {} + case -276: + break; + case 285: + {} + case -277: + break; + case 286: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -278: + break; + case 287: + {} + case -279: + break; + case 288: + {} + case -280: + break; + case 289: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -281: + break; + case 290: + {} + case -282: + break; + case 291: + {} + case -283: + break; + case 292: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -284: + break; + case 293: + {} + case -285: + break; + case 294: + {} + case -286: + break; + case 295: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -287: + break; + case 296: + {} + case -288: + break; + case 297: + {} + case -289: + break; + case 298: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -290: + break; + case 299: + {} + case -291: + break; + case 300: + {} + case -292: + break; + case 301: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -293: + break; + case 302: + {} + case -294: + break; + case 303: + {} + case -295: + break; + case 304: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -296: + break; + case 305: + {} + case -297: + break; + case 306: + {} + case -298: + break; + case 307: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -299: + break; + case 308: + {} + case -300: + break; + case 309: + {} + case -301: + break; + case 310: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -302: + break; + case 311: + {} + case -303: + break; + case 312: + {} + case -304: + break; + case 313: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -305: + break; + case 314: + {} + case -306: + break; + case 315: + {} + case -307: + break; + case 316: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -308: + break; + case 317: + {} + case -309: + break; + case 318: + {} + case -310: + break; + case 319: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -311: + break; + case 320: + {} + case -312: + break; + case 321: + {} + case -313: + break; + case 322: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -314: + break; + case 323: + {} + case -315: + break; + case 324: + {} + case -316: + break; + case 325: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -317: + break; + case 326: + {} + case -318: + break; + case 327: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -319: + break; + case 328: + {} + case -320: + break; + case 329: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -321: + break; + case 330: + {} + case -322: + break; + case 331: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -323: + break; + case 332: + {} + case -324: + break; + case 333: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -325: + break; + case 334: + {} + case -326: + break; + case 335: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -327: + break; + case 336: + {} + case -328: + break; + case 337: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -329: + break; + case 338: + {} + case -330: + break; + case 339: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -331: + break; + case 340: + {} + case -332: + break; + case 341: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -333: + break; + case 342: + {} + case -334: + break; + case 343: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -335: + break; + case 344: + {} + case -336: + break; + case 345: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -337: + break; + case 346: + {} + case -338: + break; + case 347: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -339: + break; + case 348: + {} + case -340: + break; + case 349: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -341: + break; + case 350: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -342: + break; + case 351: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -343: + break; + case 352: + {} + case -344: + break; + case 353: + {} + case -345: + break; + case 354: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -346: + break; + case 355: + {} + case -347: + break; + case 356: + {} + case -348: + break; + case 357: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -349: + break; + case 358: + {} + case -350: + break; + case 359: + {} + case -351: + break; + case 360: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -352: + break; + case 361: + {} + case -353: + break; + case 362: + {} + case -354: + break; + case 363: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -355: + break; + case 364: + {} + case -356: + break; + case 365: + {} + case -357: + break; + case 366: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -358: + break; + case 367: + {} + case -359: + break; + case 368: + {} + case -360: + break; + case 369: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -361: + break; + case 370: + {} + case -362: + break; + case 371: + {} + case -363: + break; + case 372: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -364: + break; + case 373: + {} + case -365: + break; + case 374: + {} + case -366: + break; + case 375: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -367: + break; + case 376: + {} + case -368: + break; + case 377: + {} + case -369: + break; + case 378: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -370: + break; + case 379: + {} + case -371: + break; + case 380: + {} + case -372: + break; + case 381: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -373: + break; + case 382: + {} + case -374: + break; + case 383: + {} + case -375: + break; + case 384: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -376: + break; + case 385: + {} + case -377: + break; + case 386: + {} + case -378: + break; + case 387: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -379: + break; + case 388: + {} + case -380: + break; + case 389: + {} + case -381: + break; + case 390: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -382: + break; + case 391: + {} + case -383: + break; + case 392: + {} + case -384: + break; + case 393: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -385: + break; + case 394: + {} + case -386: + break; + case 395: + {} + case -387: + break; + case 396: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -388: + break; + case 397: + {} + case -389: + break; + case 398: + {} + case -390: + break; + case 399: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -391: + break; + case 400: + {} + case -392: + break; + case 401: + {} + case -393: + break; + case 402: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -394: + break; + case 403: + {} + case -395: + break; + case 404: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -396: + break; + case 405: + {} + case -397: + break; + case 406: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -398: + break; + case 407: + {} + case -399: + break; + case 408: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -400: + break; + case 409: + {} + case -401: + break; + case 410: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -402: + break; + case 411: + {} + case -403: + break; + case 412: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -404: + break; + case 413: + {} + case -405: + break; + case 414: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -406: + break; + case 415: + {} + case -407: + break; + case 416: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -408: + break; + case 417: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -409: + break; + case 418: + {} + case -410: + break; + case 419: + {} + case -411: + break; + case 420: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -412: + break; + case 421: + {} + case -413: + break; + case 422: + {} + case -414: + break; + case 423: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -415: + break; + case 424: + {} + case -416: + break; + case 425: + {} + case -417: + break; + case 426: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -418: + break; + case 427: + {} + case -419: + break; + case 428: + {} + case -420: + break; + case 429: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -421: + break; + case 430: + {} + case -422: + break; + case 431: + {} + case -423: + break; + case 432: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -424: + break; + case 433: + {} + case -425: + break; + case 434: + {} + case -426: + break; + case 435: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -427: + break; + case 436: + {} + case -428: + break; + case 437: + {} + case -429: + break; + case 438: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -430: + break; + case 439: + {} + case -431: + break; + case 440: + {} + case -432: + break; + case 441: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -433: + break; + case 442: + {} + case -434: + break; + case 443: + {} + case -435: + break; + case 444: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -436: + break; + case 445: + {} + case -437: + break; + case 446: + {} + case -438: + break; + case 447: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -439: + break; + case 448: + {} + case -440: + break; + case 449: + {} + case -441: + break; + case 450: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -442: + break; + case 451: + {} + case -443: + break; + case 452: + {} + case -444: + break; + case 453: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -445: + break; + case 454: + {} + case -446: + break; + case 455: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -447: + break; + case 456: + {} + case -448: + break; + case 457: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -449: + break; + case 458: + {} + case -450: + break; + case 459: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -451: + break; + case 460: + {} + case -452: + break; + case 461: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -453: + break; + case 462: + {} + case -454: + break; + case 463: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -455: + break; + case 464: + {} + case -456: + break; + case 465: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -457: + break; + case 466: + {} + case -458: + break; + case 467: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -459: + break; + case 468: + {} + case -460: + break; + case 469: + {} + case -461: + break; + case 470: + {} + case -462: + break; + case 471: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -463: + break; + case 472: + {} + case -464: + break; + case 473: + {} + case -465: + break; + case 474: + {} + case -466: + break; + case 475: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -467: + break; + case 476: + {} + case -468: + break; + case 477: + {} + case -469: + break; + case 478: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -470: + break; + case 479: + {} + case -471: + break; + case 480: + {} + case -472: + break; + case 481: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -473: + break; + case 482: + {} + case -474: + break; + case 483: + {} + case -475: + break; + case 484: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -476: + break; + case 485: + {} + case -477: + break; + case 486: + {} + case -478: + break; + case 487: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -479: + break; + case 488: + {} + case -480: + break; + case 489: + {} + case -481: + break; + case 490: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -482: + break; + case 491: + {} + case -483: + break; + case 492: + {} + case -484: + break; + case 493: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -485: + break; + case 494: + {} + case -486: + break; + case 495: + {} + case -487: + break; + case 496: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -488: + break; + case 497: + {} + case -489: + break; + case 498: + {} + case -490: + break; + case 499: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -491: + break; + case 500: + {} + case -492: + break; + case 501: + {} + case -493: + break; + case 502: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -494: + break; + case 503: + {} + case -495: + break; + case 504: + {} + case -496: + break; + case 505: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -497: + break; + case 506: + {} + case -498: + break; + case 507: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -499: + break; + case 508: + {} + case -500: + break; + case 509: + {} + case -501: + break; + case 510: + {} + case -502: + break; + case 511: + {} + case -503: + break; + case 512: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -504: + break; + case 513: + {} + case -505: + break; + case 514: + {} + case -506: + break; + case 515: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -507: + break; + case 516: + {} + case -508: + break; + case 517: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -509: + break; + case 518: + {} + case -510: + break; + case 519: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -511: + break; + case 520: + {} + case -512: + break; + case 521: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -513: + break; + case 522: + {} + case -514: + break; + case 523: + {} + case -515: + break; + case 524: + {} + case -516: + break; + case 525: + {} + case -517: + break; + case 526: + {} + case -518: + break; + case 527: + {} + case -519: + break; + case 528: + {} + case -520: + break; + case 529: + {} + case -521: + break; + case 530: + {} + case -522: + break; + case 531: + {} + case -523: + break; + case 532: + {} + case -524: + break; + case 533: + {} + case -525: + break; + case 534: + {} + case -526: + break; + case 535: + {} + case -527: + break; + case 536: + {} + case -528: + break; + case 537: + {} + case -529: + break; + case 538: + { + this.token = new Token(JavaParser.IDENTIFIER, yytext(), yyline, yychar);return true; +} + case -530: + break; + case 539: + {} + case -531: + break; + case 540: + {} + case -532: + break; + case 541: + {} + case -533: + break; + case 542: + {} + case -534: + break; + case 543: + {} + case -535: + break; + case 544: + {} + case -536: + break; + case 545: + {} + case -537: + break; + case 546: + {} + case -538: + break; + case 547: + {} + case -539: + break; + case 548: + {} + case -540: + break; + default: + yy_error(YY_E_INTERNAL,false); + case -1: + } + yy_initial = true; + yy_state = yy_state_dtrans[yy_lexical_state]; + yy_next_state = YY_NO_STATE; + yy_last_accept_state = YY_NO_STATE; + yy_mark_start(); + yy_this_accept = yy_acpt[yy_state]; + if (YY_NOT_ACCEPT != yy_this_accept) { + yy_last_accept_state = yy_state; + yy_mark_end(); + } + } + } + } + } +} diff --git a/src/mycompiler/myparser/JavaParser.java b/src/mycompiler/myparser/JavaParser.java new file mode 100644 index 000000000..2a1b16617 --- /dev/null +++ b/src/mycompiler/myparser/JavaParser.java @@ -0,0 +1,4114 @@ +// created by jay 0.7 (c) 1998 Axel.Schreiner@informatik.uni-osnabrueck.de + + // line 2 "./../src/mycompiler/myparser/JavaParser.jay" + +/* +Backup von JavaParser.jay 10.April 17 Uhr +*/ + +package mycompiler.myparser; + + +import java.util.Vector; +import mycompiler.myclass.FieldInitialization; +import mycompiler.SourceFile; +import mycompiler.AClassOrInterface; +import mycompiler.myclass.Class; +import mycompiler.myclass.ClassBody; +import mycompiler.myclass.Constructor; +import mycompiler.myclass.Constant; +import mycompiler.myclass.ImportDeclarations; +import mycompiler.myclass.DeclId; +import mycompiler.myclass.ExceptionList; +import mycompiler.myclass.FieldDecl; +import mycompiler.myclass.FormalParameter; +import mycompiler.myclass.InstVarDecl; +import mycompiler.myclass.Method; +import mycompiler.myclass.ParameterList; +import mycompiler.myclass.UsedId; +import mycompiler.myinterface.Interface; +import mycompiler.myinterface.InterfaceBody; +import mycompiler.mymodifier.Abstract; +import mycompiler.mymodifier.Final; +import mycompiler.mymodifier.Modifier; +import mycompiler.mymodifier.Modifiers; +import mycompiler.mymodifier.Private; +import mycompiler.mymodifier.Protected; +import mycompiler.mymodifier.Public; +import mycompiler.mymodifier.Static; +import mycompiler.myoperator.AndOp; +import mycompiler.myoperator.DivideOp; +import mycompiler.myoperator.EqualOp; +import mycompiler.myoperator.GreaterEquOp; +import mycompiler.myoperator.GreaterOp; +import mycompiler.myoperator.LessEquOp; +import mycompiler.myoperator.LessOp; +import mycompiler.myoperator.MinusOp; +import mycompiler.myoperator.ModuloOp; +import mycompiler.myoperator.NotEqualOp; +import mycompiler.myoperator.Operator; +import mycompiler.myoperator.OrOp; +import mycompiler.myoperator.PlusOp; +import mycompiler.myoperator.TimesOp; +import mycompiler.mystatement.ArgumentList; +import mycompiler.mystatement.Assign; +import mycompiler.mystatement.Binary; +import mycompiler.mystatement.Block; +import mycompiler.mystatement.BoolLiteral; +import mycompiler.mystatement.FloatLiteral; +import mycompiler.mystatement.DoubleLiteral; +import mycompiler.mystatement.LongLiteral; +import mycompiler.mystatement.CastExpr; +import mycompiler.mystatement.CharLiteral; +import mycompiler.mystatement.EmptyStmt; +import mycompiler.mystatement.Expr; +import mycompiler.mystatement.ExprStmt; +import mycompiler.mystatement.IfStmt; +import mycompiler.mystatement.InstanceOf; +import mycompiler.mystatement.IntLiteral; +import mycompiler.mystatement.Literal; +import mycompiler.mystatement.InstVar; +import mycompiler.mystatement.LocalOrFieldVar; +import mycompiler.mystatement.LocalVarDecl; +import mycompiler.mystatement.MethodCall; +import mycompiler.mystatement.NegativeExpr; +import mycompiler.mystatement.NewClass; +import mycompiler.mystatement.NotExpr; +import mycompiler.mystatement.Null; +import mycompiler.mystatement.PositivExpr; +import mycompiler.mystatement.PostDecExpr; +import mycompiler.mystatement.PostIncExpr; +import mycompiler.mystatement.PreDecExpr; +import mycompiler.mystatement.PreIncExpr; +import mycompiler.mystatement.Receiver; +import mycompiler.mystatement.Return; +import mycompiler.mystatement.Statement; +import mycompiler.mystatement.StringLiteral; +import mycompiler.mystatement.This; +import mycompiler.mystatement.UnaryMinus; +import mycompiler.mystatement.UnaryNot; +import mycompiler.mystatement.UnaryPlus; +import mycompiler.mystatement.WhileStmt; +import mycompiler.mystatement.ForStmt; +import mycompiler.mystatement.LambdaExpression; +import mycompiler.mytype.BaseType; +import mycompiler.mytype.BooleanType; +import mycompiler.mytype.CharacterType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.IntegerType; +import mycompiler.mytype.ParaList; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Void; +import mycompiler.mytype.WildcardType; +import mycompiler.mytype.ExtendsWildcardType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Pair; + +public class JavaParser{ +public Vector path = new Vector(); + +//PL 05-07-30 eingefuegt. ANFANG +private Vector containedTypes = new Vector(); +private Vector usedIdsToCheck = new Vector(); + //Vektor aller Typdeklarationen die in aktueller Klasse vorkommen. + //wird nach Beendigung der Klasse des Attributs der jeweiligen + //Klasse zugeordnet + //nach dem Parsen wird mit wandleGeneric2RefType die + //die RefTypes gesetzt. +void initContainedTypes() { + this.containedTypes = new Vector(); +} +void initUsedIdsToCheck() { + this.usedIdsToCheck = new Vector(); +} +//PL 05-07-30 eingefuegt. ENDE + +//LUAR 07-05-29 Anfang für Wildcard Test +public Vector testPair = new Vector(); +//LUAR 07-05-29 Ende + // line 133 "-" +// %token constants + //{ //ergaenzt PL 23.01.01 wieder entfernt 21.12.01 + public static final int ABSTRACT = 257; + public static final int BOOLEAN = 258; + public static final int BREAK = 259; + public static final int CASE = 260; + public static final int CATCH = 261; + public static final int CHAR = 262; + public static final int CLASS = 263; + public static final int CONTINUE = 264; + public static final int DEFAULT = 265; + public static final int DO = 266; + public static final int ELSE = 267; + public static final int EXTENDS = 268; + public static final int FINAL = 269; + public static final int FINALLY = 270; + public static final int FOR = 271; + public static final int IF = 272; + public static final int INSTANCEOF = 273; + public static final int INT = 274; + public static final int NEW = 275; + public static final int PRIVATE = 276; + public static final int PROTECTED = 277; + public static final int PUBLIC = 278; + public static final int PACKAGE = 279; + public static final int IMPORT = 280; + public static final int INTERFACE = 281; + public static final int IMPLEMENTS = 282; + public static final int RETURN = 283; + public static final int STATIC = 284; + public static final int SUPER = 285; + public static final int SWITCH = 286; + public static final int THIS = 287; + public static final int THROW = 288; + public static final int THROWS = 289; + public static final int TRY = 290; + public static final int VOID = 291; + public static final int WHILE = 292; + public static final int INTLITERAL = 293; + public static final int LONGLITERAL = 294; + public static final int DOUBLELITERAL = 295; + public static final int FLOATLITERAL = 296; + public static final int BOOLLITERAL = 297; + public static final int JNULL = 298; + public static final int CHARLITERAL = 299; + public static final int STRINGLITERAL = 300; + public static final int IDENTIFIER = 301; + public static final int EQUAL = 302; + public static final int LESSEQUAL = 303; + public static final int GREATEREQUAL = 304; + public static final int NOTEQUAL = 305; + public static final int LOGICALOR = 306; + public static final int LOGICALAND = 307; + public static final int INCREMENT = 308; + public static final int DECREMENT = 309; + public static final int SHIFTLEFT = 310; + public static final int SHIFTRIGHT = 311; + public static final int UNSIGNEDSHIFTRIGHT = 312; + public static final int SIGNEDSHIFTRIGHT = 313; + public static final int PLUSEQUAL = 314; + public static final int MINUSEQUAL = 315; + public static final int TIMESEQUAL = 316; + public static final int DIVIDEEQUAL = 317; + public static final int ANDEQUAL = 318; + public static final int OREQUAL = 319; + public static final int XOREQUAL = 320; + public static final int MODULOEQUAL = 321; + public static final int SHIFTLEFTEQUAL = 322; + public static final int SIGNEDSHIFTRIGHTEQUAL = 323; + public static final int UNSIGNEDSHIFTRIGHTEQUAL = 324; + public static final int BRACE = 325; + public static final int RELOP = 326; + public static final int OP = 327; + public static final int EOF = 328; + public static final int LAMBDAASSIGNMENT = 329; + public static final int yyErrorCode = 256; + + /** thrown for irrecoverable syntax errors and stack overflow. + */ + public static class yyException extends java.lang.Exception { + public Token token; + public yyException (String message, Token token) { + super(message); + this.token=token; + } + } + + /** must be implemented by a scanner object to supply input to the parser. + */ + public interface yyInput { + /** move on to next token. + @return false if positioned beyond tokens. + @throws IOException on input error. + */ + boolean advance () throws java.io.IOException; + /** classifies current token. + Should not be called if advance() returned false. + @return current %token or single character. + */ + int token (); + /** associated with current token. + Should not be called if advance() returned false. + @return value for token(). + */ + Object value (); + } + + /** simplified error message. + @see
yyerror + */ + public void yyerror (String message) { + yyerror(message, null); + } + + /** (syntax) error message. + Can be overwritten to control message format. + @param message text to be displayed. + @param expected vector of acceptable tokens, if available. + */ + public String yyerror (String message, String[] expected) { + if (expected != null && expected.length > 0) { + System.err.print(message+", expecting"); + message+=", expecting"; + for (int n = 0; n < expected.length; ++ n){ + System.err.print(" "+expected[n]); + message+=" "+expected[n];} + System.err.println(); + return message; + } else{ + System.err.println(message); + return message;} + } + + /** debugging support, requires the package jay.yydebug. + Set to null to suppress debugging messages. + */ +//t protected jay.yydebug.yyDebug yydebug; + + protected static final int yyFinal = 8; +//t public static final String yyRule [] = { +//t "$accept : compilationunit", +//t "compilationunit : typedeclarations", +//t "packagedeclaration : PACKAGE name ';'", +//t "importdeclarations : importdeclaration", +//t "importdeclarations : importdeclarations importdeclaration", +//t "importdeclaration : IMPORT importqualifiedname ';'", +//t "typedeclarations : typedeclaration", +//t "typedeclarations : typedeclarations typedeclaration", +//t "name : qualifiedname", +//t "name : simplename", +//t "typedeclaration : classdeclaration", +//t "qualifiedname : name '.' IDENTIFIER", +//t "importqualifiedname : name '.' IDENTIFIER", +//t "importqualifiedname : name '.' '*'", +//t "simplename : IDENTIFIER", +//t "classdeclaration : CLASS classidentifier classbody", +//t "classdeclaration : modifiers CLASS classidentifier classbody", +//t "classdeclaration : CLASS classidentifier super classbody", +//t "classdeclaration : modifiers CLASS classidentifier super classbody", +//t "classdeclaration : CLASS classidentifier interfaces classbody", +//t "classdeclaration : modifiers CLASS classidentifier interfaces classbody", +//t "classdeclaration : CLASS classidentifier super interfaces classbody", +//t "classdeclaration : modifiers CLASS classidentifier super interfaces classbody", +//t "interfaceidentifier : IDENTIFIER", +//t "interfaceidentifier : IDENTIFIER '<' boundedClassParameters '>'", +//t "classidentifier : IDENTIFIER", +//t "classidentifier : IDENTIFIER '<' boundedClassParameters '>'", +//t "interfacedeclaration : INTERFACE interfaceidentifier interfacebody", +//t "interfacedeclaration : modifiers INTERFACE interfaceidentifier interfacebody", +//t "interfacedeclaration : INTERFACE interfaceidentifier extendsinterfaces interfacebody", +//t "interfacedeclaration : modifiers INTERFACE interfaceidentifier extendsinterfaces interfacebody", +//t "paralist : IDENTIFIER", +//t "paralist : IDENTIFIER '<' paralist '>'", +//t "paralist : wildcardparameter", +//t "paralist : paralist ',' IDENTIFIER", +//t "paralist : paralist ',' IDENTIFIER '<' paralist '>'", +//t "paralist : paralist ',' wildcardparameter", +//t "wildcardparameter : '?'", +//t "wildcardparameter : '?' EXTENDS referencetype", +//t "wildcardparameter : '?' SUPER referencetype", +//t "classbody : '{' '}'", +//t "classbody : '{' classbodydeclarations '}'", +//t "modifiers : modifier", +//t "modifiers : modifiers modifier", +//t "super : EXTENDS classtype", +//t "interfaces : IMPLEMENTS interfacetype", +//t "interfaces : interfaces ',' interfacetype", +//t "interfacebody : '{' '}'", +//t "interfacebody : '{' interfacememberdeclarations '}'", +//t "extendsinterfaces : EXTENDS interfacetype", +//t "extendsinterfaces : extendsinterfaces ',' interfacetype", +//t "classbodydeclarations : classbodydeclaration", +//t "classbodydeclarations : classbodydeclarations classbodydeclaration", +//t "modifier : PUBLIC", +//t "modifier : PROTECTED", +//t "modifier : PRIVATE", +//t "modifier : STATIC", +//t "modifier : ABSTRACT", +//t "modifier : FINAL", +//t "classtype : classorinterfacetype", +//t "interfacememberdeclarations : interfacememberdeclaration", +//t "interfacememberdeclarations : interfacememberdeclarations interfacememberdeclaration", +//t "interfacetype : classorinterfacetype", +//t "classbodydeclaration : classmemberdeclaration", +//t "classbodydeclaration : staticinitializer", +//t "classbodydeclaration : constructordeclaration", +//t "classorinterfacetype : simplename parameter", +//t "parameter :", +//t "parameter : '<' paralist '>'", +//t "interfacememberdeclaration : constantdeclaration", +//t "interfacememberdeclaration : abstractmethoddeclaration", +//t "classmemberdeclaration : fielddeclaration", +//t "classmemberdeclaration : methoddeclaration", +//t "staticinitializer : STATIC block", +//t "constructordeclaration : constructordeclarator constructorbody", +//t "constructordeclaration : modifiers constructordeclarator constructorbody", +//t "constantdeclaration : modifiers type IDENTIFIER '=' expression ';'", +//t "abstractmethoddeclaration : methodheader ';'", +//t "fielddeclarator : variabledeclarator '=' expression", +//t "fielddeclaration : fielddeclarator ';'", +//t "fielddeclaration : type fielddeclarator", +//t "fielddeclaration : variabledeclarators ';'", +//t "fielddeclaration : type variabledeclarators ';'", +//t "fielddeclaration : modifiers type variabledeclarators ';'", +//t "methoddeclaration : methodheader methodbody", +//t "block : '{' '}'", +//t "block : '{' blockstatements '}'", +//t "constructordeclarator : simplename '(' ')'", +//t "constructordeclarator : simplename '(' formalparameterlist ')'", +//t "constructorbody : '{' '}'", +//t "constructorbody : '{' explicitconstructorinvocation '}'", +//t "constructorbody : '{' blockstatements '}'", +//t "constructorbody : '{' explicitconstructorinvocation blockstatements '}'", +//t "throws : THROWS classtypelist", +//t "boundedClassParameter : boundedMethodParameter", +//t "boundedClassParameters : boundedClassParameter", +//t "boundedClassParameters : boundedClassParameters ',' boundedClassParameter", +//t "boundedMethodParameter : IDENTIFIER", +//t "boundedMethodParameter : IDENTIFIER EXTENDS boundedclassidentifierlist", +//t "boundedclassidentifierlist : referencetype", +//t "boundedclassidentifierlist : boundedclassidentifierlist '&' referencetype", +//t "boundedMethodParameters : boundedMethodParameter", +//t "boundedMethodParameters : boundedMethodParameters ',' boundedMethodParameter", +//t "methodheader : '<' boundedMethodParameters '>' type methoddeclarator", +//t "methodheader : type methoddeclarator", +//t "methodheader : modifiers type methoddeclarator", +//t "methodheader : modifiers '<' boundedMethodParameters '>' type methoddeclarator", +//t "methodheader : type methoddeclarator throws", +//t "methodheader : '<' boundedMethodParameters '>' type methoddeclarator throws", +//t "methodheader : modifiers type methoddeclarator throws", +//t "methodheader : modifiers '<' boundedMethodParameters '>' type methoddeclarator throws", +//t "methodheader : VOID methoddeclarator", +//t "methodheader : modifiers VOID methoddeclarator", +//t "methodheader : VOID methoddeclarator throws", +//t "methodheader : modifiers VOID methoddeclarator throws", +//t "methodheader : '<' boundedMethodParameters '>' VOID methoddeclarator", +//t "methodheader : modifiers '<' boundedMethodParameters '>' VOID methoddeclarator", +//t "methodheader : '<' boundedMethodParameters '>' VOID methoddeclarator throws", +//t "methodheader : modifiers '<' boundedMethodParameters '>' VOID methoddeclarator throws", +//t "methodheader : methoddeclarator", +//t "methodheader : '<' boundedMethodParameters '>' methoddeclarator", +//t "methodheader : modifiers methoddeclarator", +//t "methodheader : methoddeclarator throws", +//t "methodheader : modifiers methoddeclarator throws", +//t "type : primitivetype", +//t "type : primitivetype '[' ']'", +//t "type : referencetype", +//t "type : referencetype '[' ']'", +//t "variabledeclarators : variabledeclarator", +//t "variabledeclarators : variabledeclarators ',' variabledeclarator", +//t "methodbody : block", +//t "blockstatements : blockstatement", +//t "blockstatements : blockstatements blockstatement", +//t "formalparameterlist : formalparameter", +//t "formalparameterlist : formalparameterlist ',' formalparameter", +//t "explicitconstructorinvocation : THIS '(' ')' ';'", +//t "explicitconstructorinvocation : THIS '(' argumentlist ')' ';'", +//t "classtypelist : classtype", +//t "classtypelist : classtypelist ',' classtype", +//t "methoddeclarator : IDENTIFIER '(' ')'", +//t "methoddeclarator : IDENTIFIER '(' formalparameterlist ')'", +//t "primitivetype : BOOLEAN", +//t "primitivetype : numerictype", +//t "referencetype : classorinterfacetype", +//t "variabledeclarator : variabledeclaratorid", +//t "blockstatement : localvariabledeclarationstatement", +//t "blockstatement : statement", +//t "formalparameter : type variabledeclaratorid", +//t "formalparameter : variabledeclaratorid", +//t "argumentlist : expression", +//t "argumentlist : argumentlist ',' expression", +//t "numerictype : integraltype", +//t "variabledeclaratorid : IDENTIFIER", +//t "variableinitializer : expression", +//t "localvariabledeclarationstatement : localvariabledeclaration ';'", +//t "statement : statementwithouttrailingsubstatement", +//t "statement : ifthenstatement", +//t "statement : ifthenelsestatement", +//t "statement : whilestatement", +//t "statement : forstatement", +//t "expression : assignmentexpression", +//t "expression : classinstancecreationexpression", +//t "integraltype : INT", +//t "integraltype : CHAR", +//t "localvariabledeclaration : type variabledeclarators", +//t "localvariabledeclaration : variabledeclarators", +//t "statementwithouttrailingsubstatement : block", +//t "statementwithouttrailingsubstatement : emptystatement", +//t "statementwithouttrailingsubstatement : expressionstatement", +//t "statementwithouttrailingsubstatement : returnstatement", +//t "ifthenstatement : IF '(' expression ')' statement", +//t "ifthenelsestatement : IF '(' expression ')' statementnoshortif ELSE statement", +//t "whilestatement : WHILE '(' expression ')' statement", +//t "forstatement : FOR '(' expression ';' expression ';' expression ')' statement", +//t "forstatement : FOR '(' expression ';' expression ';' ')' statement", +//t "forstatement : FOR '(' expression ';' ';' expression ')' statement", +//t "forstatement : FOR '(' ';' expression ';' expression ')' statement", +//t "forstatement : FOR '(' expression ';' ';' ')' statement", +//t "forstatement : FOR '(' ';' expression ';' ')' statement", +//t "forstatement : FOR '(' ';' ';' expression ')' statement", +//t "forstatement : FOR '(' ';' ';' ')' statement", +//t "assignmentexpression : conditionalexpression", +//t "assignmentexpression : assignment", +//t "emptystatement : ';'", +//t "expressionstatement : statementexpression ';'", +//t "returnstatement : RETURN ';'", +//t "returnstatement : RETURN expression ';'", +//t "statementnoshortif : statementwithouttrailingsubstatement", +//t "statementnoshortif : ifthenelsestatementnoshortif", +//t "statementnoshortif : whilestatementnoshortif", +//t "conditionalexpression : conditionalorexpression", +//t "assignment : lefthandside assignmentoperator assignmentexpression", +//t "assignment : lefthandside assignmentoperator classinstancecreationexpression", +//t "statementexpression : assignment", +//t "statementexpression : preincrementexpression", +//t "statementexpression : predecrementexpression", +//t "statementexpression : postincrementexpression", +//t "statementexpression : postdecrementexpression", +//t "statementexpression : methodinvocation", +//t "ifthenelsestatementnoshortif : IF '(' expression ')' statementnoshortif ELSE statementnoshortif", +//t "whilestatementnoshortif : WHILE '(' expression ')' statementnoshortif", +//t "conditionalorexpression : conditionalandexpression", +//t "conditionalorexpression : conditionalorexpression LOGICALOR conditionalandexpression", +//t "lambdaassignmentoperator : LAMBDAASSIGNMENT", +//t "lambdabody : block", +//t "lambdabody : expression", +//t "lambdaexpressionparameter : '(' ')'", +//t "lambdaexpressionparameter : '(' formalparameterlist ')'", +//t "lambdaexpression : lambdaexpressionparameter lambdaassignmentoperator lambdabody", +//t "lefthandside : name", +//t "assignmentoperator : '='", +//t "assignmentoperator : TIMESEQUAL", +//t "assignmentoperator : DIVIDEEQUAL", +//t "assignmentoperator : MODULOEQUAL", +//t "assignmentoperator : PLUSEQUAL", +//t "assignmentoperator : MINUSEQUAL", +//t "preincrementexpression : INCREMENT unaryexpression", +//t "predecrementexpression : DECREMENT unaryexpression", +//t "postincrementexpression : postfixexpression INCREMENT", +//t "postdecrementexpression : postfixexpression DECREMENT", +//t "methodinvocation : name '(' ')'", +//t "methodinvocation : name '(' argumentlist ')'", +//t "methodinvocation : primary '.' IDENTIFIER '(' ')'", +//t "methodinvocation : primary '.' IDENTIFIER '(' argumentlist ')'", +//t "classinstancecreationexpression : NEW classtype '(' ')'", +//t "classinstancecreationexpression : NEW classtype '(' argumentlist ')'", +//t "conditionalandexpression : inclusiveorexpression", +//t "conditionalandexpression : conditionalandexpression LOGICALAND inclusiveorexpression", +//t "unaryexpression : preincrementexpression", +//t "unaryexpression : predecrementexpression", +//t "unaryexpression : '+' unaryexpression", +//t "unaryexpression : '-' unaryexpression", +//t "unaryexpression : unaryexpressionnotplusminus", +//t "postfixexpression : primary", +//t "postfixexpression : name", +//t "postfixexpression : postincrementexpression", +//t "postfixexpression : postdecrementexpression", +//t "primary : primarynonewarray", +//t "inclusiveorexpression : exclusiveorexpression", +//t "inclusiveorexpression : inclusiveorexpression '|' exclusiveorexpression", +//t "primarynonewarray : literal", +//t "primarynonewarray : THIS", +//t "primarynonewarray : methodinvocation", +//t "primarynonewarray : lambdaexpression", +//t "unaryexpressionnotplusminus : postfixexpression", +//t "unaryexpressionnotplusminus : '!' unaryexpression", +//t "unaryexpressionnotplusminus : castexpression", +//t "exclusiveorexpression : andexpression", +//t "exclusiveorexpression : exclusiveorexpression '^' andexpression", +//t "literal : INTLITERAL", +//t "literal : BOOLLITERAL", +//t "literal : CHARLITERAL", +//t "literal : STRINGLITERAL", +//t "literal : LONGLITERAL", +//t "literal : FLOATLITERAL", +//t "literal : DOUBLELITERAL", +//t "literal : JNULL", +//t "castexpression : '(' primitivetype ')' unaryexpression", +//t "andexpression : equalityexpression", +//t "andexpression : andexpression '&' equalityexpression", +//t "equalityexpression : relationalexpression", +//t "equalityexpression : equalityexpression EQUAL relationalexpression", +//t "equalityexpression : equalityexpression NOTEQUAL relationalexpression", +//t "relationalexpression : shiftexpression", +//t "relationalexpression : relationalexpression '<' shiftexpression", +//t "relationalexpression : relationalexpression '>' shiftexpression", +//t "relationalexpression : relationalexpression LESSEQUAL shiftexpression", +//t "relationalexpression : relationalexpression GREATEREQUAL shiftexpression", +//t "relationalexpression : relationalexpression INSTANCEOF referencetype", +//t "shiftexpression : additiveexpression", +//t "additiveexpression : multiplicativeexpression", +//t "additiveexpression : additiveexpression '+' multiplicativeexpression", +//t "additiveexpression : additiveexpression '-' multiplicativeexpression", +//t "multiplicativeexpression : unaryexpression", +//t "multiplicativeexpression : multiplicativeexpression '*' unaryexpression", +//t "multiplicativeexpression : multiplicativeexpression '/' unaryexpression", +//t "multiplicativeexpression : multiplicativeexpression '%' unaryexpression", +//t }; + protected static final String yyName [] = { + "end-of-file",null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,"'!'",null,null,null,"'%'","'&'", + null,"'('","')'","'*'","'+'","','","'-'","'.'","'/'",null,null,null, + null,null,null,null,null,null,null,null,"';'","'<'","'='","'>'","'?'", + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null, + "'['",null,"']'","'^'",null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,"'{'","'|'","'}'",null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null, + "ABSTRACT","BOOLEAN","BREAK","CASE","CATCH","CHAR","CLASS","CONTINUE", + "DEFAULT","DO","ELSE","EXTENDS","FINAL","FINALLY","FOR","IF", + "INSTANCEOF","INT","NEW","PRIVATE","PROTECTED","PUBLIC","PACKAGE", + "IMPORT","INTERFACE","IMPLEMENTS","RETURN","STATIC","SUPER","SWITCH", + "THIS","THROW","THROWS","TRY","VOID","WHILE","INTLITERAL", + "LONGLITERAL","DOUBLELITERAL","FLOATLITERAL","BOOLLITERAL","JNULL", + "CHARLITERAL","STRINGLITERAL","IDENTIFIER","EQUAL","LESSEQUAL", + "GREATEREQUAL","NOTEQUAL","LOGICALOR","LOGICALAND","INCREMENT", + "DECREMENT","SHIFTLEFT","SHIFTRIGHT","UNSIGNEDSHIFTRIGHT", + "SIGNEDSHIFTRIGHT","PLUSEQUAL","MINUSEQUAL","TIMESEQUAL", + "DIVIDEEQUAL","ANDEQUAL","OREQUAL","XOREQUAL","MODULOEQUAL", + "SHIFTLEFTEQUAL","SIGNEDSHIFTRIGHTEQUAL","UNSIGNEDSHIFTRIGHTEQUAL", + "BRACE","RELOP","OP","EOF","LAMBDAASSIGNMENT", + }; + + /** index-checked interface to yyName[]. + @param token single character or %token value. + @return token name or [illegal] or [unknown]. + */ +//t public static final String yyname (int token) { +//t if (token < 0 || token > yyName.length) return "[illegal]"; +//t String name; +//t if ((name = yyName[token]) != null) return name; +//t return "[unknown]"; +//t } + + /** computes list of expected tokens on error by tracing the tables. + @param state for which to compute the list. + @return list of token names. + */ + protected String[] yyExpecting (int state) { + // yyCheck durch yyCheckInit.yyCheck; ersetzt PL 25.1.01 + int token, n, len = 0; + boolean[] ok = new boolean[yyName.length]; + + if ((n = yySindex[state]) != 0) + for (token = n < 0 ? -n : 0; + token < yyName.length && n+token < yyTable.length; ++ token) + if (yyCheckInit.yyCheck[n+token] == token && !ok[token] && yyName[token] != null) { + ++ len; + ok[token] = true; + } + if ((n = yyRindex[state]) != 0) + for (token = n < 0 ? -n : 0; + token < yyName.length && n+token < yyTable.length; ++ token) + if (yyCheckInit.yyCheck[n+token] == token && !ok[token] && yyName[token] != null) { + ++ len; + ok[token] = true; + } + + String result[] = new String[len]; + for (n = token = 0; n < len; ++ token) + if (ok[token]) result[n++] = yyName[token]; + return result; + } + + /** the generated parser, with debugging messages. + Maintains a state and a value stack, currently with fixed maximum size. + @param yyLex scanner. + @param yydebug debug message writer implementing yyDebug, or null. + @return result of the last reduction, if any. + @throws yyException on irrecoverable parse error. + */ + public Object yyparse (yyInput yyLex, Object yydebug) + throws java.io.IOException, yyException { +//t this.yydebug = (jay.yydebug.yyDebug)yydebug; + return yyparse(yyLex); + } + + /** initial size and increment of the state/value stack [default 256]. + This is not final so that it can be overwritten outside of invocations + of yyparse(). + */ + protected int yyMax; + + /** executed at the beginning of a reduce action. + Used as $$ = yyDefault($1), prior to the user-specified action, if any. + Can be overwritten to provide deep copy, etc. + @param first value for $1, or null. + @return first. + */ + protected Object yyDefault (Object first) { + return first; + } + + /** the generated parser. + Maintains a state and a value stack, currently with fixed maximum size. + @param yyLex scanner. + @return result of the last reduction, if any. + @throws yyException on irrecoverable parse error. + */ + public Object yyparse (yyInput yyLex) + throws java.io.IOException, yyException { + // yyCheck durch yyCheckInit.yyCheck; ersetzt PL 23.1.01 + yyCheckInit.yyCheckInit(); // initial yyCheck eingefuegt PL 25.1.01 + if (yyMax <= 0) yyMax = 256; // initial size + int yyState = 0, yyStates[] = new int[yyMax]; // state stack + Object yyVal = null, yyVals[] = new Object[yyMax]; // value stack + int yyToken = -1; // current input + int yyErrorFlag = 0; // #tks to shift + Scanner yyScanner = (Scanner)yyLex; + String yyErrorString = "irrecoverable syntax error"; + + yyLoop: for (int yyTop = 0;; ++ yyTop) { + if (yyTop >= yyStates.length) { // dynamically increase + int[] i = new int[yyStates.length+yyMax]; + System.arraycopy(yyStates, 0, i, 0, yyStates.length); + yyStates = i; + Object[] o = new Object[yyVals.length+yyMax]; + System.arraycopy(yyVals, 0, o, 0, yyVals.length); + yyVals = o; + } + yyStates[yyTop] = yyState; + yyVals[yyTop] = yyVal; +//t if (yydebug != null) yydebug.push(yyState, yyVal); + + yyDiscarded: for (;;) { // discarding a token does not change stack + int yyN; + if ((yyN = yyDefRed[yyState]) == 0) { // else [default] reduce (yyN) + if (yyToken < 0) { + yyToken = yyLex.advance() ? yyLex.token() : 0; +//t if (yydebug != null) +//t yydebug.lex(yyState, yyToken, yyname(yyToken), yyLex.value()); + } + if ((yyN = yySindex[yyState]) != 0 && (yyN += yyToken) >= 0 + && yyN < yyTable.length && yyCheckInit.yyCheck[yyN] == yyToken) { +//t if (yydebug != null) +//t yydebug.shift(yyState, yyTable[yyN], yyErrorFlag-1); + yyState = yyTable[yyN]; // shift to yyN + yyVal = yyLex.value(); + yyToken = -1; + if (yyErrorFlag > 0) -- yyErrorFlag; + continue yyLoop; + } + if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0 + && yyN < yyTable.length && yyCheckInit.yyCheck[yyN] == yyToken) + yyN = yyTable[yyN]; // reduce (yyN) + else + switch (yyErrorFlag) { + + case 0: + yyErrorString=yyerror("syntax error", yyExpecting(yyState)); +//t if (yydebug != null) yydebug.error("syntax error"); + + case 1: case 2: + yyErrorFlag = 3; + do { + if ((yyN = yySindex[yyStates[yyTop]]) != 0 + && (yyN += yyErrorCode) >= 0 && yyN < yyTable.length + && yyCheckInit.yyCheck[yyN] == yyErrorCode) { +//t if (yydebug != null) +//t yydebug.shift(yyStates[yyTop], yyTable[yyN], 3); + yyState = yyTable[yyN]; + yyVal = yyLex.value(); + continue yyLoop; + } +//t if (yydebug != null) yydebug.pop(yyStates[yyTop]); + } while (-- yyTop >= 0); +//t if (yydebug != null) yydebug.reject(); + throw new yyException(yyErrorString, yyScanner.token); + + case 3: + if (yyToken == 0) { +//t if (yydebug != null) yydebug.reject(); + throw new yyException(yyErrorString+"at end-of-file", yyScanner.token); + } +//t if (yydebug != null) +//t yydebug.discard(yyState, yyToken, yyname(yyToken), +//t yyLex.value()); + yyToken = -1; + continue yyDiscarded; // leave stack alone + } + } + int yyV = yyTop + 1-yyLen[yyN]; +//t if (yydebug != null) +//t yydebug.reduce(yyState, yyStates[yyV-1], yyN, yyRule[yyN], yyLen[yyN]); + yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]); + switch (yyN) { +case 1: + // line 324 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((SourceFile)yyVals[0+yyTop]); + } + break; +case 2: + // line 352 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Package*/ + yyVal = ((UsedId)yyVals[-1+yyTop]); + } + break; +case 3: + // line 358 "./../src/mycompiler/myparser/JavaParser.jay" + { + ImportDeclarations declarations=new ImportDeclarations(); + declarations.addElement(((UsedId)yyVals[0+yyTop])); + yyVal=declarations; + } + break; +case 4: + // line 364 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((ImportDeclarations)yyVals[-1+yyTop]).addElement(((UsedId)yyVals[0+yyTop])); + yyVal=((ImportDeclarations)yyVals[-1+yyTop]); + } + break; +case 5: + // line 370 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((UsedId)yyVals[-1+yyTop]); + } + break; +case 6: + // line 375 "./../src/mycompiler/myparser/JavaParser.jay" + { + SourceFile Scfile = new SourceFile(); + Scfile.addElement(((AClassOrInterface)yyVals[0+yyTop])); + yyVal=Scfile; + } + break; +case 7: + // line 381 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((SourceFile)yyVals[-1+yyTop]).addElement(((AClassOrInterface)yyVals[0+yyTop])); + yyVal=((SourceFile)yyVals[-1+yyTop]); + } + break; +case 8: + // line 387 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((UsedId)yyVals[0+yyTop]); + } + break; +case 9: + // line 391 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((UsedId)yyVals[0+yyTop]); + } + break; +case 10: + // line 396 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Class)yyVals[0+yyTop]); + } + break; +case 11: + // line 407 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((UsedId)yyVals[-2+yyTop]).set_Name(((Token)yyVals[0+yyTop]).getLexem()); + ((UsedId)yyVals[-2+yyTop]).setOffset(((UsedId)yyVals[-2+yyTop]).getOffset()); + yyVal=((UsedId)yyVals[-2+yyTop]); + } + break; +case 12: + // line 414 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((UsedId)yyVals[-2+yyTop]).set_Name(((Token)yyVals[0+yyTop]).getLexem()); + ((UsedId)yyVals[-2+yyTop]).setOffset(((UsedId)yyVals[-2+yyTop]).getOffset()); + yyVal=((UsedId)yyVals[-2+yyTop]); + } + break; +case 13: + // line 420 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((UsedId)yyVals[-2+yyTop]).set_Name("*"); + ((UsedId)yyVals[-2+yyTop]).setOffset(((UsedId)yyVals[-2+yyTop]).getOffset()); + yyVal=((UsedId)yyVals[-2+yyTop]); + } + break; +case 14: + // line 428 "./../src/mycompiler/myparser/JavaParser.jay" + { + UsedId UI = new UsedId(((Token)yyVals[0+yyTop]).getOffset()); + UI.set_Name( ((Token)yyVals[0+yyTop]).getLexem() ); + UI.setOffset(((Token)yyVals[0+yyTop]).getOffset());/*hinzugef�gt hoth: 07.04.2006*/ + yyVal = UI; + } + break; +case 15: + // line 436 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Um das hier uebersichtlicher zu halten,*/ + /* gibt es einen allumfassenden Konstruktor fuer Class*/ + /* Parameter:*/ + /* String name, */ + /* Modifiers mod,*/ + /* ClassBody classbody, */ + /* Vector containedtypes, */ + /* UsedId superclass, */ + /* Vector SuperInterfaces, */ + /* Vector Parameterliste*/ + + yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector()); + this.initContainedTypes(); + this.initUsedIdsToCheck(); + } + break; +case 16: + // line 453 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), ((Modifiers)yyVals[-3+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, null, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector()); + this.initContainedTypes(); + this.initUsedIdsToCheck(); + } + break; +case 17: + // line 459 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector()); + this.initContainedTypes(); + this.initUsedIdsToCheck(); + } + break; +case 18: + // line 465 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector()); + this.initContainedTypes(); + this.initUsedIdsToCheck(); + } + break; +case 19: + // line 472 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector()); + this.initContainedTypes(); + this.initUsedIdsToCheck(); + } + break; +case 20: + // line 478 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector()); + this.initContainedTypes(); + this.initUsedIdsToCheck(); + } + break; +case 21: + // line 484 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector()); + this.initContainedTypes(); + this.initUsedIdsToCheck(); + } + break; +case 22: + // line 490 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), ((Modifiers)yyVals[-5+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector()); + this.initContainedTypes(); + this.initUsedIdsToCheck(); + } + break; +case 23: + // line 497 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* HOTI*/ + /* Verbindet den Namen eines Interfaces mit einer optionalen Parameterliste*/ + yyVal = new InterfaceAndParameter(((Token)yyVals[0+yyTop]).getLexem()); + } + break; +case 24: + // line 503 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = new InterfaceAndParameter(((Token)yyVals[-3+yyTop]).getLexem(), ((ParaList)yyVals[-1+yyTop])); + } + break; +case 25: + // line 508 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Hilfskonstrukt, um die Grammatik ueberschaubar zu halten*/ + /* Verbindet den Namen einer Klasse mit einer optionalen Parameterliste*/ + yyVal = new ClassAndParameter(((Token)yyVals[0+yyTop]).getLexem()); + } + break; +case 26: + // line 514 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = new ClassAndParameter(((Token)yyVals[-3+yyTop]).getLexem(), ((ParaList)yyVals[-1+yyTop])); + } + break; +case 27: + // line 519 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Interface*/ + Interface ic = new Interface(((InterfaceAndParameter)yyVals[-1+yyTop]).getName()); + ic.setParaList(((InterfaceAndParameter)yyVals[-1+yyTop]).getParaVector()); + ic.setInterfaceBody(((InterfaceBody)yyVals[0+yyTop])); + ic.setContainedTypes(containedTypes); + initContainedTypes(); + yyVal = ic; + } + break; +case 28: + // line 529 "./../src/mycompiler/myparser/JavaParser.jay" + { + Interface ic = new Interface(((InterfaceAndParameter)yyVals[-1+yyTop]).getName(), ((Modifiers)yyVals[-3+yyTop])); + ic.setInterfaceBody(((InterfaceBody)yyVals[0+yyTop])); + ic.setParaList(((InterfaceAndParameter)yyVals[-1+yyTop]).getParaVector()); + ic.setContainedTypes(containedTypes); + initContainedTypes(); + yyVal = ic; + } + break; +case 29: + // line 538 "./../src/mycompiler/myparser/JavaParser.jay" + { + Interface ic = new Interface(((InterfaceAndParameter)yyVals[-2+yyTop]).getName()); + ic.setParaList(((InterfaceAndParameter)yyVals[-2+yyTop]).getParaVector()); + ic.setSuperInterfaces(((InterfaceList)yyVals[-1+yyTop]).getVector()); + ic.setInterfaceBody(((InterfaceBody)yyVals[0+yyTop])); + ic.setContainedTypes(containedTypes); + initContainedTypes(); + yyVal = ic; + } + break; +case 30: + // line 548 "./../src/mycompiler/myparser/JavaParser.jay" + { + Interface ic = new Interface(((InterfaceAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop])); + ic.setParaList(((InterfaceAndParameter)yyVals[-2+yyTop]).getParaVector()); + ic.setSuperInterfaces(((InterfaceList)yyVals[-1+yyTop]).getVector()); + ic.setInterfaceBody(((InterfaceBody)yyVals[0+yyTop])); + ic.setContainedTypes(containedTypes); + initContainedTypes(); + yyVal = ic; + } + break; +case 31: + // line 559 "./../src/mycompiler/myparser/JavaParser.jay" + { + ParaList pl = new ParaList(); + /* #JB# 05.04.2005 */ + /* ########################################################### */ + pl.getParalist().addElement(new GenericTypeVar(((Token)yyVals[0+yyTop]).getLexem(), ((Token)yyVals[0+yyTop]).getOffset())); + /*pl.getParalist().addElement( new TypePlaceholder($1.getLexem()) );*/ + /* ########################################################### */ + org.apache.log4j.Logger.getLogger("parser").debug( "IDENTIFIER --> Paralist f�r " + ((Token)yyVals[0+yyTop]).getLexem() + " TV"); + yyVal = pl; + } + break; +case 32: + // line 570 "./../src/mycompiler/myparser/JavaParser.jay" + { + ParaList pl = new ParaList(); + RefType t = new RefType( ((Token)yyVals[-3+yyTop]).getLexem(),((Token)yyVals[-3+yyTop]).getOffset() ); + t.set_ParaList( ((ParaList)yyVals[-1+yyTop]).get_ParaList() ); + pl.getParalist().addElement(t); + org.apache.log4j.Logger.getLogger("parser").debug( "IDENTIFIER '<' paralist '>' --> Paralist f�r " + ((Token)yyVals[-3+yyTop]).getLexem() + ": RefType"); + yyVal = pl; + } + break; +case 33: + // line 579 "./../src/mycompiler/myparser/JavaParser.jay" + { + ParaList pl = new ParaList(); + pl.getParalist().addElement(((WildcardType)yyVals[0+yyTop])); + yyVal = pl; + } + break; +case 34: + // line 585 "./../src/mycompiler/myparser/JavaParser.jay" + { + + /* #JB# 05.04.2005 */ + /* ########################################################### */ + ((ParaList)yyVals[-2+yyTop]).getParalist().addElement(new GenericTypeVar(((Token)yyVals[0+yyTop]).getLexem(),((Token)yyVals[0+yyTop]).getOffset())); + /*$1.getParalist().addElement(new TypePlaceholder($3.getLexem()));*/ + /* ########################################################### */ + org.apache.log4j.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER --> Paralist f�r " + ((Token)yyVals[0+yyTop]).getLexem() + ": TV"); + org.apache.log4j.Logger.getLogger("parser").debug( "paralist: " + ((ParaList)yyVals[-2+yyTop]).getParalist()); + yyVal=((ParaList)yyVals[-2+yyTop]); + } + break; +case 35: + // line 598 "./../src/mycompiler/myparser/JavaParser.jay" + { + RefType t = new RefType( ((Token)yyVals[-3+yyTop]).getLexem() ,((Token)yyVals[-3+yyTop]).getOffset() ); + t.set_ParaList( ((ParaList)yyVals[-1+yyTop]).get_ParaList() ); + ((ParaList)yyVals[-5+yyTop]).getParalist().addElement(t); + org.apache.log4j.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER '<' paralist '>' --> Paralist f�r " + ((Token)yyVals[-3+yyTop]).getLexem() + ": RefType"); + yyVal=((ParaList)yyVals[-5+yyTop]); + } + break; +case 36: + // line 606 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((ParaList)yyVals[-2+yyTop]).getParalist().addElement(((WildcardType)yyVals[0+yyTop])); + yyVal=((ParaList)yyVals[-2+yyTop]); + } + break; +case 37: + // line 612 "./../src/mycompiler/myparser/JavaParser.jay" + { + /*Luar 29.11.06 Offset auf -1, da keine Angabe vorhanden*/ + WildcardType wc = new WildcardType(-1); + yyVal = wc; + } + break; +case 38: + // line 618 "./../src/mycompiler/myparser/JavaParser.jay" + { + ExtendsWildcardType ewc = new ExtendsWildcardType(((Token)yyVals[-1+yyTop]).getOffset(),((RefType)yyVals[0+yyTop])); + yyVal = ewc; + } + break; +case 39: + // line 623 "./../src/mycompiler/myparser/JavaParser.jay" + { + SuperWildcardType swc = new SuperWildcardType(((Token)yyVals[-1+yyTop]).getOffset(),((RefType)yyVals[0+yyTop])); + yyVal = swc; + } + break; +case 40: + // line 629 "./../src/mycompiler/myparser/JavaParser.jay" + { + ClassBody CB = new ClassBody(); + yyVal = CB; + } + break; +case 41: + // line 635 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = ((ClassBody)yyVals[-1+yyTop]); + } + break; +case 42: + // line 640 "./../src/mycompiler/myparser/JavaParser.jay" + { + Modifiers Mod = new Modifiers(); + Mod.addModifier(((Modifier)yyVals[0+yyTop])); + yyVal = Mod; + } + break; +case 43: + // line 646 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Modifiers)yyVals[-1+yyTop]).addModifier(((Modifier)yyVals[0+yyTop])); + yyVal = ((Modifiers)yyVals[-1+yyTop]); + } + break; +case 44: + // line 652 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = ((UsedId)yyVals[0+yyTop]); + } + break; +case 45: + // line 657 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Interface*/ + InterfaceList il = new InterfaceList(); + il.addInterface(((UsedId)yyVals[0+yyTop])); + yyVal = il; + } + break; +case 46: + // line 664 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((InterfaceList)yyVals[-2+yyTop]).addInterface(((UsedId)yyVals[0+yyTop])); + yyVal = ((InterfaceList)yyVals[-2+yyTop]); + } + break; +case 47: + // line 670 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Interface*/ + yyVal = new InterfaceBody(); + } + break; +case 48: + // line 675 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = ((InterfaceBody)yyVals[-1+yyTop]); + } + break; +case 49: + // line 682 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Interface*/ + InterfaceList il = new InterfaceList(); + il.addInterface(((UsedId)yyVals[0+yyTop])); + yyVal = il; + } + break; +case 50: + // line 689 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((InterfaceList)yyVals[-2+yyTop]).addInterface(((UsedId)yyVals[0+yyTop])); + yyVal = ((InterfaceList)yyVals[-2+yyTop]); + } + break; +case 51: + // line 696 "./../src/mycompiler/myparser/JavaParser.jay" + { + ClassBody CB = new ClassBody(); + CB.set_FieldDecl( ((FieldDecl)yyVals[0+yyTop]) ); + yyVal=CB; + } + break; +case 52: + // line 702 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((ClassBody)yyVals[-1+yyTop]).set_FieldDecl(((FieldDecl)yyVals[0+yyTop])); + yyVal = ((ClassBody)yyVals[-1+yyTop]); + } + break; +case 53: + // line 709 "./../src/mycompiler/myparser/JavaParser.jay" + { + Public Pub = new Public(); + yyVal=Pub; + } + break; +case 54: + // line 714 "./../src/mycompiler/myparser/JavaParser.jay" + { + Protected Pro = new Protected(); + yyVal=Pro; + } + break; +case 55: + // line 719 "./../src/mycompiler/myparser/JavaParser.jay" + { + Private Pri = new Private(); + yyVal=Pri; + } + break; +case 56: + // line 724 "./../src/mycompiler/myparser/JavaParser.jay" + { + Static Sta = new Static(); + yyVal=Sta; + } + break; +case 57: + // line 729 "./../src/mycompiler/myparser/JavaParser.jay" + { + Abstract Abs = new Abstract(); + yyVal=Abs; + } + break; +case 58: + // line 734 "./../src/mycompiler/myparser/JavaParser.jay" + { Final fin = new Final(); + yyVal = fin; + } + break; +case 59: + // line 740 "./../src/mycompiler/myparser/JavaParser.jay" + { + /*PL 05-07-30 eingefuegt containedTypes ANFANG*/ + RefType RT = new RefType(-1); + /*RT.set_UsedId($1);*/ + /*RT.setName(RT.get_UsedId().get_Name_1Element());*/ + RT.set_ParaList(((UsedId)yyVals[0+yyTop]).get_RealParaList()); + RT.setName(((UsedId)yyVals[0+yyTop]).get_Name_1Element()); + containedTypes.addElement(RT); + /*PL 05-07-30 eingefuegt containedTypes ENDE*/ + + yyVal = ((UsedId)yyVals[0+yyTop]); + } + break; +case 60: + // line 755 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Interface*/ + InterfaceBody ib = new InterfaceBody(); + ib.addElement(((FieldDecl)yyVals[0+yyTop])); + yyVal = ib; + } + break; +case 61: + // line 762 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((InterfaceBody)yyVals[-1+yyTop]).addElement(((FieldDecl)yyVals[0+yyTop])); + yyVal = ((InterfaceBody)yyVals[-1+yyTop]); + } + break; +case 62: + // line 768 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Interfaces*/ + yyVal = ((UsedId)yyVals[0+yyTop]); + } + break; +case 63: + // line 774 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((FieldDecl)yyVals[0+yyTop]); + } + break; +case 64: + // line 779 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 65: + // line 783 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((FieldDecl)yyVals[0+yyTop]); + } + break; +case 66: + // line 788 "./../src/mycompiler/myparser/JavaParser.jay" + { + if (((ParaList)yyVals[0+yyTop]) != null) { + ((UsedId)yyVals[-1+yyTop]).set_ParaList(((ParaList)yyVals[0+yyTop]).get_ParaList()); + + /* otth: originale (also diese) Parameterliste retten */ + ((UsedId)((UsedId)yyVals[-1+yyTop])).vParaOrg = new Vector( ((ParaList)yyVals[0+yyTop]).get_ParaList() ); + } + yyVal=((UsedId)yyVals[-1+yyTop]); + } + break; +case 67: + // line 799 "./../src/mycompiler/myparser/JavaParser.jay" + { yyVal = null; } + break; +case 68: + // line 801 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = ((ParaList)yyVals[-1+yyTop]); + } + break; +case 69: + // line 806 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Interfaces, Spezialform Konstantendef.*/ + yyVal = ((Constant)yyVals[0+yyTop]); + } + break; +case 70: + // line 811 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = ((Method)yyVals[0+yyTop]); + } + break; +case 71: + // line 816 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((FieldDecl)yyVals[0+yyTop]); + } + break; +case 72: + // line 820 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 73: + // line 825 "./../src/mycompiler/myparser/JavaParser.jay" + { + Method STAT = new Method(); + DeclId DST = new DeclId(); + DST.set_Name(((Token)yyVals[-1+yyTop]).getLexem()); + STAT.set_DeclId(DST); + Static ST = new Static(); + Modifiers MOD = new Modifiers(); + MOD.addModifier(ST); + STAT.set_Modifiers(MOD); + STAT.set_Block(((Block)yyVals[0+yyTop])); + yyVal=STAT; + } + break; +case 74: + // line 839 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Constructor)yyVals[-1+yyTop]).set_Block(((Block)yyVals[0+yyTop])); + yyVal = ((Constructor)yyVals[-1+yyTop]); + } + break; +case 75: + // line 844 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Constructor)yyVals[-1+yyTop]).set_Block(((Block)yyVals[0+yyTop])); + ((Constructor)yyVals[-1+yyTop]).set_Modifiers(((Modifiers)yyVals[-2+yyTop])); + yyVal = ((Constructor)yyVals[-1+yyTop]); + } + break; +case 76: + // line 851 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Interface*/ + Constant c = new Constant(((Token)yyVals[-3+yyTop]).getLexem(), ((Modifiers)yyVals[-5+yyTop])); + c.setType(((Type)yyVals[-4+yyTop])); + c.setValue(((Expr)yyVals[-1+yyTop])); + yyVal = c; + } + break; +case 77: + // line 860 "./../src/mycompiler/myparser/JavaParser.jay" + { + /* SCJU: Interface*/ + yyVal = ((Method)yyVals[-1+yyTop]); + } + break; +case 78: + // line 873 "./../src/mycompiler/myparser/JavaParser.jay" + { + FieldInitialization ret = new FieldInitialization(); + ret.set_DeclId(((DeclId)yyVals[-2+yyTop])); + ret.setWert(((Expr)yyVals[0+yyTop])); + yyVal=ret; + } + break; +case 79: + // line 881 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((FieldInitialization)yyVals[-1+yyTop]); + } + break; +case 80: + // line 885 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((FieldInitialization)yyVals[0+yyTop]).setType(((Type)yyVals[-1+yyTop])); + yyVal=((FieldInitialization)yyVals[0+yyTop]); + } + break; +case 81: + // line 891 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((InstVarDecl)yyVals[-1+yyTop]); + } + break; +case 82: + // line 896 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("T->Parser->fielddeclaration ...: type " + ((Type)yyVals[-2+yyTop])); + ((InstVarDecl)yyVals[-1+yyTop]).setType(((Type)yyVals[-2+yyTop])); + yyVal = ((InstVarDecl)yyVals[-1+yyTop]); + } + break; +case 83: + // line 903 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((InstVarDecl)yyVals[-1+yyTop]).setType(((Type)yyVals[-2+yyTop])); + for(int i=0;i<(((InstVarDecl)yyVals[-1+yyTop]).getDeclIdVector().size());i++) + { + ((InstVarDecl)yyVals[-1+yyTop]).getDeclIdVector().elementAt(i).modifiers=((Modifiers)yyVals[-3+yyTop]); + } + yyVal = ((InstVarDecl)yyVals[-1+yyTop]); + } + break; +case 84: + // line 913 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[-1+yyTop]).set_Block(((Block)yyVals[0+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 85: + // line 920 "./../src/mycompiler/myparser/JavaParser.jay" + { + Block Bl = new Block(); + yyVal=Bl; + } + break; +case 86: + // line 926 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Block)yyVals[-1+yyTop]); + } + break; +case 87: + // line 931 "./../src/mycompiler/myparser/JavaParser.jay" + { + Constructor CON = new Constructor(); + DeclId DIDCon = new DeclId(); + DIDCon.set_Name(((UsedId)yyVals[-2+yyTop]).get_Name_1Element()); + CON.set_DeclId(DIDCon); + yyVal=CON; + } + break; +case 88: + // line 939 "./../src/mycompiler/myparser/JavaParser.jay" + { + Constructor CONpara = new Constructor(); + DeclId DIconpara = new DeclId(); + DIconpara.set_Name(((UsedId)yyVals[-3+yyTop]).get_Name_1Element()); + CONpara.set_DeclId(DIconpara); + CONpara.setParameterList(((ParameterList)yyVals[-1+yyTop])); + yyVal=CONpara; + } + break; +case 89: + // line 949 "./../src/mycompiler/myparser/JavaParser.jay" + { + Block CBL = new Block(); + yyVal=CBL; + } + break; +case 90: + // line 954 "./../src/mycompiler/myparser/JavaParser.jay" + { + Block CBLexpl = new Block(); + CBLexpl.set_Statement(((Statement)yyVals[-1+yyTop])); + yyVal=CBLexpl; + } + break; +case 91: + // line 960 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Block)yyVals[-1+yyTop]); + } + break; +case 92: + // line 964 "./../src/mycompiler/myparser/JavaParser.jay" + { + Block CBes = new Block(); + CBes.set_Statement(((Statement)yyVals[-2+yyTop])); + for(int j=0;j<((Block)yyVals[-1+yyTop]).statements.size();j++) + { + CBes.set_Statement((Statement)((Block)yyVals[-1+yyTop]).statements.elementAt(j)); + } + yyVal=CBes; + } + break; +case 93: + // line 975 "./../src/mycompiler/myparser/JavaParser.jay" + { + ExceptionList EL = new ExceptionList(); + EL.set_addElem(((RefType)yyVals[0+yyTop])); + yyVal=EL; + } + break; +case 94: + // line 982 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal = ((GenericTypeVar)yyVals[0+yyTop]); + } + break; +case 95: + // line 987 "./../src/mycompiler/myparser/JavaParser.jay" + { + ParaList p = new ParaList(); + p.add_ParaList(((GenericTypeVar)yyVals[0+yyTop])); + yyVal=p; + } + break; +case 96: + // line 993 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((ParaList)yyVals[-2+yyTop]).add_ParaList(((GenericTypeVar)yyVals[0+yyTop])); + yyVal=((ParaList)yyVals[-2+yyTop]); + } + break; +case 97: + // line 1000 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=new GenericTypeVar(((Token)yyVals[0+yyTop]).getLexem(),((Token)yyVals[0+yyTop]).getOffset()); + } + break; +case 98: + // line 1004 "./../src/mycompiler/myparser/JavaParser.jay" + { + BoundedGenericTypeVar gtv=new BoundedGenericTypeVar(((Token)yyVals[-2+yyTop]).getLexem(),((Token)yyVals[-2+yyTop]).getOffset()); + gtv.setBounds(((Vector)yyVals[0+yyTop])); + yyVal=gtv; + } + break; +case 99: + // line 1011 "./../src/mycompiler/myparser/JavaParser.jay" + { + Vector vec=new Vector(); + vec.addElement(((RefType)yyVals[0+yyTop])); + containedTypes.addElement(((RefType)yyVals[0+yyTop])); + yyVal=vec; + } + break; +case 100: + // line 1018 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Vector)yyVals[-2+yyTop]).addElement(((RefType)yyVals[0+yyTop])); + containedTypes.addElement(((RefType)yyVals[0+yyTop])); + yyVal=((Vector)yyVals[-2+yyTop]); + } + break; +case 101: + // line 1025 "./../src/mycompiler/myparser/JavaParser.jay" + { + Vector vec=new Vector(); + vec.addElement(((GenericTypeVar)yyVals[0+yyTop])); + yyVal=vec; + } + break; +case 102: + // line 1031 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Vector)yyVals[-2+yyTop]).addElement(((GenericTypeVar)yyVals[0+yyTop])); + yyVal=((Vector)yyVals[-2+yyTop]); + } + break; +case 103: + // line 1039 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[0+yyTop]).setReturnType(((Type)yyVals[-1+yyTop])); + ((Method)yyVals[0+yyTop]).setGenericMethodParameters(((Vector)yyVals[-3+yyTop])); + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 104: + // line 1045 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[0+yyTop]).setReturnType(((Type)yyVals[-1+yyTop])); + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 105: + // line 1050 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[0+yyTop]).set_Modifiers(((Modifiers)yyVals[-2+yyTop])); + ((Method)yyVals[0+yyTop]).setReturnType(((Type)yyVals[-1+yyTop])); + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 106: + // line 1056 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[0+yyTop]).set_Modifiers(((Modifiers)yyVals[-5+yyTop])); + ((Method)yyVals[0+yyTop]).setGenericMethodParameters(((Vector)yyVals[-3+yyTop])); + ((Method)yyVals[0+yyTop]).setReturnType(((Type)yyVals[-1+yyTop])); + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 107: + // line 1063 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[-1+yyTop]).setReturnType(((Type)yyVals[-2+yyTop])); + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 108: + // line 1069 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[-1+yyTop]).setGenericMethodParameters(((Vector)yyVals[-4+yyTop])); + ((Method)yyVals[-1+yyTop]).setReturnType(((Type)yyVals[-2+yyTop])); + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 109: + // line 1076 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[-1+yyTop]).set_Modifiers(((Modifiers)yyVals[-3+yyTop])); + ((Method)yyVals[-1+yyTop]).setReturnType(((Type)yyVals[-2+yyTop])); + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 110: + // line 1083 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[-1+yyTop]).set_Modifiers(((Modifiers)yyVals[-6+yyTop])); + ((Method)yyVals[-1+yyTop]).setGenericMethodParameters(((Vector)yyVals[-4+yyTop])); + ((Method)yyVals[-1+yyTop]).setReturnType(((Type)yyVals[-2+yyTop])); + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 111: + // line 1091 "./../src/mycompiler/myparser/JavaParser.jay" + { + Void Voit = new Void(((Token)yyVals[-1+yyTop]).getOffset()); + ((Method)yyVals[0+yyTop]).setReturnType(Voit); + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 112: + // line 1097 "./../src/mycompiler/myparser/JavaParser.jay" + { + Void voit = new Void(((Token)yyVals[-1+yyTop]).getOffset()); + ((Method)yyVals[0+yyTop]).set_Modifiers(((Modifiers)yyVals[-2+yyTop])); + ((Method)yyVals[0+yyTop]).setReturnType(voit); + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 113: + // line 1104 "./../src/mycompiler/myparser/JavaParser.jay" + { + Void voyt = new Void(((Token)yyVals[-2+yyTop]).getOffset()); + ((Method)yyVals[-1+yyTop]).setReturnType(voyt); + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 114: + // line 1111 "./../src/mycompiler/myparser/JavaParser.jay" + { + Void voyd = new Void(((Token)yyVals[-2+yyTop]).getOffset()); + ((Method)yyVals[-1+yyTop]).set_Modifiers(((Modifiers)yyVals[-3+yyTop])); + ((Method)yyVals[-1+yyTop]).setReturnType(voyd); + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 115: + // line 1119 "./../src/mycompiler/myparser/JavaParser.jay" + { + Void Voit = new Void(((Token)yyVals[-1+yyTop]).getOffset()); + ((Method)yyVals[0+yyTop]).setReturnType(Voit); + ((Method)yyVals[0+yyTop]).setGenericMethodParameters(((Vector)yyVals[-3+yyTop])); + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 116: + // line 1126 "./../src/mycompiler/myparser/JavaParser.jay" + { + Void voit = new Void(((Token)yyVals[-1+yyTop]).getOffset()); + ((Method)yyVals[0+yyTop]).set_Modifiers(((Modifiers)yyVals[-5+yyTop])); + ((Method)yyVals[0+yyTop]).setReturnType(voit); + ((Method)yyVals[0+yyTop]).setGenericMethodParameters(((Vector)yyVals[-3+yyTop])); + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 117: + // line 1134 "./../src/mycompiler/myparser/JavaParser.jay" + { + Void voyt = new Void(((Token)yyVals[-2+yyTop]).getOffset()); + ((Method)yyVals[-1+yyTop]).setReturnType(voyt); + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + ((Method)yyVals[-1+yyTop]).setGenericMethodParameters(((Vector)yyVals[-4+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 118: + // line 1142 "./../src/mycompiler/myparser/JavaParser.jay" + { + Void voyd = new Void(((Token)yyVals[-2+yyTop]).getOffset()); + ((Method)yyVals[-1+yyTop]).set_Modifiers(((Modifiers)yyVals[-6+yyTop])); + ((Method)yyVals[-1+yyTop]).setReturnType(voyd); + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + ((Method)yyVals[-1+yyTop]).setGenericMethodParameters(((Vector)yyVals[-4+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 119: + // line 1152 "./../src/mycompiler/myparser/JavaParser.jay" + { + /*auskommentiert von Andreas Stadelmeier (a10023) $1.setReturnType(TypePlaceholder.fresh()); */ + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 120: + // line 1157 "./../src/mycompiler/myparser/JavaParser.jay" + { + /*auskommentiert von Andreas Stadelmeier (a10023) $4.setReturnType(TypePlaceholder.fresh());*/ + ((Method)yyVals[0+yyTop]).setGenericMethodParameters(((Vector)yyVals[-2+yyTop])); + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 121: + // line 1164 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[0+yyTop]).set_Modifiers(((Modifiers)yyVals[-1+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) $2.setReturnType(TypePlaceholder.fresh());*/ + yyVal=((Method)yyVals[0+yyTop]); + } + break; +case 122: + // line 1170 "./../src/mycompiler/myparser/JavaParser.jay" + { + /*auskommentiert von Andreas Stadelmeier (a10023) $1.setReturnType(TypePlaceholder.fresh());*/ + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 123: + // line 1176 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Method)yyVals[-1+yyTop]).set_Modifiers(((Modifiers)yyVals[-2+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) $2.setReturnType(TypePlaceholder.fresh());*/ + ((Method)yyVals[-1+yyTop]).set_ExceptionList(((ExceptionList)yyVals[0+yyTop])); + yyVal=((Method)yyVals[-1+yyTop]); + } + break; +case 124: + // line 1185 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((BaseType)yyVals[0+yyTop]); + } + break; +case 125: + // line 1189 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((BaseType)yyVals[-2+yyTop]).setArray(true); + } + break; +case 126: + // line 1193 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((RefType)yyVals[0+yyTop]); + } + break; +case 127: + // line 1197 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((RefType)yyVals[-2+yyTop]).setArray(true); + } + break; +case 128: + // line 1201 "./../src/mycompiler/myparser/JavaParser.jay" + { + InstVarDecl IVD = new InstVarDecl(); + IVD.getDeclIdVector().addElement( ((DeclId)yyVals[0+yyTop]) ); + yyVal = IVD; + } + break; +case 129: + // line 1207 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((InstVarDecl)yyVals[-2+yyTop]).getDeclIdVector().addElement(((DeclId)yyVals[0+yyTop])); + yyVal=((InstVarDecl)yyVals[-2+yyTop]); + } + break; +case 130: + // line 1213 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Block)yyVals[0+yyTop]); + } + break; +case 131: + // line 1218 "./../src/mycompiler/myparser/JavaParser.jay" + { + Block Blstat = new Block(); + Blstat.set_Statement(((Statement)yyVals[0+yyTop])); + yyVal=Blstat; + } + break; +case 132: + // line 1225 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((Block)yyVals[-1+yyTop]).set_Statement(((Statement)yyVals[0+yyTop])); + yyVal=((Block)yyVals[-1+yyTop]); + } + break; +case 133: + // line 1231 "./../src/mycompiler/myparser/JavaParser.jay" + { + ParameterList PL = new ParameterList(); + PL.set_AddParameter(((FormalParameter)yyVals[0+yyTop])); + yyVal = PL; + } + break; +case 134: + // line 1237 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((ParameterList)yyVals[-2+yyTop]).set_AddParameter(((FormalParameter)yyVals[0+yyTop])); + yyVal = ((ParameterList)yyVals[-2+yyTop]); + } + break; +case 135: + // line 1243 "./../src/mycompiler/myparser/JavaParser.jay" + { + This THCON = new This(((Token)yyVals[-3+yyTop]).getOffset(),((Token)yyVals[-3+yyTop]).getLexem().length()); + yyVal=THCON; + } + break; +case 136: + // line 1248 "./../src/mycompiler/myparser/JavaParser.jay" + { + This THCONargl = new This(((Token)yyVals[-4+yyTop]).getOffset(),((Token)yyVals[-4+yyTop]).getLexem().length()); + THCONargl.set_ArgumentList(((ArgumentList)yyVals[-2+yyTop])); + yyVal=THCONargl; + } + break; +case 137: + // line 1257 "./../src/mycompiler/myparser/JavaParser.jay" + { + RefType RT = new RefType(-1); + RT.set_UsedId(((UsedId)yyVals[0+yyTop])); + RT.setName(RT.get_UsedId().get_Name_1Element()); + yyVal=RT; + } + break; +case 138: + // line 1264 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((RefType)yyVals[-2+yyTop]).set_UsedId(((UsedId)yyVals[0+yyTop])); + ((RefType)yyVals[-2+yyTop]).setName(((RefType)yyVals[-2+yyTop]).get_UsedId().get_Name_1Element()); + yyVal=((RefType)yyVals[-2+yyTop]); + } + break; +case 139: + // line 1271 "./../src/mycompiler/myparser/JavaParser.jay" + { + Method met = new Method(); + /* #JB# 10.04.2005 */ + /* ########################################################### */ + met.setLineNumber(((Token)yyVals[-2+yyTop]).getLineNumber()); + met.setOffset(((Token)yyVals[-2+yyTop]).getOffset());/*hinzugef�gt hoth: 07.04.2006*/ + /* ########################################################### */ + DeclId DImethod = new DeclId(); + DImethod.set_Name(((Token)yyVals[-2+yyTop]).getLexem()); + met.set_DeclId(DImethod); + yyVal = met; + } + break; +case 140: + // line 1284 "./../src/mycompiler/myparser/JavaParser.jay" + { + Method met_para = new Method(); + /* #JB# 10.04.2005 */ + /* ########################################################### */ + met_para.setLineNumber(((Token)yyVals[-3+yyTop]).getLineNumber()); + met_para.setOffset(((Token)yyVals[-3+yyTop]).getOffset());/*hinzugef�gt hoth: 07.04.2006*/ + /* ########################################################### */ + DeclId Dimet_para = new DeclId(); + Dimet_para.set_Name(((Token)yyVals[-3+yyTop]).getLexem()); + met_para.set_DeclId(Dimet_para); + met_para.setParameterList(((ParameterList)yyVals[-1+yyTop])); + yyVal = met_para; + } + break; +case 141: + // line 1299 "./../src/mycompiler/myparser/JavaParser.jay" + { + BooleanType BT = new BooleanType(); + /* #JB# 05.04.2005 */ + /* ########################################################### */ + /*BT.setName($1.getLexem());*/ + /* ########################################################### */ + yyVal=BT; + } + break; +case 142: + // line 1308 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((BaseType)yyVals[0+yyTop]); + } + break; +case 143: + // line 1314 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("T->Parser->referenctype: " + ((UsedId)yyVals[0+yyTop])); + RefType RT = new RefType(((UsedId)yyVals[0+yyTop]).getOffset()); + + /*ausgetauscht PL 05-07-30*/ + /*RT.set_UsedId($1); */ + /*RT.setName(RT.get_UsedId().get_Name_1Element());*/ + RT.set_ParaList(((UsedId)yyVals[0+yyTop]).get_RealParaList()); + RT.setName(((UsedId)yyVals[0+yyTop]).getQualifiedName()); + + + /*PL 05-07-30 eingefuegt containedTypes ANFANG*/ + containedTypes.addElement(RT); + /*PL 05-07-30 eingefuegt containedTypes ENDE*/ + + yyVal=RT; + } + break; +case 144: + // line 1334 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((DeclId)yyVals[0+yyTop]); + } + break; +case 145: + // line 1355 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((LocalVarDecl)yyVals[0+yyTop]); + } + break; +case 146: + // line 1359 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Statement)yyVals[0+yyTop]); + } + break; +case 147: + // line 1364 "./../src/mycompiler/myparser/JavaParser.jay" + { + FormalParameter FP = new FormalParameter(); + FP.setType(((Type)yyVals[-1+yyTop])); + FP.set_DeclId(((DeclId)yyVals[0+yyTop])); + yyVal=FP; + } + break; +case 148: + // line 1389 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("\nFunktionsdeklaration mit typlosen Parametern: " + ((DeclId)yyVals[0+yyTop]).name); + + FormalParameter FP = new FormalParameter(); + + /* #JB# 31.03.2005*/ + /* ###########################################################*/ + Type T = TypePlaceholder.fresh(); + /* Type T = new TypePlaceholder(""); /* otth: Name wird automatisch berechnet * /*/ + /* ###########################################################*/ + org.apache.log4j.Logger.getLogger("parser").debug("\n--> berechneter Name: " + T.getName()); + + /*auskommentiert von Andreas Stadelmeier (a10023) FP.setType( T );*/ + FP.set_DeclId(((DeclId)yyVals[0+yyTop])); + + yyVal=FP; + } + break; +case 149: + // line 1408 "./../src/mycompiler/myparser/JavaParser.jay" + { + ArgumentList AL = new ArgumentList(); + AL.expr.addElement(((Expr)yyVals[0+yyTop])); + yyVal=AL; + } + break; +case 150: + // line 1414 "./../src/mycompiler/myparser/JavaParser.jay" + { + ((ArgumentList)yyVals[-2+yyTop]).expr.addElement(((Expr)yyVals[0+yyTop])); + yyVal=((ArgumentList)yyVals[-2+yyTop]); + } + break; +case 151: + // line 1420 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((BaseType)yyVals[0+yyTop]); + } + break; +case 152: + // line 1425 "./../src/mycompiler/myparser/JavaParser.jay" + { + DeclId DI = new DeclId(); + /* #JB# 10.04.2005 */ + /* ########################################################### */ + DI.setLineNumber(((Token)yyVals[0+yyTop]).getLineNumber()); + DI.setOffset(((Token)yyVals[0+yyTop]).getOffset());/*hinzugef�gt hoth: 07.04.2006*/ + /* ########################################################### */ + DI.set_Name(((Token)yyVals[0+yyTop]).getLexem()); + yyVal=DI; + } + break; +case 153: + // line 1437 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 154: + // line 1442 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((LocalVarDecl)yyVals[-1+yyTop]); + } + break; +case 155: + // line 1447 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Statement)yyVals[0+yyTop]); + } + break; +case 156: + // line 1451 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((IfStmt)yyVals[0+yyTop]); + } + break; +case 157: + // line 1455 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((IfStmt)yyVals[0+yyTop]); + } + break; +case 158: + // line 1459 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((WhileStmt)yyVals[0+yyTop]); + } + break; +case 159: + // line 1463 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((ForStmt)yyVals[0+yyTop]); + } + break; +case 160: + // line 1468 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 161: + // line 1472 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((NewClass)yyVals[0+yyTop]); + } + break; +case 162: + // line 1477 "./../src/mycompiler/myparser/JavaParser.jay" + { + IntegerType IT = new IntegerType(); + /* #JB# 05.04.2005 */ + /* ########################################################### */ + /*IT.setName($1.getLexem());*/ + /* ########################################################### */ + yyVal=IT; + } + break; +case 163: + // line 1486 "./../src/mycompiler/myparser/JavaParser.jay" + { + CharacterType CT = new CharacterType(); + /* #JB# 05.04.2005 */ + /* ########################################################### */ + /*CT.setName($1.getLexem());*/ + /* ########################################################### */ + yyVal=CT; + } + break; +case 164: + // line 1496 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); + LocalVarDecl LVD = new LocalVarDecl(((Type)yyVals[-1+yyTop]).getOffset(),((Type)yyVals[-1+yyTop]).getVariableLength()); + LVD.setType(((Type)yyVals[-1+yyTop])); + LVD.setDeclidVector(((InstVarDecl)yyVals[0+yyTop]).getDeclIdVector()); + yyVal = LVD; + } + break; +case 165: + // line 1507 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); + LocalVarDecl LVD = new LocalVarDecl(((InstVarDecl)yyVals[0+yyTop]).getOffset(),((InstVarDecl)yyVals[0+yyTop]).getVariableLength()); + /*auskommentiert von Andreas Stadelmeier (a10023) LVD.setType(TypePlaceholder.fresh());*/ + LVD.setDeclidVector(((InstVarDecl)yyVals[0+yyTop]).getDeclIdVector()); + yyVal = LVD; + } + break; +case 166: + // line 1517 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Block)yyVals[0+yyTop]); + } + break; +case 167: + // line 1521 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((EmptyStmt)yyVals[0+yyTop]); + } + break; +case 168: + // line 1525 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((ExprStmt)yyVals[0+yyTop]); + } + break; +case 169: + // line 1529 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Return)yyVals[0+yyTop]); + } + break; +case 170: + // line 1534 "./../src/mycompiler/myparser/JavaParser.jay" + { + IfStmt Ifst = new IfStmt(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + Ifst.set_Expr(((Expr)yyVals[-2+yyTop])); + Ifst.set_Then_block(((Statement)yyVals[0+yyTop])); + yyVal=Ifst; + } + break; +case 171: + // line 1542 "./../src/mycompiler/myparser/JavaParser.jay" + { + IfStmt IfstElst = new IfStmt(((Expr)yyVals[-4+yyTop]).getOffset(),((Expr)yyVals[-4+yyTop]).getVariableLength()); + IfstElst.set_Expr(((Expr)yyVals[-4+yyTop])); + IfstElst.set_Then_block(((Statement)yyVals[-2+yyTop])); + IfstElst.set_Else_block(((Statement)yyVals[0+yyTop])); + yyVal=IfstElst; + } + break; +case 172: + // line 1551 "./../src/mycompiler/myparser/JavaParser.jay" + { + WhileStmt Whlst = new WhileStmt(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + Whlst.set_Expr(((Expr)yyVals[-2+yyTop])); + Whlst.set_Loop_block(((Statement)yyVals[0+yyTop])); + yyVal=Whlst; + } + break; +case 173: + // line 1562 "./../src/mycompiler/myparser/JavaParser.jay" + { + ForStmt Fst = new ForStmt(((Expr)yyVals[-6+yyTop]).getOffset(),((Expr)yyVals[-6+yyTop]).getVariableLength()); + Fst.set_head_Initializer(((Expr)yyVals[-6+yyTop])); + Fst.set_head_Condition(((Expr)yyVals[-4+yyTop])); + Fst.set_head_Loop_expr(((Expr)yyVals[-2+yyTop])); + Fst.set_body_Loop_block(((Statement)yyVals[0+yyTop])); + + /*Typannahme*/ + yyVal = Fst; + } + break; +case 174: + // line 1574 "./../src/mycompiler/myparser/JavaParser.jay" + { + ForStmt Fst = new ForStmt(((Expr)yyVals[-5+yyTop]).getOffset(),((Expr)yyVals[-5+yyTop]).getVariableLength()); + Fst.set_head_Initializer(((Expr)yyVals[-5+yyTop])); + Fst.set_head_Condition(((Expr)yyVals[-3+yyTop])); + Fst.set_body_Loop_block(((Statement)yyVals[0+yyTop])); + + /*Typannahme*/ + yyVal = Fst; + } + break; +case 175: + // line 1585 "./../src/mycompiler/myparser/JavaParser.jay" + { + ForStmt Fst = new ForStmt(((Expr)yyVals[-5+yyTop]).getOffset(),((Expr)yyVals[-5+yyTop]).getVariableLength()); + Fst.set_head_Initializer(((Expr)yyVals[-5+yyTop])); + Fst.set_head_Loop_expr(((Expr)yyVals[-2+yyTop])); + Fst.set_body_Loop_block(((Statement)yyVals[0+yyTop])); + + /*Typannahme*/ + yyVal = Fst; + } + break; +case 176: + // line 1596 "./../src/mycompiler/myparser/JavaParser.jay" + { + ForStmt Fst = new ForStmt(((Expr)yyVals[-4+yyTop]).getOffset(),((Expr)yyVals[-4+yyTop]).getVariableLength()); + Fst.set_head_Condition(((Expr)yyVals[-4+yyTop])); + Fst.set_head_Loop_expr(((Expr)yyVals[-2+yyTop])); + Fst.set_body_Loop_block(((Statement)yyVals[0+yyTop])); + + /*Typannahme*/ + yyVal = Fst; + } + break; +case 177: + // line 1607 "./../src/mycompiler/myparser/JavaParser.jay" + { + ForStmt Fst = new ForStmt(((Expr)yyVals[-4+yyTop]).getOffset(),((Expr)yyVals[-4+yyTop]).getVariableLength()); + Fst.set_head_Initializer(((Expr)yyVals[-4+yyTop])); + Fst.set_body_Loop_block(((Statement)yyVals[0+yyTop])); + + /*Typannahme*/ + yyVal = Fst; + } + break; +case 178: + // line 1617 "./../src/mycompiler/myparser/JavaParser.jay" + { + ForStmt Fst = new ForStmt(((Expr)yyVals[-3+yyTop]).getOffset(),((Expr)yyVals[-3+yyTop]).getVariableLength()); + Fst.set_head_Condition(((Expr)yyVals[-3+yyTop])); + Fst.set_body_Loop_block(((Statement)yyVals[0+yyTop])); + + /*Typannahme*/ + yyVal = Fst; + } + break; +case 179: + // line 1627 "./../src/mycompiler/myparser/JavaParser.jay" + { + ForStmt Fst = new ForStmt(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + Fst.set_head_Loop_expr(((Expr)yyVals[-2+yyTop])); + Fst.set_body_Loop_block(((Statement)yyVals[0+yyTop])); + + /*Typannahme*/ + yyVal = Fst; + } + break; +case 180: + // line 1637 "./../src/mycompiler/myparser/JavaParser.jay" + { + ForStmt Fst = new ForStmt(((Statement)yyVals[0+yyTop]).getOffset(),((Statement)yyVals[0+yyTop]).getVariableLength()); + Fst.set_body_Loop_block(((Statement)yyVals[0+yyTop])); + + /*Typannahme*/ + yyVal = Fst; + } + break; +case 181: + // line 1646 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("conditionalexpression"); + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 182: + // line 1651 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Assign)yyVals[0+yyTop]); + } + break; +case 183: + // line 1657 "./../src/mycompiler/myparser/JavaParser.jay" + { + EmptyStmt Empst = new EmptyStmt(); + yyVal=Empst; + } + break; +case 184: + // line 1663 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[-1+yyTop]); + } + break; +case 185: + // line 1668 "./../src/mycompiler/myparser/JavaParser.jay" + { + Return ret = new Return(-1,-1); + yyVal= ret; + } + break; +case 186: + // line 1673 "./../src/mycompiler/myparser/JavaParser.jay" + { + Return retexp = new Return(((Expr)yyVals[-1+yyTop]).getOffset(),((Expr)yyVals[-1+yyTop]).getVariableLength()); + retexp.set_ReturnExpr(((Expr)yyVals[-1+yyTop])); + yyVal=retexp; + } + break; +case 187: + // line 1680 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Statement)yyVals[0+yyTop]); + } + break; +case 188: + // line 1684 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((IfStmt)yyVals[0+yyTop]); + } + break; +case 189: + // line 1688 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((WhileStmt)yyVals[0+yyTop]); + } + break; +case 190: + // line 1693 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 191: + // line 1699 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("\nParser --> Zuweisung1!\n"); + Assign Ass = new Assign(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); + LocalOrFieldVar LOFV = new LocalOrFieldVar(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); + LOFV.set_UsedId(((UsedId)yyVals[-2+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());*/ + /*auskommentiert von Andreas Stadelmeier (a10023) Ass.setType(TypePlaceholder.fresh());*/ + if( ((Operator)yyVals[-1+yyTop]) == null ) + { + org.apache.log4j.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> " + ((Expr)yyVals[0+yyTop]) + " \n"); + Ass.set_Expr( LOFV,((Expr)yyVals[0+yyTop]) ); + } + else + { + Binary Bin = new Binary(((Expr)yyVals[0+yyTop]).getOffset(),((Expr)yyVals[0+yyTop]).getVariableLength()); + Bin.set_Expr1(LOFV); + Bin.set_Operator(((Operator)yyVals[-1+yyTop])); + Bin.set_Expr2(((Expr)yyVals[0+yyTop])); + org.apache.log4j.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> Binary\n"); + /*auskommentiert von Andreas Stadelmeier (a10023) Bin.setType(TypePlaceholder.fresh());*/ + Ass.set_Expr( LOFV, Bin ); + } + yyVal=Ass; + } + break; +case 192: + // line 1724 "./../src/mycompiler/myparser/JavaParser.jay" + { + Assign Ass =new Assign(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); + LocalOrFieldVar LOFV = new LocalOrFieldVar(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); + LOFV.set_UsedId(((UsedId)yyVals[-2+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());*/ + /*auskommentiert von Andreas Stadelmeier (a10023) Ass.setType(TypePlaceholder.fresh());*/ + if(((Operator)yyVals[-1+yyTop])==null) + { + Ass.set_Expr(LOFV,((NewClass)yyVals[0+yyTop])); + } + else + { + Binary Bin = new Binary(((NewClass)yyVals[0+yyTop]).getOffset(),((NewClass)yyVals[0+yyTop]).getVariableLength()); + Bin.set_Expr1(LOFV); + Bin.set_Operator(((Operator)yyVals[-1+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) Bin.setType(TypePlaceholder.fresh());*/ + Bin.set_Expr2(((NewClass)yyVals[0+yyTop])); + Ass.set_Expr(LOFV,Bin); + } + yyVal=Ass; + } + break; +case 193: + // line 1747 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Assign)yyVals[0+yyTop]); + } + break; +case 194: + // line 1751 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 195: + // line 1755 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 196: + // line 1759 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 197: + // line 1763 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 198: + // line 1767 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((MethodCall)yyVals[0+yyTop]); + } + break; +case 199: + // line 1778 "./../src/mycompiler/myparser/JavaParser.jay" + { + IfStmt IfElno = new IfStmt(((Expr)yyVals[-4+yyTop]).getOffset(),((Expr)yyVals[-4+yyTop]).getVariableLength()); + IfElno.set_Expr(((Expr)yyVals[-4+yyTop])); + IfElno.set_Then_block(((Statement)yyVals[-2+yyTop])); + IfElno.set_Else_block(((Statement)yyVals[0+yyTop])); + yyVal=IfElno; + } + break; +case 200: + // line 1787 "./../src/mycompiler/myparser/JavaParser.jay" + { + WhileStmt Whstno = new WhileStmt(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + Whstno.set_Expr(((Expr)yyVals[-2+yyTop])); + Whstno.set_Loop_block(((Statement)yyVals[0+yyTop])); + yyVal=Whstno; + } + break; +case 201: + // line 1795 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 202: + // line 1799 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary LogOr = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + OrOp OrO = new OrOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + LogOr.set_Expr1(((Expr)yyVals[-2+yyTop])); + LogOr.set_Expr2(((Expr)yyVals[0+yyTop])); + LogOr.set_Operator(OrO); + /*auskommentiert von Andreas Stadelmeier (a10023) LogOr.setType(TypePlaceholder.fresh());*/ + yyVal=LogOr; + } + break; +case 203: + // line 1812 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=null; + } + break; +case 204: + // line 1817 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Block)yyVals[0+yyTop]); + } + break; +case 205: + // line 1821 "./../src/mycompiler/myparser/JavaParser.jay" + { + /*Lambdabody kann auch nur aus einer Expression bestehen. In diesem Fall wird ein Block erstellt, welcher als einziges Statement ein return statment mit der expression hat.*/ + /*Bsp.: Aus der Expression |var=="hallo"| wird: |{return var=="hallo";}|*/ + Block ret=new Block(); + ret.statements.add((Statement)new Return(0,0).set_ReturnExpr(((Expr)yyVals[0+yyTop]))); + /*ret.statements.add((ExprStmt)$1);*/ + yyVal=ret; + } + break; +case 206: + // line 1831 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=null; + } + break; +case 207: + // line 1835 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((ParameterList)yyVals[-1+yyTop]); + } + break; +case 208: + // line 1840 "./../src/mycompiler/myparser/JavaParser.jay" + { + LambdaExpression lambda = new LambdaExpression(/*((ParameSterList)$2).getOffset(),((ParameterList)$2).getVariableLength()*/0,0); + if(((ParameterList)yyVals[-2+yyTop])!=null)lambda.setParameterList(((ParameterList)yyVals[-2+yyTop])); + lambda.setBody((Block)((Block)yyVals[0+yyTop])); + yyVal=lambda; + } + break; +case 209: + // line 1859 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((UsedId)yyVals[0+yyTop]); + } + break; +case 210: + // line 1864 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=null; + } + break; +case 211: + // line 1868 "./../src/mycompiler/myparser/JavaParser.jay" + { + TimesOp TEO = new TimesOp(-1,-1); + yyVal=TEO; + } + break; +case 212: + // line 1873 "./../src/mycompiler/myparser/JavaParser.jay" + { + DivideOp DEO = new DivideOp(-1,-1); + yyVal=DEO; + } + break; +case 213: + // line 1878 "./../src/mycompiler/myparser/JavaParser.jay" + { + ModuloOp MEO = new ModuloOp(-1,-1); + yyVal=MEO; + } + break; +case 214: + // line 1883 "./../src/mycompiler/myparser/JavaParser.jay" + { + PlusOp PEO = new PlusOp(-1,-1); + yyVal=PEO; + } + break; +case 215: + // line 1888 "./../src/mycompiler/myparser/JavaParser.jay" + { + MinusOp MEO = new MinusOp(-1,-1); + yyVal=MEO; + } + break; +case 216: + // line 1900 "./../src/mycompiler/myparser/JavaParser.jay" + { + PreIncExpr PRINC = new PreIncExpr(((Expr)yyVals[0+yyTop]).getOffset(),((Expr)yyVals[0+yyTop]).getVariableLength()); + PRINC.set_Expr(((Expr)yyVals[0+yyTop])); + yyVal=PRINC; + } + break; +case 217: + // line 1907 "./../src/mycompiler/myparser/JavaParser.jay" + { + PreDecExpr PRDEC = new PreDecExpr(((Expr)yyVals[0+yyTop]).getOffset(),((Expr)yyVals[0+yyTop]).getVariableLength()); + PRDEC.set_Expr(((Expr)yyVals[0+yyTop])); + yyVal=PRDEC; + } + break; +case 218: + // line 1914 "./../src/mycompiler/myparser/JavaParser.jay" + { + PostIncExpr PIE = new PostIncExpr(((Expr)yyVals[-1+yyTop]).getOffset(),((Expr)yyVals[-1+yyTop]).getVariableLength()); + PIE.set_Expr(((Expr)yyVals[-1+yyTop])); + yyVal=PIE; + } + break; +case 219: + // line 1921 "./../src/mycompiler/myparser/JavaParser.jay" + { + PostDecExpr PDE = new PostDecExpr(((Expr)yyVals[-1+yyTop]).getOffset(),((Expr)yyVals[-1+yyTop]).getVariableLength()); + PDE.set_Expr(((Expr)yyVals[-1+yyTop])); + yyVal=PDE; + } + break; +case 220: + // line 1929 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("M1"); + MethodCall MC = new MethodCall(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); + UsedId udidmeth = new UsedId(((UsedId)yyVals[-2+yyTop]).getOffset()); + udidmeth.set_Name((String)((((UsedId)yyVals[-2+yyTop]).get_Name()).elementAt(((UsedId)yyVals[-2+yyTop]).get_Name().size()-1))); + MC.set_UsedId(udidmeth); + Receiver rec = null; + if (((UsedId)yyVals[-2+yyTop]).get_Name().size() > 2) { + + ((UsedId)yyVals[-2+yyTop]).removeLast(); + + /*macht aus der Liste von Strings */ + /*in usedid.name einen InstVar */ + InstVar INSTVA = new InstVar(((UsedId)yyVals[-2+yyTop]),((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); + + /*auskommentiert von Andreas Stadelmeier (a10023) INSTVA.setType(TypePlaceholder.fresh());*/ + rec = new Receiver(INSTVA); + } + else if (((UsedId)yyVals[-2+yyTop]).get_Name().size() == 2) { + LocalOrFieldVar LOFV = new LocalOrFieldVar(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); + ((UsedId)yyVals[-2+yyTop]).removeLast(); + LOFV.set_UsedId(((UsedId)yyVals[-2+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());*/ + rec = new Receiver(LOFV); + } + MC.set_Receiver(rec); + /*auskommentiert von Andreas Stadelmeier (a10023) MC.setType(TypePlaceholder.fresh());*/ + yyVal=MC; + } + break; +case 221: + // line 1959 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("M2"); + MethodCall MCarg = new MethodCall(((UsedId)yyVals[-3+yyTop]).getOffset(),((UsedId)yyVals[-3+yyTop]).getVariableLength()); + UsedId udidmeth = new UsedId(((UsedId)yyVals[-3+yyTop]).getOffset()); + udidmeth.set_Name((String)((((UsedId)yyVals[-3+yyTop]).get_Name()).elementAt(((UsedId)yyVals[-3+yyTop]).get_Name().size()-1))); + MCarg.set_UsedId(udidmeth); + Receiver rec = null; + if (((UsedId)yyVals[-3+yyTop]).get_Name().size() > 2) { + + ((UsedId)yyVals[-3+yyTop]).removeLast(); + + /*macht aus der Liste von Strings */ + /*in usedid.name einen InstVar */ + InstVar INSTVA = new InstVar(((UsedId)yyVals[-3+yyTop]),((UsedId)yyVals[-3+yyTop]).getOffset(),((UsedId)yyVals[-3+yyTop]).getVariableLength()); + + /*auskommentiert von Andreas Stadelmeier (a10023) INSTVA.setType(TypePlaceholder.fresh());*/ + rec = new Receiver(INSTVA); + } + else if (((UsedId)yyVals[-3+yyTop]).get_Name().size() == 2) { + LocalOrFieldVar LOFV = new LocalOrFieldVar(((UsedId)yyVals[-3+yyTop]).getOffset(),((UsedId)yyVals[-3+yyTop]).getVariableLength()); + ((UsedId)yyVals[-3+yyTop]).removeLast(); + LOFV.set_UsedId(((UsedId)yyVals[-3+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());*/ + rec = new Receiver(LOFV); + } + MCarg.set_Receiver(rec); + MCarg.set_ArgumentList(((ArgumentList)yyVals[-1+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) MCarg.setType(TypePlaceholder.fresh());*/ + yyVal=MCarg; + } + break; +case 222: + // line 1990 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("M3"); + MethodCall MCpr = new MethodCall(((Expr)yyVals[-4+yyTop]).getOffset(),((Expr)yyVals[-4+yyTop]).getVariableLength()); + + /* PL 05-08-21 primary ist kein UsedId*/ + /*$1.usedid.set_Name($3.getLexem());*/ + /*MCpr.set_UsedId($1.get_UsedId());*/ + UsedId udidmeth = new UsedId(((Expr)yyVals[-4+yyTop]).getOffset()); + udidmeth.set_Name(((Token)yyVals[-2+yyTop]).getLexem()); + MCpr.set_UsedId(udidmeth); + + /* #JB# 04.06.2005 */ + /* ########################################################### */ + MCpr.set_Receiver(new Receiver(((Expr)yyVals[-4+yyTop]))); + /* ########################################################### */ + /*auskommentiert von Andreas Stadelmeier (a10023) MCpr.setType(TypePlaceholder.fresh());*/ + yyVal=MCpr; + } + break; +case 223: + // line 2009 "./../src/mycompiler/myparser/JavaParser.jay" + { + org.apache.log4j.Logger.getLogger("parser").debug("M4"); + MethodCall MCPA = new MethodCall(((Expr)yyVals[-5+yyTop]).getOffset(),((Expr)yyVals[-5+yyTop]).getVariableLength()); + + /* PL 05-08-21 primary ist kein UsedId*/ + /*$1.usedid.set_Name($3.getLexem());*/ + /*MCPA.set_UsedId($1.get_UsedId());*/ + UsedId udidmeth = new UsedId(((Token)yyVals[-3+yyTop]).getOffset()); + udidmeth.set_Name(((Token)yyVals[-3+yyTop]).getLexem()); + MCPA.set_UsedId(udidmeth); + + /* #JB# 04.06.2005 */ + /* ########################################################### */ + MCPA.set_Receiver(new Receiver(((Expr)yyVals[-5+yyTop]))); + /* ########################################################### */ + MCPA.set_ArgumentList(((ArgumentList)yyVals[-1+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) MCPA.setType(TypePlaceholder.fresh());*/ + yyVal=MCPA; + } + break; +case 224: + // line 2032 "./../src/mycompiler/myparser/JavaParser.jay" + { + NewClass NC = new NewClass(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); + NC.set_UsedId(((UsedId)yyVals[-2+yyTop])); + usedIdsToCheck.addElement(((UsedId)yyVals[-2+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) NC.setType(TypePlaceholder.fresh());*/ + yyVal=NC; + } + break; +case 225: + // line 2040 "./../src/mycompiler/myparser/JavaParser.jay" + { + NewClass NCarg = new NewClass(((UsedId)yyVals[-3+yyTop]).getOffset(),((UsedId)yyVals[-3+yyTop]).getVariableLength()); + NCarg.set_UsedId(((UsedId)yyVals[-3+yyTop])); + usedIdsToCheck.addElement(((UsedId)yyVals[-3+yyTop])); + NCarg.set_ArgumentList(((ArgumentList)yyVals[-1+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) NCarg.setType(TypePlaceholder.fresh());*/ + yyVal=NCarg; + } + break; +case 226: + // line 2050 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 227: + // line 2054 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary And = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + AndOp AndO = new AndOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + And.set_Expr1(((Expr)yyVals[-2+yyTop])); + And.set_Expr2(((Expr)yyVals[0+yyTop])); + And.set_Operator(AndO); + /*auskommentiert von Andreas Stadelmeier (a10023) And.setType(TypePlaceholder.fresh());*/ + yyVal=And; + } + break; +case 228: + // line 2070 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 229: + // line 2074 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 230: + // line 2078 "./../src/mycompiler/myparser/JavaParser.jay" + { + PositivExpr POSEX=new PositivExpr(((Expr)yyVals[0+yyTop]).getOffset(),((Expr)yyVals[0+yyTop]).getVariableLength()); + UnaryPlus UP= new UnaryPlus(); + POSEX.set_UnaryPlus(UP); + POSEX.set_Expr(((Expr)yyVals[0+yyTop])); + yyVal=POSEX; + } + break; +case 231: + // line 2086 "./../src/mycompiler/myparser/JavaParser.jay" + { + NegativeExpr NEGEX=new NegativeExpr(((Expr)yyVals[0+yyTop]).getOffset(),((Expr)yyVals[0+yyTop]).getVariableLength()); + UnaryMinus UM=new UnaryMinus(); + NEGEX.set_UnaryMinus(UM); + NEGEX.set_Expr(((Expr)yyVals[0+yyTop])); + yyVal=NEGEX; + } + break; +case 232: + // line 2094 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 233: + // line 2099 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 234: + // line 2103 "./../src/mycompiler/myparser/JavaParser.jay" + { + if (((UsedId)yyVals[0+yyTop]).get_Name().size() > 1) { + + /*macht aus der Liste von Strings */ + /*in usedid.name einen InstVar */ + InstVar INSTVA = new InstVar(((UsedId)yyVals[0+yyTop]),((UsedId)yyVals[0+yyTop]).getOffset(),((UsedId)yyVals[0+yyTop]).getVariableLength()); + + /*auskommentiert von Andreas Stadelmeier (a10023) INSTVA.setType(TypePlaceholder.fresh());*/ + yyVal = INSTVA; + } + else { + LocalOrFieldVar Postincexpr = new LocalOrFieldVar(((UsedId)yyVals[0+yyTop]).getOffset(),((UsedId)yyVals[0+yyTop]).getVariableLength()); + Postincexpr.set_UsedId(((UsedId)yyVals[0+yyTop])); + /*auskommentiert von Andreas Stadelmeier (a10023) Postincexpr.setType(TypePlaceholder.fresh());*/ + yyVal=Postincexpr; + } + } + break; +case 235: + // line 2121 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 236: + // line 2125 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 237: + // line 2130 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 238: + // line 2135 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 240: + // line 2141 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Literal)yyVals[0+yyTop]); + } + break; +case 241: + // line 2145 "./../src/mycompiler/myparser/JavaParser.jay" + { + This T = new This(((Token)yyVals[0+yyTop]).getOffset(),((Token)yyVals[0+yyTop]).getLexem().length()); + UsedId UT = new UsedId(((Token)yyVals[0+yyTop]).getOffset()); + UT.set_Name(((Token)yyVals[0+yyTop]).getLexem()); + T.set_UsedId(UT); + yyVal=T; + } + break; +case 242: + // line 2166 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((MethodCall)yyVals[0+yyTop]); + } + break; +case 243: + // line 2170 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 244: + // line 2175 "./../src/mycompiler/myparser/JavaParser.jay" + {yyVal=((Expr)yyVals[0+yyTop]);} + break; +case 245: + // line 2177 "./../src/mycompiler/myparser/JavaParser.jay" + {NotExpr NE=new NotExpr(((Expr)yyVals[0+yyTop]).getOffset(),((Expr)yyVals[0+yyTop]).getVariableLength()); + UnaryNot UN=new UnaryNot(); + NE.set_UnaryNot(UN); + NE.set_Expr(((Expr)yyVals[0+yyTop])); + yyVal=NE; + } + break; +case 246: + // line 2183 "./../src/mycompiler/myparser/JavaParser.jay" + {yyVal=((CastExpr)yyVals[0+yyTop]);} + break; +case 247: + // line 2185 "./../src/mycompiler/myparser/JavaParser.jay" + {yyVal=((Expr)yyVals[0+yyTop]);} + break; +case 249: + // line 2190 "./../src/mycompiler/myparser/JavaParser.jay" + {IntLiteral IL = new IntLiteral(); + IL.set_Int(((Token)yyVals[0+yyTop]).String2Int()); + yyVal = IL; + } + break; +case 250: + // line 2195 "./../src/mycompiler/myparser/JavaParser.jay" + {BoolLiteral BL = new BoolLiteral(); + BL.set_Bool(((Token)yyVals[0+yyTop]).String2Bool()); + yyVal = BL; + } + break; +case 251: + // line 2199 "./../src/mycompiler/myparser/JavaParser.jay" + {CharLiteral CL = new CharLiteral(); + CL.set_Char(((Token)yyVals[0+yyTop]).CharInString()); + yyVal=CL; + } + break; +case 252: + // line 2204 "./../src/mycompiler/myparser/JavaParser.jay" + { + StringLiteral ST = new StringLiteral(); + ST.set_String(((Token)yyVals[0+yyTop]).get_String()); + yyVal=ST; + } + break; +case 253: + // line 2209 "./../src/mycompiler/myparser/JavaParser.jay" + { LongLiteral LL = new LongLiteral(); + LL.set_Long(((Token)yyVals[0+yyTop]).String2Long()); + yyVal = LL; + } + break; +case 254: + // line 2213 "./../src/mycompiler/myparser/JavaParser.jay" + { + FloatLiteral FL = new FloatLiteral(); + FL.set_Float(((Token)yyVals[0+yyTop]).String2Float()); + yyVal = FL; + } + break; +case 255: + // line 2218 "./../src/mycompiler/myparser/JavaParser.jay" + { + DoubleLiteral DL = new DoubleLiteral(); + DL.set_Double(((Token)yyVals[0+yyTop]).String2Double()); + yyVal = DL; + } + break; +case 256: + // line 2224 "./../src/mycompiler/myparser/JavaParser.jay" + { + Null NN = new Null(); + yyVal=NN; + } + break; +case 257: + // line 2230 "./../src/mycompiler/myparser/JavaParser.jay" + { + CastExpr CaEx=new CastExpr(((Expr)yyVals[0+yyTop]).getOffset(),((Expr)yyVals[0+yyTop]).getVariableLength()); + CaEx.set_Type(((BaseType)yyVals[-2+yyTop])); + CaEx.set_Expr(((Expr)yyVals[0+yyTop])); + yyVal=CaEx; + } + break; +case 258: + // line 2239 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 259: + // line 2243 "./../src/mycompiler/myparser/JavaParser.jay" + { + } + break; +case 260: + // line 2247 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 261: + // line 2251 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary EQ = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + EqualOp EO = new EqualOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + EQ.set_Expr1(((Expr)yyVals[-2+yyTop])); + EQ.set_Expr2(((Expr)yyVals[0+yyTop])); + EQ.set_Operator(EO); + /*auskommentiert von Andreas Stadelmeier (a10023) EQ.setType(TypePlaceholder.fresh());*/ + yyVal=EQ; + } + break; +case 262: + // line 2261 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary NEQ = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + NotEqualOp NEO = new NotEqualOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + NEQ.set_Expr1(((Expr)yyVals[-2+yyTop])); + NEQ.set_Expr2(((Expr)yyVals[0+yyTop])); + NEQ.set_Operator(NEO); + /*auskommentiert von Andreas Stadelmeier (a10023) NEQ.setType(TypePlaceholder.fresh());*/ + yyVal=NEQ; + } + break; +case 263: + // line 2272 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 264: + // line 2276 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary LO = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + LessOp LOO = new LessOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + LO.set_Expr1(((Expr)yyVals[-2+yyTop])); + LO.set_Expr2(((Expr)yyVals[0+yyTop])); + LO.set_Operator(LOO); + /*auskommentiert von Andreas Stadelmeier (a10023) LO.setType(TypePlaceholder.fresh());*/ + yyVal=LO; + } + break; +case 265: + // line 2286 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary GO = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + GreaterOp GOO = new GreaterOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + GO.set_Expr1(((Expr)yyVals[-2+yyTop])); + GO.set_Expr2(((Expr)yyVals[0+yyTop])); + GO.set_Operator( GOO ); + /*auskommentiert von Andreas Stadelmeier (a10023) GO.setType(TypePlaceholder.fresh());*/ + yyVal=GO; + } + break; +case 266: + // line 2296 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary LE = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + LessEquOp LEO = new LessEquOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + LE.set_Expr1(((Expr)yyVals[-2+yyTop])); + LE.set_Expr2(((Expr)yyVals[0+yyTop])); + LE.set_Operator(LEO); + /*auskommentiert von Andreas Stadelmeier (a10023) LE.setType(TypePlaceholder.fresh());*/ + yyVal=LE; + } + break; +case 267: + // line 2306 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary GE = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + GreaterEquOp GEO = new GreaterEquOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + GE.set_Expr1(((Expr)yyVals[-2+yyTop])); + GE.set_Expr2(((Expr)yyVals[0+yyTop])); + GE.set_Operator(GEO); + /*auskommentiert von Andreas Stadelmeier (a10023) GE.setType(TypePlaceholder.fresh());*/ + yyVal=GE; + } + break; +case 268: + // line 2316 "./../src/mycompiler/myparser/JavaParser.jay" + { + InstanceOf ISO=new InstanceOf(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + ISO.set_Expr(((Expr)yyVals[-2+yyTop])); + ISO.set_Type(((RefType)yyVals[0+yyTop])); + yyVal=ISO; + } + break; +case 269: + // line 2324 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 270: + // line 2329 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 271: + // line 2333 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary AD = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + PlusOp PO = new PlusOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + AD.set_Expr1(((Expr)yyVals[-2+yyTop])); + AD.set_Expr2(((Expr)yyVals[0+yyTop])); + AD.set_Operator(PO); + /*auskommentiert von Andreas Stadelmeier (a10023) AD.setType(TypePlaceholder.fresh());*/ + yyVal=AD; + } + break; +case 272: + // line 2343 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary MI = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + MinusOp MO = new MinusOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + MI.set_Expr1(((Expr)yyVals[-2+yyTop])); + MI.set_Expr2(((Expr)yyVals[0+yyTop])); + MI.set_Operator(MO); + /*auskommentiert von Andreas Stadelmeier (a10023) MI.setType(TypePlaceholder.fresh());*/ + yyVal=MI; + } + break; +case 273: + // line 2354 "./../src/mycompiler/myparser/JavaParser.jay" + { + yyVal=((Expr)yyVals[0+yyTop]); + } + break; +case 274: + // line 2358 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary ML = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + TimesOp TO = new TimesOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + ML.set_Expr1(((Expr)yyVals[-2+yyTop])); + ML.set_Expr2(((Expr)yyVals[0+yyTop])); + ML.set_Operator(TO); + /*auskommentiert von Andreas Stadelmeier (a10023) ML.setType(TypePlaceholder.fresh());*/ + yyVal=ML; + } + break; +case 275: + // line 2368 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary DV = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + DivideOp DO = new DivideOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + DV.set_Expr1(((Expr)yyVals[-2+yyTop])); + DV.set_Expr2(((Expr)yyVals[0+yyTop])); + DV.set_Operator(DO); + /*auskommentiert von Andreas Stadelmeier (a10023) DV.setType(TypePlaceholder.fresh());*/ + yyVal = DV; + } + break; +case 276: + // line 2378 "./../src/mycompiler/myparser/JavaParser.jay" + { + Binary MD = new Binary(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + ModuloOp MO = new ModuloOp(((Expr)yyVals[-2+yyTop]).getOffset(),((Expr)yyVals[-2+yyTop]).getVariableLength()); + MD.set_Expr1(((Expr)yyVals[-2+yyTop])); + MD.set_Expr2(((Expr)yyVals[0+yyTop])); + MD.set_Operator(MO); + /*auskommentiert von Andreas Stadelmeier (a10023) MD.setType(TypePlaceholder.fresh());*/ + yyVal =MD; + } + break; + // line 3092 "-" + } + yyTop -= yyLen[yyN]; + yyState = yyStates[yyTop]; + int yyM = yyLhs[yyN]; + if (yyState == 0 && yyM == 0) { +//t if (yydebug != null) yydebug.shift(0, yyFinal); + yyState = yyFinal; + if (yyToken < 0) { + yyToken = yyLex.advance() ? yyLex.token() : 0; +//t if (yydebug != null) +//t yydebug.lex(yyState, yyToken,yyname(yyToken), yyLex.value()); + } + if (yyToken == 0) { +//t if (yydebug != null) yydebug.accept(yyVal); + return yyVal; + } + continue yyLoop; + } + if ((yyN = yyGindex[yyM]) != 0 && (yyN += yyState) >= 0 + && yyN < yyTable.length && yyCheckInit.yyCheck[yyN] == yyState) + yyState = yyTable[yyN]; + else + yyState = yyDgoto[yyM]; +//t if (yydebug != null) yydebug.shift(yyStates[yyTop], yyState); + continue yyLoop; + } + } + } + + protected static final short yyLhs [] = { -1, + 0, 98, 26, 26, 25, 92, 92, 27, 27, 105, + 23, 24, 24, 22, 1, 1, 1, 1, 1, 1, + 1, 1, 9, 9, 8, 8, 2, 2, 2, 2, + 112, 112, 112, 112, 112, 112, 114, 114, 114, 7, + 7, 40, 40, 28, 32, 32, 3, 3, 33, 33, + 15, 15, 41, 41, 41, 41, 41, 41, 29, 4, + 4, 31, 16, 16, 16, 30, 113, 113, 5, 5, + 17, 17, 110, 106, 106, 10, 6, 19, 11, 11, + 11, 11, 11, 13, 42, 42, 107, 107, 108, 108, + 108, 108, 48, 94, 97, 97, 93, 93, 95, 95, + 96, 96, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 39, 39, 39, 39, 18, 18, 43, + 44, 44, 50, 50, 109, 109, 38, 38, 14, 14, + 36, 36, 37, 20, 80, 80, 49, 49, 103, 103, + 35, 21, 78, 46, 81, 81, 81, 81, 81, 71, + 71, 34, 34, 47, 47, 79, 79, 79, 79, 86, + 87, 83, 84, 84, 84, 84, 84, 84, 84, 84, + 69, 69, 89, 77, 90, 90, 82, 82, 82, 68, + 99, 99, 72, 72, 72, 72, 72, 72, 88, 85, + 67, 67, 101, 45, 45, 51, 51, 70, 102, 100, + 100, 100, 100, 100, 100, 73, 74, 75, 76, 104, + 104, 104, 104, 91, 91, 66, 66, 57, 57, 57, + 57, 57, 55, 55, 55, 55, 54, 65, 65, 53, + 53, 53, 53, 56, 56, 56, 64, 64, 52, 52, + 52, 52, 52, 52, 52, 52, 111, 63, 63, 62, + 62, 62, 61, 61, 61, 61, 61, 61, 60, 59, + 59, 59, 58, 58, 58, 58, + }; + protected static final short yyLen [] = { 2, + 1, 3, 1, 2, 3, 1, 2, 1, 1, 1, + 3, 3, 3, 1, 3, 4, 4, 5, 4, 5, + 5, 6, 1, 4, 1, 4, 3, 4, 4, 5, + 1, 4, 1, 3, 6, 3, 1, 3, 3, 2, + 3, 1, 2, 2, 2, 3, 2, 3, 2, 3, + 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 1, 1, 1, 1, 2, 0, 3, 1, 1, + 1, 1, 2, 2, 3, 6, 2, 3, 2, 2, + 2, 3, 4, 2, 2, 3, 3, 4, 2, 3, + 3, 4, 2, 1, 1, 3, 1, 3, 1, 3, + 1, 3, 5, 2, 3, 6, 3, 6, 4, 7, + 2, 3, 3, 4, 5, 6, 6, 7, 1, 4, + 2, 2, 3, 1, 3, 1, 3, 1, 3, 1, + 1, 2, 1, 3, 4, 5, 1, 3, 3, 4, + 1, 1, 1, 1, 1, 1, 2, 1, 1, 3, + 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 2, 1, 1, 1, 1, 1, 5, + 7, 5, 9, 8, 8, 8, 7, 7, 7, 6, + 1, 1, 1, 2, 2, 3, 1, 1, 1, 1, + 3, 3, 1, 1, 1, 1, 1, 1, 7, 5, + 1, 3, 1, 1, 1, 2, 3, 3, 1, 1, + 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, + 4, 5, 6, 4, 5, 1, 3, 1, 1, 2, + 2, 1, 1, 1, 1, 1, 1, 1, 3, 1, + 1, 1, 1, 1, 2, 1, 1, 3, 1, 1, + 1, 1, 1, 1, 1, 1, 4, 1, 3, 1, + 3, 3, 1, 3, 3, 3, 3, 3, 1, 1, + 3, 3, 1, 3, 3, 3, + }; + protected static final short yyDefRed [] = { 0, + 57, 0, 58, 55, 54, 53, 56, 0, 10, 0, + 42, 0, 6, 0, 0, 0, 43, 7, 0, 0, + 0, 0, 15, 0, 0, 0, 0, 94, 95, 0, + 14, 0, 44, 59, 62, 45, 141, 163, 162, 0, + 0, 0, 0, 40, 71, 0, 72, 0, 0, 51, + 63, 0, 0, 0, 144, 0, 143, 151, 142, 0, + 0, 0, 0, 65, 0, 64, 17, 0, 0, 19, + 16, 0, 0, 0, 0, 26, 0, 66, 0, 73, + 0, 0, 0, 101, 0, 130, 84, 0, 122, 41, + 52, 0, 81, 79, 0, 0, 0, 0, 0, 0, + 0, 80, 0, 0, 0, 0, 0, 0, 0, 74, + 21, 46, 18, 0, 20, 99, 0, 96, 0, 0, + 0, 33, 0, 0, 0, 241, 0, 249, 253, 255, + 254, 250, 256, 251, 252, 0, 0, 0, 183, 85, + 0, 0, 128, 0, 8, 0, 0, 166, 0, 145, + 0, 0, 240, 237, 0, 0, 243, 0, 194, 195, + 0, 0, 168, 155, 131, 146, 158, 159, 156, 157, + 167, 169, 193, 0, 0, 113, 139, 148, 0, 133, + 0, 0, 0, 137, 0, 152, 129, 0, 0, 0, + 0, 0, 9, 0, 232, 273, 0, 0, 263, 0, + 0, 0, 0, 0, 0, 0, 181, 160, 78, 228, + 229, 235, 236, 161, 182, 242, 246, 87, 0, 125, + 127, 107, 82, 0, 0, 123, 0, 0, 75, 0, + 89, 0, 0, 22, 0, 0, 0, 0, 0, 68, + 0, 0, 185, 0, 0, 0, 216, 217, 206, 0, + 0, 0, 0, 86, 132, 154, 203, 0, 0, 218, + 219, 184, 214, 215, 211, 212, 213, 210, 0, 147, + 0, 140, 102, 0, 120, 0, 0, 0, 0, 230, + 231, 245, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, + 114, 0, 109, 83, 0, 91, 90, 0, 100, 0, + 38, 39, 0, 36, 0, 0, 0, 186, 0, 207, + 11, 220, 149, 0, 204, 208, 205, 0, 191, 192, + 134, 0, 0, 138, 0, 0, 274, 275, 276, 0, + 0, 268, 266, 267, 264, 265, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 92, 32, 0, + 0, 0, 0, 0, 0, 0, 221, 0, 117, 108, + 224, 0, 257, 0, 0, 135, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 170, 0, 189, 188, + 172, 150, 222, 0, 225, 118, 110, 136, 35, 180, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 223, + 179, 178, 0, 177, 0, 0, 0, 0, 0, 171, + 176, 175, 174, 0, 0, 0, 173, 0, 200, 0, + 199, + }; + protected static final short yyDgoto [] = { 8, + 9, 0, 0, 0, 0, 0, 23, 15, 0, 0, + 45, 46, 47, 48, 49, 50, 51, 142, 53, 143, + 55, 193, 145, 0, 0, 0, 146, 24, 33, 57, + 36, 25, 0, 58, 59, 60, 61, 185, 147, 10, + 11, 148, 87, 149, 326, 150, 151, 89, 180, 250, + 152, 153, 154, 155, 194, 195, 196, 197, 198, 199, + 200, 201, 202, 203, 204, 205, 206, 207, 208, 157, + 323, 158, 210, 211, 212, 213, 163, 0, 164, 165, + 166, 388, 167, 168, 389, 169, 170, 390, 171, 172, + 214, 12, 28, 29, 117, 85, 30, 0, 173, 269, + 258, 174, 324, 216, 13, 64, 65, 110, 233, 66, + 217, 121, 78, 122, + }; + protected static final short yySindex [] = { 249, + 0, -251, 0, 0, 0, 0, 0, 0, 0, 332, + 0, 249, 0, 9, -104, -251, 0, 0, -241, -208, + -208, 1029, 0, -88, -1, -104, -170, 0, 0, 20, + 0, 100, 0, 0, 0, 0, 0, 0, 0, 33, + -139, 144, -241, 0, 0, 33, 0, -78, 1351, 0, + 0, 70, 137, 155, 0, 25, 0, 0, 0, 114, + 129, -70, 1946, 0, 99, 0, 0, -1, -208, 0, + 0, -88, -1, -208, -241, 0, -59, 0, 3006, 0, + 144, -78, -17, 0, 29, 0, 0, -208, 0, 0, + 0, -55, 0, 0, 941, -14, 165, 204, 144, -78, + 111, 0, -139, 144, -241, -78, -70, 99, 3058, 0, + 0, 0, 0, -1, 0, 0, 269, 0, 252, -73, + 42, 0, 273, 276, 462, 0, 277, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 968, 968, 0, 0, + 34, 275, 0, 100, 0, 61, -55, 0, 3110, 0, + 265, -3, 0, 0, 274, -118, 0, 268, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -44, 0, 0, 0, 0, -55, 0, + 107, -241, -196, 0, 284, 0, 0, -208, 34, 968, + 968, 968, 0, -118, 0, 0, 167, 83, 0, -54, + -120, 291, 237, 208, 26, 36, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 169, 0, + 0, 0, 0, -78, 59, 0, -78, 117, 0, 304, + 0, 3167, 3211, 0, -208, -59, -208, -208, -18, 0, + 579, 941, 0, 290, 941, 61, 0, 0, 0, 177, + 49, 616, 275, 0, 0, 0, 0, 426, 58, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 941, 0, + -93, 0, 0, -139, 0, -139, -208, 321, 5, 0, + 0, 0, 968, 968, 968, 968, 968, -208, 968, 968, + 968, 968, 968, 968, 968, 968, 968, 968, 968, 0, + 0, -128, 0, 0, 633, 0, 0, 3269, 0, 62, + 0, 0, 302, 0, 671, 308, 327, 0, 329, 0, + 0, 0, 0, 189, 0, 0, 0, 331, 0, 0, + 0, -78, -78, 0, 698, 968, 0, 0, 0, 167, + 167, 0, 0, 0, 0, 0, -54, -54, -120, 291, + 237, 208, 26, -139, -139, 314, 191, 0, 0, -59, + 735, 318, 778, 1489, 2205, 941, 0, 805, 0, 0, + 0, 199, 0, -78, -78, 0, 323, 71, 2205, 338, + 822, 849, 325, 340, 345, 0, 0, 119, 0, 0, + 0, 0, 0, 261, 0, 0, 0, 0, 0, 0, + 2205, 2205, 347, 2205, 350, 904, 941, 941, 2205, 0, + 0, 0, 2205, 0, 2205, 2205, 351, 352, 355, 0, + 0, 0, 0, 2205, 1489, 1489, 0, 134, 0, 1489, + 0, + }; + protected static final short yyRindex [] = { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 403, 0, -89, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 74, 0, 0, 0, + 0, 1123, 0, 0, 0, 0, 0, 0, 0, 2588, + 0, -23, 0, 0, 0, 0, 0, 282, 0, 0, + 0, 0, 0, 139, 0, -84, 0, 0, 0, 106, + 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 292, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 91, 293, + 0, 0, 0, -50, 0, 297, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 76, 0, 87, 96, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 215, 0, 0, 0, 0, + 0, 362, 0, 320, 0, 526, 0, 0, 0, 0, + 0, 0, 0, 0, 1237, 0, 0, 0, 0, 0, + -45, 2, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -43, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 299, 0, 0, 0, 0, 0, + 0, 0, 0, 2981, 0, 0, 2708, 2152, 0, 2428, + 2254, 1292, 1398, 1543, 1602, 1671, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 301, 0, 0, 305, 0, 0, -41, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1708, 0, 0, 0, 0, + 0, 0, 380, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 106, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 97, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 317, 324, 0, 0, 0, 0, 0, 0, 2780, + 2870, 0, 0, 0, 0, 0, 2529, 2619, 2343, 1794, + 1879, 1981, 2067, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 328, 333, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1192, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, + }; + protected static final short yyGindex [] = { 0, + 0, 0, 0, 0, 0, 0, 558, 398, 0, 0, + 0, 0, 0, -40, 0, 394, 0, -10, 382, 27, + -2, 465, 0, 0, 0, 0, 2657, 420, -77, 11, + 379, 53, 0, 0, 0, 266, -49, 0, -9, 35, + 37, -31, 0, -67, 0, 0, 0, -80, 187, -25, + 0, 0, 0, 0, -79, 0, -82, 3, 0, 143, + -56, 170, 164, 179, 182, 163, 0, 0, 214, 0, + 196, 0, -61, -26, -7, 48, 0, 0, -313, -116, + 944, -202, 0, 0, 0, 0, 0, 0, 0, 0, + 219, 0, -15, 402, 0, 388, 0, 0, 184, 0, + 0, 0, -276, 66, 472, 0, 431, 389, 0, 0, + 0, -192, 0, 259, + }; + protected static final short yyTable [] = { 156, + 82, 176, 242, 120, 241, 291, 67, 292, 80, 14, + 184, 52, 62, 196, 86, 198, 268, 159, 22, 222, + 152, 100, 106, 177, 116, 226, 218, 84, 357, 156, + 34, 35, 255, 25, 22, 152, 14, 152, 52, 62, + 14, 232, 69, 310, 120, 336, 17, 159, 54, 14, + 386, 101, 160, 107, 247, 248, 63, 181, 372, 27, + 197, 37, 224, 75, 96, 38, 227, 14, 19, 156, + 219, 161, 182, 179, 249, 54, 68, 39, 73, 35, + 178, 76, 160, 63, 77, 239, 179, 159, 54, 84, + 183, 394, 31, 178, 274, 97, 228, 74, 34, 17, + 252, 161, 182, 240, 104, 239, 251, 280, 281, 282, + 278, 386, 386, 92, 239, 255, 386, 97, 187, 98, + 302, 22, 160, 359, 114, 286, 162, 287, 93, 37, + 31, 179, 399, 38, 152, 97, 253, 98, 178, 37, + 34, 161, 275, 301, 175, 39, 303, 272, 31, 152, + 271, 152, 156, 156, 92, 79, 162, 37, 34, 77, + 92, 81, 354, 20, 37, 308, 273, 378, 38, 223, + 159, 159, 31, 276, 175, 304, 270, 21, 25, 179, + 39, 293, 128, 83, 294, 309, 178, 311, 312, 260, + 261, 255, 25, 21, 237, 94, 162, 128, 34, 334, + 337, 338, 339, 285, 97, 160, 160, 136, 283, 300, + 88, 238, 271, 284, 175, 95, 67, 320, 288, 98, + 271, 109, 428, 429, 161, 161, 325, 431, 156, 367, + 99, 377, 366, 332, 366, 333, 347, 348, 342, 395, + 37, 119, 366, 37, 38, 186, 159, 38, 289, 290, + 14, 369, 370, 373, 14, 152, 39, 220, 152, 39, + 14, 179, 235, 235, 242, 242, 241, 241, 178, 263, + 264, 265, 266, 152, 14, 14, 267, 14, 215, 162, + 162, 160, 313, 136, 156, 156, 136, 34, 340, 341, + 209, 37, 355, 396, 397, 38, 221, 175, 175, 156, + 161, 410, 159, 159, 366, 14, 235, 39, 215, 236, + 236, 236, 241, 374, 375, 242, 245, 159, 92, 259, + 244, 156, 156, 256, 156, 257, 262, 277, 295, 156, + 296, 297, 298, 156, 136, 156, 156, 160, 160, 159, + 159, 299, 159, 305, 156, 156, 156, 159, 318, 321, + 156, 159, 160, 159, 159, 162, 161, 161, 328, 9, + 335, 360, 159, 159, 159, 9, 363, 364, 159, 365, + 368, 161, 376, 175, 160, 160, 381, 160, 401, 407, + 9, 398, 160, 406, 408, 409, 160, 413, 160, 160, + 415, 424, 425, 161, 161, 426, 161, 160, 160, 160, + 430, 161, 1, 160, 119, 161, 124, 161, 161, 126, + 67, 162, 162, 26, 111, 104, 161, 161, 161, 121, + 165, 93, 161, 112, 215, 215, 162, 105, 215, 175, + 175, 343, 344, 345, 346, 215, 316, 317, 164, 115, + 319, 215, 91, 102, 175, 72, 103, 112, 162, 162, + 116, 162, 215, 327, 279, 106, 162, 331, 192, 350, + 162, 353, 162, 162, 349, 189, 175, 175, 190, 175, + 191, 162, 162, 162, 175, 351, 118, 162, 175, 352, + 175, 175, 329, 18, 32, 32, 56, 330, 215, 175, + 175, 175, 225, 108, 192, 175, 229, 314, 215, 0, + 0, 189, 0, 0, 190, 1, 191, 0, 0, 0, + 362, 2, 0, 56, 0, 14, 0, 3, 215, 0, + 243, 0, 14, 14, 4, 5, 6, 56, 14, 14, + 14, 14, 7, 32, 0, 14, 0, 0, 32, 0, + 0, 0, 0, 144, 215, 0, 215, 32, 79, 215, + 0, 215, 32, 0, 0, 0, 380, 0, 383, 0, + 32, 392, 234, 234, 215, 215, 234, 234, 234, 234, + 234, 0, 234, 144, 0, 0, 403, 405, 0, 0, + 0, 67, 70, 71, 234, 234, 209, 234, 1, 215, + 215, 215, 0, 0, 16, 0, 0, 0, 0, 0, + 3, 417, 418, 419, 0, 32, 0, 4, 5, 6, + 0, 192, 0, 144, 0, 7, 0, 0, 189, 234, + 67, 190, 0, 191, 0, 111, 0, 9, 9, 113, + 115, 0, 0, 9, 9, 9, 9, 315, 0, 0, + 9, 0, 0, 0, 0, 0, 0, 32, 192, 234, + 234, 0, 32, 32, 0, 189, 322, 0, 190, 0, + 191, 0, 0, 0, 0, 192, 0, 0, 0, 0, + 0, 234, 189, 356, 0, 190, 0, 191, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 144, 144, 0, 32, + 188, 32, 32, 192, 0, 0, 0, 0, 0, 0, + 189, 0, 126, 190, 0, 191, 0, 0, 128, 129, + 130, 131, 132, 133, 134, 135, 31, 0, 0, 361, + 192, 0, 0, 137, 138, 32, 188, 189, 371, 0, + 190, 32, 191, 0, 0, 0, 0, 0, 126, 0, + 0, 0, 32, 0, 128, 129, 130, 131, 132, 133, + 134, 135, 31, 0, 0, 0, 32, 192, 0, 137, + 138, 0, 144, 0, 189, 379, 0, 190, 0, 191, + 0, 0, 234, 234, 0, 0, 0, 234, 0, 0, + 0, 0, 0, 0, 234, 0, 0, 0, 234, 234, + 0, 234, 234, 234, 0, 0, 0, 0, 0, 234, + 192, 0, 0, 0, 0, 0, 234, 189, 0, 0, + 190, 0, 191, 0, 0, 0, 234, 234, 234, 234, + 234, 234, 234, 234, 234, 0, 382, 192, 0, 209, + 209, 209, 209, 0, 189, 393, 209, 190, 0, 191, + 0, 0, 0, 188, 192, 0, 0, 0, 0, 0, + 0, 189, 402, 0, 190, 126, 191, 0, 0, 0, + 0, 128, 129, 130, 131, 132, 133, 134, 135, 31, + 0, 192, 0, 0, 0, 0, 137, 138, 189, 404, + 188, 190, 0, 191, 0, 0, 0, 0, 0, 0, + 0, 0, 126, 0, 0, 0, 0, 188, 128, 129, + 130, 131, 132, 133, 134, 135, 31, 0, 0, 126, + 0, 0, 0, 137, 138, 128, 129, 130, 131, 132, + 133, 134, 135, 31, 0, 0, 192, 0, 0, 0, + 137, 138, 0, 189, 416, 188, 190, 0, 191, 0, + 0, 0, 0, 0, 0, 0, 0, 126, 0, 0, + 0, 0, 0, 128, 129, 130, 131, 132, 133, 134, + 135, 31, 188, 192, 0, 0, 0, 0, 137, 138, + 189, 0, 0, 190, 126, 191, 0, 0, 0, 0, + 128, 129, 130, 131, 132, 133, 134, 135, 31, 0, + 192, 0, 0, 0, 0, 137, 138, 189, 0, 188, + 190, 0, 191, 0, 0, 0, 0, 0, 0, 0, + 0, 126, 0, 0, 0, 0, 0, 128, 129, 130, + 131, 132, 133, 134, 135, 31, 0, 0, 0, 0, + 0, 0, 137, 138, 0, 0, 0, 0, 0, 0, + 0, 0, 188, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 126, 0, 0, 0, 0, 0, + 128, 129, 130, 131, 132, 133, 134, 135, 31, 188, + 0, 0, 0, 0, 0, 137, 138, 0, 43, 0, + 0, 126, 0, 0, 0, 0, 188, 128, 129, 130, + 131, 132, 133, 134, 135, 31, 0, 0, 126, 0, + 0, 0, 137, 138, 128, 129, 130, 131, 132, 133, + 134, 135, 31, 188, 0, 0, 0, 0, 0, 137, + 138, 0, 0, 0, 0, 126, 0, 0, 0, 0, + 0, 128, 129, 130, 131, 132, 133, 134, 135, 31, + 0, 0, 0, 44, 0, 0, 137, 138, 0, 67, + 67, 0, 67, 67, 67, 67, 67, 67, 67, 67, + 0, 0, 0, 0, 0, 0, 0, 0, 188, 0, + 0, 67, 0, 0, 67, 0, 0, 0, 0, 0, + 126, 0, 0, 0, 0, 0, 128, 129, 130, 131, + 132, 133, 134, 135, 31, 0, 0, 0, 0, 0, + 0, 137, 138, 67, 0, 188, 67, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 126, 0, 0, + 0, 155, 0, 128, 129, 130, 131, 132, 133, 134, + 135, 31, 0, 0, 0, 67, 67, 67, 137, 138, + 155, 0, 0, 0, 126, 0, 0, 0, 0, 0, + 128, 129, 130, 131, 132, 133, 134, 135, 31, 0, + 0, 0, 0, 233, 233, 137, 138, 233, 233, 233, + 233, 233, 0, 233, 0, 1, 37, 0, 0, 0, + 38, 0, 0, 0, 0, 233, 233, 3, 233, 0, + 0, 0, 39, 0, 4, 5, 6, 387, 391, 0, + 0, 0, 40, 0, 155, 0, 155, 0, 0, 41, + 0, 0, 400, 0, 0, 0, 0, 0, 247, 42, + 233, 0, 247, 247, 247, 247, 247, 247, 247, 0, + 0, 0, 0, 0, 411, 412, 0, 414, 0, 0, + 247, 247, 420, 247, 0, 0, 421, 0, 422, 423, + 233, 233, 0, 0, 0, 0, 0, 427, 387, 391, + 0, 0, 0, 420, 0, 0, 0, 0, 0, 67, + 67, 0, 0, 0, 67, 247, 0, 0, 0, 0, + 0, 67, 0, 0, 0, 67, 67, 0, 67, 67, + 67, 0, 0, 0, 67, 0, 67, 0, 0, 0, + 43, 0, 0, 67, 0, 247, 247, 0, 0, 0, + 0, 0, 0, 67, 67, 67, 67, 67, 67, 67, + 67, 67, 0, 0, 238, 238, 0, 0, 238, 238, + 238, 238, 238, 238, 238, 0, 0, 0, 0, 155, + 0, 0, 0, 155, 0, 0, 238, 238, 187, 238, + 0, 0, 155, 155, 0, 155, 0, 0, 0, 0, + 0, 0, 0, 0, 155, 90, 0, 0, 155, 0, + 0, 0, 0, 155, 155, 155, 155, 155, 155, 155, + 155, 155, 155, 233, 233, 0, 0, 0, 233, 155, + 155, 0, 0, 0, 0, 233, 0, 0, 0, 233, + 233, 0, 233, 233, 233, 0, 0, 0, 0, 0, + 233, 238, 238, 0, 0, 0, 0, 233, 141, 0, + 0, 0, 0, 0, 0, 0, 0, 233, 233, 233, + 233, 233, 233, 233, 233, 233, 0, 139, 247, 247, + 0, 0, 0, 247, 0, 0, 0, 0, 0, 0, + 247, 0, 0, 0, 247, 247, 0, 247, 247, 247, + 0, 0, 0, 0, 0, 247, 0, 0, 0, 226, + 226, 0, 247, 226, 226, 226, 226, 226, 226, 226, + 0, 0, 247, 247, 247, 247, 247, 247, 247, 247, + 247, 226, 226, 0, 226, 0, 0, 1, 37, 0, + 0, 79, 38, 0, 0, 0, 0, 0, 0, 3, + 0, 0, 0, 0, 39, 0, 4, 5, 6, 0, + 0, 0, 0, 0, 40, 0, 226, 0, 201, 201, + 0, 41, 201, 201, 201, 201, 201, 201, 201, 0, + 0, 42, 0, 0, 238, 238, 0, 0, 0, 238, + 201, 201, 0, 201, 0, 0, 238, 226, 0, 0, + 238, 238, 0, 238, 238, 238, 0, 0, 0, 0, + 0, 238, 0, 0, 0, 0, 0, 0, 238, 0, + 0, 0, 0, 0, 0, 201, 0, 0, 238, 238, + 238, 238, 238, 238, 238, 238, 238, 190, 190, 0, + 0, 190, 190, 190, 190, 190, 190, 190, 0, 0, + 0, 0, 0, 0, 0, 201, 201, 0, 0, 190, + 190, 0, 190, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 234, 234, 0, 0, 234, 234, + 234, 234, 234, 0, 234, 0, 0, 0, 0, 123, + 384, 0, 0, 0, 190, 0, 234, 234, 0, 234, + 0, 125, 0, 0, 0, 126, 0, 0, 0, 0, + 385, 128, 129, 130, 131, 132, 133, 134, 135, 31, + 0, 0, 0, 0, 190, 190, 137, 138, 0, 226, + 226, 234, 0, 0, 226, 0, 0, 0, 0, 0, + 0, 226, 0, 0, 0, 226, 226, 0, 226, 226, + 226, 0, 0, 0, 0, 0, 226, 0, 0, 0, + 248, 234, 234, 226, 248, 248, 248, 248, 248, 248, + 248, 0, 0, 226, 226, 226, 226, 226, 226, 226, + 226, 226, 248, 248, 0, 248, 0, 0, 201, 201, + 0, 0, 0, 201, 0, 0, 0, 0, 0, 0, + 201, 0, 0, 0, 201, 201, 0, 201, 201, 201, + 0, 0, 0, 0, 0, 201, 0, 248, 0, 0, + 0, 0, 201, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 201, 201, 201, 201, 201, 201, 0, 201, + 201, 0, 0, 0, 0, 239, 239, 248, 248, 239, + 239, 239, 239, 239, 239, 239, 0, 190, 190, 0, + 0, 0, 190, 0, 0, 0, 0, 239, 239, 190, + 239, 0, 0, 190, 190, 0, 190, 190, 190, 0, + 0, 0, 0, 0, 190, 0, 0, 0, 0, 0, + 0, 190, 0, 0, 234, 234, 0, 0, 0, 234, + 0, 190, 190, 190, 190, 190, 234, 190, 190, 190, + 234, 234, 0, 234, 234, 234, 0, 0, 0, 0, + 0, 234, 0, 0, 0, 0, 0, 0, 234, 0, + 0, 0, 239, 239, 0, 105, 0, 0, 234, 234, + 234, 234, 234, 234, 234, 234, 234, 227, 227, 0, + 0, 227, 227, 227, 227, 227, 227, 227, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 227, + 227, 0, 227, 0, 0, 0, 0, 0, 0, 0, + 248, 248, 0, 0, 0, 248, 0, 0, 0, 0, + 0, 0, 248, 0, 0, 0, 248, 248, 0, 248, + 248, 248, 0, 0, 227, 0, 0, 248, 0, 0, + 0, 0, 0, 0, 248, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 202, 202, 227, 0, 202, 202, 202, + 202, 202, 202, 202, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 202, 202, 0, 202, 0, + 0, 0, 0, 0, 0, 239, 239, 0, 0, 0, + 239, 0, 0, 0, 0, 0, 0, 239, 0, 0, + 0, 239, 239, 0, 239, 239, 239, 0, 0, 0, + 202, 0, 239, 0, 0, 0, 0, 0, 0, 239, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 239, + 239, 239, 239, 239, 239, 239, 239, 239, 269, 269, + 202, 202, 269, 269, 0, 269, 0, 269, 269, 0, + 0, 0, 1, 37, 0, 0, 0, 38, 0, 0, + 269, 269, 0, 269, 3, 0, 0, 0, 0, 39, + 0, 4, 5, 6, 0, 0, 0, 0, 0, 7, + 0, 0, 0, 0, 0, 0, 103, 227, 227, 0, + 0, 0, 227, 0, 141, 269, 104, 0, 0, 227, + 0, 0, 0, 227, 227, 0, 227, 227, 227, 0, + 0, 0, 0, 139, 227, 0, 0, 0, 0, 0, + 0, 227, 0, 0, 0, 269, 269, 0, 0, 0, + 0, 227, 227, 227, 227, 227, 227, 227, 227, 227, + 258, 258, 0, 0, 258, 258, 258, 258, 258, 258, + 258, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 258, 258, 0, 258, 0, 0, 0, 0, + 0, 0, 0, 202, 202, 0, 0, 79, 202, 0, + 0, 0, 0, 0, 0, 202, 0, 0, 0, 202, + 202, 0, 202, 202, 202, 0, 0, 258, 0, 0, + 202, 0, 0, 0, 0, 0, 0, 202, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 202, 202, 202, + 202, 202, 202, 0, 202, 202, 0, 258, 258, 259, + 259, 0, 0, 259, 259, 259, 259, 259, 259, 259, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 259, 259, 0, 259, 0, 0, 0, 269, 269, + 0, 0, 0, 269, 0, 0, 0, 0, 0, 0, + 269, 0, 0, 0, 269, 269, 0, 269, 269, 269, + 0, 0, 0, 0, 0, 269, 259, 0, 0, 0, + 0, 0, 269, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 269, 269, 269, 269, 269, 269, 269, 269, + 269, 0, 0, 0, 260, 260, 259, 259, 260, 260, + 260, 260, 260, 260, 260, 123, 124, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 260, 125, 0, 0, + 0, 126, 0, 0, 0, 0, 127, 128, 129, 130, + 131, 132, 133, 134, 135, 31, 0, 0, 0, 0, + 258, 258, 137, 138, 0, 258, 0, 0, 0, 0, + 0, 260, 258, 0, 0, 0, 258, 258, 0, 258, + 258, 258, 0, 0, 0, 0, 0, 258, 0, 0, + 0, 0, 0, 0, 258, 0, 0, 0, 0, 0, + 0, 260, 260, 0, 258, 0, 258, 258, 0, 258, + 258, 258, 258, 0, 0, 261, 261, 0, 0, 261, + 261, 261, 261, 261, 261, 261, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 261, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 259, + 259, 0, 0, 0, 259, 0, 0, 0, 0, 0, + 0, 259, 0, 0, 0, 259, 259, 0, 259, 259, + 259, 0, 261, 0, 0, 0, 259, 0, 0, 0, + 0, 0, 0, 259, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 259, 0, 259, 259, 56, 259, 259, + 259, 259, 261, 261, 0, 262, 262, 0, 0, 262, + 262, 262, 262, 262, 262, 262, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 262, 0, 0, + 0, 0, 0, 0, 260, 260, 0, 0, 0, 260, + 0, 0, 0, 0, 0, 0, 260, 0, 0, 0, + 0, 260, 0, 260, 260, 260, 0, 0, 0, 0, + 0, 260, 262, 0, 0, 0, 0, 0, 260, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 260, 260, + 0, 0, 260, 260, 260, 260, 260, 0, 0, 0, + 0, 0, 262, 262, 0, 270, 0, 0, 270, 0, + 270, 270, 270, 270, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 270, 270, 0, 270, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 261, 261, 0, 0, 0, + 261, 0, 0, 246, 246, 0, 0, 261, 0, 0, + 0, 270, 261, 0, 261, 261, 261, 0, 0, 0, + 0, 0, 261, 0, 0, 0, 0, 271, 0, 261, + 271, 0, 271, 271, 271, 271, 0, 0, 0, 261, + 261, 270, 270, 261, 261, 261, 261, 261, 271, 271, + 0, 271, 0, 0, 56, 56, 246, 246, 246, 56, + 0, 0, 0, 0, 0, 0, 56, 0, 0, 0, + 0, 56, 0, 56, 56, 56, 0, 0, 0, 0, + 0, 56, 0, 271, 0, 262, 262, 0, 56, 0, + 262, 0, 0, 0, 0, 0, 0, 262, 56, 0, + 0, 0, 262, 0, 262, 262, 262, 0, 0, 0, + 0, 0, 262, 271, 271, 0, 0, 272, 0, 262, + 272, 0, 272, 272, 272, 272, 0, 0, 0, 262, + 262, 0, 0, 262, 262, 262, 262, 262, 272, 272, + 0, 272, 0, 0, 0, 0, 0, 0, 0, 246, + 246, 246, 246, 246, 0, 246, 246, 246, 246, 246, + 246, 246, 246, 246, 246, 246, 0, 0, 0, 0, + 0, 0, 0, 272, 270, 270, 0, 0, 0, 270, + 0, 0, 0, 0, 0, 0, 270, 0, 0, 0, + 270, 270, 0, 270, 270, 270, 0, 0, 0, 0, + 0, 270, 246, 272, 272, 0, 0, 0, 270, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 270, 270, + 270, 270, 270, 270, 270, 270, 270, 244, 244, 0, + 0, 244, 244, 244, 244, 244, 244, 244, 0, 0, + 0, 0, 0, 0, 0, 0, 271, 271, 0, 244, + 244, 271, 244, 0, 0, 141, 0, 0, 271, 0, + 0, 0, 271, 271, 0, 271, 271, 271, 0, 0, + 0, 0, 0, 271, 139, 0, 0, 0, 0, 0, + 271, 0, 0, 0, 244, 0, 0, 0, 0, 0, + 271, 271, 271, 271, 271, 271, 271, 271, 271, 0, + 0, 0, 0, 0, 0, 0, 0, 141, 0, 0, + 0, 0, 0, 0, 244, 244, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 139, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 272, 272, 79, 0, + 140, 272, 0, 0, 0, 0, 0, 0, 272, 0, + 0, 0, 272, 272, 0, 272, 272, 272, 0, 141, + 0, 0, 0, 272, 0, 0, 0, 0, 0, 0, + 272, 0, 0, 0, 0, 0, 0, 0, 139, 0, + 272, 272, 272, 272, 272, 272, 272, 272, 272, 0, + 79, 0, 231, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 141, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 139, 0, 0, 0, 0, + 0, 0, 79, 0, 254, 0, 0, 244, 244, 0, + 0, 0, 244, 0, 0, 0, 0, 0, 0, 244, + 141, 0, 0, 244, 244, 0, 244, 244, 244, 0, + 0, 0, 0, 37, 244, 0, 0, 38, 0, 139, + 0, 244, 0, 0, 0, 0, 123, 124, 0, 39, + 0, 244, 244, 244, 244, 244, 244, 244, 125, 79, + 0, 306, 126, 0, 0, 0, 0, 127, 128, 129, + 130, 131, 132, 133, 134, 135, 136, 0, 141, 0, + 0, 0, 0, 137, 138, 37, 0, 0, 0, 38, + 0, 0, 0, 0, 0, 0, 0, 139, 123, 124, + 0, 39, 0, 79, 0, 307, 0, 0, 0, 0, + 125, 0, 0, 0, 230, 0, 0, 0, 0, 127, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 0, + 0, 0, 0, 0, 0, 137, 138, 37, 0, 0, + 0, 38, 0, 0, 0, 0, 0, 0, 0, 0, + 123, 124, 0, 39, 0, 0, 0, 0, 0, 0, + 0, 79, 125, 358, 0, 0, 126, 0, 0, 0, + 0, 127, 128, 129, 130, 131, 132, 133, 134, 135, + 136, 0, 0, 0, 0, 0, 0, 137, 138, 0, + 0, 0, 0, 0, 37, 0, 0, 0, 38, 0, + 0, 0, 0, 0, 0, 0, 0, 123, 124, 0, + 39, 0, 0, 0, 0, 0, 0, 0, 0, 125, + 0, 0, 0, 126, 0, 0, 0, 0, 127, 128, + 129, 130, 131, 132, 133, 134, 135, 136, 37, 0, + 0, 0, 38, 0, 137, 138, 0, 0, 0, 0, + 0, 123, 124, 0, 39, 0, 0, 0, 0, 0, + 0, 0, 0, 125, 0, 0, 0, 126, 0, 0, + 0, 0, 127, 128, 129, 130, 131, 132, 133, 134, + 135, 136, 0, 0, 0, 0, 0, 0, 137, 138, + 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, + 38, 0, 0, 0, 0, 0, 0, 0, 0, 123, + 124, 0, 39, 0, 0, 0, 0, 0, 0, 0, + 0, 125, 0, 0, 0, 126, 0, 0, 0, 0, + 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, + 0, 0, 0, 0, 0, 0, 137, 138, + }; + protected short yyCheck[] = new short[3579]; +} +class yyCheck0 { + protected static final short yyCheck0 [] = { 79, + 41, 82, 46, 63, 46, 60, 91, 62, 40, 60, + 88, 22, 22, 59, 46, 59, 61, 79, 123, 100, + 44, 62, 63, 41, 74, 106, 41, 43, 305, 109, + 20, 21, 149, 123, 123, 59, 60, 61, 49, 49, + 91, 109, 44, 236, 63, 41, 10, 109, 22, 301, + 364, 62, 79, 63, 137, 138, 22, 83, 335, 301, + 59, 258, 103, 44, 40, 262, 107, 91, 60, 149, + 96, 79, 44, 83, 41, 49, 24, 274, 26, 69, + 83, 62, 109, 49, 60, 44, 96, 149, 62, 105, + 62, 368, 301, 96, 291, 91, 107, 268, 88, 63, + 40, 109, 44, 62, 301, 44, 46, 190, 191, 192, + 188, 425, 426, 44, 44, 232, 430, 44, 92, 44, + 62, 123, 149, 62, 72, 43, 79, 45, 59, 258, + 44, 141, 62, 262, 44, 62, 147, 62, 141, 44, + 44, 149, 183, 224, 79, 274, 227, 41, 62, 59, + 44, 61, 232, 233, 44, 123, 109, 62, 62, 60, + 44, 301, 291, 268, 258, 233, 182, 360, 262, 59, + 232, 233, 301, 183, 109, 59, 179, 282, 268, 189, + 274, 302, 44, 40, 305, 235, 189, 237, 238, 308, + 309, 308, 282, 282, 268, 59, 149, 59, 188, 277, + 283, 284, 285, 37, 91, 232, 233, 301, 42, 41, + 289, 285, 44, 47, 149, 61, 301, 41, 273, 91, + 44, 123, 425, 426, 232, 233, 258, 430, 308, 41, + 301, 41, 44, 274, 44, 276, 293, 294, 288, 41, + 258, 301, 44, 258, 262, 301, 308, 262, 303, 304, + 301, 332, 333, 336, 40, 41, 274, 93, 44, 274, + 46, 271, 308, 309, 308, 309, 308, 309, 271, 314, + 315, 316, 317, 59, 60, 61, 321, 301, 95, 232, + 233, 308, 301, 301, 364, 365, 301, 277, 286, 287, + 95, 258, 302, 374, 375, 262, 93, 232, 233, 379, + 308, 41, 364, 365, 44, 91, 38, 274, 125, 308, + 309, 60, 40, 354, 355, 40, 40, 379, 44, 46, + 125, 401, 402, 59, 404, 329, 59, 44, 38, 409, + 94, 124, 307, 413, 301, 415, 416, 364, 365, 401, + 402, 306, 404, 40, 424, 425, 426, 409, 59, 301, + 430, 413, 379, 415, 416, 308, 364, 365, 301, 40, + 40, 60, 424, 425, 426, 46, 59, 41, 430, 41, + 40, 379, 59, 308, 401, 402, 59, 404, 41, 40, + 61, 59, 409, 59, 40, 267, 413, 41, 415, 416, + 41, 41, 41, 401, 402, 41, 404, 424, 425, 426, + 267, 409, 0, 430, 123, 413, 301, 415, 416, 301, + 91, 364, 365, 16, 123, 123, 424, 425, 426, 123, + 59, 123, 430, 123, 241, 242, 379, 123, 245, 364, + 365, 289, 290, 291, 292, 252, 241, 242, 59, 123, + 245, 258, 49, 62, 379, 26, 123, 69, 401, 402, + 123, 404, 269, 258, 189, 123, 409, 271, 33, 296, + 413, 299, 415, 416, 295, 40, 401, 402, 43, 404, + 45, 424, 425, 426, 409, 297, 75, 430, 413, 298, + 415, 416, 269, 12, 20, 21, 22, 269, 305, 424, + 425, 426, 105, 63, 33, 430, 108, 239, 315, -1, + -1, 40, -1, -1, 43, 257, 45, -1, -1, -1, + 315, 263, -1, 49, -1, 301, -1, 269, 335, -1, + 59, -1, 308, 309, 276, 277, 278, 63, 314, 315, + 316, 317, 284, 69, -1, 321, -1, -1, 74, -1, + -1, -1, -1, 79, 361, -1, 363, 83, 123, 366, + -1, 368, 88, -1, -1, -1, 361, -1, 363, -1, + 96, 366, 37, 38, 381, 382, 41, 42, 43, 44, + 45, -1, 47, 109, -1, -1, 381, 382, -1, -1, + -1, 24, 25, 26, 59, 60, 61, 62, 257, 406, + 407, 408, -1, -1, 263, -1, -1, -1, -1, -1, + 269, 406, 407, 408, -1, 141, -1, 276, 277, 278, + -1, 33, -1, 149, -1, 284, -1, -1, 40, 94, + 301, 43, -1, 45, -1, 68, -1, 308, 309, 72, + 73, -1, -1, 314, 315, 316, 317, 59, -1, -1, + 321, -1, -1, -1, -1, -1, -1, 183, 33, 124, + 125, -1, 188, 189, -1, 40, 41, -1, 43, -1, + 45, -1, -1, -1, -1, 33, -1, -1, -1, -1, + -1, 114, 40, 41, -1, 43, -1, 45, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 232, 233, -1, 235, + 275, 237, 238, 33, -1, -1, -1, -1, -1, -1, + 40, -1, 287, 43, -1, 45, -1, -1, 293, 294, + 295, 296, 297, 298, 299, 300, 301, -1, -1, 59, + 33, -1, -1, 308, 309, 271, 275, 40, 41, -1, + 43, 277, 45, -1, -1, -1, -1, -1, 287, -1, + -1, -1, 288, -1, 293, 294, 295, 296, 297, 298, + 299, 300, 301, -1, -1, -1, 302, 33, -1, 308, + 309, -1, 308, -1, 40, 41, -1, 43, -1, 45, + -1, -1, 257, 258, -1, -1, -1, 262, -1, -1, + -1, -1, -1, -1, 269, -1, -1, -1, 273, 274, + -1, 276, 277, 278, -1, -1, -1, -1, -1, 284, + 33, -1, -1, -1, -1, -1, 291, 40, -1, -1, + 43, -1, 45, -1, -1, -1, 301, 302, 303, 304, + 305, 306, 307, 308, 309, -1, 59, 33, -1, 314, + 315, 316, 317, -1, 40, 41, 321, 43, -1, 45, + -1, -1, -1, 275, 33, -1, -1, -1, -1, -1, + -1, 40, 41, -1, 43, 287, 45, -1, -1, -1, + -1, 293, 294, 295, 296, 297, 298, 299, 300, 301, + -1, 33, -1, -1, -1, -1, 308, 309, 40, 41, + 275, 43, -1, 45, -1, -1, -1, -1, -1, -1, + -1, -1, 287, -1, -1, -1, -1, 275, 293, 294, + 295, 296, 297, 298, 299, 300, 301, -1, -1, 287, + -1, -1, -1, 308, 309, 293, 294, 295, 296, 297, + 298, 299, 300, 301, -1, -1, 33, -1, -1, -1, + 308, 309, -1, 40, 41, 275, 43, -1, 45, -1, + -1, -1, -1, -1, -1, -1, -1, 287, -1, -1, + -1, -1, -1, 293, 294, 295, 296, 297, 298, 299, + 300, 301, 275, 33, -1, -1, -1, -1, 308, 309, + 40, -1, -1, 43, 287, 45, -1, -1, -1, -1, + 293, 294, 295, 296, 297, 298, 299, 300, 301, -1, + }; +} +class yyCheck1 { + protected static final short yyCheck1 [] = { 33, + -1, -1, -1, -1, 308, 309, 40, -1, 275, 43, + -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, + 287, -1, -1, -1, -1, -1, 293, 294, 295, 296, + 297, 298, 299, 300, 301, -1, -1, -1, -1, -1, + -1, 308, 309, -1, -1, -1, -1, -1, -1, -1, + -1, 275, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 287, -1, -1, -1, -1, -1, 293, + 294, 295, 296, 297, 298, 299, 300, 301, 275, -1, + -1, -1, -1, -1, 308, 309, -1, 60, -1, -1, + 287, -1, -1, -1, -1, 275, 293, 294, 295, 296, + 297, 298, 299, 300, 301, -1, -1, 287, -1, -1, + -1, 308, 309, 293, 294, 295, 296, 297, 298, 299, + 300, 301, 275, -1, -1, -1, -1, -1, 308, 309, + -1, -1, -1, -1, 287, -1, -1, -1, -1, -1, + 293, 294, 295, 296, 297, 298, 299, 300, 301, -1, + -1, -1, 125, -1, -1, 308, 309, -1, 37, 38, + -1, 40, 41, 42, 43, 44, 45, 46, 47, -1, + -1, -1, -1, -1, -1, -1, -1, 275, -1, -1, + 59, -1, -1, 62, -1, -1, -1, -1, -1, 287, + -1, -1, -1, -1, -1, 293, 294, 295, 296, 297, + 298, 299, 300, 301, -1, -1, -1, -1, -1, -1, + 308, 309, 91, -1, 275, 94, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 287, -1, -1, -1, + 40, -1, 293, 294, 295, 296, 297, 298, 299, 300, + 301, -1, -1, -1, 123, 124, 125, 308, 309, 59, + -1, -1, -1, 287, -1, -1, -1, -1, -1, 293, + 294, 295, 296, 297, 298, 299, 300, 301, -1, -1, + -1, -1, 37, 38, 308, 309, 41, 42, 43, 44, + 45, -1, 47, -1, 257, 258, -1, -1, -1, 262, + -1, -1, -1, -1, 59, 60, 269, 62, -1, -1, + -1, 274, -1, 276, 277, 278, 364, 365, -1, -1, + -1, 284, -1, 123, -1, 125, -1, -1, 291, -1, + -1, 379, -1, -1, -1, -1, -1, 37, 301, 94, + -1, 41, 42, 43, 44, 45, 46, 47, -1, -1, + -1, -1, -1, 401, 402, -1, 404, -1, -1, 59, + 60, 409, 62, -1, -1, 413, -1, 415, 416, 124, + 125, -1, -1, -1, -1, -1, 424, 425, 426, -1, + -1, -1, 430, -1, -1, -1, -1, -1, 257, 258, + -1, -1, -1, 262, 94, -1, -1, -1, -1, -1, + 269, -1, -1, -1, 273, 274, -1, 276, 277, 278, + -1, -1, -1, 282, -1, 284, -1, -1, -1, 60, + -1, -1, 291, -1, 124, 125, -1, -1, -1, -1, + -1, -1, 301, 302, 303, 304, 305, 306, 307, 308, + 309, -1, -1, 37, 38, -1, -1, 41, 42, 43, + 44, 45, 46, 47, -1, -1, -1, -1, 258, -1, + -1, -1, 262, -1, -1, 59, 60, 267, 62, -1, + -1, 271, 272, -1, 274, -1, -1, -1, -1, -1, + -1, -1, -1, 283, 125, -1, -1, 287, -1, -1, + -1, -1, 292, 293, 294, 295, 296, 297, 298, 299, + 300, 301, 257, 258, -1, -1, -1, 262, 308, 309, + -1, -1, -1, -1, 269, -1, -1, -1, 273, 274, + -1, 276, 277, 278, -1, -1, -1, -1, -1, 284, + 124, 125, -1, -1, -1, -1, 291, 40, -1, -1, + -1, -1, -1, -1, -1, -1, 301, 302, 303, 304, + 305, 306, 307, 308, 309, -1, 59, 257, 258, -1, + -1, -1, 262, -1, -1, -1, -1, -1, -1, 269, + -1, -1, -1, 273, 274, -1, 276, 277, 278, -1, + -1, -1, -1, -1, 284, -1, -1, -1, 37, 38, + -1, 291, 41, 42, 43, 44, 45, 46, 47, -1, + -1, 301, 302, 303, 304, 305, 306, 307, 308, 309, + 59, 60, -1, 62, -1, -1, 257, 258, -1, -1, + 123, 262, -1, -1, -1, -1, -1, -1, 269, -1, + -1, -1, -1, 274, -1, 276, 277, 278, -1, -1, + -1, -1, -1, 284, -1, 94, -1, 37, 38, -1, + 291, 41, 42, 43, 44, 45, 46, 47, -1, -1, + 301, -1, -1, 257, 258, -1, -1, -1, 262, 59, + 60, -1, 62, -1, -1, 269, 125, -1, -1, 273, + 274, -1, 276, 277, 278, -1, -1, -1, -1, -1, + 284, -1, -1, -1, -1, -1, -1, 291, -1, -1, + -1, -1, -1, -1, 94, -1, -1, 301, 302, 303, + 304, 305, 306, 307, 308, 309, 37, 38, -1, -1, + 41, 42, 43, 44, 45, 46, 47, -1, -1, -1, + -1, -1, -1, -1, 124, 125, -1, -1, 59, 60, + -1, 62, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 37, 38, -1, -1, 41, 42, 43, + 44, 45, -1, 47, -1, -1, -1, -1, 271, 272, + -1, -1, -1, 94, -1, 59, 60, -1, 62, -1, + 283, -1, -1, -1, 287, -1, -1, -1, -1, 292, + 293, 294, 295, 296, 297, 298, 299, 300, 301, -1, + -1, -1, -1, 124, 125, 308, 309, -1, 257, 258, + 94, -1, -1, 262, -1, -1, -1, -1, -1, -1, + 269, -1, -1, -1, 273, 274, -1, 276, 277, 278, + -1, -1, -1, -1, -1, 284, -1, -1, -1, 37, + 124, 125, 291, 41, 42, 43, 44, 45, 46, 47, + -1, -1, 301, 302, 303, 304, 305, 306, 307, 308, + 309, 59, 60, -1, 62, -1, -1, 257, 258, -1, + -1, -1, 262, -1, -1, -1, -1, -1, -1, 269, + -1, -1, -1, 273, 274, -1, 276, 277, 278, -1, + -1, -1, -1, -1, 284, -1, 94, -1, -1, -1, + -1, 291, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 301, 302, 303, 304, 305, 306, -1, 308, 309, + -1, -1, -1, -1, 37, 38, 124, 125, 41, 42, + 43, 44, 45, 46, 47, -1, 257, 258, -1, -1, + -1, 262, -1, -1, -1, -1, 59, 60, 269, 62, + -1, -1, 273, 274, -1, 276, 277, 278, -1, -1, + -1, -1, -1, 284, -1, -1, -1, -1, -1, -1, + 291, -1, -1, 257, 258, -1, -1, -1, 262, -1, + 301, 302, 303, 304, 305, 269, 307, 308, 309, 273, + 274, -1, 276, 277, 278, -1, -1, -1, -1, -1, + 284, -1, -1, -1, -1, -1, -1, 291, -1, -1, + }; +} +class yyCheck2 { + protected static final short yyCheck2 [] = { -1, + 124, 125, -1, 60, -1, -1, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 37, 38, -1, -1, 41, + 42, 43, 44, 45, 46, 47, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 59, 60, -1, + 62, -1, -1, -1, -1, -1, -1, -1, 257, 258, + -1, -1, -1, 262, -1, -1, -1, -1, -1, -1, + 269, -1, -1, -1, 273, 274, -1, 276, 277, 278, + -1, -1, 94, -1, -1, 284, -1, -1, -1, -1, + -1, -1, 291, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 301, 302, 303, 304, 305, 306, 307, 308, + 309, 37, 38, 125, -1, 41, 42, 43, 44, 45, + 46, 47, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 59, 60, -1, 62, -1, -1, -1, + -1, -1, -1, 257, 258, -1, -1, -1, 262, -1, + -1, -1, -1, -1, -1, 269, -1, -1, -1, 273, + 274, -1, 276, 277, 278, -1, -1, -1, 94, -1, + 284, -1, -1, -1, -1, -1, -1, 291, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 301, 302, 303, + 304, 305, 306, 307, 308, 309, 37, 38, 124, 125, + 41, 42, -1, 44, -1, 46, 47, -1, -1, -1, + 257, 258, -1, -1, -1, 262, -1, -1, 59, 60, + -1, 62, 269, -1, -1, -1, -1, 274, -1, 276, + 277, 278, -1, -1, -1, -1, -1, 284, -1, -1, + -1, -1, -1, -1, 291, 257, 258, -1, -1, -1, + 262, -1, 40, 94, 301, -1, -1, 269, -1, -1, + -1, 273, 274, -1, 276, 277, 278, -1, -1, -1, + -1, 59, 284, -1, -1, -1, -1, -1, -1, 291, + -1, -1, -1, 124, 125, -1, -1, -1, -1, 301, + 302, 303, 304, 305, 306, 307, 308, 309, 37, 38, + -1, -1, 41, 42, 43, 44, 45, 46, 47, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 59, 60, -1, 62, -1, -1, -1, -1, -1, -1, + -1, 257, 258, -1, -1, 123, 262, -1, -1, -1, + -1, -1, -1, 269, -1, -1, -1, 273, 274, -1, + 276, 277, 278, -1, -1, 94, -1, -1, 284, -1, + -1, -1, -1, -1, -1, 291, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 301, 302, 303, 304, 305, + 306, -1, 308, 309, -1, 124, 125, 37, 38, -1, + -1, 41, 42, 43, 44, 45, 46, 47, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 59, + 60, -1, 62, -1, -1, -1, 257, 258, -1, -1, + -1, 262, -1, -1, -1, -1, -1, -1, 269, -1, + -1, -1, 273, 274, -1, 276, 277, 278, -1, -1, + -1, -1, -1, 284, 94, -1, -1, -1, -1, -1, + 291, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 301, 302, 303, 304, 305, 306, 307, 308, 309, -1, + -1, -1, 37, 38, 124, 125, 41, 42, 43, 44, + 45, 46, 47, 271, 272, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 59, 283, -1, -1, -1, 287, + -1, -1, -1, -1, 292, 293, 294, 295, 296, 297, + 298, 299, 300, 301, -1, -1, -1, -1, 257, 258, + 308, 309, -1, 262, -1, -1, -1, -1, -1, 94, + 269, -1, -1, -1, 273, 274, -1, 276, 277, 278, + -1, -1, -1, -1, -1, 284, -1, -1, -1, -1, + -1, -1, 291, -1, -1, -1, -1, -1, -1, 124, + 125, -1, 301, -1, 303, 304, -1, 306, 307, 308, + 309, -1, -1, 37, 38, -1, -1, 41, 42, 43, + 44, 45, 46, 47, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 59, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 257, 258, -1, + -1, -1, 262, -1, -1, -1, -1, -1, -1, 269, + -1, -1, -1, 273, 274, -1, 276, 277, 278, -1, + 94, -1, -1, -1, 284, -1, -1, -1, -1, -1, + -1, 291, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 301, -1, 303, 304, 60, 306, 307, 308, 309, + 124, 125, -1, 37, 38, -1, -1, 41, 42, 43, + 44, 45, 46, 47, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 59, -1, -1, -1, -1, + -1, -1, 257, 258, -1, -1, -1, 262, -1, -1, + -1, -1, -1, -1, 269, -1, -1, -1, -1, 274, + -1, 276, 277, 278, -1, -1, -1, -1, -1, 284, + 94, -1, -1, -1, -1, -1, 291, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 301, 302, -1, -1, + 305, 306, 307, 308, 309, -1, -1, -1, -1, -1, + 124, 125, -1, 38, -1, -1, 41, -1, 43, 44, + 45, 46, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 59, 60, -1, 62, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 257, 258, -1, -1, -1, 262, -1, + -1, 137, 138, -1, -1, 269, -1, -1, -1, 94, + 274, -1, 276, 277, 278, -1, -1, -1, -1, -1, + 284, -1, -1, -1, -1, 38, -1, 291, 41, -1, + 43, 44, 45, 46, -1, -1, -1, 301, 302, 124, + 125, 305, 306, 307, 308, 309, 59, 60, -1, 62, + -1, -1, 257, 258, 190, 191, 192, 262, -1, -1, + -1, -1, -1, -1, 269, -1, -1, -1, -1, 274, + -1, 276, 277, 278, -1, -1, -1, -1, -1, 284, + -1, 94, -1, 257, 258, -1, 291, -1, 262, -1, + -1, -1, -1, -1, -1, 269, 301, -1, -1, -1, + 274, -1, 276, 277, 278, -1, -1, -1, -1, -1, + 284, 124, 125, -1, -1, 38, -1, 291, 41, -1, + 43, 44, 45, 46, -1, -1, -1, 301, 302, -1, + -1, 305, 306, 307, 308, 309, 59, 60, -1, 62, + -1, -1, -1, -1, -1, -1, -1, 283, 284, 285, + 286, 287, -1, 289, 290, 291, 292, 293, 294, 295, + 296, 297, 298, 299, -1, -1, -1, -1, -1, -1, + -1, 94, 257, 258, -1, -1, -1, 262, -1, -1, + -1, -1, -1, -1, 269, -1, -1, -1, 273, 274, + -1, 276, 277, 278, -1, -1, -1, -1, -1, 284, + 336, 124, 125, -1, -1, -1, 291, -1, -1, -1, + }; +} +class yyCheck3 { + protected static final short yyCheck3 [] = { -1, + -1, -1, -1, -1, -1, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 37, 38, -1, -1, 41, 42, + 43, 44, 45, 46, 47, -1, -1, -1, -1, -1, + -1, -1, -1, 257, 258, -1, 59, 60, 262, 62, + -1, -1, 40, -1, -1, 269, -1, -1, -1, 273, + 274, -1, 276, 277, 278, -1, -1, -1, -1, -1, + 284, 59, -1, -1, -1, -1, -1, 291, -1, -1, + -1, 94, -1, -1, -1, -1, -1, 301, 302, 303, + 304, 305, 306, 307, 308, 309, -1, -1, -1, -1, + -1, -1, -1, -1, 40, -1, -1, -1, -1, -1, + -1, 124, 125, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 59, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 257, 258, 123, -1, 125, 262, -1, + -1, -1, -1, -1, -1, 269, -1, -1, -1, 273, + 274, -1, 276, 277, 278, -1, 40, -1, -1, -1, + 284, -1, -1, -1, -1, -1, -1, 291, -1, -1, + -1, -1, -1, -1, -1, 59, -1, 301, 302, 303, + 304, 305, 306, 307, 308, 309, -1, 123, -1, 125, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 40, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 59, -1, -1, -1, -1, -1, -1, 123, + -1, 125, -1, -1, 257, 258, -1, -1, -1, 262, + -1, -1, -1, -1, -1, -1, 269, 40, -1, -1, + 273, 274, -1, 276, 277, 278, -1, -1, -1, -1, + 258, 284, -1, -1, 262, -1, 59, -1, 291, -1, + -1, -1, -1, 271, 272, -1, 274, -1, 301, 302, + 303, 304, 305, 306, 307, 283, 123, -1, 125, 287, + -1, -1, -1, -1, 292, 293, 294, 295, 296, 297, + 298, 299, 300, 301, -1, 40, -1, -1, -1, -1, + 308, 309, 258, -1, -1, -1, 262, -1, -1, -1, + -1, -1, -1, -1, 59, 271, 272, -1, 274, -1, + 123, -1, 125, -1, -1, -1, -1, 283, -1, -1, + -1, 287, -1, -1, -1, -1, 292, 293, 294, 295, + 296, 297, 298, 299, 300, 301, -1, -1, -1, -1, + -1, -1, 308, 309, 258, -1, -1, -1, 262, -1, + -1, -1, -1, -1, -1, -1, -1, 271, 272, -1, + 274, -1, -1, -1, -1, -1, -1, -1, 123, 283, + 125, -1, -1, 287, -1, -1, -1, -1, 292, 293, + 294, 295, 296, 297, 298, 299, 300, 301, -1, -1, + -1, -1, -1, -1, 308, 309, -1, -1, -1, -1, + -1, 258, -1, -1, -1, 262, -1, -1, -1, -1, + -1, -1, -1, -1, 271, 272, -1, 274, -1, -1, + -1, -1, -1, -1, -1, -1, 283, -1, -1, -1, + 287, -1, -1, -1, -1, 292, 293, 294, 295, 296, + 297, 298, 299, 300, 301, 258, -1, -1, -1, 262, + -1, 308, 309, -1, -1, -1, -1, -1, 271, 272, + -1, 274, -1, -1, -1, -1, -1, -1, -1, -1, + 283, -1, -1, -1, 287, -1, -1, -1, -1, 292, + 293, 294, 295, 296, 297, 298, 299, 300, 301, -1, + -1, -1, -1, -1, -1, 308, 309, -1, -1, -1, + -1, -1, -1, 258, -1, -1, -1, 262, -1, -1, + -1, -1, -1, -1, -1, -1, 271, 272, -1, 274, + -1, -1, -1, -1, -1, -1, -1, -1, 283, -1, + -1, -1, 287, -1, -1, -1, -1, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, -1, -1, -1, + -1, -1, -1, 308, 309, + }; +} +class yyCheckInit { + static short[] yyCheck = new short[3579]; + protected static void yyCheckInit () { + int numyycheck; + int yyCheckerun = 0; + for (numyycheck = 0; numyycheck <= 1000; numyycheck++) { + if (yyCheckerun < 3579) { + yyCheck[yyCheckerun] = yyCheck0.yyCheck0[numyycheck]; + yyCheckerun++; + } + } + for (numyycheck = 0; numyycheck <= 1000; numyycheck++) { + if (yyCheckerun < 3579) { + yyCheck[yyCheckerun] = yyCheck1.yyCheck1[numyycheck]; + yyCheckerun++; + } + } + for (numyycheck = 0; numyycheck <= 1000; numyycheck++) { + if (yyCheckerun < 3579) { + yyCheck[yyCheckerun] = yyCheck2.yyCheck2[numyycheck]; + yyCheckerun++; + } + } + for (numyycheck = 0; numyycheck <= 1000; numyycheck++) { + if (yyCheckerun < 3579) { + yyCheck[yyCheckerun] = yyCheck3.yyCheck3[numyycheck]; + yyCheckerun++; + } + } +} +} + diff --git a/src/mycompiler/myparser/Scanner.java b/src/mycompiler/myparser/Scanner.java new file mode 100755 index 000000000..95553520c --- /dev/null +++ b/src/mycompiler/myparser/Scanner.java @@ -0,0 +1,54 @@ +// ino.module.Scanner.8618.package +package mycompiler.myparser; +// ino.end +// ino.class.Scanner.24842.declaration +public class Scanner extends JavaLexer implements JavaParser.yyInput +// ino.end +// ino.class.Scanner.24842.body +{ + // ino.method.Scanner.24847.definition + public Scanner (java.io.Reader reader) + // ino.end + // ino.method.Scanner.24847.body + { + super (reader); + } + // ino.end + + // ino.method.token.24850.definition + public int token () + // ino.end + // ino.method.token.24850.body + { + if (token.token instanceof String) + { + return (int)(((String)token.token).charAt(0)); + } + else + { + return ((Integer)token.token).intValue(); + } + } + // ino.end + + // ino.method.advance.24853.definition + public boolean advance () + throws java.io.IOException + // ino.end + // ino.method.advance.24853.body + { + boolean ret = yylex(); + return ret; + } + // ino.end + + // ino.method.value.24856.definition + public Object value () + // ino.end + // ino.method.value.24856.body + { + return this.token; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/myparser/Token.java b/src/mycompiler/myparser/Token.java new file mode 100755 index 000000000..3a7133bf4 --- /dev/null +++ b/src/mycompiler/myparser/Token.java @@ -0,0 +1,177 @@ +// ino.module.Token.8619.package +package mycompiler.myparser; +// ino.end +// ino.class.Token.24859.declaration +public class Token +// ino.end +// ino.class.Token.24859.body +{ + // ino.attribute.token.24862.declaration + public Object token; + // ino.end + // ino.attribute.lexem.24865.declaration + private String lexem; + // ino.end + // ino.attribute.m_LineNumber.24868.declaration + private int m_LineNumber; + // ino.end + // ino.attribute.m_Offset.24871.declaration + private int m_Offset;//hinzugefügt hoth: 14.04.2006 + // ino.end + + + // ino.method.Token.24874.definition + Token (int tok, int lineNumber) + // ino.end + // ino.method.Token.24874.body + { + this.token = new Integer(tok); + m_LineNumber = lineNumber; + } + // ino.end + + // ino.method.Token.24877.definition + Token (int tok, String s, int lineNumber) + // ino.end + // ino.method.Token.24877.body + { + lexem = s; + this.token = new Integer(tok); + m_LineNumber = lineNumber; + } + // ino.end + + // ino.method.Token.24880.definition + Token (int tok, char c, int lineNumber) + // ino.end + // ino.method.Token.24880.body + { + char[] ch = new char[1]; + ch[0] = c; + this.token = new String(ch); + m_LineNumber = lineNumber; + } + // ino.end + + // ino.method.Token.24883.defdescription type=line + // hinzugefügt hoth: 14.04.2006 + // ino.end + // ino.method.Token.24883.definition + Token (int tok, String s, int lineNumber, int charOffset) + // ino.end + // ino.method.Token.24883.body + { + lexem = s; + this.token = new Integer(tok); + m_LineNumber = lineNumber; + m_Offset = charOffset; + } + // ino.end + + // ino.method.Token.24886.defdescription type=line + // hinzugefügt hoth: 14.04.2006 + // ino.end + // ino.method.Token.24886.definition + Token (int tok, char c, int lineNumber, int charOffset) + // ino.end + // ino.method.Token.24886.body + { + char[] ch = new char[1]; + ch[0] = c; + this.token = new String(ch); + m_LineNumber = lineNumber; + m_Offset = charOffset; + } + // ino.end + + // ino.method.getLineNumber.24889.definition + public int getLineNumber() + // ino.end + // ino.method.getLineNumber.24889.body + { + return m_LineNumber; + } + // ino.end + + // ino.method.getOffset.24892.definition + public int getOffset() + // ino.end + // ino.method.getOffset.24892.body + { + return m_Offset; + } + // ino.end + + + // ino.method.getLexem.24895.definition + public String getLexem () + // ino.end + // ino.method.getLexem.24895.body + { + return lexem; + } + // ino.end + + // ino.method.String2Int.24898.definition + public int String2Int() + // ino.end + // ino.method.String2Int.24898.body + { + return Integer.decode(lexem); + } + // ino.end + + public long String2Long() + { + return Long.decode(lexem); + } + + public float String2Float() + { + return Float.parseFloat(lexem); + } + + public double String2Double() + { + return Double.parseDouble(lexem); + } + + // ino.method.CharInString.24901.definition + public char CharInString() + // ino.end + // ino.method.CharInString.24901.body + { + char[] tmp = lexem.toCharArray(); + return tmp[1]; + } + // ino.end + + // ino.method.String2Bool.24904.definition + public boolean String2Bool() + // ino.end + // ino.method.String2Bool.24904.body + { + if(lexem.equals("true")) + { + return(true); + } + else + { + return(false); + } + } + // ino.end + + // ino.method.get_String.24907.definition + public String get_String() + // ino.end + // ino.method.get_String.24907.body + { + int laenge = lexem.length(); + String rueck; + rueck = lexem.substring(1,laenge-1); + return rueck; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mystatement/ArgumentList.java b/src/mycompiler/mystatement/ArgumentList.java new file mode 100755 index 000000000..ffda3031b --- /dev/null +++ b/src/mycompiler/mystatement/ArgumentList.java @@ -0,0 +1,112 @@ +// ino.module.ArgumentList.8621.package +package mycompiler.mystatement; +// ino.end +// ino.module.ArgumentList.8621.import +import java.util.Iterator; +import java.util.Vector; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.FormalParameter; +import mycompiler.myexception.JVMCodeException; +// ino.end + + + + +// ino.class.ArgumentList.24911.declaration +public class ArgumentList +// ino.end +// ino.class.ArgumentList.24911.body +{ + // ino.attribute.expr.24914.declaration + public Vector expr = new Vector(); + // ino.end + + + + // ino.method.codegen.24917.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.24917.body + { + for(int i = 0; i < expr.size(); i++) + { + expr.elementAt(i).codegen(classfile, code, paralist); + } + } + // ino.end + + + + // ino.method.get_codegen_ArgumentList.24920.definition + public String get_codegen_ArgumentList(Vector paralist) + // ino.end + // ino.method.get_codegen_ArgumentList.24920.body + { + String ret = "("; + for(int i = 0; i < expr.size(); i++) + { + ret += JVMCode.get_codegen_Type(expr.elementAt(i).getTypeName(), paralist); + } + return ret + ")"; + } + // ino.end + + + + // ino.method.get_firstElement.24923.definition + public Object get_firstElement() + // ino.end + // ino.method.get_firstElement.24923.body + { + return expr.firstElement(); + } + // ino.end + + + + /** + * @author Andreas Stadelmeier, a10023 + * @return Anzahl der Argumente in der ArgumentList + */ + public int size() { + return expr.size(); + } + + /** + * @author Andreas Stadelmeier, a10023 + * @param n + * @return Das Element (Expr) in der Argumentliste an der Stelle n + */ + public Expr argumentAt(int n){ + return expr.elementAt(n); + } + public String toString(){ + if(expr == null)return "[]"; + String ret = " [ "; + for(Expr expr : this.expr){ + ret += expr.toString()+", "; + } + return ret + "]"; + } + + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult(); + Iterator it = this.expr.iterator(); + while(it.hasNext()){ + Expr expr = it.next(); + ret.attach(expr.printJavaCode(resultSet)); + if(it.hasNext())ret.attach(", "); + } + //if(this.expr.size()>0)ret = ret.substring(0, ret.length()-2); + return ret; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/Assign.java b/src/mycompiler/mystatement/Assign.java new file mode 100755 index 000000000..3fd23dc24 --- /dev/null +++ b/src/mycompiler/mystatement/Assign.java @@ -0,0 +1,501 @@ +// ino.module.Assign.8622.package +package mycompiler.mystatement; +// ino.end +// ino.module.Assign.8622.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CMultiplyTuple; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CMultiplyTupleSet; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end +import typinferenz.JavaCodeResult; +import typinferenz.SingleConstraint; +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.Assign.24926.declaration +public class Assign extends Expr +// ino.end +// ino.class.Assign.24926.body +{ + // ino.method.Assign.24930.definition + public Assign(int offset,int variableLength) + // ino.end + // ino.method.Assign.24930.body + { + super(offset,variableLength); + } + // ino.end + + + // ino.attribute.expr1.24933.declaration + public Expr expr1; + // ino.end + // ino.attribute.expr2.24936.declaration + public Expr expr2; + // ino.end + + // ino.attribute.parserlog.24939.decldescription type=javadoc + /** + * Logger log4j + */ + // ino.end + // ino.attribute.parserlog.24939.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.set_Expr.24942.definition + public void set_Expr(Expr expr1,Expr expr2) + // ino.end + // ino.method.set_Expr.24942.body + { + this.expr1 = expr1; + this.expr2 = expr2; + } + // ino.end + + + + // ino.method.sc_check.24945.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.24945.body + { + SCStatementException except = null; + try + { + expr1.sc_check(classname, ch, bh, ext, parach, parabh); + } + catch(SCStatementException ex) + { + except=ex; + } + try + { + expr2.sc_check(classname, ch, bh, ext, parach, parabh); + } + catch(SCStatementException ex) + { + if(except==null) + { + except=ex; + } + else + { + Vector v = ex.get_exlist(); + SCExcept hilf; + for(Enumeration el=v.elements() ; el.hasMoreElements() ; ) + { + hilf = el.nextElement(); + except.addException(hilf); + } + } + } + expr1.getTypeName(); + expr2.getTypeName(); + parserlog.debug( "SC -> Expression linker Typ: " + expr1.getTypeName()); + parserlog.debug( "SC -> Expression rechter Typ: " + expr1.getTypeName()); + if( expr1.getTypeName() == null || expr2.getTypeName() == null ) + { + SCExcept ex = new SCExcept(); + ex.set_error("Eine Variable ist ohne gesetzten Typ."); + ex.set_statement("Assign"); + if( except == null ) + { + except=new SCStatementException(); + } + except.addException(ex); + } + else + { + if(expr2.getTypeName().equals("__NULL__")) + { + if(ext) + { + parserlog.debug("Assign setzt Variable auf null"); + } + } + else + { + if(!expr1.getTypeName().equals(expr2.getTypeName())) + { + // Linker Typ = Rechter Typ + parserlog.debug( "SC -> Linker Typ = Rechter Typ"); + if(expr1.getTypeName().equals("int")&&expr2.getTypeName().equals("char")) + { + parserlog.info("ACHTUNG! Hier wird einem int ein char zugewiesen."); + if(expr1.get_UsedId()==null) + { + parserlog.error("UsedId geht net"); + } + parserlog.debug("int "+expr1.get_UsedId().get_Name().toString()+" = char "+expr2.get_UsedId().get_Name().toString()); + } + else + { + if(ext) + { + parserlog.error("Typfehler: -->Assign.sc_check() "); + } + SCExcept neu=new SCExcept(); + neu.set_error("Typfehler"); + neu.set_statement("Assign: "+expr1.getTypeName()+" = "+expr2.getTypeName()); + if(except == null) + { + except=new SCStatementException(); + } + except.addException(neu); + } + } + } + } + if(except!= null) + { + throw except; + } + } + // ino.end + + + + // ino.method.get_Name.24948.definition + public String get_Name() + // ino.end + // ino.method.get_Name.24948.body + { + return null; + } + // ino.end + + + + // ino.method.codegen.24951.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.24951.body + { + // AutoBoxing-Feature: Literale koennen nur als Objekt zugewiesen werden + if (expr2 instanceof Literal) ((Literal)expr2).setPrimitiveFlag(false); + + + if(expr1 instanceof LocalOrFieldVar) + { + LocalOrFieldVar local = (LocalOrFieldVar)expr1; + Vector name_vector = local.get_Name_Vector(); + Vector type_vector = local.get_Type_Vector(); + String local_name = null; + String class_name = null; + String type = null; + for(int i=0; i < name_vector.size()-1; i++) + { + local_name = (String)name_vector.elementAt(i); + type = JVMCode.get_codegen_Type((String)type_vector.elementAt(i), paralist); + int index = code.get_indexOf_Var(local_name); + if(index != -1) + { + // LocalVar + try + { + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload_n(local_type, index)); + } + catch(JVMCodeException e) + { + // out of nload_n + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload(local_type)); + code.add_code_byte((byte)index); + } + } + else + { + // FieldVar + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.getfield); + code.add_code_short(classfile.add_field_ref(local_name, class_name, type)); + } + class_name = (String)type_vector.elementAt(i); + } + expr2.codegen(classfile, code, paralist); + local_name = (String)name_vector.lastElement(); + int index = code.get_indexOf_Var(local_name); + if(index != -1) + { + // LocalVar + try + { + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nstore_n(local_type, index)); + } + catch(JVMCodeException e) + { + // out of nstore_n + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nstore(local_type)); + code.add_code_byte((byte)index); + } + } + else + { + // FieldVar + code.add_code(JVMCode.putfield); + code.add_code_short(classfile.add_field_ref(local_name, class_name, JVMCode.get_codegen_Type(expr2.getTypeName(), paralist))); + } + } + else if(expr1 instanceof InstVar) + { + InstVar instvar = (InstVar)expr1; + String instvar_name = instvar.get_codegen_UsedId(); + code.add_code(JVMCode.aload_0); + expr2.codegen(classfile, code, paralist); + code.add_code(JVMCode.putfield); + code.add_code_short(classfile.add_field_ref(instvar_name, null, null)); + } + else throw new JVMCodeException("JVMCodeException: Assign: void test codegen(ClassFile classfile, Code_attribute code)"); + } + // ino.end + + /** + * @author AI10023 - Andreas Stadelmeier + */ + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + ret.add(expr1.TYPEExpr(assumptions)); + ret.add(expr2.TYPEExpr(assumptions)); + //this.setTypeVariable( TypePlaceholder.fresh(this)); + this.setTypeVariable(TypePlaceholder.fresh(this)); + ret.add(new SingleConstraint(expr2.getTypeVariable(), expr1.getTypeVariable())); //expr1.type < expr2.type + ret.add(new SingleConstraint(expr1.getTypeVariable(), this.getTypeVariable())); + return ret; + } + + /** + * Spezifikation: + * TYPEStmt( Ass, stmt ) = + * let (stmt : rty, ConS) = TYPEExpr( Ass, stmt ) + * in (stmt : Void, ConS) + */ + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){ + ConstraintsSet ret = this.TYPEExpr(assumptions); //TypeExpr aufrufen + this.setTypeVariable(new Void(0)); //Typ des Statments auf Void setzen. + return ret; + } + + // ino.method.TRExp.24954.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.30 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.24954.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.24954.body + { + CTripleSet returnSet = new CTripleSet(); + + Vector epressions = new Vector(); + epressions.addElement(this.expr1); + epressions.addElement(this.expr2); + // -------------------------- + // TRTuple rufen: + // -------------------------- + CMultiplyTupleSet tupleSet = this.TRTuple(new CMultiplyTuple(sigma, new Vector(), V), epressions, supportData); + Iterator tupleIt = tupleSet.getIterator(); + Vector exceptions=new Vector(); + while(tupleIt.hasNext()){ + CMultiplyTuple tuple = tupleIt.next(); + if(tuple.getResultTypes().size()!=2){ + throw new CTypeReconstructionException("Assign.TRExp(): Ung�ltige Anzahl von ReturnTypes",this); + } + // -------------------------- + // Die beiden ReturnTypes unifizieren: + // -------------------------- + Type ty1 = tuple.getResultTypes().elementAt(0); + Type ty2 = tuple.getResultTypes().elementAt(1); + Vector> unifierPossibilities = Unify.unify(ty2, ty1, supportData.getFiniteClosure()); + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Wenn Unifier vorhanden, dann anwenden: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Alle m�glichen Unifier auf V anwenden: + // -------------------------- + for(int k=0; k pairIt = unifier.getIterator(); + // while(pairIt.hasNext()){ + // CSubstitution pair = pairIt.next(); + // if(pair.getTypeVar().getName().equals(ty1.getName())){ + // ty1 = pair.getType(); + // break; + // } + // } + // } + // -------------------------- + CTriple subTriple = new CTriple(substitutionSet, substitutionSet.applyThisSubstitutionSet(ty1), V_substituted); + + // -------------------------- + // Triple zu R�ckgabemenge hinzuf�gen + // -------------------------- + subSet.addElement(subTriple); + } + } + // -------------------------- + // Ansonsten Fehlermeldung: + // -------------------------- + else { + //MUSS AUSSERHALB DER ITERATOR WHILE-SRHLEIFE PL 07-08-11 STEHEN + //throw new CTypeReconstructionException("Assign.TRExp(): Typen "+ty1+" und "+ty2+" lassen sich nicht unifizieren.",this); + exceptions.add(new CTypeReconstructionException("Assign.TRExp(): Typen "+ty1+" und "+ty2+" lassen sich nicht unifizieren.",this)); + + } + returnSet.unite(subSet); + } + //CTripleSet returnSet2 = super.unifyAndRegisterType(returnSet, supportData); + CTripleSet returnSet2 = super.registerType(returnSet, supportData); + + //eingefuegt PL 07-08-11 + //Anfang + if(returnSet.getCardinality()==0){ + if (exceptions.size()==1) { + throw exceptions.elementAt(0); + } + else { + throw new CTypeReconstructionException("Assign.TRExp(): Es gibt kein Typpaar das sich unifizieren laesst.",this); + } + + } + //Ende + + return returnSet2; + } + // ino.end + + + + // ino.method.TRStatement.24957.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.25 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRStatement.24957.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.24957.body + { + CTripleSet resultSet = this.TRExp(sigma, V, supportData); + resultSet = resultSet.deepCopy(); + Iterator it = resultSet.getIterator(); + while(it.hasNext()){ + it.next().setResultType(new Void(getOffset())); + } + return resultSet; + } + // ino.end + + // ino.method.toString.24960.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.24960.definition + public String toString() + // ino.end + // ino.method.toString.24960.body + { + if(getTypeVariable() == null)return "(" + expr1.toString() + " = " + expr2.toString() + ")"; + return getTypeVariable().toString() + "(" + expr1.toString() + " = " + expr2.toString() + ")"; + } + // ino.end + + + // ino.method.wandleRefTypeAttributes2GenericAttributes.24963.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.24963.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr1.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + expr2.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + @Override + public String getTypeInformation(){ + return "(" + expr1.getTypeInformation() + " = " + expr2.getTypeInformation() + ") : "+this.getTypeVariable(); + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet){ + JavaCodeResult ret = new JavaCodeResult().attach(this.expr1.printJavaCode(resultSet) ).attach( " = " ).attach( this.expr2.printJavaCode(resultSet)); + return ret; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/Binary.java b/src/mycompiler/mystatement/Binary.java new file mode 100755 index 000000000..2219d6ae1 --- /dev/null +++ b/src/mycompiler/mystatement/Binary.java @@ -0,0 +1,396 @@ +// ino.module.Binary.8623.package +package mycompiler.mystatement; +// ino.end +// ino.module.Binary.8623.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.myoperator.AddOp; +import mycompiler.myoperator.LogOp; +import mycompiler.myoperator.MulOp; +import mycompiler.myoperator.Operator; +import mycompiler.myoperator.RelOp; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + +// ino.class.Binary.24966.description type=line +// neu von Felix +// ino.end +// ino.class.Binary.24966.declaration +public class Binary extends BinaryExpr +// ino.end +// ino.class.Binary.24966.body +{ + + // ino.method.Binary.24970.definition + public Binary(int offset, int variableLength) + // ino.end + // ino.method.Binary.24970.body + { + super(offset,variableLength); + } + // ino.end + + + // ino.attribute.parserlog.24973.decldescription type=javadoc + /** + * Logger: log4j + */ + // ino.end + // ino.attribute.parserlog.24973.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + // ino.attribute.expr1.24976.declaration + public Expr expr1; + // ino.end + // ino.attribute.op.24979.declaration + public Operator op; + // ino.end + // ino.attribute.expr2.24982.declaration + public Expr expr2; + // ino.end + + // ino.method.sc_check.24985.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.24985.body + { + Operator testen = get_Operator(); + if(ext) + parserlog.debug(" ---Binary---"); + SCStatementException except=null; + try + { + expr1.sc_check(classname, ch, bh, ext, parach, parabh); + parserlog.debug("expr1.get_Type: "+expr1.getTypeName()); + } + catch(SCStatementException ex) + { + except=ex; + } + try + { + expr2.sc_check(classname, ch, bh, ext, parach, parabh); + parserlog.debug("expr1.get_Type: "+expr2.getTypeName()); + } + //System/.out.println(expr1.get_Type()); + //System/.out.println(expr2.get_Type()); + catch(SCStatementException ex) + { + if(except==null) + except=ex; + else + { + Vector v; + SCExcept hilf; + v=ex.get_exlist(); + for(Enumeration el=v.elements();el.hasMoreElements();) + { + hilf=el.nextElement(); + except.addException(hilf); + } + } + } + //Type type1 = new Type(expr1.getTypeName()); + if(!expr1.getTypeName().equals(expr2.getTypeName())) + { + if(ext) + parserlog.error("Typfehler: -->Binary.sc_check() "); + SCExcept neu=new SCExcept(); + neu.set_error("Typfehler: "+expr1.getTypeName()+" != "+expr2.getTypeName()); + neu.set_statement("Binary"); + if(except==null) + except=new SCStatementException(); + except.addException(neu); + } + else + { + if(testen instanceof AddOp ||testen instanceof MulOp) + this.setType(new Type(expr1.getTypeName(),getOffset())); + else + this.setType(new Type("boolean",getOffset())); + } + if(except!=null) + throw except; + } + // ino.end + + + + // ino.method.set_Expr1.24988.definition + public void set_Expr1(Expr exp) + // ino.end + // ino.method.set_Expr1.24988.body + { + this.expr1=exp; + } + // ino.end + + + + // ino.method.set_Expr2.24991.definition + public void set_Expr2(Expr exp) + // ino.end + // ino.method.set_Expr2.24991.body + { + this.expr2=exp; + } + // ino.end + + + + // ino.method.set_Operator.24994.definition + public void set_Operator(Operator Op) + // ino.end + // ino.method.set_Operator.24994.body + { + this.op=Op; + } + // ino.end + + + + // ino.method.get_Name.24997.definition + public String get_Name() + // ino.end + // ino.method.get_Name.24997.body + { + return null; + } + // ino.end + + + + // ino.method.get_Operator.25000.definition + public Operator get_Operator() + // ino.end + // ino.method.get_Operator.25000.body + { + return op; + } + // ino.end + + + + // ino.method.get_Expr1.25003.definition + public Expr get_Expr1() + // ino.end + // ino.method.get_Expr1.25003.body + { + return expr1; + } + // ino.end + + + + // ino.method.get_Expr2.25006.definition + public Expr get_Expr2() + // ino.end + // ino.method.get_Expr2.25006.body + { + return expr2; + } + // ino.end + + + + // ino.method.codegen.25009.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25009.body + { + if(type_check(code)) + { + op.codegen(classfile, code, this, false, paralist); + } + else + { + throw new JVMCodeException("JVMCodeException: Binary: void codegen(ClassFile classfile, Code_attribute code)"); + } + } + // ino.end + + + + // ino.method.not_codegen.25012.definition + public void not_codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.not_codegen.25012.body + { + if(((op instanceof RelOp) || (op instanceof LogOp)) && type_check(code)) + { + op.codegen(classfile, code, this, true, paralist); + } + else + { + throw new JVMCodeException("JVMCodeException: Binary: void not_codegen(ClassFile classfile, Code_attribute code)"); + } + } + // ino.end + + + + // ino.method.neg_codegen.25015.definition + public void neg_codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.neg_codegen.25015.body + { + if(((op instanceof AddOp) || (op instanceof MulOp)) && type_check(code)) + { + op.codegen(classfile, code, this, true, paralist); + } + else + { + throw new JVMCodeException("JVMCodeException: Binary: void neg_codegen(ClassFile classfile, Code_attribute code)"); + } + } + // ino.end + + + + // ino.method.type_check.25018.definition + public boolean type_check(CodeAttribute code) + throws JVMCodeException + // ino.end + // ino.method.type_check.25018.body + { + int type1 = JVMCode.get_nType(expr1.getTypeName()); + int type2 = JVMCode.get_nType(expr2.getTypeName()); + if((type1 < type2) || ((type1==0 || type1==1) && (type2==2 || type2==3))) + { + return false; + } + if(type1 != type2) + { + code.add_code(JVMCode.n2n(expr2.getTypeName(), expr1.getTypeName())); + } + return true; + } + // ino.end + + + + // ino.method.TRExp.25021.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + throws CTypeReconstructionException + // ino.end + // ino.method.TRExp.25021.body + { + CTripleSet ret = op.TRExp(this, sigma, V, supportData); + //CTripleSet returnSet = super.unifyAndRegisterType(ret, supportData); + CTripleSet returnSet = super.registerType(ret, supportData); + // //CTripleSet expr2Set = binary.get_Expr2().TRExp(intTriple1.getSubstitutions(), intTriple1.getAssumptionSet(), supportData); + // // -------------------------- + // // Alle Triple durchgehen: + // // -------------------------- + // Iterator retIt = ret.getIterator(); + // while(retIt.hasNext()){ + // CTriple retTriple = (CTriple)retIt.next(); + // // -------------------------- + // // ReturnType mit type von this (Binary) unifizieren: + // // -------------------------- + // Vector> unifierPossibilities = Unify.unify(retTriple.getResultType(), this.getType(), supportData.getFiniteClosure()); + // // -------------------------- + // // Wenn Unifier vorhanden, dann + // // anwenden und Triple hinzuf�gen: + // // -------------------------- + // if(unifierPossibilities.size()!=0){ + // // -------------------------- + // // Subset bauen: + // // -------------------------- + // CTripleSet subSet = new CTripleSet(); + // // -------------------------- + // // Alle m�glichen Unifier anwenden: + // // -------------------------- + // for(int j=0; j paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25027.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr1.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + expr2.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + // TODO Implement Method stub + return ret; + } + + + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + throw new NotImplementedException(); + } + + +} +// ino.end diff --git a/src/mycompiler/mystatement/BinaryExpr.java b/src/mycompiler/mystatement/BinaryExpr.java new file mode 100755 index 000000000..8af06a319 --- /dev/null +++ b/src/mycompiler/mystatement/BinaryExpr.java @@ -0,0 +1,25 @@ +// ino.module.BinaryExpr.8624.package +package mycompiler.mystatement; +// ino.end + + +// ino.class.BinaryExpr.25030.declaration +public abstract class BinaryExpr extends Expr +// ino.end +// ino.class.BinaryExpr.25030.body +{ + + // ino.method.BinaryExpr.25034.definition + public BinaryExpr(int offset,int variableLength) + // ino.end + // ino.method.BinaryExpr.25034.body + { + super(offset,variableLength); + } + // ino.end + + // abstract public void if_codegen(ClassFile classfile, Code_attribute code, boolean sw) throws jvmCode_Exception; + // abstract public void not_codegen(ClassFile classfile, Code_attribute code) throws jvmCode_Exception; + +} +// ino.end diff --git a/src/mycompiler/mystatement/Block.java b/src/mycompiler/mystatement/Block.java new file mode 100755 index 000000000..3d0ae5ce2 --- /dev/null +++ b/src/mycompiler/mystatement/Block.java @@ -0,0 +1,472 @@ +// ino.module.Block.8625.package +package mycompiler.mystatement; +// ino.end +// ino.module.Block.8625.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.JavaCodeResult; +import typinferenz.SingleConstraint; +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; +import typinferenz.TypinferenzException; + + + + +// ino.class.Block.25037.declaration +public class Block extends Statement +// ino.end +// ino.class.Block.25037.body +{ + + // ino.method.Block.25041.definition + public Block() + // ino.end + // ino.method.Block.25041.body + { + super(-1,-1); + } + // ino.end + + + // ino.attribute.parserlog.25044.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.attribute.statements.25047.declaration + public Vector statements = new Vector(); + // ino.end + // ino.attribute.HashTabelleKlasse.25050.declaration + private Hashtable HashTabelleKlasse; + // ino.end + // ino.attribute.HashTabelleBlock.25053.declaration + private Hashtable HashTabelleBlock; + // ino.end + // ino.attribute.block_para.25056.declaration + private Hashtable block_para; + // ino.end + + //private String sc_meth_ret_type; + // ino.attribute.inferencelog.25059.decldescription type=javadoc + /** + * Logger: log4j + */ + // ino.end + // ino.attribute.inferencelog.25059.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + protected static Logger typinferenceLog = Logger.getLogger("Typeinference"); + + // ino.method.sc_check.25062.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25062.body + { + SCStatementException except = null; + SCExcept hilfex; + Statement tempStatement; + Vector v; + this.HashTabelleKlasse = ch; + this.HashTabelleBlock = (Hashtable) bh.clone(); + this.block_para = (Hashtable) parabh.clone(); + + // otth: Alle Statements durchgehen und von allen Statements den Semantik-Check machen + parserlog.debug( "Statements (Anzahl): " + statements.size()); + parserlog.debug( "Statements: " + statements); + + for( Enumeration el = this.statements.elements(); el.hasMoreElements(); ) + { + tempStatement = el.nextElement(); + try + { + // Semantik-Check + tempStatement.sc_check( classname, HashTabelleKlasse, HashTabelleBlock, ext, parach, block_para ); + } + catch (SCStatementException ex) + { + // Fehler abfangen + if( except==null ) + except=new SCStatementException(); + v = ex.get_exlist(); + for( Enumeration el1=v.elements();el1.hasMoreElements(); ) + { + hilfex=el1.nextElement(); + except.addException(hilfex); + } + } + } + if(except!=null) + { + throw except; + } + parserlog.debug("SC -> SC f�r Block war erfoglreich!"); + parserlog.debug("SC -> Blockhashtabelle: " + HashTabelleBlock); + } + // ino.end + + + + // ino.method.get_Statement.25065.definition + public Vector get_Statement() + // ino.end + // ino.method.get_Statement.25065.body + { + return statements; + } + // ino.end + + + + // ino.method.set_Statement.25068.definition + public void set_Statement(Statement s) + // ino.end + // ino.method.set_Statement.25068.body + { + statements.addElement(s); + } + // ino.end + + + + // ino.method.set_Statement_Vector.25071.definition + public void set_Statement_Vector(Vector v) + // ino.end + // ino.method.set_Statement_Vector.25071.body + { + statements = v; + } + // ino.end + + + + // ino.method.codegen.25074.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25074.body + { + for(int i = 0; i < statements.size(); i++) + { + statements.elementAt(i).codegen(classfile, code, paralist); + } + } + // ino.end + + + + ///////////////////////////////////////////////////////////////////////// + // TypeReconstructionAlgorithmus + ///////////////////////////////////////////////////////////////////////// + + // ino.method.TRStatement.25077.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.20 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + * @throws CTypeReconstructionException + */ + // ino.end + // ino.method.TRStatement.25077.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + throws CTypeReconstructionException + // ino.end + // ino.method.TRStatement.25077.body + { + supportData.incBlockDepth(); + CTypeAssumptionSet V_Start = V.shallowCopy(); + CTripleSet returnSet = this.TRStatements(sigma, V, statements, 0, V_Start, supportData); + supportData.decBlockDepth(); + return returnSet; + } + // ino.end + + // ino.method.TRStatements.25080.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.19 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param statementList + * @param index + * @param V_start + * @param supportData + * @return + * @throws CTypeReconstructionException + */ + // ino.end + // ino.method.TRStatements.25080.definition + public CTripleSet TRStatements(CSubstitutionSet sigma, CTypeAssumptionSet V, Vector statementList, int index, CTypeAssumptionSet V_start, CSupportData supportData) + throws CTypeReconstructionException + // ino.end + // ino.method.TRStatements.25080.body + { + CTripleSet returnSet = new CTripleSet(); + //////////////////// + // Leere Statementsliste: + //////////////////// + if(index>statements.size()-1){ + // HOTI Bei leeren Blöcken sollte dann schon aber auch was zurück gegeben werden + if(statements.size()==0){ + returnSet.addElement(new CTriple(sigma, new Void(this.getOffset()), V)); + } + return returnSet; + } + + //////////////////// + // Letztes Statement erreicht (Rekursionsanker): + //////////////////// + if(index==statements.size()-1){ + // TRStatement f�r aktuelles Statement rufen: + Statement stmnt = statementList.elementAt(index); + returnSet = stmnt.TRStatement(sigma, V, supportData); + inferencelog.debug(stmnt.toString()); + // Das L�schen von Typannahmen f�r lokale Variablen ist bei dieser Implementierung nicht notwendig. + // Im Gegenteil: Die lokalen Variablen m�ssen sogar erhalten bleiben. + } + //////////////////// + // Statementliste rekursiv durcharbeiten: + //////////////////// + else{ + // TRStatement f�r aktuelles Statement rufen: + Statement stmnt = statementList.elementAt(index); + + //setze Block f�r Offset-Setzung f�r lokale Variablen + if(stmnt instanceof LocalVarDecl)//hinzugef�gt hoth: 07.04.2006 + { + LocalVarDecl lokaleVar = (LocalVarDecl)stmnt; + lokaleVar.block=this; + } + + CTripleSet set = stmnt.TRStatement(sigma, V, supportData); + + // Alle m�glichen Kombinationen herstellen: + Iterator it = set.getIterator(); + Vector exceptions=new Vector(); + int successfulls=0; + while(it.hasNext()){ + CTriple triple = it.next(); + if (it.hasNext()) { + inferencelog.debug(stmnt.toString()); + } + // Rekursionsaufruf: + if(triple.getResultType() instanceof Void){ + // SupportData muss geklont werden, damit BlockID nicht mehrmals hochgez�hlt wird... + try{ + CTripleSet subset = this.TRStatements(triple.getSubstitutions(),triple.getAssumptionSet(),statementList,index+1,V_start,supportData.clone()); + // Rekursions-R�ckgabewert mit aktueller Menge vereinigen: + returnSet.unite(subset); + successfulls++; + }catch(CTypeReconstructionException tre){ + exceptions.addElement(tre); + } + } + else { + throw new CTypeReconstructionException("Block.TRStatements(): Unerreichbare Anweisung",this); + } + } + if(successfulls==0){ + if(exceptions.size()==1){ + throw exceptions.elementAt(0); + } + throw new CTypeReconstructionException("Block: Es konnte keine Assumption gefunden werden, die auf die Anforderung passt.",exceptions,this); + } + } + return returnSet; + } + // ino.end + + // ino.method.toString.25083.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25083.definition + public String toString() + // ino.end + // ino.method.toString.25083.body + { + return this.type + " { " + statements.toString(); + } + // ino.end + + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25086.defdescription type=javadoc + /** + * In allen lokalen Variablendeklarationen die "falschen" RefTypes ersetzen + * @param paralist + * @param genericMethodParameters + */ + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25086.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25086.body + { + if(statements==null) + return; + + for(int i=0;i0){ + Statement stmt = statements.elementAt(statements.size()-1); + typinferenceLog.debug("Prozessing statement: "+stmt); + this.setTypeVariable(stmt.getTypeVariable()); + for(int i= statements.size()-2; i >= 0; i--) { + stmt = statements.elementAt(i); + typinferenceLog.debug("Prozessing statement: "+stmt); + if (!(stmt.getTypeVariable() instanceof Void)) + if (this.getTypeVariable() instanceof Void) { + //this.setTypeVariable(stmt.getTypeVariable()); + throw new TypinferenzException("Falscher Return Type"); + } + else { + TypePlaceholder tph = TypePlaceholder.fresh(); + ret.add(new SingleConstraint(this.getTypeVariable(), tph)); + ret.add(new SingleConstraint(stmt.getTypeVariable(), tph)); + this.setTypeVariable(tph); + } + } + if (this.type instanceof TypePlaceholder) { + ((TypePlaceholder)this.type).addReplacementListener(this); + } + }else{ + this.setType(new Void(0)); + } + return ret; + } + + /* + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + if(this.getTypeVariable()==null)this.setTypeVariable(TypePlaceholder.fresh(this)); + for(Statement stmt : statements){ + typinferenceLog.debug("Prozessing statement: "+stmt); + ret.add(stmt.TYPEStmt(assumptions)); + if((stmt instanceof Return)){ + ret.add(new Constraint(stmt.getTypeVariable(), this.getTypeVariable()));//TODO: Dies nochmal prüfen. + } + } + return ret; + } + */ + + + public void replaceType(CReplaceTypeEvent e) { + super.replaceType(e); + } + + @Override + public String getTypeInformation(){ + String ret = "\n"; + for(Statement s : this.get_Statement()){ + ret += s.getTypeInformation()+"\n"; + } + return ret; + } + + + public int getTypeLineNumber() { + throw new NotImplementedException(); + } + + + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult().attach("{\n"); + for(Statement stmt : this.get_Statement()){ + ret.attach(stmt.printJavaCode(resultSet)); + ret.attach((stmt instanceof ExprStmt ? ";" : "") + "\n"); + } + return ret.attach("}"); + + } +} +// ino.end diff --git a/src/mycompiler/mystatement/BoolLiteral.java b/src/mycompiler/mystatement/BoolLiteral.java new file mode 100755 index 000000000..e21e02be8 --- /dev/null +++ b/src/mycompiler/mystatement/BoolLiteral.java @@ -0,0 +1,192 @@ +// ino.module.BoolLiteral.8626.package +package mycompiler.mystatement; +// ino.end +// ino.module.BoolLiteral.8626.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.BooleanType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.BoolLiteral.25089.declaration +public class BoolLiteral extends Literal +// ino.end +// ino.class.BoolLiteral.25089.body +{ + // ino.attribute.Bool.25093.declaration + private boolean Bool; + // ino.end + // ino.attribute.parserlog.25096.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.BoolLiteral.25099.definition + public BoolLiteral() + // ino.end + // ino.method.BoolLiteral.25099.body + { + super(-1,-1); + // #JB# 20.04.2005 + // ########################################################### + this.setType(new BooleanType()); + //this.setType(new Type("boolean")); + // ########################################################### + } + // ino.end + + + + // ino.method.sc_check.25102.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach,Hashtable parabh) + // ino.end + // ino.method.sc_check.25102.body + { + if(ext) + { + parserlog.debug(" ---BoolLiteral---"); + } + } + // ino.end + + + + // ino.method.set_Bool.25105.definition + public void set_Bool(boolean b) + // ino.end + // ino.method.set_Bool.25105.body + { + this.Bool = b; + } + // ino.end + + + + // ino.method.get_Name.25108.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25108.body + { + return null; + } + // ino.end + + + + // ino.method.codegen.25111.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25111.body + { + if(Bool) + code.add_code(JVMCode.iconst_1); + else + code.add_code(JVMCode.iconst_0); + + // Auto-Boxing des Typs in Boolean + code.add_code(JVMCode.invokestatic); + code.add_code_short(classfile.add_method_ref("java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;")); + } + // ino.end + + // ino.method.ConstantCodegen.25114.definition + public short ConstantCodegen(ClassFile classfile) + throws JVMCodeException + // ino.end + // ino.method.ConstantCodegen.25114.body + { + if (Bool) + return (short) classfile.add_CONSTANT_Integer_info(1); + else + return (short) classfile.add_CONSTANT_Integer_info(0); + } + // ino.end + + + // ino.method.TRStatement.25117.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25117.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + + // ino.method.TRExp.25120.defdescription type=javadoc + /** + * Workaround: �berschreibt Methode TRExp aus der Super-Klasse + * Literal, weil die Implementierung von Unify (noch) nicht mit + * Basetypes umgehen kann.
+ * Anstatt den Basetype BooleanType zur�ckzugeben, wird ein + * RefType zur�ckgegeben.
+ * Diese Methode kann sp�ter entfernt werden, sodass automatisch die Methode der + * Super-Klasse verwendet wird. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25120.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25120.body + { + CTripleSet tripleSet = new CTripleSet(); + tripleSet.addElement(new CTriple(sigma, new RefType("java.lang.Boolean",getOffset()),V)); + return tripleSet; + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25123.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25123.body + { + } + // ino.end + + + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + + return new ConstraintsSet(); + } + + + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + if(Bool)return new JavaCodeResult("true"); + return new JavaCodeResult("false"); + } + + +} +// ino.end diff --git a/src/mycompiler/mystatement/CastExpr.java b/src/mycompiler/mystatement/CastExpr.java new file mode 100755 index 000000000..a40b71748 --- /dev/null +++ b/src/mycompiler/mystatement/CastExpr.java @@ -0,0 +1,228 @@ +// ino.module.CastExpr.8627.package +package mycompiler.mystatement; +// ino.end +// ino.module.CastExpr.8627.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.CastExpr.25126.declaration +public class CastExpr extends UnaryExpr +// ino.end +// ino.class.CastExpr.25126.body +{ + // ino.method.CastExpr.25130.definition + public CastExpr(int offset,int variableLength) + // ino.end + // ino.method.CastExpr.25130.body + { + super(offset,variableLength); + } + // ino.end + + // ino.attribute.type.25133.declaration + private Type type; + // ino.end + // ino.attribute.expr.25136.declaration + public Expr expr; + // ino.end + // ino.attribute.parserlog.25139.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.sc_check.25142.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25142.body + { + if(ext) + parserlog.debug(" ---CastExpr---"); + SCStatementException except=null; + if(ext) + parserlog.debug("CastExpr.sc_check() berechnet Typ von expr und ceckt kompatibilitaet"); + try + { + expr.sc_check(classname, ch, bh, ext, parach, parabh); + } + catch(SCStatementException ex) + { + except=ex; + } + if(this.type.getName() != expr.getTypeName()) + { + if(ext) + parserlog.error("Typinkompatibilitaet - moeglicher Datenverlust --> CastExpr.sc_check() "); + SCExcept neu=new SCExcept(); + neu.set_error("Typfehler"); + neu.set_statement("ArrayAccess"); + if(except==null) + except=new SCStatementException(); + except.addException(neu); + } + if(except!=null) + throw except; + } + // ino.end + + + + // ino.method.get_Name.25145.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25145.body + { + return null; + } + // ino.end + + + + // ino.method.set_Type.25148.definition + public void set_Type(Type ty) + // ino.end + // ino.method.set_Type.25148.body + { + this.type = ty; + } + // ino.end + + + + // ino.method.set_Expr.25151.definition + public void set_Expr(Expr ex) + // ino.end + // ino.method.set_Expr.25151.body + { + this.expr = ex; + } + // ino.end + + + + + // ino.method.codegen.25154.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25154.body + { + int itype = JVMCode.get_nType(type.getName()); + int iexpr = JVMCode.get_nType(expr.getTypeName()); + if(itype != iexpr) + { + if((itype == 4) || (iexpr == 4)) + { + throw new JVMCodeException("JVMCodeException: CastExpr: void codegen(ClassFile classfile, Code_attribute code)"); + } + else + { + expr.set_Type(type); + code.add_code(JVMCode.n2n(expr.getTypeName(), type.getName())); + } + } + else if(itype == 4) expr.set_Type(type); + } + // ino.end + + // ino.method.TRExp.25157.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.43 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25157.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25157.body + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr rufen: + // -------------------------- + CTripleSet exprSet = expr.TRExp(sigma, V, supportData); + // -------------------------- + // ReturnType der Triple �ndern: + // -------------------------- + Iterator exprIt = exprSet.deepCopy().getIterator(); + while(exprIt.hasNext()){ + CTriple exprTriple = exprIt.next(); + exprTriple.setResultType(this.type); + returnSet.addElement(exprTriple); + } + return returnSet; + } + // ino.end + + // ino.method.TRStatement.25160.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25160.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25163.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25163.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("(("+this.usedid+")").attach(this.expr.printJavaCode(resultSet)).attach(")"); + } + + +} +// ino.end diff --git a/src/mycompiler/mystatement/CharLiteral.java b/src/mycompiler/mystatement/CharLiteral.java new file mode 100755 index 000000000..aa67f3632 --- /dev/null +++ b/src/mycompiler/mystatement/CharLiteral.java @@ -0,0 +1,184 @@ +// ino.module.CharLiteral.8628.package +package mycompiler.mystatement; +// ino.end +// ino.module.CharLiteral.8628.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.CharacterType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.CharLiteral.25166.declaration +public class CharLiteral extends Literal +// ino.end +// ino.class.CharLiteral.25166.body +{ + // ino.attribute.Char.25170.declaration + private char Char; + // ino.end + // ino.attribute.parserlog.25173.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.CharLiteral.25176.definition + public CharLiteral() + // ino.end + // ino.method.CharLiteral.25176.body + { + super(-1,-1); + // #JB# 20.04.2005 + // ########################################################### + this.setType(new CharacterType()); + //this.setType(new Type("char")); + // ########################################################### + } + // ino.end + + + + // ino.method.sc_check.25179.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25179.body + { + if(ext) + parserlog.debug(" ---CharLiteral---"); + } + // ino.end + + // ino.method.set_Char.25182.definition + public void set_Char( char c) + // ino.end + // ino.method.set_Char.25182.body + { + this.Char = c ; + } + // ino.end + + + + // ino.method.get_Name.25185.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25185.body + { + return null; + } + // ino.end + + + + // ino.method.codegen.25188.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25188.body + { + // Wert des chars auf den Stack laden + code.add_code(JVMCode.bipush); + code.add_code_byte((byte)Char); + + // Auto-Boxing des Typs in Character + code.add_code(JVMCode.invokestatic); + code.add_code_short(classfile.add_method_ref("java/lang/Character", "valueOf", "(C)Ljava/lang/Character;")); + } + // ino.end + + // ino.method.ConstantCodegen.25191.definition + public short ConstantCodegen(ClassFile classfile) + throws JVMCodeException + // ino.end + // ino.method.ConstantCodegen.25191.body + { + return (short) classfile.add_CONSTANT_Integer_info(Char); + } + // ino.end + + + // ino.method.TRStatement.25194.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25194.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + + // ino.method.TRExp.25197.defdescription type=javadoc + /** + * Workaround: �berschreibt Methode TRExp aus der Super-Klasse + * Literal, weil die Implementierung von Unify (noch) nicht mit + * Basetypes umgehen kann.
+ * Anstatt den Basetype CharacterType zur�ckzugeben, wird ein + * RefType zur�ckgegeben.
+ * Diese Methode kann sp�ter entfernt werden, sodass automatisch die Methode der + * Super-Klasse verwendet wird. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25197.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25197.body + { + CTripleSet tripleSet = new CTripleSet(); + tripleSet.addElement(new CTriple(sigma, new RefType("java.lang.Character",getOffset()),V)); + return tripleSet; + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25200.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25200.body + { + } + // ino.end + + + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("'"+String.valueOf(this.Char)+"'"); + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/DoubleLiteral.java b/src/mycompiler/mystatement/DoubleLiteral.java new file mode 100755 index 000000000..89cafba0e --- /dev/null +++ b/src/mycompiler/mystatement/DoubleLiteral.java @@ -0,0 +1,217 @@ +// ino.module.IntLiteral.8635.package +package mycompiler.mystatement; +// ino.end +// ino.module.IntLiteral.8635.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.DoubleType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.IntegerType; +import mycompiler.mytype.LongType; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +// ino.end +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.IntLiteral.25447.declaration +public class DoubleLiteral extends Literal +// ino.end +// ino.class.IntLiteral.25447.body +{ + // ino.attribute.Int.25451.declaration + private double Double; + // ino.end + // ino.attribute.parserlog.25454.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.IntLiteral.25457.definition + public DoubleLiteral() + // ino.end + // ino.method.IntLiteral.25457.body + { + super(-1,-1); + + this.setType(new DoubleType()); + + } + // ino.end + + // ino.method.set_Int.25460.definition + public void set_Double(double i) + // ino.end + // ino.method.set_Int.25460.body + { + this.Double = i; + } + // ino.end + + // ino.method.get_Int.25463.definition + public double get_Double() + // ino.end + // ino.method.get_Int.25463.body + { + return Double; + } + // ino.end + + // ino.method.sc_check.25466.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25466.body + { + parserlog.debug("SC -> Semantik-Check f�r DoubleLiteral wurde aufgerufen --> nichts zu tun!"); + } + // ino.end + + // ino.method.get_Name.25469.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25469.body + { + return null; + } + // ino.end + + // ino.method.codegen.25472.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end +// ino.method.codegen.25472.body +{ + /*if (Int >= 0 && Int <= 5) // Kleine Werte lassen sich direkt realisieren + code.add_code(JVMCode.nconst_n("int", Int)); + else if (Int >= -128 && Int <= 127) { // Aenderung des Codes fuer etwas groessere Werte + code.add_code(JVMCode.bipush); + code.add_code_byte((byte) Int); + } else if (Int >= -32768 && Int <= 32767) { // Aenderung des Codes fuer groessere Werte + code.add_code(JVMCode.sipush); + code.add_code_short((short) Int); + } else { // Ablage als Konstante + int index = classfile.add_CONSTANT_Integer_info(Int); + if (index < 256) { + code.add_code(JVMCode.ldc); + code.add_code_byte((byte) index); + } else { + code.add_code(JVMCode.ldc_w); + code.add_code_short((short) index); + } + } + + // Auto-Boxing: Da int nicht so nicht weiterverwendet werden kann, + // in Integer umwandeln. + if (!getPrimitiveFlag()) { + code.add_code(JVMCode.invokestatic); + code.add_code_short(classfile.add_method_ref("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;")); + }*/ + throw new JVMCodeException("Bytecode nicht implementiert"); + } +// ino.end + + // ino.method.ConstantCodegen.25475.definition + public short ConstantCodegen(ClassFile classfile) + throws JVMCodeException + // ino.end + // ino.method.ConstantCodegen.25475.body + { + //return (short) classfile.add_CONSTANT_Integer_info(get_Int()); + throw new JVMCodeException("Bytecode nicht implementiert"); + } + // ino.end + + + // ino.method.TRStatement.25478.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25478.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.TRExp.25481.defdescription type=javadoc + /** + * Workaround: �berschreibt Methode TRExp aus der Super-Klasse + * Literal, weil die Implementierung von Unify (noch) nicht mit + * Basetypes umgehen kann.
+ * Anstatt den Basetype IntegerType zur�ckzugeben, wird ein + * RefType zur�ckgegeben.
+ * Diese Methode kann sp�ter entfernt werden, sodass automatisch die Methode der + * Super-Klasse verwendet wird. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25481.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25481.body + { + CTripleSet tripleSet = new CTripleSet(); + tripleSet.addElement(new CTriple(sigma, new RefType("java.lang.Double",getOffset()),V)); + return tripleSet; + } + // ino.end + + // ino.method.toString.25484.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25484.definition + public String toString() + // ino.end + // ino.method.toString.25484.body + { + return type.toString() + " " + Double; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25487.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25487.body + { + } + // ino.end + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/EmptyStmt.java b/src/mycompiler/mystatement/EmptyStmt.java new file mode 100755 index 000000000..74acda805 --- /dev/null +++ b/src/mycompiler/mystatement/EmptyStmt.java @@ -0,0 +1,113 @@ +// ino.module.EmptyStmt.8629.package +package mycompiler.mystatement; +// ino.end +// ino.module.EmptyStmt.8629.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.EmptyStmt.25203.declaration +public class EmptyStmt extends Statement +// ino.end +// ino.class.EmptyStmt.25203.body +{ + // ino.method.EmptyStmt.25207.definition + public EmptyStmt() + // ino.end + // ino.method.EmptyStmt.25207.body + { + super(-1,-1); + } + // ino.end + + // ino.attribute.parserlog.25210.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + // ino.method.sc_check.25213.definition + public void sc_check(Vector classlist, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25213.body + { + if(ext){ + parserlog.debug(" ---EmptyStmt---"); + } + } + // ino.end + + // ino.method.codegen.25216.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25216.body + { } + // ino.end + + // ino.method.TRStatement.25219.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25219.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25222.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25222.body + { + } + // ino.end + + public boolean addOffsetsToStatement(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + return true; + } + + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + public void replaceType(CReplaceTypeEvent e) { + // TODO Auto-generated method stub + throw new NotImplementedException(); + } + + + + public int getTypeLineNumber() { + throw new NotImplementedException(); + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult(""); + } +} +// ino.end diff --git a/src/mycompiler/mystatement/Expr.java b/src/mycompiler/mystatement/Expr.java new file mode 100755 index 000000000..3ddea1727 --- /dev/null +++ b/src/mycompiler/mystatement/Expr.java @@ -0,0 +1,245 @@ +// ino.module.Expr.8630.package +package mycompiler.mystatement; +// ino.end +// ino.module.Expr.8630.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.ConstraintsSet; +import typinferenz.TypeAssumptions; +import mycompiler.myclass.Class; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CMultiplyTuple; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CMultiplyTupleSet; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +// ino.end + + + + +// ino.class.Expr.25225.declaration +public abstract class Expr extends ExprStmt +// ino.end +// ino.class.Expr.25225.body +{ + // ino.method.Expr.25229.definition + public Expr(int offset, int variableLength) + // ino.end + // ino.method.Expr.25229.body + { + super(offset, variableLength); + } + // ino.end + + // ino.attribute.usedid.25232.declaration + public UsedId usedid; //String type; ab sofort in die Klasse ExprStmt verlegt. last1 17.03.02 + // ino.end + + // ino.method.set_Type.25235.definition + public void set_Type(Type type) + // ino.end + // ino.method.set_Type.25235.body + { + this.setType(type); + } + // ino.end + + // ino.method.set_UsedId.25238.definition + public void set_UsedId(UsedId ui) + // ino.end + // ino.method.set_UsedId.25238.body + { + this.usedid = ui; + } + // ino.end + + // ino.method.get_UsedId.25241.definition + public UsedId get_UsedId() + // ino.end + // ino.method.get_UsedId.25241.body + { + return usedid; + } + // ino.end + + // ino.method.get_Name_Vector.25244.definition + public Vector get_Name_Vector() + // ino.end + // ino.method.get_Name_Vector.25244.body + { + return usedid.get_Name(); + } + // ino.end + + + + // ino.method.get_Type_Vector.25247.definition + public Vector get_Type_Vector() + // ino.end + // ino.method.get_Type_Vector.25247.body + { + return usedid.get_Typen(); + } + // ino.end + + + + // ino.method.sc_check.25250.declaration + public abstract void sc_check(Vector classname, Hashtable ch, Hashtable bh ,boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException; + // ino.end + + + + // ino.method.get_Name.25253.declaration + public abstract String get_Name(); + // ino.end + + // ino.method.TRExp.25256.declaration + public abstract CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + throws CTypeReconstructionException; + // ino.end + + /** + * @author AI10023 - Andreas Stadelmeier + * Implementierung des Java 8 - Typinferenzalgorithmus von Martin Plümicke + * Jede Expression wird im Zuge des Algorithmus durch die TYPEExpr-Funktion angesprochen. + */ + public abstract ConstraintsSet TYPEExpr(TypeAssumptions assumptions); + + /** + * @author AI10023 - Andreas Stadelmeier + * Die Funktion überschreiben, damit sie von Expressions nicht mehr spezifiziert werden muss. + * Denn Expressions müssen diese Funktion nicht implementieren. + */ + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){ + throw new NotImplementedException(); //wird die TYPEStmt-Methode innerhalb einer Expr aufgerufen, dann ist etwas schief gelaufen. + } + + // ino.method.TRTuple.25259.defdescription type=javadoc + /** + * (siehe Algorithmus 5.28 TRTuple, Martin Pl�micke) + *
Author: J�rg B�uerle + * @param result + * @param terms + * @param supportData + * @return + */ + // ino.end + // ino.method.TRTuple.25259.definition + public CMultiplyTupleSet TRTuple(CMultiplyTuple result, Vector terms, CSupportData supportData) + // ino.end + // ino.method.TRTuple.25259.body + { + if(terms.size()==0){ + throw new CTypeReconstructionException("Unify.TRTuple(): Vector \"terms\" ist leer.",this); + } + CMultiplyTupleSet results = this.TRMultiply(result, terms.firstElement(), supportData); + // -------------------------- + // Rekursionsanker erreicht: + // -------------------------- + if(terms.size()==1){ + return results; + } + // -------------------------- + // Rekursiv absteigen: + // -------------------------- + else { + CMultiplyTupleSet returnSet = new CMultiplyTupleSet(); + Iterator tupleIt = results.getIterator(); + + // PL 05-08-21 vorgezogen, da es sonst bei jedem Iterationsschritt + //der unterschiedlichen Moeglichkeiten der Typisierung geloescht wird. + terms.removeElementAt(0); + + while(tupleIt.hasNext()){ + //terms.removeElementAt(0); + returnSet.unite(this.TRTuple(tupleIt.next(), terms, supportData)); + } + return returnSet; + } + } + // ino.end + + // ino.method.TRMultiply.25262.defdescription type=javadoc + /** + * (siehe Algorithmus 5.29 TRMultiply, Martin Pl�micke) + *
Author: J�rg B�uerle + * @param tuple + * @param t + * @param supportData + * @return + */ + // ino.end + // ino.method.TRMultiply.25262.definition + public CMultiplyTupleSet TRMultiply(CMultiplyTuple tuple, Expr t, CSupportData supportData) + // ino.end + // ino.method.TRMultiply.25262.body + { + // -------------------------- + // TRExp des Terms rufen: + // -------------------------- + CTripleSet results = t.TRExp(tuple.getSubstitutions(), tuple.getAssumptionSet(), supportData); + // -------------------------- + // Alle zur�ckgelieferten Triple durchgehen: + // -------------------------- + CMultiplyTupleSet returnSet = new CMultiplyTupleSet(); + Iterator tripleIt = results.getIterator(); + while(tripleIt.hasNext()){ + CTriple triple = tripleIt.next(); + // -------------------------- + // Ergebnis-MultiplyTuple bauen: + // -------------------------- + CMultiplyTuple retTuple =tuple.clone(); + retTuple.setSubstitutions(triple.getSubstitutions()); + retTuple.setAssumptionSet(triple.getAssumptionSet()); + // -------------------------- + // Substitutionen auf ReturnTypes anwenden: + // -------------------------- + for(int i=0; i pairIt = retTuple.getSubstitutions().getIterator(); + while(pairIt.hasNext()){ + CSubstitution pair = pairIt.next(); + // -------------------------- + // Falls Match, dann ReturnType ersetzen: + // -------------------------- + if(pair.getTypeVar().getName().equals(type.getName())){ + retTuple.getResultTypes().setElementAt(pair.getType(), i); + } + } + } + } + retTuple.getResultTypes().addElement(triple.getResultType()); + // -------------------------- + // Tuple zur Ergebnismenge hinzuf�gen: + // -------------------------- + returnSet.addElement(retTuple); + } + return returnSet; + } + // ino.end + + public abstract void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable); + + public boolean addOffsetsToStatement(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + return true; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/ExprStmt.java b/src/mycompiler/mystatement/ExprStmt.java new file mode 100755 index 000000000..147d75b7c --- /dev/null +++ b/src/mycompiler/mystatement/ExprStmt.java @@ -0,0 +1,161 @@ +// ino.module.ExprStmt.8631.package +package mycompiler.mystatement; +// ino.end + +// ino.module.ExprStmt.8631.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.MyCompiler; +import mycompiler.mytype.Pair; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.ExprStmt.25265.declaration +public abstract class ExprStmt extends Statement implements ITypeReplacementListener +// ino.end +// ino.class.ExprStmt.25265.body +{ + // ino.method.ExprStmt.25270.definition + public ExprStmt(int offset, int variableLength) + // ino.end + // ino.method.ExprStmt.25270.body + { + super(offset,variableLength); + } + // ino.end + + + // ino.attribute.type.25273.declaration + //protected Type type; // Type type; + // ino.end + // ino.attribute.inferencelog.25276.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + + // ino.method.getTypeName.25279.definition + public String getTypeName() + // ino.end + // ino.method.getTypeName.25279.body + { + if (getTypeVariable()!=null) + return getTypeVariable().getName(); + else + return null; + } + // ino.end + + // ino.method.getType.25282.definition + public Type getType() + // ino.end + // ino.method.getType.25282.body + { + return getTypeVariable(); + } + // ino.end + + + + // ino.method.getTypeLineNumber.25291.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.getTypeLineNumber.25291.definition + public int getTypeLineNumber() + // ino.end + // ino.method.getTypeLineNumber.25291.body + { + return MyCompiler.NO_LINENUMBER; + } + // ino.end + + // ino.method.unifyAndRegisterType.25294.definition + CTripleSet unifyAndRegisterType(CTripleSet ret, CSupportData supportData) + // ino.end + // ino.method.unifyAndRegisterType.25294.body + { + CTripleSet returnSet = new CTripleSet(); + Iterator retIt = ret.getIterator(); + while(retIt.hasNext()){ + CTriple retTriple = (CTriple)retIt.next(); + // -------------------------- + // ReturnType mit type von this unifizieren: + // -------------------------- + Vector> unifierPossibilities = Unify.unify(retTriple.getResultType(), this.getType(), supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann + // anwenden und Triple hinzuf�gen: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + for(int j=0; j tlvRestype = new Vector(); + tlvRestype.addElement(new Pair(this.getType(), retTriple.getResultType())); + CSubstitutionSet unifier2 = new CSubstitutionSet(tlvRestype); + // -------------------------- + // Unifier zu retTriple hinzufuegen + // -------------------------- + CTriple intTriple2 = retTriple.cloneAndApplyUnify(unifier2); + //intTriple2.setResultType(unifier2.applyThisSubstitutionSet(this.getType())); + // -------------------------- + // Triple zu R�ckgabemenge hinzuf�gen + // -------------------------- + returnSet.addElement(intTriple2); + } + else {//Typ war vorher schon explizit definiert + if (this.getType().equals(retTriple.getResultType())) { + returnSet.addElement(retTriple); + } + } + } + return returnSet; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mystatement/FloatLiteral.java b/src/mycompiler/mystatement/FloatLiteral.java new file mode 100755 index 000000000..cd1904fcb --- /dev/null +++ b/src/mycompiler/mystatement/FloatLiteral.java @@ -0,0 +1,212 @@ +// ino.module.IntLiteral.8635.package +package mycompiler.mystatement; +// ino.end +// ino.module.IntLiteral.8635.import +import java.util.Hashtable; +import java.util.Vector; + +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.FloatType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; + +import org.apache.log4j.Logger; + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.IntLiteral.25447.declaration +public class FloatLiteral extends Literal +// ino.end +// ino.class.IntLiteral.25447.body +{ + // ino.attribute.Int.25451.declaration + private float Float; + // ino.end + // ino.attribute.parserlog.25454.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.IntLiteral.25457.definition + public FloatLiteral() + // ino.end + // ino.method.IntLiteral.25457.body + { + super(-1,-1); + + this.setType(new FloatType()); + + } + // ino.end + + // ino.method.set_Int.25460.definition + public void set_Float(float i) + // ino.end + // ino.method.set_Int.25460.body + { + this.Float = i; + } + // ino.end + + // ino.method.get_Int.25463.definition + public float get_Float() + // ino.end + // ino.method.get_Int.25463.body + { + return Float; + } + // ino.end + + // ino.method.sc_check.25466.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25466.body + { + parserlog.debug("SC -> Semantik-Check f�r FloatLiteral wurde aufgerufen --> nichts zu tun!"); + } + // ino.end + + // ino.method.get_Name.25469.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25469.body + { + return null; + } + // ino.end + + // ino.method.codegen.25472.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end +// ino.method.codegen.25472.body +{ + /*if (Int >= 0 && Int <= 5) // Kleine Werte lassen sich direkt realisieren + code.add_code(JVMCode.nconst_n("int", Int)); + else if (Int >= -128 && Int <= 127) { // Aenderung des Codes fuer etwas groessere Werte + code.add_code(JVMCode.bipush); + code.add_code_byte((byte) Int); + } else if (Int >= -32768 && Int <= 32767) { // Aenderung des Codes fuer groessere Werte + code.add_code(JVMCode.sipush); + code.add_code_short((short) Int); + } else { // Ablage als Konstante + int index = classfile.add_CONSTANT_Integer_info(Int); + if (index < 256) { + code.add_code(JVMCode.ldc); + code.add_code_byte((byte) index); + } else { + code.add_code(JVMCode.ldc_w); + code.add_code_short((short) index); + } + } + + // Auto-Boxing: Da int nicht so nicht weiterverwendet werden kann, + // in Integer umwandeln. + if (!getPrimitiveFlag()) { + code.add_code(JVMCode.invokestatic); + code.add_code_short(classfile.add_method_ref("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;")); + }*/ + throw new JVMCodeException("Bytecode nicht implementiert"); + } +// ino.end + + // ino.method.ConstantCodegen.25475.definition + public short ConstantCodegen(ClassFile classfile) + throws JVMCodeException + // ino.end + // ino.method.ConstantCodegen.25475.body + { + //return (short) classfile.add_CONSTANT_Integer_info(get_Int()); + throw new JVMCodeException("Bytecode nicht implementiert"); + } + // ino.end + + + // ino.method.TRStatement.25478.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25478.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.TRExp.25481.defdescription type=javadoc + /** + * Workaround: �berschreibt Methode TRExp aus der Super-Klasse + * Literal, weil die Implementierung von Unify (noch) nicht mit + * Basetypes umgehen kann.
+ * Anstatt den Basetype IntegerType zur�ckzugeben, wird ein + * RefType zur�ckgegeben.
+ * Diese Methode kann sp�ter entfernt werden, sodass automatisch die Methode der + * Super-Klasse verwendet wird. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25481.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25481.body + { + CTripleSet tripleSet = new CTripleSet(); + tripleSet.addElement(new CTriple(sigma, new RefType("java.lang.Float",getOffset()),V)); + return tripleSet; + } + // ino.end + + // ino.method.toString.25484.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25484.definition + public String toString() + // ino.end + // ino.method.toString.25484.body + { + return type.toString() + " " + Float; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25487.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25487.body + { + } + // ino.end + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/ForStmt.java b/src/mycompiler/mystatement/ForStmt.java new file mode 100755 index 000000000..438ce4418 --- /dev/null +++ b/src/mycompiler/mystatement/ForStmt.java @@ -0,0 +1,310 @@ + +package mycompiler.mystatement; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.myoperator.LogOp; +import mycompiler.myoperator.Operator; +import mycompiler.myoperator.RelOp; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + + + +public class ForStmt extends Statement +{ + + private Expr head_Initializer_1; + private Expr head_Condition_1; + private Expr head_Loop_expr_1; + private Expr head_Initializer; + private Expr head_Condition; + private Expr head_Loop_expr; + private Statement body_Loop_block; + + public ForStmt(int offset, int variableLength) + { + super(offset,variableLength); + } + + void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + { + + } + + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + { + + } + + /** + * Implementierung des Algorithmus 5.23 von Martin Pl�micke + *
Achtung Workaround: RefType "Boolean" muss noch durch BaseType + * "BooleanType" ersetzt werden. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + { + CTripleSet start_set = new CTripleSet(); + + CTripleSet init_set = new CTripleSet(); + + CTripleSet cond_set = new CTripleSet(); + + CTripleSet return_set = new CTripleSet(); + + //Expressions kopieren für die Typrekonstruktion um Codegen nicht zu tangieren + head_Initializer_1 = head_Initializer; + head_Condition_1 = head_Condition; + head_Loop_expr_1 = head_Loop_expr; + + //Fälle überprüfen, in denen nicht alle drei Expressions im Schleifenkopf existieren + + //Überprüfen, ob eine Expression existiert und diese in ersatz speichern + boolean condition_exists = true; + Expr ersatz = null; + if(head_Initializer_1 == null){ + if(head_Condition_1 == null){ + condition_exists = false; + if(head_Loop_expr_1 == null){ + //Falls keine Expression existiert, nur TRStatement mit Loop-Block + return_set = body_Loop_block.TRStatement(sigma, V,supportData); + return return_set; + } + else ersatz = head_Loop_expr_1; + } + else ersatz = head_Condition_1; + } + else ersatz = head_Initializer_1; + + //Falls mindestens eine Expression existiert, werden die leeren mit ersatz überschrieben + if(ersatz != null){ + if(head_Initializer_1 == null) head_Initializer_1 = ersatz; + if(head_Condition_1 == null) head_Condition_1 = ersatz; + if(head_Loop_expr_1 == null) head_Loop_expr_1 = ersatz; + } + + //Folgender Code wird ausgeführt, wenn mindestens eine Expression existiert + start_set = head_Initializer_1.TRExp(sigma,V,supportData); + Iterator it_init = start_set.getIterator(); + + //-------------------------- + // Initializer-Typ rekonstruieren: + // -------------------------- + int successfulls1 = 0; + Vector exceptions1 = new Vector(); + + while( it_init.hasNext() ) { +// CTriple initTriple = it_init.next(); +// init_set.unite(head_Condition_1.TRExp(initTriple.getSubstitutions(), initTriple.getAssumptionSet(),supportData)); +// //init_set = head_Condition_1.TRExp(initTriple.getSubstitutions(), initTriple.getAssumptionSet(),supportData); +// Type r = initTriple.getResultType(); + + try{ + CTriple initTriple = it_init.next(); + CTripleSet condit = head_Condition_1.TRExp(initTriple.getSubstitutions(), initTriple.getAssumptionSet (),supportData); + init_set.unite( condit ); + //init_set = head_Condition_1.TRExp(initTriple.getSubstitutions(), initTriple.getAssumptionSet(),supportData); + Type r = initTriple.getResultType (); + successfulls1++; + } catch (CTypeReconstructionException tre) { + exceptions1.addElement(tre); + } + } + + if (successfulls1 == 0) { + if (exceptions1.size() == 1) { + throw exceptions1.elementAt(0); + } + throw new CTypeReconstructionException( + "ForStmt: Es konnte keine Assumption gefunden werden, die auf die Anforderung passt.", + exceptions1, this); + } + + Iterator it_cond = init_set.getIterator(); + + while(it_cond.hasNext()){ + CTriple condTriple = it_cond.next(); + + //Wird ausgeführt, falls die Condition existiert + if(condition_exists == true){ + // -------------------------- + // Rückgabe der Condition mit Boolean unifizieren: + // -------------------------- + Vector> cond_poss = Unify.unify(condTriple.getResultType(), new RefType("java.lang.Boolean",getOffset()), supportData.getFiniteClosure()); + // System.out.println("cond_set:"+cond_set.toString()); + // System.out.println("condTriple:"+condTriple.toString()); + if (cond_poss.size() != 0) { + // -------------------------- + // Alle möglichen Unifier anwenden: + // -------------------------- + + int successfulls = 0; + Vector exceptions = new Vector(); + + for (int i = 0; i < cond_poss.size(); i++) { + + // -------------------------- + // Condition-Typ rekonstruieren: + // -------------------------- + try { + + CSubstitutionSet unifier = new CSubstitutionSet(cond_poss.elementAt(i)); + CTriple boolTriple = condTriple.cloneAndApplyUnify(unifier); + cond_set.unite(head_Loop_expr_1.TRExp(boolTriple.getSubstitutions(), + boolTriple.getAssumptionSet(), supportData)); + + successfulls++; + } catch (CTypeReconstructionException tre) { + exceptions.addElement(tre); + } + + if (successfulls == 0) { + if (exceptions.size() == 1) { + throw exceptions.elementAt(0); + } + throw new CTypeReconstructionException( + "ForStmt: Es konnte keine Assumption gefunden werden, die auf die Anforderung passt.", + exceptions, this); + } + + } + } else { + throw new CTypeReconstructionException("ForStmt.TRStatement(): Bedingung muss boolean sein!",this); + } + } + //Wird ausgeführt, falls keine Condition existiert + else{ + int successfulls2 = 0; + Vector exceptions2 = new Vector(); + try{ + CTripleSet condit = head_Loop_expr_1.TRExp(condTriple.getSubstitutions(), condTriple.getAssumptionSet (),supportData); + cond_set.unite( condit ); + successfulls2++; + } catch (CTypeReconstructionException tre) { + exceptions2.addElement(tre); + } + + if (successfulls2 == 0) { + if (exceptions2.size() == 1) { + throw exceptions2.elementAt(0); + } + throw new CTypeReconstructionException( + "ForStmt: Es konnte keine Assumption gefunden werden, die auf die Anforderung passt.", + exceptions2, this); + } + } + } + + Iterator it_loop_block = cond_set.getIterator(); + + // -------------------------- + // Loop-Expression-Typ rekonstruieren: + // -------------------------- + while( it_loop_block.hasNext() ) { + CTriple loop_blockTriple = it_loop_block.next(); + + return_set.unite(body_Loop_block.TRStatement(loop_blockTriple.getSubstitutions(), loop_blockTriple.getAssumptionSet(),supportData)); + + } + + return return_set; + } + + public String toString() + { + return "FOR "; + } + + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + { + if(body_Loop_block!=null){ + body_Loop_block.wandleRefTypeAttributes2GenericAttributes(paralist,genericMethodParameters); + } + + } + + public void set_head_Initializer(Expr expr) { + head_Initializer = expr; + + } + + public void set_head_Condition(Expr expr) { + head_Condition = expr; + + } + + public void set_head_Loop_expr(Expr expr) { + head_Loop_expr = expr; + + } + + public void set_body_Loop_block(Statement statement) { + body_Loop_block = statement; + + } + + public boolean addOffsetsToStatement(CTypeAssumption localAssumption, String NameVariable, boolean isMemberVariable) + { + head_Initializer_1.addOffsetsToStatement(localAssumption,NameVariable,isMemberVariable); + body_Loop_block.addOffsetsToStatement(localAssumption,NameVariable,isMemberVariable); + return true; + } + + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + public void replaceType(CReplaceTypeEvent e) { + // TODO Auto-generated method stub + throw new NotImplementedException(); + } + + public int getTypeLineNumber() { + throw new NotImplementedException(); + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/mycompiler/mystatement/IfStmt.java b/src/mycompiler/mystatement/IfStmt.java new file mode 100755 index 000000000..375467670 --- /dev/null +++ b/src/mycompiler/mystatement/IfStmt.java @@ -0,0 +1,625 @@ +// ino.module.IfStmt.8632.package +package mycompiler.mystatement; +// ino.end +// ino.module.IfStmt.8632.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.myoperator.LogOp; +import mycompiler.myoperator.Operator; +import mycompiler.myoperator.RelOp; +import mycompiler.mytype.BooleanType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.MUB; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.JavaCodeResult; +import typinferenz.SingleConstraint; +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.IfStmt.25300.declaration +public class IfStmt extends Statement +// ino.end +// ino.class.IfStmt.25300.body +{ + // ino.method.IfStmt.25304.definition + public IfStmt(int offset, int variableLength) + // ino.end + // ino.method.IfStmt.25304.body + { + super(offset,variableLength); + } + // ino.end + + // ino.attribute.hamaDebug.25307.declaration + public boolean hamaDebug = true; //hama: Debug Ausgaben von mir ein- bzw. ausschalten + // ino.end + // ino.attribute.expr.25310.declaration + public Expr expr; + // ino.end + // ino.attribute.then_block.25313.declaration + public Statement then_block; + // ino.end + // ino.attribute.else_block.25316.declaration + public Statement else_block; + // ino.end + // ino.attribute.parserlog.25319.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + + // ino.method.set_Expr.25322.definition + public void set_Expr(Expr exp) + // ino.end + // ino.method.set_Expr.25322.body + { + this.expr = exp; + } + // ino.end + + + + // ino.method.set_Then_block.25325.definition + public void set_Then_block(Statement blk) + // ino.end + // ino.method.set_Then_block.25325.body + { + this.then_block = blk; + } + // ino.end + + + + // ino.method.set_Else_block.25328.definition + public void set_Else_block(Statement blk) + // ino.end + // ino.method.set_Else_block.25328.body + { + this.else_block = blk; + } + // ino.end + + + + // ino.method.sc_check.25331.definition + void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25331.body + { + if(ext) + { + parserlog.debug(" ---IfStmt---"); + } + SCStatementException exc = null; + try + { + expr.sc_check(classname,ch,bh,ext,parach, parabh); + } + catch(SCStatementException ex) + { + exc = ex; + } + try + { + then_block.sc_check(classname,ch,(Hashtable) bh.clone(), ext, parach, (Hashtable)parabh.clone()); + } + catch(SCStatementException ex) + { + if(exc == null) + { + exc = ex; + } + else + { + Vector v=ex.get_exlist(); + SCExcept hilfe; + for(Enumeration el = v.elements() ; el.hasMoreElements() ; ) + { + hilfe=el.nextElement(); + exc.addException(hilfe); + } + } + } + if(else_block != null) + { + try + { + else_block.sc_check(classname,ch,(Hashtable) bh.clone(), ext, parach, (Hashtable)parabh.clone()); + } + catch(SCStatementException ex) + { + if(exc == null) + { + exc=ex; + } + else + { + Vector v=ex.get_exlist(); + SCExcept hilfe; + for(Enumeration el=v.elements() ; el.hasMoreElements() ; ) + { + hilfe=el.nextElement(); + exc.addException(hilfe); + } + } + } + } + if(exc != null) + { + throw exc; + } + } + // ino.end + + + + // ino.method.codegen.25334.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25334.body + { + if_codegen(classfile, code, false, paralist); + } + // ino.end + + + + // ino.method.if_codegen.25337.definition + public void if_codegen(ClassFile classfile, CodeAttribute code, boolean not, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.if_codegen.25337.body + { + if(expr instanceof NotExpr) + { + expr = ((NotExpr)expr).get_Expr(); + if_codegen(classfile, code, !not, paralist); + } + else + { + if(expr instanceof Binary) + { + Operator op = ((Binary)expr).get_Operator(); + if(op instanceof LogOp) + { + ((LogOp)op).if_codegen(classfile, code, not, expr, then_block, else_block, paralist); + } + else + { + if(op instanceof RelOp) + { + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + expr1.codegen(classfile, code, paralist); + expr2.codegen(classfile, code, paralist); + if(expr1 instanceof Null || expr2 instanceof Null) + { + ((RelOp)op).if_codegen(classfile, code, "null", not); + } + else + { + ((RelOp)op).if_codegen(classfile, code, expr1.getTypeName(), not); + } + int breakpoint1 = code.get_code_length(); + code.add_code_short(0); + if(then_block!=null) + { + then_block.codegen(classfile, code, paralist); + code.set_code_short(code.get_code_length() + 1 - breakpoint1, breakpoint1); + } + int breakpoint2 = code.get_code_length(); + if(else_block != null) + { + code.add_code(JVMCode.goto_); + code.add_code_short(0); // replaced later + else_block.codegen(classfile, code, paralist); + code.set_code_short(breakpoint2 + 4 - breakpoint1, breakpoint1); + code.set_code_short(code.get_code_length() - breakpoint2, breakpoint2 + 1); + } + } + else + { + throw new JVMCodeException("JVMCodeException: IfStmt: void if_codegen(ClassFile classfile, Code_attribute code, boolean not)"); + } + } + } + else + { + expr.codegen(classfile, code, paralist); + if(!not) + { + code.add_code(JVMCode.ifeq); + } + else + { + code.add_code(JVMCode.ifne); + } + int breakpoint1 = code.get_code_length(); + code.add_code_short(0); + if(then_block!=null) + { + then_block.codegen(classfile, code, paralist); + code.set_code_short(code.get_code_length() + 1 - breakpoint1, breakpoint1); + } + int breakpoint2 = code.get_code_length(); + if(!(else_block==null || else_block instanceof EmptyStmt)) + { + //hama: Die zwei folgenen if-Abfragen wurden eingef�gt und beheben den Bug, + //der zuerst im Use Case Toggle1 bemerkt wurde. Hier wird nun gepr�ft ob der + //letzte Befehl in einem if-Block ein return war. Trifft dieser Fall zu, + //so wird kein goto Befehl (f�r das �berspringen des else-Blocks eingef�gt) + //-> das verlangt die vm ->der code w�re nicht erreichbar. + //Allerdings k�nnte das return-Statement nat�rlich auch an einer anderen + //Stelle (nicht als letzter Befehl) stehen, f�r diesen Fall d�rfte die + //Codegenerierung noch nicht funktionieren. Hab versucht diesen Fall mit + //Toggle3 zu erzeugen - wird aber richtig generiert. + //letztes Statement im Vector in s schreiben + //Statement s = (Statement)(((Block)this.then_block).statements.lastElement()); + //Instanz von Return zum pr�fen anlegen + Return r = new Return(getOffset(),getVariableLength()); + + if( !(((Block)this.then_block).statements.lastElement()).getClass().equals(r.getClass()) ) + { + code.add_code(JVMCode.goto_); + code.add_code_short(0); + } + else_block.codegen(classfile, code, paralist); + if( !(((Block)this.then_block).statements.lastElement()).getClass().equals(r.getClass()) ) + { + code.set_code_short(breakpoint2 + 4 - breakpoint1, breakpoint1); + code.set_code_short(code.get_code_length()-breakpoint2, breakpoint2 + 1); + } + } + } + } + } + // ino.end + + + + // ino.method.TRStatement.25340.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.21 von Martin Pl�micke + *
Achtung Workaround: RefType "Boolean" durch BaseType \code{BooleanType} + * ersetzen.
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRStatement.25340.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + throws CTypeReconstructionException + // ino.end +// ino.method.TRStatement.25340.body +{ + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // Bedingungsausdruck rekonstruieren: + // -------------------------- + CTripleSet exprTSet = this.expr.TRExp(sigma, V, supportData); + // -------------------------- + // Bedingungs-Triple durchgehen: + // -------------------------- + Iterator exprTIt = exprTSet.getIterator(); + while(exprTIt.hasNext()){ + CTriple exprTriple = exprTIt.next(); + // -------------------------- + // ReturnType mit Boolean unifizieren: + // -------------------------- + + // Sollte doch mit "boolean" statt "Boolean" unifiziert werden? + // Vector> unifierPossibilities1 = Unify.unify(exprTriple.getResultType(), new BooleanType()/*new RefType("Boolean")*/, supportData.getFiniteClosure()); + + Vector> unifierPossibilities1 = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Boolean",getOffset()), supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann anwenden: + // -------------------------- + if(unifierPossibilities1.size()!=0){ + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + + Vector exceptions=new Vector(); + int successfulls=0; + + for(int i=0; i thenTIt = thenTSet.getIterator(); + while(thenTIt.hasNext()){ + CTriple thenTriple = thenTIt.next(); + // -------------------------- + // Else-Zweig rekonstruieren: + // -------------------------- + if(this.else_block==null){ + returnSet.addElement(thenTriple); + continue; + } + CTripleSet elseTSet = this.else_block.TRStatement(thenTriple.getSubstitutions(), thenTriple.getAssumptionSet(), supportData); + // -------------------------- + // ReturnType �berpr�fen: + // -------------------------- + //boolean isElseBlockVoid = false; + if(elseTSet.getCardinality()!=0){ + ///*isElseBlockVoid =*/ (((CTriple)elseTSet.getVector().firstElement()).getResultType() instanceof Void); + } + // -------------------------- + // Else-Triples durchgehen: + // -------------------------- + Iterator elseTIt = elseTSet.getIterator(); + while(elseTIt.hasNext()){ + CTriple elseTriple = elseTIt.next(); + // -------------------------- + // Wenn Void, Typannahmen zur�ckliefern: + // -------------------------- + if(isThenBlockVoid){ + /* + Urspr�nglich nach Pl�micke: + if(isElseBlockVoid){ + returnSet.addElement(new CTriple(elseTriple.getSubstitutions(), elseTriple.getResultType(), elseTriple.getAssumptionSet())); + } + else { + throw new CTypeReconstructionException("IfStmt.TRStatement(): Typen nicht vereinbar - Then-Zweig hat ReturnType, Else-Zweig ist Void"); + } */ // Korrekt aber so: + returnSet.addElement(new CTriple(elseTriple.getSubstitutions(), elseTriple.getResultType(), elseTriple.getAssumptionSet())); + } + // --------------------------+ + // Ansonsten ReturnTypes-unifizieren: + // -------------------------- + else { + // -------------------------- + // MUB berechen + // -------------------------- + MUB mub = Unify.unify_Mub(thenTriple.getResultType(), elseTriple.getResultType(), supportData.getFiniteClosure()); + // -------------------------- + // Unifier anwenden: + // -------------------------- + this.makeNewResult(mub, elseTriple, elseTriple.getAssumptionSet(), returnSet); + } + } + } + successfulls++; + }catch(CTypeReconstructionException tre){ + exceptions.addElement(tre); + } + } + if(successfulls==0){ + if(exceptions.size()==1){ + throw exceptions.elementAt(0); + } + throw new CTypeReconstructionException("IfStmt: Es konnte keine Assumption gefunden werden, die auf die Anforderung passt.",exceptions,this); + } + }else { + throw new CTypeReconstructionException("IfStmt.TRStatement(): Bedingung muss boolean sein!",this); + } + } + return returnSet; + } +// ino.end + + // ino.method.makeNewResult.25343.definition + private void makeNewResult(MUB Mub, CTriple triple, CTypeAssumptionSet V, CTripleSet returnSet) + throws CTypeReconstructionException + // ino.end + // ino.method.makeNewResult.25343.body + { + CSubstitutionSet unifier = new CSubstitutionSet(Mub.getUnifier()); + // -------------------------- + // Typannahmen bauen: + // -------------------------- + CTypeAssumptionSet V_substituted = V.deepCopy(); + V_substituted.sub(unifier); + // -------------------------- + // Substitutionen bauen: + // -------------------------- + CSubstitutionSet substSet = triple.getSubstitutions().deepCopy(); + substSet.applyUnifier(unifier); + substSet.unite(unifier); + // -------------------------- + // R�ckgabetyp bauen: + // -------------------------- + Iterator setMubIt = Mub.getMub().iterator(); + + while(setMubIt.hasNext()) { + Type retType = setMubIt.next(); + Type retType2 = substSet.applyThisSubstitutionSet(retType.clone()); + // Muesste eigentlich cloneAndApplyUnify machen PL 06-03-18 + // If(Rettype Instanceof TypePlaceholders){ + // Iterator Pairit = Unifier.Getiterator(); + // While(Pairit.Hasnext()){ + // Csubstitution Pair = Pairit.Next(); + // If(Pair.Gettypevar().Getname().Equals(Rettype.Getname())){ + // Rettype = Pair.Gettype(); + // Break; + // } + // } + // } + // -------------------------- + CTriple resultTriple = new CTriple(substSet, retType2, V_substituted); + //CSubstitutionSet CSubstUnifier = new CSubstitutionSet(unifier); + //CTriple resultTriple2 = retTriple.cloneAndApplyUnify(CSubstUnifier); + // -------------------------- + // Triple zu R�ckgabemenge hinzuf�gen + // -------------------------- + if(!returnSet.contains(resultTriple)){ + returnSet.addElement(resultTriple); + } + } + } + // ino.end + + + // ino.method.applyUnifier.25346.definition + private void applyUnifier(Vector> unifierPossibilities, CTriple triple, CTypeAssumptionSet V, CTripleSet returnSet) + throws CTypeReconstructionException + // ino.end + // ino.method.applyUnifier.25346.body + { + // -------------------------- + // Wenn Unifier vorhanden, dann anwenden: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Alle m�glichen Unifier auf V_i,j anwenden: + // -------------------------- + for(int k=0; k pairIt = unifier.getIterator(); + while(pairIt.hasNext()){ + CSubstitution pair = pairIt.next(); + if(pair.getTypeVar().getName().equals(retType.getName())){ + retType = pair.getType(); + break; + } + } + } + // -------------------------- + CTriple resultTriple = new CTriple(substSet, retType, V_substituted); + // -------------------------- + // Triple zu R�ckgabemenge hinzuf�gen + // -------------------------- + if(!returnSet.contains(resultTriple)){ + returnSet.addElement(resultTriple); + } + } + } + // -------------------------- + // Ansonsten Fehlermeldung: + // -------------------------- + else { + throw new CTypeReconstructionException("IfStmt.TRStatement(): Block-Typen lassen sich nicht unifizieren.",this); + } + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25349.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25349.body + { + if(then_block!=null){ + then_block.wandleRefTypeAttributes2GenericAttributes(paralist,genericMethodParameters); + } + if(else_block!=null){ + else_block.wandleRefTypeAttributes2GenericAttributes(paralist,genericMethodParameters); + } + + } + // ino.end + + public boolean addOffsetsToStatement(CTypeAssumption localAssumption, String NameVariable, boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + else_block.addOffsetsToStatement(localAssumption,NameVariable,isMemberVariable); + then_block.addOffsetsToStatement(localAssumption,NameVariable,isMemberVariable); + return true; + } + + + + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + this.setTypeVariable(TypePlaceholder.fresh(this)); + + ret.add(expr.TYPEExpr(assumptions)); // die Constraints für (expressionDesIfStmt) + ret.add(this.then_block.TYPEStmt(assumptions)); + if(else_block!=null){ + ret.add(this.else_block.TYPEStmt(assumptions)); + if(!(else_block.getTypeVariable() instanceof Void))ret.add(new SingleConstraint(else_block.getTypeVariable(),this.getTypeVariable())); + } + ret.add(new SingleConstraint(expr.getTypeVariable(),new RefType("boolean",0))); //(expressionDesIfStmt)<.boolean + if(!(then_block.getTypeVariable() instanceof Void))ret.add(new SingleConstraint(then_block.getTypeVariable(),this.getTypeVariable())); + if(then_block.getTypeVariable() instanceof Void && + (else_block == null || else_block.getTypeVariable() instanceof Void))this.setTypeVariable(new Void(this.getOffset())); + return ret; + } + + public void replaceType(CReplaceTypeEvent e) { + // TODO Auto-generated method stub + throw new NotImplementedException(); + } + + public int getTypeLineNumber() { + throw new NotImplementedException(); + } + + + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult("If(").attach(this.expr.printJavaCode(resultSet)).attach("){\n"); + if(this.then_block!=null)ret.attach(this.then_block.printJavaCode(resultSet)); + ret.attach("\n}else{\n"); + if(this.else_block!=null)ret.attach(this.else_block.printJavaCode(resultSet)); + ret.attach("\n}"); + return ret; + } +} +// ino.end diff --git a/src/mycompiler/mystatement/InstVar.java b/src/mycompiler/mystatement/InstVar.java new file mode 100755 index 000000000..c878a9160 --- /dev/null +++ b/src/mycompiler/mystatement/InstVar.java @@ -0,0 +1,376 @@ +// ino.module.InstVar.8634.package +package mycompiler.mystatement; +// ino.end +// ino.module.InstVar.8634.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.typeassumptionkey.CInstVarKey; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.InstVar.25392.declaration +public class InstVar extends Expr +// ino.end +// ino.class.InstVar.25392.body +{ + // ino.attribute.expr.25396.declaration + private Expr expr; + // ino.end + // ino.attribute.usedid.25399.declaration + private UsedId usedid; + // ino.end + // ino.attribute.type.25402.declaration + protected String type; //???? BRAUCHT MAN DEN??? + // ino.end + // ino.attribute.parserlog.25405.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.InstVar.25408.definition + public InstVar(Expr e, String n, int offset) + // ino.end + // ino.method.InstVar.25408.body + { + super(offset,n.length()); + expr = e; + usedid = new UsedId(getOffset()); + usedid.set_Name(n); + } + // ino.end + + // ino.method.InstVar.25411.definition + public InstVar(String n, String t, int offset) + // ino.end + // ino.method.InstVar.25411.body + { + super(offset,n.length()); + usedid = new UsedId(getOffset()); + usedid.set_Name(n); + type = t; + } + // ino.end + + // ino.method.InstVar.25414.defdescription type=javadoc + /** + * macht aus einem UsedId mit einem Vector von Strings eine InstVar + *
Author: Martin Pl�micke PL 05-08-17 + * @param ui + * @return + */ + // ino.end + // ino.method.InstVar.25414.definition + public InstVar(UsedId ui, int offset,int variableLength) + // ino.end + // ino.method.InstVar.25414.body + { + super(offset,variableLength); + Iterator namen = ui.get_Name().iterator(); + LocalOrFieldVar innerLOFV = new LocalOrFieldVar((String)namen.next(),getOffset()); + innerLOFV.setType(TypePlaceholder.fresh(this)); + InstVar INSTVA = new InstVar(innerLOFV, (String)namen.next(),offset); + INSTVA.setType(TypePlaceholder.fresh(this)); + while(namen.hasNext()) { + INSTVA = new InstVar(INSTVA, (String)namen.next(),offset); + INSTVA.setType(TypePlaceholder.fresh(this)); + } + expr = INSTVA.expr; + usedid = INSTVA.usedid; + } + // ino.end + + // ino.method.sc_check.25417.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25417.body + { + if(ext) + parserlog.debug(" ---InstVar---"); + Vector name = usedid.get_Name(); + + for(Enumeration el = name.elements(); el.hasMoreElements();) + { + String name1 = (String) el.nextElement(); + + if(bh.containsKey(name1)) + { + this.type = (String)bh.get(name1); //type wird von Expr geerbt + if(ext) + parserlog.debug("Variable " + name1 + " im Block gefunden."); + } + else if(ch.containsKey(name1)) + { + this.type = (String)ch.get(name1); + if(ext) + parserlog.debug("Variable " + name1 + " in Class gefunden."); + } + else + if(ext) + parserlog.debug("Typfehler: -->InstVar.sc_check() "+ name1); + } + } + // ino.end + + // ino.method.get_Name.25420.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25420.body + { + return null; + } + // ino.end + + // ino.method.get_codegen_UsedId.25423.definition + public String get_codegen_UsedId() + // ino.end + // ino.method.get_codegen_UsedId.25423.body + { return usedid.get_codegen_UsedId(); } + // ino.end + + // ino.method.codegen.25426.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25426.body + { + String instvar_name = usedid.get_codegen_UsedId(); + + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.getfield); + code.add_code_short(classfile.add_field_ref(instvar_name, null, null)); + } + // ino.end + + // ino.method.TRStatement.25429.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25429.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.TRExp.25432.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.38 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25432.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25432.body + { + CTripleSet resultSet = new CTripleSet(); + CTripleSet tripleSet = this.expr.TRExp(sigma, V, supportData); + Iterator tripleIt = tripleSet.getIterator(); + while(tripleIt.hasNext()){ + CTriple triple = tripleIt.next(); + CTripleSet instVarSet = this.TRInstVar(triple, supportData); + resultSet.unite(instVarSet); + } + //PL 05-08-17 unifyAndRegisterType eingebaut + //return resultSet; + CTripleSet resultSet2 = super.registerType(resultSet, supportData); + return resultSet2; + + } + // ino.end + + // ino.method.TRInstVar.25435.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.38-1 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param triple + * @param supportData + * @return + */ + // ino.end + // ino.method.TRInstVar.25435.definition + public CTripleSet TRInstVar(CTriple triple, CSupportData supportData) + // ino.end + // ino.method.TRInstVar.25435.body + { + CTripleSet returnSet = new CTripleSet(); + // ########################## + // 1. Alle bisherigen Typkombinationen durchgehen: + // ########################## + for(int i=0; iAuthor: J�rg B�uerle + * @param triple Triple des Receivers + * @param thetaZero Typ der gefundenen Klasse + * @param thetaC Typ der InstanzVariable + * @param resultSet + * @param supportData + */ + // ino.end + // ino.method.handleInstVarAssum.25438.definition + private void handleInstVarAssum(CTriple triple, Type thetaZero, Type thetaC, CTripleSet resultSet, CSupportData supportData) + // ino.end + // ino.method.handleInstVarAssum.25438.body + { + // -------------------------- + // ReturnType mit Integer unifizieren: + // -------------------------- + Vector> unifierPossibilities = Unify.unify(triple.getResultType(), thetaZero, supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann + // anwenden und Triple hinzuf�gen: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + for(int i=0; iAuthor: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25441.definition + public String toString() + // ino.end + // ino.method.toString.25441.body + { + return super.type.toString() + " " + usedid.toString(); + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25444.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25444.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + if(this.get_UsedId().get_Name_1Element().equals(NameVariable)) + { + //wenn Variable mit gleichem Namen gefunden->schreibe Offset + localAssumption.addOffset(this.get_UsedId().getOffset()); + } + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + ret.add(expr.TYPEExpr(assumptions)); + this.setTypeVariable(TypePlaceholder.fresh(this)); + return null; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult().attach(this.expr.printJavaCode(resultSet)).attach("."+this.usedid.get_Name_1Element()); + } +} +// ino.end diff --git a/src/mycompiler/mystatement/InstanceOf.java b/src/mycompiler/mystatement/InstanceOf.java new file mode 100755 index 000000000..321cc9646 --- /dev/null +++ b/src/mycompiler/mystatement/InstanceOf.java @@ -0,0 +1,236 @@ +// ino.module.InstanceOf.8633.package +package mycompiler.mystatement; +// ino.end +// ino.module.InstanceOf.8633.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.BooleanType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.InstanceOf.25352.declaration +public class InstanceOf extends BinaryExpr +// ino.end +// ino.class.InstanceOf.25352.body +{ + // ino.attribute.expr.25356.declaration + public Expr expr; + // ino.end + // ino.attribute.reftype.25359.declaration + private RefType reftype; + // ino.end + // ino.attribute.parserlog.25362.decldescription type=line + // private boolean is_instance = false; + // ino.end + // ino.attribute.parserlog.25362.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.InstanceOf.25365.definition + public InstanceOf(int offset,int variableLength) + // ino.end + // ino.method.InstanceOf.25365.body + { + super(offset,variableLength); + // #JB# 20.04.2005 + // ########################################################### + this.setType(new BooleanType()); + //this.setType(new Type("boolean")); + // ########################################################### + } + // ino.end + + // ino.method.set_Expr.25368.definition + public void set_Expr(Expr exp) + // ino.end + // ino.method.set_Expr.25368.body + { + this.expr = exp; + } + // ino.end + + // ino.method.set_Type.25371.definition + public void set_Type(RefType typ) + // ino.end + // ino.method.set_Type.25371.body + { + this.reftype = typ; + } + // ino.end + + // ino.method.sc_check.25374.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25374.body + { + if(ext) + parserlog.debug(" ---InstanceOf---"); + Class cl; + String hilf, basis; + boolean merker=false; + + if(ext) + parserlog.debug("InstanceOf ruft sc_check von expr auf"); + try + { + expr.sc_check(classname,ch,bh,ext, parach, parabh); + } + catch(SCStatementException ex) + { + throw ex; + } + + if(ext) + parserlog.debug("InstanceOf pr�ft Typgleichheit: "); + if(expr.getTypeName().equals(reftype.getName())) + { + //is_instance = true; + if(ext) + parserlog.debug("...erf�llt!"); + } + else + { + //is_instance = false; + if(ext) + parserlog.debug("...nicht erf�llt!"); + } + if(!reftype.getName().equals("int")|| !reftype.getName().equals("char") || !reftype.getName().equals("String") || !reftype.getName().equals("boolean")) + { + if(ext) + parserlog.debug("Pr�fe auf Basisklassen"); + hilf=expr.getTypeName(); + for(;;) + { + if(merker) + break; + for(Enumeration el=classname.elements();el.hasMoreElements();) + { + cl=el.nextElement(); + if(cl.getName().equals(hilf)) + { + basis=cl.get_Superclass_Name(); + if(basis==null) + { + if(ext) + parserlog.debug("Keine Basisklasse gefunden!"); + //is_instance=false; + merker=true; + break; + } + else + if(reftype.getName().equals(basis)) + { + if(ext) + parserlog.debug("Basisklasse "+basis+" gefunden!Typ korrekt!"); + merker=true; + break; + } + else + { + if(ext) + parserlog.debug("Gehe in n�chste Vererbungsebene......"); + hilf=basis; + merker=false; + break; + } + } + } + } + } + } + // ino.end + + // ino.method.get_Name.25377.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25377.body + { + return null; + } + // ino.end + + // ino.method.codegen.25380.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25380.body + { + expr.codegen(classfile, code, paralist); + code.add_code(JVMCode.instanceof_); + code.add_code_short(classfile.add_CONSTANT_Class_info(reftype.getName())); + } + // ino.end + + // ino.method.TRExp.25383.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25383.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.TRStatement.25386.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25386.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25389.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25389.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + + +} +// ino.end diff --git a/src/mycompiler/mystatement/IntLiteral.java b/src/mycompiler/mystatement/IntLiteral.java new file mode 100755 index 000000000..0fc4c5858 --- /dev/null +++ b/src/mycompiler/mystatement/IntLiteral.java @@ -0,0 +1,215 @@ +// ino.module.IntLiteral.8635.package +package mycompiler.mystatement; +// ino.end +// ino.module.IntLiteral.8635.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.IntegerType; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.IntLiteral.25447.declaration +public class IntLiteral extends Literal +// ino.end +// ino.class.IntLiteral.25447.body +{ + // ino.attribute.Int.25451.declaration + private int Int; + // ino.end + // ino.attribute.parserlog.25454.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.IntLiteral.25457.definition + public IntLiteral() + // ino.end + // ino.method.IntLiteral.25457.body + { + super(-1,-1); + // #JB# 20.04.2005 + // ########################################################### + this.setType(new IntegerType()); + //this.setType(new Type("int")); + // ########################################################### + } + // ino.end + + // ino.method.set_Int.25460.definition + public void set_Int(int i) + // ino.end + // ino.method.set_Int.25460.body + { + this.Int = i; + } + // ino.end + + // ino.method.get_Int.25463.definition + public int get_Int() + // ino.end + // ino.method.get_Int.25463.body + { + return Int; + } + // ino.end + + // ino.method.sc_check.25466.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25466.body + { + parserlog.debug("SC -> Semantik-Check f�r IntLiteral wurde aufgerufen --> nichts zu tun!"); + } + // ino.end + + // ino.method.get_Name.25469.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25469.body + { + return null; + } + // ino.end + + // ino.method.codegen.25472.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end +// ino.method.codegen.25472.body +{ + if (Int >= 0 && Int <= 5) // Kleine Werte lassen sich direkt realisieren + code.add_code(JVMCode.nconst_n("int", Int)); + else if (Int >= -128 && Int <= 127) { // Aenderung des Codes fuer etwas groessere Werte + code.add_code(JVMCode.bipush); + code.add_code_byte((byte) Int); + } else if (Int >= -32768 && Int <= 32767) { // Aenderung des Codes fuer groessere Werte + code.add_code(JVMCode.sipush); + code.add_code_short((short) Int); + } else { // Ablage als Konstante + int index = classfile.add_CONSTANT_Integer_info(Int); + if (index < 256) { + code.add_code(JVMCode.ldc); + code.add_code_byte((byte) index); + } else { + code.add_code(JVMCode.ldc_w); + code.add_code_short((short) index); + } + } + + // Auto-Boxing: Da int nicht so nicht weiterverwendet werden kann, + // in Integer umwandeln. + if (!getPrimitiveFlag()) { + code.add_code(JVMCode.invokestatic); + code.add_code_short(classfile.add_method_ref("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;")); + } + } +// ino.end + + // ino.method.ConstantCodegen.25475.definition + public short ConstantCodegen(ClassFile classfile) + throws JVMCodeException + // ino.end + // ino.method.ConstantCodegen.25475.body + { + return (short) classfile.add_CONSTANT_Integer_info(get_Int()); + } + // ino.end + + + // ino.method.TRStatement.25478.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25478.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.TRExp.25481.defdescription type=javadoc + /** + * Workaround: �berschreibt Methode TRExp aus der Super-Klasse + * Literal, weil die Implementierung von Unify (noch) nicht mit + * Basetypes umgehen kann.
+ * Anstatt den Basetype IntegerType zur�ckzugeben, wird ein + * RefType zur�ckgegeben.
+ * Diese Methode kann sp�ter entfernt werden, sodass automatisch die Methode der + * Super-Klasse verwendet wird. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25481.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25481.body + { + CTripleSet tripleSet = new CTripleSet(); + tripleSet.addElement(new CTriple(sigma, new RefType("java.lang.Integer",getOffset()),V)); + return tripleSet; + } + // ino.end + + // ino.method.toString.25484.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25484.definition + public String toString() + // ino.end + // ino.method.toString.25484.body + { + return getTypeVariable().toString() + " " + Int; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25487.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25487.body + { + } + // ino.end + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + this.setTypeVariable(new IntegerType()); + return ret; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult(String.valueOf(this.Int)); + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/LambdaExpression.java b/src/mycompiler/mystatement/LambdaExpression.java new file mode 100644 index 000000000..dbbeeb3c9 --- /dev/null +++ b/src/mycompiler/mystatement/LambdaExpression.java @@ -0,0 +1,192 @@ +package mycompiler.mystatement; + +import java.util.Hashtable; +import java.util.Vector; + +import typinferenz.JavaCodeResult; +import typinferenz.SingleConstraint; +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.FunN; +import typinferenz.ResultSet; +import typinferenz.Typable; +import typinferenz.TypeAssumptions; +import typinferenz.TypinferenzException; + +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myclass.Class; +import mycompiler.myclass.FormalParameter; +import mycompiler.myclass.Method; +import mycompiler.myclass.ParameterList; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.DoubleType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +/** + * @author A10023 - Andreas Stadelmeier + * Momentan erweitert LambdaExpression noch Expr und erbt dadurch auch von ExprStatement ist also auch ein Statement + * + * LambdaExpression Aufbau: + * ( ParameterList ) -> { method_body }; + */ +public class LambdaExpression extends Expr{ + + private Block method_body; + private ParameterList params; + + public LambdaExpression(int offset, int variableLength) { + super(offset, variableLength); + setParameterList(new ParameterList());//default is empty parameterlist + } + + public void setBody(Block block){ + method_body = block; + } + + public void setExpr(Expr expression){ + Block bl = new Block(); + Return returnStmt = new Return(0, 0); + returnStmt.retexpr = expression; + bl.set_Statement(returnStmt); + this.setBody(bl); + } + + public void setParameterList(ParameterList params){ + this.params = params; + } + + @Override + public + void sc_check(Vector classlist, Hashtable ch, + Hashtable bh, boolean ext, Hashtable parach, + Hashtable parabh) throws SCStatementException { + // TODO Auto-generated method stub + + } + + @Override + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException { + // TODO Auto-generated method stub + + } + + @Override + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, + CSupportData supportData) throws CTypeReconstructionException { + // TODO An dieser Funktion weiterarbeiten + CTripleSet ret; + ret = new CTripleSet(); + //ret. + return ret; + } + + @Override + public void wandleRefTypeAttributes2GenericAttributes( + Vector paralist, + Vector genericMethodParameters) { + // TODO Auto-generated method stub + + } + + @Override + public boolean addOffsetsToStatement(CTypeAssumption localAssumption, + String NameVariable, boolean isMemberVariable) { + // TODO Auto-generated method stub + return false; + } + + @Override + public String get_Name() { + // TODO Auto-generated method stub + return null; + } + + @Override + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, + CSupportData supportData) throws CTypeReconstructionException { + // Diese Funktion wird aufgerufen wenn die LambdaExpression als Expression behandelt wird. + CTripleSet tripleSet = new CTripleSet(); + tripleSet.addElement(new CTriple(sigma, new DoubleType(),V)); + return tripleSet; + } + + @Override + public void addOffsetsToExpression(CTypeAssumption localAssumption, + String NameVariable, boolean isMemberVariable) { + // TODO Auto-generated method stub + + } + + + /** + * Spezifikation: + * + * TYPEExpr( Ass, Lambda( (x1 , . . . , xN ), expr|stmt ) ) = + * let + * AssArgs = { xi : ai | ai fresh type variables } + * (exprt : rty, ConS) = TYPEExpr( Ass ∪ AssArgs, expr ) + * | (stmtt : rty, ConS) = TYPEStmt( Ass u AssArgs, stmt ) + * in + * (Lambda( (x1 : a1 , . . . , xN : aN ), exprt : rty|stmtt : rty ) : a, + * ConS ∪ { (FunN a) }), + * where a is a fresh type variable + */ + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + //Die Assumptions für die Parameter der LambdaExpression + TypeAssumptions ArgumentAssumptions = new TypeAssumptions(assumptions.getThisValue().getName()); + Vector paramTypes = new Vector(); + + for(FormalParameter param : params.formalparameter){ + if(param.getTypeVariable()==null)param.setTypeVariable(TypePlaceholder.fresh(this)); + int offset = 0; + //Jeder Parameter der LambdaExpression wird als CParaTypeAssumption der Assumption liste hinzugefügt: + ArgumentAssumptions.add(new CParaTypeAssumption("", "", offset, offset, param.get_Name(), param.getTypeVariable(), offset, offset, null)); + paramTypes.add(param.getTypeVariable()); + } + this.setTypeVariable(TypePlaceholder.fresh(this)); + //ArgumentAssumptions + assumptions ergeben die Assumptions für die Statements innerhalb des Lambda-Bodys: + ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression + ret.add(new SingleConstraint(new FunN(method_body.getTypeVariable(), paramTypes),this.getTypeVariable())); + return ret; + } + + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions ass){ + throw new TypinferenzException("Eine LambdaExpression darf nicht als Statement verwendet werden."); + } + + @Override + public String getTypeInformation(){ + return this.getTypeVariable().toString()+" :: ("+this.params.getTypeInformation()+ ") -> " +this.method_body.getTypeInformation(); + } + + @Override + public String toString(){ + //return "LambdaExpression, Parameter: "+this.params+ ", Body: " +this.method_body; + return this.getType() + " (("+this.params+ ") -> "+this.method_body + ")"; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet){ + JavaCodeResult ret = new JavaCodeResult(); + ret.attach( "(").attach(this.params.printJavaCode(resultSet)).attach(")"); + ret.attach( " -> ").attach( this.method_body.printJavaCode(resultSet)); + return ret; + } + +} diff --git a/src/mycompiler/mystatement/Literal.java b/src/mycompiler/mystatement/Literal.java new file mode 100755 index 000000000..41274a682 --- /dev/null +++ b/src/mycompiler/mystatement/Literal.java @@ -0,0 +1,100 @@ +// ino.module.Literal.8636.package +package mycompiler.mystatement; +// ino.end + +// ino.module.Literal.8636.import +import mycompiler.mybytecode.ClassFile; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +// ino.end + +// ino.class.Literal.25490.declaration +public abstract class Literal extends Expr +// ino.end +// ino.class.Literal.25490.body +{ + // ino.attribute.primitiveFlag.29399.decldescription type=line + // Gibt an, ob das Literal fuer einen Objekttyp oder + // als primitive Konstante generiert werden soll. + // Default: Konstanten werden als primitiver Typ generiert. + // ino.end + + // ino.attribute.primitiveFlag.29399.declaration + private boolean primitiveFlag=true; + // ino.end + + // ino.method.setPrimitiveFlag.29402.definition + public void setPrimitiveFlag(boolean b) + // ino.end + // ino.method.setPrimitiveFlag.29402.body + { + this.primitiveFlag=b; + } + // ino.end + // ino.method.getPrimitiveFlag.29405.definition + public boolean getPrimitiveFlag() + // ino.end + // ino.method.getPrimitiveFlag.29405.body + { + return(this.primitiveFlag); + } + // ino.end + + + // ino.method.Literal.25494.definition + public Literal(int offset,int variableLength) + // ino.end + // ino.method.Literal.25494.body + { + super(offset,variableLength); + } + // ino.end + + // ino.method.TRExp.25497.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.40 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25497.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25497.body + { + CTripleSet tripleSet = new CTripleSet(); + tripleSet.addElement(new CTriple(sigma, this.getType(),V)); + return tripleSet; + } + // ino.end + + // ino.method.ConstantCodegen.25500.defdescription type=javadoc + /** + * Erzeugt die benoetigten Konstanteneintraege, die den Wert + * des Literals darstellen. + */ + // ino.end + // ino.method.ConstantCodegen.25500.definition + public short ConstantCodegen(ClassFile cf) + throws JVMCodeException + // ino.end + // ino.method.ConstantCodegen.25500.body + { + throw new JVMCodeException("Bytecodegenerierung fuer das Literal " + this.getClass().toString() + + " wurde nicht implementiert!"); + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + } +} +// ino.end diff --git a/src/mycompiler/mystatement/LocalOrFieldVar.java b/src/mycompiler/mystatement/LocalOrFieldVar.java new file mode 100755 index 000000000..a93c12138 --- /dev/null +++ b/src/mycompiler/mystatement/LocalOrFieldVar.java @@ -0,0 +1,461 @@ +// ino.module.LocalOrFieldVar.8637.package +package mycompiler.mystatement; +// ino.end +// ino.module.LocalOrFieldVar.8637.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.typeassumptionkey.CInstVarKey; +import mycompiler.mytypereconstruction.typeassumptionkey.CLocalVarKey; +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.JavaCodeResult; +import typinferenz.SingleConstraint; +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.LocalOrFieldVar.25503.declaration +public class LocalOrFieldVar extends Expr +// ino.end +// ino.class.LocalOrFieldVar.25503.body +{ + + // ino.attribute.parserlog.25507.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.LocalOrFieldVar.25510.definition + public LocalOrFieldVar(int offset, int variableLength) + // ino.end + // ino.method.LocalOrFieldVar.25510.body + { + super(offset,variableLength); + } + // ino.end + + // ino.method.LocalOrFieldVar.25513.definition + public LocalOrFieldVar(String n, int offset) + // ino.end + // ino.method.LocalOrFieldVar.25513.body + { + super(offset,n.length()); + usedid = new UsedId(offset); + usedid.set_Name(n); + } + // ino.end + + // ino.method.sc_check.25516.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25516.body + { + Vector typen = new Vector(); + SCStatementException except=null; + Vector name = usedid.get_Name(); + Class klasse = null; + Class hilfe = null; + String hilfstr; + Hashtable parahilf=null; + for(Enumeration el = name.elements(); el.hasMoreElements();) + { + String name1 = (String) el.nextElement(); + if(klasse!=null) //hier geht's rein, wenn eine Instanzvariable gefunden wurde + { + if(!el.hasMoreElements()) //es folgen keine weiteren Strings mehr -> name1 muss der Variablen-Name sein. + { + this.setType(new Type(klasse.is_member(name1),getOffset())); + if(klasse.get_ParaHash().containsKey(name1)) + { + /* Typ der Klasse ist parametrisierbar, nach Zuweisung schauen */ + if(parahilf!=null){ + this.setType((Type)parahilf.get(name1)); + for(Enumeration e3=parahilf.keys();e3.hasMoreElements();) + { + // System.out.println("parahilf.typen "+ (String)e3.nextElement()); + // System.out.print("+++++++++ "+type.get_Type()+" "); + parserlog.debug(string_rec(parahilf)); + // System.out.println(); + } + } + } + + if(this.getType().getName()==null) + { + SCExcept exc = new SCExcept(); + except = new SCStatementException(); + exc.set_error("Variable "+name1+" nicht gefunden"); + exc.set_statement("LocalOrFieldVar"); + except.addException(exc); + throw except; + } + else + { + typen.addElement(this.getType().getName()); + } + } + else //es folgen Strings -> weitere Klassen m�ssen auf die Variable �berpr�ft werden + { + this.setType(new Type(klasse.is_member(name1),getOffset())); + if( this.getType().getName() == null ) + { + SCExcept exc=new SCExcept(); + except=new SCStatementException(); + exc.set_error("Variable "+name1+" nicht gefunden"); + exc.set_statement("LocalOrFieldVar"); + except.addException(exc); + throw except; + } + else{ + typen.addElement(this.getType().getName()); + } + for(Enumeration el1 = classname.elements();el1.hasMoreElements();){ + hilfe=el1.nextElement(); + hilfstr=hilfe.getName(); + + if(this.getType().getName().equals(hilfstr)){ + klasse = hilfe; } + } + } + } + else if(!el.hasMoreElements()) //es steht nur der Variablenname im Vector name, + { //also MUSS die Variable in dieser Klasse deklariert sein + if(bh.containsKey(name1)) + { + this.setType(new Type( (String)bh.get(name1),getOffset())); + typen.addElement(this.getType().getName()); + if(bh.containsKey(name1)) + { + // System.out.println("type enthalten in bh: "+name1+ " - " +type.get_Type()); + } + /************/ + if(parabh.containsKey(name1)) + { + parahilf = (Hashtable) parabh.get(name1); + parserlog.debug(string_rec(parahilf)); + } + } + else if(ch.containsKey(name1)) + { + this.setType(new Type((String)ch.get(name1),getOffset())); + typen.addElement(this.getType().getName()); + if(ch.contains(this.getType().getName())) + { + // System.out.println("type enthalten in ch: " + name1 + " - " +type.get_Type()); + } + + if(parach.containsKey(name1)) + { + parahilf = (Hashtable) parach.get(name1); + // System.out.print("parahilf: "); string_rec(parahilf); System.out.println(); + } + } + else + { + SCExcept exc=new SCExcept(); + except=new SCStatementException(); + exc.set_error("Variable "+name1+" nicht gefunden"); + exc.set_statement("LocalOrFieldVar"); + except.addException(exc); + throw except; + } + } + else //es folgen Strings im Vector, also handelt es sich um eine Instanzvar. + { //wir m�ssen in Blockhash und Classhash nach der zugeh�rigen Klasse suchen. + if(bh.containsKey(name1)) + { + this.setType(new Type((String)bh.get(name1),getOffset())); //Attribut "type" von Basisklasse Expr + + for(Enumeration el1 = classname.elements();el1.hasMoreElements();) + { + hilfe = el1.nextElement(); + hilfstr = hilfe.getName(); + if(this.getType().getName().equals(hilfstr)){ + klasse = hilfe;} + } + typen.addElement(this.getType().getName()); + + if(bh.containsKey(name1)) + parserlog.debug("type enthalten in bh: "+name1+ " - " + this.getType().getName() ); + /***********************/ + if(parabh.containsKey(name1)){ + parahilf = (Hashtable) parabh.get(name1); + // System.out.print("parahilf: "); string_rec(parahilf); System.out.println(); + } + } + else if(ch.containsKey(name1)) + { + this.setType(new Type((String)ch.get(name1),getOffset())); //Attribut "type" von Basisklasse Expr + for(Enumeration el1 = classname.elements();el1.hasMoreElements();) + { + hilfe = el1.nextElement(); + hilfstr = hilfe.getName(); + parserlog.debug(this.getType().getName()+" ********* "+hilfstr); + if(this.getType().getName().equals(hilfstr)){ + klasse = hilfe;} + } + typen.addElement(this.getType().getName()); + + if(ch.containsKey(name1)) + { + // System.out.println("type enthalten in ch: "+name1+ " - " +type.get_Type()); + } + /*****************/ + if(parach.containsKey(name1)){ + parahilf = (Hashtable) parach.get(name1); + // System.out.print("parahilf: "); string_rec(parahilf); System.out.println(); + } + } + else + { + SCExcept exc=new SCExcept(); + except=new SCStatementException(); + exc.set_error("Variable "+name1+" nicht gefunden"); + exc.set_statement("LocalOrFieldVar"); + except.addException(exc); + throw except; + } + } + + } + usedid.set_Typen(typen); + parserlog.debug("SC -> Semantik-Check in LocalOrFieldVar erfolgreich!"); + } + // ino.end + + // ino.method.set_UsedId.25519.definition + public void set_UsedId(UsedId u) + // ino.end + // ino.method.set_UsedId.25519.body + { + this.usedid=u; + } + // ino.end + + + + // ino.method.get_Name.25522.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25522.body + { + return usedid.get_Name_1Element(); + } + // ino.end + + + + // ino.method.codegen.25525.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25525.body + { + Vector name_vector = get_Name_Vector(); + Vector type_vector = get_Type_Vector(); + String local_name = null; + String class_name = null; + String type = null; + + for(int i=0; i < name_vector.size(); i++) + { + local_name = (String)name_vector.elementAt(i); + try {// TEST SCJU. ArrayIndexoutofBounds umgehen! + type = JVMCode.get_codegen_Type((String)type_vector.elementAt(i), paralist); + } catch (Throwable e) {type = null; } + + int index = code.get_indexOf_Var(local_name); + if(index != -1) + { + // LocalVar + try + { + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload_n(local_type, index)); + } + catch(JVMCodeException e) + { + // out of nstore_n + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload(local_type)); + code.add_code_byte((byte)index); + } + } + else + { + // FieldVar + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.getfield); + code.add_code_short(classfile.add_field_ref(local_name, class_name, type)); + } + try { + // TEST SCJU. ArrayIndexoutofBounds umgehen! + class_name = (String)type_vector.elementAt(i); + } catch (Throwable e) { } + } + + // Falls noetig, Unboxing auf primitiven Typ! + if (this.getTypeVariable() instanceof RefType) { + RefType rt = (RefType) this.getTypeVariable(); + if (! rt.getPrimitiveFlag()) return; + + if (rt.getName().equalsIgnoreCase("java.lang.Integer")) { // Int Unboxen + code.add_code(JVMCode.invokevirtual); + code.add_code_short(classfile.add_method_ref("java/lang/Integer", "intValue", "()I")); + } + } + } + // ino.end + + // ino.method.TRExp.25528.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.37 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25528.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25528.body + { + CTypeAssumption assum = null; + // -------------------------- + // Lokale Variable aufsteigend + // in den Bl�cken suchen: + // -------------------------- + for(int depth=supportData.getCurrentBlockDepth(); assum==null && depth>0; depth--){ + CLocalVarKey localKey = new CLocalVarKey( + supportData.getCurrentClass(), + supportData.getCurrentMethod(), + supportData.getCurrentMethodParaCount(), + supportData.getCurrentMethodOverloadedID(), + supportData.getBlockId(depth), + this.get_Name()); + assum = V.getElement(localKey); + } + // -------------------------- + // Falls keine gefunden, Feldvariable suchen: + // -------------------------- + if(assum==null){ + CInstVarKey instKey = new CInstVarKey( + supportData.getCurrentClass(), + this.get_Name()); + assum = V.getElement(instKey); + } + //-------------------------- + // Falls nichts gefunden: + // -------------------------- + if(assum==null){ + //-------------------------- + // 15.04.2007 feda + // Wenn nichts gefunden dann neuen Typ anlegen. Verdacht auf Klassenmethode mit static + //-------------------------- + CTripleSet retSet = new CTripleSet(); + retSet.addElement(new CTriple(sigma, new RefType(this.get_Name(),this.getOffset()) , V)); + CTripleSet retSet2 = super.registerType(retSet, supportData); + return retSet2; + }else{ + //-------------------------- + // Ergebnismenge bauen: + // -------------------------- + CTripleSet retSet = new CTripleSet(); + retSet.addElement(new CTriple(sigma, assum.getAssumedType(), V)); + CTripleSet retSet2 = super.registerType(retSet, supportData); + return retSet2; + } + } + // ino.end + // ino.method.TRStatement.25531.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25531.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.toString.25534.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25534.definition + public String toString() + // ino.end + // ino.method.toString.25534.body + { + if(getTypeVariable()==null)return usedid.toString(); + return usedid.toString() + ": " + getTypeVariable().toString(); + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25537.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25537.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + if(this.get_UsedId().get_Name_1Element().equals(NameVariable)) + { + //wenn Variable mit gleichem Namen gefunden->schreibe Offset + localAssumption.addOffset(this.get_UsedId().getOffset()); + } + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + //gibt es eine Assumption für den die LocalOrFieldVar-Variablen, dann folgendes ausführen: + Type thisTypeAssumption = assumptions.getVarType(this.get_Name()); + this.setTypeVariable(thisTypeAssumption); + //ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable())); + return ret; + } + + public String getTypeInformation(){ + return this.getTypeVariable()+" "+this.get_Name(); + + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult(this.get_Name()); + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/LocalVarDecl.java b/src/mycompiler/mystatement/LocalVarDecl.java new file mode 100755 index 000000000..11982c959 --- /dev/null +++ b/src/mycompiler/mystatement/LocalVarDecl.java @@ -0,0 +1,641 @@ +// ino.module.LocalVarDecl.8638.package +package mycompiler.mystatement; +// ino.end +// ino.module.LocalVarDecl.8638.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myclass.Class; +import mycompiler.myclass.ClassHelper; +import mycompiler.myclass.DeclId; +import mycompiler.MyCompiler; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.LocalVarDecl.25540.declaration +public class LocalVarDecl extends Statement implements ITypeReplacementListener +// ino.end +// ino.class.LocalVarDecl.25540.body +{ + // ino.method.LocalVarDecl.25545.definition + public LocalVarDecl(int offset,int variableLength) + // ino.end + // ino.method.LocalVarDecl.25545.body + { + super(offset,variableLength); + } + // ino.end + + // ino.attribute.declid.25548.declaration + private Vector declid = new Vector(); + // ino.end + // ino.attribute.type.25551.declaration + private Type declType; + // ino.end + // ino.attribute.paralist.25554.declaration + private Vector paralist = null; + // ino.end + // ino.attribute.parahash.25557.declaration + private Hashtable parahash = null; + // ino.end + // ino.attribute.inferencelog.25560.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + // ino.attribute.parserlog.25563.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + // ino.attribute.block.25566.declaration + public Block block; + // ino.end + + + // ino.method.setType.25569.definition + public void setDeclType(Type t) + // ino.end + // ino.method.setType.25569.body + { + if(this.declType instanceof TypePlaceholder){ + ((TypePlaceholder)this.declType).removeReplacementListener(this); + } + + if(t instanceof TypePlaceholder){ + ((TypePlaceholder)t).addReplacementListener(this); + } + this.declType=t; + } + // ino.end + + // ino.method.getType.25572.definition + public Type getDeclType() + // ino.end + // ino.method.getType.25572.body + { + return this.declType; + } + // ino.end + + + // ino.method.set_DeclId.25575.definition + public void set_DeclId(DeclId did) + // ino.end + // ino.method.set_DeclId.25575.body + { + this.declid.addElement(did); + } + // ino.end + + // ino.method.get_Name.25578.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25578.body + { + DeclId hilf; + hilf=declid.elementAt(0); + return hilf.get_Name(); + } + // ino.end + // ino.method.set_ParaList.25581.definition + public void set_ParaList(Vector pl) + // ino.end + // ino.method.set_ParaList.25581.body + { + this.paralist = pl; + } + // ino.end + + // ino.method.sc_check.25584.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25584.body + { + parserlog.debug("SC -> Blockhashtab. vor LocalVarDecl.sc_check: " + bh); + DeclId hilf; + ExprStmt hilf2; + for(Enumeration e1=declid.elements(); e1.hasMoreElements();) + { + hilf=e1.nextElement(); + + //************* Hashtabelle f�r die LocalVar wird erzeugt + + if(hilf.paratyp != null) + { + this.paralist = hilf.get_Paratyp(); + parserlog.debug("++++ localvardecl.declid.paralist:"); + parserlog.debug(string_rec(this.paralist)); + + for(Enumeration e11=this.paralist.elements();e11.hasMoreElements();){ + Type t = (Type)e11.nextElement(); + try{ + is_declared(t,classname); + } + catch(SCStatementException ex){ + throw ex; + } + } + try{ + check_anz(this.getDeclType(),paralist,classname); + } + catch(SCStatementException ex){ + throw ex; + } + + // Erstellen der Hashtabelle f�r die Instaz der Klasse mit den zugewiesesen Parameter-Variablen + for(Enumeration e=classname.elements();e.hasMoreElements();){ + Class cl = e.nextElement(); + if(this.getDeclType().getName().equals(cl.getName())){ + if(ext){ + parserlog.debug("++ Klasse verifiziert, parahash und paralist: "+cl.get_ParaHash().toString()+" "); + parserlog.debug(string_rec(this.paralist)); + } + String para,var; + Type typ; + Hashtable ph = new Hashtable(); + Hashtable clph = cl.get_ParaHash(); + + // System.out.println("*********clph.size() = "+ clph.size()+" paralist.size()= " +paralist.size()); + if(clph.size() != paralist.size()){ + SCExcept exc = new SCExcept(); + exc.set_error("Anzahl der Parameter bei der Instantiierung von \""+ hilf.get_Name() +"\" stimmt nicht!"); + exc.set_statement("LocalVarDecl"); + SCStatementException ex = new SCStatementException(); + ex.addException(exc); + throw ex; + } + + //Hashtabelle in Class mu� die gleiche Anzahl an Elementen haben, wie die Parameterliste!! ** noch Abbruchbedingung impl.** + for(Enumeration en = clph.keys();en.hasMoreElements();){ + var = (String)en.nextElement(); + para= (String)cl.get_ParaHash().get(var); // sucht die Parametervariable f�r die Variable aus der Parahash-Tabelle... + parserlog.debug("var: "+var+" para: "+para); + //for(Enumeration e3=this.paralist.elements() ;e3.hasMoreElements();){ + for(Enumeration e2=cl.get_ParaList().elements(),e3=this.paralist.elements();e2.hasMoreElements();){ + Type t1 = (Type)e2.nextElement(); + Type t2 = (Type)e3.nextElement(); + if(t1.getName().equals(para)){ + typ = t2; // bestimmt die neue Zuordnung an der entsprechenden Stelle + ph.put(var,typ); // f�gt Variable und neuer Typ in die Hashtabelle ein + // System.out.println("++ typ "+typ.get_Type()); + } + } + } + this.parahash = ph; + parabh.put(hilf.get_Name(),ph); + if(ext){ + parserlog.debug("++ ParaHashtabelle der InstVar: "+this.parahash.toString()); + parserlog.debug("++ parach der InstVar: "); + parserlog.debug(string_rec(parach)); + parserlog.debug("++ parabh der InstVar: "); + parserlog.debug(string_rec(parabh)); + + parserlog.debug(string_rec("paralist: ",paralist)); + + } + } + } + } + //********************************** + + + + bh.put(hilf.get_Name(), this.getDeclType().getName()); + hilf2=hilf.get_Wert(); + if(hilf2!=null) + { + try + { + hilf2.sc_check(classname,ch,bh,ext, parach, parabh); + } + catch (SCStatementException ex) + { + throw ex; + } + if(!hilf2.getTypeName().equals(this.getDeclType().getName())) + { + if(this.getDeclType().getName().equals("int")) + { + if(hilf2.getTypeName().equals("char")) + { + parserlog.error("ACHTUNG! Hier wird einem int ein char zugewiesen!"); + parserlog.error("int "+get_Name()); + } + } + else + { + parserlog.error("Falscher Typ wird der neu deklarierten Variable zugewiesen. ---> SCWrongTypeAssignError"); + SCExcept exc = new SCExcept(); + exc.set_error("Der neu deklarierten Variable "+hilf.get_Name()+" vom Typ "+this.getDeclType().getName()+" soll ein Objekt vom Typ "+hilf2.getTypeName()+" zugewiesen werden. ---> SCWrongTypeAssignError :-)"); + exc.set_statement("LocalVarDecl"); + SCStatementException ex = new SCStatementException(); + ex.addException(exc); + throw ex; + } + } + } + + } + + parserlog.debug( "SC -> Blockhashtab. nach LocalVarDecl.sc_check: " + bh); + } + // ino.end + + + + // ino.method.is_declared.25587.definition + public void is_declared(Type t, Vector classlist) + throws SCStatementException + // ino.end + // ino.method.is_declared.25587.body + { + boolean flag=false; + for(Enumeration e = classlist.elements();e.hasMoreElements();){ + flag = false; + Class c = e.nextElement(); + + // System.out.println("is_init: vergleiche "+t.get_Type_()+" mit "+c.get_classname()); + if(c.getName().equals(t.getName())){ + // System.out.println("Klasse "+t.get_Type()+" im Vector classlist gefunden."); + flag = true; + break; + } + } + + if ( t instanceof RefType ) + { + if(((RefType)t).get_ParaList()!=null) + { + if( ((RefType)t).get_ParaList().size()>0) + { + for(Enumeration e1 = ((RefType)t).get_ParaList().elements();e1.hasMoreElements();) + { + try + { + is_declared((Type)e1.nextElement(),classlist); + } + catch(SCStatementException ex) + { + throw ex; + } + } + } + } + } + + if(!flag) + { + SCStatementException ex = new SCStatementException(); + SCExcept e = new SCExcept(); + e.set_error("unbekannte Klasse "+t.getName()+"."); + e.set_function("complete_parahashtable() --> is_declared()"); + e.set_statement(t.getName()); + ex.addException(e); + throw ex; + } + } + // ino.end + + // ino.method.check_anz.25590.definition + public void check_anz(Type type, Vector paralist, Vector classlist) + throws SCStatementException + // ino.end + // ino.method.check_anz.25590.body + { + boolean flag = false; + for(Enumeration e2 = classlist.elements();e2.hasMoreElements();){ + Class c = e2.nextElement(); + // System.out.println("vergleiche "+type.get_Type_()+" mit "+c.getName()); + if(c.getName().equals(type.getName())){ + // System.out.println("if(c.getName().equals(type.get_Type())){"); + if(c.get_ParaList().size()>0 && paralist!=null){ + + parserlog.debug("Type "+type.getName()+" in classlist gefunden!"); + parserlog.debug("Anzahl der localvar.paralist:"+ paralist.size()+" class.paralist: (soll) "+c.get_ParaList().size()); + if(paralist.size()==c.get_ParaList().size()){ + + for(Enumeration e3=paralist.elements();e3.hasMoreElements();){ + Type t = (Type)e3.nextElement(); + parserlog.debug("Type "+t.getName()+" wird gerade untersucht"); + + try + { + if ( t instanceof RefType ) + { + check_anz(t, ((RefType)t).get_ParaList(),classlist); + } + } + catch(SCStatementException ex) + { + throw ex; + } + } + flag = true; + parserlog.debug("flag gesetzt"); + break; + } + else{ + SCStatementException ex = new SCStatementException(); + SCExcept e = new SCExcept(); + e.set_error("Klasse "+c.getName()+" ist falsch parametrisiert!"); + e.set_function("complete_parahashtable() --> check_anz()"); + e.set_statement(type.getName()); + ex.addException(e); + throw ex; + } + } + else if(c.get_ParaList().size()==0 && paralist!=null){ + SCStatementException ex = new SCStatementException(); + SCExcept e = new SCExcept(); + e.set_error("Klasse "+c.getName()+" ist nicht parametrisierbar!"); + e.set_function("complete_parahashtable() --> check_anz()"); + e.set_statement(type.getName()); + ex.addException(e); + throw ex; + } + else if(paralist==null && c.get_ParaList().size()>0){ + parserlog.debug(paralist); + parserlog.debug(c.getName()+" "+c.get_ParaList().size()); + SCStatementException ex = new SCStatementException(); + SCExcept e = new SCExcept(); + e.set_error("Klasse "+c.getName()+" �berhaupt garnicht parametrisiert!"); + e.set_function("complete_parahashtable() --> check_anz()"); + e.set_statement(type.getName()); + ex.addException(e); + throw ex; + + } + else{ + flag = true; + parserlog.debug(type.getName()+" nicht parametrisierbar"); + break; + } + } + } + if(!flag) + { + SCStatementException ex = new SCStatementException(); + SCExcept e = new SCExcept(); + if ( type instanceof RefType ) + { + e.set_error("Type " + type.getName()+ " falsche Parameter-Anzahl " + ((RefType)type).get_ParaList().size()); + } + e.set_function("complete_parahashtable() --> check_anz()"); + e.set_statement(type.getName()); + ex.addException(e); + throw ex; + } + + } + // ino.end + + + + + + // ino.method.codegen.25593.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25593.body + { + if(declid != null) + for(int i = 0; i < declid.size(); i++) + declid.elementAt(i).codegen_LocalVarDecl(classfile, code, this.getDeclType(), paralist); + } + // ino.end + // ino.method.getDeclidVector.25596.definition + public Vector getDeclidVector() + // ino.end + // ino.method.getDeclidVector.25596.body + { + return declid; + } + // ino.end + // ino.method.setDeclidVector.25599.definition + public void setDeclidVector(Vector declid) + // ino.end + // ino.method.setDeclidVector.25599.body + { + this.declid = declid; + } + // ino.end + + // ino.method.getLineNumber.25602.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.getLineNumber.25602.definition + public int getLineNumber() + // ino.end + // ino.method.getLineNumber.25602.body + { + if(declid.size()<=0) + return MyCompiler.NO_LINENUMBER; + else{ + return declid.elementAt(0).getLineNumber(); + } + } + // ino.end + + // ino.method.getOffset.25605.defdescription type=javadoc + /** + *
Author: Thomas Hornberger + * @return + */ + // ino.end + // ino.method.getOffset.25605.definition + public int getOffset() + // ino.end + // ino.method.getOffset.25605.body + { + if(declid.size()<=0) + return MyCompiler.NO_LINENUMBER; + else{ + return declid.elementAt(0).getOffset(); + } + } + // ino.end + + + // ino.method.replaceType.25608.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param e + */ + // ino.end + // ino.method.replaceType.25608.definition + public void replaceType(CReplaceTypeEvent e) + // ino.end + // ino.method.replaceType.25608.body + { + if(e.getOldType().equals(this.getTypeVariable())){ + inferencelog.debug("Ersetze Typ in LocalVarDecl \""+this.get_Name()+"\"\n"); + if(getTypeVariable() instanceof TypePlaceholder){ + ((TypePlaceholder)getTypeVariable()).removeReplacementListener(this); + } + this.setTypeVariable(e.getNewType()); + } + if(e.getOldType().equals(this.getDeclType())){ + inferencelog.debug("Ersetze Typ in LocalVarDecl \""+this.get_Name()+"\"\n"); + if(declType instanceof TypePlaceholder){ + ((TypePlaceholder)declType).removeReplacementListener(this); + } + this.setDeclType(e.getNewType()); + } + } + // ino.end + + // ino.method.getTypeLineNumber.25611.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.getTypeLineNumber.25611.definition + public int getTypeLineNumber() + // ino.end + // ino.method.getTypeLineNumber.25611.body + { + return this.getLineNumber(); + } + // ino.end + + // ino.method.TRStatement.25614.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.24 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRStatement.25614.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25614.body + { + CTripleSet resultSet = new CTripleSet(); + V = V.shallowCopy(); + CTypeAssumptionSet localSet = new CTypeAssumptionSet(); + CLocalVarTypeAssumption varAssum = new CLocalVarTypeAssumption(supportData.getCurrentClass(), supportData.getCurrentMethod(), supportData.getCurrentMethodParaCount(), supportData.getCurrentMethodOverloadedID(), supportData.getCurrentBlockId(), this.get_Name() ,this.getDeclType(), this.getLineNumber(),this.getOffset(),new Vector()); + Class.isFirstLocalVarDecl=true; + + if(this.block != null) + this.block.addOffsetsToAssumption(varAssum,this.get_Name(),false);//hinzugef�gt hoth: 07.04.2006 + + localSet.addElement(varAssum); + V.unite(localSet); + resultSet.addElement(new CTriple(sigma, new Void(getOffset()), V)); + return resultSet; + } + // ino.end + + // ino.method.toString.25617.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25617.definition + public String toString() + // ino.end + // ino.method.toString.25617.body + { + if(declType == null)return "no type " + declid.toString(); + return declType.toString() + " " + declid.toString(); + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25620.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25620.body + { + + Type fpType=getDeclType(); + // Nur wenn es sich um ein RefType-Field handelt + GenericTypeVar pendantPara=ClassHelper.findGenericType(fpType,paralist,genericMethodParameters); + if(pendantPara!=null){ //Wenn generisch, dann modifizieren + setType(pendantPara); + } + + + } + // ino.end + + public boolean addOffsetsToStatement(CTypeAssumption localAssumption, String NameVariable, boolean isMemberVariable) + { + isMemberVariable=true;//hoth 02.05.06 + if(isMemberVariable)//Wenn Objektvariable + { + if(this.get_Name().equals(NameVariable)) + { + if(Class.isFirstLocalVarDecl==false) + {return false;}//Wenn jetzt lokale Variable kommt, dann springe raus + else + {Class.isFirstLocalVarDecl=false;} + } + } + return true; + } + + /** + * @author Andreas Stadelmeier, a10023 + * Der Typ der Variablendeklaration wird den Assumptions angefügt. + * Bei einer Deklaration ohne Typangabe wird ein TypePlaceholder den Assumptions hinzugefügt. + */ + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + if(this.getDeclType()==null || this.getDeclType() instanceof TypePlaceholder)this.setDeclType(TypePlaceholder.fresh(this)); + assumptions.addInstVarAssumption(assumptions.getThisValue().getName(), this.get_Name(), this.getDeclType()); + //assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden. + this.setTypeVariable(new Void(0)); //Return typ einer Variablendeklaration ist Void + return ret; + } + + @Override + public String getTypeInformation(){ + String ret = "VarDeclaration "; + if(this.getDeclType()!=null)ret+= this.getDeclType().toString()+" "; + ret+=this.get_Name(); + return ret; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult().attach(getDeclType().printJavaCode(resultSet)) .attach( " "+this.get_Name()+";"); + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/LongLiteral.java b/src/mycompiler/mystatement/LongLiteral.java new file mode 100755 index 000000000..3a73ae439 --- /dev/null +++ b/src/mycompiler/mystatement/LongLiteral.java @@ -0,0 +1,216 @@ +// ino.module.IntLiteral.8635.package +package mycompiler.mystatement; +// ino.end +// ino.module.IntLiteral.8635.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.IntegerType; +import mycompiler.mytype.LongType; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +// ino.end +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.IntLiteral.25447.declaration +public class LongLiteral extends Literal +// ino.end +// ino.class.IntLiteral.25447.body +{ + // ino.attribute.Int.25451.declaration + private long Long; + // ino.end + // ino.attribute.parserlog.25454.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.IntLiteral.25457.definition + public LongLiteral() + // ino.end + // ino.method.IntLiteral.25457.body + { + super(-1,-1); + + this.setType(new LongType()); + + } + // ino.end + + // ino.method.set_Int.25460.definition + public void set_Long(long i) + // ino.end + // ino.method.set_Int.25460.body + { + this.Long = i; + } + // ino.end + + // ino.method.get_Int.25463.definition + public long get_Long() + // ino.end + // ino.method.get_Int.25463.body + { + return Long; + } + // ino.end + + // ino.method.sc_check.25466.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25466.body + { + parserlog.debug("SC -> Semantik-Check f�r LongLiteral wurde aufgerufen --> nichts zu tun!"); + } + // ino.end + + // ino.method.get_Name.25469.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25469.body + { + return null; + } + // ino.end + + // ino.method.codegen.25472.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end +// ino.method.codegen.25472.body +{ + /*if (Int >= 0 && Int <= 5) // Kleine Werte lassen sich direkt realisieren + code.add_code(JVMCode.nconst_n("int", Int)); + else if (Int >= -128 && Int <= 127) { // Aenderung des Codes fuer etwas groessere Werte + code.add_code(JVMCode.bipush); + code.add_code_byte((byte) Int); + } else if (Int >= -32768 && Int <= 32767) { // Aenderung des Codes fuer groessere Werte + code.add_code(JVMCode.sipush); + code.add_code_short((short) Int); + } else { // Ablage als Konstante + int index = classfile.add_CONSTANT_Integer_info(Int); + if (index < 256) { + code.add_code(JVMCode.ldc); + code.add_code_byte((byte) index); + } else { + code.add_code(JVMCode.ldc_w); + code.add_code_short((short) index); + } + } + + // Auto-Boxing: Da int nicht so nicht weiterverwendet werden kann, + // in Integer umwandeln. + if (!getPrimitiveFlag()) { + code.add_code(JVMCode.invokestatic); + code.add_code_short(classfile.add_method_ref("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;")); + }*/ + throw new JVMCodeException("Bytecode nicht implementiert"); + } +// ino.end + + // ino.method.ConstantCodegen.25475.definition + public short ConstantCodegen(ClassFile classfile) + throws JVMCodeException + // ino.end + // ino.method.ConstantCodegen.25475.body + { + //return (short) classfile.add_CONSTANT_Integer_info(get_Int()); + throw new JVMCodeException("Bytecode nicht implementiert"); + } + // ino.end + + + // ino.method.TRStatement.25478.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25478.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.TRExp.25481.defdescription type=javadoc + /** + * Workaround: �berschreibt Methode TRExp aus der Super-Klasse + * Literal, weil die Implementierung von Unify (noch) nicht mit + * Basetypes umgehen kann.
+ * Anstatt den Basetype IntegerType zur�ckzugeben, wird ein + * RefType zur�ckgegeben.
+ * Diese Methode kann sp�ter entfernt werden, sodass automatisch die Methode der + * Super-Klasse verwendet wird. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25481.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25481.body + { + CTripleSet tripleSet = new CTripleSet(); + tripleSet.addElement(new CTriple(sigma, new RefType("java.lang.Long",getOffset()),V)); + return tripleSet; + } + // ino.end + + // ino.method.toString.25484.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25484.definition + public String toString() + // ino.end + // ino.method.toString.25484.body + { + return getTypeVariable().toString() + " " + Long; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25487.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25487.body + { + } + // ino.end + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/MethodCall.java b/src/mycompiler/mystatement/MethodCall.java new file mode 100755 index 000000000..a511a83af --- /dev/null +++ b/src/mycompiler/mystatement/MethodCall.java @@ -0,0 +1,1547 @@ +// ino.module.MethodCall.8639.package +package mycompiler.mystatement; +// ino.end +// ino.module.MethodCall.8639.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myclass.ClassBody; +import mycompiler.myclass.DeclId; +import mycompiler.myclass.FormalParameter; +import mycompiler.myclass.Method; +import mycompiler.myclass.ParameterList; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CIntersectionType; +import mycompiler.mytypereconstruction.CMultiplyTuple; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.CSubstitutionGenVar; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import mycompiler.mytypereconstruction.set.CMultiplyTupleSet; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.typeassumptionkey.CMethodKey; +import mycompiler.mytypereconstruction.unify.FC_TTO; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.JavaCodeResult; +import typinferenz.Overloading; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.MethodCall.25623.declaration +public class MethodCall extends Expr +// ino.end +// ino.class.MethodCall.25623.body +{ + // ino.method.MethodCall.25627.definition + public MethodCall(int offset, int variableLength) + // ino.end + // ino.method.MethodCall.25627.body + { + super(offset,variableLength); + } + // ino.end + + // ino.attribute.OK.25630.declaration + private static final int OK = 0; + // ino.end + // ino.attribute.UNIFY_ERROR.25633.declaration + private static final int UNIFY_ERROR = 1; + // ino.end + // ino.attribute.METHOD_NOT_FOUND_ERROR.25636.declaration + private static final int METHOD_NOT_FOUND_ERROR = 2; + // ino.end + + + // ino.attribute.receiver.25639.declaration + /** + * Diese Variable speichert die Expression, welche die Klasse von welcher die Methode aufgerufen wird darstellt. + */ + private Receiver receiver; + // ino.end + // ino.attribute.arglist.25642.declaration + private ArgumentList arglist=null; + // ino.end + private Vector exprtypes=new Vector(); //hier werden die Typen der �bergabewerten von sc_check eingetragen. + // ino.attribute.class_name.25645.declaration + private String class_name; //hier steht in welcher Klasse die Methode deklariert ist. + // ino.end + // ino.attribute.called_method.25648.declaration + private Method called_method=null; //hier steht nach Ende von sc_check die aufgerufene Methode. + // ino.end + // ino.attribute.uebernachdurch.25651.declaration + private Hashtable uebernachdurch; + // ino.end + // ino.attribute.finde_method.25654.declaration + private Vector> finde_method=new Vector>(); + // ino.end + // ino.attribute.counter.25657.declaration + private int counter; + // ino.end + + // ino.attribute.methodsFittingMethodCall.25660.decldescription type=javadoc + /** + * Da der SemanticCheck nicht mehr ausgeführt wird, werden hier die bei der + * Typrekonstruktion gefundenen Methoden abgespeichert. Problem ist hier jedoch, + * dass der receiver in diesem Moment noch nicht fest steht. Deshalb wird je + * Receiver ein Methodcall abgelegt. Dieser kann dann mit bspw. + * methodsFittingMethodCAll.get("Vector") abgerufen werden. + */ + // ino.end + // ino.attribute.methodsFittingMethodCall.25660.declaration + private Hashtable methodsFittingMethodCall=new Hashtable(); + // ino.end + // ino.attribute.parserlog.25663.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.set_ArgumentList.25666.definition + public void set_ArgumentList(ArgumentList al) + // ino.end + // ino.method.set_ArgumentList.25666.body + { + this.arglist = al; + } + // ino.end + + // ino.method.getArgumentList.25669.definition + public ArgumentList getArgumentList() + // ino.end + // ino.method.getArgumentList.25669.body + { + if(this.arglist==null)return this.arglist = new ArgumentList(); + return this.arglist; + } + // ino.end + + // ino.method.get_Receiver.25672.definition + public Receiver get_Receiver() + // ino.end + // ino.method.get_Receiver.25672.body + { + return receiver; + } + // ino.end + + // ino.method.get_Name.25675.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25675.body + { + return this.usedid.name.firstElement(); + } + // ino.end + + public void set_Name(String name){ + + this.usedid = new UsedId(name, 0); + } + + // ino.method.sc_check.25678.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25678.body + { + if(ext) + parserlog.debug(" --- MethodCall ---"); + parserlog.debug("ch: "+ch.toString()); + SCStatementException except=null; + + // 1. Vector expr wird nun durchgegangen, um die Typen der �bergabewerte zu erhalten + parserlog.debug(" ---- 1. Vector expr wird nun durchgegangen, um die Typen der �bergabewerte zu erhalten ---- "); + if(arglist!=null) + { + for(Enumeration el2 = arglist.expr.elements(); el2.hasMoreElements();) + { + Expr e=(Expr)el2.nextElement(); + try + { + e.sc_check(classname,ch,bh,ext, parach, parabh); + } + catch(SCStatementException ex) + { + if(except==null) + except=ex; + else + { + Vector v; + SCExcept hilf; + v=ex.get_exlist(); + for(Enumeration el=v.elements();el.hasMoreElements();) + { + hilf=el.nextElement(); + except.addException(hilf); + } + } + } + if(except!=null) + throw except; + if(ext) + parserlog.debug("Es wird in den Vector exprtypes ein Element eingefuegt vom Typ: "+e.getTypeName()); + exprtypes.addElement(e.getTypeName()); + } + } + + + // 2. �berpr�fung des Methodennamens + parserlog.debug(" ---- 2. �berpr�fung des Methodennamens ---- "); + Vector name = usedid.get_Name(); + Vector typen = new Vector(); + Class klasse = null; //Klasse wird auf null gesetzt um zuerst in der aktuellen Klasse zu checken + Hashtable parahilf=null; + + for(Enumeration el = name.elements(); el.hasMoreElements();) + { + String name1 = (String) el.nextElement(); + Class hilfe; + String hilfstr=null; + + if(name1.equals("System")) + { + if(ext) + parserlog.debug("Semantikcheck wird an CODEGEN weitergeleitet."); + typen.addElement("System"); + break; + } + if(klasse!=null) //hier geht's rein, wenn eine Instanzvariable gefunden wurde + { + if(!el.hasMoreElements()) //es folgen keine weiteren Strings mehr -> name1 muss der Methoden-Name sein. + { + if(ext) + inferencelog.debug("Checke Methode " + name1 + " in Klasse " + this.getType().getName()); + this.setType(new Type(klasse.is_member(name1),getOffset())); + if(this.getType()==null) + { + if(ext) + parserlog.debug("Methode "+name1+" nicht gefunden.sc_check-->MethodCall.sc_check()"); + SCExcept exc =new SCExcept(); + exc.set_error("Methode " + name1 + " in Klasse " + klasse.getName() + " nicht gefunden!"); + exc.set_statement("MethodCall"); + SCStatementException ex = new SCStatementException(); + ex.addException(exc); + throw ex; + } + else + { + if(ext) + parserlog.debug("Methode "+name1+" gefunden."); + class_name=klasse.getName(); + + // System.out.println("typen: "+typen.toString()+" type: "+ type+" parach: "+parach.toString()+" parabh: "+parabh.toString()); + if(parahilf != null){ + if(parahilf.containsKey(name1)) + this.setType((Type)parahilf.get(name1)); + } + parserlog.debug("typen: "+typen.toString()+", (ret.)type: "+ this.getType().getName()+", parach: "); + parserlog.debug(string_rec(parach)); + parserlog.debug(", parabh: "); + parserlog.debug(string_rec(parabh)); + parserlog.debug("name1 "+name1 +" hilfstr "+hilfstr); + typen.addElement(this.getType().getName()); + } + sc_check_get_Method(classname,name1,ext,parach,parabh); + } + else //es folgen Strings -> weitere Klassen m�ssen auf die Methode �berpr�ft werden + { + if(ext) + parserlog.debug("Checke Variable "+name1+"in Klasse "+this.getType().getName()+"."); + this.setType(new Type(klasse.is_member(name1),getOffset())); + if(this.getType()==null) + { + if(ext) + parserlog.debug("Variable "+name1+" nicht gefunden.sc_check-->MethodCall.sc_check()"); + SCExcept exc=new SCExcept(); + exc.set_error("Variable "+name1+" wurde in Klasse "+klasse.getName()+" nicht gefunden."); + exc.set_statement("MethodCall"); + SCStatementException ex = new SCStatementException(); + ex.addException(exc); + throw ex; + } + else + { + parserlog.debug(this.getType().getName()+" ******** 1"); + typen.addElement(this.getType().getName()); + if(ext) + parserlog.debug("Variable "+name1+" gefunden."); + } + for(Enumeration el1 = classname.elements();el1.hasMoreElements();) + { + hilfe=el1.nextElement(); + hilfstr=hilfe.getName(); + if(this.getType().equals(hilfstr)) + klasse = hilfe; + } + } + } + else if(!el.hasMoreElements()) //es steht nur der Methoden-Aufruf im Vector name, + { //also MUSS die Methode in dieser Klasse deklariert sein + if(ch.containsKey(name1)) + { + this.setType(new Type((String)ch.get(name1),getOffset())); + if(ext) + parserlog.debug("Methode " + name1 + " in Class gefunden vom Typ: " + this.getType().getName()); + class_name=(String)ch.get("###_classname"); + typen.addElement(this.getType().getName()); + try + { + sc_check_get_Method(classname,name1, ext,parach,parabh); //hier geht's weiter!!! + } + catch(SCStatementException ex) + { + throw ex; + } + } + else + { + if(ext) + parserlog.error("Methode "+name1+" nicht in Class gefunden.sc_check-->MethodCall.sc_check()"); + SCExcept exc= new SCExcept(); + exc.set_error("Methode "+name1+" nicht gefunden."); + exc.set_statement("MethodCall"); + SCStatementException ex=new SCStatementException(); + ex.addException(exc); + throw ex; + } + } + else if(bh.containsKey(name1)) //es folgen Strings im Vector, also handelt es sich um eine Instanzvar. + { //wir m�ssen im Blockhash nach der zugeh�rigen Klasse suchen. + this.setType(new Type((String)bh.get(name1),getOffset())); //Attribut "type" von Basisklasse Expr + if(ext) + parserlog.debug("Variable " + name1 + " im Block gefunden."); + for(Enumeration el1 = classname.elements();el1.hasMoreElements();) + { + hilfe = el1.nextElement(); + hilfstr = hilfe.getName(); + if(this.getType().getName().equals(hilfstr)) + klasse = hilfe; + } + + if(parabh.containsKey(name1)) + parahilf =(Hashtable) parabh.get(name1); + + typen.addElement(this.getType().getName()); + parserlog.debug(this.getType().getName()+" ******** 2 parahilf:"); + parserlog.debug(string_rec(parahilf)); + } + else if(ch.containsKey(name1)) //im Blockhash wurde der String nicht gefunden, also + { //m�ssen wir im Classhash nach der zugeh�rigen Klasse suchen. + this.setType(new Type((String)ch.get(name1),getOffset())); //Attribut "type" von Basisklasse Expr + if(ext) + parserlog.debug("Variable " + name1 + " im ClassBody gefunden."); + for(Enumeration el1 = classname.elements();el1.hasMoreElements();) + { + hilfe = el1.nextElement(); + hilfstr = hilfe.getName(); + if(this.getType().getName().equals(hilfstr)) + klasse = hilfe; + } + + if(parach.containsKey(name1)) + parahilf =(Hashtable) parach.get(name1); + + typen.addElement(this.getType().getName()); + parserlog.debug(this.getType().getName()+" ******** 3 parahilf:"); + parserlog.debug(string_rec(parahilf)); + } + else + { + if(ext) + parserlog.debug("Methoden-Aufruf "+name1+" nicht gefunden.sc_check-->MethodCall.sc_check()"); + SCExcept exc = new SCExcept(); + exc.set_error(name1+ " weder in Blockhash noch in Classhash gefunden."); + exc.set_statement("MethodCall"); + SCStatementException ex = new SCStatementException(); + ex.addException(exc); + throw ex; + + } + } + usedid.set_Typen(typen); + // 3. Ueberpruefung, welche Methode den/die richtigen �bergabeparmeter hat + // findet in der Funktion void sc_check_get_Method() statt + + + } + // ino.end + + // ino.method.sc_check_get_Method.25681.definition + public void sc_check_get_Method(Vector classlist, String methodname, boolean ext,Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check_get_Method.25681.body + { + Class hilf; + String hilfclassname; + ClassBody hilfbody; + Vector varundmeth; + Object typecheck; + Vector method=new Vector(); + Method moeglich; + String vergleich; + String classname; + int no_of_exprtypes; + Vector paralist; + no_of_exprtypes=exprtypes.size(); //Hier wird die Anzahl der �bergabeparameter festgestellt + if(ext) + parserlog.debug("Semantik-Check ist in sc_check_get_Method: Die Methode hat "+no_of_exprtypes+" �bergabewerte."); + + for(Enumeration el=classlist.elements();el.hasMoreElements();) //wir suchen alle Methoden mit dem gleichen + { //Namen, wie die aufgerufene Methode, die in der Klasse vorkommen + hilf=el.nextElement(); + hilfclassname=hilf.getName(); + if(hilfclassname.equals(class_name)) + { + hilfbody=hilf.get_ClassBody(); + varundmeth=hilfbody.get_FieldDeclVector(); + for(Enumeration el1=varundmeth.elements();el1.hasMoreElements();) + { + typecheck=el1.nextElement(); + if(typecheck instanceof Method) + { + moeglich=(Method)typecheck; + vergleich=moeglich.get_Method_Name(); + if(vergleich.equals(methodname)) + { + paralist=moeglich.get_Type_Paralist(); + if(ext) + parserlog.error("Es wurde eine Methode mit dem gleichen Namen gefunden. Sie hat "+paralist.size()+" �bergabewerte"); + if(paralist.size()==no_of_exprtypes)//Es werden nur noch Methoden hier hinzugefuegt, die die richtige Parameteranzahl + { //haben. last1 07.03.02 + method.addElement(moeglich); + } + } + } + } + if(hilf.does_Class_extend()) //hat die Klasse geerbt suchen wir in der Basisklasse nach weiteren + { //Methoden mit dem selben Namen + classname=hilf.get_Superclass_Name(); + sc_init_extended_fcts(method,classlist,methodname,classname,ext); + } + } + } + //Jetzt befinden sich im Vector method alle Funktionen mit dem richtigen Namen und der richtigen Anzahl an Parametern!, die + //m�glich sind => Wir koennen also die �bergabewerte pruefen + + for(int i=0;exprtypes.size()>i;i++) //l�uft so ab: F�r jeden �bergabeparameter wird die Funktion + { //sc_check_uebergabe aufgerufen + try + { + sc_check_uebergabe(classlist,method,ext,i,parach, parabh); + } + catch(SCStatementException ex) + { + throw ex; + } + finde_method.addElement(uebernachdurch); + if (ext) + parserlog.debug("Wir sind dabei, die Hashtables in den Vector zu schreiben."); + } + //jetzt muss noch die passende Methode rausgefischt werden + Hashtable zumueberpruefen; + String intnummern; + Method passt; + int indexnr=0; + boolean best=false; + int vererbschritte=0; + int zaehlen=0; + Vector aussuchen=new Vector(); + for(int j=0;exprtypes.size()>j;j++) + { + if(ext) + parserlog.debug("Hashtable Nr. "+j+" wird gecheckt."); + zumueberpruefen=finde_method.elementAt(j); //wir benutzen dazu die in sc_check_uebergabe + for(int k=0;k<10;k++) //erstellten Hashtables, ist die Schl�ssel-Nr. + { //m�glichst klein, ist die Methode in der Hash- + intnummern=String.valueOf(k); //table die bestpassende. + if(j==0) + { + if(zumueberpruefen.containsKey(intnummern)) + { + if(ext) + parserlog.debug("Methode wird in den Moeglichkeits-Vector aufgenommen!"); + aussuchen.addElement(zumueberpruefen.get(intnummern)); + if(best==false) + { + best=true; + vererbschritte=k; + } + } + } + else + { + if(zumueberpruefen.containsKey(intnummern)) + { + passt=zumueberpruefen.get(intnummern); + aussuchen.indexOf(passt); + if(indexnr!=zaehlen&&k classlist,Vector method,boolean ext,int paranum, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check_uebergabe.25684.body + { + Vector parameterlist; + String soll,ist; + boolean found=false; + Class hilfscl; + Method moeglich; + //String geerbt; + String intnummern; + uebernachdurch=new Hashtable(); + if(ext) + parserlog.debug("Semantik-Check pr�ft "+paranum+". �bergabewert."); + int vectorlaenge=method.size(); + for(int zaehl=0;zaehl e = classlist.elements();e.hasMoreElements();){ + hilfscl = e.nextElement(); + if(hilfscl.getName().equals(this.class_name)){ + if(hilfscl.get_ParaHash().containsValue(soll)){ + soll=ist; + } + } + } + /******/ + if(ist.equals(soll)) //hier wird untersucht, ob die �bergabetypen passen + { + found=true; + intnummern="0"; + uebernachdurch.put(intnummern,moeglich); //passen sie sofort -> Eintragung der Methode in Hashtable + if(ext) //unter Schl�ssel "0" + parserlog.debug("Semantik-Check hat "+paranum+". �bergabewert vom Typ "+ist+" gefunden."); + } + else + { + if(ist.equals("String")||ist.equals("int")||ist.equals("char")||ist.equals("boolean")) + { //ist der Typ String, int, char oder boolean passt die Methode im Normalfall nicht + found=false; + if(ist.equals("char")) + { + if(soll.equals("int")) + { + parserlog.info("ACHTUNG! Hier wird einem int ein char zugewiesen!"); + parserlog.info("Methode: "+usedid.get_Name().toString()); + found=true; + } + } + } + else // bei anderem Typ muss auf Vererbung �berpr�ft werden + { + if(ext) + parserlog.debug("Semantik-Check hat noch nichts gefunden. �bergabewert vom Typ "+ist+" k�nnte vererbt sein."); + counter=0; + found=sc_check_method_kleiner(classlist,ist,soll,ext);//hier wird auf Vererbung gepr�ft + if(found) + { + intnummern=String.valueOf(counter); //Counter gibt an wieviele Schritte bis zur richtigen + uebernachdurch.put(intnummern,moeglich); //Klasse durchgef�hrt wurden -> Counter ist + if(ext) //der Schl�ssel zur m�glichen Methode + parserlog.debug("Semantik-Check hat Uebergabewert vom Typ "+ist+" vererbt gefunden nach "+counter+" Durchl�ufen."); + } + + } + } + if(!found) + { + if(ext) + parserlog.debug("Nicht passende Funktion gefunden, wird vom Vector gel�scht."); + method.remove(moeglich); //Die m�gliche Methode wird gel�scht, wenn die Parameter nicht passen. + } + if(vectorlaenge!=method.size()) + { + vectorlaenge=method.size(); + zaehl=-1; + } + } + if(method.isEmpty()) + { + SCExcept ex=new SCExcept(); + ex.set_error("Keine passende Funktion gefunden!"); + ex.set_statement("Method - Call"); + SCStatementException exce=new SCStatementException(); + exce.addException(ex); + throw exce; + } + } + // ino.end + + + // ino.method.sc_check_method_kleiner.25687.definition + public boolean sc_check_method_kleiner(Vector classlist,String ist,String soll,boolean ext) + // ino.end + // ino.method.sc_check_method_kleiner.25687.body + { + Class hilf; + String geerbtvon; + String hilfmir; + boolean erg=false; + counter++; + for(Enumeration el1=classlist.elements();el1.hasMoreElements();) + { + hilf=el1.nextElement(); + hilfmir=hilf.getName(); + if(hilfmir.equals(ist)) + { + if(ext) + parserlog.debug("Habe Klasse gefunden "+hilfmir); + geerbtvon=hilf.get_Superclass_Name(); + if(ext) + parserlog.debug("Aktuell geerbtvon: "+geerbtvon); + if(geerbtvon!=null) + { + if(geerbtvon.equals(soll)) + { + if(ext) + parserlog.debug("Kleiner gefunden. Klassenname "+geerbtvon); + erg=true; + break; + } + else + { + erg=sc_check_method_kleiner(classlist,geerbtvon,soll,ext); + break; + } + } + else + erg=false; + } + else + erg=false; + } + return erg; + } + // ino.end + + // ino.method.sc_init_extended_fcts.25690.definition + public void sc_init_extended_fcts(Vector method, Vector classlist, String methodname, String classname, boolean ext) + // ino.end + // ino.method.sc_init_extended_fcts.25690.body + { //hier werden die Funktionen mit dem gleichen Namen, die von einer anderen Klasse geerbt wurden in den + Class hilf; //Vektor der m�glichen Methoden mitaufgenommen. + String hilfclassname; + ClassBody hilfbody; + Vector varundmeth; + Object typecheck; + Method moeglich; + String vergleich; + for(Enumeration el=classlist.elements();el.hasMoreElements();) + { + hilf=el.nextElement(); + hilfclassname=hilf.getName(); + if(hilfclassname.equals(classname)) + { + hilfbody=hilf.get_ClassBody(); + varundmeth=hilfbody.get_FieldDeclVector(); + for(Enumeration el1=varundmeth.elements();el1.hasMoreElements();) + { + typecheck=el1.nextElement(); + if(typecheck instanceof Method) + { + moeglich=(Method)typecheck; + vergleich=moeglich.get_Method_Name(); + if(vergleich.equals(methodname)) + method.addElement(moeglich); + } + } + if(hilf.does_Class_extend()) + { + classname=hilf.get_Superclass_Name(); + sc_init_extended_fcts(method,classlist,methodname,classname,ext); + } + } + } + } + // ino.end + + + // ino.method.set_Receiver.25693.definition + public void set_Receiver(Receiver rec) + // ino.end + // ino.method.set_Receiver.25693.body + { + receiver=rec; + } + // ino.end + + // ino.method.set_UsedId.25696.definition + public void set_UsedId(UsedId u) + // ino.end + // ino.method.set_UsedId.25696.body + { + usedid=u; + } + // ino.end + + // ino.method.set_Expr_Vector.25699.definition + public void set_Expr_Vector(Vector v) + // ino.end + // ino.method.set_Expr_Vector.25699.body + { + arglist.expr=v; + } + // ino.end + + // ino.method.add_Expr.25702.definition + public void add_Expr(Expr e) + // ino.end + // ino.method.add_Expr.25702.body + { + arglist.expr.addElement(e); + } + // ino.end + + // ino.method.getMethodFittingMethodCallAndClassname.25705.defdescription type=javadoc + /** + * hoti 4.5.06 + * Diese Methode lädt die Methodeninfos einer Methode aus der Hashtable + * methodsfittingmethodcall in ein Method-Objekt + * anhand der angegeben klasse + * @see methodsFittingMethodCall + * @param className + * @return + * @throws JVMCodeException + */ + // ino.end + // ino.method.getMethodFittingMethodCallAndClassname.25705.definition + public Method getMethodFittingMethodCallAndClassname(String className) + throws JVMCodeException + // ino.end + // ino.method.getMethodFittingMethodCallAndClassname.25705.body + { + CMethodTypeAssumption assumption=methodsFittingMethodCall.get(className); + if(assumption==null){ + throw new JVMCodeException("Codegen: Fuer die Klasse "+className+" wurde die Methode "+usedid.get_Name_1Element()+" nicht gefunden"); + } + Vector paraAssumptions=assumption.getParaAssumptions(); + Type returnType=assumption.getAssumedType(); + Method meth=new Method(); + Vector parameterVector=new Vector(); + ParameterList pl=new ParameterList(); + for(int i=0;i nichterkannte) kann kein Methodenaufruf ausgeführt werden + // Es muss sich also um einen RefType handeln. Ansonsten gibt es einen Fehler + + if(!(receiver.get_Expr().getTypeVariable() instanceof RefType)){ + throw new JVMCodeException("Es kann nur auf ein RefType ein Methodenaufruf ausgeführt werden ("+receiver+"["+receiver.get_Expr().getTypeVariable()+"])"); + } + + // HOTI 4.5.06 + // Es handelt sich also um einen RefType. Der Klassenname wird nun bezogen + String receiverClassName=((RefType)receiver.get_Expr().getTypeVariable()).getTypeName(); + + // Die richtige Methode wird gesucht und gesetzt + called_method=getMethodFittingMethodCallAndClassname(receiverClassName); + + + Vector name_vector = get_Name_Vector(); + String local_name = receiver.get_Expr().get_Name(); + + // Richtiges Objekt auf den Stack legen + int index = code.get_indexOf_Var(local_name); + + if (index != -1 ) { // Lokale Variable + try { + String local_type = code.get_TypeOf_Var(local_name) + .getName(); + code.add_code(JVMCode.nload_n(local_type, index)); + } catch (JVMCodeException e) { // out of nload_n + String local_type = code.get_TypeOf_Var(local_name) + .getName(); + code.add_code(JVMCode.nload(local_type)); + code.add_code_byte((byte) index); + } + } else { // FieldVariable + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.getfield); + code.add_code_short(classfile.add_field_ref(local_name, + class_name, JVMCode.get_codegen_Type(receiver.get_Type(), null))); + } + + String called_method_name = called_method.get_Method_Name(); + if (called_method_name == null) + called_method_name = (String) name_vector.lastElement(); + // feda 04.07.07 an dieser Stelle muss geschaut werden ob + // die Methode eine Static Methode ist. + // Wenn Static dann aload_0 weg und anstellen von + // code.add_code(JVMCode.invokevirtual); muss + // code.add_code(JVMCode.invokestatic); stehen. + + + if (arglist != null) + arglist.codegen(classfile, code, paralist); + code.add_code(JVMCode.invokevirtual); + code.add_code_short(classfile.add_method_ref(receiverClassName, + called_method_name, called_method + .get_codegen_Param_Type(paralist))); + } +// ino.end + + // ino.method.TRStatement.25711.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.27 von Martin Pl�micke
+ * Author: J�rg B�uerle + * + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRStatement.25711.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25711.body + { + CTripleSet resultSet = this.TRExp(sigma, V, supportData); + Iterator it = resultSet.getIterator(); + while(it.hasNext()){ + ((CTriple)it.next()).setResultType(new Void(getOffset())); + } + return resultSet; + } + // ino.end + + // ino.method.makeReceiver.25714.definition + private void makeReceiver() + // ino.end + // ino.method.makeReceiver.25714.body + { + usedid.get_Name().remove(usedid.get_Name().size()-1); //Methodenname loeschen + Iterator namen = usedid.get_Name().iterator(); + LocalOrFieldVar LOFV = new LocalOrFieldVar((String)namen.next(),getOffset()); + LOFV.setType(TypePlaceholder.fresh(this)); + receiver = new Receiver(LOFV); + while(namen.hasNext()) { + InstVar INSTVA = new InstVar(receiver.get_Expr(), (String)namen.next(),getOffset()); + INSTVA.setType(TypePlaceholder.fresh(this)); + receiver = new Receiver(INSTVA); + } + } + // ino.end + + // ino.method.TRExp.25717.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.33 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25717.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25717.body + { + CTripleSet resultSet = new CTripleSet(); + //String identifierName = (String)this.usedid.get_Name().elementAt(this.usedid.get_Name().size()-2); + String identifierName = (String)this.usedid.get_Name().elementAt(0); + String functionName = (String)this.usedid.get_Name().elementAt(this.usedid.get_Name().size()-1); + if (receiver == null) { // PL 05-08-21 wenn im Parser nicht primary geparst wurde + // also Aufruf von Objektkette oder Packagekette (nicht impl.) + if (this.usedid.get_Name().size() > 1) { + makeReceiver(); // macht aus der Liste von Strings in usedid.name einen receiver + } + else { + receiver = new Receiver(new This (getOffset(),getVariableLength())); + } + } + //called_method = functionName; MUSS NOCH GESETZT WERDEN, WENN KLAR IST WELCHEN TYP DIE PARAMETER HABEN + Vector expressions = new Vector(); + expressions.addElement(this.receiver.get_Expr()); + if(this.arglist!=null){ + expressions.addAll(this.arglist.expr); + } + // -------------------------- + // TRTuple rufen: + // -------------------------- + CMultiplyTupleSet tupleSet = this.TRTuple(new CMultiplyTuple(sigma, new Vector(), V), expressions, supportData); + Iterator tupleIt = tupleSet.getIterator(); + int successfulls=0; + Vector exceptions=new Vector(); + while(tupleIt.hasNext()){ + CMultiplyTuple tuple = tupleIt.next(); + int paraCount = 0; + if(this.arglist!=null){ + paraCount = this.arglist.expr.size(); + } + try{ + CTripleSet callAppSet = TRMCallApp(tuple, identifierName, functionName, paraCount, false, supportData); + resultSet.unite(callAppSet); + successfulls++; + }catch(CTypeReconstructionException exception){ + exceptions.addElement(exception); + } + } + if(successfulls==0){ + if(exceptions.size()>0){ + throw exceptions.elementAt(0); + } + throw new CTypeReconstructionException("MethodCall: Es konnte keine Assumption gefunden werden, die auf die Anforderung passt.",exceptions,this); + } + CTripleSet resultSet2 = super.registerType(resultSet, supportData); + return resultSet2; + //ALLE VARIANTEN MethodCall TESTEN UsecaseOne_pl.jav TUT SO NICHT + } + // ino.end + + // ino.method.TRMCallApp.25720.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.34 von Martin Pl�micke + * @param multiTuple + * @param classOrIdentifierName + * @param methodName + * @param paraCount + * @param isConstructorCall + * @param supportData + * @return + */ + // ino.end + // ino.method.TRMCallApp.25720.definition + public CTripleSet TRMCallApp(CMultiplyTuple multiTuple, String classOrIdentifierName, String methodName, int paraCount, boolean isConstructorCall, CSupportData supportData) + // ino.end + // ino.method.TRMCallApp.25720.body + { + // ########################## + // 1. Alle bisherigen Typkombinationen durchgehen: + // ########################## + CTripleSet case1 = new CTripleSet(); + for(int i=0; ihandleMethodAssum().
Author: J�rg B�uerle + * @param multiTuple + * @param possibleTypeComb + * @param returnSet + * @param className + * @param methodName + * @param paraCount + * @param supportData + * @param methodsFittingMethodCall Hashtable in der jede erfolgreiche Methode + * abgelegt wird @return Einen Error-Code: OK, + * UNIFY_ERROR oder METHOD_NOT_FOUND_ERROR + */ + // ino.end + // ino.method.searchAndHandleMethod.25723.definition + private int searchAndHandleMethod(CMultiplyTuple multiTuple, CTypeReconstructionResult possibleTypeComb, CTripleSet returnSet, String className, String methodName, int paraCount, CSupportData supportData, Hashtable methodsFittingMethodCall) + // ino.end + // ino.method.searchAndHandleMethod.25723.body + { + // -------------------------- + // Typannahme f�r Methode heraussuchen: + // -------------------------- + CMethodKey key = new CMethodKey( + className, + methodName, + paraCount + ); + Vector intersects = possibleTypeComb.getMethodIntersectionTypes(key); + + if(intersects.size()==0){ + return METHOD_NOT_FOUND_ERROR; + } + int wellUnifiedMethodCount=0; + + // Alle Methoden durchgehen, die gefunden wurden + for(int item=0;item genericClassParameters = possibleTypeComb.getGenerics(className); + // Generics der Methode holen + // p.ex. E test(){...} + // ___________________ + Vector genericMethodParameters=methodAssum.getGenericMethodParameters(); + + // Classtype initialisieren + // Wird fuer die Unifizierung benoetigt + RefType classType; + // Wird spaeter fuer die Codegen benoetigt + RefType classTypeWithRealParameters; + + // Klassenparameter berechnen + // => aus p.ex. Vector wird Vector + Vector unifyTypePara = new Vector(); + + if (genericClassParameters != null && genericClassParameters.size()>0) { + CSubstitutionSet sub = new CSubstitutionSet(); + for( int i = 0; i < genericClassParameters.size(); i++ ) + { + TypePlaceholder tlv = TypePlaceholder.fresh(this); + unifyTypePara.addElement(tlv); + + sub.addElement(new CSubstitutionGenVar(genericClassParameters.elementAt(i), tlv)); + } + methodAssum.sub(sub); + + classType=new RefType(className,unifyTypePara,getOffset()); + classTypeWithRealParameters=new RefType(className,possibleTypeComb.getGenerics(className),getOffset()); + }else{ + classType=new RefType(className,getOffset()); + classTypeWithRealParameters=new RefType(className,getOffset()); + } + + // Konstruktoren haben (inoffiziell) den Return-Typ des Objektes + if(methodAssum.getIdentifier().equals("")){ + methodAssum.setAssumedType(classType); + } + + + // Generische Methodenparameter hinzufuegen + + Vector additionalPairsToUnify=new Vector(); + + if (genericMethodParameters != null && genericMethodParameters.size()>0) { + + CSubstitutionSet sub = new CSubstitutionSet(); + + for( int i = 0; i < genericMethodParameters.size(); i++ ){ + + + if(genericMethodParameters.elementAt(i) instanceof BoundedGenericTypeVar){ + // Jede Bound als Paar zum Unifizieren vormerken + TypePlaceholder newTLV=TypePlaceholder.fresh(this); + BoundedGenericTypeVar bgtv=(BoundedGenericTypeVar)genericMethodParameters.elementAt(i); + for(int j=0;j + // Output: Alle Klassen <= Vector ... ohne Parameter + RefType cloneRT=classToAdd.clone(); + CSubstitutionSet sub=cloneRT.GenericTypeVar2TypePlaceholder(); + sub.applyThisSubstitutionSet(cloneRT); + Vector vec=sub.getVector(); + for(int i=0;i> test=Unify.instanceSmaller(pair,fctto); + for(int j=0;jhandleMethodAssum().
Author: J�rg B�uerle + * @param multiTuple + * @param possibleTypeComb + * @param returnSet + * @param className + * @param methodName + * @param paraCount + * @param methodsFittingMethodCall Hashtable in der jede erfolgreiche Methode + * abgelegt wird @param supportData + * @return Einen Error-Code: OK, UNIFY_ERROR oder + * METHOD_NOT_FOUND_ERROR + */ + // ino.end + // ino.method.searchAndHandleMethod.25729.definition + private int searchAndHandleMethod(CMultiplyTuple multiTuple, CTypeAssumptionSet V, CTripleSet returnSet, RefType classType, String methodName, int paraCount, CSupportData supportData, Hashtable methodsFittingMethodCall) + // ino.end + // ino.method.searchAndHandleMethod.25729.body + { + // -------------------------- + // Typannahme f�r Methode heraussuchen: + // -------------------------- + + String className; + if(classType instanceof RefType){ + className=((RefType)classType).getTypeName(); + }else{ + className=classType.getName(); + } + + CMethodKey key = new CMethodKey( + className, + methodName, + paraCount + ); + + Vector methodAssums = V.getElements(key); + + + // Wenn die Methode nicht fuendig war: + + if(methodAssums.size()==0){ + return METHOD_NOT_FOUND_ERROR; + } + + // Fuendig: Alle Methoden, die "xxx" heißen und y Parameter haben sind nun in dem Vector drin + // Für alle soll jetzt geschaut werden + + int wellDoneFunctionCount=0; + + for(int item=0;item typeGenPara = supportData.getCurrentClassPara(); + + // Generics der Methode holen + // p.ex. E test(){...} + // ___________________ + Vector genericMethodParameters=methodAssum.getGenericMethodParameters(); + + // Klassengenerics verarbeiten + Vector typePara = null; + if (typeGenPara != null) { + typePara = new Vector(); + for( int i = 0; i < typeGenPara.size(); i++ ) + { + typePara.addElement(typeGenPara.elementAt(i)); + } + } + + // Methodengenerics verarbeiten + Vector additionalPairsToUnify=new Vector(); + + if (genericMethodParameters != null && genericMethodParameters.size()>0) { + + CSubstitutionSet sub = new CSubstitutionSet(); + + for( int i = 0; i < genericMethodParameters.size(); i++ ){ + + + if(genericMethodParameters.elementAt(i) instanceof BoundedGenericTypeVar){ + // Jede Bound als Paar zum Unifizieren vormerken + TypePlaceholder newTLV=TypePlaceholder.fresh(this); + BoundedGenericTypeVar bgtv=(BoundedGenericTypeVar)genericMethodParameters.elementAt(i); + for(int j=0;jAuthor: J�rg B�uerle + * @param multiTuple + * @param returnSet + * @param methodAssum + * @param className + * @param supportData + * @param additionalPairsToUnify + * @return Einen Error-Code: OK, UNIFY_ERROR oder + * METHOD_NOT_FOUND_ERROR + */ + // ino.end + // ino.method.handleMethodAssum.25732.definition + private static int handleMethodAssum(CMultiplyTuple multiTuple, Vector typePara, CTripleSet returnSet, CMethodTypeAssumption methodAssum, Type classType, CSupportData supportData, Vector additionalPairsToUnify) + // ino.end + // ino.method.handleMethodAssum.25732.body + { + // -------------------------- + // Typen unifizieren: + // -------------------------- + + // Vorerst Paare zum Unifizieren bilden + Vector pairsToUnify = createPairsToUnify(multiTuple, typePara, classType, methodAssum); + + // Vorgemerkte Paare + if(pairsToUnify!=null && additionalPairsToUnify!=null) + pairsToUnify.addAll(additionalPairsToUnify); + + // Die Paare endlich unifizieren + Vector> unifierPossibilities = Unify.unify(pairsToUnify, supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann anwenden: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle Unifer durchgehen: + // -------------------------- + for(int j=0; jAuthor: J�rg B�uerle + * @param multiTuple + * @param receiverClass + * @param methodAssum + * @return + */ + // ino.end + // ino.method.createPairsToUnify.25735.definition + private static Vector createPairsToUnify(CMultiplyTuple multiTuple, Vector typePara, Type receiverClass, CMethodTypeAssumption methodAssum) + // ino.end + // ino.method.createPairsToUnify.25735.body + { + Vector pairList = new Vector(); + Pair p = new Pair(multiTuple.getResultTypes().firstElement(), receiverClass); + pairList.addElement(p); + for(int i=1; iAuthor: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25738.definition + public String toString() + // ino.end + // ino.method.toString.25738.body + { + //return receiver/*.toString()*/ + " " + usedid.toString(); + return type + " (" + this.get_Receiver() + "." + this.get_Name() +"(" + this.getArgumentList() + "))"; + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25741.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25741.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + if(this.get_Receiver()!=null) + { + this.get_Receiver().get_Expr().addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + if(this.getArgumentList()!=null){ + for(Expr n : this.getArgumentList().expr) + { + n.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + }} + } + + /** + * @author Andreas Stadelmeier, a10023 + * @return der Name der Methode, welcher dieser MethodCall aufruft. + */ + public String getName(){ + return this.usedid.toString(); + } + + /** + * @author AI10023 - Andreas Stadelmeier + * + * Mögliche Probleme: + * Wenn die Methode ohne Angabe eines Receivers im Quelltext steht: + * methodCall(param); -> (bedeutet:) this.methodCall(param); + * Der Parser macht hier aber komische Faxen (siehe JavaParser.jay Zeile 1858 ff) + */ + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + //TODO hier muss unterschieden werden zwischen einem Konstruktor und einer Methode. + //Hier der Ablauf für einen Methodenaufruf: + ConstraintsSet ret = new ConstraintsSet(); + //Der Return-Type des MEthodenaufrufs ist zunächst unbekannt: + this.setTypeVariable(TypePlaceholder.fresh(this)); + //Berechne die Constraints des Receivers + if(receiver == null){ + receiver = new Receiver(new This(0,0)); + } + ret.add(receiver.get_Expr().TYPEExpr(assumptions)); + + //Berechne die Constraints der Argumente aus der Argumentlist (also der Parameter, welche der Funktion übergeben wurden) + if(this.arglist != null)for(Expr arg : this.arglist.expr){ + ret.add(arg.TYPEExpr(assumptions)); + } + + //Noch das Overloading-Constraint anhängen: + ret.add(new Overloading(assumptions, this, this.getTypeVariable()).generateConsstraints()); + + return ret; + } + + /** + * Spezifikation: + * TYPEStmt( Ass, stmt ) = + * let (stmt : rty, ConS) = TYPEExpr( Ass, stmt ) + * in (stmt : Void, ConS) + */ + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){ + ConstraintsSet ret = this.TYPEExpr(assumptions); //TypeExpr aufrufen + this.setTypeVariable(new Void(0)); //Typ des Statments auf Void setzen, da als alleinstehendes Statement + return ret; + } + + @Override + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult(); + if(this.receiver != null)ret.attach( this.receiver.printJavaCode(resultSet)).attach("."); + ret .attach( this.get_Name()); + ret .attach( "(" ).attach( this.getArgumentList().printJavaCode(resultSet)).attach( ")"); + return ret.attach(";"); + + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/NegativeExpr.java b/src/mycompiler/mystatement/NegativeExpr.java new file mode 100755 index 000000000..2c9b2b475 --- /dev/null +++ b/src/mycompiler/mystatement/NegativeExpr.java @@ -0,0 +1,251 @@ +// ino.module.NegativeExpr.8640.package +package mycompiler.mystatement; +// ino.end +// ino.module.NegativeExpr.8640.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.NegativeExpr.25744.declaration +public class NegativeExpr extends UnaryExpr +// ino.end +// ino.class.NegativeExpr.25744.body +{ + // ino.method.NegativeExpr.25748.definition + public NegativeExpr(int offset,int variableLength) + // ino.end + // ino.method.NegativeExpr.25748.body + { + super(offset,variableLength); + } + // ino.end + // ino.attribute.neg.25751.declaration + private UnaryMinus neg; + // ino.end + // ino.attribute.expr.25754.declaration + public Expr expr; + // ino.end + // ino.attribute.parserlog.25757.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.get_Name.25760.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25760.body + { + return null; + } + // ino.end + + // ino.method.sc_check.25763.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25763.body + { + if(ext) + parserlog.debug(" ---NegativeExpr---"); + SCStatementException except=null; + String type = this.expr.getTypeName(); + try + { + this.expr.sc_check(classname,ch,bh,ext, parach, parabh); + } + catch(SCStatementException ex) + { + except=ex; + } + if(type != "int" || type != "boolean") + { + if(ext) + parserlog.warn("Warnung -- Typfehler!! Moeglicher Datenverlust --> NegativeExpr.sc_check()"); + SCExcept neu=new SCExcept(); + neu.set_error("Typfehler"); + neu.set_statement("NegativeExpr"); + if(except==null) + except=new SCStatementException(); + except.addException(neu); + } + if(except!=null) + throw except; + } + // ino.end + + // ino.method.set_UnaryMinus.25766.definition + public void set_UnaryMinus(UnaryMinus umin) + // ino.end + // ino.method.set_UnaryMinus.25766.body + { + this.neg = umin; + } + // ino.end + + // ino.method.set_Expr.25769.definition + public void set_Expr(Expr ex) + // ino.end + // ino.method.set_Expr.25769.body + { + this.expr = ex; + } + // ino.end + + // ino.method.codegen.25772.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25772.body + { + if(expr instanceof Binary) ((Binary)expr).neg_codegen(classfile, code, paralist); + else if(expr instanceof NegativeExpr) ((NegativeExpr)expr).neg_codegen(classfile, code, paralist); + else { + expr.codegen(classfile, code, paralist); + neg.codegen(classfile, code, expr.getTypeName(), true); + } + } + // ino.end + + // ino.method.neg_codegen.25775.definition + public void neg_codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.neg_codegen.25775.body + { + if(expr instanceof Binary) ((Binary)expr).codegen(classfile, code, paralist); + else if(expr instanceof NegativeExpr) ((NegativeExpr)expr).codegen(classfile, code, paralist); + else { + expr.codegen(classfile, code, paralist); + neg.codegen(classfile, code, expr.getTypeName(), false); + } + } + // ino.end + + // ino.method.TRExp.25778.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.41 von Martin Pl�micke + *
Achtung Workaround: Wenn die BaseTypes endlich korrekt implementiert sind, + * dann sollte der RefType "Integer" �berall durch den BaseType "IntegerType" + * ersetzt werden!!!
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25778.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25778.body + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr rufen: + // -------------------------- + CTripleSet exprSet = expr.TRExp(sigma, V, supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + Iterator exprIt = exprSet.getIterator(); + while(exprIt.hasNext()){ + CTriple exprTriple = exprIt.next(); + // -------------------------- + // ReturnType mit Integer unifizieren: + // -------------------------- + Vector> unifierPossibilities = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Integer",getOffset()), supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann + // anwenden und Triple hinzuf�gen: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + for(int i=0; i tripleIt = tripleSet.getIterator(); + while(tripleIt.hasNext()){ + tripleIt.next().setResultType(new Void(getOffset())); + } + return tripleSet; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25784.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25784.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/NewArray.java b/src/mycompiler/mystatement/NewArray.java new file mode 100755 index 000000000..928c40ab6 --- /dev/null +++ b/src/mycompiler/mystatement/NewArray.java @@ -0,0 +1,204 @@ +// ino.module.NewArray.8641.package +package mycompiler.mystatement; +// ino.end +// ino.module.NewArray.8641.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.NewArray.25787.declaration +public class NewArray extends Expr +// ino.end +// ino.class.NewArray.25787.body +{ + // ino.method.NewArray.25791.definition + public NewArray(int offset,int variableLength) + // ino.end + // ino.method.NewArray.25791.body + { + super(offset,variableLength); + } + // ino.end + // ino.attribute.type.25794.declaration + private Type type; + // ino.end + // ino.attribute.expr.25797.declaration + public Vector expr = new Vector(); + // ino.end + // ino.attribute.parserlog.25800.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.getType.25803.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @return Returns the type. + */ + // ino.end + // ino.method.getType.25803.definition + public Type getType() + // ino.end + // ino.method.getType.25803.body + { + return type; + } + // ino.end + + // ino.method.setType.25806.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param type The type to set. + */ + // ino.end + // ino.method.setType.25806.definition + public void setType(Type type) + // ino.end + // ino.method.setType.25806.body + { + this.type = type; + } + // ino.end + + // ino.method.get_Name.25809.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25809.body + { + return null; + } + // ino.end + + // ino.method.sc_check.25812.definition + public void sc_check(Vector classname, Hashtable bh, Hashtable ch,boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25812.body + { + if(ext) + parserlog.debug(" ---NewArray---"); + } + // ino.end + + // ino.method.get_codegen_Array_Type.25815.definition + public int get_codegen_Array_Type() + throws JVMCodeException + // ino.end + // ino.method.get_codegen_Array_Type.25815.body + { + if(this.getType().equals("boolean")) return 4; + else if(this.getType().equals("char")) return 5; + else if(this.getType().equals("float")) return 6; + else if(this.getType().equals("double")) return 7; + else if(this.getType().equals("byte")) return 8; + else if(this.getType().equals("short")) return 9; + else if(this.getType().equals("int")) return 10; + else if(this.getType().equals("long")) return 11; + else throw new JVMCodeException("JVMCodeException: NewArray: int get_codegen_Array_Type()"); + } + // ino.end + + // ino.method.codegen.25818.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25818.body + { + if(JVMCode.get_nType(this.getType().getName()) == 4) { + for(int i = 0; i < expr.size(); i++) ((Expr)expr.elementAt(i)).codegen(classfile, code, paralist); + code.add_code(JVMCode.anewarray); + code.add_code_short(classfile.add_CONSTANT_Class_info(this.getType().getName())); + } + else { + for(int i = 0; i < expr.size(); i++) ((Expr)expr.elementAt(i)).codegen(classfile, code, paralist); + code.add_code(JVMCode.newarray); + code.add_code_byte(this.get_codegen_Array_Type()); + } + } + // ino.end + + // ino.method.TRExp.25821.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.32 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25821.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25821.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.TRStatement.25824.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25824.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25827.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25827.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + if(this.get_UsedId().get_Name_1Element().equals(NameVariable)) + { + //wenn Variable mit gleichem Namen gefunden->schreibe Offset + localAssumption.addOffset(this.get_UsedId().getOffset()); + } + if(this.expr!=null){ + for(Expr n : this.expr) + { + n.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + }} + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/NewClass.java b/src/mycompiler/mystatement/NewClass.java new file mode 100755 index 000000000..e25392b3f --- /dev/null +++ b/src/mycompiler/mystatement/NewClass.java @@ -0,0 +1,381 @@ +// ino.module.NewClass.8642.package +package mycompiler.mystatement; +// ino.end +// ino.module.NewClass.8642.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CMultiplyTuple; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CMultiplyTupleSet; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.JavaCodeResult; +import typinferenz.Overloading; +import typinferenz.SingleConstraint; +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.FunN; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.NewClass.25830.declaration +public class NewClass extends Expr +// ino.end +// ino.class.NewClass.25830.body +{ + // ino.method.NewClass.25834.definition + public NewClass(int offset,int variableLength) + // ino.end + // ino.method.NewClass.25834.body + { + super(offset,variableLength); + } + // ino.end + + // ino.attribute.arglist.25837.declaration + private ArgumentList arglist; + // ino.end + // ino.attribute.parserlog.25840.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.getArgumentList.25843.definition + public ArgumentList getArgumentList() + // ino.end + // ino.method.getArgumentList.25843.body + { + return this.arglist; + } + // ino.end + + // ino.method.get_Name.25846.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25846.body + { + return this.usedid.get_Name_1Element(); + } + // ino.end + + // ino.method.set_UsedId.25849.definition + public void set_UsedId( UsedId t) + // ino.end + // ino.method.set_UsedId.25849.body + { + this.usedid = t; + } + // ino.end + + // ino.method.sc_check.25852.definition + public void sc_check(Vector classname, Hashtable bh, Hashtable ch, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25852.body + { + if(ext) + parserlog.debug(" ---NewClass---"); + Class cl; + String usedid = this.usedid.get_Name_1Element(); + String next = null; + for(Enumeration el = classname.elements(); el.hasMoreElements();) + { + cl = el.nextElement(); + next = (String)cl.getName(); + if(ext) + parserlog.debug("Vergleiche "+usedid+" mit "+next); + if(usedid.equals(next)) + { + this.set_Type(new Type(next,getOffset())); + break; + } + else next = null; + } + if(next == null) + { + if(ext) + parserlog.error("Typfehler --> NewClass.sc_check()" ); + SCStatementException stex = new SCStatementException(); + SCExcept ex = new SCExcept(); + ex.set_error("Typfehler"); + ex.set_statement("NewClass: Klasse "+usedid+" existiert nicht im Vector classname."); + stex.addException(ex); + throw stex; + } + if(ext) + parserlog.debug("Klasse "+usedid+" im class-Vector gefunden"); + } + // ino.end + + // ino.method.set_ArgumentList.25855.definition + public void set_ArgumentList(ArgumentList al) + // ino.end + // ino.method.set_ArgumentList.25855.body + { + this.arglist = al; + } + // ino.end + + // ino.method.codegen.25858.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end +// ino.method.codegen.25858.body +{ + String class_name = this.get_UsedId().get_codegen_UsedId(); + String arg; + + // Argumentliste verarbeiten + if (arglist != null) { + arg = arglist.get_codegen_ArgumentList(paralist); + } else { + arg = "()"; + } + code.add_code(JVMCode.new_); + code.add_code_short(classfile.add_CONSTANT_Class_info(class_name)); + code.add_code(JVMCode.dup); + + // Vor invokespecial die Parameter auf den Stack legen + if (arglist != null) { + // Die einzelnen Argumente generieren + for (int i=0; i< arglist.expr.size(); i++) { + arglist.expr.elementAt(i).codegen(classfile, code, paralist); + } + } + + code.add_code(JVMCode.invokespecial); + code.add_code_short(classfile.add_method_ref(class_name, "", arg + + "V")); + } +// ino.end + + // ino.method.TRStatement.25861.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.26 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRStatement.25861.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25861.body + { + CTripleSet returnSet = this.TRExp(sigma, V, supportData).deepCopy(); + Iterator tripleIt = returnSet.getIterator(); + while(tripleIt.hasNext()){ + tripleIt.next().setResultType(new Void(getOffset())); + } + return returnSet; + } + // ino.end + + // ino.method.TRExp.25864.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.31 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25864.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25864.body + { + String constructorName = (String)this.usedid.getQualifiedName(); + Vector typeParaList = this.usedid.get_RealParaList(); //eingefuegt 05-07-26 PL + CTripleSet resultSet = new CTripleSet(); + + // -------------------------- + // Standard-Konstruktor: + // -------------------------- + if(this.arglist==null || this.arglist.expr.size()==0){ + //resultSet.addElement(new CTriple(sigma, new RefType(constructorName), V)); + //eingefuegt 05-07-26 PL + resultSet.addElement(new CTriple(sigma, new RefType(constructorName, typeParaList,getOffset()), V)); + //return resultSet; 05-07-31 auskommentiert siehe nach else + } + // -------------------------- + // Konstruktor mit Argumenten: + // -------------------------- + else { + Vector expressions = new Vector(); + if(this.arglist!=null){ + expressions.addAll(this.arglist.expr); + } + // -------------------------- + // TRTuple rufen: + // -------------------------- + CMultiplyTupleSet tupleSet = this.TRTuple(new CMultiplyTuple(sigma, new Vector(), V), expressions, supportData); + Iterator tupleIt = tupleSet.getIterator(); + + Vector exceptions=new Vector(); + int successfulls=0; + + while(tupleIt.hasNext()){ + CMultiplyTuple tuple = tupleIt.next(); + int paraCount = 0; + if(this.arglist!=null){ + paraCount = this.arglist.expr.size(); + } + MethodCall constructorCall=new MethodCall(getOffset(),getVariableLength()); + try{ + CTripleSet callAppSet = constructorCall.TRMCallApp(tuple, constructorName, "", paraCount, true, supportData); + resultSet.unite(callAppSet); + successfulls++; + }catch(CTypeReconstructionException tre){ + exceptions.addElement(tre); + } + } + if(successfulls==0){ + if(exceptions.size()==1){ + throw exceptions.elementAt(0); + } + throw new CTypeReconstructionException("NewClass: Es konnte keine Assumption gefunden werden, die auf die Anforderung passt.",exceptions,this); + } + + } + //CTripleSet resultSet2 = super.unifyAndRegisterType(resultSet, supportData); + CTripleSet resultSet2 = super.registerType(resultSet, supportData); + return resultSet2; + } + // ino.end + + // ino.method.toString.25867.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.25867.definition + public String toString() + // ino.end + // ino.method.toString.25867.body + { + String ret = "NEW "; + Type thisType = getTypeVariable(); + if(thisType != null)ret += thisType.toString(); + else ret += this.get_Name(); + return ret; + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.25870.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25870.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + if(this.get_UsedId().get_Name_1Element().equals(NameVariable)) + { + //wenn Variable mit gleichem Namen gefunden->schreibe Offset + localAssumption.addOffset(this.get_UsedId().getOffset()); + } + if(this.getArgumentList()!=null){ + for(Expr n : this.getArgumentList().expr) + { + n.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + }} + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + //TODO: Das hier noch vervollständigen + ConstraintsSet ret = new ConstraintsSet(); + + this.set_Type(TypePlaceholder.fresh(this)); + //Die Auskommentierten Zeilen gehören zu MethodRefNew + //Vector argumentTypeList = new Vector(); + //for(Expr expr : this.arglist.expr){ + // argumentTypeList.add(expr.getTypeVariable()); + //} + //FunN funN= new FunN(null,argumentTypeList); + + //Constraint newClassTypeConstraint = new Constraint(null,null); + //ret.add(newClassTypeConstraint); + + if(this.arglist != null && this.arglist.expr != null)for(Expr arg : this.arglist.expr){ + ret.add(arg.TYPEExpr(assumptions)); + } + + //Ein new-Aufruf ist nichts anderes als ein MethodCall der Methode + MethodCall newAufruf = new MethodCall(0,0); + this.setTypeVariable(new RefType(this.get_Name(),0)); + newAufruf.type = new RefType(this.get_Name(),0); + newAufruf.set_Name(""); + newAufruf.set_Receiver(null); + ret.add(new Overloading(assumptions, newAufruf, this.getTypeVariable()).generateConsstraints()); + + return ret; + } + + /** + * Spezifikation: + * TYPEStmt( Ass, stmt ) = + * let (stmt : rty, ConS) = TYPEExpr( Ass, stmt ) + * in (stmt : Void, ConS) + */ + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){ + ConstraintsSet ret = this.TYPEExpr(assumptions); //TypeExpr aufrufen + this.set_Type(new Void(0)); //Typ des Statments auf Void setzen. + return ret; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult("new "); + ret.attach(this.getTypeVariable().printJavaCode(resultSet)); + ret.attach("("); + if(this.arglist!=null && this.arglist.expr != null){ + Iterator it = this.arglist.expr.iterator(); + while(it.hasNext()){ + Expr arg = it.next(); + ret.attach(arg.printJavaCode(resultSet)); + if(it.hasNext())ret.attach(", "); + } + //ret = ret.substring(0, ret.length()-2); + } + ret.attach(")"); + + return ret; + } +} +// ino.end diff --git a/src/mycompiler/mystatement/NotExpr.java b/src/mycompiler/mystatement/NotExpr.java new file mode 100755 index 000000000..5091b469c --- /dev/null +++ b/src/mycompiler/mystatement/NotExpr.java @@ -0,0 +1,269 @@ +// ino.module.NotExpr.8643.package +package mycompiler.mystatement; +// ino.end +// ino.module.NotExpr.8643.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.NotExpr.25873.declaration +public class NotExpr extends UnaryExpr +// ino.end +// ino.class.NotExpr.25873.body +{ + // ino.method.NotExpr.25877.definition + public NotExpr(int offset,int variableLength) + // ino.end + // ino.method.NotExpr.25877.body + { + super(offset,variableLength); + } + // ino.end + // ino.attribute.not.25880.declaration + private UnaryNot not; + // ino.end + // ino.attribute.expr.25883.declaration + public Expr expr; + // ino.end + // ino.attribute.parserlog.25886.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + + // ino.method.sc_check.25889.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.25889.body + { + if(ext) + parserlog.debug(" ---NotExpr---"); + SCStatementException except=null; + try + { + expr.sc_check(classname, ch, bh,ext, parach, parabh); + } + catch (SCStatementException ex) + { + except=ex; + } + this.setType(new Type( "boolean",getOffset())); + /*if(expr.get_Type() != "int" || expr.get_Type() != "boolean") + { + if(ext) + System.out.println("Warnung -- Typfehler!! Moeglicher Datenverlust --> NegativeExpr.sc_check()"); + scexcept exception =new scexcept(); + exception.set_error("Warnung!!! Moeglicher Datenverlust!!!"); + exception.set_statement("NotExpr"); + if(except==null) + except=new SCStatementException(); + except.addException(exception); + }*/ + if(except!=null) + throw except; + } + // ino.end + + // ino.method.get_Name.25892.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25892.body + { + return null; + } + // ino.end + + // ino.method.get_Expr.25895.definition + public Expr get_Expr() + // ino.end + // ino.method.get_Expr.25895.body + { + return expr; + } + // ino.end + + // ino.method.set_UnaryNot.25898.definition + public void set_UnaryNot(UnaryNot unot) + // ino.end + // ino.method.set_UnaryNot.25898.body + { + this.not = unot; + } + // ino.end + + // ino.method.set_Expr.25901.definition + public void set_Expr(Expr ex) + // ino.end + // ino.method.set_Expr.25901.body + { + this.expr = ex; + } + // ino.end + + // ino.method.codegen.25904.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25904.body + { + if(expr instanceof Binary) ((Binary)expr).not_codegen(classfile, code, paralist); + else if(expr instanceof NotExpr) ((NotExpr)expr).not_codegen(classfile, code, paralist); + else { + expr.codegen(classfile, code, paralist); + not.codegen(classfile, code, true); + } + } + // ino.end + + // ino.method.not_codegen.25907.definition + public void not_codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.not_codegen.25907.body + { + if(expr instanceof Binary) ((Binary)expr).codegen(classfile, code, paralist); + else if(expr instanceof NotExpr) ((NotExpr)expr).codegen(classfile, code, paralist); + else { + expr.codegen(classfile, code, paralist); + not.codegen(classfile, code, false); + } + } + // ino.end +/* + public void if_codegen(ClassFile classfile, Code_attribute code, boolean sw) throws JVMCodeException { + if(expr instanceof NotExpr) if_codegen(classfile, code, !sw); + else { + expr.codegen(classfile, code); + not.if_codegen(classfile, code, sw); + } + } +*/ + + // ino.method.TRExp.25910.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.42 von Martin Pl�micke + *
Achtung Workaround: Wenn die BaseTypes endlich korrekt implementiert sind, + * dann sollte der RefType "Boolean" �berall durch den BaseType "BooleanType" + * ersetzt werden!!!
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.25910.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25910.body + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr rufen: + // -------------------------- + CTripleSet exprSet = expr.TRExp(sigma, V, supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + Iterator exprIt = exprSet.getIterator(); + while(exprIt.hasNext()){ + CTriple exprTriple = exprIt.next(); + // -------------------------- + // ReturnType mit Integer unifizieren: + // -------------------------- + Vector> unifierPossibilities = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Boolean",getOffset()), supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann + // anwenden und Triple hinzuf�gen: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + for(int i=0; i tripleIt = tripleSet.getIterator(); + while(tripleIt.hasNext()){ + tripleIt.next().setResultType(new Void(getOffset())); + } + return tripleSet; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25916.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25916.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/Null.java b/src/mycompiler/mystatement/Null.java new file mode 100755 index 000000000..da02b7220 --- /dev/null +++ b/src/mycompiler/mystatement/Null.java @@ -0,0 +1,122 @@ +// ino.module.Null.8644.package +package mycompiler.mystatement; +// ino.end +// ino.module.Null.8644.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.Null.25919.declaration +public class Null extends Literal +// ino.end +// ino.class.Null.25919.body +{ + + // ino.attribute.parserlog.25923.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.Null.25926.definition + public Null() + // ino.end + // ino.method.Null.25926.body + { + super(-1,-1); + this.setType(new Type("__NULL__",getOffset())); + } + // ino.end + + // ino.method.get_Name.25929.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25929.body + { + return null; + } + // ino.end + + // ino.method.sc_check.25932.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25932.body + { + if(ext) + parserlog.debug(" ---Null---"); + } + // ino.end + + // ino.method.codegen.25935.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25935.body + { + code.add_code(JVMCode.aconst_null); + } + // ino.end + + // ino.method.TRStatement.25938.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25938.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.TRExp.25941.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25941.body + { + CTripleSet tripleSet = new CTripleSet(); + tripleSet.addElement(new CTriple(sigma, TypePlaceholder.fresh(this) ,V)); + return tripleSet; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25944.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25944.body + { + } + // ino.end + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("null"); + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/PositivExpr.java b/src/mycompiler/mystatement/PositivExpr.java new file mode 100755 index 000000000..cbfb7bab1 --- /dev/null +++ b/src/mycompiler/mystatement/PositivExpr.java @@ -0,0 +1,145 @@ +// ino.module.PositivExpr.8645.package +package mycompiler.mystatement; +// ino.end +// ino.module.PositivExpr.8645.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.PositivExpr.25947.declaration +public class PositivExpr extends UnaryExpr +// ino.end +// ino.class.PositivExpr.25947.body +{ + // ino.method.PositivExpr.25951.definition + public PositivExpr(int offset,int variableLength) + // ino.end + // ino.method.PositivExpr.25951.body + { + super(offset,variableLength); + } + // ino.end + // ino.attribute.plus.25954.declaration + protected UnaryPlus plus; + // ino.end + // ino.attribute.expr.25957.declaration + public Expr expr; + // ino.end + // ino.attribute.parserlog.25960.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + + // ino.method.set_UnaryPlus.25963.definition + public void set_UnaryPlus(UnaryPlus up) + // ino.end + // ino.method.set_UnaryPlus.25963.body + { + this.plus = up; + } + // ino.end + + // ino.method.set_Expr.25966.definition + public void set_Expr(Expr ex) + // ino.end + // ino.method.set_Expr.25966.body + { + this.expr = ex; + } + // ino.end + + // ino.method.get_Name.25969.definition + public String get_Name() + // ino.end + // ino.method.get_Name.25969.body + { + return null; + } + // ino.end + + // ino.method.sc_check.25972.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.25972.body + { + if(ext) + parserlog.debug(" ---PositivExpr---"); + //Wartet noch auf Implementierung + } + // ino.end + + // ino.method.codegen.25975.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.25975.body + {} + // ino.end + + // ino.method.TRExp.25978.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.25978.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.TRStatement.25981.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.25981.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25984.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.25984.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/PostDecExpr.java b/src/mycompiler/mystatement/PostDecExpr.java new file mode 100755 index 000000000..de0acec30 --- /dev/null +++ b/src/mycompiler/mystatement/PostDecExpr.java @@ -0,0 +1,301 @@ +// ino.module.PostDecExpr.8646.package +package mycompiler.mystatement; +// ino.end +// ino.module.PostDecExpr.8646.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.PostDecExpr.25987.declaration +public class PostDecExpr extends UnaryExpr +// ino.end +// ino.class.PostDecExpr.25987.body +{ + // ino.method.PostDecExpr.25991.definition + public PostDecExpr(int offset,int variableLength) + // ino.end + // ino.method.PostDecExpr.25991.body + { + super(offset,variableLength); + } + // ino.end + // ino.attribute.expr.25994.declaration + public Expr expr; + // ino.end + // ino.attribute.parserlog.25997.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + + // ino.method.set_Expr.26000.definition + public void set_Expr(Expr ex) + // ino.end + // ino.method.set_Expr.26000.body + { + this.expr = ex; + } + // ino.end + + // ino.method.get_Name.26003.definition + public String get_Name() + // ino.end + // ino.method.get_Name.26003.body + { + return null; + } + // ino.end + +// ino.method.sc_check.26006.definition +public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) +throws SCStatementException +// ino.end + // ino.method.sc_check.26006.body + { + SCStatementException ex=null; + if(ext) + parserlog.debug(" ---PostDecExpr---"); + try + { + expr.sc_check(classname,ch,bh,ext,parach, parabh); + this.setType(new Type(expr.getTypeName(),getOffset())); + } + catch (SCStatementException except) + { + ex=except; + } + if(this.getType()==null) + { + if(ext) + parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! --- NoTypeDefError :-)"); + if(ex==null) + ex=new SCStatementException(); + SCExcept exc = new SCExcept(); + exc.set_error("Kein Typ vorhanden - NoTypeDefError"); + exc.set_statement("PostDecExpr"); + ex.addException(exc); + } + else + { + if(!this.getType().getName().equals("int")) + { + if (ext) + parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! -- wird auf anderen Typ als int angewendet."); + SCExcept exc = new SCExcept(); + exc.set_error("-- Operator wird auf "+this.getType()+" angewendet."); + exc.set_statement("PostDecExpr"); + if(ex==null) + ex = new SCStatementException(); + ex.addException(exc); + } + } + if(ex!=null) + throw ex; + } + // ino.end + + // ino.method.codegen.26009.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.26009.body + { + if(expr instanceof LocalOrFieldVar) { + String local_name = (String)((LocalOrFieldVar)expr).get_Name_Vector().lastElement(); + + int index = code.get_indexOf_Var(local_name); + if(index != -1) { + code.add_code(JVMCode.iinc); + code.add_code_byte(index); + code.add_code_byte(-1); + } + else { + if(expr instanceof LocalOrFieldVar) { + LocalOrFieldVar local = (LocalOrFieldVar)expr; + Vector name_vector = local.get_Name_Vector(); + Vector type_vector = local.get_Type_Vector(); + String class_name = null; + String type = null; + for(int i=0; i < name_vector.size()-1; i++) { + local_name = (String)name_vector.elementAt(i); + type = JVMCode.get_codegen_Type((String)type_vector.elementAt(i), paralist); + + index = code.get_indexOf_Var(local_name); + if(index != -1) { // LocalVar + try{ + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload_n(local_type, index)); + } + catch(JVMCodeException e) { // out of nload_n + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload(local_type)); + code.add_code_byte((byte)index); + } + } + else { // FieldVar + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.getfield); + code.add_code_short(classfile.add_field_ref(local_name, class_name, type)); + } + class_name = (String)type_vector.elementAt(i); + } + + local_name = (String)name_vector.lastElement(); + index = classfile.add_field_ref(local_name, class_name, JVMCode.get_codegen_Type("int", paralist)); + + code.add_code(JVMCode.dup); + code.add_code(JVMCode.getfield); + code.add_code_short(index); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.isub); + code.add_code(JVMCode.putfield); + code.add_code_short(index); + + } + } + } + else if(expr instanceof InstVar) { + InstVar instvar = (InstVar)expr; + String instvar_name = instvar.get_codegen_UsedId(); + int index = classfile.add_field_ref(instvar_name, null, null); + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.dup); + code.add_code(JVMCode.getfield); + code.add_code_short(index); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.isub); + code.add_code(JVMCode.putfield); + code.add_code_short(index); + } + else throw new JVMCodeException("JVMCodeException: PostDecExpr: void codegen(ClassFile classfile, Code_attribute code)"); + } + // ino.end + + // ino.method.TRExp.26012.defdescription type=javadoc + /** + * Achtung Workaround: RefType "Integer" sollte irgendwann gegen BaseType + * IntegerType ausgetauscht werden. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.26012.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.26012.body + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr rufen: + // -------------------------- + CTripleSet exprSet = expr.TRExp(sigma, V, supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + Iterator exprIt = exprSet.getIterator(); + while(exprIt.hasNext()){ + CTriple exprTriple = exprIt.next(); + // -------------------------- + // ReturnType mit Integer unifizieren: + // -------------------------- + Vector> unifierPossibilities = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Integer",getOffset()), supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann + // anwenden und Triple hinzuf�gen: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + for(int i=0; i tripleIt = tripleSet.getIterator(); + while(tripleIt.hasNext()){ + tripleIt.next().setResultType(new Void(getOffset())); + } + return tripleSet; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26018.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26018.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/PostIncExpr.java b/src/mycompiler/mystatement/PostIncExpr.java new file mode 100755 index 000000000..f8b543b48 --- /dev/null +++ b/src/mycompiler/mystatement/PostIncExpr.java @@ -0,0 +1,302 @@ +// ino.module.PostIncExpr.8647.package +package mycompiler.mystatement; +// ino.end +// ino.module.PostIncExpr.8647.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.PostIncExpr.26021.declaration +public class PostIncExpr extends UnaryExpr +// ino.end +// ino.class.PostIncExpr.26021.body +{ + // ino.method.PostIncExpr.26025.definition + public PostIncExpr(int offset,int variableLength) + // ino.end + // ino.method.PostIncExpr.26025.body + { + super(offset,variableLength); + } + // ino.end + // ino.attribute.expr.26028.declaration + public Expr expr; + // ino.end + // ino.attribute.parserlog.26031.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + + // ino.method.set_Expr.26034.definition + public void set_Expr(Expr ex) + // ino.end + // ino.method.set_Expr.26034.body + { + this.expr = ex; + } + // ino.end + + // ino.method.get_Name.26037.definition + public String get_Name() + // ino.end + // ino.method.get_Name.26037.body + { + return null; + } + // ino.end + + // ino.method.sc_check.26040.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.26040.body + { + SCStatementException ex=null; + if(ext) + parserlog.debug(" ---PostIncExpr---"); + try + { + expr.sc_check(classname,ch,bh,ext,parach,parabh); + this.setType(new Type(expr.getTypeName(),getOffset())); + } + catch (SCStatementException except) + { + ex=except; + } + if(this.getType()==null) + { + if(ext) + parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! --- NoTypeDefError :-)"); + if(ex==null) + ex=new SCStatementException(); + SCExcept exc = new SCExcept(); + exc.set_error("Kein Typ vorhanden - NoTypeDefError"); + exc.set_statement("PostIncExpr"); + ex.addException(exc); + } + else + { + if(!this.getType().getName().equals("int")) + { + if (ext) + parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! ++ wird auf anderen Typ als int angewendet."); + SCExcept exc = new SCExcept(); + exc.set_error("++ Operator wird auf "+this.getType()+" angewendet."); + exc.set_statement("PostIncExpr"); + if(ex==null) + ex = new SCStatementException(); + ex.addException(exc); + } + } + if(ex!=null) + throw ex; + + } + // ino.end + + // ino.method.codegen.26043.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.26043.body + { + if(expr instanceof LocalOrFieldVar) { + String local_name = (String)((LocalOrFieldVar)expr).get_Name_Vector().lastElement(); + + int index = code.get_indexOf_Var(local_name); + if(index != -1) { + code.add_code(JVMCode.iinc); + code.add_code_byte(index); + code.add_code_byte(1); + } + else { + if(expr instanceof LocalOrFieldVar) { + LocalOrFieldVar local = (LocalOrFieldVar)expr; + Vector name_vector = local.get_Name_Vector(); + Vector type_vector = local.get_Type_Vector(); + String class_name = null; + String type = null; + for(int i=0; i < name_vector.size()-1; i++) { + local_name = (String)name_vector.elementAt(i); + type = JVMCode.get_codegen_Type((String)type_vector.elementAt(i), paralist); + + index = code.get_indexOf_Var(local_name); + if(index != -1) { // LocalVar + try{ + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload_n(local_type, index)); + } + catch(JVMCodeException e) { // out of nload_n + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload(local_type)); + code.add_code_byte((byte)index); + } + } + else { // FieldVar + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.getfield); + code.add_code_short(classfile.add_field_ref(local_name, class_name, type)); + } + class_name = (String)type_vector.elementAt(i); + } + + local_name = (String)name_vector.lastElement(); + index = classfile.add_field_ref(local_name, class_name, JVMCode.get_codegen_Type("int", paralist)); + + code.add_code(JVMCode.dup); + code.add_code(JVMCode.getfield); + code.add_code_short(index); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.iadd); + code.add_code(JVMCode.putfield); + code.add_code_short(index); + + } + } + } + else if(expr instanceof InstVar) { + InstVar instvar = (InstVar)expr; + String instvar_name = instvar.get_codegen_UsedId(); + int index = classfile.add_field_ref(instvar_name, null, null); + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.dup); + code.add_code(JVMCode.getfield); + code.add_code_short(index); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.iadd); + code.add_code(JVMCode.putfield); + code.add_code_short(index); + } + else throw new JVMCodeException("JVMCodeException: PostIncExpr: void codegen(ClassFile classfile, Code_attribute code)"); + } + // ino.end + + // ino.method.TRExp.26046.defdescription type=javadoc + /** + * Achtung Workaround: RefType "Integer" sollte irgendwann gegen BaseType + * IntegerType ausgetauscht werden. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.26046.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.26046.body + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr rufen: + // -------------------------- + CTripleSet exprSet = expr.TRExp(sigma, V, supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + Iterator exprIt = exprSet.getIterator(); + while(exprIt.hasNext()){ + CTriple exprTriple = exprIt.next(); + // -------------------------- + // ReturnType mit Integer unifizieren: + // -------------------------- + Vector> unifierPossibilities = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Integer",getOffset()), supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann + // anwenden und Triple hinzuf�gen: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + for(int i=0; i tripleIt = tripleSet.getIterator(); + while(tripleIt.hasNext()){ + tripleIt.next().setResultType(new Void(getOffset())); + } + return tripleSet; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26052.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26052.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/PreDecExpr.java b/src/mycompiler/mystatement/PreDecExpr.java new file mode 100755 index 000000000..9b98a6c73 --- /dev/null +++ b/src/mycompiler/mystatement/PreDecExpr.java @@ -0,0 +1,299 @@ +// ino.module.PreDecExpr.8648.package +package mycompiler.mystatement; +// ino.end +// ino.module.PreDecExpr.8648.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.PreDecExpr.26055.declaration +public class PreDecExpr extends UnaryExpr +// ino.end +// ino.class.PreDecExpr.26055.body +{ + // ino.method.PreDecExpr.26059.definition + public PreDecExpr(int offset,int variableLength) + // ino.end + // ino.method.PreDecExpr.26059.body + { + super(offset,variableLength); + } + // ino.end + + // ino.attribute.expr.26062.declaration + public Expr expr; + // ino.end + // ino.attribute.parserlog.26065.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + + // ino.method.set_Expr.26068.definition + public void set_Expr(Expr ex) + // ino.end + // ino.method.set_Expr.26068.body + { + this.expr = ex; + } + // ino.end + // ino.method.get_Name.26071.definition + public String get_Name() + // ino.end + // ino.method.get_Name.26071.body + { + return null; + } + // ino.end + + // ino.method.sc_check.26074.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.26074.body + { + SCStatementException ex=null; + if(ext) + parserlog.debug(" ---PreDecExpr---"); + try + { + expr.sc_check(classname,ch,bh,ext,parach,parabh); + this.setType(new Type(expr.getTypeName(),getOffset())); + } + catch (SCStatementException except) + { + ex=except; + } + if(this.getType()==null) + { + if(ext) + parserlog.debug("Semantik-Check hat einen Typ-Fehler gefunden!!! --- NoTypeDefError :-)"); + if(ex==null) + ex=new SCStatementException(); + SCExcept exc = new SCExcept(); + exc.set_error("Kein Typ vorhanden - NoTypeDefError"); + exc.set_statement("PostDecExpr"); + ex.addException(exc); + } + else + { + if(!this.getType().getName().equals("int")) + { + if (ext) + parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! -- wird auf anderen Typ als int angewendet."); + SCExcept exc = new SCExcept(); + exc.set_error("-- Operator wird auf "+this.getType()+" angewendet."); + exc.set_statement("PreDecExpr"); + if(ex==null) + ex = new SCStatementException(); + ex.addException(exc); + } + } + if(ex!=null) + throw ex; + } + // ino.end + + // ino.method.codegen.26077.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.26077.body + { + if(expr instanceof LocalOrFieldVar) { + String local_name = (String)((LocalOrFieldVar)expr).get_Name_Vector().lastElement(); + + int index = code.get_indexOf_Var(local_name); + if(index != -1) { + code.add_code(JVMCode.iinc); + code.add_code_byte(index); + code.add_code_byte(-1); + } + else { + if(expr instanceof LocalOrFieldVar) { + LocalOrFieldVar local = (LocalOrFieldVar)expr; + Vector name_vector = local.get_Name_Vector(); + Vector type_vector = local.get_Type_Vector(); + String class_name = null; + String type = null; + for(int i=0; i < name_vector.size()-1; i++) { + local_name = (String)name_vector.elementAt(i); + type = JVMCode.get_codegen_Type((String)type_vector.elementAt(i), paralist); + + index = code.get_indexOf_Var(local_name); + if(index != -1) { // LocalVar + try{ + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload_n(local_type, index)); + } + catch(JVMCodeException e) { // out of nload_n + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload(local_type)); + code.add_code_byte((byte)index); + } + } + else { // FieldVar + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.getfield); + code.add_code_short(classfile.add_field_ref(local_name, class_name, type)); + } + class_name = (String)type_vector.elementAt(i); + } + + local_name = (String)name_vector.lastElement(); + index = classfile.add_field_ref(local_name, class_name, JVMCode.get_codegen_Type("int", paralist)); + + code.add_code(JVMCode.dup); + code.add_code(JVMCode.getfield); + code.add_code_short(index); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.isub); + code.add_code(JVMCode.putfield); + code.add_code_short(index); + + } + } + } + else if(expr instanceof InstVar) { + InstVar instvar = (InstVar)expr; + String instvar_name = instvar.get_codegen_UsedId(); + int index = classfile.add_field_ref(instvar_name, null, null); + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.dup); + code.add_code(JVMCode.getfield); + code.add_code_short(index); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.isub); + code.add_code(JVMCode.putfield); + code.add_code_short(index); + } + else throw new JVMCodeException("JVMCodeException: PreDecExpr: void codegen(ClassFile classfile, Code_attribute code)"); + } + // ino.end + + // ino.method.TRExp.26080.defdescription type=javadoc + /** + * Achtung Workaround: RefType "Integer" sollte irgendwann gegen BaseType + * IntegerType ausgetauscht werden. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.26080.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.26080.body + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr rufen: + // -------------------------- + CTripleSet exprSet = expr.TRExp(sigma, V, supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + Iterator exprIt = exprSet.getIterator(); + while(exprIt.hasNext()){ + CTriple exprTriple = exprIt.next(); + // -------------------------- + // ReturnType mit Integer unifizieren: + // -------------------------- + Vector> unifierPossibilities = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Integer",getOffset()), supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann + // anwenden und Triple hinzuf�gen: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + for(int i=0; i tripleIt = tripleSet.getIterator(); + while(tripleIt.hasNext()){ + tripleIt.next().setResultType(new Void(getOffset())); + } + return tripleSet; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26086.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26086.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/PreIncExpr.java b/src/mycompiler/mystatement/PreIncExpr.java new file mode 100755 index 000000000..2a15b5654 --- /dev/null +++ b/src/mycompiler/mystatement/PreIncExpr.java @@ -0,0 +1,302 @@ +// ino.module.PreIncExpr.8649.package +package mycompiler.mystatement; +// ino.end +// ino.module.PreIncExpr.8649.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.Void; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.PreIncExpr.26089.declaration +public class PreIncExpr extends UnaryExpr +// ino.end +// ino.class.PreIncExpr.26089.body +{ + // ino.method.PreIncExpr.26093.definition + public PreIncExpr(int offset,int variableLength) + // ino.end + // ino.method.PreIncExpr.26093.body + { + super(offset,variableLength); + } + // ino.end + // ino.attribute.expr.26096.declaration + public Expr expr; + // ino.end + // ino.attribute.parserlog.26099.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + + + // ino.method.set_Expr.26102.definition + public void set_Expr(Expr ex) + // ino.end + // ino.method.set_Expr.26102.body + { + this.expr = ex; + } + // ino.end + + // ino.method.get_Name.26105.definition + public String get_Name() + // ino.end + // ino.method.get_Name.26105.body + { + return null; + } + // ino.end + + // ino.method.sc_check.26108.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.26108.body + { + SCStatementException ex=null; + if(ext) + parserlog.debug(" ---PreIncExpr---"); + try + { + expr.sc_check(classname,ch,bh,ext,parach,parabh); + this.setType(new Type(expr.getTypeName(),getOffset())); + } + catch (SCStatementException except) + { + ex=except; + } + if(this.getType().getName()==null) + { + if(ext) + parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! --- NoTypeDefError :-)"); + if(ex==null) + ex=new SCStatementException(); + SCExcept exc = new SCExcept(); + exc.set_error("Kein Typ vorhanden - NoTypeDefError"); + exc.set_statement("PreIncExpr"); + ex.addException(exc); + } + else + { + if(!this.getType().getName().equals("int")) + { + if (ext) + parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! -- wird auf anderen Typ als int angewendet."); + SCExcept exc = new SCExcept(); + exc.set_error("++ Operator wird auf "+this.getType()+" angewendet."); + exc.set_statement("PreIncExpr"); + if(ex==null) + ex = new SCStatementException(); + ex.addException(exc); + } + } + if(ex!=null) + throw ex; + } + // ino.end + + // ino.method.codegen.26111.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.26111.body + { + if(expr instanceof LocalOrFieldVar) { + String local_name = (String)((LocalOrFieldVar)expr).get_Name_Vector().lastElement(); + + int index = code.get_indexOf_Var(local_name); + if(index != -1) { + code.add_code(JVMCode.iinc); + code.add_code_byte(index); + code.add_code_byte(1); + } + else { + if(expr instanceof LocalOrFieldVar) { + LocalOrFieldVar local = (LocalOrFieldVar)expr; + Vector name_vector = local.get_Name_Vector(); + Vector type_vector = local.get_Type_Vector(); + String class_name = null; + String type = null; + for(int i=0; i < name_vector.size()-1; i++) { + local_name = (String)name_vector.elementAt(i); + type = JVMCode.get_codegen_Type((String)type_vector.elementAt(i), paralist); + + index = code.get_indexOf_Var(local_name); + if(index != -1) { // LocalVar + try{ + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload_n(local_type, index)); + } + catch(JVMCodeException e) { // out of nload_n + String local_type = code.get_TypeOf_Var(local_name).getName(); + code.add_code(JVMCode.nload(local_type)); + code.add_code_byte((byte)index); + } + } + else { // FieldVar + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.getfield); + code.add_code_short(classfile.add_field_ref(local_name, class_name, type)); + } + class_name = (String)type_vector.elementAt(i); + } + + local_name = (String)name_vector.lastElement(); + index = classfile.add_field_ref(local_name, class_name, JVMCode.get_codegen_Type("int", paralist)); + + code.add_code(JVMCode.dup); + code.add_code(JVMCode.getfield); + code.add_code_short(index); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.iadd); + code.add_code(JVMCode.putfield); + code.add_code_short(index); + + } + } + } + else if(expr instanceof InstVar) { + InstVar instvar = (InstVar)expr; + String instvar_name = instvar.get_codegen_UsedId(); + int index = classfile.add_field_ref(instvar_name, null, null); + code.add_code(JVMCode.aload_0); + code.add_code(JVMCode.dup); + code.add_code(JVMCode.getfield); + code.add_code_short(index); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.iadd); + code.add_code(JVMCode.putfield); + code.add_code_short(index); + } + else throw new JVMCodeException("JVMCodeException: PreIncExpr: void codegen(ClassFile classfile, Code_attribute code)"); + } + // ino.end + + // ino.method.TRExp.26114.defdescription type=javadoc + /** + * Achtung Workaround: RefType "Integer" sollte irgendwann gegen BaseType + * IntegerType ausgetauscht werden. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.26114.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.26114.body + { + CTripleSet returnSet = new CTripleSet(); + // -------------------------- + // TRExpr f�r Expr rufen: + // -------------------------- + CTripleSet exprSet = expr.TRExp(sigma, V, supportData); + // -------------------------- + // Alle Triple durchgehen: + // -------------------------- + Iterator exprIt = exprSet.getIterator(); + while(exprIt.hasNext()){ + CTriple exprTriple = exprIt.next(); + // -------------------------- + // ReturnType mit Integer unifizieren: + // -------------------------- + Vector> unifierPossibilities = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Integer",getOffset()), supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann + // anwenden und Triple hinzuf�gen: + // -------------------------- + if(unifierPossibilities.size()!=0){ + // -------------------------- + // Subset bauen: + // -------------------------- + CTripleSet subSet = new CTripleSet(); + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + for(int i=0; i tripleIt = tripleSet.getIterator(); + while(tripleIt.hasNext()){ + tripleIt.next().setResultType(new Void(getOffset())); + } + return tripleSet; + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26120.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26120.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + // TODO Auto-generated method stub + return null; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/Receiver.java b/src/mycompiler/mystatement/Receiver.java new file mode 100755 index 000000000..3835be2ba --- /dev/null +++ b/src/mycompiler/mystatement/Receiver.java @@ -0,0 +1,114 @@ +// ino.module.Receiver.8650.package +package mycompiler.mystatement; +// ino.end +// ino.module.Receiver.8650.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.myclass.Class; +import mycompiler.myexception.SCStatementException; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + + + + +// ino.class.Receiver.26123.declaration +public class Receiver +// ino.end +// ino.class.Receiver.26123.body +{ + // ino.attribute.expr.26126.declaration + private Expr expr; + // ino.end + // ino.attribute.parserlog.26129.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.Receiver.26132.defdescription type=javadoc + /** + * Autor: J�rg B�uerle + * @param expr + */ + // ino.end + // ino.method.Receiver.26132.definition + public Receiver(Expr expr) + // ino.end + // ino.method.Receiver.26132.body + { + this.expr = expr; + } + // ino.end + + // ino.method.sc_check.26135.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.26135.body + { + if(ext) + parserlog.debug(" ---Receiver---"); + SCStatementException except=null; + try + { + expr.sc_check(classname,ch,bh, ext,parach,parabh); + } + catch(SCStatementException ex) + { + except=ex; + } + if(except!=null) + throw except; + } + // ino.end + + // ino.method.get_Type.26138.definition + public String get_Type() + // ino.end + // ino.method.get_Type.26138.body + { + return expr.getTypeName(); + } + // ino.end + + // ino.method.set_Expr.26141.definition + public void set_Expr(Expr express) + // ino.end + // ino.method.set_Expr.26141.body + { + expr=express; + } + // ino.end + + // ino.method.get_Expr.26144.definition + public Expr get_Expr() + // ino.end + // ino.method.get_Expr.26144.body + { + return expr; + } + // ino.end + + // ino.method.toString.26147.defdescription type=javadoc + /** + *
Author: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.26147.definition + public String toString() + // ino.end + // ino.method.toString.26147.body + { + return expr.toString(); + } + // ino.end + + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult().attach(this.get_Expr().printJavaCode(resultSet)); + } +} +// ino.end diff --git a/src/mycompiler/mystatement/Return.java b/src/mycompiler/mystatement/Return.java new file mode 100755 index 000000000..d44e3839e --- /dev/null +++ b/src/mycompiler/mystatement/Return.java @@ -0,0 +1,206 @@ +// ino.module.Return.8651.package +package mycompiler.mystatement; +// ino.end +// ino.module.Return.8651.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.JavaCodeResult; +import typinferenz.SingleConstraint; +import typinferenz.ConstraintsSet; +import typinferenz.FreshTypeVariable; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.Return.26150.declaration +public class Return extends Statement +// ino.end +// ino.class.Return.26150.body +{ + // ino.method.Return.26154.definition + public Return(int offset,int variableLength) + // ino.end + // ino.method.Return.26154.body + { + super(offset,variableLength); + } + // ino.end + // ino.attribute.retexpr.26157.declaration + public Expr retexpr; + // ino.end + // ino.attribute.parserlog.26160.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + + // ino.method.sc_check.26163.definition + void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.26163.body + { + if(ext) + parserlog.debug(" ---Return---"); + SCStatementException excep=null; + if(ext) + parserlog.debug("Semantik-Check pr�ft Return-Anweisung"); + try + { + retexpr.sc_check(classname,ch,bh,ext, parach, parabh); + } + catch (SCStatementException ex) + { + excep=ex; + } + String gefordert; + String ist; + ist=get_Type(); + gefordert=(String)bh.get("###_Method_Ret_Type"); + parserlog.debug(ist+gefordert); + if(!ist.equals(gefordert)) + { + if(ext) + parserlog.error("FEHLER: R�ckgabewert hat anderen Typ als von Methode gefordert sc_check-->Return"); + SCExcept exc=new SCExcept(); + exc.set_error("R�ckgabewert hat anderen Typ als von Methode gefordert!"); + exc.set_statement("Return"); + if(excep==null) + excep = new SCStatementException(); + excep.addException(exc); + } + if(excep!=null) + throw excep; + } + // ino.end + + // ino.method.set_ReturnExpr.26166.definition + public Return set_ReturnExpr(Expr ret) + // ino.end + // ino.method.set_ReturnExpr.26166.body + { + this.retexpr=ret; + return this; + } + // ino.end + + // ino.method.get_Type.26169.definition + public String get_Type() + // ino.end + // ino.method.get_Type.26169.body + { + return retexpr.getTypeName(); + } + // ino.end + + // ino.method.codegen.26172.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.26172.body + { + retexpr.codegen(classfile, code, paralist); + code.add_code(JVMCode.nreturn(retexpr.getTypeName())); + } + // ino.end + + // ino.method.TRStatement.26175.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.22 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + * @throws CTypeReconstructionException + */ + // ino.end + // ino.method.TRStatement.26175.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + throws CTypeReconstructionException + // ino.end + // ino.method.TRStatement.26175.body + { + return retexpr.TRExp(sigma, V, supportData); + } + // ino.end + + // ino.method.toString.26178.definition + public String toString() + // ino.end + // ino.method.toString.26178.body + { + return type + " Return " + retexpr.toString(); + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26181.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26181.body + { + } + // ino.end + + public boolean addOffsetsToStatement(CTypeAssumption localAssumption, String NameVariable, boolean isMemberVariable) + { + retexpr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + return true; + } + + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + ret.add(this.retexpr.TYPEExpr(assumptions)); + //this.setTypeVariable(TypePlaceholder.fresh("Return Type")); + this.setTypeVariable(TypePlaceholder.fresh(this)); + ret.add(new SingleConstraint(retexpr.getTypeVariable(), this.getTypeVariable())); + return ret; + } + + public void replaceType(CReplaceTypeEvent e) { + super.replaceType(e); + } + + public int getTypeLineNumber() { + return 0; + } + + @Override + public String getTypeInformation(){ + String ret = this.getTypeVariable()+" :: (Return "+this.retexpr.getTypeInformation()+")"; + return ret; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult("return "); + ret.attach(this.retexpr.printJavaCode(resultSet)); + return ret.attach(";"); + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/Statement.java b/src/mycompiler/mystatement/Statement.java new file mode 100755 index 000000000..fff0111da --- /dev/null +++ b/src/mycompiler/mystatement/Statement.java @@ -0,0 +1,277 @@ +// ino.module.Statement.8652.package +package mycompiler.mystatement; +// ino.end +// ino.module.Statement.8652.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.Typable; +import typinferenz.TypeAssumptions; +import mycompiler.IItemWithOffset; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +// ino.end + + + + +// ino.class.Statement.26184.declaration +public abstract class Statement implements IItemWithOffset, Typable, ITypeReplacementListener +// ino.end +// ino.class.Statement.26184.body +{ + + // ino.attribute.offset.26188.declaration + private int offset; + // ino.end + // ino.attribute.variableLength.26191.declaration + private int variableLength; + // ino.end + + protected Type type; + + // ino.method.Statement.26194.definition + public Statement(int offset, int variableLength) + // ino.end + // ino.method.Statement.26194.body + { + this.offset=offset; + this.variableLength=variableLength; + } + // ino.end + + // ino.method.getOffset.26197.definition + public int getOffset() + // ino.end + // ino.method.getOffset.26197.body + { + return offset; + } + // ino.end + + // ino.method.getVariableLength.26200.definition + public int getVariableLength() + // ino.end + // ino.method.getVariableLength.26200.body + { + return variableLength; + } + // ino.end + + // ino.method.sc_check.26203.declaration + abstract void sc_check(Vector classlist, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException; + // ino.end + + + + // ino.method.codegen.26206.declaration + public abstract void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException; + // ino.end + + + + // ino.method.string_rec.26209.definition + static String string_rec(Hashtable ht) + // ino.end + // ino.method.string_rec.26209.body + { + String record=""; + if(ht != null){ + record=record.concat("["); + for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){ + String s = (String)k.nextElement(); + Object o = e.nextElement(); + + record=record.concat(" "+s); + + if(o instanceof Type){ + record=record.concat(" = "+((Type)o).getName()); + } + + else if(o instanceof Hashtable){ + record=record.concat("= "); + record=record.concat(string_rec((Hashtable)o)); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else if(o instanceof String){ + record=record.concat(" = "+o); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else record=("[FEHLER: string_rec: unbekannter Typ!!!!!!"); + } + record=record.concat("]"); + } + return(record); + } + // ino.end + + // ino.method.string_rec.26212.definition + static String string_rec(Vector v) + // ino.end + // ino.method.string_rec.26212.body + { + String record=""; + record=record.concat("{"); + for(Enumeration e=v.elements();e.hasMoreElements();){ + Type t = (Type)e.nextElement(); + record=record.concat(" "+t.getName()); + + if(e.hasMoreElements()) + record=record.concat(","); + } + record=record.concat("}"); + return(record); + } + // ino.end + // ino.method.string_rec.26215.definition + static String string_rec(String st, Hashtable ht) + // ino.end + // ino.method.string_rec.26215.body + { + String record=""; + record=record.concat(st); + record=record.concat("["); + for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){ + String s = (String)k.nextElement(); + Object o = e.nextElement(); + + record=record.concat(" "+s); + + if(o instanceof Type){ + record=record.concat(" = "+((Type)o).getName()); + } + + else if(o instanceof Hashtable){ + record=record.concat("= "); + record=record.concat(string_rec((Hashtable)o)); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else if(o instanceof String){ + record=record.concat(" = "+o); + if(e.hasMoreElements()) + record=record.concat(", "); + } + else record=("[FEHLER: string_rec: unbekannter Typ!!!!!!"); + } + record=record.concat("]"); + return(record); + } + // ino.end + + // ino.method.string_rec.26218.definition + static String string_rec(String st,Vector v) + // ino.end + // ino.method.string_rec.26218.body + { + + String record=(st); + record=record.concat("{"); + for(Enumeration e=v.elements();e.hasMoreElements();){ + Type t = (Type)e.nextElement(); + record=record.concat(" "+t.getName()); + if(e.hasMoreElements()) + record=record.concat(", "); + } + record=record.concat("}"); + return(record); + } + // ino.end + + // ino.method.TRStatement.26221.declaration + public abstract CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + throws CTypeReconstructionException; + // ino.end + + + + // ino.method.wandleRefTypeAttributes2GenericAttributes.26224.declaration + public abstract void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters); + // ino.end + + public abstract boolean addOffsetsToStatement(CTypeAssumption localAssumption, String NameVariable, boolean isMemberVariable); + + /** + * @author AI10023 - Andreas Stadelmeier + * Implementierung des Java 8 - Typinferenzalgorithmus von Martin Plümicke + * Jedes Statement wird im Zuge des Algorithmus durch die TYPEExpr-Funktion angesprochen. + */ + public abstract ConstraintsSet TYPEStmt(TypeAssumptions assumptions); + + /** + * @author AI10023 - Andreas Stadelmeier + * Jedem Statement und jeder Expression wird im Zuge des Typinferenzalgorithmus eine Typvariable zugewiesen. + * Daher müssen alle Statements und Expressions die Methoden setTypeVariable und getTypeVariable implementieren. + */ + public void setTypeVariable(Type typ){ + this.setType(typ); + } + public Type getTypeVariable(){ + return type; + } + + /** + * @author Andreas Stadelmeier, a10023 + * Sollte von jedem Statement überschrieben werden. + * Liefert Informationen zum Statment und dessen Typ. + * @return + */ + public String getTypeInformation(){ + return this.printJavaCode(new ResultSet(new Vector()))+" : "+type.toString(); + } + + + /** + *
Author: J�rg B�uerle + * Verschoben aus ExprStmt von Andreas Stadelmeier, a10023 + * @param t + */ + public void setType(Type t) + { + if(this.getTypeVariable() instanceof TypePlaceholder){ + ((TypePlaceholder)this.getTypeVariable()).removeReplacementListener(this); + } + if(t instanceof TypePlaceholder){ + ((TypePlaceholder)t).addReplacementListener(this); + } + this.type=t; + } + + public void replaceType(CReplaceTypeEvent e) + { + if(getTypeVariable() instanceof TypePlaceholder){ + ((TypePlaceholder)getTypeVariable()).removeReplacementListener(this); + } + this.setType(e.getNewType()); + } + + + public abstract JavaCodeResult printJavaCode(ResultSet resultSet); + + +} +// ino.end diff --git a/src/mycompiler/mystatement/StringLiteral.java b/src/mycompiler/mystatement/StringLiteral.java new file mode 100755 index 000000000..cff02b38c --- /dev/null +++ b/src/mycompiler/mystatement/StringLiteral.java @@ -0,0 +1,147 @@ +// ino.module.StringLiteral.8653.package +package mycompiler.mystatement; +// ino.end +// ino.module.StringLiteral.8653.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.mytype.CharacterType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.StringLiteral.26227.declaration +public class StringLiteral extends Literal +// ino.end +// ino.class.StringLiteral.26227.body +{ + // ino.attribute.string.26231.declaration + private String string; + // ino.end + + // ino.attribute.parserlog.26234.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.StringLiteral.26237.definition + public StringLiteral() + // ino.end + // ino.method.StringLiteral.26237.body + { + super(-1,-1); + // #JB# 20.04.2005 + // ########################################################### + this.setType(new RefType("java.lang.String",getOffset())); + //this.setType(new Type("String")); + // ########################################################### + } + // ino.end + + // ino.method.sc_check.26240.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + // ino.end + // ino.method.sc_check.26240.body + { + if(ext) + parserlog.debug(" ---StringLiteral---"); + } + // ino.end + + // ino.method.set_String.26243.definition + public void set_String( String s) + // ino.end + // ino.method.set_String.26243.body + { + this.string = s; + } + // ino.end + + // ino.method.get_Name.26246.definition + public String get_Name() + // ino.end + // ino.method.get_Name.26246.body + { + return null; + } + // ino.end + + // ino.method.codegen.26249.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.26249.body + { + int index = classfile.add_CONSTANT_String_info(string); + if(index < 256) { + code.add_code(JVMCode.ldc); + code.add_code_byte((byte)index); + } + else { + code.add_code(JVMCode.ldc_w); + code.add_code_short((short)index); + } + } + // ino.end + + // ino.method.ConstantCodegen.26252.definition + public short ConstantCodegen(ClassFile classfile) + throws JVMCodeException + // ino.end + // ino.method.ConstantCodegen.26252.body + { + return (short) classfile.add_CONSTANT_String_info(string); + } + // ino.end + + + // ino.method.TRStatement.26255.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.26255.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26258.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26258.body + { + } + // ino.end + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + this.set_Type(new RefType("String",0)); + return new ConstraintsSet(); + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("\""+this.string+"\""); + } + + +} +// ino.end diff --git a/src/mycompiler/mystatement/This.java b/src/mycompiler/mystatement/This.java new file mode 100755 index 000000000..8a1664f0a --- /dev/null +++ b/src/mycompiler/mystatement/This.java @@ -0,0 +1,187 @@ +// ino.module.This.8654.package +package mycompiler.mystatement; +// ino.end +// ino.module.This.8654.import +import java.util.Hashtable; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCStatementException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.ConstraintsSet; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + +// ino.class.This.26261.declaration +public class This extends Expr +// ino.end +// ino.class.This.26261.body +{ + // ino.method.This.26265.definition + public This(int offset,int variableLength) + // ino.end + // ino.method.This.26265.body + { + super(offset,variableLength); + } + // ino.end + + // ino.attribute.arglist.26268.declaration + public ArgumentList arglist; + // ino.end + + // ino.attribute.parserlog.26271.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + + // ino.method.set_ArgumentList.26274.definition + public void set_ArgumentList(ArgumentList al) + // ino.end + // ino.method.set_ArgumentList.26274.body + { + this.arglist = al; + } + // ino.end + + public ArgumentList getArgumentList() + { + return this.arglist; + } + + // ino.method.set_UsedId.26277.definition + public void set_UsedId(UsedId ui) + // ino.end + // ino.method.set_UsedId.26277.body + { + this.usedid = ui; + } + // ino.end + + + // ino.method.sc_check.26280.definition + public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.26280.body + { + if(ext) + parserlog.debug(" ---This---"); + } + // ino.end + + // ino.method.codegen.26283.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.26283.body + { + code.add_code(JVMCode.aload_0); + } + // ino.end + + // ino.method.get_Name.26286.definition + public String get_Name() + // ino.end + // ino.method.get_Name.26286.body + { return null; } + // ino.end + + // ino.method.TRExp.26289.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.35 von Martin Pl�micke + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRExp.26289.definition + public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRExp.26289.body + { + CTripleSet ret = new CTripleSet(); + RefType newType; + Type supportDataType=supportData.getCurrentClassType(); + if(supportDataType instanceof RefType){ + newType=(RefType)supportDataType; + }else{ + newType=new RefType(supportData.getCurrentClass(),getOffset()); + } + this.type=newType; + ret.addElement(new CTriple(sigma, newType,V)); + return ret; + } + // ino.end + + // ino.method.TRStatement.26292.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.26292.body + { + throw CTypeReconstructionException.createNotImplementedException(); + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.26295.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26295.body + { + } + // ino.end + + public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable) + { + if(this.arglist.expr!=null){ + for(Expr n : this.arglist.expr) + { + n.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + }} + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + //this.set_Type(new); + this.setTypeVariable(assumptions.getThisValue());//Die Assumption für this als TypeVariable setzen. + return ret; + } + + public String toString() + // ino.end + // ino.method.toString.25738.body + { + //return receiver/*.toString()*/ + " " + usedid.toString(); + return type + " (" + "this" +"(" + this.getArgumentList() + "))"; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("this"); + } + +} +// ino.end diff --git a/src/mycompiler/mystatement/UnaryExpr.java b/src/mycompiler/mystatement/UnaryExpr.java new file mode 100755 index 000000000..6b990df1b --- /dev/null +++ b/src/mycompiler/mystatement/UnaryExpr.java @@ -0,0 +1,33 @@ +// ino.module.UnaryExpr.8655.package +package mycompiler.mystatement; +// ino.end +// ino.module.UnaryExpr.8655.import +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.myexception.JVMCodeException; +// ino.end + + + + +// ino.class.UnaryExpr.26298.declaration +public abstract class UnaryExpr extends Expr +// ino.end +// ino.class.UnaryExpr.26298.body +{ + // ino.method.UnaryExpr.26302.definition + public UnaryExpr(int offset,int variableLength) + // ino.end + // ino.method.UnaryExpr.26302.body + { + super(offset,variableLength); + } + // ino.end + + // ino.method.codegen.26305.declaration + public abstract void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException; + // ino.end +} +// ino.end diff --git a/src/mycompiler/mystatement/UnaryMinus.java b/src/mycompiler/mystatement/UnaryMinus.java new file mode 100755 index 000000000..cad939870 --- /dev/null +++ b/src/mycompiler/mystatement/UnaryMinus.java @@ -0,0 +1,30 @@ +// ino.module.UnaryMinus.8656.package +package mycompiler.mystatement; +// ino.end + +// ino.module.UnaryMinus.8656.import +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myexception.JVMCodeException; +// ino.end + +// ino.class.UnaryMinus.26308.declaration +public class UnaryMinus +// ino.end +// ino.class.UnaryMinus.26308.body +{ + // ino.method.codegen.26311.definition + public void codegen(ClassFile classfile, CodeAttribute code, String type, boolean neg) + throws JVMCodeException + // ino.end + // ino.method.codegen.26311.body + { + if(!neg) code.add_code(JVMCode.nneg(type)); + } + // ino.end + + + +} +// ino.end diff --git a/src/mycompiler/mystatement/UnaryNot.java b/src/mycompiler/mystatement/UnaryNot.java new file mode 100755 index 000000000..c2cb7b0ce --- /dev/null +++ b/src/mycompiler/mystatement/UnaryNot.java @@ -0,0 +1,44 @@ +// ino.module.UnaryNot.8657.package +package mycompiler.mystatement; +// ino.end + +// ino.module.UnaryNot.8657.import +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myexception.JVMCodeException; +// ino.end + +// ino.class.UnaryNot.26314.declaration +public class UnaryNot +// ino.end +// ino.class.UnaryNot.26314.body +{ + // ino.method.codegen.26317.definition + public void codegen(ClassFile classfile, CodeAttribute code, boolean sw) + throws JVMCodeException + // ino.end + // ino.method.codegen.26317.body + { + if(!sw)code.add_code(JVMCode.ifne); + else code.add_code(JVMCode.ifeq); + code.add_code_short((short)7); + code.add_code(JVMCode.iconst_1); + code.add_code(JVMCode.goto_); + code.add_code_short((short)4); + code.add_code(JVMCode.iconst_0); + } + // ino.end + + // ino.method.if_codegen.26320.definition + public void if_codegen(ClassFile classfile, CodeAttribute code, boolean sw) + throws JVMCodeException + // ino.end + // ino.method.if_codegen.26320.body + { + if(!sw) code.add_code(JVMCode.ifne); + else code.add_code(JVMCode.ifeq); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mystatement/UnaryPlus.java b/src/mycompiler/mystatement/UnaryPlus.java new file mode 100755 index 000000000..5fbdddf32 --- /dev/null +++ b/src/mycompiler/mystatement/UnaryPlus.java @@ -0,0 +1,11 @@ +// ino.module.UnaryPlus.8658.package +package mycompiler.mystatement; +// ino.end +// ino.class.UnaryPlus.26323.declaration +public class UnaryPlus +// ino.end +// ino.class.UnaryPlus.26323.body +{ + +} +// ino.end diff --git a/src/mycompiler/mystatement/WhileStmt.java b/src/mycompiler/mystatement/WhileStmt.java new file mode 100755 index 000000000..200dd53ab --- /dev/null +++ b/src/mycompiler/mystatement/WhileStmt.java @@ -0,0 +1,315 @@ +// ino.module.WhileStmt.8659.package +package mycompiler.mystatement; +// ino.end +// ino.module.WhileStmt.8659.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.ClassFile; +import mycompiler.mybytecode.CodeAttribute; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.Class; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.JVMCodeException; +import mycompiler.myexception.SCExcept; +import mycompiler.myexception.SCStatementException; +import mycompiler.myoperator.LogOp; +import mycompiler.myoperator.Operator; +import mycompiler.myoperator.RelOp; +import mycompiler.mytype.BooleanType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSupportData; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.unify.Unify; +import org.apache.log4j.Logger; +// ino.end + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.JavaCodeResult; +import typinferenz.SingleConstraint; +import typinferenz.ConstraintsSet; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; + + + + +// ino.class.WhileStmt.26326.declaration +public class WhileStmt extends Statement +// ino.end +// ino.class.WhileStmt.26326.body +{ + // ino.method.WhileStmt.26330.definition + public WhileStmt(int offset, int variableLength) + // ino.end + // ino.method.WhileStmt.26330.body + { + super(offset,variableLength); + } + // ino.end + + // ino.attribute.expr.26333.declaration + public Expr expr; + // ino.end + // ino.attribute.loop_block.26336.declaration + public Statement loop_block; + // ino.end + + // ino.attribute.parserlog.26339.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + + // ino.method.set_Expr.26342.definition + public void set_Expr(Expr exp) + // ino.end + // ino.method.set_Expr.26342.body + { + this.expr = exp; + } + // ino.end + + // ino.method.set_Loop_block.26345.definition + public void set_Loop_block(Statement blk) + // ino.end + // ino.method.set_Loop_block.26345.body + { + this.loop_block = blk; + } + // ino.end + + // ino.method.sc_check.26348.definition + void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) + throws SCStatementException + // ino.end + // ino.method.sc_check.26348.body + { + if(ext) + parserlog.debug(" ---WhileStmt---"); + SCStatementException exc=null; + if(ext) + { + parserlog.debug("Semantik-Check ist in der Klasse WhileStmt"); + parserlog.debug("Semantik-Check ueberprueft While-Bedingung-Expression."); + } + try + { + expr.sc_check(classname,ch,bh,ext,parach,parabh); + } + catch (SCStatementException ex) + { + exc=ex; + } + try + { + loop_block.sc_check(classname,ch,(Hashtable) bh.clone(),ext,parach, (Hashtable)parabh.clone()); + } + catch (SCStatementException ex) + { + if(exc==null) + exc=ex; + else + { + Vector v; + SCExcept hilf; + v=ex.get_exlist(); + for(Enumeration el=v.elements();el.hasMoreElements();) + { + hilf=el.nextElement(); + exc.addException(hilf); + } + } + } + if(exc!=null) + throw exc; + } + // ino.end + + // ino.method.codegen.26351.definition + public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.codegen.26351.body + { + if(loop_block!=null && expr!=null) { + code.add_code(JVMCode.goto_); + int breakpoint = code.get_code_length(); + code.add_code_short(0); + loop_block.codegen(classfile, code, paralist); + code.set_code_short(code.get_code_length() + 1 - breakpoint, breakpoint); + + loop_codegen(classfile, code, breakpoint, false, paralist); + } + } + // ino.end + + // ino.method.loop_codegen.26354.definition + public void loop_codegen(ClassFile classfile, CodeAttribute code, int breakpoint, boolean not, Vector paralist) + throws JVMCodeException + // ino.end + // ino.method.loop_codegen.26354.body + { + if(expr instanceof NotExpr) { + expr = ((NotExpr)expr).get_Expr(); + loop_codegen(classfile, code, breakpoint, !not, paralist); + } + else if(expr instanceof Binary) { + Operator op = ((Binary)expr).get_Operator(); + if(op instanceof LogOp) ((LogOp)op).loop_codegen(classfile, code, expr, breakpoint, !not, paralist); + else if(op instanceof RelOp) { + Expr expr1 = ((Binary)expr).get_Expr1(); + Expr expr2 = ((Binary)expr).get_Expr2(); + expr1.codegen(classfile, code, paralist); + expr2.codegen(classfile, code, paralist); + + if(expr1 instanceof Null || expr2 instanceof Null) ((RelOp)op).if_codegen(classfile, code, "null", !not); + else ((RelOp)op).if_codegen(classfile, code, expr1.getTypeName(), !not); + + code.add_code_short(breakpoint + 3 - code.get_code_length()); + } + else throw new JVMCodeException("JVMCodeException: WhileStmt: void loop_codegen(ClassFile classfile, Code_attribute code, int breakpoint, boolean not)"); + } + else { + expr.codegen(classfile, code, paralist); + if(!not) code.add_code(JVMCode.ifne); + else code.add_code(JVMCode.ifeq); + code.add_code_short(breakpoint + 3 - code.get_code_length()); + } + } + // ino.end + + // ino.method.TRStatement.26357.defdescription type=javadoc + /** + * Implementierung des Algorithmus 5.23 von Martin Pl�micke + *
Achtung Workaround: RefType "Boolean" muss noch durch BaseType + * "BooleanType" ersetzt werden. + *
Author: J�rg B�uerle + * @param sigma + * @param V + * @param supportData + * @return + */ + // ino.end + // ino.method.TRStatement.26357.definition + public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) + // ino.end + // ino.method.TRStatement.26357.body + { + CTripleSet returnSet = new CTripleSet(); + CTripleSet tripleSet = expr.TRExp(sigma, V, supportData); + Iterator exprTIt = tripleSet.getIterator(); + while(exprTIt.hasNext()){ + CTriple exprTriple = exprTIt.next(); + // -------------------------- + // ReturnType mit Boolean unifizieren: + // -------------------------- + Vector> unifierPossibilities1 = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Boolean",getOffset()), supportData.getFiniteClosure()); + // -------------------------- + // Wenn Unifier vorhanden, dann anwenden: + // -------------------------- + if(unifierPossibilities1.size()!=0){ + // -------------------------- + // Alle m�glichen Unifier anwenden: + // -------------------------- + + int successfulls=0; + Vector exceptions=new Vector(); + + for(int i=0; iAuthor: Martin Pl�micke + * @return + */ + // ino.end + // ino.method.toString.26360.definition + public String toString() + // ino.end + // ino.method.toString.26360.body + { + return "WHILE " + loop_block.toString(); + } + // ino.end + + // ino.method.wandleRefTypeAttributes2GenericAttributes.26363.definition + public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) + // ino.end + // ino.method.wandleRefTypeAttributes2GenericAttributes.26363.body + { + if(loop_block!=null){ + loop_block.wandleRefTypeAttributes2GenericAttributes(paralist,genericMethodParameters); + } + + } + // ino.end + + public boolean addOffsetsToStatement(CTypeAssumption localAssumption, String NameVariable, boolean isMemberVariable) + { + expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); + loop_block.addOffsetsToStatement(localAssumption,NameVariable,isMemberVariable); + return true; + } + + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { + ConstraintsSet ret = new ConstraintsSet(); + ret.add(expr.TYPEExpr(assumptions)); + SingleConstraint exprMustBeBool = new SingleConstraint(expr.getTypeVariable(), new RefType("boolean", 0)); // while(expr){}; expr <. boolean + ret.add(exprMustBeBool); + ret.add(this.loop_block.TYPEStmt(assumptions)); + this.setTypeVariable(loop_block.getTypeVariable()); + return ret; + } + + public void replaceType(CReplaceTypeEvent e) { + // TODO Auto-generated method stub + throw new NotImplementedException(); + } + + public int getTypeLineNumber() { + throw new NotImplementedException(); + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult().attach("while(").attach(this.expr.printJavaCode(resultSet)).attach(")").attach(this.loop_block.printJavaCode(resultSet)); + } +} +// ino.end diff --git a/src/mycompiler/mytest/APITest.java b/src/mycompiler/mytest/APITest.java new file mode 100755 index 000000000..eade20e6a --- /dev/null +++ b/src/mycompiler/mytest/APITest.java @@ -0,0 +1,18 @@ +package mycompiler.mytest; + +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; + +public class APITest { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + MyCompilerAPI m_compilerApi = MyCompiler.getAPI(); + m_compilerApi.init(); + } + +} diff --git a/src/mycompiler/mytest/CByteCodeTest.java b/src/mycompiler/mytest/CByteCodeTest.java new file mode 100755 index 000000000..65c14f279 --- /dev/null +++ b/src/mycompiler/mytest/CByteCodeTest.java @@ -0,0 +1,58 @@ +// ino.module.CByteCodeTest.8661.package +package mycompiler.mytest; +// ino.end + +// ino.module.CByteCodeTest.8661.import +import java.io.File; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +// ino.end + +// ino.class.CByteCodeTest.26367.description type=javadoc +/** + * Testklasse zum Generieren des ByteCode. + * @author scju + */ +// ino.end +// ino.class.CByteCodeTest.26367.declaration +public class CByteCodeTest +// ino.end +// ino.class.CByteCodeTest.26367.body +{ + + // ino.method.main.26370.definition + public static void main(String[] args) + throws Exception + // ino.end + // ino.method.main.26370.body + { + MyCompilerAPI compiler = MyCompiler.getAPI(); + + // Ausgabeverzeichnis festlegen + compiler.setOutputDir("Bytecode/"); + + // Parsen der Klasse + compiler.parse(new File(args[0])); + + // Typ-Rekonstruktion + Vector resultSet = compiler.typeReconstruction(); + if ((resultSet != null) && (resultSet.size() > 0)) { + CTypeReconstructionResult onePossibility = resultSet.firstElement(); + Iterator substIt = onePossibility.getSubstitutions().getIterator(); + while(substIt.hasNext()){ + CSubstitution subst = (CSubstitution)substIt.next(); + // Substition machen + subst.execute(); + } + } + + // Code generieren + compiler.codeGeneration(); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytest/CInferenceTest.java b/src/mycompiler/mytest/CInferenceTest.java new file mode 100755 index 000000000..629694740 --- /dev/null +++ b/src/mycompiler/mytest/CInferenceTest.java @@ -0,0 +1,103 @@ +// ino.module.CInferenceTest.8662.package +package mycompiler.mytest; +// ino.end + +// ino.module.CInferenceTest.8662.import +import java.io.File; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.CInferenceTest.26373.description type=javadoc +/** + * Testklasse fr die Typinferenz + * @author Timo Holzherr + */ +// ino.end +// ino.class.CInferenceTest.26373.declaration +public class CInferenceTest +// ino.end +// ino.class.CInferenceTest.26373.body +{ + + // ino.attribute.inferencelog.26376.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + + // ino.method.main.26379.definition + public static void main(String[] args) + throws Exception + // ino.end + // ino.method.main.26379.body + { + MyCompilerAPI compiler = MyCompiler.getAPI(); + try{ + + ///////////////////////// + // Parsen: + ///////////////////////// + + //1. Argument: zu kompilierende Datei + compiler.parse(new File(args[0])); + + MyCompiler.getAPI().setOutputDir("Bytecode/"); + + //compiler.semanticCheck(); + + ///////////////////////// + // Typrekonstruktion: + ///////////////////////// + Vector resultSet = compiler.typeReconstruction(); + ///////////////////////// + // Ausgabe: + ///////////////////////// + + + if(resultSet==null||resultSet.size()==0){ + inferencelog.error("Das Resultset ist leer!!!"); + System.exit(1); + } + + // if(true)System.exit(0); + CTypeReconstructionResult onePossibility = resultSet.firstElement(); + Iterator substIt = onePossibility.getSubstitutions().getIterator(); + while(substIt.hasNext()){ + CSubstitution subst = (CSubstitution)substIt.next(); + /*Vector lineNumbers = ((TypePlaceholder)subst.getTypeVar()).getLineNumbers(); + String s = new String(); + for(int l=0; l resultSet = compiler.typeReconstruction(); + ///////////////////////// + // Ausgabe: + ///////////////////////// + CTypeReconstructionResult onePossibility = resultSet.firstElement(); + Iterator substIt = onePossibility.getSubstitutions().getIterator(); + while(substIt.hasNext()){ + CSubstitution subst = (CSubstitution)substIt.next(); + Vector lineNumbers = ((TypePlaceholder)subst.getTypeVar()).getLineNumbers(); + String s = new String(); + for(int l=0; l resultSet = compiler.typeReconstruction(); + ///////////////////////// + // Ausgabe: + ///////////////////////// + + //test + SourceFile file = compiler.getSyntaxTree(); + FC_TTO fc_tto = file.makeFC(); + for(Pair p : fc_tto.getFC()) + { + if(p.TA1 instanceof RefType && ((RefType)p.TA1).get_ParaList() != null) + MyCompiler.wandleGeneric2RefType(((RefType)p.TA1).get_ParaList(),fc_tto.getClasses()); + + if(p.TA2 instanceof RefType && ((RefType)p.TA2).get_ParaList() != null) + MyCompiler.wandleGeneric2RefType(((RefType)p.TA2).get_ParaList(),fc_tto.getClasses()); + } + for(Pair p : ((MyCompiler)compiler).testPair) + { + RefType TA1 = (RefType)p.TA1; + RefType TA2 = (RefType)p.TA2; + MyCompiler.wandleGeneric2RefType(TA1.get_ParaList(),fc_tto.getClasses()); + MyCompiler.wandleGeneric2RefType(TA2.get_ParaList(),fc_tto.getClasses()); + + //Vector smallers = Unify.smaller(TA2,fc_tto); + //Vector greaters = Unify.greater(TA2,fc_tto); + MyCompiler.makeGenericTypeVars2TypePlaceHolders(TA2); + MyCompiler.makeGenericTypeVars2TypePlaceHolders(TA1); + } + Vector> unifyers = Unify.unify(((MyCompiler)compiler).testPair,fc_tto); + + //Vector> testUni = Unify.unify(TypePlaceholder.fresh(),TypePlaceholder.fresh(),fc_tto); + /* + if(resultSet==null||resultSet.size()==0){ + //inferencelog.error("Das Resultset ist leer!!!"); + System.exit(1); + }*/ + + // inferencelog.debug("========FERTIG========"); + + compiler.codeGeneration(); + + + }catch(CTypeReconstructionException tre){ + tre.printStackTrace(); + }catch(Exception e){ + e.printStackTrace(); + } + } +} diff --git a/src/mycompiler/mytest/CompilerTestCase.java b/src/mycompiler/mytest/CompilerTestCase.java new file mode 100755 index 000000000..64f309172 --- /dev/null +++ b/src/mycompiler/mytest/CompilerTestCase.java @@ -0,0 +1,162 @@ +// ino.module.CompilerTestCase.8663.package +package mycompiler.mytest; +// ino.end + +// ino.module.CompilerTestCase.8663.import +import java.io.File; +import java.util.Iterator; +import java.util.Vector; +import junit.framework.TestCase; +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import org.apache.log4j.FileAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +// ino.end + + +// ino.class.CompilerTestCase.26382.description type=javadoc +/** + * Testet den Compiler mit dem angegebenen JAV-File. + * @author SCJU + * + */ +// ino.end +// ino.class.CompilerTestCase.26382.declaration +public class CompilerTestCase extends TestCase +// ino.end +// ino.class.CompilerTestCase.26382.body +{ + + // ino.attribute.javFile.26386.declaration + protected File javFile; + // ino.end + // ino.attribute.compiler.26389.declaration + protected MyCompilerAPI compiler = MyCompiler.getAPI(); + // ino.end + + // ino.method.CompilerTestCase.26392.definition + public CompilerTestCase(String javFile, String name) + // ino.end + // ino.method.CompilerTestCase.26392.body + { + this.javFile = new File(javFile); + setName(name); + } + // ino.end + + // ino.method.CompilerTestCase.26395.definition + public CompilerTestCase(String javFile) + // ino.end + // ino.method.CompilerTestCase.26395.body + { + this.javFile = new File(javFile); + setName(this.javFile.getName()); + } + // ino.end + + + // ino.method.runTest.26398.definition + protected void runTest() + throws Throwable + // ino.end + // ino.method.runTest.26398.body + { + // Testablauf. Tritt eine Exception auf, + // schlaegt der Test fehl. + parseFile(); + typeReconstruction(); + codeGeneration(); + } + // ino.end + + // ino.method.parseFile.26401.definition + protected void parseFile() + throws Throwable + // ino.end + // ino.method.parseFile.26401.body + { + // Parsen der Klasse + compiler.parse(javFile); + } + // ino.end + + // ino.method.typeReconstruction.26404.definition + protected void typeReconstruction() + throws Exception + // ino.end + // ino.method.typeReconstruction.26404.body + { + // Typ-Rekonstruktion + Vector resultSet = compiler.typeReconstruction(); + // Keine Typ-Rekonstruktion erforderlich + if (resultSet == null || resultSet.size() == 0) throw new Exception("Typrekonstruktion nicht durchfuehrbar!"); + CTypeReconstructionResult onePossibility = resultSet.firstElement(); + Iterator substIt = onePossibility.getSubstitutions().getIterator(); + while(substIt.hasNext()){ + CSubstitution subst = (CSubstitution)substIt.next(); + // Substition machen + subst.execute(); + } + } + // ino.end + + // ino.method.codeGeneration.26407.definition + protected void codeGeneration() + throws Exception + // ino.end + // ino.method.codeGeneration.26407.body + { + // Code generieren + compiler.codeGeneration(); + } + // ino.end + + // ino.method.setUp.26410.definition + protected void setUp() + throws Exception + // ino.end + // ino.method.setUp.26410.body + { + super.setUp(); + + // Setup fuer Log4J + // Logfiles werden im Ordner testResults gespeichert + // Der Dateiname ist der Klassename plus .log + String logFile = "testResults/"+ javFile.getName() + ".log"; + + File f = new File(logFile); // Altes Logfile loeschen + f.delete(); + + // Ausgabeoptionen fuer die Logger + PatternLayout pl = new PatternLayout("%-15C{1} %-5p [%-9c] %m%n"); + FileAppender fa = new FileAppender(pl, logFile); + + // Die Einstellungen jedes Loggers veraendern + ModifyLogger("parser", Level.ALL, fa); + ModifyLogger("inference", Level.INFO, fa); + ModifyLogger("codegen", Level.ALL, fa); + ModifyLogger("bytecode", Level.ALL, fa); + } + // ino.end + + // ino.method.ModifyLogger.26413.defdescription type=line + // Veraendert die Ausgabeoptionen des angegebenen Loggers + // ino.end + // ino.method.ModifyLogger.26413.definition + protected void ModifyLogger(String strlogger, Level lv, FileAppender fa) + // ino.end + // ino.method.ModifyLogger.26413.body + { + Logger lg = Logger.getLogger(strlogger); + + lg.setLevel(lv); + lg.removeAllAppenders(); + lg.addAppender(fa); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytest/JUnitTests.java b/src/mycompiler/mytest/JUnitTests.java new file mode 100755 index 000000000..e602650bf --- /dev/null +++ b/src/mycompiler/mytest/JUnitTests.java @@ -0,0 +1,98 @@ +// ino.module.JUnitTests.8665.package +package mycompiler.mytest; +// ino.end + +// ino.module.JUnitTests.8665.import +import junit.framework.Test; +import junit.framework.TestSuite; +import mycompiler.MyCompiler; +// ino.end + +// ino.class.JUnitTests.26425.description type=javadoc +/** + * Erstellt eine JUnit-Testsuite, die saemtliche Testcases enthaelt und + * ausfuehrt. + * @author SCJU + * + */ +// ino.end +// ino.class.JUnitTests.26425.declaration +public class JUnitTests +// ino.end +// ino.class.JUnitTests.26425.body +{ + + + // ino.method.main.26428.defdescription type=line + // Aufruf ist auch als normale Anwendung moeglich. + // In Eclipse bietet sich allerdings eine Run-Config + // als JUnit-Test an! + // ino.end + // ino.method.main.26428.definition + public static void main(String[] args) + // ino.end + // ino.method.main.26428.body + { + junit.textui.TestRunner.run(JUnitTests.suite()); + } + // ino.end + + // ino.method.suite.26431.definition + public static Test suite() + // ino.end + // ino.method.suite.26431.body + { + TestSuite suite = new TestSuite("Teste Usecases for Compiler ..."); + //$JUnit-BEGIN$ + + + MyCompiler.getAPI().setOutputDir("Bytecode/"); + + + + // DER WICHTIGSTE + suite.addTest(new CompilerTestCase("examples/bajo1_usecases/Matrix.jav")); + + // Usecases PL + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseOne_pl.jav")); + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseTwo_pl.jav")); + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseThree_pl.jav")); + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseFour_pl.jav")); + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseFive_pl.jav")); + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseSix_pl.jav")); + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseSeven_pl.jav")); + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseEight_pl.jav")); + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseNine_pl.jav")); + suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseTen_pl.jav")); + + + // Usecases HOTI + suite.addTest(new CompilerTestCase("examples/hoti/Constr.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Generic.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/GenericsTest.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/ImplClass.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Import.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Intf.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Multiclass.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Overl.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Simple.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Simple2.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Test.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Test2.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/Test3.jav")); + suite.addTest(new CompilerTestCase("examples/hoti/VererbProb.jav")); + + // Usecases SCJU + suite.addTest(new CompilerTestCase("examples/scju/ClassGenerics.jav")); + suite.addTest(new CompilerTestCase("examples/scju/FieldGenerics.jav")); + suite.addTest(new CompilerTestCase("examples/scju/MethodGenerics.jav")); + suite.addTest(new CompilerTestCase("examples/scju/ClassKonstanten.jav")); + suite.addTest(new CompilerTestCase("examples/scju/InterfaceTest.jav")); + suite.addTest(new CompilerTestCase("examples/scju/testPackage/Test.jav")); + //$JUnit-END$ + return suite; + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mytest/LambdaTest.java b/src/mycompiler/mytest/LambdaTest.java new file mode 100644 index 000000000..758519e97 --- /dev/null +++ b/src/mycompiler/mytest/LambdaTest.java @@ -0,0 +1,206 @@ +package mycompiler.mytest; + +import static org.junit.Assert.*; + +import java.io.File; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Vector; + +import org.apache.log4j.Appender; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.FileAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.SimpleLayout; + +import typinferenz.TypeAssumptions; +import typinferenz.TypinferenzException; + +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; + +public class LambdaTest { + + protected static Logger inferencelog = Logger.getLogger("Typeinference"); + + private static final String directory = System.getProperty("user.dir")+"/test/mycompiler/test/lambda/"; + + // Logfiles werden im Ordner testResults gespeichert + public final String LOG_FILENAME = directory+"testResults/"+ "LambdaTest.log"; + + private Vector filenames; + + public static void main(String[] args){ + try { + new LambdaTest(args[0]).runTest(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private LambdaTest setUp() throws Exception{ + // Setup fuer Log4J + + File f = new File(LOG_FILENAME); // Altes Logfile loeschen + f.delete(); + + // Ausgabeoptionen fuer die Logger + PatternLayout pl = new PatternLayout("%-15C{1} %-5p [%-9c] %m%n"); + FileAppender fa = new FileAppender(pl, LOG_FILENAME); + + // Die Einstellungen jedes Loggers veraendern + //ModifyLogger("parser", Level.ALL, fa); + //ModifyLogger("inference", Level.ALL, fa); + ModifyLogger("Typeinference", Level.ALL, fa); //Alle Messages von inference in die Datei schreiben. + ConsoleAppender logAppender = new ConsoleAppender(new SimpleLayout()); + logAppender.setTarget("System.out"); + logAppender.activateOptions(); + inferencelog.addAppender(logAppender); //Bei den Tests wird der Log auch in System.out geschrieben. + //ModifyLogger("codegen", Level.ALL, fa); + //ModifyLogger("bytecode", Level.ALL, fa); + return this; + } + + public LambdaTest(String testfile){ + this(new Vector()); + filenames.add(directory + testfile); + } + + public LambdaTest(Vector testfiles) { + if(filenames == null)filenames = new Vector(); + for(String filename : testfiles){ + filenames.add(directory + filename); + } + try { + this.setUp(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + /** + * Führt einen Test aus, bei dem beliebig viele ResultSets entstehen dürfen. + * Anschließend werden die Typen in der Klasse classname nach den in der HashMap variableTypeAssumptions angegebenen Annahmen geprüft. + * Diesen Test muss jedes der ermittelten ResultSets bestehen. + * @param classname + * @param variableTypeAssumptions + */ + public void runTestAndCheckResultSet(String classname, HashMap variableTypeAssumptions){ + Vector result = this.runTest(); + if(result.size()==0)fail("Keine Lösung!"); + for(CTypeReconstructionResult result1 : result){ + TypeAssumptions assumptions = result1.getInterferedClass().getPublicFieldAssumptions();// TypeAssumptions.getAssumptionsFor(classname); + assertTrue("Fehler in Methode TypeAssumptions.getAssumptionsFor", assumptions!=null); + for(String variable : variableTypeAssumptions.keySet()){ + Type assumedType = assumptions.getVarType(variable); + assertTrue("Der Variable muss ein TPH zugewiesen sein.", assumedType!=null && assumedType instanceof TypePlaceholder); + //AssumedType auflösen: + + String assumedTypeString = result1.getTypeOfPlaceholder((TypePlaceholder)assumedType).printJavaCode(result1.getUnifiedConstraints()).toString(); + assertTrue("Die Variable "+variable+" muss vom Typ "+variableTypeAssumptions.get(variable)+" anstatt "+assumedTypeString+" sein", + assumedTypeString.equals(variableTypeAssumptions.get(variable))); + } + } + } + + /** + * Führt den Test aus und geht davon aus, dass es bei der Testdatei nur eine richtige Auflösung für die Typvariablen gibt. + * Diese eine Lösung wird zurückgegeben. + * @return + */ + public CTypeReconstructionResult runTestAndGetSingularResultSet(){ + Vector result = this.runTest(); + assertTrue("ResultSet muss genau 1 Element enthalten", result.size()==1); + CTypeReconstructionResult result1 = result.get(0); + + return result1; + } + + + public Vector runTest() + { + + //String[] arguments = new String[1]; + //arguments[0]="/home/janulrich/workspace/JavaCompilerCore/test/LampdaExpressions/general.java"; + //MyCompiler.main(arguments); + Vector resultSet = null; + + MyCompilerAPI compiler = MyCompiler.getAPI(); + try{ + ///////////////////////// + // Parsen: + ///////////////////////// + //compiler.parse(new File(filename)); + compiler.parse(filenames); + //SourceFile tree = compiler.getSyntaxTree(); + + ///////////////////////// + // Typrekonstruktion: + ///////////////////////// + try{ + resultSet = compiler.typeReconstruction(); + }catch(TypinferenzException texc){ + texc.printStackTrace(); + fail("Fehler bei Typinferenzalgorithmus. Message: "+texc.getMessage()); + } + + return resultSet; + //System.out.println(resultSet); + ///////////////////////// + // Ausgabe: + /////////////////////// + // + /* + CTypeReconstructionResult onePossibility = resultSet.firstElement(); + Iterator substIt = onePossibility.getSubstitutions().getIterator(); + while(substIt.hasNext()){ + CSubstitution subst = (CSubstitution)substIt.next(); + Vector lineNumbers = ((TypePlaceholder)subst.getTypeVar()).getLineNumbers(); + String s = new String(); + for(int l=0; l + * @param Object + * @return + */ + // ino.end + // ino.method.equals.26445.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26445.body + { + if(obj instanceof BaseType){ + return super.equals(obj); + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26448.declaration + public abstract BaseType clone(); + // ino.end + + /** + * Author: Daniel Feinler
+ * Handelt ab, ob der Typ eines Objekts ein Array ist, wenn true dann + * wird im Bytecode ein flag gesetzt wenn nicht, dann halt nicht. + * @return the IsArray + */ + public boolean IsArray() { + return IsArray; + } + + /** + * Author: Daniel Feinler
+ * Handelt ab, ob der Typ eines Objekts ein Array ist, wenn true dann + * wird im Bytecode ein flag gesetzt wenn nicht, dann halt nicht. + * @param IsArray the IsArray to set + */ + public void setArray(boolean IsArray) { + this.IsArray = IsArray; + } +} +// ino.end diff --git a/src/mycompiler/mytype/BooleanType.java b/src/mycompiler/mytype/BooleanType.java new file mode 100755 index 000000000..b66073f75 --- /dev/null +++ b/src/mycompiler/mytype/BooleanType.java @@ -0,0 +1,63 @@ +// ino.module.BooleanType.8668.package +package mycompiler.mytype; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +// ino.end +// ino.class.BooleanType.26451.declaration +public class BooleanType extends BaseType +// ino.end +// ino.class.BooleanType.26451.body +{ + // ino.method.BooleanType.26455.definition + public BooleanType() + // ino.end + // ino.method.BooleanType.26455.body + { + super("boolean",-1); + } + // ino.end + + // ino.method.equals.26458.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26458.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26458.body + { + if(obj instanceof BooleanType){ + return super.equals(obj); + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26461.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26461.definition + public BooleanType clone() + // ino.end + // ino.method.clone.26461.body + { + return new BooleanType(); + } + // ino.end + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("boolean"); + } +} +// ino.end diff --git a/src/mycompiler/mytype/BoundedGenericTypeVar.java b/src/mycompiler/mytype/BoundedGenericTypeVar.java new file mode 100755 index 000000000..c8bbdc175 --- /dev/null +++ b/src/mycompiler/mytype/BoundedGenericTypeVar.java @@ -0,0 +1,122 @@ + +// ino.module.BoundedGenericTypeVar.8669.package +package mycompiler.mytype; +// ino.end + +// ino.module.BoundedGenericTypeVar.8669.import +import java.util.Vector; +// ino.end + +// ino.class.BoundedGenericTypeVar.26464.description type=javadoc +/** + * Entspricht einem GenericTypeVar, jedoch mit Bounds + * (d.h. vorgaben, von welchem Typ die Typevar sein darf + * => extends Class x + * => implements Interface y + * ... + * @author hoti 4.5.06 + * + */ +// ino.end +// ino.class.BoundedGenericTypeVar.26464.declaration +public class BoundedGenericTypeVar extends GenericTypeVar +// ino.end +// ino.class.BoundedGenericTypeVar.26464.body +{ + + // ino.attribute.bounds.26468.decldescription type=javadoc + /** + * Hier sind die Bounds in Form von Type-Objekten abgespeichert + */ + // ino.end + // ino.attribute.bounds.26468.declaration + Vector bounds=new Vector(); + // ino.end + + // ino.method.BoundedGenericTypeVar.26471.definition + public BoundedGenericTypeVar(String s, int offset) + // ino.end + // ino.method.BoundedGenericTypeVar.26471.body + { + super(s, offset); + } + // ino.end + + // ino.method.BoundedGenericTypeVar.29409.definition + public BoundedGenericTypeVar(String s, Vector bounds, int offset) + // ino.end + // ino.method.BoundedGenericTypeVar.29409.body + { + super(s, offset); + this.bounds = bounds; + } + // ino.end + + // ino.method.getBounds.26474.definition + public Vector getBounds() + // ino.end + // ino.method.getBounds.26474.body + { + return bounds; + } + // ino.end + + // ino.method.setBounds.26477.definition + public void setBounds(Vector types) + // ino.end + // ino.method.setBounds.26477.body + { + this.bounds=types; + } + // ino.end + + // ino.method.addBound.26480.definition + public void addBound(Type bound) + // ino.end + // ino.method.addBound.26480.body + { + bounds.addElement(bound); + } + // ino.end + + // ino.method.clone.26483.definition + public BoundedGenericTypeVar clone() + // ino.end + // ino.method.clone.26483.body + { + return new BoundedGenericTypeVar(this.getName(), this.getBounds(), getOffset()); + } + // ino.end + + // ino.method.toString.26486.definition + public String toString() + // ino.end + // ino.method.toString.26486.body + { + return "BoGTV " + this.getName(); + } + // ino.end + + // ino.method.getSignatureDefinition.26489.definition + public String getSignatureDefinition() + // ino.end + // ino.method.getSignatureDefinition.26489.body + { + // Rueckgabeformat: + // Zur kompletten Definition (bspw. Rueckgabewert) muss zusaetzlich + // noch ((GenericTypeVar)obj).getSignatureType(paralist) aufgerufen + // werden! + StringBuffer sb = new StringBuffer(); + sb.append(name); + + for (int i=0; i < bounds.size(); i++) { + sb.append(":"); + sb.append(bounds.elementAt(i).get_codegen_Type( null)); + } + + return sb.toString(); + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mytype/CRefTypeSet.java b/src/mycompiler/mytype/CRefTypeSet.java new file mode 100755 index 000000000..296d9e260 --- /dev/null +++ b/src/mycompiler/mytype/CRefTypeSet.java @@ -0,0 +1,29 @@ +package mycompiler.mytype; + +import java.util.Iterator; +import java.util.Vector; + +import mycompiler.mytypereconstruction.set.CVectorSet; + +public class CRefTypeSet extends CVectorSet { + + public CRefTypeSet shallowCopy(){ + CRefTypeSet copy = new CRefTypeSet(); + copy.setVector((Vector)this.getVector().clone()); + return copy; + } + + public CRefTypeSet deepCopy() { + + CRefTypeSet copy = new CRefTypeSet(); + Iterator it = this.getIterator(); + while(it.hasNext()){ + copy.addElement(it.next().clone()); + } + return copy; + } + + public Iterator iterator() { + return this.getIterator(); + } +} diff --git a/src/mycompiler/mytype/CharacterType.java b/src/mycompiler/mytype/CharacterType.java new file mode 100755 index 000000000..b8c78462d --- /dev/null +++ b/src/mycompiler/mytype/CharacterType.java @@ -0,0 +1,63 @@ +// ino.module.CharacterType.8670.package +package mycompiler.mytype; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +// ino.end +// ino.class.CharacterType.26492.declaration +public class CharacterType extends BaseType +// ino.end +// ino.class.CharacterType.26492.body +{ + // ino.method.CharacterType.26496.definition + public CharacterType() + // ino.end + // ino.method.CharacterType.26496.body + { + super("char",-1); + } + // ino.end + + // ino.method.equals.26499.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26499.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26499.body + { + if(obj instanceof CharacterType){ + return super.equals(obj); + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26502.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26502.definition + public CharacterType clone() + // ino.end + // ino.method.clone.26502.body + { + return new CharacterType(); + } + // ino.end + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("char"); + } +} +// ino.end diff --git a/src/mycompiler/mytype/DoubleType.java b/src/mycompiler/mytype/DoubleType.java new file mode 100755 index 000000000..a497d5e7b --- /dev/null +++ b/src/mycompiler/mytype/DoubleType.java @@ -0,0 +1,63 @@ +// ino.module.IntegerType.8672.package +package mycompiler.mytype; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +// ino.end +// ino.class.IntegerType.26527.declaration +public class DoubleType extends BaseType +// ino.end +// ino.class.IntegerType.26527.body +{ + // ino.method.IntegerType.26531.definition + public DoubleType() + // ino.end + // ino.method.IntegerType.26531.body + { + super("double",-1); + } + // ino.end + + // ino.method.equals.26534.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26534.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26534.body + { + if(obj instanceof DoubleType){ + return super.equals(obj); + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26537.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26537.definition + public DoubleType clone() + // ino.end + // ino.method.clone.26537.body + { + return new DoubleType(); + } + // ino.end + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("double"); + } +} +// ino.end diff --git a/src/mycompiler/mytype/ExtendsWildcardType.java b/src/mycompiler/mytype/ExtendsWildcardType.java new file mode 100755 index 000000000..132958c6a --- /dev/null +++ b/src/mycompiler/mytype/ExtendsWildcardType.java @@ -0,0 +1,124 @@ +package mycompiler.mytype; + + +/** + * Stellt eine Wildcard mit oberer Grenze dar. + * z.B. void test(? extends Number var){..} + * ... + * @author luar 2.12.06 + * + */ + +public class ExtendsWildcardType extends WildcardType implements ITypeContainer, IMatchable{ + + private Type extendsType = null; + + /** + * Author: Arne Lüdtke
+ * Standard Konstruktor für eine ExtendsWildcard + */ + public ExtendsWildcardType (int offset, Type extendsType) + { + super(offset); + this.extendsType = extendsType; + } + + /** + * Author: Arne Lüdtke
+ * Gibt den Typen in der Wildcard zurück. + * Beispiel: ? extends Integer. + * Integer wird zurückgegeben. + */ + public Type get_ExtendsType() + { + return this.extendsType; + } + + /** + * Author: Arne Lüdtke
+ * Gibt String Entsprechung zurück. + */ + public String toString() + { + return "? extends " + extendsType.toString(); + } + + /** + * Author: Arne Lüdtke
+ * Gibt einen Klon der Wildcard zurück. + * Der Innere Typ wird auch geklont + */ + public ExtendsWildcardType clone() + { + //Hier ist unklar, ob der Extends Type auch geklont werden muss. + return new ExtendsWildcardType(getOffset(),extendsType.clone()); + } + + /** + * Author: Arne Lüdtke
+ * Vergleicht mit einem anderen Objekt. + * @param obj - Object to compare. + */ + public boolean equals(Object obj) + { + if(obj instanceof ExtendsWildcardType) + { + return this.extendsType.equals(((ExtendsWildcardType)obj).get_ExtendsType()); + } + else + { + return false; + } + } + + /** + * Author: Arne Lüdtke
+ * Gibt die passende FreshWildcardType Klasse zurück. + * Wird für CaptureConversion verwendet + */ + public FreshExtendsWildcardType GetFreshWildcardType() + { + return new FreshExtendsWildcardType(this.extendsType,-1); + } + + /** + * Author: Arne Lüdtke
+ * Das gleiche wie get_ExtendsType(). + * Überschreibt die Methode der Superklasse. + */ + public Type GetWildcardType() + { + return this.get_ExtendsType(); + } + + /** + * Author: Arne Lüdtke
+ * Setzt den Typ in der Wildcard + * @param T - Type to be set + */ + public void SetWildcardType(Type T) + { + if(T instanceof RefType) + this.extendsType = (RefType)T; + } + + /** + * Author: Arne Lüdtke
+ * Das gleiche wie get_ExtendsType(). + * Implementiert ITypeContainer + */ + public Type getContainedType() + { + return this.get_ExtendsType(); + } + + /** + * Author: Arne Lüdtke
+ * Gibt den Typen zurück, der bei einem match im Unify verwendet werden soll. + * Wird über IMatchable implementiert. + */ + public Type getMatchType() + { + return this.get_ExtendsType(); + } +} diff --git a/src/mycompiler/mytype/FloatType.java b/src/mycompiler/mytype/FloatType.java new file mode 100755 index 000000000..bcfde7257 --- /dev/null +++ b/src/mycompiler/mytype/FloatType.java @@ -0,0 +1,63 @@ +// ino.module.IntegerType.8672.package +package mycompiler.mytype; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +// ino.end +// ino.class.IntegerType.26527.declaration +public class FloatType extends BaseType +// ino.end +// ino.class.IntegerType.26527.body +{ + // ino.method.IntegerType.26531.definition + public FloatType() + // ino.end + // ino.method.IntegerType.26531.body + { + super("float",-1); + } + // ino.end + + // ino.method.equals.26534.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26534.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26534.body + { + if(obj instanceof FloatType){ + return super.equals(obj); + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26537.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26537.definition + public FloatType clone() + // ino.end + // ino.method.clone.26537.body + { + return new FloatType(); + } + // ino.end + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("float"); + } +} +// ino.end diff --git a/src/mycompiler/mytype/FreshExtendsWildcardType.java b/src/mycompiler/mytype/FreshExtendsWildcardType.java new file mode 100755 index 000000000..731d93761 --- /dev/null +++ b/src/mycompiler/mytype/FreshExtendsWildcardType.java @@ -0,0 +1,93 @@ +package mycompiler.mytype; + +public class FreshExtendsWildcardType extends FreshWildcardType implements IMatchable { + + private Type extendsBoundType; + + /** + * Author: Arne Lüdtke
+ * Standard Konstruktor für eine FreshExtendsWildcard + */ + public FreshExtendsWildcardType(Type extendsBound ,int offset) + { + super(offset); + this.extendsBoundType = extendsBound; + } + + /** + * Author: Arne Lüdtke
+ * Privater Konstruktor für clone + */ + private FreshExtendsWildcardType(Type extendsBound ,int offset, String name) + { + super(offset,name); + this.extendsBoundType = extendsBound; + } + + /** + * Author: Arne Lüdtke
+ * Gibt String Entsprechung zurück. + */ + public String toString() + { + String s = "FEWCT " + this.name; + if(extendsBoundType != null) + s += " " + extendsBoundType.toString(); + + return s; + } + + /** + * Author: Arne Lüdtke
+ * Gibt einen Klon der Wildcard zurück. + * Der Innere Typ wird auch geklont + */ + public FreshExtendsWildcardType clone() + { + return new FreshExtendsWildcardType(this.extendsBoundType.clone(),getOffset(),this.name); + } + + /** + * Author: Arne Lüdtke
+ * Gibt die Grenze der Wildcard zurück + */ + public Type get_ExtendsBound() + { + return extendsBoundType; + } + + /** + * Author: Arne Lüdtke
+ * Prüft, ob zwei Objekte gleich sind. NICHT INSTANZGLEICH + */ + public boolean equals(Object obj) + { + if(obj instanceof FreshExtendsWildcardType) + { + FreshExtendsWildcardType FEWT = (FreshExtendsWildcardType)obj; + return this.get_ExtendsBound().equals(FEWT.get_ExtendsBound()); + } + else + return false; + } + + /** + * Author: Arne Lüdtke
+ * Gibt die passende ExtendsWildcardType Klasse zurück. + * Wird für smaller4 verwendet + */ + public ExtendsWildcardType get_WildcardType() + { + return new ExtendsWildcardType(this.getOffset(),this.get_ExtendsBound()); + } + + /** + * Author: Arne Lüdtke
+ * Gibt den Typen zurück, der bei einem match im Unify verwendet werden soll. + * Wird über IMatchable implementiert. + */ + public Type getMatchType() + { + return this.get_ExtendsBound(); + } +} diff --git a/src/mycompiler/mytype/FreshSuperWildcardType.java b/src/mycompiler/mytype/FreshSuperWildcardType.java new file mode 100755 index 000000000..66889b79f --- /dev/null +++ b/src/mycompiler/mytype/FreshSuperWildcardType.java @@ -0,0 +1,93 @@ +package mycompiler.mytype; + +public class FreshSuperWildcardType extends FreshWildcardType implements IMatchable { + + private Type superBoundType; + + /** + * Author: Arne Lüdtke
+ * Standard Konstruktor für eine FreshSuperWildcard + */ + public FreshSuperWildcardType(Type superBound ,int offset) + { + super(offset); + this.superBoundType = superBound; + } + + /** + * Author: Arne Lüdtke
+ * Privater Konstruktor für clone + */ + private FreshSuperWildcardType(Type superBound,int offset, String name) + { + super(offset,name); + this.superBoundType = superBound; + } + + /** + * Author: Arne Lüdtke
+ * Gibt String Entsprechung zurück. + */ + public String toString() + { + String s = "FSWCT " + this.name; + if(superBoundType != null) + s += " " + superBoundType.toString(); + + return s; + } + + /** + * Author: Arne Lüdtke
+ * Gibt einen Klon der Wildcard zurück. + * Der Innere Typ wird auch geklont + */ + public FreshSuperWildcardType clone() + { + return new FreshSuperWildcardType(this.superBoundType.clone(),getOffset(),this.name); + } + + /** + * Author: Arne Lüdtke
+ * Gibt die Grenze der Wildcard zurück + */ + public Type get_SuperBound() + { + return superBoundType; + } + + /** + * Author: Arne Lüdtke
+ * Prüft, ob zwei Objekte gleich sind. NICHT INSTANZGLEICH + */ + public boolean equals(Object obj) + { + if(obj instanceof FreshSuperWildcardType) + { + FreshSuperWildcardType FSWT = (FreshSuperWildcardType)obj; + return this.get_SuperBound().equals(FSWT.get_SuperBound()); + } + else + return false; + } + + /** + * Author: Arne Lüdtke
+ * Gibt die passende SuperWildcardType Klasse zurück. + * Wird für smaller4 verwendet + */ + public SuperWildcardType get_WildcardType() + { + return new SuperWildcardType(this.getOffset(),this.get_SuperBound()); + } + + /** + * Author: Arne Lüdtke
+ * Gibt den Typen zurück, der bei einem match im Unify verwendet werden soll. + * Wird über IMatchable implementiert. + */ + public Type getMatchType() + { + return this.get_SuperBound(); + } +} diff --git a/src/mycompiler/mytype/FreshWildcardType.java b/src/mycompiler/mytype/FreshWildcardType.java new file mode 100755 index 000000000..e1eb4a9c5 --- /dev/null +++ b/src/mycompiler/mytype/FreshWildcardType.java @@ -0,0 +1,171 @@ +package mycompiler.mytype; + +import java.util.Vector; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +public class FreshWildcardType extends Type { + + private static String strNextName = "A"; + private Vector upperBounds = new Vector(); + + /** + * Author: Arne Lüdtke
+ * Standard Konstruktor für eine FreshWildcard + */ + public FreshWildcardType(int offset) + { + super(offset); + this.name = makeNewName(); + } + + /** + * Author: Arne Lüdtke
+ * Protected Konstruktor für clone. + * Protected, da vererbte Klassen ihn verwenden müssen. + */ + protected FreshWildcardType(int offset, String name) + { + super(offset); + this.name = name; + } + + /** + * Author: Arne Lüdtke
+ * Gibt String Entsprechung zurück. + */ + public String toString() + { + String s = "FWCT " + this.name; + if(upperBounds.size() > 0) + { + s += "|"; + for(int i = 0;i + * Gibt einen Klon der Wildcard zurück. + * Der Innere Typ wird auch geklont + */ + public FreshWildcardType clone() + { + return new FreshWildcardType(getOffset(),this.name); + } + + /** + * Author: Arne Lüdtke
+ * Prüft, ob zwei Objekte gleich sind. NICHT INSTANZGLEICH + */ + public boolean equals(Object obj) + { + //Da die Namensgebung von Typeplaceholdern und FreshWildcards identisch ist, + //und im Type nur auf Namen geprüft wird muss verhindert werden, dass ausversehen True zurückgegeben wird, + //Wenn eine FreshWildcard mit einem TypePlaceholder verglichen wird. + return (obj instanceof FreshWildcardType) && super.equals(obj); + } + + /** + * Erzeugt einen neuen Namen, und gibt diesen zurück + * Methode aus TypePlaceholder kopiert + */ + private static String makeNewName() + { + // luar: Methode aus TypePlaceholder kopiert. + String strReturn = strNextName; + + // n�chster Name berechnen und in strNextName speichern + inc( strNextName.length() - 1 ); + + return strReturn; + } + + /** + * Hilfsmethode für makeNewName + * Methode aus TypePlaceholder kopiert + */ + private static void inc(int i) + { + // luar: Methode aus TypePlaceholder kopiert. + if ( i == -1 ) + { + strNextName = "A" + strNextName; + return; + } + + char cBuchstabe = (char)(strNextName.charAt( i )); + cBuchstabe++; + if ( cBuchstabe - 65 > 25 ) + { + // aktuelle Stelle: auf A zuruecksetzen + manipulate( i, 'A' ); + + // vorherige Stelle erh�hen + inc( i - 1 ); + } + else + { + // aktueller Buchstabe �ndern + manipulate( i, cBuchstabe ); + } + } + + /** + * Hilfsmethode für makeNewName + * Methode aus TypePlaceholder kopiert + */ + private static void manipulate( int nStelle, char nWert ) + { + // luar: Methode aus TypePlaceholder kopiert. + String strTemp = ""; + for( int i = 0; i < strNextName.length(); i++) + { + if ( i == nStelle ) + strTemp = strTemp + nWert; + else + strTemp = strTemp + strNextName.charAt( i ); + } + strNextName = strTemp; + } + + /** + * Author: Arne Lüdtke
+ * Gibt die passende WildcardType Klasse zurück. + * Wird für smaller4 verwendet + */ + public WildcardType get_WildcardType() + { + return new WildcardType(this.getOffset()); + } + /** + * Author: Arne Lüdtke
+ * Gibt den Vector der oberen Grenzen zurück + */ + public Vector get_UpperBounds() + { + return this.upperBounds; + } + /** + * Author: Arne Lüdtke
+ * Setzt den Vector der oberen Grenzen + */ + public void set_UpperBounds(Vector bounds) + { + this.upperBounds = bounds; + } + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + throw new NotImplementedException(); + } +} diff --git a/src/mycompiler/mytype/GenericTypeVar.java b/src/mycompiler/mytype/GenericTypeVar.java new file mode 100755 index 000000000..fef548454 --- /dev/null +++ b/src/mycompiler/mytype/GenericTypeVar.java @@ -0,0 +1,137 @@ +// ino.module.GenericTypeVar.8671.package +package mycompiler.mytype; +// ino.end + +// ino.module.GenericTypeVar.8671.import +import java.util.Vector; +// ino.end + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + + +// ino.class.GenericTypeVar.26505.description type=javadoc +/** + * + * @author J�rg B�uerle + * @version $Date: 2013/09/22 20:12:53 $ + */ +// ino.end +// ino.class.GenericTypeVar.26505.declaration +public class GenericTypeVar extends Type +// ino.end +// ino.class.GenericTypeVar.26505.body +{ + Pair genericTypeVar; + /** + * Eine Registry f�r alle Generic-Instanzen, die vor der Bytecode-Generierung durch + * Ihre Superklasse ersetzt werden m�ssen. Siehe "Type Erasure" in Sun Spezifikation. + *
Autor: J�rg B�uerle + */ + // ino.method.GenericTypeVar.26509.defdescription type=line + // private Hashtable> m_TypeErasureList; + // ino.end + + /** + * + * @param genericTypeVarExtendsVar + */ + public GenericTypeVar(Pair genericTypeVarExtendsVar){ + super(0); + genericTypeVar = genericTypeVarExtendsVar; + this.name = genericTypeVar.toString(); + } + + // ino.method.GenericTypeVar.26509.definition + public GenericTypeVar(String s, int offset) + // ino.end + // ino.method.GenericTypeVar.26509.body + { + super(offset); + this.name = s; + } + // ino.end + + public GenericTypeVar(Type tA1) { + this(new Pair(tA1,null)); + } + + // ino.method.clone.26512.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26512.definition + public GenericTypeVar clone() + // ino.end + // ino.method.clone.26512.body + { + return new GenericTypeVar(this.getName(),getOffset()); + } + // ino.end + + // ino.method.equals.26515.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param obj + * @return + */ + // ino.end + // ino.method.equals.26515.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26515.body + { + return super.equals(obj) && (obj instanceof GenericTypeVar); + } + // ino.end + + // ino.method.toString.26518.definition + public String toString() + // ino.end + // ino.method.toString.26518.body + { + return "GTV " + this.getName(); + } + // ino.end + + // ino.method.get_codegen_Type.26521.defdescription type=javadoc + /** + * hoti 4.5.06 + * Generische Typen werden im Bytecode + * aus Abwaertskompatiblitaet wie Object dargestellt + */ + // ino.end + // ino.method.get_codegen_Type.26521.definition + public String get_codegen_Type(Vector paralist) + // ino.end + // ino.method.get_codegen_Type.26521.body + { + return("Ljava/lang/Object;"); + } + // ino.end + + // ino.method.getSignatureType.26524.definition + public String getSignatureType(Vector paralist) + // ino.end + // ino.method.getSignatureType.26524.body + { + return "T" + name + ";"; + } + // ino.end + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + if(this.genericTypeVar!=null){ + JavaCodeResult ret = new JavaCodeResult(); + ret.attach(this.genericTypeVar.TA1.printJavaCode(resultSet)); + if(this.genericTypeVar.TA2!=null)ret.attach(" extends ").attach(this.genericTypeVar.TA2.printJavaCode(resultSet)); + return ret; + } + return new JavaCodeResult(this.name); + } +} +// ino.end + + diff --git a/src/mycompiler/mytype/IMatchable.java b/src/mycompiler/mytype/IMatchable.java new file mode 100755 index 000000000..0981d13f8 --- /dev/null +++ b/src/mycompiler/mytype/IMatchable.java @@ -0,0 +1,18 @@ +package mycompiler.mytype; + +/** + * Dieses Interface wird von allen Klassen implementiert, die weitere Klassen + * enthalten, die im match des Unify beachtet werden müssen. + * + * @author Arne Lüdtke + * + */ +public interface IMatchable +{ + /** + * Author: Arne Lüdtke
+ * Gibt den Typen zurück, der bei einem match im Unify verwendet werden soll. + * Wird über IMatchable implementiert. + */ + Type getMatchType(); +} diff --git a/src/mycompiler/mytype/ITypeContainer.java b/src/mycompiler/mytype/ITypeContainer.java new file mode 100755 index 000000000..0b7fdbae3 --- /dev/null +++ b/src/mycompiler/mytype/ITypeContainer.java @@ -0,0 +1,19 @@ +package mycompiler.mytype; + +/** + * Dieses Interface wird von allen Klassen implementiert, die weitere Klassen enthalten. + * Wird für diverse Hilfsmethoden verwendet. + * + * @author Arne Lüdtke + * + */ + +public interface ITypeContainer +{ + /** + * Author: Arne Lüdtke
+ * Das gleiche wie get_ExtendsType(). + * Implementiert ITypeContainer + */ + Type getContainedType(); +} diff --git a/src/mycompiler/mytype/IntegerType.java b/src/mycompiler/mytype/IntegerType.java new file mode 100755 index 000000000..4fa054588 --- /dev/null +++ b/src/mycompiler/mytype/IntegerType.java @@ -0,0 +1,63 @@ +// ino.module.IntegerType.8672.package +package mycompiler.mytype; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +// ino.end +// ino.class.IntegerType.26527.declaration +public class IntegerType extends BaseType +// ino.end +// ino.class.IntegerType.26527.body +{ + // ino.method.IntegerType.26531.definition + public IntegerType() + // ino.end + // ino.method.IntegerType.26531.body + { + super("int",-1); + } + // ino.end + + // ino.method.equals.26534.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26534.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26534.body + { + if(obj instanceof IntegerType){ + return super.equals(obj); + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26537.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26537.definition + public IntegerType clone() + // ino.end + // ino.method.clone.26537.body + { + return new IntegerType(); + } + // ino.end + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + return new JavaCodeResult("int"); + } +} +// ino.end diff --git a/src/mycompiler/mytype/LongType.java b/src/mycompiler/mytype/LongType.java new file mode 100755 index 000000000..9a28792fc --- /dev/null +++ b/src/mycompiler/mytype/LongType.java @@ -0,0 +1,64 @@ +// ino.module.IntegerType.8672.package +package mycompiler.mytype; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +// ino.end +// ino.class.IntegerType.26527.declaration +public class LongType extends BaseType +// ino.end +// ino.class.IntegerType.26527.body +{ + // ino.method.IntegerType.26531.definition + public LongType() + // ino.end + // ino.method.IntegerType.26531.body + { + super("long",-1); + } + // ino.end + + // ino.method.equals.26534.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26534.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26534.body + { + if(obj instanceof LongType){ + return super.equals(obj); + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26537.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26537.definition + public LongType clone() + // ino.end + // ino.method.clone.26537.body + { + return new LongType(); + } + // ino.end + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } +} +// ino.end diff --git a/src/mycompiler/mytype/Pair.java b/src/mycompiler/mytype/Pair.java new file mode 100755 index 000000000..df8bae90b --- /dev/null +++ b/src/mycompiler/mytype/Pair.java @@ -0,0 +1,376 @@ +// ino.module.Pair.8673.package +package mycompiler.mytype; +// ino.end +// ino.module.Pair.8673.import +import java.util.Hashtable; +import java.util.Vector; +// ino.end + + + + + +// ino.class.Pair.26540.description type=line +// Klasse, die ein Paar in der Menge Eq speichern kann +// ino.end +// ino.class.Pair.26540.declaration +public class Pair +// ino.end +// ino.class.Pair.26540.body +{ + // ino.attribute.TA1.26543.declaration + public Type TA1; + // ino.end + // ino.attribute.TA2.26546.declaration + public Type TA2; + // ino.end + + // ino.attribute.bEqual.26549.declaration + private PairOperator eOperator = PairOperator.Smaller; + + public enum PairOperator { Smaller, SmallerExtends, Equal }; + // ino.end + // ino.attribute.bSubst.26552.decldescription type=line + // false <--> vorinitialisierter Wert + // true <--> Dieses Paar entstand durch reduce1-Regel (=.) + // --> Name von TA1 mu� gleich sein wie Name von TA2 + // Nur noch reduce2-Regel anwendbar + + // luar 15-04-2007 + // Der Unify mit Wildcards benötigt 3 verschiedene Operatoren. + // Deshalb wurde der boolean durch einen Enum ersetzt. + // Smaller <--> vorinitialisierter Wert + // SmallerExtends <--> Kleiner extends (wie vorinitialisiert, nur mit einschluss der Wildcard) + // Equal <--> Gleich: Name von TA1 und TA2 müssen gleich sein. + // ino.end + + // ino.attribute.bSubst.26552.declaration + public boolean bSubst; // speichert, ob die SUBST -Regel auf diese Paar + // ino.end + // ino.method.Pair.26555.defdescription type=line + // schon angewandt wurde, Default = FALSE + // ino.end + + + // ino.method.Pair.26555.definition + public Pair( Type TA1, Type TA2 ) + // ino.end + // ino.method.Pair.26555.body + { + // Konstruktor + //if(TA1 == null || TA2 == null)throw new NullPointerException(); + this.TA1 = TA1; + this.TA2 = TA2; + bSubst = false; + eOperator = PairOperator.Smaller; + } + // ino.end + + // ino.method.Pair.26558.definition + public Pair( Type TA1, Type TA2, PairOperator eOp) + // ino.end + // ino.method.Pair.26558.body + { + // Konstruktor + this(TA1,TA2); + this.eOperator = eOp; + } + // ino.end + + // ino.method.Pair.26561.definition + public Pair( Type TA1, Type TA2, PairOperator eOp, boolean bSubst ) + // ino.end + // ino.method.Pair.26561.body + { + // Konstruktor + this(TA1,TA2,eOp); + this.bSubst = bSubst; + } + // ino.end + + // ino.method.toString.26564.definition + public String toString() + // ino.end + // ino.method.toString.26564.body + { + // otth: Gibt ein Paar als String aus --> zum Debuggen und Vergleichen + String strElement1 = "NULL"; + String strElement2 = "NULL"; + String Operator = "<."; + + if( TA1 != null ) + strElement1 = TA1.toString(); + + if( TA2 != null ) + strElement2 = TA2.toString(); + + if(OperatorEqual()) + Operator = "="; + if(OperatorSmaller()) + Operator = "<."; + if(OperatorSmallerExtends()) + Operator = " v1=RT1.get_ParaList(); + Vector v2=RT2.get_ParaList(); + if(v1==null && v2==null){ + return true; + }else{ + if(v1==null && v2!=null || v1!=null && v2==null){ + return false; + }else{ + if(v1.size()!=v2.size()){ + return false; + }else{ + for(int i=0;i Stringvergleich + // TA1 == TA2 + return true; + }*/ + + }else if( TA1 instanceof TypePlaceholder && TA2 instanceof TypePlaceholder ) { + + if( TA1.getName().equals( TA2.getName() ) ) + { + // TA1 = TA2 + return true; + } + + } else if( TA1 instanceof GenericTypeVar && TA2 instanceof GenericTypeVar ) { + //eingefuegt PL 06-05-16 + if( TA1.getName().equals( TA2.getName() ) ) + { + // TA1 = TA2 + return true; + } + } else if(TA1 instanceof WildcardType && TA2 instanceof WildcardType) + { + return TA1.equals(TA2); + } + else if(TA1 instanceof FreshWildcardType && TA2 instanceof FreshWildcardType) + { + return TA1.equals(TA2); + } + + // Rest: Typen sind wohl verschieden + return false; + + + } + // ino.end + + // ino.method.copyType.26570.defdescription type=line + // PL 05-01-22 static eingefuegt + // ino.end + // ino.method.copyType.26570.definition + public static Type copyType( Type T ) + // ino.end + // ino.method.copyType.26570.body + { + // #JB# 22.05.2005 + // ########################################################### + return T.clone(); + // ########################################################### + + } + // ino.end + + // ino.method.getTA1Copy.26573.definition + public Type getTA1Copy( ) + // ino.end + // ino.method.getTA1Copy.26573.body + { + return copyType( TA1 ); + } + // ino.end + + // ino.method.getTA2Copy.26576.definition + public Type getTA2Copy( ) + // ino.end + // ino.method.getTA2Copy.26576.body + { + return copyType( TA2 ); + } + // ino.end + + // ino.method.copyPair.26579.definition + public Pair copyPair() + // ino.end + // ino.method.copyPair.26579.body + { + return new Pair(getTA1Copy(), getTA2Copy(), eOperator, bSubst); + } + // ino.end + + // ino.method.Pair_isEquiv.26582.definition + public boolean Pair_isEquiv(Pair p) + // ino.end + // ino.method.Pair_isEquiv.26582.body + { + //vergleicht Paare mit Reftype's, bis auf Variablenumbennung + Hashtable ht = new Hashtable(); + //System.out.println((((RefType)TA1).is_Equiv((RefType)p.TA1, ht))); + //System.out.println(((RefType)TA2).is_Equiv((RefType)p.TA2, ht)); + + //Typen boxen, da es sich um TypePlaceholder handeln koennte + Vector hilfsvector1 = new Vector(); + Vector hilfsvector2 = new Vector(); + hilfsvector1.addElement(TA1); + hilfsvector2.addElement(TA2); + Vector hilfsvector3 = new Vector(); + Vector hilfsvector4 = new Vector(); + hilfsvector3.addElement(p.TA1); + hilfsvector4.addElement(p.TA2); + //return (((RefType)TA1).is_Equiv((RefType)p.TA1, ht) && ((RefType)TA2).is_Equiv((RefType)p.TA2, ht)); + return (new RefType("dummy", hilfsvector3,-1)).is_Equiv(new RefType("dummy", hilfsvector1,-1), ht) && + (new RefType("dummy", hilfsvector4,-1)).is_Equiv(new RefType("dummy", hilfsvector2,-1), ht); + } + // ino.end + + + // ino.method.isInVector.26585.definition + public boolean isInVector( Vector V ) + // ino.end + // ino.method.isInVector.26585.body + { + // otth: prueft, ob Paar in Vektor liegt + for( int i = 0; i < V.size(); i++ ) + { + if( V.elementAt(i) instanceof Pair ) + { + //if( this.toString().equals( ( (Pair)V.elementAt(i) ).toString() ) ) + if(Pair_isEquiv(V.elementAt(i))) { + return true; + } + } + } + return false; + } + // ino.end + + // ino.method.equals.26588.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param obj + * @return + */ + // ino.end + // ino.method.equals.26588.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26588.body + { + boolean ret = true; + ret &= (obj instanceof Pair); + ret &= ((Pair)obj).TA1.equals(this.TA1); + ret &= ((Pair)obj).TA2.equals(this.TA2); + return ret; + } + // ino.end + + /** + * Author: Arne Lüdtke
+ * Überprüft ob die Paare die gleichen Instanzen sind. + */ + public boolean instanzeEquals(Object obj) + { + return super.equals(obj); + } + + /** + * Author: Arne Lüdtke
+ * Abfrage, ob Operator vom Typ Equal ist. + */ + public boolean OperatorEqual() + { + return eOperator == PairOperator.Equal; + } + + /** + * Author: Arne Lüdtke
+ * Abfrage, ob Operator vom Typ Smaller ist. + */ + public boolean OperatorSmaller() + { + return eOperator == PairOperator.Smaller; + } + + /** + * Author: Arne Lüdtke
+ * Abfrage, ob Operator vom Typ SmallerExtends ist. + */ + public boolean OperatorSmallerExtends() + { + return eOperator == PairOperator.SmallerExtends; + } + + /** + * Author: Arne Lüdtke
+ * Gibt den Operator zurück. + */ + public PairOperator GetOperator() + { + return eOperator; + } + + /** + * Author: Arne Lüdtke
+ * Setzt den Operator + * @param operator - Operator to set. + */ + public void SetOperator(PairOperator operator) + { + this.eOperator = operator; + } + + /** + * Author: Arne Lüdtke
+ * Erzeugt einen Klon des Paares. + */ + public Pair clone() + { + return this.copyPair(); + } +} +// ino.end diff --git a/src/mycompiler/mytype/ParaList.java b/src/mycompiler/mytype/ParaList.java new file mode 100755 index 000000000..b886ce904 --- /dev/null +++ b/src/mycompiler/mytype/ParaList.java @@ -0,0 +1,84 @@ +// ino.module.ParaList.8674.package +package mycompiler.mytype; +// ino.end +// ino.module.ParaList.8674.import +import java.util.Vector; +import org.apache.log4j.Logger; +// ino.end + + + + + +// ino.class.ParaList.26591.declaration +public class ParaList +// ino.end +// ino.class.ParaList.26591.body +{ + // ino.attribute.paralist.26594.declaration + protected Vector paralist = new Vector(); + // ino.end + // ino.attribute.parserlog.26597.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + // ino.method.ParaList.26600.definition + public ParaList() + // ino.end + // ino.method.ParaList.26600.body + {} + // ino.end + // ino.method.ParaList.26603.definition + ParaList(Type t) + // ino.end + // ino.method.ParaList.26603.body + { + parserlog.debug( "ParaList: " + t ); + this.paralist.addElement(t); + } + // ino.end + + // ino.method.get_ParaList.26606.definition + public Vector get_ParaList() + // ino.end + // ino.method.get_ParaList.26606.body + { + return this.paralist; + } + // ino.end + + // ino.method.add_ParaList.26609.definition + public void add_ParaList(Type obj) + // ino.end + // ino.method.add_ParaList.26609.body + { + this.paralist.addElement(obj); + parserlog.debug("ParaList: " + obj); + } + // ino.end + + // ino.method.get_firstElement.26612.definition + public Object get_firstElement() + // ino.end + // ino.method.get_firstElement.26612.body + { + return paralist.firstElement(); + } + // ino.end + // ino.method.getParalist.26615.definition + public Vector getParalist() + // ino.end + // ino.method.getParalist.26615.body + { + return paralist; + } + // ino.end + // ino.method.setParalist.26618.definition + public void setParalist(Vector paralist) + // ino.end + // ino.method.setParalist.26618.body + { + this.paralist = paralist; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytype/RefType.java b/src/mycompiler/mytype/RefType.java new file mode 100755 index 000000000..8ba53664e --- /dev/null +++ b/src/mycompiler/mytype/RefType.java @@ -0,0 +1,677 @@ +// ino.module.RefType.8675.package +package mycompiler.mytype; +// ino.end +// ino.module.RefType.8675.import +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.UsedId; +import mycompiler.myexception.SCException; +import mycompiler.mytypereconstruction.CSubstitutionGenVar; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import org.apache.log4j.Logger; +// ino.end + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + + + + +// ino.class.RefType.26621.declaration +public class RefType extends Type implements IMatchable +// ino.end +// ino.class.RefType.26621.body +{ + /** + * Ist IsArray auf true, muss beim Codegen ein Zeichen [ gesetzt werden + * Bsp.: 15| tag = CONSTANT_Utf8, length = 22, ([Ljava/lang/String;)V + * Ist IsArray auf false, muss beim Codegen ein Zeichen [ gesetzt werden + * Bsp.: 9| tag = CONSTANT_Utf8, length = 21, (Ljava/lang/String;)V + */ + private boolean IsArray = false; + + // ino.attribute.parameter.26625.declaration + private Vector parameter = null; + // ino.end + // ino.attribute.primitiveFlag.29412.decldescription type=javadoc + /** + * Ist primitiveFlag auf true, muss beim Codegen dieser Reftype durch + * den primitiven Datentyp ersetzt werden + * + * Bsp: java.lang.Integer mit Flag wird dann zu [int] + */ + // ino.end + // ino.attribute.primitiveFlag.29412.declaration + private boolean primitiveFlag=false; + // ino.end + // ino.attribute.parserlog.26628.declaration + protected static Logger parserlog = Logger.getLogger("parser"); + // ino.end + // ino.attribute.codegenlog.26631.declaration + protected static Logger codegenlog = Logger.getLogger("codegen"); + // ino.end + + + + // ino.method.RefType.26634.definition + public RefType(int offset) + // ino.end + // ino.method.RefType.26634.body + { + super(offset); + } + // ino.end + + // ino.method.RefType.26637.definition + public RefType(String fullyQualifiedName, int offset) + // ino.end + // ino.method.RefType.26637.body + { + super(offset); + this.setName(fullyQualifiedName); + } + // ino.end + + // ino.method.RefType.26640.definition + public RefType(String fullyQualifiedName, Vector parameter, int offset) + // ino.end + // ino.method.RefType.26640.body + { + super(offset); + this.setName(fullyQualifiedName); + if(parameter != null && parameter.size()>0)this.parameter = parameter; + } + // ino.end + + // ino.method.RefType.26643.definition + public RefType( RefType R, int offset ) + // ino.end + // ino.method.RefType.26643.body + { + super(offset); + // otth: Copy-Konstruktor + this.setName(R.getTypeName()); + this.parameter = R.get_ParaList(); + } + // ino.end + + /** + * Erstellt einen Referenztyp aus dem übergebenen Type. + * Dabei wird der Name und der Offset des baseType's übernommen. + * @param baseType + */ + public RefType( Type baseType ){ + super(baseType.getOffset()); + this.setName(baseType.name); + //this.parameter = null; + } + + // ino.method.Type2Key.26646.definition + public String Type2Key() + // ino.end + // ino.method.Type2Key.26646.body + { + if(parameter==null) + { + return name; + } + else + { + String para = new String(); + for(Enumeration e=parameter.elements();e.hasMoreElements();) + { + String t = ((Type)e.nextElement()).Type2Key(); + if(para.length() > 0) + para = para +", "+ t; + else para = " " + t; + } + return name + "<"+para + " >" ; + } + } + // ino.end + + // ino.method.Type2String.26649.definition + public String Type2String() + // ino.end + // ino.method.Type2String.26649.body + { + if(parameter==null) + { + return name; + } + else + { + String para = new String(); + for(Enumeration e=parameter.elements();e.hasMoreElements();) + { + String t = ((Type)e.nextElement()).Type2String(); + if(para.length() > 0) + para = para +", "+ t; + else para = " " + t; + } + return name + "<"+para + " >" ; + } + } + // ino.end + + // ino.method.GenericTypeVar2TypePlaceholder.26652.definition + public CSubstitutionSet GenericTypeVar2TypePlaceholder () + // ino.end + // ino.method.GenericTypeVar2TypePlaceholder.26652.body + { + CSubstitutionSet sub = new CSubstitutionSet(); + if(parameter != null) + { + for (int i = 0; i < parameter.size(); i++) + { + if (parameter.elementAt(i) instanceof GenericTypeVar) + { + TypePlaceholder tlv = TypePlaceholder.fresh(); + sub.addElement(new CSubstitutionGenVar((GenericTypeVar)parameter.elementAt(i), tlv)); + parameter.set(i, tlv); + } + if (parameter.elementAt(i) instanceof RefType) + { + CSubstitutionSet parasub = ((RefType)parameter.elementAt(i)).GenericTypeVar2TypePlaceholder(); + sub.addAll(parasub); //korrigiert PL 07=07=29 + } + } + } + return sub; + } + // ino.end + + // ino.method.setName.26655.definition + public void setName( String name ) + // ino.end + // ino.method.setName.26655.body + { + this.name = name; + } + // ino.end + + @Override + public String get_Name() + { + return getName(); + } + + // ino.method.getName.26658.definition + public String getName() + // ino.end + // ino.method.getName.26658.body + { + return name; + + // Damit wir hier konsistent bleiben, gibts nur + // den Typ, keine Generics! Sonst gibts Probleme mit der BCG + /* if(parameter==null) + { + return name; + } + else + { + String para = new String(); + Enumeration e=parameter.elements(); + while(e.hasMoreElements()) + { + Type ty = (Type)e.nextElement(); + String t = ty.getName(); + if(para.length() > 0) + para = para +", "+ t; + else para = " " + t; + } + return name + "<"+para + " >" ; + }*/ + } + // ino.end + + // ino.method.set_ParaList.26661.definition + public void set_ParaList(Vector v) + // ino.end + // ino.method.set_ParaList.26661.body + { + this.parameter = v; + parserlog.debug("T->Type.java->set_ParaList->parameter: " + parameter); + parserlog.debug("T->Type.java->get_Type: " + getName()); + } + // ino.end + + // ino.method.get_ParaList.26664.definition + public Vector get_ParaList() + // ino.end + // ino.method.get_ParaList.26664.body + { + return this.parameter; + } + // ino.end + + // ino.method.add_Parameter.26667.definition + public void add_Parameter(Type o) + // ino.end + // ino.method.add_Parameter.26667.body + { + this.parameter.add(o); + } + // ino.end + + // ino.method.getTypeName.26670.definition + public String getTypeName() + // ino.end + // ino.method.getTypeName.26670.body + { + // otth: Liefert den Namen des Typs, ohne Parameter, z.B. Stapel bei Stapel + return name; + } + // ino.end + + // ino.method.getParaN.26673.definition + public String getParaN( int n ) + throws SCException + // ino.end + // ino.method.getParaN.26673.body + { + // otth: liefert n.ten Parameter + if( parameter == null ) + { + throw new SCException(); + } + + if( n >= parameter.size() ) + return ""; + + return ((Type)parameter.elementAt(n)).getName(); + } + // ino.end + + // ino.method.isTV.26676.definition + public boolean isTV( int n ) + // ino.end + // ino.method.isTV.26676.body + { + // otth: Prueft, ob Parameter n eine TV ist + return parameter.elementAt(n) instanceof TypePlaceholder; + } + // ino.end + + + // ino.method.is_Equiv.26679.defdescription type=line + // GenericTypeVar ergaenzt PL 06-03-16 + // ino.end + // ino.method.is_Equiv.26679.definition + public boolean is_Equiv(RefType ty2, Hashtable ht) + // ino.end + // ino.method.is_Equiv.26679.body + { + //vergleicht einen Typ ty2 mit dem aktuellen Typ, ob es bis auf Variablenumbennung + //gleich ist. + //System.out.println("is_EquivSTART: " + this.get_Type()); + //System.out.println("is_EquivSTART: " + ty2.get_Type()); + if (this.getTypeName().equals(ty2.getTypeName())) { + //System.out.println("is_EquivSTARTx: " + this.get_Type()); + if ((get_ParaList() != null) && (ty2.get_ParaList() != null)) { + if (get_ParaList().size() == ty2.get_ParaList().size()) { + for(int i=0; i < get_ParaList().size(); i++) { + Type pty1 = (Type)get_ParaList().elementAt(i); + Type pty2 = (Type)ty2.get_ParaList().elementAt(i); + if ((pty1 instanceof RefType) && (pty2 instanceof RefType)) { + //System.out.println("Instance RefType" + ((RefType)pty1).get_Type()); + //System.out.println("Instance RefType" + ((RefType)pty2).get_Type()); + if (!((RefType)pty1).is_Equiv((RefType)pty2, ht)) return false; + } + else { + if ((pty1 instanceof TypePlaceholder) && (pty2 instanceof TypePlaceholder)) { + //System.out.println("Instance TypePlaceholder" + (((TypePlaceholder)pty1).get_Type())); + //System.out.println("Instance TypePlaceholder" + (((TypePlaceholder)pty2).get_Type())); + if (ht.get((((TypePlaceholder)pty1).getName())) != null) { + //System.out.println(ht.get((((TypePlaceholder)pty1).getName()))); + if (!((TypePlaceholder)ht.get((((TypePlaceholder)pty1).getName()))).getName().equals(pty2.getName())) return false; + } + else { + //System.out.println("INPUT" + pty1.getName()); + //System.out.println("INPUT" + pty2); + ht.put(pty1.getName(), pty2); + } + } + else { + if ((pty1 instanceof GenericTypeVar) && (pty2 instanceof GenericTypeVar)) { + if (ht.get((((GenericTypeVar)pty1).getName())) != null) { + if (!((GenericTypeVar)ht.get((((GenericTypeVar)pty1).getName()))).getName().equals(pty2.getName())) return false; + } + else { + ht.put(pty1.getName(), pty2); + } + } + else { + return false; + } + } + } + } + return true; + } + else { + return false; + } + } + else { + //Typ ohne Parameter + return true; + } + } + else { + return false; + } + } + // ino.end + + // ino.method.Equiv2Equal.26682.definition + public boolean Equiv2Equal(RefType ty2, Hashtable ht) + // ino.end + // ino.method.Equiv2Equal.26682.body + { + //vergleicht einen Typ ty2 mit dem aktuellen Typ, ob er bis auf Variablenumbennung + //gleich ist und bennent ty2 so um, dass sie gleich sind. + //System.out.println("is_EquivSTART: " + this.getName()); + //System.out.println("is_EquivSTART: " + ty2.getName()); + if (this.getTypeName().equals(ty2.getTypeName())) { + //System.out.println("is_EquivSTARTx: " + this.getName()); + if ((get_ParaList() != null) && (ty2.get_ParaList() != null)) { + if (get_ParaList().size() == ty2.get_ParaList().size()) { + for(int i=0; i < get_ParaList().size(); i++) { + Type pty1 = (Type)get_ParaList().elementAt(i); + Type pty2 = (Type)ty2.get_ParaList().elementAt(i); + if ((pty1 instanceof RefType) && (pty2 instanceof RefType)) { + //System.out.println("Instance RefType" + ((RefType)pty1).getName()); + //System.out.println("Instance RefType" + ((RefType)pty2).getName()); + if (!((RefType)pty1).is_Equiv((RefType)pty2, ht)) return false; + } + else { + if ((pty1 instanceof TypePlaceholder) && (pty2 instanceof TypePlaceholder)) { + //System.out.println("Instance TypePlaceholder" + (((TypePlaceholder)pty1).getName())); + //System.out.println("Instance TypePlaceholder" + (((TypePlaceholder)pty2).getName())); + if (ht.get((((TypePlaceholder)pty1).getName())) != null) { + //System.out.println(ht.get((((TypePlaceholder)pty1).getName()))); + if (!((TypePlaceholder)ht.get((((TypePlaceholder)pty1).getName()))).getName().equals(pty2.getName())) return false; + else { //Typvariablen gleich machen + // #JB# 11.04.2005 + // ########################################################### + ((TypePlaceholder)pty2).backdoorSetName(((TypePlaceholder)ht.get((((TypePlaceholder)pty1).getName()))).getName()); + //pty2.setName(((TypePlaceholder)ht.get((((TypePlaceholder)pty1).getName()))).getName()); + // ########################################################### + } + + } + else { + //System.out.println("INPUT" + pty1.getName()); + //System.out.println("INPUT" + pty2); + ht.put(pty1.getName(), pty2); + // #JB# 11.04.2005 + // ########################################################### + ((TypePlaceholder)pty2).backdoorSetName(pty1.getName()); + //pty2.setName(pty1.getName()); + // ########################################################### + } + } + else { + return false; + } + } + } + return true; + } + else { + return false; + } + } + else { + //Typ ohne Parameter + return true; + } + } + else { + return false; + } + } + // ino.end + + // ino.method.equals.26685.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26685.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26685.body + { + if(obj instanceof RefType){ + boolean ret = true; + + if(!super.equals(obj)) + return false; + + if(parameter==null || parameter.size()==0){ + ret &= (((RefType)obj).get_ParaList()==null || ((RefType)obj).get_ParaList().size()==0); + } + else{ + if(((RefType)obj).get_ParaList()==null){ + ret = false; + } + else if(parameter.size() != ((RefType)obj).get_ParaList().size()) + { + ret = false; + } + else + { + for(int i = 0; i clonepara = new Vector(); + for(int i = 0; i< para.size(); i++) + { + clonepara.addElement(((Type)para.elementAt(i)).clone()); + } + RefType newRefType=new RefType(this.getTypeName(), clonepara,getOffset()); + newRefType.setPrimitiveFlag(this.getPrimitiveFlag()); + return newRefType; + } + else { + RefType newRefType = new RefType(this.getTypeName(), null,getOffset()); + newRefType.setPrimitiveFlag(this.getPrimitiveFlag()); + + return newRefType; + } + } + // ino.end + + // ino.method.toString.26691.definition + public String toString() + // ino.end + // ino.method.toString.26691.body + { + String primitiveFlagMarker=primitiveFlag?"*":""; + if(parameter==null) + { + return name+primitiveFlagMarker; + } + else + { + String para = new String(); + Enumeration e=parameter.elements(); + while(e.hasMoreElements()) + { + Type ty = (Type)e.nextElement(); + String t = ty.toString(); + if(para.length() > 0) + para = para +", "+ t; + else para = " " + t; + } + String ret = name; + if(parameter.size()>0)ret += "<"+para + " >"; + return ret + primitiveFlagMarker;//name + "<"+para + " >" +primitiveFlagMarker; + } + } + // ino.end + + // ino.method.modifyToGenericTypeVar.26694.definition + public GenericTypeVar modifyToGenericTypeVar() + // ino.end + // ino.method.modifyToGenericTypeVar.26694.body + { + return new GenericTypeVar(this.name,getOffset()); + } + // ino.end + + // ino.method.getSimpleName.26697.defdescription type=javadoc + /** + * HOTI + * Liefert bei Klassen die fullyQualified angegeben wurden + * nur den schlussendlichen Bezeichner + * p.ex. java.util.Vector => Vector + * @return + */ + // ino.end + // ino.method.getSimpleName.26697.definition + public String getSimpleName() + // ino.end + // ino.method.getSimpleName.26697.body + { + return UsedId.createFromQualifiedName(getTypeName(),getOffset()).getSimpleName(); + } + // ino.end + + // ino.method.getSignatureType.26700.definition + public String getSignatureType(Vector paralist) + // ino.end + // ino.method.getSignatureType.26700.body + { + if (parameter == null || parameter.size() == 0) + return get_codegen_Type(paralist); + + StringBuffer sb = new StringBuffer(); + + // Basistyp, ; entfernen + String basis = JVMCode.get_codegen_Type(getTypeName(),null); + basis = basis.substring(0, basis.length() -1); + sb.append(basis); + + sb.append("<"); + + for(int i = 0; i< parameter.size(); i++) { + sb.append(parameter.elementAt(i).get_codegen_Type(null)); + } + + sb.append(">;"); + + return sb.toString(); + } + // ino.end + + // ino.method.setPrimitiveFlag.29415.definition + public void setPrimitiveFlag(boolean b) + // ino.end + // ino.method.setPrimitiveFlag.29415.body + { + this.primitiveFlag=b; + } + // ino.end + // ino.method.getPrimitiveFlag.29418.definition + public boolean getPrimitiveFlag() + // ino.end + // ino.method.getPrimitiveFlag.29418.body + { + return(this.primitiveFlag); + } + // ino.end + + + /** + * Author: Daniel Feinler
+ * Handelt ab, ob der Typ eines Objekts ein Array ist, wenn true dann + * wird im Bytecode ein flag gesetzt wenn nicht, dann halt nicht. + * @return the IsArray + */ + public boolean IsArray() { + return IsArray; + } + + /** + * Author: Daniel Feinler
+ * Handelt ab, ob der Typ eines Objekts ein Array ist, wenn true dann + * wird im Bytecode ein flag gesetzt wenn nicht, dann halt nicht. + * @param IsArray the IsArray to set + */ + public void setArray(boolean IsArray) { + this.IsArray = IsArray; + } + + /** + * Author: Arne Lüdtke
+ * Gibt den Typen zurück, der bei einem match im Unify verwendet werden soll. + * Wird über IMatchable implementiert. + */ + public Type getMatchType() + { + return this; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + JavaCodeResult ret = new JavaCodeResult(this.name); + if(this.get_ParaList()!=null && this.get_ParaList().size()>0){ + ret .attach( "<" ); + Iterator it = this.get_ParaList().iterator(); + while(it.hasNext()){ + Type t = it.next(); + ret .attach( t.printJavaCode(resultSet)); + if(it.hasNext())ret.attach(", "); + } + //ret = ret.substring(0,ret.length()-2); + ret .attach(">"); + } + return ret; + } + + /** + * Liefert alle SuperWildcardTypes, die in diesem Typ enthalten sind. + * Dabei werden auch die parameter auf SuperWildcardTypes durchsucht. + * @return + */ + @Override + public ArrayList getSuperWildcardTypes() { + ArrayList ret = super.getSuperWildcardTypes(); + if(this.parameter!=null)for(Type paraType : this.parameter){ + if(paraType instanceof SuperWildcardType)ret.add((SuperWildcardType)paraType); + } + return ret; + } + +} +// ino.end + diff --git a/src/mycompiler/mytype/ReturnType.java b/src/mycompiler/mytype/ReturnType.java new file mode 100755 index 000000000..c7663f45e --- /dev/null +++ b/src/mycompiler/mytype/ReturnType.java @@ -0,0 +1,64 @@ +// ino.module.ReturnType.8676.package +package mycompiler.mytype; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +// ino.end +// ino.class.ReturnType.26703.declaration +public class ReturnType extends Type +// ino.end +// ino.class.ReturnType.26703.body +{ + // ino.method.ReturnType.26707.definition + public ReturnType(int offset) + // ino.end + // ino.method.ReturnType.26707.body + { + super(offset); + } + // ino.end + + // ino.method.equals.26710.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26710.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26710.body + { + if(obj instanceof ReturnType){ + return super.equals(obj); + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26713.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26713.definition + public ReturnType clone() + // ino.end + // ino.method.clone.26713.body + { + return new ReturnType(getOffset()); + } + // ino.end + + @Override +public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO Auto-generated method stub + return null; + } +} +// ino.end diff --git a/src/mycompiler/mytype/SuperWildcardType.java b/src/mycompiler/mytype/SuperWildcardType.java new file mode 100755 index 000000000..1a65a4c29 --- /dev/null +++ b/src/mycompiler/mytype/SuperWildcardType.java @@ -0,0 +1,132 @@ +package mycompiler.mytype; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +/** + * Stellt eine Wildcard mit unterer Grenze dar. + * z.B. void test(? super Integer var){..} + * ... + * @author luar 2.12.06 + * + */ + +public class SuperWildcardType extends WildcardType implements ITypeContainer, IMatchable{ + + private Type superType = null; + + /** + * Author: Arne Lüdtke
+ * Standard Konstruktor für eine SuperWildcard + */ + public SuperWildcardType(int offset, Type superType) + { + super(offset); + this.superType = superType; + } + + /** + * Author: Arne Lüdtke
+ * Gibt den Typen in der Wildcard zurück. + * Beispiel: ? super Integer. + * Integer wird zurückgegeben. + */ + public Type get_SuperType() + { + return this.superType; + } + + /** + * Author: Arne Lüdtke
+ * Gibt String Entsprechung zurück. + */ + public String toString() + { + return "? super " + superType.toString(); + } + + /** + * Author: Arne Lüdtke
+ * Gibt einen Klon der Wildcard zurück. + * Der Innere Typ wird auch geklont + */ + public SuperWildcardType clone() + { + //Hier ist unklar, ob der Supertyp auch geklont werden muss. + return new SuperWildcardType(getOffset(), superType.clone()); + } + + /** + * Author: Arne Lüdtke
+ * Vergleicht mit einem anderen Objekt. + * @param obj - Object to compare. + */ + public boolean equals(Object obj) + { + if(obj instanceof SuperWildcardType) + { + return this.superType.equals(((SuperWildcardType)obj).get_SuperType()); + } + else + { + return false; + } + } + + /** + * Author: Arne Lüdtke
+ * Gibt die passende FreshWildcardType Klasse zurück. + * Wird für CaptureConversion verwendet + */ + public FreshSuperWildcardType GetFreshWildcardType() + { + return new FreshSuperWildcardType(this.superType,-1); + } + + /** + * Author: Arne Lüdtke
+ * Das gleiche wie get_SuperType(). + * Überschreibt die Methode der Superklasse + */ + public Type GetWildcardType() + { + return this.get_SuperType(); + } + + /** + * Author: Arne Lüdtke
+ * Setzt den Typ in der Wildcard + * @param T - Type to be set + */ + public void SetWildcardType(Type T) + { + if(T instanceof RefType) + this.superType = (RefType)T; + } + + /** + * Author: Arne Lüdtke
+ * Das gleiche wie get_SuperType(). + * Implementiert ITypeContainer + */ + public Type getContainedType() + { + return this.get_SuperType(); + } + + /** + * Author: Arne Lüdtke
+ * Gibt den Typen zurück, der bei einem match im Unify verwendet werden soll. + * Wird über IMatchable implementiert. + */ + public Type getMatchType() + { + return this.get_SuperType(); + } + + @Override + public JavaCodeResult printJavaCode(ResultSet result){ + return new JavaCodeResult(this.toString()); + } + +} diff --git a/src/mycompiler/mytype/Type.java b/src/mycompiler/mytype/Type.java new file mode 100755 index 000000000..15b23b94d --- /dev/null +++ b/src/mycompiler/mytype/Type.java @@ -0,0 +1,259 @@ +// ino.module.Type.8677.package +package mycompiler.mytype; +// ino.end +// ino.module.Type.8677.import +import java.util.ArrayList; +import java.util.Vector; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import mycompiler.IItemWithOffset; +import mycompiler.mybytecode.JVMCode; +import mycompiler.myclass.UsedId; +// ino.end + + + + +// ino.class.Type.26716.declaration +public class Type implements IItemWithOffset +// ino.end +// ino.class.Type.26716.body +{ + // ino.attribute.name.26720.declaration + protected String name; + // ino.end + // ino.attribute.used.26723.declaration + protected UsedId used; + // ino.end + // ino.attribute.offset.26726.declaration + private int offset; + // ino.end + + // ino.method.Type.26729.definition + public Type(String s, int offset) + // ino.end + // ino.method.Type.26729.body + { + this(offset); + this.name = s; + } + // ino.end + + // ino.method.Type.26732.definition + public Type(int offset) + // ino.end + // ino.method.Type.26732.body + { + this.offset=offset; + } + // ino.end + + // ino.method.getOffset.26735.definition + public int getOffset() + // ino.end + // ino.method.getOffset.26735.body + { + return offset; + } + // ino.end + + // ino.method.getVariableLength.26738.definition + public int getVariableLength() + // ino.end + // ino.method.getVariableLength.26738.body + { + if(this.name!=null){return this.name.length();} + else{return 1;} + } + // ino.end + + // ino.method.set_UsedId.26741.definition + public void set_UsedId( UsedId uid) + // ino.end + // ino.method.set_UsedId.26741.body + { + this.used = uid; + } + // ino.end + + + + // ino.method.get_UsedId.26744.definition + public UsedId get_UsedId() + // ino.end + // ino.method.get_UsedId.26744.body + { + return this.used; + } + // ino.end + + + + // ino.method.get_Name.26747.definition + public String get_Name() + // ino.end + // ino.method.get_Name.26747.body + { + return used.name.toString(); + } + // ino.end + + // ino.method.get_codegen_Type.26750.defdescription type=javadoc + /** + * Liefert die Typrepraesentation fuer die + * Bytecodegenerierung zurueck. + */ + // ino.end + // ino.method.get_codegen_Type.26750.definition + public String get_codegen_Type(Vector paralist) + // ino.end + // ino.method.get_codegen_Type.26750.body + { + return JVMCode.get_codegen_Type(name, paralist); + } + // ino.end + + // ino.method.getSignatureType.26753.defdescription type=javadoc + /** + * Liefert den Typ fuer das Signature-Attribut zurueck. + */ + // ino.end + // ino.method.getSignatureType.26753.definition + public String getSignatureType(Vector paralist) + // ino.end + // ino.method.getSignatureType.26753.body + { + return get_codegen_Type(paralist); + } + // ino.end + + + // ino.method.Type2String.26756.definition + public String Type2String() + // ino.end + // ino.method.Type2String.26756.body + { + return "((TypePlaceholder))" + getName(); + } + // ino.end + + // ino.method.Type2Key.26759.definition + public String Type2Key() + // ino.end + // ino.method.Type2Key.26759.body + { + return ""; + } + // ino.end + + // ino.method.getName.26762.definition + public String getName() + // ino.end + // ino.method.getName.26762.body + { + return name; + } + // ino.end + + // ino.method.equals.26765.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26765.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26765.body + { + if(obj instanceof Type){ + String name2 = ((Type)obj).name; + return getName().equals(name2); + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26768.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26768.definition + public Type clone() + // ino.end + // ino.method.clone.26768.body + { + return new Type(this.getName(),getOffset()); + } + // ino.end + + // ino.method.toString.26771.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.toString.26771.definition + public String toString() + // ino.end + // ino.method.toString.26771.body + { + return getName(); + } + // ino.end + + // ino.method.removeClassParameters.26774.definition + public Type removeClassParameters() + // ino.end + // ino.method.removeClassParameters.26774.body + { + if(this instanceof RefType){ + RefType rt=(RefType)this.clone(); + rt.set_ParaList(null); + return(rt); + }else{ + return(this); + } + } + // ino.end + + // ino.method.getSimpleName.26777.defdescription type=javadoc + /** + * HOTI + * Liefert bei Klassen die fullyQualified angegeben wurden + * nur den schlussendlichen Bezeichner + * p.ex. java.util.Vector => Vector + * @return + */ + // ino.end + // ino.method.getSimpleName.26777.definition + public String getSimpleName() + // ino.end + // ino.method.getSimpleName.26777.body + { + return UsedId.createFromQualifiedName(getName(),getOffset()).getSimpleName(); + } + // ino.end + + public JavaCodeResult printJavaCode(ResultSet resultSet){ + return new JavaCodeResult(this.name); + } + + /** + * Liefert alle SuperWildcardTypes, die in diesem Typ enthalten sind. + * @return + */ + public ArrayList getSuperWildcardTypes() { + ArrayList ret = new ArrayList(); + if(this instanceof SuperWildcardType)ret.add((SuperWildcardType)this); + return ret; + } + +} +// ino.end diff --git a/src/mycompiler/mytype/TypePlaceholder.java b/src/mycompiler/mytype/TypePlaceholder.java new file mode 100755 index 000000000..c996f9aa8 --- /dev/null +++ b/src/mycompiler/mytype/TypePlaceholder.java @@ -0,0 +1,513 @@ +// ino.module.TypePlaceholder.8678.package +package mycompiler.mytype; +// ino.end + +// ino.module.TypePlaceholder.8678.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; + +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; +import mycompiler.MyCompiler; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.replacementlistener.IReplaceTypeEventProvider; +import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; +// ino.end + +// ino.class.TypePlaceholder.26780.description type=javadoc +/** + * Repr�sentiert einen Typparameter f�r einen vom Programmierer nicht angegeben + * Typ. Jede TypePlaceholder besitzt einen eindeutigen Namen aus einem Namenspool + * und + * ist in einer zentralen Registry, d.h. einer Hashtable abgelegt. + * @author J�rg B�uerle + * @version $Date: 2013/06/19 12:45:37 $ + */ +// ino.end +// ino.class.TypePlaceholder.26780.declaration +public class TypePlaceholder extends Type implements IReplaceTypeEventProvider +// ino.end +// ino.class.TypePlaceholder.26780.body +{ + // ino.attribute.strNextName.26785.declaration + private static String strNextName = "A"; + // ino.end + // ino.attribute.m_TypePlaceholdersRegistry.26788.declaration + private static Hashtable m_TypePlaceholdersRegistry = new Hashtable(); + // ino.end + + // ino.attribute.m_ReplacementListeners.26791.declaration + private Vector m_ReplacementListeners; + // ino.end + + // ino.method.TypePlaceholder.26794.defdescription type=javadoc + /** + * Privater Konstruktor - Eine TypePlaceholder-Variable wird �ber die + * Factory-Methode fresh() erzeugt. + *
Author: J�rg B�uerle + * @param typeName Der Name der TypePlaceholder-Variablen + */ + // ino.end + // ino.method.TypePlaceholder.26794.definition + private TypePlaceholder(String typeName) + // ino.end + // ino.method.TypePlaceholder.26794.body + { + super(-1); + this.name = typeName; + m_ReplacementListeners = new Vector(); + } + // ino.end + + // ino.method.getInstance.26797.defdescription type=javadoc + /** + * Statische Methode, um einen TypePlaceholder aus der Registry zu holen. + *
Author: J�rg B�uerle + * @param name Der Name des TypePlaceholders + * @return Der TypePlaceholder oder null, falls er nicht in der + * Registry existiert + */ + // ino.end + // ino.method.getInstance.26797.definition + public static TypePlaceholder getInstance(String name) + // ino.end + // ino.method.getInstance.26797.body + { + return m_TypePlaceholdersRegistry.get(name); + } + // ino.end + + // ino.method.fresh.26800.defdescription type=javadoc + /** + * Erzeugt eine neue TypePlaceholder mit einem eindeutigen Namen. Die + * erzeugte Instanz ist die einzig im Syntaxbaum existierende Instanz dieser + * Variablen.
Author: J�rg B�uerle + * @return Die TypePlaceholder + */ + // ino.end + // ino.method.fresh.26800.definition + public static TypePlaceholder fresh() + // ino.end + // ino.method.fresh.26800.body + { + TypePlaceholder typeVar = new TypePlaceholder(makeNewName()); + m_TypePlaceholdersRegistry.put(typeVar.getName(), typeVar); + return typeVar; + } + // ino.end + + /** + * @author Andreas Stadelmeier, a10023 + * Ruft die TypePlaceholder.fresh()-Methode auf. + * Fügt zusätzlich einen Replacementlistener hinzu. + * @param listener + * @return + */ + public static TypePlaceholder fresh(ITypeReplacementListener listener){ + TypePlaceholder ret = fresh(); + //System.out.println(""+ret+" -> "+listener); + ret.addReplacementListener(listener); + return ret; + } + + // ino.method.makeNewName.26803.defdescription type=javadoc + /** + * Berechnet einen neuen, eindeutigen Namen f�r eine neue + * TypePlaceholder.
Author: J�rg B�uerle + * @return Der Name + */ + // ino.end + // ino.method.makeNewName.26803.definition + private static String makeNewName() + // ino.end + // ino.method.makeNewName.26803.body + { + // otth: Funktion berechnet einen neuen Namen anhand eines alten gespeicherten + String strReturn = strNextName; + + // n�chster Name berechnen und in strNextName speichern + inc( strNextName.length() - 1 ); + + return strReturn; + } + // ino.end + + // ino.method.inc.26806.defdescription type=javadoc + /** + * Hilfsfunktion zur Berechnung eines neuen Namens + *
Author: J�rg B�uerle + * @param i + */ + // ino.end + // ino.method.inc.26806.definition + private static void inc(int i) + // ino.end + // ino.method.inc.26806.body + { + // otth: Hilfsfunktion zur Berechnung eines neuen Namens + // otth: Erh�hung des Buchstabens an der Stelle i im String strNextName + // otth: Nach �berlauf: rekursiver Aufruf + + // falls i = -1 --> neuer Buchstabe vorne anf�gen + if ( i == -1 ) + { + strNextName = "A" + strNextName; + return; + } + + char cBuchstabe = (char)(strNextName.charAt( i )); + cBuchstabe++; + if ( cBuchstabe - 65 > 25 ) + { + // aktuelle Stelle: auf A zuruecksetzen + manipulate( i, 'A' ); + + // vorherige Stelle erh�hen + inc( i - 1 ); + } + else + { + // aktueller Buchstabe �ndern + manipulate( i, cBuchstabe ); + } + + } + // ino.end + + // ino.method.manipulate.26809.defdescription type=javadoc + /** + * Hilfsfunktion zur Berechnung eines neuen Namens. + *
Author: J�rg B�uerle + * @param nStelle + * @param nWert + */ + // ino.end + // ino.method.manipulate.26809.definition + private static void manipulate( int nStelle, char nWert ) + // ino.end + // ino.method.manipulate.26809.body + { + // otth: Hilfsfunktion zur Berechnung eines neuen Namens + // otth: Ersetzt im String 'strNextName' an der Position 'nStelle' den Buchstaben durch 'nWert' + + String strTemp = ""; + for( int i = 0; i < strNextName.length(); i++) + { + if ( i == nStelle ) + strTemp = strTemp + nWert; + else + strTemp = strTemp + strNextName.charAt( i ); + } + strNextName = strTemp; + } + // ino.end + + // ino.method.equals.26812.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26812.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26812.body + { + if(obj instanceof TypePlaceholder){ + return this.toString().equals(((TypePlaceholder)obj).toString()); + //return super.equals(obj); + } + else{ + return false; + } + } + // ino.end + + // ino.method.addReplacementListener.26815.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param listener + */ + // ino.end + // ino.method.addReplacementListener.26815.definition + public void addReplacementListener(ITypeReplacementListener listener) + // ino.end + // ino.method.addReplacementListener.26815.body + { + if(!this.containsListener(listener)){ + m_ReplacementListeners.addElement(listener); + } + } + // ino.end + + // ino.method.containsListener.26818.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param listener + * @return + */ + // ino.end + // ino.method.containsListener.26818.definition + public boolean containsListener(ITypeReplacementListener listener) + // ino.end + // ino.method.containsListener.26818.body + { + return m_ReplacementListeners.contains(listener); + } + // ino.end + + // ino.method.removeReplacementListener.26821.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param listener + */ + // ino.end + // ino.method.removeReplacementListener.26821.definition + public void removeReplacementListener(ITypeReplacementListener listener) + // ino.end + // ino.method.removeReplacementListener.26821.body + { + m_ReplacementListeners.removeElement(listener); + } + // ino.end + + // ino.method.removeAllReplacementListeners.26824.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + */ + // ino.end + // ino.method.removeAllReplacementListeners.26824.definition + public void removeAllReplacementListeners() + // ino.end + // ino.method.removeAllReplacementListeners.26824.body + { + m_ReplacementListeners.removeAllElements(); + } + // ino.end + + // ino.method.fireReplaceTypeEvent.26827.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @param e + */ + // ino.end + // ino.method.fireReplaceTypeEvent.26827.definition + public void fireReplaceTypeEvent(CReplaceTypeEvent e) + // ino.end + // ino.method.fireReplaceTypeEvent.26827.body + { + for(int i=0; iAuthor: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.getReplacementListeners.26830.definition + public Iterator getReplacementListeners() + // ino.end + // ino.method.getReplacementListeners.26830.body + { + return m_ReplacementListeners.iterator(); + } + // ino.end + + // ino.method.replaceWithType.26833.defdescription type=javadoc + /** + * Diese Methode geht alle TypeReplacmentListener durch und tauscht �ber deren + * Callback-Methode diesen Typ gegen den neuen aus. + *
Author: J�rg B�uerle + * @param newType + */ + // ino.end + // ino.method.replaceWithType.26833.definition + public void replaceWithType(Type newType) + // ino.end + // ino.method.replaceWithType.26833.body + { + this.fireReplaceTypeEvent(new CReplaceTypeEvent(this, newType)); + } + // ino.end + + // ino.method.getLineNumbers.26836.definition + public Vector getLineNumbers() + // ino.end + // ino.method.getLineNumbers.26836.body + { + Vector lineNumbers = new Vector(); + for(int i=0; iMyCompiler.init() aufgerufen werden!!! + *
Author: J�rg B�uerle + */ + // ino.end + // ino.method.deleteRegistry.26839.definition + public static void deleteRegistry() + // ino.end + // ino.method.deleteRegistry.26839.body + { + m_TypePlaceholdersRegistry.clear(); + m_TypePlaceholdersRegistry = new Hashtable(); + } + // ino.end + + // ino.method.clone.26842.defdescription type=javadoc + /** + * Diese Methode sollte nur sehr sparsam und mit Vorsicht verwendet werden, da die + * Registrierung neuer Listener �ber die zentrale Instanz in der Registry laufen + * muss.
+ * Diese Methode erzeugt eine Kopie dieser zentralen Instanz. Listener, die sich + * �ber diese Kopie registrieren, werden sp�ter nicht �ber Status�nderungen + * benachrichtigt, d.h. ihre TypePlaceholders werden nicht substituiert. + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26842.definition + public TypePlaceholder clone() + // ino.end + // ino.method.clone.26842.body + { + TypePlaceholder dolly = new TypePlaceholder(name); + dolly.m_ReplacementListeners = (Vector)m_ReplacementListeners.clone(); + return dolly; + } + // ino.end + + /** + * @author Andreas Stadelmeier, a10023 + * Überschreibt die get_Name-Methode der Type-Klasse. (Keine Ahnung wieso es überhaupt ein get_Name und ein getName gibt!) + */ + @Override + public String get_Name(){ + return getName(); + } + + // ino.method.toString.26845.definition + public String toString() + // ino.end + // ino.method.toString.26845.body + { + return "TPH " + this.getName(); + } + // ino.end + + /////////////////////////////////////////////////////////////////// + // Spezialfunktionen, f�r makeFC() und unify() + // Sollten sonst nicht aufgerufen werden... + /////////////////////////////////////////////////////////////////// + // ino.method.backdoorFresh.26848.defdescription type=javadoc + /** + * Backdoor-Hilfsfunktion, die f�r makeFC() und unify() + * ben�tigt wird, um neue TypePlaceholders zu erzeugen. Die erzeugten Variablen + * werden nicht registriert und sind v�llig losgel�st vom abstrakten Syntaxbaum. + *
Author: J�rg B�uerle + * @return Eine neue TypePlaceholder + */ + // ino.end + // ino.method.backdoorFresh.26848.definition + public static TypePlaceholder backdoorFresh() + // ino.end + // ino.method.backdoorFresh.26848.body + { + + //PL 05-08-22 SEHR GEFAEHRLICH + //backdoorvars werden registiert, weil am Ende beim execute + //auf den CSubstitution nicht registrierte Variablen zu + //Exceptions fuehrt + TypePlaceholder typeVar = new TypePlaceholder(makeNewName()); + m_TypePlaceholdersRegistry.put(typeVar.getName(), typeVar); + return typeVar; + + //return new TypePlaceholder(makeNewName()); + } + // ino.end + + // ino.method.backdoorSetName.26851.defdescription type=javadoc + /** + * Backdoor-Hilfsfunktion, die f�r makeFC() und unify() + * ben�tigt wird, um den Namen eines TypePlaceholders zu ver�ndern.
+ * ACHTUNG: Diese TypePlaceholder darf nicht Teil des abstrakten + * Syntaxbaumes sein!!! Es muss sicher gestellt werden, dass die betreffende + * TypePlaceholder nicht �ber die Methode fresh(), + * sondern �ber backdoorCreate() oder backdoorClone() + * erzeugt worden ist. + *
Author: J�rg B�uerle + * @param varName Der Name des zu erzeugenden TypePlaceholders + */ + // ino.end + // ino.method.backdoorSetName.26851.definition + public void backdoorSetName(String varName) + // ino.end + // ino.method.backdoorSetName.26851.body + { + name = varName; + } + // ino.end + + // ino.method.backdoorCreate.26854.defdescription type=javadoc + /** + * Backdoor-Hilfsfunktion, die f�r makeFC() und unify() + * ben�tigt wird, zum Erzeugen eines TypePlaceholders, der nicht in + * der zentralen Registry eingetragen wird. Die erzeugte Variablen ist somit v�llig + * losgel�st vom abstrakten Syntaxbaum.
Author: J�rg B�uerle + * @param name + * @return + */ + // ino.end + // ino.method.backdoorCreate.26854.definition + public static TypePlaceholder backdoorCreate(String name) + // ino.end + // ino.method.backdoorCreate.26854.body + { + + //PL 05-08-22 SEHR GEFAEHRLICH + //backdoorvars werden registiert, weil am Ende beim execute + //auf den CSubstitution nicht registrierte Variablen zu + //Exceptions fuehrt + TypePlaceholder typeVar = new TypePlaceholder(name); + m_TypePlaceholdersRegistry.put(typeVar.getName(), typeVar); + return typeVar; + + //return new TypePlaceholder(name); + } + // ino.end + /////////////////////////////////////////////////////////////////// + // Ende Spezialfunktionen + /////////////////////////////////////////////////////////////////// + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + Type equalType = resultSet.getTypeEqualTo(this); + if(equalType == null || equalType.equals(this)){ + //Für den Fall das der TPH nicht aufgelöst werden konnte. + JavaCodeResult ret = new JavaCodeResult(this.getName()); + //Jetzt muss eine nicht aufgelöste generische Variable dem JavaCodeResult-Set angefügt werden + ret.addUnresolvedTPH(this); + return ret; + } + + return equalType.printJavaCode(resultSet); + } + +} +// ino.end diff --git a/src/mycompiler/mytype/Void.java b/src/mycompiler/mytype/Void.java new file mode 100755 index 000000000..00c817780 --- /dev/null +++ b/src/mycompiler/mytype/Void.java @@ -0,0 +1,65 @@ +// ino.module.Void.8679.package +package mycompiler.mytype; +// ino.end +// ino.class.Void.26857.declaration +public class Void extends RefType +// ino.end +// ino.class.Void.26857.body +{ + // ino.method.Void.26861.definition + public Void(int offset) + // ino.end + // ino.method.Void.26861.body + { + super(offset); + super.setName("void"); + } + // ino.end + + // ino.method.equals.26864.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param Object + * @return + */ + // ino.end + // ino.method.equals.26864.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26864.body + { + if(obj instanceof RefType){ + boolean ret = true; + ret &= super.equals(obj); + // if(name==null){ + // ret &= ((Void)obj).get_Name()==null; + // } + + //PL 05-07-31 auf void kann man nicht casten, da parameter in RefType private + //ret &= name.equals(((Void)obj).getName()); + ret &= name.equals(((Type)obj).getName()); + + return ret; + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.26867.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.clone.26867.definition + public Void clone() + // ino.end + // ino.method.clone.26867.body + { + return new Void(getOffset()); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytype/WildcardType.java b/src/mycompiler/mytype/WildcardType.java new file mode 100755 index 000000000..0a796db7d --- /dev/null +++ b/src/mycompiler/mytype/WildcardType.java @@ -0,0 +1,98 @@ +package mycompiler.mytype; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import typinferenz.JavaCodeResult; +import typinferenz.ResultSet; + +/** + * Stellt eine Wildcard in Java dar. + * z.B. void Test(? var){..} + * @author luar 2.12.06 + * + */ + +public class WildcardType extends Type{ + + /** + * Author: Arne Lüdtke
+ * Standard Konstruktor für eine Wildcard + */ + public WildcardType(int offset) + { + super(offset); + } + + /** + * Author: Arne Lüdtke
+ * Gibt String Entsprechung zurück. + */ + public String toString() + { + return "?"; + } + + /** + * Author: Arne Lüdtke
+ * Gibt einen Klon der Wildcard zurück. + */ + public WildcardType clone() + { + return new WildcardType(getOffset()); + } + + /** + * Author: Arne Lüdtke
+ * Vergleicht mit einem anderen Objekt. + * @param obj - Object to compare. + */ + public boolean equals(Object obj) + { + //Luar 06-11-29 If Block erstellt, falls weitere Einschränkungen notwendig werden. + if(obj instanceof WildcardType && !(obj instanceof SuperWildcardType || obj instanceof ExtendsWildcardType)) + { + return true; + } + else + { + return false; + } + } + + /** + * Author: Arne Lüdtke
+ * Gibt die passende FreshWildcardType Klasse zurück. + * Wird für CaptureConversion verwendet + */ + public FreshWildcardType GetFreshWildcardType() + { + return new FreshWildcardType(-1); + } + + /** + * Author: Arne Lüdtke
+ * Die Allgemeine Wildcard enthält keinen Typen. + */ + public Type GetWildcardType() + { + return null; + } + + /** + * Author: Arne Lüdtke
+ * Setzt den Typ in der Wildcard, Allgemeine Wildcard hat aber keinen Typen. + * @param T - Type to be set + */ + public void SetWildcardType(Type T) + { + + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet) { + //String ret = "? extends "; + //ret+=this.extendsType; + //TODO hier wird statt "? extends class" nur "class" ausgegeben + return new JavaCodeResult(this.toString()); + + } +} diff --git a/src/mycompiler/mytypereconstruction/CHelper.java b/src/mycompiler/mytypereconstruction/CHelper.java new file mode 100755 index 000000000..271b4825b --- /dev/null +++ b/src/mycompiler/mytypereconstruction/CHelper.java @@ -0,0 +1,62 @@ +// ino.module.CHelper.8681.package +package mycompiler.mytypereconstruction; +// ino.end + +// ino.module.CHelper.8681.import +import java.text.DateFormat; +import java.util.Date; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.CHelper.26871.description type=javadoc +/** + * @author Jörg Bäuerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CHelper.26871.declaration +public class CHelper +// ino.end +// ino.class.CHelper.26871.body +{ + // ino.attribute.inferencelog.26874.decldescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * Liefert die aktuelle Zeit in Langformat zurück. + * + * @return Zeit in Langformat als String + */ + // ino.end + + // ino.attribute.inferencelog.26874.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + + // ino.method.time.26877.definition + public static String time() + // ino.end + // ino.method.time.26877.body + { + DateFormat longTime = DateFormat.getTimeInstance(DateFormat.LONG); + return longTime.format(new Date()); + } + // ino.end + + // ino.method.print.26880.defdescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * Gibt einen String aus. + * + * @param s Der auszugebende String + */ + // ino.end + // ino.method.print.26880.definition + public static void print(String s) + // ino.end + // ino.method.print.26880.body + { + inferencelog.debug("TypeReconstruction@"+CHelper.time()+"> "+s); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/CIntersectionType.java b/src/mycompiler/mytypereconstruction/CIntersectionType.java new file mode 100755 index 000000000..7773f3725 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/CIntersectionType.java @@ -0,0 +1,127 @@ +// ino.module.CIntersectionType.8682.package +package mycompiler.mytypereconstruction; +// ino.end + +// ino.module.CIntersectionType.8682.import +import java.util.Vector; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumptionkey.CMethodKey; +// ino.end + +// ino.class.CIntersectionType.26883.description type=javadoc +/** + * Ein CIntersectionType gruppiert alle Typmglichkeiten einer + * bestimmten Methode, die ber den CMethodKey eindeutig definiert + * ist.

Bei der bisherigen Implementierung enthlt IntersectionType jedoch + * nur eine + * einzige Typmglichkeit, d.h. der Vector + * m_MethodTypeAssumptions enthlt stets nur ein einziges Element.
+ * Der Grund hierfr ist in der Kopplung der Typannahmen fr die einzelnen Methoden, + * d.h. der Typkombinationen, begrndet. Diese Kopplung von Methoden wird bisher ber + * die getrennten Mengen von CTypeReconstructionResults realisiert. + * @author Jrg Buerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CIntersectionType.26883.declaration +public class CIntersectionType +// ino.end +// ino.class.CIntersectionType.26883.body +{ + // ino.attribute.m_IntersectionTypeKey.26886.declaration + private CMethodKey m_IntersectionTypeKey; + // ino.end + // ino.attribute.m_MethodTypeAssumptions.26889.declaration + private Vector m_MethodTypeAssumptions; + // ino.end + + // ino.method.CIntersectionType.26892.definition + public CIntersectionType(String className, String methodIdentifier, int methodParaCount, int methodOverloadedID) + // ino.end + // ino.method.CIntersectionType.26892.body + { + m_IntersectionTypeKey = new CMethodKey(className, methodIdentifier, methodParaCount, methodOverloadedID); + m_MethodTypeAssumptions = new Vector(); + } + // ino.end + + // ino.method.CIntersectionType.26895.definition + public CIntersectionType(CMethodTypeAssumption assum) + // ino.end + // ino.method.CIntersectionType.26895.body + { + this(assum.getClassName(), assum.getIdentifier(), assum.getParaCount(),assum.getOverloadedMethodID()); + this.addMethodTypeAssumption(assum); + } + // ino.end + + // ino.method.getIntersectionTypeKey.26898.definition + public CMethodKey getIntersectionTypeKey() + // ino.end + // ino.method.getIntersectionTypeKey.26898.body + { + return m_IntersectionTypeKey; + } + // ino.end + + // ino.method.setIntersectionTypeKey.26901.definition + public void setIntersectionTypeKey(CMethodKey intersectionTypeKey) + // ino.end + // ino.method.setIntersectionTypeKey.26901.body + { + m_IntersectionTypeKey = intersectionTypeKey; + } + // ino.end + + // ino.method.getMethodTypeAssumptions.26904.definition + public Vector getMethodTypeAssumptions() + // ino.end + // ino.method.getMethodTypeAssumptions.26904.body + { + return m_MethodTypeAssumptions; + } + // ino.end + + // ino.method.setMethodTypeAssumptions.26907.definition + public void setMethodTypeAssumptions(Vector methodTypeAssumptions) + // ino.end + // ino.method.setMethodTypeAssumptions.26907.body + { + m_MethodTypeAssumptions = methodTypeAssumptions; + } + // ino.end + + // ino.method.addMethodTypeAssumption.26910.definition + public void addMethodTypeAssumption(CMethodTypeAssumption assum) + // ino.end + // ino.method.addMethodTypeAssumption.26910.body + { + m_MethodTypeAssumptions.addElement(assum); + } + // ino.end + + // ino.method.removeMethodTypeAssumption.26913.definition + public void removeMethodTypeAssumption(CMethodTypeAssumption assum) + // ino.end + // ino.method.removeMethodTypeAssumption.26913.body + { + m_MethodTypeAssumptions.removeElement(assum); + } + // ino.end + + // ino.method.toString.26916.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @return + */ + // ino.end + // ino.method.toString.26916.definition + public String toString() + // ino.end + // ino.method.toString.26916.body + { + return m_MethodTypeAssumptions.toString(); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/CMultiplyTuple.java b/src/mycompiler/mytypereconstruction/CMultiplyTuple.java new file mode 100755 index 000000000..086411758 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/CMultiplyTuple.java @@ -0,0 +1,217 @@ +// ino.module.CMultiplyTuple.8683.package +package mycompiler.mytypereconstruction; +// ino.end + +// ino.module.CMultiplyTuple.8683.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +// ino.end + +// ino.class.CMultiplyTuple.26919.description type=javadoc +/** + * Container-Klasse für Ergebniswerte der Algorithmen TRTuple und TRMultiply. + * (siehe Algorithmen 5.28 ff, Martin Plümicke) + * @author Jörg Bäuerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CMultiplyTuple.26919.declaration +public class CMultiplyTuple +// ino.end +// ino.class.CMultiplyTuple.26919.body +{ + // ino.attribute.m_Substitutions.26922.declaration + private CSubstitutionSet m_Substitutions = null; + // ino.end + // ino.attribute.m_ResultTypes.26925.declaration + private Vector m_ResultTypes = null; + // ino.end + // ino.attribute.m_AssumptionSet.26928.declaration + private CTypeAssumptionSet m_AssumptionSet = null; + // ino.end + + // ino.method.CMultiplyTuple.26931.defdescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * + */ + // ino.end + // ino.method.CMultiplyTuple.26931.definition + public CMultiplyTuple() + // ino.end + // ino.method.CMultiplyTuple.26931.body + { + m_Substitutions = new CSubstitutionSet(); + m_ResultTypes = new Vector(); + m_AssumptionSet = new CTypeAssumptionSet(); + } + // ino.end + + // ino.method.CMultiplyTuple.26934.definition + public CMultiplyTuple(CSubstitutionSet substitutions, Vector resultTypes, CTypeAssumptionSet assumptionSet) + // ino.end + // ino.method.CMultiplyTuple.26934.body + { + m_Substitutions = substitutions; + m_ResultTypes = resultTypes; + m_AssumptionSet = assumptionSet; + } + // ino.end + + + // ino.method.getAssumptionSet.26937.defdescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * @return Returns the AssumptionSet. + */ + // ino.end + // ino.method.getAssumptionSet.26937.definition + public CTypeAssumptionSet getAssumptionSet() + // ino.end + // ino.method.getAssumptionSet.26937.body + { + return m_AssumptionSet; + } + // ino.end + + // ino.method.setAssumptionSet.26940.defdescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * @param assumptionSet The AssumptionSet to set. + */ + // ino.end + // ino.method.setAssumptionSet.26940.definition + public void setAssumptionSet(CTypeAssumptionSet assumptionSet) + // ino.end + // ino.method.setAssumptionSet.26940.body + { + m_AssumptionSet = assumptionSet; + } + // ino.end + + // ino.method.getResultTypes.26943.defdescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * @return Returns the ResultTypes. + */ + // ino.end + // ino.method.getResultTypes.26943.definition + public Vector getResultTypes() + // ino.end + // ino.method.getResultTypes.26943.body + { + return m_ResultTypes; + } + // ino.end + + // ino.method.getResultTypeIterator.26946.definition + public Iterator getResultTypeIterator() + // ino.end + // ino.method.getResultTypeIterator.26946.body + { + return this.getResultTypes().iterator(); + } + // ino.end + + // ino.method.setResultTypes.26949.defdescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * @param resultType The ResultType to set. + */ + // ino.end + // ino.method.setResultTypes.26949.definition + public void setResultTypes(Vector resultTypes) + // ino.end + // ino.method.setResultTypes.26949.body + { + m_ResultTypes = resultTypes; + } + // ino.end + + // ino.method.getSubstitutions.26952.defdescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * @return Returns the Substitutions. + */ + // ino.end + // ino.method.getSubstitutions.26952.definition + public CSubstitutionSet getSubstitutions() + // ino.end + // ino.method.getSubstitutions.26952.body + { + return m_Substitutions; + } + // ino.end + + // ino.method.setSubstitutions.26955.defdescription type=javadoc + /** + * Author: Jörg Bäuerle
+ * @param substitution The Substitutions to set. + */ + // ino.end + // ino.method.setSubstitutions.26955.definition + public void setSubstitutions(CSubstitutionSet substitutions) + // ino.end + // ino.method.setSubstitutions.26955.body + { + m_Substitutions = substitutions; + } + // ino.end + + + // ino.method.equals.26958.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26958.body + { + if(obj instanceof CSubstitution){ + CMultiplyTuple tup = (CMultiplyTuple)obj; + boolean ret = true; + ret &= (m_AssumptionSet.equals(tup.m_AssumptionSet)); + ret &= (m_ResultTypes.equals(tup.m_ResultTypes)); + ret &= (m_Substitutions.equals(tup.m_Substitutions)); + return ret; + } + else{ + return false; + } + } + // ino.end + + // ino.method.toString.26961.definition + public String toString() + // ino.end + // ino.method.toString.26961.body + { + StringBuffer sb = new StringBuffer(); + sb.append("MultiplyTuple (\n"); + sb.append("Substitutions:\n"); + sb.append(m_Substitutions.toString()); + sb.append(m_ResultTypes.toString()); + sb.append("\n"); + sb.append(m_AssumptionSet.toString()); + sb.append(" )"); + return sb.toString(); + } + // ino.end + + // ino.method.clone.26964.definition + public CMultiplyTuple clone() + // ino.end + // ino.method.clone.26964.body + { + CMultiplyTuple copy = new CMultiplyTuple(); + copy.setSubstitutions(m_Substitutions.deepCopy()); + Iterator typeIt = this.getResultTypeIterator(); + while(typeIt.hasNext()){ + copy.getResultTypes().addElement(typeIt.next().clone()); + } + copy.setAssumptionSet(m_AssumptionSet.deepCopy()); + return copy; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/CReconstructionTuple.java b/src/mycompiler/mytypereconstruction/CReconstructionTuple.java new file mode 100755 index 000000000..0b5c6fdfc --- /dev/null +++ b/src/mycompiler/mytypereconstruction/CReconstructionTuple.java @@ -0,0 +1,133 @@ +// ino.module.CReconstructionTuple.8684.package +package mycompiler.mytypereconstruction; +// ino.end + +// ino.module.CReconstructionTuple.8684.import +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +// ino.end + + +// ino.class.CReconstructionTuple.26967.description type=javadoc +/** + * Container-Klasse für Ergebniswerte des Algorithmus TRStart. + * (siehe Algorithmus 5.18 TRStart, Martin Plümicke) + * @author Jörg Bäuerle + * @version $date + */ +// ino.end +// ino.class.CReconstructionTuple.26967.declaration +public class CReconstructionTuple +// ino.end +// ino.class.CReconstructionTuple.26967.body +{ + // ino.attribute.m_SubSet.26970.declaration + private CSubstitutionSet m_SubSet; + // ino.end + // ino.attribute.m_AssumSet.26973.declaration + private CTypeAssumptionSet m_AssumSet; + // ino.end + + // ino.method.CReconstructionTuple.26976.definition + public CReconstructionTuple() + // ino.end + // ino.method.CReconstructionTuple.26976.body + { + this(new CSubstitutionSet(), new CTypeAssumptionSet()); + } + // ino.end + + // ino.method.CReconstructionTuple.26979.definition + public CReconstructionTuple(CSubstitutionSet subSet, CTypeAssumptionSet assumSet) + // ino.end + // ino.method.CReconstructionTuple.26979.body + { + m_SubSet = subSet; + m_AssumSet = assumSet; + } + // ino.end + + // ino.method.getAssumSet.26982.definition + public CTypeAssumptionSet getAssumSet() + // ino.end + // ino.method.getAssumSet.26982.body + { + return m_AssumSet; + } + // ino.end + + // ino.method.setAssumSet.26985.definition + public void setAssumSet(CTypeAssumptionSet assumSet) + // ino.end + // ino.method.setAssumSet.26985.body + { + m_AssumSet = assumSet; + } + // ino.end + + // ino.method.getSubSet.26988.definition + public CSubstitutionSet getSubSet() + // ino.end + // ino.method.getSubSet.26988.body + { + return m_SubSet; + } + // ino.end + + // ino.method.setSubSet.26991.definition + public void setSubSet(CSubstitutionSet subSet) + // ino.end + // ino.method.setSubSet.26991.body + { + m_SubSet = subSet; + } + // ino.end + + // ino.method.equals.26994.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.26994.body + { + if(obj instanceof CReconstructionTuple){ + CReconstructionTuple tuple = (CReconstructionTuple)obj; + boolean ret = true; + ret &= (m_SubSet.equals(tuple.m_SubSet)); + ret &= (m_AssumSet.equals(tuple.m_AssumSet)); + return ret; + } + else{ + return false; + } + } + // ino.end + + // ino.method.toString.26997.definition + public String toString() + // ino.end + // ino.method.toString.26997.body + { + StringBuffer sb = new StringBuffer(); + sb.append("ReconstructionTuple (\n"); + sb.append("Substitutions:\n"); + sb.append(m_SubSet.toString()); + sb.append("\n"); + sb.append("Assumptions:\n"); + sb.append(m_AssumSet.toString()); + sb.append("\n)"); + return sb.toString(); + } + // ino.end + + // ino.method.clone.27000.definition + public CReconstructionTuple clone() + // ino.end + // ino.method.clone.27000.body + { + CReconstructionTuple copy = new CReconstructionTuple(); + copy.setSubSet(m_SubSet.deepCopy()); + copy.setAssumSet(m_AssumSet.deepCopy()); + return copy; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/CSubstitution.java b/src/mycompiler/mytypereconstruction/CSubstitution.java new file mode 100755 index 000000000..9ba5ecfa5 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/CSubstitution.java @@ -0,0 +1,269 @@ +// ino.module.CSubstitution.8685.package +package mycompiler.mytypereconstruction; +// ino.end + +// ino.module.CSubstitution.8685.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.CSubstitution.27003.description type=javadoc +/** + * Implementierung einer Typsubstitution. Bildet eine zu ersetzende + * TypePlaceholder auf einen Substitutions-Typ ab. Instanzen dieser + * Klasse werden in der Regel aus + * Pair-Objekten erzeugt. + * @author J�rg B�uerle + * @version $Date: 2006/07/10 11:27:04 $ + */ +// ino.end +// ino.class.CSubstitution.27003.declaration +public class CSubstitution +// ino.end +// ino.class.CSubstitution.27003.body +{ + // ino.attribute.m_TypeVar.27006.declaration + private TypePlaceholder m_TypeVar = null; + // ino.end + // ino.attribute.m_Type.27009.declaration + protected Type m_Type = null; + // ino.end + // ino.attribute.inferencelog.27012.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + // ino.method.CSubstitution.27015.definition + public CSubstitution() + // ino.end + // ino.method.CSubstitution.27015.body + { + this(null, null); + } + // ino.end + + // ino.method.CSubstitution.27018.definition + public CSubstitution(TypePlaceholder typeVar, Type type) + // ino.end + // ino.method.CSubstitution.27018.body + { + m_TypeVar = typeVar; + m_Type = type; + } + // ino.end + + // ino.method.CSubstitution.27021.definition + public CSubstitution(Pair unifier) + throws CTypeReconstructionException + // ino.end + // ino.method.CSubstitution.27021.body + { + if(!(unifier.TA1 instanceof TypePlaceholder)){ + throw new CTypeReconstructionException("Unifier enth�lt keinen Typeplaceholder",unifier.TA1); + } + m_TypeVar = (TypePlaceholder)unifier.TA1; + m_Type = unifier.TA2; + } + // ino.end + + + // ino.method.getType.27024.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @return Returns the Type. + */ + // ino.end + // ino.method.getType.27024.definition + public Type getType() + // ino.end + // ino.method.getType.27024.body + { + return m_Type; + } + // ino.end + + // ino.method.setType.27027.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param type The Type to set. + */ + // ino.end + // ino.method.setType.27027.definition + public void setType(Type type) + // ino.end + // ino.method.setType.27027.body + { + m_Type = type; + } + // ino.end + + // ino.method.getTypeVar.27030.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @return Returns the TypeVar. + */ + // ino.end + // ino.method.getTypeVar.27030.definition + public Type getTypeVar() + // ino.end + // ino.method.getTypeVar.27030.body + { + return this.m_TypeVar; + } + // ino.end + + // ino.method.setTypeVar.27033.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param typeVar The TypeVar to set. + */ + // ino.end + // ino.method.setTypeVar.27033.definition + public void setTypeVar(TypePlaceholder typeVar) + // ino.end + // ino.method.setTypeVar.27033.body + { + m_TypeVar = typeVar; + } + // ino.end + + // ino.method.equals.27036.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.27036.body + { + if(obj instanceof CSubstitution){ + CSubstitution sub = (CSubstitution)obj; + boolean ret = true; + ret &= (m_TypeVar.equals(sub.m_TypeVar)); + ret &= (m_Type.equals(sub.m_Type)); + return ret; + } + else{ + return false; + } + } + // ino.end + + // ino.method.toString.27039.definition + public String toString() + // ino.end + // ino.method.toString.27039.body + { + //return m_TypeVar.getName() +" --> "+m_Type.getName(); + return m_TypeVar.toString() +" --> "+m_Type.toString(); + } + // ino.end + + // ino.method.clone.27042.definition + public CSubstitution clone() + // ino.end + // ino.method.clone.27042.body + { + CSubstitution copy = new CSubstitution(m_TypeVar.clone(), m_Type.clone()); + return copy; + } + // ino.end + + // ino.method.execute.27045.defdescription type=javadoc + /** + * Sucht die eindeutige Instanz der Typeplaceholders in der Registry der + * Typeplaceholders des Syntaxbaumes und f�hrt die Typsubstitution im + * Syntaxbaum durch. + *
Author: J�rg B�uerle + * wenn die TypePlaceholder nicht in der Registry gefunden wurde. + * @throws CTypeReconstructionException Falls TypePlaceholder nicht in Registry + * gefunden wird. + */ + // ino.end + // ino.method.execute.27045.definition + public void execute() + throws CTypeReconstructionException + // ino.end + // ino.method.execute.27045.body + { + TypePlaceholder uniqueVar = TypePlaceholder.getInstance(m_TypeVar.getName()); + if(uniqueVar==null){ + throw new CTypeReconstructionException("CSubstitution.execute(): TypePlaceholder \""+m_TypeVar.getName()+"\" wurde nicht in der Registry gefunden!",null); + } + inferencelog.debug("F�hre Substitution aus: "+this.toString()); + uniqueVar.replaceWithType(m_Type); + } + // ino.end + + // ino.method.applyUnifier.27048.defdescription type=javadoc + /** + * Wendet den Unifier auf die rechte Seite dieser Substitution an. + *
Author: J�rg B�uerle + * @param unifier + */ + // ino.end + // ino.method.applyUnifier.27048.definition + public void applyUnifier(CSubstitutionSet unifier) + // ino.end + // ino.method.applyUnifier.27048.body + { + Iterator pairIt = unifier.getIterator(); + while(pairIt.hasNext()){ + CSubstitution subst = (CSubstitution)pairIt.next(); + + //korrigiert PL 05-07-31 das erste duerfte doch richtig sein. + //subst.setType(this.applySubstitution(subst.getType(), subst)); + this.setType(this.applySubstitution(this.getType(), subst)); + } + + } + // ino.end + + // ino.method.applySubstitution.27051.defdescription type=javadoc + /** + * Wendet die �bergebene Substitution rekursiv auf den �bergebenen Typ an. + *
Author: J�rg B�uerle + * @param type Der zu untersuchende Typ + * @param unifierSub Die anzuwendende Substitution + * @return Den ermittelnden Typ + */ + // ino.end + // ino.method.applySubstitution.27051.definition + private Type applySubstitution(Type type, CSubstitution unifierSub) + // ino.end + // ino.method.applySubstitution.27051.body + { + if(type instanceof TypePlaceholder){ + if(type.equals(unifierSub.getTypeVar())){ + return unifierSub.getType(); + } + } + else if(type instanceof GenericTypeVar){ + if(type.equals(unifierSub.getTypeVar())){ + return unifierSub.getType(); + } + } + else if(type instanceof RefType){ + Vector paras = ((RefType)type).get_ParaList(); + if(paras != null){ + for(int i=0; iTypePlaceholder auf einen Substitutions-Typ ab. Instanzen dieser + * Klasse werden in der Regel aus + * Pair-Objekten erzeugt. + * @author Martin Pl�micke + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CSubstitutionGenVar.27057.declaration +public class CSubstitutionGenVar extends CSubstitution +// ino.end +// ino.class.CSubstitutionGenVar.27057.body +{ + // ino.attribute.m_TypeVar.27061.declaration + private GenericTypeVar m_TypeVar = null; + // ino.end + + // ino.method.CSubstitutionGenVar.27064.definition + public CSubstitutionGenVar() + // ino.end + // ino.method.CSubstitutionGenVar.27064.body + { + this(null, null); + } + // ino.end + + // ino.method.CSubstitutionGenVar.27067.definition + public CSubstitutionGenVar(GenericTypeVar typeVar, Type type) + // ino.end + // ino.method.CSubstitutionGenVar.27067.body + { + m_TypeVar = typeVar; + m_Type = type; + } + // ino.end + + // ino.method.getTypeVar.27070.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @return Returns the TypeVar. + */ + // ino.end + // ino.method.getTypeVar.27070.definition + public Type getTypeVar() + // ino.end + // ino.method.getTypeVar.27070.body + { + return this.m_TypeVar; + } + // ino.end + + // ino.method.toString.27073.definition + public String toString() + // ino.end + // ino.method.toString.27073.body + { + return this.m_TypeVar.getName() +" --> "+this.m_Type.getName(); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/CSupportData.java b/src/mycompiler/mytypereconstruction/CSupportData.java new file mode 100755 index 000000000..934c5fbce --- /dev/null +++ b/src/mycompiler/mytypereconstruction/CSupportData.java @@ -0,0 +1,345 @@ +// ino.module.CSupportData.8687.package +package mycompiler.mytypereconstruction; +// ino.end + +// ino.module.CSupportData.8687.import +import java.util.Vector; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytypereconstruction.unify.FC_TTO; +// ino.end + +// ino.class.CSupportData.27076.description type=javadoc +/** + * Container-Klasse fr bestimmte Hilfsdaten, die beim + * Typrekonstruktionsalgorithmus bentigt und deshalb + * rekursiv weiter gereicht werden. + * @author Jrg Buerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CSupportData.27076.declaration +public class CSupportData +// ino.end +// ino.class.CSupportData.27076.body +{ + // ino.attribute.NO_METHOD.27079.decldescription type=javadoc + /** + * Gibt Namensstring fr den Classbody auerhalb einer Methode + * fr m_CurrentMethod. + */ + // ino.end + // ino.attribute.NO_METHOD.27079.declaration + public static final String NO_METHOD = "#nomethod#"; + // ino.end + + // ino.attribute.m_FiniteClosure.27082.declaration + private FC_TTO m_FiniteClosure; + // ino.end + // ino.attribute.m_A.27085.declaration + private Vector m_A; + // ino.end + // ino.attribute.m_CurrentClass.27088.declaration + private String m_CurrentClass; + // ino.end + // ino.attribute.m_CurrentClassPara.27091.declaration + private Vector m_CurrentClassPara; + // ino.end + // ino.attribute.m_CurrentMethod.27094.declaration + private String m_CurrentMethod; + // ino.end + // ino.attribute.m_CurrentMethodParaCount.27097.declaration + private int m_CurrentMethodParaCount; + // ino.end + // ino.attribute.m_BlockIdList.27100.declaration + private Vector m_BlockIdList; + // ino.end + // ino.attribute.m_CurrentBlockDepth.27103.declaration + private int m_CurrentBlockDepth; + // ino.end + + // ino.attribute.m_CurrentMethodOverloadedID.27106.declaration + private int m_CurrentMethodOverloadedID; + // ino.end + + // ino.method.CSupportData.27109.definition + public CSupportData(FC_TTO finiteClosure, Vector A, String currentClass, Vector currentClassPara) + // ino.end + // ino.method.CSupportData.27109.body + { + this(finiteClosure, A, currentClass, currentClassPara, NO_METHOD, 0, 0, new Vector(), 0); + } + // ino.end + + // ino.method.CSupportData.27112.definition + public CSupportData(FC_TTO finiteClosure, Vector A, String currentClass, Vector currentClassPara, String currentMethod, int currentMethodParaCount, int currentMethodOverloadedID, Vector blockIdList, int blockDepth) + // ino.end + // ino.method.CSupportData.27112.body + { + m_FiniteClosure = finiteClosure; + m_A = A; + m_CurrentClass = currentClass; + m_CurrentClassPara = currentClassPara; + m_CurrentMethod = currentMethod; + m_CurrentMethodParaCount = currentMethodParaCount; + m_CurrentMethodOverloadedID=currentMethodOverloadedID; + m_BlockIdList = blockIdList; + m_CurrentBlockDepth = blockDepth; + } + // ino.end + + // ino.method.getFiniteClosure.27115.definition + public FC_TTO getFiniteClosure() + // ino.end + // ino.method.getFiniteClosure.27115.body + { + return m_FiniteClosure; + } + // ino.end + + // ino.method.setFiniteClosure.27118.definition + public void setFiniteClosure(FC_TTO finiteClosure) + // ino.end + // ino.method.setFiniteClosure.27118.body + { + m_FiniteClosure = finiteClosure; + } + // ino.end + + // ino.method.getA.27121.definition + public Vector getA() + // ino.end + // ino.method.getA.27121.body + { + return m_A; + } + // ino.end + + // ino.method.setA.27124.definition + public void setA(Vector A) + // ino.end + // ino.method.setA.27124.body + { + m_A = A; + } + // ino.end + + // ino.method.getCurrentClassType.27127.definition + public RefType getCurrentClassType() + // ino.end + // ino.method.getCurrentClassType.27127.body + { + if(m_CurrentClassPara==null || m_CurrentClassPara.size()==0){ + return(new RefType(m_CurrentClass,-1)); + }else{ + return(new RefType(m_CurrentClass,m_CurrentClassPara,-1)); + } + + } + // ino.end + + // ino.method.getCurrentClass.27130.definition + public String getCurrentClass() + // ino.end + // ino.method.getCurrentClass.27130.body + { + return m_CurrentClass; + } + // ino.end + + // ino.method.setCurrentClass.27133.definition + public void setCurrentClass(String currentClass) + // ino.end + // ino.method.setCurrentClass.27133.body + { + m_CurrentClass = currentClass; + } + // ino.end + + // ino.method.getCurrentClassPara.27136.definition + public Vector getCurrentClassPara() + // ino.end + // ino.method.getCurrentClassPara.27136.body + { + return m_CurrentClassPara; + } + // ino.end + + // ino.method.setCurrentClassPara.27139.definition + public void setCurrentClassPara(Vector currentClassPara) + // ino.end + // ino.method.setCurrentClassPara.27139.body + { + m_CurrentClassPara = currentClassPara; + } + // ino.end + + // ino.method.getCurrentMethod.27142.definition + public String getCurrentMethod() + // ino.end + // ino.method.getCurrentMethod.27142.body + { + return m_CurrentMethod; + } + // ino.end + + // ino.method.setCurrentMethod.27145.definition + public void setCurrentMethod(String currentMethod) + // ino.end + // ino.method.setCurrentMethod.27145.body + { + m_CurrentMethod = currentMethod; + } + // ino.end + + // ino.method.getCurrentMethodParaCount.27148.definition + public int getCurrentMethodParaCount() + // ino.end + // ino.method.getCurrentMethodParaCount.27148.body + { + return m_CurrentMethodParaCount; + } + // ino.end + + // ino.method.setCurrentMethodParaCount.27151.definition + public void setCurrentMethodParaCount(int currentMethodParaCount) + // ino.end + // ino.method.setCurrentMethodParaCount.27151.body + { + m_CurrentMethodParaCount = currentMethodParaCount; + } + // ino.end + // ino.method.setCurrentMethodOverloadedID.27154.definition + public void setCurrentMethodOverloadedID(int currentMethodOverloadedID) + // ino.end + // ino.method.setCurrentMethodOverloadedID.27154.body + { + m_CurrentMethodOverloadedID = currentMethodOverloadedID; + } + // ino.end + + // ino.method.getBlockIdList.27157.definition + public Vector getBlockIdList() + // ino.end + // ino.method.getBlockIdList.27157.body + { + return m_BlockIdList; + } + // ino.end + + // ino.method.setBlockIdList.27160.definition + public void setBlockIdList(Vector blockId) + // ino.end + // ino.method.setBlockIdList.27160.body + { + m_BlockIdList = blockId; + } + // ino.end + + // ino.method.resetBlockId.27163.definition + public void resetBlockId() + // ino.end + // ino.method.resetBlockId.27163.body + { + m_BlockIdList = new Vector(); + m_CurrentBlockDepth = 0; + } + // ino.end + + // ino.method.getCurrentBlockDepth.27166.definition + public int getCurrentBlockDepth() + // ino.end + // ino.method.getCurrentBlockDepth.27166.body + { + return m_CurrentBlockDepth; + } + // ino.end + + // ino.method.setCurrentBlockDepth.27169.definition + public void setCurrentBlockDepth(int currentBlockDepth) + // ino.end + // ino.method.setCurrentBlockDepth.27169.body + { + m_CurrentBlockDepth = currentBlockDepth; + } + // ino.end + + // ino.method.incBlockDepth.27172.definition + public int incBlockDepth() + // ino.end + // ino.method.incBlockDepth.27172.body + { + m_CurrentBlockDepth++; + if(m_CurrentBlockDepth>m_BlockIdList.size()){ + m_BlockIdList.addElement(new Integer(0)); + } + int blockCount = m_BlockIdList.elementAt(m_CurrentBlockDepth-1).intValue(); + blockCount++; + m_BlockIdList.setElementAt(blockCount, m_CurrentBlockDepth-1); + return m_CurrentBlockDepth; + } + // ino.end + + // ino.method.decBlockDepth.27175.definition + public int decBlockDepth() + // ino.end + // ino.method.decBlockDepth.27175.body + { + if(m_CurrentBlockDepth>0){ + m_CurrentBlockDepth--; + } + return m_CurrentBlockDepth; + } + // ino.end + + // ino.method.getCurrentBlockId.27178.definition + public String getCurrentBlockId() + // ino.end + // ino.method.getCurrentBlockId.27178.body + { + return this.getBlockId(m_CurrentBlockDepth); + } + // ino.end + + // ino.method.getBlockId.27181.definition + public String getBlockId(int blockDepth) + // ino.end + // ino.method.getBlockId.27181.body + { + StringBuffer sb = new StringBuffer(); + for(int i=0; i)m_A.clone(), + m_CurrentClass, (Vector) m_CurrentClassPara.clone(), m_CurrentMethod, m_CurrentMethodParaCount,m_CurrentMethodOverloadedID, + (Vector)m_BlockIdList.clone(), m_CurrentBlockDepth + ); + return dolly; + } + // ino.end + + // ino.method.getCurrentMethodOverloadedID.27187.definition + public int getCurrentMethodOverloadedID() + // ino.end + // ino.method.getCurrentMethodOverloadedID.27187.body + { + return(m_CurrentMethodOverloadedID); + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/CTriple.java b/src/mycompiler/mytypereconstruction/CTriple.java new file mode 100755 index 000000000..c5f483d5f --- /dev/null +++ b/src/mycompiler/mytypereconstruction/CTriple.java @@ -0,0 +1,263 @@ +// ino.module.CTriple.8688.package +package mycompiler.mytypereconstruction; +// ino.end + +// ino.module.CTriple.8688.import +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +// ino.end + +// ino.class.CTriple.27190.description type=javadoc +/** + * Container-Klasse f�r Ergebniswerte der Algorithmen TRStmt und TRExp. + * (siehe Algorithmus 5.20 ff TRStmt und 5.30 ff TRExp, Martin Pl�micke) + * CTriple steht genau wie CReconstructionTuple für eine mögliche Typkombination mit + * dem einzigen Unterschied, dass sie zusätzlich noch den berechneten ReturnType des aktuell + * betrachteten Blocks enthält. Bei diesem ReturnTyp kann es sich auch nur um eine Vermutung handeln. + * Die Klasse taucht meistens als CTripleSet auf. Der Inferenzalgorithmus kann dann unter den verschiedenen vorgeschlagenen ReturnTypen auswählen. + * @author J�rg B�uerle + * @version $Date: 2013/02/07 05:08:51 $ + */ +// ino.end +// ino.class.CTriple.27190.declaration +public class CTriple +// ino.end +// ino.class.CTriple.27190.body +{ + // ino.attribute.m_Substitutions.27193.declaration + private CSubstitutionSet m_Substitutions = null; + // ino.end + // ino.attribute.m_ResultType.27196.declaration + private Type m_ResultType = null; + // ino.end + // ino.attribute.m_AssumptionSet.27199.declaration + private CTypeAssumptionSet m_AssumptionSet = null; + // ino.end + + // ino.method.CTriple.27202.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * + */ + // ino.end + // ino.method.CTriple.27202.definition + public CTriple() + // ino.end + // ino.method.CTriple.27202.body + { + m_Substitutions = new CSubstitutionSet(); + m_ResultType = null; + m_AssumptionSet = new CTypeAssumptionSet(); + } + // ino.end + + /** + * + * @param substitutions + * @param resultType + * @param assumptionSet + */ + // ino.method.CTriple.27205.definition + public CTriple(CSubstitutionSet substitutions, Type resultType, CTypeAssumptionSet assumptionSet) + // ino.end + // ino.method.CTriple.27205.body + { + m_Substitutions = substitutions; + m_ResultType = resultType; + m_AssumptionSet = assumptionSet; + } + // ino.end + + + // ino.method.getAssumptionSet.27208.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @return Returns the AssumptionSet. + */ + // ino.end + // ino.method.getAssumptionSet.27208.definition + public CTypeAssumptionSet getAssumptionSet() + // ino.end + // ino.method.getAssumptionSet.27208.body + { + return m_AssumptionSet; + } + // ino.end + + // ino.method.setAssumptionSet.27211.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param assumptionSet The AssumptionSet to set. + */ + // ino.end + // ino.method.setAssumptionSet.27211.definition + public void setAssumptionSet(CTypeAssumptionSet assumptionSet) + // ino.end + // ino.method.setAssumptionSet.27211.body + { + m_AssumptionSet = assumptionSet; + } + // ino.end + + // ino.method.getResultType.27214.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @return Returns the ResultType. + */ + // ino.end + // ino.method.getResultType.27214.definition + public Type getResultType() + // ino.end + // ino.method.getResultType.27214.body + { + return m_ResultType; + } + // ino.end + + // ino.method.setResultType.27217.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param resultType The ResultType to set. + */ + // ino.end + // ino.method.setResultType.27217.definition + public void setResultType(Type resultType) + // ino.end + // ino.method.setResultType.27217.body + { + m_ResultType = resultType; + } + // ino.end + + // ino.method.getSubstitutions.27220.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @return Returns the Substitutions. + */ + // ino.end + // ino.method.getSubstitutions.27220.definition + public CSubstitutionSet getSubstitutions() + // ino.end + // ino.method.getSubstitutions.27220.body + { + return m_Substitutions; + } + // ino.end + + // ino.method.setSubstitutions.27223.defdescription type=javadoc + /** + * Author: J�rg B�uerle
+ * @param substitution The Substitutions to set. + */ + // ino.end + // ino.method.setSubstitutions.27223.definition + public void setSubstitutions(CSubstitutionSet substitutions) + // ino.end + // ino.method.setSubstitutions.27223.body + { + m_Substitutions = substitutions; + } + // ino.end + + + // ino.method.equals.27226.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.27226.body + { + if(obj instanceof CTriple){ + CTriple trip = (CTriple)obj; + boolean ret = true; + ret &= (m_AssumptionSet.equals(trip.m_AssumptionSet)); + ret &= (m_ResultType.equals(trip.m_ResultType)); + ret &= (m_Substitutions.equals(trip.m_Substitutions)); + return ret; + } + else{ + return false; + } + } + // ino.end + + // ino.method.toString.27229.definition + public String toString() + // ino.end + // ino.method.toString.27229.body + { + StringBuffer sb = new StringBuffer(); + sb.append("Triple (\n"); + sb.append("Substitutions:\n"); + sb.append(m_Substitutions.toString()); + sb.append("\n"); + sb.append("ResultType: "+m_ResultType.getName()); + sb.append("\n"); + sb.append("Assumptions:\n"); + sb.append(m_AssumptionSet.toString()); + sb.append(" )"); + return sb.toString(); + } + // ino.end + + // ino.method.clone.27232.definition + public CTriple clone() + // ino.end + // ino.method.clone.27232.body + { + CTriple copy = new CTriple(); + copy.setSubstitutions(m_Substitutions.deepCopy()); + copy.setResultType(m_ResultType.clone()); + copy.setAssumptionSet(m_AssumptionSet.deepCopy()); + return copy; + } + // ino.end + + // ino.method.cloneAndApplyUnify.27235.defdescription type=javadoc + /** + * Kopiert dieses Triple und wendet alle Substitutionen eines Unifiers auf + * die Kopie an. + *
Author: J�rg B�uerle + * @param unifier + * @return Die Kopie nach Anwendung des Unifiers + */ + // ino.end + // ino.method.cloneAndApplyUnify.27235.definition + public CTriple cloneAndApplyUnify(CSubstitutionSet unifier) + // ino.end + // ino.method.cloneAndApplyUnify.27235.body + { + // -------------------------- + // Typannahmen bauen: + // -------------------------- + CTypeAssumptionSet V_substituted = this.getAssumptionSet().deepCopy(); + V_substituted.sub(unifier); + // -------------------------- + // Substitutionen bauen: + // -------------------------- + CSubstitutionSet substitutionSet = this.getSubstitutions().deepCopy(); + substitutionSet.applyUnifier(unifier); + substitutionSet.unite(unifier); + // -------------------------- + // R�ckgabetyp bauen: + // -------------------------- + Type ty = substitutionSet.applyThisSubstitutionSet(this.getResultType().clone()); + //PL 05-08-25 hier muessen TypePlaceholders-Variablen auch erstezt werden, + //wenn sie als Subvariablen in typen vorkommen.if(ty instanceof TypePlaceholder){ + // Iterator pairIt = unifier.getIterator(); + // while(pairIt.hasNext()){ + // CSubstitution pair = pairIt.next(); + // if(pair.getTypeVar().getName().equals(ty.getName())){ + // ty = pair.getType(); + // break; + // } + // } + //} + // -------------------------- + // Triple zusammensetzen: + // -------------------------- + CTriple triple = new CTriple(substitutionSet, ty, V_substituted); + return triple; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/CTypeReconstructionResult.java b/src/mycompiler/mytypereconstruction/CTypeReconstructionResult.java new file mode 100755 index 000000000..b8eb45f6c --- /dev/null +++ b/src/mycompiler/mytypereconstruction/CTypeReconstructionResult.java @@ -0,0 +1,312 @@ +// ino.module.CTypeReconstructionResult.8689.package +package mycompiler.mytypereconstruction; +// ino.end + +// ino.module.CTypeReconstructionResult.8689.import +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; + +import typinferenz.ConstraintsSet; +import typinferenz.ResultSet; +import typinferenz.TypeAssumptions; +import typinferenz.TypinferenzException; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.typeassumptionkey.CMethodKey; +import mycompiler.mytypereconstruction.typeassumptionkey.CTypeAssumptionKey; +// ino.end + +// ino.class.CTypeReconstructionResult.27238.description type=javadoc +/** + * Diese Container-Klasse kapselt alle Ergebniswerte f�r eine m�gliche + * Typkombination aller Klassen und deren Methoden sowie lokalen Variablen. Eine + * Instanz dieser Klasse steht f�r genau eine m�gliche Typkombination.
+ * Objekte dieser Klasse werden vom Typrekonstruktionsalgorithmus �ber die + * Compiler-API zur�ckgegeben. + * @author J�rg B�uerle + * @version $Date: 2013/09/22 20:13:02 $ + */ +// ino.end +// ino.class.CTypeReconstructionResult.27238.declaration +public class CTypeReconstructionResult +// ino.end +// ino.class.CTypeReconstructionResult.27238.body +{ + // ino.attribute.m_MethodIntersectionTypes.27241.declaration + private Hashtable m_MethodIntersectionTypes; + // ino.end + // ino.attribute.m_FieldAndLocalVarAssumptions.27244.declaration + private Hashtable m_FieldAndLocalVarAssumptions; + // ino.end + // ino.attribute.m_Substitutions.27247.declaration + private CSubstitutionSet m_Substitutions; + // ino.end + // ino.attribute.m_ClassNames.27250.declaration + private Vector m_ClassNames; + // ino.end + // ino.attribute.m_GenericTypeVars.27253.declaration + private Hashtable> m_GenericTypeVars; + // ino.end + + private Vector constraints; + private ResultSet unifiedConstraints; + private mycompiler.myclass.Class ownerOfResultSet;//Jedes Resultset gilt immer nur für eine Klasse. Diese wird in dieser Variable gespeichert. + + // ino.method.CTypeReconstructionResult.27256.definition + public CTypeReconstructionResult(mycompiler.myclass.Class inferedClass) + // ino.end + // ino.method.CTypeReconstructionResult.27256.body + { + this.ownerOfResultSet = inferedClass; + m_MethodIntersectionTypes = new Hashtable(); + m_FieldAndLocalVarAssumptions = new Hashtable(); + m_Substitutions = new CSubstitutionSet(); + m_ClassNames = new Vector(); + m_GenericTypeVars = new Hashtable>(); + } + // ino.end + + // ino.method.getFieldAndLocalVarAssumptions.27259.definition + public Hashtable getFieldAndLocalVarAssumptions() + // ino.end + // ino.method.getFieldAndLocalVarAssumptions.27259.body + { + return m_FieldAndLocalVarAssumptions; + } + // ino.end + + // ino.method.setFieldAndLocalVarAssumptions.27262.definition + public void setFieldAndLocalVarAssumptions(Hashtable fieldAndLocalVarAssumptions) + // ino.end + // ino.method.setFieldAndLocalVarAssumptions.27262.body + { + m_FieldAndLocalVarAssumptions = fieldAndLocalVarAssumptions; + } + // ino.end + + // ino.method.addFieldOrLocalVarAssumption.27265.definition + public void addFieldOrLocalVarAssumption(CTypeAssumption assum) + // ino.end + // ino.method.addFieldOrLocalVarAssumption.27265.body + { + m_FieldAndLocalVarAssumptions.put(assum.getHashSetKey(), assum); + } + // ino.end + + // ino.method.getMethodIntersectionTypes.27268.definition + public Hashtable getMethodIntersectionTypes() + // ino.end + // ino.method.getMethodIntersectionTypes.27268.body + { + return m_MethodIntersectionTypes; + } + // ino.end + + // ino.method.addMethodIntersectionType.27271.definition + public void addMethodIntersectionType(CIntersectionType intersect) + // ino.end + // ino.method.addMethodIntersectionType.27271.body + { + m_MethodIntersectionTypes.put(intersect.getIntersectionTypeKey(), intersect); + } + // ino.end + + // ino.method.getMethodIntersectionTypes.27274.definition + public Vector getMethodIntersectionTypes(CMethodKey key) + // ino.end + // ino.method.getMethodIntersectionTypes.27274.body + { + Vector elements=new Vector(); + CMethodKey keyToIterate=key.getFirstMethodKey(); + CIntersectionType elem; + while((elem=m_MethodIntersectionTypes.get(keyToIterate))!=null){ + elements.add(elem); + keyToIterate=keyToIterate.getNextMethodKey(); + } + + return(elements); + + // ALTE VERSION: + // return m_MethodIntersectionTypes.get(key); + } + // ino.end + + // ino.method.getSubstitutions.27277.definition + public CSubstitutionSet getSubstitutions() + // ino.end + // ino.method.getSubstitutions.27277.body + { + return m_Substitutions; + } + // ino.end + + // ino.method.setSubstitutions.27280.definition + public void setSubstitutions(CSubstitutionSet substitutions) + // ino.end + // ino.method.setSubstitutions.27280.body + { + m_Substitutions = substitutions; + } + // ino.end + + // ino.method.addDataFromTupel.27283.definition + public void addDataFromTupel(CReconstructionTuple tuple) + // ino.end + // ino.method.addDataFromTupel.27283.body + { + this.addDataFromSubstitutionSet(tuple.getSubSet()); + this.addDataFromTypeAssumptionSet(tuple.getAssumSet()); + } + // ino.end + + // ino.method.addDataFromSubstitutionSet.27286.definition + private void addDataFromSubstitutionSet(CSubstitutionSet subSet) + // ino.end + // ino.method.addDataFromSubstitutionSet.27286.body + { + this.getSubstitutions().getVector().addAll(subSet.getVector()); + } + // ino.end + + // ino.method.addDataFromTypeAssumptionSet.27289.definition + private void addDataFromTypeAssumptionSet(CTypeAssumptionSet assumSet) + // ino.end + // ino.method.addDataFromTypeAssumptionSet.27289.body + { + Iterator assumIter = assumSet.getIterator(); + while(assumIter.hasNext()){ + CTypeAssumption assum = (CTypeAssumption)assumIter.next(); + if(assum instanceof CMethodTypeAssumption){ + this.addMethodIntersectionType(new CIntersectionType((CMethodTypeAssumption)assum)); + } + else{ + this.addFieldOrLocalVarAssumption(assum); + } + } + } + // ino.end + + // ino.method.addClassName.27292.definition + public void addClassName(String className) + // ino.end + // ino.method.addClassName.27292.body + { + m_ClassNames.addElement(className); + } + // ino.end + + // ino.method.getClassNameList.27295.definition + public Vector getClassNameList() + // ino.end + // ino.method.getClassNameList.27295.body + { + return m_ClassNames; + } + // ino.end + + // ino.method.addGenericTypeVars.27298.definition + public void addGenericTypeVars(String className, Vector typeVarList) + // ino.end + // ino.method.addGenericTypeVars.27298.body + { + m_GenericTypeVars.put(className, typeVarList); + } + // ino.end + + // ino.method.getGenericsTable.27301.definition + public Hashtable> getGenericsTable() + // ino.end + // ino.method.getGenericsTable.27301.body + { + return m_GenericTypeVars; + } + // ino.end + + // ino.method.getGenerics.27304.definition + public Vector getGenerics(String key) + // ino.end + // ino.method.getGenerics.27304.body + { + return m_GenericTypeVars.get(key); + } + // ino.end + + // ino.method.shallowCopy.27307.definition + public CTypeReconstructionResult shallowCopy() + // ino.end + // ino.method.shallowCopy.27307.body + { + CTypeReconstructionResult dolly = new CTypeReconstructionResult(this.ownerOfResultSet); + Iterator assumIter = m_FieldAndLocalVarAssumptions.values().iterator(); + while(assumIter.hasNext()){ + dolly.addFieldOrLocalVarAssumption(assumIter.next()); + } + dolly.m_MethodIntersectionTypes = (Hashtable)m_MethodIntersectionTypes.clone(); + dolly.m_Substitutions.getVector().addAll(m_Substitutions.getVector()); + dolly.m_ClassNames.addAll(m_ClassNames); + dolly.m_GenericTypeVars = (Hashtable>)m_GenericTypeVars.clone(); + return dolly; + } + // ino.end + + /** + * @author Andreas Stadelmeier, a10023 + * Anhand des Syntaxbaums errechnet der Typinferenzalgorithmus ein Set von Constraints. + * Diese Funktion ist nur für automatisierte Tests interessant. + * Zum abrufen der Unifizierten Constraints siehe getUnifiedConstraints() + * @return + */ + public Vector getConstraints() { + return this.constraints; + } + + + public void setConstraints(Vector constraints) { + this.constraints = constraints; + } + + /** + * @author Andreas Stadelmeier, a10023 + * Nach dem Durchführen des Interferenzalgorithmus von Lambda 8 entsteht für jede Lösung ein Set con Constraints. + * Diese Constraints haben bereits den Unify-Algorithmus durchlaufen und weißen die errechneten Typen den Typeplacholdern zu. + * @return Das fertige ConstraintsSet dieser CTypeRecunstructionResult + */ + public ResultSet getUnifiedConstraints() { + return unifiedConstraints; + } + + public void setUnifiedConstraints(Vector unifiedConstraints) { + this.unifiedConstraints = new ResultSet(unifiedConstraints); + } + + /** + * Ermittelt den in diesem ResultSet für den TypePlaceholder tph zugewiesenen Wert. + * @author Andreas Stadelmeier, a10023 + */ + public Type getTypeOfPlaceholder(TypePlaceholder tph){ + return this.getUnifiedConstraints().getTypeEqualTo(tph); + } + + /** + * Jedes TypeReconstructionResultSet entstand bei der Typinferierung einer Klasse. + * @return Gibt die Klasse zurück der dieses ResultSet zugeordnet ist. + */ + public mycompiler.myclass.Class getInterferedClass(){ + return this.ownerOfResultSet; + } + + @Override + public String toString(){ + return "Unified Constraints: "+this.unifiedConstraints.toString(); + } + +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/replacementlistener/CReplaceTypeEvent.java b/src/mycompiler/mytypereconstruction/replacementlistener/CReplaceTypeEvent.java new file mode 100755 index 000000000..66c2c638c --- /dev/null +++ b/src/mycompiler/mytypereconstruction/replacementlistener/CReplaceTypeEvent.java @@ -0,0 +1,56 @@ +// ino.module.CReplaceTypeEvent.8691.package +package mycompiler.mytypereconstruction.replacementlistener; +// ino.end + +// ino.module.CReplaceTypeEvent.8691.import +import mycompiler.mytype.Type; +// ino.end + +// ino.class.CReplaceTypeEvent.27311.description type=javadoc +/** + * + * @author Jörg Bäuerle + * @version $date + */ +// ino.end +// ino.class.CReplaceTypeEvent.27311.declaration +public class CReplaceTypeEvent +// ino.end +// ino.class.CReplaceTypeEvent.27311.body +{ + // ino.attribute.m_OldType.27314.declaration + private Type m_OldType; + // ino.end + // ino.attribute.m_NewType.27317.declaration + private Type m_NewType; + // ino.end + + // ino.method.CReplaceTypeEvent.27320.definition + public CReplaceTypeEvent(Type oldType, Type newType) + // ino.end + // ino.method.CReplaceTypeEvent.27320.body + { + m_OldType = oldType; + m_NewType = newType; + } + // ino.end + + // ino.method.getNewType.27323.definition + public Type getNewType() + // ino.end + // ino.method.getNewType.27323.body + { + return m_NewType; + } + // ino.end + + // ino.method.getOldType.27326.definition + public Type getOldType() + // ino.end + // ino.method.getOldType.27326.body + { + return m_OldType; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/replacementlistener/IReplaceTypeEventProvider.java b/src/mycompiler/mytypereconstruction/replacementlistener/IReplaceTypeEventProvider.java new file mode 100755 index 000000000..32789888d --- /dev/null +++ b/src/mycompiler/mytypereconstruction/replacementlistener/IReplaceTypeEventProvider.java @@ -0,0 +1,41 @@ +// ino.module.IReplaceTypeEventProvider.8692.package +package mycompiler.mytypereconstruction.replacementlistener; +// ino.end + +// ino.module.IReplaceTypeEventProvider.8692.import +import java.util.Iterator; +// ino.end + +// ino.class.IReplaceTypeEventProvider.27329.description type=javadoc +/** + * Interface für ein Objekt, das ReplaceTypeEvents zur Verfügung stellt und + * es TypeReplacementListenern erlaubt, sich zu registrieren. + * @author Jörg Bäuerle + * @version $date + */ +// ino.end +// ino.class.IReplaceTypeEventProvider.27329.declaration +public interface IReplaceTypeEventProvider +// ino.end +// ino.class.IReplaceTypeEventProvider.27329.body +{ + // ino.method.addReplacementListener.27332.declaration + public void addReplacementListener(ITypeReplacementListener listener); + // ino.end + // ino.method.removeReplacementListener.27335.declaration + public void removeReplacementListener(ITypeReplacementListener listener); + // ino.end + // ino.method.removeAllReplacementListeners.27338.declaration + public void removeAllReplacementListeners(); + // ino.end + // ino.method.getReplacementListeners.27341.declaration + public Iterator getReplacementListeners(); + // ino.end + // ino.method.containsListener.27344.declaration + public boolean containsListener(ITypeReplacementListener listener); + // ino.end + // ino.method.fireReplaceTypeEvent.27347.declaration + public void fireReplaceTypeEvent(CReplaceTypeEvent e); + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/replacementlistener/ITypeReplacementListener.java b/src/mycompiler/mytypereconstruction/replacementlistener/ITypeReplacementListener.java new file mode 100755 index 000000000..12728490d --- /dev/null +++ b/src/mycompiler/mytypereconstruction/replacementlistener/ITypeReplacementListener.java @@ -0,0 +1,42 @@ +// ino.module.ITypeReplacementListener.8693.package +package mycompiler.mytypereconstruction.replacementlistener; +// ino.end + + +// ino.class.ITypeReplacementListener.27350.description type=javadoc +/** + * Interface f�r einen TypeReplacementListener, der es erm�glicht, + * einen Typ gegen einen anderen auszutauschen. + * @author J�rg B�uerle + * @version $date + */ +// ino.end +// ino.class.ITypeReplacementListener.27350.declaration +public interface ITypeReplacementListener +// ino.end +// ino.class.ITypeReplacementListener.27350.body +{ + // ino.method.replaceType.27353.decldescription type=javadoc + /** + * Tauscht einen Typ gegen einen anderen aus. + *
Author: J�rg B�uerle + * @param e Das Event mit dem neuen Typ + */ + // ino.end + // ino.method.replaceType.27353.declaration + public void replaceType(CReplaceTypeEvent e); + // ino.end + + // ino.method.getTypeLineNumber.27356.decldescription type=javadoc + /** + * Gibt die Zeilennummer zur�ck, in der eine TypePlaceholder + * angelegt worden ist. + *
Author: J�rg B�uerle + * @return Die Zeilennummer + */ + // ino.end + // ino.method.getTypeLineNumber.27356.declaration + public int getTypeLineNumber(); + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/CHashtableSet.java b/src/mycompiler/mytypereconstruction/set/CHashtableSet.java new file mode 100755 index 000000000..38606cf8b --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/CHashtableSet.java @@ -0,0 +1,262 @@ +// ino.module.CHashtableSet.8695.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.module.CHashtableSet.8695.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mytypereconstruction.typeassumptionkey.IMethodBoundKey; +import org.apache.log4j.Logger; +// ino.end + +// ino.class.CHashtableSet.27360.description type=javadoc +/** + * @author Jrg Buerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CHashtableSet.27360.declaration +public abstract class CHashtableSet extends CSet +// ino.end +// ino.class.CHashtableSet.27360.body +{ + + // ino.attribute.inferencelog.27364.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + + // ino.attribute.m_Elements.27367.declaration + private Hashtable m_Elements = null; + // ino.end + + // ino.method.CHashtableSet.27370.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * + */ + // ino.end + // ino.method.CHashtableSet.27370.definition + public CHashtableSet() + // ino.end + // ino.method.CHashtableSet.27370.body + { + m_Elements = new Hashtable(); + } + // ino.end + + // ino.method.addElement.27373.defdescription type=javadoc + /** + * Diese Methode fügt das Element element unter dem Key des Elements + * in der HashMap ab, falls diese Position schon belegt ist (überladene + * Methode mit gleicher Parameteranzahl), wird ein neuer Key generiert + * mit einer um 1 höheren overloadedMethodID + * + * @return Liefert die overloadedMethodID zurück + */ + // ino.end + // ino.method.addElement.27373.definition + public void addElement(E element) + // ino.end + // ino.method.addElement.27373.body + { + this.addElement(element.getHashSetKey(), element); + } + // ino.end + + // ino.method.addElement.27376.defdescription type=javadoc + /** + * Diese Methode fügt das Element element unter dem Key elementKey + * in der HashMap ab, falls diese Position schon belegt ist (überladene + * Methode mit gleicher Parameteranzahl), wird ein neuer Key generiert + * mit einer um 1 höheren overloadedMethodID + * + * @return Liefert die overloadedMethodID zurück + */ + // ino.end + // ino.method.addElement.27376.definition + public void addElement(IHashSetKey elementKey, E element) + // ino.end + // ino.method.addElement.27376.body + { + if(elementKey instanceof IMethodBoundKey){ + IMethodBoundKey key=(IMethodBoundKey)elementKey; + while(m_Elements.get((IHashSetKey)key)!=null){ + key=key.getNextMethodKey(); + } + element.updateHashSetKey((IHashSetKey)key); + // fixme Key in element storen + m_Elements.put((IHashSetKey)key, element); + }else{ + m_Elements.put(elementKey, element); + } + } + // ino.end + + + // ino.method.getElement.27379.definition + public E getElement(IHashSetKey key) + // ino.end + // ino.method.getElement.27379.body + { + if(key instanceof IMethodBoundKey){ + if(!((IMethodBoundKey)key).isOverloadedIDSet()){ + inferencelog.warn("Es wurde ein nicht-initialisierter MethodKey verwendet! Kann zu Problemen fürhren: " + key); + } + } + return m_Elements.get(key); + } + // ino.end + + // ino.method.getElements.27382.defdescription type=javadoc + /** + * Liefert alle Elemente in der HashTable, die zu der Methoden-Signatur-Klass + * gehören d.h. + * liefert - overloaded(String a) + * - overloaded(int a) + * - ... + * + */ + // ino.end + // ino.method.getElements.27382.definition + public Vector getElements(IHashSetKey key) + // ino.end + // ino.method.getElements.27382.body + { + Vector elements=new Vector(); + if(key instanceof IMethodBoundKey){ + IMethodBoundKey keyToIterate=((IMethodBoundKey)key).getFirstMethodKey(); + E elem; + while((elem=getElement((IHashSetKey)keyToIterate))!=null){ + elements.add(elem); + keyToIterate=keyToIterate.getNextMethodKey(); + } + + }else{ + elements.add(getElement(key)); + } + return elements; + } + // ino.end + + // ino.method.removeElement.27385.definition + public void removeElement(E element) + // ino.end + // ino.method.removeElement.27385.body + { + this.removeElement(element.getHashSetKey()); + } + // ino.end + + // ino.method.removeElement.27388.definition + public void removeElement(IHashSetKey key) + // ino.end + // ino.method.removeElement.27388.body + { + m_Elements.remove(key); + } + // ino.end + + // ino.method.getCardinality.27391.definition + public int getCardinality() + // ino.end + // ino.method.getCardinality.27391.body + { + return m_Elements.size(); + } + // ino.end + + // ino.method.getHashtable.27394.definition + public Hashtable getHashtable() + // ino.end + // ino.method.getHashtable.27394.body + { + return m_Elements; + } + // ino.end + + // ino.method.setHashtable.27397.definition + public void setHashtable(Hashtable hash) + // ino.end + // ino.method.setHashtable.27397.body + { + m_Elements = hash; + } + // ino.end + + // ino.method.getIterator.27400.definition + public Iterator getIterator() + // ino.end + // ino.method.getIterator.27400.body + { + return m_Elements.values().iterator(); + } + // ino.end + + // ino.method.unite.27403.definition + public void unite(CSet anotherSet) + // ino.end + // ino.method.unite.27403.body + { + if(!(anotherSet instanceof CHashtableSet)){ + return; + } + CHashtableSet assumSet = (CHashtableSet)anotherSet; + + // Elemente der anderen Menge hinzufgen: + Enumeration enumer = assumSet.getHashtable().keys(); + while(enumer.hasMoreElements()){ + this.addElement(assumSet.getElement(enumer.nextElement())); + } + } + // ino.end + + // ino.method.subtract.27406.definition + public void subtract(CSet anotherSet) + // ino.end + // ino.method.subtract.27406.body + { + if(!(anotherSet instanceof CHashtableSet)){ + return; + } + CHashtableSet assumSet = (CHashtableSet)anotherSet; + + // Elemente der anderen Menge entfernen: + Enumeration enumer = assumSet.getHashtable().keys(); + while(enumer.hasMoreElements()){ + this.removeElement(assumSet.getElement(enumer.nextElement())); + } + } + // ino.end + + // ino.method.contains.27409.definition + public boolean contains(E element) + // ino.end + // ino.method.contains.27409.body + { + return m_Elements.contains(element); + } + // ino.end + + // ino.method.equals.27412.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.27412.body + { + if(obj instanceof CHashtableSet){ + CHashtableSet hashSet = (CHashtableSet)obj; + boolean ret = true; + ret &= m_Elements.size() == hashSet.getHashtable().size(); + if(ret){ + m_Elements.equals(hashSet.m_Elements); + } + return ret; + } + else{ + return false; + } + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/CMultiplyTupleSet.java b/src/mycompiler/mytypereconstruction/set/CMultiplyTupleSet.java new file mode 100755 index 000000000..32eea6c83 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/CMultiplyTupleSet.java @@ -0,0 +1,52 @@ +// ino.module.CMultiplyTupleSet.8696.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.module.CMultiplyTupleSet.8696.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mytypereconstruction.CMultiplyTuple; +// ino.end + +// ino.class.CMultiplyTupleSet.27415.description type=javadoc +/** + * @author J�rg B�uerle + * @version $Date: 2013/03/27 18:29:34 $ + */ +// ino.end +// ino.class.CMultiplyTupleSet.27415.declaration +public class CMultiplyTupleSet extends CVectorSet +// ino.end +// ino.class.CMultiplyTupleSet.27415.body +{ + + // ino.method.shallowCopy.27419.definition + public CMultiplyTupleSet shallowCopy() + // ino.end + // ino.method.shallowCopy.27419.body + { + CMultiplyTupleSet copy = new CMultiplyTupleSet(); + copy.setVector((Vector)this.getVector().clone()); + return copy; + } + // ino.end + + // ino.method.deepCopy.27422.definition + public CMultiplyTupleSet deepCopy() + // ino.end + // ino.method.deepCopy.27422.body + { + CMultiplyTupleSet copy = new CMultiplyTupleSet(); + Iterator it = this.getIterator(); + while(it.hasNext()){ + copy.addElement(it.next().clone()); + } + return copy; + } + // ino.end + + public Iterator iterator() { + return this.getIterator(); + } +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/CReconstructionTupleSet.java b/src/mycompiler/mytypereconstruction/set/CReconstructionTupleSet.java new file mode 100755 index 000000000..a4903032e --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/CReconstructionTupleSet.java @@ -0,0 +1,58 @@ +// ino.module.CReconstructionTupleSet.8697.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.module.CReconstructionTupleSet.8697.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mytypereconstruction.CReconstructionTuple; +// ino.end + +// ino.class.CReconstructionTupleSet.27425.description type=javadoc +/** + * @author J�rg B�uerle + * @version $Date: 2013/03/27 18:29:34 $ + */ +// ino.end +// ino.class.CReconstructionTupleSet.27425.declaration +public class CReconstructionTupleSet extends CVectorSet +// ino.end +// ino.class.CReconstructionTupleSet.27425.body +{ + + // ino.method.shallowCopy.27429.definition + public CReconstructionTupleSet shallowCopy() + // ino.end + // ino.method.shallowCopy.27429.body + { + CReconstructionTupleSet copy = new CReconstructionTupleSet(); + copy.setVector((Vector)this.getVector().clone()); + return copy; + } + // ino.end + + // ino.method.deepCopy.27432.defdescription type=javadoc + /** + *
Author: J�rg B�uerle + * @return + */ + // ino.end + // ino.method.deepCopy.27432.definition + public CReconstructionTupleSet deepCopy() + // ino.end + // ino.method.deepCopy.27432.body + { + CReconstructionTupleSet copy = new CReconstructionTupleSet(); + Iterator it = this.getIterator(); + while(it.hasNext()){ + copy.addElement(it.next().clone()); + } + return copy; + } + // ino.end + + public Iterator iterator() { + return this.getIterator(); + } +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/CSet.java b/src/mycompiler/mytypereconstruction/set/CSet.java new file mode 100755 index 000000000..088afb99e --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/CSet.java @@ -0,0 +1,72 @@ +// ino.module.CSet.8698.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.module.CSet.8698.import +import java.util.Iterator; +// ino.end + +// ino.class.CSet.27435.description type=javadoc +/** + * + * @author Jrg Buerle + * @version $date + */ +// ino.end +// ino.class.CSet.27435.declaration +public abstract class CSet implements Iterable +// ino.end +// ino.class.CSet.27435.body +{ + // ino.method.addElement.27438.declaration + public abstract void addElement(E element); + // ino.end + // ino.method.removeElement.27441.declaration + public abstract void removeElement(E element); + // ino.end + // ino.method.unite.27444.declaration + public abstract void unite(CSet anotherSet); + // ino.end + // ino.method.subtract.27447.declaration + public abstract void subtract(CSet anotherSet); + // ino.end + // ino.method.shallowCopy.27450.declaration + public abstract CSet shallowCopy(); + // ino.end + // ino.method.deepCopy.27453.declaration + public abstract CSet deepCopy(); + // ino.end + // ino.method.contains.27456.declaration + public abstract boolean contains(E element); + // ino.end + // ino.method.getCardinality.27459.declaration + public abstract int getCardinality(); + // ino.end + // ino.method.getIterator.27462.declaration + public abstract Iterator getIterator(); + // ino.end + // ino.method.equals.27465.declaration + public abstract boolean equals(Object obj); + // ino.end + + // ino.method.toString.27468.definition + public String toString() + // ino.end + // ino.method.toString.27468.body + { + StringBuffer sb = new StringBuffer(); + sb.append("Set {\n"); + Iterator it = this.getIterator(); + while(it.hasNext()){ + sb.append(it.next().toString()); + sb.append(",\n"); + } + if(this.getCardinality()>0){ + sb.delete(sb.length()-2, sb.length()-1); + } + sb.append("}"); + return sb.toString(); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/CSubstitutionSet.java b/src/mycompiler/mytypereconstruction/set/CSubstitutionSet.java new file mode 100755 index 000000000..c63106dbe --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/CSubstitutionSet.java @@ -0,0 +1,133 @@ +// ino.module.CSubstitutionSet.8699.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.module.CSubstitutionSet.8699.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.mytype.Pair; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSubstitution; +// ino.end + +// ino.class.CSubstitutionSet.27471.description type=javadoc +/** + * @author J�rg B�uerle + * @version $Date: 2013/03/27 18:29:34 $ + */ +// ino.end +// ino.class.CSubstitutionSet.27471.declaration +public class CSubstitutionSet extends CVectorSet +// ino.end +// ino.class.CSubstitutionSet.27471.body +{ + // ino.method.CSubstitutionSet.27475.definition + public CSubstitutionSet() + // ino.end + // ino.method.CSubstitutionSet.27475.body + { + super(); + } + // ino.end + + // ino.method.CSubstitutionSet.27478.definition + public CSubstitutionSet(Vector unifiers) + throws CTypeReconstructionException + // ino.end + // ino.method.CSubstitutionSet.27478.body + { + super(); + for(int i=0; i substIter = this.getIterator(); + while(substIter.hasNext()){ + copy.addElement(substIter.next().clone()); + } + return copy; + } + // ino.end + + // ino.method.applyUnifier.27487.defdescription type=javadoc + /** + * Wendet den Unifier auf die rechten Seiten alle Substitutionen an. + *
Author: J�rg B�uerle + * @param unifier + */ + // ino.end + // ino.method.applyUnifier.27487.definition + public void applyUnifier(CSubstitutionSet unifier) + // ino.end + // ino.method.applyUnifier.27487.body + { + Iterator substIt = this.getIterator(); + + while(substIt.hasNext()){ + substIt.next().applyUnifier(unifier); + } + } + // ino.end + + // ino.method.applyThisSubstitutionSet.27490.definition + public Type applyThisSubstitutionSet(Type type) + // ino.end + // ino.method.applyThisSubstitutionSet.27490.body + { + Iterator substIt = this.getIterator(); + Type ty = type; + + while(substIt.hasNext()) { + ty = substIt.next().applyThisSubstitution(ty); + } + return ty; + } + // ino.end + + // ino.method.execute.27493.defdescription type=javadoc + /** + * F�hrt jede einzelne CSubstitution aus. + *
Author: J�rg B�uerle + * @throws CTypeReconstructionException Falls TypePlaceholder nicht in Registry + * gefunden wird. + */ + // ino.end + // ino.method.execute.27493.definition + public void execute() + throws CTypeReconstructionException + // ino.end + // ino.method.execute.27493.body + { + Iterator substIt = this.getIterator(); + + while(substIt.hasNext()){ + substIt.next().execute(); + } + } + // ino.end + + public Iterator iterator() { + return this.getIterator(); + } +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/CTripleSet.java b/src/mycompiler/mytypereconstruction/set/CTripleSet.java new file mode 100755 index 000000000..6bc86b403 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/CTripleSet.java @@ -0,0 +1,60 @@ +// ino.module.CTripleSet.8700.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.module.CTripleSet.8700.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mytypereconstruction.CTriple; +// ino.end + +// ino.class.CTripleSet.27496.description type=javadoc +/** + * Enthält Objekte vom Typ CTriple + * (Ist im Grunde ein CVectorSet) + * Es enthält alle Typannahmen in Form von CTriple s + * @see CTriple + * @author J�rg B�uerle + * @version $Date: 2013/03/27 18:29:34 $ + */ +// ino.end +// ino.class.CTripleSet.27496.declaration +public class CTripleSet extends CVectorSet +// ino.end +// ino.class.CTripleSet.27496.body +{ + + // ino.method.shallowCopy.27500.definition + public CTripleSet shallowCopy() + // ino.end + // ino.method.shallowCopy.27500.body + { + CTripleSet copy = new CTripleSet(); + copy.setVector((Vector)this.getVector().clone()); + return copy; + } + // ino.end + + /** + * Diese Funktion kopiert nicht nur das VectorSet, sondern auch alle enthaltenen CTriple-Sets. + * Dadurch wirken sich Modifizierungen an den enthaltenen Elementen nicht auf die Kopie aus. + */ + // ino.method.deepCopy.27503.definition + public CTripleSet deepCopy() + // ino.end + // ino.method.deepCopy.27503.body + { + CTripleSet copy = new CTripleSet(); + Iterator it = this.getIterator(); + while(it.hasNext()){ + copy.addElement(it.next().clone()); + } + return copy; + } + // ino.end + + public Iterator iterator() { + return this.getIterator(); + } +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/CTypeAssumptionSet.java b/src/mycompiler/mytypereconstruction/set/CTypeAssumptionSet.java new file mode 100755 index 000000000..af930103e --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/CTypeAssumptionSet.java @@ -0,0 +1,67 @@ +// ino.module.CTypeAssumptionSet.8701.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.module.CTypeAssumptionSet.8701.import +import java.util.Hashtable; +import java.util.Iterator; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +// ino.end + +// ino.class.CTypeAssumptionSet.27506.description type=javadoc +/** + * @author Jrg Buerle + * @version $Date: 2013/06/18 05:18:59 $ + */ +// ino.end +// ino.class.CTypeAssumptionSet.27506.declaration +public class CTypeAssumptionSet extends CHashtableSet +// ino.end +// ino.class.CTypeAssumptionSet.27506.body +{ + + // ino.method.sub.27510.definition + public void sub(CSubstitutionSet subtitutions) + // ino.end + // ino.method.sub.27510.body + { + Iterator it = this.getIterator(); + while(it.hasNext()){ + it.next().sub(subtitutions); + } + } + // ino.end + + // ino.method.shallowCopy.27513.definition + public CTypeAssumptionSet shallowCopy() + // ino.end + // ino.method.shallowCopy.27513.body + { + CTypeAssumptionSet copy = new CTypeAssumptionSet(); + copy.setHashtable((Hashtable)this.getHashtable().clone()); + return copy; + } + // ino.end + + // ino.method.deepCopy.27516.definition + public CTypeAssumptionSet deepCopy() + // ino.end + // ino.method.deepCopy.27516.body + { + CTypeAssumptionSet copy = new CTypeAssumptionSet(); + Iterator assumIter = this.getHashtable().values().iterator(); + while(assumIter.hasNext()){ + CTypeAssumption actualAssum=assumIter.next(); + CTypeAssumption clonedObject=actualAssum.clone(); + copy.addElement(clonedObject); + } + return copy; + } + // ino.end + + public Iterator iterator() { + return this.getIterator(); + } + +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/CVectorSet.java b/src/mycompiler/mytypereconstruction/set/CVectorSet.java new file mode 100755 index 000000000..c9bf78d01 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/CVectorSet.java @@ -0,0 +1,165 @@ +// ino.module.CVectorSet.8702.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.module.CVectorSet.8702.import +import java.util.Iterator; +import java.util.Vector; +// ino.end + +// ino.class.CVectorSet.27519.description type=javadoc +/** + * @author J�rg B�uerle + * @version $Date: 2013/02/07 05:08:51 $ + */ +// ino.end +// ino.class.CVectorSet.27519.declaration +public abstract class CVectorSet extends CSet +// ino.end +// ino.class.CVectorSet.27519.body +{ + // ino.attribute.m_Elements.27523.declaration + private Vector m_Elements = null; + // ino.end + + // ino.method.CVectorSet.27526.definition + public CVectorSet() + // ino.end + // ino.method.CVectorSet.27526.body + { + m_Elements = new Vector(); + } + // ino.end + + // ino.method.addElement.27529.definition + public void addElement(E element) + // ino.end + // ino.method.addElement.27529.body + { + m_Elements.addElement(element); + } + // ino.end + + // ino.method.removeElement.27532.definition + public void removeElement(E element) + // ino.end + // ino.method.removeElement.27532.body + { + m_Elements.addElement(element); + } + // ino.end + + public void addAll( CVectorSet set ) + { + for( int i=0;i getIterator() + // ino.end + // ino.method.getIterator.27535.body + { + return m_Elements.iterator(); + } + // ino.end + + // ino.method.getVector.27538.definition + public Vector getVector() + // ino.end + // ino.method.getVector.27538.body + { + return m_Elements; + } + // ino.end + + // ino.method.setVector.27541.definition + public void setVector(Vector elements) + // ino.end + // ino.method.setVector.27541.body + { + m_Elements = elements; + } + // ino.end + + /** + * Fügt ein CVectorSet an! + * Es handelt sich um eine Vereinigung (es werden keine bereits vorhandenen Elemente übernommen) + * @param anotherSet Das hinzuzufügende CVectorSet (CSet wird ignoriert) + */ + // ino.method.unite.27544.definition + public void unite(CSet anotherSet) + // ino.end + // ino.method.unite.27544.body + { + if(!(anotherSet instanceof CVectorSet)){ + return; + } + CVectorSet vectorSet = (CVectorSet)anotherSet; + + // Elemente der anderen Menge hinzuf�gen: + Iterator it = vectorSet.getIterator(); + while(it.hasNext()){ + E elem = it.next(); + if(!m_Elements.contains(elem)){ + m_Elements.addElement(elem); + } + } + //m_Elements.addAll(vectorSet.m_Elements); + } + // ino.end + + // ino.method.subtract.27547.definition + public void subtract(CSet anotherSet) + // ino.end + // ino.method.subtract.27547.body + { + if(!(anotherSet instanceof CVectorSet)){ + return; + } + CVectorSet vectorSet = (CVectorSet)anotherSet; + + // Elemente der anderen Menge entfernen: + m_Elements.removeAll(vectorSet.m_Elements); + } + // ino.end + + // ino.method.contains.27550.definition + public boolean contains(E element) + // ino.end + // ino.method.contains.27550.body + { + return m_Elements.contains(element); + } + // ino.end + + // ino.method.equals.27553.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.27553.body + { + if(obj instanceof CVectorSet){ + CVectorSet tripSet= (CVectorSet)obj; + boolean ret = true; + ret &= (m_Elements.containsAll(tripSet.m_Elements)); + ret &= (tripSet.m_Elements.containsAll(m_Elements)); + return ret; + } + else{ + return false; + } + } + // ino.end + + // ino.method.getCardinality.27556.definition + public int getCardinality() + // ino.end + // ino.method.getCardinality.27556.body + { + return m_Elements.size(); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/IHashSetElement.java b/src/mycompiler/mytypereconstruction/set/IHashSetElement.java new file mode 100755 index 000000000..c37140c66 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/IHashSetElement.java @@ -0,0 +1,24 @@ +// ino.module.IHashSetElement.8703.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.class.IHashSetElement.27559.description type=javadoc +/** + * + * @author Jrg Buerle + * @version $date + */ +// ino.end +// ino.class.IHashSetElement.27559.declaration +public interface IHashSetElement +// ino.end +// ino.class.IHashSetElement.27559.body +{ + // ino.method.getHashSetKey.27562.declaration + public IHashSetKey getHashSetKey(); + // ino.end + // ino.method.updateHashSetKey.27565.declaration + public void updateHashSetKey(IHashSetKey key); + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/set/IHashSetKey.java b/src/mycompiler/mytypereconstruction/set/IHashSetKey.java new file mode 100755 index 000000000..b1990b8e4 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/set/IHashSetKey.java @@ -0,0 +1,19 @@ +// ino.module.IHashSetKey.8704.package +package mycompiler.mytypereconstruction.set; +// ino.end + +// ino.class.IHashSetKey.27568.description type=javadoc +/** + * + * @author Jörg Bäuerle + * @version $date + */ +// ino.end +// ino.class.IHashSetKey.27568.declaration +public interface IHashSetKey +// ino.end +// ino.class.IHashSetKey.27568.body +{ + +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumption/CInstVarTypeAssumption.java b/src/mycompiler/mytypereconstruction/typeassumption/CInstVarTypeAssumption.java new file mode 100755 index 000000000..2f3b3be4b --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumption/CInstVarTypeAssumption.java @@ -0,0 +1,98 @@ +// ino.module.CInstVarTypeAssumption.8706.package +package mycompiler.mytypereconstruction.typeassumption; +// ino.end + +// ino.module.CInstVarTypeAssumption.8706.import +import java.util.Vector; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.set.IHashSetKey; +import mycompiler.mytypereconstruction.typeassumptionkey.CInstVarKey; +// ino.end + +// ino.class.CInstVarTypeAssumption.27572.description type=javadoc +/** + * @author Jrg Buerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CInstVarTypeAssumption.27572.declaration +public class CInstVarTypeAssumption extends CTypeAssumption +// ino.end +// ino.class.CInstVarTypeAssumption.27572.body +{ + + // ino.attribute.hashSetKey.27576.declaration + private CInstVarKey hashSetKey; + // ino.end + + + // ino.method.CInstVarTypeAssumption.27579.definition + public CInstVarTypeAssumption(String className, String identifier, Type type, int lineNumber,int offset, Vector Offsetvektor) + // ino.end + // ino.method.CInstVarTypeAssumption.27579.body + { + super(className, identifier, type, lineNumber,offset,Offsetvektor); + } + // ino.end + + // ino.method.getHashSetKey.27582.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @return + */ + // ino.end + // ino.method.getHashSetKey.27582.definition + public CInstVarKey getHashSetKey() + // ino.end + // ino.method.getHashSetKey.27582.body + { + if(hashSetKey==null){ + this.hashSetKey=new CInstVarKey(m_ClassName, m_Identifier); + } + return hashSetKey; + } + // ino.end + + // ino.method.equalsAssumption.27585.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @param assumption + * @return + */ + // ino.end + // ino.method.equalsAssumption.27585.definition + public boolean equalsAssumption(CTypeAssumption assumption) + // ino.end + // ino.method.equalsAssumption.27585.body + { + if(assumption instanceof CInstVarTypeAssumption){ + return true; + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.27588.definition + public CInstVarTypeAssumption clone() + // ino.end + // ino.method.clone.27588.body + { + CInstVarTypeAssumption copy = new CInstVarTypeAssumption(m_ClassName, m_Identifier, m_AssumedType.clone(), m_LineNumber,m_Offset,m_OffsetVector); + return copy; + } + // ino.end + + // ino.method.updateHashSetKey.27591.definition + public void updateHashSetKey(IHashSetKey key) + // ino.end + // ino.method.updateHashSetKey.27591.body + { + this.hashSetKey=(CInstVarKey)key; + + } + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumption/CLocalVarTypeAssumption.java b/src/mycompiler/mytypereconstruction/typeassumption/CLocalVarTypeAssumption.java new file mode 100755 index 000000000..ffbfa2ec4 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumption/CLocalVarTypeAssumption.java @@ -0,0 +1,178 @@ +// ino.module.CLocalVarTypeAssumption.8707.package +package mycompiler.mytypereconstruction.typeassumption; +// ino.end + +// ino.module.CLocalVarTypeAssumption.8707.import +import java.util.Vector; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.set.IHashSetKey; +import mycompiler.mytypereconstruction.typeassumptionkey.CLocalVarKey; +// ino.end + +// ino.class.CLocalVarTypeAssumption.27594.description type=javadoc +/** + * @author Jrg Buerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CLocalVarTypeAssumption.27594.declaration +public class CLocalVarTypeAssumption extends CTypeAssumption +// ino.end +// ino.class.CLocalVarTypeAssumption.27594.body +{ + // ino.attribute.m_MethodName.27598.declaration + protected String m_MethodName; + // ino.end + // ino.attribute.m_MethodParaCount.27601.declaration + protected int m_MethodParaCount; + // ino.end + // ino.attribute.m_BlockId.27604.declaration + protected String m_BlockId; + // ino.end + // ino.attribute.hashSetKey.27607.declaration + private CLocalVarKey hashSetKey; + // ino.end + // ino.attribute.m_methodOverloadedID.27610.declaration + private int m_methodOverloadedID; + // ino.end + + // ino.method.CLocalVarTypeAssumption.27613.definition + public CLocalVarTypeAssumption(String className, String methodName, int methodParaCount, int methodOverloadedID, String blockId, String identifier, Type assumedType, int lineNumber,int offset, Vector Offsetvektor) + // ino.end + // ino.method.CLocalVarTypeAssumption.27613.body + { + super(className, identifier, assumedType, lineNumber,offset,Offsetvektor); + m_MethodName = methodName; + m_MethodParaCount = methodParaCount; + m_BlockId = blockId; + m_methodOverloadedID=methodOverloadedID; + + } + // ino.end + + // ino.method.getMethodOverloadedID.27616.definition + public int getMethodOverloadedID() + // ino.end + // ino.method.getMethodOverloadedID.27616.body + { + return m_methodOverloadedID; + } + // ino.end + + // ino.method.getMethodName.27619.definition + public String getMethodName() + // ino.end + // ino.method.getMethodName.27619.body + { + return m_MethodName; + } + // ino.end + + // ino.method.setMethodName.27622.definition + public void setMethodName(String methodName) + // ino.end + // ino.method.setMethodName.27622.body + { + m_MethodName = methodName; + } + // ino.end + + // ino.method.getMethodParaCount.27625.definition + public int getMethodParaCount() + // ino.end + // ino.method.getMethodParaCount.27625.body + { + return m_MethodParaCount; + } + // ino.end + + // ino.method.setMethodParaCount.27628.definition + public void setMethodParaCount(int methodParaCount) + // ino.end + // ino.method.setMethodParaCount.27628.body + { + m_MethodParaCount = methodParaCount; + } + // ino.end + + // ino.method.getBlockId.27631.definition + public String getBlockId() + // ino.end + // ino.method.getBlockId.27631.body + { + return m_BlockId; + } + // ino.end + + // ino.method.setBlockId.27634.definition + public void setBlockId(String blockId) + // ino.end + // ino.method.setBlockId.27634.body + { + m_BlockId = blockId; + } + // ino.end + + // ino.method.getHashSetKey.27637.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @return + */ + // ino.end + // ino.method.getHashSetKey.27637.definition + public CLocalVarKey getHashSetKey() + // ino.end + // ino.method.getHashSetKey.27637.body + { + if(hashSetKey==null){ + hashSetKey=new CLocalVarKey(m_ClassName, m_MethodName, m_MethodParaCount, m_methodOverloadedID, m_BlockId, m_Identifier); + } + return hashSetKey; + } + // ino.end + + // ino.method.equalsAssumption.27640.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @param assumption + * @return + */ + // ino.end + // ino.method.equalsAssumption.27640.definition + public boolean equalsAssumption(CTypeAssumption assumption) + // ino.end + // ino.method.equalsAssumption.27640.body + { + if(assumption instanceof CLocalVarTypeAssumption){ + CLocalVarTypeAssumption assum = (CLocalVarTypeAssumption)assumption; + boolean ret = true; + ret &= m_MethodName.equals(assum.getMethodName()); + ret &= m_MethodParaCount == assum.getMethodParaCount(); + ret &= m_BlockId == assum.getBlockId(); + return ret; + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.27643.definition + public CLocalVarTypeAssumption clone() + // ino.end + // ino.method.clone.27643.body + { + CLocalVarTypeAssumption copy = new CLocalVarTypeAssumption(m_ClassName, m_MethodName, m_MethodParaCount, m_methodOverloadedID, m_BlockId, m_Identifier, m_AssumedType.clone(), m_LineNumber,m_Offset,m_OffsetVector); + return copy; + } + // ino.end + // ino.method.updateHashSetKey.27646.definition + public void updateHashSetKey(IHashSetKey key) + // ino.end + // ino.method.updateHashSetKey.27646.body + { + this.hashSetKey=(CLocalVarKey)key; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumption/CMethodTypeAssumption.java b/src/mycompiler/mytypereconstruction/typeassumption/CMethodTypeAssumption.java new file mode 100755 index 000000000..d492502c2 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumption/CMethodTypeAssumption.java @@ -0,0 +1,250 @@ +// ino.module.CMethodTypeAssumption.8708.package +package mycompiler.mytypereconstruction.typeassumption; +// ino.end + +// ino.module.CMethodTypeAssumption.8708.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.set.IHashSetKey; +import mycompiler.mytypereconstruction.typeassumptionkey.CMethodKey; +// ino.end + +// ino.class.CMethodTypeAssumption.27649.description type=javadoc +/** + * @author Jrg Buerle + * @version $Date: 2013/07/28 17:05:44 $ + */ +// ino.end +// ino.class.CMethodTypeAssumption.27649.declaration +public class CMethodTypeAssumption extends CTypeAssumption +// ino.end +// ino.class.CMethodTypeAssumption.27649.body +{ + /** + * classType enthält den Typ der Klasse, zu welcher die Methode gehört + */ + private Type classType; + + // ino.attribute.m_ParaAssumptions.27653.declaration + protected Vector m_ParaAssumptions = null; + // ino.end + // ino.attribute.hashSetKey.27656.declaration + private CMethodKey hashSetKey; + // ino.end + // ino.attribute.m_overloadedMethodID.27659.declaration + private int m_overloadedMethodID; + // ino.end + // ino.attribute.parameterCount.27662.declaration + private int parameterCount; + // ino.end + // ino.attribute.genericMethodParameters.27665.declaration + private Vector genericMethodParameters=new Vector(); + // ino.end + + // ino.method.CMethodTypeAssumption.27668.definition + public CMethodTypeAssumption(Type classType, String identifier, Type assumedType, int parameterCount, int lineNumber,int offset, Vector Offsetvektor, Vector genericMethodParameters) + // ino.end + // ino.method.CMethodTypeAssumption.27668.body + { + super(classType.get_Name(), identifier, assumedType, lineNumber,offset,Offsetvektor); + if(genericMethodParameters!=null) + this.genericMethodParameters=genericMethodParameters; + this.parameterCount=parameterCount; + m_ParaAssumptions = new Vector(); + this.classType = classType; + } + // ino.end + + // ino.method.getParaCount.27671.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @return Returns the ParaCount. + */ + // ino.end + // ino.method.getParaCount.27671.definition + public int getParaCount() + // ino.end + // ino.method.getParaCount.27671.body + { + return parameterCount; + } + // ino.end + + // ino.method.getGenericMethodParameters.27674.definition + public Vector getGenericMethodParameters() + // ino.end + // ino.method.getGenericMethodParameters.27674.body + { + return genericMethodParameters; + } + // ino.end + + // ino.method.addParaAssumption.27677.definition + public void addParaAssumption(CParaTypeAssumption paraAssumption) + // ino.end + // ino.method.addParaAssumption.27677.body + { + m_ParaAssumptions.addElement(paraAssumption); + parameterCount=m_ParaAssumptions.size(); + } + // ino.end + + // ino.method.getParaAssumption.27680.definition + public CParaTypeAssumption getParaAssumption(int index) + // ino.end + // ino.method.getParaAssumption.27680.body + { + return m_ParaAssumptions.elementAt(index); + } + // ino.end + + // ino.method.getParaAssumptions.27683.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @return Returns the m_ParaAssumptions. + */ + // ino.end + // ino.method.getParaAssumptions.27683.definition + public Vector getParaAssumptions() + // ino.end + // ino.method.getParaAssumptions.27683.body + { + return m_ParaAssumptions; + } + // ino.end + + // ino.method.sub.27686.definition + public void sub(CSubstitution substitution) + // ino.end + // ino.method.sub.27686.body + { + super.sub(substitution); + for(int i=0; iAuthor: Jrg Buerle + * @param assumption + * @return + */ + // ino.end + // ino.method.equalsAssumption.27689.definition + public boolean equalsAssumption(CTypeAssumption assumption) + // ino.end + // ino.method.equalsAssumption.27689.body + { + if(assumption instanceof CMethodTypeAssumption){ + CMethodTypeAssumption assum = (CMethodTypeAssumption)assumption; + boolean ret = true; + ret &= (this.getParaCount() == assum.getParaCount()); + for(int i=0; i it = m_ParaAssumptions.iterator(); + while(it.hasNext()){ + sb.append(it.next().getAssumedType().getName()); + sb.append(" * "); + } + sb.delete(sb.length()-3,sb.length()); + } + else { + sb.append("NOPARAS"); + } + sb.append(" --> "); + if(this.getAssumedType()!=null)sb.append(this.getAssumedType().toString()); + return sb.toString(); + } + // ino.end + + // ino.method.getHashSetKey.27695.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @return + */ + // ino.end + // ino.method.getHashSetKey.27695.definition + public CMethodKey getHashSetKey() + // ino.end + // ino.method.getHashSetKey.27695.body + { + if(hashSetKey==null){ + this.hashSetKey=new CMethodKey(m_ClassName, m_Identifier, this.getParaCount(),this.getOverloadedMethodID()); + } + return(hashSetKey); + } + // ino.end + + // ino.method.getOverloadedMethodID.27698.definition + public int getOverloadedMethodID() + // ino.end + // ino.method.getOverloadedMethodID.27698.body + { + return(m_overloadedMethodID); + } + // ino.end + + // ino.method.clone.27701.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @return + */ + // ino.end + // ino.method.clone.27701.definition + public CMethodTypeAssumption clone() + // ino.end + // ino.method.clone.27701.body + { + CMethodTypeAssumption copy = new CMethodTypeAssumption(this.classType, m_Identifier, m_AssumedType.clone(), parameterCount,m_LineNumber,m_Offset,m_OffsetVector,genericMethodParameters); + for(int i=0; i Offsetvektor) + // ino.end + // ino.method.CParaTypeAssumption.27723.body + { + super(className, identifier, assumedType, lineNumber,offset,Offsetvektor); + m_MethodName = methodName; + m_MethodParaCount = methodParaCount; + m_methodOverloadedID=methodOverloadedID; + } + // ino.end + + // ino.method.getMethodName.27726.definition + public String getMethodName() + // ino.end + // ino.method.getMethodName.27726.body + { + return m_MethodName; + } + // ino.end + + // ino.method.setMethodName.27729.definition + public void setMethodName(String methodName) + // ino.end + // ino.method.setMethodName.27729.body + { + m_MethodName = methodName; + } + // ino.end + + // ino.method.getMethodParaCount.27732.definition + public int getMethodParaCount() + // ino.end + // ino.method.getMethodParaCount.27732.body + { + return m_MethodParaCount; + } + // ino.end + + // ino.method.setMethodParaCount.27735.definition + public void setMethodParaCount(int methodParaCount) + // ino.end + // ino.method.setMethodParaCount.27735.body + { + m_MethodParaCount = methodParaCount; + } + // ino.end + + // ino.method.getHashSetKey.27738.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @return + */ + // ino.end + // ino.method.getHashSetKey.27738.definition + public CMethodParaKey getHashSetKey() + // ino.end + // ino.method.getHashSetKey.27738.body + { + if(hashSetKey==null){ + this.hashSetKey=new CMethodParaKey(m_ClassName, m_MethodName, m_MethodParaCount,m_methodOverloadedID, m_Identifier); + } + return(hashSetKey); + } + // ino.end + + // ino.method.equalsAssumption.27741.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @param assumption + * @return + */ + // ino.end + // ino.method.equalsAssumption.27741.definition + public boolean equalsAssumption(CTypeAssumption assumption) + // ino.end + // ino.method.equalsAssumption.27741.body + { + if(assumption instanceof CParaTypeAssumption){ + CParaTypeAssumption assum = (CParaTypeAssumption)assumption; + boolean ret = true; + ret &= m_MethodName.equals(assum.getMethodName()); + ret &= m_MethodParaCount == assum.getMethodParaCount(); + return ret; + } + else{ + return false; + } + } + // ino.end + + // ino.method.clone.27744.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @return + */ + // ino.end + // ino.method.clone.27744.definition + public CParaTypeAssumption clone() + // ino.end + // ino.method.clone.27744.body + { + CParaTypeAssumption copy = new CParaTypeAssumption(m_ClassName, m_MethodName, m_MethodParaCount, m_methodOverloadedID, m_Identifier, m_AssumedType.clone(), m_LineNumber, m_Offset,m_OffsetVector); + return copy; + } + // ino.end + + // ino.method.updateHashSetKey.27747.definition + public void updateHashSetKey(IHashSetKey key) + // ino.end + // ino.method.updateHashSetKey.27747.body + { + hashSetKey=(CMethodParaKey)key; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumption/CTypeAssumption.java b/src/mycompiler/mytypereconstruction/typeassumption/CTypeAssumption.java new file mode 100755 index 000000000..eed59bf4d --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumption/CTypeAssumption.java @@ -0,0 +1,253 @@ +// ino.module.CTypeAssumption.8710.package +package mycompiler.mytypereconstruction.typeassumption; +// ino.end + +// ino.module.CTypeAssumption.8710.import +import java.util.Iterator; +import java.util.Vector; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import mycompiler.mytypereconstruction.set.IHashSetElement; +import mycompiler.mytypereconstruction.typeassumptionkey.CTypeAssumptionKey; +// ino.end + +// ino.class.CTypeAssumption.27750.description type=javadoc +/** + * Diese Klasse repr�sentiert eine Typannahme und bildet einen + * Bezeichner innerhalb einer bestimmten Klasse auf einen angenommenen + * Typ ab.
+ * Die von dieser Klasse abgeleiteten Subklassen stehen f�r bestimmte + * Typannahmen des abstrakten Syntaxbaumes, wie z.B. f�r Felder, Methoden, + * lokale Variablen, etc. + * @author J�rg B�uerle + * @version $Date: 2006/07/10 11:27:04 $ + */ +// ino.end +// ino.class.CTypeAssumption.27750.declaration +public abstract class CTypeAssumption implements IHashSetElement +// ino.end +// ino.class.CTypeAssumption.27750.body +{ + // ino.attribute.m_ClassName.27754.declaration + protected String m_ClassName; + // ino.end + // ino.attribute.m_Identifier.27757.declaration + protected String m_Identifier; + // ino.end + // ino.attribute.m_AssumedType.27760.declaration + protected Type m_AssumedType; + // ino.end + // ino.attribute.m_LineNumber.27763.declaration + protected int m_LineNumber; + // ino.end + // ino.attribute.m_Offset.27766.declaration + protected int m_Offset; + // ino.end + // ino.attribute.m_OffsetVector.27769.declaration + protected Vector m_OffsetVector; + // ino.end + + // ino.method.CTypeAssumption.27772.definition + public CTypeAssumption(String className, String identifier, Type assumedType, int lineNumber, int offset, Vector OffsetVektor) + // ino.end + // ino.method.CTypeAssumption.27772.body + { + m_ClassName = className; + m_Identifier = identifier; + m_AssumedType = assumedType; + m_LineNumber = lineNumber; + m_Offset = offset; + m_OffsetVector = OffsetVektor; + } + // ino.end + + // ino.method.getClassName.27775.definition + public String getClassName() + // ino.end + // ino.method.getClassName.27775.body + { + return m_ClassName; + } + // ino.end + + // ino.method.setClassName.27778.definition + public void setClassName(String className) + // ino.end + // ino.method.setClassName.27778.body + { + m_ClassName = className; + } + // ino.end + + // ino.method.getIdentifier.27781.definition + public String getIdentifier() + // ino.end + // ino.method.getIdentifier.27781.body + { + return m_Identifier; + } + // ino.end + + // ino.method.setIdentifier.27784.definition + public void setIdentifier(String identifier) + // ino.end + // ino.method.setIdentifier.27784.body + { + m_Identifier = identifier; + } + // ino.end + + // ino.method.getAssumedType.27787.definition + public Type getAssumedType() + // ino.end + // ino.method.getAssumedType.27787.body + { + return m_AssumedType; + } + // ino.end + + // ino.method.setAssumedType.27790.definition + public void setAssumedType(Type assumedType) + // ino.end + // ino.method.setAssumedType.27790.body + { + m_AssumedType = assumedType; + } + // ino.end + + // ino.method.getLineNumber.27793.definition + public int getLineNumber() + // ino.end + // ino.method.getLineNumber.27793.body + { + return m_LineNumber; + } + // ino.end + + // ino.method.setLineNumber.27796.definition + public void setLineNumber(int lineNumber) + // ino.end + // ino.method.setLineNumber.27796.body + { + m_LineNumber = lineNumber; + } + // ino.end + + // ino.method.getOffset.27799.definition + public int getOffset() + // ino.end + // ino.method.getOffset.27799.body + { + return m_Offset; + } + // ino.end + + // ino.method.addOffset.27802.definition + public void addOffset(int i) + // ino.end + // ino.method.addOffset.27802.body + { + m_OffsetVector.addElement(new Integer(i)); + } + // ino.end + + // ino.method.getOffsetVector.27805.definition + public Vector getOffsetVector() + // ino.end + // ino.method.getOffsetVector.27805.body + { + return m_OffsetVector; + } + // ino.end + + // ino.method.setOffset.27808.definition + public void setOffset(int Offset) + // ino.end + // ino.method.setOffset.27808.body + { + m_Offset = Offset; + } + // ino.end + + + // ino.method.sub.27811.definition + public void sub(CSubstitutionSet substitutionSet) + // ino.end + // ino.method.sub.27811.body + { + Iterator it = substitutionSet.getIterator(); + while(it.hasNext()){ + this.sub(it.next()); + } + } + // ino.end + + // ino.method.sub.27814.definition + public void sub(CSubstitution substitution) + // ino.end + // ino.method.sub.27814.body + { + //PL 05-08-25 hier muessen TypePlaceholder-Variablen auch erstezt werden, + //wenn sie als Subvariablen in typen vorkommen. + //if(m_AssumedType.equals(substitution.getTypeVar())){ + // m_AssumedType = substitution.getType(); + // System.out.println(); + m_AssumedType = substitution.applyThisSubstitution(m_AssumedType); + + } + // ino.end + + // ino.method.toString.27817.definition + public String toString() + // ino.end + // ino.method.toString.27817.body + { + return m_Identifier +": "+m_AssumedType.toString(); + //return m_Identifier +": "+m_AssumedType.getName(); + } + // ino.end + + // ino.method.equals.27820.definition + public final boolean equals(Object obj) + // ino.end + // ino.method.equals.27820.body + { + if(obj instanceof CTypeAssumption){ + CTypeAssumption assum = (CTypeAssumption)obj; + boolean ret = true; + ret &= m_ClassName.equals(assum.getClassName()); + ret &= m_Identifier.equals(assum.getIdentifier()); + ret &= m_AssumedType.equals(assum.getAssumedType()); + ret &= m_LineNumber==assum.getLineNumber(); + ret &= this.equalsAssumption(assum); + return ret; + } + else{ + return false; + } + } + // ino.end + + // ino.method.isPlaceholderVariable.27823.definition + public boolean isPlaceholderVariable() + // ino.end + // ino.method.isPlaceholderVariable.27823.body + { + return (m_AssumedType instanceof TypePlaceholder); + } + // ino.end + + // ino.method.equalsAssumption.27826.declaration + public abstract boolean equalsAssumption(CTypeAssumption assumption); + // ino.end + // ino.method.clone.27829.declaration + public abstract CTypeAssumption clone(); + // ino.end + // ino.method.getHashSetKey.27832.declaration + public abstract CTypeAssumptionKey getHashSetKey(); + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumptionkey/CInstVarKey.java b/src/mycompiler/mytypereconstruction/typeassumptionkey/CInstVarKey.java new file mode 100755 index 000000000..e9794c3c7 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumptionkey/CInstVarKey.java @@ -0,0 +1,37 @@ +// ino.module.CInstVarKey.8712.package +package mycompiler.mytypereconstruction.typeassumptionkey; +// ino.end + +// ino.class.CInstVarKey.27836.description type=javadoc +/** + * @author Jörg Bäuerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CInstVarKey.27836.declaration +public class CInstVarKey extends CTypeAssumptionKey +// ino.end +// ino.class.CInstVarKey.27836.body +{ + // ino.attribute.KEYPREFIX.27840.declaration + public static String KEYPREFIX = "InstVar"; + // ino.end + + // ino.method.CInstVarKey.27843.definition + public CInstVarKey(String className, String identifier) + // ino.end + // ino.method.CInstVarKey.27843.body + { + StringBuffer key = new StringBuffer(); + + key.append(KEYPREFIX); + key.append("#"); + key.append(className); + key.append("."); + key.append(identifier); + + m_KeyString = key.toString(); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumptionkey/CLocalVarKey.java b/src/mycompiler/mytypereconstruction/typeassumptionkey/CLocalVarKey.java new file mode 100755 index 000000000..7b0f7e4a8 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumptionkey/CLocalVarKey.java @@ -0,0 +1,131 @@ +// ino.module.CLocalVarKey.8713.package +package mycompiler.mytypereconstruction.typeassumptionkey; +// ino.end + + +// ino.class.CLocalVarKey.27846.description type=javadoc +/** + * @author Jrg Buerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CLocalVarKey.27846.declaration +public class CLocalVarKey extends CTypeAssumptionKey implements IMethodBoundKey +// ino.end +// ino.class.CLocalVarKey.27846.body +{ + // ino.attribute.KEYPREFIX.27851.declaration + public static String KEYPREFIX = "LocalVar"; + // ino.end + + // ino.attribute.className.27854.declaration + String className; + // ino.end + // ino.attribute.methodName.27857.declaration + String methodName; + // ino.end + // ino.attribute.methodParaCount.27860.declaration + int methodParaCount; + // ino.end + // ino.attribute.blockId.27863.declaration + String blockId; + // ino.end + // ino.attribute.identifier.27866.declaration + String identifier; + // ino.end + // ino.attribute.overloadedMethodID.27869.declaration + int overloadedMethodID; + // ino.end + + // ino.attribute.isOverloadedInitialized.27872.declaration + private boolean isOverloadedInitialized=true; + // ino.end + + + // ino.method.CLocalVarKey.27875.definition + public CLocalVarKey(String className, String methodName, int methodParaCount, String blockId, String identifier) + // ino.end + // ino.method.CLocalVarKey.27875.body + { + this(className,methodName,methodParaCount,0,blockId,identifier); + isOverloadedInitialized=false; + } + // ino.end + + + // ino.method.CLocalVarKey.27878.definition + public CLocalVarKey(String className, String methodName, int methodParaCount, int overloadedMethodID, String blockId, String identifier) + // ino.end + // ino.method.CLocalVarKey.27878.body + { + + this.className=className; + this.methodName=methodName; + this.methodParaCount=methodParaCount; + this.blockId=blockId; + this.identifier=identifier; + this.overloadedMethodID=overloadedMethodID; + + StringBuffer key = new StringBuffer(); + + key.append(KEYPREFIX); + key.append("#"); + key.append(className); + key.append("."); + key.append(methodName); + key.append("("); + key.append(methodParaCount); + key.append(";"); + key.append(overloadedMethodID); + key.append(")"); + key.append("."); + key.append("Block_"); + key.append(blockId); + key.append("."); + key.append(identifier); + + m_KeyString = key.toString(); + } + // ino.end + + + // ino.method.getNextMethodKey.27881.definition + public CLocalVarKey getNextMethodKey() + // ino.end + // ino.method.getNextMethodKey.27881.body + { + return(new CLocalVarKey(className,methodName,methodParaCount,overloadedMethodID+1,blockId,identifier)); + } + // ino.end + + + // ino.method.getFirstMethodKey.27884.definition + public CLocalVarKey getFirstMethodKey() + // ino.end + // ino.method.getFirstMethodKey.27884.body + { + return(new CLocalVarKey(className,methodName,methodParaCount,blockId,identifier)); + } + // ino.end + + + // ino.method.getOverloadedMethodID.27887.definition + public int getOverloadedMethodID() + // ino.end + // ino.method.getOverloadedMethodID.27887.body + { + return overloadedMethodID; + } + // ino.end + + + // ino.method.isOverloadedIDSet.27890.definition + public boolean isOverloadedIDSet() + // ino.end + // ino.method.isOverloadedIDSet.27890.body + { + return isOverloadedInitialized; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumptionkey/CMethodKey.java b/src/mycompiler/mytypereconstruction/typeassumptionkey/CMethodKey.java new file mode 100755 index 000000000..cedd57b67 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumptionkey/CMethodKey.java @@ -0,0 +1,112 @@ +// ino.module.CMethodKey.8714.package +package mycompiler.mytypereconstruction.typeassumptionkey; +// ino.end + +// ino.class.CMethodKey.27893.description type=javadoc +/** + * @author Jrg Buerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CMethodKey.27893.declaration +public class CMethodKey extends CTypeAssumptionKey implements IMethodBoundKey +// ino.end +// ino.class.CMethodKey.27893.body +{ + // ino.attribute.KEYPREFIX.27898.declaration + public static String KEYPREFIX = "Method"; + // ino.end + + + // ino.attribute.identifier.27901.declaration + private String identifier; + // ino.end + // ino.attribute.paraCount.27904.declaration + private int paraCount; + // ino.end + // ino.attribute.overloadedMethodID.27907.declaration + private int overloadedMethodID; + // ino.end + // ino.attribute.className.27910.declaration + private String className; + // ino.end + // ino.attribute.isOverloadedInitialized.27913.declaration + private boolean isOverloadedInitialized=true; + // ino.end + + // ino.method.CMethodKey.27916.definition + public CMethodKey(String className, String identifier, int paraCount) + // ino.end + // ino.method.CMethodKey.27916.body + { + this(className,identifier,paraCount,0); + isOverloadedInitialized=false; + } + // ino.end + + + // ino.method.CMethodKey.27919.definition + public CMethodKey(String className, String identifier, int paraCount, int overloadedMethodID) + // ino.end + // ino.method.CMethodKey.27919.body + { + + this.className=className; + this.identifier=identifier; + this.paraCount=paraCount; + this.overloadedMethodID=overloadedMethodID; + + StringBuffer key = new StringBuffer(); + + key.append(KEYPREFIX); + key.append("#"); + key.append(className); + key.append("."); + key.append(identifier); + key.append("("); + key.append(paraCount); + key.append(";"); + key.append(overloadedMethodID); + key.append(")"); + + m_KeyString = key.toString(); + } + // ino.end + + // ino.method.getNextMethodKey.27922.definition + public CMethodKey getNextMethodKey() + // ino.end + // ino.method.getNextMethodKey.27922.body + { + return(new CMethodKey(className,identifier, paraCount, overloadedMethodID+1)); + } + // ino.end + + // ino.method.getFirstMethodKey.27925.definition + public CMethodKey getFirstMethodKey() + // ino.end + // ino.method.getFirstMethodKey.27925.body + { + return(new CMethodKey(className,identifier, paraCount, 0)); + } + // ino.end + + // ino.method.getOverloadedMethodID.27928.definition + public int getOverloadedMethodID() + // ino.end + // ino.method.getOverloadedMethodID.27928.body + { + return overloadedMethodID; + } + // ino.end + + // ino.method.isOverloadedIDSet.27931.definition + public boolean isOverloadedIDSet() + // ino.end + // ino.method.isOverloadedIDSet.27931.body + { + return isOverloadedInitialized; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumptionkey/CMethodParaKey.java b/src/mycompiler/mytypereconstruction/typeassumptionkey/CMethodParaKey.java new file mode 100755 index 000000000..ebc4cb436 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumptionkey/CMethodParaKey.java @@ -0,0 +1,118 @@ +// ino.module.CMethodParaKey.8715.package +package mycompiler.mytypereconstruction.typeassumptionkey; +// ino.end + +// ino.class.CMethodParaKey.27934.description type=javadoc +/** + * @author Jrg Buerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CMethodParaKey.27934.declaration +public class CMethodParaKey extends CTypeAssumptionKey implements IMethodBoundKey +// ino.end +// ino.class.CMethodParaKey.27934.body +{ + // ino.attribute.KEYPREFIX.27939.declaration + public static String KEYPREFIX = "MethodPara"; + // ino.end + + + // ino.attribute.className.27942.declaration + private String className; + // ino.end + // ino.attribute.methodName.27945.declaration + private String methodName; + // ino.end + // ino.attribute.overloadedMethodID.27948.declaration + private int overloadedMethodID; + // ino.end + // ino.attribute.identifier.27951.declaration + private String identifier; + // ino.end + // ino.attribute.methodParaCount.27954.declaration + private int methodParaCount; + // ino.end + + + // ino.attribute.isOverloadedInitialized.27957.declaration + private boolean isOverloadedInitialized=true; + // ino.end + + // ino.method.CMethodParaKey.27960.definition + public CMethodParaKey(String className, String methodName, int methodParaCount, String identifier) + // ino.end + // ino.method.CMethodParaKey.27960.body + { + this(className,methodName,methodParaCount,0,identifier); + isOverloadedInitialized=false; + } + // ino.end + + // ino.method.CMethodParaKey.27963.definition + public CMethodParaKey(String className, String methodName, int methodParaCount,int overloadedMethodID, String identifier) + // ino.end + // ino.method.CMethodParaKey.27963.body + { + + this.className=className; + this.methodName=methodName; + this.overloadedMethodID=overloadedMethodID; + this.identifier=identifier; + this.methodParaCount=methodParaCount; + + + StringBuffer key = new StringBuffer(); + + key.append(KEYPREFIX); + key.append("#"); + key.append(className); + key.append("."); + key.append(methodName); + key.append("("); + key.append(methodParaCount); + key.append(";"); + key.append(overloadedMethodID); + key.append(")"); + key.append("."); + key.append(identifier); + + m_KeyString = key.toString(); + } + // ino.end + // ino.method.getNextMethodKey.27966.definition + public CMethodParaKey getNextMethodKey() + // ino.end + // ino.method.getNextMethodKey.27966.body + { + return(new CMethodParaKey(className,methodName, methodParaCount, overloadedMethodID+1,identifier)); + + } + // ino.end + // ino.method.getFirstMethodKey.27969.definition + public CMethodParaKey getFirstMethodKey() + // ino.end + // ino.method.getFirstMethodKey.27969.body + { + return(new CMethodParaKey(className,methodName, methodParaCount,identifier)); + } + // ino.end + // ino.method.getOverloadedMethodID.27972.definition + public int getOverloadedMethodID() + // ino.end + // ino.method.getOverloadedMethodID.27972.body + { + return overloadedMethodID; + } + // ino.end + + // ino.method.isOverloadedIDSet.27975.definition + public boolean isOverloadedIDSet() + // ino.end + // ino.method.isOverloadedIDSet.27975.body + { + return isOverloadedInitialized; + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumptionkey/CTypeAssumptionKey.java b/src/mycompiler/mytypereconstruction/typeassumptionkey/CTypeAssumptionKey.java new file mode 100755 index 000000000..5e60a1173 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumptionkey/CTypeAssumptionKey.java @@ -0,0 +1,94 @@ +// ino.module.CTypeAssumptionKey.8716.package +package mycompiler.mytypereconstruction.typeassumptionkey; +// ino.end + +// ino.module.CTypeAssumptionKey.8716.import +import mycompiler.mytypereconstruction.set.IHashSetKey; +// ino.end + + +// ino.class.CTypeAssumptionKey.27978.description type=javadoc +/** + * Diese Klasse modelliert einen eindeutigen Schlssel fr eine Typannahme, + * die in einem CTypeAssumptionSet abgelegt wird. + * @author Jrg Buerle + * @version $Date: 2006/06/13 10:37:32 $ + */ +// ino.end +// ino.class.CTypeAssumptionKey.27978.declaration +public abstract class CTypeAssumptionKey implements IHashSetKey +// ino.end +// ino.class.CTypeAssumptionKey.27978.body +{ + + // ino.attribute.m_KeyString.27982.declaration + protected String m_KeyString = null; + // ino.end + + // ino.method.getKeyString.27985.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @return Returns the KeyString. + */ + // ino.end + // ino.method.getKeyString.27985.definition + public String getKeyString() + // ino.end + // ino.method.getKeyString.27985.body + { + return m_KeyString; + } + // ino.end + + // ino.method.equals.27988.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @param obj + * @return + */ + // ino.end + // ino.method.equals.27988.definition + public boolean equals(Object obj) + // ino.end + // ino.method.equals.27988.body + { + if(obj instanceof CTypeAssumptionKey){ + return m_KeyString.equals(((CTypeAssumptionKey)obj).getKeyString()); + } + else{ + return false; + } + } + // ino.end + + // ino.method.hashCode.27991.defdescription type=javadoc + /** + * Author: Jrg Buerle
+ * @return + */ + // ino.end + // ino.method.hashCode.27991.definition + public int hashCode() + // ino.end + // ino.method.hashCode.27991.body + { + return m_KeyString.hashCode(); + } + // ino.end + + // ino.method.toString.27994.defdescription type=javadoc + /** + *
Author: Jrg Buerle + * @return + */ + // ino.end + // ino.method.toString.27994.definition + public String toString() + // ino.end + // ino.method.toString.27994.body + { + return this.getKeyString(); + } + // ino.end +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/typeassumptionkey/IMethodBoundKey.java b/src/mycompiler/mytypereconstruction/typeassumptionkey/IMethodBoundKey.java new file mode 100755 index 000000000..928529373 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/typeassumptionkey/IMethodBoundKey.java @@ -0,0 +1,68 @@ +// ino.module.IMethodBoundKey.8717.package +package mycompiler.mytypereconstruction.typeassumptionkey; +// ino.end + +// ino.class.IMethodBoundKey.27997.declaration +public interface IMethodBoundKey +// ino.end +// ino.class.IMethodBoundKey.27997.body +{ + + + // ino.method.getNextMethodKey.28000.decldescription type=javadoc + /** + * Berechnet anhand des aktuellen Schluessels den Schluessel + * fuer die naechste Ueberlandene Methode + * + * Bsp: + * + * Es gibt 2 Methoden + * + * -overloaded(int a) + * -overloaded(char a) + * + * Wenn ich den MethodKey der 1. Methode (je nach reihenfolge + * der Methodendeklaration) habe, kann ich durch den Aufruf + * von getNextMethodKey() den Key der 2. Methode berechnen + * lassen ohne dass der Key neu erstellt werden muss + */ + // ino.end + // ino.method.getNextMethodKey.28000.declaration + public IMethodBoundKey getNextMethodKey(); + // ino.end + + // ino.method.getFirstMethodKey.28003.decldescription type=javadoc + /** + * Liefert immer den Key der 1. Methode + * + */ + // ino.end + // ino.method.getFirstMethodKey.28003.declaration + public IMethodBoundKey getFirstMethodKey(); + // ino.end + + + // ino.method.getOverloadedMethodID.28006.decldescription type=javadoc + /** + * Liefert die Überladen-ID der Methode + * @return overloaded-ID + */ + // ino.end + // ino.method.getOverloadedMethodID.28006.declaration + public int getOverloadedMethodID(); + // ino.end + + + // ino.method.isOverloadedIDSet.28009.decldescription type=javadoc + /** + * Gibt an, ob die overloaded-id initialisiert wurde, + * oder ob das Objekt mit dem "lazy"-konstruktor initialisiert wurde + * @return true/false + */ + // ino.end + // ino.method.isOverloadedIDSet.28009.declaration + public boolean isOverloadedIDSet(); + // ino.end + +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/unify/FC_TTO.java b/src/mycompiler/mytypereconstruction/unify/FC_TTO.java new file mode 100755 index 000000000..79d60fff9 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/unify/FC_TTO.java @@ -0,0 +1,74 @@ +// ino.module.FC_TTO.8719.package +package mycompiler.mytypereconstruction.unify; +// ino.end + +// ino.module.FC_TTO.8719.import +import java.util.Vector; +import mycompiler.mytype.Pair; +import mycompiler.myclass.Class; +// ino.end + +// ino.class.FC_TTO.28013.description type=javadoc +/** + * Hilfsklasse f�r den Unifizierungsalgorithmus + * @author Martin Pl�micke + * @version $Date: 2013/05/12 14:00:05 $ + */ +// ino.end +// ino.class.FC_TTO.28013.declaration +public class FC_TTO +// ino.end +// ino.class.FC_TTO.28013.body +{ + + // ino.attribute.FC.28016.declaration + Vector FC; + // ino.end + // ino.attribute.TTO.28019.declaration + Vector TTO; + // ino.end + + Vector CLASSVEC; + + // ino.method.FC_TTO.28022.definition + public FC_TTO(Vector fc, Vector tto, Vector classv) + // ino.end + // ino.method.FC_TTO.28022.body + { + + this.FC = fc; + this.TTO = tto; + this.CLASSVEC = classv; + + } + // ino.end + + // ino.method.getFC.28025.definition + public Vector getFC() + // ino.end + // ino.method.getFC.28025.body + { + return FC; + } + // ino.end + + // ino.method.getTTO.28028.definition + public Vector getTTO() + // ino.end + // ino.method.getTTO.28028.body + { + return TTO; + } + // ino.end + + public Vector getClasses() + { + return CLASSVEC; + } + + @Override + public String toString(){ + return "FC: "+getFC()+"\nTTO: "+getTTO()+"\nCLASSVEC: "+getClasses(); + } +} +// ino.end diff --git a/src/mycompiler/mytypereconstruction/unify/MUB.java b/src/mycompiler/mytypereconstruction/unify/MUB.java new file mode 100755 index 000000000..09a0a44fa --- /dev/null +++ b/src/mycompiler/mytypereconstruction/unify/MUB.java @@ -0,0 +1,53 @@ +// ino.module.MUB.8720.package +package mycompiler.mytypereconstruction.unify; +// ino.end + +// ino.module.MUB.8720.import +import java.util.Vector; +import mycompiler.mytype.Pair; +import mycompiler.mytype.Type; +// ino.end + +// ino.class.MUB.28031.declaration +public class MUB +// ino.end +// ino.class.MUB.28031.body +{ + // ino.attribute.Mub.28034.declaration + Vector Mub; + // ino.end + // ino.attribute.sigma.28037.declaration + Vector sigma; + // ino.end + + // ino.method.MUB.28040.definition + MUB(Vector M, Vector s) + // ino.end + // ino.method.MUB.28040.body + { + Mub = M; + sigma = s; + } + // ino.end + + // ino.method.getUnifier.28043.definition + public Vector getUnifier() + // ino.end + // ino.method.getUnifier.28043.body + { + return sigma; + } + // ino.end + + // ino.method.getMub.28046.definition + public Vector getMub() + // ino.end + // ino.method.getMub.28046.body + { + return Mub; + } + // ino.end + +} +// ino.end + diff --git a/src/mycompiler/mytypereconstruction/unify/Unify.java b/src/mycompiler/mytypereconstruction/unify/Unify.java new file mode 100755 index 000000000..48cad7419 --- /dev/null +++ b/src/mycompiler/mytypereconstruction/unify/Unify.java @@ -0,0 +1,3389 @@ +//otth/pluemicke2.1.jav funktioniert nicht xxx anschauen +// ino.module.Unify.8721.package +package mycompiler.mytypereconstruction.unify; +// ino.end +// ino.module.Unify.8721.import +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; +import mycompiler.MyCompiler; +import mycompiler.myexception.CTypeReconstructionException; +import mycompiler.myexception.MatchException; +import mycompiler.myexception.SCException; +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.CRefTypeSet; +import mycompiler.mytype.ExtendsWildcardType; +import mycompiler.mytype.FreshExtendsWildcardType; +import mycompiler.mytype.FreshSuperWildcardType; +import mycompiler.mytype.FreshWildcardType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.IMatchable; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.WildcardType; +import mycompiler.mytype.Pair.PairOperator; +import mycompiler.myclass.Class; +import mycompiler.mytypereconstruction.set.CSubstitutionSet; +import org.apache.log4j.Logger; + +// ino.end + +// ino.class.Unify.28049.description type=javadoc +/** + * Implementierung des Unifizierungsalgorithmus + * @author Martin Pl�micke, Thomas Ott + * @version $Date: 2013/05/22 22:23:50 $ + */ +// ino.end +// ino.class.Unify.28049.declaration +public class Unify +// ino.end +// ino.class.Unify.28049.body +{ + + // ino.attribute.inferencelog.28052.declaration + protected static Logger inferencelog = Logger.getLogger("inference"); + // ino.end + + /** + * Unifiziert ein Pair mit den Elementen ty1 und ty2 -> (ty1 < ty2) + * @param ty1 + * @param ty2 + * @param fc_tto + * @return + */ + // ino.method.unify.28055.definition + public static Vector> unify(Type ty1, Type ty2, FC_TTO fc_tto ) + // ino.end + // ino.method.unify.28055.body + { + Vector pairsToUnify = new Vector(); + Pair retTypePair = new Pair(ty1, ty2); + pairsToUnify.addElement(retTypePair); + return Unify.unify(pairsToUnify, fc_tto); + } + // ino.end + + // ino.method.unify.28058.definition + //public static Vector> unify(Vector E, FC_TTO fc_tto ) + public static Vector> unifyOld(Vector E, FC_TTO fc_tto ) + // ino.end + // ino.method.unify.28058.body + { + //HIER MUSS NICHT-UNITARY UNIFIER NOCH PROGRAMMIERT WERDEN + + Vector FC = fc_tto.getFC(); + //Vector TTO = fc_tto.getTTO(); + //Vector> Eq_set = new Vector>(); + Vector Eq_11 = new Vector (); + Vector Eq_12 = new Vector (); + Vector>> sm_set = new Vector>>(); + Vector>> gr_set = new Vector>>(); + Vector>> bound_set = new Vector>>(); + + //1./2. Schritt (smaller und greater Set bilden) + for( int i = 0; i < E.size(); i++ ) + { + Pair P = E.elementAt(i); + inferencelog.debug(""); + inferencelog.debug(""); + inferencelog.debug("Ausgew�hltes Paar = " + P.toString() + ""); + inferencelog.debug( "--------------------------------------------------"); + if ( P.TA1 instanceof TypePlaceholder && P.TA2 instanceof RefType && P.OperatorSmaller()) + { + //1. Schritt (smaller) + Vector> setofsetofpairs= instanceSmaller(P, fc_tto); + + //sm_set = setofsetofpairs; // Urspruenglich + sm_set.addElement(setofsetofpairs); // PL + } + else if ( (P.TA1 instanceof RefType || P.TA1 instanceof BoundedGenericTypeVar) && P.TA2 instanceof TypePlaceholder && P.OperatorSmaller()) + { + //2. Schritt (greater) + //IST KEIN MATCH IN DER FUNKTION allGreater NOETIG + Vector gr; + if (P.TA1 instanceof RefType) + gr = allGreater((RefType)P.TA1, FC); + else + gr = allGreater((BoundedGenericTypeVar)P.TA1, FC); + + Vector setofpairs = new Vector (); + setofpairs.addElement(new Pair(P.TA2, P.TA1, PairOperator.Equal)); //Reflexivitaet + Vector> setofsetofpairs = new Vector>(); + setofsetofpairs.addElement(setofpairs); + for (int ii = 0; ii < gr.size(); ii++) + { + setofpairs = new Vector (); + setofpairs.addElement(new Pair(P.TA2, gr.elementAt(ii), PairOperator.Equal)); + setofsetofpairs.addElement(setofpairs); + } + gr_set.addElement(setofsetofpairs); + } + else if ( P.TA1 instanceof TypePlaceholder && P.TA2 instanceof TypePlaceholder && P.OperatorSmaller()) + { + //WAS PASSIERT MIT EINE PAAR HIER DRIN BLEIBT??? + Eq_12.addElement(P); + printMenge("Eq_12", Eq_12, 6); + inferencelog.debug(P.OperatorEqual()); + } + else if (P.TA1 instanceof BoundedGenericTypeVar && P.TA2 instanceof RefType) + { //PL 06-06-13 + Vector bounds = ((BoundedGenericTypeVar)(P.TA1)).getBounds(); + Vector> setofsetofpairs = new Vector>(); + for (int ii = 0; ii < bounds.size(); ii++) + { + Vector setofpairs = new Vector (); + setofpairs.addElement(new Pair(bounds.elementAt(ii), P.TA2)); + setofsetofpairs.addElement(setofpairs); + } + bound_set.addElement(setofsetofpairs); + } + else + { //P.TA1 instanceof RefType && P.TA2 instanceof RefType + Eq_11.addElement(P); + printMenge("Eq_11", Eq_11, 6); + } + //ret.addElement(sub_unify(E, FC)); + } + + //3. Schritt, kartesisches Produkt + Vector helpvp; + Vector> newvecvecpair1 = new Vector>(); + + //notwendig damit die naechste for-Schleife (ii) auf alle Faelle + //mindestens einmal durchlaufen wird. + //if (sm_set.size() == 0) sm_set.addElement(new Vector()); + + //korregiert PL 06-05-12 + Vector>> Eq_2expand = sm_set; + Eq_2expand.addAll(gr_set); //kleinere und groessere Elemente zusammengefasst + Eq_2expand.addAll(bound_set); //bounds werden auch hinzugefuegt //PL 06-06-13 + + newvecvecpair1.addElement(copyVectorPair(Eq_11)); + + for (int ii = 0; ii < Eq_2expand.size(); ii++) { + Vector> OneE_Element = Eq_2expand.elementAt(ii); + Vector> newvecvecpair1old = newvecvecpair1; + newvecvecpair1 = new Vector>(); + for(int iii=0; iii< OneE_Element.size(); iii++) { + for(int k = 0; k < newvecvecpair1old.size(); k++) { + helpvp = copyVectorPair(newvecvecpair1old.elementAt(k)); + helpvp.addAll(copyVectorPair(OneE_Element.elementAt(iii))); + newvecvecpair1.addElement(helpvp); + } + } + } + + //groessere Elemente auskommentiert PL 06-05-12 + // Vector> helpvp2; + Vector> newvecvecpair2 = newvecvecpair1; //new Vector>(); + // for (int ii = 0; ii < newvecvecpair1.size(); ii++) { + // Vector OneUnifier = newvecvecpair1.elementAt(ii); + // //notwendig damit die naechste for-Schleife (jj) auf alle Faelle + // //mindestens einmal durchlaufen wird. + // //if (gr_set.size() == 0) gr_set.addElement(new Vector ()); + // if (gr_set.size() == 0) newvecvecpair2.addElement(OneUnifier); + // for (int jj = 0; jj < gr_set.size(); jj++) { + // Vector> OneE_Element = gr_set.elementAt(ii); + // for(int jjj = 0; jjj< OneE_Element.size(); jjj++) { + // helpvp = copyVectorPair(OneUnifier); + // inferencelog.debug(gr_set); + // helpvp.addAll(copyVectorPair(OneE_Element.elementAt(jjj))); + // newvecvecpair2.addElement(helpvp); + // } + // } + // } + + + Vector> newvecvecpair3 = new Vector>(); + //Vector> rek = new Vector>(); + //Vector> ret = new Vector>(); + for (int kk = 0; kk < newvecvecpair2.size(); kk++) { + //newvecvecpair3.addElement(sub_unify(newvecvecpair2.elementAt(kk), FC)); + printMenge("Sigma_alt", newvecvecpair2.elementAt(kk), 6); + + //4. Schritt + Vector sigma = sub_unify(newvecvecpair2.elementAt(kk), fc_tto); + //5, Schritt + if (hasSolvedForm(sigma)) //PL 13-05-22: hasSolvedForm geaendert, es nicht geklärt, ob es funktioniert. + { + Hashtable ht = VectorPair2SubstHashtableVectorPair(sigma); + Type r1; + Type r2; + boolean ready = true; + for(int ll = 0; ll < Eq_12.size(); ll++) { + r1 = (Type)ht.get(Eq_12.elementAt(ll).TA1.getName()); + r2 = (Type)ht.get(Eq_12.elementAt(ll).TA2.getName()); + if (r1 == null) r1 = Eq_12.elementAt(ll).TA1; + else ready = false; + if (r2 == null) r2 = Eq_12.elementAt(ll).TA2; + else ready = false; + sigma.addElement(new Pair(r1, r2)); + } + inferencelog.debug(ready); + if (!ready) { + printMenge("Sigma", sigma, 6); + + //6. Schritt (a) + //7. Schritt (addAll) + newvecvecpair3.addAll(unify(sigma, fc_tto)); + printMengeUnifier("newvecvecpair3_alt", newvecvecpair3, 6); + } + else { + //6. Schritt (b) + newvecvecpair3.addElement(sigma); + } + } + } + return newvecvecpair3; + } + // ino.end + + /** + * Einstieg in die Unifizierung mit Wildcards + * + * @param ty1 - Typ 1 der Unifizierung + * @param ty2 - Typ 2 der Unifizierung + * @param fc_tto - Hilfsklasse mit FC + * @return Vector> - Ergebnispaare + */ + public static Vector> unifyWC(Type ty1, Type ty2, FC_TTO fc_tto) + { + return unifyWC(new Pair(ty1,ty2),fc_tto); + } + + /** + * Einstieg in die Unifizierung mit Wildcards + * + * @param P - Paar das unifiziert werden soll. + * @param fc_tto - Hilfsklasse mit FC + * @return Vector> - Ergebnispaare + */ + public static Vector> unifyWC (Pair P, FC_TTO fc_tto) + { + Vector tmp = new Vector(); + tmp.add(P); + return unify(tmp,fc_tto); + } + + /** + * Einstieg in die Unifizierung mit Wildcards + * + * @param E - Vector von Paaren die unifiziert werden sollen + * @param fc_tto - Hilfsklasse mit FC + * @return Vector> - Ergebnispaare + * Entweder alle Elemente in solved Form [A =. type, B =. type2, ...] + * oder alle Elemente in der Form [A <. B, C <. D, ..., E in Typ A ...> werden keine ? extends-, ? super-Typen erzeugt + */ + //public static Vector> unifyWC (Vector E, FC_TTO fc_tto) + public static Vector> unify (Vector E, FC_TTO fc_tto) + { + //Schritt 1: Aufrufen der Regeln durch sub_unify. + Vector Eq = sub_unify(E,fc_tto); + /* Schritt 2: Rausfiltern der Typen die entweder beides Typvariablen sind oder nicht. + * Sobald ein Paar auftauch, bei denen kein Typ mehr eine Typvariable ist, kann dieses Paar + * nicht mehr unifiziert werden, deshalb abbruch.*/ + Vector Eq1 = new Vector(); + for(Pair p : Eq) + { + if(p.TA1 instanceof TypePlaceholder && p.TA2 instanceof TypePlaceholder) + { + Eq1.add(p); + } + else if(!(p.TA1 instanceof TypePlaceholder) && !(p.TA2 instanceof TypePlaceholder)) + { + //Diese Paare können nicht mehr Unifiziert werden. fail. + return new Vector>(); + } + } + //Schritt 3: Differenz bilden, in Eq2 landen alle Paare die nicht in Eq1 sind. + Vector Eq2 = new Vector(); + for(Pair p : Eq) + { + if(!Eq1.contains(p)) + Eq2.add(p); + } + /* Schritt 4, Teil 1: Einsammeln der Sets für das Kartesiche Produkt. + * Hier werden die Paare verglichen. Je nach Struktur können neue Paare erzeugt + * werden, aus denen dann das kartesische Produkt gebildet wird.*/ + Vector>> cartProduktSets = new Vector>>(); + for(Pair p : Eq2) + { + if(p.TA1 instanceof TypePlaceholder) + { + if(p.OperatorEqual()) + { + //Alle Paare die bereits durch sub_unify die richtige Struktur haben einfach durchleiten. + Vector> setofsetofpairs = new Vector>(); + Vector vTmp = new Vector(); + vTmp.add(p); + setofsetofpairs.add(vTmp); + cartProduktSets.add(setofsetofpairs); + } + else if(p.OperatorSmaller() && p.TA2 instanceof RefType) + { + RefType p_TA2 = (RefType)p.TA2; + //1. Menge + //Durch alle Paare p_fc laufen und schauen ob diese von der Struktur zu dem Paar p passen. + Vector fc_refl = copyVectorPair(fc_tto.getFC()); + fc_refl.add(new Pair(p_TA2.clone(), p_TA2.clone())); //Reflexivitaet muss beruecksichtigt werden; ergaenzt PL 07-07-28 + //Ist aber in FC nicht enthalten. + Vector> ergMenge1 = new Vector>(); //Ergebnismenge der 1. Menge; + for(Pair p_fc : fc_refl) + { + RefType tmp = ((RefType)p_fc.TA2).clone(); //Unifikation vorgezogen, da isRXSimilarRY nicht ausreicht PL 07-07-29 + CSubstitutionSet gtv2tv = tmp.GenericTypeVar2TypePlaceholder(); + Vector greater1elemente; + if (tmp.get_ParaList() == null) + { + greater1elemente = new Vector(); //Bei Konstanten liefert greater1 [] zurueck + greater1elemente.add(tmp); + } + else + { + greater1elemente = greater1(tmp, fc_tto); + } + Vector> unifyErgs = new Vector>(); + for (Type p_TA2_gr : greater1elemente) //Unify alleine reicht nicht, da p_TA2 Wildcards vorkommen koennen + { //muessen auch alle Typen deren Args Subtypen von p_TA2 sind betrachtet werden. + //Dies wird durch smaller1elemente bzw. smaller1 erledigt PL 07-07-29 + Pair pUnify = new Pair(p_TA2.clone(),p_TA2_gr,PairOperator.Equal); + Vector> unifyErgsElement = unifyWC(pUnify,fc_tto); + if (!unifyErgsElement.isEmpty()) { + unifyErgs.add(unifyErgsElement.firstElement()); + } + } +// Nach dem Unifizieren wird das Ergebnis überprüft, und evtl. durch die FC entstandene TPHs werden gelöscht. + if((p_fc.TA2 instanceof RefType && !unifyErgs.isEmpty()) + || p_fc.TA2.equals(p_TA2)) //Bedingung fuer Reflexifitaet BRAURHT MAN VERMUTLIRH NIRHT PL 07-08-05 + { + //Wenn die Unifizierung erfolgreich war durch jeden Ergebnisvektor der Unifizierung laufen. + for(Vector pVec : unifyErgs) + { +// Das Ergebnis in die linke Seite von p_fc einsetzen, und dort Smaller anwenden. + Hashtable ht = VectorPair2SubstHashtableVectorPair(pVec); + //PL 07-07-04 smallerArg wird auf die linke Seite von p_FC nach subst angewandt + RefType p_fc_TA1_new = (RefType)p_fc.TA1.clone(); + gtv2tv.applyThisSubstitutionSet(p_fc_TA1_new); //auf der linken Seite + //muessen die GTV durch die gleichen fresh tvs ersetzt werden, wie auf der rechten Seite. PL 07-07-29 + p_fc_TA1_new.GenericTypeVar2TypePlaceholder(); + //die uebrigen GTV muessen durch freshe tvs ersetzt werden. + SubstHashtable((RefType)p_fc_TA1_new,ht); + + //smallerArg ersetz durch folgende Zeilen. Durch Transistivitaet von fc kommen sonst + //doppelte Elemente rein + //Anfang + Vector smallers = new Vector(); + Vector smaller1elemente; + if (p_fc_TA1_new.get_ParaList() == null) + { + smaller1elemente = new Vector(); //Bei Konstanten liefert smaller1 [] zurueck + smaller1elemente.add(p_fc_TA1_new); + } + else + { + smaller1elemente = smaller0(p_fc_TA1_new, fc_tto); //Von Menge 2 kopiert und smaller1 durch smaller0 ersetzt, Luar 07-08-08 + } + + for(Type smele : smaller1elemente) + { + smallers.add(smele); + //smallers.add(new ExtendsWildcardType(smele.getOffset(), smele).clone()); //Auskommentiert luar 07-08-08 + } + //Ende + +// Ersatz fuer testUnifyErg PL 07-08-05 + //Anfang + for(int vec = 0; vec < pVec.size(); vec++) + { + Pair pTest = pVec.elementAt(vec); + if(!(pTest.TA1 instanceof TypePlaceholder) || !isTVinRefType((TypePlaceholder)pTest.TA1,p_TA2)) + { + pVec.remove(vec); + vec--; + } + } + //ENDE + + Vector> cartProduktErg = new Vector>(); + cartProduktErg.add(pVec); + + //Mit den kleineren Typen neue Paare bilden, linke Seite Klonen. + Vector smallerPairs = new Vector(); + for(Type sT : smallers) + { + smallerPairs.add(new Pair(p.TA1.clone(),sT,PairOperator.Equal)); + } + + //Hier noch das Kartesische Produkt aus den Greater und den Smaller Ergebnissen bilden. + Vector> ergs = new Vector>(); + for(Pair PsmP : smallerPairs) + { + Vector> dolly = copyVectorVectorPair(cartProduktErg); + if(dolly.isEmpty()) dolly.add(new Vector()); + for(Vector vecp : dolly) + { + vecp.add(PsmP.clone()); + } + ergs.addAll(dolly); + } + if(!ergs.isEmpty()) + for (Vector ergele : ergs) + if (!ergMenge1.contains(ergele)) //ABFRAGE BRAURHT MAN VERMUTLIRH NIRHT, DA DURRH smaller1 keine doppelten Elemente reinkommen koennen + ergMenge1.add(ergele); + } + } + } + cartProduktSets.add(ergMenge1); + } + else if(p.OperatorSmallerExtends()) + { + if(p.TA2 instanceof ExtendsWildcardType && ((ExtendsWildcardType)p.TA2).get_ExtendsType() instanceof RefType) + { + RefType p_TA2 = (RefType)((ExtendsWildcardType)p.TA2).get_ExtendsType(); + //2. Menge + //Durch alle Paare p_fc laufen und schauen ob diese von der Struktur zu dem Paar p passen. + Vector fc_refl = copyVectorPair(fc_tto.getFC()); + fc_refl.add(new Pair(p_TA2.clone(), p_TA2.clone())); //Reflexivitaet muss beruecksichtigt werden; ergaenzt PL 07-07-28 + //Ist aber in FC nicht enthalten. + Vector> ergMenge2 = new Vector>(); //Ergebnismenge der 2. Menge; ergaenzt PL 07-07-28 + for(Pair p_fc : fc_refl) + { + RefType tmp = ((RefType)p_fc.TA2).clone(); //Unifikation vorgezogen, da isRXSimilarRY nicht ausreicht PL 07-07-29 + CSubstitutionSet gtv2tv = tmp.GenericTypeVar2TypePlaceholder(); + Vector greater1elemente; + if (tmp.get_ParaList() == null) + { + greater1elemente = new Vector(); //Bei Konstanten liefert greater1 [] zurueck + greater1elemente.add(tmp); + } + else + { + greater1elemente = greater1(tmp, fc_tto); + } + Vector> unifyErgs = new Vector>(); + for (Type p_TA2_gr : greater1elemente) //Unify alleine reicht nicht, da p_TA2 Wildcards vorkommen koennen + { //muessen auch alle Typen deren Args Subtypen von p_TA2 sind betrachtet werden. + //Dies wird durch smaller1elemente bzw. smaller1 erledigt PL 07-07-29 + Pair pUnify = new Pair(p_TA2.clone(),p_TA2_gr,PairOperator.Equal); + Vector> unifyErgsElement = unifyWC(pUnify,fc_tto); + if (!unifyErgsElement.isEmpty()) { + unifyErgs.add(unifyErgsElement.firstElement()); + } + } + //Nach dem Unifizieren wird das Ergebnis überprüft, und evtl. durch die FC entstandene TPHs werden gelöscht. + if((p_fc.TA2 instanceof RefType && !unifyErgs.isEmpty()) + || p_fc.TA2.equals(p_TA2)) //Bedingung fuer Reflexifitaet BRAURHT MAN VERMUTLIRH NIRHT PL 07-08-05 + { + //Wenn die Unifizierung erfolgreich war durch jeden Ergebnisvektor der Unifizierung laufen. + for(Vector pVec : unifyErgs) //unifyErgs enthaelt nur einen Unifier STIMMT NIRHT MEHR!!! + { + //Das Ergebnis in die linke Seite von p_fc einsetzen, und dort Smaller anwenden. + Hashtable ht = VectorPair2SubstHashtableVectorPair(pVec); + //PL 07-07-04 smallerArg wird auf die linke Seite von p_FC nach subst angewandt + RefType p_fc_TA1_new = (RefType)p_fc.TA1.clone(); + gtv2tv.applyThisSubstitutionSet(p_fc_TA1_new); //auf der linken Seite + //muessen die GTV durch die gleichen fresh tvs ersetzt werden, wie auf der rechten Seite. PL 07-07-29 + p_fc_TA1_new.GenericTypeVar2TypePlaceholder(); + //die uebrigen GTV muessen durch freshe tvs ersetzt werden. + SubstHashtable((RefType)p_fc_TA1_new,ht); + + //smallerArg ersetz durch folgende Zeilen. Durch Transistivitaet von fc kommen sonst + //doppelte Elemente rein + //Anfang + Vector smallers = new Vector(); + Vector smaller1elemente; + if (p_fc_TA1_new.get_ParaList() == null) + { + smaller1elemente = new Vector(); //Bei Konstanten liefert smaller1 [] zurueck + smaller1elemente.add(p_fc_TA1_new); + } + else + { + smaller1elemente = smaller1(p_fc_TA1_new, fc_tto); + } + + for(Type smele : smaller1elemente) + { + smallers.add(smele); + smallers.add(new ExtendsWildcardType(smele.getOffset(), smele).clone()); + } + //Ende + + //Ersatz fuer testUnifyErg PL 07-08-05 + //Anfang + for(int vec = 0; vec < pVec.size(); vec++) + { + Pair pTest = pVec.elementAt(vec); + if(!(pTest.TA1 instanceof TypePlaceholder) || !isTVinRefType((TypePlaceholder)pTest.TA1,p_TA2)) + { + pVec.remove(vec); + vec--; + } + } + //ENDE + + Vector> cartProduktErg = new Vector>(); + cartProduktErg.add(pVec); + + //Mit den kleineren Typen neue Paare bilden, linke Seite Klonen. + Vector smallerPairs = new Vector(); + for(Type sT : smallers) + { + smallerPairs.add(new Pair(p.TA1.clone(),sT,PairOperator.Equal)); + } + + //Hier noch das Kartesische Produkt aus den Greater und den Smaller Ergebnissen bilden. + Vector> ergs = new Vector>(); + for(Pair PsmP : smallerPairs) + { + Vector> dolly = copyVectorVectorPair(cartProduktErg); + if(dolly.isEmpty()) dolly.add(new Vector()); + for(Vector vecp : dolly) + { + vecp.add(PsmP.clone()); + } + ergs.addAll(dolly); + } + if(!ergs.isEmpty()) + for (Vector ergele : ergs) + if (!ergMenge2.contains(ergele)) //ABFRAGE BRAURHT MAN VERMUTLIRH NIRHT, DA DURRH smaller1 keine doppelten Elemente reinkommen koennen + ergMenge2.add(ergele); + } + } + } + cartProduktSets.add(ergMenge2);// ergaenzt PL 07-07-28 + } + else if(p.TA2 instanceof SuperWildcardType) + { + //3. Menge + //Einfach smallerArg auf die Wildcard aufrufen, mit den Ergebnissen neue Paare bilden. + Vector smErg = smallerArg(p.TA2,fc_tto); + cartProduktSets.add(generateSetOfSetOfPair(p.TA1,smErg)); + } + else + { + //4. Menge + //Den Operator des Paares auf = umbiegen und das Paar in einen Vector verpacken. + Vector> setofsetofpairs = new Vector>(); + Vector vTmp = new Vector(); + p.SetOperator(PairOperator.Equal); + vTmp.add(p); + setofsetofpairs.add(vTmp); + cartProduktSets.add(setofsetofpairs); + } + } + } + else if (p.TA2 instanceof TypePlaceholder) + { + if(p.OperatorSmaller()) + { + //5. Menge + //Greater auf den Typen bilden, und mit den Ergebnissen neue Paare bilden. + Vector grErg = greater(p.TA1,fc_tto); + cartProduktSets.add(generateSetOfSetOfPair(p.TA2,grErg)); + } + else if(p.OperatorSmallerExtends()) + { + if(p.TA1 instanceof ExtendsWildcardType) + { + //6. Menge + //GreaterArg auf die Wildcard aufrufen, und mit den Ergebnissen neue Paare bilden. + Vector grErg = greaterArg(p.TA1,fc_tto); + cartProduktSets.add(generateSetOfSetOfPair(p.TA2,grErg)); + } + else if(p.TA1 instanceof SuperWildcardType && ((SuperWildcardType)p.TA1).get_SuperType() instanceof RefType) + { + RefType p_TA1 = (RefType)((SuperWildcardType)p.TA1).get_SuperType(); + //7. Menge + //Durch alle Paare p_fc laufen und schauen ob diese von der Struktur zu dem Paar p passen. + Vector fc_refl = copyVectorPair(fc_tto.getFC()); + fc_refl.add(new Pair(p_TA1.clone(), p_TA1.clone())); //Reflexivitaet muss beruecksichtigt werden; ergaenzt PL 07-07-28 + //Ist aber in FC nicht enthalten. + Vector> ergMenge1 = new Vector>(); //Ergebnismenge der 1. Menge; + for(Pair p_fc : fc_refl) + { + RefType tmp = ((RefType)p_fc.TA2).clone(); //Unifikation vorgezogen, da isRXSimilarRY nicht ausreicht PL 07-07-29 + CSubstitutionSet gtv2tv = tmp.GenericTypeVar2TypePlaceholder(); + Vector greater1elemente; + if (tmp.get_ParaList() == null) + { + greater1elemente = new Vector(); //Bei Konstanten liefert greater1 [] zurueck + greater1elemente.add(tmp); + } + else + { + greater1elemente = greater1(tmp, fc_tto); + } + Vector> unifyErgs = new Vector>(); + for (Type p_TA2_gr : greater1elemente) //Unify alleine reicht nicht, da p_TA2 Wildcards vorkommen koennen + { //muessen auch alle Typen deren Args Subtypen von p_TA2 sind betrachtet werden. + //Dies wird durch smaller1elemente bzw. smaller1 erledigt PL 07-07-29 + Pair pUnify = new Pair(p_TA1.clone(),p_TA2_gr,PairOperator.Equal); + Vector> unifyErgsElement = unifyWC(pUnify,fc_tto); + if (!unifyErgsElement.isEmpty()) { + unifyErgs.add(unifyErgsElement.firstElement()); + } + } +// Nach dem Unifizieren wird das Ergebnis überprüft, und evtl. durch die FC entstandene TPHs werden gelöscht. + if((p_fc.TA2 instanceof RefType && !unifyErgs.isEmpty()) + || p_fc.TA2.equals(p_TA1)) //Bedingung fuer Reflexifitaet BRAURHT MAN VERMUTLIRH NIRHT PL 07-08-05 + { + //Wenn die Unifizierung erfolgreich war durch jeden Ergebnisvektor der Unifizierung laufen. + for(Vector pVec : unifyErgs) + { +// Das Ergebnis in die linke Seite von p_fc einsetzen, und dort Smaller anwenden. + Hashtable ht = VectorPair2SubstHashtableVectorPair(pVec); + //PL 07-07-04 smallerArg wird auf die linke Seite von p_FC nach subst angewandt + RefType p_fc_TA1_new = (RefType)p_fc.TA1.clone(); + gtv2tv.applyThisSubstitutionSet(p_fc_TA1_new); //auf der linken Seite + //muessen die GTV durch die gleichen fresh tvs ersetzt werden, wie auf der rechten Seite. PL 07-07-29 + p_fc_TA1_new.GenericTypeVar2TypePlaceholder(); + //die uebrigen GTV muessen durch freshe tvs ersetzt werden. + SubstHashtable((RefType)p_fc_TA1_new,ht); + + //smallerArg ersetz durch folgende Zeilen. Durch Transistivitaet von fc kommen sonst + //doppelte Elemente rein + //Anfang + Vector smallers = new Vector(); + Vector smaller1elemente; + if (p_fc_TA1_new.get_ParaList() == null) + { + smaller1elemente = new Vector(); //Bei Konstanten liefert smaller1 [] zurueck + smaller1elemente.add(p_fc_TA1_new); + } + else + { + smaller1elemente = smaller0(p_fc_TA1_new, fc_tto); //Von Menge 2 kopiert und smaller1 durch smaller0 ersetzt, Luar 07-08-08 + } + + for(Type smele : smaller1elemente) + { + smallers.add(smele); + //smallers.add(new ExtendsWildcardType(smele.getOffset(), smele).clone()); //Auskommentiert luar 07-08-08 + } + //Ende + +// Ersatz fuer testUnifyErg PL 07-08-05 + //Anfang + for(int vec = 0; vec < pVec.size(); vec++) + { + Pair pTest = pVec.elementAt(vec); + if(!(pTest.TA1 instanceof TypePlaceholder) || !isTVinRefType((TypePlaceholder)pTest.TA1,p_TA1)) + { + pVec.remove(vec); + vec--; + } + } + //ENDE + + Vector> cartProduktErg = new Vector>(); + cartProduktErg.add(pVec); + + //Mit den kleineren Typen neue Paare bilden, linke Seite Klonen. + Vector smallerPairs = new Vector(); + for(Type sT : smallers) + { + smallerPairs.add(new Pair(p.TA2.clone(),new SuperWildcardType(sT.getOffset(),sT),PairOperator.Equal)); + } + + //Hier noch das Kartesische Produkt aus den Greater und den Smaller Ergebnissen bilden. + Vector> ergs = new Vector>(); + for(Pair PsmP : smallerPairs) + { + Vector> dolly = copyVectorVectorPair(cartProduktErg); + if(dolly.isEmpty()) dolly.add(new Vector()); + for(Vector vecp : dolly) + { + vecp.add(PsmP.clone()); + } + ergs.addAll(dolly); + } + if(!ergs.isEmpty()) + for (Vector ergele : ergs) + if (!ergMenge1.contains(ergele)) //ABFRAGE BRAURHT MAN VERMUTLIRH NIRHT, DA DURRH smaller1 keine doppelten Elemente reinkommen koennen + ergMenge1.add(ergele); + } + } + } + cartProduktSets.add(ergMenge1); + } + else + { + //8. Menge + //GreaterArg auf die Linke Seite Aufrufen, mit den Ergebnissen neue Paare erzeugen + Vector grErg = greaterArg(p.TA1,fc_tto); + cartProduktSets.add(generateSetOfSetOfPair(p.TA2,grErg)); + } + } + } + } + //Schritt 4, Teil 2: Kartesisches Produkt bilden. + //Hier wird aus den in Schritt 4, Teil 1 erzeugten Vektoren das Kartesische Produkt gebilden. + Vector helpvp; + Vector> bigCartProductErg = new Vector>(); + bigCartProductErg.addElement(copyVectorPair(Eq1)); + + for (Vector> vecvecpair : cartProduktSets) + { + Vector> bigCartProductErgOld = bigCartProductErg; + bigCartProductErg = new Vector>(); + for(Vector vecpair1 : vecvecpair) + { + for(Vector vecpair2 : bigCartProductErgOld) + { + helpvp = copyVectorPair(vecpair2); + helpvp.addAll(copyVectorPair(vecpair1)); + bigCartProductErg.addElement(helpvp); + } + } + } + + //Schritt 5: Einsetzen der Subst Regel + //Hier werden die TPHs substituiert, und dann nach geänderten und nicht geänderten Sets sortiert. + Vector> changedSets = new Vector>(); + Vector> notChangedSets = new Vector>(); + for(Vector vecpair : bigCartProductErg) + { + boolean change = false; //eingefuegt PL 13-05-22 + Pair substPair = null; + do + { + substPair = null; + //Einsammeln der Paare von der Signatur a = Typ + for(Pair p : vecpair) + { + if(p.TA1 instanceof TypePlaceholder && p.OperatorEqual() && !p.bSubst) + { + substPair = p; + p.bSubst = true; + break; + } + } + if(substPair != null) + { + //Einsetzen der Typen in die anderen Paare + //boolean change = false; auskommentiert PL 13-05-22 + for(int i = 0; i< vecpair.size();i++) + { + Pair p = vecpair.elementAt(i); + if(!p.instanzeEquals(substPair)) + { + change |= Subst(p,1,(TypePlaceholder)substPair.TA1,substPair.TA2,true); + change |= Subst(p,2,(TypePlaceholder)substPair.TA1,substPair.TA2,true); + } + } + //Substitution abgeschlossen. Sortieren. + //if(change) auskommentiert PL 13-05-22, da erst nach komplett erfolgter Substitution sortiert wird. + //{ + //changedSets.add(vecpair); + //break; + //} + } + } + while(substPair != null); + + if(change) // NEU PL 13-05-22, da erst nach komplett erfolgter Substitution sortiert wird. + { + changedSets.add(vecpair); + } + else + //if(substPair == null) + { + notChangedSets.add(vecpair); + } + } + + //Eq2Set ist das eigentliche Ergebnis, dass zurückgegeben wird. + Vector> Eq2Set = new Vector>(); + + //Schritt 6A: Beginnen mit Schritt 1 bei den geänderten. + for(Vector vecpair : changedSets) + { + Vector> unifyErgs = unify(vecpair,fc_tto); + //Die Ergebnissvektoren sind schon im Schritt 7 von dem Rekursiven Aufruf geprüft worden. Sie können direkt eingefügt werden. + Eq2Set.addAll(unifyErgs); + } + + //Schritt 6B Einfügen der nicht geänderten. + //Schritt 7: Aussortieren der falschen Sets + /* + * Durch die Rekursion in Schritt 6A sind die Ergebnisse, welche in 6A dazukommen auf jeden Fall korrekt. + * Es müssen nur die Ergebnisse aus 6B geprüft werden. + */ + for(Vector vecpair : notChangedSets) + { + //Überprüfen ob Vector in SolvedForm ist. + if(hasSolvedForm(vecpair)) //PL 13-05-22 hasSolvedForm angepasst + { + //Überprüfung auf FreshTypeVars in den Typen + boolean foundFresh = false; + for(Pair p : vecpair) + { + //EINSRHUB ANFANG UM PAARE A + * In diesm fall wird b = Number aus dem Vector entfernt. + * + * Durch das Entfernen entstehen evtl. Identische Vectoren, diese werden auch gelöscht. + * + * @param unifyErgs - Ergebnisse des Unify, die geprüft werden sollen. + * @param test - RefType gegen den geprüft werden soll. + */ + private static void testUnifyErg(Vector> unifyErgs, RefType test) + { + for(Vector pVec : unifyErgs) + for(int vec = 0; vec < pVec.size(); vec++) + { + Pair pTest = pVec.elementAt(vec); + if(!(pTest.TA1 instanceof TypePlaceholder) || !isTVinRefType((TypePlaceholder)pTest.TA1,test)) + { + pVec.remove(vec); + vec--; + } + } + //Gleiche Vectoren löschen + for(int i = 0; i < unifyErgs.size(); i++) + { + Vector p1 = unifyErgs.elementAt(i); + for(int j = i + 1; j < unifyErgs.size(); j++) + { + Vector p2 = unifyErgs.elementAt(j); + if(p1.size() == p2.size()) + { + boolean equal = true; + for(Pair p1P : p1) + { + boolean found = false; + for(Pair p2P : p2) + found |= p2P.equals(p1P); + + equal &= found; + } + if(equal) + { + unifyErgs.remove(j); + j--; + } + } + } + } + } + + /** + * Diese Methode generiert einen Vector> wobei immer der übergebene TA1 vorne steht, und jeder Typ aus otherPairTypes hinten. + * Beispiel: otherPairTypes = [Integer, Number, Vector], TA1 = TPH a. + * return: [[TPH a = Integer],[TPH a = Number],[TPH a = Vector]] + * + * @param TA1 - Der Typ der immer vorne steht + * @param otherPairTypes - Die anderen Typen + * @return - Ein Vector> der alle Paare enthält. + */ + private static Vector> generateSetOfSetOfPair(Type TA1, Vector otherPairTypes) + { + Vector> setofsetofpairs = new Vector>(); + for(Type t : otherPairTypes) + { + Vector vTmp = new Vector(); + vTmp.add(new Pair(TA1.clone(),t,PairOperator.Equal)); + setofsetofpairs.add(vTmp); + } + return setofsetofpairs; + } + + // ino.method.unify_Mub.28061.definition + public static MUB unify_Mub(Type ty1, Type ty2, FC_TTO fc_tto) + throws CTypeReconstructionException + // ino.end + // ino.method.unify_Mub.28061.body + { + Vector FC = fc_tto.getFC(); + if (ty1 instanceof TypePlaceholder) { + Vector Mub = new Vector(); + Mub.addElement(ty2); + Vector sigma = new Vector(); + sigma.addElement(new Pair(ty1, ty2)); + return new MUB(Mub, sigma); + } + else if (ty2 instanceof TypePlaceholder) { + Vector Mub = new Vector(); + Mub.addElement(ty1); + Vector sigma = new Vector(); + sigma.addElement(new Pair(ty2, ty1)); + return new MUB(Mub, sigma); + } + else { + Vector ub = new Vector(); //alle oberen Schranken + Vector gr1 = new Vector(); //alle Elemente groesser ty1 + boolean refl_flag1=true; + + //alle groesseren Elemente in FC + for (int i=0; i < FC.size(); i++) { + Pair P; + + // Reflexivitaet, wenn es kein groesseres Element, aber + // kleinere Elemente gibt. + P = isInFC((RefType)(FC.elementAt(i).TA1), (RefType)ty1, FC); + if (P != null) { + gr1.addElement(((RefType)P.TA2).clone()); //Reflexivitaet + refl_flag1 = false; + } + + //echt groessere Elemente aus FC suchen + P = isInFC((RefType)ty1, (RefType)(FC.elementAt(i).TA2), FC); + if (P != null) { + gr1.addElement(((RefType)P.TA2).clone()); + if (refl_flag1) { + gr1.addElement(((RefType)P.TA1).clone()); //Reflexivitaet + } + } + } + + Vector gr2 = new Vector(); + boolean refl_flag2=true; + + //alle groesseren Elemente in FC + for (int i=0; i < FC.size(); i++) { + Pair P; + + // Reflexivitaet, wenn es kein groesseres Element, aber + // kleinere Elemente gibt. + P = isInFC((RefType)(FC.elementAt(i).TA1), (RefType)ty2, FC); + if (P != null) { + gr2.addElement(((RefType)P.TA2).clone()); //Reflexivitaet + } + + P = isInFC((RefType)ty2, (RefType)(FC.elementAt(i).TA2), FC); + if (P != null) { + gr2.addElement(((RefType)P.TA2).clone()); + if (refl_flag2) { + gr2.addElement(((RefType)P.TA1).clone()); //Reflexivitaet + refl_flag1 = false; + } + } + } + if (gr1.size()==0) gr1.addElement((RefType)ty1.clone()); + if (gr2.size()==0) gr2.addElement((RefType)ty2.clone()); + //MIT Usecase_MUBTest4.jav testen und gr1 und gr2 ueberpruefen + + for (int i = 0; i < gr1.size(); i++) { //gemeinsame obere Schranken suchen + for (int j = 0; j < gr2.size(); j++){ + if (gr1.elementAt(i).is_Equiv(gr2.elementAt(j), new Hashtable())) { + ub.addElement(gr1.elementAt(i)); + break; + } + } + } + + //Vector wird geclont, Elemente nicht + //Vector Mub = (Vector)ub.clone(); + + //Elemente die nicht kleinste obere Schranken sind, werden gel�scht + //FUNKTIONIERT NICHT. SIEHE iftest.java PL 08-08-13 + for (int i = 0; i < ub.size(); i++) { + for (int j = 0; j < ub.size(); j++) { + //PL 05-03-22 alle aequivalenten Elemente sollten auch entfernt werden. + if (i != j && + (isInFC(ub.elementAt(j), ub.elementAt(i), FC) != null + || ub.elementAt(j).equals(ub.elementAt(i)))) { + ub.remove(ub.elementAt(i)); + + //durch remove wuerde sonst ein Element + //nicht geprueft + if (j > i) j--; + } + } + } + + //es gibt eine kleinste obere Schranke + if (ub.size() > 0) { + RefType max = ub.elementAt(0); + + //liefert die Sustitution von Genvars in Typeplaceholders, um + //sub dann auf die anderen Elemente von Mub anwenden zu koennen + CSubstitutionSet sub = max.GenericTypeVar2TypePlaceholder(); + //PL 06-03-22 in allen Elementen von Mub muessten die gleichen Typeplaceholders stehen + Vector sigma = unify(ty1, max, fc_tto).elementAt(0); + Vector sigma2 = unify(ty2, max, fc_tto).elementAt(0); + sigma.addAll(sigma2); + Vector> unifiers = unify(sigma, fc_tto); + + //es gibt keinen Unifier + if (unifiers.size()==0) { + throw new CTypeReconstructionException("Es gibt keinen Unifier",null); + } + Iterator MubsIt = ub.iterator(); + while(MubsIt.hasNext()){ + sub.applyThisSubstitutionSet(MubsIt.next()); + } + return new MUB(ub, unifiers.elementAt(0)); + } + //es gibt keine kleinste obere Schranke + else { + throw new CTypeReconstructionException("Es existiert kein MUB",null); + } + + } + } + // ino.end + +// ino.method.match.28064.definition +public static Hashtable match(RefType FCtype, RefType tomatch, Hashtable ht) +throws MatchException +// ino.end +// ino.method.match.28064.body +{ + //PL 05-01-22 + //gibt eine Substitution zur�ck, die den Variablen aus FCtype + //die Typterme aus tomatch zu ordnet. Es wird davon ausgegangen, dass + //FCtype gegen tomatch gematcht werden kann. + if (FCtype.getTypeName().equals(tomatch.getTypeName())) { + inferencelog.debug("match: " + FCtype.getTypeName()); + if (FCtype.get_ParaList() != null) { + for(int i=0; i < FCtype.get_ParaList().size(); i++) { + if (FCtype.get_ParaList().elementAt(i) instanceof GenericTypeVar) { + inferencelog.debug("PUT"); + ht.put(((GenericTypeVar)FCtype.get_ParaList().elementAt(i)).getName(), + tomatch.get_ParaList().elementAt(i)); + } + else if ((FCtype.get_ParaList().elementAt(i) instanceof RefType) && + (tomatch.get_ParaList().elementAt(i) instanceof TypePlaceholder)) { + throw new MatchException("vorne Typterm hinten Typvariable "); + } + else if((FCtype.get_ParaList().elementAt(i) instanceof RefType) && + (tomatch.get_ParaList().elementAt(i) instanceof IMatchable) && + ((IMatchable)tomatch.get_ParaList().elementAt(i)).getMatchType() instanceof RefType) + { + match((RefType)FCtype.get_ParaList().elementAt(i), (RefType)((IMatchable)tomatch.get_ParaList().elementAt(i)).getMatchType(), ht); + } + } + } + return ht; + } + else { + throw new MatchException("different Name 1. " + FCtype.getTypeName()+ " 2. " + tomatch.getTypeName()); + } + } +// ino.end + + /* Einstieg in die Unifizierung mit den 4 Regeln. */ + public static Vector sub_unify(Vector E, FC_TTO fc_tto) + { + return sub_unify(E,fc_tto,true); + } + + // ino.method.sub_unify.28067.definition + public static Vector sub_unify( Vector E, FC_TTO fc_tto, boolean useSubst ) + // ino.end + // ino.method.sub_unify.28067.body + { + //PL 05-01-21 umbenannt in sub_unify + //Luar boolean useSubst hinzugefügt, um bei bedarf zu Steuern ob Subst Regel angewendet wird oder nicht. + // otth: Unifikation - Versuch 1 :-) + + //Vector FC = fc_tto.getFC(); + Vector TTO = fc_tto.getTTO(); + Vector H = new Vector(); // Hilfsmenge + boolean bRegel = true; // gibt an, ob eine Regel gepasst hat + + int n = 0; + + while( bRegel ) + { + n++; + + // zum Debuggen + printMenge( "E", E, 6 ); + bRegel = false; + for( int i = 0; i < E.size(); i++ ) + { + Pair P = E.elementAt(i); + inferencelog.debug(""); + inferencelog.debug(""); + inferencelog.debug("Ausgewaehltes Paar = " + P.toString() + ""); + inferencelog.debug( "--------------------------------------------------"); + + // Bei allen Erase erfolgt keine Kopie nach H, dadurch wird das Pair gelöscht. + //ERASE3 + if( P.isEqual() && P.OperatorEqual() ) + { + inferencelog.debug(" ================================"); + inferencelog.debug(" ERASE3"); + inferencelog.debug(" ================================"); + bRegel = true; + continue; + } + // ERASE1 luar 15-04-07 + if(P.OperatorSmaller()) + { + if((P.TA1 instanceof RefType) == false || ((RefType)P.TA1).get_ParaList() == null) + { + if((P.TA2 instanceof RefType) == false || ((RefType)P.TA2).get_ParaList() == null) + { + Vector greaters = greater(P.TA1,fc_tto); + + //System.out.println(P.TA2.toString()); + // "P.TA2.toString() != null" angefügt von Andreas Stadelmeier a10023 + if(P.TA2.toString() != null && greaters.contains(P.TA2)) + { + inferencelog.debug(" ================================"); + inferencelog.debug(" ERASE1"); + inferencelog.debug(" ================================"); + bRegel = true; + continue; + } + } + } + } + //ERASE2 luar 15-04-07 + if(P.OperatorSmallerExtends()) + { + Vector greaterArgs = greaterArg(P.TA1,fc_tto); + if(greaterArgs.contains(P.TA2)) + { + inferencelog.debug(" ================================"); + inferencelog.debug(" ERASE2"); + inferencelog.debug(" ================================"); + bRegel = true; + continue; + } + } + + //ReduceUp luar 10-04-2007 + if(P.TA1 instanceof RefType && P.TA2 instanceof SuperWildcardType && P.OperatorSmaller()) + { + inferencelog.debug(" REDUCEUP"); + SuperWildcardType TA2 = ((SuperWildcardType)P.TA2); + + H.add(new Pair(P.TA1,TA2.get_SuperType())); + bRegel = true; + continue; + } + //ReduceLow luar 10-04-2007 + if(P.TA1 instanceof ExtendsWildcardType && P.TA2 instanceof RefType && P.OperatorSmaller()) + { + inferencelog.debug(" REDUCELOW"); + ExtendsWildcardType TA1 = ((ExtendsWildcardType)P.TA1); + + H.add(new Pair(TA1.get_ExtendsType(),P.TA2)); + bRegel = true; + continue; + } + //ReduceUpLow luar 10-04-2007 + if(P.TA1 instanceof ExtendsWildcardType && P.TA2 instanceof SuperWildcardType && P.OperatorSmaller()) + { + inferencelog.debug(" REDUCEUPLOW"); + ExtendsWildcardType TA1 = ((ExtendsWildcardType)P.TA1); + SuperWildcardType TA2 = ((SuperWildcardType)P.TA2); + + H.add(new Pair(TA1.get_ExtendsType(),TA2.get_SuperType())); + bRegel = true; + continue; + } + + //ReduceExt luar 19-04-2007 + if((P.TA1 instanceof RefType + || (P.TA1 instanceof ExtendsWildcardType && ((ExtendsWildcardType)P.TA1).get_ExtendsType() instanceof RefType)) + && P.TA2 instanceof ExtendsWildcardType && P.OperatorSmallerExtends()) + { + inferencelog.debug(" REDUCEEXT"); + ExtendsWildcardType ExT = (ExtendsWildcardType)P.TA2; + RefType TA1; + if(P.TA1 instanceof RefType) + TA1 = (RefType)P.TA1; + else + TA1 = (RefType)((ExtendsWildcardType)P.TA1).get_ExtendsType(); + + if(ExT.get_ExtendsType() instanceof RefType) + { + RefType TA2 = (RefType)ExT.get_ExtendsType(); + if(isRealSubClass(TA1.getTypeName(),TA2.getTypeName(),fc_tto) || TA1.getTypeName().equals(TA2.getTypeName())) + { + if(TA1.get_ParaList() != null && TA2.get_ParaList() != null) + { + if(TA1.get_ParaList().size() == TA2.get_ParaList().size()) + { + try + { + reduceExt(H,TA1,TA2,TTO); + bRegel = true; + continue; + } + catch( SCException Ex ) + { + inferencelog.debug("---- Unifikation nicht m�glich: Permutation fehlgeschlagen!"); + break; + } + } + else + { + inferencelog.info("---- Unifikation nicht m�glich: Anzahl der Parameter verschieden!"); + break; + } + } + } + } + + inferencelog.debug(" ADAPTEXT"); + if(ExT.get_ExtendsType() instanceof RefType) + { + RefType TA2 = (RefType)ExT.get_ExtendsType(); + Pair PFC = isInFClinks( TA1, TA2, fc_tto.getFC() ); + if(PFC != null) + { + adaptExt(H,PFC,TA1,TA2,fc_tto); + bRegel = true; + continue; + } + } + } + + //ReduceSup luar 19-04-2007 + if((P.TA1 instanceof RefType + || (P.TA1 instanceof SuperWildcardType && ((SuperWildcardType)P.TA1).get_SuperType() instanceof RefType)) + && P.TA2 instanceof SuperWildcardType && P.OperatorSmallerExtends()) + { + inferencelog.debug(" REDUCESUP"); + SuperWildcardType SuT = (SuperWildcardType)P.TA2; + RefType TA1; + if(P.TA1 instanceof RefType) + TA1 = (RefType)P.TA1; + else + TA1 = (RefType)((SuperWildcardType)P.TA1).get_SuperType(); + + if(SuT.get_SuperType() instanceof RefType) + { + RefType TA2 = (RefType)SuT.get_SuperType(); + if(isRealSubClass(TA2.getTypeName(),TA1.getTypeName(),fc_tto) || TA1.getTypeName().equals(TA2.getTypeName())) + { + if(TA1.get_ParaList() != null && TA2.get_ParaList() != null) + { + if(TA1.get_ParaList().size() == TA2.get_ParaList().size()) + { + try + { + reduceSup(H,TA1,TA2,TTO); + bRegel = true; + continue; + } + catch( SCException Ex ) + { + inferencelog.debug("---- Unifikation nicht m�glich: Permutation fehlgeschlagen!"); + break; + } + } + else + { + inferencelog.info("---- Unifikation nicht m�glich: Anzahl der Parameter verschieden!"); + break; + } + } + } + } + + inferencelog.debug(" ADAPTSUP"); + if(SuT.get_SuperType() instanceof RefType) + { + RefType TA2 = (RefType)SuT.get_SuperType(); + Pair PFC = isInFClinks( TA2, TA1, fc_tto.getFC() ); + if(PFC != null) + { + adaptSup(H,PFC,TA2,TA1,fc_tto); + bRegel = true; + continue; + } + } + } + //REDUCE2 + if(P.OperatorEqual()) + { + RefType TA1 = null; + RefType TA2 = null; + //Hier werden die RefTypes gefüllt. + if(P.TA1 instanceof RefType && P.TA2 instanceof RefType) + { + TA1 = (RefType)P.TA1; + TA2 = (RefType)P.TA2; + } + else if(P.TA1 instanceof ExtendsWildcardType && P.TA2 instanceof ExtendsWildcardType) + { + ExtendsWildcardType exT1 = (ExtendsWildcardType)P.TA1; + ExtendsWildcardType exT2 = (ExtendsWildcardType)P.TA2; + if(exT1.get_ExtendsType() instanceof RefType && exT2.get_ExtendsType() instanceof RefType) + { + TA1 = (RefType)exT1.get_ExtendsType(); + TA2 = (RefType)exT2.get_ExtendsType(); + } + } + else if(P.TA1 instanceof SuperWildcardType && P.TA2 instanceof SuperWildcardType) + { + SuperWildcardType suT1 = (SuperWildcardType)P.TA1; + SuperWildcardType suT2 = (SuperWildcardType)P.TA2; + if(suT1.get_SuperType() instanceof RefType && suT2.get_SuperType() instanceof RefType) + { + TA1 = (RefType)suT1.get_SuperType(); + TA2 = (RefType)suT2.get_SuperType(); + } + } + + if(TA1 != null && TA2 != null && TA1.getTypeName().equals(TA2.getTypeName())) + { + inferencelog.debug(" REDUCE2"); + // REDUCE + if(TA1.get_ParaList() != null && TA2.get_ParaList() != null && TA1.get_ParaList().size() == TA2.get_ParaList().size()) + { + try + { + // REDUCE-Regel anwendbar + reduce2(H,TA1,TA2,TTO); + bRegel = true; + continue; + } + catch( SCException Ex ) + { + inferencelog.error("---- Unifikation nicht m�glich: Permutation fehlgeschlagen!"); + break; + } + } + } + } // end if: Reduce2 + inferencelog.debug("NACH REDUCE2"); + + // REDUCE1, REDUCEEQ, ADAPT + //HIER MUSS BEI PAARBILDUNG NOCH bEqual AUF true GESETZT WERDEN + //CONTRAVARIANZ-PROBLEM OO-PROGRAMMIERUNG erlegigt PL 05-01-22 + //BEISPIEL pl1.1.1.2.java + if (P.TA1 instanceof RefType && P.TA2 instanceof RefType) + { + inferencelog.debug(" REDUCE1"); + RefType TA1 = ((RefType)P.TA1); + RefType TA2 = ((RefType)P.TA2); + + // REDUCE1 + if((isRealSubClass(TA1.getTypeName(), TA2.getTypeName(), fc_tto) || TA1.getTypeName().equals(TA2.getTypeName())) + && P.OperatorSmaller()) + { + // REDUCE + if(TA1.get_ParaList() != null && TA2.get_ParaList() != null && TA1.get_ParaList().size() == TA2.get_ParaList().size()) + { + try + { + reduce1(H,TA1,TA2,TTO); + bRegel = true; + continue; + } + catch( SCException Ex ) + { + inferencelog.debug("---- Unifikation nicht m�glich: Permutation fehlgeschlagen!"); + break; + } + } + } // end if: Reduce1 + inferencelog.debug("NACH REDUCE1"); + // REDUCEEQ + if(TA1.getTypeName().equals(TA2.getTypeName()) && P.OperatorSmallerExtends()) + { + inferencelog.debug("REDUCEEQ"); + if(TA1.get_ParaList() != null && TA2.get_ParaList() != null && TA1.get_ParaList().size() == TA2.get_ParaList().size()) + { + try + { + reduceEq(H,TA1,TA2,TTO); + bRegel = true; + continue; + } + catch( SCException Ex ) + { + inferencelog.error("---- Unifikation nicht m�glich: Permutation fehlgeschlagen!"); + break; + } + } + } // end if: Reduce2 + inferencelog.debug("NACH REDUCEEQ"); + // ADAPT + if (P.OperatorSmaller()) + { + Pair PFC = isInFClinks( TA1, TA2, fc_tto.getFC() ); + inferencelog.debug(" ADAPTStart"); + if( PFC != null ) + { + inferencelog.debug("isInFCrechtsUnify" + PFC.toString()); + adapt(H,PFC,TA1,TA2,fc_tto); + bRegel = true; + continue; + + } // end if: Ende Adapt bzw. isInFC + } // end if P.OperatorSmaller() + } // end if: RefType + + + // Swap + if( (P.TA1 instanceof RefType || P.TA1 instanceof GenericTypeVar || P.TA1 instanceof WildcardType) && P.TA2 instanceof TypePlaceholder && P.OperatorEqual()) + //PL 06-05-16 GenericTypeVar eingefuegt + { + H.addElement( new Pair( P.TA2, P.TA1, PairOperator.Equal ) ); + inferencelog.debug(" ================================"); + inferencelog.debug(" SWAP"); + inferencelog.debug(" ================================"); + bRegel = true; + continue; + } + + // Subst --> noch zu pr�fen + if( P.TA1 instanceof TypePlaceholder && P.OperatorEqual() && useSubst) //&& P.TA2 instanceof RefType ) + //PL 05-02-09 P.TA@ duerfen auch TypePlaceholder sein + /* BEISPIEL: + ******************************* + Menge E = { + (A, %F%), + (A, %F%), + (C, %G%) } + ******************************* + */ + { + inferencelog.debug(" SUBSTITUTE: in "); + // Ersetzungen im Rest von E + inferencelog.debug(" Subst?"); + boolean bTempSubst = P.bSubst; + for( int q = i+1; q < E.size(); q++ ) + { + if( !P.bSubst ) + //GIBT ES PROBLEME: WIRD DAS P.bSubst ZURUECKGESETZT????? + { + inferencelog.debug(" ================================"); + inferencelog.debug(" SUBSTITUTE: in " + E.elementAt(q).toString() + " alle " + P.TA1.getName() + " durch " + P.TA2.getName()); + inferencelog.debug(" ================================"); + bRegel = true; + bTempSubst = true; + + //PL 05-02-09 Typecast vor P.TA2 entfernt, da auch TypePlaceholder + //eingesetzt werden duerfen + Subst( E.elementAt(q), 1, (TypePlaceholder)P.TA1, P.TA2, true ); + Subst( E.elementAt(q), 2, (TypePlaceholder)P.TA1, P.TA2, true ); + } + } + // Ersetzungen in H + for( int q = 0; q < H.size(); q++ ) + { + if( !P.bSubst ) + { + inferencelog.debug(" ================================"); + inferencelog.debug(" SUBSTITUTE: in " + E.elementAt(q).toString() + " alle " + P.TA1.getName() + " durch " + P.TA2.getName()); + inferencelog.debug(" ================================"); + bRegel = true; + bTempSubst = true; + //P.bSubst = true; geloescht PL 06-04-29 darf hire nicht sein, sonst + //wird P nur auf ein Paar in E bzw. H angewandt. + + // Ursprungspaar nicht ersetzen + //PL 05-02-09 Typecast vor P.TA2 entfernt, da auch TypePlaceholder + //eingesetzt werden duerfen + Subst( H.elementAt(q), 1, (TypePlaceholder)P.TA1, P.TA2, true ); + Subst( H.elementAt(q), 2, (TypePlaceholder)P.TA1, P.TA2, true ); + } + } + + P.bSubst = bTempSubst; + + // falls wirklich was gemacht wurde + H.addElement( E.elementAt(i) ); + continue; + } + + // keine Regel --> Element nach H kopieren! + H.addElement( E.elementAt(i) ); + inferencelog.debug("\n--> keine Regel anwendbar --> umkopieren !!!!!!!!!!!!!!!!!!!!!"); + } + + // Hilfsvektor nach E kopieren + // MyCompiler.printDebugInfo("---- Vektoren kopieren", 6); + // MyCompiler.printDebugInfo("---- E = " + E, 6); + // MyCompiler.printDebugInfo("---- H = " + H, 6); + E.removeAllElements(); + Vector vTemp = E; + E = H; + H = vTemp; + } + return E; + } + // ino.end + + /** + * Implementiert die reduce1 Regel des sub_unify + */ + private static void reduce1(Vector H, RefType TA1, RefType TA2, Vector TTO) throws SCException + { + inferencelog.debug(" ================================"); + inferencelog.debug(" REDUCE1"); + inferencelog.debug(" ================================"); + + Vector L1 = TA1.get_ParaList(); + Vector L2 = TA2.get_ParaList(); + + inferencelog.debug("---- Parameteranzahl gleich"); + inferencelog.debug("---- Reduce !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (" + L1.size() + ") neue(s) Paar(e)"); + + inferencelog.debug("---- PAARBILDUNG "); + for( int k = 0; k < L1.size(); k++ ) + { + Pair P2 = new Pair(L1.elementAt( pi(k, TA1.getTypeName(), TA2.getTypeName(), TTO )),L2.elementAt(k), PairOperator.SmallerExtends ); + inferencelog.debug("---- Paar1: (" + (L1.elementAt( pi(k, TA1.getTypeName(), TA2.getTypeName(), TTO ) )).getName() + ", " + (L2.elementAt(k)).getName() + P2.OperatorEqual() + ")"); + H.addElement(P2); + } + } + + /** + * Implementiert die reduceExt Regel des sub_unify + */ + private static void reduceExt(Vector H, RefType TA1, RefType TA2, Vector TTO) throws SCException + { + inferencelog.debug(" ================================"); + inferencelog.debug(" REDUCEEXT"); + inferencelog.debug(" ================================"); + + Vector L1 = TA1.get_ParaList(); + Vector L2 = TA2.get_ParaList(); + + inferencelog.debug("---- Parameteranzahl gleich"); + inferencelog.debug("---- ReduceExt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (" + L1.size() + ") neue(s) Paar(e)"); + + inferencelog.debug("---- PAARBILDUNG "); + for( int k = 0; k < L1.size(); k++ ) + { + Pair P2 = new Pair( L1.elementAt( pi(k, TA1.getTypeName(), TA2.getTypeName(), TTO )), L2.elementAt(k), PairOperator.SmallerExtends ); + inferencelog.debug("---- Paar1: (" + (L1.elementAt( pi(k, TA1.getTypeName(), TA2.getTypeName(), TTO ) )).getName() + ", " + (L2.elementAt(k)).getName() + P2.OperatorEqual() + ")"); + H.addElement(P2); + + } + } + + /** + * Implementiert die reduceSup Regel des sub_unify + */ + private static void reduceSup(Vector H, RefType TA1, RefType TA2, Vector TTO) throws SCException + { + inferencelog.debug(" ================================"); + inferencelog.debug(" REDUCEEXT"); + inferencelog.debug(" ================================"); + + Vector L1 = TA1.get_ParaList(); + Vector L2 = TA2.get_ParaList(); + + inferencelog.debug("---- Parameteranzahl gleich"); + inferencelog.debug("---- ReduceExt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (" + L1.size() + ") neue(s) Paar(e)"); + + inferencelog.debug("---- PAARBILDUNG "); + for( int k = 0; k < L1.size(); k++ ) + { + Pair P2 = new Pair(L2.elementAt(k), L1.elementAt( pi(k, TA2.getTypeName(), TA1.getTypeName(), TTO )), PairOperator.SmallerExtends ); + inferencelog.debug("---- Paar1: (" + (L1.elementAt( pi(k, TA2.getTypeName(), TA1.getTypeName(), TTO ) )).getName() + ", " + (L2.elementAt(k)).getName() + P2.OperatorEqual() + ")"); + H.addElement(P2); + } + } + + /** + * Implementiert die reduceEq Regel des sub_unify + * Da in reduce2 unnötigerweise pi verwendet wird (siehe Kommentar in reduce2), kann reduceEq einfach an reduce2 deligieren. + */ + private static void reduceEq(Vector H, RefType TA1, RefType TA2, Vector TTO) throws SCException + { + reduce2(H,TA1,TA2,TTO); + } + + /** + * Implementiert die reduce2 Regel des sub_unify + */ + private static void reduce2(Vector H, RefType TA1, RefType TA2, Vector TTO) throws SCException + { + inferencelog.debug(" ================================"); + inferencelog.debug(" REDUCE2"); + inferencelog.debug(" ================================"); + + Vector L1 = TA1.get_ParaList(); + Vector L2 = TA2.get_ParaList(); + + inferencelog.debug("---- Parameteranzahl gleich"); + inferencelog.debug("---- Reduce !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (" + L1.size() + ") neue(s) Paar(e)"); + + // hier mu� die PERMUTATION erfolgen + inferencelog.debug("---- PAARBILDUNG "); + for( int k = 0; k < L1.size(); k++ ) + { + // pi eig. bei reduce2 �berfl�ssig, schadet aber hoff. auch nicht :-) + //luar 19-04-2007 durch das pi kann reduce2 auch als reduceEq verwendet werden. Wenn das pi durch k ersetzt wird, muss reduceEq entsprechend ausprogrammiert werden. + Pair P2 = new Pair( L1.elementAt( pi(k, TA1.getTypeName(), TA2.getTypeName(), TTO ) ), L2.elementAt(k), PairOperator.Equal ); + inferencelog.debug("---- Paar1: (" + (L1.elementAt( pi(k, TA1.getTypeName(), TA2.getTypeName(), TTO ) )).getName() + ", " + (L2.elementAt(k)).getName() + P2.OperatorEqual() + ")"); + H.addElement(P2); + } + } + + /** + * Implementiert die adapt Regel des sub_unify + */ + private static void adapt(Vector H, Pair PFC, RefType TA1, RefType TA2,FC_TTO fc_tto) + { + Hashtable ht = new Hashtable(); + RefType TA1neu = (RefType)Pair.copyType((RefType)PFC.TA2); + inferencelog.debug("TA1neu " + TA1neu.Type2String()); + try + { + match ((RefType)(PFC.TA1), TA1, ht); + ht = CaptureConversionHashtable(ht,fc_tto); + SubstHashtable(TA1neu, ht); + inferencelog.debug("TA1neu " + TA1neu.Type2String()); + } + catch (MatchException e) + { + inferencelog.debug("match im adapt nicht geklappt"); + return; + } + H.addElement(new Pair(TA1neu, TA2, PairOperator.Smaller)); + // Paar P ist Element von FC (von der Struktur her) + inferencelog.debug(" ================================"); + inferencelog.debug(" ADAPT"); + inferencelog.debug(" ================================"); + } + + /** + * Implementiert die adaptExt Regel des sub_unify + */ + private static void adaptExt(Vector H, Pair PFC, RefType TA1, RefType TA2, FC_TTO fc_tto) + { + Hashtable ht = new Hashtable(); + RefType TA1neu = (RefType)Pair.copyType((RefType)PFC.TA2); + inferencelog.debug("TA1neu " + TA1neu.Type2String()); + try + { + match ((RefType)(PFC.TA1), TA1, ht); + ht = CaptureConversionHashtable(ht,fc_tto); + SubstHashtable(TA1neu, ht); + inferencelog.debug("TA1neu " + TA1neu.Type2String()); + } + catch (MatchException e) + { + inferencelog.debug("match im adapt nicht geklappt"); + return; + } + H.addElement(new Pair(TA1neu, new ExtendsWildcardType(TA2.getOffset(),TA2), PairOperator.SmallerExtends)); + // Paar P ist Element von FC (von der Struktur her) + inferencelog.debug(" ================================"); + inferencelog.debug(" ADAPTEXT"); + inferencelog.debug(" ================================"); + } + + /** + * Implementiert die adaptSup Regel des sub_unify + */ + private static void adaptSup(Vector H, Pair PFC, RefType TA1, RefType TA2, FC_TTO fc_tto) + { + Hashtable ht = new Hashtable(); + RefType TA1neu = (RefType)Pair.copyType((RefType)PFC.TA2); + inferencelog.debug("TA1neu " + TA1neu.Type2String()); + try + { + match ((RefType)(PFC.TA1), TA1, ht); + ht = CaptureConversionHashtable(ht,fc_tto); + SubstHashtable(TA1neu, ht); + inferencelog.debug("TA1neu " + TA1neu.Type2String()); + } + catch (MatchException e) + { + inferencelog.debug("match im adapt nicht geklappt"); + return; + } + H.addElement(new Pair(TA1neu, new ExtendsWildcardType(TA2.getOffset(),TA2), PairOperator.SmallerExtends)); + // Paar P ist Element von FC (von der Struktur her) + inferencelog.debug(" ================================"); + inferencelog.debug(" ADAPTSUP"); + inferencelog.debug(" ================================"); + } + + /* luar 03-05-2007 + * Diese Methode ersetzt alle Typen in der Hashtable durch deren CaptureConversion + */ + private static Hashtable CaptureConversionHashtable(Hashtable ht, FC_TTO fc_tto) + { + Hashtable retHT = new Hashtable(); + for(String s : ht.keySet()) + { + Type t = ht.get(s); + Type ccT = CaptureConversion(t,fc_tto); + if(ccT != null) + retHT.put(s,ccT); + else + retHT.put(s,t); + } + return retHT; + } + + private static Pair isInFClinks( RefType RT1, RefType RT2, Vector FC) + { + for(Pair p : FC) + { + if(p.TA1 instanceof RefType && p.TA2 instanceof RefType) + { + RefType TA1 = (RefType)p.TA1; + RefType TA2 = (RefType)p.TA2; + if(TA1.getTypeName().equals(RT1.getTypeName()) && TA2.getTypeName().equals(RT2.getTypeName())) + { + Pair dolly = p.clone(); + //((RefType)dolly.TA1).GenericTypeVar2TypePlaceholder(); + MyCompiler.makeGenericTypeVars2TypePlaceHolders(dolly.TA2); + return dolly; + } + } + } + + return null; + } + + + + // ino.method.isRXSimilarRY.28073.defdescription type=line + // PL 06-03-16 + // TypePlaceholder durch GenericTypeVar ersetzt. Das duerfte eigentlich keine + // Fehler ergeben. + // ino.end + // ino.method.isRXSimilarRY.28073.definition + public static boolean isRXSimilarRY( RefType RFC, RefType RY, boolean allowTPH ) + // ino.end + // ino.method.isRXSimilarRY.28073.body + { + // otth: prueft (rekursiv) ob RFC gleiche Sturktur hat wie RY + // RFC: falls Typvariable als Parameterlistenelement vorkommt --> Entsprechung in RY ist egal + + // Namen von RFC und RY muessen gleich sein + if( RFC.getTypeName().equals( RY.getTypeName() ) ) + { + if( RFC.get_ParaList() == null && RY.get_ParaList() == null ) + { + // beide Typen haben keine Parameter --> nur Typnamen muessen uebereinstimmen + return true; + } + + if( RFC.get_ParaList() != null && RY.get_ParaList() != null ) + { + // beide Typen haben Parameter --> Parameterliste durchlaufen + Vector px = RFC.get_ParaList(); + Vector py = RY.get_ParaList(); + if( px.size() == py.size() ) + { + for( int i = 0; i < px.size(); i++ ) + { + if(px.elementAt(i) instanceof GenericTypeVar || (px.elementAt(i) instanceof TypePlaceholder && allowTPH)) { + // Element von RFC ist Typvariable --> Entsprechung von RY kann alles sein + continue; + } + + if( px.elementAt(i) instanceof RefType && py.elementAt(i) instanceof RefType ) + { + RefType RTempX = (RefType)px.elementAt(i); + RefType RTempY = (RefType)py.elementAt(i); + + if( RTempX.get_ParaList() == null && RTempY.get_ParaList() == null ) + { + continue; + } + + // zwei RefTypes --> weiter, rekursiv pruefen + if( isRXSimilarRY( RTempX, RTempY,allowTPH ) ) + { + continue; + } + } + + return false; + } + return true; + } + } + } + + return false; + } + // ino.end + + // ino.method.SubstHashtable2VectorPair.28076.definition + public static Vector SubstHashtable2VectorPair (Hashtable ht) + // ino.end + // ino.method.SubstHashtable2VectorPair.28076.body + { + //PL 05-01-23 wandelt eine Hashtable von Substitutionen + //PL 05-02-12 true BEI KONSTRUKTOR Pair EINGEFUEGT + //in ein Vector von Paaren um. + + Vector ret = new Vector(); + for(Enumeration e=ht.keys();e.hasMoreElements();) { + String k = (String)e.nextElement(); + // #JB# 11.04.2005 + // ########################################################### + ret.addElement(new Pair(TypePlaceholder.backdoorCreate(k), (Type)ht.get(k), PairOperator.Equal)); + //ret.addElement(new Pair(new TypePlaceholder(k), (Type)ht.get(k), true)); + // ########################################################### + } + return ret; + } + // ino.end + + // ino.method.VectorPair2SubstHashtableVectorPair.28079.definition + public static Hashtable VectorPair2SubstHashtableVectorPair (Vector v) + // ino.end + // ino.method.VectorPair2SubstHashtableVectorPair.28079.body + { + //PL 05-01-23 wandelt einen Vector von Paaren (a, ty) von Substitutionen + //in eine Hashtable um. + + Hashtable ret = new Hashtable(); + for(Enumeration e=v.elements();e.hasMoreElements();) { + Pair p = e.nextElement(); + ret.put(p.TA1.getName(), p.TA2); + } + return ret; + } + // ino.end + + // ino.method.copyVectorPair.28082.definition + public static Vector copyVectorPair (Vector vp) + // ino.end + // ino.method.copyVectorPair.28082.body + { + //PL 05-01-23 kopiert einen Vector von Typ-Paaren + + Vector ret = new Vector(); + for (int i=0; i < vp.size(); i++) { + ret.addElement(vp.elementAt(i).copyPair()); + } + return ret; + } + // ino.end + + // ino.method.copyVectorVectorPair.28085.definition + public static Vector> copyVectorVectorPair (Vector> vp) + // ino.end + // ino.method.copyVectorVectorPair.28085.body + { + //PL 05-02-08 kopiert einen Vector von Vectoren von Typ-Paaren + + Vector> ret = new Vector>(); + for (int i=0; i < vp.size(); i++) { + ret.addElement(copyVectorPair(vp.elementAt(i))); + } + return ret; + } + // ino.end + + + + // ino.method.instanceSmaller.28088.definition + public static Vector> instanceSmaller(Pair P, FC_TTO fc_tto ) + // ino.end + // ino.method.instanceSmaller.28088.body + { + //PL 05-01-23 bekommt als Eingabe ein Paar (a, ty') und bestimmt + //die Menge der Menge aller Substitutionen a \leq^* \sigma(ty), wobei + //\sigma = unify(ty', \ol{ty}') (ty, \ol{ty}') \in FC + + Vector FC = fc_tto.getFC(); + Vector> ret = new Vector>(); + Vector element; + + RefType ty = (RefType)P.TA2; + //Menge der \sigma(\theta) bestimmen, die in FC als linke Seite + //vorkommt + Hashtable testht = new Hashtable(); + for (int i=0; i < FC.size(); i++) { + // try { + Hashtable ht = new Hashtable(); + //HIER MOEGLICHERWEISE sub_unify MIT true IN DEN PAAREN AUFRUFEN + //BEI INSTANZIERTEN TYPEN WEREDN KEINE SUBTYPEN GEBILDET + //VERGLEICHE pl1.1.1.3.jav + //match(ty, (RefType)(((Pair)FC.elementAt(i)).TA2), ht); + Vector subunifypair = new Vector (); + RefType ob = ((RefType)(FC.elementAt(i).TA2)).clone();// !!!oder Pair.copyType!!! + CSubstitutionSet sub = ob.GenericTypeVar2TypePlaceholder(); + sub.applyThisSubstitutionSet(ob); + subunifypair.addElement(new Pair(Pair.copyType(ty), ob, PairOperator.Equal)); + //06-04-27 PL HIER MUSS VERMUTLIRH NORH AUF DAS TA2 ein fresh angewandt werden. + //MEHRFACHES UNIFIZIEREN, WENN EIN TYP UND EINE INSTANZ DAVON AUCH IN FC + //LIEGT + //erlegigt 06-04-28 + Vector res = sub_unify(subunifypair, fc_tto); + if (hasSolvedForm(res)) { //PL 13-05-22: hasSolvedForm geaendert, es nicht geklärt, ob es funktioniert. + inferencelog.debug("HasSolvedForm: "); + printMenge("RES_SMALLER", res, 6); + ht = VectorPair2SubstHashtableVectorPair(res); + //RefType tynew = (RefType)Pair.copyType(ty); + RefType tynew = (RefType)Pair.copyType((RefType)(FC.elementAt(i).TA1)); + sub.applyThisSubstitutionSet(tynew); + //HIER MUESSEN IM SUBTYPE tynew NEU HINZUGEKOMMENE GENTYPEVARS NOCH DURCH TypePlaceholders VARS ERSETZT WERDEN + //pl 06-04-29 + SubstHashtable(tynew, ht); + //falls Typvariablen bei Vererbung hinzugekommen sind. + CSubstitutionSet sub1 = tynew.GenericTypeVar2TypePlaceholder(); + sub1.applyThisSubstitutionSet(tynew); + element = SubstHashtable2VectorPair(ht); + printMenge("ELEMENT", element, 6); + //Vector smaller = new Vector (); + //smaller.addElement(tynew); + Vector smaller; + + //DIESER AUFRUF IS MOEGLICHERWEISE UNNOETIG, DA ALLE + //KLEINEREN ELEMENTE BEREITS DURCH ANDERE ELEMENTE AUS + //FC BESTIMMT WURDEN BZW. WERDEN. + smaller = allSmaller(tynew, FC); + + //wegen Reflexivitaet hinzufuegen, wenn tynew und ty aequivalent + //dann wird ganz am Ende hinzugefuet + smaller.addElement(tynew); + + for (int j = 0; j < smaller.size(); j++) { + Vector newelement = copyVectorPair(element); + if (smaller.size() >= 1) { + RefType testreftype = testht.put(smaller.elementAt(j).Type2Key(), smaller.elementAt(j)); + if (testreftype == null) + { + newelement.addElement(new Pair(P.TA1, smaller.elementAt(j), PairOperator.Equal)); + printMenge("NEWELEMENT", newelement, 6); + ret.addElement(newelement); + } + } + } + // } + // catch (matchException e) { + // System.out.println("matchException " + e.getMessage() + " " + ((RefType)(((Pair)FC.elementAt(i)).TA2)).Type2String()); + // //smaller = new Vector(); + // //element = new Vector(); + // } + } + } + Vector equalElement = new Vector(); + equalElement.addElement(new Pair(P.TA1, P.TA2, PairOperator.Equal)); + ret.addElement(equalElement); + printMengeUnifier("RES_SMALLERend", ret, 6); + return ret; + } + // ino.end + + // ino.method.allSmaller.28091.definition + public static Vector allSmaller(RefType ty, Vector FC) + // ino.end + // ino.method.allSmaller.28091.body + { + //PL 05-01-22 bestimmt alle Typen die kleiner sind als ty + + Vector ret = new Vector(); + + inferencelog.debug("New allSmaller " + ty.Type2String()); + + //doppelte untere Typen von Paaren eleminieren + Hashtable hht = new Hashtable(); + + for (int i=0; i < FC.size(); i++) { + if (hht.put(((RefType)(FC.elementAt(i).TA1)).getName(), (RefType)(FC.elementAt(i).TA1)) != null) { } + else { + inferencelog.debug("Getestet1: " + (new Pair((RefType)(FC.elementAt(i).TA1), ty)).toString()); + RefType ty1 = (RefType)Pair.copyType(ty); + Pair P = isInFC((RefType)(FC.elementAt(i).TA1), ty1, FC); + // RefType FCrselem = (RefType)(((Pair)FC.elementAt(i)).TA2); + + // //bestimmt alle Element, die ohne instance kleiner als ty ist + // P = (Pair)FC.elementAt(i); //angenommenes Ergebnis, wird ggfs. geloescht + // if (FCrselem.getTypeName().equals(ty.getTypeName())) { + // if (FCrselem.get_ParaList() != null && ty.get_ParaList() != null) { + // if (FCrselem.get_ParaList().size() == ty.get_ParaList().size()) { + // for (int j = 0; j < FCrselem.get_ParaList().size(); j++) { + // if (!(FCrselem.get_ParaList().elementAt(j) instanceof TypePlaceholder) + // || !(ty.get_ParaList().elementAt(j) instanceof TypePlaceholder)) { + // P = null; + // break; + // } + // } + // } + // } + // } + // else P = null; + inferencelog.debug("Getestet2: " + P); + //HIER IN isInFC SCHEINT EIN FEHLER ZU SEIN. + + if (P != null) { + //System.out.println("ISIN"); + RefType smaller = (RefType)Pair.copyType(P.TA1); + Hashtable ht = new Hashtable(); + try { + match((RefType)P.TA2, ty, ht); + //Problem koennte sein, dass ein TypePlaceholder mehrere Typterme + //zugeordnet werden. + SubstHashtable(smaller, ht); + ret.addElement(smaller); + } + catch (MatchException e) { } + } + } + } + return ret; + } + // ino.end + + // ino.method.allGreater.29428.definition + public static Vector allGreater (BoundedGenericTypeVar ty, Vector FC) + // ino.end + // ino.method.allGreater.29428.body + { + CRefTypeSet ret = new CRefTypeSet(); + Iterator typeIt = ty.getBounds().iterator(); + while(typeIt.hasNext()) { + CRefTypeSet grBounds = new CRefTypeSet(); + RefType act = (RefType)typeIt.next(); + grBounds.setVector(allGreater(act, FC)); + grBounds.addElement(act); + ret.unite(grBounds); + } + return ret.getVector(); + } + // ino.end + + // ino.method.allGreater.28094.definition + public static Vector allGreater (RefType ty, Vector FC) + // ino.end + // ino.method.allGreater.28094.body + { + + Vector ret = new Vector(); + + + Hashtable testht = new Hashtable(); + for (int i=0; i < FC.size(); i++) { + //System.out.println("Getestet1: " + (new Pair((RefType)(((Pair)FC.elementAt(i)).TA1), ty)).toString()); + Pair P; + P = isInFC(ty, (RefType)(FC.elementAt(i).TA2), FC); + if (P != null) { + //Testen, ob das mit der Hashtable funktioniert. + Pair testreftype = testht.put(P, P); + if (testreftype == null) { + inferencelog.debug("ISIN" + ty.Type2String() + P.toString()+" "+(FC.elementAt(i)).toString()); + RefType greater = (RefType)Pair.copyType(P.TA2); + Hashtable ht = new Hashtable(); + try { + //Hier muessen GTV durch TLV ersetzt werden. + //vgl. searchAndHandleMethod in MethodCall.java + match((RefType)P.TA1, ty, ht); + //Problem koennte sein, dass ein TypePlaceholder mehrere Typterme + //zugeordnet werden. + SubstHashtableGeneric(greater, ht); + ret.addElement(greater); + } + catch (MatchException e) { + inferencelog.error("Kein Match im allGreater"); + } + } + } + } + return ret; + } + // ino.end + + // ino.method.isInFC.28097.definition + public static Pair isInFC( RefType R1, RefType R2, Vector FC ) + // ino.end + // ino.method.isInFC.28097.body + { + // otth: Funktion, die prueft, ob Paar( R1, R2 ) in FC liegt, + // bzw. deren rechten Seiten, ohne die TypePlaceholder-Variablen zu beachten + // z.B. Vector w�re hier gleich wie Vector + + // z.B. FC = { ( AA <=* CC< DD > ) ,...} + // R1 = AA + // R2 = CC< DD< Char, a> > + + // FC durchlaufen + RefType RFC = null; // temporaer, fuer Element von FC + for( int i = 0; i < FC.size(); i++ ) + { + Pair P = FC.elementAt(i); + + // R1 bzw. linke Seite testen + if( P.TA1 instanceof RefType && P.TA2 instanceof RefType ) + { + RFC = (RefType)P.TA1; + //System.out.println("SIMILAR1"); + if( isRXSimilarRY( RFC, R1, false ) ) + { + //System.out.println("SIMILAR2"); + // linke Seiten gleich --> rechte Seiten testen + RFC = (RefType)P.TA2; + if( isRXSimilarRY( RFC, R2, false ) ) + { + // rechte Seiten gleich + inferencelog.debug("Folgendes Paar ist Element von FC: " + P.toString() + (new Pair(R1, R2)).toString()); + return P; + } + } + } + + // Paare sind nicht gleich --> FC weiter durchlaufen + + } // end for: FC durchlaufen + + // kein passendes Paar in FC gefunden + return null; + + } // end Funktino: isInFC + // ino.end + + // ino.method.isInFCrechtsUnify.28100.definition + public static Pair isInFCrechtsUnify( RefType RT1, RefType RT2, FC_TTO fc_tto ) + // ino.end + // ino.method.isInFCrechtsUnify.28100.body + { + // otth: Funktion, die prueft, ob Paar( R1, \sigma(R2) ) in FC liegt, + // bzw. deren rechten Seiten, ohne die TypePlaceholders zu beachten + // z.B. Vector w�re hier gleich wie Vector + + // z.B. FC = { ( AA <=* CC< DD > ) ,...} + // R1 = AA + // R2 = CC< DD< Char, a> > + + // FC durchlaufen + Vector FC = fc_tto.getFC(); + RefType RFC = null; // temporaer, fuer Element von FC + for( int i = 0; i < FC.size(); i++ ) + { + RefType R1 = (RefType)Pair.copyType(RT1); + RefType R2 = (RefType)Pair.copyType(RT2); + Pair P = FC.elementAt(i); + inferencelog.debug("getestestes Paar" + P.toString()); + + // R1 bzw. linke Seite testen + if( P.TA1 instanceof RefType && P.TA2 instanceof RefType ) + { + RFC = (RefType)P.TA1; + inferencelog.debug("VOR SIMILAR1" + RFC.Type2String() + " " + R1.Type2String()); + if( isRXSimilarRY( RFC, R1, false ) ) + { + inferencelog.debug("SIMILAR1"); + // linke Seiten gleich --> rechte Seiten testen + RFC = (RefType)P.TA2; + Vector R2vec = new Vector (); + inferencelog.debug("New_Pair" + (new Pair(RFC, R2, PairOperator.Smaller)).toString()); + + //STIMMT DAS copyType??? + RefType RFC_new = RFC.clone(); + RFC_new.GenericTypeVar2TypePlaceholder(); + R2vec.addElement(new Pair(RFC_new, R2.clone(), PairOperator.Smaller)); + + printMenge("R2vec", R2vec, 6); + Vector vp = sub_unify(R2vec, fc_tto); + + printMenge("VP", vp, 6); + if ( hasSolvedForm(vp) ) //PL 13-05-22: hasSolvedForm geaendert, es nicht geklärt, ob es funktioniert. + //if( isRXSimilarRY( RFC, R2 ) ) + { + inferencelog.debug("SIMILAR2"); + // rechte Seiten gleich + inferencelog.debug("Folgendes Paar ist Element von FC: " + P.toString()); + return P; + } + } + } + + // Paare sind nicht gleich --> FC weiter durchlaufen + + } // end for: FC durchlaufen + + // kein passendes Paar in FC gefunden + return null; + + } // end Funktino: isInFC + // ino.end + + // ino.method.isTVinRefType.28103.definition + public static boolean isTVinRefType( TypePlaceholder TV, RefType RT ) + // ino.end + // ino.method.isTVinRefType.28103.body + { + // otth: Prueft ob TV in RefType vorkommt, falls ja --> true + + // Name der Typvariablen + String strTV = TV.getName(); + + // Parameterliste extrahieren + if( RT.get_ParaList() == null ) + // keine Parameterliste + return false; + else + { + // Parameterliste vorhanden --> durchiterieren + Vector P = RT.get_ParaList(); + for( int i = 0; i < P.size(); i++ ) + { + Type T = (Type)P.elementAt( i ); + if (T instanceof ExtendsWildcardType) T = ((ExtendsWildcardType)T).get_ExtendsType(); + + if( T instanceof TypePlaceholder ) + { + // T ist eine Typvariable --> gleiche Namen??? + if( strTV.equals(T.getName()) ) + return true; + } + + if( T instanceof RefType ) + { + // T ist wieder ein RefType --> rekursiver Aufruf + if( isTVinRefType( TV, (RefType)T ) ) + return true; + } + + } + + return false; + } + } + // ino.end + + // ino.method.Subst.28106.defdescription type=line + // void Subst( Pair P, int nTypnrInPair, TypePlaceholder a, RefType o, boolean + // bMitVorbedingung ) PL 05-02-10 fuer o sind auch TypePlaceholder moeglich + // ino.end + // ino.method.Subst.28106.definition + public static boolean Subst( Pair P, int nTypnrInPair, TypePlaceholder a, Type o, boolean bMitVorbedingung ) + // ino.end + // ino.method.Subst.28106.body + { + // otth: Hilfsfunktion zur Unifikation + // otth: Ersetzen der Typvariablen a durch den RefType o + // otth: in dem nTypnrInPair. Type des Paares P + // otth: Pair uebergeben, da Zeiger nur by Value kopiert wird, s. TV + // otth: bMitVorbedingung: Darf die Typvariable a auf der rechten Seite auch vorkommen oder nicht? + + inferencelog.debug("SUBST: "); + inferencelog.debug("Pair: " + P.toString()); + inferencelog.debug("Nummer: " + nTypnrInPair); + inferencelog.debug("TV: " + a.getName()); + inferencelog.debug("Bedingung: " + bMitVorbedingung); + + // richtiger Typ aus Pair raussuchen + Type T = null; + if( nTypnrInPair == 1 ) + T = (Type)P.TA1; + else + T = (Type)P.TA2; + + // Vorbedingung: in o darf a nicht vorkommen!!! + if (o instanceof RefType) {//PL 05-02-09 eingefuegt siehe Methodenkopf + if( bMitVorbedingung && isTVinRefType( a, (RefType)o ) ) + { + inferencelog.debug(" Subst nicht m�glich, da TV " + a.getName() + " in RefType " + o.getName()); + return false; + } + } + + // Reftypes substituieren + if( T instanceof RefType && ((RefType)T).get_ParaList() != null ) + { + // Parameterliste durchgehen + Vector vTemp = ((RefType)T).get_ParaList(); + for( int i = 0; i < vTemp.size(); i++ ) + { + Type Temp = (Type)vTemp.elementAt(i); + + // u.U. umwandeln in TypePlaceholders, auskommentiert, da umgestellt auf RefType und TypePlaceholder + // if( Temp instanceof RefType && ((RefType)Temp).get_ParaList() == null ) + // Temp = new TypePlaceholder( ((RefType)Temp).getName() ); + + if( Temp instanceof TypePlaceholder ) + { + + if( Temp.getName().equals(a.getName()) ) + { + // Typvariable ersetzen + Vector vParaListTemp = ((RefType)T).get_ParaList(); + vParaListTemp.set( i, o ); // i. Element ersetzen + return true; + } + } + if( Temp instanceof RefType ) + { + Pair PTemp = new Pair( Temp, null); + inferencelog.debug(" TV!!!" + PTemp.toString() ); + return Subst( PTemp, 1, a, o, bMitVorbedingung ); + } + } + } + + // TV substituieren + if( T instanceof TypePlaceholder ) + { + if( T.getName().equals( a.getName() ) ) + { + // TV ersetzen + if( nTypnrInPair == 1 ) + P.TA1 = o; + else + P.TA2 = o; + + return true; + } + } + return false; + } + // ino.end + + // ino.method.SubstHashtableGeneric.28109.defdescription type=line + // SubstHashtableGeneric ersetzt in typterm alle GenericType Variablen aus ht + // durch den zugeordneten Typ. + // ht enthaelt Elemente der (String, Type) + // ino.end + // ino.method.SubstHashtableGeneric.28109.definition + public static void SubstHashtableGeneric(RefType typterm, Hashtable ht) + // ino.end + // ino.method.SubstHashtableGeneric.28109.body + { + Vector para = typterm.get_ParaList(); + if (para != null) { + for (int i=0; i < para.size(); i++) { + if (para.elementAt(i) instanceof GenericTypeVar) { + if (ht.get(((GenericTypeVar)para.elementAt(i)).getName()) != null) { + para.set(i, ht.get(((GenericTypeVar)para.elementAt(i)).getName())); + } + } + else { + if (para.elementAt(i) instanceof RefType) + SubstHashtableGeneric(((RefType)para.elementAt(i)), ht); + } + } + } + } + // ino.end + + // ino.method.SubstHashtable.28112.defdescription type=line + // SubstHashtable ersetzt in typterm alle TypePlaceholder-Variablen aus ht durch + // den zugeordneten Typ. + // ht enthaelt Elemente der (String, Type) + // ino.end + // ino.method.SubstHashtable.28112.definition + public static void SubstHashtable(RefType typterm, Hashtable ht) + // ino.end + // ino.method.SubstHashtable.28112.body + { + Vector para = typterm.get_ParaList(); + if (para != null) { + for (int i=0; i < para.size(); i++) { + if (para.elementAt(i) instanceof TypePlaceholder) { + if (ht.get(((TypePlaceholder)para.elementAt(i)).getName()) != null) { + para.set(i, ht.get(((TypePlaceholder)para.elementAt(i)).getName())); + } + } + else { + if (para.elementAt(i) instanceof RefType) + SubstHashtable(((RefType)para.elementAt(i)), ht); + } + } + } + } + // ino.end + + + // ino.method.isRealSubClass.28115.definition + public static boolean isRealSubClass( String Basis, String Mutter, FC_TTO fc_tto ) + // ino.end + // ino.method.isRealSubClass.28115.body + { + + + // otth: Funktion pr�ft, ob Klasse 'Basis' von Klasse 'Mutter' direkt oder indirekt abgeleitet ist + + // Basisklasse suchen + Vector tto = fc_tto.getTTO(); + for( int i = 0; i < tto.size(); i++ ) + { + //Class tempKlasse = (Class)KlassenVektor.elementAt(i); + Pair tempPair = (Pair)tto.elementAt(i); + //if( Basis.equals( tempKlasse.get_classname() ) ) + if( Basis.equals( ((RefType)tempPair.TA1).getTypeName() ) ) + { + //if( tempKlasse.get_Superclass_Name() != null ) + { + // Zusatzbedingung: otth - falls Typkonstruktoren in Superklassen auftreten --> ungueltig ?? + //Vector s = ((UsedId)tempKlasse.superclassid).vParaOrg; + Vector s = ((RefType)tempPair.TA2).get_ParaList(); + + // HOTI: Bugfixing: Wenn die ParaList leer ist, wird schlich ein neuer Vektor angelegt,der leer ist + + if(s==null){ + s=new Vector(); + } + + /* + * Hier wird überprüft ob in der Paraliste ein anderes Element als ein GTV drinne ist. + * Sollte ein anderes Element gefunden werden ist Reduce nicht möglich. + * Beispiel: Matrix <. Vector> ist nur durch adapt möglich. + */ + for(Type t : s) + { + if(!(t instanceof GenericTypeVar)) + return false; + } + + /*for( int l = 0; l < s.size(); l++ ) + { + if( s.elementAt(l) instanceof RefType ) + { + if( ((RefType)s.elementAt(l)).get_ParaList() != null ) + { + inferencelog.debug("Superklasse enthaelt Typkonstruktoren!"); + return false; + } + } + }*/ + + //if( tempKlasse.get_Superclass_Name().equals( Mutter ) ) + if( ((RefType)tempPair.TA2).getTypeName().equals( Mutter ) ) + return true; // Basis ist von Mutter abgeleitet + else + { + //return isRealSubClass( tempKlasse.get_Superclass_Name(), Mutter, fc_tto ); + return isRealSubClass( ((RefType)tempPair.TA2).getTypeName(), Mutter, fc_tto ); + } + } + //else + //{ + // return false; + //} + } + } + return false; + } + // ino.end + +// ino.method.pi.28118.defdescription type=block +/* + public static void test( ) + { + for( int i = 0; i < KlassenVektor.size(); i++ ) + { + Class tempKlasse = (Class)KlassenVektor.elementAt(i); + System.out.println( "Klasse: " + tempKlasse.get_classname() ); + System.out.println( "P. K.: " + tempKlasse.get_ParaList() ); + if( tempKlasse.get_Superclass_Name() != null ) + { + Vector s = ((UsedId)tempKlasse.superclassid).vParaOrg; + System.out.println( "S. Klasse: " + +tempKlasse.get_Superclass_Name() ); System.out.println( "P. S.: +" + tempKlasse.get_ParaList() ); + } + } + } +*/ +// ino.end + + // ino.method.pi.28118.definition + public static int pi( int n, String C, String D, Vector tto ) + throws SCException + // ino.end + // ino.method.pi.28118.body + { + // otth: Permutation, benoetigt fuer Unifikation + // C, D: Namen von Klassen + // z.B. class C --- class D + // pi(1) = 2 + + // MyCompiler.printDebugInfo("---------------- Permutation: n = " + String.valueOf(n) + " - C = " + C + " - D = " + D, 6); + + // Klassen suchen + //Class KlasseC = null; + //Class KlasseD = null; + //Class tempKlasse = null; + // for( int i = 0; i < KlassenVektor.size(); i++ ) + // { + // // MyCompiler.printDebugInfo("---------------- Permutation: i = " + String.valueOf(i) + " - Classname = " + ((Class)KlassenVektor.elementAt(i)).get_classname(), 6); + + // if( KlasseC != null && KlasseD != null ) + // break; + + // tempKlasse = (Class)KlassenVektor.elementAt(i); + // if( C.equals( tempKlasse.get_classname() ) ) + // { + // KlasseC = tempKlasse; + // // MyCompiler.printDebugInfo("---------------- Permutation: C-Klasse gefunden!", 6); + // } + + // if( D.equals( tempKlasse.get_classname() ) ) + // { + // KlasseD = tempKlasse; + // // MyCompiler.printDebugInfo("---------------- Permutation: D-Klasse gefunden!", 6); + // } + // } + + if (C.equals(D)) return n; //Reduktion mit gleichen Typkonstruktoren + + else { + RefType KlasseC = null; + RefType KlasseD = null; + //RefType tempKlasse = null; + + for( int i = 0; i < tto.size(); i++ ) { + + KlasseC = (RefType)((Pair)tto.elementAt(i)).TA1; + KlasseD = (RefType)((Pair)tto.elementAt(i)).TA2; + + if (KlasseC.getTypeName().equals(C) && KlasseD.getTypeName().equals(D)) { + break; + } + else { + KlasseC = null; + KlasseD = null; + } + + } + + SCException F = new SCException(); + if( KlasseC == null && KlasseD == null ) + throw F; // Fehler + + // Vektorlisten extrahieren + Vector vC = KlasseC.get_ParaList(); + Vector vD = KlasseD.get_ParaList(); + + if( vC == null || vD == null ) + throw F; + + if( n >= vD.size() ) + throw F; + + // Permuationswert f�r 'n' berechnen + Type TV = (Type)vD.elementAt(n); + + int nPos = -1; + + // MyCompiler.printDebugInfo("---------------- Permutation: vC.size() = " + String.valueOf( vC.size() ), 6); + + for( int i = 0; i < vC.size(); i++ ) + { + // MyCompiler.printDebugInfo("---------------- Permutation: TV = " + ((Type)vC.elementAt(i)).getName_(), 6); + if( ((Type)vC.elementAt(i)).getName().equals( TV.getName() ) ) + { + nPos = i; + break; + } + } + + if (nPos == -1) + throw F; + + // MyCompiler.printDebugInfo("---------------- Permutation: = " + String.valueOf( nPos ), 6); + + return nPos; + } + } + // ino.end + // ino.method.printMengeUnifier.28121.definition + public static void printMengeUnifier(String strMenge, Vector> Uni, int nDebug ) + // ino.end + // ino.method.printMengeUnifier.28121.body + { + //PL 05-01-21 + //Ruft f�r eine Menge von Unifikatoren die Methode + //printMenge auf + for (int i = 0; i < Uni.size(); i++) { + inferencelog.debug((i+1) + ". Unifier"); + printMenge(strMenge, Uni.elementAt(i), nDebug); + if( hasSolvedForm( Uni.elementAt(i) ) ) { //PL 13-05-22: hasSolvedForm geaendert, es nicht geklärt, ob es funktioniert. + inferencelog.debug((i+1) + ". Unifier ist in 'Solved form'!\n"); + } + else { + inferencelog.debug((i+1) + ". Unifier ist nicht in 'Solved Form'\n"); + } + + } + } + // ino.end + + // ino.method.printMenge.28124.definition + public static void printMenge( String strMenge, Vector E, int nDebug ) + // ino.end + // ino.method.printMenge.28124.body + { + // otth - zum Debuggen: Menge ausgeben *********************** + String strTemp = ""; + if( E.size() == 0 ) + { + inferencelog.debug("*******************************"); + inferencelog.debug("Menge " + strMenge + " ist leer!"); + inferencelog.debug("*******************************"); + return; + } + + for( int tt = 0; tt < E.size(); tt++ ) { + //luar 13-03-07 If Else Block gelöscht, da sinnlos. + if( tt > 0 ) + strTemp = strTemp + ",\n" + E.elementAt(tt).toString(); + else + strTemp = E.elementAt(tt).toString(); + strTemp = strTemp + (E.elementAt(tt).GetOperator()); + } + inferencelog.debug("*******************************"); + inferencelog.debug("Menge " + strMenge + " = {" + strTemp + " }"); + inferencelog.debug("*******************************"); + } + // ino.end + + // ino.method.hasSolvedForm.28127.definition + public static boolean hasSolvedForm( Vector E ) + // ino.end + // ino.method.hasSolvedForm.28127.body + { + // otth: prueft, ob Menge E in 'Solved form' + + // TV im Vektor speichern + Vector vTV = new Vector(); + for(Pair P : E) + { + // linke Seite == TypePlaceholder + if( !(P.TA1 instanceof TypePlaceholder) ) + { + return false; + } + else + { + vTV.add( (TypePlaceholder)P.TA1 ); //wird benoetigt um spaeter zu pruefen, + //ob tlv auf der rechten Seite steht + } + } + + for(Pair P : E) + { + //for( int u = 0; u < vTV.size(); u++ )// geloescht PL 13-05-22 + { + if (P.TA2 instanceof RefType) + { //eingefuegt PL 05-01-30 s.o. + //if( isTVinRefType(vTV.elementAt(u), (RefType)P.TA2 ) ) + if (isTVinRefType((TypePlaceholder)P.TA1, (RefType)P.TA2 )) + return false; + } + } + } + return true; + } + // ino.end + + // ino.method.varSubst.28130.defdescription type=line + // varSubst ersetzt all TypePlaceholders eines Typterms. + // Wenn eine Variable zum ersten Mal auftritt, wird eine freshe generiert + // und diese in ht gespeichert. + // Wenn eine Variable auftaucht, die bereits schon einmal ersetzt wurde, wird + // sie durch die selbe Variable ersetzt. + // ino.end + // ino.method.varSubst.28130.definition + public static void varSubst(RefType typterm, Hashtable ht) + // ino.end + // ino.method.varSubst.28130.body + { + Vector para = typterm.get_ParaList(); + if (para != null) { + for (int i=0; i < para.size(); i++) { + if (para.elementAt(i) instanceof TypePlaceholder) { + if (ht.get(((TypePlaceholder)para.elementAt(i)).getName()) != null) { + para.set(i, ht.get(((TypePlaceholder)para.elementAt(i)).getName())); + } + else { + // #JB# 11.04.2005 + // ########################################################### + ht.put(((TypePlaceholder)para.elementAt(i)).getName(), TypePlaceholder.backdoorFresh()); + //ht.put(((TypePlaceholder)para.elementAt(i)).getName(), TypePlaceholder.fresh()); + // ########################################################### + para.set(i, ht.get(((TypePlaceholder)para.elementAt(i)).getName())); + + } + } + else { + if (para.elementAt(i) instanceof RefType) + varSubst(((RefType)para.elementAt(i)), ht); + } + } + } + } + // ino.end + + + /** + * Implementiert die CaptureConversion. Wendet diese auf jeden Typ im Vector TVec an. + * Rückgabe ist ein Ergebnisvector + */ + private static Vector CaptureConversion(Vector TVec, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + for(Type t : TVec) + { + Type ccT = CaptureConversion(t,fc_tto); + if(ccT != null) + retVec.add(ccT); + } + return retVec; + } + + /** + * Erzeugt die CaptureConversion von einem Typ. + * + * @param T - Übergebener Typ, von welchem die CaptureConversion gemacht werden soll. + * @param fc_tto - Hilfsklasse. + * @return - CC(T) + */ + private static Type CaptureConversion(Type T, FC_TTO fc_tto) + { + if(T instanceof RefType) + { + //Klasse aus Klassenvektor holen. + Class cl = null; + for(Class c : fc_tto.getClasses()) + { + if(c.getSimpleName().equals(T.getName())) + { + cl = c; + break; + } + } + if(cl == null) //Keine Klasse gefunden? + return null; + + Vector ccTypes = new Vector(); + RefType refT = (RefType)T.clone(); + boolean ccDone = false; + if(refT.get_ParaList() != null) + { + Vector paras = refT.get_ParaList(); + //Durch jeden Typ in der Paralist des RefTypes laufen. + for(int i = 0; i in Typ A ...> werden keine ? extends-, ? super-Typen erzeugt + */ + private static Vector greater(Type T, FC_TTO fc_tto) + //an die Aenderungen im Skript anpassen 07-11-03 + { + Vector retVec = new Vector(); + Vector greater0Erg = greater0(T,fc_tto); + for(Type t : greater0Erg) + { + if(!DelFreshWildcardTypeVar(t)) + retVec.add(t); + } + return retVec; + } + + /** + * greater0 Schritt von greater. + */ + private static Vector greater0(Type T, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + + //greater1 Erzeugen + Vector greater1Erg = greater1(T,fc_tto); + + //Reflexivität, deshalb T hinzufügen. + if(!greater1Erg.contains(T)) + greater1Erg.add(T); + + //Falls in greater1Erg Typen doppelt vorhanden sind werden diese nicht in retVec übernommen. + for(Type t : greater1Erg) + if(!retVec.contains(t)) + retVec.add(t); + + //Ergebnis von greater1 an greater2 durchreichen, ERgebnisse in retVec einfügen + Vector greater2Erg = greater2(greater1Erg,fc_tto); + for(Type t : greater2Erg) + if(!retVec.contains(t)) + retVec.add(t); + + //Ergebnis von greater2 an greater3 durchreichen, ERgebnisse in retVec einfügen + Vector greater3Erg = greater3(greater2Erg,fc_tto); + for(Type t : greater3Erg) + if(!retVec.contains(t)) + retVec.add(t); + + return retVec; + } + + /** + * greater1 Schritt von greater. + * Für den Argumenttype FunN<...> in Typ A ...> werden keine ? extends-, ? super-Typen erzeugt + */ + private static Vector greater1(Type T, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + if(T instanceof RefType) + { + RefType refT = (RefType)T; + if(refT.get_ParaList() != null && refT.get_ParaList().size() > 0) + { + Vector> types = new Vector>(); + Vector paras = refT.get_ParaList(); + //Greater Arg von jedem Parameter einsammeln. + for(int i = 0; i> kart = cartProductType(types); + //Mit den neuen Parameterlisten neue Typen erzeugen. + for(Vector t : kart) + { + RefType dolly = refT.clone(); + dolly.set_ParaList(t); + retVec.add(dolly); + } + } + } + return retVec; + } + + /** + * Überladung der Funktion cartProductType, damit der Programmierer beim ersten Aufruf nicht den 2. Parameter + * welcher für die rekursion erforderlich ist mit übergeben muss. + */ + private static Vector> cartProductType (Vector> vec) + { + return cartProductType(vec,0); + } + + /** + * Erzeugt das Kartesische Product von mehreren Vectoren von Typen. + * Für den Startaufruf ist der index = 0. Danach ruft sich cartProductType rekursiv auf. + */ + private static Vector> cartProductType (Vector> vec, int index) + { + Vector> retVec = new Vector>(); + if(vec.isEmpty()) return retVec; + + Vector myTypes = vec.get(index); + + if(index < (vec.size()-1)) + { + Vector> nextTypes = cartProductType(vec,index+1); + for(Type t : myTypes) + { + for(Vector tt : nextTypes) + { + Vector actual = copyVectorType(tt); + actual.insertElementAt(t.clone(),0); + retVec.add(actual); + } + } + } + else + { + for(Type t : myTypes) + { + Vector tVec = new Vector(); + tVec.insertElementAt(t.clone(),0); + retVec.add(tVec); + } + } + return retVec; + } + + /** + * Überladung der Funktion cartProductPair, damit der Programmierer beim ersten Aufruf nicht den 2. Parameter + * welcher für die rekursion erforderlich ist mit übergeben muss. + */ + private static Vector> cartProductPair (Vector> vec) + { + return cartProductPair(vec,0); + } + + /** + * Erzeugt das Kartesische Product von mehreren Vectoren von Paaren. + * Für den Startaufruf ist der index = 0. Danach ruft sich cartProductPair rekursiv auf. + */ + private static Vector> cartProductPair (Vector> vec, int index) + { + Vector> retVec = new Vector>(); + if(vec.isEmpty()) return retVec; + + Vector myPairs = vec.get(index); + + if(index < (vec.size()-1)) + { + Vector> nextPairs = cartProductPair(vec,index+1); + for(Pair p : myPairs) + { + for(Vector pp : nextPairs) + { + Vector actual = copyVectorPair(pp); + actual.insertElementAt(p.clone(),0); + retVec.add(actual); + } + } + } + else + { + for(Pair p : myPairs) + { + Vector tVec = new Vector(); + tVec.insertElementAt(p.clone(),0); + retVec.add(tVec); + } + } + return retVec; + } + + /** + * Kopiert einen Vector. Es ist eine Deep Copy, da die Elemente auch kopiert werden. + */ + private static Vector copyVectorType(Vector vec) + { + Vector retVec = new Vector(); + for(Type t : vec) + retVec.add(t.clone()); + + return retVec; + } + + /** + * greaterArg Schritt von greater + * Für den Argumenttype FunN<...> werden keine ? extends-, ? super-Typen erzeugt + */ + private static Vector greaterArg(Type T, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + if(T instanceof ExtendsWildcardType) + { + //Bei einer ExtendsWildcard Rekursiv greater0 aufrufen und neue ExtendsWildcars erzeugen + ExtendsWildcardType exT = (ExtendsWildcardType)T; + Vector greaterTypes = greater0(exT.get_ExtendsType(),fc_tto); + for(Type t : greaterTypes) + retVec.add(new ExtendsWildcardType(t.getOffset(),t.clone())); + } + else if(T instanceof SuperWildcardType) + { + //Bei einer SuperWildcard Rekursiv smaller0 aufrufen und neue SuperWildcards erzeugen. + SuperWildcardType suT = (SuperWildcardType)T; + Vector smallerTypes = smaller0(suT.get_SuperType(),fc_tto); + for(Type t : smallerTypes) + retVec.add(new SuperWildcardType(t.getOffset(),t.clone())); + } + else if(T instanceof FreshExtendsWildcardType) + { + //Bei einer FreshExtendsWildcard greaterArg aufrufen, auf Bounds achten. + retVec.add(T); + retVec.add(new ExtendsWildcardType(T.getOffset(),T.clone())); + + FreshExtendsWildcardType fexT = (FreshExtendsWildcardType)T; + ExtendsWildcardType extT = new ExtendsWildcardType(fexT.get_ExtendsBound().getOffset(), fexT.get_ExtendsBound().clone()); + + //Vector tmp = greaterArg(fexT.get_ExtendsBound(),fc_tto); //hier stimmt es nicht PL 07-07-21 + Vector tmp = greaterArg(extT,fc_tto); + //for(int i = 0; i(); + //Diese Abfrage sorgt für grArg(a) = {a} //Luar 07-07-31 + else if(T instanceof TypePlaceholder) + retVec.add(T); + //Diese Abfrage verhindert, dass bei FunN Wildcard-Typen generiert werden //PL 13-05-22 + else if((T instanceof RefType) && (T.getName().equals("FunN"))) + retVec.add(T); + else + { + //Bei allen anderen Typen greater0 und smaller0 aufrufen. + retVec.add(T); + Vector greaterTypes = greater0(T,fc_tto); + Vector smallerTypes = smaller0(T,fc_tto); + for(Type t : greaterTypes) + retVec.add(new ExtendsWildcardType(t.getOffset(),t.clone())); + + for(Type t : smallerTypes) + retVec.add(new SuperWildcardType(t.getOffset(),t.clone())); + } + return retVec; + } + + /** + * greater2 Schritt von greater + */ + private static Vector greater2(Vector greater1Erg, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + /* + * luar 02-05-07: Beschreibung der Funktion: + * Für Jeden Typ aus greater1 durch die FC laufen, und auf der Linken seite einen Match versuchen. + * Wenn das Funktioniert, dann ist der Typ auf der rechten Seite auch greater. + * */ + Hashtable ht = new Hashtable(); + for(Type t : greater1Erg) + { + for(Pair p : fc_tto.getFC()) + { + ht.clear(); + if(p.TA2 instanceof RefType && p.TA1 instanceof RefType && t instanceof RefType) + { + try + { + match((RefType)p.TA1,(RefType)t,ht); + ht = CaptureConversionHashtable(ht,fc_tto); + for(Type tt : ht.values()) + { + if(tt instanceof WildcardType) + throw new MatchException("Wildcards not allowed"); + } + + //Macht hat funktioniert. In Linker Seite Typen substituieren + RefType TA2neu = ((RefType)p.TA2).clone(); + SubstHashtableGeneric(TA2neu,ht); + + //TA2neu ist greater als T. Einfügen in retVec + if(!retVec.contains(TA2neu)) + retVec.add(TA2neu); + } + catch(MatchException ex) + {} + } + } + } + return retVec; + } + + /** + * greater3 Schritt von greater + */ + private static Vector greater3(Vector greater2Erg, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + for(Type t : greater2Erg) + { + Vector greater1Erg = greater1(t,fc_tto); + for(Type tt : greater1Erg) + if(!retVec.contains(tt)) + retVec.add(tt); + } + return retVec; + } + + //Von hier an Smaller implementierung luar 28-03-07 + /** + * Der Komplette Ablauf von smaller und was die einzelnen Teilschritte machen kann anhand von Aktivitätsdiagrammen + * im Inovator Projekt, oder in der Studienarbeit Arne Lüdtke, 2007 nachgelesen werden. + */ + + /** + * Erzeugt alle Typen die smaller sind als T. Gibt diese zurück. + */ + private static Vector smaller(Type T, FC_TTO fc_tto) + //an die Aenderungen im Skript anpassen 07-11-03 + { + Vector retVec = new Vector(); + Vector smaller0Erg = smaller0(T,fc_tto); + for(Type t : smaller0Erg) + { + if(!DelFreshWildcardTypeVar(t)) + retVec.add(t); + } + return retVec; + } + + /** + * smaller0 Schritt von smaller + */ + private static Vector smaller0(Type T, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + + Vector smaller1Erg = smaller1(T,fc_tto); + Vector smaller2Erg = smaller2(smaller1Erg,fc_tto); + + //Unite von smaller 1 und 2 bilden, um dies an smaller 3 weiterzugeben. + Vector smaller12Erg = copyVectorType(smaller1Erg); + for(Type t : smaller2Erg) + if(!smaller12Erg.contains(t)) + smaller12Erg.add(t); + + if(!smaller12Erg.contains(T)) + smaller12Erg.add(T); + + //Ergebnise in retVec einfügen. Doppelte werden gelöscht. + for(Type t : smaller12Erg) + if(!retVec.contains(t)) + retVec.add(t); + + //Ergebnis von smaller1 und smaller2 an smaller3 weitergeben, Ergebnisse einfügen. + Vector smaller3Erg = smaller3(smaller12Erg,fc_tto); + for(Type t : smaller3Erg) + if(!retVec.contains(t)) + retVec.add(t); + + //Ergebnisse von smaller3 an smaller4 weitergeben, Ergebnisse einfügen. + Vector smaller4Erg = smaller4(smaller3Erg); + for(Type t : smaller4Erg) + if(!retVec.contains(t)) + retVec.add(t); + + return retVec; + } + + /** + * smaller1 Schritt von smaller + */ + private static Vector smaller1(Type T, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + if(T instanceof RefType) + { + RefType refT = (RefType)T; + if(refT.get_ParaList() != null && refT.get_ParaList().size() > 0) + { + Vector> types = new Vector>(); + Vector paras = refT.get_ParaList(); + //Smaller Arg von jedem Parameter einsammeln. + for(int i = 0; i> kart = cartProductType(types); + //Mit den neuen Parameterlisten neue Typen klonen, Parameterlisten zuweisen + for(Vector t : kart) + { + RefType dolly = refT.clone(); + dolly.set_ParaList(t); + retVec.add(dolly); + } + } + } + return retVec; + } + + /** + * smallerArg Schritt von smaller + */ + private static Vector smallerArg(Type T, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + if(T instanceof ExtendsWildcardType) + { + //Für eine ExtendsWildcard rekursiv smaller0 aufrufen, und neue Wildcards erzeugen. + ExtendsWildcardType exT = (ExtendsWildcardType)T; + Vector smallerTypes = smaller0(exT.get_ExtendsType(),fc_tto); + for(Type t : smallerTypes) + { + retVec.add(new ExtendsWildcardType(t.getOffset(),t.clone())); + retVec.add(t.clone()); + } + } + else if(T instanceof SuperWildcardType) + { + //Für eine SuperWildcard rekursiv greater0 aufrufen, unr neue Wildcards erzeugen. + SuperWildcardType suT = (SuperWildcardType)T; + Vector greaterTypes = greater0(suT.get_SuperType(),fc_tto); + for(Type t : greaterTypes) + { + retVec.add(new SuperWildcardType(-1,t.clone())); + retVec.add(t.clone()); + } + } + else if(T instanceof FreshExtendsWildcardType) + return new Vector(); //HIER NOCH T EINFUEGEN 07-11-03 PL + + else if(T instanceof FreshSuperWildcardType) + {//HIER AUCH NUR T EINFUEGEN 07-11-03 PL + FreshSuperWildcardType fsuT = (FreshSuperWildcardType)T; + return smallerArg(fsuT.get_SuperBound(),fc_tto); + } + else + retVec.add(T); + + return retVec; + } + + /** + * smaller2 Schritt von smaller + */ + private static Vector smaller2(Vector smaller1Erg, FC_TTO fc_tto) + { + return CaptureConversion(smaller1Erg,fc_tto); + } + + /** + * smaller3 Schritt von smaller + */ + private static Vector smaller3(Vector smaller12Erg, FC_TTO fc_tto) + { + Vector retVec = new Vector(); + /* + * luar 02-05-07: Beschreibung der Funktion: + * Für Jeden Typ aus Smaller12 durch die FC laufen, und auf der Rechten seite einen Match versuchen. + * Wenn das Funktioniert, dann ist der Typ auf der linken Seite auch smaller. + * */ + Hashtable ht = new Hashtable(); + for(Type t : smaller12Erg) + { + for(Pair p : fc_tto.getFC()) + { + ht.clear(); + if(p.TA2 instanceof RefType && p.TA1 instanceof RefType && t instanceof RefType) + { + try + { + match((RefType)p.TA2,(RefType)t,ht); + for(Type tt : ht.values()) + { + if(tt instanceof WildcardType) + throw new MatchException("Wildcards not allowed"); + } + + //Macht hat funktioniert. In Linker Seite Typen substituieren + RefType TA1neu = ((RefType)p.TA1).clone(); + SubstHashtableGeneric(TA1neu,ht); + //TA1neu ist smaller als T. Einfügen in retVec + if(!retVec.contains(TA1neu)) + retVec.add(TA1neu); + } + catch(MatchException ex) + {} + } + } + } + return retVec; + } + + /** + * smaller4 Schritt von smaller + */ + private static Vector smaller4(Vector smallerErg) + { + /* smaller4 ist die inverse CaptureConversion. + * Alle Typen in smallerErg werden durchlaufen, und evtl. gefundene + * FreshWildcardTypes werden durch die entsprechenden Wildcards ersetzt. + * */ + Vector retVec = new Vector(); + for(Type t : smallerErg) + { + if(t instanceof RefType) + { + RefType refT = (RefType)t.clone(); + if(refT.get_ParaList() != null) + { + Vector paras = refT.get_ParaList(); + for(int i = 0; i set = new CTypeAssumptionSet(); + set.unite((CSet)substSet); + } +} diff --git a/src/typinferenz/ConstraintsSet.java b/src/typinferenz/ConstraintsSet.java new file mode 100644 index 000000000..ba5aa979e --- /dev/null +++ b/src/typinferenz/ConstraintsSet.java @@ -0,0 +1,61 @@ +package typinferenz; + +import java.util.Iterator; +import java.util.Vector; + +import mycompiler.mytype.Pair; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CSet; +import mycompiler.mytypereconstruction.set.CTripleSet; +import mycompiler.mytypereconstruction.set.CVectorSet; + +public class ConstraintsSet implements Iterable{ + private Vector constraintsSet; + + public ConstraintsSet(){ + constraintsSet = new Vector(); + } + + public void add(ConstraintsSet CSet){ + for(OderConstraint element : CSet) + add(element); + } + public void add(OderConstraint constraint){ + constraintsSet.add(constraint); + } + + /** + * Liefert alle Constraint-Variationen + * @return + */ + public Vector> getConstraints(){ + Vector> ret = new Vector>(); + for(OderConstraint con : constraintsSet){ + ret.add(con.getUndConstraints()); + } + ret = new KarthesischesProdukt().berechneKarthesischesProdukt(ret); + /*Vector firstConstraints = new Vector(); + for(Constraint con : constraintsSet){ + firstConstraints.addAll(con.getConstraintPairs()); + } + ret.add(firstConstraints); + */ + return ret; + } + + @Override + public String toString(){ + String ret =""; + for(OderConstraint constraint : this){ + ret += constraint.toString()+"\n"; + } + return ret; + } + + public Iterator iterator() { + return constraintsSet.iterator(); + } + + + +} diff --git a/src/typinferenz/FreshTypeVariable.java b/src/typinferenz/FreshTypeVariable.java new file mode 100644 index 000000000..e381f3aba --- /dev/null +++ b/src/typinferenz/FreshTypeVariable.java @@ -0,0 +1,38 @@ +package typinferenz; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import mycompiler.mytype.Type; + +public class FreshTypeVariable extends Type{ + + private String hint = ""; + + public FreshTypeVariable(int offset) { + super(offset); + } + + /** + * Aufruf für Debug-Zwecke. + * @param hint - Eine Message die von der toString - Methode ausgegeben wird. + */ + public FreshTypeVariable(String hint){ + this(0); + this.hint = hint; + } + + public FreshTypeVariable(){ + this(0); + } + + @Override + public String toString(){ + if(hint.length()>0)return hint+" : a"; + return "FreshTypeVariable"; + } + + @Override + + public JavaCodeResult printJavaCode(ResultSet resultSet) { + throw new NotImplementedException(); + } +} diff --git a/src/typinferenz/FunN.java b/src/typinferenz/FunN.java new file mode 100644 index 000000000..44284ff5d --- /dev/null +++ b/src/typinferenz/FunN.java @@ -0,0 +1,150 @@ +package typinferenz; + + +import java.util.Iterator; +import java.util.Vector; + +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; +import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; + +/** + * @see Spezifikation "Complete Typeinference in Java 8" von Martin Plümicke + * "interface FunN { R apply(T1 arg1, T2 arg2, ... , TN argN); }" + * @author A10023 - Andreas Stadelmeier + * + */ +public class FunN extends RefType implements ITypeReplacementListener{ + + private Type R; + private Vector T; + + /** + * @author Andreas Stadelmeier, a10023 + * Benötigt für den Typinferenzalgorithmus für Java 8 + * Generiert einen RefType auf eine FunN - Klasse. + * @param R + * @param T + * @return + */ + public FunN(Type R, Vector T) { + super("",null,0); + if(T==null || R == null)throw new NullPointerException(); + setT(T); + setR(R); + this.name = "Fun"+T.size();//getName(); + } + + /** + * Erstellt eine FunN: + * FunN + * R und T1 - TparameterCount werden mit TypePlaceholdern besetzt. + * @param parameterCount + */ + public FunN(int parameterCount) { + super("",null,0); + if(parameterCount<0)throw new RuntimeException("Anzahl der Parameter muss >0 sein"); + Vector t = new Vector(); + for(int i=0;i t = new Vector(); + for(int i=0;i t = new Vector(); + if(R!=null)t.add(R); + if(T!=null)t.addAll(T); + this.set_ParaList(t); + } + + protected void setT(Vector T){ + this.T = T; + calculateNewParalist(); + //ReplacementListener registrieren: + for(Type t : T)if(t instanceof TypePlaceholder)((TypePlaceholder)t).addReplacementListener(this); + } + protected void setR(Type R){ + this.R = R; + calculateNewParalist(); + //Sind die übergebenen Typen TypePlaceholder, so soll die FunN über TypReplacements informiert werden. + if(R instanceof TypePlaceholder){ + ((TypePlaceholder)R).addReplacementListener(this); + } + } + + /* + @Override + public String getName(){ + String ret = "FunN<"+R.toString(); + for(Type t : T){ + ret += ", " + t.toString(); + } + ret += ">"; + return ret; + } +*/ + public void replaceType(CReplaceTypeEvent e) { + if(R.equals(e.getOldType()))R=e.getNewType(); + for(Type t : T){ + if(t.equals(e.getOldType()))T.setElementAt(e.getNewType(),T.indexOf(t)); + } + } + + public int getTypeLineNumber() { + // TODO Auto-generated method stub + return 0; + } + + public CMethodTypeAssumption toCMethodTypeAssumption() { + CMethodTypeAssumption ret = new CMethodTypeAssumption(this, "apply", R, this.T.size(), 0,this.getOffset(),new Vector(),null); + for(Type t : T){ + ret.addParaAssumption(TypeAssumptions.createCParaTypeAssumption(t.get_Name(), t)); + } + return ret; + } + + @Override + public JavaCodeResult printJavaCode(ResultSet resultSet){ + //String ret = super.printJavaCode(resultSet) + (T!=null ? this.T.size() : 0) +"<"; + JavaCodeResult ret = new JavaCodeResult("Fun" + (T!=null ? this.T.size() : 0) +"<"); + ret .attach( this.R.printJavaCode(resultSet)).attach(", "); + Iterator it = T.iterator(); + while(it.hasNext()){ + Type t = it.next(); + ret.attach( t.printJavaCode(resultSet)); + if(it.hasNext())ret.attach(", "); + } + //ret = ret.substring(0, ret.length()-2); + return ret.attach(">"); + } + + /** + * Ein Überschreiben der clone-Methode ist notwendig, da sonst beim Unify-Algorithmus die Clone-Methode der Superklasse "RefType" ausgeführt wird. + */ + @Override + public RefType clone() + { + return new FunN(this.R,this.T); + } +} diff --git a/src/typinferenz/JavaCodeResult.java b/src/typinferenz/JavaCodeResult.java new file mode 100644 index 000000000..757e35a0e --- /dev/null +++ b/src/typinferenz/JavaCodeResult.java @@ -0,0 +1,56 @@ +package typinferenz; + +import java.util.Vector; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import mycompiler.mytype.TypePlaceholder; + +public class JavaCodeResult{ + + private String javaCode = ""; + private Vector unresolvedTPHs = new Vector(); + + public JavaCodeResult(){ + + } + + public JavaCodeResult(String javaCode){ + this.javaCode += javaCode; + } + + public String getJavaCode(){ + return javaCode; + } + + public JavaCodeResult attach(JavaCodeResult javaCodeResult){ + this.javaCode += javaCodeResult.getJavaCode(); + //Alle TPH anfügen: + for(TypePlaceholder tph : javaCodeResult.getUnresolvedTPH())this.addUnresolvedTPH(tph); + return this; + } + + public JavaCodeResult attach(String javaCode){ + this.javaCode += javaCode; + return this; + } + + public void addUnresolvedTPH(TypePlaceholder typePlaceholder) { + unresolvedTPHs.add(typePlaceholder); + } + + public Vector getUnresolvedTPH(){ + return unresolvedTPHs; + } + + @Override + public String toString(){ + return getJavaCode(); + } + + @Override + public boolean equals(Object obj){ + throw new NotImplementedException(); + } + +} diff --git a/src/typinferenz/KarthesischesProdukt.java b/src/typinferenz/KarthesischesProdukt.java new file mode 100644 index 000000000..7add75e30 --- /dev/null +++ b/src/typinferenz/KarthesischesProdukt.java @@ -0,0 +1,60 @@ +package typinferenz; + +import java.util.Vector; + +public class KarthesischesProdukt { + + public Vector> berechneKarthesischesProdukt(Vector> m1){ + if(m1.size()<2)return m1;//throw new TypinferenzException("m1 hat zu wenige Objekte für ein Karthesisches Produkt. Es müssen mindestens 2 sein."); + return berechneKarthesischesProdukt(m1, null); + } + + private Vector> berechneKarthesischesProdukt(Vector> m1, Vector> result){ + if(m1.size()==0)return result; + if(result == null){ + result = new Vector>(); + result.add(new Vector()); + } + Vector o1 = m1.remove(0); + Vector> newResult = new Vector>(); + for(Vector o2 : result){ + Vector> xProd = karthesischesProdukt(o2,o1); + //System.out.println("karthesischesProdukt( "+o2+" , "+o1+" ) \n = "+xProd); + newResult.addAll(xProd); + //result.addAll(karthesischesProdukt(o1, o2)); + } + return berechneKarthesischesProdukt(m1, newResult); + /* + Vector> ret = null; + Iterator> it = m1.iterator(); + while(it.hasNext()){ + + } + if(m1.size()>1){ + ret = new Vector>(); + }else if(m1.size() == 1){ + ret = new Vector>(); + ret.addAll( karthesischesProdukt2(m1.firstElement(), m2) ); + }else{ + throw new TypinferenzException("Der übergebene Vektor m1 ist leer."); + } + + return ret;*/ + } + + private Vector> karthesischesProdukt(Vector m1, Vector m2){ + Vector> ret = new Vector>(); + //for(M o1 : m1){ + for(M o2 : m2){ + Vector v1 = new Vector(); + //for(M o1 : m1)v1.add(o1); + v1.addAll(m1); + v1.add(o2); + //System.out.println("g: "+v1); + ret.add(v1); + } + //} + return ret; + } + +} diff --git a/src/typinferenz/OderConstraint.java b/src/typinferenz/OderConstraint.java new file mode 100644 index 000000000..f3208bd21 --- /dev/null +++ b/src/typinferenz/OderConstraint.java @@ -0,0 +1,82 @@ +package typinferenz; + +import java.util.Vector; + +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; + +public class OderConstraint{ + private Vector oderConstraintPairs; + + /** + * Erstellt ein neues Oder Constraint und fügt bereits ein Constraint hinzu. + * @param p1 + * @param p2 + */ + public OderConstraint(Type p1, Type p2){ + Pair constraintPair = new Pair(p1,p2); + oderConstraintPairs = new Vector(); + this.addConstraint(constraintPair); + } + + public OderConstraint(){ + oderConstraintPairs = new Vector(); + } + + + /** + * Liefert alle in diesem OderConstraint enthaltene Constraints. Dabei gehen die Verknüpfungen (Oder/Und) verloren. + * @return + */ + public Vector getConstraintPairs(){ + Vector ret = new Vector(); + for(UndConstraint oC : this.oderConstraintPairs){ + ret.addAll(oC.getConstraintPairs()); + } + return ret; + } + + /** + * Fügt ein Pair(p1, p2) dem Constraint hinzu + * @param p1 + * @param p2 + */ + public void addConstraint(Type p1, Type p2){ + addConstraint(new Pair(p1,p2)); + } + + /** + * Falls die Type des toAdd-Pairs nicht vom Typ RefType bzw. TypePlaceholder sind, so werden sie in einen RefType umgewandelt. + * @param toAdd + */ + public void addConstraint(Pair toAdd){ + oderConstraintPairs.add(new SingleConstraint(toAdd.TA1, toAdd.TA2)); + } + + @Override + public String toString(){ + String ret = "["; + for(Pair p : this.getConstraintPairs()){ + ret += p.toString()+ ", "; + } + return ret+"]"; + } + + public Vector getUndConstraints() { + return this.oderConstraintPairs; + /* + Vector ret = new Vector(); + for(Pair p : this.getConstraintPairs()){ + ret.add(new UndConstraint(p.TA1,p.TA2)); + } + return ret; + */ + } + + public void addConstraint(UndConstraint methodConstraint) { + oderConstraintPairs.add(methodConstraint); + } + +} diff --git a/src/typinferenz/Overloading.java b/src/typinferenz/Overloading.java new file mode 100644 index 000000000..d900de5d3 --- /dev/null +++ b/src/typinferenz/Overloading.java @@ -0,0 +1,84 @@ +package typinferenz; + +import java.util.Vector; + +import mycompiler.mystatement.MethodCall; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; + +/** + * + * @author Andreas Stadelmeier, a10023 + * + */ +public class Overloading{ + + private TypeAssumptions assumptions; + private MethodCall methodCall; + private Type type; + + /** + * methodCall : type + * @param ass + * @param method + * @param type - eine Type-Assumption/oder Type für den Rückgabetyp des MethodCall + */ + public Overloading(TypeAssumptions ass, MethodCall method, Type type){ + assumptions = ass.clone(); + methodCall = method; + this.type = type; + } + + /** + * Vereinfachte Version von Overloading... + * Es darf nur die erste gefundene Assumption verwendet werden, sonst widersprüchliche constraints + * + * Spezifikation: + * overloading determines for all possible overloadings and overridings + * of a method the constraints, where constraints itself forms + * the constraints from the receiver type, the argument types, the return + * type and a given type assumption for the method. If it is a + * method from a class, which is not the actual class (this), all type + * variables are replaced by fresh type variables (fresh), as different + * instances can occur. sargs determines all type assumptions of a + * method, where the argument types are supertypes of a minimal type + * assumption. + * + * @TODO: wenn es sich um eine Methode einer anderen Klasse handelt, müssen neue TPH vergeben werden und nicht die der Assumption verwendet werden. + * + * @return + */ + public OderConstraint generateConsstraints(){ + OderConstraint ret = new OderConstraint(); + for(CMethodTypeAssumption assumption : assumptions.getMethodAssumptions(methodCall.getName(), methodCall.getArgumentList().size())){ + if(!(this.type instanceof TypePlaceholder) && !this.type.equals(assumption.getAssumedType()))break; + UndConstraint methodConstraint = new UndConstraint(); + //Ein Constraint für den ReturnType der Methode... + methodConstraint.addConstraint(assumption.getAssumedType(), type); + //Ein Constraint für die Parameter der Methode... + for(int i=0; i parameterAssumptions = new Vector(); + parameterAssumptions.add(assumption.getAssumedType()); + for(CParaTypeAssumption pAss : assumption.getParaAssumptions() ){ + parameterAssumptions.add(pAss.getAssumedType()); + } + //Ein Constraint für den Receiver der Methode (falls vorhanden)... + //ret.add(new Constraint(methodCall.get_Receiver().get_Expr().getTypeVariable(), new RefType(assumption.getClassName(), null, 0))); + if(methodCall.get_Receiver() != null && methodCall.get_Receiver().get_Expr() != null) + methodConstraint.addConstraint(methodCall.get_Receiver().get_Expr().getTypeVariable(), assumption.getClassType()); + //ret.add(new Constraint(methodCall.get_Receiver().get_Expr().getTypeVariable(), new RefType(assumption.getClassName(), parameterAssumptions, 0))); + + //return ret; //Bereits nach der ersten Assumption abbrechen... + ret.addConstraint(methodConstraint); + } + return ret; + } + +} diff --git a/src/typinferenz/ResultSet.java b/src/typinferenz/ResultSet.java new file mode 100644 index 000000000..274bf02d5 --- /dev/null +++ b/src/typinferenz/ResultSet.java @@ -0,0 +1,74 @@ +package typinferenz; + +import java.util.Iterator; +import java.util.Vector; + +import mycompiler.mytype.Pair; +import mycompiler.mytype.Type; + +/** + * Im Grunde Sammlung von Pair s mit Equal-Operatoren. + * + * @author Andreas Stadelmeier, a10023 + * + */ +public class ResultSet implements Iterable { + + Vector resultPairs; + + public ResultSet(Vector resultSet){ + resultPairs = resultSet; + } + + public Vector getResultSet(){ + return resultPairs; + } + + /** + * Löst den übergebenen Typ auf. Rückgabetyp ist ein Reftype oder Void + * @param type + * @return + */ + public Type getTypeEqualTo(Type type) { + Type res = type; + Vector modifiedResultPairs = (Vector) resultPairs.clone(); + int i = findPairWithTypeEqualTo(type, modifiedResultPairs); + while(i != -1){ + res = modifiedResultPairs.get(i).TA2; + modifiedResultPairs.remove(i); + i = findPairWithTypeEqualTo(res, modifiedResultPairs); + } + return res; + } + + private int findPairWithTypeEqualTo(Type type, Vector inResultPairs){ + for(int i = 0; i iterator() { + return this.getResultSet().iterator(); + } + + /** + * Durchsucht das ResultSet (die unifizierten Constraints des ResultSets) nach diesem Typ. Der Typ wird nicht aufgelöst. + * Es spielt keine Rolle in welchem Kontext der Typ im ResultSet auftaucht. + * @param tA1 + * @return true, falls der gesuchte Typ enthalten ist. + */ + public boolean contains(Type tA1) { + for(Pair p : this){ + if(p.TA1.equals(tA1)||p.TA2.equals(tA1))return true; + } + return false; + } + + @Override + public String toString(){ + return this.getResultSet().toString(); + } + +} diff --git a/src/typinferenz/SingleConstraint.java b/src/typinferenz/SingleConstraint.java new file mode 100644 index 000000000..e15b921b3 --- /dev/null +++ b/src/typinferenz/SingleConstraint.java @@ -0,0 +1,65 @@ +package typinferenz; + +import java.util.Vector; + +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CTriple; +import mycompiler.mytypereconstruction.set.CTripleSet; + +/** + * Beschreibung von Herrn Plümicke: + * "The set of constraints consists of constraints of the form θ R θ' , where θ and + * θ' are Java types and R (R ∈ { < , getConstraintPairs(){ + Vector ret = new Vector(); + ret.add(constraintPair); + return ret; + } + + public void addConstraint(Pair toAdd){ + if(constraintPair != null)throw new TypinferenzException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich."); + + Type p1 = toAdd.TA1; + Type p2 = toAdd.TA2; + if(p1==null || p2 == null)throw new NullPointerException(); + + // BaseTypes werden in RefTypes umgewandelt. Constraints dürfen nur RefTypes oder TypePlaceholder enthalten, da sonst der Unify-Algorithmus nicht funktioniert. + if(!(p1 instanceof RefType) && !(p1 instanceof TypePlaceholder))p1 = new RefType(p1); + if(!(p2 instanceof RefType) && !(p2 instanceof TypePlaceholder))p2 = new RefType(p2); + + //if(!(TypePlaceholder.class.isInstance(p1)) || !(RefType.class.isInstance(p1)) || !(TypePlaceholder.class.isInstance(p2)) || !(RefType.class.isInstance(p2))) + //{//Wenn die beiden übergebenen Typen weder RefTypes noch TypePlaceholder sind: + // throw new TypinferenzException("Ein Constraint darf nur aus TypePlaceholdern und Reftypes bestehen"); + //} + constraintPair = new Pair(p1,p2); + } + + @Override + public String toString(){ + return ""+constraintPair.TA1.toString()+" < "+constraintPair.TA2.toString(); + } +} diff --git a/src/typinferenz/Typable.java b/src/typinferenz/Typable.java new file mode 100644 index 000000000..70fc197ee --- /dev/null +++ b/src/typinferenz/Typable.java @@ -0,0 +1,15 @@ +package typinferenz; + +import mycompiler.mytype.Type; + +public interface Typable { + /** + * @author Andreas Stadelmeier, a10023 + * Jede Expression und jedes Statement muss im Zuge des Typinferenzalgorithmus das Interfece Typable einbinden. + * Die Funktion setTypeVariable muss während des durchlaufens des Typinferenzalgorithmus einmalig für jedes Statement und jede Expression aufgerufen werden. + * Dabei kann auch eine FreshTypeVariable als Typ vergeben werden. + * @param typ Der Typ der Typable-Expression/Statement + */ + void setTypeVariable(Type typ); + Type getTypeVariable(); +} diff --git a/src/typinferenz/TypeAssumptions.java b/src/typinferenz/TypeAssumptions.java new file mode 100644 index 000000000..ec775ffab --- /dev/null +++ b/src/typinferenz/TypeAssumptions.java @@ -0,0 +1,288 @@ +package typinferenz; + +import java.util.Iterator; +import java.util.Vector; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +/** + * Eine Sammlung von TypeAssumptions. + * Jede Expression und jedes Statement erhält beim Aufrufen ihrer TYPE-Methode ein AssumptionSet mit den Assumptions ihrer Umgebung als Parameter übergeben. + * @author janulrich + * + */ +public class TypeAssumptions implements Iterable { + + //private static CTypeAssumptionSet globalAssumptions = new CTypeAssumptionSet(); + private String thisClassName; + + //private Vector assumptions; + CTypeAssumptionSet assumptions = new CTypeAssumptionSet(); + + public TypeAssumptions(){ + assumptions = new CTypeAssumptionSet(); + } + + /** + * Dieser Konstruktor setzt bei der Initialisierung auch den Wert von "this" + * @param klassenname - Wert für "this" + */ + public TypeAssumptions(String klassenname){ + this(); + this.setThisClassname(klassenname); + } + + public TypeAssumptions(CTypeAssumptionSet ass, String classname){ + assumptions = ass; + this.setThisClassname(classname); + } + + public TypeAssumptions(TypeAssumptions assumptions2) { + assumptions = new CTypeAssumptionSet(); + this.add(assumptions2); + } + + /** + * Im AssumptionSet muss je nach Umfeld der Wert von "this" neu gesetzt werden. + * Dies übernimmt diese Funktion. + * @param name - Der Klassenname der von this referenzierten Klasse. + */ + public void setThisClassname(String name){ + this.thisClassName = name; + } + + /** + * Erstellt eine CInstVarTypeAssumption und fügt sie den Assumptions hinzu. + * @param className + * @param identifier + * @param assumedType + */ + public void addInstVarAssumption(String className, String identifier, Type assumedType){ + this.add(createFieldVarAssumption(className, identifier, assumedType)); + } + + + /** + * Ruft createMethodAssumption auf und fügt die Assumption dem AssumptionSet hinzu + * @param classType + * @param identifier + * @param assumedType + * @param parameterTypes + */ + public void addMethodAssumption(Type classType, String identifier, Type assumedType, Vector parameterTypes){ + CMethodTypeAssumption ass = createMethodAssumption(classType, identifier, assumedType, parameterTypes); + this.add(ass); + } + + /** + * + * @param className + * @param identifier + * @param assumedType - ReturnTyp der Methode + * @param parameterTypes - Liste der Parameter der Methode. TIPP: Zur Erstellung der CParaTypeAssumption-Liste kann die Methode TypeAssumptions.createCParaTypeAssumption verwendert werden. + */ + public static CMethodTypeAssumption createMethodAssumption(Type classType, String identifier, Type assumedType, Vector parameterTypes){ + CMethodTypeAssumption ass = new CMethodTypeAssumption(classType, identifier, assumedType, parameterTypes.size(), 0, 0, null, null); + for(CParaTypeAssumption paraAssumption : parameterTypes){ + //Es wird eine neue ParameterAssumption generiert. Nur der Identifier und der AssumedType der CParaTypeAssumption wird dabei übernommen. + CParaTypeAssumption newParaAssumption = new CParaTypeAssumption(classType.get_Name(), identifier, parameterTypes.size(),0, paraAssumption.getIdentifier(), paraAssumption.getAssumedType(), 0,0,null); + ass.addParaAssumption(newParaAssumption); + } + return ass; + } + + public static CInstVarTypeAssumption createFieldVarAssumption(String className, String fieldName, Type type){ + if(className==null || fieldName == null || type == null) throw new TypinferenzException("Ungültige Feld-Assumption"); + CInstVarTypeAssumption ret = new CInstVarTypeAssumption(className, fieldName, type, 0,0,null); + + return ret; + } + + /** + * Erstellt eine CParaTypeAssumption. + * Diese enthält nur den Identifier und den Typ des Parameters. Die Zuordnung zu einer Methode und einer Klasse erhält die Assumption erst durch den Einsatz in der TypeAssumptions.addMethodAssumption. + * @param identifier + * @param assumedType + * @return + */ + public static CParaTypeAssumption createCParaTypeAssumption( String identifier, Type assumedType){ + CParaTypeAssumption ret; + ret = new CParaTypeAssumption( null, null, 0, 0, identifier, assumedType, 0,0, null); + return ret; + } + + public void addLocalVarAssumption(){ + throw new NotImplementedException(); + } + + + + /** + * Durchsucht die Assumptions des aktuellen Gültigkeitsbereichs (lokale Variablen und Felder der aktuellen Klasse) nach einem Eintrag für den übergebenen Variablennamen. + * In den Assumptions wird dann in der Reihenfolge LocalVarAssumptions, FieldAssumption nach dem übergebenen Variablennamen gesucht. + * @param variableName - der Identifier der gesuchten Variablen + * @return - Der Typ für diesen Identifier. + */ + public Type getVarType(String variableName){ + //Zuerst die Parameter durchsuchen + for(CTypeAssumption ass : this.assumptions){//this.getParameterAssumptions(null)){ + if(ass.getIdentifier().equals(variableName))return ass.getAssumedType(); + } + //TODO: Dann die lokalen Variablen + // ... (noch nicht implementiert) + //und zuletzt die Felder der Klasse in dessen Namensraum sich dieses AssumptionSet befindet. + for(CTypeAssumption ass : this.getInstVarAssumptions()){ + if(ass.getIdentifier().equals(variableName))return ass.getAssumedType(); + } + //Wird keine Assumption gefunden, muss ein Fehler vorliegen: + throw new TypinferenzException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden"); + } + + /** + * Ermittelt alle Assumptions zu Instanzvariablen, welche sich in der Klasse "this" befinden, also der Klasse für welche dieses AssumptionSet gültig ist. + * @return + */ + public TypeAssumptions getInstVarAssumptions(){ + String className = this.getThisValue().getName(); + TypeAssumptions ret = new TypeAssumptions(); + for(CTypeAssumption ass : this.assumptions){ + if(ass instanceof CInstVarTypeAssumption && ass.getClassName().equals(className))ret.add(ass); + } + return ret; + } + + /** + * @return - Alle Assumptions dieses AssumptionSets, welche Annahmen für Parameter darstellen + */ + private TypeAssumptions getParameterAssumptions(CMethodTypeAssumption method) { + TypeAssumptions ret = new TypeAssumptions(); + if(method==null)return ret; + for(CParaTypeAssumption ass : method.getParaAssumptions()){ + //if(ass instanceof CParaTypeAssumption)ret.add(ass); + ret.add(ass); + } + return ret; + } + + /** + * Sucht nach MethodAssumptions einer bestimmten Klasse mit einem bestimmten Namen. + * @param className + * @param methodName + * @param parameterCount + * @return + */ + public Vector getMethodAssumptions(String className, String methodName){ + Vector ret = new Vector(); + for(CTypeAssumption ass : this.getAssumptionsFor(className)){ + //System.out.println(ass.getIdentifier()); + if(ass.getIdentifier().equals(methodName) && ass instanceof CMethodTypeAssumption)ret.add((CMethodTypeAssumption)ass); + } + //if(ret.size()==0)throw new TypinferenzException("Eine Methode "+methodName+" ist in den Assumptions nicht vorhanden"); + return ret; + } + + /** + * Sucht nach Assumptions zu einer Methode mit dem Namen methodName und parameterCount Parametern. + * @param methodName + * @param parameterCount Anzahl der Parameter der gesuchten Methoden-Assumption + * @return + */ + public Vector getMethodAssumptions(String methodName, int parameterCount){ + Vector ret = new Vector(); + for(CTypeAssumption ass : assumptions){ + //System.out.println(ass.getIdentifier()); + if(ass.getIdentifier().equals(methodName) && ass instanceof CMethodTypeAssumption){ + CMethodTypeAssumption toAdd = (CMethodTypeAssumption)ass; + if(toAdd.getParaCount() == parameterCount)ret.add(toAdd); + } + } + //Falls es sich um die apply-Methode eines FunN-Interface handelt: + if(methodName.equals("apply")){ //Ein Workaround für den Typinferenzalgorithmus TODO: Das hier rausnehmen. + CMethodTypeAssumption funNAssumption = new FunN(parameterCount).toCMethodTypeAssumption(); + ret.add(funNAssumption); + } + if(ret.size()==0)throw new TypinferenzException("Eine Methode "+methodName+" ist in den Assumptions nicht vorhanden"); + return ret; + } + + + /** + * Fügt dem Assumption-Set eine neue Assumption hinzu. + * @param ass + * @return + */ + public TypeAssumptions add(CTypeAssumption ass){ + if(ass.getAssumedType()==null)ass.setAssumedType(TypePlaceholder.fresh()); + + //if(ass instanceof CParaTypeAssumption)throw new TypinferenzException("ParameterAssumptions müssen einer Methode zugewiesen sein"); + + //globalAssumptions.addElement(ass); + assumptions.addElement(ass); + return this; + } + + public void remove(CTypeAssumption typeAssumption){ + throw new NotImplementedException(); + } + + public TypeAssumptions add(TypeAssumptions assumptions){ + for(CTypeAssumption ass : assumptions){ + this.add(ass); + } + return this; + } + + public TypeAssumptions add(CTypeAssumptionSet assumptionSet){ + assumptions.unite(assumptionSet); + return this; + } + + public Iterator iterator() { + return assumptions.iterator(); + } + + @Override + public TypeAssumptions clone(){ + CTypeAssumptionSet assSet = new CTypeAssumptionSet(); + for(CTypeAssumption ass : assumptions){ + assSet.addElement(ass); + } + return new TypeAssumptions(assSet, thisClassName); + } + + /** + * Jede erstellte Assumption wird von der TypeAssumptions-Klasse gespeichert. + * Diese Funktion ermittelt alle zu einer Klasse gehörenden Assumptions. + * @param classname + * @return Alle Assumptions mit - assumption.getClassname().equals(classname) - der this-Wert ist auf "classname" gesetzt. + */ + public TypeAssumptions getAssumptionsFor(String classname){ + CTypeAssumptionSet assumptions = new CTypeAssumptionSet(); + //for(CTypeAssumption ass : globalAssumptions){ + for(CTypeAssumption ass : this.assumptions){ + if(ass.getClassName().equals(classname))assumptions.addElement(ass); + } + return new TypeAssumptions(assumptions, classname); + } + + @Override + public String toString(){ + return assumptions.toString(); + } + + public Type getThisValue() { + return new RefType(thisClassName, 0); + } + +} diff --git a/src/typinferenz/TypinferenzException.java b/src/typinferenz/TypinferenzException.java new file mode 100644 index 000000000..aa0e082fd --- /dev/null +++ b/src/typinferenz/TypinferenzException.java @@ -0,0 +1,13 @@ +package typinferenz; + +/** + * Eine RuntimeException, welche bei einem Fehler während des Typinferenzalgorithmus ausgelöst wird. + * Dies wird zum Beispiel durch Programmierfehler in der Java-Eingabedatei ausgelöst. + * @author Andreas Stadelmeier, a10023 + * + */ +public class TypinferenzException extends RuntimeException { + public TypinferenzException(String message){ + super(message); + } +} diff --git a/src/typinferenz/UndConstraint.java b/src/typinferenz/UndConstraint.java new file mode 100644 index 000000000..ceb4e3881 --- /dev/null +++ b/src/typinferenz/UndConstraint.java @@ -0,0 +1,35 @@ +package typinferenz; + +import java.util.Vector; + +import mycompiler.mytype.Pair; +import mycompiler.mytype.Type; + +/** + * Stellt ein Constraint dar, welches aus mehreren Constraint-Paaren besteht. Diese gelten alle stets gleichzeitig / sind per "Und" miteinander verknüpft. + * @author janulrich + * + */ +public class UndConstraint extends OderConstraint { + + public UndConstraint(Type p1, Type p2) { + super(p1, p2); + } + + public UndConstraint() { + super(); + } + + @Override + public Vector getUndConstraints() { + Vector ret = new Vector(); + ret.add(this); + return ret; + } + + public String toString(){ + String ret = super.toString(); + return ret.replace(',', '|'); + } + +} diff --git a/src/userinterface/ConsoleInterface.java b/src/userinterface/ConsoleInterface.java new file mode 100644 index 000000000..db6aa697e --- /dev/null +++ b/src/userinterface/ConsoleInterface.java @@ -0,0 +1,71 @@ +package userinterface; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.util.Vector; + +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import typinferenz.TypinferenzException; +import java.util.*; + +import org.apache.log4j.Logger; +import org.apache.log4j.varia.NullAppender; +public class ConsoleInterface { + private static final String directory = System.getProperty("user.dir"); + + /** + * @param args + */ + public static void main(String[] args) { + Vector filenames = new Vector(); + for(String file : args){ + filenames.add(file); + } + Logger.getRootLogger().addAppender(new NullAppender()); // sämtliches Logging unterdrücken + + run(filenames); + } + + public static void run(Vector filenames){ + Vector resultSet = null; + + MyCompilerAPI compiler = MyCompiler.getAPI(); + try{ + ///////////////////////// + // Parsen: + ///////////////////////// + compiler.parse(filenames); + + ///////////////////////// + // Typrekonstruktion: + ///////////////////////// + try{ + resultSet = compiler.typeReconstruction(); + }catch(TypinferenzException texc){ + texc.printStackTrace(); + fail("Fehler bei Typinferenzalgorithmus. Message: "+texc.getMessage()); + } + /////////////////////// + // Ausgabe: + /////////////////////// + if(resultSet == null)System.out.println("Keine Lösung!"); + ArrayList resultJavaCodes = new ArrayList(); + for(CTypeReconstructionResult result : resultSet){ + String javaCode = result.getInterferedClass().printJavaCode(result); + if(!resultJavaCodes.contains(javaCode))resultJavaCodes.add(javaCode); + } + for(String out : resultJavaCodes){ + + System.out.println("\nMögliche Typisierung:\n\n"); + System.out.println(out); + } + }catch(Exception e){ + e.printStackTrace(); + assertNotNull("Fehler bei Typinferenzalgorithmus. Message: "+e.getMessage(), resultSet); + } + } + +} diff --git a/test/mycompiler/test/AbstractInferenceTest.java b/test/mycompiler/test/AbstractInferenceTest.java new file mode 100755 index 000000000..f591a0376 --- /dev/null +++ b/test/mycompiler/test/AbstractInferenceTest.java @@ -0,0 +1,446 @@ +package mycompiler.test; + +import java.io.File; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Vector; + +import junit.framework.TestCase; +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CIntersectionType; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.mytypereconstruction.typeassumptionkey.CMethodKey; +import mycompiler.test.expectationTypes.BlockExpect; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.GenericTypeVarExpect; +import mycompiler.test.expectationTypes.IExpectation; +import mycompiler.test.expectationTypes.IUnknownTypeExpect; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.TypePlaceholderExpect; +import mycompiler.test.expectationTypes.VarExpect; + +import org.apache.log4j.Logger; + +/** Todo: + * - exception handling cannot verify correct exception yet + * + * done: - exception handling + * - commented asserts + * - log4j + * - cmethodkey usage + * - Typeplaceholder support + * @author + * last change: 26-05-08 + */ +public abstract class AbstractInferenceTest extends TestCase { + + private static Logger testlog = Logger.getLogger("funcTest"); + private File javFile=null; + private Expectation expectation=null; + private MyCompilerAPI compiler = MyCompiler.getAPI(); + + protected AbstractInferenceTest(String name, String javFilename) { + super(name); + + javFile = new File(javFilename); + + //retrieve Expectation object from specific Testcase for comparisons + this.expectation = getExpectations(); + } + + /** + * runs the JUnit-Test, calls all compiler steps + * @throws Throwable + */ + public void testSetup() throws Throwable { + //runs all compiler steps, any exception will cause the Test to fail, if not expected + + //enable Logging + Log4jWrapper.getInstance().configureLog4j(); + + try { + testlog.info("Parsing..."); + parseFile(); + testlog.info("Type reconstruction..."); + typeReconstruction(); + testlog.info("Code generation..."); + codeGeneration(); + //checks whether there is an expected exception that has not been thrown + AbstractInferenceTest.assertTrue("exception expected but not found",this.expectation.getExceptions().isEmpty()); + } catch (Exception e) { + testlog.info("Error during compiler step: " + e); + checkForExpectedException(e); + + } + } + + /** + * calls parse() from Compiler-API + * @throws Throwable + */ + + protected void parseFile() + throws Throwable + { + // Parse file + compiler.parse(javFile); + } + + /** + * calls typeReconstruction() from Compiler-API, checks result against expectations and substitutes all types according to first assumption + * @throws Exception + */ + + protected void typeReconstruction() + throws Exception + { + // Typ-Rekonstruktion + Vector resultSet = compiler.typeReconstruction(); + testlog.info("Type reconstruction completed..."); + // Keine Typ-Rekonstruktion erforderlich + if (resultSet == null || resultSet.size() == 0) throw new Exception("Type reconstruction could not be done!"); + + if (this.expectation!=null) { + if(this.expectation.getClasses()!=null) + checkResults(resultSet,this.expectation); + } + else + testlog.info("An Error has occurred receiving the expectations for this testcase: "+ this.javFile); + + CTypeReconstructionResult onePossibility = resultSet.firstElement(); + Iterator substIt = onePossibility.getSubstitutions().getIterator(); + while(substIt.hasNext()){ + CSubstitution subst = (CSubstitution)substIt.next(); + // Substition machen + subst.execute(); + } + } + + /** + * calls codeGeneration from Compiler-API + * @throws Exception + */ + + protected void codeGeneration() + throws Exception + { + // Code generieren + compiler.codeGeneration(); + } + + /** + * compares resultSet from compiler to expectations + * @param resultSet + * @param expect + */ + + protected void checkResults(Vector resultSet, Expectation expect) { + + //iterates thru all available assumption-sets + testlog.info("Starting checking for valid type assumptions..."); + for (int resIndex=0; resIndex < resultSet.size(); resIndex++) { + //checks whether all expected classes, methods, members are available + checkClasses(resultSet.get(resIndex),expect); + //-------------- + //Methods + //-------------- + //iterates through all found methods + for (CIntersectionType vecAssumpt : resultSet.get(resIndex).getMethodIntersectionTypes().values()) { + //for (int i=0; i iter2 = resultSet.get(resIndex).getFieldAndLocalVarAssumptions().values().iterator(); + //while (iter2.hasNext()) { + //CTypeAssumption assumption = iter2.next(); + for (CTypeAssumption assumption : resultSet.get(resIndex).getFieldAndLocalVarAssumptions().values()) { + // local variable + if (assumption instanceof CLocalVarTypeAssumption) { + + CLocalVarTypeAssumption assu = (CLocalVarTypeAssumption)assumption; + if (expect.getClasses().containsKey(assu.getClassName())){ + //current method to compare assumption to: + MethodExpect method = expect.getClasses().get(assu.getClassName()).getMethods().get(new CMethodKey(assu.getClassName(),assu.getMethodName(),assu.getMethodParaCount(),assu.getMethodOverloadedID())); + testlog.debug("assumption: local variable '"+assu.getIdentifier()+"' of '"+assu.getClassName()+":"+assu.getMethodName()+"'"); + testlog.debug("searching in: '"+method.getName()+"'"); + AbstractInferenceTest.assertTrue("block variable '" + assu.getIdentifier() + "' in '" + assu.getMethodName()+ "' not valid or not found!",checkFoundVariable(assu, method.getBlock())); + } + + } + + // member variable + else if (assumption instanceof CInstVarTypeAssumption) { + + CInstVarTypeAssumption assu = (CInstVarTypeAssumption)assumption; + if (expect.getClasses().containsKey(assu.getClassName())){ + //current class to compare assumption to: + ClassExpect classexpect = expect.getClasses().get(assu.getClassName()); + testlog.debug("assumption: member variable '"+assu.getIdentifier()+"' of '"+assu.getClassName()+"'"); + testlog.debug("searching in: '"+classexpect.getName()+"'"); + checkFoundMembers(assu, classexpect.getMembers()); + } + } + } + } + + //verify that every single type assumption that was expected has been detected by the compiler + testlog.info("verifying all expectations have been met"); + AbstractInferenceTest.assertTrue("not all expected types have been found", expectation.verifyTypeExpectationsCompletelyMet()); + } + + /** + * @return returns a vector of class names of tested file + */ + protected abstract Expectation getExpectations(); + + + /** + * checks the return type of a method comparing it to the expectation + * @param assumpt + * @param expect + */ + protected void checkReturnType(Type assumpt, MethodExpect expect) { + if (!expect.getReturntypes().isEmpty()) { + AbstractInferenceTest.assertTrue("found return type " + assumpt.getName() + " is not in expected list", expect.getReturntypes().contains(assumpt)); + + checkBoundedTypes(assumpt,expect.getReturntypes().get(expect.getReturntypes().indexOf(assumpt))); + //remove this expectation to assure, all expectations have been met at least once + if (expect.getReturntypesCopy().contains(assumpt)) + expect.getReturntypesCopy().remove(assumpt); + } + else if ((assumpt instanceof GenericTypeVar || assumpt instanceof TypePlaceholder) && expect.getUnknownReturnType()!=null) { + //expect.addGeneric((GenericTypeVar) assumpt); + + checkUnknownTypes(assumpt, expect.getUnknownReturnType()); + } + else + AbstractInferenceTest.fail("no return type for " + assumpt.getName() +" has been defined in expectation"); + } + + /** + * checks for generic methods comparing them to the expectation + * @param assumpt + * @param expect + */ + protected void checkFoundGenerics(Vector assumpt, Vector expect) { + AbstractInferenceTest.assertTrue("amount of generic variables expected != assumed",((assumpt==null || assumpt.size()==0) && (expect==null || expect.size()==0)) || assumpt.size()==expect.size()); + for (GenericTypeVar typ : assumpt) { + //System.out.println("Generics: " + typ.get_Name() + ((BoundedGenericTypeVar)typ).getBounds() + ", " + expect.indexOf(typ)); + AbstractInferenceTest.assertTrue("Generic " + typ.getName() + " has not been expected",expect.contains(typ)); + + checkBoundedTypes(typ,expect.get(expect.indexOf(typ))); + } + } + + protected void checkBoundedTypes(Type assumed, Type expected) { + if (assumed instanceof BoundedGenericTypeVar) { + AbstractInferenceTest.assertTrue("assumed: BoundedGenericTypeVar, expected:' "+expected.getClass()+"'",expected instanceof BoundedGenericTypeVar); + BoundedGenericTypeVar typBound = (BoundedGenericTypeVar)assumed; + BoundedGenericTypeVar expBound = (BoundedGenericTypeVar)expected; + for (Type t : typBound.getBounds()) { + boolean ret = false; + for (Type e : expBound.getBounds()) { +//System.out.println(" here " + t + " -- " + e); + if (e.equals(t)) { + ret=true; + } + } + AbstractInferenceTest.assertTrue("Bounded generic's type is not equal", ret); + } + } + else if (assumed instanceof GenericTypeVar) { +// System.out.println("GENERICTYPEVAR"); + } + } + + protected void checkUnknownTypes(Type assumed, IUnknownTypeExpect expect) { + if (assumed instanceof GenericTypeVar) { + AbstractInferenceTest.assertTrue("Assumed type is of GenericTypeVar",expect instanceof GenericTypeVarExpect); + } + else if (assumed instanceof TypePlaceholder) { + AbstractInferenceTest.assertTrue("Assumed type is of TypePlaceholder",expect instanceof TypePlaceholderExpect); + } + + String mappedType=this.expectation.getMappings().getMappedType(expect.getName()); + if (mappedType!=null) { + AbstractInferenceTest.assertEquals("Same expected UnknownType mapped to different assumed types",mappedType,assumed.getName()); + } + else + this.expectation.getMappings().addMapping(expect.getName(), assumed.getName()); + } + + /** + * searches recursively for the matching block in the expectation set and compares found variables to the expectation + * @param assumpt + * @param expect + * @return + */ + + protected boolean checkFoundVariable(CLocalVarTypeAssumption assumpt, BlockExpect expect) { + //there is an expectation for a variable + AbstractInferenceTest.assertTrue(expect!=null); + boolean ret=false; + if (expect.getBlockID().equals(assumpt.getBlockId())) { + AbstractInferenceTest.assertTrue("Variable "+assumpt.getIdentifier() + " is not defined in expectation",expect.getLocalVar().containsKey(assumpt.getIdentifier())); + VarExpect varExpect = expect.getLocalVar().get(assumpt.getIdentifier()); + Vector expTypes = varExpect.getExpectedType(); + //check if a specific type for this variable is expected or whether it should be a typeplaceholder/generictypevar + if (!expTypes.isEmpty()) { + AbstractInferenceTest.assertTrue("Type " + assumpt.getAssumedType() + " for variable " + assumpt.getIdentifier() + " is not found in expectations", expTypes.contains(assumpt.getAssumedType())); + checkBoundedTypes(assumpt.getAssumedType(), expTypes.get(expTypes.indexOf(assumpt.getAssumedType()))); + + //remove this expectation to assure, all expectations have been met at least once + expect.getLocalVar().get(assumpt.getIdentifier()).getExpectedTypeCopy().remove(assumpt.getAssumedType()); + } + else if ((assumpt.getAssumedType() instanceof GenericTypeVar || assumpt.getAssumedType() instanceof TypePlaceholder) && varExpect.getExpectedUnknownType()!=null) { + checkUnknownTypes(assumpt.getAssumedType(),varExpect.getExpectedUnknownType()); + } + else + AbstractInferenceTest.fail("no type for variable "+ assumpt.getIdentifier() + " has been defined"); + + return true; + } + else if (expect.getContainedBlocks()!=null){ + //dig one block deeper in hierarchy + for (BlockExpect exp : expect.getContainedBlocks()) + ret |= checkFoundVariable(assumpt,exp); + return ret; + } + return false; + } + /** + * checks method parameters comparing them to the expectation + * @param assumpt + * @param expect + */ + + protected void checkParameters(CMethodTypeAssumption methodAssumpt, MethodExpect methodExpect) { + Vector assumpt = methodAssumpt.getParaAssumptions(); + HashMap expect = methodExpect.getParameter(); + //amount of parameter - not needed anymore since methodkey contains amount of parameters already + //AbstractInferenceTest.assertEquals("amount of parameters not equal!", assumpt.size(),expect.size()); + + for (CParaTypeAssumption paraAssumpt : assumpt) { + //check if variable is expected + AbstractInferenceTest.assertTrue("variable " + paraAssumpt.getIdentifier() + " is not expected!", expect.containsKey(paraAssumpt.getIdentifier())); + Vector expectedTypes = expect.get(paraAssumpt.getIdentifier()).getExpectedType(); + //check if variable's type is expected + if (!expectedTypes.isEmpty()) { + AbstractInferenceTest.assertTrue("type " + paraAssumpt.getAssumedType() + " for variable " + paraAssumpt.getIdentifier() + " is not expected!", expectedTypes.contains(paraAssumpt.getAssumedType())); + AbstractInferenceTest.assertEquals("type " + paraAssumpt.getAssumedType() + " for variable " + paraAssumpt.getIdentifier() + " is not expected!", expectedTypes.get(expectedTypes.indexOf(paraAssumpt.getAssumedType())).getClass(),paraAssumpt.getAssumedType().getClass()); + checkBoundedTypes(paraAssumpt.getAssumedType(), expectedTypes.get(expectedTypes.indexOf(paraAssumpt.getAssumedType()))); + + //remove this expectation to assure, all expectations have been met at least once + expect.get(paraAssumpt.getIdentifier()).getExpectedTypeCopy().remove(paraAssumpt.getAssumedType()); + } + else if (paraAssumpt.getAssumedType() instanceof GenericTypeVar && expect.get(paraAssumpt.getIdentifier()).getExpectedUnknownType()!=null) { + //case of undefined type (generic variable), add generic to generic list + if (!methodExpect.getGenerics().contains((GenericTypeVar)paraAssumpt.getAssumedType())) + methodExpect.addGeneric((GenericTypeVar) paraAssumpt.getAssumedType()); + checkUnknownTypes(paraAssumpt.getAssumedType(),expect.get(paraAssumpt.getIdentifier()).getExpectedUnknownType() ); + } + else if (paraAssumpt.getAssumedType() instanceof TypePlaceholder && expect.get(paraAssumpt.getIdentifier()).getExpectedUnknownType()!=null) + checkUnknownTypes(paraAssumpt.getAssumedType(),expect.get(paraAssumpt.getIdentifier()).getExpectedUnknownType() ); + else + AbstractInferenceTest.fail("no type for " + paraAssumpt.getIdentifier() +" has been defined in expectation"); + } + } + + /** + * checks every class expected is included in compiler assumption + available generics + * @param assumption + * @param expectation + */ + protected void checkClasses(CTypeReconstructionResult assumption, Expectation expectation) { + + + for (String expect : expectation.getClasses().keySet()) { + //class exists + AbstractInferenceTest.assertTrue("class " + expect + " is not found in assumption!", assumption.getClassNameList().contains(expect)); + //generics + checkFoundGenerics(assumption.getGenerics(expect), expectation.getClasses().get(expect).getGenerics()); + } + } + + /** + * members found are compared to the expectation + * @param assumpt + * @param expect + */ + + protected void checkFoundMembers(CInstVarTypeAssumption assumpt, HashMap expect) { + AbstractInferenceTest.assertTrue("Member " + assumpt.getIdentifier() + " is not found in expectation!", expect.containsKey(assumpt.getIdentifier())); + AbstractInferenceTest.assertTrue("Type " + assumpt.getAssumedType() + " for member " + assumpt.getIdentifier() + " is not found in expectation",expect.get(assumpt.getIdentifier()).getExpectedType().contains(assumpt.getAssumedType())); + // + //remove this expectation to assure, all expectations have been met at least once + if (expect.get(assumpt.getIdentifier()).getExpectedTypeCopy().contains(assumpt.getAssumedType())) + expect.get(assumpt.getIdentifier()).getExpectedTypeCopy().remove(assumpt.getAssumedType()); + } + + /** + * called to verify whether thrown exception from compiler calls is expected + * @param e + * @throws Throwable + */ + protected void checkForExpectedException (Exception e) throws Throwable { + if (!this.expectation.getExceptions().isEmpty()) { + //check if thrown exception has been expected + e.printStackTrace(); +// System.out.println(e.getClass()); + //AbstractInferenceTest2.assertTrue("Exception " + e.getMessage() + " is not same as expected", e.getClass().equals(this.expectation.getExceptions().firstElement())); + AbstractInferenceTest.assertTrue("Exception " + e.getMessage() + " is not expected", !this.expectation.getExceptions().isEmpty()); + } + else + throw e; + } + +// @Deprecated +// protected void checkForValidMethodTypes(CMethodTypeAssumption assumpt) {} +// protected void setUp() {} +// protected void tearDown() {} + + protected Vector createVectorAllNumberTypes() { + Vector ret = new Vector(); + ret.add(new RefType("java.lang.Integer",-1)); + ret.add(new RefType("java.lang.Long",-1)); + ret.add(new RefType("java.lang.Double",-1)); + ret.add(new RefType("java.lang.Float",-1)); +// ret.add(new RefType("java.lang.Short",-1)); +// ret.add(new RefType("java.lang.Byte",-1)); +// ret.add(new RefType("java.lang.Character",-1)); + + return ret; + } +} diff --git a/test/mycompiler/test/AllTests.java b/test/mycompiler/test/AllTests.java new file mode 100755 index 000000000..c793951ec --- /dev/null +++ b/test/mycompiler/test/AllTests.java @@ -0,0 +1,41 @@ +package mycompiler.test; + +import junit.framework.Test; +import junit.framework.TestSuite; +import mycompiler.test.blocks.AllTestsBlocks; +import mycompiler.test.complexTypes.AllTestsComplexTypes; +import mycompiler.test.generics.AllTestsGenerics; +import mycompiler.test.inferenceByCharacteristic.AllTestsInferenceByCharacteristic; +import mycompiler.test.javaConcepts.inheritance.AllTestsInheritance; +import mycompiler.test.javaConcepts.overloading.AllTestsOverloading; +import mycompiler.test.javaConcepts.staticAccess.AllTestsStaticAccess; +import mycompiler.test.operators.AllTestsOperators; +import mycompiler.test.primitiveTypes.AllTestsPrimitiveTypes; +import mycompiler.test.trivial.AllTestsTrivial; + +import org.apache.log4j.xml.DOMConfigurator; + +public class AllTests { + + + public static Test suite() { +// DOMConfigurator.configure("test/log4jTesting.xml"); +// DOMConfigurator.configure("log4j.xml"); + TestSuite suite = new TestSuite("Test for mycompiler.test"); + //$JUnit-BEGIN$ + suite.addTest(AllTestsBlocks.suite()); + suite.addTest(AllTestsInferenceByCharacteristic.suite()); + suite.addTest(AllTestsInheritance.suite()); + suite.addTest(AllTestsOverloading.suite()); + suite.addTest(AllTestsOperators.suite()); + suite.addTest(AllTestsPrimitiveTypes.suite()); + suite.addTest(AllTestsTrivial.suite()); + suite.addTest(AllTestsGenerics.suite()); + suite.addTest(AllTestsStaticAccess.suite()); + suite.addTest(AllTestsComplexTypes.suite()); + + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/LambdaInterferenzTest.java b/test/mycompiler/test/LambdaInterferenzTest.java new file mode 100644 index 000000000..7fb0ac2d0 --- /dev/null +++ b/test/mycompiler/test/LambdaInterferenzTest.java @@ -0,0 +1,15 @@ +package mycompiler.test; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +public class LambdaInterferenzTest { + + public static Test suite() { + + TestSuite suite = new TestSuite("Test for 'Complete Typeinference in Java 8'"); + + return suite; + } +} diff --git a/test/mycompiler/test/Log4jWrapper.java b/test/mycompiler/test/Log4jWrapper.java new file mode 100755 index 000000000..456923605 --- /dev/null +++ b/test/mycompiler/test/Log4jWrapper.java @@ -0,0 +1,35 @@ +package mycompiler.test; + +import org.apache.log4j.xml.DOMConfigurator; + +/** + * needed to assure one-time execution of configure script + * @author tom + * + */ +public class Log4jWrapper { + + private static Log4jWrapper instance=null; + private static boolean log4jInit=false; + + private Log4jWrapper() { + + } + + public static Log4jWrapper getInstance() { + if (instance==null) { + instance=new Log4jWrapper(); + } + return instance; + } + + public void configureLog4j() { + if (!this.log4jInit){ + DOMConfigurator.configure("test/log4jTesting.xml"); + DOMConfigurator.configure("log4j.xml"); + this.log4jInit=true; + } + + } + +} diff --git a/test/mycompiler/test/blocks/AllTestsBlocks.java b/test/mycompiler/test/blocks/AllTestsBlocks.java new file mode 100755 index 000000000..7e07e9221 --- /dev/null +++ b/test/mycompiler/test/blocks/AllTestsBlocks.java @@ -0,0 +1,23 @@ +package mycompiler.test.blocks; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsBlocks { + + public static Test suite() { + TestSuite suite = new TestSuite("Test for mycompiler.test.blocks"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestWhileStmt.class); + suite.addTestSuite(TestUninitializedVariable.class); + suite.addTestSuite(TestForStmt.class); + suite.addTestSuite(TestInferenceAcrossBlocks.class); + suite.addTestSuite(TestIfStmt.class); + suite.addTestSuite(TestSimpleVariable.class); + suite.addTestSuite(TestSimpleBlocks.class); + suite.addTestSuite(TestUndeterminedReturnNegative.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/blocks/TestForStmt.jav b/test/mycompiler/test/blocks/TestForStmt.jav new file mode 100755 index 000000000..a12ba6c8e --- /dev/null +++ b/test/mycompiler/test/blocks/TestForStmt.jav @@ -0,0 +1,32 @@ + +public class TestForStmt { + + public void m1() { + + i; + for (i=0;i<5;i++) { + + } + } + + public void m2() { + i; + for (i=0;i<5;i++) { + j; + j="abc"; + } + j; + j=3; + } + + public m3() { + i; + for (i=0;i<5;i++) { + j; + for (j=0;j<5;j++) { + return i==j; + } + } + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestForStmt.java b/test/mycompiler/test/blocks/TestForStmt.java new file mode 100755 index 000000000..f41318661 --- /dev/null +++ b/test/mycompiler/test/blocks/TestForStmt.java @@ -0,0 +1,75 @@ +package mycompiler.test.blocks; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.BlockExpect; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 18-04-08 + * @author + * + * tests correct identification of for-stmt + */ + +public class TestForStmt extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestForStmt"; + private final static String JAVPATH="test/mycompiler/test/blocks/"; + + public TestForStmt(String name) { + super(name,TestForStmt.JAVPATH+TestForStmt.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testForStmt = new ClassExpect(TestForStmt.TESTEDCLASSNAME); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1)); + VarExpect var1 = new VarExpect("i",new RefType("java.lang.Integer",-1)); + //short not inferenced + //var1.addExpectedType(new RefType("java.lang.Short",-1)); + m1.getBlock().addLocalVar(var1); + + MethodExpect m2 = new MethodExpect("m2", new RefType("void",-1)); + VarExpect var20 = new VarExpect("i",new RefType("java.lang.Integer",-1)); + //short not inferenced + //var20.addExpectedType(new RefType("java.lang.Short",-1)); + VarExpect var21 = new VarExpect("j",new RefType("java.lang.String",-1)); + VarExpect var22 = new VarExpect("j",new RefType("java.lang.Integer",-1)); + //short not inferenced + //var22.addExpectedType(new RefType("java.lang.Short",-1)); + //var22.addExpectedType(new RefType("java.lang.Long",-1)); + m2.getBlock().addLocalVar(var20); + BlockExpect for2 = new BlockExpect("1","1"); + for2.addLocalVar(var21); + m2.getBlock().addBlock(for2); + m2.getBlock().addLocalVar(var22); + + MethodExpect m3 = new MethodExpect("m3", new RefType("java.lang.Boolean",-1)); + VarExpect var30 = new VarExpect("i",new RefType("java.lang.Integer",-1)); + //short not inferenced + //var30.addExpectedType(new RefType("java.lang.Short",-1)); + VarExpect var31 = new VarExpect("j",new RefType("java.lang.Integer",-1)); + //short not inferenced + //var31.addExpectedType(new RefType("java.lang.Short",-1)); + //var31.addExpectedType(new RefType("java.lang.Long",-1)); + m3.getBlock().addLocalVar(var30); + BlockExpect for3 = new BlockExpect("1","1"); + for3.addLocalVar(var31); + m3.getBlock().addBlock(for3); + m3.getBlock().addLocalVar(var22); + + + testForStmt.addMethod(m1); + testForStmt.addMethod(m2); + testForStmt.addMethod(m3); + return new Expectation(testForStmt); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestIfStmt.jav b/test/mycompiler/test/blocks/TestIfStmt.jav new file mode 100755 index 000000000..a59a4c0f8 --- /dev/null +++ b/test/mycompiler/test/blocks/TestIfStmt.jav @@ -0,0 +1,27 @@ +import java.util.Vector; + +public class TestIfStmt { + + public m1() { + a; + if (a) { + return a; + } + else + return false; + } + + public m2() { + a; + c; + a = new Vector(); + if (a.isEmpty()) { + c="empty"; + } + else if (a.size()==1) { + c="almost empty"; + } + else + return a; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestIfStmt.java b/test/mycompiler/test/blocks/TestIfStmt.java new file mode 100755 index 000000000..8ca1ee79e --- /dev/null +++ b/test/mycompiler/test/blocks/TestIfStmt.java @@ -0,0 +1,74 @@ +package mycompiler.test.blocks; + +import java.util.Vector; + +import mycompiler.mytype.ExtendsWildcardType; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 18-04-08 + * @author + * + * this test checks correct identification of if-stmt and block usage + */ + +public class TestIfStmt extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestIfStmt"; + private final static String JAVPATH="test/mycompiler/test/blocks/"; + + public TestIfStmt(String name) { + super(name,TestIfStmt.JAVPATH+TestIfStmt.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testIfStmt = new ClassExpect(TestIfStmt.TESTEDCLASSNAME); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("java.lang.Boolean",-1)); + VarExpect var1 = new VarExpect("a",new RefType("java.lang.Boolean",-1)); + //short not inferenced + //var1.addExpectedType(new RefType("java.lang.Short",-1)); + m1.getBlock().addLocalVar(var1); + + Vector ret = new Vector(); + ret.add(new RefType("java.lang.Integer",-1)); + MethodExpect m2 = new MethodExpect("m2",new RefType("java.util.Vector",ret,-1)); + + Vector ret1 = new Vector(); + ret1.add(new ExtendsWildcardType(-1,new RefType("java.lang.Integer",-1))); + Vector ret2 = new Vector(); + ret2.add(new SuperWildcardType(-1,new RefType("java.lang.Integer",-1))); + m2.addReturntype(new RefType("java.util.Vector",ret1,-1)); + m2.addReturntype(new RefType("java.util.Vector",ret2,-1)); + + Vector a_param = new Vector(); + a_param.add(new RefType("java.lang.Integer",-1)); + VarExpect var21 = new VarExpect("a",new RefType("java.util.Vector",a_param,-1)); + Vector a_param1 = new Vector(); + a_param1.add(new ExtendsWildcardType(-1,new RefType("java.lang.Integer",-1))); + Vector a_param2 = new Vector(); + a_param2.add(new SuperWildcardType(-1,new RefType("java.lang.Integer",-1))); + var21.addExpectedType(new RefType("java.util.Vector",a_param1,-1)); + var21.addExpectedType(new RefType("java.util.Vector",a_param2,-1)); + + VarExpect var22 = new VarExpect("c",new RefType("java.lang.String",-1)); + + m2.getBlock().addLocalVar(var21); + m2.getBlock().addLocalVar(var22); + + testIfStmt.addMethod(m1); + testIfStmt.addMethod(m2); + return new Expectation(testIfStmt); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestInferenceAcrossBlocks.jav b/test/mycompiler/test/blocks/TestInferenceAcrossBlocks.jav new file mode 100755 index 000000000..508f0aaff --- /dev/null +++ b/test/mycompiler/test/blocks/TestInferenceAcrossBlocks.jav @@ -0,0 +1,12 @@ +public class TestInferenceAcrossBlocks{ + + public m(a){ + if(a==true){ + return 3; + } + else { + x; + return x; + } + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestInferenceAcrossBlocks.java b/test/mycompiler/test/blocks/TestInferenceAcrossBlocks.java new file mode 100755 index 000000000..a89499ad2 --- /dev/null +++ b/test/mycompiler/test/blocks/TestInferenceAcrossBlocks.java @@ -0,0 +1,45 @@ +package mycompiler.test.blocks; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.BlockExpect; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 18-04-08 + * @author + * + * this test checks correct inference across different block with respect to local variables + */ + +public class TestInferenceAcrossBlocks extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInferenceAcrossBlocks"; + private final static String JAVPATH="test/mycompiler/test/blocks/"; + + public TestInferenceAcrossBlocks(String name) { + super(name,TestInferenceAcrossBlocks.JAVPATH+TestInferenceAcrossBlocks.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testInferenceAcrossBlocks = new ClassExpect(TestInferenceAcrossBlocks.TESTEDCLASSNAME); + + //Methods + MethodExpect m = new MethodExpect("m",new RefType("java.lang.Integer",-1)); + m.addParameter(new VarExpect("a", new RefType("java.lang.Boolean",-1))); + BlockExpect elseBlock = new BlockExpect(m.getBlock().getBlockID(),"2"); + elseBlock.addLocalVar(new VarExpect("x", new RefType("java.lang.Integer",-1))); + m.getBlock().addBlock(elseBlock); + + + testInferenceAcrossBlocks.addMethod(m); + return new Expectation(testInferenceAcrossBlocks); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestSimpleBlocks.jav b/test/mycompiler/test/blocks/TestSimpleBlocks.jav new file mode 100755 index 000000000..25d97b971 --- /dev/null +++ b/test/mycompiler/test/blocks/TestSimpleBlocks.jav @@ -0,0 +1,18 @@ +public class TestSimpleBlocks{ + + public m(a){ + { + d; + d = 'a'; + { + c; + c = d; + } + { + c; + c = d==a; + } + } + return a; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestSimpleBlocks.java b/test/mycompiler/test/blocks/TestSimpleBlocks.java new file mode 100755 index 000000000..93bac75ac --- /dev/null +++ b/test/mycompiler/test/blocks/TestSimpleBlocks.java @@ -0,0 +1,56 @@ +package mycompiler.test.blocks; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.BlockExpect; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 18-04-08 + * @author + * + * this test checks correct detection of scope of variables in simple blocks without a language specific statement + */ + +public class TestSimpleBlocks extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestSimpleBlocks"; + private final static String JAVPATH="test/mycompiler/test/blocks/"; + + public TestSimpleBlocks(String name) { + super(name,TestSimpleBlocks.JAVPATH+TestSimpleBlocks.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testSimpleBlocks = new ClassExpect(TestSimpleBlocks.TESTEDCLASSNAME); + + //Methods + MethodExpect m = new MethodExpect("m",new RefType("java.lang.Character",-1)); + m.addParameter(new VarExpect("a", new RefType("java.lang.Character",-1))); + BlockExpect outerBlock = new BlockExpect(m.getBlock().getBlockID(),"1"); + outerBlock.addLocalVar(new VarExpect("d",new RefType("java.lang.Character",-1))); + + + BlockExpect firstBlock = new BlockExpect(outerBlock.getBlockID(),"1"); + firstBlock.addLocalVar(new VarExpect("c", new RefType("java.lang.Character",-1))); + + BlockExpect secondBlock = new BlockExpect(outerBlock.getBlockID(),"2"); + secondBlock.addLocalVar(new VarExpect("c", new RefType("java.lang.Boolean",-1))); + + outerBlock.addBlock(firstBlock); + outerBlock.addBlock(secondBlock); + + m.getBlock().addBlock(outerBlock); + + testSimpleBlocks.addMethod(m); + + return new Expectation(testSimpleBlocks); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestSimpleVariable.jav b/test/mycompiler/test/blocks/TestSimpleVariable.jav new file mode 100755 index 000000000..b3d3ba248 --- /dev/null +++ b/test/mycompiler/test/blocks/TestSimpleVariable.jav @@ -0,0 +1,7 @@ +public class TestSimpleVariable { + + public m() { + c; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestSimpleVariable.java b/test/mycompiler/test/blocks/TestSimpleVariable.java new file mode 100755 index 000000000..9cd4ff6e3 --- /dev/null +++ b/test/mycompiler/test/blocks/TestSimpleVariable.java @@ -0,0 +1,43 @@ +package mycompiler.test.blocks; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.TypePlaceholderExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 18-04-08 + * @author + * + * this test checks correct detection of a single variable in root block + * TODO: maybe move to trival? + */ + +public class TestSimpleVariable extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestSimpleVariable"; + private final static String JAVPATH="test/mycompiler/test/blocks/"; + + public TestSimpleVariable(String name) { + super(name,TestSimpleVariable.JAVPATH+TestSimpleVariable.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testSimpleVariable = new ClassExpect(TestSimpleVariable.TESTEDCLASSNAME); + + //Methods + MethodExpect m = new MethodExpect("m",new RefType("void",-1)); + VarExpect var = new VarExpect("c",new TypePlaceholderExpect("a")); + m.getBlock().addLocalVar(var); + + testSimpleVariable.addMethod(m); + return new Expectation(testSimpleVariable); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestSwitchStmt.jav b/test/mycompiler/test/blocks/TestSwitchStmt.jav new file mode 100755 index 000000000..1b9f689bc --- /dev/null +++ b/test/mycompiler/test/blocks/TestSwitchStmt.jav @@ -0,0 +1,11 @@ +public class TestSwitchStmt { + + public m(a) { + switch (a) { + case 1: return a++; break; + case 2: return a--; break; + default: return a; + } + + +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestTryCatchBlock.jav b/test/mycompiler/test/blocks/TestTryCatchBlock.jav new file mode 100755 index 000000000..59951045a --- /dev/null +++ b/test/mycompiler/test/blocks/TestTryCatchBlock.jav @@ -0,0 +1,14 @@ +public class TestTryCatchBlock { + + public m() { + + try { + return new TestTryCatchBlock(); + } + catch (e) { + return null; + } + + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestUndeterminedReturnNegative.jav b/test/mycompiler/test/blocks/TestUndeterminedReturnNegative.jav new file mode 100755 index 000000000..166cd9739 --- /dev/null +++ b/test/mycompiler/test/blocks/TestUndeterminedReturnNegative.jav @@ -0,0 +1,12 @@ + +public class TestUndeterminedReturnNegative { + + public m1(a) { + if (a) { + a=false; + } + else + return false; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestUndeterminedReturnNegative.java b/test/mycompiler/test/blocks/TestUndeterminedReturnNegative.java new file mode 100755 index 000000000..373d8ba30 --- /dev/null +++ b/test/mycompiler/test/blocks/TestUndeterminedReturnNegative.java @@ -0,0 +1,53 @@ +package mycompiler.test.blocks; + +import java.util.Vector; + +import mycompiler.mytype.ExtendsWildcardType; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 16-05-08 + * @author + * + * this test checks a scenario where undefined return state is given by condition dependant retun statment# + * Test expects an exception thrown + */ +public class TestUndeterminedReturnNegative extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestUndeterminedReturnNegative"; + private final static String JAVPATH="test/mycompiler/test/blocks/"; + + public TestUndeterminedReturnNegative(String name) { + super(name,TestUndeterminedReturnNegative.JAVPATH+TestUndeterminedReturnNegative.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testUndeterminedReturnNegative = new ClassExpect(TestUndeterminedReturnNegative.TESTEDCLASSNAME); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("java.lang.Boolean",-1)); + //m1.addReturntype(new RefType("void",-1)); + VarExpect var1 = new VarExpect("a",new RefType("java.lang.Boolean",-1)); + m1.addParameter(var1); + //short not inferenced + //var1.addExpectedType(new RefType("java.lang.Short",-1)); + + + testUndeterminedReturnNegative.addMethod(m1); + + Expectation ret = new Expectation(testUndeterminedReturnNegative); + ret.addException(new Exception()); //returntype undefined, one case return = boolean, other case return=void + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestUninitializedVariable.jav b/test/mycompiler/test/blocks/TestUninitializedVariable.jav new file mode 100755 index 000000000..793bbbe8c --- /dev/null +++ b/test/mycompiler/test/blocks/TestUninitializedVariable.jav @@ -0,0 +1,11 @@ +public class TestUninitializedVariable { + + public void m1() { + a; + a++; + } + + void m2(T a) { + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestUninitializedVariable.java b/test/mycompiler/test/blocks/TestUninitializedVariable.java new file mode 100755 index 000000000..a0923c84a --- /dev/null +++ b/test/mycompiler/test/blocks/TestUninitializedVariable.java @@ -0,0 +1,45 @@ +package mycompiler.test.blocks; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 29-05-08 + * @author + * + * this test checks a scenario where an uninitialized variable is incremented, which should be discarded by the compiler + * Test expects an exception thrown + */ +public class TestUninitializedVariable extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestUninitializedVariable"; + private final static String JAVPATH="test/mycompiler/test/blocks/"; + + public TestUninitializedVariable(String name) { + super(name,TestUninitializedVariable.JAVPATH+TestUninitializedVariable.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testUninitializedVariable = new ClassExpect(TestUninitializedVariable.TESTEDCLASSNAME); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1)); + VarExpect var1 = new VarExpect("a",new RefType("java.lang.Integer",-1)); + m1.getBlock().addLocalVar(var1); + + + testUninitializedVariable.addMethod(m1); + + Expectation ret = new Expectation(testUninitializedVariable); + ret.addException(new Exception()); //variable used not initialized + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestWhileStmt.jav b/test/mycompiler/test/blocks/TestWhileStmt.jav new file mode 100755 index 000000000..1debca80b --- /dev/null +++ b/test/mycompiler/test/blocks/TestWhileStmt.jav @@ -0,0 +1,9 @@ +public class TestWhileStmt { + + public m1() { + i; + while (true) + i++; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/blocks/TestWhileStmt.java b/test/mycompiler/test/blocks/TestWhileStmt.java new file mode 100755 index 000000000..e6d9cabbf --- /dev/null +++ b/test/mycompiler/test/blocks/TestWhileStmt.java @@ -0,0 +1,43 @@ +package mycompiler.test.blocks; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 18-04-08 + * @author + * + * simply verifies while-stmt recognition + */ + +public class TestWhileStmt extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestWhileStmt"; + private final static String JAVPATH="test/mycompiler/test/blocks/"; + + public TestWhileStmt(String name) { + super(name,TestWhileStmt.JAVPATH+TestWhileStmt.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testWhileStmt = new ClassExpect(TestWhileStmt.TESTEDCLASSNAME); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1)); + VarExpect var1 = new VarExpect("i",new RefType("java.lang.Integer",-1)); + //var1.addExpectedType(new RefType("java.lang.Short",-1)); + //var1.addExpectedType(new RefType("java.lang.Long",-1)); + m1.getBlock().addLocalVar(var1); + + testWhileStmt.addMethod(m1); + return new Expectation(testWhileStmt); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/complexTypes/AllTestsComplexTypes.java b/test/mycompiler/test/complexTypes/AllTestsComplexTypes.java new file mode 100755 index 000000000..31cf867b0 --- /dev/null +++ b/test/mycompiler/test/complexTypes/AllTestsComplexTypes.java @@ -0,0 +1,19 @@ +package mycompiler.test.complexTypes; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsComplexTypes { + + public static Test suite() { + TestSuite suite = new TestSuite("Test for mycompiler.test.complexTypes"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestOwnClassMethod.class); + suite.addTestSuite(TestOwnClassMember.class); + suite.addTestSuite(TestStandardLibMethod.class); + suite.addTestSuite(TestStandardLibInheritanceInference.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/complexTypes/TestOwnClassMember.jav b/test/mycompiler/test/complexTypes/TestOwnClassMember.jav new file mode 100755 index 000000000..fa73127e8 --- /dev/null +++ b/test/mycompiler/test/complexTypes/TestOwnClassMember.jav @@ -0,0 +1,9 @@ +public class TestOwnClassMember { + + Integer a; + + public void m1(b) { + b += a; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/complexTypes/TestOwnClassMember.java b/test/mycompiler/test/complexTypes/TestOwnClassMember.java new file mode 100755 index 000000000..5f9cdaea4 --- /dev/null +++ b/test/mycompiler/test/complexTypes/TestOwnClassMember.java @@ -0,0 +1,41 @@ +package mycompiler.test.complexTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** + * 25-04-08 + * @author + * + * test checks for correct inference using a class member variable + */ +public class TestOwnClassMember extends AbstractInferenceTest{ + private final static String TESTEDCLASSNAME="TestOwnClassMember"; + private final static String JAVPATH="test/mycompiler/test/complexTypes/"; + + public TestOwnClassMember(String name) { + super(name,TestOwnClassMember.JAVPATH+TestOwnClassMember.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testOwnClassMember = new ClassExpect(TestOwnClassMember.TESTEDCLASSNAME); + //Member + testOwnClassMember.addMember(new VarExpect("a", new RefType("java.lang.Integer",-1))); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1)); + m1.addParameter(new VarExpect("b",new RefType("java.lang.Integer",-1))); + + + + testOwnClassMember.addMethod(m1); + + return new Expectation(testOwnClassMember); + } + } \ No newline at end of file diff --git a/test/mycompiler/test/complexTypes/TestOwnClassMethod.jav b/test/mycompiler/test/complexTypes/TestOwnClassMethod.jav new file mode 100755 index 000000000..e3d2a9255 --- /dev/null +++ b/test/mycompiler/test/complexTypes/TestOwnClassMethod.jav @@ -0,0 +1,12 @@ +public class TestOwnClassMethod { + + Integer a; + + public void m1(b) { + a += b; + } + + public void m2(c, d) { + c.m1(d); + } + } \ No newline at end of file diff --git a/test/mycompiler/test/complexTypes/TestOwnClassMethod.java b/test/mycompiler/test/complexTypes/TestOwnClassMethod.java new file mode 100755 index 000000000..87405f49b --- /dev/null +++ b/test/mycompiler/test/complexTypes/TestOwnClassMethod.java @@ -0,0 +1,47 @@ +package mycompiler.test.complexTypes; + + + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 18-04-08 + * @author + * + * tests inference using return statement of a member-method + */ +public class TestOwnClassMethod extends AbstractInferenceTest{ + private final static String TESTEDCLASSNAME="TestOwnClassMethod"; + private final static String JAVPATH="test/mycompiler/test/complexTypes/"; + + public TestOwnClassMethod(String name) { + super(name,TestOwnClassMethod.JAVPATH+TestOwnClassMethod.TESTEDCLASSNAME + ".jav"); + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testOwnClassMethod = new ClassExpect(TestOwnClassMethod.TESTEDCLASSNAME); + //Member + testOwnClassMethod.addMember(new VarExpect("a", new RefType("java.lang.Integer",-1))); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1)); + m1.addParameter(new VarExpect("b",new RefType("java.lang.Integer",-1))); + + MethodExpect m2 = new MethodExpect("m2", new RefType("void",-1)); + m2.addParameter(new VarExpect("c", new RefType(TestOwnClassMethod.TESTEDCLASSNAME,-1))); + m2.addParameter(new VarExpect("d", new RefType("java.lang.Integer",-1))); + + + testOwnClassMethod.addMethod(m1); + testOwnClassMethod.addMethod(m2); + + return new Expectation(testOwnClassMethod); + } + } \ No newline at end of file diff --git a/test/mycompiler/test/complexTypes/TestStandardLibInheritanceInference.jav b/test/mycompiler/test/complexTypes/TestStandardLibInheritanceInference.jav new file mode 100755 index 000000000..deafc13a6 --- /dev/null +++ b/test/mycompiler/test/complexTypes/TestStandardLibInheritanceInference.jav @@ -0,0 +1,12 @@ +import java.io.OutputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.BufferedOutputStream; +import java.sql.Connection; + + +class TestStandardLibInheritanceInference{ + foo(x){ + x.close(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/complexTypes/TestStandardLibInheritanceInference.java b/test/mycompiler/test/complexTypes/TestStandardLibInheritanceInference.java new file mode 100755 index 000000000..5ac5316fd --- /dev/null +++ b/test/mycompiler/test/complexTypes/TestStandardLibInheritanceInference.java @@ -0,0 +1,44 @@ +package mycompiler.test.complexTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 25-05-08 + * @author + * + * inference of std-types according to import statements with respect to inheritance structure + */ + +public class TestStandardLibInheritanceInference extends AbstractInferenceTest{ + private final static String TESTEDCLASSNAME="TestStandardLibInheritanceInference"; + private final static String JAVPATH="test/mycompiler/test/complexTypes/"; + + public TestStandardLibInheritanceInference(String name) { + super(name,TestStandardLibInheritanceInference.JAVPATH+TestStandardLibInheritanceInference.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testStandardLibInheritanceInference = new ClassExpect(TESTEDCLASSNAME); + + //Methods + MethodExpect foo = new MethodExpect("foo",new RefType("void",-1)); + VarExpect x = new VarExpect("x",new RefType("java.io.OutputStream",-1)); + x.addExpectedType(new RefType("java.io.BufferedOutputStream",-1)); + x.addExpectedType(new RefType("java.io.InputStream",-1)); + x.addExpectedType(new RefType("java.io.ByteArrayOutputStream",-1)); + x.addExpectedType(new RefType("java.sql.Connection",-1)); + foo.addParameter(x); + + testStandardLibInheritanceInference.addMethod(foo); + + return new Expectation(testStandardLibInheritanceInference); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/complexTypes/TestStandardLibMember.jav b/test/mycompiler/test/complexTypes/TestStandardLibMember.jav new file mode 100755 index 000000000..c54b0b142 --- /dev/null +++ b/test/mycompiler/test/complexTypes/TestStandardLibMember.jav @@ -0,0 +1,11 @@ +import java.lang.System; +import java.io.PrintStream; + +public class TestStandardLibMember { + + public m1() { + a; + a=System.out; + a.println(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/complexTypes/TestStandardLibMethod.jav b/test/mycompiler/test/complexTypes/TestStandardLibMethod.jav new file mode 100755 index 000000000..aef62902f --- /dev/null +++ b/test/mycompiler/test/complexTypes/TestStandardLibMethod.jav @@ -0,0 +1,20 @@ +import java.util.HashMap; +import java.util.Vector; + +public class TestStandardLibMethod { + + public m1() { + a; + a = new HashMap(); + a.put("2",-1); + } + + public m2(Vector> m){ + k; + k = 0; + ret; + ret = m.elementAt(k).elementAt(k).intValue(); + return ret; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/complexTypes/TestStandardLibMethod.java b/test/mycompiler/test/complexTypes/TestStandardLibMethod.java new file mode 100755 index 000000000..55887770d --- /dev/null +++ b/test/mycompiler/test/complexTypes/TestStandardLibMethod.java @@ -0,0 +1,53 @@ +package mycompiler.test.complexTypes; + +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** + * 18-04-08 + * @author + * + * this test checks correct inference of std types by their methods used + */ +public class TestStandardLibMethod extends AbstractInferenceTest{ + private final static String TESTEDCLASSNAME="TestStandardLibMethod"; + private final static String JAVPATH="test/mycompiler/test/complexTypes/"; + + public TestStandardLibMethod(String name) { + super(name,TestStandardLibMethod.JAVPATH+TestStandardLibMethod.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testStandardLibMethod = new ClassExpect(TestStandardLibMethod.TESTEDCLASSNAME); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1)); + RefType aType = new RefType("java.util.HashMap",new Vector(),-1); + aType.add_Parameter(new RefType("java.lang.String",-1)); + aType.add_Parameter(new RefType("java.lang.Integer",-1)); + m1.getBlock().addLocalVar(new VarExpect("a", aType)); + + MethodExpect m2 = new MethodExpect("m2", new RefType("java.lang.Integer",-1)); + RefType mType = new RefType("java.util.Vector",new Vector(),-1); + RefType mType1 = new RefType("java.util.Vector",new Vector(),-1); + mType1.add_Parameter(new RefType("java.lang.Integer",-1)); + mType.add_Parameter(mType1); + m2.addParameter(new VarExpect("m", mType)); + m2.getBlock().addLocalVar(new VarExpect("k",new RefType("java.lang.Integer",-1))); + m2.getBlock().addLocalVar(new VarExpect("ret",new RefType("java.lang.Integer",-1))); + + + testStandardLibMethod.addMethod(m1); + testStandardLibMethod.addMethod(m2); + + return new Expectation(testStandardLibMethod); + } + } \ No newline at end of file diff --git a/test/mycompiler/test/expectationTypes/BlockExpect.java b/test/mycompiler/test/expectationTypes/BlockExpect.java new file mode 100755 index 000000000..55fb52bee --- /dev/null +++ b/test/mycompiler/test/expectationTypes/BlockExpect.java @@ -0,0 +1,74 @@ +package mycompiler.test.expectationTypes; + +import java.util.HashMap; +import java.util.Vector; + +/** + * 15-04-08 + * @author + * + * expectation structure to define expectations for a particular block + */ + +public class BlockExpect implements IExpectation{ + private HashMap localVars = null; + private Vector containedBlocks = null; + private String blockID = null; + + public BlockExpect(String parentBlockID,String blockID) { + + this.localVars = new HashMap(); + this.containedBlocks = new Vector(); + if (parentBlockID==null) + this.blockID=blockID; + else + this.blockID = parentBlockID+"-"+blockID; + } + + public void addBlock(BlockExpect block) { + this.containedBlocks.add(block); + } + + public void addLocalVar(VarExpect localVar) { + this.localVars.put(localVar.getName(), localVar); + } + + public boolean verifyTypeExpectationsCompletelyMet() { + boolean ret = true; + for (VarExpect localVar : localVars.values()) { + ret &=localVar.verifyTypeExpectationsCompletelyMet(); + } + + for (BlockExpect containedBlock : containedBlocks) { + ret &=containedBlock.verifyTypeExpectationsCompletelyMet(); + } + return ret; + } + + public HashMap getLocalVar() { + return localVars; + } + + public void setLocalVar(HashMap localVar) { + this.localVars = localVar; + } + + public Vector getContainedBlocks() { + return containedBlocks; + } + + public void setContainedBlocks(Vector containedBlocks) { + this.containedBlocks = containedBlocks; + } + + public String getBlockID() { + return blockID; + } + + public void setBlockID(String blockID) { + this.blockID = blockID; + } + + + +} diff --git a/test/mycompiler/test/expectationTypes/ClassExpect.java b/test/mycompiler/test/expectationTypes/ClassExpect.java new file mode 100755 index 000000000..998aaf3c5 --- /dev/null +++ b/test/mycompiler/test/expectationTypes/ClassExpect.java @@ -0,0 +1,92 @@ +package mycompiler.test.expectationTypes; + +import java.util.HashMap; +import java.util.Vector; + +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytypereconstruction.typeassumptionkey.CMethodKey; +/** + * 15-04-08 + * @author + * + * expectation structure to define expectations for a particular class + */ +public class ClassExpect implements IExpectation { + private String name = null; + private Vector generics = null; + private HashMap members = null; + private HashMap methods = null; + + + public ClassExpect(String name) { + this.name = name; + this.generics= new Vector(); + this.members = new HashMap(); + this.methods = new HashMap(); + } + + public void addGeneric(GenericTypeVar generic) { + this.generics.add(generic); + } + + public void addMember(VarExpect member) { + this.members.put(member.getName(), member); + } + + public void addMethod(MethodExpect method) { + this.methods.put(new CMethodKey(this.getName(),method.getName(),method.getParaCount(),method.getOverloadID()),method); + } + + public boolean verifyTypeExpectationsCompletelyMet() { + boolean ret=true; + for (VarExpect member : this.members.values()) + ret &=member.verifyTypeExpectationsCompletelyMet(); + for (MethodExpect method: this.methods.values()) + ret &=method.verifyTypeExpectationsCompletelyMet(); + return ret; + } + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public Vector getGenerics() { + return generics; + } + + + public void setGenerics(Vector generics) { + this.generics = generics; + } + + + public HashMap getMembers() { + return members; + } + + + public void setMembers(HashMap members) { + this.members = members; + } + + + public HashMap getMethods() { + return methods; + } + + + public void setMethods(HashMap methods) { + this.methods = methods; + } + + + + + +} \ No newline at end of file diff --git a/test/mycompiler/test/expectationTypes/Expectation.java b/test/mycompiler/test/expectationTypes/Expectation.java new file mode 100755 index 000000000..ddda0f137 --- /dev/null +++ b/test/mycompiler/test/expectationTypes/Expectation.java @@ -0,0 +1,58 @@ +package mycompiler.test.expectationTypes; + +import java.util.HashMap; +import java.util.Vector; +/** + * 15-04-08 + * @author + * + * expectation structure to define expectations for an entire testcase + * holds information about classes, exceptions + */ +public class Expectation implements IExpectation { + + private HashMap classes = null; + private Vector exceptions = null; + private UnknownTypesMappingExpect mappings = null; + + public Expectation(ClassExpect classExpect) { + if (classExpect!=null) { + this.classes = new HashMap(); + this.classes.put(classExpect.getName(), classExpect); + } + this.exceptions = new Vector(); + this.mappings = new UnknownTypesMappingExpect(); + } + + public boolean verifyTypeExpectationsCompletelyMet() { + boolean ret = true; + for (ClassExpect classexpect : this.classes.values()) + ret &= classexpect.verifyTypeExpectationsCompletelyMet(); + return ret; + } + + public void addClass(ClassExpect classExpect) { + this.classes.put(classExpect.getName(),classExpect); + } + + public void addException (Exception e) { + this.exceptions.add(e); + } + + public Vector getExceptions() { + return this.exceptions; + } + + public HashMap getClasses() { + return classes; + } + + public void setClasses(HashMap classes) { + this.classes = classes; + } + + public UnknownTypesMappingExpect getMappings() { + return mappings; + } + +} diff --git a/test/mycompiler/test/expectationTypes/GenericTypeVarExpect.java b/test/mycompiler/test/expectationTypes/GenericTypeVarExpect.java new file mode 100755 index 000000000..8f2131e68 --- /dev/null +++ b/test/mycompiler/test/expectationTypes/GenericTypeVarExpect.java @@ -0,0 +1,21 @@ +package mycompiler.test.expectationTypes; + +import mycompiler.test.expectationTypes.IUnknownTypeExpect; +/** + * 15-05-08 + * @author + * + * class used to define variable expectations for a GenericTypeVar + */ +public class GenericTypeVarExpect implements IUnknownTypeExpect { + + private String name = null; + + public GenericTypeVarExpect(String name) { + this.name=name; + } + + public String getName() { + return this.name; + } +} diff --git a/test/mycompiler/test/expectationTypes/IExpectation.java b/test/mycompiler/test/expectationTypes/IExpectation.java new file mode 100755 index 000000000..5e74f38bd --- /dev/null +++ b/test/mycompiler/test/expectationTypes/IExpectation.java @@ -0,0 +1,12 @@ +package mycompiler.test.expectationTypes; + +/** + * 15-04-08 + * @author + * an interface defining common structure of a expectation definition + */ +public interface IExpectation { + + public boolean verifyTypeExpectationsCompletelyMet(); + +} diff --git a/test/mycompiler/test/expectationTypes/IUnknownTypeExpect.java b/test/mycompiler/test/expectationTypes/IUnknownTypeExpect.java new file mode 100755 index 000000000..bf4334ed2 --- /dev/null +++ b/test/mycompiler/test/expectationTypes/IUnknownTypeExpect.java @@ -0,0 +1,12 @@ +package mycompiler.test.expectationTypes; + +/** + * 15-05-08 + * @author + * + * interface for an expectation class to be defined + */ +public interface IUnknownTypeExpect { + + public String getName(); +} diff --git a/test/mycompiler/test/expectationTypes/MethodExpect.java b/test/mycompiler/test/expectationTypes/MethodExpect.java new file mode 100755 index 000000000..e344a5dd1 --- /dev/null +++ b/test/mycompiler/test/expectationTypes/MethodExpect.java @@ -0,0 +1,157 @@ +package mycompiler.test.expectationTypes; + +import java.util.HashMap; +import java.util.Vector; + +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +/** + * 15-04-08 + * @author + * + * defines expectations for methods + */ +public class MethodExpect implements IExpectation { + + private final static String METHODNAMEDELIMITER = "#"; + + private String name = null; + private Vector returntypes = null; + private Vector returntypesCopy = null; //used to ensure all expectations have been met + private IUnknownTypeExpect unknownReturnType=null; + private Vector generics = null; + private HashMap parameters = null; + private BlockExpect block = null; + private int overloadID = 0; + + + public MethodExpect(String name) { + this(name,0); + } + + public MethodExpect(String name, int overloadID) { + this.name = name; + + this.generics=new Vector(); + this.parameters=new HashMap(); + this.returntypes = new Vector(); + this.returntypesCopy=(Vector)this.returntypes.clone(); + this.block = new BlockExpect(null,"1"); + + this.overloadID = overloadID; + } + + public MethodExpect(String name, Type returntype) { + this(name,returntype,0); + } + + public MethodExpect(String name, Type returntype, int overloadID) { + this(name,overloadID); + this.returntypes.add(returntype); + this.returntypesCopy=(Vector)this.returntypes.clone(); + } + + public MethodExpect(String name, IUnknownTypeExpect unknownreturntype) { + this(name,unknownreturntype,0); + } + + public MethodExpect(String name, IUnknownTypeExpect unknownreturntype, int overloadID) { + this(name,overloadID); + this.unknownReturnType=unknownreturntype; + } + + public void addGeneric (GenericTypeVar generic) { + this.generics.add(generic); + } + + public void addReturntype(Type returntype) { + if (this.returntypes==null) + this.returntypes = new Vector(); + //to avoid usage of returntypes and unknownreturntypes at the same time + if (this.unknownReturnType==null) { + this.returntypes.add(returntype); + this.returntypesCopy.add(returntype); + } + } + + public void addParameter(VarExpect parameter) { + this.parameters.put(parameter.getName(),parameter); + } + + public boolean verifyTypeExpectationsCompletelyMet() { + boolean ret = true; + for (VarExpect parameter : this.parameters.values() ) { + ret &=parameter.verifyTypeExpectationsCompletelyMet(); + } + if (this.block!=null) + ret &=this.block.verifyTypeExpectationsCompletelyMet(); + ret &=this.returntypesCopy.size()==0; + return ret; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public Vector getReturntypes() { + return returntypes; + } + + public void setReturntypes(Vector returntypes) { + this.returntypes = returntypes; + } + + public Vector getGenerics() { + return generics; + } + + public void setGenerics(Vector generics) { + this.generics = generics; + } + + public HashMap getParameter() { + return parameters; + } + + public void setParameter(HashMap parameter) { + this.parameters = parameter; + } + + public BlockExpect getBlock() { + return block; + } + + public void setBlock(BlockExpect block) { + this.block = block; + } + + public int getOverloadID() { + return overloadID; + } + + public void setOverloadID(int overloadID) { + this.overloadID = overloadID; + } + + public Vector getReturntypesCopy() { + return returntypesCopy; + } + + public void setReturntypesCopy(Vector returntypesCopy) { + this.returntypesCopy = returntypesCopy; + this.returntypesCopy=(Vector)this.returntypes.clone(); + } + + public IUnknownTypeExpect getUnknownReturnType() { + return this.unknownReturnType; + } + + public int getParaCount() { + return this.getParameter().size(); + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/expectationTypes/TypePlaceholderExpect.java b/test/mycompiler/test/expectationTypes/TypePlaceholderExpect.java new file mode 100755 index 000000000..fcfc08e09 --- /dev/null +++ b/test/mycompiler/test/expectationTypes/TypePlaceholderExpect.java @@ -0,0 +1,21 @@ +package mycompiler.test.expectationTypes; + +import mycompiler.test.expectationTypes.IUnknownTypeExpect; +/** + * 15-05-08 + * @author + * + * type for defining an expected TypePlaceholder + */ +public class TypePlaceholderExpect implements IUnknownTypeExpect { + + private String name = null; + + public TypePlaceholderExpect(String name) { + this.name=name; + } + + public String getName() { + return this.name; + } +} diff --git a/test/mycompiler/test/expectationTypes/UnknownTypesMappingExpect.java b/test/mycompiler/test/expectationTypes/UnknownTypesMappingExpect.java new file mode 100755 index 000000000..6e3a5e652 --- /dev/null +++ b/test/mycompiler/test/expectationTypes/UnknownTypesMappingExpect.java @@ -0,0 +1,42 @@ +package mycompiler.test.expectationTypes; + +import java.util.HashMap; + +/** + * class is used to translate expected Typeplaceholder variable names to the ones used by the compiler allowing a comparison. It simply holds a registry that is filled upon detection of an unknown type which may later be in need of comparison + * only helps verifying that same expected typeplaceholders are mapped to same assumed typeplaceholders + * @author stresing + * + */ + +public class UnknownTypesMappingExpect { + + private HashMap unknownTypeNameMapping = null; + + public UnknownTypesMappingExpect() { + this.unknownTypeNameMapping = new HashMap(); + } + + /** + * returns mapped Type name as of expectation or null if not yet mapped + * @param foundTypeName + * @return + */ + public String getMappedType(String expectedTypeName) { + return this.unknownTypeNameMapping.get(expectedTypeName); + } + + public void addMapping(String expectedTypeName, String foundTypeName) { + this.unknownTypeNameMapping.put(expectedTypeName, foundTypeName); + + } + + public HashMap getUnknownTypeNameMapping() { + return unknownTypeNameMapping; + } + + public void setUnknownTypeNameMapping( + HashMap unknownTypeNameMapping) { + this.unknownTypeNameMapping = unknownTypeNameMapping; + } +} diff --git a/test/mycompiler/test/expectationTypes/VarExpect.java b/test/mycompiler/test/expectationTypes/VarExpect.java new file mode 100755 index 000000000..3fb0e81b2 --- /dev/null +++ b/test/mycompiler/test/expectationTypes/VarExpect.java @@ -0,0 +1,80 @@ +package mycompiler.test.expectationTypes; + +import java.util.Vector; + +import mycompiler.mytype.Type; +/** + * 15-04-08 + * @author + * + * classes used to define expectation of a particular variable + */ +public class VarExpect implements IExpectation { + private Vector expectedType = null; + private Vector expectedTypeCopy = null; + private IUnknownTypeExpect expectedUnknownType=null; + private String name = null; + + public VarExpect(String name) { + this.name=name; + this.expectedType=new Vector(); + this.expectedTypeCopy=(Vector)this.expectedType.clone(); + } + + public VarExpect(String name, Type expectedType) { + this(name); + this.expectedType.add(expectedType); + this.expectedTypeCopy=(Vector)this.expectedType.clone(); + } + + public VarExpect(String name, IUnknownTypeExpect expectedUnknownType) { + this(name); + this.expectedUnknownType=expectedUnknownType; + } + + public void addExpectedType(Type type) { + if (this.expectedType==null) + this.expectedType = new Vector(); + this.expectedType.add(type); + this.expectedTypeCopy=(Vector)this.expectedType.clone(); + } + + public boolean verifyTypeExpectationsCompletelyMet() { + return this.expectedTypeCopy.size()==0; + } + + public Vector getExpectedType() { + return expectedType; + } + + public void setExpectedType(Vector expectedType) { + this.expectedType = expectedType; + this.expectedTypeCopy=(Vector)this.expectedType.clone(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Vector getExpectedTypeCopy() { + return expectedTypeCopy; + } + + public void setExpectedTypeCopy(Vector expectedTypeCopy) { + this.expectedTypeCopy = expectedTypeCopy; + } + + public IUnknownTypeExpect getExpectedUnknownType() { + return expectedUnknownType; + } + + public void setExpectedUnknownType(IUnknownTypeExpect expectedUnknownType) { + this.expectedUnknownType = expectedUnknownType; + } + +} + diff --git a/test/mycompiler/test/generics/AllTestsGenerics.java b/test/mycompiler/test/generics/AllTestsGenerics.java new file mode 100755 index 000000000..bf3a7144d --- /dev/null +++ b/test/mycompiler/test/generics/AllTestsGenerics.java @@ -0,0 +1,25 @@ +package mycompiler.test.generics; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsGenerics { + + public static Test suite() { + TestSuite suite = new TestSuite("Test for mycompiler.test.generics"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestExtendedClassesWithBoundedGenerics.class); + suite.addTestSuite(TestAssignmentTwoGenericTypesNegative.class); + suite.addTestSuite(TestNestedGenerics.class); + suite.addTestSuite(TestSimpleClassesWithGenerics.class); + suite.addTestSuite(TestClassesWithBoundedGenericsUsedInMethods.class); + suite.addTestSuite(TestSimpleClassesWithBoundedGenerics.class); + suite.addTestSuite(TestSimpleClassesWithGenericsNegative.class); + suite.addTestSuite(TestClassesWithBoundedGenericsOfTwoTypes.class); + suite.addTestSuite(TestSimpleClassesWithBoundedGenericsNegative.class); + suite.addTestSuite(TestNestedGenericsNonExistingType.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/generics/TestAssignmentTwoGenericTypesNegative.jav b/test/mycompiler/test/generics/TestAssignmentTwoGenericTypesNegative.jav new file mode 100755 index 000000000..160126b58 --- /dev/null +++ b/test/mycompiler/test/generics/TestAssignmentTwoGenericTypesNegative.jav @@ -0,0 +1,12 @@ +import java.util.ArrayList; + +public class TestAssignmentTwoGenericTypesNegative { + + public void m() { + + ArrayList ls; + ls = new ArrayList(); + ArrayList lo; + lo = ls; /*<-- compile error*/ + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestAssignmentTwoGenericTypesNegative.java b/test/mycompiler/test/generics/TestAssignmentTwoGenericTypesNegative.java new file mode 100755 index 000000000..a3de8a853 --- /dev/null +++ b/test/mycompiler/test/generics/TestAssignmentTwoGenericTypesNegative.java @@ -0,0 +1,51 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * verifies correct detection of incompatible type assignments of two templates + * @author + * 13-05-08 + */ + + +public class TestAssignmentTwoGenericTypesNegative extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestAssignmentTwoGenericTypesNegative"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestAssignmentTwoGenericTypesNegative(String name) { + super(name,TestAssignmentTwoGenericTypesNegative.JAVPATH+TestAssignmentTwoGenericTypesNegative.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect testAssignmentTwoGenericTypesNegative = new ClassExpect(TestAssignmentTwoGenericTypesNegative.TESTEDCLASSNAME); + //Methods + MethodExpect method = new MethodExpect("m",new RefType("void",-1)); + RefType paramString = new RefType("java.lang.String",-1); + Vector param1 = new Vector(); + param1.add(paramString); + method.getBlock().addLocalVar(new VarExpect("ls", new RefType("java.util.ArrayList",param1,-1))); + RefType paramObject = new RefType("java.lang.Object",-1); + Vector param2 = new Vector(); + param2.add(paramObject); + method.getBlock().addLocalVar(new VarExpect("lo", new RefType("java.util.ArrayList",param2,-1))); + + testAssignmentTwoGenericTypesNegative.addMethod(method); + + Expectation ret = new Expectation(testAssignmentTwoGenericTypesNegative); + ret.addException(new Exception()); + return ret; + + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestClassesWithBoundedGenericsOfTwoTypes.jav b/test/mycompiler/test/generics/TestClassesWithBoundedGenericsOfTwoTypes.jav new file mode 100755 index 000000000..aec3e2351 --- /dev/null +++ b/test/mycompiler/test/generics/TestClassesWithBoundedGenericsOfTwoTypes.jav @@ -0,0 +1,17 @@ +interface I1 {} + +interface I2 {} + +class Implementation implements I1 {} + +class Implementation2 implements I2 {} + +class A {} + +class B{} + +class C{} + +class D{} + +class E{} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestClassesWithBoundedGenericsOfTwoTypes.java b/test/mycompiler/test/generics/TestClassesWithBoundedGenericsOfTwoTypes.java new file mode 100755 index 000000000..62b8c29b0 --- /dev/null +++ b/test/mycompiler/test/generics/TestClassesWithBoundedGenericsOfTwoTypes.java @@ -0,0 +1,86 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * checks inference upon bounds, however test fails up to now, bounds are not considered + * @author + * 21-04-08 + */ + + +public class TestClassesWithBoundedGenericsOfTwoTypes extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestClassesWithBoundedGenericsOfTwoTypes"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestClassesWithBoundedGenericsOfTwoTypes(String name) { + super(name,TestClassesWithBoundedGenericsOfTwoTypes.JAVPATH+TestClassesWithBoundedGenericsOfTwoTypes.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //interfaces + ClassExpect i1 = new ClassExpect("I1"); + ClassExpect i2 = new ClassExpect("I2"); + + //classes + ClassExpect impl = new ClassExpect("Implementation"); + ClassExpect impl2 = new ClassExpect("Implementation2"); + ClassExpect a = new ClassExpect("A"); + ClassExpect b = new ClassExpect("B"); + ClassExpect c = new ClassExpect("C"); + ClassExpect d = new ClassExpect("D"); + ClassExpect e = new ClassExpect("E"); + + //generics + Vector boundsA = new Vector(); + boundsA.add(new RefType("I1",-1)); + a.addGeneric(new BoundedGenericTypeVar("T",boundsA,-1)); + + Vector boundsB = new Vector(); + boundsB.add(new RefType("I1",-1)); + boundsB.add(new RefType("I2",-1)); + b.addGeneric(new BoundedGenericTypeVar("T",boundsB,-1)); + + Vector boundsC = new Vector(); + boundsC.add(new RefType("I1",-1)); + boundsC.add(new RefType("Implementation",-1)); + c.addGeneric(new BoundedGenericTypeVar("T",boundsC,-1)); + + Vector boundsD = new Vector(); + boundsD.add(new RefType("I2",-1)); + boundsD.add(new RefType("Implementation",-1)); + d.addGeneric(new BoundedGenericTypeVar("T",boundsD,-1)); + + Vector boundsE = new Vector(); + boundsE.add(new RefType("Implementation",-1)); + boundsE.add(new RefType("Implementation2",-1)); + e.addGeneric(new BoundedGenericTypeVar("T",boundsE,-1)); + + + Expectation ret = new Expectation(i1); + ret.addClass(i2); + ret.addClass(impl); + ret.addClass(impl2); + ret.addClass(a); + ret.addClass(b); + ret.addClass(c); + ret.addClass(d); + ret.addClass(e); + //generic cannot extend two classes - no multiple inheritance in java + ret.addException(new Exception()); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestClassesWithBoundedGenericsUsedInMethods.jav b/test/mycompiler/test/generics/TestClassesWithBoundedGenericsUsedInMethods.jav new file mode 100755 index 000000000..b5a53fc73 --- /dev/null +++ b/test/mycompiler/test/generics/TestClassesWithBoundedGenericsUsedInMethods.jav @@ -0,0 +1,21 @@ +interface I1 { + public m1(); +} + +class Implementation implements I1 { + public m1() { + } +} + +class TestClassesWithBoundedGenericsUsedInMethods { + + /*since S is at least of Type I1, call m1() should work*/ + public void m3 (S x) { + x.m1(); + } + + /*T is bounded by class generics, thus always at least of type I1*/ + public m2(T x) { + x.m1(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestClassesWithBoundedGenericsUsedInMethods.java b/test/mycompiler/test/generics/TestClassesWithBoundedGenericsUsedInMethods.java new file mode 100755 index 000000000..9a59cd5f4 --- /dev/null +++ b/test/mycompiler/test/generics/TestClassesWithBoundedGenericsUsedInMethods.java @@ -0,0 +1,75 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.test.expectationTypes.TypePlaceholderExpect; + +/** + * checks case of bounds being two classes, which should not be possible: multiple inheritance is not allowed in java + * @author + * 21-04-08 + */ + + +public class TestClassesWithBoundedGenericsUsedInMethods extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestClassesWithBoundedGenericsUsedInMethods"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestClassesWithBoundedGenericsUsedInMethods(String name) { + super(name,TestClassesWithBoundedGenericsUsedInMethods.JAVPATH+TestClassesWithBoundedGenericsUsedInMethods.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //interfaces + ClassExpect i1 = new ClassExpect("I1"); + + //classes + ClassExpect impl = new ClassExpect("Implementation"); + ClassExpect testClassesWithBoundedGenericsUsedInMethods = new ClassExpect(TestClassesWithBoundedGenericsUsedInMethods.TESTEDCLASSNAME); + + //generics + Vector boundsT = new Vector(); + boundsT.add(new RefType("I1",-1)); + BoundedGenericTypeVar t = new BoundedGenericTypeVar("T",boundsT,-1); + Vector boundsS = new Vector(); + boundsS.add(new RefType("I1",-1)); + + BoundedGenericTypeVar s = new BoundedGenericTypeVar("T",boundsS,-1); + + + testClassesWithBoundedGenericsUsedInMethods.addGeneric(t); + + //methods + MethodExpect m1 = new MethodExpect("m1", new TypePlaceholderExpect("a")); + i1.addMethod(m1); + + MethodExpect mImpl1 = new MethodExpect("m1", new RefType("void",-1)); + impl.addMethod(mImpl1); + + MethodExpect m2 = new MethodExpect("m2", new RefType("void",-1)); + m2.addParameter(new VarExpect("x", t)); + testClassesWithBoundedGenericsUsedInMethods.addMethod(m2); + + MethodExpect m3 = new MethodExpect("m3", new RefType("void",-1)); + m3.addGeneric(new GenericTypeVar("T",-1)); + m3.addParameter(new VarExpect("x", s)); + testClassesWithBoundedGenericsUsedInMethods.addMethod(m3); + + Expectation ret = new Expectation(testClassesWithBoundedGenericsUsedInMethods); + ret.addClass(i1); + ret.addClass(impl); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestExtendedClassesWithBoundedGenerics.jav b/test/mycompiler/test/generics/TestExtendedClassesWithBoundedGenerics.jav new file mode 100755 index 000000000..9e98bb177 --- /dev/null +++ b/test/mycompiler/test/generics/TestExtendedClassesWithBoundedGenerics.jav @@ -0,0 +1,34 @@ +interface I1 { + public m1(); +} + +interface I2 { + public m2(); +} + +class Implementation implements I1, I2 { + public m1() {} + + public m2() {} +} + +class Tester { + + public m3(T x) { + x.m1(); + x.m2(); + } +} + +public class TestExtendedClassesWithBoundedGenerics { + + public m() { + x; + /*can only be of Type Implementation*/ + x= new Implementation(); + y; + /*could be of Type: Tester, Tester*/ + y= new Tester(); + y.m3(x); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestExtendedClassesWithBoundedGenerics.java b/test/mycompiler/test/generics/TestExtendedClassesWithBoundedGenerics.java new file mode 100755 index 000000000..25992b9c9 --- /dev/null +++ b/test/mycompiler/test/generics/TestExtendedClassesWithBoundedGenerics.java @@ -0,0 +1,90 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.test.expectationTypes.TypePlaceholderExpect; + +/** + * checks extended usage of generics, however test fails up to now because of no relation between class generics and method generics + * @author + * 21-04-08 + */ + + +public class TestExtendedClassesWithBoundedGenerics extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestExtendedClassesWithBoundedGenerics"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestExtendedClassesWithBoundedGenerics(String name) { + super(name,TestExtendedClassesWithBoundedGenerics.JAVPATH+TestExtendedClassesWithBoundedGenerics.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //interfaces + ClassExpect i1 = new ClassExpect("I1"); + ClassExpect i2 = new ClassExpect("I2"); + + //classes + ClassExpect impl = new ClassExpect("Implementation"); + ClassExpect testExtendedClassesWithBoundedGenerics = new ClassExpect(TestExtendedClassesWithBoundedGenerics.TESTEDCLASSNAME); + ClassExpect tester = new ClassExpect("Tester"); + + //generics + Vector bounds = new Vector(); + bounds.add(new RefType("I1",-1)); + bounds.add(new RefType("I2",-1)); + BoundedGenericTypeVar t = new BoundedGenericTypeVar("T",bounds,-1); + tester.addGeneric(t); + + //methods + MethodExpect m1 = new MethodExpect("m1", new TypePlaceholderExpect("a")); + i1.addMethod(m1); + MethodExpect m2 = new MethodExpect("m2", new TypePlaceholderExpect("b")); + i2.addMethod(m2); + + MethodExpect mImpl1 = new MethodExpect("m1", new RefType("void",-1)); + MethodExpect mImpl2 = new MethodExpect("m2", new RefType("void",-1)); + + impl.addMethod(mImpl1); + impl.addMethod(mImpl2); + + MethodExpect m3 = new MethodExpect("m3", new RefType("void",-1)); + m3.addParameter(new VarExpect("x", t)); + tester.addMethod(m3); + + MethodExpect m = new MethodExpect("m", new RefType("void",-1)); + VarExpect x = new VarExpect("x",new RefType("Implementation",-1)); + //x.addExpectedType(new RefType("I1",-1)); + //x.addExpectedType(new RefType("I2",-1)); + m.getBlock().addLocalVar(x); + + Vector testerParams1 = new Vector(); + testerParams1.add(new RefType("Implementation",-1)); + Vector testerParams2 = new Vector(); + testerParams2.add(new SuperWildcardType(-1,new RefType("Implementation",-1))); + VarExpect y = new VarExpect("y",new RefType("Tester",testerParams1,-1)); + y.addExpectedType(new RefType("Tester",testerParams2,-1)); + m.getBlock().addLocalVar(y); + + testExtendedClassesWithBoundedGenerics.addMethod(m); + + Expectation ret = new Expectation(testExtendedClassesWithBoundedGenerics); + ret.addClass(i1); + ret.addClass(i2); + ret.addClass(impl); + ret.addClass(tester); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestNestedGenerics.jav b/test/mycompiler/test/generics/TestNestedGenerics.jav new file mode 100755 index 000000000..1b34d70c4 --- /dev/null +++ b/test/mycompiler/test/generics/TestNestedGenerics.jav @@ -0,0 +1,14 @@ +class A{ + +} + +public class TestNestedGenerics{ + ,C> void foo(T a,C b){} + + void m(){ + TestNestedGenerics t = new TestNestedGenerics(); + String str = new String(); + A a = new A(); + t.foo(a,str); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestNestedGenerics.java b/test/mycompiler/test/generics/TestNestedGenerics.java new file mode 100755 index 000000000..9ed0a0080 --- /dev/null +++ b/test/mycompiler/test/generics/TestNestedGenerics.java @@ -0,0 +1,64 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.mytype.ExtendsWildcardType; +/** + * 16-05-08 + * @author + * + * this test tests for nested generics, meaning a generic whose bound is another class with a generic + */ +public class TestNestedGenerics extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestNestedGenerics"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestNestedGenerics(String name) { + super(name,TestNestedGenerics.JAVPATH+TestNestedGenerics.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testNestedGenerics = new ClassExpect(TestNestedGenerics.TESTEDCLASSNAME); + ClassExpect a = new ClassExpect("A"); + a.addGeneric(new GenericTypeVar("T",-1)); + + //Methods + MethodExpect foo = new MethodExpect("foo",new RefType("void",-1)); + BoundedGenericTypeVar genericT = new BoundedGenericTypeVar("T",-1); + GenericTypeVar genericC = new GenericTypeVar("C",-1); + Vector param = new Vector(); + param.add(genericC); + genericT.addBound(new RefType("A",param,-1)); + foo.addParameter(new VarExpect("a",genericT)); + foo.addParameter(new VarExpect("b",genericC)); + + MethodExpect m = new MethodExpect("m", new RefType("void",-1)); + m.getBlock().addLocalVar(new VarExpect("t", new RefType("TestNestedGenerics",-1))); + m.getBlock().addLocalVar(new VarExpect("str",new RefType("java.lang.String",-1))); + RefType typeString = new RefType("java.lang.String",-1); + Vectorparam2 = new Vector(); + param2.add(typeString); + m.getBlock().addLocalVar(new VarExpect("a", new RefType("A",param2,-1))); + + testNestedGenerics.addMethod(foo); + testNestedGenerics.addMethod(m); + + Expectation ret = new Expectation(testNestedGenerics); + ret.addClass(a); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestNestedGenericsNonExistingType.jav b/test/mycompiler/test/generics/TestNestedGenericsNonExistingType.jav new file mode 100755 index 000000000..428cdda4c --- /dev/null +++ b/test/mycompiler/test/generics/TestNestedGenericsNonExistingType.jav @@ -0,0 +1,6 @@ + +public class TestNestedGenerics{ + + ,C> void foo(T a,C b){} + +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestNestedGenericsNonExistingType.java b/test/mycompiler/test/generics/TestNestedGenericsNonExistingType.java new file mode 100755 index 000000000..f1a512680 --- /dev/null +++ b/test/mycompiler/test/generics/TestNestedGenericsNonExistingType.java @@ -0,0 +1,51 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.mytype.ExtendsWildcardType; +/** + * 16-05-08 + * @author + * + * tests case where bounds are of a non exisiting type -> should throw error + */ +public class TestNestedGenericsNonExistingType extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestNestedGenericsNonExistingType"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestNestedGenericsNonExistingType(String name) { + super(name,TestNestedGenericsNonExistingType.JAVPATH+TestNestedGenericsNonExistingType.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testNestedGenericsNonExistingType = new ClassExpect(TestNestedGenericsNonExistingType.TESTEDCLASSNAME); + + //Methods + MethodExpect foo = new MethodExpect("foo",new RefType("void",-1)); + BoundedGenericTypeVar genericT = new BoundedGenericTypeVar("T",-1); + GenericTypeVar genericC = new GenericTypeVar("C",-1); + Vector param = new Vector(); + param.add(genericC); + genericT.addBound(new RefType("A",param,-1)); + foo.addParameter(new VarExpect("a",genericT)); + foo.addParameter(new VarExpect("b",genericC)); + + testNestedGenericsNonExistingType.addMethod(foo); + + return new Expectation(testNestedGenericsNonExistingType); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenerics.jav b/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenerics.jav new file mode 100755 index 000000000..622a50079 --- /dev/null +++ b/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenerics.jav @@ -0,0 +1,30 @@ +import java.util.Vector; +import java.util.HashMap; + +public class TestSimpleClassesWithBoundedGenerics { + + public ma(T x) { + return x; + } +} + +class A { + + public m1() { + x; + x= new TestSimpleClassesWithBoundedGenerics(); + return x.ma(3); + } + + public m2() { + x; + x = new TestSimpleClassesWithBoundedGenerics(); + } +/* + public m2() { + x; + x= new TestSimpleClassesWithBoundedGenerics(); + return x.m(new Double(3.)); + } +*/ +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenerics.java b/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenerics.java new file mode 100755 index 000000000..75a0c54eb --- /dev/null +++ b/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenerics.java @@ -0,0 +1,71 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.mytype.ExtendsWildcardType; +/** + * 13-05-08 + * @author + * + * test bounded generics + */ +public class TestSimpleClassesWithBoundedGenerics extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestSimpleClassesWithBoundedGenerics"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestSimpleClassesWithBoundedGenerics(String name) { + super(name,TestSimpleClassesWithBoundedGenerics.JAVPATH+TestSimpleClassesWithBoundedGenerics.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testSimpleClassesWithBoundedGenerics = new ClassExpect(TestSimpleClassesWithBoundedGenerics.TESTEDCLASSNAME); + ClassExpect a = new ClassExpect("A"); + + //generics + BoundedGenericTypeVar t = new BoundedGenericTypeVar("T",-1); + t.addBound(new RefType("java.lang.Number",-1)); + testSimpleClassesWithBoundedGenerics.addGeneric(t); + + + //methods + MethodExpect ma = new MethodExpect("ma", t); + ma.addParameter(new VarExpect("x", t)); + testSimpleClassesWithBoundedGenerics.addMethod(ma); + + MethodExpect m1 = new MethodExpect("m1", new RefType("java.lang.Integer",-1)); + Vector param = new Vector(); + param.add(new RefType("java.lang.Integer",-1)); + m1.getBlock().addLocalVar(new VarExpect("x", new RefType(TestSimpleClassesWithBoundedGenerics.TESTEDCLASSNAME,param,-1))); + a.addMethod(m1); + + MethodExpect m2 = new MethodExpect("m2", new RefType("void",-1)); + Vector testerParams1 = new Vector(); + testerParams1.add(new RefType("java.lang.Double",-1)); + Vector testerParams2 = new Vector(); + testerParams2.add(new SuperWildcardType(-1,new RefType("java.lang.Double",-1))); + Vector testerParams3 = new Vector(); + testerParams3.add(new ExtendsWildcardType(-1,new RefType("java.lang.Double",-1))); + VarExpect x = new VarExpect("x",new RefType("TestSimpleClassesWithBoundedGenerics",testerParams1,-1)); + x.addExpectedType(new RefType("TestSimpleClassesWithBoundedGenerics",testerParams2,-1)); + x.addExpectedType(new RefType("TestSimpleClassesWithBoundedGenerics",testerParams3,-1)); + m2.getBlock().addLocalVar(x); + a.addMethod(m2); + + Expectation ret = new Expectation(testSimpleClassesWithBoundedGenerics); + ret.addClass(a); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenericsNegative.jav b/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenericsNegative.jav new file mode 100755 index 000000000..19ef124c3 --- /dev/null +++ b/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenericsNegative.jav @@ -0,0 +1,17 @@ + +public class TestSimpleClassesWithBoundedGenericsNegative { + + public m(T x) { + return x; + } + +} + +class A { + public m1() { + x; + x = new TestSimpleClassesWithBoundedGenericsNegative(); + return x.m("abc"); + + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenericsNegative.java b/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenericsNegative.java new file mode 100755 index 000000000..074b74df7 --- /dev/null +++ b/test/mycompiler/test/generics/TestSimpleClassesWithBoundedGenericsNegative.java @@ -0,0 +1,62 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.mytype.Type; + +/** + * verifies correct identification of a bounded generic which is instanciated with a type not included in bounds + * @author tom + * + */ + + +public class TestSimpleClassesWithBoundedGenericsNegative extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestSimpleClassesWithBoundedGenericsNegative"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestSimpleClassesWithBoundedGenericsNegative(String name) { + super(name,TestSimpleClassesWithBoundedGenericsNegative.JAVPATH+TestSimpleClassesWithBoundedGenericsNegative.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testSimpleClassesWithBoundedGenericsNegative = new ClassExpect(TestSimpleClassesWithBoundedGenericsNegative.TESTEDCLASSNAME); + ClassExpect a = new ClassExpect("A"); + + //generics + BoundedGenericTypeVar t = new BoundedGenericTypeVar("T",-1); + t.addBound(new RefType("java.lang.Number",-1)); + testSimpleClassesWithBoundedGenericsNegative.addGeneric(t); + + + //methods + MethodExpect m = new MethodExpect("m", t); + m.addParameter(new VarExpect("x", t)); + testSimpleClassesWithBoundedGenericsNegative.addMethod(m); + + MethodExpect m1 = new MethodExpect("m1", new RefType("java.lang.String",-1)); + Vector param = new Vector(); + param.add(new RefType("java.lang.String",-1)); + m1.getBlock().addLocalVar(new VarExpect("x", new RefType(TestSimpleClassesWithBoundedGenericsNegative.TESTEDCLASSNAME,param,-1))); + a.addMethod(m1); + + Expectation ret = new Expectation(testSimpleClassesWithBoundedGenericsNegative); + ret.addClass(a); + + //Exception expected!!! + ret.addException(new Exception()); + + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestSimpleClassesWithGenerics.jav b/test/mycompiler/test/generics/TestSimpleClassesWithGenerics.jav new file mode 100755 index 000000000..359b9a522 --- /dev/null +++ b/test/mycompiler/test/generics/TestSimpleClassesWithGenerics.jav @@ -0,0 +1,17 @@ +public class TestSimpleClassesWithGenerics { + + public m(T x) { + return x; + } + +} + +class A { + + public method() { + x; + x= new TestSimpleClassesWithGenerics(); + return x.m(3); + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestSimpleClassesWithGenerics.java b/test/mycompiler/test/generics/TestSimpleClassesWithGenerics.java new file mode 100755 index 000000000..586aa42fe --- /dev/null +++ b/test/mycompiler/test/generics/TestSimpleClassesWithGenerics.java @@ -0,0 +1,58 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.mytype.GenericTypeVar; + +/** + * checks simple usage of generics without bounds + * @author tom + * + */ + + +public class TestSimpleClassesWithGenerics extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestSimpleClassesWithGenerics"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestSimpleClassesWithGenerics(String name) { + super(name,TestSimpleClassesWithGenerics.JAVPATH+TestSimpleClassesWithGenerics.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testSimpleClassesWithGenerics = new ClassExpect(TestSimpleClassesWithGenerics.TESTEDCLASSNAME); + ClassExpect a = new ClassExpect("A"); + + //generics + GenericTypeVar t = new GenericTypeVar("T",-1); + testSimpleClassesWithGenerics.addGeneric(t); + + + //methods + MethodExpect m = new MethodExpect("m", t); + m.addParameter(new VarExpect("x", t)); + testSimpleClassesWithGenerics.addMethod(m); + + MethodExpect m1 = new MethodExpect("method", new RefType("java.lang.Integer",-1)); + Vector param = new Vector(); + param.add(new RefType("java.lang.Integer",-1)); + m1.getBlock().addLocalVar(new VarExpect("x", new RefType(TestSimpleClassesWithGenerics.TESTEDCLASSNAME,param,-1))); + a.addMethod(m1); + + Expectation ret = new Expectation(testSimpleClassesWithGenerics); + ret.addClass(a); + + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestSimpleClassesWithGenericsNegative.jav b/test/mycompiler/test/generics/TestSimpleClassesWithGenericsNegative.jav new file mode 100755 index 000000000..938ea5044 --- /dev/null +++ b/test/mycompiler/test/generics/TestSimpleClassesWithGenericsNegative.jav @@ -0,0 +1,17 @@ +public class TestSimpleClassesWithGenericsNegative { + + public m(T x) { + return x; + } + +} + +class A { + + public method() { + x; + x= new TestSimpleClassesWithGenerics(); + return x.m("abc"); + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/generics/TestSimpleClassesWithGenericsNegative.java b/test/mycompiler/test/generics/TestSimpleClassesWithGenericsNegative.java new file mode 100755 index 000000000..9ebb680f5 --- /dev/null +++ b/test/mycompiler/test/generics/TestSimpleClassesWithGenericsNegative.java @@ -0,0 +1,59 @@ +package mycompiler.test.generics; + +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.mytype.GenericTypeVar; + +/** + * checks whether wrong usage of generics is detected + * @author tom + * + */ + + +public class TestSimpleClassesWithGenericsNegative extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestSimpleClassesWithGenericsNegative"; + private final static String JAVPATH="test/mycompiler/test/generics/"; + + public TestSimpleClassesWithGenericsNegative(String name) { + super(name,TestSimpleClassesWithGenericsNegative.JAVPATH+TestSimpleClassesWithGenericsNegative.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testSimpleClassesWithGenericsNegative = new ClassExpect(TestSimpleClassesWithGenericsNegative.TESTEDCLASSNAME); + ClassExpect a = new ClassExpect("A"); + + //generics + GenericTypeVar t = new GenericTypeVar("T",-1); + testSimpleClassesWithGenericsNegative.addGeneric(t); + + + //methods + MethodExpect m = new MethodExpect("m", t); + m.addParameter(new VarExpect("x", t)); + testSimpleClassesWithGenericsNegative.addMethod(m); + + MethodExpect m1 = new MethodExpect("method", new RefType("java.lang.String",-1)); + Vector param = new Vector(); + param.add(new RefType("java.lang.Integer",-1)); + m1.getBlock().addLocalVar(new VarExpect("x", new RefType(TestSimpleClassesWithGenericsNegative.TESTEDCLASSNAME,param,-1))); + a.addMethod(m1); + + Expectation ret = new Expectation(testSimpleClassesWithGenericsNegative); + ret.addClass(a); + //Exception + ret.addException(new Exception()); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/AllTestsInferenceByCharacteristic.java b/test/mycompiler/test/inferenceByCharacteristic/AllTestsInferenceByCharacteristic.java new file mode 100755 index 000000000..61f294e16 --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/AllTestsInferenceByCharacteristic.java @@ -0,0 +1,26 @@ +package mycompiler.test.inferenceByCharacteristic; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsInferenceByCharacteristic { + + public static Test suite() { + TestSuite suite = new TestSuite( + "Test for mycompiler.test.inferenceByCharacteristic"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestInferenceStdTypeByReturnType.class); + suite.addTestSuite(TestInferenceOwnTypeByMemberAcrossClasses.class); + suite.addTestSuite(TestInferenceOwnTypeByReturnType.class); + suite.addTestSuite(TestInferenceStdTypeByOperation.class); + suite.addTestSuite(TestInferenceOwnTypeByMember.class); + suite.addTestSuite(TestInferenceOwnTypeByMethodReturnTypeMixed1.class); + suite.addTestSuite(TestInferenceOwnTypeByMethodParameter.class); + suite.addTestSuite(TestInferenceOwnTypeByMethodCallAcrossClasses.class); + suite.addTestSuite(TestInferenceOwnTypeByMethodCall.class); + suite.addTestSuite(TestInferenceOwnTypeByReturnTypeAcrossClasses.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMember.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMember.jav new file mode 100755 index 000000000..d6b39b878 --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMember.jav @@ -0,0 +1,16 @@ +public class TestInferenceOwnTypeByMember { + + Float a; + + public void m1(b) { + a += b; + } + + public void m2(a) { + this.a=a; + } + + public m3() { + return a; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMember.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMember.java new file mode 100755 index 000000000..d5219e39f --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMember.java @@ -0,0 +1,52 @@ +package mycompiler.test.inferenceByCharacteristic; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 28-04-08 + * @author + * + * test inference by member of same class + */ + +public class TestInferenceOwnTypeByMember extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInferenceOwnTypeByMember"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceOwnTypeByMember(String name) { + super(name,TestInferenceOwnTypeByMember.JAVPATH+TestInferenceOwnTypeByMember.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testInferenceOwnTypeByMember = new ClassExpect(TestInferenceOwnTypeByMember.TESTEDCLASSNAME); + //Member + testInferenceOwnTypeByMember.addMember(new VarExpect("a", new RefType("java.lang.Float",-1))); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1),0); + m1.addParameter(new VarExpect("b",new RefType("java.lang.Float",-1))); + + MethodExpect m2 = new MethodExpect("m2",new RefType("void",-1),0); + m2.addParameter(new VarExpect("a",new RefType("java.lang.Float",-1))); + + MethodExpect m3 = new MethodExpect("m3",new RefType("java.lang.Float",-1),0); + + + + + testInferenceOwnTypeByMember.addMethod(m1); + //testInferenceOwnTypeByMember.addMethod(m2); + testInferenceOwnTypeByMember.addMethod(m3); + + return new Expectation(testInferenceOwnTypeByMember); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMemberAcrossClasses.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMemberAcrossClasses.jav new file mode 100755 index 000000000..c595b224b --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMemberAcrossClasses.jav @@ -0,0 +1,14 @@ +class A { + + public Character c; + +} + +public class TestInferenceOwnTypeByMemberAcrossClasses { + + public m1(a) { + x; + x = new A(); + a=x.c; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMemberAcrossClasses.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMemberAcrossClasses.java new file mode 100755 index 000000000..132a674bf --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMemberAcrossClasses.java @@ -0,0 +1,47 @@ +package mycompiler.test.inferenceByCharacteristic; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 28-04-08 + * @author + * + * test inference by member across different classes + */ + +public class TestInferenceOwnTypeByMemberAcrossClasses extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInferenceOwnTypeByMemberAcrossClasses"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceOwnTypeByMemberAcrossClasses(String name) { + super(name,TestInferenceOwnTypeByMemberAcrossClasses.JAVPATH+TestInferenceOwnTypeByMemberAcrossClasses.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect a = new ClassExpect("A"); + ClassExpect testInferenceOwnTypeByMemberAcrossClasses = new ClassExpect(TestInferenceOwnTypeByMemberAcrossClasses.TESTEDCLASSNAME); + //Member + a.addMember(new VarExpect("c", new RefType("java.lang.Character",-1))); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1),0); + m1.addParameter(new VarExpect("a",new RefType("java.lang.Character",-1))); + m1.getBlock().addLocalVar(new VarExpect("x",new RefType("A",-1))); + + + testInferenceOwnTypeByMemberAcrossClasses.addMethod(m1); + + Expectation ret = new Expectation(testInferenceOwnTypeByMemberAcrossClasses); + ret.addClass(a); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.jav new file mode 100755 index 000000000..fc3ca3d2e --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.jav @@ -0,0 +1,32 @@ +public class TestInferenceOwnTypeByMethodCall{ + + public m1(a) { + return a; + } + + public Integer m2(a) { + return a; + } + + public m3(a) { + return a; + } + + + + public void m01(d) { + e; + e=m1(d); + } + + public void m02(d) { + e; + e=m2(d); + } + + public void m03(c,Character d) { + e; + e=c.m3(d); + } + + } \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.java new file mode 100755 index 000000000..158114383 --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.java @@ -0,0 +1,68 @@ +package mycompiler.test.inferenceByCharacteristic; + +import org.apache.log4j.xml.DOMConfigurator; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.GenericTypeVarExpect; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 29-04-08 + * @author + * + * test checks extended inference by return type of a method of same class + */ + +public class TestInferenceOwnTypeByMethodCall extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInferenceOwnTypeByMethodCall"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceOwnTypeByMethodCall(String name) { + super(name,TestInferenceOwnTypeByMethodCall.JAVPATH+TestInferenceOwnTypeByMethodCall.TESTEDCLASSNAME + ".jav"); + DOMConfigurator.configure("test/log4jTesting.xml"); + DOMConfigurator.configure("log4j.xml"); + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testInferenceOwnTypeByMethodCall = new ClassExpect(TestInferenceOwnTypeByMethodCall.TESTEDCLASSNAME); + //Member + + //Methods + MethodExpect m1 = new MethodExpect("m1",new GenericTypeVarExpect("a")); + m1.addParameter(new VarExpect("a",new GenericTypeVarExpect("a"))); + MethodExpect m2 = new MethodExpect("m2",new RefType("java.lang.Integer",-1)); + m2.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + MethodExpect m3 = new MethodExpect("m3",new RefType("java.lang.Character",-1)); + m3.addParameter(new VarExpect("a",new RefType("java.lang.Character",-1))); + + MethodExpect m01 = new MethodExpect("m01",new RefType("void",-1)); + m01.addParameter(new VarExpect("d",new GenericTypeVarExpect("a"))); + m01.getBlock().addLocalVar(new VarExpect("e",new GenericTypeVarExpect("a"))); + MethodExpect m02 = new MethodExpect("m02",new RefType("void",-1),0); + m02.addParameter(new VarExpect("d",new RefType("java.lang.Integer",-1))); + m02.getBlock().addLocalVar(new VarExpect("e",new RefType("java.lang.Integer",-1))); + MethodExpect m03 = new MethodExpect("m03",new RefType("void",-1),0); + m03.addParameter(new VarExpect("c",new RefType(TestInferenceOwnTypeByMethodCall.TESTEDCLASSNAME,-1))); + m03.addParameter(new VarExpect("d",new RefType("java.lang.Character",-1))); + m03.getBlock().addLocalVar(new VarExpect("e",new RefType("java.lang.Character",-1))); + + + testInferenceOwnTypeByMethodCall.addMethod(m1); + testInferenceOwnTypeByMethodCall.addMethod(m2); + testInferenceOwnTypeByMethodCall.addMethod(m3); + + testInferenceOwnTypeByMethodCall.addMethod(m01); + testInferenceOwnTypeByMethodCall.addMethod(m02); + testInferenceOwnTypeByMethodCall.addMethod(m03); + + + return new Expectation(testInferenceOwnTypeByMethodCall); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCallAcrossClasses.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCallAcrossClasses.jav new file mode 100755 index 000000000..4bb4bcce8 --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCallAcrossClasses.jav @@ -0,0 +1,18 @@ +class A{ + public mA(x){ + return(x); + } +} + +class TestInferenceOwnTypeByMethodCallAcrossClasses{ + + public m(Integer a, String b){ + x; + x=new A(); + c; + c=x.mA(a); + d; + d=x.mA(b); + + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCallAcrossClasses.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCallAcrossClasses.java new file mode 100755 index 000000000..0f5e38ba5 --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCallAcrossClasses.java @@ -0,0 +1,55 @@ +package mycompiler.test.inferenceByCharacteristic; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.test.expectationTypes.GenericTypeVarExpect; + +/** + * 28-04-08 + * @author + * + * tests method call across classes + */ + +public class TestInferenceOwnTypeByMethodCallAcrossClasses extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInferenceOwnTypeByMethodCallAcrossClasses"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceOwnTypeByMethodCallAcrossClasses(String name) { + super(name,TestInferenceOwnTypeByMethodCallAcrossClasses.JAVPATH+TestInferenceOwnTypeByMethodCallAcrossClasses.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect a = new ClassExpect("A"); + ClassExpect testInferenceOwnTypeByMethodCallAcrossClasses = new ClassExpect(TestInferenceOwnTypeByMethodCallAcrossClasses.TESTEDCLASSNAME); + //Member + + //Methods + MethodExpect m = new MethodExpect("m",new RefType("void",-1),0); + m.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + m.addParameter(new VarExpect("b",new RefType("java.lang.String",-1))); + m.getBlock().addLocalVar(new VarExpect("c",new RefType("java.lang.Integer",-1))); + m.getBlock().addLocalVar(new VarExpect("d",new RefType("java.lang.String",-1))); + m.getBlock().addLocalVar(new VarExpect("x",new RefType("A",-1))); + + + MethodExpect mA = new MethodExpect("mA",new GenericTypeVarExpect("a")); + mA.addParameter(new VarExpect("x",new GenericTypeVarExpect("a"))); + + + testInferenceOwnTypeByMethodCallAcrossClasses.addMethod(m); + a.addMethod(mA); + + Expectation ret = new Expectation(testInferenceOwnTypeByMethodCallAcrossClasses); + ret.addClass(a); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodParameter.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodParameter.jav new file mode 100755 index 000000000..0970988fc --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodParameter.jav @@ -0,0 +1,19 @@ +class A { + static void m() {} +} + +public class TestInferenceOwnTypeByMethodParameter { + + m1(a,b) { + return a+b; + } + + m2(java.lang.String a) { + return a; + } + + m3(a) { + return a.m(); + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodParameter.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodParameter.java new file mode 100755 index 000000000..183e1553d --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodParameter.java @@ -0,0 +1,61 @@ +package mycompiler.test.inferenceByCharacteristic; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** + * 28-04-08 + * @author + * + * checks inference by method parameter + */ + +public class TestInferenceOwnTypeByMethodParameter extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInferenceOwnTypeByMethodParameter"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceOwnTypeByMethodParameter(String name) { + super(name,TestInferenceOwnTypeByMethodParameter.JAVPATH+TestInferenceOwnTypeByMethodParameter.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect a = new ClassExpect("A"); + ClassExpect testInferenceOwnTypeByMethodParameter = new ClassExpect(TestInferenceOwnTypeByMethodParameter.TESTEDCLASSNAME); + //Member + + //Methods + MethodExpect m = new MethodExpect("m", new RefType("void",-1)); + + MethodExpect m1 = new MethodExpect("m1"); + m1.setReturntypes(createVectorAllNumberTypes()); + VarExpect m1a = new VarExpect("a"); + VarExpect m1b = new VarExpect("b"); + m1a.setExpectedType(createVectorAllNumberTypes()); + m1b.setExpectedType(createVectorAllNumberTypes()); + m1.addParameter(m1a); + m1.addParameter(m1b); + + MethodExpect m2 = new MethodExpect("m2",new RefType("java.lang.String",-1)); + m2.addParameter(new VarExpect("a", new RefType("java.lang.String",-1))); + + + MethodExpect m3 = new MethodExpect("m3",new RefType("void",-1),0); + m3.addParameter(new VarExpect("a",new RefType("A",-1))); + + testInferenceOwnTypeByMethodParameter.addMethod(m1); + testInferenceOwnTypeByMethodParameter.addMethod(m2); + testInferenceOwnTypeByMethodParameter.addMethod(m3); + a.addMethod(m); + + Expectation ret = new Expectation(testInferenceOwnTypeByMethodParameter); + ret.addClass(a); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodReturnTypeMixed1.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodReturnTypeMixed1.jav new file mode 100755 index 000000000..b6e341d3f --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodReturnTypeMixed1.jav @@ -0,0 +1,20 @@ +class A1{ + void foo(java.lang.String x){} +} +class A2{ + void foo(java.lang.Integer y){} +} +class B1{ + java.lang.String bar(){return("");} +} +class B2{ + java.lang.Integer bar(){return(1);} +} +public class TestInferenceOwnTypeByMethodReturnTypeMixed1{ + method1(a,b){ + a.foo(b.bar()); + } + method2(a,B2 b) { + a.foo(b.bar()); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodReturnTypeMixed1.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodReturnTypeMixed1.java new file mode 100755 index 000000000..1ed0cff0e --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodReturnTypeMixed1.java @@ -0,0 +1,71 @@ +package mycompiler.test.inferenceByCharacteristic; +/** +* 26-04-08 +* @author +* +* identifying type of a variable by parameter passed to a method of another class +*/ +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestInferenceOwnTypeByMethodReturnTypeMixed1 extends AbstractInferenceTest{ + private final static String TESTEDCLASSNAME="TestInferenceOwnTypeByMethodReturnTypeMixed1"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceOwnTypeByMethodReturnTypeMixed1(String name) { + super(name,TestInferenceOwnTypeByMethodReturnTypeMixed1.JAVPATH+TestInferenceOwnTypeByMethodReturnTypeMixed1.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //classes + ClassExpect testInferenceOwnTypeByMethodReturnTypeMixed1 = new ClassExpect(TestInferenceOwnTypeByMethodReturnTypeMixed1.TESTEDCLASSNAME); + ClassExpect a1 = new ClassExpect("A1"); + ClassExpect a2 = new ClassExpect("A2"); + ClassExpect b1 = new ClassExpect("B1"); + ClassExpect b2 = new ClassExpect("B2"); + + //Methods + MethodExpect method1 = new MethodExpect("method1",new RefType("void",-1)); + MethodExpect method2 = new MethodExpect("method2",new RefType("void",-1)); + VarExpect method1a = new VarExpect("a",new RefType("A1",-1)); + method1a.addExpectedType(new RefType("A2",-1)); + VarExpect method1b = new VarExpect("b",new RefType("B1",-1)); + method1b.addExpectedType(new RefType("B2",-1)); + method1.addParameter(method1a); + method1.addParameter(method1b); + method2.addParameter(new VarExpect("a", new RefType("A2",-1))); + method2.addParameter(new VarExpect("b", new RefType("B2",-1))); + + + MethodExpect foo1 = new MethodExpect("foo", new RefType("void",-1)); + foo1.addParameter(new VarExpect("x", new RefType("java.lang.String",-1))); + MethodExpect foo2 = new MethodExpect("foo", new RefType("void",-1)); + foo2.addParameter(new VarExpect("y", new RefType("java.lang.Integer",-1))); + + MethodExpect bar1 = new MethodExpect("bar", new RefType("java.lang.String",-1)); + MethodExpect bar2 = new MethodExpect("bar", new RefType("java.lang.Integer",-1)); + + + testInferenceOwnTypeByMethodReturnTypeMixed1.addMethod(method1); + testInferenceOwnTypeByMethodReturnTypeMixed1.addMethod(method2); + a1.addMethod(foo1); + a2.addMethod(foo2); + b1.addMethod(bar1); + b2.addMethod(bar2); + + Expectation ret = new Expectation(testInferenceOwnTypeByMethodReturnTypeMixed1); + ret.addClass(a1); + ret.addClass(a2); + ret.addClass(b1); + ret.addClass(b2); + + + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnType.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnType.jav new file mode 100755 index 000000000..559fde50a --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnType.jav @@ -0,0 +1,18 @@ +public class TestInferenceOwnTypeByReturnType { + + public java.lang.Integer m1(a) { + return a; + } + + public String m2() { + return "abc"; + } + + public void m3(a) { + a=m2(); + } + + public java.lang.Integer m4(a,b) { + return a+b; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnType.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnType.java new file mode 100755 index 000000000..a4ab611aa --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnType.java @@ -0,0 +1,56 @@ +package mycompiler.test.inferenceByCharacteristic; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 28-04-08 + * @author + * + * checks inference by method return type +*/ + +public class TestInferenceOwnTypeByReturnType extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInferenceOwnTypeByReturnType"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceOwnTypeByReturnType(String name) { + super(name,TestInferenceOwnTypeByReturnType.JAVPATH+TestInferenceOwnTypeByReturnType.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testInferenceOwnTypeByReturnType = new ClassExpect(TestInferenceOwnTypeByReturnType.TESTEDCLASSNAME); + //Member + + //Methods + + MethodExpect m1 = new MethodExpect("m1",new RefType("java.lang.Integer",-1)); + m1.addParameter(new VarExpect("a", new RefType("java.lang.Integer",-1))); + + MethodExpect m2 = new MethodExpect("m2",new RefType("java.lang.String",-1)); + + MethodExpect m3 = new MethodExpect("m3",new RefType("void",-1)); + m3.addParameter(new VarExpect("a",new RefType("java.lang.String",-1))); + + MethodExpect m4 = new MethodExpect("m4", new RefType("java.lang.Integer",-1)); + m4.addParameter(new VarExpect("a", new RefType("java.lang.Integer",-1))); + m4.addParameter(new VarExpect("b", new RefType("java.lang.Integer",-1))); + + testInferenceOwnTypeByReturnType.addMethod(m1); + testInferenceOwnTypeByReturnType.addMethod(m2); + testInferenceOwnTypeByReturnType.addMethod(m3); + testInferenceOwnTypeByReturnType.addMethod(m4); + + + return new Expectation(testInferenceOwnTypeByReturnType); + + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnTypeAcrossClasses.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnTypeAcrossClasses.jav new file mode 100755 index 000000000..243df6d9a --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnTypeAcrossClasses.jav @@ -0,0 +1,23 @@ +class A{ + public String m() { + return "abc"; + } +} + +class B{ + public Integer m() { + return 1; + } +} + +public class TestInferenceOwnTypeByReturnTypeAcrossClasses { + + public main1(java.lang.Integer i, x){ + i=x.m(); + } + + public main2(i,x) { + i=x.m(); + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnTypeAcrossClasses.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnTypeAcrossClasses.java new file mode 100755 index 000000000..c2df63787 --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByReturnTypeAcrossClasses.java @@ -0,0 +1,66 @@ +package mycompiler.test.inferenceByCharacteristic; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** +* 27-04-08 +* @author +* +* checks inference by return type across classes +*/ +public class TestInferenceOwnTypeByReturnTypeAcrossClasses extends AbstractInferenceTest{ + + private final static String TESTEDCLASSNAME="TestInferenceOwnTypeByReturnTypeAcrossClasses"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceOwnTypeByReturnTypeAcrossClasses(String name) { + super(name,TestInferenceOwnTypeByReturnTypeAcrossClasses.JAVPATH+TestInferenceOwnTypeByReturnTypeAcrossClasses.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //classes + ClassExpect testInferenceOwnTypeByReturnTypeAcrossClasses = new ClassExpect(TestInferenceOwnTypeByReturnTypeAcrossClasses.TESTEDCLASSNAME); + ClassExpect a = new ClassExpect("A"); + ClassExpect b = new ClassExpect("B"); + + //Methods + MethodExpect main1 = new MethodExpect("main1",new RefType("void",-1),0); + main1.addParameter(new VarExpect("i",new RefType("java.lang.Integer",-1))); + main1.addParameter(new VarExpect("x",new RefType("B",-1))); + + MethodExpect main2 = new MethodExpect("main2",new RefType("void",-1),0); + VarExpect main2i = new VarExpect("i", new RefType("java.lang.Integer",-1)); + main2i.addExpectedType(new RefType("java.lang.String",-1)); + main2.addParameter(main2i); + VarExpect main2x = new VarExpect("x", new RefType("A",-1)); + main2x.addExpectedType(new RefType("B",-1)); + main2.addParameter(main2x); + + MethodExpect foo1 = new MethodExpect("foo", new RefType("void",-1)); + foo1.addParameter(new VarExpect("x", new RefType("java.lang.String",-1))); + MethodExpect foo2 = new MethodExpect("foo", new RefType("void",-1)); + foo2.addParameter(new VarExpect("y", new RefType("java.lang.Integer",-1))); + + MethodExpect mA = new MethodExpect("m", new RefType("java.lang.String",-1)); + MethodExpect mB = new MethodExpect("m", new RefType("java.lang.Integer",-1)); + + + testInferenceOwnTypeByReturnTypeAcrossClasses.addMethod(main1); + testInferenceOwnTypeByReturnTypeAcrossClasses.addMethod(main2); + a.addMethod(mA); + b.addMethod(mB); + + Expectation ret = new Expectation(testInferenceOwnTypeByReturnTypeAcrossClasses); + ret.addClass(a); + ret.addClass(b); + + + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByMember.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByMember.jav new file mode 100755 index 000000000..a2c370f4b --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByMember.jav @@ -0,0 +1,9 @@ +import java.lang.System; + +public class TestInferenceStdTypeByMember { + + public m1(a) { + a=System.out; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByOperation.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByOperation.jav new file mode 100755 index 000000000..955a14783 --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByOperation.jav @@ -0,0 +1,13 @@ +import java.util.HashMap; +import java.lang.Object; + +public class TestInferenceStdTypeByOperation { + + public m1(a) { + a.put("1","1"); + } + + public m2(b) { + b.toString(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByOperation.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByOperation.java new file mode 100755 index 000000000..937a8b95e --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByOperation.java @@ -0,0 +1,47 @@ +package mycompiler.test.inferenceByCharacteristic; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** +* 4-05-08 +* @author +* +* checks inference of std types by operation +*/ + +public class TestInferenceStdTypeByOperation extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInferenceStdTypeByOperation"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceStdTypeByOperation(String name) { + super(name,TestInferenceStdTypeByOperation.JAVPATH+TestInferenceStdTypeByOperation.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testInferenceStdTypeByOperation = new ClassExpect(TestInferenceStdTypeByOperation.TESTEDCLASSNAME); + //Member + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1)); + m1.addParameter(new VarExpect("a",new RefType("java.util.HashMap",-1))); + + MethodExpect m2 = new MethodExpect("m2",new RefType("void",-1)); + m2.addParameter(new VarExpect("b", new RefType("java.lang.Object",-1))); + + testInferenceStdTypeByOperation.addMethod(m1); + testInferenceStdTypeByOperation.addMethod(m2); + + + return new Expectation(testInferenceStdTypeByOperation); + + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByReturnType.jav b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByReturnType.jav new file mode 100755 index 000000000..9317cd986 --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByReturnType.jav @@ -0,0 +1,18 @@ +import java.util.Vector; +import java.util.ArrayList; + +public class TestInferenceStdTypeByReturnType { + + public void m1(a) { + b; + b= new Vector(); + a = b.size(); + } + + public void m2(a) { + b; + b= new ArrayList(); + a = b.get(0); + + } +} \ No newline at end of file diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByReturnType.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByReturnType.java new file mode 100755 index 000000000..4de16f852 --- /dev/null +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceStdTypeByReturnType.java @@ -0,0 +1,80 @@ +package mycompiler.test.inferenceByCharacteristic; + +import java.util.Vector; + +import mycompiler.mytype.ExtendsWildcardType; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.mytype.SuperWildcardType; + +/** +* 4-05-08 +* @author +* +* checks inference of std types by return type +*/ + +public class TestInferenceStdTypeByReturnType extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInferenceStdTypeByReturnType"; + private final static String JAVPATH="test/mycompiler/test/inferenceByCharacteristic/"; + + public TestInferenceStdTypeByReturnType(String name) { + super(name,TestInferenceStdTypeByReturnType.JAVPATH+TestInferenceStdTypeByReturnType.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testInferenceStdTypeByReturnType = new ClassExpect(TestInferenceStdTypeByReturnType.TESTEDCLASSNAME); + //Member + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1)); + m1.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + + MethodExpect m2 = new MethodExpect("m2",new RefType("void",-1)); + m2.addParameter(new VarExpect("a", new RefType("java.lang.Object",-1))); + + + + //Vars + VarExpect m1B= new VarExpect("b"); + Vector paramsm1B1 = new Vector(); + paramsm1B1.add(new RefType("java.lang.String",-1)); + m1B.addExpectedType(new RefType("java.util.Vector",paramsm1B1,-1)); + Vector paramsm1B2 = new Vector(); + paramsm1B2.add(new ExtendsWildcardType(-1,new RefType("java.lang.String",-1))); + m1B.addExpectedType(new RefType("java.util.Vector",paramsm1B2,-1)); + Vector paramsm1B3 = new Vector(); + paramsm1B3.add(new SuperWildcardType(-1,new RefType("java.lang.String",-1))); + m1B.addExpectedType(new RefType("java.util.Vector",paramsm1B3,-1)); + m1.getBlock().addLocalVar(m1B); + + VarExpect m2B= new VarExpect("b"); + Vector paramsm2B1 = new Vector(); + paramsm2B1.add(new RefType("java.lang.String",-1)); + m2B.addExpectedType(new RefType("java.util.ArrayList",paramsm2B1,-1)); + Vector paramsm2B2 = new Vector(); + paramsm2B2.add(new ExtendsWildcardType(-1,new RefType("java.lang.String",-1))); + m2B.addExpectedType(new RefType("java.util.ArrayList",paramsm2B2,-1)); + Vector paramsm2B3 = new Vector(); + paramsm2B3.add(new SuperWildcardType(-1,new RefType("java.lang.String",-1))); + m2B.addExpectedType(new RefType("java.util.ArrayList",paramsm2B3,-1)); + m2.getBlock().addLocalVar(m2B); + + + + testInferenceStdTypeByReturnType.addMethod(m1); + testInferenceStdTypeByReturnType.addMethod(m2); + + return new Expectation(testInferenceStdTypeByReturnType); + + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/inheritance/AllTestsInheritance.java b/test/mycompiler/test/javaConcepts/inheritance/AllTestsInheritance.java new file mode 100755 index 000000000..7bfd2ef51 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/AllTestsInheritance.java @@ -0,0 +1,24 @@ +package mycompiler.test.javaConcepts.inheritance; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsInheritance { + + public static Test suite() { + TestSuite suite = new TestSuite( + "Test for mycompiler.test.javaConcepts.inheritance"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestInheritanceCircle.class); + suite.addTestSuite(TestInheritanceMultipleClasses.class); + suite.addTestSuite(TestInheritanceAcrossLevel.class); + suite.addTestSuite(TestInheritanceOverriding.class); + suite.addTestSuite(TestInheritanceConstructor.class); + suite.addTestSuite(TestInheritanceTwoHierarchies.class); + suite.addTestSuite(TestSimpleInheritance.class); + suite.addTestSuite(TestInheritanceMultiple.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceAcrossLevel.jav b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceAcrossLevel.jav new file mode 100755 index 000000000..053275681 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceAcrossLevel.jav @@ -0,0 +1,56 @@ +/* + A + B C +D E + +*/ + +class A { + fooA() {} +} + +class B extends A { + fooB() {} +} + +class C extends A { + fooC(){} +} + +class D extends B { + fooD() {} +} + +class E extends B { + fooE() {} +} + + + +public class TestInheritanceAcrossLevel { + + public m1(x) { + x.fooA(); + return x; + } + + public m2(x) { + x.fooB(); + /*return x;*/ + } + + public m3(x) { + x.fooC(); + /*return x;*/ + } + + public m4(x) { + x.fooD(); + /*return x;*/ + } + + public m5(B x) { + x.fooA(); + return x; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceAcrossLevel.java b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceAcrossLevel.java new file mode 100755 index 000000000..7123952e5 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceAcrossLevel.java @@ -0,0 +1,92 @@ +package mycompiler.test.javaConcepts.inheritance; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestInheritanceAcrossLevel extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestInheritanceAcrossLevel"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/inheritance/"; + + public TestInheritanceAcrossLevel(String name) { + super(name,TestInheritanceAcrossLevel.JAVPATH+TestInheritanceAcrossLevel.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //Classes + ClassExpect a = new ClassExpect("A"); + ClassExpect b = new ClassExpect("B"); + ClassExpect c = new ClassExpect("C"); + ClassExpect d = new ClassExpect("D"); + ClassExpect e = new ClassExpect("E"); + ClassExpect testInheritanceAcrossLevel = new ClassExpect(TestInheritanceAcrossLevel.TESTEDCLASSNAME); + + //methods + MethodExpect fooA = new MethodExpect("fooA", new RefType("void",-1),0); + MethodExpect fooB = new MethodExpect("fooB", new RefType("void",-1),0); + MethodExpect fooC = new MethodExpect("fooC", new RefType("void",-1),0); + MethodExpect fooD = new MethodExpect("fooD", new RefType("void",-1),0); + MethodExpect fooE = new MethodExpect("fooE", new RefType("void",-1),0); + + MethodExpect m1 = new MethodExpect("m1",new RefType("A",-1),0); + m1.addReturntype(new RefType("B",-1)); + m1.addReturntype(new RefType("C",-1)); + m1.addReturntype(new RefType("D",-1)); + m1.addReturntype(new RefType("E",-1)); + VarExpect x1 = new VarExpect("x",new RefType("A",-1)); + x1.addExpectedType(new RefType("B",-1)); + x1.addExpectedType(new RefType("C",-1)); + x1.addExpectedType(new RefType("D",-1)); + x1.addExpectedType(new RefType("E",-1)); + m1.addParameter(x1); + + MethodExpect m2 = new MethodExpect("m2",new RefType("void",-1),0); + VarExpect x2 = new VarExpect("x",new RefType("B",-1)); + x2.addExpectedType(new RefType("D",-1)); + x2.addExpectedType(new RefType("E",-1)); + m2.addParameter(x2); + + MethodExpect m3 = new MethodExpect("m3",new RefType("void",-1),0); + VarExpect x3 = new VarExpect("x",new RefType("C",-1)); + m3.addParameter(x3); + + MethodExpect m4 = new MethodExpect("m4",new RefType("void",-1),0); + VarExpect x4 = new VarExpect("x",new RefType("D",-1)); + m4.addParameter(x4); + + MethodExpect m5 = new MethodExpect("m5",new RefType("A",-1),0); + VarExpect x5 = new VarExpect("x",new RefType("B",-1)); + m5.addReturntype(new RefType("B",-1)); + m5.addParameter(x5); + + //adding methods to classes + a.addMethod(fooA); + b.addMethod(fooB); + c.addMethod(fooC); + d.addMethod(fooD); + e.addMethod(fooE); + + + testInheritanceAcrossLevel.addMethod(m1); + testInheritanceAcrossLevel.addMethod(m2); + testInheritanceAcrossLevel.addMethod(m3); + testInheritanceAcrossLevel.addMethod(m4); + testInheritanceAcrossLevel.addMethod(m5); + + //adding classes to Expectation + Expectation ret = new Expectation(testInheritanceAcrossLevel); + ret.addClass(a); + ret.addClass(b); + ret.addClass(c); + ret.addClass(d); + ret.addClass(e); + return ret; + } + +} + diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceCircle.jav b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceCircle.jav new file mode 100755 index 000000000..354e09f54 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceCircle.jav @@ -0,0 +1,41 @@ +/* + + A + B C + D +*/ + +interface A{ + fooA(); +} + +interface B extends A{ + fooB(); +} + +interface C extends A{} + +class D implements B,C { + fooA() { + } + fooB() { + } +} + +public class TestInheritanceCircle{ + + public m1(x) { + x.fooA(); + /*return x;*/ + } + + public m2(x) { + x.fooB(); + /*return x;*/ + } + public m3(D x) { + x.fooA(); + return x; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceCircle.java b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceCircle.java new file mode 100755 index 000000000..62b514954 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceCircle.java @@ -0,0 +1,82 @@ +package mycompiler.test.javaConcepts.inheritance; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.test.expectationTypes.TypePlaceholderExpect; + + +/* + * Testcase currently adjusted to compiler implementation + */ + +public class TestInheritanceCircle extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestInheritanceCircle"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/inheritance/"; + + public TestInheritanceCircle(String name) { + super(name,TestInheritanceCircle.JAVPATH+TestInheritanceCircle.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //Interfaces + ClassExpect a = new ClassExpect("A"); + ClassExpect b = new ClassExpect("B"); + ClassExpect c = new ClassExpect("C"); + //classes + ClassExpect d = new ClassExpect("D"); + ClassExpect testInheritanceCircle = new ClassExpect(TestInheritanceCircle.TESTEDCLASSNAME); + + //methods + //return type should not be "null" since implementation shows "void" -> Testcase adjusted to current compiler implementation, but shall be changed as soon as adapted + MethodExpect fooAa = new MethodExpect("fooA", new TypePlaceholderExpect("a")); + MethodExpect fooBb = new MethodExpect("fooB", new TypePlaceholderExpect("b")); + MethodExpect fooAd = new MethodExpect("fooA", new RefType("void",-1) ,0); + MethodExpect fooBd = new MethodExpect("fooB", new RefType("void",-1),0); + + + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1),0); + VarExpect x1 = new VarExpect("x",new RefType("A",-1)); + x1.addExpectedType(new RefType("B",-1)); + x1.addExpectedType(new RefType("C",-1)); + x1.addExpectedType(new RefType("D",-1)); + m1.addParameter(x1); + + MethodExpect m2 = new MethodExpect("m2",new RefType("void",-1),0); + VarExpect x2 = new VarExpect("x",new RefType("B",-1)); + x2.addExpectedType(new RefType("D",-1)); + m2.addParameter(x2); + + MethodExpect m3 = new MethodExpect("m3",new RefType("B",-1),0); + m3.addReturntype(new RefType("A",-1)); + m3.addReturntype(new RefType("C",-1)); + m3.addReturntype(new RefType("D",-1)); + VarExpect x3 = new VarExpect("x",new RefType("D",-1)); + m3.addParameter(x3); + + //adding methods to classes + a.addMethod(fooAa); + b.addMethod(fooBb); + d.addMethod(fooAd); + d.addMethod(fooBd); + + testInheritanceCircle.addMethod(m1); + testInheritanceCircle.addMethod(m2); + testInheritanceCircle.addMethod(m3); + + //adding classes to Expectation + Expectation ret = new Expectation(testInheritanceCircle); + ret.addClass(a); + ret.addClass(b); + ret.addClass(c); + ret.addClass(d); + return ret; + } + +} + diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceConstructor.jav b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceConstructor.jav new file mode 100755 index 000000000..11073ccf8 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceConstructor.jav @@ -0,0 +1,27 @@ +class A { + public Integer memberInteger; + + public A(i) { + member=i; + } + +} + +class B extends A { + public String memberString; + public B(i,s) { + super(i); + memberString=s; + } +} + +public class TestInheritanceConstructor { + + public static main() { + x; + x=new B(3,"abc"); + y; + y=x.memberInteger; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceConstructor.java b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceConstructor.java new file mode 100755 index 000000000..17a4070b5 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceConstructor.java @@ -0,0 +1,56 @@ +package mycompiler.test.javaConcepts.inheritance; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/* + * Testcase currently adjusted to compiler implementation + */ + +public class TestInheritanceConstructor extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestInheritanceConstructor"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/inheritance/"; + + public TestInheritanceConstructor(String name) { + super(name,TestInheritanceConstructor.JAVPATH+TestInheritanceConstructor.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //classes + ClassExpect a = new ClassExpect("A"); + a.addMember(new VarExpect("memberInteger",new RefType("java.lang.Integer",-1))); + ClassExpect b = new ClassExpect("B"); + b.addMember(new VarExpect("memberString",new RefType("java.lang.String",-1))); + ClassExpect testInheritanceConstructor = new ClassExpect(TestInheritanceConstructor.TESTEDCLASSNAME); + + //methods + MethodExpect aA = new MethodExpect("A", new RefType("void",-1)); + aA.addParameter(new VarExpect("i",new RefType("java.lang.Integer",-1))); + MethodExpect bB = new MethodExpect("B", new RefType("void",-1)); + bB.addParameter(new VarExpect("i",new RefType("java.lang.Integer",-1))); + bB.addParameter(new VarExpect("s",new RefType("java.lang.String",-1))); + MethodExpect main = new MethodExpect("main",new RefType("void",-1)); + main.getBlock().addLocalVar(new VarExpect("x",new RefType("B",-1))); + main.getBlock().addLocalVar(new VarExpect("y",new RefType("java.lang.Integer",-1))); + + //adding methods to classes + a.addMethod(aA); + b.addMethod(bB); + + testInheritanceConstructor.addMethod(main); + + //adding classes to Expectation + Expectation ret = new Expectation(testInheritanceConstructor); + ret.addClass(a); + return ret; + } + +} + diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultiple.jav b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultiple.jav new file mode 100755 index 000000000..63b6a1998 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultiple.jav @@ -0,0 +1,22 @@ +interface A{ +} +interface B{} + +class Tester implements A,B{ + m(){ + } +} + +public class TestInheritanceMultiple{ + + /*should return either of Type Intf1, Intf2, or Tester*/ + public m1(x){ + x.m(); + return(x); + } + + public m2(Tester x){ + x.m(); + return x; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultiple.java b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultiple.java new file mode 100755 index 000000000..7f3cc31c5 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultiple.java @@ -0,0 +1,56 @@ +package mycompiler.test.javaConcepts.inheritance; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestInheritanceMultiple extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestInheritanceMultiple"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/inheritance/"; + + public TestInheritanceMultiple(String name) { + super(name,TestInheritanceMultiple.JAVPATH+TestInheritanceMultiple.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //Interfaces + ClassExpect a = new ClassExpect("A"); + ClassExpect b = new ClassExpect("B"); + //classes + ClassExpect tester = new ClassExpect("Tester"); + ClassExpect testInheritanceMultiple = new ClassExpect(TestInheritanceMultiple.TESTEDCLASSNAME); + + //methods + MethodExpect m = new MethodExpect("m", new RefType("void",-1),0); + + MethodExpect m1 = new MethodExpect("m1",new RefType("Tester",-1),0); + m1.addReturntype(new RefType("A",-1)); + m1.addReturntype(new RefType("B",-1)); + VarExpect x1 = new VarExpect("x",new RefType("Tester",-1)); + m1.addParameter(x1); + + MethodExpect m2 = new MethodExpect("m2",new RefType("Tester",-1),0); + VarExpect x2 = new VarExpect("x",new RefType("Tester",-1)); + m2.addReturntype(new RefType("A",-1)); + m2.addReturntype(new RefType("B",-1)); + m2.addParameter(x2); + + tester.addMethod(m); + testInheritanceMultiple.addMethod(m1); + testInheritanceMultiple.addMethod(m2); + + //adding classes to Expectation + Expectation ret = new Expectation(testInheritanceMultiple); + ret.addClass(a); + ret.addClass(b); + ret.addClass(tester); + return ret; + } + +} + diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultipleClasses.jav b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultipleClasses.jav new file mode 100755 index 000000000..70241b36f --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultipleClasses.jav @@ -0,0 +1,8 @@ + +class A {} + +class B {} + +public class TestInheritanceMultipleClasses extends A, B { + +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultipleClasses.java b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultipleClasses.java new file mode 100755 index 000000000..04b0526e5 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceMultipleClasses.java @@ -0,0 +1,34 @@ +package mycompiler.test.javaConcepts.inheritance; + +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; + +public class TestInheritanceMultipleClasses extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestInheritanceMultipleClasses"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/inheritance/"; + + public TestInheritanceMultipleClasses(String name) { + super(name,TestInheritanceMultipleClasses.JAVPATH+TestInheritanceMultipleClasses.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //classes + ClassExpect a = new ClassExpect("A"); + ClassExpect b = new ClassExpect("B"); + ClassExpect testInheritanceMultipleClasses = new ClassExpect(TestInheritanceMultipleClasses.TESTEDCLASSNAME); + + + //adding classes to Expectation + Expectation ret = new Expectation(testInheritanceMultipleClasses); + ret.addClass(a); + ret.addClass(b); + //multiple inheritance of classes not possible in java + ret.addException(new Exception()); + return ret; + } + +} + diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceOverriding.jav b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceOverriding.jav new file mode 100755 index 000000000..7690516b3 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceOverriding.jav @@ -0,0 +1,27 @@ +class A{ + public m() { + return new A(); + } +} + +class B extends A{ + + public m() { + return new B(); + } + public m(java.lang.Integer a) { + return a; + } +} + +public class TestInheritanceOverriding { + + public main1(x,A y) { + y = new B(); + x = y.m(); + } + /*public main2(x) { + y; + y=x.m(2); + }*/ +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceOverriding.java b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceOverriding.java new file mode 100755 index 000000000..06d501610 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceOverriding.java @@ -0,0 +1,55 @@ +package mycompiler.test.javaConcepts.inheritance; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestInheritanceOverriding extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestInheritanceOverriding"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/inheritance/"; + + public TestInheritanceOverriding(String name) { + super(name,TestInheritanceOverriding.JAVPATH+TestInheritanceOverriding.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //classes + ClassExpect a = new ClassExpect("A"); + ClassExpect b = new ClassExpect("B"); + ClassExpect testInheritanceOverriding = new ClassExpect(TestInheritanceOverriding.TESTEDCLASSNAME); + + //methods + MethodExpect ma = new MethodExpect("m", new RefType("A",-1)); + MethodExpect mb1 = new MethodExpect("m", new RefType("B",-1)); + mb1.addReturntype(new RefType("A",-1)); + MethodExpect mb2 = new MethodExpect("m", new RefType("java.lang.Integer",-1)); + mb2.addParameter(new VarExpect("a", new RefType("java.lang.Integer",-1))); + + MethodExpect main1 = new MethodExpect("main1",new RefType("void",-1)); + main1.addParameter(new VarExpect("x", new RefType("A",-1))); + main1.addParameter(new VarExpect("y", new RefType("A",-1))); + + MethodExpect main2 = new MethodExpect("main2",new RefType("void",-1)); + main2.addParameter(new VarExpect("x", new RefType("B",-1))); + main2.getBlock().addLocalVar(new VarExpect("y", new RefType("java.lang.Integer",-1))); + + a.addMethod(ma); + b.addMethod(mb1); + b.addMethod(mb2); + testInheritanceOverriding.addMethod(main1); + //testInheritanceOverriding.addMethod(main2); + + //adding classes to Expectation + Expectation ret = new Expectation(testInheritanceOverriding); + ret.addClass(a); + ret.addClass(b); + return ret; + } + +} + diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceTwoHierarchies.jav b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceTwoHierarchies.jav new file mode 100755 index 000000000..df2f7dca8 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceTwoHierarchies.jav @@ -0,0 +1,37 @@ + +/* + + A I + B C D +E F + +*/ +interface I{ + void fooA(); +} +class A{ + void fooA() {} +} +class B extends A{} + +class C extends A implements I{} + +class D implements I{ + fooD() {} +} +class E extends B {} + +class F extends C{} + +public class TestInheritanceTwoHierarchies { + + public m1(x) { + x.fooA(); + return x; + } + + public m2(x) { + x.fooD(); + return x; + } +} diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceTwoHierarchies.java b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceTwoHierarchies.java new file mode 100755 index 000000000..023a5086b --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestInheritanceTwoHierarchies.java @@ -0,0 +1,83 @@ +package mycompiler.test.javaConcepts.inheritance; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestInheritanceTwoHierarchies extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestInheritanceTwoHierarchies"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/inheritance/"; + + public TestInheritanceTwoHierarchies(String name) { + super(name,TestInheritanceTwoHierarchies.JAVPATH+TestInheritanceTwoHierarchies.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //interfaces + ClassExpect i = new ClassExpect("I"); + + //Classes + ClassExpect a = new ClassExpect("A"); + ClassExpect b = new ClassExpect("B"); + ClassExpect c = new ClassExpect("C"); + ClassExpect d = new ClassExpect("D"); + ClassExpect e = new ClassExpect("E"); + ClassExpect f = new ClassExpect("F"); + ClassExpect testInheritanceTwoHierarchies = new ClassExpect(TestInheritanceTwoHierarchies.TESTEDCLASSNAME); + + //methods + MethodExpect fooAa = new MethodExpect("fooA", new RefType("void",-1),0); + MethodExpect fooAi = new MethodExpect("fooA", new RefType("void",-1),0); + MethodExpect fooD = new MethodExpect("fooD", new RefType("void",-1),0); + + MethodExpect m1 = new MethodExpect("m1",new RefType("A",-1),0); + m1.addReturntype(new RefType("B",-1)); + m1.addReturntype(new RefType("C",-1)); + m1.addReturntype(new RefType("D",-1)); + m1.addReturntype(new RefType("E",-1)); + m1.addReturntype(new RefType("F",-1)); + m1.addReturntype(new RefType("I",-1)); + VarExpect x1 = new VarExpect("x",new RefType("A",-1)); + x1.addExpectedType(new RefType("B",-1)); + x1.addExpectedType(new RefType("C",-1)); + x1.addExpectedType(new RefType("D",-1)); + x1.addExpectedType(new RefType("E",-1)); + x1.addExpectedType(new RefType("F",-1)); + x1.addExpectedType(new RefType("I",-1)); + m1.addParameter(x1); + + MethodExpect m2 = new MethodExpect("m2",new RefType("I",-1),0); + m2.addReturntype(new RefType("D",-1)); + VarExpect x2 = new VarExpect("x",new RefType("D",-1)); + m2.addParameter(x2); + + + //adding methods to classes + a.addMethod(fooAa); + d.addMethod(fooD); + i.addMethod(fooAi); + + + testInheritanceTwoHierarchies.addMethod(m1); + testInheritanceTwoHierarchies.addMethod(m2); + + //adding classes to Expectation + Expectation ret = new Expectation(testInheritanceTwoHierarchies); + ret.addClass(a); + ret.addClass(b); + ret.addClass(c); + ret.addClass(d); + ret.addClass(e); + ret.addClass(f); + ret.addClass(i); + + return ret; + } + +} + diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestSimpleInheritance.jav b/test/mycompiler/test/javaConcepts/inheritance/TestSimpleInheritance.jav new file mode 100755 index 000000000..3a0c0639c --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestSimpleInheritance.jav @@ -0,0 +1,13 @@ + +class A { + + public m1() { + } +} + +public class TestSimpleInheritance extends A { + + public m(x) { + x.m1(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/inheritance/TestSimpleInheritance.java b/test/mycompiler/test/javaConcepts/inheritance/TestSimpleInheritance.java new file mode 100755 index 000000000..4f36fd722 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/inheritance/TestSimpleInheritance.java @@ -0,0 +1,42 @@ +package mycompiler.test.javaConcepts.inheritance; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestSimpleInheritance extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestSimpleInheritance"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/inheritance/"; + + public TestSimpleInheritance(String name) { + super(name,TestSimpleInheritance.JAVPATH+TestSimpleInheritance.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //classes + ClassExpect a = new ClassExpect("A"); + ClassExpect testSimpleInheritance = new ClassExpect(TestSimpleInheritance.TESTEDCLASSNAME); + + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1),0); + + MethodExpect m = new MethodExpect("m",new RefType("void",-1),0); + VarExpect x2 = new VarExpect("x",new RefType("A",-1)); + x2.addExpectedType(new RefType(TestSimpleInheritance.TESTEDCLASSNAME,-1)); + m.addParameter(x2); + + a.addMethod(m1); + testSimpleInheritance.addMethod(m); + + //adding classes to Expectation + Expectation ret = new Expectation(testSimpleInheritance); + ret.addClass(a); + return ret; + } + +} + diff --git a/test/mycompiler/test/javaConcepts/overloading/AllTestsOverloading.java b/test/mycompiler/test/javaConcepts/overloading/AllTestsOverloading.java new file mode 100755 index 000000000..9bedaa69e --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/AllTestsOverloading.java @@ -0,0 +1,31 @@ +package mycompiler.test.javaConcepts.overloading; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsOverloading { + + public static Test suite() { + TestSuite suite = new TestSuite( + "Test for mycompiler.test.javaConcepts.overloading"); + //$JUnit-BEGIN$ + suite.addTestSuite(OverloadingNotSameHierarchy.class); + suite + .addTestSuite(OverloadingDifferentNumberOfParametersAndDifferentTypes.class); + suite.addTestSuite(OverloadingTypeInferenceSameHierarchy.class); + suite.addTestSuite(OverloadingGenericSameHierarchy.class); + suite.addTestSuite(OverloadingSameSignature.class); + suite.addTestSuite(OverloadingSameHierarchy.class); + suite.addTestSuite(OverloadingSameSignatureGenerics.class); + suite.addTestSuite(OverloadingGenericTypeInferenceSameHierarchy.class); + suite.addTestSuite(OverloadingSameSignatureDifferentReturnTypes.class); + suite.addTestSuite(OverloadingTypeInferenceNotSameHierarchy.class); + suite.addTestSuite(OverloadingDifferentNumberOfParameters.class); + suite.addTestSuite(OverloadingGenericNotSameHierarchy.class); + suite + .addTestSuite(OverloadingGenericTypeInferenceNotSameHierarchy.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParameters.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParameters.jav new file mode 100755 index 000000000..27139295d --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParameters.jav @@ -0,0 +1,6 @@ +class OverloadingDifferentNumberOfParameters{ + void foo(){} + void foo(Integer a){} + void foo(Integer a, Double b){} + void foo(Integer a, Double b, Long c){} +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParameters.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParameters.java new file mode 100755 index 000000000..18622cc1d --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParameters.java @@ -0,0 +1,51 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class OverloadingDifferentNumberOfParameters extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingDifferentNumberOfParameters"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingDifferentNumberOfParameters(String name) { + super(name,OverloadingDifferentNumberOfParameters.JAVPATH+OverloadingDifferentNumberOfParameters.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(OverloadingDifferentNumberOfParameters.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1),0); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),0); + m1.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),0); + m2.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + m2.addParameter(new VarExpect("b",new RefType("java.lang.Double",-1))); + + MethodExpect m3 = new MethodExpect("foo",new RefType("void",-1),0); + m3.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + m3.addParameter(new VarExpect("b",new RefType("java.lang.Double",-1))); + m3.addParameter(new VarExpect("c",new RefType("java.lang.Long",-1))); + + overloading.addMethod(m0); + overloading.addMethod(m1); + overloading.addMethod(m2); + overloading.addMethod(m3); + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParametersAndDifferentTypes.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParametersAndDifferentTypes.jav new file mode 100755 index 000000000..5cc96afcc --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParametersAndDifferentTypes.jav @@ -0,0 +1,9 @@ +class OverloadingDifferentNumberOfParametersAndDifferentTypes{ + void foo(){} + void foo(Integer a){} + void foo(Integer a, Double b){} + void foo(Integer a, Double b, Long c){} + void foo(String a){} + void foo(String a, Integer b){} + void foo(String a, Integer b, Long c){} +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParametersAndDifferentTypes.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParametersAndDifferentTypes.java new file mode 100755 index 000000000..919c600bd --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingDifferentNumberOfParametersAndDifferentTypes.java @@ -0,0 +1,66 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class OverloadingDifferentNumberOfParametersAndDifferentTypes extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingDifferentNumberOfParametersAndDifferentTypes"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingDifferentNumberOfParametersAndDifferentTypes(String name) { + super(name,OverloadingDifferentNumberOfParametersAndDifferentTypes.JAVPATH+OverloadingDifferentNumberOfParametersAndDifferentTypes.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(OverloadingDifferentNumberOfParametersAndDifferentTypes.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1),0); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),0); + m1.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),0); + m2.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + m2.addParameter(new VarExpect("b",new RefType("java.lang.Double",-1))); + + MethodExpect m3 = new MethodExpect("foo",new RefType("void",-1),0); + m3.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + m3.addParameter(new VarExpect("b",new RefType("java.lang.Double",-1))); + m3.addParameter(new VarExpect("c",new RefType("java.lang.Long",-1))); + + MethodExpect m4 = new MethodExpect("foo",new RefType("void",-1),1); + m4.addParameter(new VarExpect("a",new RefType("java.lang.String",-1))); + + MethodExpect m5 = new MethodExpect("foo",new RefType("void",-1),1); + m5.addParameter(new VarExpect("a",new RefType("java.lang.String",-1))); + m5.addParameter(new VarExpect("b",new RefType("java.lang.Integer",-1))); + + MethodExpect m6 = new MethodExpect("foo",new RefType("void",-1),1); + m6.addParameter(new VarExpect("a",new RefType("java.lang.String",-1))); + m6.addParameter(new VarExpect("b",new RefType("java.lang.Integer",-1))); + m6.addParameter(new VarExpect("c",new RefType("java.lang.Long",-1))); + + overloading.addMethod(m0); + overloading.addMethod(m1); + overloading.addMethod(m2); + overloading.addMethod(m3); + overloading.addMethod(m4); + overloading.addMethod(m5); + overloading.addMethod(m6); + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericNotSameHierarchy.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericNotSameHierarchy.jav new file mode 100755 index 000000000..cc8b080f1 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericNotSameHierarchy.jav @@ -0,0 +1,13 @@ +/* +Diese Klasse ueberlaed eine Methoden bei total Typverschiedenen generischen parametern (nicht gleiche Vererbungshierarchie +*/ +class OverloadingGenericNotSameHierarchy{ + + void foo(){} + void foo(T n){} + void foo(T v){} + +/* + void foo(T n){} + */ +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericNotSameHierarchy.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericNotSameHierarchy.java new file mode 100755 index 000000000..c31dec617 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericNotSameHierarchy.java @@ -0,0 +1,56 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class OverloadingGenericNotSameHierarchy extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingGenericNotSameHierarchy"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingGenericNotSameHierarchy(String name) { + super(name,OverloadingGenericNotSameHierarchy.JAVPATH+OverloadingGenericNotSameHierarchy.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(OverloadingGenericNotSameHierarchy.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1),0); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),0); + Vector bounds = new Vector(); + bounds.add(new RefType("Number",-1)); + BoundedGenericTypeVar boundedGenericT = new BoundedGenericTypeVar("T",bounds,-1); + m1.addGeneric(boundedGenericT); + m1.addParameter(new VarExpect("n",boundedGenericT)); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),1); + Vector bounds2 = new Vector(); + bounds2.add(new RefType("java.util.Vector",-1)); + BoundedGenericTypeVar boundedGenericT2 = new BoundedGenericTypeVar("T",bounds2,-1); + m2.addGeneric(boundedGenericT2); + m2.addParameter(new VarExpect("v",boundedGenericT2)); + + overloading.addMethod(m0); + overloading.addMethod(m1); + overloading.addMethod(m2); + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericSameHierarchy.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericSameHierarchy.jav new file mode 100755 index 000000000..7db406522 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericSameHierarchy.jav @@ -0,0 +1,8 @@ +/* +Diese Klasse ueberlaedt eine Methoden bei verschiedenen generischen Typen von Parametern welche in der gleichen Vererbungshierarchie liegen*/ + +class OverloadingGenericSameHierarchy { + void foo(T o){} + void foo(T n){} + void foo(T i){} +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericSameHierarchy.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericSameHierarchy.java new file mode 100755 index 000000000..27bcc7896 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericSameHierarchy.java @@ -0,0 +1,61 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class OverloadingGenericSameHierarchy extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingGenericSameHierarchy"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingGenericSameHierarchy(String name) { + super(name,OverloadingGenericSameHierarchy.JAVPATH+OverloadingGenericSameHierarchy.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(OverloadingGenericSameHierarchy.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1),0); + Vector bounds0 = new Vector(); + bounds0.add(new RefType("Object",-1)); + BoundedGenericTypeVar boundedGenericT0 = new BoundedGenericTypeVar("T",bounds0,-1); + m0.addGeneric(boundedGenericT0); + m0.addParameter(new VarExpect("o",boundedGenericT0)); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),1); + Vector bounds1 = new Vector(); + bounds1.add(new RefType("Number",-1)); + BoundedGenericTypeVar boundedGenericT1 = new BoundedGenericTypeVar("T",bounds1,-1); + m1.addGeneric(boundedGenericT1); + m1.addParameter(new VarExpect("n",boundedGenericT1)); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),2); + Vector bounds2 = new Vector(); + bounds2.add(new RefType("java.lang.Integer",-1)); + BoundedGenericTypeVar boundedGenericT2 = new BoundedGenericTypeVar("T",bounds2,-1); + m2.addGeneric(boundedGenericT2); + m2.addParameter(new VarExpect("i",boundedGenericT2)); + + overloading.addMethod(m0); + overloading.addMethod(m1); + overloading.addMethod(m2); + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceNotSameHierarchy.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceNotSameHierarchy.jav new file mode 100755 index 000000000..cc0ff01ab --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceNotSameHierarchy.jav @@ -0,0 +1,19 @@ +/* +Diese Klasse ueberlaedt eine Methode durch Typinferenz erkannte generische typverschiedenen Tarametern (nicht gleiche Vererbungshierarchie) +*/ + +import java.util.Vector; + +class A { + +} + +class OverloadingGenericTypeInferenceNotSameHierarchy{ + foo(){} + foo(i){ + i = new A(); + } + foo(s){ + s = new Vector(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceNotSameHierarchy.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceNotSameHierarchy.java new file mode 100755 index 000000000..71abf6856 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceNotSameHierarchy.java @@ -0,0 +1,77 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import java.util.Vector; + +import mycompiler.mytype.ExtendsWildcardType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class OverloadingGenericTypeInferenceNotSameHierarchy extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingGenericTypeInferenceNotSameHierarchy"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingGenericTypeInferenceNotSameHierarchy(String name) { + super(name,OverloadingGenericTypeInferenceNotSameHierarchy.JAVPATH+OverloadingGenericTypeInferenceNotSameHierarchy.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect a = new ClassExpect("A"); + a.addGeneric(new GenericTypeVar("T",-1)); + + ClassExpect overloading = new ClassExpect(OverloadingGenericTypeInferenceNotSameHierarchy.TESTEDCLASSNAME); + overloading.addGeneric(new GenericTypeVar("T",-1)); + //methods + + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1)); +// m0.addParameter(new VarExpect("o",boundedGenericT0)); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),0); + Vector bounds1a = new Vector(); + bounds1a.add(new RefType("java.lang.Double",-1)); + Vector bounds1b = new Vector(); + bounds1b.add(new ExtendsWildcardType(-1,new RefType("java.lang.Double",-1))); + Vector bounds1c = new Vector(); + bounds1c.add(new SuperWildcardType(-1,new RefType("java.lang.Double",-1))); + VarExpect i = new VarExpect("i", new RefType("A",bounds1a,-1)); + i.addExpectedType(new RefType("A",bounds1b,-1)); + i.addExpectedType(new RefType("A",bounds1c,-1)); + m1.addParameter(i); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),1); + Vector bounds2a = new Vector(); + bounds2a.add(new RefType("java.lang.Integer",-1)); + Vector bounds2b = new Vector(); + bounds2b.add(new ExtendsWildcardType(-1,new RefType("java.lang.Integer",-1))); + Vector bounds2c = new Vector(); + bounds2c.add(new SuperWildcardType(-1,new RefType("java.lang.Integer",-1))); + VarExpect s = new VarExpect("s",new RefType("java.util.Vector",bounds2a,-1)); + s.addExpectedType(new RefType("java.util.Vector",bounds2b,-1)); + s.addExpectedType(new RefType("java.util.Vector",bounds2c,-1)); + + m2.addParameter(s); + + overloading.addMethod(m0); + overloading.addMethod(m1); + overloading.addMethod(m2); + + Expectation ret = new Expectation(a); + ret.addClass(overloading); + return ret; + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceSameHierarchy.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceSameHierarchy.jav new file mode 100755 index 000000000..e4af92395 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceSameHierarchy.jav @@ -0,0 +1,20 @@ +/* +Diese Klasse ueberlaedt eine Methoden durch typeinferenz erkannte generische Typverschiedenen parametern welche in der selben Typhierarchie sind*/ +class B{ +} +class C extends B{ +} +class D extends C{ +} +class OverloadingGenericTypeInferenceSameHierarchy{ + foo(i){ + i = new B(); + } + foo(n){ + n = new C(); + } + + foo(o){ + o = new D(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceSameHierarchy.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceSameHierarchy.java new file mode 100755 index 000000000..d8b4a5e8a --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingGenericTypeInferenceSameHierarchy.java @@ -0,0 +1,91 @@ +package mycompiler.test.javaConcepts.overloading; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.ExtendsWildcardType; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.mytype.GenericTypeVar; + +public class OverloadingGenericTypeInferenceSameHierarchy extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingGenericTypeInferenceSameHierarchy"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingGenericTypeInferenceSameHierarchy(String name) { + super(name,OverloadingGenericTypeInferenceSameHierarchy.JAVPATH+OverloadingGenericTypeInferenceSameHierarchy.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //classes + ClassExpect b = new ClassExpect("B"); + ClassExpect c = new ClassExpect("C"); + ClassExpect d = new ClassExpect("D"); + ClassExpect overloading = new ClassExpect(OverloadingGenericTypeInferenceSameHierarchy.TESTEDCLASSNAME); + + //generics + b.addGeneric(new GenericTypeVar("T",-1)); + c.addGeneric(new GenericTypeVar("T",-1)); + d.addGeneric(new GenericTypeVar("T",-1)); + + //methods + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),0); + Vector bounds1a = new Vector(); + bounds1a.add(new RefType("java.lang.Integer",-1)); + Vector bounds1b = new Vector(); + bounds1b.add(new ExtendsWildcardType(-1,new RefType("java.lang.Integer",-1))); + Vector bounds1c = new Vector(); + bounds1c.add(new SuperWildcardType(-1,new RefType("java.lang.Integer",-1))); + VarExpect i = new VarExpect("i", new RefType("B",bounds1a,-1)); + i.addExpectedType(new RefType("B",bounds1b,-1)); + i.addExpectedType(new RefType("B",bounds1c,-1)); + m1.addParameter(i); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),1); + Vector bounds2a = new Vector(); + bounds2a.add(new RefType("java.lang.Integer",-1)); + Vector bounds2b = new Vector(); + bounds2b.add(new ExtendsWildcardType(-1,new RefType("java.lang.Integer",-1))); + Vector bounds2c = new Vector(); + bounds2c.add(new SuperWildcardType(-1,new RefType("java.lang.Integer",-1))); + VarExpect n = new VarExpect("n", new RefType("B",bounds2a,-1)); + n.addExpectedType(new RefType("B",bounds2b,-1)); + n.addExpectedType(new RefType("B",bounds2c,-1)); + n.addExpectedType(new RefType("C",bounds2a,-1)); + n.addExpectedType(new RefType("C",bounds2b,-1)); + n.addExpectedType(new RefType("C",bounds2c,-1)); + m2.addParameter(n); + MethodExpect m3 = new MethodExpect("foo",new RefType("void",-1),2); + Vector bounds3a = new Vector(); + bounds3a.add(new RefType("java.lang.Integer",-1)); + Vector bounds3b = new Vector(); + bounds3b.add(new ExtendsWildcardType(-1,new RefType("java.lang.Integer",-1))); + Vector bounds3c = new Vector(); + bounds3c.add(new SuperWildcardType(-1,new RefType("java.lang.Integer",-1))); + VarExpect o = new VarExpect("o", new RefType("B",bounds3a,-1)); + o.addExpectedType(new RefType("B",bounds3b,-1)); + o.addExpectedType(new RefType("B",bounds3c,-1)); + o.addExpectedType(new RefType("C",bounds3a,-1)); + o.addExpectedType(new RefType("C",bounds3b,-1)); + o.addExpectedType(new RefType("C",bounds3c,-1)); + o.addExpectedType(new RefType("D",bounds3a,-1)); + o.addExpectedType(new RefType("D",bounds3b,-1)); + o.addExpectedType(new RefType("D",bounds3c,-1)); + m3.addParameter(o); + + overloading.addMethod(m1); + overloading.addMethod(m2); + overloading.addMethod(m3); + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingNotSameHierarchy.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingNotSameHierarchy.jav new file mode 100755 index 000000000..2b2e635e0 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingNotSameHierarchy.jav @@ -0,0 +1,8 @@ +/* +Diese Klasse ueberlaed eine Methoden bei total Typverschiedenen parametern (nicht gleiche Vererbungshierarchie +*/ +class OverloadingNotSameHierarchy{ + void foo(){} + void foo(String s){} + void foo(Integer i){} +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingNotSameHierarchy.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingNotSameHierarchy.java new file mode 100755 index 000000000..0a52914fa --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingNotSameHierarchy.java @@ -0,0 +1,45 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class OverloadingNotSameHierarchy extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingNotSameHierarchy"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingNotSameHierarchy(String name) { + super(name,OverloadingNotSameHierarchy.JAVPATH+OverloadingNotSameHierarchy.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(OverloadingNotSameHierarchy.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1),0); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),0); + m1.addParameter(new VarExpect("s",new RefType("java.lang.String",-1))); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),1); + m2.addParameter(new VarExpect("i",new RefType("java.lang.Integer",-1))); + + + overloading.addMethod(m0); + overloading.addMethod(m1); + overloading.addMethod(m2); + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingSameHierarchy.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameHierarchy.jav new file mode 100755 index 000000000..d622462f3 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameHierarchy.jav @@ -0,0 +1,7 @@ +/* +Diese Klasse ueberlaedt eine Methoden bei verschiedenen Typen von Parametern welche in der gleichen Vererbungshierarchie liegen*/ +class OverloadingSameHierarchy{ + void foo(java.lang.Number n){} + void foo(java.lang.Integer i){} + void foo(java.lang.Object o){} +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingSameHierarchy.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameHierarchy.java new file mode 100755 index 000000000..f652f2f72 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameHierarchy.java @@ -0,0 +1,46 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class OverloadingSameHierarchy extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingSameHierarchy"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingSameHierarchy(String name) { + super(name,OverloadingSameHierarchy.JAVPATH+OverloadingSameHierarchy.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(OverloadingSameHierarchy.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1),0); + m0.addParameter(new VarExpect("n",new RefType("java.lang.Number",-1))); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),1); + m1.addParameter(new VarExpect("i",new RefType("java.lang.Integer",-1))); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),2); + m2.addParameter(new VarExpect("o",new RefType("java.lang.Object",-1))); + + + overloading.addMethod(m0); + overloading.addMethod(m1); + overloading.addMethod(m2); + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignature.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignature.jav new file mode 100755 index 000000000..ff58ff0a7 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignature.jav @@ -0,0 +1,6 @@ +class OverloadingSameSignature{ + void foo(){ + } + void foo(){ + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignature.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignature.java new file mode 100755 index 000000000..fe856c0b0 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignature.java @@ -0,0 +1,27 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.notUsedAnymore.TestAbstractInferenceTest2; + +public class OverloadingSameSignature extends AbstractInferenceTest{ + private final static String TESTEDCLASSNAME="OverloadingSameSignature"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingSameSignature(String name) { + super(name,OverloadingSameSignature.JAVPATH+OverloadingSameSignature.TESTEDCLASSNAME + ".jav"); + } + + @Override + protected Expectation getExpectations() { + Expectation expect = new Expectation(null); + expect.addException(new Exception()); + return expect; + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureDifferentReturnTypes.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureDifferentReturnTypes.jav new file mode 100755 index 000000000..2668cd06e --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureDifferentReturnTypes.jav @@ -0,0 +1,7 @@ +class OverloadingSameSignatureDifferentReturnTypes{ + void foo(){ + } + String foo(){ + return "abcd"; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureDifferentReturnTypes.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureDifferentReturnTypes.java new file mode 100755 index 000000000..c42febce6 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureDifferentReturnTypes.java @@ -0,0 +1,26 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.Expectation; + +public class OverloadingSameSignatureDifferentReturnTypes extends AbstractInferenceTest{ + private final static String TESTEDCLASSNAME="OverloadingSameSignatureDifferentReturnTypes"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingSameSignatureDifferentReturnTypes(String name) { + super(name,OverloadingSameSignatureDifferentReturnTypes.JAVPATH+OverloadingSameSignatureDifferentReturnTypes.TESTEDCLASSNAME + ".jav"); + } + + @Override + protected Expectation getExpectations() { + Expectation expect = new Expectation(null); + expect.addException(new Exception()); + return expect; + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureGenerics.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureGenerics.jav new file mode 100755 index 000000000..de6ebda2d --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureGenerics.jav @@ -0,0 +1,8 @@ +class OverloadingSameSignatureGenerics{ + T foo(T a){ + return a; + } + void foo(T a){ + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureGenerics.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureGenerics.java new file mode 100755 index 000000000..8519973a7 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingSameSignatureGenerics.java @@ -0,0 +1,25 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.Expectation; + +public class OverloadingSameSignatureGenerics extends AbstractInferenceTest{ + private final static String TESTEDCLASSNAME="OverloadingSameSignatureGenerics"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingSameSignatureGenerics(String name) { + super(name,OverloadingSameSignatureGenerics.JAVPATH+OverloadingSameSignatureGenerics.TESTEDCLASSNAME + ".jav"); + } + + @Override + protected Expectation getExpectations() { + Expectation expect = new Expectation(null); + expect.addException(new Exception()); + return expect; + } +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceNotSameHierarchy.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceNotSameHierarchy.jav new file mode 100755 index 000000000..317fc85c1 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceNotSameHierarchy.jav @@ -0,0 +1,12 @@ +/* +Diese Klasse ueberlaed eine Methoden durch typeinferenz erkannte Typverschiedenen parametern (nicht gleiche Vererbungshierarchie +*/ +class OverloadingTypeInferenceNotSameHierarchy{ + foo(){} + foo(i){ + i = new java.lang.Integer(); + } + foo(s){ + s = "String"; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceNotSameHierarchy.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceNotSameHierarchy.java new file mode 100755 index 000000000..e9d69bf18 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceNotSameHierarchy.java @@ -0,0 +1,45 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class OverloadingTypeInferenceNotSameHierarchy extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingTypeInferenceNotSameHierarchy"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading/"; + + public OverloadingTypeInferenceNotSameHierarchy(String name) { + super(name,OverloadingTypeInferenceNotSameHierarchy.JAVPATH+OverloadingTypeInferenceNotSameHierarchy.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(OverloadingTypeInferenceNotSameHierarchy.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1),0); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),1); + m1.addParameter(new VarExpect("s",new RefType("java.lang.String",-1))); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),0); + m2.addParameter(new VarExpect("i",new RefType("java.lang.Integer",-1))); + + + overloading.addMethod(m0); + overloading.addMethod(m1); + overloading.addMethod(m2); + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceSameHierarchy.jav b/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceSameHierarchy.jav new file mode 100755 index 000000000..dc83554cb --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceSameHierarchy.jav @@ -0,0 +1,16 @@ +/* +Diese Klasse ueberlaed eine Methoden durch typeinferenz erkannte Typverschiedenen parametern welche in der selben Typhierarchie sind*/ +class OverloadingTypeInferenceSameHierarchy{ + /*i = Integer*/ + foo(i){ + i = new java.lang.Integer(); + } + /*n = Number*/ + foo(n){ + n = new java.lang.Number(); + } + /*o = Object*/ + foo(o){ + o = new java.lang.Object(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceSameHierarchy.java b/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceSameHierarchy.java new file mode 100755 index 000000000..1c3b0d79a --- /dev/null +++ b/test/mycompiler/test/javaConcepts/overloading/OverloadingTypeInferenceSameHierarchy.java @@ -0,0 +1,47 @@ +package mycompiler.test.javaConcepts.overloading; +/** +* 16-04-08 +* @author +* +* +*/ +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class OverloadingTypeInferenceSameHierarchy extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="OverloadingTypeInferenceSameHierarchy"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/overloading//"; + + public OverloadingTypeInferenceSameHierarchy(String name) { + super(name,OverloadingTypeInferenceSameHierarchy.JAVPATH+OverloadingTypeInferenceSameHierarchy.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(OverloadingTypeInferenceSameHierarchy.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1),0); + m0.addParameter(new VarExpect("i",new RefType("java.lang.Integer",-1))); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),1); + m1.addParameter(new VarExpect("n",new RefType("java.lang.Number",-1))); + + MethodExpect m2 = new MethodExpect("foo",new RefType("void",-1),2); + m2.addParameter(new VarExpect("o",new RefType("java.lang.Object",-1))); + + + + overloading.addMethod(m0); + overloading.addMethod(m1); + overloading.addMethod(m2); + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/javaConcepts/staticAccess/AllTestsStaticAccess.java b/test/mycompiler/test/javaConcepts/staticAccess/AllTestsStaticAccess.java new file mode 100755 index 000000000..ab4edc303 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/staticAccess/AllTestsStaticAccess.java @@ -0,0 +1,19 @@ +package mycompiler.test.javaConcepts.staticAccess; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsStaticAccess { + + public static Test suite() { + TestSuite suite = new TestSuite( + "Test for mycompiler.test.javaConcepts.staticAccess"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestNonStaticAccess.class); + suite.addTestSuite(TestStaticAccess.class); + suite.addTestSuite(TestStaticAccessError.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/javaConcepts/staticAccess/TestNonStaticAccess.jav b/test/mycompiler/test/javaConcepts/staticAccess/TestNonStaticAccess.jav new file mode 100755 index 000000000..717d5ed3b --- /dev/null +++ b/test/mycompiler/test/javaConcepts/staticAccess/TestNonStaticAccess.jav @@ -0,0 +1,19 @@ +public class Access{ + + public String nonStaticMember="abc"; + + public nonStaticMethod() { + return "def"; + } + +} + +class TestNonStaticAccess { + + public method1(a,b) { + x; + x = new Access(); + a=x.nonStaticMember; + b=x.nonStaticMethod(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/staticAccess/TestNonStaticAccess.java b/test/mycompiler/test/javaConcepts/staticAccess/TestNonStaticAccess.java new file mode 100755 index 000000000..55ee1f6d3 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/staticAccess/TestNonStaticAccess.java @@ -0,0 +1,53 @@ +package mycompiler.test.javaConcepts.staticAccess; +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** +* 22-04-08 +* @author +* Tests non static access of a method or a member +* +*/ +public class TestNonStaticAccess extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestNonStaticAccess"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/staticAccess/"; + + public TestNonStaticAccess(String name) { + super(name,TestNonStaticAccess.JAVPATH+TestNonStaticAccess.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect access = new ClassExpect("Access"); + ClassExpect testNonStaticAccess = new ClassExpect(TestNonStaticAccess.TESTEDCLASSNAME); + + //Methods + MethodExpect method = new MethodExpect("method1",new RefType("void",-1)); + method.addParameter(new VarExpect("a",new RefType("java.lang.String",-1))); + method.addParameter(new VarExpect("b",new RefType("java.lang.String",-1))); + method.getBlock().addLocalVar(new VarExpect("x",new RefType("Access",-1))); + + MethodExpect nonStaticMethod = new MethodExpect("nonStaticMethod",new RefType("java.lang.String",-1)); + + //add methods to classes + testNonStaticAccess.addMethod(method); + access.addMethod(nonStaticMethod); + + //Member + access.addMember(new VarExpect("nonStaticMember",new RefType("java.lang.String",-1))); + + Expectation ret = new Expectation(testNonStaticAccess); + ret.addClass(access); + + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccess.jav b/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccess.jav new file mode 100755 index 000000000..b00c2e8ef --- /dev/null +++ b/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccess.jav @@ -0,0 +1,18 @@ +public class Access{ + + public static String staticMember="def"; + + public static staticMethod() { + return "abc"; + } + +} + +class TestStaticAccess { + + public method1(a,b) { + x; + a=x.staticMember; + b=x.staticMethod(); + } +} diff --git a/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccess.java b/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccess.java new file mode 100755 index 000000000..be6183ed9 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccess.java @@ -0,0 +1,53 @@ +package mycompiler.test.javaConcepts.staticAccess; +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** +* 22-04-08 +* @author +* +* Tests static access of a member or methods +*/ +public class TestStaticAccess extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestStaticAccess"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/staticAccess/"; + + public TestStaticAccess(String name) { + super(name,TestStaticAccess.JAVPATH+TestStaticAccess.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect access = new ClassExpect("Access"); + ClassExpect testStaticAccess = new ClassExpect(TestStaticAccess.TESTEDCLASSNAME); + + //Methods + MethodExpect method = new MethodExpect("method1",new RefType("void",-1)); + method.addParameter(new VarExpect("a",new RefType("java.lang.String",-1))); + method.addParameter(new VarExpect("b",new RefType("java.lang.String",-1))); + method.getBlock().addLocalVar(new VarExpect("x",new RefType("Access",-1))); + + MethodExpect nonStaticMethod = new MethodExpect("staticMethod",new RefType("java.lang.String",-1)); + + //add methods to classes + testStaticAccess.addMethod(method); + + access.addMethod(nonStaticMethod); + //Member + access.addMember(new VarExpect("staticMember",new RefType("java.lang.String",-1))); + + Expectation ret = new Expectation(testStaticAccess); + ret.addClass(access); + + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccessError.jav b/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccessError.jav new file mode 100755 index 000000000..e7445702f --- /dev/null +++ b/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccessError.jav @@ -0,0 +1,17 @@ +public class Access{ + public String nonStaticMember="abc"; + + public nonStaticMethod() { + return "def"; + } + +} + +class TestStaticAccessError { + + public methodError1(a,b) { + x; + a=x.nonStaticMember; + b=x.nonStaticMethod(); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccessError.java b/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccessError.java new file mode 100755 index 000000000..8b0e61a85 --- /dev/null +++ b/test/mycompiler/test/javaConcepts/staticAccess/TestStaticAccessError.java @@ -0,0 +1,54 @@ +package mycompiler.test.javaConcepts.staticAccess; +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** +* 22-04-08 +* @author +* +* checks static access to non-static elements -> should throw erro +*/ + +public class TestStaticAccessError extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestStaticAccessError"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/staticAccess/"; + + public TestStaticAccessError(String name) { + super(name,TestStaticAccessError.JAVPATH+TestStaticAccessError.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect access = new ClassExpect("Access"); + ClassExpect testStaticAccessError = new ClassExpect(TestStaticAccessError.TESTEDCLASSNAME); + + //Methods + MethodExpect method = new MethodExpect("methodError1",new RefType("void",-1)); + method.addParameter(new VarExpect("a",new RefType("java.lang.String",-1))); + method.addParameter(new VarExpect("b",new RefType("java.lang.String",-1))); + method.getBlock().addLocalVar(new VarExpect("x",new RefType("Access",-1))); + + MethodExpect nonStaticMethod = new MethodExpect("nonStaticMethod",new RefType("java.lang.String",-1)); + + //add methods to classes + testStaticAccessError.addMethod(method); + + access.addMethod(nonStaticMethod); + //Member + access.addMember(new VarExpect("nonStaticMember",new RefType("java.lang.String",-1))); + + Expectation ret = new Expectation(testStaticAccessError); + ret.addClass(access); + //static accessing of objects not possible + ret.addException(new Exception()); + + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/AllgemeinerLambdaTest1.java b/test/mycompiler/test/lambda/AllgemeinerLambdaTest1.java new file mode 100644 index 000000000..0d331affa --- /dev/null +++ b/test/mycompiler/test/lambda/AllgemeinerLambdaTest1.java @@ -0,0 +1,28 @@ +package mycompiler.test.lambda; + +import java.util.HashMap; + +import mycompiler.mytest.LambdaTest; + +import org.junit.Test; + +public class AllgemeinerLambdaTest1 { + private static final String exampleJavFile = "LambdaTest1.jav"; + private static final String classname = "LambdaTest1"; + + private HashMap variableTypeAssumptions = new HashMap(); + + + @Test + public void test() { + variableTypeAssumptions.put("var", "String"); + executeTest(); + } + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); + + } + +} diff --git a/test/mycompiler/test/lambda/BasicAssumptions.jav b/test/mycompiler/test/lambda/BasicAssumptions.jav new file mode 100644 index 000000000..f9da2d184 --- /dev/null +++ b/test/mycompiler/test/lambda/BasicAssumptions.jav @@ -0,0 +1,10 @@ +class BasicAssumptionsTest{ + +varString; +var = 2; + +void methode(){ + var = 1; + varString = varString.toString(); +} +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/BasicAssumptionsTest.java b/test/mycompiler/test/lambda/BasicAssumptionsTest.java new file mode 100644 index 000000000..90b5cf8be --- /dev/null +++ b/test/mycompiler/test/lambda/BasicAssumptionsTest.java @@ -0,0 +1,30 @@ +package mycompiler.test.lambda; + +import java.util.HashMap; + +import mycompiler.mytest.LambdaTest; + +import org.junit.Test; + +public class BasicAssumptionsTest { + private static final String exampleJavFile = "BasicAssumptions.jav"; + private static final String classname = "BasicAssumptionsTest"; + + private HashMap variableTypeAssumptions = new HashMap(); + + + @Test + public void test() { + variableTypeAssumptions.put("varString", "java.lang.String"); + executeTest(); + } + + + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); + + } + +} diff --git a/test/mycompiler/test/lambda/ConstructorTest.java b/test/mycompiler/test/lambda/ConstructorTest.java new file mode 100644 index 000000000..367041731 --- /dev/null +++ b/test/mycompiler/test/lambda/ConstructorTest.java @@ -0,0 +1,47 @@ +package mycompiler.test.lambda; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.Vector; + +import mycompiler.mytest.LambdaTest; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; + +import org.junit.Test; + +import typinferenz.TypeAssumptions; + +public class ConstructorTest { + + @Test + public void test() { + executeTest(); + } + + private static final Vector exampleJavFiles = new Vector(); + static{ + exampleJavFiles.add("ConstructorTestFile1.jav"); + exampleJavFiles.add("ConstructorTestFile2.jav"); + } + + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFiles); + Vector results = tester.runTest(); + int anzahlGeparsterKlassen = 0; + for(CTypeReconstructionResult res : results){ + mycompiler.myclass.Class cl = res.getInterferedClass(); + TypeAssumptions ass = cl.getPublicFieldAssumptions(); + if(cl.getName().equals("ConstructorTest1")){ + anzahlGeparsterKlassen++; + }else if(cl.getName().equals("ConstructorTest2")){ + anzahlGeparsterKlassen++; + assertTrue("ConstructorTest2.var muss vom Typ ConstructorTest1 sein.", ass.getVarType("var").printJavaCode( + res.getUnifiedConstraints()).toString().equals("ConstructorTest1")); + }else fail("Die geparsten Klassen müssen ConstructorTest1 und ConstructorTest2 heißen"); + } + assertTrue("Es müssen insgesamt 2 Klassen inferierd worden sein", anzahlGeparsterKlassen == 2); + } + +} diff --git a/test/mycompiler/test/lambda/ConstructorTestFile1.jav b/test/mycompiler/test/lambda/ConstructorTestFile1.jav new file mode 100644 index 000000000..1b26e2bb4 --- /dev/null +++ b/test/mycompiler/test/lambda/ConstructorTestFile1.jav @@ -0,0 +1,8 @@ +class ConstructorTest1{ + +ConstructorTest1(){ +var; +var = 1; +} + +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/ConstructorTestFile2.jav b/test/mycompiler/test/lambda/ConstructorTestFile2.jav new file mode 100644 index 000000000..d2ce318e8 --- /dev/null +++ b/test/mycompiler/test/lambda/ConstructorTestFile2.jav @@ -0,0 +1,7 @@ +class ConstructorTest2{ +var; + void method(){ + var = new ConstructorTest1(); + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/GenericVarTest.jav b/test/mycompiler/test/lambda/GenericVarTest.jav new file mode 100644 index 000000000..6e6db51b8 --- /dev/null +++ b/test/mycompiler/test/lambda/GenericVarTest.jav @@ -0,0 +1,7 @@ +class GenericVarTest{ + test; + method(){ + test = test; + return 1; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/GenericVarTest.java b/test/mycompiler/test/lambda/GenericVarTest.java new file mode 100644 index 000000000..a893fa44d --- /dev/null +++ b/test/mycompiler/test/lambda/GenericVarTest.java @@ -0,0 +1,27 @@ +package mycompiler.test.lambda; + +import static org.junit.Assert.*; + +import java.util.Vector; + +import mycompiler.mytest.LambdaTest; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; + +import org.junit.Test; + +public class GenericVarTest { + + @Test + public void test() { + executeTest(); + } + + private static final String exampleJavFile = "GenericVarTest.jav"; + + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + CTypeReconstructionResult result1 = tester.runTestAndGetSingularResultSet(); + } + +} diff --git a/test/mycompiler/test/lambda/LambdaTest1.jav b/test/mycompiler/test/lambda/LambdaTest1.jav new file mode 100644 index 000000000..09076b3c5 --- /dev/null +++ b/test/mycompiler/test/lambda/LambdaTest1.jav @@ -0,0 +1,7 @@ +class LambdaTest1{ + var = "test"; + + method(String toAppend){ + return (String text) -> { return text;}; + } +} diff --git a/test/mycompiler/test/lambda/OverloadingTest.jav b/test/mycompiler/test/lambda/OverloadingTest.jav new file mode 100644 index 000000000..bed6f9604 --- /dev/null +++ b/test/mycompiler/test/lambda/OverloadingTest.jav @@ -0,0 +1,21 @@ +class OverloadingTest{ + + var; + + public Object clone(){ + return this; + } + + public testMethode(){ + return var.clone(); + } + +} + +class OverloadingTest2{ + + public Object clone(){ + return this; + } + +} diff --git a/test/mycompiler/test/lambda/OverloadingTest.java b/test/mycompiler/test/lambda/OverloadingTest.java new file mode 100644 index 000000000..bc0cdf8ac --- /dev/null +++ b/test/mycompiler/test/lambda/OverloadingTest.java @@ -0,0 +1,27 @@ +package mycompiler.test.lambda; + +import static org.junit.Assert.*; + +import java.util.Vector; + +import mycompiler.mytest.LambdaTest; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; + +import org.junit.Test; + +public class OverloadingTest { + + @Test + public void test() { + executeTest(); + } + + private static final String exampleJavFile = "OverloadingTest.jav"; + + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + Vector result1 = tester.runTest(); + } + +} diff --git a/test/mycompiler/test/lambda/ParseMultipleFilesTest.java b/test/mycompiler/test/lambda/ParseMultipleFilesTest.java new file mode 100644 index 000000000..1cab6b911 --- /dev/null +++ b/test/mycompiler/test/lambda/ParseMultipleFilesTest.java @@ -0,0 +1,44 @@ +package mycompiler.test.lambda; + +import java.util.Vector; +import static org.junit.Assert.*; +import mycompiler.mytest.LambdaTest; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; + +import org.junit.Test; + +import typinferenz.TypeAssumptions; + +public class ParseMultipleFilesTest { + + @Test + public void test() { + executeTest(); + } + + private static final Vector exampleJavFiles = new Vector(); + static{ + exampleJavFiles.add("parseMultipleFilesFile1.jav"); + exampleJavFiles.add("parseMultipleFilesFile2.jav"); + } + + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFiles); + Vector results = tester.runTest(); + int anzahlGeparsterKlassen = 0; + for(CTypeReconstructionResult res : results){ + mycompiler.myclass.Class cl = res.getInterferedClass(); + TypeAssumptions ass = cl.getPublicFieldAssumptions(); + if(cl.getName().equals("Klasse1")){ + anzahlGeparsterKlassen++; + assertTrue("Klasse1.var1 muss vom Typ int sein.", ass.getVarType("var1").printJavaCode(res.getUnifiedConstraints()).toString().equals("int")); + }else if(cl.getName().equals("Klasse2")){ + anzahlGeparsterKlassen++; + assertTrue("Klasse1.var1 muss vom Typ Klasse1 sein.", ass.getVarType("var1").printJavaCode(res.getUnifiedConstraints()).toString().equals("Klasse1")); + }else fail("Die geparsten Klassen müssen Klasse1 und Klasse2 heißen"); + } + assertTrue("Es müssen insgesamt 2 Klassen inferierd worden sein", anzahlGeparsterKlassen == 2); + } + +} diff --git a/test/mycompiler/test/lambda/TestAssign.jav b/test/mycompiler/test/lambda/TestAssign.jav new file mode 100644 index 000000000..17117f182 --- /dev/null +++ b/test/mycompiler/test/lambda/TestAssign.jav @@ -0,0 +1,3 @@ +class Assign{ +stringVar = "String"; +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/TestAssign.java b/test/mycompiler/test/lambda/TestAssign.java new file mode 100644 index 000000000..503521598 --- /dev/null +++ b/test/mycompiler/test/lambda/TestAssign.java @@ -0,0 +1,34 @@ +package mycompiler.test.lambda; + +import java.util.HashMap; +import java.util.Vector; + +import junit.framework.TestCase; +import mycompiler.mytest.LambdaTest; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; + +import org.junit.Test; + +public class TestAssign extends TestCase{ + + private static final String exampleJavFile = "TestAssign.jav"; + private static final String classname = "Assign"; + private HashMap variableTypeAssumptions = new HashMap(); + + + @Test + public void test() { + variableTypeAssumptions.put("stringVar", "String"); + executeTest(); + } + + + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); + + } + + +} diff --git a/test/mycompiler/test/lambda/TestFunN.jav b/test/mycompiler/test/lambda/TestFunN.jav new file mode 100644 index 000000000..b810f636b --- /dev/null +++ b/test/mycompiler/test/lambda/TestFunN.jav @@ -0,0 +1,2 @@ +class Matrix extends Vector> { +op = (m) -> (f) -> f.apply(this, m); } \ No newline at end of file diff --git a/test/mycompiler/test/lambda/TestFunN.java b/test/mycompiler/test/lambda/TestFunN.java new file mode 100644 index 000000000..6866be672 --- /dev/null +++ b/test/mycompiler/test/lambda/TestFunN.java @@ -0,0 +1,29 @@ +package mycompiler.test.lambda; + +import java.util.HashMap; + +import mycompiler.mytest.LambdaTest; + +import org.junit.Test; + +public class TestFunN { + + private static final String exampleJavFile = "TestFunN.jav"; + private static final String classname = "TestFunN"; + private HashMap variableTypeAssumptions = new HashMap(); + + + @Test + public void test() { + //variableTypeAssumptions.put("op", "Fun1"); + executeTest(); + } + + + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); + + } +} diff --git a/test/mycompiler/test/lambda/TestIfStmt.jav b/test/mycompiler/test/lambda/TestIfStmt.jav new file mode 100644 index 000000000..b4a244d46 --- /dev/null +++ b/test/mycompiler/test/lambda/TestIfStmt.jav @@ -0,0 +1,13 @@ +class TestIfStmt { + +methode(){ + var; + if(true){ + var=this; + }else{ + var=this; + } + return 1; +} + +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/TestIfStmt.java b/test/mycompiler/test/lambda/TestIfStmt.java new file mode 100644 index 000000000..d405c4cce --- /dev/null +++ b/test/mycompiler/test/lambda/TestIfStmt.java @@ -0,0 +1,28 @@ +package mycompiler.test.lambda; + +import static org.junit.Assert.*; + +import java.util.HashMap; + +import mycompiler.mytest.LambdaTest; + +import org.junit.Test; + +public class TestIfStmt { + @Test + public void test() { + variableTypeAssumptions.put("var", "TestIfStmt"); + executeTest(); + } + + private static final String exampleJavFile = "TestIfStmt.jav"; + private static final String classname = "TestIfStmt"; + + private HashMap variableTypeAssumptions = new HashMap(); + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); + + } +} diff --git a/test/mycompiler/test/lambda/TestLambda.jav b/test/mycompiler/test/lambda/TestLambda.jav new file mode 100644 index 000000000..36f107343 --- /dev/null +++ b/test/mycompiler/test/lambda/TestLambda.jav @@ -0,0 +1,3 @@ +class TestLambda{ +op = (test) -> test = "string"; +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/TestLambda.java b/test/mycompiler/test/lambda/TestLambda.java new file mode 100644 index 000000000..ebb52254e --- /dev/null +++ b/test/mycompiler/test/lambda/TestLambda.java @@ -0,0 +1,33 @@ +package mycompiler.test.lambda; + +import static org.junit.Assert.*; + +import java.util.HashMap; + +import mycompiler.mytest.LambdaTest; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; + +import org.junit.Test; + +public class TestLambda { + + private static final String exampleJavFile = "TestLambda.jav"; + private static final String classname = "TestLambda"; + private HashMap variableTypeAssumptions = new HashMap(); + + + @Test + public void test() { + variableTypeAssumptions.put("op", "Fun1"); + executeTest(); + } + + + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); + + } + +} diff --git a/test/mycompiler/test/lambda/TestMethodCall.jav b/test/mycompiler/test/lambda/TestMethodCall.jav new file mode 100644 index 000000000..8abb035be --- /dev/null +++ b/test/mycompiler/test/lambda/TestMethodCall.jav @@ -0,0 +1,17 @@ +class TestMethodCall { + +var; + +getSomething(){ + return this; +} + +getSomethingMore(){ + return getSomething(); +} + +void setVar(){ + var = getSomethingMore(); +} + +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/TestMethodCall.java b/test/mycompiler/test/lambda/TestMethodCall.java new file mode 100644 index 000000000..4be420a8e --- /dev/null +++ b/test/mycompiler/test/lambda/TestMethodCall.java @@ -0,0 +1,30 @@ +package mycompiler.test.lambda; + +import static org.junit.Assert.*; + +import java.util.HashMap; + +import mycompiler.mytest.LambdaTest; + +import org.junit.Test; + +public class TestMethodCall { + + @Test + public void test() { + variableTypeAssumptions.put("var", "TestMethodCall"); + executeTest(); + } + + private static final String exampleJavFile = "TestMethodCall.jav"; + private static final String classname = "TestMethodCall"; + + private HashMap variableTypeAssumptions = new HashMap(); + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); + + } + +} diff --git a/test/mycompiler/test/lambda/TestThis.java b/test/mycompiler/test/lambda/TestThis.java new file mode 100644 index 000000000..a03575e52 --- /dev/null +++ b/test/mycompiler/test/lambda/TestThis.java @@ -0,0 +1,29 @@ +package mycompiler.test.lambda; + +import java.util.HashMap; + +import mycompiler.mytest.LambdaTest; + +import org.junit.Test; + +public class TestThis { + private static final String exampleJavFile = "ThisTest.jav"; + private static final String classname = "ThisTest"; + private HashMap variableTypeAssumptions = new HashMap(); + + + @Test + public void test() { + variableTypeAssumptions.put("thisVar", "ThisTest"); + executeTest(); + } + + + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); + + } + +} diff --git a/test/mycompiler/test/lambda/TestWhile.jav b/test/mycompiler/test/lambda/TestWhile.jav new file mode 100644 index 000000000..019bf8f4e --- /dev/null +++ b/test/mycompiler/test/lambda/TestWhile.jav @@ -0,0 +1,10 @@ +class WhileTest{ + + public method(){ + var; + while(true){ + var = "String"; + } + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/TestWhile.java b/test/mycompiler/test/lambda/TestWhile.java new file mode 100644 index 000000000..8c76ec356 --- /dev/null +++ b/test/mycompiler/test/lambda/TestWhile.java @@ -0,0 +1,37 @@ +package mycompiler.test.lambda; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.Vector; + +import mycompiler.mytest.LambdaTest; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; + +import org.junit.Test; + +import typinferenz.TypeAssumptions; + +public class TestWhile { + + @Test + public void test() { + variableTypeAssumptions.put("var", "String"); + executeTest(); + } + + private static final String exampleJavFile = "TestWhile.jav"; + private static final String classname = "WhileTest"; + + private HashMap variableTypeAssumptions = new HashMap(); + + public void executeTest(){ + LambdaTest tester = new LambdaTest(exampleJavFile); + tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); + + } + +} diff --git a/test/mycompiler/test/lambda/ThisTest.jav b/test/mycompiler/test/lambda/ThisTest.jav new file mode 100644 index 000000000..0ca725581 --- /dev/null +++ b/test/mycompiler/test/lambda/ThisTest.jav @@ -0,0 +1,5 @@ +class ThisTest{ + +thisVar = this; + +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/parseMultipleFilesFile1.jav b/test/mycompiler/test/lambda/parseMultipleFilesFile1.jav new file mode 100644 index 000000000..79a5554a5 --- /dev/null +++ b/test/mycompiler/test/lambda/parseMultipleFilesFile1.jav @@ -0,0 +1,10 @@ +class Klasse2 { + +var1; + +testMethode(){ + var1 = new Klasse1(); + return var1.getVar1(); +} + +} \ No newline at end of file diff --git a/test/mycompiler/test/lambda/parseMultipleFilesFile2.jav b/test/mycompiler/test/lambda/parseMultipleFilesFile2.jav new file mode 100644 index 000000000..47def1950 --- /dev/null +++ b/test/mycompiler/test/lambda/parseMultipleFilesFile2.jav @@ -0,0 +1,7 @@ +class Klasse1 { + var1; + + int getVar1(){ + return var1; + } +} diff --git a/test/mycompiler/test/notUsedAnymore/AbstractInferenceTestExtendedOLD.java b/test/mycompiler/test/notUsedAnymore/AbstractInferenceTestExtendedOLD.java new file mode 100755 index 000000000..d71deb109 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/AbstractInferenceTestExtendedOLD.java @@ -0,0 +1,149 @@ +package mycompiler.test.notUsedAnymore; + +import java.util.HashMap; +import java.util.Vector; + +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; + +/* TODO: this file may be merged with AbstractInferenceTest, meanwhile used for extended testing, where redundant implementations are realized here + * + */ + +public abstract class AbstractInferenceTestExtendedOLD extends AbstractInferenceTestOLD_2 { + + protected HashMap expectedMethodTypeAssumptions = null; + protected HashMap> expectedMethodsTypeAssumptions = null; + + protected AbstractInferenceTestExtendedOLD(String name, String javFilename) { + super(name,javFilename); + this.expectedMethodTypeAssumptions=getExpectedMethodTypeAssumptions(); + this.expectedMethodsTypeAssumptions=getExpectedMethodsTypeAssumptions(); + } + @Deprecated + /** + * + * @return HashMap containing inference results for specific method or null + * key: method name + * value: CMethodTypeAssumption + */ + protected HashMap getExpectedMethodTypeAssumptions() { + return null; + } + + protected HashMap> getExpectedMethodsTypeAssumptions() { + return null; + } + + /** + * start test according to JUnit conventions + * @throws Throwable + */ + public void testSetup() throws Throwable { + runTest(); + } + + protected void checkForFoundClass(Vector foundClasses) { + AbstractInferenceTestExtendedOLD.assertTrue(foundClasses.contains(this.testedClasses.elementAt(0))); + } + + protected void checkForFoundGenerics(Vector foundGenerics) { + + } + + protected void checkForValidMethodTypes(CMethodTypeAssumption assumpt) { + //if called, methods have been found, thus expectation should not be null + if (this.expectedMethodTypeAssumptions!=null) { + //check if found method is expected + AbstractInferenceTestExtendedOLD.assertTrue(expectedMethodTypeAssumptions.containsKey(assumpt.getIdentifier())); + //select correct expected method for further asserts + CMethodTypeAssumption expected = this.expectedMethodTypeAssumptions.get(assumpt.getIdentifier()); + + //return type + AbstractInferenceTestExtendedOLD.assertEquals(expected.getAssumedType().getName(), assumpt.getAssumedType().getName()); + + AbstractInferenceTestExtendedOLD.assertTrue(expected.equalsAssumption(assumpt)); + //number parameters + // AbstractInferenceTestExtended.assertTrue(expected.getParaCount()==assumpt.getParaCount()); + /* for (int i=0;i param = expected.getParaAssumptions(); + AbstractInferenceTestExtended.assertTrue(expected.getParaAssumptions().contains(param.get(i))); + } + */ + //Generic Parameter + AbstractInferenceTestExtendedOLD.assertTrue(expected.getGenericMethodParameters().size()==assumpt.getGenericMethodParameters().size()); + for (int i=0;i> assumptions) { + + AbstractInferenceTestExtendedOLD.assertTrue(expectedMethodsTypeAssumptions.size()==assumptions.size()); + AbstractInferenceTestExtendedOLD.assertTrue(expectedMethodsTypeAssumptions.keySet().equals(assumptions.keySet())); + + //call test for every method + for(String method : assumptions.keySet()) { + Vector currentMethodExpectation = expectedMethodsTypeAssumptions.get(method); + Vector currentMethodAssumption = assumptions.get(method); + + //verify amount of assumption for method + AbstractInferenceTestExtendedOLD.assertTrue(currentMethodExpectation.size()==currentMethodAssumption.size()); + + for (int i=0;i paramExpected = currentMethodExpectation.elementAt(i).getParaAssumptions(); + Vector paramAssumpt = currentMethodAssumption.elementAt(i).getParaAssumptions(); + //check for parameter assumptions + for (int j=0;j genericsExpected = currentMethodExpectation.get(i).getGenericMethodParameters(); + Vector genericsAssumpt = currentMethodAssumption.get(i).getGenericMethodParameters(); + //check amount + AbstractInferenceTestExtendedOLD.assertTrue(genericsExpected.size()==genericsAssumpt.size()); + for (int j=0;j assumption,Vector expected) { + //boolean ret=false; + for (int i=0;i testedClasses = null; + protected MyCompilerAPI compiler = MyCompiler.getAPI(); + + protected AbstractInferenceTestOLD_2(String name, String javFilename) { + super(name); + javFile = new File(javFilename); + this.testedClasses = getTestedClasses(); + } + + protected void runTest() throws Throwable { + parseFile(); + typeReconstruction(); + codeGeneration(); + } + + protected void parseFile() + throws Throwable + { + // Parsen der Klasse + compiler.parse(javFile); + } + + protected void typeReconstruction() + throws Exception + { + // Typ-Rekonstruktion + Vector resultSet = compiler.typeReconstruction(); + // Keine Typ-Rekonstruktion erforderlich + if (resultSet == null || resultSet.size() == 0) throw new Exception("Typrekonstruktion nicht durchfuehrbar!"); + + //specific Testcase-Check for every tested class + + for (String testedClass : this.testedClasses) { + //System.out.println("number1: "+ testedClass); + checkResults(resultSet, testedClass); + } + + CTypeReconstructionResult onePossibility = resultSet.firstElement(); + Iterator substIt = onePossibility.getSubstitutions().getIterator(); + while(substIt.hasNext()){ + CSubstitution subst = (CSubstitution)substIt.next(); + // Substition machen + subst.execute(); + } + } + + protected void codeGeneration() + throws Exception + { + // Code generieren + compiler.codeGeneration(); + } + + + /** + * extracts type-inference results for tested class and calls test methods + * test methods shall be implemented as needed in test class, + * @param resultSet result from typeReconstruction() + */ +// protected void checkResults(Vector resultSet, String testedClass) { +// +// //check valid - implementation +//System.out.println("Länge ResultSet: " + resultSet.size()); +// for (int resIndex=0; resIndex < resultSet.size(); resIndex++) { +// //-------- +// //Classes: +// //-------- +// checkForFoundClass(resultSet.get(resIndex).getClassNameList()); +// //--------- +// //Generics: +// //---------Vector genVec = resultSet.get(resIndex).getGenericsTable().get(testedClass); +// checkForFoundGenerics(resultSet.get(resIndex).getGenericsTable().get(testedClass)); +// //---------- +// // Methods: +// //---------- +// HashMap> assumptions = new HashMap>(); +// Iterator iter1 = resultSet.get(resIndex).getMethodIntersectionTypes().values().iterator(); +// while (iter1.hasNext()) { +// Vector vecAssumpt = iter1.next().getMethodTypeAssumptions(); +// //for (int i=0; i()); +// } +// +// assumptions.get(assumpt.getIdentifier()).add(assumpt); +// //------------------------- +// } +// //} +// } +// if (!assumptions.isEmpty()) +// checkForValidMethodTypes(assumptions); +// //--------------------------- +// //Local and member variables: +// //--------------------------- +// +// Iterator iter2 = resultSet.get(resIndex).getFieldAndLocalVarAssumptions().values().iterator(); +// while (iter2.hasNext()) { +// CTypeAssumption assumption = iter2.next(); +// +// // Es ist eine locale Variable +// if (assumption instanceof CLocalVarTypeAssumption) { +// +// CLocalVarTypeAssumption assu = (CLocalVarTypeAssumption)assumption; +// +// if (assu.getClassName().equals(testedClass)) { +// //---------------------- +// checkForValidLocalVarTypes(assu); +// //---------------------- +// } +// +// } +// +// // Es ist eine Member-Variable +// else if (assumption instanceof CInstVarTypeAssumption) { +// +// CInstVarTypeAssumption assu = (CInstVarTypeAssumption)assumption; +// if (assu.getClassName().equals(testedClass)) { +// //------------------- +// checkForValidMemberTypes(assu); +// //-------------------- +// } +// } +// } +// } +// } + protected void checkResults(Vector resultSet, String testedClass) { + + //check valid - implementation +System.out.println("Länge ResultSet: " + resultSet.size()); + for (int resIndex=0; resIndex < resultSet.size(); resIndex++) { + //-------- + //Classes: + //-------- + // checkForFoundClass(resultSet.get(resIndex).getClassNameList()); + //--------- + //Generics: + //---------Vector genVec = resultSet.get(resIndex).getGenericsTable().get(testedClass); + // checkForFoundGenerics(resultSet.get(resIndex).getGenericsTable().get(testedClass)); + //---------- + // Methods: + //---------- + HashMap> assumptions = new HashMap>(); + Iterator iter1 = resultSet.get(resIndex).getMethodIntersectionTypes().values().iterator(); + while (iter1.hasNext()) { + Vector vecAssumpt = iter1.next().getMethodTypeAssumptions(); + //for (int i=0; i()); + } + + assumptions.get(assumpt.getIdentifier()).add(assumpt); + //------------------------- + } + //} + } + if (!assumptions.isEmpty()) + checkForValidMethodTypes(assumptions); + //--------------------------- + //Local and member variables: + //--------------------------- + + Iterator iter2 = resultSet.get(resIndex).getFieldAndLocalVarAssumptions().values().iterator(); + while (iter2.hasNext()) { + CTypeAssumption assumption = iter2.next(); + + // Es ist eine locale Variable + if (assumption instanceof CLocalVarTypeAssumption) { + + CLocalVarTypeAssumption assu = (CLocalVarTypeAssumption)assumption; + + if (assu.getClassName().equals(testedClass)) { + //---------------------- + checkForValidLocalVarTypes(assu); + //---------------------- + } + + } + + // Es ist eine Member-Variable + else if (assumption instanceof CInstVarTypeAssumption) { + + CInstVarTypeAssumption assu = (CInstVarTypeAssumption)assumption; + if (assu.getClassName().equals(testedClass)) { + //------------------- + checkForValidMemberTypes(assu); + //-------------------- + } + } + } + } + } + + /** + * @return returns a vector of class names of tested file + */ + protected abstract Vector getTestedClasses(); + protected void checkForFoundClass(Vector foundClasses) {} + protected void checkForFoundGenerics(Vector foundGenerics) {} + @Deprecated + protected void checkForValidMethodTypes(CMethodTypeAssumption assumpt) {} + protected void checkForValidMethodTypes(HashMap> assumptions) {} + protected void checkForValidLocalVarTypes(CLocalVarTypeAssumption assumpt) {} + protected void checkForValidMemberTypes(CInstVarTypeAssumption assumpt) {} + protected void setUp() {} + protected void tearDown() {} + +// protected void setUp() +// throws Exception +// { +// super.setUp(); +//System.out.println("setup called"); +// +// // Setup fuer Log4J +// // Logfiles werden im Ordner testResults gespeichert +// // Der Dateiname ist der Klassename plus .log +// String logFile = "testResults/"+ javFile.getName() + ".log"; +// +// File f = new File(logFile); // Altes Logfile loeschen +// f.delete(); +// +// // Ausgabeoptionen fuer die Logger +// PatternLayout pl = new PatternLayout("%-15C{1} %-5p [%-9c] %m%n"); +// FileAppender fa = new FileAppender(pl, logFile); +// +// // Die Einstellungen jedes Loggers veraendern +// ModifyLogger("parser", Level.ALL, fa); +// ModifyLogger("inference", Level.INFO, fa); +// ModifyLogger("codegen", Level.ALL, fa); +// ModifyLogger("bytecode", Level.ALL, fa); +// } +// +// protected void ModifyLogger(String strlogger, Level lv, FileAppender fa) +// { +// Logger lg = Logger.getLogger(strlogger); +// +// lg.setLevel(lv); +// lg.removeAllAppenders(); +// lg.addAppender(fa); +// } +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/AbstractInferenceTestOld.java b/test/mycompiler/test/notUsedAnymore/AbstractInferenceTestOld.java new file mode 100755 index 000000000..6e1b15cf5 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/AbstractInferenceTestOld.java @@ -0,0 +1,381 @@ +package mycompiler.test.notUsedAnymore; + +import java.io.File; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Vector; + +import junit.framework.TestCase; +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytypereconstruction.CIntersectionType; +import mycompiler.mytypereconstruction.CSubstitution; +import mycompiler.mytypereconstruction.CTypeReconstructionResult; +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.BlockExpect; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** Todo: - inheritance + * - exception handling cannot verify correct exception yet + * - generic returntype does not work well + * - cmethodkey-usage? + * - log4j + * + * done: - exception handling + * - commented asserts + * @author Stresing + * last change: 06-04-08 + */ +public abstract class AbstractInferenceTestOld extends TestCase { + + private File javFile=null; + private Expectation expectation=null; + private MyCompilerAPI compiler = MyCompiler.getAPI(); + + private final static String METHODNAMEDELIMITER = "#"; + + protected AbstractInferenceTestOld(String name, String javFilename) { + super(name); + javFile = new File(javFilename); + + //retrieve Expectation object from specific Testcase for comparisons + this.expectation = getExpectations(); + } + + /** + * runs the JUnit-Test, calls all compiler steps + * @throws Throwable + */ + public void testSetup() throws Throwable { + //runs all compiler steps, any exception will cause the Test to fail, if not expected + + try { + parseFile(); + typeReconstruction(); + //codeGeneration(); + } catch (Exception e) { + checkForExpectedException(e); + + } + } + + /** + * calls parse() from Compiler-API + * @throws Throwable + */ + + protected void parseFile() + throws Throwable + { + // Parse file + compiler.parse(javFile); + } + + /** + * calls typeReconstruction() from Compiler-API, checks result against expectations and substitutes all types according to first assumption + * @throws Exception + */ + + protected void typeReconstruction() + throws Exception + { + // Typ-Rekonstruktion + Vector resultSet = compiler.typeReconstruction(); + // Keine Typ-Rekonstruktion erforderlich + if (resultSet == null || resultSet.size() == 0) throw new Exception("Type reconstruction could not be done!"); + + if (this.expectation.getClasses()!=null) + checkResults(resultSet,this.expectation); + + CTypeReconstructionResult onePossibility = resultSet.firstElement(); + Iterator substIt = onePossibility.getSubstitutions().getIterator(); + while(substIt.hasNext()){ + CSubstitution subst = (CSubstitution)substIt.next(); + // Substition machen + subst.execute(); + } + } + + /** + * calls codeGeneration from Compiler-API + * @throws Exception + */ + + protected void codeGeneration() + throws Exception + { + // Code generieren + compiler.codeGeneration(); + } + + /** + * compares resultSet from compiler to expectations + * @param resultSet + * @param expect + */ + + protected void checkResults(Vector resultSet, Expectation expect) { + + //iterates thru all available assumption-sets + for (int resIndex=0; resIndex < resultSet.size(); resIndex++) { + //checks whether all expected classes, methods, members are available + checkClasses(resultSet.get(resIndex),expect); + //-------------- + //Methods + //-------------- + //iterates through all found methods + Iterator iter1 = resultSet.get(resIndex).getMethodIntersectionTypes().values().iterator(); + while (iter1.hasNext()) { + Vector vecAssumpt = iter1.next().getMethodTypeAssumptions(); + //for (int i=0; i iter2 = resultSet.get(resIndex).getFieldAndLocalVarAssumptions().values().iterator(); + while (iter2.hasNext()) { + CTypeAssumption assumption = iter2.next(); + + // local variable + if (assumption instanceof CLocalVarTypeAssumption) { + + CLocalVarTypeAssumption assu = (CLocalVarTypeAssumption)assumption; + + if (expect.getClasses().containsKey(assu.getClassName())){ + //current method to compare assumption to: + MethodExpect method = expect.getClasses().get(assu.getClassName()).getMethods().get(assu.getMethodName()+ AbstractInferenceTestOld.METHODNAMEDELIMITER + assu.getMethodOverloadedID() + AbstractInferenceTestOld.METHODNAMEDELIMITER + assu.getMethodParaCount()); + AbstractInferenceTest.assertTrue("block variable " + assu.getMethodName()+ " not valid or not found!",checkFoundVariable(assu, method.getBlock())); + } + + } + + // member variable + else if (assumption instanceof CInstVarTypeAssumption) { + + + CInstVarTypeAssumption assu = (CInstVarTypeAssumption)assumption; + if (expect.getClasses().containsKey(assu.getClassName())){ + //current class to compare assumption to: + ClassExpect classexpect = expect.getClasses().get(assu.getClassName()); + checkFoundMembers(assu, classexpect.getMembers()); + } + } + } + } + + //verify that every single type assumption that was expected has been detected by the compiler + AbstractInferenceTest.assertTrue("not all expected types have been found", expectation.verifyTypeExpectationsCompletelyMet()); + } + + /** + * @return returns a vector of class names of tested file + */ + protected abstract Expectation getExpectations(); + + + /** + * checks the return type of a method comparing it to the expectation + * @param assumpt + * @param expect + */ + protected void checkReturnType(Type assumpt, MethodExpect expect) { + if (!expect.getReturntypes().isEmpty()) { + AbstractInferenceTest.assertTrue("found return type " + assumpt.getName() + " is not in expected list", expect.getReturntypes().contains(assumpt)); + + checkBoundedTypes(assumpt,expect.getReturntypes().get(expect.getReturntypes().indexOf(assumpt))); + //remove this expectation to assure, all expectations have been met at least once + if (expect.getReturntypesCopy().contains(assumpt)) + expect.getReturntypesCopy().remove(assumpt); + } + else if (assumpt instanceof GenericTypeVar) + //expect.addGeneric((GenericTypeVar) assumpt); + System.out.println("assumpt is GenericTypeVar"); + else + AbstractInferenceTest.assertTrue("no return type for " + assumpt.getName() +" has been defined in expectation",assumpt instanceof TypePlaceholder); + } + + /** + * checks for generic methods comparing them to the expectation + * @param assumpt + * @param expect + */ + protected void checkFoundGenerics(Vector assumpt, Vector expect) { + AbstractInferenceTest.assertTrue("amount of generic variables expected != assumed",((assumpt==null || assumpt.size()==0) && (expect==null || expect.size()==0)) || assumpt.size()==expect.size()); + for (GenericTypeVar typ : assumpt) { + //System.out.println("Generics: " + typ.get_Name() + ((BoundedGenericTypeVar)typ).getBounds() + ", " + expect.indexOf(typ)); + AbstractInferenceTest.assertTrue("Generic " + typ.getName() + " has not been expected",expect.contains(typ)); + + checkBoundedTypes(typ,expect.get(expect.indexOf(typ))); + } + } + + private void checkBoundedTypes(Type assumed, Type expected) { + if (assumed instanceof BoundedGenericTypeVar) { + AbstractInferenceTest.assertTrue(expected instanceof BoundedGenericTypeVar); + BoundedGenericTypeVar typBound = (BoundedGenericTypeVar)assumed; + BoundedGenericTypeVar expBound = (BoundedGenericTypeVar)expected; + for (Type t : typBound.getBounds()) { + boolean ret = false; + for (Type e : expBound.getBounds()) { +System.out.println(" here " + t + " -- " + e); + if (e.equals(t)) { + ret=true; + } + } + AbstractInferenceTest.assertTrue("Bounded generic's type is not equal", ret); + } + } + else if (assumed instanceof GenericTypeVar) { + System.out.println("GENERICTYPEVAR"); + } + } + + /** + * searches recursively for the matching block in the expectation set and compares found variables to the expectation + * @param assumpt + * @param expect + * @return + */ + + protected boolean checkFoundVariable(CLocalVarTypeAssumption assumpt, BlockExpect expect) { + //there is an expectation for a variable + AbstractInferenceTest.assertTrue(expect!=null); + boolean ret=false; + if (expect.getBlockID().equals(assumpt.getBlockId())) { + AbstractInferenceTest.assertTrue("Variable "+assumpt.getIdentifier() + " is not defined in expectation",expect.getLocalVar().containsKey(assumpt.getIdentifier())); + Vector expTypes = expect.getLocalVar().get(assumpt.getIdentifier()).getExpectedType(); + //check if a specific type for this variable is expected or whether it should be a typeplaceholder + if (!expTypes.isEmpty()) { + AbstractInferenceTest.assertTrue("Type " + assumpt.getAssumedType() + " for variable " + assumpt.getIdentifier() + " is not found in expectations", expTypes.contains(assumpt.getAssumedType())); + checkBoundedTypes(assumpt.getAssumedType(), expTypes.get(expTypes.indexOf(assumpt.getAssumedType()))); + + //remove this expectation to assure, all expectations have been met at least once + expect.getLocalVar().get(assumpt.getIdentifier()).getExpectedTypeCopy().remove(assumpt.getAssumedType()); + } + else + //check for TypePlaceholder as expected + AbstractInferenceTest.assertTrue("no type for variable "+ assumpt.getIdentifier() + " has been defined", assumpt.getAssumedType() instanceof TypePlaceholder); + + return true; + } + else if (expect.getContainedBlocks()!=null){ + //dig one block deeper in hierarchy + for (BlockExpect exp : expect.getContainedBlocks()) + ret |= checkFoundVariable(assumpt,exp); + return ret; + } + return false; + } + /** + * checks method parameters comparing them to the expectation + * @param assumpt + * @param expect + */ + + protected void checkParameters(CMethodTypeAssumption methodAssumpt, MethodExpect methodExpect) { + Vector assumpt = methodAssumpt.getParaAssumptions(); + HashMap expect = methodExpect.getParameter(); + //amount of parameter + AbstractInferenceTest.assertEquals("amount of parameters not equal!", assumpt.size(),expect.size()); + + for (CParaTypeAssumption paraAssumpt : assumpt) { + //check if variable is expected + AbstractInferenceTest.assertTrue("variable " + paraAssumpt.getIdentifier() + " is not expected!", expect.containsKey(paraAssumpt.getIdentifier())); + Vector expectedTypes = expect.get(paraAssumpt.getIdentifier()).getExpectedType(); + //check if variable's type is expected + + //case of undefined type (generic variable), add generic to generic list + if (!expectedTypes.isEmpty()) { + AbstractInferenceTest.assertTrue("type " + paraAssumpt.getAssumedType() + " for variable " + paraAssumpt.getIdentifier() + " is not expected!", expectedTypes.contains(paraAssumpt.getAssumedType())); + checkBoundedTypes(paraAssumpt.getAssumedType(), expectedTypes.get(expectedTypes.indexOf(paraAssumpt.getAssumedType()))); + + //remove this expectation to assure, all expectations have been met at least once + expect.get(paraAssumpt.getIdentifier()).getExpectedTypeCopy().remove(paraAssumpt.getAssumedType()); + } + else if (paraAssumpt.getAssumedType() instanceof GenericTypeVar) { + if (!methodExpect.getGenerics().contains((GenericTypeVar)paraAssumpt.getAssumedType())) + methodExpect.addGeneric((GenericTypeVar) paraAssumpt.getAssumedType()); + } + else + AbstractInferenceTest.fail("no type for " + paraAssumpt.getIdentifier() +" has been defined in expectation"); + } + } + + /** + * checks every class expected is included in compiler assumption + available generics + * @param assumption + * @param expectation + */ + protected void checkClasses(CTypeReconstructionResult assumption, Expectation expectation) { + + + for (String expect : expectation.getClasses().keySet()) { + //class exists + AbstractInferenceTest.assertTrue("class " + expect + " is not found in assumption!", assumption.getClassNameList().contains(expect)); + //generics + checkFoundGenerics(assumption.getGenerics(expect), expectation.getClasses().get(expect).getGenerics()); + } + } + + /** + * members found are compared to the expectation + * @param assumpt + * @param expect + */ + + protected void checkFoundMembers(CInstVarTypeAssumption assumpt, HashMap expect) { + AbstractInferenceTest.assertTrue("Member " + assumpt.getIdentifier() + " is not found in expectation!", expect.containsKey(assumpt.getIdentifier())); + AbstractInferenceTest.assertTrue("Type " + assumpt.getAssumedType() + " for member " + assumpt.getIdentifier() + " is not found in expectation",expect.get(assumpt.getIdentifier()).getExpectedType().contains(assumpt.getAssumedType())); + // + //remove this expectation to assure, all expectations have been met at least once + if (expect.get(assumpt.getIdentifier()).getExpectedTypeCopy().contains(assumpt.getAssumedType())) + expect.get(assumpt.getIdentifier()).getExpectedTypeCopy().remove(assumpt.getAssumedType()); + } + + /** + * called to verify whether thrown exception from compiler calls is expected + * @param e + * @throws Throwable + */ + protected void checkForExpectedException (Exception e) throws Throwable { + if (!this.expectation.getExceptions().isEmpty()) { + //check if thrown exception has been expected + e.printStackTrace(); + System.out.println(e.getClass()); + //AbstractInferenceTest2.assertTrue("Exception " + e.getMessage() + " is not same as expected", e.getClass().equals(this.expectation.getExceptions().firstElement())); + AbstractInferenceTestOLD_2.assertTrue("Exception " + e.getMessage() + " is not expected", !this.expectation.getExceptions().isEmpty()); + } + else + throw e; + } + + @Deprecated + protected void checkForValidMethodTypes(CMethodTypeAssumption assumpt) {} + protected void setUp() {} + protected void tearDown() {} +} diff --git a/test/mycompiler/test/notUsedAnymore/CTypeAssumptionWrapper.java b/test/mycompiler/test/notUsedAnymore/CTypeAssumptionWrapper.java new file mode 100755 index 000000000..7d4c42ae9 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/CTypeAssumptionWrapper.java @@ -0,0 +1,60 @@ +package mycompiler.test.notUsedAnymore; + +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; + +public class CTypeAssumptionWrapper { + + CTypeAssumption assumption; + + public CTypeAssumptionWrapper(CTypeAssumption assumption) { + this.assumption=assumption; + } + + public final boolean equals(Object obj) + // ino.end + // ino.method.equals.27820.body + { + if(obj instanceof CTypeAssumption){ + CTypeAssumption assum = (CTypeAssumption)obj; + boolean ret = true; + ret &= getClassName().equals(assum.getClassName()); + ret &= getIdentifier().equals(assum.getIdentifier()); + ret &= getAssumedType().equals(assum.getAssumedType()); + ret &= this.equalsAssumption(assum); + return ret; + } + else{ + return false; + } + } + + public boolean equalsAssumption(CTypeAssumption assumpt) { + return assumption.equalsAssumption(assumpt); + } + + public Type getAssumedType() { + return assumption.getAssumedType(); + } + + public String getClassName() { + return assumption.getClassName(); + } + + public String getIdentifier() { + return assumption.getIdentifier(); + } + + public void setAssumedType(Type assumedType) { + assumption.setAssumedType(assumedType); + } + + public void setClassName(String className) { + assumption.setClassName(className); + } + + public String toString() { + return assumption.toString(); + } + +} diff --git a/test/mycompiler/test/notUsedAnymore/IResultValidator.java b/test/mycompiler/test/notUsedAnymore/IResultValidator.java new file mode 100755 index 000000000..380577b5e --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/IResultValidator.java @@ -0,0 +1,11 @@ +package mycompiler.test.notUsedAnymore; + +import java.util.Vector; + +import mycompiler.mytypereconstruction.CTypeReconstructionResult; + +public interface IResultValidator { + + public void checkResults(Vector resultSet); + +} diff --git a/test/mycompiler/test/notUsedAnymore/TEst_2.java b/test/mycompiler/test/notUsedAnymore/TEst_2.java new file mode 100755 index 000000000..050919a10 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TEst_2.java @@ -0,0 +1,25 @@ +package mycompiler.test.notUsedAnymore; + +import java.util.ArrayList; + +class A{ + +} + +public class TEst_2{ + ,C> void foo(T a,C b){} + + void m(){ + TEst_2 t = new TEst_2(); + String c = new String(); + A str = new A(); + t.foo(str,c); + } + + public void m2(Object a) { + + ArrayList b= new ArrayList(); + a = b.get(0); + + } +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/Test.java b/test/mycompiler/test/notUsedAnymore/Test.java new file mode 100755 index 000000000..c9a32b4a4 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/Test.java @@ -0,0 +1,67 @@ +package mycompiler.test.notUsedAnymore; + +interface I1 { + public void m1(); +} + +interface I2 { + public void m2(); +} + +class Implementation implements I1, I2 { + public void m1() {} + + public void m2() {} +} + +class Implementation2 extends Implementation { +} + +class Tester { + T x; + public void m3(Implementation x) { + x.m1(); + x.m2(); + } + public void m4 (T x) { + x.m1(); + x.m2(); + } + + public Long m4(Integer a, Long b) { + return a+b; + } + +} + + +public class Test { + + public static void main(String[] args) { + Implementation x= new Implementation(); + Implementation2 y = new Implementation2(); + + Tester a = new Tester(); + //a.m3(x); + + + Tester b = new Tester(); + b.m3(y); + + Tester c = new Tester(); + c.m3(y); + //c.m4(y); + } +} + +class TestSimpleClassesWithBoundedGenerics1 { + + public T ma(T x) { + return x; + } + + public int mb(T x) { + return x+1; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.jav b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.jav new file mode 100755 index 000000000..df5e707fc --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.jav @@ -0,0 +1,20 @@ + +class TestAbstractInferenceTest { + + public foo(a, b) { + c; + d; + d = a+ b; + { + i; + i=5; + } + { + i; + i="abc"; + } + c = new TestAbstractInferenceTest(); + return a+b; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.java b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.java new file mode 100755 index 000000000..e373a052c --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.java @@ -0,0 +1,307 @@ +package mycompiler.test.notUsedAnymore; + +import java.util.Vector; + +import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; +import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; + + +/*TODO: +*/ + +public class TestAbstractInferenceTest extends AbstractInferenceTestOLD_2 { + + private final static String TESTEDCLASSNAME="TestAbstractInferenceTest"; + private final static String JAVPATH="test/mycompiler/test/"; + + public TestAbstractInferenceTest(String name) { + super(name,TestAbstractInferenceTest.JAVPATH+TestAbstractInferenceTest.TESTEDCLASSNAME+".jav"); + + } + + protected Vector getTestedClasses(){ + Vector testedclasses = new Vector(); + testedclasses.add(TestAbstractInferenceTest.TESTEDCLASSNAME); + return testedclasses; + } + public void testThisCase() throws Throwable { + + runTest(); + } + + protected void checkForValidClass(Vector testedClass) { + } + + protected void checkForValidMethodTypes(CMethodTypeAssumption assumpt) { + System.out.println("Method "+assumpt.getIdentifier()+ ", &return:" + assumpt.getAssumedType().getName()); + } + + protected void checkForValidLocalVarTypes(CLocalVarTypeAssumption assumpt) { + System.out.println("Local-Variable "+assumpt.getIdentifier()+ "(" + assumpt.getBlockId() + "), Typ:" +assumpt.getAssumedType().getName()+ ", Methode:" + assumpt.getMethodName()); + } + + protected void checkForValidMemberTypes(CInstVarTypeAssumption assumpt) { + System.out.println("Member-Variable "+assumpt.getIdentifier()+", Typ:" +assumpt.getAssumedType().getName()); + } + +// public void checkResults(Vector resultSet) { +// //check valid - implementation +//System.out.println("checkResults called, Länge ResultSet: " + resultSet.size()); +// //for (int resIndex=0; resIndex < resultSet.size(); ++resIndex) { +// for (int resIndex=0; resIndex < resultSet.size(); resIndex++) { +// +// Vector genVec = resultSet.get(resIndex).getGenericsTable().get("Test1"); +// System.out.println("Generics: " + genVec); +// // Methoden: +// // --------- +// +// Iterator iter1 = resultSet.get(resIndex).getMethodIntersectionTypes().values().iterator(); +// while (iter1.hasNext()) { +// +// CMethodTypeAssumption assumpt = iter1.next().getMethodTypeAssumptions().get(0); +// +// // Methode geh�rt zur aktuellen Klasse (ist somit g�ltig) +// //System.out.println("Classname: " + assumpt.getClassName()); +// if (assumpt.getClassName().equals("TestAbstractInferenceTest")) { +// // if (assumpt.getIdentifier().equals("foo")) { +// // Methode holen bzw. anlegen +// String DummyMethodname;//Sonderfall fuer ueberladene Methoden +// if(assumpt.getOverloadedMethodID()<10) +// { +// DummyMethodname=assumpt.getIdentifier()+"0"+new Integer(assumpt.getOverloadedMethodID()).toString(); +// } +// else +// { +// DummyMethodname=assumpt.getIdentifier()+new Integer(assumpt.getOverloadedMethodID()).toString(); +// } +// //JavMethodIdent method = jClass.addMethod(DummyMethodname, assumpt.getLineNumber(),assumpt.getOffset(),assumpt.getOffsetVector(),assumpt.getAssumedType().getOffset()); +// //alleMethodenOffsets.addElement(assumpt.getOffset()); +// System.out.println("Method "+assumpt.getIdentifier()+ ", &return:" + assumpt.getAssumedType().getName()); +// +// // R�ckgabewert hinzuf�gen +// //method.addReturnFacility(new TypeFacility(getAssumedTypeName(assumpt.getAssumedType()), resIndex), +// // assumpt.getLineNumber()); +// +// // Parameter hinzuf�gen +// Vector vec = assumpt.getParaAssumptions(); +// for (int j=0; j genTypVec = assumpt.getGenericMethodParameters(); +// // method.setGenericMethodParameters(genTypVec); +// for(GenericTypeVar GTV : genTypVec) +// { +// System.out.println("Generic Method-Parameter "+GTV.getName()+", Methode:" + assumpt.getIdentifier()); +// } +// } +// } +// // Locale und Membervariablen: +// // --------------------------- +// +// Iterator iter2 = resultSet.get(resIndex).getFieldAndLocalVarAssumptions().values().iterator(); +// +// while (iter2.hasNext()) { +// CTypeAssumption assumption = iter2.next(); +// +// // Es ist eine locale Variable +// if (assumption instanceof CLocalVarTypeAssumption) { +// +// CLocalVarTypeAssumption assu = (CLocalVarTypeAssumption)assumption; +// +// +// if (assu.getClassName().equals("TestAbstractInferenceTest")) { +////checks whether assumption deals with focussed class +// // TestAbstractInferenceTest.assertEquals(assu.getClassName(), this.getClass().getName() ); +// +// System.out.println("Local-Variable "+assu.getIdentifier()+ "(" + assu.getBlockId() + "), Typ:" +assu.getAssumedType().getName()+ ", Methode:" + assu.getMethodName()); +// String DummyMethodname;//Sonderfall fuer ueberladene Methoden +// if(assu.getMethodOverloadedID()<10) +// { +// DummyMethodname=assu.getMethodName()+"0"+new Integer(assu.getMethodOverloadedID()).toString(); +// } +// else +// { +// DummyMethodname=assu.getMethodName()+new Integer(assu.getMethodOverloadedID()).toString(); +// } +// //JavMethodIdent method = jClass.addMethod(DummyMethodname, assu.getLineNumber(),assu.getOffset(),assu.getOffsetVector(),assu.getOffset()); +// String localVarName = assu.getIdentifier()+ "(" + assu.getBlockId() + ")"; +// +// +// if (assu.isPlaceholderVariable()) { +// +// if (resIndex==0) { +// //method.addLocalVar(localVarName, assu, genVec, assu.getLineNumber(),assu.getOffset(),assu.getOffsetVector()); +// System.out.println("assu is TypePlaceholder:"); +// } +// } +// else { +// //method.addLocalVar(localVarName, +// // new TypeFacility(getAssumedTypeName(assu.getAssumedType()), resIndex), +// // assu.getLineNumber(),assu.getOffset(),assu.getOffsetVector()); +// } +// } +// +// } +// +// // Es ist eine Member-Variable +// else if (assumption instanceof CInstVarTypeAssumption) { +// //System.out.println("eine Membervariable???"); +// +// CInstVarTypeAssumption assu = (CInstVarTypeAssumption)assumption; +// if (assu.getClassName().equals("TestAbstractInferenceTest")) { +// //TestAbstractInferenceTest.assertEquals(assu.getClassName(), this.getClass().getName()); +// System.out.println("Member-Variable "+assu.getIdentifier()+", Typ:" +assu.getAssumedType().getName()); +// //jClass.addMember(assu.getIdentifier(), +// // new TypeFacility(getAssumedTypeName(assu.getAssumedType()), resIndex), +// // assu.getLineNumber(),assu.getOffset(),assu.getOffsetVector()); +// } +// } +// } +// } +// } + +//public void checkResults(Vector resultSet) { +// //check valid - implementation +//System.out.println("checkResults called, Länge ResultSet: " + resultSet.size()); +// //for (int resIndex=0; resIndex < resultSet.size(); ++resIndex) { +// for (int resIndex=0; resIndex < 1; resIndex++) { +// +// Vector genVec = resultSet.get(resIndex).getGenericsTable().get("Test1"); +// +// // Methoden: +// // --------- +// +// Iterator iter1 = resultSet.get(resIndex).getMethodIntersectionTypes().values().iterator(); +// while (iter1.hasNext()) { +// +// CMethodTypeAssumption assumpt = iter1.next().getMethodTypeAssumptions().get(0); +// +// // Methode geh�rt zur aktuellen Klasse (ist somit g�ltig) +// //TestAbstractInferenceTest.assertTrue(1==0); +// //hier muss der Klassenassert hin +// //if (assumpt.getClassName().equals(className)) { +// if (assumpt.getIdentifier().equals("foo")) { +// // Methode holen bzw. anlegen +// String DummyMethodname;//Sonderfall fuer ueberladene Methoden +// if(assumpt.getOverloadedMethodID()<10) +// { +// DummyMethodname=assumpt.getIdentifier()+"0"+new Integer(assumpt.getOverloadedMethodID()).toString(); +// } +// else +// { +// DummyMethodname=assumpt.getIdentifier()+new Integer(assumpt.getOverloadedMethodID()).toString(); +// } +// //JavMethodIdent method = jClass.addMethod(DummyMethodname, assumpt.getLineNumber(),assumpt.getOffset(),assumpt.getOffsetVector(),assumpt.getAssumedType().getOffset()); +// //alleMethodenOffsets.addElement(assumpt.getOffset()); +// System.out.println("Method "+assumpt.getIdentifier()+ ", &return:" + assumpt.getAssumedType().getName()); +// +// // R�ckgabewert hinzuf�gen +// //method.addReturnFacility(new TypeFacility(getAssumedTypeName(assumpt.getAssumedType()), resIndex), +// // assumpt.getLineNumber()); +// +// // Parameter hinzuf�gen +// Vector vec = assumpt.getParaAssumptions(); +// for (int j=0; j genTypVec = assumpt.getGenericMethodParameters(); +// // method.setGenericMethodParameters(genTypVec); +// for(GenericTypeVar GTV : genTypVec) +// { +// System.out.println("Generic Method-Parameter "+GTV.getName()+", Methode:" + assumpt.getIdentifier()); +// } +// } +// } +// // Locale und Membervariablen: +// // --------------------------- +// +// Iterator iter2 = resultSet.get(resIndex).getFieldAndLocalVarAssumptions().values().iterator(); +// +// while (iter2.hasNext()) { +// CTypeAssumption assumption = iter2.next(); +// +// // Es ist eine locale Variable +// if (assumption instanceof CLocalVarTypeAssumption) { +// +// CLocalVarTypeAssumption assu = (CLocalVarTypeAssumption)assumption; +// +// +// //if (assu.getClassName().equals(className)) { +////checks whether assumption deals with focussed class +// // TestAbstractInferenceTest.assertEquals(assu.getClassName(), this.getClass().getName() ); +// +// System.out.println("Local-Variable "+assu.getIdentifier()+ "(" + assu.getBlockId() + "), Typ:" +assu.getAssumedType().getName()+ ", Methode:" + assu.getMethodName()); +// String DummyMethodname;//Sonderfall fuer ueberladene Methoden +// if(assu.getMethodOverloadedID()<10) +// { +// DummyMethodname=assu.getMethodName()+"0"+new Integer(assu.getMethodOverloadedID()).toString(); +// } +// else +// { +// DummyMethodname=assu.getMethodName()+new Integer(assu.getMethodOverloadedID()).toString(); +// } +// //JavMethodIdent method = jClass.addMethod(DummyMethodname, assu.getLineNumber(),assu.getOffset(),assu.getOffsetVector(),assu.getOffset()); +// String localVarName = assu.getIdentifier()+ "(" + assu.getBlockId() + ")"; +// +// +// if (assu.isPlaceholderVariable()) { +// +// if (resIndex==0) { +// //method.addLocalVar(localVarName, assu, genVec, assu.getLineNumber(),assu.getOffset(),assu.getOffsetVector()); +// System.out.println("assu is TypePlaceholder:"); +// } +// } +// else { +// //method.addLocalVar(localVarName, +// // new TypeFacility(getAssumedTypeName(assu.getAssumedType()), resIndex), +// // assu.getLineNumber(),assu.getOffset(),assu.getOffsetVector()); +// } +// +// } +// +// // Es ist eine Member-Variable +// else if (assumption instanceof CInstVarTypeAssumption) { +// System.out.println("eine Membervariable???"); +// +// CInstVarTypeAssumption assu = (CInstVarTypeAssumption)assumption; +// //if (assu.getClassName().equals(className)) { +// //TestAbstractInferenceTest.assertEquals(assu.getClassName(), this.getClass().getName()); +// System.out.println("Member-Variable "+assu.getIdentifier()+", Typ:" +assu.getAssumedType().getName()); +// //jClass.addMember(assu.getIdentifier(), +// // new TypeFacility(getAssumedTypeName(assu.getAssumedType()), resIndex), +// // assu.getLineNumber(),assu.getOffset(),assu.getOffsetVector()); +// } +// } +// } +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest2.jav b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest2.jav new file mode 100755 index 000000000..1f4cef494 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest2.jav @@ -0,0 +1,21 @@ + +public class TestAbstractInferenceTest2 { + + method(Integer a, String s) { + } +} + +class TestAbstractInferenceTest3 extends TestAbstractInferenceTest2 { +/* + method(Integer a) { + c; + }*/ + method2(String s) { + c; + c = new TestAbstractInferenceTest2(); + c.method(2,"abc"); + method(3,"abc"); + } + + +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest2.java b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest2.java new file mode 100755 index 000000000..527aa8101 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest2.java @@ -0,0 +1,56 @@ +package mycompiler.test.notUsedAnymore; + +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestAbstractInferenceTest2 extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestAbstractInferenceTest2"; + private final static String JAVPATH="test/mycompiler/test/"; + + public TestAbstractInferenceTest2(String name) { + super(name,TestAbstractInferenceTest2.JAVPATH+TestAbstractInferenceTest2.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect testAbstractInferenceTest2 = new ClassExpect(TestAbstractInferenceTest2.TESTEDCLASSNAME); + ClassExpect testAbstractInferenceTest3 = new ClassExpect("TestAbstractInferenceTest3"); + + //methods + MethodExpect m1 = new MethodExpect("method",new RefType("void",-1),0); + GenericTypeVar t = new GenericTypeVar("T",-1); + m1.addParameter(new VarExpect("a", new RefType("java.lang.Integer",-1))); + m1.addParameter(new VarExpect("s",new RefType("java.lang.String",-1))); + // m1.addGeneric(t); + + // m1.getBlock().addLocalVar(new VarExpect("c",null)); + + testAbstractInferenceTest2.addMethod(m1); + + MethodExpect m2 = new MethodExpect("method2",new RefType("void",-1),0); + m2.addParameter(new VarExpect("s", new RefType("java.lang.String",-1))); + m2.getBlock().addLocalVar(new VarExpect("c",new RefType("TestAbstractInferenceTest2",-1))); + + MethodExpect m3 = new MethodExpect("method",new RefType("void",-1),0); + m3.addParameter(new VarExpect("a", new RefType("java.lang.Integer",-1))); + m3.addParameter(new VarExpect("s", new RefType("java.lang.String",-1))); + //m3.getBlock().addLocalVar(new VarExpect("c",null)); + + //testAbstractInferenceTest3.addMethod(m1); + testAbstractInferenceTest3.addMethod(m2); + testAbstractInferenceTest3.addMethod(m3); + + + Expectation ret = new Expectation(testAbstractInferenceTest2); + ret.addClass(testAbstractInferenceTest3); + return ret; + } + +} diff --git a/test/mycompiler/test/notUsedAnymore/TestClassMemberWithoutType.jav b/test/mycompiler/test/notUsedAnymore/TestClassMemberWithoutType.jav new file mode 100755 index 000000000..249e1d57d --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestClassMemberWithoutType.jav @@ -0,0 +1,5 @@ + +public class TestClassMemberWithoutType { + + member; +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestClassMemberWithoutType.java b/test/mycompiler/test/notUsedAnymore/TestClassMemberWithoutType.java new file mode 100755 index 000000000..8ef1d5c2e --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestClassMemberWithoutType.java @@ -0,0 +1,37 @@ +package mycompiler.test.notUsedAnymore; + +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.test.expectationTypes.TypePlaceholderExpect; + +/** + * 18-04-08 + * @author + * todo: delete this test, cuz it does not make sense + * + * this test checks whether members without types are supported + */ +public class TestClassMemberWithoutType extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestClassMemberWithoutType"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestClassMemberWithoutType(String name) { + super(name,TestClassMemberWithoutType.JAVPATH+TestClassMemberWithoutType.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + //class--- TestClassMemberWithoutType + ClassExpect testClassMemberWithoutType = new ClassExpect(TestClassMemberWithoutType.TESTEDCLASSNAME); + //member + VarExpect member = new VarExpect("member",new TypePlaceholderExpect("a")); + testClassMemberWithoutType.addMember(member); + //Expectation + return new Expectation(testClassMemberWithoutType); + } + +} diff --git a/test/mycompiler/test/notUsedAnymore/TestConstantsWithoutType.jav b/test/mycompiler/test/notUsedAnymore/TestConstantsWithoutType.jav new file mode 100755 index 000000000..e61a2feb8 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestConstantsWithoutType.jav @@ -0,0 +1,6 @@ +public class TestConstantsWithoutType { + public final static B = true; + public final static I = 1; + public final static C = 'A'; + public final static S = "Hello World!"; +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestConstantsWithoutType.java b/test/mycompiler/test/notUsedAnymore/TestConstantsWithoutType.java new file mode 100755 index 000000000..5b9a001d7 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestConstantsWithoutType.java @@ -0,0 +1,39 @@ +package mycompiler.test.notUsedAnymore; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 18-04-08 + * @author + * + * this test checks correct detection of constants as members + */ +public class TestConstantsWithoutType extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestConstantsWithoutType"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestConstantsWithoutType(String name) { + super(name,TestConstantsWithoutType.JAVPATH+TestConstantsWithoutType.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + //class--- TestConstantsWithoutType + ClassExpect testConstantsWithoutType = new ClassExpect(TestConstantsWithoutType.TESTEDCLASSNAME); + //member + testConstantsWithoutType.addMember(new VarExpect("B",new RefType("java.lang.Boolean",-1))); + testConstantsWithoutType.addMember(new VarExpect("I",new RefType("java.lang.Integer",-1))); + testConstantsWithoutType.addMember(new VarExpect("C",new RefType("java.lang.Character",-1))); + testConstantsWithoutType.addMember(new VarExpect("S",new RefType("java.lang.String",-1))); + + //Expectation + return new Expectation(testConstantsWithoutType); + } + +} diff --git a/test/mycompiler/test/notUsedAnymore/TestGenerics.jav b/test/mycompiler/test/notUsedAnymore/TestGenerics.jav new file mode 100755 index 000000000..337a16164 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestGenerics.jav @@ -0,0 +1,8 @@ + + +public class TestGenerics { + + > void foo(T n) {} + void foo(T i) {} + +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestGenerics.java b/test/mycompiler/test/notUsedAnymore/TestGenerics.java new file mode 100755 index 000000000..001bffae6 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestGenerics.java @@ -0,0 +1,60 @@ +package mycompiler.test.notUsedAnymore; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 01-04-08 + * @author + * + * This test verifies identification of a simple method with returntype void + * + */ + +public class TestGenerics extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestGenerics"; + private final static String JAVPATH="test/mycompiler/test/"; + + public TestGenerics(String name) { + super(name,TestGenerics.JAVPATH+TestGenerics.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + // Classes + ClassExpect testGenerics = new ClassExpect(TestGenerics.TESTEDCLASSNAME); + + //Methods + MethodExpect m0 = new MethodExpect("foo",new RefType("void",-1),0); + Vector bounds1 = new Vector(); + Vector parameter = new Vector(); + parameter.add(new RefType("java.lang.Integer",-1)); + RefType test = new RefType("Vector",parameter,-1); + bounds1.add(test); + BoundedGenericTypeVar generic1 = new BoundedGenericTypeVar("T",bounds1,-1); + m0.addGeneric(generic1); + m0.addParameter(new VarExpect("n",generic1)); + + MethodExpect m1 = new MethodExpect("foo",new RefType("void",-1),1); + Vector bounds2 = new Vector(); + bounds2.add(new RefType("Number",-1)); + BoundedGenericTypeVar generic2 = new BoundedGenericTypeVar("T",bounds2,-1); + m1.addGeneric(generic2); + m1.addParameter(new VarExpect("i",generic2)); + + + testGenerics.addMethod(m0); + testGenerics.addMethod(m1); + return new Expectation(testGenerics); + } +} diff --git a/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterface.jav b/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterface.jav new file mode 100755 index 000000000..127ed26eb --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterface.jav @@ -0,0 +1,7 @@ +interface A{ + public m(); +} +class TestInheritanceCheckValidImplementationFromInterface implements A{ + + public void m(){} +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterface.java b/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterface.java new file mode 100755 index 000000000..1f8c15d8b --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterface.java @@ -0,0 +1,42 @@ +package mycompiler.test.notUsedAnymore; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; + +/* + * Testcase fails, because the interface's method is not inferenced according to its implementation in class + */ +public class TestInheritanceCheckValidImplementationFromInterface extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestInheritanceCheckValidImplementationFromInterface"; + private final static String JAVPATH="test/mycompiler/test/javaConcepts/inheritance/"; + + public TestInheritanceCheckValidImplementationFromInterface(String name) { + super(name,TestInheritanceCheckValidImplementationFromInterface.JAVPATH+TestInheritanceCheckValidImplementationFromInterface.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //Interface + ClassExpect a = new ClassExpect("A"); + //Class + ClassExpect testInheritanceCheckValidImplementationFromInterface = new ClassExpect(TestInheritanceCheckValidImplementationFromInterface.TESTEDCLASSNAME); + + //methods + MethodExpect mClass = new MethodExpect("m", new RefType("void",-1)); + MethodExpect mInterface = new MethodExpect("m", new RefType("void",-1)); + a.addMethod(mInterface); + testInheritanceCheckValidImplementationFromInterface.addMethod(mClass); + + //adding classes to Expectation + Expectation ret = new Expectation(testInheritanceCheckValidImplementationFromInterface); + ret.addClass(a); + return ret; + } + +} + diff --git a/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative.jav b/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative.jav new file mode 100755 index 000000000..e05fdae65 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative.jav @@ -0,0 +1,7 @@ +interface A{ + public m(); +} +class TestInheritanceCheckValidImplementationFromInterfaceNegative implements A{ + + public void m1(){} +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative2.jav b/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative2.jav new file mode 100755 index 000000000..0dd2a73e1 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestInheritanceCheckValidImplementationFromInterfaceNegative2.jav @@ -0,0 +1,14 @@ +interface TestInheritanceCheckValidImplementationFromInterfaceNegative2{ + public m(); +} +class A implements TestInheritanceCheckValidImplementationFromInterfaceNegative2{ + + public void m(){} +} + +class B implements TestInheritanceCheckValidImplementationFromInterfaceNegative2 { + + public m() { + return 1; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestMethodReturnType.jav b/test/mycompiler/test/notUsedAnymore/TestMethodReturnType.jav new file mode 100755 index 000000000..ae4d9c9be --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestMethodReturnType.jav @@ -0,0 +1,21 @@ + +public class TestMethodReturnType { + +/* methodReturnType1(a) { + return a; + } + */ + methodReturnType2(a,b) { + return a+b; + } + + methodReturnType3(String a) { + return a; + } + + Integer methodReturnType4(a) { + return a; + } + + +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestMethodReturnType.java b/test/mycompiler/test/notUsedAnymore/TestMethodReturnType.java new file mode 100755 index 000000000..00bc3cceb --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestMethodReturnType.java @@ -0,0 +1,64 @@ +package mycompiler.test.notUsedAnymore; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestMethodReturnType extends AbstractInferenceTest { + + + private final static String TESTEDCLASSNAME="TestMethodReturnType"; + private final static String JAVPATH="test/mycompiler/test/"; + + public TestMethodReturnType(String name) { + super(name,TestMethodReturnType.JAVPATH+TestMethodReturnType.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect testMethodReturnType = new ClassExpect(TestMethodReturnType.TESTEDCLASSNAME); + + //methods +// MethodExpect m0 = new MethodExpect("methodReturnType1",null,0); +// m0.addParameter(new VarExpect("a",null)); + + MethodExpect m1 = new MethodExpect("methodReturnType2",new RefType("java.lang.Integer",-1),0); + m1.addReturntype(new RefType("java.lang.Double",-1)); + m1.addReturntype(new RefType("java.lang.Float",-1)); + m1.addReturntype(new RefType("java.lang.Long",-1)); + //m1.addReturntype(new RefType("java.lang.String",-1)); + VarExpect a1 = new VarExpect("a",new RefType("java.lang.Integer",-1)); + VarExpect b1 = new VarExpect("b",new RefType("java.lang.Integer",-1)); + a1.addExpectedType(new RefType("java.lang.Double",-1)); + a1.addExpectedType(new RefType("java.lang.Float",-1)); + a1.addExpectedType(new RefType("java.lang.Long",-1)); + //a1.addExpectedType(new RefType("java.lang.String",-1)); + b1.addExpectedType(new RefType("java.lang.Double",-1)); + b1.addExpectedType(new RefType("java.lang.Float",-1)); + b1.addExpectedType(new RefType("java.lang.Long",-1)); + //b1.addExpectedType(new RefType("java.lang.String",-1)); + m1.addParameter(a1); + m1.addParameter(b1); + + MethodExpect m2 = new MethodExpect("methodReturnType3",new RefType("java.lang.String",-1),0); + m2.addParameter(new VarExpect("a",new RefType("java.lang.String",-1))); + + MethodExpect m3 = new MethodExpect("methodReturnType4",new RefType("java.lang.Integer",-1),0); + m3.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + + +// testMethodReturnType.addMethod(m0); + testMethodReturnType.addMethod(m1); + testMethodReturnType.addMethod(m2); + testMethodReturnType.addMethod(m3); + return new Expectation(testMethodReturnType); + } + + +} diff --git a/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeGeneric.jav b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeGeneric.jav new file mode 100755 index 000000000..c33e753b2 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeGeneric.jav @@ -0,0 +1,15 @@ + +public class TestMethodReturnTypeGeneric { + + testMethodReturnTypeGeneric() { + return new TestMethodReturnTypeGeneric(); + } + + testMethodReturnTypeGeneric2(T a) { + return a; + } + + + + +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative.jav b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative.jav new file mode 100755 index 000000000..10b5f1087 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative.jav @@ -0,0 +1,8 @@ + +public class TestMethodReturnTypeNegative { + + /*returned String, but must be Integer*/ + Integer m1(String a) { + return a; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative.java b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative.java new file mode 100755 index 000000000..2e8590745 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative.java @@ -0,0 +1,42 @@ +package mycompiler.test.notUsedAnymore; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestMethodReturnTypeNegative extends AbstractInferenceTest { + + + private final static String TESTEDCLASSNAME="TestMethodReturnTypeNegative"; + private final static String JAVPATH="test/mycompiler/test/"; + + public TestMethodReturnTypeNegative(String name) { + super(name,TestMethodReturnTypeNegative.JAVPATH+TestMethodReturnTypeNegative.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect testMethodReturnTypeNegative = new ClassExpect(TestMethodReturnTypeNegative.TESTEDCLASSNAME); + + //methods + MethodExpect m1 = new MethodExpect("m1",new RefType("java.lang.Integer",-1)); + m1.addParameter(new VarExpect("a", new RefType("java.lang.String",-1))); + + MethodExpect m2 = new MethodExpect("m2",new RefType("java.lang.Boolean",-1)); + m2.getBlock().addLocalVar(new VarExpect("a",new RefType("java.lang.Boolean",-1))); + + testMethodReturnTypeNegative.addMethod(m1); + testMethodReturnTypeNegative.addMethod(m2); + + + Expectation ret = new Expectation(testMethodReturnTypeNegative); + ret.addException(new Exception()); + return ret; + } + + +} diff --git a/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative2.jav b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative2.jav new file mode 100755 index 000000000..15f21075d --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative2.jav @@ -0,0 +1,11 @@ + +public class TestMethodReturnTypeNegative2 { + + /*not always boolean returned*/ + public m1() { + a; + if (a) { + return a; + } + } +} \ No newline at end of file diff --git a/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative2.java b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative2.java new file mode 100755 index 000000000..63ec83fd1 --- /dev/null +++ b/test/mycompiler/test/notUsedAnymore/TestMethodReturnTypeNegative2.java @@ -0,0 +1,38 @@ +package mycompiler.test.notUsedAnymore; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestMethodReturnTypeNegative2 extends AbstractInferenceTest { + + + private final static String TESTEDCLASSNAME="TestMethodReturnTypeNegative2"; + private final static String JAVPATH="test/mycompiler/test/"; + + public TestMethodReturnTypeNegative2(String name) { + super(name,TestMethodReturnTypeNegative2.JAVPATH+TestMethodReturnTypeNegative2.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect testMethodReturnTypeNegative2 = new ClassExpect(TestMethodReturnTypeNegative2.TESTEDCLASSNAME); + + //methods + MethodExpect m1 = new MethodExpect("m2",new RefType("java.lang.Boolean",-1)); + m1.getBlock().addLocalVar(new VarExpect("a",new RefType("java.lang.Boolean",-1))); + + testMethodReturnTypeNegative2.addMethod(m1); + + + Expectation ret = new Expectation(testMethodReturnTypeNegative2); + ret.addException(new Exception()); + return ret; + } + + +} diff --git a/test/mycompiler/test/operators/AllTestsOperators.java b/test/mycompiler/test/operators/AllTestsOperators.java new file mode 100755 index 000000000..88f2a30cf --- /dev/null +++ b/test/mycompiler/test/operators/AllTestsOperators.java @@ -0,0 +1,22 @@ +package mycompiler.test.operators; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsOperators { + + public static Test suite() { + TestSuite suite = new TestSuite("Test for mycompiler.test.operators"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestOperatorBool.class); + suite.addTestSuite(TestOperatorObjects.class); + suite.addTestSuite(TestOperatorString.class); + suite.addTestSuite(TestOperatorIncrement.class); + suite.addTestSuite(TestOperatorComparison.class); + suite.addTestSuite(TestOperatorArithmetic.class); + suite.addTestSuite(TestOperatorBitwise.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/operators/TestOperatorArithmetic.jav b/test/mycompiler/test/operators/TestOperatorArithmetic.jav new file mode 100755 index 000000000..7c346c58f --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorArithmetic.jav @@ -0,0 +1,40 @@ +public class TestOperatorArithmetic { + + public m1(i,j) { + return i+j; + } + + public m2(i,java.lang.Double j) { + return i-j; + } + + public m3(java.lang.Integer i,j) { + return i*j; + } + + public java.lang.Double m4(i,j) { + return i/j; + } + + public m5(i,j) { + return i%j; + } + + public m6(i) { + return -i; + } + + public m7 (i,j) { + i+=j; + return i; + } + + public m8(i, java.lang.Float j) { + return i/j; + } + + /*public java.lang.Long m9(i, j) { + return i+j; + }*/ + +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorArithmetic.java b/test/mycompiler/test/operators/TestOperatorArithmetic.java new file mode 100755 index 000000000..f250c7dc3 --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorArithmetic.java @@ -0,0 +1,110 @@ +package mycompiler.test.operators; +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** +* 12-04-08 +* @author +* +* checks arithmetic operations +*/ + +public class TestOperatorArithmetic extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestOperatorArithmetic"; + private final static String JAVPATH="test/mycompiler/test/operators/"; + + public TestOperatorArithmetic(String name) { + super(name,TestOperatorArithmetic.JAVPATH+TestOperatorArithmetic.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testOperatorArithmetic = new ClassExpect(TestOperatorArithmetic.TESTEDCLASSNAME); + + //Methods + VarExpect m1_i = new VarExpect("i",new RefType("java.lang.Integer",-1)); + m1_i.setExpectedType(createVectorAllNumberTypes()); + VarExpect m1_j = new VarExpect("j",new RefType("java.lang.Integer",-1)); + m1_j.setExpectedType(createVectorAllNumberTypes()); + MethodExpect m1 = new MethodExpect("m1",new RefType("java.lang.Integer",-1),0); + m1.setReturntypes(createVectorAllNumberTypes()); + m1.addParameter(m1_i); + m1.addParameter(m1_j); + + MethodExpect m2 = new MethodExpect("m2",new RefType("java.lang.Double",-1),0); + m2.addParameter(new VarExpect("i",new RefType("java.lang.Double",-1))); + m2.addParameter(new VarExpect("j",new RefType("java.lang.Double",-1))); + + MethodExpect m3 = new MethodExpect("m3",new RefType("java.lang.Integer",-1),0); + m3.addParameter(new VarExpect("i",new RefType("java.lang.Integer",-1))); + m3.addParameter(new VarExpect("j",new RefType("java.lang.Integer",-1))); + + MethodExpect m4 = new MethodExpect("m4",new RefType("java.lang.Double",-1),0); + m4.addParameter(new VarExpect("i",new RefType("java.lang.Double",-1))); + m4.addParameter(new VarExpect("j",new RefType("java.lang.Double",-1))); + + + VarExpect m5_i = new VarExpect("i",new RefType("java.lang.Integer",-1)); + m5_i.setExpectedType(createVectorAllNumberTypes()); + VarExpect m5_j = new VarExpect("j",new RefType("java.lang.Integer",-1)); + m5_j.setExpectedType(createVectorAllNumberTypes()); + MethodExpect m5 = new MethodExpect("m5",new RefType("java.lang.Integer",-1),0); + m5.setReturntypes(createVectorAllNumberTypes()); + m5.addParameter(m5_i); + m5.addParameter(m5_j); + + MethodExpect m6 = new MethodExpect("m6", new RefType("java.lang.Integer",-1),0); + m6.addParameter(new VarExpect("i", new RefType("java.lang.Integer",-1))); + + VarExpect m7_i = new VarExpect("i",new RefType("java.lang.Integer",-1)); + m7_i.setExpectedType(createVectorAllNumberTypes()); + VarExpect m7_j = new VarExpect("j",new RefType("java.lang.Integer",-1)); + m7_j.setExpectedType(createVectorAllNumberTypes()); + MethodExpect m7 = new MethodExpect("m7",new RefType("java.lang.Integer",-1),0); + m7.setReturntypes(createVectorAllNumberTypes()); + m7.addParameter(m7_i); + m7.addParameter(m7_j); + + VarExpect m8_i = new VarExpect("i",new RefType("java.lang.Float",-1)); + m8_i.setExpectedType(createVectorAllNumberTypes()); + VarExpect m8_j = new VarExpect("j",new RefType("java.lang.Float",-1)); + m8_j.setExpectedType(createVectorAllNumberTypes()); + MethodExpect m8 = new MethodExpect("m8",new RefType("java.lang.Float",-1),0); + m8.setReturntypes(createVectorAllNumberTypes()); + m8.addParameter(m8_i); + m8.addParameter(m8_j); + + VarExpect m9_i = new VarExpect("i",new RefType("java.lang.Long",-1)); + m9_i.setExpectedType(createVectorAllNumberTypes()); + VarExpect m9_j = new VarExpect("j",new RefType("java.lang.Long",-1)); + m9_j.setExpectedType(createVectorAllNumberTypes()); + MethodExpect m9 = new MethodExpect("m9",new RefType("java.lang.Long",-1),0); + m9.setReturntypes(createVectorAllNumberTypes()); + m9.addParameter(m9_i); + m9.addParameter(m9_j); + + + testOperatorArithmetic.addMethod(m1); + testOperatorArithmetic.addMethod(m2); + testOperatorArithmetic.addMethod(m3); + testOperatorArithmetic.addMethod(m4); + testOperatorArithmetic.addMethod(m5); + testOperatorArithmetic.addMethod(m6); + testOperatorArithmetic.addMethod(m7); + testOperatorArithmetic.addMethod(m8); + //testOperatorArithmetic.addMethod(m9); +// + return new Expectation(testOperatorArithmetic); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorBitwise.jav b/test/mycompiler/test/operators/TestOperatorBitwise.jav new file mode 100755 index 000000000..7c7026cc0 --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorBitwise.jav @@ -0,0 +1,45 @@ +public class TestOperatorBitwise { + + public m1(a,b) { + return a & b; + } + + public m2(a,b) { + return a ^ b; + } + + public m3(a,b) { + return a | b; + } + + public m4(Integer a, b) { + return a & b; + } + + public m5(a, Long b) { + return a & b; + } + + public Integer m6(a,b) { + return a & b; + } + + /* bit-shift not accepted by parser + + public m7(a,b) { + return x << y; + } + + public m8(a,b) { + return x >> y; + } + + public m9(a,b) { + return x >>> y; + } + + public m10(a) { + return ~a; + } + */ +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorBitwise.java b/test/mycompiler/test/operators/TestOperatorBitwise.java new file mode 100755 index 000000000..dc13f9c03 --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorBitwise.java @@ -0,0 +1,129 @@ +package mycompiler.test.operators; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.GenericTypeVarExpect; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** +* 29-05-08 +* @author +* +* checks bit operators +*/ + +public class TestOperatorBitwise extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestOperatorBitwise"; + private final static String JAVPATH="test/mycompiler/test/operators/"; + + public TestOperatorBitwise(String name) { + super(name,TestOperatorBitwise.JAVPATH+TestOperatorBitwise.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testOperatorBitwise = new ClassExpect(TestOperatorBitwise.TESTEDCLASSNAME); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("java.lang.Integer",-1)); + m1.addReturntype(new RefType("java.lang.Long",-1)); + VarExpect m1a = new VarExpect("a",new RefType("java.lang.Integer",-1)); + m1a.addExpectedType(new RefType("java.lang.Byte",-1)); + m1a.addExpectedType(new RefType("java.lang.Short",-1)); + m1a.addExpectedType(new RefType("java.lang.Character",-1)); + m1a.addExpectedType(new RefType("java.lang.Long",-1)); + VarExpect m1b = new VarExpect("b",new RefType("java.lang.Integer",-1)); + m1b.addExpectedType(new RefType("java.lang.Byte",-1)); + m1b.addExpectedType(new RefType("java.lang.Short",-1)); + m1b.addExpectedType(new RefType("java.lang.Character",-1)); + m1b.addExpectedType(new RefType("java.lang.Long",-1)); + m1.addParameter(m1a); + m1.addParameter(m1b); + + + MethodExpect m2 = new MethodExpect("m2",new RefType("java.lang.Integer",-1)); + m2.addReturntype(new RefType("java.lang.Long",-1)); + VarExpect m2a = new VarExpect("a",new RefType("java.lang.Integer",-1)); + m2a.addExpectedType(new RefType("java.lang.Byte",-1)); + m2a.addExpectedType(new RefType("java.lang.Short",-1)); + m2a.addExpectedType(new RefType("java.lang.Character",-1)); + m2a.addExpectedType(new RefType("java.lang.Long",-1)); + VarExpect m2b = new VarExpect("b",new RefType("java.lang.Integer",-1)); + m2b.addExpectedType(new RefType("java.lang.Byte",-1)); + m2b.addExpectedType(new RefType("java.lang.Short",-1)); + m2b.addExpectedType(new RefType("java.lang.Character",-1)); + m2b.addExpectedType(new RefType("java.lang.Long",-1)); + m2.addParameter(m2a); + m2.addParameter(m2b); + + MethodExpect m3 = new MethodExpect("m3",new RefType("java.lang.Integer",-1)); + m3.addReturntype(new RefType("java.lang.Long",-1)); + VarExpect m3a = new VarExpect("a",new RefType("java.lang.Integer",-1)); + m3a.addExpectedType(new RefType("java.lang.Byte",-1)); + m3a.addExpectedType(new RefType("java.lang.Short",-1)); + m3a.addExpectedType(new RefType("java.lang.Character",-1)); + m3a.addExpectedType(new RefType("java.lang.Long",-1)); + VarExpect m3b = new VarExpect("b",new RefType("java.lang.Integer",-1)); + m3b.addExpectedType(new RefType("java.lang.Byte",-1)); + m3b.addExpectedType(new RefType("java.lang.Short",-1)); + m3b.addExpectedType(new RefType("java.lang.Character",-1)); + m3b.addExpectedType(new RefType("java.lang.Long",-1)); + m3.addParameter(m3a); + m3.addParameter(m3b); + + MethodExpect m4 = new MethodExpect("m4",new RefType("java.lang.Integer",-1)); + m4.addReturntype(new RefType("java.lang.Long",-1)); + VarExpect m4a = new VarExpect("a",new RefType("java.lang.Integer",-1)); + VarExpect m4b = new VarExpect("b",new RefType("java.lang.Integer",-1)); + m4b.addExpectedType(new RefType("java.lang.Byte",-1)); + m4b.addExpectedType(new RefType("java.lang.Short",-1)); + m4b.addExpectedType(new RefType("java.lang.Character",-1)); + m4b.addExpectedType(new RefType("java.lang.Long",-1)); + m4.addParameter(m4a); + m4.addParameter(m4b); + + MethodExpect m5 = new MethodExpect("m5",new RefType("java.lang.Long",-1)); + VarExpect m5a = new VarExpect("a",new RefType("java.lang.Integer",-1)); + m5a.addExpectedType(new RefType("java.lang.Byte",-1)); + m5a.addExpectedType(new RefType("java.lang.Short",-1)); + m5a.addExpectedType(new RefType("java.lang.Character",-1)); + m5a.addExpectedType(new RefType("java.lang.Long",-1)); + VarExpect m5b = new VarExpect("b",new RefType("java.lang.Long",-1)); + m5.addParameter(m5a); + m5.addParameter(m5b); + + MethodExpect m6 = new MethodExpect("m6",new RefType("java.lang.Integer",-1)); + VarExpect m6a = new VarExpect("a",new RefType("java.lang.Integer",-1)); + m6a.addExpectedType(new RefType("java.lang.Byte",-1)); + m6a.addExpectedType(new RefType("java.lang.Short",-1)); + m6a.addExpectedType(new RefType("java.lang.Character",-1)); + VarExpect m6b = new VarExpect("b",new RefType("java.lang.Integer",-1)); + m6b.addExpectedType(new RefType("java.lang.Byte",-1)); + m6b.addExpectedType(new RefType("java.lang.Short",-1)); + m6b.addExpectedType(new RefType("java.lang.Character",-1)); + m6.addParameter(m6a); + m6.addParameter(m6b); + + + + + + + testOperatorBitwise.addMethod(m1); + testOperatorBitwise.addMethod(m2); + testOperatorBitwise.addMethod(m3); + testOperatorBitwise.addMethod(m4); + testOperatorBitwise.addMethod(m5); + testOperatorBitwise.addMethod(m6); + + + return new Expectation(testOperatorBitwise); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorBool.jav b/test/mycompiler/test/operators/TestOperatorBool.jav new file mode 100755 index 000000000..33c002b12 --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorBool.jav @@ -0,0 +1,19 @@ +public class TestOperatorBool { + + public m1(a,b) { + return a && b; + } + + public m2(a,b) { + return a || b; + } + + public m3(a) { + return !a; + } + + public m4( a, b) { + return a==b; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorBool.java b/test/mycompiler/test/operators/TestOperatorBool.java new file mode 100755 index 000000000..794220229 --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorBool.java @@ -0,0 +1,58 @@ +package mycompiler.test.operators; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.test.expectationTypes.GenericTypeVarExpect; + + +/** +* 12-04-08 +* @author +* +* checks operators requiring boolean types +*/ + +public class TestOperatorBool extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestOperatorBool"; + private final static String JAVPATH="test/mycompiler/test/operators/"; + + public TestOperatorBool(String name) { + super(name,TestOperatorBool.JAVPATH+TestOperatorBool.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testOperatorBool = new ClassExpect(TestOperatorBool.TESTEDCLASSNAME); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("java.lang.Boolean",-1),0); + m1.addParameter(new VarExpect("a",new RefType("java.lang.Boolean",-1))); + m1.addParameter(new VarExpect("b",new RefType("java.lang.Boolean",-1))); + + MethodExpect m2 = new MethodExpect("m2",new RefType("java.lang.Boolean",-1),0); + m2.addParameter(new VarExpect("a",new RefType("java.lang.Boolean",-1))); + m2.addParameter(new VarExpect("b",new RefType("java.lang.Boolean",-1))); + + MethodExpect m3 = new MethodExpect("m3",new RefType("java.lang.Boolean",-1),0); + m3.addParameter(new VarExpect("a",new RefType("java.lang.Boolean",-1))); + + MethodExpect m4 = new MethodExpect("m4",new RefType("java.lang.Boolean",-1),0); + m4.addParameter(new VarExpect("a",new GenericTypeVarExpect("a"))); + m4.addParameter(new VarExpect("b",new GenericTypeVarExpect("b"))); + + testOperatorBool.addMethod(m1); + testOperatorBool.addMethod(m2); + testOperatorBool.addMethod(m3); + testOperatorBool.addMethod(m4); + + + return new Expectation(testOperatorBool); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorComparison.jav b/test/mycompiler/test/operators/TestOperatorComparison.jav new file mode 100755 index 000000000..62aaee58f --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorComparison.jav @@ -0,0 +1,22 @@ +public class TestOperatorComparison { + +/* public m1(a,b) { + return a < b; + } + + public m2(a, b) { + return a >= b; + } + */ + public m3(a, b) { + return a==b; + } + + public java.lang.Boolean m4(a,b) { + return a!=b; + } + + public m5(Integer a, b) { + return a createVectorAllDiscreteNumberTypes() { + Vector ret = new Vector(); + ret.add(new RefType("java.lang.Integer",-1)); + // ret.add(new RefType("java.lang.Long",-1)); + // ret.add(new RefType("java.lang.Short",-1)); + // ret.add(new RefType("java.lang.Byte",-1)); + + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorIncrement.jav b/test/mycompiler/test/operators/TestOperatorIncrement.jav new file mode 100755 index 000000000..dd497c864 --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorIncrement.jav @@ -0,0 +1,11 @@ + +public class TestOperatorIncrement { + + public void m(i,j,k,l) { + i++; + j--; + ++k; + --l; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorIncrement.java b/test/mycompiler/test/operators/TestOperatorIncrement.java new file mode 100755 index 000000000..2910afd6b --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorIncrement.java @@ -0,0 +1,65 @@ +package mycompiler.test.operators; +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** +* 12-04-08 +* @author +* checks correct identification of types which the increment operator can be used for +* +*/ + +public class TestOperatorIncrement extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestOperatorIncrement"; + private final static String JAVPATH="test/mycompiler/test/operators/"; + + public TestOperatorIncrement(String name) { + super(name,TestOperatorIncrement.JAVPATH+TestOperatorIncrement.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testOperatorIncrement = new ClassExpect(TestOperatorIncrement.TESTEDCLASSNAME); + + //Methods + VarExpect m1_i = new VarExpect("i",new RefType("java.lang.Integer",-1)); + m1_i.setExpectedType(createVectorAllDiscreteNumberTypes()); + VarExpect m1_j = new VarExpect("j",new RefType("java.lang.Integer",-1)); + m1_j.setExpectedType(createVectorAllDiscreteNumberTypes()); + VarExpect m1_k = new VarExpect("k",new RefType("java.lang.Integer",-1)); + m1_j.setExpectedType(createVectorAllDiscreteNumberTypes()); + VarExpect m1_l = new VarExpect("l",new RefType("java.lang.Integer",-1)); + m1_j.setExpectedType(createVectorAllDiscreteNumberTypes()); + + MethodExpect m1 = new MethodExpect("m",new RefType("void",-1),0); + m1.addParameter(m1_i); + m1.addParameter(m1_j); + m1.addParameter(m1_k); + m1.addParameter(m1_l); + + testOperatorIncrement.addMethod(m1); + + return new Expectation(testOperatorIncrement); + } + + private Vector createVectorAllDiscreteNumberTypes() { + Vector ret = new Vector(); + ret.add(new RefType("java.lang.Integer",-1)); + // ret.add(new RefType("java.lang.Long",-1)); + // ret.add(new RefType("java.lang.Short",-1)); + // ret.add(new RefType("java.lang.Byte",-1)); + + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorObjects.jav b/test/mycompiler/test/operators/TestOperatorObjects.jav new file mode 100755 index 000000000..f9564dc01 --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorObjects.jav @@ -0,0 +1,18 @@ +class A { + + public java.lang.Integer m(a) { + return a; + } + +} + +public class TestOperatorObjects { + + public static void main() { + b; + b=new A(); + c; + c=b.m(3); + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorObjects.java b/test/mycompiler/test/operators/TestOperatorObjects.java new file mode 100755 index 000000000..7d5bb1c64 --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorObjects.java @@ -0,0 +1,48 @@ +package mycompiler.test.operators; +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** +* 12-04-08 +* @author +* +* checks object usage +*/ + +public class TestOperatorObjects extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestOperatorObjects"; + private final static String JAVPATH="test/mycompiler/test/operators/"; + + public TestOperatorObjects(String name) { + super(name,TestOperatorObjects.JAVPATH+TestOperatorObjects.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect a = new ClassExpect("A"); + ClassExpect testOperatorObjects = new ClassExpect(TestOperatorObjects.TESTEDCLASSNAME); + + //Methods + MethodExpect m = new MethodExpect("m",new RefType("java.lang.Integer",-1),0); + m.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + MethodExpect main = new MethodExpect("main",new RefType("void",-1),0); + main.getBlock().addLocalVar(new VarExpect("b",new RefType("A",-1))); + main.getBlock().addLocalVar(new VarExpect("c",new RefType("java.lang.Integer",-1))); + + + testOperatorObjects.addMethod(main); + a.addMethod(m); + + Expectation ret = new Expectation(testOperatorObjects); + ret.addClass(a); + return ret; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorString.jav b/test/mycompiler/test/operators/TestOperatorString.jav new file mode 100755 index 000000000..a209da133 --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorString.jav @@ -0,0 +1,11 @@ +public class TestOperatorString { + + public m() { + a; + b; + a="abc"; + b="def"; + return a+b; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/operators/TestOperatorString.java b/test/mycompiler/test/operators/TestOperatorString.java new file mode 100755 index 000000000..a1aa6f7ea --- /dev/null +++ b/test/mycompiler/test/operators/TestOperatorString.java @@ -0,0 +1,41 @@ +package mycompiler.test.operators; +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** +* 12-04-08 +* @author +* +* checks whether plus operator can be used on strings +*/ + +public class TestOperatorString extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestOperatorString"; + private final static String JAVPATH="test/mycompiler/test/operators/"; + + public TestOperatorString(String name) { + super(name,TestOperatorString.JAVPATH+TestOperatorString.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + ClassExpect testOperatorString = new ClassExpect(TestOperatorString.TESTEDCLASSNAME); + + //Methods + MethodExpect m = new MethodExpect("m",new RefType("java.lang.String",-1),0); + m.getBlock().addLocalVar(new VarExpect("a",new RefType("java.lang.String",-1))); + m.getBlock().addLocalVar(new VarExpect("b",new RefType("java.lang.String",-1))); + + testOperatorString.addMethod(m); + + return new Expectation(testOperatorString); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/AllTestsPrimitiveTypes.java b/test/mycompiler/test/primitiveTypes/AllTestsPrimitiveTypes.java new file mode 100755 index 000000000..9f14501ae --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/AllTestsPrimitiveTypes.java @@ -0,0 +1,25 @@ +package mycompiler.test.primitiveTypes; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsPrimitiveTypes { + + public static Test suite() { + TestSuite suite = new TestSuite( + "Test for mycompiler.test.primitiveTypes"); + //$JUnit-BEGIN$ + suite.addTestSuite(StringTest.class); + suite.addTestSuite(IntegerTest.class); + suite.addTestSuite(FloatTest.class); + suite.addTestSuite(BooleanTest.class); + suite.addTestSuite(LongTest.class); + suite.addTestSuite(ByteTest.class); + suite.addTestSuite(TestSimpleTypes.class); + suite.addTestSuite(DoubleTest.class); + suite.addTestSuite(CharTest.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/primitiveTypes/BooleanTest.jav b/test/mycompiler/test/primitiveTypes/BooleanTest.jav new file mode 100755 index 000000000..f04ef412e --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/BooleanTest.jav @@ -0,0 +1,5 @@ +class BooleanTest{ + void booleanTest(b){ + b = true; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/BooleanTest.java b/test/mycompiler/test/primitiveTypes/BooleanTest.java new file mode 100755 index 000000000..bc99f4ca2 --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/BooleanTest.java @@ -0,0 +1,38 @@ +package mycompiler.test.primitiveTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** +* 02-04-08 +* @author +* +* check type boolean +*/ +public class BooleanTest extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="BooleanTest"; + private final static String JAVPATH="test/mycompiler/test/primitiveTypes/"; + + public BooleanTest(String name) { + super(name,BooleanTest.JAVPATH+BooleanTest.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(BooleanTest.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("booleanTest",new RefType("void",-1),0); + m0.addParameter(new VarExpect("b",new RefType("java.lang.Boolean",-1))); + + overloading.addMethod(m0); + + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/primitiveTypes/ByteTest.jav b/test/mycompiler/test/primitiveTypes/ByteTest.jav new file mode 100755 index 000000000..156cf51df --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/ByteTest.jav @@ -0,0 +1,6 @@ +class ByteTest{ + void byteTest(b){ + byte myByte = -1; + b = myByte; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/ByteTest.java b/test/mycompiler/test/primitiveTypes/ByteTest.java new file mode 100755 index 000000000..4050ae397 --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/ByteTest.java @@ -0,0 +1,45 @@ +package mycompiler.test.primitiveTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.BlockExpect; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** +* 02-04-08 +* @author +* +* check type byte +*/ +public class ByteTest extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="ByteTest"; + private final static String JAVPATH="test/mycompiler/test/primitiveTypes/"; + + public ByteTest(String name) { + super(name,ByteTest.JAVPATH+ByteTest.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(ByteTest.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("byteTest",new RefType("void",-1),0); + m0.addParameter(new VarExpect("b",new RefType("byte",-1))); + + BlockExpect b0 = new BlockExpect(null,"1"); + VarExpect v0 = new VarExpect("myByte",new RefType("byte",-1)); + b0.addLocalVar(v0); + + m0.setBlock(b0); + + overloading.addMethod(m0); + + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/primitiveTypes/CharTest.jav b/test/mycompiler/test/primitiveTypes/CharTest.jav new file mode 100755 index 000000000..7c75f6755 --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/CharTest.jav @@ -0,0 +1,5 @@ +class CharTest{ + void character(c){ + c = 'c'; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/CharTest.java b/test/mycompiler/test/primitiveTypes/CharTest.java new file mode 100755 index 000000000..53cc277d1 --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/CharTest.java @@ -0,0 +1,38 @@ +package mycompiler.test.primitiveTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** +* 02-04-08 +* @author +* +* chck type character +*/ +public class CharTest extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="CharTest"; + private final static String JAVPATH="test/mycompiler/test/primitiveTypes/"; + + public CharTest(String name) { + super(name,CharTest.JAVPATH+CharTest.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(CharTest.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("character",new RefType("void",-1),0); + m0.addParameter(new VarExpect("c",new RefType("java.lang.Character",-1))); + + overloading.addMethod(m0); + + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/primitiveTypes/DoubleTest.jav b/test/mycompiler/test/primitiveTypes/DoubleTest.jav new file mode 100755 index 000000000..a13652f38 --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/DoubleTest.jav @@ -0,0 +1,5 @@ +class DoubleTest{ + void doublePrecision(d){ + d = 1.0; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/DoubleTest.java b/test/mycompiler/test/primitiveTypes/DoubleTest.java new file mode 100755 index 000000000..367cc791a --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/DoubleTest.java @@ -0,0 +1,38 @@ +package mycompiler.test.primitiveTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** +* 02-04-08 +* @author +* +* check type double +*/ +public class DoubleTest extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="DoubleTest"; + private final static String JAVPATH="test/mycompiler/test/primitiveTypes/"; + + public DoubleTest(String name) { + super(name,DoubleTest.JAVPATH+DoubleTest.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(DoubleTest.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("doublePrecision",new RefType("void",-1),0); + m0.addParameter(new VarExpect("d",new RefType("java.lang.Double",-1))); + + overloading.addMethod(m0); + + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/primitiveTypes/FloatTest.jav b/test/mycompiler/test/primitiveTypes/FloatTest.jav new file mode 100755 index 000000000..054e946ed --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/FloatTest.jav @@ -0,0 +1,5 @@ +class FloatTest { + void floatingPoint(f) { + f = 5f; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/FloatTest.java b/test/mycompiler/test/primitiveTypes/FloatTest.java new file mode 100755 index 000000000..ece240eea --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/FloatTest.java @@ -0,0 +1,38 @@ +package mycompiler.test.primitiveTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** +* 02-04-08 +* @author +* +* check type Float +*/ +public class FloatTest extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="FloatTest"; + private final static String JAVPATH="test/mycompiler/test/primitiveTypes/"; + + public FloatTest(String name) { + super(name,FloatTest.JAVPATH+FloatTest.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(FloatTest.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("floatingPoint",new RefType("void",-1),0); + m0.addParameter(new VarExpect("f",new RefType("java.lang.Float",-1))); + + overloading.addMethod(m0); + + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/primitiveTypes/IntegerTest.jav b/test/mycompiler/test/primitiveTypes/IntegerTest.jav new file mode 100755 index 000000000..5b6bc3d2d --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/IntegerTest.jav @@ -0,0 +1,5 @@ +class IntegerTest{ + void integer(i){ + i = 1; /* koennte vielleicht auch short/byte/char sein .. */ + } +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/IntegerTest.java b/test/mycompiler/test/primitiveTypes/IntegerTest.java new file mode 100755 index 000000000..fedbde4aa --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/IntegerTest.java @@ -0,0 +1,43 @@ +package mycompiler.test.primitiveTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** +* 02-04-08 +* @author +* +* check type Integer +*/ +public class IntegerTest extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="IntegerTest"; + private final static String JAVPATH="test/mycompiler/test/primitiveTypes/"; + + public IntegerTest(String name) { + super(name,IntegerTest.JAVPATH+IntegerTest.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(IntegerTest.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("integer",new RefType("void",-1),0); + VarExpect i_type = new VarExpect("i", new RefType("java.lang.Integer",-1)); +// i_type.addExpectedType(new RefType("java.lang.Short",-1)); +// i_type.addExpectedType(new RefType("java.lang.Character",-1)); +// i_type.addExpectedType(new RefType("java.lang.Long",-1)); +// i_type.addExpectedType(new RefType("java.lang.Byte",-1)); + m0.addParameter(i_type); + + overloading.addMethod(m0); + + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/primitiveTypes/LongTest.jav b/test/mycompiler/test/primitiveTypes/LongTest.jav new file mode 100755 index 000000000..4bc6590a1 --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/LongTest.jav @@ -0,0 +1,5 @@ +class LongTest{ + void longTest(l){ + l = 4L; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/LongTest.java b/test/mycompiler/test/primitiveTypes/LongTest.java new file mode 100755 index 000000000..ddb1b41db --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/LongTest.java @@ -0,0 +1,38 @@ +package mycompiler.test.primitiveTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** +* 02-04-08 +* @author +* +* check type Long +*/ +public class LongTest extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="LongTest"; + private final static String JAVPATH="test/mycompiler/test/primitiveTypes/"; + + public LongTest(String name) { + super(name,LongTest.JAVPATH+LongTest.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(LongTest.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("longTest",new RefType("void",-1),0); + m0.addParameter(new VarExpect("l",new RefType("java.lang.Long",-1))); + + overloading.addMethod(m0); + + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/primitiveTypes/StringTest.jav b/test/mycompiler/test/primitiveTypes/StringTest.jav new file mode 100755 index 000000000..72c8f75d2 --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/StringTest.jav @@ -0,0 +1,5 @@ +class StringTest{ + void string(s){ + s = "String"; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/StringTest.java b/test/mycompiler/test/primitiveTypes/StringTest.java new file mode 100755 index 000000000..01f64cbcc --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/StringTest.java @@ -0,0 +1,38 @@ +package mycompiler.test.primitiveTypes; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +/** +* 02-04-08 +* @author +* +* check type String +*/ +public class StringTest extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="StringTest"; + private final static String JAVPATH="test/mycompiler/test/primitiveTypes/"; + + public StringTest(String name) { + super(name,StringTest.JAVPATH+StringTest.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect overloading = new ClassExpect(StringTest.TESTEDCLASSNAME); + //methods + + MethodExpect m0 = new MethodExpect("string",new RefType("void",-1),0); + m0.addParameter(new VarExpect("s",new RefType("java.lang.String",-1))); + + overloading.addMethod(m0); + + + return new Expectation(overloading); + } + +} diff --git a/test/mycompiler/test/primitiveTypes/TestSimpleTypes.jav b/test/mycompiler/test/primitiveTypes/TestSimpleTypes.jav new file mode 100755 index 000000000..9ddb95262 --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/TestSimpleTypes.jav @@ -0,0 +1,22 @@ + +class TestSimpleTypes{ + + public m1(int a) { + } + + public int m2(int a) + { + return a; + } + + public m3(char a) {} + +/* not implemented? + public m4(float a) {} + public m5(double a) {}*/ + + /* cast from Integer to int does not work + public int m6() { + return 3; + }*/ +} \ No newline at end of file diff --git a/test/mycompiler/test/primitiveTypes/TestSimpleTypes.java b/test/mycompiler/test/primitiveTypes/TestSimpleTypes.java new file mode 100755 index 000000000..839c51e6a --- /dev/null +++ b/test/mycompiler/test/primitiveTypes/TestSimpleTypes.java @@ -0,0 +1,53 @@ +package mycompiler.test.primitiveTypes; + +import mycompiler.mytype.IntegerType; +import mycompiler.mytype.CharacterType; +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 01-04-08 + * @author + * + * This test verifies identification of a simple method with returntype void + * + */ + +public class TestSimpleTypes extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestSimpleTypes"; + private final static String JAVPATH="test/mycompiler/test/primitiveTypes/"; + + public TestSimpleTypes(String name) { + super(name,TestSimpleTypes.JAVPATH+TestSimpleTypes.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + // Classes + ClassExpect testSimpleType = new ClassExpect(TestSimpleTypes.TESTEDCLASSNAME); + + //Methods + MethodExpect m1 = new MethodExpect("m1",new RefType("void",-1),0); + m1.addParameter(new VarExpect("a",new IntegerType())); + MethodExpect m2 = new MethodExpect("m2",new IntegerType(),0); + m2.addParameter(new VarExpect("a",new IntegerType())); + MethodExpect m3 = new MethodExpect("m3",new RefType("void",-1),0); + m3.addParameter(new VarExpect("a",new CharacterType())); +// MethodExpect m4 = new MethodExpect("m4",new RefType("void",-1),0); +// m4.addParameter(new VarExpect("a",new FloatType())); +// MethodExpect m5 = new MethodExpect("m5",new RefType("void",-1),0); +// m5.addParameter(new VarExpect("a",new DoubleType())); + + + testSimpleType.addMethod(m1); + testSimpleType.addMethod(m2); + testSimpleType.addMethod(m3); + return new Expectation(testSimpleType); + } +} diff --git a/test/mycompiler/test/trivial/AllTestsTrivial.java b/test/mycompiler/test/trivial/AllTestsTrivial.java new file mode 100755 index 000000000..d0400368b --- /dev/null +++ b/test/mycompiler/test/trivial/AllTestsTrivial.java @@ -0,0 +1,30 @@ +package mycompiler.test.trivial; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTestsTrivial { + + public static Test suite() { + TestSuite suite = new TestSuite("Test for mycompiler.test.trivial"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestInterfaceEmpty.class); + suite.addTestSuite(TestClassMember.class); + suite.addTestSuite(TestClassMemberAssignment.class); + suite.addTestSuite(TestClassEmptyGenerics.class); + suite.addTestSuite(TestConstants.class); + suite.addTestSuite(TestConstructor.class); + suite.addTestSuite(TestInterfaceMethod.class); + suite.addTestSuite(TestClassEmpty.class); + suite.addTestSuite(TestMethodEmptyParameterGenericExtends.class); + suite.addTestSuite(TestConstructorNegative.class); + suite.addTestSuite(TestMethodEmptyParameter.class); + suite.addTestSuite(TestMethodEmptyGeneric.class); + suite.addTestSuite(TestInterfaceNotInferenced.class); + suite.addTestSuite(TestMethodEmpty.class); + suite.addTestSuite(TestInterfaceMember.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/test/mycompiler/test/trivial/TestClassEmpty.jav b/test/mycompiler/test/trivial/TestClassEmpty.jav new file mode 100755 index 000000000..d7f473a06 --- /dev/null +++ b/test/mycompiler/test/trivial/TestClassEmpty.jav @@ -0,0 +1,3 @@ + +public class TestClassEmpty { +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestClassEmpty.java b/test/mycompiler/test/trivial/TestClassEmpty.java new file mode 100755 index 000000000..f7129f960 --- /dev/null +++ b/test/mycompiler/test/trivial/TestClassEmpty.java @@ -0,0 +1,34 @@ +package mycompiler.test.trivial; + +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; + + +/** + * 01-04-08 + * @author + * + * This tests verifies correct detection of an empty class. + * + */ + +public class TestClassEmpty extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestClassEmpty"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestClassEmpty(String name) { + super(name,TestClassEmpty.JAVPATH+TestClassEmpty.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + //classes + ClassExpect testEmptyClass = new ClassExpect(TestClassEmpty.TESTEDCLASSNAME); + + return new Expectation(testEmptyClass); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestClassEmptyGenerics.jav b/test/mycompiler/test/trivial/TestClassEmptyGenerics.jav new file mode 100755 index 000000000..bb072d4b8 --- /dev/null +++ b/test/mycompiler/test/trivial/TestClassEmptyGenerics.jav @@ -0,0 +1,4 @@ + +public class TestClassEmptyGenerics { + +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestClassEmptyGenerics.java b/test/mycompiler/test/trivial/TestClassEmptyGenerics.java new file mode 100755 index 000000000..4c24c3817 --- /dev/null +++ b/test/mycompiler/test/trivial/TestClassEmptyGenerics.java @@ -0,0 +1,36 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.GenericTypeVar; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; + +/** + * 01-04-08 + * @author + * + * This tests verifies correct identification of a generic class. + * + */ + +public class TestClassEmptyGenerics extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestClassEmptyGenerics"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestClassEmptyGenerics(String name) { + super(name,TestClassEmptyGenerics.JAVPATH+TestClassEmptyGenerics.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //Classes + ClassExpect testEmptyClassGenerics = new ClassExpect(TestClassEmptyGenerics.TESTEDCLASSNAME); + testEmptyClassGenerics.addGeneric(new GenericTypeVar("E",-1)); + testEmptyClassGenerics.addGeneric(new GenericTypeVar("F",-1)); + + //Expectation + return new Expectation(testEmptyClassGenerics); + } +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestClassMember.jav b/test/mycompiler/test/trivial/TestClassMember.jav new file mode 100755 index 000000000..89a4b51dc --- /dev/null +++ b/test/mycompiler/test/trivial/TestClassMember.jav @@ -0,0 +1,6 @@ +import java.util.Vector; +public class TestClassMember { + + Integer member; + Vector member2; +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestClassMember.java b/test/mycompiler/test/trivial/TestClassMember.java new file mode 100755 index 000000000..7d3ee1cc1 --- /dev/null +++ b/test/mycompiler/test/trivial/TestClassMember.java @@ -0,0 +1,45 @@ +package mycompiler.test.trivial; + +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 01-04-08 + * @author + * + * This test verifies correct detection of a member variable. + */ +public class TestClassMember extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestClassMember"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestClassMember(String name) { + super(name,TestClassMember.JAVPATH+TestClassMember.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + //class--- TestClassMember + ClassExpect testClassMember = new ClassExpect(TestClassMember.TESTEDCLASSNAME); + //member + VarExpect member = new VarExpect("member",new RefType("java.lang.Integer",-1)); + Vector param = new Vector(); + param.add(new RefType("java.lang.String",-1)); + RefType member2Type = new RefType("java.util.Vector",param,-1); + VarExpect member2 = new VarExpect("member2",member2Type); + testClassMember.addMember(member); + testClassMember.addMember(member2); + + //Expectation + return new Expectation(testClassMember); + } + +} diff --git a/test/mycompiler/test/trivial/TestClassMemberAssignment.jav b/test/mycompiler/test/trivial/TestClassMemberAssignment.jav new file mode 100755 index 000000000..771ea288a --- /dev/null +++ b/test/mycompiler/test/trivial/TestClassMemberAssignment.jav @@ -0,0 +1,22 @@ + +public class TestClassMemberAssignment { + + Integer member; + + public m1() { + member=1; + } + + public m2() { + this.member=2; + } + + public m3(a) { + member=a; + } + + public void m(a) { + this.a=a; + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestClassMemberAssignment.java b/test/mycompiler/test/trivial/TestClassMemberAssignment.java new file mode 100755 index 000000000..ea3da679a --- /dev/null +++ b/test/mycompiler/test/trivial/TestClassMemberAssignment.java @@ -0,0 +1,53 @@ +package mycompiler.test.trivial; + +import java.util.Vector; + +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 18-04-08 + * @author + * + * This test verifies correct member assignments. + */ +public class TestClassMemberAssignment extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestClassMemberAssignment"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestClassMemberAssignment(String name) { + super(name,TestClassMemberAssignment.JAVPATH+TestClassMemberAssignment.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + //class--- TestClassMemberAssignment + ClassExpect testClassMemberAssignment = new ClassExpect(TestClassMemberAssignment.TESTEDCLASSNAME); + //member + VarExpect member = new VarExpect("member",new RefType("java.lang.Integer",-1)); + testClassMemberAssignment.addMember(member); + //methods + MethodExpect m1 = new MethodExpect("m1", new RefType("void",-1)); + MethodExpect m2 = new MethodExpect("m2", new RefType("void",-1)); + MethodExpect m3 = new MethodExpect("m3", new RefType("void",-1)); + m3.addParameter(new VarExpect("a", new RefType("java.lang.Integer",-1))); + MethodExpect m4 = new MethodExpect("m3", new RefType("void",-1)); + m3.addParameter(new VarExpect("a", new RefType("java.lang.Integer",-1))); + + testClassMemberAssignment.addMethod(m1); + testClassMemberAssignment.addMethod(m2); + testClassMemberAssignment.addMethod(m3); + testClassMemberAssignment.addMethod(m4); + + //Expectation + return new Expectation(testClassMemberAssignment); + } + +} diff --git a/test/mycompiler/test/trivial/TestConstants.jav b/test/mycompiler/test/trivial/TestConstants.jav new file mode 100755 index 000000000..f9d293ac5 --- /dev/null +++ b/test/mycompiler/test/trivial/TestConstants.jav @@ -0,0 +1,6 @@ +public class TestConstants { + public final static Boolean B = true; + public final static Integer I = 1; + public final static Character C = 'A'; + public final static String S = "Hello World!"; +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestConstants.java b/test/mycompiler/test/trivial/TestConstants.java new file mode 100755 index 000000000..9170c3b7b --- /dev/null +++ b/test/mycompiler/test/trivial/TestConstants.java @@ -0,0 +1,39 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 18-04-08 + * @author + * + * this test checks correct detection of constants as members + */ +public class TestConstants extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestConstants"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestConstants(String name) { + super(name,TestConstants.JAVPATH+TestConstants.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + //class--- TestConstants + ClassExpect testConstants = new ClassExpect(TestConstants.TESTEDCLASSNAME); + //member + testConstants.addMember(new VarExpect("B",new RefType("java.lang.Boolean",-1))); + testConstants.addMember(new VarExpect("I",new RefType("java.lang.Integer",-1))); + testConstants.addMember(new VarExpect("C",new RefType("java.lang.Character",-1))); + testConstants.addMember(new VarExpect("S",new RefType("java.lang.String",-1))); + + //Expectation + return new Expectation(testConstants); + } + +} diff --git a/test/mycompiler/test/trivial/TestConstructor.jav b/test/mycompiler/test/trivial/TestConstructor.jav new file mode 100755 index 000000000..f07566b45 --- /dev/null +++ b/test/mycompiler/test/trivial/TestConstructor.jav @@ -0,0 +1,20 @@ +import java.util.Stack; + +public class TestConstructor { + Integer i; + Stack s; + + public TestConstructor() { + i=3; + s=new Stack(); + } + + public TestConstructor(a) { + a=4; + } + + public TestConstructor(java.lang.Integer a, Stack b) { + i=a; + s=b; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestConstructor.java b/test/mycompiler/test/trivial/TestConstructor.java new file mode 100755 index 000000000..7e25ddf11 --- /dev/null +++ b/test/mycompiler/test/trivial/TestConstructor.java @@ -0,0 +1,51 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 13-04-08 + * @author + * + * This test verifies correct identification of a Constructor + * + */ + +public class TestConstructor extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestConstructor"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestConstructor(String name) { + super(name,TestConstructor.JAVPATH+TestConstructor.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + // Classes + ClassExpect testConstructor = new ClassExpect(TestConstructor.TESTEDCLASSNAME); + + //Member + testConstructor.addMember(new VarExpect("i",new RefType("java.lang.Integer",-1))); + testConstructor.addMember(new VarExpect("s",new RefType("java.util.Stack",-1))); + + + //Methods + MethodExpect constructor1 = new MethodExpect("",new RefType("void",-1)); + MethodExpect constructor2 = new MethodExpect("",new RefType("void",-1)); + constructor2.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + MethodExpect constructor3 = new MethodExpect("",new RefType("void",-1)); + constructor3.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + constructor3.addParameter(new VarExpect("b",new RefType("java.util.Stack",-1))); + + testConstructor.addMethod(constructor1); + testConstructor.addMethod(constructor2); + testConstructor.addMethod(constructor3); + return new Expectation(testConstructor); + } +} diff --git a/test/mycompiler/test/trivial/TestConstructorNegative.jav b/test/mycompiler/test/trivial/TestConstructorNegative.jav new file mode 100755 index 000000000..b4bfcf903 --- /dev/null +++ b/test/mycompiler/test/trivial/TestConstructorNegative.jav @@ -0,0 +1,8 @@ + +public class TestConstructorNegative { + + /*should throw error*/ + public TestConstructorNegative(java.lang.Integer a, String b) { + return a; + } +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestConstructorNegative.java b/test/mycompiler/test/trivial/TestConstructorNegative.java new file mode 100755 index 000000000..8a842de2d --- /dev/null +++ b/test/mycompiler/test/trivial/TestConstructorNegative.java @@ -0,0 +1,45 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + + +/** + * 13-04-08 + * @author + * + * This test verifies that it's not allowed for a constructor to return a value + * + */ + +public class TestConstructorNegative extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestConstructorNegative"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestConstructorNegative(String name) { + super(name,TestConstructorNegative.JAVPATH+TestConstructorNegative.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + // Classes + ClassExpect testConstructorNegative = new ClassExpect(TestConstructorNegative.TESTEDCLASSNAME); + + //Methods + /*this is as assumed*/ + MethodExpect constructor1 = new MethodExpect("",new RefType("void",-1)); + constructor1.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + constructor1.addParameter(new VarExpect("b",new RefType("java.lang.String",-1))); + /*however, testcase should throw an error*/ + + testConstructorNegative.addMethod(constructor1); + Expectation ret = new Expectation(testConstructorNegative); + ret.addException(new Exception()); + return ret; + } +} diff --git a/test/mycompiler/test/trivial/TestInterfaceEmpty.jav b/test/mycompiler/test/trivial/TestInterfaceEmpty.jav new file mode 100755 index 000000000..52bfca29f --- /dev/null +++ b/test/mycompiler/test/trivial/TestInterfaceEmpty.jav @@ -0,0 +1,4 @@ + +interface TestInterfaceEmpty { + +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestInterfaceEmpty.java b/test/mycompiler/test/trivial/TestInterfaceEmpty.java new file mode 100755 index 000000000..f227fa453 --- /dev/null +++ b/test/mycompiler/test/trivial/TestInterfaceEmpty.java @@ -0,0 +1,33 @@ +package mycompiler.test.trivial; + +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; + +/** + * 01-04-08 + * @author + * + *This test verifies correct detection of simple interface + * + */ + +public class TestInterfaceEmpty extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInterfaceEmpty"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestInterfaceEmpty(String name) { + super(name,TestInterfaceEmpty.JAVPATH+TestInterfaceEmpty.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + // Classes + ClassExpect testEmptyInterface = new ClassExpect(TestInterfaceEmpty.TESTEDCLASSNAME); + + //Expectation + return new Expectation(testEmptyInterface); + } +} diff --git a/test/mycompiler/test/trivial/TestInterfaceMember.jav b/test/mycompiler/test/trivial/TestInterfaceMember.jav new file mode 100755 index 000000000..5e60eb603 --- /dev/null +++ b/test/mycompiler/test/trivial/TestInterfaceMember.jav @@ -0,0 +1,5 @@ +interface TestInterfaceMember { + + Integer member=3; + +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestInterfaceMember.java b/test/mycompiler/test/trivial/TestInterfaceMember.java new file mode 100755 index 000000000..9ee65c2bb --- /dev/null +++ b/test/mycompiler/test/trivial/TestInterfaceMember.java @@ -0,0 +1,37 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 18-04-08 + * @author + * + *This test verifies correct detection of an interface with a single member + * + */ + +public class TestInterfaceMember extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInterfaceMember"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestInterfaceMember(String name) { + super(name,TestInterfaceMember.JAVPATH+TestInterfaceMember.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + // Classes + ClassExpect testInterfaceMember = new ClassExpect(TestInterfaceMember.TESTEDCLASSNAME); + + testInterfaceMember.addMember(new VarExpect("member", new RefType("java.lang.Integer",-1))); + + //Expectation + return new Expectation(testInterfaceMember); + } +} diff --git a/test/mycompiler/test/trivial/TestInterfaceMethod.jav b/test/mycompiler/test/trivial/TestInterfaceMethod.jav new file mode 100755 index 000000000..1b416fd08 --- /dev/null +++ b/test/mycompiler/test/trivial/TestInterfaceMethod.jav @@ -0,0 +1,10 @@ +interface TestInterfaceMethod { + + empty1(); + + void empty2(); + + empty3(Integer a); + + empty4(String a, Integer b); +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestInterfaceMethod.java b/test/mycompiler/test/trivial/TestInterfaceMethod.java new file mode 100755 index 000000000..77dcbd7ac --- /dev/null +++ b/test/mycompiler/test/trivial/TestInterfaceMethod.java @@ -0,0 +1,50 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.test.expectationTypes.TypePlaceholderExpect; + +/** + * 10-04-08 + * @author + * + *This test verifies correct detection of an interface with a method + * + */ + +public class TestInterfaceMethod extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestInterfaceMethod"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestInterfaceMethod(String name) { + super(name,TestInterfaceMethod.JAVPATH+TestInterfaceMethod.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + // Classes + ClassExpect testInterfaceMethod = new ClassExpect(TestInterfaceMethod.TESTEDCLASSNAME); + + MethodExpect empty1 = new MethodExpect("empty1",new TypePlaceholderExpect("a")); + MethodExpect empty2 = new MethodExpect("empty2",new RefType("void",-1)); + MethodExpect empty3 = new MethodExpect("empty3",new TypePlaceholderExpect("b")); + empty3.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + MethodExpect empty4 = new MethodExpect("empty4",new TypePlaceholderExpect("c")); + empty4.addParameter(new VarExpect("a",new RefType("java.lang.String",-1))); + empty4.addParameter(new VarExpect("b",new RefType("java.lang.Integer",-1))); + + testInterfaceMethod.addMethod(empty1); + testInterfaceMethod.addMethod(empty2); + testInterfaceMethod.addMethod(empty3); + testInterfaceMethod.addMethod(empty4); + + //Expectation + return new Expectation(testInterfaceMethod); + } +} diff --git a/test/mycompiler/test/trivial/TestInterfaceNotInferenced.jav b/test/mycompiler/test/trivial/TestInterfaceNotInferenced.jav new file mode 100755 index 000000000..f03d6b181 --- /dev/null +++ b/test/mycompiler/test/trivial/TestInterfaceNotInferenced.jav @@ -0,0 +1,10 @@ +public interface TestInterfaceNotInferenced { + + public Integer m1(); + + /*should throw error, because not all Types defined*/ + public m2(); + + public void m3(a); + +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestInterfaceNotInferenced.java b/test/mycompiler/test/trivial/TestInterfaceNotInferenced.java new file mode 100755 index 000000000..c3193ed0e --- /dev/null +++ b/test/mycompiler/test/trivial/TestInterfaceNotInferenced.java @@ -0,0 +1,48 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.TypePlaceholderExpect; +import mycompiler.test.expectationTypes.VarExpect; + +/** + * 20-05-08 + * @author + * + * checks that interfaces do not get inferenced according to discussion with M. Plümicke + */ +public class TestInterfaceNotInferenced extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestInterfaceNotInferenced"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestInterfaceNotInferenced(String name) { + super(name,TestInterfaceNotInferenced.JAVPATH+TestInterfaceNotInferenced.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + + //interface--- TestInterfaceNotInferenced + ClassExpect testInterfaceNotInferenced = new ClassExpect(TestInterfaceNotInferenced.TESTEDCLASSNAME); + + //methods + MethodExpect m1 = new MethodExpect("m1",new RefType("java.lang.Integer",-1)); + MethodExpect m2 = new MethodExpect("m2", new TypePlaceholderExpect("a")); + MethodExpect m3 = new MethodExpect("m3", new RefType("void",-1)); + m3.addParameter(new VarExpect("a", new TypePlaceholderExpect("b"))); + + testInterfaceNotInferenced.addMethod(m1); + testInterfaceNotInferenced.addMethod(m2); + testInterfaceNotInferenced.addMethod(m3); + //Expectation + Expectation ret = new Expectation(testInterfaceNotInferenced); + //interfaces should not be inferenceable + ret.addException(new Exception()); + return ret; + } + +} diff --git a/test/mycompiler/test/trivial/TestMethodEmpty.jav b/test/mycompiler/test/trivial/TestMethodEmpty.jav new file mode 100755 index 000000000..c9c21cd5c --- /dev/null +++ b/test/mycompiler/test/trivial/TestMethodEmpty.jav @@ -0,0 +1,6 @@ + +public class TestMethodEmpty { + + emptyMethod() { + } +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestMethodEmpty.java b/test/mycompiler/test/trivial/TestMethodEmpty.java new file mode 100755 index 000000000..73f26ac49 --- /dev/null +++ b/test/mycompiler/test/trivial/TestMethodEmpty.java @@ -0,0 +1,38 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; + + +/** + * 01-04-08 + * @author + * + * This test verifies identification of a simple method with return type void + * + */ + +public class TestMethodEmpty extends AbstractInferenceTest { + private final static String TESTEDCLASSNAME="TestMethodEmpty"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestMethodEmpty(String name) { + super(name,TestMethodEmpty.JAVPATH+TestMethodEmpty.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + // Classes + ClassExpect testEmptyMethod = new ClassExpect(TestMethodEmpty.TESTEDCLASSNAME); + + //Methods + MethodExpect emptyMethod = new MethodExpect("emptyMethod",new RefType("void",-1)); + testEmptyMethod.addMethod(emptyMethod); + + return new Expectation(testEmptyMethod); + } +} diff --git a/test/mycompiler/test/trivial/TestMethodEmptyGeneric.jav b/test/mycompiler/test/trivial/TestMethodEmptyGeneric.jav new file mode 100755 index 000000000..c7043f018 --- /dev/null +++ b/test/mycompiler/test/trivial/TestMethodEmptyGeneric.jav @@ -0,0 +1,10 @@ + +public class TestMethodEmptyGeneric{ + + emptyMethodGeneric() { + } + + emptyMethodGeneric2() { + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestMethodEmptyGeneric.java b/test/mycompiler/test/trivial/TestMethodEmptyGeneric.java new file mode 100755 index 000000000..63b2d81d7 --- /dev/null +++ b/test/mycompiler/test/trivial/TestMethodEmptyGeneric.java @@ -0,0 +1,46 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; + +/** + * 01-04-08 + * @author + * + * Simply tests recognition of a generic method with return type void + * + */ + +public class TestMethodEmptyGeneric extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestMethodEmptyGeneric"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestMethodEmptyGeneric(String name) { + super(name,TestMethodEmptyGeneric.JAVPATH+TestMethodEmptyGeneric.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + // classes + ClassExpect testEmptyMethodGeneric = new ClassExpect(TestMethodEmptyGeneric.TESTEDCLASSNAME); + + //methods + MethodExpect emptyMethodGeneric = new MethodExpect("emptyMethodGeneric",new RefType("void",-1)); + emptyMethodGeneric.addGeneric(new GenericTypeVar("T",-1)); + MethodExpect emptyMethodGeneric2= new MethodExpect("emptyMethodGeneric2",new RefType("void",-1)); + emptyMethodGeneric2.addGeneric(new GenericTypeVar("T",-1)); + emptyMethodGeneric2.addGeneric(new GenericTypeVar("S",-1)); + + testEmptyMethodGeneric.addMethod(emptyMethodGeneric); + testEmptyMethodGeneric.addMethod(emptyMethodGeneric2); + + return new Expectation(testEmptyMethodGeneric); + } + +} diff --git a/test/mycompiler/test/trivial/TestMethodEmptyParameter.jav b/test/mycompiler/test/trivial/TestMethodEmptyParameter.jav new file mode 100755 index 000000000..7b5b47ac0 --- /dev/null +++ b/test/mycompiler/test/trivial/TestMethodEmptyParameter.jav @@ -0,0 +1,16 @@ + +public class TestMethodEmptyParameter{ + + + emptyMethodParameter(Integer a) { + } + + + emptyMethodParameter2(Boolean a, Integer b) { + + } + + emptyMethodParameter3(a,b) { + } + +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestMethodEmptyParameter.java b/test/mycompiler/test/trivial/TestMethodEmptyParameter.java new file mode 100755 index 000000000..275ce90f3 --- /dev/null +++ b/test/mycompiler/test/trivial/TestMethodEmptyParameter.java @@ -0,0 +1,52 @@ +package mycompiler.test.trivial; + +import mycompiler.mytype.RefType; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; +import mycompiler.test.expectationTypes.GenericTypeVarExpect; + +/** + * TODO: + * @author tom + * + * Test simple empty methods with parameters -> parameters will be inference to genericstypevar + */ + +public class TestMethodEmptyParameter extends AbstractInferenceTest { + + private final static String TESTEDCLASSNAME="TestMethodEmptyParameter"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestMethodEmptyParameter(String name) { + super(name,TestMethodEmptyParameter.JAVPATH+TestMethodEmptyParameter.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + //classes + ClassExpect testEmptyMethodParameter = new ClassExpect(TestMethodEmptyParameter.TESTEDCLASSNAME); + + //methods + MethodExpect emptyMethodParameter = new MethodExpect("emptyMethodParameter",new RefType("void",-1)); + emptyMethodParameter.addParameter(new VarExpect("a",new RefType("java.lang.Integer",-1))); + + MethodExpect emptyMethodParameter2 = new MethodExpect("emptyMethodParameter2",new RefType("void",-1)); + emptyMethodParameter2.addParameter(new VarExpect("a",new RefType("java.lang.Boolean",-1))); + emptyMethodParameter2.addParameter(new VarExpect("b",new RefType("java.lang.Integer",-1))); + + MethodExpect emptyMethodParameter3 = new MethodExpect("emptyMethodParameter3",new RefType("void",-1)); + emptyMethodParameter2.addParameter(new VarExpect("a",new GenericTypeVarExpect("a"))); + emptyMethodParameter2.addParameter(new VarExpect("b",new GenericTypeVarExpect("b"))); + + testEmptyMethodParameter.addMethod(emptyMethodParameter); + testEmptyMethodParameter.addMethod(emptyMethodParameter2); + testEmptyMethodParameter.addMethod(emptyMethodParameter3); + + return new Expectation(testEmptyMethodParameter); + } + +} diff --git a/test/mycompiler/test/trivial/TestMethodEmptyParameterGenericExtends.jav b/test/mycompiler/test/trivial/TestMethodEmptyParameterGenericExtends.jav new file mode 100755 index 000000000..369661ac9 --- /dev/null +++ b/test/mycompiler/test/trivial/TestMethodEmptyParameterGenericExtends.jav @@ -0,0 +1,9 @@ + +public class TestMethodEmptyParameterGenericExtends{ + + emptyMethodGenericExtends2(T a) { + } + + emptyMethodGenericExtends3(T a, S b) { + } +} \ No newline at end of file diff --git a/test/mycompiler/test/trivial/TestMethodEmptyParameterGenericExtends.java b/test/mycompiler/test/trivial/TestMethodEmptyParameterGenericExtends.java new file mode 100755 index 000000000..a1b672dd8 --- /dev/null +++ b/test/mycompiler/test/trivial/TestMethodEmptyParameterGenericExtends.java @@ -0,0 +1,53 @@ +package mycompiler.test.trivial; + +import java.util.Vector; + +import mycompiler.mytype.BoundedGenericTypeVar; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.test.AbstractInferenceTest; +import mycompiler.test.expectationTypes.ClassExpect; +import mycompiler.test.expectationTypes.Expectation; +import mycompiler.test.expectationTypes.MethodExpect; +import mycompiler.test.expectationTypes.VarExpect; + +public class TestMethodEmptyParameterGenericExtends extends AbstractInferenceTest { + + + private final static String TESTEDCLASSNAME="TestMethodEmptyParameterGenericExtends"; + private final static String JAVPATH="test/mycompiler/test/trivial/"; + + public TestMethodEmptyParameterGenericExtends(String name) { + super(name,TestMethodEmptyParameterGenericExtends.JAVPATH+TestMethodEmptyParameterGenericExtends.TESTEDCLASSNAME + ".jav"); + + } + + @Override + protected Expectation getExpectations() { + ClassExpect testEmptyMethodParameterGenericExtends = new ClassExpect(TestMethodEmptyParameterGenericExtends.TESTEDCLASSNAME); + + //methods + MethodExpect m1 = new MethodExpect("emptyMethodGenericExtends2",new RefType("void",-1)); + Vector bounds1 = new Vector(); + bounds1.add(new RefType("java.lang.Number",-1)); + m1.addGeneric(new BoundedGenericTypeVar("T",bounds1,-1)); + m1.addParameter(new VarExpect("a",new BoundedGenericTypeVar("T",bounds1,-1))); + + MethodExpect m2 = new MethodExpect("emptyMethodGenericExtends3",new RefType("void",-1)); + Vector bounds2 = new Vector(); + bounds2.add(new RefType("java.lang.Number",-1)); + m2.addGeneric(new GenericTypeVar("T",-1)); + m2.addGeneric(new BoundedGenericTypeVar("S",bounds2,-1)); + m2.addParameter(new VarExpect("a",new GenericTypeVar("T",-1))); + m2.addParameter(new VarExpect("b",new BoundedGenericTypeVar("S",bounds2,-1))); + + + testEmptyMethodParameterGenericExtends.addMethod(m1); + testEmptyMethodParameterGenericExtends.addMethod(m2); + + return new Expectation(testEmptyMethodParameterGenericExtends); + } + + +} diff --git a/test/mycompiler/test/unittest/typeReconstructionTest/TrAlgorithmTestSuite.java b/test/mycompiler/test/unittest/typeReconstructionTest/TrAlgorithmTestSuite.java new file mode 100755 index 000000000..25c232c28 --- /dev/null +++ b/test/mycompiler/test/unittest/typeReconstructionTest/TrAlgorithmTestSuite.java @@ -0,0 +1,26 @@ +package mycompiler.test.unittest.typeReconstructionTest; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class TrAlgorithmTestSuite { + /** + * JUnit Tests for main type reconstruction algorithms + */ + + public static Test suite() { + + TestSuite trAlgoSuite = new TestSuite("TR Testsuite"); + + //trMakeFCTest + trAlgoSuite.addTest(new TrMakeFCTest("testAllMakeFC")); + trAlgoSuite.addTest(new TrMakeFCTest("testTrivialMakeFC")); + + //trUnify + trAlgoSuite.addTestSuite(TrSubUnifyTest.class); + //trAlgoSuite.addTest(TrMakeFCTest.suite()); + + return trAlgoSuite; + } + +} diff --git a/test/mycompiler/test/unittest/typeReconstructionTest/TrMakeFCTest.java b/test/mycompiler/test/unittest/typeReconstructionTest/TrMakeFCTest.java new file mode 100755 index 000000000..51aea795b --- /dev/null +++ b/test/mycompiler/test/unittest/typeReconstructionTest/TrMakeFCTest.java @@ -0,0 +1,177 @@ +package mycompiler.test.unittest.typeReconstructionTest; + +import java.util.Vector; + +import junit.framework.TestCase; +import mycompiler.SourceFile; +import mycompiler.myclass.Class; +import mycompiler.myclass.ClassBody; +import mycompiler.myclass.UsedId; +import mycompiler.myinterface.Interface; +import mycompiler.mymodifier.Modifiers; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.Type; +import mycompiler.mytypereconstruction.unify.FC_TTO; + +import org.apache.log4j.Logger; +import org.apache.log4j.xml.DOMConfigurator; + +public class TrMakeFCTest extends TestCase{ + + /* makeFC() is not being tested according to unit test specs -> used objects cannot be mocked*/ + + private static Logger testlog = Logger.getLogger("trtest"); + private SourceFile src=null; + private FC_TTO expected=null; + + public TrMakeFCTest(String name) { + super(name); + DOMConfigurator.configure("log4j.xml"); //maybe subject to asserts -> mocking + DOMConfigurator.configure("test/log4jTesting.xml"); + } + + public void setUp() { + this.src=new SourceFile(); + + } + + public void tearDown() { + this.src=null; + } + + public void testTrivialMakeFC() { + //only classes, no inheritance, no parameters + + testlog.info("----------testTrivilialMakeFC-----------"); + //start environment + //Classes + for (int i=0;i<3;i++) + this.src.addElement(new Class("Test"+i,new Modifiers(),new ClassBody(),new Vector(),null,null,new Vector(),null)); + //Interfaces + for (int i=0;i<3;i++) + this.src.addElement(new Interface("ITest"+i,new Modifiers())); + + //expected result + Vector fc = new Vector(); + //fc.add(new Pair(new RefType("Test",-1),new RefType("",-1))); + Vector tto=(Vector)fc.clone(); + expected = new FC_TTO(fc,tto,this.src.KlassenVektor); + testlog.debug("Test-Setup: " + this.src.KlassenVektor); + + //call tested method + FC_TTO ret = this.src.makeFC(); + testlog.debug("expected: "+expected.getFC()); + testlog.debug("returned: "+ret.getFC()); + + //compare results + TrMakeFCTest.assertEquals(expected.getFC(), ret.getFC()); + TrMakeFCTest.assertEquals(expected.getTTO(),ret.getTTO()); + TrMakeFCTest.assertEquals(expected.getClasses(),ret.getClasses()); + } + + public void testAllMakeFC() { + //white box: all branches of makeFC are being touched + testlog.info("----------testAllMakeFC----------"); + //start environment + //(1) class AbstractList{} + //(2) class Vektor extends AbstractList{} + //(3) class Matrix extends Vektor>{} + //(4) class ExMatrix extends Matrix{} + + //Interface + //(1) + GenericTypeVar gtv_a = new GenericTypeVar("A",20); + Vector paralist = new Vector(); + paralist.add(gtv_a); + Interface abstractlist = new Interface("AbstractList"); + abstractlist.setParaList(paralist); + this.src.addElement(abstractlist); + + //Classes with superclasses + //(1) +// GenericTypeVar param = new GenericTypeVar("A",20); +// Vector paralist = new Vector(); +// paralist.add(param); +// Class abstractlist = new Class("AbstractList",new Modifiers(),new ClassBody(),new Vector(),null,null,new Vector(),paralist); +// this.src.addElement(abstractlist); + //(2) + UsedId superclass = new UsedId(1); + superclass.set_Name(abstractlist.getName()); + Vector paralist2=abstractlist.getParaList(); + superclass.set_ParaList(paralist2); + //implements AbstractList + Vector superif = new Vector(); + superif.add(superclass); + Class vektor= new Class("Vektor",new Modifiers(),new ClassBody(),new Vector(),null,null,superif,paralist); + this.src.addElement(vektor); + //(3) + UsedId superclass2 = new UsedId(2); + superclass2.set_Name(vektor.getName()); + RefType param2 = new RefType("Vektor",paralist,20); + Vector paralist3 = new Vector(); + paralist3.add(param2); + superclass2.set_ParaList(paralist3); + Class matrix = new Class("Matrix",new Modifiers(), new ClassBody(), new Vector(),null,superclass2,new Vector(),paralist); + this.src.addElement(matrix); + + //(4) + UsedId superclass3 = new UsedId(3); + superclass3.set_Name(matrix.getName()); + superclass3.set_ParaList(matrix.get_ParaList()); + Class exmatrix = new Class("ExMatrix", new Modifiers(), new ClassBody(), new Vector(),null,superclass3, new Vector(),paralist); + this.src.addElement(exmatrix); + //Interfaces + + testlog.debug("Test-Setup: " + this.src.KlassenVektor); + + + + //expected Result + GenericTypeVar gtv = new GenericTypeVar("A",20); + Vector gtvparameter = new Vector(); + gtvparameter.add(gtv); + + RefType vektortype = new RefType("Vektor",gtvparameter,-1); + RefType abstractlisttype = new RefType("AbstractList",gtvparameter,-1); + RefType matrixtype = new RefType("Matrix",gtvparameter,-1); + RefType exmatrixtype = new RefType("ExMatrix",gtvparameter,-1); + + Vector vektorparameter = new Vector(); + vektorparameter.add(vektortype); + + Vector fc = new Vector(); + // set "=" + fc.add(new Pair(vektortype,abstractlisttype)); + fc.add(new Pair(matrixtype,new RefType("Vektor",vektorparameter,-1))); + fc.add(new Pair(exmatrixtype,matrixtype)); + + Vector tto=(Vector)fc.clone(); + // set "=*" + fc.add(new Pair(matrixtype,new RefType("AbstractList",vektorparameter,-1))); + fc.add(new Pair(exmatrixtype,new RefType("Vektor",vektorparameter,-1))); + fc.add(new Pair(exmatrixtype,new RefType("AbstractList",vektorparameter,-1))); + + expected = new FC_TTO(fc,tto,this.src.KlassenVektor); + + //call tested method + FC_TTO ret = this.src.makeFC(); + + testlog.debug("expected: "+expected.getFC()); + testlog.debug("returned: "+ret.getFC());; + + //compare results + TrMakeFCTest.assertEquals(expected.getFC(), ret.getFC()); + TrMakeFCTest.assertEquals(expected.getTTO(),ret.getTTO()); + TrMakeFCTest.assertEquals(expected.getClasses(),ret.getClasses()); + } + + /*public static Test suite() { + TestSuite thisch = new TestSuite("TrMakeFCTest"); + + thisch.addTest(new TrMakeFCTest("testTrivialMakeFC")); + thisch.addTest(new TrMakeFCTest("testAllMakeFC")); + return thisch; + }*/ +} diff --git a/test/mycompiler/test/unittest/typeReconstructionTest/TrSubUnifyTest.java b/test/mycompiler/test/unittest/typeReconstructionTest/TrSubUnifyTest.java new file mode 100755 index 000000000..ef3866204 --- /dev/null +++ b/test/mycompiler/test/unittest/typeReconstructionTest/TrSubUnifyTest.java @@ -0,0 +1,635 @@ +package mycompiler.test.unittest.typeReconstructionTest; + + +import java.util.Vector; + +import junit.framework.TestCase; +import mycompiler.SourceFile; +import mycompiler.myclass.Class; +import mycompiler.myclass.ClassBody; +import mycompiler.myclass.UsedId; +import mycompiler.myinterface.Interface; +import mycompiler.mymodifier.Modifiers; +import mycompiler.mytype.ExtendsWildcardType; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Pair.PairOperator; +import mycompiler.mytypereconstruction.unify.FC_TTO; +import mycompiler.mytypereconstruction.unify.Unify; + +import org.apache.log4j.Logger; +import org.apache.log4j.xml.DOMConfigurator; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; + +/*TODO: - mock makeFC and needs to be relocated (now called for every test) + * - erase2 -> FreshWildcardType?? + * - reduce2 wird niemals verwendet!!! <-> erase3 + * - reduce 1/2,... werfen exceptions, die gefangen werden -> schwer testbar, wäre aber vllt sinnvoll + * - adapts not implemented + */ + +public class TrSubUnifyTest extends TestCase{ + + private static Logger testlog = Logger.getLogger("trtest"); + private FC_TTO fc=null; + private FC_TTO fcWithPara=null; + + public TrSubUnifyTest(String name) { + super(name); + DOMConfigurator.configure("test/log4jTesting.xml"); + DOMConfigurator.configure("log4j.xml"); + this.fcWithPara = constructFCwithParams(); + this.fc=constructFC(); + + } + + private FC_TTO constructFC() { + //constructs FC according to the following Environment + //however uses real makeFC up until now + //environment + //(1) interface A + //(2) class B implements A + //(3) class C extends B + + SourceFile src=new SourceFile(); + + //(1) + Interface a = new Interface("A"); + src.addElement(a); + + //(2) + UsedId superclass = new UsedId(1); + superclass.set_Name(a.getName()); + Vector superif = new Vector(); + superif.add(superclass); + Class b= new Class("B",new Modifiers(),new ClassBody(),new Vector(),null,null,superif,null); + src.addElement(b); + //(3) + UsedId superclass2 = new UsedId(2); + superclass2.set_Name(b.getName()); + Class c = new Class("C",new Modifiers(), new ClassBody(), new Vector(),null,superclass2,new Vector(),null); + src.addElement(c); + FC_TTO fca = src.makeFC(); + testlog.info(fca.getTTO()); + return fca; + + } + + private FC_TTO constructFCwithParams() { + //constructs FC according to the following Environment + //however uses real makeFC up until now + //environment + //(1) interface AbstractList{} + //(2) class Vektor extends AbstractList{} + //(3) class Matrix extends Vektor>{} + //(4) class ExMatrix extends Matrix{} + + SourceFile src=new SourceFile(); + + //Interface + //(1) + GenericTypeVar gtv_a = new GenericTypeVar("A",20); + Vector paralist = new Vector(); + paralist.add(gtv_a); + Interface abstractlist = new Interface("AbstractList"); + abstractlist.setParaList(paralist); + src.addElement(abstractlist); + + //Classes with superclasses + //(1) (either as a class or as an interface +// GenericTypeVar param = new GenericTypeVar("A",20); +// Vector paralist = new Vector(); +// paralist.add(param); +// Class abstractlist = new Class("AbstractList",new Modifiers(),new ClassBody(),new Vector(),null,null,new Vector(),paralist); +// this.src.addElement(abstractlist); + //(2) + UsedId superclass = new UsedId(1); + superclass.set_Name(abstractlist.getName()); + Vector paralist2=abstractlist.getParaList(); + superclass.set_ParaList(paralist2); + //implements AbstractList + Vector superif = new Vector(); + superif.add(superclass); + Class vektor= new Class("Vektor",new Modifiers(),new ClassBody(),new Vector(),null,null,superif,paralist); + src.addElement(vektor); + //(3) + UsedId superclass2 = new UsedId(2); + superclass2.set_Name(vektor.getName()); + RefType param2 = new RefType("Vektor",paralist,20); + Vector paralist3 = new Vector(); + paralist3.add(param2); + superclass2.set_ParaList(paralist3); + Class matrix = new Class("Matrix",new Modifiers(), new ClassBody(), new Vector(),null,superclass2,new Vector(),paralist); + src.addElement(matrix); + + //(4) + UsedId superclass3 = new UsedId(3); + superclass3.set_Name(matrix.getName()); + superclass3.set_ParaList(matrix.get_ParaList()); + Class exmatrix = new Class("ExMatrix", new Modifiers(), new ClassBody(), new Vector(),null,superclass3, new Vector(),paralist); + src.addElement(exmatrix); + return src.makeFC(); + } + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + //erase + +// public void testSubUnifyErase1() { +// //setup - see constructFC() +// //(1){ B <* A} -> {} +// //(2){ C <* A} -> {} +// //(3){ C <* B} -> {} +// testlog.info("-------testSubUnifyErase1---------"); +// //Type 1 +// Type ty1 = new RefType("A",-1); +// +// //Type2 +// Type ty2 = new RefType("B",-1); +// +// //Type3 +// Type ty3 = new RefType("C",-1); +//testlog.debug("Test-Setup: " + ty2 + " -> " + ty1); +//testlog.debug("Test-Setup: " + ty3 + " -> " + ty1); +//testlog.debug("Test-Setup: " + ty3 + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +//testlog.debug("expected: " + expected); +// +// //actual +// //(1) +// Vector types1 = new Vector(); +// types1.add(new Pair(ty2,ty1,PairOperator.Smaller)); +// //(2) +// Vector types2 = new Vector(); +// types2.add(new Pair(ty3,ty1,PairOperator.Smaller)); +// //(3) +// Vector types3 = new Vector(); +// types3.add(new Pair(ty3,ty2,PairOperator.Smaller)); +// //execution of tested method +// Vector ret1 = Unify.sub_unify(types1 ,fc); +// Vector ret2 = Unify.sub_unify(types2 ,fc); +// Vector ret3 = Unify.sub_unify(types3 ,fc); +// //comparisons +//testlog.debug("returned: "+ ret1); +//testlog.debug("returned: "+ ret2); +//testlog.debug("returned: "+ ret3); +// TrMakeFCTest.assertEquals("erase1a",expected.toString(), ret1.toString()); +// TrMakeFCTest.assertEquals("erase1b",expected.toString(), ret2.toString()); +// TrMakeFCTest.assertEquals("erase1c",expected.toString(), ret3.toString()); +// } +// +// public void testSubUnifyErase2() { +//testlog.info("-------testSubUnifyErase2---------"); +// //setup - see constructFC() +// //(1){ B <*? extends A} -> {} +// //(2){ C <*? super A} -> {} +// //(3){ C <* B} -> {} <- TODO FreshWildCards???? +// //Type 1 +// Type ty1 = new ExtendsWildcardType(-1, new RefType("A",-1)); +// +// //Type2 +// Type ty2 = new RefType("B",-1); +// +// //Type3 +// Type ty3 = new SuperWildcardType(-1, new RefType("C",-1)); +//testlog.debug("Test-Setup: " + ty2 + " -> extends " + ty1); +//testlog.debug("Test-Setup: " + ty2 + " -> super " + ty3); +////testlog.debug("Test-Setup: " + ty3 + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +//testlog.debug("expected: " + expected); +// +// //actual +// //(1) +// Vector types1 = new Vector(); +// types1.add(new Pair(ty2,ty1,PairOperator.SmallerExtends)); +// //(2) +// Vector types2 = new Vector(); +// types2.add(new Pair(ty2,ty3,PairOperator.SmallerExtends)); +// //(3) +//// Vector types3 = new Vector(); +//// types3.add(new Pair(ty3,ty2,PairOperator.SmallerExtends)); +// //execution of tested method +// Vector ret1 = Unify.sub_unify(types1 ,fc); +// Vector ret2 = Unify.sub_unify(types2 ,fc); +//// Vector ret3 = Unify.sub_unify(types3 ,fc); +// //comparisons +//testlog.debug("returned: "+ ret1); +//testlog.debug("returned: "+ ret2); +////testlog.info("returned: "+ ret3); +// TrMakeFCTest.assertEquals("erase2a",expected.toString(), ret1.toString()); +// TrMakeFCTest.assertEquals("erase2b",expected.toString(), ret2.toString()); +//// TrMakeFCTest.assertEquals("erase2c",expected.toString(), ret3.toString()); +// } +// +// public void testSubUnifyErase3() { +// //{ A = B} -> {} +//testlog.info("-------testSubUnifyErase3---------"); +// //Type 1 +// Type ty1 = new RefType("A",-1); +// +// //Type2 +// Type ty2 = new RefType("A",-1); +//testlog.debug("Test-Setup: " + ty1 + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +// //expected.add(new Pair(ty1,ty2,PairOperator.Equal)); +//testlog.debug("expected: " + expected); +// +// //actual +// //execution of tested method +// Vector types = new Vector(); +// types.add(new Pair(ty1,ty2,PairOperator.Equal)); +// Vector ret = Unify.sub_unify(types ,fc); +//testlog.debug("returned: "+ ret); +// //comparison +// TrMakeFCTest.assertEquals("erase3",expected.toString(), ret.toString()); +// } +// +// //swap +// +// public void testSubUnifySwap() { +// //{ A = TypePlaceholder a} -> {a = A} +// //A can be: RefType, GenericTypeVar, WildcardType +//testlog.info("-------testSubUnifySwap---------"); +// //Type 1 +// Type ty1a = new RefType("A",-1); +// Type ty1b = new GenericTypeVar("B",-1); +// Type ty1c = new SuperWildcardType(-1,new RefType("C",-1)); +// Type ty1d = new ExtendsWildcardType(-1, new RefType("D",-1)); +// +// //Type2 +// Type ty2a = TypePlaceholder.fresh(); +// Type ty2b = TypePlaceholder.fresh(); +// Type ty2c = TypePlaceholder.fresh(); +// Type ty2d = TypePlaceholder.fresh(); +// +//testlog.debug("Test-Setup: " + ty1a + " = " + ty2a + "; "); +//testlog.debug(ty1b + " = " + ty2b + "; "); +//testlog.debug(ty1c + " = " + ty2c + "; "); +//testlog.debug(ty1d + " = " + ty2d + "; "); +// +// //expected +// Vector expected = new Vector(); +// expected.add(new Pair(ty2a,ty1a,PairOperator.Equal)); +// expected.add(new Pair(ty2b,ty1b,PairOperator.Equal)); +// expected.add(new Pair(ty2c,ty1c,PairOperator.Equal)); +// expected.add(new Pair(ty2d,ty1d,PairOperator.Equal)); +//testlog.debug("expected: " + expected); +// +// //actual +// //execution of tested method +// Vector types = new Vector(); +// types.add(new Pair(ty1a,ty2a,PairOperator.Equal)); +// types.add(new Pair(ty1b,ty2b,PairOperator.Equal)); +// types.add(new Pair(ty1c,ty2c,PairOperator.Equal)); +// types.add(new Pair(ty1d,ty2d,PairOperator.Equal)); +// Vector ret = Unify.sub_unify(types ,fc); +//testlog.debug("returned: "+ ret); +// //comparison +// TrMakeFCTest.assertEquals("swap",expected.toString(), ret.toString()); +// } +// +// //adapt +// public void testSubUnifyAdapt() { +// //adapt-meaning of test unclear +// // +//testlog.info("-------testSubUnifyAdapt---------"); +// //Type 1 +// //Parameter +// Vector paramAa = new Vector(); +// paramAa.add(new RefType("java.lang.Integer",-1)); +// paramAa.add(TypePlaceholder.fresh()); +// //paramAa.add(TypePlaceholder.fresh()); +// Vector paramAb = new Vector(); +// paramAb.add(new RefType("Vektor",paramAa,-1)); +// Type ty1 = new RefType("Vektor",paramAa,-1); +// +// //Type2 +// Vector paramB = new Vector(); +// //paramB.add(new RefType("java.lang.Number",-1)); +// paramB.add(TypePlaceholder.fresh()); +// Type ty2 = new RefType("AbstractList",paramB,-1); +// +// testlog.debug("Test-Setup: " + ty1 + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +//// for (int i = 0;i types = new Vector(); +// types.add(new Pair(ty1,ty2,PairOperator.Smaller)); +// Vector ret = Unify.sub_unify(types ,fcWithPara); +// testlog.debug("returned: "+ ret); +// //comparison +// TrMakeFCTest.assertEquals("adapt",expected.toString(), ret.toString()); +//// fail("not correctly implemented"); +// } +// +// +// //reduce +// +// public void testSubUnfiyReduceLow() { +// //{?extends A < B} -> {A < B} +// //setup - unification of two types +//testlog.info("-------testSubUnifyReduceLow---------"); +// //Type 1 +// Type ty1 = new ExtendsWildcardType(-1,new RefType("A",-1)); +// +// //Type2 +// Type ty2 = new RefType("B",-1); +//testlog.debug("Test-Setup: " + ty1 + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +// expected.add(new Pair(((ExtendsWildcardType)ty1).get_ExtendsType(),ty2,PairOperator.Smaller)); +//testlog.debug("expected: " + expected); +// +// //actual +// //execution of tested method +// Vector types = new Vector(); +// types.add(new Pair(ty1,ty2,PairOperator.Smaller)); +// Vector ret = Unify.sub_unify(types ,fc); +//testlog.debug("returned: "+ ret); +// //comparison +// TrMakeFCTest.assertEquals("reduceLow",expected.toString(), ret.toString()); +// } +// +// public void testSubUnifyReduceUp() { +// //{A {A < B} +// //setup - unification of two types +//testlog.info("-------testSubUnifyReduceUp---------"); +// //Type 1 +// Type ty1 = new RefType("A",-1); +// +// //Type2 +// Type ty2 = new SuperWildcardType(-1, new RefType("B",-1)); +//testlog.debug("Test-Setup: " + ty1 + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +// expected.add(new Pair(ty1,((SuperWildcardType)ty2).get_SuperType(),PairOperator.Smaller)); +//testlog.debug("expected: " + expected); +////ReduceU +// //actual +// //execution of tested method +// Vector types = new Vector(); +// types.add(new Pair(ty1,ty2,PairOperator.Smaller)); +// Vector ret = Unify.sub_unify(types ,fc); +//testlog.debug("returned: "+ ret); +// //comparison +// TrMakeFCTest.assertEquals("reduceUp",expected.toString(), ret.toString()); +// } +// +// public void testSubUnifyReduceUpLow() { +// //{?extends A {A < B} +// //setup - unification of two types +//testlog.info("-------testSubUnifyReduceUpLow---------"); +// //Type 1 +// Type ty1 = new ExtendsWildcardType(-1,new RefType("A",-1)); +// +// //Type2 +// Type ty2 = new SuperWildcardType(-1, new RefType("B",-1)); +//testlog.debug("Test-Setup: " + ty1 + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +// expected.add(new Pair(((ExtendsWildcardType)ty1).get_ExtendsType(),((SuperWildcardType)ty2).get_SuperType(),PairOperator.Smaller)); +//testlog.debug("expected: " + expected); +// +// //actual +// //execution of tested method +// Vector types = new Vector(); +// types.add(new Pair(ty1,ty2,PairOperator.Smaller)); +// Vector ret = Unify.sub_unify(types ,fc); +//testlog.debug("returned: "+ ret); +// //comparison +// TrMakeFCTest.assertEquals("reduceUpLow",expected.toString(), ret.toString()); +// } +// +// public void testSubUnifyReduce1() { +// //{Vektor < AbstractList -> {a paramA = new Vector(); +// paramA.add(TypePlaceholder.fresh()); +// Type ty1 = new RefType("Vektor",paramA,-1); +// +// //Type2 +// Vector paramB = new Vector(); +// paramB.add(TypePlaceholder.fresh()); +// Type ty2 = new RefType("AbstractList",paramB,-1); +// +//testlog.debug("Test-Setup: " + ty1 + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +// for (int i = 0;i types = new Vector(); +// types.add(new Pair(ty1,ty2,PairOperator.Smaller)); +// Vector ret = Unify.sub_unify(types ,fcWithPara); +//testlog.debug("returned: "+ ret); +// //comparison +// TrMakeFCTest.assertEquals("reduce1",expected.toString(), ret.toString()); +// } +// + public void testSubUnifyReduce2() { + + //!!!! Fall tritt niemals ein + //Vor: type1 = type2 wird vorher schon gefangen + + //{A = A -> {a=d,b=e,c=f} + //setup - unification of two types +testlog.info("-------testSubUnifyReduce2---------"); + //Type 1 + //Parameter + Vector paramA = new Vector(); + paramA.add(new GenericTypeVar("a",-1)); + paramA.add(new GenericTypeVar("b",-1)); + paramA.add(new GenericTypeVar("c",-1)); + Type ty1 = new RefType("A",paramA,-1); + + //Type2 + Vector paramB = new Vector(); + paramB.add(new GenericTypeVar("d",-1)); + paramB.add(new GenericTypeVar("e",-1)); + paramB.add(new GenericTypeVar("f",-1)); + Type ty2 = new RefType("A",paramB,-1); + +testlog.debug("Test-Setup: " + ty1 + " -> " + ty2); + + //expected + Vector expected = new Vector(); + for (int i = 0;i types = new Vector(); + types.add(new Pair(ty1,ty2,PairOperator.Equal)); + Vector ret = Unify.sub_unify(types ,fc); +testlog.debug("returned: "+ ret); + //comparison + TrMakeFCTest.assertEquals("reduce2",expected.toString(), ret.toString()); + } +// +// public void testSubUnifyReduceExt() { +// //a: {Vektor -> {a -> {a paramA = new Vector(); +// paramA.add(TypePlaceholder.fresh()); +// Type ty1a = new RefType("Vektor",paramA,-1); +// Type ty1b = new ExtendsWildcardType(-1, new RefType("Vektor",paramA,-1)); +// +// //Type2 +// Vector paramB = new Vector(); +// paramB.add(TypePlaceholder.fresh()); +// Type ty2 = new ExtendsWildcardType(-1,new RefType("AbstractList",paramB,-1)); +// +//testlog.debug("Test-Setup: " + ty1a + " -> " + ty2 + "; " + ty1b + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +// for (int i = 0;i typesa = new Vector(); +// typesa.add(new Pair(ty1a,ty2,PairOperator.SmallerExtends)); +// Vector reta = Unify.sub_unify(typesa ,fcWithPara); +// //b +// Vector typesb = new Vector(); +// typesb.add(new Pair(ty1b,ty2,PairOperator.SmallerExtends)); +// Vector retb = Unify.sub_unify(typesb ,fcWithPara); +// +//testlog.debug("returned: "+ reta); +//testlog.debug("returned: "+ retb); +// //comparison +// TrMakeFCTest.assertEquals("reduceExt",expected.toString(), reta.toString()); +// TrMakeFCTest.assertEquals("reduceExt",expected.toString(), retb.toString()); +// } +// +// public void testSubUnifyReduceSup() { +// //a: {Vektor -> {a -> {a paramA = new Vector(); +// paramA.add(TypePlaceholder.fresh()); +// Type ty1a = new RefType("AbstractList",paramA,-1); +// Type ty1b = new SuperWildcardType(-1, new RefType("AbstractList",paramA,-1)); +// +// //Type2 +// Vector paramB = new Vector(); +// paramB.add(TypePlaceholder.fresh()); +// Type ty2 = new SuperWildcardType(-1,new RefType("Vektor",paramB,-1)); +// +//testlog.debug("Test-Setup: " + ty1a + " -> " + ty2 + "; " + ty1b + " -> " + ty2); +// +// //expected +// Vector expected = new Vector(); +// for (int i = 0;i typesa = new Vector(); +// typesa.add(new Pair(ty1a,ty2,PairOperator.SmallerExtends)); +// Vector reta = Unify.sub_unify(typesa ,fcWithPara); +// //b +// Vector typesb = new Vector(); +// typesb.add(new Pair(ty1b,ty2,PairOperator.SmallerExtends)); +// Vector retb = Unify.sub_unify(typesb ,fcWithPara); +// +//testlog.debug("returned: "+ reta); +//testlog.debug("returned: "+ retb); +// //comparison +// TrMakeFCTest.assertEquals("reduceSup",expected.toString(), reta.toString()); +// TrMakeFCTest.assertEquals("reduceSup",expected.toString(), retb.toString()); +// } +// +// public void testSubUnfiyReduceEq() { +// //{Vektor -> {a=d, b=e, c=f} +//System.out.println("-------testSubUnifyReduceEq---------"); +// //Type 1 +// //Parameter +// Vector paramA = new Vector(); +// paramA.add(TypePlaceholder.fresh()); +// paramA.add(TypePlaceholder.fresh()); +// paramA.add(TypePlaceholder.fresh()); +// Type ty1 = new RefType("Vektor",paramA,-1); +// +// //Type2 +// Vector paramB = new Vector(); +// paramB.add(TypePlaceholder.fresh()); +// paramB.add(TypePlaceholder.fresh()); +// paramB.add(TypePlaceholder.fresh()); +// Type ty2 = new RefType("Vektor",paramB,-1); +// +//testlog.debug("Test-Setup: " + ty1 + " ->? " + ty2); +// +// //expected +// Vector expected = new Vector(); +// for (int i = 0;i types = new Vector(); +// types.add(new Pair(ty1,ty2,PairOperator.SmallerExtends)); +// Vector ret = Unify.sub_unify(types ,fcWithPara); +//testlog.debug("returned: "+ ret); +// //comparison +// TrMakeFCTest.assertEquals("reduceEq",expected.toString(), ret.toString()); +// } + +} diff --git a/test/mycompiler/test/unittest/typeReconstructionTest/TrUnifyTest.java b/test/mycompiler/test/unittest/typeReconstructionTest/TrUnifyTest.java new file mode 100755 index 000000000..88490fec0 --- /dev/null +++ b/test/mycompiler/test/unittest/typeReconstructionTest/TrUnifyTest.java @@ -0,0 +1,176 @@ +package mycompiler.test.unittest.typeReconstructionTest; + +import java.util.Vector; + +import junit.framework.TestCase; +import mycompiler.SourceFile; +import mycompiler.myclass.Class; +import mycompiler.myclass.ClassBody; +import mycompiler.myclass.UsedId; +import mycompiler.myinterface.Interface; +import mycompiler.mymodifier.Modifiers; +import mycompiler.mytype.GenericTypeVar; +import mycompiler.mytype.Pair; +import mycompiler.mytype.RefType; +import mycompiler.mytype.SuperWildcardType; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; +import mycompiler.mytype.Pair.PairOperator; +import mycompiler.mytypereconstruction.unify.FC_TTO; +import mycompiler.mytypereconstruction.unify.Unify; + +import org.apache.log4j.xml.DOMConfigurator; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TrUnifyTest extends TestCase { + + FC_TTO fc=null; + + public TrUnifyTest(String name) { + super(name); + DOMConfigurator.configure("log4j.xml"); //maybe subject to asserts -> mocking + this.fc = constructFC(); + + } + public void setUpBeforeClass() { + System.out.println("test"); + } + + private FC_TTO constructFC() { + SourceFile src=new SourceFile(); + + //environment + //(1) interface AbstractList{} + //(2) class Vektor extends AbstractList{} + //(3) class Matrix extends Vektor>{} + //(4) class ExMatrix extends Matrix{} + + //Interface + //(1) + GenericTypeVar gtv_a = new GenericTypeVar("A",20); + Vector paralist = new Vector(); + paralist.add(gtv_a); + Interface abstractlist = new Interface("AbstractList"); + abstractlist.setParaList(paralist); + src.addElement(abstractlist); + + //Classes with superclasses + //(1) (either as a class or as an interface +// GenericTypeVar param = new GenericTypeVar("A",20); +// Vector paralist = new Vector(); +// paralist.add(param); +// Class abstractlist = new Class("AbstractList",new Modifiers(),new ClassBody(),new Vector(),null,null,new Vector(),paralist); +// this.src.addElement(abstractlist); + //(2) + UsedId superclass = new UsedId(1); + superclass.set_Name(abstractlist.getName()); + Vector paralist2=abstractlist.getParaList(); + superclass.set_ParaList(paralist2); + //implements AbstractList + Vector superif = new Vector(); + superif.add(superclass); + Class vektor= new Class("Vektor",new Modifiers(),new ClassBody(),new Vector(),null,null,superif,paralist); + src.addElement(vektor); + //(3) + UsedId superclass2 = new UsedId(2); + superclass2.set_Name(vektor.getName()); + RefType param2 = new RefType("Vektor",paralist,20); + Vector paralist3 = new Vector(); + paralist3.add(param2); + superclass2.set_ParaList(paralist3); + Class matrix = new Class("Matrix",new Modifiers(), new ClassBody(), new Vector(),null,superclass2,new Vector(),paralist); + src.addElement(matrix); + + //(4) + UsedId superclass3 = new UsedId(3); + superclass3.set_Name(matrix.getName()); + superclass3.set_ParaList(matrix.get_ParaList()); + Class exmatrix = new Class("ExMatrix", new Modifiers(), new ClassBody(), new Vector(),null,superclass3, new Vector(),paralist); + src.addElement(exmatrix); + return src.makeFC(); + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + //Java-Types without respect to FC (java types) + public void testUnifytesting() { + //setup - unification of two types + //Type 1 + TypePlaceholder th1 = TypePlaceholder.fresh(); + // TypePlaceholder ty2 = TypePlaceholder.fresh(); + Vector param = new Vector(); + //param.add(new GenericTypeVar("A",-1)); + param.add(th1); + + Vector param2 = new Vector(); + param2.add(new RefType("B",-1)); + Vector param1 = new Vector(); + param1.add(new RefType("Vektor",param2,-1)); + Type ty1 = new RefType("Vektor",param,-1); + // ty1.replaceWithType(ty3); + // Type ty1 = new RefType("java.lang.Number",-1); + Type ty2 = new RefType("Matrix",param1,-1); + + //expected + Vector> expected = new Vector>(); + Vector result1 = new Vector(); + result1.add(new Pair(ty1,ty2,PairOperator.Equal)); + expected.add(result1); +System.out.println("expected: " + expected); + + //actual + //execution of tested method + // Vector> ret = Unify.unify(ty1, ty2 ,new FC_TTO(new Vector(),new Vector(),new Vector())); + Vector> ret = Unify.unify(ty1, ty2 ,fc); +System.out.println("returned: "+ ret); + //comparison + //TrMakeFCTest.assertEquals(expected, ret); + } + + //Java-Types with respect to FC +// public void testUnifyWithFC() { +// //setup - unification of two types +// //Type 1 +// Type ty1 = TypePlaceholder.fresh(); +// Type ty2 = new RefType("java.lang.Boolean",-1); +// +// //expected +// Vector> expected = new Vector>(); +// Vector result1 = new Vector(); +// result1.add(new Pair(ty1,ty2,PairOperator.Equal)); +// expected.add(result1); +//System.out.println("expected: " + expected); +// +// //actual +// //execution of tested method +// Vector> ret = Unify.unify(ty1, ty2 ,new FC_TTO(new Vector(),new Vector(),new Vector())); +//System.out.println("returned: "+ ret); +// //comparison +// TrMakeFCTest.assertEquals(expected, ret); +// //fail("Not yet implemented"); +// } +// + + + + + public void testUnifyReduce1() { + fail("Not yet implemented"); + } + + + public void testUnifyErase1() { + //löscht "A extends B" + + } + +}