From 3b6363d71a9cc83db851d332e00987b16e57e6a7 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 21 Dec 2016 15:06:55 +0100 Subject: [PATCH] =?UTF-8?q?Aufr=C3=B6men?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/syntaxtree/Class.java | 22 +-- .../syntaxtree/FormalParameter.java | 19 ++- .../syntaxtree/GenericDeclarationList.java | 9 +- .../syntaxtree/GenericTypeVar.java | 19 ++- src/de/dhbwstuttgart/syntaxtree/Method.java | 132 ++++-------------- .../syntaxtree/factory/ASTFactory.java | 14 +- .../syntaxtree/type/GenericType.java | 11 ++ .../typecheck/JavaClassName.java | 2 +- .../typeinference/TypeInsertable.java | 1 - .../dhbwstuttgart/typeinference/Typeable.java | 4 +- .../typeinference/TypeinferenceResultSet.java | 15 +- .../typedeployment/TypeInsertPoint.java | 7 +- 12 files changed, 98 insertions(+), 157 deletions(-) create mode 100644 src/de/dhbwstuttgart/syntaxtree/type/GenericType.java diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 5ad5122c3..4914cb855 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -13,6 +13,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.*; import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import java.util.ArrayList; import java.util.List; @@ -40,7 +41,11 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen protected boolean isInterface; private List implementedInterfaces; - ///////////////////////////////////////////////////////////////////////// + public Class(JavaClassName name, GenericDeclarationList genericDeclarations, List methode, List felder, int offset) { + super(offset); + } + + ///////////////////////////////////////////////////////////////////////// // TypeReconstructionAlgorithmus ///////////////////////////////////////////////////////////////////////// /** @@ -71,13 +76,7 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen assumptions.add(globalAssumptions); ConstraintsSet oderConstraints = new ConstraintsSet(); - - for(Type gparam : this.get_ParaList()){ - if(gparam instanceof GenericTypeVar)assumptions.add(((GenericTypeVar)gparam).createAssumptions()); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen - } - for(Type gparam : this.get_ParaList()){ - if(gparam instanceof GenericTypeVar)oderConstraints.add(((GenericTypeVar)gparam).TYPE(assumptions)); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen - } + typinferenzLog.debug("Erstellte Assumptions: "+assumptions, Section.TYPEINFERENCE); @@ -213,7 +212,12 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen public GenericDeclarationList getGenericParameter() { return this.genericClassParameters; } - + + @Override + public List getChildren() { + throw new NotImplementedException(); + } + @Override public String getDescription(){ return "class "+this.getName(); diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index a56767b45..93636ad11 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.syntaxtree; +import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.typeinference.Menge; import java.util.List; @@ -7,7 +8,6 @@ import java.util.List; import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; -import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; @@ -21,11 +21,11 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeInsertable { - private Type type; + private RefType type; private String name; protected static Logger inferencelog = Logger.getLogger("inference"); - public FormalParameter(String name, Type type, int offset){ + public FormalParameter(String name, RefType type, int offset){ super(offset); this.name = name; this.type = type; @@ -42,13 +42,13 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns } return true; } - - public String getIdentifier() + + public String getIdentifier() { return name; } - public Type getType() + public RefType getType() { return type; } @@ -74,10 +74,15 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph, ResultSet resultSet) { if(this.getOffset()<=0)return null; - Type t = resultSet.getTypeEqualTo(tph); + RefType t = resultSet.getTypeEqualTo(tph); return new TypeInsertPoint(this, this, t, resultSet); } + @Override + public List getChildren() { + return null; + } + @Override public String getDescription(){ String ret = ""; diff --git a/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java b/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java index c70663c3a..8504f225a 100644 --- a/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java +++ b/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java @@ -4,9 +4,11 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; + +import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Menge; -import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; +import de.dhbwstuttgart.typeinference.ResultSet; /** * Stellt eine Deklarations-Liste von Generischen Variablen dar. @@ -34,6 +36,11 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable iterator() { return this.gtvs.iterator(); diff --git a/src/de/dhbwstuttgart/syntaxtree/GenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/GenericTypeVar.java index a1ecd49c2..8ec0dad77 100755 --- a/src/de/dhbwstuttgart/syntaxtree/GenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/GenericTypeVar.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.syntaxtree; import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.typecheck.JavaClassName; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.ResultSet; @@ -26,9 +27,9 @@ public class GenericTypeVar extends SyntaxTreeNode */ List bounds=new ArrayList(); private int endOffset; - private String name; + private GenericTypeName name; - public GenericTypeVar(String s, List bounds, int offset, int endOffset) + public GenericTypeVar(GenericTypeName s, List bounds, int offset, int endOffset) { super(offset); name = s; @@ -66,7 +67,19 @@ public class GenericTypeVar extends SyntaxTreeNode throw new NotImplementedException(); } - public String getName() { + public GenericTypeName getName() { return name; } } + +public class GenericTypeName{ + private final String simpleName; + + public GenericTypeName(JavaClassName inClass, String name){ + this.simpleName = name; + } + + public GenericTypeName(JavaClassName inClass, String inField, String name){ + this(inClass, name); + } +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 638c095ab..e950def78 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -1,9 +1,11 @@ // ino.module.Method.8564.package package de.dhbwstuttgart.syntaxtree; +import java.sql.Ref; import java.util.ArrayList; import java.util.List; +import de.dhbwstuttgart.syntaxtree.type.RefType; import org.apache.bcel.Constants; import org.apache.bcel.generic.InstructionList; @@ -19,8 +21,6 @@ import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; import de.dhbwstuttgart.syntaxtree.modifier.Static; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Statement; -import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; -import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; @@ -45,7 +45,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable private Block block; public ParameterList parameterlist = new ParameterList(); private ExceptionList exceptionlist; - private Type returntype; + private RefType returntype; private String name; private Menge types_in_parameterlist = new Menge(); @@ -62,17 +62,17 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable * @param block - use null to create abstract method * @param offset */ - public Method(String name, Type returnType, ParameterList params, Block block, int offset) { + public Method(String name, RefType returnType, ParameterList params, Block block, int offset) { this(name, returnType, params, new ExceptionList(), block, offset); } - public Method(String name, Type returnType, ParameterList params, ExceptionList exceptions, Block block, int offset){ + public Method(String name, RefType returnType, ParameterList params, ExceptionList exceptions, Block block, int offset){ super(name, generateMethodType(returnType, params), offset); } - public Method(String name, Type returnType, ParameterList parameterList, Block block, + public Method(String name, RefType returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, int offset) { - this(offset); + super(offset); this.name = name; this.parameterlist = parameterList; this.block = block; @@ -80,15 +80,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable this.returntype = returnType; } - public JavaClassName getTypeName() - { - if (this.getType() == null) - return null; - else - return this.getType().getName(); - } - - public Block get_Block() { return block; @@ -118,63 +109,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return this.exceptionlist; } - public int getOverloadedID() - { - return (overloadedID); - } - - - public void setOverloadedID(int overloadedID) - { - this.overloadedID = overloadedID; - } - - public String get_Name() - { - return name; - } - - public Menge get_Type_Paralist() - { - return types_in_parameterlist; - } - - public int getLineNumber() - { - return m_LineNumber; - } - - public void setLineNumber(int lineNumber) - { - m_LineNumber = lineNumber; - } - - public int getOffset() - { - return m_Offset; - } - - public int getVariableLength() - { - return get_Name().length(); - } - - public void setOffset(int Offset) - { - m_Offset = Offset; - } - - /** - *
- * Author: Jrg Buerle - * - * @return - */ - public int getTypeLineNumber() - { - return this.getLineNumber(); - } - /** *
* Author: Martin Pl�micke @@ -185,15 +119,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable { return this.getType() + " " + this.get_Name() + ((block != null) ? block.toString() : ""); } - - /** - * Legt fuer die ByteCodeGen fest, ob Bytecode innerhalb der Methode - * generiert wird. - */ - public void setAbstract(boolean b) - { - isAbstract = b; - } /** * Gibt zurueck, ob ByteCode innerhabl der Methode generiert wird. @@ -279,7 +204,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable * Der Typ einer Methode ist ihr Returntype */ @Override - public Type getType() { + public RefType getType() { // Methode und Block teilen sich einen ReturnType: return this.returntype; } @@ -324,40 +249,31 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable addMethodToClassGenerator(cg, _factory, t, classObj); } } -<<<<<<< HEAD private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t, Class parentClass) { -======= - - private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { ->>>>>>> refactoring + DHBWConstantPoolGen _cp = cg.getConstantPool(); InstructionList il = new InstructionList(); - + ArrayList argumentTypes = new ArrayList(); ArrayList argumentNames = new ArrayList(); - - if(this.parameterlist != null && this.parameterlist.size() > 0){ + + if (this.parameterlist != null && this.parameterlist.size() > 0) { generateArgumentList(argumentTypes, argumentNames, cg, t); } - + short constants = Constants.ACC_PUBLIC; - if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; - - Type returnType = this.getType(); - + if (this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; + + RefType returnType = this.getType(); + MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), -<<<<<<< HEAD - argumentTypes.toArray(new org.apache.bcel.generic.Type[parameterlist.size()]) - , argumentNames.toArray(new String[parameterlist.size()]), this.get_Name(), parentClass.name.toString(), il, _cp); -======= - 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); ->>>>>>> refactoring - + argumentTypes.toArray(new org.apache.bcel.generic.Type[parameterlist.size()]), + argumentNames.toArray(new String[parameterlist.size()]), this.getName(), + parentClass.name.toString(), il, _cp); + cg.setMethodeGenerator(method); - + cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t)); } @@ -367,4 +283,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable argumentNames.add(parameter.getIdentifier()); } } + + public String getName() { + return name; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 400fc1e1a..e4812898d 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -120,7 +120,7 @@ public class ASTFactory { Block block = new Block(new ArrayList(), -1); List gtvs = new ArrayList<>(); for(TypeVariable jreTV : jreMethod.getTypeParameters()){ - GenericTypeVar gtv = createGeneric(jreTV, inClass); + GenericTypeVar gtv = createGeneric(jreTV, new GenericTypeName(new JavaClassName(inClass.getName()),jreTV.getName())); gtvs.add(gtv); } GenericDeclarationList gtvDeclarations = new GenericDeclarationList(gtvs,-1); @@ -147,26 +147,18 @@ public class ASTFactory { /** * Erstellt eine GenericTypeVar oder eine BoundedGenericTypeVar - * Um die Variablen korrekt zu generieren, muss die Klasse inClass übergeben werden, in der dieser Generic auftaucht - * TODO: Warum? - * Wird der AST von JREClass erzeugt, so kann davon ausgegangen werden, dass die Generics korrekt sind. - * Unser AST ist immutable und nicht im Kreis verzeigert. Generics die gleich heißen und gleiche Bounds haben, sind auch gleich. Müssen nicht die selben Instanzen sein. * @param jreTypeVar - * @param inClass Die Klasse in der der Typ auftritt * @return */ - public GenericTypeVar createGeneric(TypeVariable jreTypeVar, java.lang.Class inClass){ - //TODO: Bei den Namen der Parameter des Generishen Typs nachschauen, ob er in der Klasse als Generic deklariert wurde - String name = jreTypeVar.getTypeName(); + public GenericTypeVar createGeneric(TypeVariable jreTypeVar, GenericTypeName name){ List genericBounds = new ArrayList<>(); java.lang.reflect.Type[] bounds = jreTypeVar.getBounds(); if(bounds.length > 0){ for(java.lang.reflect.Type bound : bounds){ genericBounds.add(createType(bound)); } - return new BoundedGenericVar(); } - return new GenericTypeVar(); + return new GenericTypeVar(name, genericBounds, -1, -1); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericType.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericType.java new file mode 100644 index 000000000..0e2af88fc --- /dev/null +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericType.java @@ -0,0 +1,11 @@ +package de.dhbwstuttgart.syntaxtree.type; + +import de.dhbwstuttgart.typecheck.JavaClassName; + +import java.util.ArrayList; + +public class GenericType extends RefType{ + public GenericType(JavaClassName fullyQualifiedName, int offset){ + super(fullyQualifiedName, new ArrayList(), true, offset); + } +} diff --git a/src/de/dhbwstuttgart/typecheck/JavaClassName.java b/src/de/dhbwstuttgart/typecheck/JavaClassName.java index f650a9fc1..d62ad06b3 100644 --- a/src/de/dhbwstuttgart/typecheck/JavaClassName.java +++ b/src/de/dhbwstuttgart/typecheck/JavaClassName.java @@ -20,7 +20,7 @@ public class JavaClassName { * TODO: JavaClassName sollten aus den Assumptions generiert werden. * Diese wissen, welche Typen und Typnamen existieren und können direkt auf Korrektheit prüfen. */ - JavaClassName(String name){ + public JavaClassName(String name){ if(name == null)throw new NullPointerException(); String[] names = name.split("[.]"); diff --git a/src/de/dhbwstuttgart/typeinference/TypeInsertable.java b/src/de/dhbwstuttgart/typeinference/TypeInsertable.java index cba61fcea..fc3e5716e 100644 --- a/src/de/dhbwstuttgart/typeinference/TypeInsertable.java +++ b/src/de/dhbwstuttgart/typeinference/TypeInsertable.java @@ -7,7 +7,6 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; public interface TypeInsertable extends Typeable, IItemWithOffset { public int getOffset(); - public void setOffset(int offset); public String getIdentifier(); /** diff --git a/src/de/dhbwstuttgart/typeinference/Typeable.java b/src/de/dhbwstuttgart/typeinference/Typeable.java index ad305b011..a297a6519 100755 --- a/src/de/dhbwstuttgart/typeinference/Typeable.java +++ b/src/de/dhbwstuttgart/typeinference/Typeable.java @@ -1,6 +1,6 @@ package de.dhbwstuttgart.typeinference; -import de.dhbwstuttgart.syntaxtree.type.Type; +import de.dhbwstuttgart.syntaxtree.type.RefType; public interface Typeable { /** @@ -10,5 +10,5 @@ public interface Typeable { * Dadurch bleibt der Syntaxbaum immutable. * @param typ Der Typ der Typable-Expression/Statement */ - Type getType(); + RefType getType(); } diff --git a/src/de/dhbwstuttgart/typeinference/TypeinferenceResultSet.java b/src/de/dhbwstuttgart/typeinference/TypeinferenceResultSet.java index 3059529cc..c332d10c9 100755 --- a/src/de/dhbwstuttgart/typeinference/TypeinferenceResultSet.java +++ b/src/de/dhbwstuttgart/typeinference/TypeinferenceResultSet.java @@ -1,15 +1,6 @@ -// ino.module.CTypeReconstructionResult.8689.package package de.dhbwstuttgart.typeinference; -// ino.end -// ino.module.CTypeReconstructionResult.8689.import -import java.util.Hashtable; -import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; - -import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; -import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -26,8 +17,6 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; * @author J�rg B�uerle * @version $Date: 2013/09/22 20:13:02 $ */ -// ino.end -// ino.class.CTypeReconstructionResult.27238.declaration public class TypeinferenceResultSet { @@ -79,10 +68,10 @@ public class TypeinferenceResultSet * Ermittelt den in diesem ResultSet für den TypePlaceholder tph zugewiesenen Wert. * @author Andreas Stadelmeier, a10023 */ - public Type getTypeOfPlaceholder(TypePlaceholder tph){ + public RefType getTypeOfPlaceholder(TypePlaceholder tph){ return this.getTypeOfPlaceholder(tph,null); } - public Type getTypeOfPlaceholder(TypePlaceholder tph, Menge ofType){ + public RefType getTypeOfPlaceholder(TypePlaceholder tph, Menge ofType){ return this.getUnifiedConstraints().getTypeEqualTo(tph, ofType); } diff --git a/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertPoint.java b/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertPoint.java index 6540249be..1ebe30c28 100644 --- a/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertPoint.java +++ b/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertPoint.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.typedeployment; +import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.core.IItemWithOffset; @@ -21,7 +22,7 @@ import de.dhbwstuttgart.typeinference.exceptions.DebugException; */ public class TypeInsertPoint extends SourcePatchPoint { - public Type type; + public RefType type; private TypeInsertable point; private SyntaxTreeNode node; @@ -33,7 +34,7 @@ public class TypeInsertPoint extends SourcePatchPoint { * @param resultSet * @param generics - die generischen Parameter des einzusetzenden Typs */ - public TypeInsertPoint(TypeInsertable insertPoint, SyntaxTreeNode insertNode, Type insertType, ResultSet resultSet){ + public TypeInsertPoint(TypeInsertable insertPoint, SyntaxTreeNode insertNode, RefType insertType, ResultSet resultSet){ this.point = insertPoint; this.type = insertType; this.resultSet = resultSet; @@ -65,7 +66,7 @@ public class TypeInsertPoint extends SourcePatchPoint { return this.getInsertPoint().getOffset(); } - protected Type getInsertType(){ + protected RefType getInsertType(){ return this.type; }