Compare commits
316 Commits
Author | SHA1 | Date | |
---|---|---|---|
5821839cbc | |||
b6df854cc6 | |||
47c2b78713 | |||
58db64ad22 | |||
ae01af7a40 | |||
db93a1dfe1 | |||
f17745bfa5 | |||
84176275be | |||
da49e42515 | |||
0a6aa450db | |||
dc52dc5dec | |||
ca8952a43c | |||
4a6a8d62e3 | |||
4f265b56a4 | |||
e5fc8c8288 | |||
c2d3fce75e | |||
8134bbb297 | |||
46f1134bad | |||
32741f41e9 | |||
d03e20df90 | |||
d19414c513 | |||
ba6ae74ad1 | |||
dad06a5626 | |||
324864f8d8 | |||
f2410154aa | |||
b39dedb9aa | |||
7c0a91e624 | |||
c043717c06 | |||
9a51e79f2a | |||
a31e7b1108 | |||
bbb79b1a1d | |||
b3e13d09b9 | |||
5ac19d7a59 | |||
362be98c30 | |||
8bda352bc9 | |||
856f5da86b | |||
7d75f18319 | |||
8fa8fc8758 | |||
752723020e | |||
6eb7f2d1bb | |||
7b6b720b57 | |||
bb8df92cba | |||
b8415b122b | |||
629d2dcc4d | |||
16cbf8e1b7 | |||
0ca4f16c49 | |||
1a32ea9ce9 | |||
1afe2d4d5c | |||
d8feb04938 | |||
e08485740f | |||
8780d5d47a | |||
863bfa40d3 | |||
6a42c8ef11 | |||
07d63a9586 | |||
fcbd05fa9c | |||
8bad95f774 | |||
5a7c2310a1 | |||
a8f18e77be | |||
904ca01207 | |||
b70dc71a62 | |||
afc6bc7b89 | |||
fbcd0cd8a5 | |||
12abb0b34d | |||
65a1038574 | |||
9e114207ce | |||
a23f77c337 | |||
5c12a61699 | |||
4b9eda962e | |||
e26f87afba | |||
3cd7dba316 | |||
9a07201498 | |||
dfe79a8030 | |||
e8c46dcdbd | |||
558a873e68 | |||
b1febd7a50 | |||
ae9220c04b | |||
11e149110a | |||
d8e7df425d | |||
27f6abefe8 | |||
ba636e1da0 | |||
4173733ada | |||
1b9a9c0841 | |||
ff0d1e907f | |||
3f62ef4072 | |||
b14c264435 | |||
7a47de7bfa | |||
f4d0dbf95d | |||
b0aeaae80e | |||
03b1321a45 | |||
7363758603 | |||
f8d7a95731 | |||
8b6a4d1746 | |||
a16e62f4bd | |||
ea32cd5680 | |||
377987abda | |||
1e96811127 | |||
22393888f1 | |||
b68107286a | |||
f630f93a3d | |||
0438ef9af4 | |||
3bb2153b6a | |||
6cc0d462ab | |||
df1881bf41 | |||
de238b90df | |||
55f288022a | |||
0313d297e1 | |||
044e6fbc3f | |||
aa692c2f25 | |||
6616d78dcb | |||
5dd90cb30c | |||
64247b689b | |||
23e0be2572 | |||
d080eb4a0a | |||
41b3e4f6c2 | |||
5c73224f8f | |||
e06888f5f7 | |||
3a2a5510b9 | |||
b7f41c4d13 | |||
53cfb4b046 | |||
284447aad2 | |||
b707a0f03e | |||
d63f08bf33 | |||
d3ebee1b3c | |||
45cad9f675 | |||
74c2b5e323 | |||
e537a76cd9 | |||
44318ee5d8 | |||
8d69f6c82b | |||
943c4e6043 | |||
7b78cf8471 | |||
3a8f1252a4 | |||
e1c925b9bc | |||
6793b0bd24 | |||
2e30429252 | |||
2c642cb6ef | |||
20d1106e07 | |||
6c2d71d005 | |||
0d5b515a47 | |||
b12f301656 | |||
0be7534b98 | |||
1bf208b833 | |||
a3e7b4567a | |||
4cdcde8fef | |||
d89d06797e | |||
336dc52be6 | |||
098cafac00 | |||
4deb91b99f | |||
8d8e27c84c | |||
e2d384e7f9 | |||
304a5693a6 | |||
5b07d58093 | |||
b51079280e | |||
5030410978 | |||
23142adc70 | |||
43a8c9e647 | |||
fa337c5546 | |||
639ac8430c | |||
332dd57de3 | |||
ac3ce7d214 | |||
b4d7ab02eb | |||
67e1c5c736 | |||
de607cfd53 | |||
26cc9b85ef | |||
257edfc0b3 | |||
5e18496847 | |||
bbfd8699e8 | |||
ad2804fab9 | |||
1e9d0517f2 | |||
a5b86dc84c | |||
11bcf5735a | |||
88726ccb70 | |||
14e00913e8 | |||
0e524caae7 | |||
f788b74f26 | |||
47c9be5488 | |||
c80dc162d9 | |||
21c6aef7fd | |||
299f8f56ca | |||
1f825360df | |||
fa9627b883 | |||
d19a79bd63 | |||
1762101330 | |||
e061dea7f5 | |||
a8d8dec899 | |||
4681b03838 | |||
6acc3c1366 | |||
863904a4e8 | |||
6778160315 | |||
27acee3385 | |||
b1d6b44fb9 | |||
a4ea466fe6 | |||
7c00940cba | |||
b069bb7b8f | |||
bdd018d922 | |||
98cbe9b389 | |||
039dd3b3f4 | |||
8eecda2a8f | |||
3ff45a01de | |||
264910bfa4 | |||
89b53351ce | |||
ab7f56db6f | |||
ac42bdf0a2 | |||
cd569a8374 | |||
bb165e007d | |||
5f428894ea | |||
116232df57 | |||
53dd7b019e | |||
3c80cb275b | |||
1017b02704 | |||
f7804b754d | |||
dd478961e2 | |||
141e952c7a | |||
63b2224f46 | |||
8ae7bda535 | |||
a27b4f9d3b | |||
e4374c06fd | |||
8b0005ecee | |||
97e0e2fc72 | |||
7ff9554d78 | |||
4576efe3ec | |||
e2ba4490b1 | |||
6fd382580a | |||
9552831d4e | |||
3f4f2cd27b | |||
2958c52610 | |||
fc03a744fe | |||
be6a719433 | |||
c45c426011 | |||
ae37dd6255 | |||
480c7dca61 | |||
e447e1cd46 | |||
3739747eca | |||
82c0736fee | |||
8a40acb73e | |||
fd5902f6dd | |||
fb82d8c3eb | |||
9f37139ab3 | |||
ed246e0f88 | |||
c646a34745 | |||
b8c0d87056 | |||
4c908abede | |||
61891177a1 | |||
dc0cf0cd34 | |||
f18fcd2b12 | |||
ecad9e138c | |||
0c63695f7b | |||
c83697dedb | |||
54a11c8779 | |||
01ef0e9385 | |||
c1e4fce67f | |||
eeba9fb734 | |||
7ada9cbd47 | |||
176ec7b707 | |||
777a9b5beb | |||
e695429262 | |||
b3514a8375 | |||
4c6c77929f | |||
2eb11748ca | |||
1b1fae6b13 | |||
84641d4abf | |||
a263ba5fd4 | |||
4765c2afe0 | |||
e49c2a35de | |||
28e0e8e94d | |||
6b709f0198 | |||
b93f1dd376 | |||
c08a8fd347 | |||
2483044e0c | |||
a86b70e672 | |||
0048d5f305 | |||
87e49a692a | |||
a221adb28c | |||
1a0c76accf | |||
92d81ac097 | |||
947d145cf1 | |||
6619b73d80 | |||
e9607e37b1 | |||
64dce5d814 | |||
50916b5db2 | |||
bdbe20552e | |||
f077829d30 | |||
ce52fd8904 | |||
12093f2fc7 | |||
931fb01d74 | |||
11fc7a4512 | |||
5f9452cfda | |||
4539faf241 | |||
3d38ea2e08 | |||
b0153be1cd | |||
52be0a1af3 | |||
040a1f4088 | |||
0dcb36f49e | |||
47361ca22c | |||
b99f1bc3c9 | |||
36a3aeddb3 | |||
ca447fd44e | |||
05187aa49f | |||
c9546d9762 | |||
eda270d451 | |||
356794d753 | |||
f16171a8f6 | |||
77c06225a6 | |||
fab73a4d62 | |||
422f3b4144 | |||
bfb00ac1d1 | |||
347b06ac68 | |||
66b37482db | |||
632c2ca508 | |||
bafffe26ad | |||
edf1d817d2 | |||
cfc6711897 | |||
9e1f417280 | |||
4fa160529d | |||
7484ace724 | |||
bd8a62cda7 | |||
50dda3041f |
.settings
BCEL/bcelifier
IfStatement.javaIfStatementCreator.javaJavaToBCEL.javaLambda1.classLambda1Creator.javaNewClass.javaNewClassCreator.javaThis.classThisCreator.java
doc/Papers
lib
notizen
stan
lambdaBytecode
stackmaptable
stf
src/de/dhbwstuttgart
bytecode
core
logger
myexception
parser
syntaxtree
Class.javaClassBody.javaConstructor.javaField.javaFieldDeclaration.javaFormalParameter.javaMethod.javaNullSyntaxTreeNode.javaParameterList.javaSourceFile.javaSyntaxTreeNode.java
factory
misc
operator
AddOp.javaAndOp.javaDivideOp.javaEqualOp.javaGreaterEquOp.javaGreaterOp.javaLessEquOp.javaLessOp.javaLogOp.javaMinusOp.javaModuloOp.javaMulOp.javaNotEqualOp.javaOperator.javaOrOp.javaPlusOp.javaRelOp.javaTimesOp.java
statement
ArgumentList.javaAssign.javaBinary.javaBlock.javaBoolLiteral.javaCastExpr.javaCharLiteral.javaDoubleLiteral.javaEmptyStmt.javaExprStmt.javaFloatLiteral.javaForStmt.javaIfStmt.javaInstVar.javaInstanceOf.javaIntLiteral.javaLambdaExpression.javaLiteral.javaLocalOrFieldVarOrClassname.javaLocalVarDecl.javaLongLiteral.javaMethodCall.javaNegativeExpr.javaNewArray.javaNewClass.javaNotExpr.javaNull.javaPositivExpr.javaPostDecExpr.javaPostIncExpr.javaPreDecExpr.javaPreIncExpr.javaReceiver.javaReturn.javaStatement.javaStringLiteral.javaSuperCall.javaThis.javaThisCall.javaWhileStmt.java
type
typeinference
ByteCodeResult.javaConstraintsSet.javaEinzelElement.javaFunNInterface.javaFunNMethod.javaFunVoidNMethod.javaKomplexeMenge.javaMenge.javaOderConstraint.javaOderMenge.javaPair.javaSingleConstraint.javaTypeinferenceResultSet.javaTypeinferenceResults.javaUndConstraint.javaUndMenge.javaUnifyConstraintsSet.javaUnifyOderConstraint.javaUnifySingleConstraint.javaUnifyUndConstraint.java
assumptions
exceptions
unify
test
bytecode
ASTBytecodeTest.javaAssignTest.javaBinary.javBinary2.javBinaryTest.javaBinaryTest2.javaBoolLitTest.javaCharLitTest.javaConditionTest.javaEmptyClassTest.javaFieldDeclarationTest.javaForTest.javForTest.javaFun0.javaFun1.javaGenericsTest.javaIdTest.javaIdentityField.javIdentityFieldTest.javaIdentityTest.javaIfElseIfStatement.javIfElseIfStatementTest.javaIfElseStatement.javIfElseStatementTest.javaIfStatementTest.javaLambdaExpr2Test.javaLambdaExprTest.javaMain.javMainTest.javaMatrix_lambda.javMatrix_lambda2.javMatrix_lambda3.javMatrix_lambdaTest.javaMatrix_lambdaTest2.javaMatrix_lambdaTest3.javaMethodAndVariable.javMethodCallTest.javaMethodEmpty.javaMethodEmptyRetType.javaMethodsAndVariableTest.javaMultiClass.javMultiClassTest.javaNewClass.javNewClassTest.javaNewStatement.javNewStatementTest.javaParameter.javParameterTest.javaPostDecrement.javaPostIncrement.javaReturnTest.javaRunnableTest.javaSingleClassTester.javaSourceFileBytecodeTest.javaStringLitTest.javaSystemOutPrintln.javSystemOutPrintlnTest.javaTest2.javaTest3.javaTestStackMap.javaUninitializedVariable.javUninitializedVariableTest.javaVariable.javVariableMultimethods.javVariableMultimethodsTest.javaVariableTest.javaWhileTest.javWhileTest.java
operators
AddDoubleOperator.javAddDoubleOperatorTest.javaAddFloatOperator.javAddFloatOperatorTest.javaAddIntegerOperator.javAddIntegerOperatorTest.javaAddLongOperator.javAddLongOperatorTest.javaAddOperator.javAddOperatorTest.javaDivOperator.javDivOperatorTest.javaEqualOperator.javEqualOperatorTest.javaGreaterEqualOperator.javGreaterEqualOperatorTest.javaGreaterOperator.javGreaterOperatorTest.javaModuloOperator.javModuloOperatorTest.javaMulOperator.javMulOperatorTest.javaNotEqualOperator.javNotEqualOperatorTest.javaOrOperator.javOrOperatorTest.javaRelOperatorTest.javaSmallerEqualOperator.javSmallerEqualOperatorTest.javaSmallerOperator.javSmallerOperatorTest.javaSubOperator.javSubOperatorTest.java
stackmaptable
types
AutoOverloading.javAutoOverloadingMultiResults.javAutoOverloadingMultiResultsTest.javaAutoOverloadingTest.javaAutoOverloadingVector.javAutoOverloadingVectorTest.javaExtendsObject.javExtendsObjectTest.javaExtendsType.javExtendsVector.javExtendsVectorString.javExtendsVectorStringTest.javaExtendsVectorTest.javaMethodWithTypedVector.javMethodWithTypedVectorTest.javaMethodWithUntypedVector.javMethodWithUntypedVectorTest.javaMultiExtends.javMultiExtendsTest.javaNewStatement.javNewStatementTest.javaOL.javOLTest.javaOverloading.javOverloading2.javOverloading2Test.javaOverloadingReplace.javOverloadingTest.javaSuperType.javTypedVector.javWildcardTest.javWildcardTest.java
plugindevelopment
TypeInsertTests
unify
@ -1,5 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/de/dhbwstuttgart/core/MyCompiler.java=UTF-8
|
||||
encoding//src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java=UTF-8
|
||||
encoding//src/de/dhbwstuttgart/typeinference/SingleConstraint.java=UTF-8
|
||||
encoding//src/de/dhbwstuttgart/typeinference/UndConstraint.java=UTF-8
|
||||
encoding//src/de/dhbwstuttgart/typeinference/UnifySingleConstraint.java=UTF-8
|
||||
encoding//src/de/dhbwstuttgart/typeinference/UnifyUndConstraint.java=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
12
BCEL/bcelifier/IfStatement.java
Normal file
12
BCEL/bcelifier/IfStatement.java
Normal file
@ -0,0 +1,12 @@
|
||||
package bcelifier;
|
||||
|
||||
class IfStatement{
|
||||
Integer methode(Boolean b){
|
||||
if(b){
|
||||
return 1;
|
||||
}else{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
71
BCEL/bcelifier/IfStatementCreator.java
Normal file
71
BCEL/bcelifier/IfStatementCreator.java
Normal file
@ -0,0 +1,71 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.MethodGenerator;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResults;
|
||||
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class IfStatementCreator {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGenerator _cg;
|
||||
|
||||
public IfStatementCreator() {
|
||||
|
||||
TypeinferenceResults typeinferenceResults = null;
|
||||
_cg = new ClassGenerator("bcelifier.IfStatement", new RefType("java.lang.Object", null, 0), "IfStatement.java", Const.ACC_SUPER, new String[] { }, typeinferenceResults);
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGenerator(0, Type.VOID, new Type[] { new ObjectType("java.lang.Boolean") }, new String[] { "arg0" }, "<init>", "bcelifier.IfStatement", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGenerator(0, new ObjectType("java.lang.Integer"), new Type[] { new ObjectType("java.lang.Boolean") }, new String[] { "arg0" }, "methode", "bcelifier.IfStatement", il, _cp);
|
||||
|
||||
il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
|
||||
il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", Type.BOOLEAN, Type.NO_ARGS, Const.INVOKEVIRTUAL));
|
||||
BranchInstruction ifeq_4 = InstructionFactory.createBranchInstruction(Const.IFEQ, null);
|
||||
il.append(ifeq_4);
|
||||
il.append(new PUSH(_cp, 1));
|
||||
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC));
|
||||
il.append(InstructionFactory.createReturn(Type.OBJECT));
|
||||
InstructionHandle ih_12 = il.append(new PUSH(_cp, 2));
|
||||
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC));
|
||||
il.append(InstructionFactory.createReturn(Type.OBJECT));
|
||||
ifeq_4.setTarget(ih_12);
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.IfStatementCreator creator = new bcelifier.IfStatementCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.IfStatement.class"));
|
||||
|
||||
System.out.println("bcelifier.IfStatement.class");
|
||||
}
|
||||
}
|
@ -23,16 +23,17 @@ public class JavaToBCEL {
|
||||
|
||||
public JavaToBCEL(){
|
||||
try {
|
||||
new BCELifier(new ClassParser(rootDirectory+"Lambda1.class").parse(), new FileOutputStream(new File(rootDirectory+"Lambda1Creator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"This.class").parse(), new FileOutputStream(new File(rootDirectory+"ThisCreator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"IntLiteral.class").parse(), new FileOutputStream(new File(rootDirectory+"IntLiteralCreator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"MethodCall.class").parse(), new FileOutputStream(new File(rootDirectory+"MethodCallCreator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"FieldDeclaration.class").parse(), new FileOutputStream(new File(rootDirectory+"FieldDeclarationCreator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"Null.class").parse(), new FileOutputStream(new File(rootDirectory+"NullCreator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"LocalVarAccess.class").parse(), new FileOutputStream(new File(rootDirectory+"LocalVarAccessCreator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"Wildcard.class").parse(), new FileOutputStream(new File(rootDirectory+"WildcardCreator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"BooleanValue.class").parse(), new FileOutputStream(new File(rootDirectory+"BooleanValueCreator.java"))).start();
|
||||
|
||||
//new BCELifier(new ClassParser(rootDirectory+"Lambda1.class").parse(), new FileOutputStream(new File(rootDirectory+"Lambda1Creator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"This.class").parse(), new FileOutputStream(new File(rootDirectory+"ThisCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"IntLiteral.class").parse(), new FileOutputStream(new File(rootDirectory+"IntLiteralCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"MethodCall.class").parse(), new FileOutputStream(new File(rootDirectory+"MethodCallCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"FieldDeclaration.class").parse(), new FileOutputStream(new File(rootDirectory+"FieldDeclarationCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"Null.class").parse(), new FileOutputStream(new File(rootDirectory+"NullCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"LocalVarAccess.class").parse(), new FileOutputStream(new File(rootDirectory+"LocalVarAccessCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"Wildcard.class").parse(), new FileOutputStream(new File(rootDirectory+"WildcardCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"BooleanValue.class").parse(), new FileOutputStream(new File(rootDirectory+"BooleanValueCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"NewClass.class").parse(), new FileOutputStream(new File(rootDirectory+"NewClassCreator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"IfStatement.class").parse(), new FileOutputStream(new File(rootDirectory+"IfStatementCreator.java"))).start();
|
||||
} catch (ClassFormatException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Binary file not shown.
@ -1,70 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Lambda1Creator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public Lambda1Creator() {
|
||||
_cg = new ClassGen("bcelifier.Lambda1", "java.lang.Object", "Lambda1.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
createMethod_2();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.Lambda1", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(0, new ObjectType("java.lang.Runnable"), Type.NO_ARGS, new String[] { }, "methode", "bcelifier.Lambda1", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
InstructionHandle ih_1 = il.append(_factory.createReturn(Type.OBJECT));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_2() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PRIVATE | ACC_SYNTHETIC, Type.VOID, Type.NO_ARGS, new String[] { }, "lambda$methode$0", "bcelifier.Lambda1", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createFieldAccess("java.lang.System", "out", new ObjectType("java.io.PrintStream"), Constants.GETSTATIC));
|
||||
il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.io.PrintStream", "println", Type.VOID, new Type[] { Type.OBJECT }, Constants.INVOKEVIRTUAL));
|
||||
InstructionHandle ih_7 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.Lambda1Creator creator = new bcelifier.Lambda1Creator();
|
||||
creator.create(new FileOutputStream("bcelifier.Lambda1.class"));
|
||||
}
|
||||
}
|
||||
|
10
BCEL/bcelifier/NewClass.java
Normal file
10
BCEL/bcelifier/NewClass.java
Normal file
@ -0,0 +1,10 @@
|
||||
package bcelifier;
|
||||
|
||||
|
||||
public class NewClass {
|
||||
public NewClass(Integer i){}
|
||||
void methode2(){
|
||||
new NewClass(1);
|
||||
}
|
||||
}
|
||||
|
60
BCEL/bcelifier/NewClassCreator.java
Normal file
60
BCEL/bcelifier/NewClassCreator.java
Normal file
@ -0,0 +1,60 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class NewClassCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public NewClassCreator() {
|
||||
_cg = new ClassGen("bcelifier.NewClass", "java.lang.Object", "NewClass.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, new Type[] { new ObjectType("java.lang.Integer") }, new String[] { "arg0" }, "<init>", "bcelifier.NewClass", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(0, Type.VOID, Type.NO_ARGS, new String[] { }, "methode2", "bcelifier.NewClass", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createNew("bcelifier.NewClass"));
|
||||
il.append(InstructionConstants.DUP);
|
||||
il.append(new PUSH(_cp, 1));
|
||||
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Constants.INVOKESTATIC));
|
||||
il.append(_factory.createInvoke("bcelifier.NewClass", "<init>", Type.VOID, new Type[] { new ObjectType("java.lang.Integer") }, Constants.INVOKESPECIAL));
|
||||
il.append(InstructionConstants.POP);
|
||||
InstructionHandle ih_12 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.NewClassCreator creator = new bcelifier.NewClassCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.NewClass.class"));
|
||||
}
|
||||
}
|
Binary file not shown.
@ -11,7 +11,7 @@ public class ThisCreator implements Constants {
|
||||
private ClassGen _cg;
|
||||
|
||||
public ThisCreator() {
|
||||
_cg = new ClassGen("bcelifier.This", "java.lang.Object", "<Unknown>", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
_cg = new ClassGen("bcelifier.This", "java.lang.Object", "This.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
|
BIN
doc/Papers/Java_Type_Unificytion_With_Wildcards.pdf
Normal file
BIN
doc/Papers/Java_Type_Unificytion_With_Wildcards.pdf
Normal file
Binary file not shown.
Binary file not shown.
@ -35,3 +35,9 @@
|
||||
# TODO:
|
||||
* Matrix Beispiel muss funktionieren (verschachtelter Lambda Ausdruck)
|
||||
* Automatisch Bytecode generieren, wenn alle Typen eingesetzt sind
|
||||
|
||||
## StackMapTable
|
||||
* Attribute für Codeattribut
|
||||
* Wird für Sprünge im Bytecode benötigt
|
||||
* Quelle: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.4
|
||||
|
||||
|
@ -1,104 +0,0 @@
|
||||
Classfile /home/janulrich/Development/eclipseworkspace/JavaCompilerCore/notizen/stan/lambdaBytecode/Lambda1.class
|
||||
Last modified 20.08.2015; size 903 bytes
|
||||
MD5 checksum acb53c553588f3c919f2b0e6359bbd94
|
||||
class Lambda1
|
||||
InnerClasses:
|
||||
public static final #46= #45 of #49; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
|
||||
BootstrapMethods:
|
||||
0: #18 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
||||
Method arguments:
|
||||
#19 ()V
|
||||
#20 invokestatic Lambda1.lambda$methode$0:()V
|
||||
#19 ()V
|
||||
minor version: 0
|
||||
major version: 52
|
||||
flags: ACC_SUPER
|
||||
Constant pool:
|
||||
#1 = Methodref #8.#16 // java/lang/Object."<init>":()V
|
||||
#2 = InvokeDynamic #0:#21 // #0:run:()Ljava/lang/Runnable;
|
||||
#3 = Methodref #7.#22 // Lambda1.methode:()Ljava/lang/Runnable;
|
||||
#4 = InterfaceMethodref #23.#24 // java/lang/Runnable.run:()V
|
||||
#5 = Fieldref #25.#26 // java/lang/System.out:Ljava/io/PrintStream;
|
||||
#6 = Methodref #27.#28 // java/io/PrintStream.println:()V
|
||||
#7 = Class #29 // Lambda1
|
||||
#8 = Class #30 // java/lang/Object
|
||||
#9 = Utf8 <init>
|
||||
#10 = Utf8 ()V
|
||||
#11 = Utf8 Code
|
||||
#12 = Utf8 methode
|
||||
#13 = Utf8 ()Ljava/lang/Runnable;
|
||||
#14 = Utf8 methode2
|
||||
#15 = Utf8 lambda$methode$0
|
||||
#16 = NameAndType #9:#10 // "<init>":()V
|
||||
#17 = Utf8 BootstrapMethods
|
||||
#18 = MethodHandle #6:#31 // invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
||||
#19 = MethodType #10 // ()V
|
||||
#20 = MethodHandle #6:#32 // invokestatic Lambda1.lambda$methode$0:()V
|
||||
#21 = NameAndType #33:#13 // run:()Ljava/lang/Runnable;
|
||||
#22 = NameAndType #12:#13 // methode:()Ljava/lang/Runnable;
|
||||
#23 = Class #34 // java/lang/Runnable
|
||||
#24 = NameAndType #33:#10 // run:()V
|
||||
#25 = Class #35 // java/lang/System
|
||||
#26 = NameAndType #36:#37 // out:Ljava/io/PrintStream;
|
||||
#27 = Class #38 // java/io/PrintStream
|
||||
#28 = NameAndType #39:#10 // println:()V
|
||||
#29 = Utf8 Lambda1
|
||||
#30 = Utf8 java/lang/Object
|
||||
#31 = Methodref #40.#41 // java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
||||
#32 = Methodref #7.#42 // Lambda1.lambda$methode$0:()V
|
||||
#33 = Utf8 run
|
||||
#34 = Utf8 java/lang/Runnable
|
||||
#35 = Utf8 java/lang/System
|
||||
#36 = Utf8 out
|
||||
#37 = Utf8 Ljava/io/PrintStream;
|
||||
#38 = Utf8 java/io/PrintStream
|
||||
#39 = Utf8 println
|
||||
#40 = Class #43 // java/lang/invoke/LambdaMetafactory
|
||||
#41 = NameAndType #44:#48 // metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
||||
#42 = NameAndType #15:#10 // lambda$methode$0:()V
|
||||
#43 = Utf8 java/lang/invoke/LambdaMetafactory
|
||||
#44 = Utf8 metafactory
|
||||
#45 = Class #50 // java/lang/invoke/MethodHandles$Lookup
|
||||
#46 = Utf8 Lookup
|
||||
#47 = Utf8 InnerClasses
|
||||
#48 = Utf8 (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
|
||||
#49 = Class #51 // java/lang/invoke/MethodHandles
|
||||
#50 = Utf8 java/lang/invoke/MethodHandles$Lookup
|
||||
#51 = Utf8 java/lang/invoke/MethodHandles
|
||||
{
|
||||
Lambda1();
|
||||
Signature: ()V
|
||||
flags:
|
||||
Code:
|
||||
stack=1, locals=1, args_size=1
|
||||
0: aload_0
|
||||
1: invokespecial #1 // Method java/lang/Object."<init>":()V
|
||||
4: return
|
||||
|
||||
java.lang.Runnable methode();
|
||||
Signature: ()Ljava/lang/Runnable;
|
||||
flags:
|
||||
Code:
|
||||
stack=1, locals=1, args_size=1
|
||||
0: invokedynamic #2, 0 // InvokeDynamic #0:run:()Ljava/lang/Runnable;
|
||||
5: areturn
|
||||
|
||||
void methode2();
|
||||
Signature: ()V
|
||||
flags:
|
||||
Code:
|
||||
stack=1, locals=1, args_size=1
|
||||
0: aload_0
|
||||
1: invokevirtual #3 // Method methode:()Ljava/lang/Runnable;
|
||||
4: invokeinterface #4, 1 // InterfaceMethod java/lang/Runnable.run:()V
|
||||
9: return
|
||||
|
||||
private static void lambda$methode$0();
|
||||
Signature: ()V
|
||||
flags: ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC
|
||||
Code:
|
||||
stack=1, locals=0, args_size=0
|
||||
0: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
|
||||
3: invokevirtual #6 // Method java/io/PrintStream.println:()V
|
||||
6: return
|
||||
}
|
9
notizen/stan/stackmaptable/IfElseStatement.java
Normal file
9
notizen/stan/stackmaptable/IfElseStatement.java
Normal file
@ -0,0 +1,9 @@
|
||||
class IfElseStatement{
|
||||
Integer method(Boolean flag){
|
||||
if(flag){
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
21
notizen/stan/stackmaptable/Notizen.md
Normal file
21
notizen/stan/stackmaptable/Notizen.md
Normal file
@ -0,0 +1,21 @@
|
||||
# StackMapTable
|
||||
* Attribute für Codeattribut
|
||||
* Wird für Sprünge im Bytecode benötigt
|
||||
* Quelle: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.4
|
||||
|
||||
## Generierung
|
||||
* StackMapTable könnte generiert werden, indem im bytecode geschaut wird, wo Sprünge vorliegen.
|
||||
* https://stackoverflow.com/questions/24927993/what-kind-of-java-code-requires-stackmap-frames#24930521
|
||||
* It is illegal to have code after an unconditional branch without a stack map frame being provided for it.
|
||||
|
||||
## BCEL Patch
|
||||
https://issues.apache.org/jira/browse/BCEL-268
|
||||
* Submitting patch: https://commons.apache.org/patches.html
|
||||
### Änderungen im BCEL-Projekt
|
||||
* Neue Datei StackMapTableGen
|
||||
* Testen TODO:
|
||||
* Mittels BCELifier Code generieren lassen, welcher Methoden erstellt, die Branches enthalten
|
||||
* Dies dann dem StackMapTableGen übergeben und auf das erstellen von StackMapEntries abprüfen
|
||||
|
||||
# Literatur
|
||||
* Zu JVM allgemein: http://blog.jamesdbloom.com/JVMInternals.html
|
6
notizen/stan/stackmaptable/StackMapTest.java
Normal file
6
notizen/stan/stackmaptable/StackMapTest.java
Normal file
@ -0,0 +1,6 @@
|
||||
class StackMapTest{
|
||||
|
||||
void methode(){
|
||||
while(true){}
|
||||
}
|
||||
}
|
8
notizen/stan/stackmaptable/StackMapTest2.java
Normal file
8
notizen/stan/stackmaptable/StackMapTest2.java
Normal file
@ -0,0 +1,8 @@
|
||||
class StackMapTest2{
|
||||
|
||||
void methode(){
|
||||
Integer i = 1;
|
||||
while(System.out == null){
|
||||
i+=1;}
|
||||
}
|
||||
}
|
14
notizen/stan/stackmaptable/StackMapTest3.java
Normal file
14
notizen/stan/stackmaptable/StackMapTest3.java
Normal file
@ -0,0 +1,14 @@
|
||||
class StackMapTest3{
|
||||
|
||||
void methode(){
|
||||
Integer i = 1;
|
||||
while(System.out == null){
|
||||
i+=1;
|
||||
}
|
||||
System.out.println(i);
|
||||
StackMapTest3 o = new StackMapTest3();
|
||||
while(i<0){
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
17
notizen/stan/stackmaptable/StackMapTest4.java
Normal file
17
notizen/stan/stackmaptable/StackMapTest4.java
Normal file
@ -0,0 +1,17 @@
|
||||
class StackMapTest4{
|
||||
|
||||
int test = 1;
|
||||
|
||||
void methode(){
|
||||
Integer i = 1;
|
||||
while(System.out == null){
|
||||
i+=test;
|
||||
}
|
||||
Runnable r = ()->System.out.println("");
|
||||
System.out.println(i);
|
||||
StackMapTest3 o = new StackMapTest3();
|
||||
while(i<0){
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
12
notizen/stan/stackmaptable/StackMapTest5.java
Normal file
12
notizen/stan/stackmaptable/StackMapTest5.java
Normal file
@ -0,0 +1,12 @@
|
||||
class StackMapTest5{
|
||||
|
||||
void methode(){
|
||||
int i = 0;
|
||||
while(System.out == null){
|
||||
i+=1;
|
||||
while(true){
|
||||
String s = "2";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
notizen/stf/Notes
Normal file
50
notizen/stf/Notes
Normal file
@ -0,0 +1,50 @@
|
||||
- Was sind / wof<6F>r brauch man TTO und Classes
|
||||
- Unify l<>st auch zirkul<75>re Abh<62>ngigkeiten a <. b <. c <. a
|
||||
- Tests dazu?
|
||||
- Pr<50>fung im Builder?
|
||||
|
||||
- Unterschied Wildcard und FreshWildcard, ExtendsWildcard und FreshExtendsWildcard etc...
|
||||
- FreshWildcard = TPH f<>r Wildcards?
|
||||
|
||||
- Warum ist result von unify = Menge<Menge<Pair>> und nicht Menge<Pair>
|
||||
|
||||
- Menge Equals <20>berarbeiten (Momentan Reihenfolgensensitiv)
|
||||
|
||||
- Wie kommen die Mengen des Unify-Algorithmus zustande? Siehe test:
|
||||
/*
|
||||
* Test b <. a, a <. b
|
||||
*/
|
||||
|
||||
-
|
||||
|
||||
|
||||
- Transitiven Abschluss von FC bilden um schneller Subtypen bestimmen zu k<>nnen
|
||||
- Problem: 2 FCs f<>r Pairs und MPairs durch das Mapping
|
||||
- Equals der Typen schreiben um instanceof Pr<50>fungen zu vermeiden
|
||||
|
||||
- Refactoring der Klassen Menge und Pair erlaubt?
|
||||
++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
|
||||
Instanceof wird verwendet da:
|
||||
-> Entscheidung f<>r diese L<>sung, da 2-Fach-Visitor oder DoubleDispatch Pattern
|
||||
enorm viele <20>berladene Methoden zur folge h<>tten, nicht intuitiv w<>ren und die rules in die Typen verschoben h<>tten.
|
||||
|
||||
Gilt reduce f<>r alle Typen oder nur f<>r simple und tphs? (Vermutlich nur s und tph sonst br<62>uchte man keine upLow regel)
|
||||
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
HashCode implementierungen testen (type paramerte mit einbeziehen, hashcodes cachen -> da immutable)
|
||||
|
||||
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++
|
||||
- Typen sind anhand ihres identifiers durchg<68>ngig identifizierbar
|
||||
|
||||
- ReduceEq nur auf SimpleTypes oder auf alles anwenden? (Momentan alles)
|
||||
- ReduceEq Permutation?
|
||||
|
||||
EED UP
|
||||
- Anwendungsreihenfolge der Regeln (wahrscheinlichste zuerst, evtl ist nach regel 1 regel 2 nie m<>glich etc...)
|
||||
- Erase vor Reduce
|
||||
- Rechenarm vor rechenintensiv
|
||||
|
@ -1,6 +1,12 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.commons.bcel6.classfile.BootstrapMethod;
|
||||
import org.apache.commons.bcel6.classfile.BootstrapMethods;
|
||||
@ -8,6 +14,7 @@ import org.apache.commons.bcel6.classfile.ConstantPool;
|
||||
import org.apache.commons.bcel6.classfile.InnerClass;
|
||||
import org.apache.commons.bcel6.classfile.InnerClasses;
|
||||
import org.apache.commons.bcel6.classfile.JavaClass;
|
||||
import org.apache.commons.bcel6.classfile.Method;
|
||||
import org.apache.commons.bcel6.classfile.Signature;
|
||||
import org.apache.commons.bcel6.generic.ClassGen;
|
||||
import org.apache.commons.bcel6.generic.ConstantPoolGen;
|
||||
@ -18,22 +25,26 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResults;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
|
||||
public class ClassGenerator extends ClassGen{
|
||||
|
||||
private DHBWConstantPoolGen cp;
|
||||
private DHBWInstructionFactory factory;
|
||||
private TypeinferenceResultSet tiResult;
|
||||
private TypeinferenceResults tiResult;
|
||||
private int lambdaMethodeNr = 0;
|
||||
private Type superClass;
|
||||
|
||||
private Menge<TypePlaceholder> usedTPHs = new Menge<>();
|
||||
|
||||
private Map<String, ClassGenerator> extraClasses = new HashMap<>();
|
||||
private List<String> methodsNamesAndTypes = new LinkedList<>();
|
||||
private MethodGenerator methodGenerator;
|
||||
|
||||
public ClassGenerator(String name, Type superClass, String string,
|
||||
short accPublic, String[] strings, TypeinferenceResultSet resultSet) {
|
||||
super(name,superClass.get_Name(),string,accPublic,strings, new DHBWConstantPoolGen());
|
||||
this.tiResult = resultSet;
|
||||
public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings, TypeinferenceResults typeinferenceResults) {
|
||||
super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen());
|
||||
this.tiResult = typeinferenceResults;
|
||||
this.superClass = superClass;
|
||||
|
||||
cp = (DHBWConstantPoolGen) super.getConstantPool();
|
||||
@ -43,7 +54,7 @@ public class ClassGenerator extends ClassGen{
|
||||
}
|
||||
|
||||
public DHBWInstructionFactory getInstructionFactory() {
|
||||
return factory ;
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,28 +62,19 @@ public class ClassGenerator extends ClassGen{
|
||||
* @param toTPH
|
||||
* @return Es gilt dann "toTPH extends Type"
|
||||
*/
|
||||
public org.apache.commons.bcel6.generic.Type getNearestUsedType(TypePlaceholder toTPH, Menge<TypePlaceholder> usedTypes){
|
||||
Type t = resolveTPH(toTPH, usedTypes);
|
||||
public org.apache.commons.bcel6.generic.Type getNearestUsedType(Type t, Menge<TypePlaceholder> usedTypes){
|
||||
if(t == null){
|
||||
return this.getInstructionFactory().createObjectType();
|
||||
}else if(t instanceof TypePlaceholder){ //Es muss sich in diesem Fall um einen TPH handeln:
|
||||
//return getNearestType((TypePlaceholder) t);
|
||||
return new TypePlaceholderType((TypePlaceholder) t);
|
||||
}else{
|
||||
return t.getBytecodeType(this);
|
||||
return t.getBytecodeType(this, getTypeinferenceResults().getTypeReconstructions().get(0));
|
||||
}
|
||||
}
|
||||
public org.apache.commons.bcel6.generic.Type getNearestUsedType(TypePlaceholder toTPH){
|
||||
return this.getNearestUsedType(toTPH, null);
|
||||
}
|
||||
|
||||
public Type resolveTPH(TypePlaceholder typePlaceholder) {
|
||||
return resolveTPH(typePlaceholder, null);
|
||||
}
|
||||
|
||||
public Type resolveTPH(TypePlaceholder typePlaceholder, Menge<TypePlaceholder> toOneOfTheseTypes) {
|
||||
return tiResult.getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes);
|
||||
}
|
||||
|
||||
public String createLambdaMethodName() {
|
||||
return "lambda$methode$"+(lambdaMethodeNr++);
|
||||
@ -100,7 +102,7 @@ public class ClassGenerator extends ClassGen{
|
||||
int innerClassesUTF8 = this.getConstantPool().addUtf8("InnerClasses");
|
||||
this.addAttribute(new InnerClasses(innerClassesUTF8,numberOfInnerClasses*8+2,innerClasses,this.getConstantPool().getConstantPool()));
|
||||
}
|
||||
|
||||
|
||||
public int addBootstrapMethod(BootstrapMethod bMethod) {
|
||||
int numberOfBootstrapMethods = 1;
|
||||
int name_index = this.getConstantPool().addUtf8("BootstrapMethods");
|
||||
@ -131,7 +133,7 @@ public class ClassGenerator extends ClassGen{
|
||||
|
||||
//Signatur setzen:
|
||||
String typeParameters = this.generateParameterSignature();
|
||||
String superClassSignature = this.superClass.getBytecodeSignature(this);
|
||||
String superClassSignature = this.superClass.getBytecodeSignature(this, null);
|
||||
String classSignature = typeParameters + superClassSignature;
|
||||
if(classSignature.length()>0){
|
||||
this.addAttribute(new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(classSignature),cp.getConstantPool()));
|
||||
@ -149,11 +151,44 @@ public class ClassGenerator extends ClassGen{
|
||||
TypePlaceholder tph = it.next();
|
||||
//ret += tph.getBytecodeMethodSignature(this);
|
||||
//ret += ":";
|
||||
ret += tph.getClassSignature(this);
|
||||
ret += tph.getClassSignature(this, getTypeinferenceResults().getTypeReconstructions().get(0));
|
||||
}
|
||||
ret += ">";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void addExtraClass(ClassGenerator cg){
|
||||
extraClasses.put(cg.getClassName(), cg);
|
||||
}
|
||||
|
||||
public Map<String, ClassGenerator> getExtraClasses() {
|
||||
return extraClasses;
|
||||
}
|
||||
|
||||
public TypeinferenceResults getTypeinferenceResults() {
|
||||
return tiResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMethod(Method m) {
|
||||
String methodNameAndTypes = m.getReturnType().toString()+m.getName()+Arrays.toString(m.getArgumentTypes());
|
||||
|
||||
if(methodsNamesAndTypes.contains(methodNameAndTypes)){
|
||||
return;
|
||||
}
|
||||
|
||||
methodsNamesAndTypes.add(methodNameAndTypes);
|
||||
super.addMethod(m);
|
||||
}
|
||||
|
||||
public void setMethodeGenerator(MethodGenerator methodGenerator) {
|
||||
this.methodGenerator = methodGenerator;
|
||||
}
|
||||
|
||||
public MethodGenerator getMethodGenerator() {
|
||||
return methodGenerator;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.awt.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.classfile.Attribute;
|
||||
@ -26,11 +28,13 @@ import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.type.FunN;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
|
||||
public class DHBWInstructionFactory extends InstructionFactory{
|
||||
|
||||
private DHBWConstantPoolGen cp;
|
||||
private ClassGenerator cg;
|
||||
private static Map<String, Integer> storeIndexes = new HashMap<>();
|
||||
|
||||
public DHBWInstructionFactory(ClassGenerator cg, DHBWConstantPoolGen cp) {
|
||||
super(cg, cp);
|
||||
@ -46,7 +50,7 @@ public class DHBWInstructionFactory extends InstructionFactory{
|
||||
* @param lambdaMethod
|
||||
* @return
|
||||
*/
|
||||
public INVOKEDYNAMIC createInvokeDynamic( String interfaceMethodName, String invokeDynamicMethodType, FunN interfaceMethodType, MethodGen lambdaMethod ) {
|
||||
public INVOKEDYNAMIC createInvokeDynamic( String interfaceMethodName, String invokeDynamicMethodType, FunN interfaceMethodType, MethodGen lambdaMethod, TypeinferenceResultSet rs) {
|
||||
//Zuerst die Bootstrap-Methode erstellen: Diese müssen dann in ein BootstrapMethods-Attribut zusammengefasst und dem Classfile hinzugefügt werden
|
||||
//this.cp.addMethodref(lambdaMethod);
|
||||
|
||||
@ -67,7 +71,7 @@ public class DHBWInstructionFactory extends InstructionFactory{
|
||||
|
||||
String lambdaTypeParameterList = "()";
|
||||
ConstantMethodType lambdaMethodType1 = new ConstantMethodType(this.cp.addUtf8(interfaceMethodType.getBytecodeInvokeDynamicSignatureUpperBound(cg))); //TODO: Hier den Grund finden, warum Object stehen muss.
|
||||
ConstantMethodType lambdaMethodType = new ConstantMethodType(this.cp.addUtf8(interfaceMethodType.getBytecodeInvokeDynamicSignature(cg)));
|
||||
ConstantMethodType lambdaMethodType = new ConstantMethodType(this.cp.addUtf8(interfaceMethodType.getBytecodeInvokeDynamicSignature(cg, rs)));
|
||||
int implMethodKind = 7; // 7 = InvokeSpecial @see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.5
|
||||
ConstantMethodHandle implMethod = new ConstantMethodHandle(implMethodKind,cg.getConstantPool().addMethodref(lambdaMethod)); //Das zweite Argument ist der MethodRef zur LambdaMethode
|
||||
|
||||
@ -96,7 +100,7 @@ public class DHBWInstructionFactory extends InstructionFactory{
|
||||
for(int i = 0; i<arguments.size();i++){
|
||||
argumentsArray[i] = arguments.get(i);
|
||||
}
|
||||
BootstrapMethod bMethod = new BootstrapMethod(lambdaMetafactoryHandle, arguments.size(), argumentsArray);
|
||||
BootstrapMethod bMethod = new BootstrapMethod(lambdaMetafactoryHandle, argumentsArray);
|
||||
|
||||
int index;
|
||||
|
||||
@ -135,11 +139,6 @@ public class DHBWInstructionFactory extends InstructionFactory{
|
||||
return new INVOKEDYNAMIC(index);
|
||||
}
|
||||
|
||||
public LocalVariableInstruction createLoad(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) {
|
||||
int index = 1; //TODO: Hier muss ein Logger her, welcher aufzeichnet, an welcher Position welche Variable liegt.
|
||||
return InstructionFactory.createLoad(bytecodeType, index);
|
||||
}
|
||||
|
||||
public static Type createObjectType() {
|
||||
return new org.apache.commons.bcel6.generic.ObjectType("java.lang.Object");
|
||||
}
|
||||
|
@ -1,36 +1,74 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.commons.bcel6.classfile.Attribute;
|
||||
import org.apache.commons.bcel6.classfile.ConstantPool;
|
||||
import org.apache.commons.bcel6.classfile.ConstantUtf8;
|
||||
import org.apache.commons.bcel6.classfile.Method;
|
||||
import org.apache.commons.bcel6.classfile.Signature;
|
||||
import org.apache.commons.bcel6.classfile.StackMap;
|
||||
import org.apache.commons.bcel6.classfile.StackMapEntry;
|
||||
import org.apache.commons.bcel6.classfile.Visitor;
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.ConstantPoolGen;
|
||||
import org.apache.commons.bcel6.generic.Instruction;
|
||||
import org.apache.commons.bcel6.generic.InstructionFactory;
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.LocalVariableInstruction;
|
||||
import org.apache.commons.bcel6.generic.MethodGen;
|
||||
import org.apache.commons.bcel6.generic.StackMapTableGen;
|
||||
import org.apache.commons.bcel6.generic.Type;
|
||||
|
||||
import org.apache.commons.bcel6.Const;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.stackmaptable.CodeHelper;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
|
||||
public class MethodGenerator extends MethodGen{
|
||||
|
||||
private Map<String, Integer> storeIndexes = new HashMap<>();
|
||||
|
||||
public MethodGenerator(int access_flags, Type return_type, Type[] arg_types, String[] arg_names, String method_name,
|
||||
String class_name, InstructionList il, ConstantPoolGen cp) {
|
||||
String class_name, InstructionList il, ConstantPoolGen cp) {
|
||||
super(access_flags, return_type, arg_types, arg_names, method_name, class_name, il, cp);
|
||||
|
||||
for(String name: arg_names){
|
||||
getStoreIndex(name);
|
||||
}
|
||||
}
|
||||
|
||||
public Method createMethod(ClassGenerator cg, ParameterList parameter, de.dhbwstuttgart.syntaxtree.type.Type retType, Block block){
|
||||
public Method createMethod(ClassGenerator cg, ParameterList parameter, de.dhbwstuttgart.syntaxtree.type.Type retType, Block block, TypeinferenceResultSet rs){
|
||||
MethodGen method = this;
|
||||
DHBWInstructionFactory factory = cg.getInstructionFactory();
|
||||
|
||||
InstructionList blockInstructions = block.genByteCode(cg);
|
||||
InstructionList blockInstructions = block.genByteCode(cg, rs);
|
||||
InstructionList il = this.getInstructionList();
|
||||
|
||||
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
|
||||
//Ein return Statement anfügen, falls nicht vorhanden:
|
||||
//TODO: Das ist schlecht! Der Parser oder der Typinferenzalgorithmus muss dafür sorgen, dass sich in jeder Methode ein Return befindet.
|
||||
if (block.get_Statement().size() == 0) { il.append(factory.createReturn( org.apache.commons.bcel6.generic.Type.VOID)); }
|
||||
else {
|
||||
if (!(block.get_Statement().lastElement() instanceof Return)) { il.append(factory.createReturn( org.apache.commons.bcel6.generic.Type.VOID)); }
|
||||
if (!(block.get_Statement().lastElement() instanceof Return) &&
|
||||
this.getType().equals(org.apache.commons.bcel6.generic.Type.VOID)) {
|
||||
il.append(factory.createReturn( org.apache.commons.bcel6.generic.Type.VOID));
|
||||
}
|
||||
}
|
||||
|
||||
method.stripAttributes(true);
|
||||
@ -39,13 +77,38 @@ public class MethodGenerator extends MethodGen{
|
||||
//Die korrekte Signatur für die Methode anhängen. Hier sind dann auch die Parameter von RefTypes enthalten:
|
||||
String paramTypesSig = "(";
|
||||
for(FormalParameter p : parameter){
|
||||
paramTypesSig += p.getType().getBytecodeSignature(cg);
|
||||
paramTypesSig += p.getType().getBytecodeSignature(cg, rs);
|
||||
|
||||
Logger.getLogger("MethodGenerator").error(paramTypesSig, Section.CODEGEN);
|
||||
}
|
||||
paramTypesSig += ")";
|
||||
String retTypeSig = retType.getBytecodeSignature(cg);
|
||||
String retTypeSig = retType.getBytecodeSignature(cg, rs);
|
||||
|
||||
method.addAttribute(factory.createSignatureAttribute(paramTypesSig+retTypeSig));
|
||||
|
||||
StackMap stackMap = new StackMapTableGen(this, cp).getStackMap();
|
||||
if(stackMap != null)method.addCodeAttribute(stackMap);
|
||||
|
||||
return method.getMethod();
|
||||
}
|
||||
|
||||
public LocalVariableInstruction createLoad(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) {
|
||||
return InstructionFactory.createLoad(bytecodeType, getStoreIndex(variableName));
|
||||
}
|
||||
|
||||
public LocalVariableInstruction createStore(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) {
|
||||
return InstructionFactory.createStore(bytecodeType, getStoreIndex(variableName));
|
||||
}
|
||||
|
||||
public Integer getStoreIndex(String variableName) {
|
||||
if(storeIndexes.get(variableName) == null){
|
||||
Integer index = storeIndexes.size()+1;
|
||||
storeIndexes.put(variableName, index);
|
||||
}
|
||||
|
||||
return storeIndexes.get(variableName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
710
src/de/dhbwstuttgart/bytecode/stackmaptable/CodeHelper.java
Normal file
710
src/de/dhbwstuttgart/bytecode/stackmaptable/CodeHelper.java
Normal file
@ -0,0 +1,710 @@
|
||||
package de.dhbwstuttgart.bytecode.stackmaptable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.commons.bcel6.generic.ALOAD;
|
||||
import org.apache.commons.bcel6.generic.ASTORE;
|
||||
import org.apache.commons.bcel6.generic.ArrayType;
|
||||
import org.apache.commons.bcel6.generic.BasicType;
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.ConstantPoolGen;
|
||||
import org.apache.commons.bcel6.generic.DSTORE;
|
||||
import org.apache.commons.bcel6.generic.GETFIELD;
|
||||
import org.apache.commons.bcel6.generic.GotoInstruction;
|
||||
import org.apache.commons.bcel6.generic.IINC;
|
||||
import org.apache.commons.bcel6.generic.INVOKEDYNAMIC;
|
||||
import org.apache.commons.bcel6.generic.INVOKEINTERFACE;
|
||||
import org.apache.commons.bcel6.generic.Instruction;
|
||||
import org.apache.commons.bcel6.generic.InstructionHandle;
|
||||
import org.apache.commons.bcel6.Const;
|
||||
import org.apache.commons.bcel6.classfile.ConstantPool;
|
||||
import org.apache.commons.bcel6.classfile.StackMapEntry;
|
||||
import org.apache.commons.bcel6.classfile.StackMapType;
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.InstructionTargeter;
|
||||
import org.apache.commons.bcel6.generic.InvokeInstruction;
|
||||
import org.apache.commons.bcel6.generic.LDC;
|
||||
import org.apache.commons.bcel6.generic.NEW;
|
||||
import org.apache.commons.bcel6.generic.ObjectType;
|
||||
import org.apache.commons.bcel6.generic.PUTFIELD;
|
||||
import org.apache.commons.bcel6.generic.ReferenceType;
|
||||
import org.apache.commons.bcel6.generic.StoreInstruction;
|
||||
import org.apache.commons.bcel6.generic.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.MethodGenerator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
class JVMState{
|
||||
|
||||
HashMap<Integer, StackItem> localVars = new HashMap<>();
|
||||
Stack<StackItem> stack = new Stack();
|
||||
|
||||
public StackItem getLocalType(int index) {
|
||||
return localVars.get(index);
|
||||
}
|
||||
|
||||
public void set(int index, StackItem objectRef) {
|
||||
localVars.put(index, objectRef);
|
||||
}
|
||||
|
||||
public void push(StackItem si){
|
||||
|
||||
}
|
||||
|
||||
void pop(int i){
|
||||
|
||||
}
|
||||
|
||||
public StackItem pop() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Menge<StackMapType> getStackTypes(ConstantPoolGen cp){
|
||||
Menge<StackMapType> ret = new Menge<StackMapType>();
|
||||
for(StackItem si : stack){
|
||||
ret.add(si.getType(cp));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Menge<StackMapType> getLocalTypes(ConstantPoolGen cp) {
|
||||
Menge<StackMapType> ret = new Menge<StackMapType>();
|
||||
//TODO
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
interface StackItem{
|
||||
public static final StackItem NULL = new StackItemNull();
|
||||
public static final StackItem INTEGER = new StackItemType(BasicType.INT);
|
||||
public static final StackItem FLOAT = new StackItemType(BasicType.FLOAT);
|
||||
public static final StackItem LONG = new StackItemType(BasicType.LONG);
|
||||
public static final StackItem DOUBLE = new StackItemType(BasicType.DOUBLE);
|
||||
public static final StackItem TOP = new StackItemTop();
|
||||
|
||||
StackMapType getType(ConstantPoolGen cp);
|
||||
}
|
||||
|
||||
class StackItemNull implements StackItem{
|
||||
|
||||
@Override
|
||||
public StackMapType getType(ConstantPoolGen cp) {
|
||||
return new StackMapType(Const.ITEM_Null, 0, cp.getConstantPool());
|
||||
}
|
||||
}
|
||||
class StackItemType implements StackItem{
|
||||
|
||||
Type t = null;
|
||||
|
||||
//TODO: BasicType kann auch Void sein, dann ändert sich nichts am Stack
|
||||
public StackItemType(BasicType b){
|
||||
t=b;
|
||||
}
|
||||
public StackItemType(ReferenceType r){
|
||||
t=r;
|
||||
}
|
||||
public StackItemType(Type t){
|
||||
t=t;
|
||||
}
|
||||
@Override
|
||||
public StackMapType getType(ConstantPoolGen cp) {
|
||||
if(t instanceof BasicType){
|
||||
return null;//TODO
|
||||
}else if(t instanceof ObjectType){
|
||||
int classInfo = cp.addClass(((ObjectType)t));
|
||||
return new StackMapType(Const.ITEM_Object,classInfo,cp.getConstantPool());
|
||||
}else if(t instanceof ArrayType){
|
||||
return null; //TODO
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
class StackItemTop implements StackItem{
|
||||
|
||||
@Override
|
||||
public StackMapType getType(ConstantPoolGen cp) {
|
||||
return new StackMapType(Const.ITEM_Bogus,0,cp.getConstantPool());
|
||||
}
|
||||
|
||||
}
|
||||
class StackItemUninitialized implements StackItem{
|
||||
private NEW newIns;
|
||||
private InstructionHandle handle;
|
||||
public StackItemUninitialized(NEW newInstruction, InstructionHandle instructionHandle){
|
||||
newIns = newInstruction;
|
||||
handle = instructionHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackMapType getType(ConstantPoolGen cp) {
|
||||
return new StackMapType(Const.ITEM_NewObject,handle.getPosition(),cp.getConstantPool());
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
class StackItemObject implements StackItem{
|
||||
public StackItemObject(String objName){
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class CodeHelper {
|
||||
|
||||
private ArrayList<Integer> outputStack = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Generiert die StackMapEntrys zu einer gegebenen Methode
|
||||
* @param forCode
|
||||
* @return
|
||||
*/
|
||||
public static Menge<StackMapEntry> getStackMapEntries(InstructionList forCode, ConstantPoolGen cp){
|
||||
Menge<StackMapEntry> ret = new Menge<>();
|
||||
JVMState state = new JVMState();
|
||||
if(forCode.isEmpty())return new Menge<>();
|
||||
forCode.setPositions(); //Otherwise InstructionHandle positions are wrong
|
||||
Instruction[] instructions = forCode.getInstructions();
|
||||
InstructionHandle[] instructionHandles = forCode.getInstructionHandles();
|
||||
int lastPosition = 0;
|
||||
|
||||
for(InstructionHandle ih : forCode.getInstructionHandles()){
|
||||
getOutput(ih, state, cp);
|
||||
if(isFrameEndpoint(ih, forCode)){
|
||||
if(!state.stack.isEmpty()){
|
||||
StackMapEntry entry = generateFullFrame(ih.getPosition(),state, cp);
|
||||
ret.add(entry);
|
||||
}else{
|
||||
int offset = ih.getPosition()-lastPosition;
|
||||
ret.add(new StackMapEntry(Const.SAME_FRAME + offset, 0, null, null, cp.getConstantPool()));
|
||||
}
|
||||
lastPosition = ih.getPosition()+1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static StackMapEntry generateFullFrame(int bytecodeOffset, JVMState state, ConstantPoolGen cp){
|
||||
Menge<StackMapType> stackTypes = state.getStackTypes(cp);
|
||||
Menge<StackMapType> localTypes = state.getLocalTypes(cp);
|
||||
StackMapType[] st = null;
|
||||
StackMapType[] lt = null;
|
||||
if(!stackTypes.isEmpty())st = stackTypes.toArray();
|
||||
if(!localTypes.isEmpty())lt = localTypes.toArray();
|
||||
StackMapEntry ret = new StackMapEntry(Const.FULL_FRAME,bytecodeOffset, lt, st, cp.getConstantPool());
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Frame hört bei einem unconditionalBranch auf bzw. fängt bei dem Sprungziel eines Branches an.
|
||||
* @see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.10.1
|
||||
* @param position
|
||||
* @param inCode
|
||||
* @return
|
||||
*/
|
||||
private static boolean isFrameEndpoint(InstructionHandle position, InstructionList inCode){
|
||||
if(position.getInstruction() instanceof GotoInstruction){
|
||||
//Falls Instruktion ein unconditional Branch ist:
|
||||
return true;
|
||||
}
|
||||
for(InstructionHandle i : inCode.getInstructionHandles()){
|
||||
if(i.hasTargeters()){
|
||||
for(InstructionTargeter target : i.getTargeters()){
|
||||
if(target.containsTarget(position))return true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
if(i instanceof BranchInstruction){
|
||||
inCode.getInstructionHandles()[1].getTargeters()
|
||||
if(((BranchInstruction) i).containsTarget(position)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void getOutput(InstructionHandle instructionHandle, JVMState ret, ConstantPoolGen cp){
|
||||
/*
|
||||
* TODO:
|
||||
* Berechnet den Output auf den Stack und ändert den LocalVarState und den StackState je nach Instruktion ab
|
||||
*/
|
||||
Instruction ins = instructionHandle.getInstruction();
|
||||
int opcode = ins.getOpcode();
|
||||
StackItem t1,t2,t3,t4;
|
||||
switch (opcode) {
|
||||
case Const.NOP:
|
||||
case Const.INEG:
|
||||
case Const.LNEG:
|
||||
case Const.FNEG:
|
||||
case Const.DNEG:
|
||||
case Const.I2B:
|
||||
case Const.I2C:
|
||||
case Const.I2S:
|
||||
case Const.GOTO:
|
||||
case Const.RETURN:
|
||||
break;
|
||||
case Const.ACONST_NULL:
|
||||
ret.push(StackItem.NULL);
|
||||
break;
|
||||
case Const.ICONST_M1:
|
||||
case Const.ICONST_0:
|
||||
case Const.ICONST_1:
|
||||
case Const.ICONST_2:
|
||||
case Const.ICONST_3:
|
||||
case Const.ICONST_4:
|
||||
case Const.ICONST_5:
|
||||
case Const.BIPUSH:
|
||||
case Const.SIPUSH:
|
||||
case Const.ILOAD:
|
||||
ret.push(StackItem.INTEGER);
|
||||
break;
|
||||
case Const.LCONST_0:
|
||||
case Const.LCONST_1:
|
||||
case Const.LLOAD:
|
||||
ret.push(StackItem.LONG);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case Const.FCONST_0:
|
||||
case Const.FCONST_1:
|
||||
case Const.FCONST_2:
|
||||
case Const.FLOAD:
|
||||
ret.push(StackItem.FLOAT);
|
||||
break;
|
||||
case Const.DCONST_0:
|
||||
case Const.DCONST_1:
|
||||
case Const.DLOAD:
|
||||
ret.push(StackItem.DOUBLE);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case Const.LDC:
|
||||
LDC ldcIns = (LDC) ins;
|
||||
Type t = ldcIns.getType(cp);
|
||||
if(t.equals(Type.STRING)){
|
||||
ret.push(new StackItemType(Type.STRING));
|
||||
}else if(t.equals(Type.INT)){
|
||||
ret.push(StackItem.INTEGER);
|
||||
}else if(t.equals(Type.FLOAT)){
|
||||
ret.push(StackItem.FLOAT);
|
||||
}else if(t.equals(Type.DOUBLE)){
|
||||
ret.push(StackItem.DOUBLE);
|
||||
ret.push(StackItem.TOP);
|
||||
}else if(t.equals(Type.FLOAT)){
|
||||
ret.push(StackItem.LONG);
|
||||
ret.push(StackItem.TOP);
|
||||
}else if(t.equals(Type.CLASS)){
|
||||
ret.push(new StackItemType(Type.CLASS));
|
||||
}
|
||||
/*
|
||||
switch (item.type) {
|
||||
case ClassWriter.INT:
|
||||
ret.push(StackItem.INTEGER);
|
||||
break;
|
||||
case ClassWriter.StackItem.LONG:
|
||||
ret.push(StackItem.LONG);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case ClassWriter.StackItem.FLOAT:
|
||||
ret.push(StackItem.FLOAT);
|
||||
break;
|
||||
case ClassWriter.StackItem.DOUBLE:
|
||||
ret.push(StackItem.DOUBLE);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case ClassWriter.CLASS:
|
||||
ret.push(new StackItemOBJECT("java/lang/Class"));
|
||||
break;
|
||||
case ClassWriter.STR:
|
||||
ret.push(new StackItemOBJECT("java/lang/String"));
|
||||
break;
|
||||
case ClassWriter.MTYPE:
|
||||
ret.push(new StackItemOBJECT("java/lang/invoke/MethodType"));
|
||||
break;
|
||||
// case ClassWriter.HANDLE_BASE + [1..9]:
|
||||
default:
|
||||
ret.push(new StackItemOBJECT("java/lang/invoke/MethodHandle"));
|
||||
break;
|
||||
}
|
||||
*/
|
||||
break;
|
||||
case Const.ALOAD:
|
||||
ALOAD aloadIns = (ALOAD) ins;
|
||||
ret.push(ret.getLocalType(aloadIns.getIndex()));
|
||||
break;
|
||||
case Const.IALOAD:
|
||||
case Const.BALOAD:
|
||||
case Const.CALOAD:
|
||||
case Const.SALOAD:
|
||||
ret.pop(2);
|
||||
ret.push(StackItem.INTEGER);
|
||||
break;
|
||||
case Const.LALOAD:
|
||||
case Const.D2L:
|
||||
ret.pop(2);
|
||||
ret.push(StackItem.LONG);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case Const.FALOAD:
|
||||
ret.pop(2);
|
||||
ret.push(StackItem.FLOAT);
|
||||
break;
|
||||
case Const.DALOAD:
|
||||
case Const.L2D:
|
||||
ret.pop(2);
|
||||
ret.push(StackItem.DOUBLE);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case Const.AALOAD:
|
||||
ret.pop(1);
|
||||
StackItem arrayReference = ret.pop();
|
||||
ret.push(arrayReference); //TODO: Fixen, es darf nicht die ArrayReference sonder der Typ eines Elements des Arrays auf den Stack
|
||||
//ret.push(ELEMENT_OF + t1);
|
||||
break;
|
||||
case Const.ISTORE:
|
||||
case Const.FSTORE:
|
||||
case Const.ASTORE:
|
||||
StoreInstruction storeIns = (StoreInstruction)ins;
|
||||
t1 = ret.pop();
|
||||
ret.set(storeIns.getIndex(), t1);
|
||||
if (storeIns.getIndex() > 0) {
|
||||
t2 = ret.getLocalType(storeIns.getIndex() - 1);
|
||||
// if t2 is of kind STACK or LOCAL we cannot know its size!
|
||||
if (t2 == StackItem.LONG || t2 == StackItem.DOUBLE) {
|
||||
ret.set(storeIns.getIndex() - 1, StackItem.TOP);
|
||||
}
|
||||
//TODO:
|
||||
/*else if ((t2 & KIND) != BASE) {
|
||||
set(arg - 1, t2 | StackItem.TOP_IF_StackItem.LONG_OR_StackItem.DOUBLE);
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case Const.LSTORE:
|
||||
case Const.DSTORE:
|
||||
StoreInstruction largeStoreIns = (StoreInstruction)ins;
|
||||
ret.pop(1);
|
||||
t1 = ret.pop();
|
||||
ret.set(largeStoreIns.getIndex(), t1);
|
||||
ret.set(largeStoreIns.getIndex() + 1, StackItem.TOP);
|
||||
if (largeStoreIns.getIndex() > 0) {
|
||||
t2 = ret.getLocalType(largeStoreIns.getIndex() - 1);
|
||||
// if t2 is of kind STACK or LOCAL we cannot know its size!
|
||||
if (t2 == StackItem.LONG || t2 == StackItem.DOUBLE) {
|
||||
ret.set(largeStoreIns.getIndex() - 1, StackItem.TOP);
|
||||
} //TODO:
|
||||
/*else if ((t2 & KIND) != BASE) {
|
||||
set(arg - 1, t2 | StackItem.TOP_IF_StackItem.LONG_OR_StackItem.DOUBLE);
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case Const.IASTORE:
|
||||
case Const.BASTORE:
|
||||
case Const.CASTORE:
|
||||
case Const.SASTORE:
|
||||
case Const.FASTORE:
|
||||
case Const.AASTORE:
|
||||
ret.pop(3);
|
||||
break;
|
||||
case Const.LASTORE:
|
||||
case Const.DASTORE:
|
||||
ret.pop(4);
|
||||
break;
|
||||
case Const.POP:
|
||||
case Const.IFEQ:
|
||||
case Const.IFNE:
|
||||
case Const.IFLT:
|
||||
case Const.IFGE:
|
||||
case Const.IFGT:
|
||||
case Const.IFLE:
|
||||
case Const.IRETURN:
|
||||
case Const.FRETURN:
|
||||
case Const.ARETURN:
|
||||
case Const.TABLESWITCH:
|
||||
case Const.LOOKUPSWITCH:
|
||||
case Const.ATHROW:
|
||||
case Const.MONITORENTER:
|
||||
case Const.MONITOREXIT:
|
||||
case Const.IFNULL:
|
||||
case Const.IFNONNULL:
|
||||
ret.pop(1);
|
||||
break;
|
||||
case Const.POP2:
|
||||
case Const.IF_ICMPEQ:
|
||||
case Const.IF_ICMPNE:
|
||||
case Const.IF_ICMPLT:
|
||||
case Const.IF_ICMPGE:
|
||||
case Const.IF_ICMPGT:
|
||||
case Const.IF_ICMPLE:
|
||||
case Const.IF_ACMPEQ:
|
||||
case Const.IF_ACMPNE:
|
||||
case Const.LRETURN:
|
||||
case Const.DRETURN:
|
||||
ret.pop(2);
|
||||
break;
|
||||
case Const.DUP:
|
||||
t1 = ret.pop();
|
||||
ret.push(t1);
|
||||
ret.push(t1);
|
||||
break;
|
||||
case Const.DUP_X1:
|
||||
t1 = ret.pop();
|
||||
t2 = ret.pop();
|
||||
ret.push(t1);
|
||||
ret.push(t2);
|
||||
ret.push(t1);
|
||||
break;
|
||||
case Const.DUP_X2:
|
||||
t1 = ret.pop();
|
||||
t2 = ret.pop();
|
||||
t3 = ret.pop();
|
||||
ret.push(t1);
|
||||
ret.push(t3);
|
||||
ret.push(t2);
|
||||
ret.push(t1);
|
||||
break;
|
||||
case Const.DUP2:
|
||||
t1 = ret.pop();
|
||||
t2 = ret.pop();
|
||||
ret.push(t2);
|
||||
ret.push(t1);
|
||||
ret.push(t2);
|
||||
ret.push(t1);
|
||||
break;
|
||||
case Const.DUP2_X1:
|
||||
t1 = ret.pop();
|
||||
t2 = ret.pop();
|
||||
t3 = ret.pop();
|
||||
ret.push(t2);
|
||||
ret.push(t1);
|
||||
ret.push(t3);
|
||||
ret.push(t2);
|
||||
ret.push(t1);
|
||||
break;
|
||||
case Const.DUP2_X2:
|
||||
t1 = ret.pop();
|
||||
t2 = ret.pop();
|
||||
t3 = ret.pop();
|
||||
t4 = ret.pop();
|
||||
ret.push(t2);
|
||||
ret.push(t1);
|
||||
ret.push(t4);
|
||||
ret.push(t3);
|
||||
ret.push(t2);
|
||||
ret.push(t1);
|
||||
break;
|
||||
case Const.SWAP:
|
||||
t1 = ret.pop();
|
||||
t2 = ret.pop();
|
||||
ret.push(t1);
|
||||
ret.push(t2);
|
||||
break;
|
||||
case Const.IADD:
|
||||
case Const.ISUB:
|
||||
case Const.IMUL:
|
||||
case Const.IDIV:
|
||||
case Const.IREM:
|
||||
case Const.IAND:
|
||||
case Const.IOR:
|
||||
case Const.IXOR:
|
||||
case Const.ISHL:
|
||||
case Const.ISHR:
|
||||
case Const.IUSHR:
|
||||
case Const.L2I:
|
||||
case Const.D2I:
|
||||
case Const.FCMPL:
|
||||
case Const.FCMPG:
|
||||
ret.pop(2);
|
||||
ret.push(StackItem.INTEGER);
|
||||
break;
|
||||
case Const.LADD:
|
||||
case Const.LSUB:
|
||||
case Const.LMUL:
|
||||
case Const.LDIV:
|
||||
case Const.LREM:
|
||||
case Const.LAND:
|
||||
case Const.LOR:
|
||||
case Const.LXOR:
|
||||
ret.pop(4);
|
||||
ret.push(StackItem.LONG);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case Const.FADD:
|
||||
case Const.FSUB:
|
||||
case Const.FMUL:
|
||||
case Const.FDIV:
|
||||
case Const.FREM:
|
||||
case Const.L2F:
|
||||
case Const.D2F:
|
||||
ret.pop(2);
|
||||
ret.push(StackItem.FLOAT);
|
||||
break;
|
||||
case Const.DADD:
|
||||
case Const.DSUB:
|
||||
case Const.DMUL:
|
||||
case Const.DDIV:
|
||||
case Const.DREM:
|
||||
ret.pop(4);
|
||||
ret.push(StackItem.DOUBLE);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case Const.LSHL:
|
||||
case Const.LSHR:
|
||||
case Const.LUSHR:
|
||||
ret.pop(3);
|
||||
ret.push(StackItem.LONG);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case Const.IINC:
|
||||
ret.set(((IINC)ins).getIndex(), StackItem.INTEGER);
|
||||
break;
|
||||
case Const.I2L:
|
||||
case Const.F2L:
|
||||
ret.pop(1);
|
||||
ret.push(StackItem.LONG);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case Const.I2F:
|
||||
ret.pop(1);
|
||||
ret.push(StackItem.FLOAT);
|
||||
break;
|
||||
case Const.I2D:
|
||||
case Const.F2D:
|
||||
ret.pop(1);
|
||||
ret.push(StackItem.DOUBLE);
|
||||
ret.push(StackItem.TOP);
|
||||
break;
|
||||
case Const.F2I:
|
||||
case Const.ARRAYLENGTH:
|
||||
case Const.INSTANCEOF:
|
||||
ret.pop(1);
|
||||
ret.push(StackItem.INTEGER);
|
||||
break;
|
||||
case Const.LCMP:
|
||||
case Const.DCMPL:
|
||||
case Const.DCMPG:
|
||||
ret.pop(4);
|
||||
ret.push(StackItem.INTEGER);
|
||||
break;
|
||||
case Const.JSR:
|
||||
case Const.RET:
|
||||
throw new RuntimeException(
|
||||
"JSR/RET are not supported with computeFrames option"); //TODO: Fehlermeldung anpassen
|
||||
case Const.GETSTATIC:
|
||||
//ret.push(cw, item.strVal3); //TODO
|
||||
break;
|
||||
case Const.PUTSTATIC:
|
||||
//ret.pop(item.strVal3); //TODO
|
||||
break;
|
||||
case Const.GETFIELD:
|
||||
GETFIELD getfieldIns = (GETFIELD) ins;
|
||||
ret.pop(1);
|
||||
ret.push(new StackItemType(getfieldIns.getFieldType(cp)));
|
||||
break;
|
||||
case Const.PUTFIELD:
|
||||
PUTFIELD putfieldIns = (PUTFIELD) ins;
|
||||
ret.pop(putfieldIns.consumeStack(cp));
|
||||
break;
|
||||
case Const.INVOKEVIRTUAL:
|
||||
case Const.INVOKESPECIAL:
|
||||
case Const.INVOKESTATIC:
|
||||
case Const.INVOKEINTERFACE:
|
||||
case Const.INVOKEDYNAMIC:
|
||||
InvokeInstruction invokeIns = (InvokeInstruction) ins;
|
||||
ret.pop(invokeIns.consumeStack(cp));
|
||||
/*
|
||||
* TODO:
|
||||
* Hier return new StackItemOBJECT(returnTypeDerMethode);
|
||||
* returnTypeDerMethode bestimmen indem man im ConstantPool nach dem Argument für die Instruktion nachsieht.
|
||||
* Wie kann man bestimmen, ob es sich um Object oder primären Datentyp handelt. bcel-Typen verwenden? Müsste dann weiter oben auch gepatcht werden.
|
||||
*/
|
||||
/*
|
||||
ret.pop(item.strVal3);
|
||||
|
||||
if (opcode != Const.INVOKESTATIC) {
|
||||
t1 = ret.pop();
|
||||
if (opcode == Const.INVOKESPECIAL
|
||||
&& item.strVal2.charAt(0) == '<') {
|
||||
init(t1);
|
||||
}
|
||||
}
|
||||
|
||||
ret.push(cw, item.strVal3);
|
||||
*/
|
||||
Type retType = invokeIns.getReturnType(cp);
|
||||
if(retType instanceof BasicType){
|
||||
ret.push(new StackItemType((BasicType)retType));
|
||||
}else if(retType instanceof ArrayType){
|
||||
//TODO
|
||||
}else if(retType instanceof ReferenceType){
|
||||
ret.push(new StackItemType((ReferenceType) retType));
|
||||
}
|
||||
break;
|
||||
case Const.NEW:
|
||||
NEW newIns = (NEW) ins;
|
||||
ret.push(new StackItemUninitialized(newIns, instructionHandle));
|
||||
//ret.push(UNINITIALIZED | cw.addUninitializedType(item.strVal1, arg));
|
||||
break;
|
||||
/*
|
||||
case Const.NEWARRAY:
|
||||
ret.pop();
|
||||
switch (arg) {
|
||||
case Const.T_BOOLEAN:
|
||||
ret.push(ARRAY_OF | BOOLEAN);
|
||||
break;
|
||||
case Const.T_CHAR:
|
||||
ret.push(ARRAY_OF | CHAR);
|
||||
break;
|
||||
case Const.T_BYTE:
|
||||
ret.push(ARRAY_OF | BYTE);
|
||||
break;
|
||||
case Const.T_SHORT:
|
||||
ret.push(ARRAY_OF | SHORT);
|
||||
break;
|
||||
case Const.T_INT:
|
||||
ret.push(ARRAY_OF | StackItem.INTEGER);
|
||||
break;
|
||||
case Const.T_StackItem.FLOAT:
|
||||
ret.push(ARRAY_OF | StackItem.FLOAT);
|
||||
break;
|
||||
case Const.T_StackItem.DOUBLE:
|
||||
ret.push(ARRAY_OF | StackItem.DOUBLE);
|
||||
break;
|
||||
// case Const.T_StackItem.LONG:
|
||||
default:
|
||||
ret.push(ARRAY_OF | StackItem.LONG);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Const.ANEWARRAY:
|
||||
String s = item.strVal1;
|
||||
ret.pop();
|
||||
if (s.charAt(0) == '[') {
|
||||
ret.push(cw, '[' + s);
|
||||
} else {
|
||||
ret.push(ARRAY_OF | OBJECT | cw.addType(s));
|
||||
}
|
||||
break;
|
||||
case Const.CHECKCAST:
|
||||
s = item.strVal1;
|
||||
ret.pop();
|
||||
if (s.charAt(0) == '[') {
|
||||
ret.push(cw, s);
|
||||
} else {
|
||||
ret.push(OBJECT | cw.addType(s));
|
||||
}
|
||||
break;
|
||||
// case Const.MULTIANEWARRAY:
|
||||
default:
|
||||
ret.pop(arg);
|
||||
ret.push(cw, item.strVal1);
|
||||
break;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.logger.LoggerConfiguration;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -34,13 +35,13 @@ public class ConsoleInterface {
|
||||
/////////////////////////
|
||||
// Parsen:
|
||||
/////////////////////////
|
||||
compiler.parse(filenames);
|
||||
Menge<SourceFile> sourceFiles = compiler.parse(filenames);
|
||||
|
||||
/////////////////////////
|
||||
// Typrekonstruktion:
|
||||
/////////////////////////
|
||||
try{
|
||||
resultSet = compiler.typeReconstruction();
|
||||
resultSet = compiler.typeReconstruction(sourceFiles);
|
||||
}catch(TypeinferenceException texc){
|
||||
texc.printStackTrace();
|
||||
fail("Fehler bei Typinferenzalgorithmus. Message: "+texc.getMessage());
|
||||
|
@ -1,9 +1,6 @@
|
||||
// ino.module.MyCompiler.8569.package
|
||||
|
||||
package de.dhbwstuttgart.core;
|
||||
// ino.end
|
||||
|
||||
|
||||
// ino.module.MyCompiler.8569.import
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -42,73 +39,35 @@ import de.dhbwstuttgart.typeinference.FunVoidNInterface;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResults;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.ParserError;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
|
||||
// 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
|
||||
public class MyCompiler implements MyCompilerAPI{
|
||||
// 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(MyCompiler.class.getName());
|
||||
// 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
|
||||
|
||||
public Menge<Pair> testPair = null;
|
||||
|
||||
// ino.attribute.m_AbstractSyntaxTree.21280.decldescription type=javadoc
|
||||
/**
|
||||
* Der abstrake Syntaxbaum
|
||||
* <br/>Autor: J�rg B�uerle
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.m_AbstractSyntaxTree.21280.declaration
|
||||
private Menge<SourceFile> m_AbstractSyntaxTree = new Menge<SourceFile>();
|
||||
// ino.end
|
||||
|
||||
// ino.method.MyCompiler.21283.defdescription type=javadoc
|
||||
/**
|
||||
* Author: J�rg B�uerle<br/>
|
||||
* Der private Konstruktor. Es soll von au�en kein Compiler angelegt werden
|
||||
* k�nnen, sondern nur eine API zur Verf�gung gestellt werden.
|
||||
* @param logger Konfiguration für Debug Ausgabe TODO
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.MyCompiler.21283.definition
|
||||
private MyCompiler()
|
||||
// ino.end
|
||||
// ino.method.MyCompiler.21283.body
|
||||
{
|
||||
private MyCompiler(){
|
||||
this.init();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.getAPI.21286.defdescription type=javadoc
|
||||
|
||||
/**
|
||||
* Author: Jörg Bäuerle<br/>
|
||||
* Stellt eine neue Instanz der CompilerAPI zur Verf�gung.
|
||||
@ -116,116 +75,11 @@ public class MyCompiler implements MyCompilerAPI
|
||||
* um eine Quellcode-Datei zu kompilieren.
|
||||
* @return Die Compiler-API
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.getAPI.21286.definition
|
||||
public static MyCompilerAPI getAPI(LoggerConfiguration loggerConfig)
|
||||
// ino.end
|
||||
// ino.method.getAPI.21286.body
|
||||
{
|
||||
public static MyCompilerAPI getAPI(LoggerConfiguration loggerConfig){
|
||||
Logger.setStandardConfiguration(loggerConfig);
|
||||
return new MyCompiler();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
public Menge<Pair> testPair = null;
|
||||
|
||||
// ino.method.wandleGeneric2RefType.21289.defdescription type=javadoc
|
||||
/**
|
||||
* Author: Thomas Ott<br/>
|
||||
* Ersetzt in der Superklassenparameterliste einer Klasse, diejenigen
|
||||
* <code>GenericTypeVars</code>, 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.<br/>
|
||||
* Bsp.: class JoergsTolleKlasse<A> extends MartinsSuperklasse<Integer, B>
|
||||
* <br/>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(Menge<Type> Parameter, Menge<Class> 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().toString(), 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
|
||||
@ -236,246 +90,19 @@ public class MyCompiler implements MyCompilerAPI
|
||||
* @throws IOException
|
||||
* @throws JavaParser.yyException
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.parse.21292.definition
|
||||
private void parse_backup(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
|
||||
// Menge 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;
|
||||
Menge<mycompiler.myclass.Field> tempMengeFieldDecl;
|
||||
mycompiler.myclass.Field 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
|
||||
tempMengeFieldDecl = tempKlassBody.getFields();
|
||||
for( int k = 0; k < tempMengeFieldDecl.size(); k++ )
|
||||
{
|
||||
tempFieldDecl = tempMengeFieldDecl.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.setDeclIdMenge( Konstruktor.getDeclIdMenge() );
|
||||
// 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));
|
||||
//Methode.setReturnType( new TypePlaceholder("###NEU###") );
|
||||
// ###########################################################
|
||||
|
||||
// Element an der Position k durch neues ersetzen!
|
||||
tempMengeFieldDecl.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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Debugg-Infos
|
||||
parserlog.debug("");
|
||||
parserlog.debug("T->NEUE Felddeklarationen f�r die Klasse:" + strKlasse);
|
||||
parserlog.debug( "-----------------------------------------");
|
||||
for( int k = 0; k < tempMengeFieldDecl.size(); k++ )
|
||||
{
|
||||
tempFieldDecl = tempMengeFieldDecl.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;
|
||||
Menge<FormalParameter> tempVFktPara;
|
||||
FormalParameter tempFP;
|
||||
Method tempMethod;
|
||||
Type tempReturn;
|
||||
Type tempType;
|
||||
for( int k = 0; k < tempMengeFieldDecl.size(); k++ )
|
||||
{
|
||||
tempFieldDecl = tempMengeFieldDecl.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
|
||||
|
||||
private void parse_backup(Reader reader) throws IOException, JavaParser.yyException{
|
||||
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementierte API-Methoden:
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ino.method.init.21295.defdescription type=javadoc
|
||||
/**
|
||||
* Author: J�rg B�uerle<br/>
|
||||
* Initialisiert den Compiler
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.init.21295.definition
|
||||
public void init()
|
||||
// ino.end
|
||||
// ino.method.init.21295.body
|
||||
{
|
||||
public void init(){
|
||||
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<br/>
|
||||
* Ruft die Parse-Methode.
|
||||
@ -484,22 +111,13 @@ public class MyCompiler implements MyCompilerAPI
|
||||
* @throws IOException Wenn was schief l�uft.
|
||||
* @throws JavaParser.yyException Wenn ein Fehler beim Parsen auftritt.
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.parse.21298.definition
|
||||
public SourceFile parse(File file)
|
||||
throws FileNotFoundException, IOException, JavaParser.yyException
|
||||
// ino.end
|
||||
// ino.method.parse.21298.body
|
||||
{
|
||||
public SourceFile parse(File file) throws FileNotFoundException, IOException, JavaParser.yyException{
|
||||
FileReader fr = new FileReader(file);
|
||||
SourceFile ret = this.parse2SyntaxTree(fr);
|
||||
this.m_AbstractSyntaxTree.add(ret);
|
||||
fr.close();
|
||||
return ret;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.typeReconstruction.21304.defdescription type=javadoc
|
||||
|
||||
/**
|
||||
* Author: J�rg B�uerle<br/>
|
||||
* Ruft den Typrekonstruktionsalgorithmus auf.
|
||||
@ -508,16 +126,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
* ist. @throws CTypeReconstructionException Wenn ein Fehler bei der
|
||||
* Typrekonstruktion auftritt.
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.typeReconstruction.21304.definition
|
||||
public Menge<TypeinferenceResultSet> 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!");
|
||||
}
|
||||
public Menge<TypeinferenceResultSet> typeReconstruction(Menge<SourceFile> m_AbstractSyntaxTree) throws NullPointerException, CTypeReconstructionException{
|
||||
inferencelog.info("##########################################", Section.TYPEINFERENCE);
|
||||
inferencelog.info("# TypeReconstruction-Algorithmus - START #", Section.TYPEINFERENCE);
|
||||
inferencelog.info("##########################################\n", Section.TYPEINFERENCE);
|
||||
@ -535,7 +144,6 @@ public class MyCompiler implements MyCompilerAPI
|
||||
|
||||
return result;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
/**
|
||||
* Erstellt die FunN-Assumptions
|
||||
@ -551,53 +159,21 @@ public class MyCompiler implements MyCompilerAPI
|
||||
FunNInterface funN = new FunNInterface(i);
|
||||
ret.add(funN.getPublicFieldAssumptions());
|
||||
}
|
||||
for(int i = 0; i<6; i++){
|
||||
FunVoidNInterface funN = new FunVoidNInterface(i);
|
||||
ret.add(funN.getPublicFieldAssumptions());
|
||||
}
|
||||
|
||||
//Keine FunVoidInterfaces in den Assumptions.
|
||||
//for(int i = 0; i<6; i++){
|
||||
// FunVoidNInterface funN = new FunVoidNInterface(i);
|
||||
// ret.add(funN.getPublicFieldAssumptions());
|
||||
//}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: J�rg B�uerle<br/>
|
||||
* Generiert den Bytecode und das Class-File f�r den Syntaxbaum.
|
||||
* @throws NullPointerException Wenn noch kein abstrakter Syntaxbaum vorhanden
|
||||
* ist.
|
||||
|
||||
@Override
|
||||
public Menge<ClassFile> codeGeneration(ResultSet result)
|
||||
throws NullPointerException, JVMCodeException
|
||||
{
|
||||
if(m_AbstractSyntaxTree==null){
|
||||
throw new NullPointerException("Es wurde noch kein Abstrakter Syntaxbaum erstellt!");
|
||||
}
|
||||
codegenlog.info("Beginn der Codegenerierung ...");
|
||||
|
||||
Menge<ClassFile> ret = new Menge<ClassFile>();
|
||||
|
||||
for(SourceFile sf : m_AbstractSyntaxTree){
|
||||
ret.addAll(sf.codegen(result));
|
||||
}
|
||||
|
||||
codegenlog.info("Codegenerierung beendet!");
|
||||
return ret;
|
||||
}*/
|
||||
|
||||
|
||||
// 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
|
||||
{
|
||||
public static void main(String[] args){
|
||||
MyCompilerAPI compiler = MyCompiler.getAPI(new LoggerConfiguration());
|
||||
|
||||
// Hier koennten ggf. Aenderungen der Ausgabeeinstellungen
|
||||
@ -617,33 +193,9 @@ public class MyCompiler implements MyCompilerAPI
|
||||
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
|
||||
{
|
||||
public void setOutputDir(String dir){
|
||||
char c = dir.charAt(dir.length()-1);
|
||||
if (c != '/' & c != '\\') dir = dir + "/";
|
||||
OutputDir = dir;
|
||||
@ -652,112 +204,11 @@ public class MyCompiler implements MyCompilerAPI
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.getOutputDir.21319.definition
|
||||
public String getOutputDir()
|
||||
// ino.end
|
||||
// ino.method.getOutputDir.21319.body
|
||||
{
|
||||
public String getOutputDir(){
|
||||
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<declarations.size();j++){
|
||||
UsedId impDecl=declarations.elementAt(j);
|
||||
if(impDecl.getSimpleName().equals(typ)){
|
||||
ret=(impDecl.getQualifiedName().toString());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
// ino.end
|
||||
*/
|
||||
// ino.method.makeRefTypesFullyQualified.21325.defdescription type=javadoc
|
||||
/**
|
||||
* @author HOTI
|
||||
* Macht alle Referenzen auf Objekte zu fully qualified Names
|
||||
* p.ex Menge x; => de.dhbwstuttgart.typeinference.Menge 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(Menge<Type> 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)
|
||||
{
|
||||
Menge<Type> paras = refT.get_ParaList();
|
||||
for(int i = 0; i<paras.size();i++)
|
||||
{
|
||||
Type tt = paras.elementAt(i);
|
||||
if(tt instanceof GenericTypeVar)
|
||||
{
|
||||
GenericTypeVar gtv = (GenericTypeVar)tt;
|
||||
paras.set(i,TypePlaceholder.backdoorCreate(gtv.getName().toString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
makeGenericTypeVars2TypePlaceHolders(tt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(T instanceof IMatchable)
|
||||
{
|
||||
Type TT = ((IMatchable)T).getMatchType();
|
||||
makeGenericTypeVars2TypePlaceHolders(TT);
|
||||
}
|
||||
return T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parst den Inhalt einer Datei zu einem Syntaxbaum.
|
||||
*/
|
||||
@ -790,8 +241,10 @@ public class MyCompiler implements MyCompilerAPI
|
||||
|
||||
/**
|
||||
* Diese Funktion nimmt einen Menge von Dateinamen. Alle diese Dateien werden zu einem SyntaxBaum geparst.
|
||||
* @return
|
||||
*/
|
||||
public void parse(Menge<String> filenames) throws ParserError {
|
||||
public Menge<SourceFile> parse(Menge<String> filenames) throws ParserError {
|
||||
Menge<SourceFile> m_AbstractSyntaxTree = new Menge<SourceFile>();
|
||||
|
||||
for(String filename : filenames){
|
||||
StringBuffer fileData = new StringBuffer();
|
||||
@ -816,58 +269,26 @@ public class MyCompiler implements MyCompilerAPI
|
||||
|
||||
StringReader srcreader = new StringReader(fileData.toString());
|
||||
//Den aus der Datei ausgelesenen Quellcode zu einem Syntaxbaum parsen:
|
||||
this.m_AbstractSyntaxTree.add(parse2SyntaxTree(srcreader)); // Alle Dateien nacheinander hintereinander anhängen...
|
||||
|
||||
}
|
||||
/*
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
throw new TypinferenzException("Die übergebenen Dateien konnten nicht zum Parsen eingelesen werden.");
|
||||
}
|
||||
m_AbstractSyntaxTree.add(parse2SyntaxTree(srcreader)); // Alle Dateien nacheinander hintereinander anhängen...
|
||||
}
|
||||
|
||||
try {
|
||||
// und anschlieÃend zum Parsen übergeben.
|
||||
this.parse(gesamterSrc.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//throw new TypinferenzException("Fehler beim Parsen");
|
||||
}
|
||||
|
||||
*/
|
||||
return m_AbstractSyntaxTree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceFile parse(String sourceCode) {
|
||||
SourceFile ret = this.parse2SyntaxTree(new StringReader(sourceCode));
|
||||
this.m_AbstractSyntaxTree.add(ret);
|
||||
return ret;
|
||||
return parse2SyntaxTree(new StringReader(sourceCode));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menge<Menge<ByteCodeResult>> generateBytecode(TypeinferenceResultSet typeinferenceResult) {
|
||||
public Menge<ByteCodeResult> generateBytecode(Menge<SourceFile> m_AbstractSyntaxTree, TypeinferenceResults typeinferenceResults) {
|
||||
//SourceFile parsedFile = this.m_AbstractSyntaxTree.firstElement();
|
||||
//Class parsedClass = parsedFile.KlassenVektor.firstElement();
|
||||
Menge<Menge<ByteCodeResult>> ret = new Menge<>();
|
||||
for(SourceFile sf : this.m_AbstractSyntaxTree){
|
||||
ret.addAll(sf.generateBytecode(typeinferenceResult));
|
||||
Menge<ByteCodeResult> ret = new Menge<>();
|
||||
for(SourceFile sf : m_AbstractSyntaxTree){
|
||||
ret.addAll(sf.generateBytecode(typeinferenceResults));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
@ -15,6 +15,7 @@ import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.typeinference.ByteCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResults;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.ParserError;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
|
||||
@ -85,8 +86,7 @@ public interface MyCompilerAPI
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.typeReconstruction.21340.declaration
|
||||
public Menge<TypeinferenceResultSet> typeReconstruction()
|
||||
throws NullPointerException, TypeinferenceException;
|
||||
public Menge<TypeinferenceResultSet> typeReconstruction(Menge<SourceFile> m_AbstractSyntaxTree) throws NullPointerException, CTypeReconstructionException;
|
||||
// ino.end
|
||||
|
||||
// ino.method.setOutputDir.21349.decldescription type=javadoc
|
||||
@ -112,8 +112,9 @@ public interface MyCompilerAPI
|
||||
/**
|
||||
* Parst zusammenhängende JavaKlassen in verschiedenen Dateien.
|
||||
* @param filenames - Eine Liste von Quellcodedateien, welche gseparst werden sollen
|
||||
* @return
|
||||
*/
|
||||
public void parse(Menge<String> filenames) throws ParserError;
|
||||
public Menge<SourceFile> parse(Menge<String> filenames) throws ParserError;
|
||||
|
||||
/**
|
||||
* Parst den SourceCode einer Datei.
|
||||
@ -127,6 +128,6 @@ public interface MyCompilerAPI
|
||||
* Dafür müssen die Schritte Parsen und typeReconstruction ausgeführt werden.
|
||||
* @return
|
||||
*/
|
||||
public Menge<Menge<ByteCodeResult>> generateBytecode(TypeinferenceResultSet rs);
|
||||
public Menge<ByteCodeResult> generateBytecode(Menge<SourceFile> m_AbstractSyntaxTree, TypeinferenceResults typeinferenceResults);
|
||||
}
|
||||
// ino.end
|
||||
|
@ -94,6 +94,7 @@ public class Logger {
|
||||
|
||||
public static String getWholeLog(){
|
||||
String ret = "";
|
||||
LOG_HISTORY.removeIf((logLine)->logLine==null);
|
||||
Logger.LOG_HISTORY.sort((log1, log2)->log1.timestamp.compareTo(log2.timestamp));
|
||||
ret += Logger.LOG_HISTORY.toString();
|
||||
return ret;
|
||||
@ -127,11 +128,11 @@ class LogHistory extends ArrayList<LogLine>{
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
String ret = "";
|
||||
StringBuilder ret = new StringBuilder();
|
||||
for(LogLine l : this){
|
||||
ret += l.toString() + "\n";
|
||||
ret.append(l.toString() + "\n");
|
||||
}
|
||||
return ret;
|
||||
return ret.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,14 @@ package de.dhbwstuttgart.myexception;
|
||||
|
||||
public class NotImplementedException extends RuntimeException {
|
||||
|
||||
public NotImplementedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NotImplementedException() {
|
||||
super("Nicht implementiert");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -18,6 +18,7 @@ public class JavaClassName {
|
||||
|
||||
public JavaClassName(String name){
|
||||
if(name == null)throw new NullPointerException();
|
||||
|
||||
String[] names = name.split("[.]");
|
||||
boolean match = true;
|
||||
if(names.length == 1){
|
||||
|
@ -2298,7 +2298,7 @@ case 199:
|
||||
{
|
||||
de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nParser --> Zuweisung1!\n", Section.PARSER);
|
||||
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());
|
||||
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname(((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());*/
|
||||
@ -2324,7 +2324,7 @@ case 200:
|
||||
// line 1718 "./../src/de/dhbwstuttgart/parser/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());
|
||||
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname(((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());*/
|
||||
@ -2561,7 +2561,7 @@ case 228:
|
||||
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());
|
||||
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname(((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());*/
|
||||
@ -2593,7 +2593,7 @@ case 229:
|
||||
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());
|
||||
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname(((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());*/
|
||||
@ -2744,7 +2744,7 @@ case 242:
|
||||
yyVal = INSTVA;
|
||||
}
|
||||
else {
|
||||
LocalOrFieldVar Postincexpr = new LocalOrFieldVar(((UsedId)yyVals[0+yyTop]).getOffset(),((UsedId)yyVals[0+yyTop]).getVariableLength());
|
||||
LocalOrFieldVarOrClassname Postincexpr = new LocalOrFieldVarOrClassname(((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;
|
||||
|
@ -1693,7 +1693,7 @@ assignment :lefthandside assignmentoperator assignmentexpr
|
||||
{
|
||||
de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nParser --> Zuweisung1!\n", Section.PARSER);
|
||||
Assign Ass = new Assign($1.getOffset(),$1.getVariableLength());
|
||||
LocalOrFieldVar LOFV = new LocalOrFieldVar($1.getOffset(),$1.getVariableLength());
|
||||
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname($1.getOffset(),$1.getVariableLength());
|
||||
LOFV.set_UsedId($1);
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) Ass.setType(TypePlaceholder.fresh());
|
||||
@ -1717,7 +1717,7 @@ assignment :lefthandside assignmentoperator assignmentexpr
|
||||
| lefthandside assignmentoperator classinstancecreationexpression
|
||||
{
|
||||
Assign Ass =new Assign($1.getOffset(),$1.getVariableLength());
|
||||
LocalOrFieldVar LOFV = new LocalOrFieldVar($1.getOffset(),$1.getVariableLength());
|
||||
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname($1.getOffset(),$1.getVariableLength());
|
||||
LOFV.set_UsedId($1);
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) Ass.setType(TypePlaceholder.fresh());
|
||||
@ -1939,7 +1939,7 @@ methodinvocation:
|
||||
rec = new Receiver(INSTVA);
|
||||
}
|
||||
else if ($1.get_Name().size() == 2) {
|
||||
LocalOrFieldVar LOFV = new LocalOrFieldVar($1.getOffset(),$1.getVariableLength());
|
||||
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname($1.getOffset(),$1.getVariableLength());
|
||||
$1.removeLast();
|
||||
LOFV.set_UsedId($1);
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());
|
||||
@ -1969,7 +1969,7 @@ methodinvocation:
|
||||
rec = new Receiver(INSTVA);
|
||||
}
|
||||
else if ($1.get_Name().size() == 2) {
|
||||
LocalOrFieldVar LOFV = new LocalOrFieldVar($1.getOffset(),$1.getVariableLength());
|
||||
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname($1.getOffset(),$1.getVariableLength());
|
||||
$1.removeLast();
|
||||
LOFV.set_UsedId($1);
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());
|
||||
@ -2105,7 +2105,7 @@ postfixexpression :primary
|
||||
$$ = INSTVA;
|
||||
}
|
||||
else {
|
||||
LocalOrFieldVar Postincexpr = new LocalOrFieldVar($1.getOffset(),$1.getVariableLength());
|
||||
LocalOrFieldVarOrClassname Postincexpr = new LocalOrFieldVarOrClassname($1.getOffset(),$1.getVariableLength());
|
||||
Postincexpr.set_UsedId($1);
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) Postincexpr.setType(TypePlaceholder.fresh());
|
||||
$$=Postincexpr;
|
||||
|
@ -7,6 +7,10 @@ import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.ClassGen;
|
||||
import org.apache.commons.bcel6.generic.ConstantPoolGen;
|
||||
@ -24,8 +28,10 @@ import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.core.AClassOrInterface;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Static;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
@ -43,8 +49,7 @@ import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||||
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
@ -74,7 +79,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
* @param resultSet - Fehlende Typen im Syntaxbaum werden nach diesem ResultSet aufgelöst
|
||||
* @return
|
||||
*/
|
||||
public Menge<ByteCodeResult> genByteCode(TypeinferenceResultSet resultSet) {
|
||||
public ByteCodeResult genByteCode(TypeinferenceResults typeinferenceResults) {
|
||||
InstructionFactory _factory;
|
||||
DHBWConstantPoolGen _cp;
|
||||
ClassGenerator _cg;
|
||||
@ -85,7 +90,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
logger.debug("Test");
|
||||
|
||||
if(pkgName != null)throw new NotImplementedException();
|
||||
_cg = new ClassGenerator(name, this.getSuperClass(), name + ".java", Constants.ACC_PUBLIC , new String[] { }, resultSet); //letzter Parameter sind implementierte Interfaces
|
||||
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
|
||||
_cg = new ClassGenerator(name, this.getSuperClass(), name + ".java", constants , new String[] { }, typeinferenceResults); //letzter Parameter sind implementierte Interfaces
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new DHBWInstructionFactory(_cg, _cp);
|
||||
|
||||
@ -101,23 +107,18 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
}
|
||||
//Zuerst die Methoden und Felder abarbeiten:
|
||||
for(Method m : methods){
|
||||
m.genByteCode(_cg);
|
||||
m.genByteCode(_cg, this);
|
||||
}
|
||||
InstructionList fieldInitializations = new InstructionList();
|
||||
for(FieldDeclaration f : fieldDeclarations){
|
||||
fieldInitializations.append(f.genByteCode(_cg));
|
||||
fieldInitializations.append(f.genByteCode(_cg, typeinferenceResults.getTypeReconstructions().get(0)));
|
||||
}
|
||||
//Die Konstruktoren müssen die Feld initialisierungswerte beinhalten:
|
||||
for(Constructor c : constructors){
|
||||
c.genByteCode(_cg, fieldInitializations);
|
||||
}
|
||||
|
||||
ByteCodeResult code = new ByteCodeResult(_cg);
|
||||
results.add(code);
|
||||
|
||||
results.addAll(getGenericClasses(_cg));
|
||||
|
||||
return results;
|
||||
return new ByteCodeResult(_cg);
|
||||
}
|
||||
|
||||
private Menge<Type> superif = new Menge<Type>();
|
||||
@ -168,67 +169,38 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
{
|
||||
this.superif = superif;
|
||||
}
|
||||
|
||||
// ino.attribute.superclassid.23014.decldescription type=line
|
||||
// private Status status;
|
||||
// ino.end
|
||||
// ino.attribute.superclassid.23014.declaration
|
||||
public UsedId superclassid = (SourceFile.READ_OBJECT_SUPERCLASSES_FROM_JRE?UsedId.createFromQualifiedName("Object",-1):null);
|
||||
// ino.end
|
||||
// ino.attribute.class_block.23020.decldescription type=line
|
||||
// private Class java;
|
||||
// ino.end
|
||||
// ino.attribute.class_block.23020.declaration
|
||||
private Block class_block;
|
||||
// ino.end
|
||||
// ino.attribute.paralist.23023.declaration
|
||||
//private Menge<Type> paralist = new Menge<Type>(); // Parameterliste 'class xy<para1, para2,...>{}' wird gespeichert
|
||||
// ino.end
|
||||
// ino.attribute.parahash.23026.declaration
|
||||
private Hashtable<String,String> parahash = new Hashtable<String,String>(); // 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 Menge<GenericTypeVar> genericClassParameters=new Menge<GenericTypeVar>();
|
||||
|
||||
// ino.attribute.containedTypes.23032.decldescription type=line
|
||||
public UsedId superclassid = (SourceFile.READ_OBJECT_SUPERCLASSES_FROM_JRE?UsedId.createFromQualifiedName("Object",-1):null);
|
||||
|
||||
private Block class_block;
|
||||
|
||||
private Hashtable<String,String> parahash = new Hashtable<String,String>(); // parametrisierten Attrib. werden mit den Paramet.aus paralist verk.
|
||||
|
||||
public static boolean isFirstLocalVarDecl; //Hilfsvariable fuer Offsets, hoth
|
||||
// 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 Menge<Type> containedTypes = new Menge<Type>();
|
||||
// ino.end
|
||||
// ino.attribute.usedIdsToCheck.23035.declaration
|
||||
private Menge<UsedId> usedIdsToCheck = new Menge<UsedId>();
|
||||
// ino.end
|
||||
|
||||
private TypeAssumptions typeAssumptions = null;//muss mit null Initialisiert werden. Darf nur über getTypeAssumptions abgerufen werden.
|
||||
|
||||
// ino.attribute.parserlog.23038.declaration
|
||||
//protected Logger parselog = Logger.getLogger("parser");
|
||||
// ino.end
|
||||
protected Logger typinferenzLog = Logger.getLogger(Class.class.getName());
|
||||
private SyntaxTreeNode parent;
|
||||
private Menge<Field> fielddecl = new Menge<Field>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private int offset;
|
||||
private Type superClass;
|
||||
private RefType superClass;
|
||||
|
||||
|
||||
// ino.method.Class.23041.definition
|
||||
public Class(String name, int offset)
|
||||
// ino.end
|
||||
// ino.method.Class.23041.body
|
||||
{
|
||||
this.name = name;
|
||||
if(name.equals("java.lang.Object")){
|
||||
superclassid=null;
|
||||
}
|
||||
this.offset = offset;
|
||||
if(!name.equals("Object"))//Alle Klassen auÃer Object erben von Object:
|
||||
this.superClass = new Class("Object", -1).getType();
|
||||
if(!name.equals("Object") && !name.equals("java.lang.Object"))//Alle Klassen auÃer Object erben von Object:
|
||||
this.superClass = new Class("java.lang.Object", -1).getType();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@ -240,21 +212,30 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
* @param modifiers
|
||||
* @param supertypeGenPara - Eine Liste von Namen, welche die Generischen Parameter der Klasse darstellen.
|
||||
*/
|
||||
public Class(String name, RefType superClass, Modifiers modifiers,
|
||||
Menge<String> supertypeGenPara) {
|
||||
public Class(String name, RefType superClass, Modifiers modifiers, Menge<String> supertypeGenPara) {
|
||||
this(name,superClass,modifiers,0);
|
||||
if(supertypeGenPara == null)return;
|
||||
Menge<GenericTypeVar> gtvs = new Menge<>();
|
||||
for(String gname : supertypeGenPara){
|
||||
GenericTypeVar newGTV=new GenericTypeVar(gname,this,0);
|
||||
gtvs.add(newGTV);
|
||||
for(Object gname : supertypeGenPara){
|
||||
if(gname instanceof String){
|
||||
GenericTypeVar newGTV=new GenericTypeVar((String)gname,this,0);
|
||||
gtvs.add(newGTV);
|
||||
}else if(gname instanceof GenericTypeVar){
|
||||
gtvs.add((GenericTypeVar) gname);
|
||||
}else{
|
||||
GenericTypeVar newGTV=new GenericTypeVar(gname.toString(),this,0);
|
||||
gtvs.add(newGTV);
|
||||
|
||||
throw new RuntimeException(gname.toString());
|
||||
}
|
||||
|
||||
}
|
||||
this.setGenericParameter(new GenericDeclarationList(gtvs,0));
|
||||
}
|
||||
|
||||
public Class(String name, RefType superClass, Modifiers mod, int offset){
|
||||
this(name,mod,offset);
|
||||
if(superClass == null)this.superClass = new Class("Object",-1).getType();
|
||||
if(superClass == null)this.superClass = new Class("java.lang.Object",-1).getType();
|
||||
else this.superClass = superClass;
|
||||
}
|
||||
|
||||
@ -284,14 +265,14 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
public Class(String name2, Modifiers object, ClassBody classBody,
|
||||
Menge<Type> containedTypes2, Menge<Type> typeMenge,
|
||||
Menge<Type> paraMenge, int offset2) {
|
||||
this(name2, object, classBody, containedTypes2,(Type)null, typeMenge, paraMenge, offset2);
|
||||
this(name2, object, classBody, containedTypes2,(RefType)null, typeMenge, paraMenge, offset2);
|
||||
}
|
||||
private static Menge<Type> usedIdToRefType(Menge<UsedId> superif2) {
|
||||
Menge<Type> ret = new Menge<>();
|
||||
for(UsedId id : superif2)ret.add(usedIdToRefType(id));
|
||||
return ret;
|
||||
}
|
||||
private static Type usedIdToRefType(UsedId superclass2) {
|
||||
private static RefType usedIdToRefType(UsedId superclass2) {
|
||||
RefType ret = new RefType(superclass2.getSimpleName(), null, superclass2.getOffset());
|
||||
ret.set_ParaList(superclass2.get_ParaList());
|
||||
return ret;
|
||||
@ -305,7 +286,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
// ino.end
|
||||
// ino.method.Class.23047.definition
|
||||
public Class(String name, Modifiers mod, ClassBody cb, Menge<Type> ct,
|
||||
Type superclass, Menge<Type> Menge, Menge<? extends Type> paralist, int offset)
|
||||
RefType superclass, Menge<Type> Menge, Menge<? extends Type> paralist, int offset)
|
||||
// ino.end
|
||||
// ino.method.Class.23047.body
|
||||
{
|
||||
@ -573,7 +554,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
*/
|
||||
|
||||
// ino.method.get_ParaList.23101.definition
|
||||
public Menge<? extends Type> get_ParaList()
|
||||
public List<? extends Type> get_ParaList()
|
||||
// ino.end
|
||||
// ino.method.get_ParaList.23101.body
|
||||
{
|
||||
@ -616,7 +597,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.TRProg.23110.definition
|
||||
public ConstraintsSet typeReconstruction(FC_TTO supportData, TypeAssumptions globalAssumptions)
|
||||
public ConstraintsSet typeReconstruction(TypeAssumptions globalAssumptions)
|
||||
// ino.end
|
||||
// ino.method.TRProg.23110.body
|
||||
{
|
||||
@ -628,8 +609,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
//////////////////////////////
|
||||
inferencelog.info("Rufe TRStart()...", Section.TYPEINFERENCE);
|
||||
|
||||
typinferenzLog.debug("Erstellte FiniteClosure: "+supportData, Section.TYPEINFERENCE);
|
||||
//////////////////////////////
|
||||
//////////////////////////////
|
||||
// Ab hier ...
|
||||
// @author A10023 - Andreas Stadelmeier:
|
||||
//////////////////////////////
|
||||
@ -662,7 +642,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
|
||||
//ConstraintsSet oderConstraints = this.TYPE(this.getMethodList(), fieldInitializers, assumptions);
|
||||
|
||||
this.superClass = this.superClass.TYPE(assumptions, this);
|
||||
//Gibt es hier eine ClassCastException stimmt etwas grundsätzlich nicht!
|
||||
this.superClass = (RefType)this.superClass.TYPE(assumptions, this);
|
||||
|
||||
for(Field f:this.getFields()){
|
||||
oderConstraints.add(f.TYPE(assumptions));
|
||||
@ -1019,7 +1000,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
* Die Super Klasse dieser Klasse.
|
||||
* @return null für Klasse Object
|
||||
*/
|
||||
public Type getSuperClass(){
|
||||
public RefType getSuperClass(){
|
||||
return this.superClass;
|
||||
}
|
||||
@Override
|
||||
@ -1031,21 +1012,66 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
return false;
|
||||
}
|
||||
|
||||
private Collection<? extends ByteCodeResult> getGenericClasses(ClassGenerator _cg) {
|
||||
/*
|
||||
private Collection<? extends ByteCodeResult> getGenericClasses() {
|
||||
Collection<ByteCodeResult> results = new Menge<>();
|
||||
|
||||
//Super Klasse
|
||||
String name = "java/util/Vectorjava/lang/String"; //getParentClass().getType().getBytecodeSignature(_cg);
|
||||
|
||||
Type superClass = new Class("java/util/Vector",-1).getType();
|
||||
|
||||
_cg = new ClassGenerator(name, superClass, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null));
|
||||
|
||||
ByteCodeResult code = new ByteCodeResult(_cg);
|
||||
|
||||
results.add(code);
|
||||
for(Field field : this.fielddecl){
|
||||
Type type = field.getType();
|
||||
//Der Type des Feldes
|
||||
if(type instanceof RefType){
|
||||
RefType refType = (RefType) type;
|
||||
|
||||
if(!refType.getCombinedType(null).equals(refType.get_Name().replace(".", "%"))){
|
||||
results.addAll(generateGenericClass(refType.getCombinedType(null), new Class("java/util/Vector",-1)));
|
||||
}
|
||||
}
|
||||
|
||||
if(field instanceof Method){
|
||||
Method method = (Method) field;
|
||||
ParameterList parameterList = method.getParameterList();
|
||||
|
||||
//Die Typen der Methodenparameter
|
||||
for(FormalParameter parameter: parameterList){
|
||||
Type parameterType = parameter.getType();
|
||||
|
||||
if(parameterType instanceof RefType){
|
||||
RefType refType = (RefType) parameterType;
|
||||
|
||||
if(!refType.getCombinedType(null).equals(refType.get_Name().replace(".", "%"))){
|
||||
results.addAll(generateGenericClass(refType.getCombinedType(null), new Class("java/util/Vector",-1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
private Menge<ByteCodeResult> generateGenericClass(String name, Class superClass){
|
||||
//TODO: bytecode -- Generics hinzuf<75>gen
|
||||
//Type superClassType = superClass.getType();
|
||||
|
||||
//TODO: bytecode
|
||||
//ClassGenerator genericClassGenerator = new ClassGenerator(name, superClassType, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null));
|
||||
|
||||
//TODO: bytecode -- Namen der neuen Klasse
|
||||
Class generatedClass = new Class(name, 0);
|
||||
|
||||
//TODO: bytecode -- alle Konstruktoren generieren
|
||||
Block konstruktorBlock = new Block();
|
||||
konstruktorBlock.setType(new de.dhbwstuttgart.syntaxtree.type.Void(konstruktorBlock, 0));
|
||||
konstruktorBlock.statements.add(new SuperCall(konstruktorBlock));
|
||||
Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock, name, superClass), superClass);
|
||||
standardKonstruktor.parserPostProcessing(generatedClass);
|
||||
|
||||
generatedClass.addField(standardKonstruktor);
|
||||
|
||||
return generatedClass.genByteCode(new TypeinferenceResultSet(generatedClass, new Menge<>(), new ResultSet()));
|
||||
}
|
||||
*/
|
||||
}
|
||||
// ino.end
|
||||
|
@ -85,64 +85,6 @@ Paratyp gesetzt."); }
|
||||
fielddecl.addElement(i);
|
||||
}
|
||||
|
||||
// ino.method.is_declared.23188.defdescription type=line
|
||||
//
|
||||
// ********************************************************************************************
|
||||
//
|
||||
// ino.end
|
||||
|
||||
// ino.method.is_declared.23188.definition
|
||||
public boolean is_declared(Type t, Menge<Class> classlist)
|
||||
throws SCClassBodyException
|
||||
// ino.end
|
||||
// ino.method.is_declared.23188.body
|
||||
{
|
||||
boolean flag=false;
|
||||
for(Enumeration<Class> 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 Menge 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().toString());
|
||||
ex.addException(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.string_rec.23191.definition
|
||||
static String string_rec(Hashtable ht)
|
||||
|
@ -28,7 +28,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
|
||||
@ -65,8 +65,8 @@ public class Constructor extends Method {
|
||||
DHBWConstantPoolGen _cp = cg.getConstantPool();
|
||||
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
|
||||
Class parentClass = this.getParentClass();
|
||||
|
||||
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg), org.apache.commons.bcel6.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
|
||||
|
||||
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, null), this.parameterlist.getBytecodeTypeList(cg,null) , this.parameterlist.getParameterNameArray(), "<init>", parentClass.name, il, _cp);
|
||||
|
||||
//FieldInitializations an Block anfügen
|
||||
Block block = this.get_Block();
|
||||
@ -78,7 +78,7 @@ public class Constructor extends Method {
|
||||
|
||||
//method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)
|
||||
|
||||
cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block()));
|
||||
cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block(), null));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,13 +91,13 @@ public class Constructor extends Method {
|
||||
il = toInsert;
|
||||
}
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg){
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
return il;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genByteCode(ClassGenerator cg) {
|
||||
public void genByteCode(ClassGenerator cg, Class classObj) {
|
||||
this.genByteCode(cg, new InstructionList());
|
||||
}
|
||||
// super statement muss drin sein
|
||||
|
@ -16,6 +16,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeInsertable;
|
||||
import de.dhbwstuttgart.typeinference.Typeable;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||||
|
||||
|
@ -21,7 +21,8 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -147,13 +148,13 @@ public class FieldDeclaration extends Field{
|
||||
}
|
||||
*/
|
||||
|
||||
SingleConstraint c1 = new SingleConstraint(thisType, thisType);
|
||||
UndConstraint c1 = ConstraintsSet.createSingleConstraint(thisType, thisType);
|
||||
ret.add(c1); //Damit die TypVariable des Felds in den Constraints auftaucht
|
||||
|
||||
if(this.wert!=null){
|
||||
//Falls bei der Deklaration ein Wert zugewiesen wird, verhält sich das Constraintserzeugen wie bei dem Assign-Statement:
|
||||
ret.add(this.wert.TYPEExpr(localAssumptions));
|
||||
ret.add(new SingleConstraint(this.wert.getType().TYPE(localAssumptions,this), thisType));
|
||||
ret.add(ConstraintsSet.createSingleConstraint(this.wert.getType().TYPE(localAssumptions,this), thisType));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -170,23 +171,27 @@ public class FieldDeclaration extends Field{
|
||||
* @param cg
|
||||
* @return - Die InstructionList, welche das Feld initialisiert
|
||||
*/
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
//Das Feld an die Klasse anfügen:
|
||||
FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg), this.getDescription(), cg.getConstantPool());
|
||||
field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg)));
|
||||
FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(), cg.getConstantPool());
|
||||
field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg, rs)));
|
||||
cg.addField(field.getField());
|
||||
|
||||
//Die Felddekleration an den Konstruktor anhängen:
|
||||
InstructionList il = new InstructionList();
|
||||
il.append(new This(this).genByteCode(cg));
|
||||
il.append(this.wert.genByteCode(cg));
|
||||
il.append(new This(this).genByteCode(cg, rs));
|
||||
|
||||
if(wert != null){
|
||||
il.append(this.wert.genByteCode(cg, rs));
|
||||
}
|
||||
|
||||
FieldInstruction putFieldInstruction =
|
||||
cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(),
|
||||
this.getDescription(), this.getType().getBytecodeType(cg), Constants.PUTFIELD);
|
||||
this.getDescription(), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD);
|
||||
il.append(putFieldInstruction );
|
||||
return il;
|
||||
}
|
||||
|
||||
|
||||
/*@Override
|
||||
public void genByteCode(ClassGen cg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
// ino.module.FormalParameter.8561.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||||
@ -14,6 +14,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeInsertable;
|
||||
import de.dhbwstuttgart.typeinference.Typeable;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||||
@ -233,10 +234,10 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription(){
|
||||
String ret = "";
|
||||
if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){
|
||||
ret += this.getType().getName() + " ";
|
||||
ret += this.getType().toString();//getBytecodeSignature(null, null);
|
||||
}
|
||||
return ret+this.getIdentifier();
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
// ino.module.Method.8564.package
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
// ino.end
|
||||
// ino.module.Method.8564.import
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.classfile.Signature;
|
||||
@ -17,7 +19,9 @@ import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.MethodGen;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.Menge.Equal;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.DHBWConstantPoolGen;
|
||||
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
@ -30,6 +34,7 @@ import de.dhbwstuttgart.myexception.SCStatementException;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Static;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
@ -40,8 +45,9 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeInsertable;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
@ -58,61 +64,26 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||||
*
|
||||
*/
|
||||
public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
// 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 = new ParameterList();
|
||||
// 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 Menge<GenericTypeVar> genericMethodParameters=new
|
||||
// Menge<GenericTypeVar>();
|
||||
// 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 Menge<String> types_in_parameterlist = new Menge<String>();
|
||||
// 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
|
||||
private Modifiers modifiers;
|
||||
protected static Logger inferencelog = Logger.getLogger("inference");
|
||||
// ino.end
|
||||
// ino.attribute.parserlog.23518.declaration
|
||||
protected static Logger parserlog = Logger.getLogger("parser");
|
||||
|
||||
// ino.end
|
||||
|
||||
public Method(int offset) {
|
||||
super(offset);
|
||||
}
|
||||
|
||||
public Method(String name, Type returnType, ParameterList parameterList,
|
||||
Block block, GenericDeclarationList gtvDeclarations, int offset) {
|
||||
public Method(String name, Type returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, int offset) {
|
||||
this(offset);
|
||||
/*
|
||||
* if(parameterList != null)parameterList.parserPostProcessing(this);
|
||||
@ -126,51 +97,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
this.setReturnType(returnType);
|
||||
}
|
||||
|
||||
/*
|
||||
* // ino.method.setGenericMethodParameters.23521.definition public void
|
||||
* setGenericMethodParameters(Menge<GenericTypeVar> genericMethodParameters)
|
||||
* // ino.end // ino.method.setGenericMethodParameters.23521.body {
|
||||
* this.genericMethodParameters=genericMethodParameters; } // ino.end //
|
||||
* ino.method.getGenericMethodParameters.23524.definition public
|
||||
* Menge<GenericTypeVar> getGenericMethodParameters() // ino.end //
|
||||
* ino.method.getGenericMethodParameters.23524.body {
|
||||
* return(genericMethodParameters); } // 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;
|
||||
* Menge<FormalParameter> 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(); //Menge
|
||||
* Formalparalist aus FormalParameterList wird zwischen gesichert
|
||||
* for(Enumeration<FormalParameter> 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 Menge 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 JavaClassName getTypeName()
|
||||
// ino.end
|
||||
// ino.method.getTypeName.23533.body
|
||||
{
|
||||
if (this.getType() == null)
|
||||
return null;
|
||||
@ -178,101 +105,58 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
return this.getType().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
|
||||
/**
|
||||
* <br/>
|
||||
* Author: Jrg Buerle
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.setReturnType.23539.definition
|
||||
private void setReturnType(Type type)
|
||||
// ino.end
|
||||
// ino.method.setReturnType.23539.body
|
||||
{
|
||||
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.getType() == null)
|
||||
blo.setType(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;
|
||||
this.modifiers = 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<br/>
|
||||
*
|
||||
* @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;
|
||||
@ -280,216 +164,100 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
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
|
||||
|
||||
// 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 Menge get_Type_Paralist()
|
||||
// ino.end
|
||||
// ino.method.get_Type_Paralist.23578.body
|
||||
{
|
||||
return types_in_parameterlist;
|
||||
}
|
||||
|
||||
// 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.getTypeLineNumber.23602.defdescription type=javadoc
|
||||
/**
|
||||
* <br>
|
||||
* 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
|
||||
|
||||
/**
|
||||
* <br/>
|
||||
* Author: Martin Pl�micke
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.toString.23605.definition
|
||||
public String toString()
|
||||
// ino.end
|
||||
// ino.method.toString.23605.body
|
||||
{
|
||||
return this.getType() + " " + this.get_Name()
|
||||
+ ((block != null) ? block.toString() : "");
|
||||
return this.getType() + " " + this.get_Name() + ((block != null) ? 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wandleRefTypeAttributes2GenericAttributes(
|
||||
Menge<Type> classParalist) {
|
||||
/*
|
||||
* Menge<Type> paralist = new Menge<Type>();//Mit den Generischen Typen
|
||||
* der Methode paralist.addAll(classParalist);
|
||||
* paralist.addAll(this.genericMethodParameters);
|
||||
*
|
||||
* // Zuerst Returntype untersuchen Type returnType=getType(); Type
|
||||
* pendantReturnType = null; if(returnType instanceof
|
||||
* RefType)pendantReturnType =
|
||||
* ((RefType)returnType).findGenericType(paralist, new
|
||||
* Menge<GenericTypeVar>()); //GenericTypeVar
|
||||
* pendantReturnType=ClassHelper.findGenericType(returnType,
|
||||
* paralist,genericMethodParameters); if(pendantReturnType!=null){
|
||||
* //Wenn generisch, dann modifizieren setReturnType(pendantReturnType);
|
||||
* }
|
||||
*
|
||||
* // Dann parameterlist untersuchen for(int
|
||||
* par=0;par<getParameterCount();par++){ FormalParameter
|
||||
* fp=parameterlist.formalparameter.get(par); Type fpType=fp.getType();
|
||||
* // Nur wenn es sich um ein RefType-Field handelt Type pendantPara =
|
||||
* null; if(fpType instanceof RefType)pendantPara =
|
||||
* ((RefType)fpType).findGenericType(paralist, new
|
||||
* Menge<GenericTypeVar>()); //GenericTypeVar
|
||||
* pendantPara=ClassHelper.findGenericType
|
||||
* (fpType,paralist,genericMethodParameters); if(pendantPara!=null){
|
||||
* //Wenn generisch, dann modifizieren fp.setType(pendantPara); } }
|
||||
*
|
||||
* // Zuletzt alle Lokalen Variablendeklarationen durchgehen
|
||||
* if(block!=null){
|
||||
* block.wandleRefTypeAttributes2GenericAttributes(paralist
|
||||
* ,genericMethodParameters); }
|
||||
*/
|
||||
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> classParalist) {
|
||||
}
|
||||
|
||||
public void set_Method_Name(String string) {
|
||||
@ -512,36 +280,17 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
|
||||
// TypeCheck, falls es sich um einen RefType handelt:
|
||||
this.returntype = this.returntype.checkTYPE(localAss, this);
|
||||
/*
|
||||
* if(this.returntype!=null && (this.returntype instanceof RefType)&&
|
||||
* !(this.returntype instanceof mycompiler.mytype.Void)){//Sonderfall
|
||||
* der Methode: Ihr Typ darf Void definiert werden. Type replaceType =
|
||||
* null; replaceType = ass.getTypeFor((RefType)this.returntype);
|
||||
* if(replaceType == null)throw new
|
||||
* TypeinferenceException("Der Typ "+this
|
||||
* .getType().getName()+" ist nicht korrekt",this); this.returntype =
|
||||
* replaceType; }
|
||||
*/
|
||||
// Die Parameter zu den Assumptions hinzufügen:
|
||||
if (this.parameterlist != null)
|
||||
for (FormalParameter param : this.parameterlist) {
|
||||
|
||||
param.setType(param.getType().checkTYPE(localAss, this));
|
||||
/*
|
||||
* if(param.getType() instanceof RefType) { Type replaceType =
|
||||
* null; replaceType = ass.getTypeFor((RefType)param.getType());
|
||||
* if(replaceType == null) throw new
|
||||
* TypeinferenceException("Der Typ "
|
||||
* +param.getType().getName()+" ist nicht korrekt",param);
|
||||
* param.setType(replaceType); }
|
||||
*/
|
||||
|
||||
localAss.addAssumption(new ParameterAssumption(param));
|
||||
}
|
||||
ret.add(this.block.TYPEStmt(localAss));
|
||||
// eine Verknüpfung mit der Type Assumption aus dem Assumption Set
|
||||
// und dem ermittelten Typ der Methode:
|
||||
ret.add(new SingleConstraint(this.block.getType().TYPE(localAss, this), this.returntype.TYPE(localAss, this)));
|
||||
ret.add(ConstraintsSet.createSingleConstraint(this.block.getType().TYPE(localAss, this), this.returntype.TYPE(localAss, this)));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -579,107 +328,15 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
TypeAssumptions ret = new TypeAssumptions();
|
||||
ret.addAssumption(new MethodAssumption(this, parentClass));
|
||||
return ret;
|
||||
/*
|
||||
* TypeAssumptions assumptions = new TypeAssumptions(); this.assumedType
|
||||
* = null; //if((this.get_Method_Name().equals(classmember.getName()) ||
|
||||
* this.get_Method_Name().equals("<init>")) &&
|
||||
* ((this.getType().equals(new mycompiler.mytype.Void(0))) ||
|
||||
* this.getType() instanceof TypePlaceholder)){
|
||||
* if((this.get_Method_Name().equals(classmember.getName()) ||
|
||||
* this.get_Method_Name().equals("<init>"))) {
|
||||
* this.set_Method_Name("<init>"); 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<CTypeAssumption> 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.getType(),
|
||||
* this.getParameterCount(),this.getLineNumber(),this.getOffset(),new
|
||||
* Menge<Integer>(),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<parameterList.sc_get_Formalparalist().size(); i++){ FormalParameter
|
||||
* para = parameterList.sc_get_Formalparalist().elementAt(i); //
|
||||
* F�r V_fields_methods: CParaTypeAssumption paraAssum = new
|
||||
* CParaTypeAssumption(classmember.getName(), this.get_Method_Name(),
|
||||
* this.getParameterCount(), this.getOverloadedID(),para.get_Name(),
|
||||
* para.getType(), para.getLineNumber(),para.getOffset(),new
|
||||
* Menge<Integer>()); //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 Menge<Integer>());
|
||||
* 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;
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
if (this.getType() == null)
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
// Bei dem Elterntyp der Methode darf es sich nur um eine Klasse
|
||||
// handeln, daher Cast ohne Prüfung:
|
||||
// Class parentClass = (Class)parent;
|
||||
if (this.returntype == null)
|
||||
this.returntype = TypePlaceholder.fresh(this);
|
||||
super.parserPostProcessing(parent);
|
||||
/*
|
||||
* this.returntype.parserPostProcessing(this); if(this.parameterlist !=
|
||||
* null){ for(FormalParameter fp : this.parameterlist){
|
||||
* fp.parserPostProcessing(this); } } for(GenericTypeVar gtv :
|
||||
* this.getGenericParameter()){ gtv.parserPostProcessing(this); }
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -720,7 +377,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
DImethod.set_Name(withSignature);
|
||||
ret.set_DeclId(DImethod);
|
||||
Block tempBlock = new Block();
|
||||
// tempBlock.setType(new RefType(parent.getName(),0));
|
||||
ret.set_Block(tempBlock);
|
||||
ret.parserPostProcessing(parent);
|
||||
return ret;
|
||||
@ -743,34 +399,42 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
public void genByteCode(ClassGenerator cg) {
|
||||
DHBWConstantPoolGen _cp = cg.getConstantPool();
|
||||
DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, _cp);
|
||||
InstructionList il = new InstructionList();
|
||||
Class parentClass = this.getParentClass();
|
||||
|
||||
//Die Argumentliste generieren:
|
||||
org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS;
|
||||
String[] argumentNames = new String[]{};
|
||||
if(this.parameterlist != null &&
|
||||
this.parameterlist.size() > 0){
|
||||
argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()];
|
||||
argumentNames = new String[this.parameterlist.size()];
|
||||
int i = 0;
|
||||
for(FormalParameter parameter : this.parameterlist){
|
||||
argumentTypes[i] = parameter.getType().getBytecodeType(cg);
|
||||
argumentNames[i] = parameter.getIdentifier();
|
||||
i++;
|
||||
}
|
||||
public void genByteCode(ClassGenerator cg, Class classObj) {
|
||||
List<TypeinferenceResultSet> typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg);
|
||||
DHBWInstructionFactory _factory = cg.getInstructionFactory();
|
||||
|
||||
for(TypeinferenceResultSet t: typeInterferenceResults){
|
||||
addMethodToClassGenerator(cg, _factory, t);
|
||||
}
|
||||
|
||||
//Methode generieren:
|
||||
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
|
||||
|
||||
//Methode generieren und anfügen:
|
||||
cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block()));
|
||||
|
||||
}
|
||||
|
||||
private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) {
|
||||
DHBWConstantPoolGen _cp = cg.getConstantPool();
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
ArrayList<org.apache.commons.bcel6.generic.Type> argumentTypes = new ArrayList<org.apache.commons.bcel6.generic.Type>();
|
||||
ArrayList<String> argumentNames = new ArrayList<String>();
|
||||
|
||||
if(this.parameterlist != null && this.parameterlist.size() > 0){
|
||||
generateArgumentList(argumentTypes, argumentNames, cg, t);
|
||||
}
|
||||
|
||||
short constants = Constants.ACC_PUBLIC;
|
||||
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
|
||||
|
||||
Type returnType = this.getType();
|
||||
|
||||
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes.toArray(new org.apache.commons.bcel6.generic.Type[parameterlist.size()]) , argumentNames.toArray(new String[parameterlist.size()]), this.get_Method_Name(), getParentClass().name, il, _cp);
|
||||
|
||||
cg.setMethodeGenerator(method);
|
||||
|
||||
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t));
|
||||
}
|
||||
|
||||
private void generateArgumentList(ArrayList<org.apache.commons.bcel6.generic.Type> argumentTypes, ArrayList<String> argumentNames, ClassGenerator cg, TypeinferenceResultSet t) {
|
||||
for(FormalParameter parameter : this.parameterlist){
|
||||
argumentTypes.add(parameter.getType().getBytecodeType(cg, t));
|
||||
argumentNames.add(parameter.getIdentifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
26
src/de/dhbwstuttgart/syntaxtree/NullSyntaxTreeNode.java
Normal file
26
src/de/dhbwstuttgart/syntaxtree/NullSyntaxTreeNode.java
Normal file
@ -0,0 +1,26 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
/**
|
||||
* Dieser SyntaxTreeNode kann anstelle von null in einem Syntaxbaum eingesetzt werden.
|
||||
* Vorsicht: Als Offset wird dann immer 0 zurück gegeben.
|
||||
*/
|
||||
public class NullSyntaxTreeNode extends SyntaxTreeNode {
|
||||
|
||||
@Override
|
||||
public int getOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVariableLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menge<? extends SyntaxTreeNode> getChildren() {
|
||||
return new Menge<>();
|
||||
}
|
||||
|
||||
}
|
@ -11,6 +11,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
|
||||
// ino.end
|
||||
|
||||
@ -145,11 +146,11 @@ public class ParameterList extends SyntaxTreeNode implements Iterable<FormalPara
|
||||
return this.formalparameter.size();
|
||||
}
|
||||
|
||||
public org.apache.commons.bcel6.generic.Type[] getBytecodeTypeList(ClassGenerator cg){
|
||||
public org.apache.commons.bcel6.generic.Type[] getBytecodeTypeList(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
org.apache.commons.bcel6.generic.Type[] ret = new org.apache.commons.bcel6.generic.Type[formalparameter.size()];
|
||||
int i = 0;
|
||||
for(FormalParameter f : formalparameter){
|
||||
ret[i] = f.getType().getBytecodeType(cg);
|
||||
ret[i] = f.getType().getBytecodeType(cg, rs);
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
import org.apache.commons.bcel6.generic.ClassGen;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
@ -10,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeInsertable;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.GenericTypeInsertPoint;
|
||||
@ -53,6 +55,8 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
|
||||
/**
|
||||
* Eine Beschreibung/Name des SyntaxTree-Nodes
|
||||
* Hat nichts mit der Description im Bytecode zu tun,
|
||||
* wird für die Anzeige des AST im Plugin verwendet
|
||||
* @return
|
||||
*/
|
||||
public String getDescription(){
|
||||
|
74
src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java
Normal file
74
src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java
Normal file
@ -0,0 +1,74 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
|
||||
public class ASTFactory {
|
||||
public static Method createMethod(String name, ParameterList paralist, Block block, Class parent) {
|
||||
|
||||
|
||||
Method method = new Method(0);
|
||||
DeclId DImethod = new DeclId();
|
||||
DImethod.set_Name(name);
|
||||
method.set_DeclId(DImethod);
|
||||
method.set_Block(block);
|
||||
method.setParameterList(paralist);
|
||||
|
||||
block.parserPostProcessing(method);
|
||||
method.parserPostProcessing(parent);
|
||||
return method;
|
||||
}
|
||||
|
||||
public static Method createEmptyMethod(String withSignature, Class parent) {
|
||||
return ASTFactory.createMethod(withSignature, new ParameterList(), new Block(), parent);
|
||||
}
|
||||
|
||||
public static Constructor createEmptyConstructor(Class parent){
|
||||
Block block = new Block();
|
||||
block.setType(new de.dhbwstuttgart.syntaxtree.type.Void(block, 0));
|
||||
block.statements.add(new SuperCall(block));
|
||||
|
||||
return ASTFactory.createConstructor(parent, new ParameterList(), block);
|
||||
}
|
||||
|
||||
public static Constructor createConstructor(Class superClass, ParameterList paralist, Block block){
|
||||
block.parserPostProcessing(superClass);
|
||||
|
||||
Method method = ASTFactory.createMethod("<init>", paralist, block, superClass);
|
||||
method.setType(new de.dhbwstuttgart.syntaxtree.type.Void(block, 0));
|
||||
|
||||
return new Constructor(method, superClass);
|
||||
}
|
||||
|
||||
public static Class createClass(String className, RefType type, Modifiers modifiers, Menge supertypeGenPara, SourceFile parent) {
|
||||
// TODO bytecode createClass
|
||||
//String name, RefType superClass, Modifiers modifiers, Menge<String> supertypeGenPara
|
||||
Class generatedClass = new Class(className, type, modifiers, supertypeGenPara);
|
||||
generatedClass.addField(ASTFactory.createEmptyConstructor(generatedClass));
|
||||
|
||||
generatedClass.parserPostProcessing(parent);
|
||||
|
||||
return generatedClass;
|
||||
}
|
||||
|
||||
public static Class createObjectClass() {
|
||||
Class generatedClass = new Class("java.lang.Object", 0);
|
||||
|
||||
return generatedClass;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
public class UnifyPairMengenBuilder {
|
||||
|
||||
private Menge<Pair> buildMenge = new Menge<Pair>();
|
||||
|
||||
public void addPair(Type t1, Type t2) {
|
||||
buildMenge.add(new Pair(t1, t2));
|
||||
}
|
||||
|
||||
public void addPair(Type t1, Type t2, PairOperator pairOp) {
|
||||
buildMenge.add(new Pair(t1, t2, pairOp));
|
||||
}
|
||||
|
||||
public Menge<Pair> getPairMenge() {
|
||||
return buildMenge;
|
||||
}
|
||||
|
||||
public Menge<Menge<Pair>> getNestedPairMenge() {
|
||||
Menge<Menge<Pair>> nested = new Menge<>();
|
||||
|
||||
for(Pair p : buildMenge) {
|
||||
Menge<Pair> m = new Menge<Pair>();
|
||||
m.add(p);
|
||||
nested.add(m);
|
||||
}
|
||||
|
||||
return nested;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
buildMenge = new Menge<Pair>();
|
||||
}
|
||||
}
|
223
src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
Normal file
223
src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
Normal file
@ -0,0 +1,223 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import de.dhbwstuttgart.myexception.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.NullSyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.FunN;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ObjectType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.EinzelElement;
|
||||
import de.dhbwstuttgart.typeinference.KomplexeMenge;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.OderMenge;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.UndMenge;
|
||||
import de.dhbwstuttgart.typeinference.UnifyConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.UnifyOderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.UnifyUndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
|
||||
|
||||
public class UnifyTypeFactory {
|
||||
|
||||
private final static NullSyntaxTreeNode NULL_NODE = new NullSyntaxTreeNode();
|
||||
|
||||
public static FiniteClosure generateFC(TypeAssumptions fromAss){
|
||||
HashSet<UnifyPair> pairs = new HashSet<>();
|
||||
for(ClassAssumption cAss : fromAss.getClassAssumptions()){
|
||||
UnifyType tl = UnifyTypeFactory.convert(cAss.getAssumedClass().getType());
|
||||
RefType superClass = cAss.getAssumedClass().getSuperClass();
|
||||
if(superClass != null){
|
||||
UnifyType tr = UnifyTypeFactory.convert(superClass);
|
||||
pairs.add(generateSmallerPair(tl, tr));
|
||||
}
|
||||
}
|
||||
return new FiniteClosure(pairs);
|
||||
}
|
||||
|
||||
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){
|
||||
return new UnifyPair(tl, tr, PairOperator.SMALLER);
|
||||
}
|
||||
|
||||
public static UnifyPair generateSmallerDotPair(UnifyType tl, UnifyType tr){
|
||||
return new UnifyPair(tl, tr, PairOperator.SMALLERDOT);
|
||||
}
|
||||
|
||||
public static UnifyType convert(Type t){
|
||||
//Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist
|
||||
if(t instanceof GenericTypeVar){
|
||||
return UnifyTypeFactory.convert((GenericTypeVar)t);
|
||||
}else if(t instanceof FunN){
|
||||
return UnifyTypeFactory.convert((FunN)t);
|
||||
}else if(t instanceof TypePlaceholder){
|
||||
return UnifyTypeFactory.convert((TypePlaceholder)t);
|
||||
}else if(t instanceof ExtendsWildcardType){
|
||||
return UnifyTypeFactory.convert((ExtendsWildcardType)t);
|
||||
}else if(t instanceof SuperWildcardType){
|
||||
return UnifyTypeFactory.convert((SuperWildcardType)t);
|
||||
}else if(t instanceof RefType){
|
||||
return UnifyTypeFactory.convert((RefType)t);
|
||||
}
|
||||
throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden");
|
||||
}
|
||||
|
||||
public static UnifyType convert(RefType t){
|
||||
UnifyType ret;
|
||||
if(t.getParaList() != null && t.getParaList().size() > 0){
|
||||
Menge<UnifyType> params = new Menge<>();
|
||||
for(Type pT : t.getParaList()){
|
||||
params.add(UnifyTypeFactory.convert(pT));
|
||||
}
|
||||
ret = new ReferenceType(t.get_Name(),new TypeParams(params));
|
||||
}else{
|
||||
ret = new ReferenceType(t.get_Name());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static UnifyType convert(FunN t){
|
||||
UnifyType ret;
|
||||
Menge<UnifyType> params = new Menge<>();
|
||||
if(t.getParaList() != null && t.getParaList().size() > 0){
|
||||
for(Type pT : t.getParaList()){
|
||||
params.add(UnifyTypeFactory.convert(pT));
|
||||
}
|
||||
}
|
||||
ret = FunNType.getFunNType(new TypeParams(params));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static UnifyType convert(TypePlaceholder tph){
|
||||
return new PlaceholderType(tph.get_Name());
|
||||
}
|
||||
|
||||
public static UnifyType convert(ExtendsWildcardType t){
|
||||
return new ExtendsType(UnifyTypeFactory.convert(t.get_ExtendsType()));
|
||||
}
|
||||
|
||||
public static UnifyType convert(SuperWildcardType t){
|
||||
return new SuperType(UnifyTypeFactory.convert(t.get_SuperType()));
|
||||
}
|
||||
|
||||
public static UnifyType convert(GenericTypeVar t){
|
||||
//return new PlaceholderType(t.get_Name());
|
||||
return new ReferenceType(t.get_Name());
|
||||
}
|
||||
|
||||
public static UnifyConstraintsSet convert(ConstraintsSet constraints) {
|
||||
UnifyConstraintsSet ret = new UnifyConstraintsSet();
|
||||
for(OderConstraint oC : constraints.getOderConstraints()){
|
||||
ret.add(UnifyTypeFactory.convert(oC));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static UnifyOderConstraint convert(OderConstraint set) {
|
||||
UnifyOderConstraint ret = new UnifyOderConstraint();
|
||||
for(UndConstraint oC : set.getUndConstraints()){
|
||||
ret.addConstraint(UnifyTypeFactory.convert(oC));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static UnifyUndConstraint convert(UndConstraint set) {
|
||||
UnifyUndConstraint ret = new UnifyUndConstraint();
|
||||
for(EinzelElement<Pair> oC : set.getPairs()){
|
||||
ret.add(UnifyTypeFactory.convert(oC));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static UnifyPair convert(EinzelElement<Pair> p) {
|
||||
return convert(p.getItem());
|
||||
}
|
||||
|
||||
public static UnifyPair convert(Pair p) {
|
||||
if(!p.OperatorSmaller())throw new NotImplementedException();
|
||||
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
|
||||
, UnifyTypeFactory.convert(p.TA2));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Pair convert(UnifyPair mp) {
|
||||
Type tl = UnifyTypeFactory.convert(mp.getLhsType());
|
||||
Type tr = UnifyTypeFactory.convert(mp.getRhsType());
|
||||
return new Pair(tl, tr, mp.getPairOp());
|
||||
}
|
||||
|
||||
public static Type convert(ReferenceType t) {
|
||||
//TODO: Hier kann man die GTVs extrahieren
|
||||
if(t.getName().toString().equals(Void.VOID_NAME))return new Void(NULL_NODE, 0);
|
||||
RefType ret = new RefType(t.getName(),null,0);
|
||||
ret.set_ParaList(convert(t.getTypeParams()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Type convert(FunNType t) {
|
||||
RefType ret = new RefType(t.getName(),null,0);
|
||||
ret.set_ParaList(convert(t.getTypeParams()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Type convert(SuperType t) {
|
||||
RefType innerType = new RefType(t.getSuperedType().getName(),NULL_NODE,0);
|
||||
return new SuperWildcardType(innerType);
|
||||
}
|
||||
|
||||
public static Type convert(ExtendsType t) {
|
||||
RefType innerType = new RefType(t.getExtendedType().getName(),NULL_NODE,0);
|
||||
return new ExtendsWildcardType(innerType);
|
||||
}
|
||||
|
||||
public static Type convert(PlaceholderType t) {
|
||||
TypePlaceholder ret = TypePlaceholder.getInstance(t.getName());
|
||||
if(ret == null){ //Dieser TPH wurde vom Unifikationsalgorithmus erstellt
|
||||
ret = TypePlaceholder.fresh(NULL_NODE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Type convert(UnifyType t) {
|
||||
if(t instanceof FunNType)return convert((FunNType) t);
|
||||
if(t instanceof ReferenceType)return convert((ReferenceType) t);
|
||||
if(t instanceof SuperType)return convert((SuperType) t);
|
||||
if(t instanceof ExtendsType)return convert((ExtendsType) t);
|
||||
if(t instanceof PlaceholderType)return convert((PlaceholderType) t);
|
||||
throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden");
|
||||
}
|
||||
|
||||
private static List<Type> convert(TypeParams typeParams) {
|
||||
List<Type> ret = new ArrayList<>();
|
||||
for(UnifyType uT : typeParams){
|
||||
Type toAdd = convert(uT);
|
||||
ret.add(toAdd);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
|
||||
public class Unify_FC_TTO_Builder {
|
||||
|
||||
private Menge<Pair> fc = new Menge<Pair>();
|
||||
private Menge<Class> classes = new Menge<Class>();
|
||||
|
||||
public void AddInheritance(Type t1, Type t2) {
|
||||
if(t1 instanceof RefType)
|
||||
if(!classes.stream().anyMatch(x -> x.getName().equals(t1.getName())))
|
||||
classes.add(new Class(t1.get_Name(), t1.getOffset()));
|
||||
|
||||
if(t2 instanceof RefType)
|
||||
if(!classes.stream().anyMatch(x -> x.getName().equals(t2.getName())))
|
||||
classes.add(new Class(t2.get_Name(), t2.getOffset()));
|
||||
|
||||
fc.add(new Pair(t1, t2));
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
fc = new Menge<Pair>();
|
||||
classes = new Menge<Class>();
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ExprStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.InstVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalOrFieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalOrFieldVarOrClassname;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
|
||||
|
@ -5,20 +5,36 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.generic.ArithmeticInstruction;
|
||||
import org.apache.commons.bcel6.generic.DUP;
|
||||
import org.apache.commons.bcel6.generic.IADD;
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.InvokeInstruction;
|
||||
import org.apache.commons.bcel6.generic.ObjectType;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
|
||||
|
||||
@ -62,5 +78,86 @@ public abstract class AddOp extends Operator
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) {
|
||||
/*
|
||||
0: aload_1
|
||||
1: invokevirtual #2 // Method java/lang/Integer.intValue:()I
|
||||
4: aload_1
|
||||
5: invokevirtual #2 // Method java/lang/Integer.intValue:()I
|
||||
8: iadd
|
||||
9: invokestatic #3 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
|
||||
12: areturn
|
||||
*/
|
||||
|
||||
String returnType = getReturnType(operator.get_Expr1(), operator.get_Expr2(), rs);
|
||||
|
||||
if(returnType.equals("java.lang.String")){
|
||||
DHBWInstructionFactory _factory = _cg.getInstructionFactory();
|
||||
|
||||
ObjectType objectType = new ObjectType("java.lang.StringBuilder");
|
||||
|
||||
InstructionList il = new InstructionList();
|
||||
il.append(_factory.createNew("java.lang.StringBuilder"));
|
||||
il.append(new DUP());
|
||||
il.append(_cg.getInstructionFactory().createInvoke("java.lang.StringBuilder", "<init>", org.apache.commons.bcel6.generic.Type.VOID, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKESPECIAL));
|
||||
|
||||
il.append(operator.get_Expr1().genByteCode(_cg, rs));
|
||||
|
||||
|
||||
il.append(_cg.getInstructionFactory().createInvoke("java.lang.StringBuilder", "append", objectType, new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.STRING}, Constants.INVOKEVIRTUAL));
|
||||
|
||||
il.append(operator.get_Expr2().genByteCode(_cg, rs));
|
||||
|
||||
il.append(_cg.getInstructionFactory().createInvoke("java.lang.StringBuilder", "append", objectType, new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.STRING}, Constants.INVOKEVIRTUAL));
|
||||
|
||||
il.append(_cg.getInstructionFactory().createInvoke("java.lang.StringBuilder", "toString", new ObjectType("java.lang.String"), new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL));
|
||||
|
||||
return il;
|
||||
}else{
|
||||
DHBWInstructionFactory _factory = _cg.getInstructionFactory();
|
||||
|
||||
InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), returnType);
|
||||
|
||||
il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), returnType));
|
||||
|
||||
il.append(getOperator(returnType));
|
||||
|
||||
il.append(convertValueToObject(_factory, returnType));
|
||||
return il;
|
||||
}
|
||||
}
|
||||
|
||||
private String getReturnType(Expr expr1, Expr expr2, TypeinferenceResultSet rs) {
|
||||
Type type = expr1.getType();
|
||||
if(type instanceof TypePlaceholder){
|
||||
Type tphType = rs.getTypeOfPlaceholder((TypePlaceholder) expr1.getType());
|
||||
if(tphType instanceof ExtendsWildcardType){
|
||||
return ((ExtendsWildcardType) tphType).get_ExtendsType().get_Name();
|
||||
}else if(tphType instanceof SuperWildcardType){
|
||||
return ((SuperWildcardType) tphType).get_SuperType().get_Name();
|
||||
}else{
|
||||
return tphType.getName().toString();
|
||||
}
|
||||
}else{
|
||||
return type.get_Name();
|
||||
}
|
||||
}
|
||||
|
||||
abstract ArithmeticInstruction getOperator(String returnType);
|
||||
|
||||
private InvokeInstruction convertValueToObject(DHBWInstructionFactory _factory, String returnType) {
|
||||
if(returnType.equals("java.lang.Integer")){
|
||||
return _factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.INT}, Constants.INVOKESTATIC);
|
||||
}else if(returnType.equals("java.lang.Double")){
|
||||
return _factory.createInvoke("java.lang.Double", "valueOf", new ObjectType("java.lang.Double"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.DOUBLE}, Constants.INVOKESTATIC);
|
||||
}else if(returnType.equals("java.lang.Float")){
|
||||
return _factory.createInvoke("java.lang.Float", "valueOf", new ObjectType("java.lang.Float"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.FLOAT}, Constants.INVOKESTATIC);
|
||||
}else if(returnType.equals("java.lang.Long")){
|
||||
return _factory.createInvoke("java.lang.Long", "valueOf", new ObjectType("java.lang.Long"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.LONG}, Constants.INVOKESTATIC);
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -3,11 +3,15 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
|
||||
// ino.class.AndOp.24101.declaration
|
||||
@ -25,6 +29,12 @@ public class AndOp extends LogOp
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -3,6 +3,17 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.end
|
||||
// ino.module.DivideOp.8596.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
import org.apache.commons.bcel6.generic.ArithmeticInstruction;
|
||||
import org.apache.commons.bcel6.generic.DADD;
|
||||
import org.apache.commons.bcel6.generic.DDIV;
|
||||
import org.apache.commons.bcel6.generic.FADD;
|
||||
import org.apache.commons.bcel6.generic.FDIV;
|
||||
import org.apache.commons.bcel6.generic.IADD;
|
||||
import org.apache.commons.bcel6.generic.IDIV;
|
||||
import org.apache.commons.bcel6.generic.LADD;
|
||||
import org.apache.commons.bcel6.generic.LDIV;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
@ -25,9 +36,19 @@ public class DivideOp extends MulOp
|
||||
super(offset,variableLength);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ArithmeticInstruction getOperator(String returnType) {
|
||||
if(returnType.equals("java.lang.Integer")){
|
||||
return new IDIV();
|
||||
}else if(returnType.equals("java.lang.Double")){
|
||||
return new DDIV();
|
||||
}else if(returnType.equals("java.lang.Float")){
|
||||
return new FDIV();
|
||||
}else if(returnType.equals("java.lang.Long")){
|
||||
return new LDIV();
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -3,17 +3,31 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.end
|
||||
// ino.module.EqualOp.8597.import
|
||||
import java.util.Iterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.GOTO;
|
||||
import org.apache.commons.bcel6.generic.IF_ICMPNE;
|
||||
import org.apache.commons.bcel6.generic.InstructionConstants;
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.NOP;
|
||||
import org.apache.commons.bcel6.generic.ObjectType;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Null;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
|
||||
@ -31,6 +45,11 @@ public class EqualOp extends RelOp
|
||||
super(offset, variableLength);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
BranchInstruction getOperator() {
|
||||
return new IF_ICMPNE(null);
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.module.GreaterEquOp.8598.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.IF_ICMPLT;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
@ -25,6 +28,11 @@ public class GreaterEquOp extends RelOp
|
||||
super(offset,variableLength);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
BranchInstruction getOperator() {
|
||||
return new IF_ICMPLT(null);
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.module.GreaterOp.8599.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.IF_ICMPLE;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
@ -25,5 +28,10 @@ public class GreaterOp extends RelOp
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
BranchInstruction getOperator() {
|
||||
return new IF_ICMPLE(null);
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.module.LessEquOp.8600.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.IF_ICMPGT;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
@ -25,5 +28,10 @@ public class LessEquOp extends RelOp
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
BranchInstruction getOperator() {
|
||||
return new IF_ICMPGT(null);
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -3,6 +3,8 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.end
|
||||
// ino.module.LessOp.8601.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.IF_ICMPGE;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
@ -25,5 +27,10 @@ public class LessOp extends RelOp
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
BranchInstruction getOperator() {
|
||||
return new IF_ICMPGE(null);
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -18,10 +18,9 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
|
@ -4,6 +4,10 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.module.MinusOp.8603.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.generic.ArithmeticInstruction;
|
||||
import org.apache.commons.bcel6.generic.IADD;
|
||||
import org.apache.commons.bcel6.generic.ISUB;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
@ -25,6 +29,8 @@ public class MinusOp extends AddOp
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
ArithmeticInstruction getOperator(String returnType) {
|
||||
return new ISUB();
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.module.ModuloOp.8604.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.generic.ArithmeticInstruction;
|
||||
import org.apache.commons.bcel6.generic.IREM;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
@ -25,5 +28,10 @@ public class ModuloOp extends MulOp
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
ArithmeticInstruction getOperator(String returnType) {
|
||||
return new IREM();
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -6,16 +6,30 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.generic.ArithmeticInstruction;
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.InvokeInstruction;
|
||||
import org.apache.commons.bcel6.generic.ObjectType;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
// ino.class.MulOp.24231.declaration
|
||||
public abstract class MulOp extends Operator
|
||||
@ -50,6 +64,62 @@ public abstract class MulOp extends Operator
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) {
|
||||
// TODO Plus Operator ist bis jetzt nur für Integer implementiert
|
||||
/*
|
||||
0: aload_1
|
||||
1: invokevirtual #2 // Method java/lang/Integer.intValue:()I
|
||||
4: aload_1
|
||||
5: invokevirtual #2 // Method java/lang/Integer.intValue:()I
|
||||
8: imul
|
||||
9: invokestatic #3 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
|
||||
12: areturn
|
||||
*/
|
||||
DHBWInstructionFactory _factory = _cg.getInstructionFactory();
|
||||
|
||||
String returnType = getReturnType(operator.get_Expr1(), operator.get_Expr2(), rs);
|
||||
|
||||
InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), returnType);
|
||||
|
||||
il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), returnType));
|
||||
|
||||
il.append(getOperator(returnType));
|
||||
|
||||
il.append(convertValueToObject(_factory, returnType));
|
||||
return il;
|
||||
}
|
||||
|
||||
private String getReturnType(Expr expr1, Expr expr2, TypeinferenceResultSet rs) {
|
||||
Type type = expr1.getType();
|
||||
if(type instanceof TypePlaceholder){
|
||||
Type tphType = rs.getTypeOfPlaceholder((TypePlaceholder) expr1.getType());
|
||||
if(tphType instanceof ExtendsWildcardType){
|
||||
return ((ExtendsWildcardType) tphType).get_ExtendsType().get_Name();
|
||||
}else if(tphType instanceof SuperWildcardType){
|
||||
return ((SuperWildcardType) tphType).get_SuperType().get_Name();
|
||||
}else{
|
||||
return tphType.getName().toString();
|
||||
}
|
||||
}else{
|
||||
return type.get_Name();
|
||||
}
|
||||
}
|
||||
|
||||
abstract ArithmeticInstruction getOperator(String returnType);
|
||||
|
||||
private InvokeInstruction convertValueToObject(DHBWInstructionFactory _factory, String returnType) {
|
||||
if(returnType.equals("java.lang.Integer")){
|
||||
return _factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.INT}, Constants.INVOKESTATIC);
|
||||
}else if(returnType.equals("java.lang.Double")){
|
||||
return _factory.createInvoke("java.lang.Double", "valueOf", new ObjectType("java.lang.Double"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.DOUBLE}, Constants.INVOKESTATIC);
|
||||
}else if(returnType.equals("java.lang.Float")){
|
||||
return _factory.createInvoke("java.lang.Float", "valueOf", new ObjectType("java.lang.Float"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.FLOAT}, Constants.INVOKESTATIC);
|
||||
}else if(returnType.equals("java.lang.Long")){
|
||||
return _factory.createInvoke("java.lang.Long", "valueOf", new ObjectType("java.lang.Long"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.LONG}, Constants.INVOKESTATIC);
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -3,7 +3,6 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.end
|
||||
// ino.module.NotEqualOp.8606.import
|
||||
import java.util.Iterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
@ -12,7 +11,10 @@ import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Null;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.IF_ACMPEQ;
|
||||
|
||||
|
||||
// ino.class.NotEqualOp.24241.declaration
|
||||
public class NotEqualOp extends RelOp
|
||||
@ -28,5 +30,10 @@ public class NotEqualOp extends RelOp
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
BranchInstruction getOperator() {
|
||||
return new IF_ACMPEQ(null);
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -5,8 +5,16 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.generic.DADD;
|
||||
import org.apache.commons.bcel6.generic.FADD;
|
||||
import org.apache.commons.bcel6.generic.IADD;
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.LADD;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
@ -19,54 +27,34 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
// ino.class.Operator.24257.declaration
|
||||
public abstract class Operator extends SyntaxTreeNode
|
||||
// ino.end
|
||||
// ino.class.Operator.24257.body
|
||||
{
|
||||
|
||||
// ino.attribute.offset.24261.declaration
|
||||
private int offset;
|
||||
// ino.end
|
||||
// ino.attribute.variableLength.24264.declaration
|
||||
private int variableLength;
|
||||
// ino.end
|
||||
|
||||
// ino.method.Operator.24267.definition
|
||||
public Operator(int offset,int variableLength)
|
||||
// ino.end
|
||||
// ino.method.Operator.24267.body
|
||||
{
|
||||
this.offset=offset;
|
||||
this.variableLength=variableLength;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.getOffset.24270.definition
|
||||
public int getOffset()
|
||||
// ino.end
|
||||
// ino.method.getOffset.24270.body
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.getVariableLength.24273.definition
|
||||
public int getVariableLength()
|
||||
// ino.end
|
||||
// ino.method.getVariableLength.24273.body
|
||||
{
|
||||
return variableLength;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
/**
|
||||
@ -85,11 +73,33 @@ public abstract class Operator extends SyntaxTreeNode
|
||||
* @return
|
||||
*/
|
||||
public abstract HashMap<Type,Type> getReturnTypes(TypeAssumptions ass);
|
||||
|
||||
public abstract InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator);
|
||||
|
||||
|
||||
@Override
|
||||
public Menge<SyntaxTreeNode> getChildren() {
|
||||
return new Menge<>();
|
||||
}
|
||||
|
||||
|
||||
protected InstructionList getInstructionListForOperand(ClassGenerator _cg, TypeinferenceResultSet rs, Expr operand, String returnType){
|
||||
InstructionList il = new InstructionList();
|
||||
il.append(operand.genByteCode(_cg, rs));
|
||||
if(returnType.equals("java.lang.Integer")){
|
||||
il.append(_cg.getInstructionFactory().createInvoke("java.lang.Integer", "intValue", org.apache.commons.bcel6.generic.Type.INT, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL));
|
||||
}else if(returnType.equals("java.lang.Double")){
|
||||
il.append(_cg.getInstructionFactory().createInvoke("java.lang.Double", "doubleValue", org.apache.commons.bcel6.generic.Type.DOUBLE, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL));
|
||||
}else if(returnType.equals("java.lang.Float")){
|
||||
il.append(_cg.getInstructionFactory().createInvoke("java.lang.Float", "floatValue", org.apache.commons.bcel6.generic.Type.FLOAT, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL));
|
||||
}else if(returnType.equals("java.lang.Long")){
|
||||
il.append(_cg.getInstructionFactory().createInvoke("java.lang.Long", "longValue", org.apache.commons.bcel6.generic.Type.LONG, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL));
|
||||
}else if(returnType.equals("java.lang.String")){
|
||||
|
||||
}else{
|
||||
throw new NotImplementedException(returnType);
|
||||
}
|
||||
return il;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -2,6 +2,19 @@
|
||||
package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.end
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.GOTO;
|
||||
import org.apache.commons.bcel6.generic.IFEQ;
|
||||
import org.apache.commons.bcel6.generic.IFNE;
|
||||
import org.apache.commons.bcel6.generic.InstructionConstants;
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.ObjectType;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
|
||||
// ino.class.OrOp.24282.declaration
|
||||
public class OrOp extends LogOp
|
||||
@ -17,6 +30,47 @@ public class OrOp extends LogOp
|
||||
super(offset,variableLength);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) {
|
||||
/*
|
||||
0: aload_1
|
||||
1: invokevirtual #2 // Method java/lang/Boolean.booleanValue:()Z
|
||||
4: ifne 14
|
||||
7: aload_2
|
||||
8: invokevirtual #2 // Method java/lang/Boolean.booleanValue:()Z
|
||||
11: ifeq 18
|
||||
14: iconst_1
|
||||
15: goto 19
|
||||
18: iconst_0
|
||||
19: invokestatic #3 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
|
||||
22: areturn
|
||||
*/
|
||||
DHBWInstructionFactory _factory = _cg.getInstructionFactory();
|
||||
|
||||
InstructionList il = operator.get_Expr1().genByteCode(_cg, rs);
|
||||
il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", org.apache.commons.bcel6.generic.Type.BOOLEAN, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL));
|
||||
|
||||
BranchInstruction firstTest = new IFNE(null);
|
||||
il.append(firstTest);
|
||||
|
||||
il.append(operator.get_Expr2().genByteCode(_cg, rs));
|
||||
il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", org.apache.commons.bcel6.generic.Type.BOOLEAN, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL));
|
||||
|
||||
BranchInstruction secondTest = new IFEQ(null);
|
||||
il.append(secondTest);
|
||||
|
||||
firstTest.setTarget(il.append(InstructionConstants.ICONST_1));
|
||||
|
||||
BranchInstruction gotoInstruction = new GOTO(null);
|
||||
il.append(gotoInstruction);
|
||||
|
||||
secondTest.setTarget(il.append(InstructionConstants.ICONST_0));
|
||||
|
||||
gotoInstruction.setTarget(il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.BOOLEAN}, Constants.INVOKESTATIC)));
|
||||
|
||||
return il;
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -3,10 +3,30 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.end
|
||||
// ino.module.PlusOp.8609.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.generic.ArithmeticInstruction;
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.DADD;
|
||||
import org.apache.commons.bcel6.generic.FADD;
|
||||
import org.apache.commons.bcel6.generic.GOTO;
|
||||
import org.apache.commons.bcel6.generic.IADD;
|
||||
import org.apache.commons.bcel6.generic.IFEQ;
|
||||
import org.apache.commons.bcel6.generic.IFNE;
|
||||
import org.apache.commons.bcel6.generic.InstructionConstants;
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.InvokeInstruction;
|
||||
import org.apache.commons.bcel6.generic.LADD;
|
||||
import org.apache.commons.bcel6.generic.ObjectType;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
|
||||
|
||||
|
||||
@ -24,6 +44,19 @@ public class PlusOp extends AddOp
|
||||
super(offset,variableLength);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
ArithmeticInstruction getOperator(String returnType) {
|
||||
if(returnType.equals("java.lang.Integer")){
|
||||
return new IADD();
|
||||
}else if(returnType.equals("java.lang.Double")){
|
||||
return new DADD();
|
||||
}else if(returnType.equals("java.lang.Float")){
|
||||
return new FADD();
|
||||
}else if(returnType.equals("java.lang.Long")){
|
||||
return new LADD();
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -6,17 +6,27 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.generic.BranchInstruction;
|
||||
import org.apache.commons.bcel6.generic.GOTO;
|
||||
import org.apache.commons.bcel6.generic.InstructionConstants;
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.ObjectType;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
// ino.class.RelOp.24299.declaration
|
||||
public abstract class RelOp extends Operator
|
||||
// ino.end
|
||||
@ -54,6 +64,45 @@ public abstract class RelOp extends Operator
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) {
|
||||
/*
|
||||
0: aload_1
|
||||
1: invokevirtual #3 // Method java/lang/Integer.intValue:()I
|
||||
4: aload_2
|
||||
5: invokevirtual #3 // Method java/lang/Integer.intValue:()I
|
||||
8: if_icmplt 15
|
||||
11: iconst_1
|
||||
12: goto 16
|
||||
15: iconst_0
|
||||
16: invokestatic #2 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
|
||||
19: areturn
|
||||
*/
|
||||
|
||||
DHBWInstructionFactory _factory = _cg.getInstructionFactory();
|
||||
|
||||
InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), "java.lang.Boolean");
|
||||
|
||||
il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), "java.lang.Boolean"));
|
||||
|
||||
BranchInstruction operatorBranchInstruction = getOperator();
|
||||
|
||||
il.append(operatorBranchInstruction);
|
||||
|
||||
il.append(InstructionConstants.ICONST_1);
|
||||
|
||||
BranchInstruction gotoInstruction = new GOTO(null);
|
||||
|
||||
il.append(gotoInstruction);
|
||||
|
||||
operatorBranchInstruction.setTarget(il.append(InstructionConstants.ICONST_0));
|
||||
gotoInstruction.setTarget(il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.BOOLEAN}, Constants.INVOKESTATIC)));
|
||||
|
||||
return il;
|
||||
}
|
||||
|
||||
abstract BranchInstruction getOperator();
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -4,6 +4,13 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
|
||||
// ino.module.TimesOp.8611.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
import org.apache.commons.bcel6.generic.ArithmeticInstruction;
|
||||
import org.apache.commons.bcel6.generic.DMUL;
|
||||
import org.apache.commons.bcel6.generic.FMUL;
|
||||
import org.apache.commons.bcel6.generic.IMUL;
|
||||
import org.apache.commons.bcel6.generic.LMUL;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
@ -22,6 +29,20 @@ public class TimesOp extends MulOp
|
||||
super(offset,variableLength);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
ArithmeticInstruction getOperator(String returnType) {
|
||||
if(returnType.equals("java.lang.Integer")){
|
||||
return new IMUL();
|
||||
}else if(returnType.equals("java.lang.Double")){
|
||||
return new DMUL();
|
||||
}else if(returnType.equals("java.lang.Float")){
|
||||
return new FMUL();
|
||||
}else if(returnType.equals("java.lang.Long")){
|
||||
return new LMUL();
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -1,39 +1,27 @@
|
||||
// ino.module.ArgumentList.8621.package
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
// ino.end
|
||||
// ino.module.ArgumentList.8621.import
|
||||
import java.util.Iterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
|
||||
|
||||
|
||||
|
||||
// ino.class.ArgumentList.24911.declaration
|
||||
public class ArgumentList extends SyntaxTreeNode
|
||||
// ino.end
|
||||
// ino.class.ArgumentList.24911.body
|
||||
{
|
||||
// ino.attribute.expr.24914.declaration
|
||||
public Menge<Expr> expr = new Menge<Expr>();
|
||||
// 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
|
||||
@ -93,6 +81,22 @@ public class ArgumentList extends SyntaxTreeNode
|
||||
public Menge<? extends SyntaxTreeNode> getChildren() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
||||
public InstructionList generateBytecode(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
InstructionList ret = new InstructionList();
|
||||
for(Expr e : expr){
|
||||
ret.append(e.genByteCode(cg, rs));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public org.apache.commons.bcel6.generic.Type[] getBytecodeTypeList(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
org.apache.commons.bcel6.generic.Type[] ret = new org.apache.commons.bcel6.generic.Type[expr.size()];
|
||||
int i = 0;
|
||||
for(Expr e : expr){
|
||||
ret[i] = e.getType().getBytecodeType(cg, rs);
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -17,6 +17,7 @@ import org.apache.commons.bcel6.generic.LSTORE;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
@ -33,9 +34,9 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
@ -106,8 +107,8 @@ public class Assign extends Expr
|
||||
ret.add(expr2.TYPEExpr(assumptions));
|
||||
//this.setTypeVariable( TypePlaceholder.fresh(this));
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
ret.add(new SingleConstraint(expr2.getType().TYPE(assumptions, this), expr1.getType().TYPE(assumptions, this))); //expr2.type <. expr1.type
|
||||
ret.add(new SingleConstraint(expr1.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
|
||||
ret.add(ConstraintsSet.createSingleConstraint(expr2.getType().TYPE(assumptions, this), expr1.getType().TYPE(assumptions, this))); //expr2.type <. expr1.type
|
||||
ret.add(ConstraintsSet.createSingleConstraint(expr1.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -175,17 +176,10 @@ public class Assign extends Expr
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static int counterAssign = 0; //Zaehlvariable f<>r ISTORE
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
// TODO Auto-generated method stub
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr
|
||||
|
||||
//TODO: ^^
|
||||
counterAssign++; //macht STORE f<>r meherere Variable nutzbar (nicht nur ISTORE_1, ISTORE_2, etc.)
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = expr2.genByteCode(cg, rs);//expr2 rechte expr
|
||||
|
||||
/*
|
||||
String expr2Type = expr2.getType().get_Name().toString();
|
||||
@ -212,7 +206,7 @@ public class Assign extends Expr
|
||||
}
|
||||
*/
|
||||
//Es wird momentan immer von RefType ausgegangen:
|
||||
il.append(new ASTORE(counterAssign));
|
||||
il.append(cg.getMethodGenerator().createStore(expr2.getType().getBytecodeType(cg, rs), expr1.get_Name()));
|
||||
|
||||
return il;
|
||||
}
|
||||
|
@ -38,11 +38,10 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -227,28 +226,8 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
InstructionList linkeSeite = this.expr1.genByteCode(_cg);
|
||||
InstructionList rechteSeite = this.expr2.genByteCode(_cg);
|
||||
if(this.getReturnType().getName().equals(new JavaClassName("String"))){
|
||||
throw new TypeinferenceException("Zeichenketten zusammenfügen ist noch nicht unterstützt",this);
|
||||
}
|
||||
|
||||
linkeSeite.append(rechteSeite);
|
||||
|
||||
//TODO: bytecode (Bis jetzt wird jeder Condition als EQUALS behandelt)
|
||||
//TODO: bytecode autoboxing
|
||||
|
||||
BranchInstruction if_icmpneInstruction = new IF_ICMPNE(null);
|
||||
linkeSeite.append(if_icmpneInstruction);
|
||||
linkeSeite.append(InstructionConstants.ICONST_1);
|
||||
|
||||
BranchInstruction gotoInstruction = new GOTO(null);
|
||||
|
||||
linkeSeite.append(gotoInstruction);
|
||||
if_icmpneInstruction.setTarget(linkeSeite.append(InstructionConstants.ICONST_0));
|
||||
gotoInstruction.setTarget(linkeSeite.append(new NOP()));
|
||||
return linkeSeite;
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
return op.genByteCode(_cg, rs, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,11 +32,10 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -187,8 +186,8 @@ public class Block extends Statement
|
||||
}
|
||||
else {
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(this);
|
||||
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), tph));
|
||||
ret.add(new SingleConstraint(stmt.getType().TYPE(assumptions, this), tph));
|
||||
ret.add(ConstraintsSet.createSingleConstraint(this.getType().TYPE(assumptions, this), tph));
|
||||
ret.add(ConstraintsSet.createSingleConstraint(stmt.getType().TYPE(assumptions, this), tph));
|
||||
this.setType(tph);
|
||||
}
|
||||
}
|
||||
@ -256,12 +255,12 @@ public class Block extends Statement
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
//ConstantPoolGen _cp = cg.getConstantPool();
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
for(Statement stmt : this.get_Statement()){
|
||||
il.append(stmt.genByteCode(cg));
|
||||
il.append(stmt.genByteCode(cg, rs));
|
||||
}
|
||||
//il.dispose();
|
||||
|
||||
|
@ -22,8 +22,8 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -130,7 +130,7 @@ public class BoolLiteral extends Literal
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
|
@ -23,8 +23,8 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ public class CastExpr extends UnaryExpr
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -125,7 +125,7 @@ public class CharLiteral extends Literal
|
||||
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
il.append(new BIPUSH((byte) get_Char()));
|
||||
|
@ -25,8 +25,8 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -145,7 +145,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
ConstantPoolGen cp = _cg.getConstantPool();
|
||||
//InstructionFactory _factory = new InstructionFactory(cg, cp);
|
||||
InstructionList il = new InstructionList();
|
||||
|
@ -19,9 +19,9 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ public class EmptyStmt extends Statement
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import de.dhbwstuttgart.core.MyCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
// ino.class.ExprStmt.25265.declaration
|
||||
public abstract class ExprStmt extends Statement
|
||||
|
@ -23,6 +23,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
|
||||
|
||||
@ -133,7 +134,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
ConstantPoolGen cp = _cg.getConstantPool();
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
|
@ -33,14 +33,10 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
|
||||
|
||||
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
public class ForStmt extends Statement
|
||||
{
|
||||
@ -133,7 +129,7 @@ public class ForStmt extends Statement
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
/*
|
||||
0: iconst_0
|
||||
1: istore_1
|
||||
@ -147,16 +143,16 @@ public class ForStmt extends Statement
|
||||
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
il.append(head_Initializer.genByteCode(_cg));
|
||||
il.append(head_Initializer.genByteCode(_cg, rs));
|
||||
|
||||
InstructionHandle ih = il.append(head_Condition.genByteCode(_cg));
|
||||
InstructionHandle ih = il.append(head_Condition.genByteCode(_cg, rs));
|
||||
|
||||
BranchInstruction branch = new IF_ICMPGE(null);
|
||||
il.append(branch);
|
||||
|
||||
il.append(body_Loop_block.genByteCode(_cg));
|
||||
il.append(body_Loop_block.genByteCode(_cg, rs));
|
||||
|
||||
il.append(head_Loop_expr.genByteCode(_cg));
|
||||
il.append(head_Loop_expr.genByteCode(_cg, rs));
|
||||
|
||||
il.append(new GOTO(ih));
|
||||
|
||||
|
@ -44,11 +44,10 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.unify.MUB;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
@ -141,10 +140,10 @@ public class IfStmt extends Statement
|
||||
ret.add(this.then_block.TYPEStmt(assumptions));
|
||||
if(else_block!=null){
|
||||
ret.add(this.else_block.TYPEStmt(assumptions));
|
||||
if(!(else_block.getType() instanceof Void))ret.add(new SingleConstraint(else_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
|
||||
if(!(else_block.getType() instanceof Void))ret.add(ConstraintsSet.createSingleConstraint(else_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
|
||||
}
|
||||
ret.add(new SingleConstraint(expr.getType().TYPE(assumptions, this),new RefType("Boolean",this,0).TYPE(assumptions, this))); //(expressionDesIfStmt)<.boolean
|
||||
if(!(then_block.getType() instanceof Void))ret.add(new SingleConstraint(then_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
|
||||
ret.add(ConstraintsSet.createSingleConstraint(expr.getType().TYPE(assumptions, this),new RefType("Boolean",this,0).TYPE(assumptions, this))); //(expressionDesIfStmt)<.boolean
|
||||
if(!(then_block.getType() instanceof Void))ret.add(ConstraintsSet.createSingleConstraint(then_block.getType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
|
||||
if(then_block.getType() instanceof Void &&
|
||||
(else_block == null || else_block.getType() instanceof Void))this.setType(new Void(this,this.getOffset()));
|
||||
return ret;
|
||||
@ -178,22 +177,22 @@ public class IfStmt extends Statement
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
InstructionFactory _factory = _cg.getInstructionFactory();
|
||||
InstructionList il = new InstructionList();
|
||||
IfInstruction ifInstruction = new IFEQ(null);
|
||||
|
||||
il.append(expr.genByteCode(_cg));
|
||||
il.append(expr.genByteCode(_cg, rs));
|
||||
//Anmerkung: expr ist vom Typ java.lang.Boolean (per Definition)
|
||||
il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", org.apache.commons.bcel6.generic.Type.BOOLEAN, org.apache.commons.bcel6.generic.Type.NO_ARGS, Constants.INVOKEVIRTUAL));
|
||||
il.append(ifInstruction);
|
||||
il.append(then_block.genByteCode(_cg));
|
||||
il.append(then_block.genByteCode(_cg, rs));
|
||||
|
||||
if(else_block != null && !(else_block instanceof EmptyStmt)){
|
||||
GotoInstruction gotoInstruction = new GOTO(null);
|
||||
il.append(gotoInstruction);
|
||||
ifInstruction.setTarget(il.append(else_block.genByteCode(_cg)));
|
||||
gotoInstruction.setTarget(il.append(new NOP()));
|
||||
//GotoInstruction gotoInstruction = new GOTO(null);
|
||||
//il.append(gotoInstruction);
|
||||
ifInstruction.setTarget(il.append(else_block.genByteCode(_cg, rs)));
|
||||
//gotoInstruction.setTarget(il.append(new NOP()));
|
||||
}else{
|
||||
ifInstruction.setTarget(il.append(new NOP()));
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ public class InstVar extends Expr
|
||||
{
|
||||
super(offset,variableLength);
|
||||
Iterator namen = ui.get_Name().iterator();
|
||||
LocalOrFieldVar innerLOFV = new LocalOrFieldVar((String)namen.next(),getOffset());
|
||||
LocalOrFieldVarOrClassname innerLOFV = new LocalOrFieldVarOrClassname((String)namen.next(),getOffset());
|
||||
//innerLOFV.setType(TypePlaceholder.fresh(this));
|
||||
InstVar INSTVA = new InstVar(innerLOFV, (String)namen.next(),offset);
|
||||
//INSTVA.setType(TypePlaceholder.fresh(this));
|
||||
@ -166,25 +166,16 @@ public class InstVar extends Expr
|
||||
* <br/>Author: Martin Pl�micke
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.toString.25441.definition
|
||||
public String toString()
|
||||
// ino.end
|
||||
// ino.method.toString.25441.body
|
||||
{
|
||||
String superType = "";
|
||||
if(super.type != null)superType += super.type.toString();
|
||||
return superType + " " + usedid.toString();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25444.definition
|
||||
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist, Menge<GenericTypeVar> genericMethodParameters)
|
||||
// ino.end
|
||||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25444.body
|
||||
{
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
@ -220,7 +211,7 @@ public class InstVar extends Expr
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
|
||||
|
||||
@ -119,7 +120,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -139,7 +139,7 @@ public class IntLiteral extends Literal
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
|
@ -41,12 +41,11 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.Typeable;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
/**
|
||||
* @author A10023 - Andreas Stadelmeier
|
||||
@ -165,40 +164,15 @@ public class LambdaExpression extends Expr{
|
||||
ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression
|
||||
|
||||
//Die Constraints für ParameterTypen und Ret Typ erstellen:
|
||||
Menge<Type> modifiedParamTypes = new Menge<>();
|
||||
for(Type pT : paramTypes){
|
||||
if(pT instanceof WildcardType){
|
||||
//Auf Typfehler kontrollieren. Siehe Bug #12 Kommentar 3
|
||||
if(pT instanceof ExtendsWildcardType){
|
||||
throw new TypeinferenceException("Typfehler von Parametertyp "+pT,this);
|
||||
}else{
|
||||
modifiedParamTypes.add(pT);
|
||||
}
|
||||
}else{
|
||||
modifiedParamTypes.add(new SuperWildcardType((ObjectType) pT));
|
||||
}
|
||||
}
|
||||
|
||||
Type retType = method_body.getType();
|
||||
// PN < TPH PN
|
||||
if(retType instanceof WildcardType){
|
||||
//Auf Typfehler kontrollieren. Siehe Bug #12 Kommentar 3
|
||||
if(retType instanceof SuperWildcardType){
|
||||
throw new TypeinferenceException("Typfehler von Parametertyp "+retType,this);
|
||||
}else{
|
||||
//retType bleibt unverändert
|
||||
}
|
||||
}else{
|
||||
//Die LambdaExpression kann zu diesem Zeit schon feststellen, ob der Return-Type Void ist (Kein Return-Statement):
|
||||
if(!typeIsVoid(retType)){ //Nur, wenn es nicht void ist, kann der ExtendsWildcardType gebildet werden.
|
||||
retType = new ExtendsWildcardType((ObjectType) retType);
|
||||
}
|
||||
}
|
||||
|
||||
if(typeIsVoid(retType)){//In diesem Fall, muss der Typ des LambdaAusdrucks FunVoid sein
|
||||
this.lambdaType = new FunVoidN(modifiedParamTypes);
|
||||
this.lambdaType = new FunVoidN(paramTypes);
|
||||
}else{
|
||||
this.lambdaType = new FunN(retType, modifiedParamTypes);
|
||||
this.lambdaType = new FunN(retType, paramTypes);
|
||||
}
|
||||
ret.add(new SingleConstraint(lambdaType.TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
|
||||
ret.add(ConstraintsSet.createSingleConstraint(lambdaType.TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -238,12 +212,12 @@ public class LambdaExpression extends Expr{
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
ConstantPoolGen cp = cg.getConstantPool();
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
org.apache.commons.bcel6.generic.Type[] paramTypes = params.getBytecodeTypeList(cg);
|
||||
org.apache.commons.bcel6.generic.Type retType = method_body.getType().getBytecodeType(cg);
|
||||
org.apache.commons.bcel6.generic.Type[] paramTypes = params.getBytecodeTypeList(cg, rs);
|
||||
org.apache.commons.bcel6.generic.Type retType = method_body.getType().getBytecodeType(cg, rs);
|
||||
|
||||
MethodGenerator lambdaMethod = new MethodGenerator(0, retType,
|
||||
paramTypes, params.getParameterNameArray(), cg.createLambdaMethodName(),
|
||||
@ -255,18 +229,18 @@ public class LambdaExpression extends Expr{
|
||||
|
||||
String interfaceMethodName = "apply"; //Das ist ein Hack, funktioniert momentan, da nur FunN Interfaces für LambdaAusdrücke funktionieren
|
||||
il.append(InstructionFactory.createLoad( org.apache.commons.bcel6.generic.Type.OBJECT, 0));
|
||||
il.append(cg.getInstructionFactory().createInvokeDynamic(interfaceMethodName,this.getLambdaSignature(cg),lambdaType,lambdaMethod));
|
||||
il.append(cg.getInstructionFactory().createInvokeDynamic(interfaceMethodName,this.getLambdaSignature(cg, rs),lambdaType,lambdaMethod, rs));
|
||||
|
||||
cg.addMethod(lambdaMethod.createMethod(cg, params, method_body.getType(), method_body));
|
||||
cg.addMethod(lambdaMethod.createMethod(cg, params, method_body.getType(), method_body, rs));
|
||||
|
||||
return il;
|
||||
}
|
||||
|
||||
private String getLambdaSignature(ClassGenerator cg){
|
||||
private String getLambdaSignature(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
String typeSignature = "(";
|
||||
typeSignature+=this.getParentClass().getType().getBytecodeType(cg).getSignature();
|
||||
typeSignature+=this.getParentClass().getType().getBytecodeType(cg, rs).getSignature();
|
||||
typeSignature += ")";
|
||||
typeSignature += this.lambdaType.getBytecodeType(cg).getSignature();
|
||||
typeSignature += this.lambdaType.getBytecodeType(cg, rs).getSignature();
|
||||
return typeSignature;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
// ino.end
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
// ino.class.Literal.25490.declaration
|
||||
public abstract class Literal extends Expr
|
||||
|
@ -28,17 +28,17 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
|
||||
// ino.class.LocalOrFieldVar.25503.declaration
|
||||
public class LocalOrFieldVar extends Expr
|
||||
public class LocalOrFieldVarOrClassname extends Expr
|
||||
// ino.end
|
||||
// ino.class.LocalOrFieldVar.25503.body
|
||||
{
|
||||
@ -47,9 +47,10 @@ public class LocalOrFieldVar extends Expr
|
||||
protected static Logger parserlog = Logger.getLogger("parser");
|
||||
// ino.end
|
||||
private boolean isFieldAccess = false;
|
||||
private boolean isClassAccess = false;
|
||||
|
||||
// ino.method.LocalOrFieldVar.25510.definition
|
||||
public LocalOrFieldVar(int offset, int variableLength)
|
||||
public LocalOrFieldVarOrClassname(int offset, int variableLength)
|
||||
// ino.end
|
||||
// ino.method.LocalOrFieldVar.25510.body
|
||||
{
|
||||
@ -58,7 +59,7 @@ public class LocalOrFieldVar extends Expr
|
||||
// ino.end
|
||||
|
||||
// ino.method.LocalOrFieldVar.25513.definition
|
||||
public LocalOrFieldVar(String n, int offset)
|
||||
public LocalOrFieldVarOrClassname(String n, int offset)
|
||||
// ino.end
|
||||
// ino.method.LocalOrFieldVar.25513.body
|
||||
{
|
||||
@ -120,14 +121,23 @@ public class LocalOrFieldVar extends Expr
|
||||
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.getParentClass());
|
||||
if(thisTypeAssumption == null)throw new TypeinferenceException("Eine Variable "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this);
|
||||
Type thisType = thisTypeAssumption.checkTYPE(assumptions, this);
|
||||
this.setType(thisType);
|
||||
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
|
||||
//Rausfinden, ob es Feld oder Locale Variable ist:
|
||||
for(FieldAssumption fAss : assumptions.getFieldVars(this.get_Name())){
|
||||
if(this.getParentClass().equals(fAss.getParentClass()))this.isFieldAccess = true;
|
||||
};
|
||||
if(thisTypeAssumption == null){//Es ist keine Variable oder Feld
|
||||
//Testen ob es ein Klassenname ist:
|
||||
ClassAssumption cAss = assumptions.getClass(this.get_Name());
|
||||
if(cAss == null)throw new TypeinferenceException("Weder eine Variable noch eine Klasse "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this);
|
||||
|
||||
thisTypeAssumption = cAss.getAssumedClass().getType();
|
||||
this.set_Type(thisTypeAssumption);
|
||||
this.isClassAccess = true;
|
||||
}else{
|
||||
Type thisType = thisTypeAssumption.checkTYPE(assumptions, this);
|
||||
this.setType(thisType);
|
||||
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
|
||||
//Rausfinden, ob es Feld oder Locale Variable ist:
|
||||
for(FieldAssumption fAss : assumptions.getFieldVars(this.get_Name())){
|
||||
if(this.getParentClass().equals(fAss.getParentClass()))this.isFieldAccess = true;
|
||||
};
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -148,18 +158,18 @@ public class LocalOrFieldVar extends Expr
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
InstructionList il = new InstructionList();
|
||||
if(this.isFieldAccess){
|
||||
il.append(cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), this.get_Name(), this.getType().getBytecodeType(cg), Constants.GETFIELD));
|
||||
il.append(cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), this.get_Name(), this.getType().getBytecodeType(cg, rs), Constants.GETFIELD));
|
||||
}
|
||||
|
||||
Type type = this.getType();
|
||||
org.apache.commons.bcel6.generic.Type byteCodeType = type.getBytecodeType(cg);
|
||||
org.apache.commons.bcel6.generic.Type byteCodeType = type.getBytecodeType(cg, rs);
|
||||
|
||||
String name = this.get_Name();
|
||||
|
||||
il.append(cg.getInstructionFactory().createLoad(byteCodeType, name));
|
||||
il.append(cg.getMethodGenerator().createLoad(byteCodeType, name));
|
||||
return il;
|
||||
}
|
||||
|
@ -27,14 +27,13 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeInsertable;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.LocalVarAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -100,59 +99,6 @@ public class LocalVarDecl extends Statement implements TypeInsertable
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.is_declared.25587.definition
|
||||
public void is_declared(Type t, Menge<Class> classlist)
|
||||
throws SCStatementException
|
||||
// ino.end
|
||||
// ino.method.is_declared.25587.body
|
||||
{
|
||||
boolean flag=false;
|
||||
for(Enumeration<Class> 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 Menge 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().toString());
|
||||
ex.addException(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
||||
/*
|
||||
// ino.method.check_anz.25590.definition
|
||||
public void check_anz(Type type, Menge paralist, Menge<Class> classlist)
|
||||
@ -371,14 +317,14 @@ public class LocalVarDecl extends Statement implements TypeInsertable
|
||||
}
|
||||
assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird.
|
||||
//if(this.getType() == null)throw new DebugException("Parser Post Processing nicht aufgerufen");
|
||||
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
|
||||
ret.add(ConstraintsSet.createSingleConstraint(this.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
|
||||
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
|
||||
this.setReturnType(new Void(this,0)); //Return typ einer Variablendeklaration ist Void
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription(){
|
||||
if(this.getType() == null)return "no type " + declid.toString();
|
||||
if(this.getType() instanceof TypePlaceholder)return declid.toString();
|
||||
return this.getType().toString() + " " + declid.toString();
|
||||
@ -429,8 +375,8 @@ public class LocalVarDecl extends Statement implements TypeInsertable
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
// TODO Auto-generated method stub
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
_cg.getMethodGenerator().getStoreIndex(get_Name());
|
||||
return new InstructionList();
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -129,7 +129,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
ConstantPoolGen cp = _cg.getConstantPool();
|
||||
//InstructionFactory _factory = new InstructionFactory(cg, cp);
|
||||
InstructionList il = new InstructionList();
|
||||
|
@ -12,6 +12,7 @@ import org.apache.commons.bcel6.generic.InstructionList;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
@ -25,6 +26,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
@ -321,15 +323,15 @@ public class MethodCall extends Expr
|
||||
*/
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
InstructionList il = new InstructionList();
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
DHBWInstructionFactory _factory = cg.getInstructionFactory();
|
||||
|
||||
il.append(receiver.get_Expr().genByteCode(cg));
|
||||
il.append(receiver.get_Expr().genByteCode(cg, rs));
|
||||
|
||||
//Herausfinden, ob eine Methode oder ein Interface aufgerufen wird:
|
||||
Type receiverType = this.receiver.get_Expr().getType();
|
||||
de.dhbwstuttgart.syntaxtree.Class receiverClass = this.receiver.getReceiverClass(cg);
|
||||
de.dhbwstuttgart.syntaxtree.Class receiverClass = this.receiver.getReceiverClass(cg, rs);
|
||||
short kind = 0;
|
||||
if(receiverClass.isInterface()){
|
||||
kind = Constants.INVOKEINTERFACE;
|
||||
@ -342,15 +344,17 @@ public class MethodCall extends Expr
|
||||
argumentTypen = new org.apache.commons.bcel6.generic.Type[this.getArgumentList().size()];
|
||||
int i = 0;
|
||||
for(Expr argument : this.arglist.expr){
|
||||
argumentTypen[i] = argument.getType().getBytecodeType(cg);
|
||||
cg.getMethodGenerator().getStoreIndex(argument.get_Name());
|
||||
|
||||
argumentTypen[i] = argument.getType().getBytecodeType(cg, rs);
|
||||
//Das Argument auf den Stack legen:
|
||||
il.append(argument.genByteCode(cg));
|
||||
il.append(argument.genByteCode(cg, rs));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
org.apache.commons.bcel6.generic.Type returnType = this.getType().getBytecodeType(cg);
|
||||
il.append(_factory.createInvoke(receiver.getReceiverClass(cg).getName().toString(), this.get_Name(), returnType , argumentTypen, kind));
|
||||
org.apache.commons.bcel6.generic.Type returnType = this.getType().getBytecodeType(cg, rs);
|
||||
il.append(_factory.createInvoke(receiver.getReceiverClass(cg, rs).getName().toString(), this.get_Name(), returnType , argumentTypen, kind));
|
||||
return il;
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,9 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
@ -112,7 +112,7 @@ public class NegativeExpr extends UnaryExpr
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -147,11 +147,11 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
il.append(expr.elementAt(0).genByteCode(_cg));
|
||||
il.append(expr.elementAt(0).genByteCode(_cg, rs));
|
||||
il.append(_factory.createNewArray( org.apache.commons.bcel6.generic.Type.getType(getTypeName()), (short)1));
|
||||
|
||||
|
||||
|
@ -6,8 +6,13 @@ import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.bcel6.Constants;
|
||||
import org.apache.commons.bcel6.generic.ClassGen;
|
||||
import org.apache.commons.bcel6.generic.InstructionConstants;
|
||||
|
||||
import org.apache.commons.bcel6.generic.InstructionList;
|
||||
import org.apache.commons.bcel6.generic.ObjectType;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
@ -29,12 +34,11 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -55,6 +59,7 @@ public class NewClass extends Expr
|
||||
|
||||
// ino.attribute.arglist.25837.declaration
|
||||
private ArgumentList arglist;
|
||||
private boolean isStatement = false;
|
||||
// ino.end
|
||||
// ino.attribute.parserlog.25840.declaration
|
||||
protected static Logger parserlog = Logger.getLogger("parser");
|
||||
@ -129,15 +134,7 @@ public class NewClass extends Expr
|
||||
//TODO: Das hier noch vervollständigen
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
UndConstraint callConstraints = new UndConstraint();
|
||||
//Die Auskommentierten Zeilen gehören zu MethodRefNew
|
||||
//Menge<Type> argumentTypeList = new Menge<Type>();
|
||||
//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);
|
||||
int numArgs = 0;
|
||||
if(this.arglist != null)numArgs = this.arglist.size();
|
||||
ConstructorAssumption cA = assumptions.getConstructorAssumption(this.get_Name(), numArgs);
|
||||
@ -147,22 +144,9 @@ public class NewClass extends Expr
|
||||
ret.add(this.arglist.expr.elementAt(i).TYPEExpr(assumptions));
|
||||
callConstraints.addConstraint( this.arglist.expr.elementAt(i).getType().TYPE(assumptions, this), cA.getParameterType(i).TYPE(assumptions, this));
|
||||
}
|
||||
//if(this.arglist != null && this.arglist.expr != null)for(Expr arg : this.arglist.expr){
|
||||
// ret.add(arg.TYPEExpr(assumptions));
|
||||
//}
|
||||
Type thisT = assumptions.checkType(new RefType(this.get_Name(),this,0), (SyntaxTreeNode)this);
|
||||
this.setType(thisT);
|
||||
|
||||
|
||||
/*
|
||||
//Ein new-Aufruf ist nichts anderes als ein MethodCall der Methode <init>
|
||||
MethodCall newAufruf = new MethodCall(0,0);
|
||||
this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),0)));
|
||||
newAufruf.type = this.getType();
|
||||
newAufruf.set_Name("<init>");
|
||||
newAufruf.set_Receiver(null);
|
||||
ret.add(new Overloading(assumptions, newAufruf, this.getType()).generateConsstraints());
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -176,6 +160,7 @@ public class NewClass extends Expr
|
||||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){
|
||||
ConstraintsSet ret = this.TYPEExpr(assumptions); //TypeExpr aufrufen
|
||||
this.setType(new Void(this,0)); //Typ des Statments auf Void setzen.
|
||||
this.isStatement = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -207,9 +192,29 @@ public class NewClass extends Expr
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
InstructionList il = new InstructionList();
|
||||
//il.append(_cg.getInstructionFactory().createNew(get_Name()));
|
||||
il.append(_cg.getInstructionFactory().createNew(this.getType().getBytecodeType(_cg, rs).toString()));
|
||||
il.append(InstructionConstants.DUP);
|
||||
|
||||
String signature = getType().getBytecodeSignature(_cg, rs);
|
||||
String description = signature.substring(1, signature.length()-1);
|
||||
|
||||
if(arglist!=null){
|
||||
il.append(arglist.generateBytecode(_cg, rs));
|
||||
il.append(_cg.getInstructionFactory().createInvoke(description, "<init>",
|
||||
org.apache.commons.bcel6.generic.Type.VOID,
|
||||
this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL));
|
||||
}else{
|
||||
il.append(_cg.getInstructionFactory().createInvoke(description, "<init>",
|
||||
org.apache.commons.bcel6.generic.Type.VOID,
|
||||
new org.apache.commons.bcel6.generic.Type[]{}, Constants.INVOKESPECIAL));
|
||||
}
|
||||
if(this.isStatement){
|
||||
il.append(InstructionConstants.POP);
|
||||
}
|
||||
return il;
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,9 +26,9 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
@ -136,7 +136,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ public class Null extends Literal
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
|
@ -20,8 +20,8 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
|
||||
|
||||
@ -120,7 +120,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -30,10 +30,10 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
public static int counterPostInc = 0;
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
counterPostInc++;
|
||||
|
@ -26,9 +26,9 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
@ -92,7 +92,7 @@ public class PreDecExpr extends UnaryExpr
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user