TypeinferenceResultSet von ClassGenerator getrennt
This commit is contained in:
parent
8ae7bda535
commit
dd478961e2
@ -62,22 +62,13 @@ public class ClassGenerator extends ClassGen{
|
||||
//return getNearestType((TypePlaceholder) t);
|
||||
return new TypePlaceholderType((TypePlaceholder) t);
|
||||
}else{
|
||||
return t.getBytecodeType(this);
|
||||
return t.getBytecodeType(this, getTypeinferenceResults().getTypeReconstructions().firstElement());
|
||||
}
|
||||
}
|
||||
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++);
|
||||
}
|
||||
@ -135,7 +126,7 @@ public class ClassGenerator extends ClassGen{
|
||||
|
||||
//Signatur setzen:
|
||||
String typeParameters = this.generateParameterSignature();
|
||||
String superClassSignature = this.superClass.getBytecodeSignature(this);
|
||||
String superClassSignature = this.superClass.getBytecodeSignature(this, getTypeinferenceResults().getTypeReconstructions().firstElement());
|
||||
String classSignature = typeParameters + superClassSignature;
|
||||
if(classSignature.length()>0){
|
||||
this.addAttribute(new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(classSignature),cp.getConstantPool()));
|
||||
@ -153,7 +144,7 @@ public class ClassGenerator extends ClassGen{
|
||||
TypePlaceholder tph = it.next();
|
||||
//ret += tph.getBytecodeMethodSignature(this);
|
||||
//ret += ":";
|
||||
ret += tph.getClassSignature(this);
|
||||
ret += tph.getClassSignature(this, getTypeinferenceResults().getTypeReconstructions().firstElement());
|
||||
}
|
||||
ret += ">";
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ 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{
|
||||
|
||||
@ -46,7 +47,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 +68,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
|
||||
|
||||
|
@ -14,6 +14,7 @@ import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
|
||||
public class MethodGenerator extends MethodGen{
|
||||
|
||||
@ -22,11 +23,11 @@ public class MethodGenerator extends MethodGen{
|
||||
super(access_flags, return_type, arg_types, arg_names, method_name, class_name, il, cp);
|
||||
}
|
||||
|
||||
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
|
||||
@ -42,12 +43,12 @@ 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));
|
||||
|
||||
|
@ -110,7 +110,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
}
|
||||
InstructionList fieldInitializations = new InstructionList();
|
||||
for(FieldDeclaration f : fieldDeclarations){
|
||||
fieldInitializations.append(f.genByteCode(_cg));
|
||||
fieldInitializations.append(f.genByteCode(_cg, typeinferenceResults.getTypeReconstructions().firstElement()));
|
||||
}
|
||||
//Die Konstruktoren müssen die Feld initialisierungswerte beinhalten:
|
||||
for(Constructor c : constructors){
|
||||
|
@ -29,6 +29,7 @@ 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;
|
||||
@ -66,7 +67,7 @@ public class Constructor extends Method {
|
||||
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, cg.getTypeinferenceResults().getTypeReconstructions().firstElement()), org.apache.commons.bcel6.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
|
||||
|
||||
//FieldInitializations an Block anfügen
|
||||
Block block = this.get_Block();
|
||||
@ -78,7 +79,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(), cg.getTypeinferenceResults().getTypeReconstructions().firstElement()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,7 +92,7 @@ public class Constructor extends Method {
|
||||
il = toInsert;
|
||||
}
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg){
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
return il;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ 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.assumptions.FieldAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -170,19 +171,19 @@ 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));
|
||||
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;
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
|
||||
public String getDescription() {
|
||||
String ret = "";
|
||||
if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){
|
||||
ret += this.getType().getBytecodeSignature(null);
|
||||
ret += this.getType().getBytecodeSignature(null, null);
|
||||
}
|
||||
return ret+this.getIdentifier();
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ 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.MethodAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
@ -746,11 +747,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
}
|
||||
|
||||
public void genByteCode(ClassGenerator cg) {
|
||||
List<Integer> typeReconstructionSetIndexList = cg.getTypeinferenceResults().getTypeReconstructionSetIndexList(this, cg);
|
||||
List<TypeinferenceResultSet> typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg);
|
||||
|
||||
for(Integer t: typeReconstructionSetIndexList){
|
||||
cg.getTypeinferenceResults().setTypeReconstructionSetIndex(t);
|
||||
|
||||
for(TypeinferenceResultSet t: typeInterferenceResults){
|
||||
DHBWConstantPoolGen _cp = cg.getConstantPool();
|
||||
InstructionList il = new InstructionList();
|
||||
Class parentClass = this.getParentClass();
|
||||
@ -763,7 +762,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
argumentNames = new String[this.parameterlist.size()];
|
||||
int i = 0;
|
||||
for(FormalParameter parameter : this.parameterlist){
|
||||
argumentTypes[i] = parameter.getType().getBytecodeType(cg);
|
||||
argumentTypes[i] = parameter.getType().getBytecodeType(cg, t);
|
||||
argumentNames[i] = parameter.getIdentifier();
|
||||
i++;
|
||||
}
|
||||
@ -774,10 +773,10 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
Type returnType = this.getType();
|
||||
|
||||
//Methode generieren:
|
||||
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
|
||||
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
|
||||
|
||||
//Methode generieren und anfügen:
|
||||
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block()));
|
||||
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -11,6 +11,7 @@ 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;
|
||||
|
||||
public class ArgumentList extends SyntaxTreeNode
|
||||
{
|
||||
@ -81,19 +82,19 @@ public class ArgumentList extends SyntaxTreeNode
|
||||
return expr;
|
||||
}
|
||||
|
||||
public InstructionList generateBytecode(ClassGenerator cg){
|
||||
public InstructionList generateBytecode(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
InstructionList ret = new InstructionList();
|
||||
for(Expr e : expr){
|
||||
ret.append(e.genByteCode(cg));
|
||||
ret.append(e.genByteCode(cg, rs));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
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[expr.size()];
|
||||
int i = 0;
|
||||
for(Expr e : expr){
|
||||
ret[i] = e.getType().getBytecodeType(cg);
|
||||
ret[i] = e.getType().getBytecodeType(cg, rs);
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
|
@ -34,6 +34,7 @@ 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;
|
||||
|
||||
@ -179,10 +180,10 @@ public class Assign extends Expr
|
||||
public static int counterAssign = 0; //Zaehlvariable f<EFBFBD>r ISTORE
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
// TODO Auto-generated method stub
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr
|
||||
InstructionList il = expr2.genByteCode(cg, rs);//expr2 rechte expr
|
||||
|
||||
|
||||
|
||||
|
@ -39,6 +39,7 @@ 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;
|
||||
@ -227,9 +228,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
InstructionList linkeSeite = this.expr1.genByteCode(_cg);
|
||||
InstructionList rechteSeite = this.expr2.genByteCode(_cg);
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
InstructionList linkeSeite = this.expr1.genByteCode(_cg, rs);
|
||||
InstructionList rechteSeite = this.expr2.genByteCode(_cg, rs);
|
||||
if(this.getReturnType().getName().equals(new JavaClassName("String"))){
|
||||
throw new TypeinferenceException("Zeichenketten zusammenfügen ist noch nicht unterstützt",this);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ 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;
|
||||
@ -256,12 +257,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,6 +22,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;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
@ -130,7 +131,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,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;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
@ -123,7 +124,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,6 +22,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;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
@ -125,7 +126,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,6 +25,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;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
@ -145,7 +146,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,6 +19,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;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
@ -89,7 +90,7 @@ public class EmptyStmt extends Statement
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
|
@ -34,6 +34,7 @@ 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;
|
||||
@ -133,7 +134,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 +148,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));
|
||||
|
||||
|
@ -45,6 +45,7 @@ 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;
|
||||
@ -178,21 +179,21 @@ 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)));
|
||||
ifInstruction.setTarget(il.append(else_block.genByteCode(_cg, rs)));
|
||||
gotoInstruction.setTarget(il.append(new NOP()));
|
||||
}else{
|
||||
ifInstruction.setTarget(il.append(new NOP()));
|
||||
|
@ -220,7 +220,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,6 +26,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;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
@ -139,7 +140,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();
|
||||
|
||||
|
@ -43,6 +43,7 @@ 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;
|
||||
@ -238,12 +239,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 +256,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;
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ 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.FieldAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -148,14 +149,14 @@ 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();
|
||||
|
||||
|
@ -29,6 +29,7 @@ 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;
|
||||
@ -429,7 +430,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Auto-generated method stub
|
||||
return new InstructionList();
|
||||
}
|
||||
|
@ -22,6 +22,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;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
@ -129,7 +130,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();
|
||||
|
@ -25,6 +25,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 +322,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());
|
||||
|
||||
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 +343,15 @@ 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);
|
||||
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,6 +26,7 @@ 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;
|
||||
@ -112,7 +113,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,6 +20,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;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
@ -147,11 +148,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));
|
||||
|
||||
|
||||
|
@ -35,6 +35,7 @@ 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;
|
||||
@ -193,17 +194,17 @@ public class NewClass extends Expr
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
il.append(_cg.getInstructionFactory().createNew(get_Name()));
|
||||
il.append(InstructionConstants.DUP);
|
||||
|
||||
if(arglist!=null){
|
||||
il.append(arglist.generateBytecode(_cg));
|
||||
il.append(arglist.generateBytecode(_cg, rs));
|
||||
il.append(_cg.getInstructionFactory().createInvoke(this.get_Name(), "<init>",
|
||||
org.apache.commons.bcel6.generic.Type.VOID,
|
||||
this.arglist.getBytecodeTypeList(_cg), Constants.INVOKESPECIAL));
|
||||
this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL));
|
||||
}else{
|
||||
il.append(_cg.getInstructionFactory().createInvoke(this.get_Name(), "<init>",
|
||||
org.apache.commons.bcel6.generic.Type.VOID,
|
||||
|
@ -26,6 +26,7 @@ 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;
|
||||
@ -136,7 +137,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,6 +22,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.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
@ -95,7 +96,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,6 +20,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;
|
||||
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
||||
|
||||
@ -120,7 +121,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,6 +26,7 @@ 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;
|
||||
@ -93,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();
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ 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;
|
||||
@ -103,7 +104,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,6 +26,7 @@ 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;
|
||||
@ -92,7 +93,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,6 +26,7 @@ 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;
|
||||
@ -94,7 +95,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -101,10 +102,10 @@ public class Receiver
|
||||
}
|
||||
*/
|
||||
|
||||
public Class getReceiverClass(ClassGenerator cg){
|
||||
public Class getReceiverClass(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
de.dhbwstuttgart.syntaxtree.type.Type receiverType = this.get_Expr().getType();
|
||||
if(receiverType instanceof TypePlaceholder){
|
||||
receiverType = cg.resolveTPH((TypePlaceholder)receiverType);
|
||||
receiverType = rs.getTypeOfPlaceholder((TypePlaceholder)receiverType);
|
||||
}
|
||||
if(!(receiverType instanceof RefType)){
|
||||
throw new TypeinferenceException("Typ des Receivers nicht eindeutig",this.get_Expr());
|
||||
|
@ -25,6 +25,7 @@ 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.unify.CSubstitutionSet;
|
||||
|
||||
@ -134,12 +135,12 @@ public class Return extends Statement
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
InstructionList il = retexpr.genByteCode(cg);
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
InstructionList il = retexpr.genByteCode(cg, rs);
|
||||
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
|
||||
org.apache.commons.bcel6.generic.Type retType = this.getReturnType().getBytecodeType(cg);//retexpr.getType().getBytecodeType();
|
||||
org.apache.commons.bcel6.generic.Type retType = this.getReturnType().getBytecodeType(cg, rs);//retexpr.getType().getBytecodeType();
|
||||
il.append(_factory.createReturn(retType ));
|
||||
|
||||
return il;
|
||||
|
@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.Typeable;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
|
||||
|
||||
@ -130,7 +131,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
|
||||
}
|
||||
|
||||
|
||||
public abstract InstructionList genByteCode(ClassGenerator _cg);
|
||||
public abstract InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs);
|
||||
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,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;
|
||||
|
||||
|
||||
@ -123,7 +124,7 @@ public class StringLiteral extends Literal
|
||||
}
|
||||
//public static int counterString = 0;
|
||||
@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();
|
||||
|
@ -28,6 +28,7 @@ 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.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -92,7 +93,7 @@ public class SuperCall extends ThisCall
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg) {
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
Type superClass = this.getParentClass().getSuperClass();
|
||||
|
@ -28,6 +28,7 @@ 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.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -149,7 +150,7 @@ public class This extends Expr
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
InstructionList il = new InstructionList();
|
||||
il.append(InstructionFactory.createLoad( org.apache.commons.bcel6.generic.Type.OBJECT, 0));
|
||||
return il;
|
||||
|
@ -29,6 +29,7 @@ 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.CSubstitutionSet;
|
||||
@ -137,7 +138,7 @@ public class WhileStmt extends Statement
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator _cg) {
|
||||
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
public class FreshWildcardType extends ObjectType {
|
||||
@ -172,7 +173,7 @@ public class FreshWildcardType extends ObjectType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
// TODO: Bytecode
|
||||
return null;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import java.util.Iterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
@ -116,13 +117,13 @@ public class FunN extends RefType {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getBytecodeInvokeDynamicSignature(ClassGenerator cg) {
|
||||
public String getBytecodeInvokeDynamicSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
String ret = "(";
|
||||
for(Type t : T){
|
||||
ret+=t.getBytecodeType(cg).getSignature();
|
||||
ret+=t.getBytecodeType(cg, rs).getSignature();
|
||||
}
|
||||
ret +=")";
|
||||
ret+= R.getBytecodeType(cg).getSignature();
|
||||
ret+= R.getBytecodeType(cg, rs).getSignature();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class GenericClassType extends RefType{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBytecodeSignature(ClassGenerator cg) {
|
||||
public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return "L"+getTypeName()+";";
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import de.dhbwstuttgart.typeinference.Pair;
|
||||
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.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -232,7 +233,7 @@ public class GenericTypeVar extends ObjectType
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
// TODO Bytecode
|
||||
return null;
|
||||
}
|
||||
|
@ -822,8 +822,9 @@ public class RefType extends ObjectType implements IMatchable
|
||||
}
|
||||
}
|
||||
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
|
||||
org.apache.commons.bcel6.generic.ObjectType ret = new org.apache.commons.bcel6.generic.ObjectType(getCombinedType(cg));
|
||||
@Override
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
org.apache.commons.bcel6.generic.ObjectType ret = new org.apache.commons.bcel6.generic.ObjectType(getCombinedType(cg, rs));
|
||||
if(this.IsArray()){
|
||||
//Hier wird einfachhalber von einer Dimension ausgegangen. Arrays sind im Bytecode nur für main-Methode relevant
|
||||
return new org.apache.commons.bcel6.generic.ArrayType(ret, 1);
|
||||
@ -833,11 +834,11 @@ public class RefType extends ObjectType implements IMatchable
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBytecodeSignature(ClassGenerator cg) {
|
||||
String combinedType = getCombinedType(cg);
|
||||
public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
String combinedType = getCombinedType(cg, rs);
|
||||
if(!combinedType.equals(getName().toString())){
|
||||
getSuperWildcardTypes();
|
||||
Class generatedClass = ASTFactory.createClass(getCombinedType(cg), getGenericClassType(), null, null, new SourceFile());
|
||||
Class generatedClass = ASTFactory.createClass(getCombinedType(cg, rs), getGenericClassType(), null, null, new SourceFile());
|
||||
|
||||
cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResults()).getByteCode());
|
||||
}
|
||||
@ -845,7 +846,7 @@ public class RefType extends ObjectType implements IMatchable
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getCombinedType(ClassGenerator cg){
|
||||
public String getCombinedType(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
//Bsp.: Ljava/util/Vector<Ljava/lang/String;>;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@ -854,11 +855,11 @@ public class RefType extends ObjectType implements IMatchable
|
||||
sb.append("%%");
|
||||
for(Type type: parameter){
|
||||
if(type instanceof RefType){
|
||||
sb.append(((RefType) type).getCombinedType(cg).replace(".", "%"));
|
||||
sb.append(((RefType) type).getCombinedType(cg, rs).replace(".", "%"));
|
||||
}else if(type instanceof TypePlaceholder){
|
||||
sb.append(((TypePlaceholder) type).getBytecodeType(cg).toString().replace(".", "%"));
|
||||
sb.append(((TypePlaceholder) type).getBytecodeType(cg, rs).toString().replace(".", "%"));
|
||||
}else{
|
||||
sb.append(type.getBytecodeType(cg).toString().replace(".", "%"));
|
||||
sb.append(type.getBytecodeType(cg, rs).toString().replace(".", "%"));
|
||||
}
|
||||
|
||||
sb.append("%");
|
||||
|
@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
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.DebugException;
|
||||
|
||||
@ -163,8 +164,8 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getBytecodeSignature(ClassGenerator cg) {
|
||||
return "-" + this.innerType.getBytecodeSignature(cg);
|
||||
public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return "-" + this.innerType.getBytecodeSignature(cg, rs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||
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.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -309,7 +310,7 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg);
|
||||
public abstract org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs);
|
||||
|
||||
/**
|
||||
* Erzeugt einen String, welcher den Typ genauer angibt.
|
||||
@ -317,16 +318,16 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
|
||||
* @param cg
|
||||
* @return
|
||||
*/
|
||||
public String getBytecodeSignature(ClassGenerator cg) {
|
||||
return this.getBytecodeType(cg).getSignature();
|
||||
public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return this.getBytecodeType(cg, rs).getSignature();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cg
|
||||
* @return Die Signatur wie sie in Klassensignaturen verwendet wird
|
||||
*/
|
||||
public String getClassSignature(ClassGenerator cg){
|
||||
return this.getBytecodeSignature(cg);
|
||||
public String getClassSignature(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
return this.getBytecodeSignature(cg, rs);
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -17,6 +17,7 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeInsertable;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
@ -436,26 +437,26 @@ public class TypePlaceholder extends ObjectType
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
|
||||
Type resolvedType = cg.resolveTPH(this);
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
Type resolvedType = rs.getTypeOfPlaceholder(this);
|
||||
if(resolvedType instanceof TypePlaceholder){
|
||||
return DHBWInstructionFactory.createObjectType();
|
||||
}
|
||||
return resolvedType.getBytecodeType(cg);
|
||||
return resolvedType.getBytecodeType(cg, rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBytecodeSignature(ClassGenerator cg) {
|
||||
Type resolvedType = cg.resolveTPH(this);
|
||||
public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
Type resolvedType = rs.getTypeOfPlaceholder(this);
|
||||
if(resolvedType instanceof TypePlaceholder){
|
||||
cg.addUsedTPH((TypePlaceholder)resolvedType);
|
||||
return new TypePlaceholderType((TypePlaceholder)resolvedType).getSignature();
|
||||
}
|
||||
return resolvedType.getBytecodeSignature(cg);
|
||||
return resolvedType.getBytecodeSignature(cg, rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassSignature(ClassGenerator cg) {
|
||||
public String getClassSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
//Die Signaturen in der Klasse bauen sich für Generische Variabeln (also TPHs) folgendermaßen auf: "GVAR:SuperClass"
|
||||
String ret = this.get_Name();//this.getBytecodeSignature(cg);
|
||||
//ret = ret.substring(1, ret.length()-1) + ":"; //";" mit ":" ersetzen
|
||||
|
@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
|
||||
@ -81,16 +82,17 @@ public class Void extends RefType
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return org.apache.commons.bcel6.generic.Type.VOID;
|
||||
}
|
||||
|
||||
public String getBytecodeSignature(ClassGenerator cg) {
|
||||
return this.getBytecodeType(cg).getSignature();
|
||||
@Override
|
||||
public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return this.getBytecodeType(cg, rs).getSignature();
|
||||
}
|
||||
|
||||
public String getBytecodeMethodSignature(ClassGenerator cg) {
|
||||
return this.getBytecodeSignature(cg);
|
||||
public String getBytecodeMethodSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return this.getBytecodeSignature(cg, rs);
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
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.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
@ -101,13 +102,13 @@ public class WildcardType extends Type{
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
|
||||
return this.innerType.getBytecodeType(cg);
|
||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return this.innerType.getBytecodeType(cg, rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBytecodeSignature(ClassGenerator cg) {
|
||||
return this.innerType.getBytecodeSignature(cg);
|
||||
public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
return this.innerType.getBytecodeSignature(cg, rs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,88 +17,23 @@ import de.dhbwstuttgart.typeinference.Menge.Equal;
|
||||
public class TypeinferenceResults {
|
||||
|
||||
private Menge<TypeinferenceResultSet> typeReconstructions;
|
||||
private Integer typeReconstructionSetIndex = 0;
|
||||
|
||||
public TypeinferenceResults() {
|
||||
typeReconstructions = new Menge<>();
|
||||
}
|
||||
|
||||
public TypeinferenceResults(Menge<TypeinferenceResultSet> typeReconstructions) {
|
||||
//TODO: filter
|
||||
|
||||
|
||||
this.typeReconstructions = typeReconstructions;
|
||||
}
|
||||
|
||||
public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Menge<TypePlaceholder> toOneOfTheseTypes) {
|
||||
return typeReconstructions.get(typeReconstructionSetIndex).getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes);
|
||||
}
|
||||
|
||||
public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder) {
|
||||
return getTypeOfPlaceholder(typePlaceholder, null);
|
||||
}
|
||||
|
||||
public Menge<TypeinferenceResultSet> getTypeReconstructions() {
|
||||
return typeReconstructions;
|
||||
}
|
||||
|
||||
public void setTypeReconstructionSetIndex(Integer typeReconstructionSetIndex) {
|
||||
this.typeReconstructionSetIndex = typeReconstructionSetIndex;
|
||||
public Menge<TypeinferenceResultSet> getTypeReconstructions(Method method, ClassGenerator cg) {
|
||||
return typeReconstructions;
|
||||
}
|
||||
|
||||
public List<Integer> getTypeReconstructionSetIndexList(Method method, ClassGenerator cg) {
|
||||
Menge<FormalParameter> parameters = method.parameterlist.formalparameter;
|
||||
Menge<TypePlaceholder> typePlaceholders = new Menge<>();
|
||||
List<Integer> result = new LinkedList<>();
|
||||
Menge<Type[]> types = new Menge<>();
|
||||
|
||||
for(FormalParameter parameter: parameters){
|
||||
if(parameter.getType() instanceof TypePlaceholder){
|
||||
typePlaceholders.add((TypePlaceholder) parameter.getType());
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < typeReconstructions.size(); i++){
|
||||
setTypeReconstructionSetIndex(i);
|
||||
|
||||
Type[] reconstructionTypes = new Type[typePlaceholders.size()];
|
||||
|
||||
for(int t = 0; t < typePlaceholders.size(); t++){
|
||||
reconstructionTypes[t] = getTypeOfPlaceholder(typePlaceholders.get(t));
|
||||
}
|
||||
|
||||
if(!types.contains(reconstructionTypes, new TypeArrayEqual(cg))){
|
||||
types.add(reconstructionTypes);
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class TypeArrayEqual implements Equal<Type[]>{
|
||||
private ClassGenerator cg;
|
||||
|
||||
public TypeArrayEqual(ClassGenerator cg) {
|
||||
this.cg = cg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equal(Type[] a, Type[] b) {
|
||||
if(a.length != b.length){
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i = 0; i < a.length; i++){
|
||||
Logger.getLogger("TypeArrayEqual").error(a[i].toString(), Section.CODEGEN);
|
||||
Logger.getLogger("TypeArrayEqual").error(b[i].toString(), Section.CODEGEN);
|
||||
|
||||
if(!a[i].getBytecodeType(cg).equals(b[i].getBytecodeType(cg))){
|
||||
Logger.getLogger("TypeArrayEqual").error(a[i].toString(), Section.CODEGEN);
|
||||
Logger.getLogger("TypeArrayEqual").error(b[i].toString(), Section.CODEGEN);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user