Fehler in FunN Generierung beheben

This commit is contained in:
JanUlrich 2016-10-28 18:31:42 +02:00
parent e60e6b622c
commit 107201c00c
13 changed files with 120 additions and 358 deletions

View File

@ -20,6 +20,8 @@ import org.apache.bcel.classfile.Signature;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -33,9 +35,10 @@ public class ClassGenerator extends ClassGen{
private DHBWConstantPoolGen cp;
private DHBWInstructionFactory factory;
//private TypeinferenceResults tiResult;
private TypeinferenceResults tiResult;
private int lambdaMethodeNr = 0;
private Type superClass;
private List<GenericTypeVar> generics;
private Menge<TypePlaceholder> usedTPHs = new Menge<>();
@ -43,11 +46,14 @@ public class ClassGenerator extends ClassGen{
private List<String> methodsNamesAndTypes = new LinkedList<>();
private MethodGenerator methodGenerator;
public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings) {
super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen());
public ClassGenerator(JavaClassName name, Type superClass, List<GenericTypeVar> generics,
String sourceFileName, short accessflags, String[] implementedInterfaces, TypeinferenceResults rs) {
super(name.toString(),superClass.get_Name(),sourceFileName,accessflags,implementedInterfaces, new DHBWConstantPoolGen());
//this.tiResult = typeinferenceResultSet;
this.superClass = superClass;
this.generics = generics;
tiResult = rs;
cp = (DHBWConstantPoolGen) super.getConstantPool();
factory = new DHBWInstructionFactory(this, cp);
this.setMajor(52); //Java 8 Version 52.0
@ -152,8 +158,18 @@ public class ClassGenerator extends ClassGen{
//Signatur setzen:
String typeParameters = this.generateParameterSignature();
String superClassSignature = this.superClass.getBytecodeSignature(this, null);
String classSignature = typeParameters + superClassSignature;
String superClassSignature = this.superClass.get_Name();
if(this.superClass instanceof RefType &&
((RefType)superClass).get_ParaList() != null &&
((RefType)superClass).get_ParaList().size() > 0){
superClassSignature += "<";
RefType superRefType = (RefType) this.superClass;
for(Type param : superRefType.get_ParaList()){
superClassSignature += param.getBytecodeSignature(this, null);
}
superClassSignature += ">";
}
String classSignature = typeParameters + superClassSignature; //TOOD: Hier noch die Signaturen der SuperInterfaces anfügen
if(classSignature.length()>0){
this.addAttribute(new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(classSignature),cp.getConstantPool()));
}
@ -178,6 +194,16 @@ public class ClassGenerator extends ClassGen{
private String generateParameterSignature(){
String ret = "";
//ret += "L" + this.getClassName().replace(".", "/") + ";";
if(this.generics != null && this.generics.size() > 0){
ret += "<";
for(GenericTypeVar gtv : this.generics){
ret += gtv.getBytecodeSignature(this, tiResult.getTypeReconstructions().get(0));
}
ret += ">";
}
/*
if(this.getUsedTPH().size()>0){
ret += "<";
Iterator<TypePlaceholder> it = ((Menge<TypePlaceholder>)this.getUsedTPH().clone()).iterator();
@ -189,6 +215,7 @@ public class ClassGenerator extends ClassGen{
}
ret += ">";
}
*/
return ret;
}

View File

@ -148,7 +148,7 @@ public class MyCompiler implements MyCompilerAPI{
* Fun0-FunN (momentan ¼r N = 6)
* @return
*/
private TypeAssumptions makeFunNAssumptions(){
public static TypeAssumptions makeFunNAssumptions(){
TypeAssumptions ret = new TypeAssumptions();
//Basic Assumptions ¼r die FunN Interfaces:

View File

@ -72,7 +72,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
protected static Logger parserlog = Logger.getLogger("parser");
protected UsedId pkgName;
protected Modifiers modifiers;
protected String name;
protected JavaClassName name;
protected List<RefType> implementedInterfaces = new ArrayList<>();
/**
*
@ -90,8 +91,10 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
logger.debug("Test");
if(pkgName != null)throw new NotImplementedException();
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
_cg = new ClassGenerator(name, this.getSuperClass(), name + ".java", constants , new String[] { }); //letzter Parameter sind implementierte Interfaces
short constants = Const.ACC_PUBLIC; //Per Definition ist jede Methode public
if(isInterface())constants+=Const.ACC_INTERFACE;
_cg = new ClassGenerator(name, this.getSuperClass(), this.getGenericParameter(), name + ".java", constants , new String[] { }, typeinferenceResults); //letzter Parameter sind implementierte Interfaces
_cp = _cg.getConstantPool();
_factory = new DHBWInstructionFactory(_cg, _cp);
@ -105,6 +108,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
if(field instanceof FieldDeclaration)fieldDeclarations.add((FieldDeclaration)field);
//field.genByteCode(_cg);
}
//Zuerst die Methoden und Felder abarbeiten:
for(Method m : methods){
m.genByteCode(_cg, this, typeinferenceResults);
@ -138,7 +142,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
}
public void setName(String strName)
{
name = strName;
name = new JavaClassName(strName);
}
public void setModifiers(Modifiers mod)
{
@ -195,7 +199,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
public Class(String name, int offset)
{
this.name = name;
this.name = new JavaClassName(name);
if(name.equals("java.lang.Object")){
superclassid=null;
}
@ -203,8 +207,18 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
if(!name.equals("Object") && !name.equals("java.lang.Object"))//Alle Klassen außer Object erben von Object:
this.superClass = new Class("java.lang.Object", -1).getType();
}
// ino.end
public Class(JavaClassName name, List<Method> methoden, List<Field> felder, Modifiers modifier,
boolean isInterface, RefType superClass, List<RefType> implementedInterfaces,
GenericDeclarationList generics, int offset){
this(name.toString(), superClass, modifier, new Menge<>());
this.implementedInterfaces = implementedInterfaces;
this.offset = offset;
this.isInterface = isInterface;
this.isInterface();
this.genericClassParameters = generics;
}
/**
* Erstellt eine Klasse, welche nur ¼r die Assumptions verwendet wird.
* Sie enthält keine unnÃtigen Informationen, wie Offset oder ClassBody.
@ -695,7 +709,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
{
//return superclassid.toString() + body.toString();
//geaendert PL 07-07-28
return name;
return name.toString();
}
// ino.end
@ -897,7 +911,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
break;
}
}
if(!constructorVorhanden){//Falls kein Konstruktor vorhanden ist, muss noch der Standardkonstruktor angefügt werden:
if(!constructorVorhanden && ! isInterface()){//Falls kein Konstruktor vorhanden ist, muss noch der Standardkonstruktor angefügt werden:
Block konstruktorBlock = new Block();
konstruktorBlock.statements.add(new SuperCall(konstruktorBlock));
Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock,this.getName().toString(), this), this);
@ -1009,8 +1023,9 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
return true;
}
protected boolean isInterface;
public boolean isInterface(){
return false;
return isInterface;
}
/*
private Collection<? extends ByteCodeResult> getGenericClasses() {

View File

@ -66,7 +66,9 @@ 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, null), this.parameterlist.getBytecodeTypeList(cg,null) , this.parameterlist.getParameterNameArray(), "<init>", parentClass.name, il, _cp);
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC,
this.getType().getBytecodeType(cg, null), this.parameterlist.getBytecodeTypeList(cg,null),
this.parameterlist.getParameterNameArray(), "<init>", parentClass.name.toString(), il, _cp);
//FieldInitializations an Block anfügen
Block block = this.get_Block();

View File

@ -21,6 +21,10 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
private int offsetOfLastElement;
private Menge<GenericTypeVar> gtvs = new Menge<>();
public GenericDeclarationList(){
this(new Menge<GenericTypeVar>(), -1);
}
public GenericDeclarationList(Menge<GenericTypeVar> values, int endOffset) {
this.addAll(values);
this.offsetOfLastElement = endOffset;

View File

@ -81,7 +81,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
super(offset);
}
public Method(String name, Type returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, int offset) {
public Method(String name, Type returnType, ParameterList parameterList, Block block,
GenericDeclarationList gtvDeclarations, int offset) {
this(offset);
/*
* if(parameterList != null)parameterList.parserPostProcessing(this);
@ -405,7 +406,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
addMethodToClassGenerator(cg, _factory, t);
}
}
private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) {
DHBWConstantPoolGen _cp = cg.getConstantPool();
InstructionList il = new InstructionList();
@ -422,7 +423,10 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
Type returnType = this.getType();
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes.toArray(new org.apache.bcel.generic.Type[parameterlist.size()]) , argumentNames.toArray(new String[parameterlist.size()]), this.get_Method_Name(), getParentClass().name, il, _cp);
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t),
argumentTypes.toArray(new org.apache.bcel.generic.Type[parameterlist.size()]) ,
argumentNames.toArray(new String[parameterlist.size()]), this.get_Method_Name(),
getParentClass().name.toString(), il, _cp);
cg.setMethodeGenerator(method);

View File

@ -707,227 +707,6 @@ public class SourceFile
}
//}
}
// ino.end
// ino.method.makeBasicAssumptions.21418.defdescription type=javadoc
/**
* Erzeugt die Anfangsinformationen �ber bereits bekannte Klassen.
* <br/>Achtung Workaround: Die RefTypes ¯Â¿Â½ssen sp�ter noch durch BaseTypes
* ersetzt werden. <br>
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle
*
* @return A priori Typinformationen
* @throws ClassNotFoundException
*/
// ino.end
// ino.method.makeBasicAssumptions.21418.definition
private TypeAssumptions makeBasicAssumptions()
// ino.end
// ino.method.makeBasicAssumptions.21418.body
{
/*
if(LOAD_BASIC_ASSUMPTIONS_FROM_JRE){
Menge<UsedId> strImports=new Menge<UsedId>();
ImportDeclarations usedIdImports=getImports();
for(int i=0;i<usedIdImports.size();i++){
UsedId uid=usedIdImports.get(i);
if(uid.hasWildCard()){
throw new CTypeReconstructionException("Wildcards in den Imports werden bislang nicht unterstuetzt: "+uid.getQualifiedName(),uid);
//throw new ClassNotFoundException("Bei den Imports sind momentan keine Wildcards erlaubt!");
}else{
strImports.addElement(uid);
}
}
TypeinferenceResultSet res=makeBasicAssumptionsFromJRE(strImports);
ImportDeclarations newImports=new ImportDeclarations();
for(int i=0;i<strImports.size();i++){
newImports.addElement(strImports.get(i));
}
setImports(newImports);
return(res);
}
TypeinferenceResultSet foo = new TypeinferenceResultSet(null);
CMethodTypeAssumption meth = null;
CInstVarTypeAssumption instVar = null;
Class c = null;
UsedId ui = null;
//Menge pl = null;
Modifiers mod = new Modifiers();
mod.addModifier(new Public());
//------------------------
// Integer bauen:
//------------------------
foo.addClassName("java.lang.Integer"); //PL 05-08-01 eingefuegt
instVar = new CInstVarTypeAssumption("java.lang.Integer", "MAX_VALUE", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>());
foo.addFieldOrLocalVarAssumption(instVar);
meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "<init>", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "<init>", new RefType("java.lang.Integer",-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Integer", "<init>", 1, 0,"value", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "intValue", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
c = new BasicAssumptionClass("java.lang.Integer", mod);
// ui = new UsedId();
// ui.set_Name("Super-Class-Blub");
// c.set_UsedId(ui);
// pl = new Menge();
// pl.addElement(new GenericTypeVar("bla"));
// c.set_ParaList(pl);
this.addElement(c);
//------------------------
// Boolean bauen:
//------------------------
foo.addClassName("java.lang.Boolean"); //PL 05-08-01 eingefuegt
meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "<init>", new RefType("java.lang.Boolean",-1),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "<init>", new RefType("java.lang.Boolean",-1), 1,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Boolean", "<init>", 1, 0, "value", new RefType("java.lang.Boolean",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "booleanValue", new RefType("java.lang.Boolean",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
c = new BasicAssumptionClass("java.lang.Boolean", mod);
// ui = new UsedId();
// ui.set_Name("Super-Class-Blub");
// c.set_UsedId(ui);
// pl = new Menge();
// pl.addElement(new GenericTypeVar("bla"));
// c.set_ParaList(pl);
this.addElement(c);
//------------------------
// Character bauen:
//------------------------
foo.addClassName("java.lang.Character"); //PL 05-08-01 eingefuegt
meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "<init>", new RefType("java.lang.Character",-1),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "<init>", new RefType("java.lang.Character",-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Character", "<init>", 1, 0,"value", new RefType("java.lang.Character",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "charValue", new BooleanType(),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
c = new BasicAssumptionClass("java.lang.Character", mod);
// ui = new UsedId();
// ui.set_Name("Super-Class-Blub");
// c.set_UsedId(ui);
// pl = new Menge();
// pl.addElement(new GenericTypeVar("bla"));
// c.set_ParaList(pl);
this.addElement(c);
//------------------------
// Menge bauen:
//------------------------
foo.addClassName("java.lang.Menge"); //PL 05-08-01 eingefuegt
TypePlaceholder E = TypePlaceholder.fresh(); // Sp�ter ersetzen durch GenericTypeVar
Menge<GenericTypeVar> typeGenPara = new Menge<GenericTypeVar>();
typeGenPara.addElement(new GenericTypeVar(E.getName(),-1));
foo.addGenericTypeVars("java.lang.Menge", typeGenPara);
meth = new CMethodTypeAssumption(new RefType("java.lang.Menge", 0), "elementAt", new GenericTypeVar(E.getName(),-1), 1,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Menge", "elementAt", 1, 0, "index", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Menge", 0), "addElement", new Void(-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Menge", "addElement", 1, 0,"element", new GenericTypeVar(E.getName(),-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Menge", 0), "size", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
c = new BasicAssumptionClass("java.lang.Menge", mod);
// ui = new UsedId();
// ui.set_Name("Super-Class-Blub");
// c.set_UsedId(ui);
// pl = new Menge();
// pl.addElement(E);
// c.set_ParaList(pl);
this.addElement(c);
//------------------------
// Stack bauen:
//------------------------
foo.addClassName("java.lang.Stack"); //PL 05-08-01 eingefuegt
c = new BasicAssumptionClass("java.lang.Stack", mod);
ui = new UsedId(-1);
ui.set_Name("java.lang.Menge");
c.set_UsedId(ui);
// pl = new Menge();
// pl.addElement(E);
// c.set_ParaList(pl);
this.addElement(c);
return foo;
*/
TypeAssumptions ret = new TypeAssumptions();
//Basic Assumptions ¼r die FunN Interfaces:
//TODO: Hier mehr als Fun1-Fun5 implementieren
for(int i = 0; i<6; i++){
FunNInterface funN = new FunNInterface(i);
ret.add(funN.getPublicFieldAssumptions());
}
return ret; //TODO: Diese TypeAssumptions mit basic-Assumptions ¼llen
}
// ino.end
// ino.method.setImports.21421.definition
private void setImports(ImportDeclarations newImports)
// ino.end
// ino.method.setImports.21421.body
{
this.imports=newImports;
}
// ino.end
// ino.method.removeBasicAssumptions.21424.defdescription type=javadoc
/**
* ¯Â¿Â½scht die Anfangsinformation wieder aus dem Klassenvektor
* <br/>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
*/
// ino.end
// ino.method.removeBasicAssumptions.21424.definition
private void removeBasicAssumptions()
// ino.end
// ino.method.removeBasicAssumptions.21424.body
{
for(int i=0; i<KlassenVektor.size(); i++){
Class cl = KlassenVektor.elementAt(i);
if(cl instanceof BasicAssumptionClass){
KlassenVektor.removeElementAt(i);
i--;
}
}
}
// ino.end
// ino.method.getPackageName.21427.defdescription type=javadoc
/**
@ -1073,6 +852,10 @@ public class SourceFile
for(Class cl : this.KlassenVektor){
ret.add(cl.genByteCode(results));
}
//Alle FunN Klassen erzeugen:
for(ClassAssumption funNAss : MyCompiler.makeFunNAssumptions().getClassAssumptions()){
ret.add(funNAss.getAssumedClass().genByteCode(results));
}
/*
//Add all FunN Interfaces
for(Pair ucons : results.getUnifiedConstraints()){

View File

@ -1,8 +1,14 @@
package de.dhbwstuttgart.syntaxtree.factory;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
@ -55,6 +61,7 @@ public class ASTFactory {
return new Constructor(method, superClass);
}
/*
public static Class createClass(String className, RefType type, Modifiers modifiers, Menge supertypeGenPara, SourceFile parent) {
// TODO bytecode createClass
//String name, RefType superClass, Modifiers modifiers, Menge<String> supertypeGenPara
@ -65,10 +72,13 @@ public class ASTFactory {
return generatedClass;
}
public static Class createInterface(String className, RefType type){
//Class generatedClass = new Class(className, )
return null;
*/
public static Class createInterface(String className, RefType superClass, Modifiers modifiers,
Menge supertypeGenPara, SourceFile parent){
Class generatedClass = new Class(new JavaClassName(className), new ArrayList<Method>(), new ArrayList<Field>(), modifiers,
true, superClass, new ArrayList<RefType>(), new GenericDeclarationList(), -1);
generatedClass.parserPostProcessing(parent);
return generatedClass;
}
public static Class createObjectClass() {

View File

@ -13,6 +13,7 @@ import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
@ -50,18 +51,19 @@ public class FunN extends RefType {
/**
* Spezieller Konstruktor um eine FunN ohne Returntype zu generieren
*/
protected FunN(List<? extends Type> list){
super("",null,0);
if(list==null)throw new NullPointerException();
setT(list);
this.name = new JavaClassName("Fun"+list.size());//getName();
}
*/
/**
* Erstellt eine FunN:
* FunN<R, T1, ..., TparameterCount>
* R und T1 - TparameterCount werden mit TypePlaceholdern besetzt.
* R und T1 - TparameterCount werden mit GenericTypeVars besetzt.
* @param parameterCount
*/
public FunN(int parameterCount) {
@ -69,14 +71,15 @@ public class FunN extends RefType {
if(parameterCount<0)throw new RuntimeException("Anzahl der Parameter muss >0 sein");
Menge<Type> t = new Menge<Type>();
for(int i=0;i<parameterCount;i++){
t.add(TypePlaceholder.fresh(this));
//t.add(TypePlaceholder.fresh(this));
t.add(new GenericTypeVar(NameGenerator.makeNewName(), this, -1));
}
setR(TypePlaceholder.fresh(this));
setR(new GenericTypeVar(NameGenerator.makeNewName(), this, -1));
setT(t);
this.name = new JavaClassName("Fun"+parameterCount);
}
/**
* Muss nach jeder Änderung von T oder R aufgerufen werden.
* Dabei werden bestimmte, von RefType geerbte, Parameter angepasst. Dies ist wichtig ¼r den Typinferenzalgorithmus.

View File

@ -30,7 +30,8 @@ public class FunVoidN extends FunN {
* @return
*/
public FunVoidN(Menge<Type> T) {
super(T);
super(null,T);
this.setR(new Void(this, -1));
this.name = new JavaClassName("FunVoid"+T.size());
}

View File

@ -589,7 +589,7 @@ public class RefType extends ObjectType implements IMatchable
public String getCombinedType(ClassGenerator cg, TypeinferenceResultSet rs){
//Bsp.: Ljava/util/Vector<Ljava/lang/String;>;
StringBuilder sb = new StringBuilder();
String ret;
if(parameter != null && parameter.size() > 0){
sb.append(getName().toString().replace(".", "%"));
sb.append("%%");
@ -606,21 +606,24 @@ public class RefType extends ObjectType implements IMatchable
sb.append("%");
}
return sb.toString();
}
String ret = sb.append(this.getName().toString()).toString();
ret = sb.toString();
}else{
ret = sb.append(this.getName().toString()).toString();
}
if(!ret.equals(getName().toString())){
//getSuperWildcardTypes();
Class generatedClass = ASTFactory.createClass(getCombinedType(cg, rs), getGenericClassType(), null, null, new SourceFile());
Class generatedClass = ASTFactory.createInterface(ret, this, null, null, new SourceFile());
cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResults()).getByteCode());
}
return ret;
}
/*
public GenericClassType getGenericClassType(){
return new GenericClassType(getName().toString(), getParaList(), parent, getOffset());
}
*/
}
// ino.end

View File

@ -14,6 +14,7 @@ import de.dhbwstuttgart.bytecode.TypePlaceholderType;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
@ -39,8 +40,6 @@ public class TypePlaceholder extends ObjectType
// ino.class.TypePlaceholder.26780.body
{
private static final Logger log = Logger.getLogger(TypePlaceholder.class.getName());
// ino.attribute.strNextName.26785.declaration
private static String strNextName = "A";
// ino.end
// ino.attribute.m_TypePlaceholdersRegistry.26788.declaration
private static Hashtable<String, TypePlaceholder> m_TypePlaceholdersRegistry = new Hashtable<String, TypePlaceholder>();
@ -104,7 +103,7 @@ public class TypePlaceholder extends ObjectType
TypePlaceholder typeVar = new TypePlaceholder(name, parent);
TypePlaceholder oldTPH = m_TypePlaceholdersRegistry.put(typeVar.getName().toString(), typeVar);
if(oldTPH != null){
oldTPH.name = new JavaClassName(makeNewName());
oldTPH.name = new JavaClassName(NameGenerator.makeNewName());
m_TypePlaceholdersRegistry.put(oldTPH.getName().toString(), oldTPH);
}
return typeVar;
@ -120,7 +119,7 @@ public class TypePlaceholder extends ObjectType
* @return
*/
public static TypePlaceholder fresh(SyntaxTreeNode parent){
TypePlaceholder ret= new TypePlaceholder(makeNewName(), parent);
TypePlaceholder ret= new TypePlaceholder(NameGenerator.makeNewName(), parent);
m_TypePlaceholdersRegistry.put(ret.getName().toString(), ret);
return ret;
}
@ -132,98 +131,7 @@ public class TypePlaceholder extends ObjectType
return ret;
}
// ino.method.makeNewName.26803.defdescription type=javadoc
/**
* Berechnet einen neuen, eindeutigen Namen ¯Â¿Â½r eine neue
* <code>TypePlaceholder</code>. <br>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
* @return Der Name
*/
// ino.end
// ino.method.makeNewName.26803.definition
private static String makeNewName()
// ino.end
// ino.method.makeNewName.26803.body
{
// otth: Funktion berechnet einen neuen Namen anhand eines alten gespeicherten
String strReturn = strNextName;
// ¯Â¿Â½chster Name berechnen und in strNextName speichern
inc( strNextName.length() - 1 );
return strReturn;
}
// ino.end
// ino.method.inc.26806.defdescription type=javadoc
/**
* Hilfsfunktion zur Berechnung eines neuen Namens
* <br>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
* @param i
*/
// ino.end
// ino.method.inc.26806.definition
private static void inc(int i)
// ino.end
// ino.method.inc.26806.body
{
// otth: Hilfsfunktion zur Berechnung eines neuen Namens
// otth: Erh�hung des Buchstabens an der Stelle i im String strNextName
// otth: Nach �berlauf: rekursiver Aufruf
// falls i = -1 --> neuer Buchstabe vorne anf�gen
if ( i == -1 )
{
strNextName = "A" + strNextName;
return;
}
char cBuchstabe = (char)(strNextName.charAt( i ));
cBuchstabe++;
if ( cBuchstabe - 65 > 25 )
{
// aktuelle Stelle: auf A zuruecksetzen
manipulate( i, 'A' );
// vorherige Stelle erh�hen
inc( i - 1 );
}
else
{
// aktueller Buchstabe �ndern
manipulate( i, cBuchstabe );
}
}
// ino.end
// ino.method.manipulate.26809.defdescription type=javadoc
/**
* Hilfsfunktion zur Berechnung eines neuen Namens.
* <br>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
* @param nStelle
* @param nWert
*/
// ino.end
// ino.method.manipulate.26809.definition
private static void manipulate( int nStelle, char nWert )
// ino.end
// ino.method.manipulate.26809.body
{
// otth: Hilfsfunktion zur Berechnung eines neuen Namens
// otth: Ersetzt im String 'strNextName' an der Position 'nStelle' den Buchstaben durch 'nWert'
String strTemp = "";
for( int i = 0; i < strNextName.length(); i++)
{
if ( i == nStelle )
strTemp = strTemp + nWert;
else
strTemp = strTemp + strNextName.charAt( i );
}
strNextName = strTemp;
}
// ino.end
// ino.method.equals.26812.defdescription type=javadoc
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
@ -327,7 +235,7 @@ public class TypePlaceholder extends ObjectType
//backdoorvars werden registiert, weil am Ende beim execute
//auf den CSubstitution nicht registrierte Variablen zu
//Exceptions fuehrt
TypePlaceholder typeVar = new TypePlaceholder(makeNewName(), null);
TypePlaceholder typeVar = new TypePlaceholder(NameGenerator.makeNewName(), null);
m_TypePlaceholdersRegistry.put(typeVar.getName().toString(), typeVar);
return typeVar;
@ -447,6 +355,10 @@ public class TypePlaceholder extends ObjectType
@Override
public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
if(rs == null){
System.out.println("");
return null;
}
Type resolvedType = rs.getTypeOfPlaceholder(this);
if(resolvedType instanceof TypePlaceholder){
cg.addUsedTPH((TypePlaceholder)resolvedType);
@ -463,7 +375,8 @@ public class TypePlaceholder extends ObjectType
ret+=":";
Menge<TypePlaceholder> possibleTPHs = cg.getUsedTPH();
possibleTPHs.remove(this);
org.apache.bcel.generic.Type nearestType = cg.getNearestUsedType(this, possibleTPHs);
//TODO: hier komplett überarbeiten. Wann wird ein TPH eine generische Variable, das sollte geklärt werden.
org.apache.bcel.generic.Type nearestType = null;//cg.getNearestUsedType(this, possibleTPHs);
//if(nearestType instanceof TypePlaceholderType){ //Handelt es sich um einen weiteren TPH als nächsten Typ, so ist es ein allgemeiner Typ und wir nehmen Object als Superklasse
if(nearestType == null){
ret += cg.getInstructionFactory().createObjectType().getSignature();

View File

@ -38,21 +38,18 @@ public class SingleClassTester {
Menge<ByteCodeResult> bytecode = compiler.generateBytecode(sourceFiles, results);
//System.out.println(bytecode);
for(ByteCodeResult result: bytecode){
for(ByteCodeResult result: bytecode){
JavaClass javaClass = result.getByteCode().getJavaClass();
javaClass.dump(new File(outputDirectory+javaClass.getClassName()+".class"));
/*
///*
for(ClassGenerator cg: result.getByteCode().getExtraClasses().values()){
JavaClass jc = cg.getJavaClass();
jc.dump(new File(outputDirectory+jc.getClassName()+".class"));
}
*/
//*/
Logger.getLogger("SingleClassTester").error(result.getByteCode().getJavaClass().toString(), Section.CODEGEN);
}
} catch (IOException | yyException e) {
Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN);