generateBytecode von Class gibt eine Menge an ByteCodeResults zurück, wird benötigt um zusätzliche Klassen anzulegen
This commit is contained in:
parent
3a18088801
commit
1a07c186a6
@ -860,10 +860,10 @@ public class MyCompiler implements MyCompilerAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Menge<ByteCodeResult> generateBytecode(TypeinferenceResultSet typeinferenceResult) {
|
public Menge<Menge<ByteCodeResult>> generateBytecode(TypeinferenceResultSet typeinferenceResult) {
|
||||||
//SourceFile parsedFile = this.m_AbstractSyntaxTree.firstElement();
|
//SourceFile parsedFile = this.m_AbstractSyntaxTree.firstElement();
|
||||||
//Class parsedClass = parsedFile.KlassenVektor.firstElement();
|
//Class parsedClass = parsedFile.KlassenVektor.firstElement();
|
||||||
Menge<ByteCodeResult> ret = new Menge<>();
|
Menge<Menge<ByteCodeResult>> ret = new Menge<>();
|
||||||
for(SourceFile sf : this.m_AbstractSyntaxTree){
|
for(SourceFile sf : this.m_AbstractSyntaxTree){
|
||||||
ret.addAll(sf.generateBytecode(typeinferenceResult));
|
ret.addAll(sf.generateBytecode(typeinferenceResult));
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,6 @@ public interface MyCompilerAPI
|
|||||||
* Dafür müssen die Schritte Parsen und typeReconstruction ausgeführt werden.
|
* Dafür müssen die Schritte Parsen und typeReconstruction ausgeführt werden.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Menge<ByteCodeResult> generateBytecode(TypeinferenceResultSet rs);
|
public Menge<Menge<ByteCodeResult>> generateBytecode(TypeinferenceResultSet rs);
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -15,7 +15,6 @@ import org.apache.commons.bcel6.generic.InstructionHandle;
|
|||||||
import org.apache.commons.bcel6.generic.InstructionList;
|
import org.apache.commons.bcel6.generic.InstructionList;
|
||||||
import org.apache.commons.bcel6.generic.MethodGen;
|
import org.apache.commons.bcel6.generic.MethodGen;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.Menge;
|
|
||||||
import de.dhbwstuttgart.logger.Logger;
|
import de.dhbwstuttgart.logger.Logger;
|
||||||
import de.dhbwstuttgart.logger.Section;
|
import de.dhbwstuttgart.logger.Section;
|
||||||
import de.dhbwstuttgart.logger.SectionLogger;
|
import de.dhbwstuttgart.logger.SectionLogger;
|
||||||
@ -75,11 +74,13 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
|||||||
* @param resultSet - Fehlende Typen im Syntaxbaum werden nach diesem ResultSet aufgelöst
|
* @param resultSet - Fehlende Typen im Syntaxbaum werden nach diesem ResultSet aufgelöst
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ByteCodeResult genByteCode(TypeinferenceResultSet resultSet) {
|
public Menge<ByteCodeResult> genByteCode(TypeinferenceResultSet resultSet) {
|
||||||
InstructionFactory _factory;
|
InstructionFactory _factory;
|
||||||
DHBWConstantPoolGen _cp;
|
DHBWConstantPoolGen _cp;
|
||||||
ClassGenerator _cg;
|
ClassGenerator _cg;
|
||||||
|
|
||||||
|
Menge<ByteCodeResult> results = new Menge<ByteCodeResult>();
|
||||||
|
|
||||||
SectionLogger logger = Logger.getSectionLogger(this.getClass().getName(), Section.CODEGEN);
|
SectionLogger logger = Logger.getSectionLogger(this.getClass().getName(), Section.CODEGEN);
|
||||||
logger.debug("Test");
|
logger.debug("Test");
|
||||||
|
|
||||||
@ -112,7 +113,11 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
ByteCodeResult code = new ByteCodeResult(_cg);
|
ByteCodeResult code = new ByteCodeResult(_cg);
|
||||||
return code;
|
results.add(code);
|
||||||
|
|
||||||
|
results.addAll(getGenericClasses(_cg));
|
||||||
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Menge<Type> superif = new Menge<Type>();
|
private Menge<Type> superif = new Menge<Type>();
|
||||||
@ -593,112 +598,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
|||||||
{
|
{
|
||||||
return this.parahash;
|
return this.parahash;
|
||||||
}
|
}
|
||||||
// ino.end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*static void string_rec(Hashtable ht){
|
|
||||||
String record="";
|
|
||||||
boolean isError=false;
|
|
||||||
record=record.concat("[");
|
|
||||||
for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){
|
|
||||||
String s = (String)k.nextElement();
|
|
||||||
Object o = e.nextElement();
|
|
||||||
|
|
||||||
record=record.concat(" "+s);
|
|
||||||
|
|
||||||
if(o instanceof Type){
|
|
||||||
record=record.concat(" = "+((Type)o).getName());
|
|
||||||
} else if(o instanceof Hashtable){
|
|
||||||
record=record.concat("= ");
|
|
||||||
string_rec((Hashtable)o);
|
|
||||||
if(e.hasMoreElements())
|
|
||||||
record=record.concat(", ");
|
|
||||||
} else if(o instanceof String){
|
|
||||||
record=record.concat(" = "+o);
|
|
||||||
if(e.hasMoreElements())
|
|
||||||
record=record.concat(", ");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
record=("[FEHLER: string_rec: unbekannter Typ!!!!!!");
|
|
||||||
isError=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
record=record.concat("]");
|
|
||||||
if(isError){
|
|
||||||
parserlog.error(record);
|
|
||||||
}else{
|
|
||||||
parserlog.debug(record);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*static void string_rec(Menge v){
|
|
||||||
String record=("{");
|
|
||||||
for(Enumeration e=v.elements();e.hasMoreElements();){
|
|
||||||
Type t = (Type)e.nextElement();
|
|
||||||
record=record.concat(" "+t.getName());
|
|
||||||
|
|
||||||
if(e.hasMoreElements())
|
|
||||||
record=record.concat(",");
|
|
||||||
}
|
|
||||||
record=record.concat("}");
|
|
||||||
parserlog.debug(record);
|
|
||||||
}*/
|
|
||||||
/*static void string_rec(String st, Hashtable ht){
|
|
||||||
String record=(st);
|
|
||||||
boolean isError=false;
|
|
||||||
record=record.concat("[");
|
|
||||||
for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){
|
|
||||||
String s = (String)k.nextElement();
|
|
||||||
Object o = e.nextElement();
|
|
||||||
|
|
||||||
record=record.concat(" "+s);
|
|
||||||
|
|
||||||
if(o instanceof Type){
|
|
||||||
record=record.concat(" = "+((Type)o).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(o instanceof Hashtable){
|
|
||||||
record=record.concat("= ");
|
|
||||||
string_rec((Hashtable)o);
|
|
||||||
if(e.hasMoreElements())
|
|
||||||
record=record.concat(", ");
|
|
||||||
}
|
|
||||||
else if(o instanceof String){
|
|
||||||
record=record.concat(" = "+o);
|
|
||||||
if(e.hasMoreElements())
|
|
||||||
record=record.concat(", ");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
record=("[FEHLER: string_rec: unbekannter Typ!!!!!! " +o);
|
|
||||||
isError = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
record=record.concat("]");
|
|
||||||
if(isError){
|
|
||||||
parserlog.error(record);
|
|
||||||
}else{
|
|
||||||
parserlog.debug(record);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*static void string_rec(String st,Menge v)
|
|
||||||
{
|
|
||||||
String record=(st);
|
|
||||||
record=record.concat("{");
|
|
||||||
for(Enumeration e=v.elements();e.hasMoreElements();)
|
|
||||||
{
|
|
||||||
Type t = (Type)e.nextElement();
|
|
||||||
record=record.concat(" "+t.getName());
|
|
||||||
if(e.hasMoreElements())
|
|
||||||
{
|
|
||||||
record=record.concat(", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
record=record.concat("}");
|
|
||||||
parserlog.debug(record);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// TypeReconstructionAlgorithmus
|
// TypeReconstructionAlgorithmus
|
||||||
@ -771,165 +670,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
|||||||
typinferenzLog.debug("Erstellte Constraints: "+oderConstraints, Section.TYPEINFERENCE);
|
typinferenzLog.debug("Erstellte Constraints: "+oderConstraints, Section.TYPEINFERENCE);
|
||||||
|
|
||||||
return oderConstraints;
|
return oderConstraints;
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
CReconstructionTupleSet retTupleSet = this.TRStart(methodList, V, V_fields_methods, supportData);
|
|
||||||
inferencelog.debug("Bin aus TRStart() zur�ck in TRProg().");
|
|
||||||
//////////////////////////////
|
|
||||||
// Neu Ergebnismenge A aller
|
|
||||||
// Typannahmen erzeugen:
|
|
||||||
//////////////////////////////
|
|
||||||
inferencelog.debug("Erstelle Ergebnismenge...");
|
|
||||||
Menge<CTypeReconstructionResult> newA = new Menge<CTypeReconstructionResult>();
|
|
||||||
|
|
||||||
// Alle bisherigen M�glichkeiten an Typkombinationen durchgehen:
|
|
||||||
Menge<CTypeReconstructionResult> oldA = supportData.getA();
|
|
||||||
for(int i=0; i<oldA.size(); i++){
|
|
||||||
CTypeReconstructionResult oneReconResult = oldA.elementAt(i);
|
|
||||||
|
|
||||||
// Und mit den neuen m�glichen Typkombinationen vereinigen:
|
|
||||||
Iterator<CReconstructionTuple> retTupleIt = retTupleSet.getIterator();
|
|
||||||
while(retTupleIt.hasNext()){
|
|
||||||
CReconstructionTuple possibleTuple = retTupleIt.next();
|
|
||||||
this.clear(possibleTuple.getAssumSet(), rememberLocals);
|
|
||||||
|
|
||||||
// Neue Typinformationen mit alten Typinformationen vereinigen:
|
|
||||||
CTypeReconstructionResult newReconResult = oneReconResult.shallowCopy();
|
|
||||||
newReconResult.addDataFromTupel(possibleTuple);
|
|
||||||
|
|
||||||
|
|
||||||
//PL 05-08-02 eingefuegt
|
|
||||||
//Fuegt Klassen und GenericTypeVars zu A hinzu
|
|
||||||
newReconResult.addClassName(this.getName());
|
|
||||||
Menge<GenericTypeVar> genericsList = new Menge<GenericTypeVar>();
|
|
||||||
for(int ii =0; ii<this.get_ParaList().size(); ii++){
|
|
||||||
Type para = (Type)this.get_ParaList().elementAt(ii);
|
|
||||||
if(para instanceof GenericTypeVar){
|
|
||||||
genericsList.addElement((GenericTypeVar)para);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
newReconResult.addGenericTypeVars(this.getName(), genericsList);
|
|
||||||
|
|
||||||
//Hinzuf�gen:
|
|
||||||
newA.addElement(newReconResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newA;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
// ino.end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Eine Liste mit allen Methoden dieser Klasse
|
|
||||||
|
|
||||||
private Menge<Method> getMethodList() {
|
|
||||||
|
|
||||||
|
|
||||||
if(this.methodList != null) return this.methodList;
|
|
||||||
//TODO: Unnötige Berechnungen im folgenden Code rauskürzen:
|
|
||||||
//////////////////////////////
|
|
||||||
// Die Eingabedaten bauen:
|
|
||||||
//////////////////////////////
|
|
||||||
inferencelog.debug("Baue Eingabedaten...");
|
|
||||||
TypeAssumptions V_fields_methods = new TypeAssumptions(this.getName());
|
|
||||||
Menge<Method> methodList = new Menge<Method>();
|
|
||||||
Menge<CTypeAssumptionSet> V = new Menge<CTypeAssumptionSet>();
|
|
||||||
Menge<CTypeAssumption> rememberLocals = new Menge<CTypeAssumption>();
|
|
||||||
|
|
||||||
//////////////////////////////
|
|
||||||
// Alle Felder durchgehen:
|
|
||||||
// Zuerst alle Attribute, dann Methoden
|
|
||||||
// ge�ndert: hoth 06.04.2006
|
|
||||||
|
|
||||||
//////////////////////////////
|
|
||||||
for(Field field : this.getFields())
|
|
||||||
{
|
|
||||||
//////////////////////////////
|
|
||||||
// Attribut:
|
|
||||||
//////////////////////////////
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Field field : this.getFields())
|
|
||||||
{
|
|
||||||
//////////////////////////////
|
|
||||||
// Methode:
|
|
||||||
//////////////////////////////
|
|
||||||
if(field instanceof Method){
|
|
||||||
Method method = (Method)field;
|
|
||||||
//if(method.get_Method_Name().equals(this.getName()) && ((method.getReturnType().equals(new mycompiler.mytype.Void(0))) || method.getReturnType() instanceof TypePlaceholder)){
|
|
||||||
if(method.get_Method_Name().equals(this.getName()) ){
|
|
||||||
method.set_Method_Name("<init>");
|
|
||||||
}
|
|
||||||
//hoth: 06.04.2006
|
|
||||||
//durchlaufe Block und suche nach Objektvariablen fuer Offset-Markierung
|
|
||||||
Iterator<CTypeAssumption> fieldVarIterator = V_fields_methods.iterator();
|
|
||||||
while (fieldVarIterator.hasNext())
|
|
||||||
{
|
|
||||||
//Wenn ObjektVariable
|
|
||||||
CTypeAssumption dieAssum = fieldVarIterator.next();
|
|
||||||
if(dieAssum instanceof CInstVarTypeAssumption)
|
|
||||||
{
|
|
||||||
Class.isFirstLocalVarDecl=false;
|
|
||||||
if(method.get_Block() != null)
|
|
||||||
method.get_Block().addOffsetsToAssumption(dieAssum,dieAssum.getIdentifier(),true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
methodList.addElement(method);
|
|
||||||
|
|
||||||
// F�r V_fields_methods:
|
|
||||||
CMethodTypeAssumption methodAssum = new CMethodTypeAssumption(this.getType(), method.get_Method_Name(), method.getReturnType(), method.getParameterCount(),method.getLineNumber(),method.getOffset(),new Menge<Integer>(),method.getGenericMethodParameters()); // Typannahme bauen...
|
|
||||||
|
|
||||||
|
|
||||||
// Methode in V_Fields_methods ablegen
|
|
||||||
// Dabei wird die OverloadedMethodID ermittelt !!
|
|
||||||
// => Method setzenuct
|
|
||||||
|
|
||||||
|
|
||||||
V_fields_methods.add(methodAssum);
|
|
||||||
method.setOverloadedID(methodAssum.getHashSetKey().getOverloadedMethodID());
|
|
||||||
|
|
||||||
|
|
||||||
// F�r die V_i:
|
|
||||||
CTypeAssumptionSet localAssum = new CTypeAssumptionSet();
|
|
||||||
|
|
||||||
// Bauen...
|
|
||||||
ParameterList parameterList = method.getParameterList();
|
|
||||||
if(parameterList!=null){
|
|
||||||
for(int i=0; i<parameterList.sc_get_Formalparalist().size(); i++){
|
|
||||||
FormalParameter para = parameterList.sc_get_Formalparalist().elementAt(i);
|
|
||||||
// F�r V_fields_methods:
|
|
||||||
CParaTypeAssumption paraAssum = new CParaTypeAssumption(this.getName(), method.get_Method_Name(), method.getParameterCount(), method.getOverloadedID(),para.getIdentifier(), para.getType(), para.getLineNumber(),para.getOffset(),new Menge<Integer>());
|
|
||||||
//fuege Offsets fuer Parameter hinzu, hoth: 06.04.2006
|
|
||||||
Class.isFirstLocalVarDecl=false;
|
|
||||||
|
|
||||||
if(method.get_Block() != null)
|
|
||||||
method.get_Block().addOffsetsToAssumption(paraAssum,paraAssum.getIdentifier(),true);
|
|
||||||
|
|
||||||
methodAssum.addParaAssumption(paraAssum);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// F�r die V_i:
|
|
||||||
CLocalVarTypeAssumption varAssum = new CLocalVarTypeAssumption(this.getName(), method.get_Method_Name(), method.getParameterCount(), method.getOverloadedID(),"1", para.getIdentifier(),para.getType(), para.getLineNumber(),para.getOffset(),new Menge<Integer>());
|
|
||||||
localAssum.addElement(varAssum);
|
|
||||||
rememberLocals.addElement(varAssum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ...und hinzuf�gen:
|
|
||||||
|
|
||||||
V.addElement(localAssum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.methodList = methodList;
|
|
||||||
return methodList;
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ermittelt alle privaten Felder und Methoden der Klasse und Erstellt eine Assumption für diese.
|
* Ermittelt alle privaten Felder und Methoden der Klasse und Erstellt eine Assumption für diese.
|
||||||
@ -958,48 +699,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
|||||||
this.typeAssumptions = assumptions; //Diese müssen anschlieÃend nicht wieder generiert werden.
|
this.typeAssumptions = assumptions; //Diese müssen anschlieÃend nicht wieder generiert werden.
|
||||||
return assumptions;
|
return assumptions;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
public ConstraintsSet TYPE(Menge<Method> methodList, Menge<Expr> fielddeclarationList, TypeAssumptions assumptions){
|
|
||||||
ConstraintsSet ret = new ConstraintsSet();
|
|
||||||
// Die Felddeklarationen werden zu den Assumptions hinzugefügt und gelten danach für jede Methode.
|
|
||||||
//TypeAssumptions assumptionsPlusFieldAssumptions = new TypeAssumptions(assumptions);
|
|
||||||
for(Expr expr : fielddeclarationList){
|
|
||||||
//ret.add(expr.TYPEStmt(assumptionsPlusFieldAssumptions));
|
|
||||||
ret.add(expr.TYPEStmt(assumptions));
|
|
||||||
}
|
|
||||||
for(Method methode : methodList){
|
|
||||||
//ret.add(methode.TYPE(assumptionsPlusFieldAssumptions));
|
|
||||||
ret.add(methode.TYPE(assumptions));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// ino.method.RetType.23119.defdescription type=javadoc
|
|
||||||
/**
|
|
||||||
* Liefert den berechneten R�ckgabetyp f�r die �bergebene Methode zur�ck.<br/>
|
|
||||||
* (siehe Algorithmus RetType, Martin Pl�micke)
|
|
||||||
* <br/>Author: J�rg B�uerle
|
|
||||||
* @param me
|
|
||||||
* @param V
|
|
||||||
* @return
|
|
||||||
|
|
||||||
// ino.end
|
|
||||||
// ino.method.RetType.23119.definition
|
|
||||||
private Type RetType(Method me, CTypeAssumptionSet V)
|
|
||||||
// ino.end
|
|
||||||
// ino.method.RetType.23119.body
|
|
||||||
{
|
|
||||||
CTypeAssumption assum = V.getElement(new CMethodKey(this.getName(), me.get_Method_Name(), me.getParameterCount(),me.getOverloadedID()));
|
|
||||||
if(assum instanceof CMethodTypeAssumption){
|
|
||||||
return ((CMethodTypeAssumption)assum).getAssumedType();
|
|
||||||
}
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
// ino.end
|
|
||||||
|
|
||||||
*/
|
|
||||||
// ino.method.toString.23125.defdescription type=javadoc
|
// ino.method.toString.23125.defdescription type=javadoc
|
||||||
/**
|
/**
|
||||||
* <br/>Author: Martin Pl�micke
|
* <br/>Author: Martin Pl�micke
|
||||||
@ -1037,48 +737,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
|||||||
for(Field f : this.getFields()){
|
for(Field f : this.getFields()){
|
||||||
//f.wandleRefTypeAttributes2GenericAttributes(paralist);
|
//f.wandleRefTypeAttributes2GenericAttributes(paralist);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
Menge fieldsAndMethods=this.getFields();
|
|
||||||
|
|
||||||
// Alle Methoden und Instanzvariablen durchgehen
|
|
||||||
for(int i=0;i<fieldsAndMethods.size();i++){
|
|
||||||
|
|
||||||
// Ist es eine Methode?
|
|
||||||
if(fieldsAndMethods.get(i) instanceof Method){
|
|
||||||
Method method=(Method)fieldsAndMethods.get(i);
|
|
||||||
method.wandleRefTypeAttributes2GenericAttributes(paralist);
|
|
||||||
}// Ist es eine InstanzVariable?
|
|
||||||
*//*
|
|
||||||
else if(fieldsAndMethods.get(i) instanceof InstVarDecl){
|
|
||||||
InstVarDecl instVar=(InstVarDecl)fieldsAndMethods.get(i);
|
|
||||||
Type type=instVar.getType();
|
|
||||||
// Nur wenn es sich um ein RefType-Field handelt
|
|
||||||
if(type instanceof RefType){
|
|
||||||
GenericTypeVar pendant=ClassHelper.findGenericType((RefType)type,paralist,null);
|
|
||||||
if(pendant!=null){ //Wenn generisch, dann modifizieren
|
|
||||||
instVar.setType(pendant);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
// ino.end
|
|
||||||
|
|
||||||
|
|
||||||
// private void removeOldLocalVars(CTypeAssumptionSet V_i, CTypeAssumptionSet V_last){
|
|
||||||
// Enumeration<IHashSetKey> enumer = V_last.getHashtable().keys();
|
|
||||||
// while(enumer.hasMoreElements()){
|
|
||||||
// CTypeAssumption currentAssum = V_last.getElement(enumer.nextElement());
|
|
||||||
// if(currentAssum instanceof CLocalVarTypeAssumption){
|
|
||||||
// V_i.removeElement(currentAssum);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// ino.method.getSimpleName.23140.defdescription type=javadoc
|
|
||||||
/**
|
/**
|
||||||
* HOTI
|
* HOTI
|
||||||
* Liefert bei Klassen die fullyQualified angegeben wurden
|
* Liefert bei Klassen die fullyQualified angegeben wurden
|
||||||
@ -1116,18 +776,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
|||||||
public String printJavaCode(TypeinferenceResultSet reconstructionResult){
|
public String printJavaCode(TypeinferenceResultSet reconstructionResult){
|
||||||
JavaCodeResult ret = new JavaCodeResult("class ");
|
JavaCodeResult ret = new JavaCodeResult("class ");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Generiere JavaCode der extends-Typen:
|
|
||||||
/*
|
|
||||||
String containedTypesJavaCode = "";
|
|
||||||
for(Type containedType : containedTypes){
|
|
||||||
containedTypesJavaCode += containedType.printJavaCode(resultSet)+ ", ";
|
|
||||||
}
|
|
||||||
if(containedTypesJavaCode.length()>1)containedTypesJavaCode = containedTypesJavaCode.substring(0, containedTypesJavaCode.length() -2);
|
|
||||||
*/
|
|
||||||
|
|
||||||
JavaCodeResult classBodyCode = new JavaCodeResult();
|
JavaCodeResult classBodyCode = new JavaCodeResult();
|
||||||
if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" ");
|
if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" ");
|
||||||
|
|
||||||
@ -1382,5 +1030,22 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
|||||||
public boolean isInterface(){
|
public boolean isInterface(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collection<? extends ByteCodeResult> getGenericClasses(ClassGenerator _cg) {
|
||||||
|
Collection<ByteCodeResult> results = new Menge<>();
|
||||||
|
|
||||||
|
//Super Klasse
|
||||||
|
String name = "java/util/Vectorjava/lang/String"; //getParentClass().getType().getBytecodeSignature(_cg);
|
||||||
|
|
||||||
|
Type superClass = new Class("java/util/Vector",-1).getType();
|
||||||
|
|
||||||
|
_cg = new ClassGenerator(name, superClass, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null));
|
||||||
|
|
||||||
|
ByteCodeResult code = new ByteCodeResult(_cg);
|
||||||
|
|
||||||
|
results.add(code);
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -1834,8 +1834,8 @@ public class SourceFile
|
|||||||
* Bisher wird nur der Bytecode der Klassen generiert. Nicht der Interfaces.
|
* Bisher wird nur der Bytecode der Klassen generiert. Nicht der Interfaces.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Collection<? extends ByteCodeResult> generateBytecode(TypeinferenceResultSet rs) {
|
public Menge<Menge<ByteCodeResult>> generateBytecode(TypeinferenceResultSet rs) {
|
||||||
Menge<ByteCodeResult> ret = new Menge<>();
|
Menge<Menge<ByteCodeResult>> ret = new Menge<>();
|
||||||
for(Class cl : this.KlassenVektor){
|
for(Class cl : this.KlassenVektor){
|
||||||
ret.add(cl.genByteCode(rs));
|
ret.add(cl.genByteCode(rs));
|
||||||
}
|
}
|
||||||
|
@ -814,11 +814,12 @@ public class RefType extends ObjectType implements IMatchable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
|
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
|
||||||
return new org.apache.commons.bcel6.generic.ObjectType(this.getBytecodeSignature(cg));
|
return new org.apache.commons.bcel6.generic.ObjectType(this.get_Name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBytecodeSignature(ClassGenerator cg) {
|
public String getBytecodeSignature(ClassGenerator cg) {
|
||||||
|
/*
|
||||||
//Bsp.: Ljava/util/Vector<Ljava/lang/String;>;
|
//Bsp.: Ljava/util/Vector<Ljava/lang/String;>;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
@ -826,12 +827,14 @@ public class RefType extends ObjectType implements IMatchable
|
|||||||
|
|
||||||
if(parameter != null){
|
if(parameter != null){
|
||||||
for(Type type: parameter){
|
for(Type type: parameter){
|
||||||
sb.append("%");
|
sb.append(""); //TODO: einen geeignete Delemiter suchen
|
||||||
sb.append(type.getBytecodeSignature(cg));
|
sb.append(type.getBytecodeSignature(cg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
return sb.toString();
|
||||||
|
*/
|
||||||
|
|
||||||
String paramString = "";
|
String paramString = "";
|
||||||
if(this.parameter != null && this.parameter.size()>0){
|
if(this.parameter != null && this.parameter.size()>0){
|
||||||
paramString+="<";
|
paramString+="<";
|
||||||
@ -847,9 +850,6 @@ public class RefType extends ObjectType implements IMatchable
|
|||||||
String typeSignature = this.getBytecodeType(cg).getSignature();
|
String typeSignature = this.getBytecodeType(cg).getSignature();
|
||||||
typeSignature = typeSignature.substring(0, typeSignature.length()-1);
|
typeSignature = typeSignature.substring(0, typeSignature.length()-1);
|
||||||
return typeSignature+paramString+";";
|
return typeSignature+paramString+";";
|
||||||
*/
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public class TypeinferenceResultSet
|
|||||||
* Dabei wird die codegen-Methode der inferierten Klasse mit diesem ResultSet aufgerufen.
|
* Dabei wird die codegen-Methode der inferierten Klasse mit diesem ResultSet aufgerufen.
|
||||||
*/
|
*/
|
||||||
public ByteCodeResult codegen(){
|
public ByteCodeResult codegen(){
|
||||||
ByteCodeResult res = this.ownerOfResultSet.genByteCode(this);
|
ByteCodeResult res = this.ownerOfResultSet.genByteCode(this).firstElement();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import org.junit.Test;
|
|||||||
public abstract class BytecodeTest extends TestCase{
|
public abstract class BytecodeTest extends TestCase{
|
||||||
public String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
public String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||||
public String testFile;
|
public String testFile;
|
||||||
public String outputFile;
|
public String outputDirectory;
|
||||||
|
|
||||||
protected String testName;
|
protected String testName;
|
||||||
|
|
||||||
@ -26,9 +26,9 @@ public abstract class BytecodeTest extends TestCase{
|
|||||||
if(testName != null){
|
if(testName != null){
|
||||||
|
|
||||||
testFile = testName+".jav";
|
testFile = testName+".jav";
|
||||||
outputFile = testName+".class";
|
outputDirectory = "";
|
||||||
|
|
||||||
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
|
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputDirectory);
|
||||||
}else{
|
}else{
|
||||||
throw new RuntimeException("rootDirectory, testFile or outputFile is null.");
|
throw new RuntimeException("rootDirectory, testFile or outputFile is null.");
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package bytecode;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.bcel6.classfile.JavaClass;
|
||||||
|
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
@ -18,20 +20,28 @@ import de.dhbwstuttgart.typeinference.Menge;
|
|||||||
|
|
||||||
public class SingleClassTester {
|
public class SingleClassTester {
|
||||||
|
|
||||||
public static void compileToBytecode(String inputFile, String outputFile){
|
public static void compileToBytecode(String inputFile, String outputDirectory){
|
||||||
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
|
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
|
||||||
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
||||||
try {
|
try {
|
||||||
compiler.parse(new File(inputFile));
|
compiler.parse(new File(inputFile));
|
||||||
Menge<ByteCodeResult> bytecode = compiler.generateBytecode(compiler.typeReconstruction().firstElement());
|
Menge<Menge<ByteCodeResult>> bytecode = compiler.generateBytecode(compiler.typeReconstruction().firstElement());
|
||||||
//System.out.println(bytecode);
|
//System.out.println(bytecode);
|
||||||
bytecode.firstElement().getByteCode().getJavaClass().dump(new File(outputFile));
|
|
||||||
|
for(ByteCodeResult result: bytecode.firstElement()){
|
||||||
|
JavaClass javaClass = result.getByteCode().getJavaClass();
|
||||||
|
|
||||||
|
Logger.getLogger("SingleClassTester").error(result.getByteCode().getJavaClass().toString(), Section.CODEGEN);
|
||||||
|
|
||||||
|
javaClass.dump(new File(outputDirectory+javaClass.getClassName()+".class"));
|
||||||
|
}
|
||||||
|
|
||||||
} catch (IOException | yyException e) {
|
} catch (IOException | yyException e) {
|
||||||
Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN);
|
Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
TestCase.fail();
|
TestCase.fail();
|
||||||
}finally{
|
}finally{
|
||||||
writeLog(outputFile+".log");
|
writeLog(outputDirectory+".log");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
class ExtendsVector extends Vector{
|
class ExtendsVector extends Vector{
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import java.util.Stack;
|
import java.util.Vector;
|
||||||
|
|
||||||
class TypedVector{
|
class TypedVector{
|
||||||
public void method(Vector<String> v) {
|
public void method(Vector<String> v) {
|
||||||
|
@ -9,6 +9,8 @@ import java.util.Vector;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import bytecode.BytecodeTest;
|
import bytecode.BytecodeTest;
|
||||||
|
import de.dhbwstuttgart.logger.Logger;
|
||||||
|
import de.dhbwstuttgart.logger.Section;
|
||||||
|
|
||||||
public class TypedVectorTest extends BytecodeTest{
|
public class TypedVectorTest extends BytecodeTest{
|
||||||
@Override
|
@Override
|
||||||
@ -32,7 +34,7 @@ public class TypedVectorTest extends BytecodeTest{
|
|||||||
method.invoke(obj, stringVector);
|
method.invoke(obj, stringVector);
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN);
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user