Aufrömen

This commit is contained in:
JanUlrich 2016-12-21 15:06:55 +01:00
parent ddbcc5ee6e
commit 3b6363d71a
12 changed files with 98 additions and 157 deletions

View File

@ -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,6 +41,10 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
protected boolean isInterface;
private List<RefType> implementedInterfaces;
public Class(JavaClassName name, GenericDeclarationList genericDeclarations, List<Method> methode, List<Field> felder, int offset) {
super(offset);
}
/////////////////////////////////////////////////////////////////////////
// TypeReconstructionAlgorithmus
/////////////////////////////////////////////////////////////////////////
@ -72,12 +77,6 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
ConstraintsSet oderConstraints = new ConstraintsSet();
for(Type gparam : this.get_ParaList()){
if(gparam instanceof GenericTypeVar)assumptions.add(((GenericTypeVar)gparam).createAssumptions()); //Constraints ¼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 ¼r die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen
}
typinferenzLog.debug("Erstellte Assumptions: "+assumptions, Section.TYPEINFERENCE);
@ -214,6 +213,11 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
return this.genericClassParameters;
}
@Override
public List<? extends SyntaxTreeNode> getChildren() {
throw new NotImplementedException();
}
@Override
public String getDescription(){
return "class "+this.getName();

View File

@ -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;
@ -48,7 +48,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
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<? extends SyntaxTreeNode> getChildren() {
return null;
}
@Override
public String getDescription(){
String ret = "";

View File

@ -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<G
return getEndOffset();
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
return null;
}
@Override
public Iterator<GenericTypeVar> iterator() {
return this.gtvs.iterator();

View File

@ -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<RefType> bounds=new ArrayList<RefType>();
private int endOffset;
private String name;
private GenericTypeName name;
public GenericTypeVar(String s, List<RefType> bounds, int offset, int endOffset)
public GenericTypeVar(GenericTypeName s, List<RefType> 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);
}
}

View File

@ -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<String> types_in_parameterlist = new Menge<String>();
@ -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;
}
/**
* <br>
* Author: Jrg Buerle
*
* @return
*/
public int getTypeLineNumber()
{
return this.getLineNumber();
}
/**
* <br/>
* Author: Martin Pl�micke
@ -186,15 +120,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,13 +249,9 @@ 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();
@ -344,17 +265,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
short constants = Constants.ACC_PUBLIC;
if (this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
Type returnType = this.getType();
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
argumentNames.toArray(new String[parameterlist.size()]), this.getName(),
parentClass.name.toString(), il, _cp);
cg.setMethodeGenerator(method);
@ -367,4 +283,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
argumentNames.add(parameter.getIdentifier());
}
}
public String getName() {
return name;
}
}

View File

@ -120,7 +120,7 @@ public class ASTFactory {
Block block = new Block(new ArrayList<Statement>(), -1);
List<GenericTypeVar> 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<RefType> 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);
}

View File

@ -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<RefType>(), true, offset);
}
}

View File

@ -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("[.]");

View File

@ -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();
/**

View File

@ -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();
}

View File

@ -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 ¯Â¿Â½rg ¯Â¿Â½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 ¼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<TypePlaceholder> ofType){
public RefType getTypeOfPlaceholder(TypePlaceholder tph, Menge<TypePlaceholder> ofType){
return this.getUnifiedConstraints().getTypeEqualTo(tph, ofType);
}

View File

@ -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;
}