Merge branch 'bytecode' into refactoring

This commit is contained in:
JanUlrich 2016-03-31 11:50:53 +02:00
commit 4deb91b99f
24 changed files with 205 additions and 215 deletions

View File

@ -1,8 +1,12 @@
package de.dhbwstuttgart.bytecode; package de.dhbwstuttgart.bytecode;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector;
import org.apache.commons.bcel6.classfile.BootstrapMethod; import org.apache.commons.bcel6.classfile.BootstrapMethod;
import org.apache.commons.bcel6.classfile.BootstrapMethods; import org.apache.commons.bcel6.classfile.BootstrapMethods;
@ -10,6 +14,7 @@ import org.apache.commons.bcel6.classfile.ConstantPool;
import org.apache.commons.bcel6.classfile.InnerClass; import org.apache.commons.bcel6.classfile.InnerClass;
import org.apache.commons.bcel6.classfile.InnerClasses; import org.apache.commons.bcel6.classfile.InnerClasses;
import org.apache.commons.bcel6.classfile.JavaClass; 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.classfile.Signature;
import org.apache.commons.bcel6.generic.ClassGen; import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen; import org.apache.commons.bcel6.generic.ConstantPoolGen;
@ -34,6 +39,7 @@ public class ClassGenerator extends ClassGen{
private Menge<TypePlaceholder> usedTPHs = new Menge<>(); private Menge<TypePlaceholder> usedTPHs = new Menge<>();
private Map<String, ClassGenerator> extraClasses = new HashMap<>(); private Map<String, ClassGenerator> extraClasses = new HashMap<>();
private List<String> methodsNamesAndTypes = new LinkedList<>();
public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings, TypeinferenceResults typeinferenceResults) { public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings, TypeinferenceResults typeinferenceResults) {
super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen()); super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen());
@ -163,6 +169,20 @@ public class ClassGenerator extends ClassGen{
return tiResult; return tiResult;
} }
@Override
public void addMethod(Method m) {
String methodNameAndTypes = m.getName()+Arrays.toString(m.getArgumentTypes());
if(methodsNamesAndTypes.contains(methodNameAndTypes)){
return;
}
methodsNamesAndTypes.add(methodNameAndTypes);
super.addMethod(m);
}
} }

View File

@ -7,6 +7,8 @@ import java.util.Collection;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
@ -105,7 +107,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
} }
//Zuerst die Methoden und Felder abarbeiten: //Zuerst die Methoden und Felder abarbeiten:
for(Method m : methods){ for(Method m : methods){
m.genByteCode(_cg); m.genByteCode(_cg, this);
} }
InstructionList fieldInitializations = new InstructionList(); InstructionList fieldInitializations = new InstructionList();
for(FieldDeclaration f : fieldDeclarations){ for(FieldDeclaration f : fieldDeclarations){
@ -990,7 +992,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
} }
@Override @Override
public String getDescription(){ public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return "class "+this.getName(); return "class "+this.getName();
} }
@Override @Override

View File

@ -98,7 +98,7 @@ public class Constructor extends Method {
} }
@Override @Override
public void genByteCode(ClassGenerator cg) { public void genByteCode(ClassGenerator cg, Class classObj) {
this.genByteCode(cg, new InstructionList()); this.genByteCode(cg, new InstructionList());
} }
// super statement muss drin sein // super statement muss drin sein

View File

@ -16,6 +16,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.Typeable; import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
@ -107,7 +108,7 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta
} }
@Override @Override
public String getDescription(){ public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return this.getIdentifier(); return this.getIdentifier();
} }

View File

@ -173,17 +173,23 @@ public class FieldDeclaration extends Field{
*/ */
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
//Das Feld an die Klasse anfügen: //Das Feld an die Klasse anfügen:
FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(), cg.getConstantPool()); FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(cg, rs), cg.getConstantPool());
field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg, rs))); field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg, rs)));
cg.addField(field.getField()); cg.addField(field.getField());
//Die Felddekleration an den Konstruktor anhängen: //Die Felddekleration an den Konstruktor anhängen:
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
il.append(new This(this).genByteCode(cg, rs)); il.append(new This(this).genByteCode(cg, rs));
il.append(this.wert.genByteCode(cg, rs));
if(wert != null){
il.append(this.wert.genByteCode(cg, rs));
}else{
//todo: default wert?
}
FieldInstruction putFieldInstruction = FieldInstruction putFieldInstruction =
cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(),
this.getDescription(), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD); this.getDescription(cg, rs), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD);
il.append(putFieldInstruction ); il.append(putFieldInstruction );
return il; return il;
} }

View File

@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree;
// ino.module.FormalParameter.8561.import // ino.module.FormalParameter.8561.import
import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.syntaxtree.misc.DeclId; import de.dhbwstuttgart.syntaxtree.misc.DeclId;
@ -14,6 +14,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.Typeable; import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
@ -233,7 +234,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
} }
@Override @Override
public String getDescription() { public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
String ret = ""; String ret = "";
if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){ if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){
ret += this.getType().getBytecodeSignature(null, null); ret += this.getType().getBytecodeSignature(null, null);

View File

@ -1,6 +1,7 @@
// ino.module.Method.8564.package // ino.module.Method.8564.package
package de.dhbwstuttgart.syntaxtree; package de.dhbwstuttgart.syntaxtree;
import java.util.Arrays;
// ino.end // ino.end
// ino.module.Method.8564.import // ino.module.Method.8564.import
import java.util.Enumeration; import java.util.Enumeration;
@ -465,39 +466,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
} }
@Override @Override
public void wandleRefTypeAttributes2GenericAttributes( public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> classParalist) {
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 set_Method_Name(String string) { public void set_Method_Name(String string) {
@ -520,30 +489,11 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// TypeCheck, falls es sich um einen RefType handelt: // TypeCheck, falls es sich um einen RefType handelt:
this.returntype = this.returntype.checkTYPE(localAss, this); 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: // Die Parameter zu den Assumptions hinzufügen:
if (this.parameterlist != null) if (this.parameterlist != null)
for (FormalParameter param : this.parameterlist) { for (FormalParameter param : this.parameterlist) {
param.setType(param.getType().checkTYPE(localAss, this)); 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)); localAss.addAssumption(new ParameterAssumption(param));
} }
ret.add(this.block.TYPEStmt(localAss)); ret.add(this.block.TYPEStmt(localAss));
@ -587,107 +537,15 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
TypeAssumptions ret = new TypeAssumptions(); TypeAssumptions ret = new TypeAssumptions();
ret.addAssumption(new MethodAssumption(this, parentClass)); ret.addAssumption(new MethodAssumption(this, parentClass));
return ret; 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);
*
* //¯Â¿Â½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());
*
*
* //¯Â¿Â½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); //
* ¯Â¿Â½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);
*
* // ¯Â¿Â½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 ¼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 @Override
public void parserPostProcessing(SyntaxTreeNode parent) { public void parserPostProcessing(SyntaxTreeNode parent) {
if (this.getType() == null) if (this.getType() == null)
this.setType(TypePlaceholder.fresh(this)); 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) if (this.returntype == null)
this.returntype = TypePlaceholder.fresh(this); this.returntype = TypePlaceholder.fresh(this);
super.parserPostProcessing(parent); 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 @Override
@ -728,7 +586,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
DImethod.set_Name(withSignature); DImethod.set_Name(withSignature);
ret.set_DeclId(DImethod); ret.set_DeclId(DImethod);
Block tempBlock = new Block(); Block tempBlock = new Block();
// tempBlock.setType(new RefType(parent.getName(),0));
ret.set_Block(tempBlock); ret.set_Block(tempBlock);
ret.parserPostProcessing(parent); ret.parserPostProcessing(parent);
return ret; return ret;
@ -751,7 +608,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
return super.equals(obj); return super.equals(obj);
} }
public void genByteCode(ClassGenerator cg) { public void genByteCode(ClassGenerator cg, Class classObj) {
List<TypeinferenceResultSet> typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg); List<TypeinferenceResultSet> typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg);
for(TypeinferenceResultSet t: typeInterferenceResults){ for(TypeinferenceResultSet t: typeInterferenceResults){
@ -771,12 +628,13 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
argumentNames[i] = parameter.getIdentifier(); argumentNames[i] = parameter.getIdentifier();
i++; i++;
} }
if(!createdMethods.contains(argumentTypes, new ArgumentTypeEquals())){
createdMethods.add(argumentTypes);
}
} }
String nameAndSignature = get_Method_Name()+Arrays.toString(argumentTypes);
Logger.getLogger("nameAndSignature").error(nameAndSignature, Section.CODEGEN);
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
@ -788,44 +646,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
//Methode generieren und anfügen: //Methode generieren und anfügen:
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t)); cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t));
/* Logger.getLogger("createMethod").debug(this.toString(), Section.CODEGEN);
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
Type returnType = this.getType();
//Methode generieren:
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
//Methode generieren und anfügen:
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block()));
*/
} }
} }
} }
class ArgumentTypeEquals implements Equal<org.apache.commons.bcel6.generic.Type[]>{
@Override
public boolean equal(org.apache.commons.bcel6.generic.Type[] a, org.apache.commons.bcel6.generic.Type[] b) {
if(a.length != b.length){
Logger.getLogger("ArgumentTypeEquals").error("false(length)", Section.CODEGEN);
return false;
}
for(int i = 0; i < a.length; i++){
if(!a[i].equals(b[i])){
String as = a[i].toString();
String bs = b[i].toString();
Logger.getLogger("ArgumentTypeEquals").error("false "+as+" != "+bs, Section.CODEGEN);
return false;
}
}
Logger.getLogger("ArgumentTypeEquals").error("true", Section.CODEGEN);
return true;
}
}
// ino.end // ino.end

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
import org.apache.commons.bcel6.generic.ClassGen; import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Type; 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.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.GenericTypeInsertPoint; import de.dhbwstuttgart.typeinference.typedeployment.GenericTypeInsertPoint;
@ -55,7 +57,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
* Eine Beschreibung/Name des SyntaxTree-Nodes * Eine Beschreibung/Name des SyntaxTree-Nodes
* @return * @return
*/ */
public String getDescription(){ public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return this.toString(); return this.toString();
} }
@ -64,7 +66,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
public boolean equals(Object object){ public boolean equals(Object object){
if(!(object instanceof SyntaxTreeNode))return false; if(!(object instanceof SyntaxTreeNode))return false;
SyntaxTreeNode equal = (SyntaxTreeNode)object; SyntaxTreeNode equal = (SyntaxTreeNode)object;
if(!equal.getDescription().equals(this.getDescription()))return false; if(!equal.getDescription(null, null).equals(this.getDescription(null, null)))return false;
if(this.getParent()!=null) if(this.getParent()!=null)
if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement überprüfen. if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement überprüfen.
return true; return true;

View File

@ -251,7 +251,7 @@ public class Block extends Statement
} }
@Override @Override
public String getDescription(){ public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return "Block"; return "Block";
} }

View File

@ -378,7 +378,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
} }
@Override @Override
public String getDescription() { public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
if(this.getType() == null)return "no type " + declid.toString(); if(this.getType() == null)return "no type " + declid.toString();
if(this.getType() instanceof TypePlaceholder)return declid.toString(); if(this.getType() instanceof TypePlaceholder)return declid.toString();
return this.getType().toString() + " " + declid.toString(); return this.getType().toString() + " " + declid.toString();

View File

@ -201,11 +201,11 @@ public class NewClass extends Expr
if(arglist!=null){ if(arglist!=null){
il.append(arglist.generateBytecode(_cg, rs)); il.append(arglist.generateBytecode(_cg, rs));
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(), "<init>", il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "<init>",
org.apache.commons.bcel6.generic.Type.VOID, org.apache.commons.bcel6.generic.Type.VOID,
this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL)); this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL));
}else{ }else{
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(), "<init>", il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "<init>",
org.apache.commons.bcel6.generic.Type.VOID, org.apache.commons.bcel6.generic.Type.VOID,
new org.apache.commons.bcel6.generic.Type[]{}, Constants.INVOKESPECIAL)); new org.apache.commons.bcel6.generic.Type[]{}, Constants.INVOKESPECIAL));
} }

View File

@ -119,7 +119,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
public abstract JavaCodeResult printJavaCode(ResultSet resultSet); public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
@Override @Override
public String getDescription(){ public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs){
return this.printJavaCode(new ResultSet(new Menge<Pair>())).toString(); return this.printJavaCode(new ResultSet(new Menge<Pair>())).toString();
} }

View File

@ -838,6 +838,11 @@ public class RefType extends ObjectType implements IMatchable
return new GenericClassType(getName().toString(), getParaList(), parent, getOffset()); return new GenericClassType(getName().toString(), getParaList(), parent, getOffset());
} }
@Override
public String getDescription(ClassGenerator cg, TypeinferenceResultSet rs) {
String signature = getBytecodeSignature(cg, rs);
return signature.substring(1, signature.length()-1);
}
} }
// ino.end // ino.end

