forked from JavaTX/JavaCompilerCore
Aufräumen
This commit is contained in:
parent
1ac500715b
commit
bc812ad083
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.awt.List;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -65,10 +66,11 @@ public class MethodGenerator extends MethodGen{
|
||||
//TODO: Das ist schlecht! Der Parser oder der Typinferenzalgorithmus muss dafür sorgen, dass sich in jeder Methode ein Return befindet.
|
||||
if (block.get_Statement().size() == 0) { il.append(factory.createReturn( org.apache.bcel.generic.Type.VOID)); }
|
||||
else {
|
||||
if (!(block.get_Statement().lastElement() instanceof Return) &&
|
||||
this.getType().equals(org.apache.bcel.generic.Type.VOID)) {
|
||||
il.append(factory.createReturn( org.apache.bcel.generic.Type.VOID));
|
||||
}
|
||||
java.util.List<Statement> stmts = block.get_Statement();
|
||||
if (!(stmts.get(stmts.size()-1) instanceof Return) &&
|
||||
this.getType().equals(org.apache.bcel.generic.Type.VOID)) {
|
||||
il.append(factory.createReturn( org.apache.bcel.generic.Type.VOID));
|
||||
}
|
||||
}
|
||||
|
||||
method.getInstructionList().setPositions();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbwstuttgart.core;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SourceCodePosition;
|
||||
|
||||
public interface IItemWithOffset
|
||||
{
|
||||
|
@ -19,12 +19,9 @@ import de.dhbwstuttgart.parser.JavaParser.yyException;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassBody;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.ImportDeclarations;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.IMatchable;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ITypeContainer;
|
||||
|
@ -75,7 +75,7 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
|
||||
public Class(JavaClassName name, List<Method> methoden, List<Field> felder, Modifiers modifier,
|
||||
boolean isInterface, RefType superClass, List<RefType> implementedInterfaces, int offset){
|
||||
|
||||
super(offset);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -172,7 +172,7 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
// ino.method.get_ParaList.23101.body
|
||||
{
|
||||
//if(this.paralist == null)return new Menge<Type>();
|
||||
return this.getGenericParameter();
|
||||
return this.getGenericParameter().getGTVList();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@ -421,7 +421,7 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
//}
|
||||
ret.addAll(this.getFields());
|
||||
ret.addAll(this.get_ParaList());
|
||||
ret.addAll(this.getGenericParameter());
|
||||
ret.addAll(this.getGenericParameter().getGTVList());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -435,9 +435,8 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menge<GenericTypeVar> getGenericParameter() {
|
||||
if(this.genericClassParameters == null)return new Menge<GenericTypeVar>();
|
||||
return this.genericClassParameters.getMenge();
|
||||
public GenericDeclarationList getGenericParameter() {
|
||||
return this.genericClassParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,9 +43,10 @@ public class Constructor extends Method {
|
||||
* Diese Klasse beherbegt den als Methode geparsten Konstruktor und wandelt sein verhalten zu dem eines Konstruktors ab.
|
||||
*/
|
||||
public Constructor(Method methode, Class parent){
|
||||
super(methode.get_Method_Name(), methode.getType(), methode.getParameterList(),methode.get_Block(), methode.getGenericDeclarationList(), methode.getOffset());
|
||||
super(methode.get_Name(), methode.getType(), methode.getParameterList(),
|
||||
methode.get_Block(), methode.getGenericDeclarationList(), methode.getOffset());
|
||||
//Sicherstellen, dass das erste Statement in der Methode ein SuperCall ist:
|
||||
if(this.get_Block().get_Statement().size() <1 || ! (this.get_Block().get_Statement().firstElement() instanceof SuperCall)){
|
||||
if(this.get_Block().get_Statement().size() <1 || ! (this.get_Block().get_Statement().get(0) instanceof SuperCall)){
|
||||
this.get_Block().statements.add(0, new SuperCall(this.get_Block()));
|
||||
this.parserPostProcessing(parent);
|
||||
}
|
||||
@ -53,7 +54,7 @@ public class Constructor extends Method {
|
||||
@Override
|
||||
public TypeAssumptions createTypeAssumptions(Class classmember) {
|
||||
this.parent = classmember;
|
||||
Class parentClass = this.getParentClass();
|
||||
Class parentClass = classmember;
|
||||
TypeAssumptions ret = new TypeAssumptions();
|
||||
ret.addAssumption(new ConstructorAssumption(this, parentClass));
|
||||
return ret;
|
||||
@ -62,15 +63,14 @@ public class Constructor extends Method {
|
||||
public void genByteCode(ClassGenerator cg, InstructionList fieldInitializations){
|
||||
DHBWConstantPoolGen _cp = cg.getConstantPool();
|
||||
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
|
||||
Class parentClass = this.getParentClass();
|
||||
|
||||
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, null), this.parameterlist.getBytecodeTypeList(cg,null) , this.parameterlist.getParameterNameArray(), "<init>", parentClass.name.getName(), il, _cp);
|
||||
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, null),
|
||||
this.parameterlist.getBytecodeTypeList(cg,null) , this.parameterlist.getParameterNameArray(),
|
||||
"<init>", cg.getClassName(), il, _cp);
|
||||
|
||||
//FieldInitializations an Block anfügen
|
||||
Block block = this.get_Block();
|
||||
if(block.statements.firstElement() instanceof SuperCall){
|
||||
block.statements.insertElementAt(new BytecodeInstructionBlock(fieldInitializations), 1);
|
||||
}else{
|
||||
if(! (block.statements.get(0) instanceof SuperCall)){
|
||||
throw new DebugException("Fehlender SuperCall im Konstruktor");
|
||||
}
|
||||
|
||||
@ -79,20 +79,6 @@ public class Constructor extends Method {
|
||||
cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block(), null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Mit dieser Hilfsklasse kann eine beliebige InstructionList in eine vorhandenen Block als Statement eingefügt werden.
|
||||
* Wird für Bytecodegenerierung benötigt.
|
||||
*/
|
||||
private class BytecodeInstructionBlock extends Block{
|
||||
InstructionList il;
|
||||
BytecodeInstructionBlock(InstructionList toInsert){
|
||||
il = toInsert;
|
||||
}
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs){
|
||||
return il;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genByteCode(ClassGenerator cg, Class classObj) {
|
||||
@ -118,18 +104,6 @@ public class Constructor extends Method {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintsSet TYPE(TypeAssumptions ass) {
|
||||
//super.setType(this.getParentClass().getType());
|
||||
super.setType(new Void(this, 0));
|
||||
return super.TYPE(ass);
|
||||
}
|
||||
@Override
|
||||
public void setType(Type t) {
|
||||
super.setType(new Void(this, this.getOffset()));
|
||||
//throw new TypeinferenceException("Einem Konstruktor kann kein Typ zugewiesen werden", this);
|
||||
//this.methode.setType(t);
|
||||
}
|
||||
|
||||
/*public Constructor(Method methode){
|
||||
super(methode.getOffset());
|
||||
|
@ -23,12 +23,11 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta
|
||||
private String name;
|
||||
protected Type typ;
|
||||
|
||||
private int offset;
|
||||
|
||||
private GenericDeclarationList genericParameters;
|
||||
|
||||
public Field(int offset){
|
||||
this.offset = offset;
|
||||
super(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,7 +49,7 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta
|
||||
public Menge<GenericTypeVar> getGenericParameter() {
|
||||
Menge<GenericTypeVar> ret = new Menge<>();
|
||||
if(this.genericParameters == null)return ret;
|
||||
ret.addAll(this.genericParameters.getMenge());
|
||||
ret.addAll(this.genericParameters.getGTVList());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ public class FieldDeclaration extends Field{
|
||||
}
|
||||
|
||||
FieldInstruction putFieldInstruction =
|
||||
cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(),
|
||||
cg.getInstructionFactory().createFieldAccess(cg.getClassName(),
|
||||
this.getDescription(), this.getType().getBytecodeType(cg, rs), Const.PUTFIELD);
|
||||
il.append(putFieldInstruction );
|
||||
return il;
|
||||
|
@ -28,7 +28,8 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
|
||||
private String name;
|
||||
protected static Logger inferencelog = Logger.getLogger("inference");
|
||||
|
||||
public FormalParameter(String name, Type type){
|
||||
public FormalParameter(String name, Type type, int offset){
|
||||
super(offset);
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
@ -72,23 +73,6 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
// ino.method.getOffset.23422.defdescription type=javadoc
|
||||
/**
|
||||
* <br/>Author: Thomas Hornberger 09.04.2006
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.getOffset.23422.definition
|
||||
public int getOffset()
|
||||
// ino.end
|
||||
// ino.method.getOffset.23422.body
|
||||
{
|
||||
return position.getOffset();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
//private Type typeVariable;
|
||||
|
||||
public String getTypeInformation() {
|
||||
|
@ -5,6 +5,9 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
* dass bei seiner Deklaration auch Generische Typvariablen deklariert wurden.
|
||||
*/
|
||||
public abstract class GTVDeclarationContext extends SyntaxTreeNode {
|
||||
public GTVDeclarationContext(int offset) {
|
||||
super(offset);
|
||||
}
|
||||
@Override
|
||||
public GTVDeclarationContext getGTVDeclarationContext(){
|
||||
return this;
|
||||
|
@ -22,6 +22,7 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
||||
private List<GenericTypeVar> gtvs = new Menge<>();
|
||||
|
||||
public GenericDeclarationList(List<GenericTypeVar> values, int endOffset) {
|
||||
super(endOffset);
|
||||
gtvs = values;
|
||||
this.offsetOfLastElement = endOffset;
|
||||
}
|
||||
@ -61,4 +62,8 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
||||
public void add(GenericTypeVar t) {
|
||||
this.gtvs.add(t);
|
||||
}
|
||||
|
||||
public List<GenericTypeVar> getGTVList() {
|
||||
return this.gtvs;
|
||||
}
|
||||
}
|
||||
|
@ -326,12 +326,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
public void genByteCode(ClassGenerator cg, Class classObj, Class parentClass) {
|
||||
public void genByteCode(ClassGenerator cg, Class classObj) {
|
||||
List<TypeinferenceResultSet> typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg);
|
||||
DHBWInstructionFactory _factory = cg.getInstructionFactory();
|
||||
|
||||
for(TypeinferenceResultSet t: typeInterferenceResults){
|
||||
addMethodToClassGenerator(cg, _factory, t, parentClass);
|
||||
addMethodToClassGenerator(cg, _factory, t, classObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,11 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
|
||||
public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
|
||||
protected SyntaxTreeNode parent;
|
||||
protected int offset;
|
||||
|
||||
public SyntaxTreeNode(int offset){
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird nach dem Parsen aufgerufen.
|
||||
@ -137,5 +142,8 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
return this.getParent().getGTVDeclarationContext();
|
||||
}
|
||||
|
||||
public int getOffset(){
|
||||
return offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -172,25 +172,25 @@ public class UnifyTypeFactory {
|
||||
|
||||
public static Type convert(ReferenceType t) {
|
||||
//TODO: Hier kann man die GTVs extrahieren
|
||||
if(t.getName().toString().equals(Void.VOID_NAME))return new Void(NULL_NODE, 0);
|
||||
RefType ret = new RefType(t.getName(),null,0);
|
||||
if(t.getName().toString().equals(Void.VOID_NAME))return new Void( 0);
|
||||
RefType ret = new RefType(t.getName(),0);
|
||||
ret.set_ParaList(convert(t.getTypeParams()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Type convert(FunNType t) {
|
||||
RefType ret = new RefType(t.getName(),null,0);
|
||||
RefType ret = new RefType(t.getName(),0);
|
||||
ret.set_ParaList(convert(t.getTypeParams()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Type convert(SuperType t) {
|
||||
RefType innerType = new RefType(t.getSuperedType().getName(),NULL_NODE,0);
|
||||
RefType innerType = new RefType(t.getSuperedType().getName(),0);
|
||||
return new SuperWildcardType(innerType);
|
||||
}
|
||||
|
||||
public static Type convert(ExtendsType t) {
|
||||
RefType innerType = new RefType(t.getExtendedType().getName(),NULL_NODE,0);
|
||||
RefType innerType = new RefType(t.getExtendedType().getName(),0);
|
||||
return new ExtendsWildcardType(innerType);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ public class Unify_FC_TTO_Builder {
|
||||
private Menge<Pair> fc = new Menge<Pair>();
|
||||
private Menge<Class> classes = new Menge<Class>();
|
||||
|
||||
/*
|
||||
public void AddInheritance(Type t1, Type t2) {
|
||||
if(t1 instanceof RefType)
|
||||
if(!classes.stream().anyMatch(x -> x.getName().equals(t1.getName())))
|
||||
@ -22,6 +23,7 @@ public class Unify_FC_TTO_Builder {
|
||||
|
||||
fc.add(new Pair(t1, t2));
|
||||
}
|
||||
*/
|
||||
|
||||
public void clear() {
|
||||
fc = new Menge<Pair>();
|
||||
|
@ -112,7 +112,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
|
||||
}
|
||||
|
||||
public Type getReturnType(){
|
||||
return new de.dhbwstuttgart.syntaxtree.type.Void(this,-1);
|
||||
return new de.dhbwstuttgart.syntaxtree.type.Void(-1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,11 +52,11 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
*/
|
||||
|
||||
// ino.method.BoundedGenericTypeVar.29409.definition
|
||||
public BoundedGenericTypeVar(String s, Menge<ObjectType> bounds, SyntaxTreeNode parentClass, int offset, int endOffset)
|
||||
public BoundedGenericTypeVar(String s, Menge<ObjectType> bounds, int offset, int endOffset)
|
||||
// ino.end
|
||||
// ino.method.BoundedGenericTypeVar.29409.body
|
||||
{
|
||||
super(s, parentClass ,offset);
|
||||
super(s, offset);
|
||||
if(bounds != null)for(Type t : bounds){
|
||||
//if(t!=null)this.extendVars.add(t);
|
||||
}
|
||||
@ -103,7 +103,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
// ino.end
|
||||
// ino.method.clone.26483.body
|
||||
{
|
||||
return new BoundedGenericTypeVar(this.getName().toString(), this.getBounds(), this.getParentClass(), getOffset(), this.getEndOffset());
|
||||
return new BoundedGenericTypeVar(this.getName().toString(), this.getBounds(), getOffset(), this.getEndOffset());
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer,
|
||||
*/
|
||||
public ExtendsWildcardType (int offset, ObjectType extendsType)
|
||||
{
|
||||
super(extendsType, extendsType.getParent(), offset);
|
||||
super(extendsType, offset);
|
||||
this.name = new JavaClassName(this.toString());
|
||||
}
|
||||
|
||||
@ -81,16 +81,6 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt die passende FreshWildcardType Klasse zurück.
|
||||
* Wird für CaptureConversion verwendet
|
||||
*/
|
||||
public FreshExtendsWildcardType GetFreshWildcardType()
|
||||
{
|
||||
return new FreshExtendsWildcardType(this.innerType,this.getParent(),-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Das gleiche wie get_ExtendsType().
|
||||
|
@ -1,95 +0,0 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
|
||||
public class FreshExtendsWildcardType extends FreshWildcardType implements IMatchable {
|
||||
|
||||
private ObjectType extendsBoundType;
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Standard Konstruktor für eine FreshExtendsWildcard
|
||||
*/
|
||||
public FreshExtendsWildcardType(ObjectType extendsBound,SyntaxTreeNode parent ,int offset)
|
||||
{
|
||||
super(parent,offset);
|
||||
this.extendsBoundType = extendsBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Privater Konstruktor für clone
|
||||
*/
|
||||
private FreshExtendsWildcardType(ObjectType extendsBound ,SyntaxTreeNode parent,int offset, String name)
|
||||
{
|
||||
super(parent,offset,name);
|
||||
this.extendsBoundType = extendsBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt String Entsprechung zurück.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
String s = "FEWCT " + this.name;
|
||||
if(extendsBoundType != null)
|
||||
s += " " + extendsBoundType.toString();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt einen Klon der Wildcard zurück.
|
||||
* Der Innere Typ wird auch geklont
|
||||
*/
|
||||
public FreshExtendsWildcardType clone()
|
||||
{
|
||||
return new FreshExtendsWildcardType(this.extendsBoundType.clone(),this.getParent(),getOffset(),this.name.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt die Grenze der Wildcard zurück
|
||||
*/
|
||||
public ObjectType get_ExtendsBound()
|
||||
{
|
||||
return extendsBoundType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Prüft, ob zwei Objekte gleich sind. NICHT INSTANZGLEICH
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(obj instanceof FreshExtendsWildcardType)
|
||||
{
|
||||
FreshExtendsWildcardType FEWT = (FreshExtendsWildcardType)obj;
|
||||
return this.get_ExtendsBound().equals(FEWT.get_ExtendsBound());
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt die passende ExtendsWildcardType Klasse zurück.
|
||||
* Wird für smaller4 verwendet
|
||||
*/
|
||||
public ExtendsWildcardType get_WildcardType()
|
||||
{
|
||||
return new ExtendsWildcardType(this.getOffset(),this.get_ExtendsBound());
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt den Typen zurück, der bei einem match im Unify verwendet werden soll.
|
||||
* Wird über IMatchable implementiert.
|
||||
*/
|
||||
public Type getMatchType()
|
||||
{
|
||||
return this.get_ExtendsBound();
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
|
||||
public class FreshSuperWildcardType extends FreshWildcardType implements IMatchable {
|
||||
|
||||
private ObjectType superBoundType;
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Standard Konstruktor für eine FreshSuperWildcard
|
||||
*/
|
||||
public FreshSuperWildcardType(ObjectType superBound ,SyntaxTreeNode parent, int offset)
|
||||
{
|
||||
super(parent,offset);
|
||||
this.superBoundType = superBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Privater Konstruktor für clone
|
||||
*/
|
||||
private FreshSuperWildcardType(ObjectType superBound,SyntaxTreeNode parent,int offset, String name)
|
||||
{
|
||||
super(parent,offset,name);
|
||||
this.superBoundType = superBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt String Entsprechung zurück.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
String s = "FSWCT " + this.name;
|
||||
if(superBoundType != null)
|
||||
s += " " + superBoundType.toString();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt einen Klon der Wildcard zurück.
|
||||
* Der Innere Typ wird auch geklont
|
||||
*/
|
||||
public FreshSuperWildcardType clone()
|
||||
{
|
||||
return new FreshSuperWildcardType((ObjectType) this.superBoundType.clone(),this.getParent(),getOffset(),this.name.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt die Grenze der Wildcard zurück
|
||||
*/
|
||||
public ObjectType get_SuperBound()
|
||||
{
|
||||
return superBoundType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Prüft, ob zwei Objekte gleich sind. NICHT INSTANZGLEICH
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(obj instanceof FreshSuperWildcardType)
|
||||
{
|
||||
FreshSuperWildcardType FSWT = (FreshSuperWildcardType)obj;
|
||||
return this.get_SuperBound().equals(FSWT.get_SuperBound());
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt die passende SuperWildcardType Klasse zurück.
|
||||
* Wird für smaller4 verwendet
|
||||
*/
|
||||
public SuperWildcardType get_WildcardType()
|
||||
{
|
||||
return new SuperWildcardType(this.getOffset(),this.get_SuperBound());
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt den Typen zurück, der bei einem match im Unify verwendet werden soll.
|
||||
* Wird über IMatchable implementiert.
|
||||
*/
|
||||
public Type getMatchType()
|
||||
{
|
||||
return this.get_SuperBound();
|
||||
}
|
||||
}
|
@ -1,180 +0,0 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
public class FreshWildcardType extends ObjectType {
|
||||
|
||||
private static String strNextName = "A";
|
||||
private Menge<Type> upperBounds = new Menge<Type>();
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Standard Konstruktor für eine FreshWildcard
|
||||
*/
|
||||
public FreshWildcardType(SyntaxTreeNode parent, int offset)
|
||||
{
|
||||
super(parent, offset);
|
||||
this.name = makeNewName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Protected Konstruktor für clone.
|
||||
* Protected, da vererbte Klassen ihn verwenden müssen.
|
||||
*/
|
||||
protected FreshWildcardType(SyntaxTreeNode parent, int offset, String name)
|
||||
{
|
||||
super(parent, offset);
|
||||
this.name = new JavaClassName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt String Entsprechung zurück.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
String s = "FWCT " + this.name;
|
||||
if(upperBounds.size() > 0)
|
||||
{
|
||||
s += "|";
|
||||
for(int i = 0;i<upperBounds.size();i++)
|
||||
{
|
||||
if(i<upperBounds.size()-1)
|
||||
s += upperBounds.elementAt(i).toString() + " & ";
|
||||
else
|
||||
s += upperBounds.elementAt(i).toString();
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt einen Klon der Wildcard zurück.
|
||||
* Der Innere Typ wird auch geklont
|
||||
*/
|
||||
public FreshWildcardType clone()
|
||||
{
|
||||
return new FreshWildcardType(this.getParent(),getOffset(),this.name.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Prüft, ob zwei Objekte gleich sind. NICHT INSTANZGLEICH
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
//Da die Namensgebung von Typeplaceholdern und FreshWildcards identisch ist,
|
||||
//und im Type nur auf Namen geprüft wird muss verhindert werden, dass ausversehen True zurückgegeben wird,
|
||||
//Wenn eine FreshWildcard mit einem TypePlaceholder verglichen wird.
|
||||
return (obj instanceof FreshWildcardType) && super.equals(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt einen neuen Namen, und gibt diesen zurück
|
||||
* Methode aus TypePlaceholder kopiert
|
||||
*/
|
||||
private static JavaClassName makeNewName()
|
||||
{
|
||||
// luar: Methode aus TypePlaceholder kopiert.
|
||||
String strReturn = strNextName;
|
||||
|
||||
// n�chster Name berechnen und in strNextName speichern
|
||||
inc( strNextName.length() - 1 );
|
||||
|
||||
return new JavaClassName(strReturn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hilfsmethode für makeNewName
|
||||
* Methode aus TypePlaceholder kopiert
|
||||
*/
|
||||
private static void inc(int i)
|
||||
{
|
||||
// luar: Methode aus TypePlaceholder kopiert.
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hilfsmethode für makeNewName
|
||||
* Methode aus TypePlaceholder kopiert
|
||||
*/
|
||||
private static void manipulate( int nStelle, char nWert )
|
||||
{
|
||||
// luar: Methode aus TypePlaceholder kopiert.
|
||||
String strTemp = "";
|
||||
for( int i = 0; i < strNextName.length(); i++)
|
||||
{
|
||||
if ( i == nStelle )
|
||||
strTemp = strTemp + nWert;
|
||||
else
|
||||
strTemp = strTemp + strNextName.charAt( i );
|
||||
}
|
||||
strNextName = strTemp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt die passende WildcardType Klasse zurück.
|
||||
* Wird für smaller4 verwendet
|
||||
*/
|
||||
public WildcardType get_WildcardType()
|
||||
{
|
||||
return new WildcardType(null, this.getParent(),this.getOffset());
|
||||
}
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt den Menge der oberen Grenzen zurück
|
||||
*/
|
||||
public Menge<Type> get_UpperBounds()
|
||||
{
|
||||
return this.upperBounds;
|
||||
}
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Setzt den Menge der oberen Grenzen
|
||||
*/
|
||||
public void set_UpperBounds(Menge<Type> bounds)
|
||||
{
|
||||
this.upperBounds = bounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.apache.bcel.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
// TODO: Bytecode
|
||||
return null;
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ public class FunN extends RefType {
|
||||
* @return
|
||||
*/
|
||||
public FunN(Type R, List<? extends Type> T) {
|
||||
super("",null,0);
|
||||
super("",0);
|
||||
if(T==null || R == null)throw new NullPointerException();
|
||||
setT(T);
|
||||
setR(R);
|
||||
@ -52,7 +52,7 @@ public class FunN extends RefType {
|
||||
* Spezieller Konstruktor um eine FunN ohne Returntype zu generieren
|
||||
*/
|
||||
protected FunN(List<? extends Type> list){
|
||||
super("",null,0);
|
||||
super("",0);
|
||||
if(list==null)throw new NullPointerException();
|
||||
setT(list);
|
||||
this.name = new JavaClassName("Fun"+list.size());//getName();
|
||||
@ -65,7 +65,7 @@ public class FunN extends RefType {
|
||||
* @param parameterCount
|
||||
*/
|
||||
public FunN(int parameterCount) {
|
||||
super("",null,0);
|
||||
super("",0);
|
||||
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++){
|
||||
|
@ -61,11 +61,11 @@ public class GenericTypeVar extends ObjectType
|
||||
*/
|
||||
|
||||
// ino.method.GenericTypeVar.26509.definition
|
||||
public GenericTypeVar(String s, SyntaxTreeNode parentClass, int offset)
|
||||
public GenericTypeVar(String s, int offset)
|
||||
// ino.end
|
||||
// ino.method.GenericTypeVar.26509.body
|
||||
{
|
||||
super(parentClass,offset);
|
||||
super(s,offset);
|
||||
this.name = new JavaClassName(s);
|
||||
}
|
||||
// ino.end
|
||||
@ -86,7 +86,7 @@ public class GenericTypeVar extends ObjectType
|
||||
// ino.end
|
||||
// ino.method.clone.26512.body
|
||||
{
|
||||
return new GenericTypeVar(this.getName().toString(), this.getParentClass(), getOffset());
|
||||
return new GenericTypeVar(this.getName().toString(), getOffset());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,11 +9,8 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
*/
|
||||
public abstract class ObjectType extends Type {
|
||||
|
||||
public ObjectType(String s, SyntaxTreeNode parent, int offset) {
|
||||
super(s, parent, offset);
|
||||
}
|
||||
public ObjectType(SyntaxTreeNode parent, int offset) {
|
||||
super(parent, offset);
|
||||
public ObjectType(String s, int offset) {
|
||||
super(s, offset);
|
||||
}
|
||||
public abstract ObjectType clone();
|
||||
}
|
||||
|
@ -45,47 +45,20 @@ public class RefType extends ObjectType implements IMatchable
|
||||
*/
|
||||
private boolean IsArray = false;
|
||||
|
||||
// ino.attribute.parameter.26625.declaration
|
||||
private List<Type> parameter = null;
|
||||
// ino.end
|
||||
// ino.attribute.primitiveFlag.29412.decldescription type=javadoc
|
||||
/**
|
||||
* Ist primitiveFlag auf true, muss beim Codegen dieser Reftype durch
|
||||
* den primitiven Datentyp ersetzt werden
|
||||
*
|
||||
* Bsp: java.lang.Integer mit Flag wird dann zu [int]
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.primitiveFlag.29412.declaration
|
||||
private boolean primitiveFlag=false;
|
||||
// ino.end
|
||||
// ino.attribute.parserlog.26628.declaration
|
||||
//protected static Logger parserlog = Logger.getLogger("parser");
|
||||
// ino.end
|
||||
// ino.attribute.codegenlog.26631.declaration
|
||||
//protected static Logger codegenlog = Logger.getLogger("codegen");
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.RefType.26634.definition
|
||||
protected RefType(SyntaxTreeNode parent, int offset)
|
||||
// ino.end
|
||||
// ino.method.RefType.26634.body
|
||||
{
|
||||
super(parent,offset);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.RefType.26637.definition
|
||||
public RefType(String fullyQualifiedName, int offset)
|
||||
// ino.end
|
||||
// ino.method.RefType.26637.body
|
||||
{
|
||||
super(parent,offset);
|
||||
super(fullyQualifiedName,offset);
|
||||
this.setName(fullyQualifiedName);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@ -100,7 +73,7 @@ public class RefType extends ObjectType implements IMatchable
|
||||
// ino.end
|
||||
// ino.method.RefType.26640.body
|
||||
{
|
||||
super(parent,offset);
|
||||
super(fullyQualifiedName,offset);
|
||||
this.setName(fullyQualifiedName);
|
||||
if(parameter != null && parameter.size()>0)this.set_ParaList(parameter);
|
||||
}
|
||||
@ -111,28 +84,17 @@ public class RefType extends ObjectType implements IMatchable
|
||||
// ino.end
|
||||
// ino.method.RefType.26643.body
|
||||
{
|
||||
super(parent,offset);
|
||||
super(R.name.toString(),offset);
|
||||
// otth: Copy-Konstruktor
|
||||
this.setName(R.getTypeName());
|
||||
this.set_ParaList(R.getParaList());
|
||||
}
|
||||
// ino.end
|
||||
|
||||
/**
|
||||
* Erstellt einen Referenztyp aus dem übergebenen Type.
|
||||
* Dabei wird der Name und der Offset des baseType's übernommen.
|
||||
* @param baseType
|
||||
*/
|
||||
public RefType( Type baseType){
|
||||
super(baseType.getParent(),baseType.getOffset());
|
||||
this.setName(baseType.name.toString());
|
||||
//this.parameter = null;
|
||||
public RefType(JavaClassName name, List<Type> parameter, int offset){
|
||||
super(name.toString(), offset);
|
||||
}
|
||||
|
||||
public RefType(JavaClassName jName, SyntaxTreeNode parent, int offset) {
|
||||
this(jName.toString(), parent, offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wandelt die Parameter des RefTypes in TPHs um, sofern es sich um Generische Variablen handelt.
|
||||
@ -356,7 +318,7 @@ public class RefType extends ObjectType implements IMatchable
|
||||
return newRefType;
|
||||
}
|
||||
else {
|
||||
RefType newRefType = new RefType(this.getTypeName(), null,getOffset());
|
||||
RefType newRefType = new RefType(this.getTypeName(),getOffset());
|
||||
newRefType.setPrimitiveFlag(this.getPrimitiveFlag());
|
||||
newRefType.IsArray = this.IsArray;
|
||||
return newRefType;
|
||||
@ -412,15 +374,10 @@ public class RefType extends ObjectType implements IMatchable
|
||||
* p.ex. de.dhbwstuttgart.typeinference.Menge => Menge
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.getSimpleName.26697.definition
|
||||
public String getSimpleName()
|
||||
// ino.end
|
||||
// ino.method.getSimpleName.26697.body
|
||||
{
|
||||
return UsedId.createFromQualifiedName(getTypeName(),getOffset()).getSimpleName();
|
||||
return name.getName();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
// ino.method.setPrimitiveFlag.29415.definition
|
||||
|
@ -30,7 +30,7 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I
|
||||
*/
|
||||
public SuperWildcardType(int offset, ObjectType innerType)
|
||||
{
|
||||
super(innerType, innerType.getParent(),offset);
|
||||
super(innerType, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,17 +63,6 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I
|
||||
return new SuperWildcardType(getOffset(), (ObjectType) innerType.clone());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt die passende FreshWildcardType Klasse zurück.
|
||||
* Wird für CaptureConversion verwendet
|
||||
*/
|
||||
public FreshSuperWildcardType GetFreshWildcardType()
|
||||
{
|
||||
return new FreshSuperWildcardType(this.innerType,this.getParent(),-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Das gleiche wie get_innerType().
|
||||
|
@ -9,7 +9,6 @@ import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
@ -24,37 +23,22 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
|
||||
// ino.end
|
||||
// ino.class.Type.26716.body
|
||||
{
|
||||
// ino.attribute.name.26720.declaration
|
||||
protected JavaClassName name;
|
||||
// ino.end
|
||||
// ino.attribute.used.26723.declaration
|
||||
protected UsedId used;
|
||||
// ino.end
|
||||
// ino.attribute.offset.26726.declaration
|
||||
private int offset;
|
||||
// ino.end
|
||||
|
||||
// ino.method.Type.26729.definition
|
||||
public Type(String s, SyntaxTreeNode parent, int offset)
|
||||
// ino.end
|
||||
// ino.method.Type.26729.body
|
||||
public Type(String s, int offset)
|
||||
{
|
||||
this(parent, offset);
|
||||
this.offset = offset;
|
||||
this.name = new JavaClassName(s);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.Type.26732.definition
|
||||
protected Type(SyntaxTreeNode parent,int offset)
|
||||
// ino.end
|
||||
// ino.method.Type.26732.body
|
||||
|
||||
public Type(JavaClassName s, int offset)
|
||||
{
|
||||
//if(parent == null)throw new NullPointerException();
|
||||
//if(parent == null)throw new DebugException("Parent darf nicht null sein");
|
||||
this.parent = parent;
|
||||
this.offset=offset;
|
||||
this.offset = offset;
|
||||
this.name = s;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.getOffset.26735.definition
|
||||
public int getOffset()
|
||||
@ -79,34 +63,12 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.set_UsedId.26741.definition
|
||||
public void set_UsedId( UsedId uid)
|
||||
// ino.end
|
||||
// ino.method.set_UsedId.26741.body
|
||||
{
|
||||
this.used = uid;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.get_UsedId.26744.definition
|
||||
public UsedId get_UsedId()
|
||||
// ino.end
|
||||
// ino.method.get_UsedId.26744.body
|
||||
{
|
||||
return this.used;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.get_Name.26747.definition
|
||||
public String get_Name()
|
||||
// ino.end
|
||||
// ino.method.get_Name.26747.body
|
||||
{
|
||||
return used.name.toString();
|
||||
return name.toString();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@ -227,7 +189,7 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
|
||||
// ino.end
|
||||
// ino.method.getSimpleName.26777.body
|
||||
{
|
||||
return UsedId.createFromQualifiedName(getName().toString(),getOffset()).getSimpleName();
|
||||
return name.getName();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
@ -53,20 +53,15 @@ public class TypePlaceholder extends ObjectType
|
||||
return this;
|
||||
}
|
||||
|
||||
// ino.method.TypePlaceholder.26794.defdescription type=javadoc
|
||||
/**
|
||||
* Privater Konstruktor - Eine TypePlaceholder-Variable wird �ber die
|
||||
* Factory-Methode <code>fresh()</code> erzeugt.
|
||||
* <br>Author: J�rg B�uerle
|
||||
* @param typeName Der Name der TypePlaceholder-Variablen
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.TypePlaceholder.26794.definition
|
||||
private TypePlaceholder(String typeName, SyntaxTreeNode parent)
|
||||
// ino.end
|
||||
// ino.method.TypePlaceholder.26794.body
|
||||
{
|
||||
super(parent, -1);
|
||||
super(typeName, -1);
|
||||
if(typeName == null)throw new NullPointerException();
|
||||
this.name = new JavaClassName(typeName);
|
||||
if(parent != null)log.debug("Erstelle TPH "+typeName+" für SyntaxTreeNode: "+parent, Section.TYPEINFERENCE);
|
||||
|
@ -21,7 +21,7 @@ public class Void extends RefType
|
||||
// ino.end
|
||||
// ino.method.Void.26861.body
|
||||
{
|
||||
super(offset);
|
||||
super("void",offset);
|
||||
super.setName(VOID_NAME);
|
||||
}
|
||||
// ino.end
|
||||
@ -68,7 +68,7 @@ public class Void extends RefType
|
||||
// ino.end
|
||||
// ino.method.clone.26867.body
|
||||
{
|
||||
return new Void(this.getParent(),getOffset());
|
||||
return new Void(getOffset());
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
@ -18,7 +18,7 @@ import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
*
|
||||
*/
|
||||
|
||||
public class WildcardType extends Type{
|
||||
public abstract class WildcardType extends Type{
|
||||
|
||||
protected ObjectType innerType = null;
|
||||
|
||||
@ -26,9 +26,9 @@ public class WildcardType extends Type{
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Standard Konstruktor für eine Wildcard
|
||||
*/
|
||||
public WildcardType(ObjectType innerType, SyntaxTreeNode parent, int offset)
|
||||
public WildcardType(ObjectType innerType, int offset)
|
||||
{
|
||||
super(parent, offset);
|
||||
super(innerType.name, offset);
|
||||
this.innerType = innerType;
|
||||
}
|
||||
|
||||
@ -41,24 +41,6 @@ public class WildcardType extends Type{
|
||||
return "?";
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt einen Klon der Wildcard zurück.
|
||||
*/
|
||||
public WildcardType clone()
|
||||
{
|
||||
return new WildcardType(this.innerType, this.getParent(), getOffset());
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
* Gibt die passende FreshWildcardType Klasse zurück.
|
||||
* Wird für CaptureConversion verwendet
|
||||
*/
|
||||
public FreshWildcardType GetFreshWildcardType()
|
||||
{
|
||||
return new FreshWildcardType(this.getParent(),-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Arne Lüdtke<br/>
|
||||
|
@ -26,7 +26,7 @@ public class ConstructorAssumption extends MethodAssumption{
|
||||
|
||||
@Override
|
||||
public Type getAssumedType() {
|
||||
return new Void(this.method, this.method.getOffset());
|
||||
return new Void(this.method.getOffset());
|
||||
//throw new DebugException("Eine ConstructorAssumption hat keinen Typ bzw. er ist nicht relevant");
|
||||
//return this.getMethod().getParentClass().getType();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class MethodAssumption extends FieldAssumption {
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return this.method.get_Method_Name();
|
||||
return this.method.get_Name();
|
||||
}
|
||||
|
||||
public int getParaCount(){
|
||||
|
@ -250,89 +250,6 @@ public class TypeAssumptions {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kontrolliert den vom Parser gesetzten Typ.
|
||||
* Erweitert dessen Bezeichnung, wenn nötig.
|
||||
* @param t
|
||||
* @return null, falls der Typ nicht vorhanden ist.
|
||||
*/
|
||||
public Type getTypeFor(Type t, SyntaxTreeNode inNode){
|
||||
//Alle bekannten Klassen nach diesem Typ durchsuchen:
|
||||
JavaClassName typName = t.getName();
|
||||
for(ClassAssumption ass : this.classAssumptions){
|
||||
JavaClassName name = ass.getAssumedClass().getName(); //Das kann auch de.dhbwstuttgart.typeinference.Menge sein
|
||||
boolean match = true;
|
||||
match = name.equals(typName);
|
||||
if(match && t instanceof RefType){
|
||||
RefType tr = (RefType)t;
|
||||
RefType ret = ass.getAssumedClass().getType(); //Dadurch erhält der RefType den vollen Namen (bsp. java.lang.Integer)
|
||||
ret.setArray(((RefType) t).IsArray());
|
||||
//Falls der RefType mit Parametern angegeben wurde, so müssen diese erhalten bleiben:
|
||||
if(tr.get_ParaList()!=null && tr.getParaList().size()>0){
|
||||
ret.set_ParaList(tr.getParaList());
|
||||
}
|
||||
|
||||
//Der RefType muss zusätzlich seine Parameter prüfen.
|
||||
Menge<Type> parameterList = new Menge<>();
|
||||
if(ret.get_ParaList()!=null)for(Type param : ret.get_ParaList()){
|
||||
Type ct = param.TYPE(this, inNode);
|
||||
parameterList.add(ct);
|
||||
}
|
||||
ret.set_ParaList(parameterList);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
//Auch die generischen Variablen durchsuchen:
|
||||
for(GenericVarAssumption ass : this.genericVarAssumptions){
|
||||
//if(ass.inheritsType(t))return t;
|
||||
if(ass.getIdentifier().equals(t.getName())){
|
||||
//Generische Variable gefunden!
|
||||
//Erkennen, ob sich inNode im gleichen Kontext wie die GTV aus den Assumptions befindet.
|
||||
boolean sameContext = true;
|
||||
//Der GTV-Kontext der einzusetzenden GTV
|
||||
GTVDeclarationContext gtvDeclNode = ass.getAssumedType().getDeclarationContext();
|
||||
//Der GTV-Kontext von inNOde
|
||||
GTVDeclarationContext gtvNode = inNode.getGTVDeclarationContext();
|
||||
//Ãberprüfungen (siehe Dokumentation):
|
||||
if(gtvDeclNode.isClass()){ //GTV wurde in Klasse definiert
|
||||
if(! gtvNode.getParentClass().equals(gtvDeclNode))sameContext = false;
|
||||
}else{ //GTV wurde in Methode oder Feld definiert:
|
||||
if(! gtvNode.equals(gtvDeclNode))sameContext = false;
|
||||
}
|
||||
|
||||
if(sameContext){
|
||||
TypeAssumptions.log.debug(t+" ist in Klasse: "+ass.getAssumedType().getParentClass(), Section.ASSUMPTIONS);
|
||||
return ass.getAssumedType();
|
||||
}else{
|
||||
TypeAssumptions.log.debug(t+" ist NICHT in Klasse: "+ass.getAssumedType().getParentClass(), Section.ASSUMPTIONS);
|
||||
//Ist die Generische Variable nicht aus dieser Klasse, so muss sie zu einem TPH umgewandelt werden:
|
||||
return ass.getAssumedType().getTypePlaceHolder(inNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(t.getName() == null)throw new DebugException(t.toString());
|
||||
//Spezialfälle bei char, int, boolean, ....
|
||||
String name = t.getName().toString();
|
||||
switch(name){
|
||||
case "int":
|
||||
return new RefType("java.lang.Integer",t.getParent(),t.getOffset());
|
||||
case "boolean":
|
||||
return new RefType("java.lang.Boolean",t.getParent(),t.getOffset());
|
||||
case "double":
|
||||
return new RefType("java.lang.Double",t.getParent(),t.getOffset());
|
||||
case "float":
|
||||
return new RefType("java.lang.Float",t.getParent(),t.getOffset());
|
||||
case "long":
|
||||
return new RefType("java.lang.Long",t.getParent(),t.getOffset());
|
||||
case "char":
|
||||
return new RefType("java.lang.Character",t.getParent(),t.getOffset());
|
||||
}
|
||||
|
||||
throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt eine TypAssumption an.
|
||||
* Dadurch wird ein Pool von Typen aufgebaut, welche überhaupt erlaubt sind.
|
||||
@ -381,12 +298,6 @@ public class TypeAssumptions {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Type checkType(RefType type, SyntaxTreeNode parent) {
|
||||
Type t = this.getTypeFor(type, parent); //Richtigkeit des Typnahmensprüfen
|
||||
type.setName(t.getName()); //Und diesen auf den Typ anwenden
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft einen Typ auf das vorhandensein in den BasicAssumptions.
|
||||
* Dabei werden alle Konstruktoren nach diesem Typ durchsucht. Denn jede Klasse hat einen Konstruktor und der muss in den TypeAssumptions vorhanden sein.
|
||||
|
Loading…
Reference in New Issue
Block a user