View File

@ -0,0 +1,3 @@
class Parameter{
public String param;
}

View File

@ -0,0 +1,34 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class ParameterTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "Parameter.jav";
public final static String outputFile = "Parameter.class";
@Test
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -0,0 +1,8 @@
import java.util.Vector;
class AutoOverloadingMultiResults{
void method(Integer a) {
b;
b = 1;
}
}

View File

@ -0,0 +1,35 @@
package bytecode.types;
import static org.junit.Assert.*;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector;
import org.junit.Test;
import org.junit.Ignore;
import bytecode.SourceFileBytecodeTest;
public class AutoOverloadingMultiResultsTest extends SourceFileBytecodeTest{
@Override
protected void init() {
testName = "AutoOverloadingMultiResults";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void testConstruct() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
assertTrue(true);
}
}

View File

@ -43,7 +43,7 @@ public class AutoOverloadingVectorTest extends SourceFileBytecodeTest{
URL url = file.toURL(); URL url = file.toURL();
URL[] urls = new URL[]{url}; URL[] urls = new URL[]{url};
Class string = classLoader.loadClass("java.lang.String"); Class string = classLoader.loadClass("java%util%Vector%%java%lang%String%");
Class[] params = new Class[1]; Class[] params = new Class[1];
params[0] = string; params[0] = string;
@ -69,13 +69,13 @@ public class AutoOverloadingVectorTest extends SourceFileBytecodeTest{
URL url = file.toURL(); URL url = file.toURL();
URL[] urls = new URL[]{url}; URL[] urls = new URL[]{url};
Integer integer = new Integer(123); Class integer = classLoader.loadClass("java%util%Vector%%java%lang%Integer%");
Class[] params = new Class[1]; Class[] params = new Class[1];
params[0] = integer.getClass(); params[0] = integer;
Method method = cls.getDeclaredMethod("method2", params); Method method = cls.getDeclaredMethod("method2", params);
method.invoke(obj, integer); method.invoke(obj, integer.newInstance());
assertTrue(true); assertTrue(true);
}catch(Exception e){ }catch(Exception e){
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@ -1,6 +1,6 @@
import java.util.Vector; import java.util.Vector;
class SuperType{ class ExtendsType{
Vector<Integer> integerVector; Vector<Integer> integerVector;
void method() { void method() {

View File

@ -16,7 +16,7 @@ import bytecode.SourceFileBytecodeTest;
public class ExtendsTypeTest extends SourceFileBytecodeTest{ public class ExtendsTypeTest extends SourceFileBytecodeTest{
@Override @Override
protected void init() { protected void init() {
testName = "SuperType"; testName = "ExtendsType";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
} }

View File

@ -4,6 +4,7 @@ import static org.junit.Assert.*;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Vector;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -60,13 +61,13 @@ public class ExtendsVectorStringTest extends ASTBytecodeTest{
Object obj = cls.newInstance(); Object obj = cls.newInstance();
Class stringClass = classLoader.loadClass("java.lang.Object"); Class objectClass = classLoader.loadClass("java.lang.Object");
Class[] params = new Class[1]; Class[] params = new Class[1];
params[0] = stringClass; params[0] = objectClass;
Method method = cls.getDeclaredMethod("add", params); Method method = cls.getDeclaredMethod("add", params);
method.invoke(obj, stringClass.newInstance()); method.invoke(obj, objectClass.newInstance());
}catch(Exception e){ }catch(Exception e){
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -84,4 +85,8 @@ public class ExtendsVectorStringTest extends ASTBytecodeTest{
return "ExtendsVectorString"; return "ExtendsVectorString";
} }
class StringVector extends Vector<String>{
}
} }

View File

@ -0,0 +1,11 @@
import java.util.Vector;
class MultiExtends{
Integer method(Vector<Integer> a){
return method2(a);
}
Integer method2(Vector<Number> b){
return 1;
}
}

View File

@ -0,0 +1,35 @@
package bytecode.types;
import static org.junit.Assert.*;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector;
import org.junit.Test;
import org.junit.Ignore;
import bytecode.SourceFileBytecodeTest;
public class MultiExtendsTest extends SourceFileBytecodeTest{
@Override
protected void init() {
testName = "MultiExtends";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void testConstruct() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
assertTrue(true);
}
}