From 4c4c0d5ada82089e4175cb0aa4e71876816e59a6 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 6 Mar 2017 17:59:01 +0100 Subject: [PATCH] =?UTF-8?q?getConstraints()=20eingef=C3=BChrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 8 +- .../parser/SyntaxTreeGenerator.java | 91 +++++++++++-------- .../syntaxtree/ClassOrInterface.java | 26 +++++- .../syntaxtree/FieldDeclaration.java | 6 +- src/de/dhbwstuttgart/syntaxtree/Method.java | 9 ++ .../dhbwstuttgart/syntaxtree/SourceFile.java | 12 +++ .../syntaxtree/SyntaxTreeNode.java | 2 + .../syntaxtree/operator/DivideOp.java | 14 --- .../syntaxtree/operator/GreaterEquOp.java | 6 -- .../syntaxtree/operator/GreaterOp.java | 4 - .../syntaxtree/operator/LessEquOp.java | 4 - .../syntaxtree/operator/LessOp.java | 4 - .../syntaxtree/operator/ModuloOp.java | 4 - .../syntaxtree/operator/TimesOp.java | 10 -- .../syntaxtree/statement/ArgumentList.java | 2 +- .../syntaxtree/statement/Assign.java | 41 ++++----- .../syntaxtree/statement/Binary.java | 19 ++-- .../syntaxtree/statement/Block.java | 24 ++--- .../syntaxtree/statement/CastExpr.java | 31 +++---- .../syntaxtree/statement/EmptyStmt.java | 11 ++- .../syntaxtree/statement/Expr.java | 11 --- .../syntaxtree/statement/ExprStmt.java | 11 --- .../syntaxtree/statement/Expression.java | 16 +++- .../syntaxtree/statement/ForStmt.java | 27 +++--- .../syntaxtree/statement/IfStmt.java | 24 ++--- .../syntaxtree/statement/InstVar.java | 19 ++-- .../syntaxtree/statement/InstanceOf.java | 28 ++---- .../statement/LambdaExpression.java | 11 ++- .../syntaxtree/statement/LocalOrFieldVar.java | 31 +++++++ .../statement/LocalOrFieldVarOrClassname.java | 32 +++---- .../statement/LocalVarBunchDeclaration.java | 12 ++- .../syntaxtree/statement/LocalVarDecl.java | 10 ++ .../syntaxtree/statement/MethodCall.java | 44 ++++----- .../syntaxtree/statement/NegativeExpr.java | 17 +--- .../syntaxtree/statement/NewArray.java | 11 ++- .../syntaxtree/statement/NewClass.java | 14 ++- .../syntaxtree/statement/NotExpr.java | 24 +---- .../syntaxtree/statement/PositivExpr.java | 29 +----- .../syntaxtree/statement/PostDecExpr.java | 12 +-- .../syntaxtree/statement/PostIncExpr.java | 23 ++--- .../syntaxtree/statement/PreDecExpr.java | 13 --- .../syntaxtree/statement/PreIncExpr.java | 15 --- .../syntaxtree/statement/Receiver.java | 18 +++- .../syntaxtree/statement/Return.java | 26 +++--- .../syntaxtree/statement/Statement.java | 11 ++- .../syntaxtree/statement/Super.java | 10 ++ .../syntaxtree/statement/This.java | 12 ++- .../syntaxtree/statement/UnaryExpr.java | 4 +- .../syntaxtree/statement/UnaryMinus.java | 2 +- .../syntaxtree/statement/UnaryPlus.java | 17 +++- .../syntaxtree/statement/WhileStmt.java | 26 +++--- .../syntaxtree/statement/literal/Literal.java | 6 ++ .../typeinference/ConstraintSet.java | 11 +++ .../typeinference/EinzelElement.java | 39 ++++++++ .../typeinference/KomplexeMenge.java | 8 ++ .../typeinference/OderConstraint.java | 69 ++++++++++++++ .../typeinference/OderMenge.java | 28 ++++++ .../TypeInferenceInformation.java | 31 +++++++ .../typeinference/UndConstraint.java | 53 +++++++++++ .../dhbwstuttgart/typeinference/UndMenge.java | 44 +++++++++ .../typeinference/unify/Mapping.java | 72 --------------- 61 files changed, 732 insertions(+), 517 deletions(-) delete mode 100755 src/de/dhbwstuttgart/syntaxtree/statement/Expr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java create mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java create mode 100644 src/de/dhbwstuttgart/typeinference/ConstraintSet.java create mode 100644 src/de/dhbwstuttgart/typeinference/EinzelElement.java create mode 100644 src/de/dhbwstuttgart/typeinference/KomplexeMenge.java create mode 100755 src/de/dhbwstuttgart/typeinference/OderConstraint.java create mode 100644 src/de/dhbwstuttgart/typeinference/OderMenge.java create mode 100644 src/de/dhbwstuttgart/typeinference/TypeInferenceInformation.java create mode 100755 src/de/dhbwstuttgart/typeinference/UndConstraint.java create mode 100644 src/de/dhbwstuttgart/typeinference/UndMenge.java delete mode 100644 src/de/dhbwstuttgart/typeinference/unify/Mapping.java diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index ec7b97dc..002428e7 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -2,6 +2,9 @@ package de.dhbwstuttgart.core; import de.dhbwstuttgart.parser.JavaTXParser; import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import java.io.File; import java.io.IOException; @@ -13,7 +16,10 @@ public class JavaTXCompiler { private List sourceFiles = new ArrayList<>(); public void typeInference(){ - + ConstraintSet cons = new ConstraintSet(); + for(SourceFile sf : sourceFiles){ + cons.addAll(sf.getConstraints(new TypeInferenceInformation())); + } } public void parse(File sourceFile) throws IOException, ClassNotFoundException { diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java index 39e9fbf0..a7cf3cef 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java @@ -203,12 +203,28 @@ public class SyntaxTreeGenerator{ JavaClassName name = convert(ctx.Identifier()); Block class_block = null; List fielddecl = convertFields(ctx.classBody()); + List methods = convertMethods(ctx.classBody()); GenericDeclarationList genericClassParameters = null; Token offset = ctx.getStart(); RefTypeOrTPH superClass = null; Boolean isInterface = false; List implementedInterfaces = null; - return new ClassOrInterface(modifiers, name, fielddecl, genericClassParameters, superClass, isInterface, implementedInterfaces, offset); + return new ClassOrInterface(modifiers, name, fielddecl, methods, genericClassParameters, superClass, isInterface, implementedInterfaces, offset); + } + + private List convertMethods(Java8Parser.ClassBodyContext classBodyContext) { + List ret = new ArrayList<>(); + for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){ + if(classMember.classMemberDeclaration() != null){ + Java8Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration(); + if(classMemberDeclarationContext.fieldDeclaration() != null){ + //Do nothing! + }else if(classMemberDeclarationContext.methodDeclaration()!= null){ + ret.add(convert(classMemberDeclarationContext.methodDeclaration())); + } + } + } + return ret; } private List convertFields(Java8Parser.ClassBodyContext classBodyContext) { @@ -219,7 +235,7 @@ public class SyntaxTreeGenerator{ if(classMemberDeclarationContext.fieldDeclaration() != null){ ret.addAll(convert(classMember.classMemberDeclaration().fieldDeclaration())); }else if(classMemberDeclarationContext.methodDeclaration()!= null){ - ret.add(convert(classMemberDeclarationContext.methodDeclaration())); + //Do nothing! } } } @@ -550,7 +566,7 @@ public class SyntaxTreeGenerator{ }else{// if(methodInvocationContext.Identifier() != null){ name = methodInvocationContext.Identifier().getText(); } - Expr receiver; + Expression receiver; if(methodInvocationContext.typeName() != null){ receiver = new LocalOrFieldVarOrClassname(methodInvocationContext.typeName().getText(), methodInvocationContext.typeName().getStart()); }else if(methodInvocationContext.expressionName()!=null){ @@ -566,7 +582,7 @@ public class SyntaxTreeGenerator{ return ret; } - private Expr convert(Java8Parser.ExpressionNameContext expressionNameContext) { + private Expression convert(Java8Parser.ExpressionNameContext expressionNameContext) { /* Der Parser könnte feststellen, ob es sich um einen Klassennamen, eine lokale Variable oder einen Feldzugriff handelt. @@ -583,12 +599,12 @@ public class SyntaxTreeGenerator{ throw new NotImplementedException(); } - private ExprStmt convert(Java8Parser.PreIncrementExpressionContext stmt) { + private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) { //TODO throw new NotImplementedException(); } - private ExprStmt convert(Java8Parser.PreDecrementExpressionContext stmt) { + private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) { //TODO throw new NotImplementedException(); } @@ -603,10 +619,13 @@ public class SyntaxTreeGenerator{ throw new NotImplementedException(); } - private ExprStmt convert(Java8Parser.AssignmentContext stmt) { - //TODO - //return new StatementReturn(new Assign()) - throw new NotImplementedException(); + private Statement convert(Java8Parser.AssignmentContext stmt) { + LocalOrFieldVar leftHandSide = convert(stmt.leftHandSide()); + return new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart()); + } + + private LocalOrFieldVar convert(Java8Parser.LeftHandSideContext leftHandSide) { + return new LocalOrFieldVar(leftHandSide.toString(), leftHandSide.getStart()); } private Statement convert(Java8Parser.IfThenStatementContext stmt){ @@ -775,7 +794,7 @@ public class SyntaxTreeGenerator{ ***************+ Expression Conversions: */ - private Expr convert(Java8Parser.ExpressionContext expression) { + private Expression convert(Java8Parser.ExpressionContext expression) { if(expression.lambdaExpression()!=null){ return convert(expression.lambdaExpression()); }else{ @@ -783,7 +802,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.AssignmentExpressionContext expression) { + private Expression convert(Java8Parser.AssignmentExpressionContext expression) { if(expression.conditionalExpression() != null){ return convert(expression.conditionalExpression()); }else{ @@ -791,7 +810,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.ConditionalExpressionContext expression) { + private Expression convert(Java8Parser.ConditionalExpressionContext expression) { if(expression.conditionalOrExpression() != null){ return convert(expression.conditionalOrExpression()); }else{ @@ -799,7 +818,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.ConditionalOrExpressionContext expression) { + private Expression convert(Java8Parser.ConditionalOrExpressionContext expression) { if(expression.conditionalOrExpression() == null){ return convert(expression.conditionalAndExpression()); }else{ @@ -808,7 +827,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.ConditionalAndExpressionContext expression) { + private Expression convert(Java8Parser.ConditionalAndExpressionContext expression) { if(expression.conditionalAndExpression() == null){ return convert(expression.inclusiveOrExpression()); }else{ @@ -817,7 +836,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.InclusiveOrExpressionContext expression) { + private Expression convert(Java8Parser.InclusiveOrExpressionContext expression) { if(expression.inclusiveOrExpression() == null){ return convert(expression.exclusiveOrExpression()); }else{ @@ -825,7 +844,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.ExclusiveOrExpressionContext expression) { + private Expression convert(Java8Parser.ExclusiveOrExpressionContext expression) { if(expression.exclusiveOrExpression() == null){ return convert(expression.andExpression()); }else{ @@ -833,7 +852,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.AndExpressionContext expression) { + private Expression convert(Java8Parser.AndExpressionContext expression) { if(expression.andExpression() == null){ return convert(expression.equalityExpression()); }else{ @@ -841,7 +860,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.EqualityExpressionContext expression) { + private Expression convert(Java8Parser.EqualityExpressionContext expression) { if(expression.equalityExpression() == null){ return convert(expression.relationalExpression()); }else{ @@ -849,7 +868,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.RelationalExpressionContext expression) { + private Expression convert(Java8Parser.RelationalExpressionContext expression) { if(expression.relationalExpression() == null){ return convert(expression.shiftExpression()); }else{ @@ -857,7 +876,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.ShiftExpressionContext expression) { + private Expression convert(Java8Parser.ShiftExpressionContext expression) { if(expression.shiftExpression() == null){ return convert(expression.additiveExpression()); }else{ @@ -865,7 +884,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.AdditiveExpressionContext expression) { + private Expression convert(Java8Parser.AdditiveExpressionContext expression) { if(expression.additiveExpression() == null){ return convert(expression.multiplicativeExpression()); }else{ @@ -873,7 +892,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.MultiplicativeExpressionContext expression) { + private Expression convert(Java8Parser.MultiplicativeExpressionContext expression) { if(expression.multiplicativeExpression() == null){ return convert(expression.unaryExpression()); }else{ @@ -881,7 +900,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.UnaryExpressionContext expression) { + private Expression convert(Java8Parser.UnaryExpressionContext expression) { if(expression.preIncrementExpression() != null){ return convert(expression.preIncrementExpression()); }else if(expression.preDecrementExpression() != null){ @@ -899,7 +918,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.UnaryExpressionNotPlusMinusContext expression) { + private Expression convert(Java8Parser.UnaryExpressionNotPlusMinusContext expression) { if(expression.postfixExpression() != null){ return convert(expression.postfixExpression()); }else if(expression.castExpression() != null){ @@ -909,12 +928,12 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.CastExpressionContext expressionContext) { + private Expression convert(Java8Parser.CastExpressionContext expressionContext) { throw new NotImplementedException(); } - private Expr convert(Java8Parser.PostfixExpressionContext expression) { - Expr expr; + private Expression convert(Java8Parser.PostfixExpressionContext expression) { + Expression expr; if(expression.primary() != null){ expr = convert(expression.primary()); }else{ @@ -935,8 +954,8 @@ public class SyntaxTreeGenerator{ return expr; } - private Expr convert(Java8Parser.PrimaryContext primary) { - Expr expr; + private Expression convert(Java8Parser.PrimaryContext primary) { + Expression expr; if(primary.primaryNoNewArray_lfno_primary()!=null){ expr = convert(primary.primaryNoNewArray_lfno_primary()); }else{ @@ -951,11 +970,11 @@ public class SyntaxTreeGenerator{ return expr; } - private Expr convert(Java8Parser.ArrayCreationExpressionContext expression) { + private Expression convert(Java8Parser.ArrayCreationExpressionContext expression) { throw new NotImplementedException(); } - private Expr convert(Java8Parser.PrimaryNoNewArray_lfno_primaryContext expression) { + private Expression convert(Java8Parser.PrimaryNoNewArray_lfno_primaryContext expression) { if(expression.literal() != null){ return convert(expression.literal()); }else if(expression.expression()!=null){ @@ -967,7 +986,7 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.LiteralContext literal) { + private Expression convert(Java8Parser.LiteralContext literal) { /*if(literal.IntegerLiteral() != null){ RefType type = new RefType(reg.getName("java.lang.Integer"),literal.getStart()); @@ -1005,14 +1024,14 @@ public class SyntaxTreeGenerator{ } } - private Expr convert(Java8Parser.MethodInvocation_lfno_primaryContext methodInvocationContext) { + private Expression convert(Java8Parser.MethodInvocation_lfno_primaryContext methodInvocationContext) { String name; if(methodInvocationContext.methodName()!=null){ name = methodInvocationContext.methodName().Identifier().getText(); }else{// if(methodInvocationContext.Identifier() != null){ name = methodInvocationContext.Identifier().getText(); } - Expr receiver; + Expression receiver; if(methodInvocationContext.typeName() != null){ receiver = new LocalOrFieldVarOrClassname(methodInvocationContext.typeName().getText(), methodInvocationContext.typeName().getStart()); }else if(methodInvocationContext.expressionName()!=null){ @@ -1026,7 +1045,7 @@ public class SyntaxTreeGenerator{ return ret; } - private static Expr convert(Java8Parser.LambdaExpressionContext expression) { + private static Expression convert(Java8Parser.LambdaExpressionContext expression) { throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index 5806027f..5945628c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -4,9 +4,13 @@ import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.typecheck.JavaClassName; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -15,14 +19,15 @@ import java.util.List; public class ClassOrInterface extends GTVDeclarationContext implements IItemWithOffset, Generic{ protected Modifiers modifiers; protected JavaClassName name; - private List fielddecl = new ArrayList<>(); + private List fields = new ArrayList<>(); + private List methods = new ArrayList<>(); private GenericDeclarationList genericClassParameters; private Token offset; private RefTypeOrTPH superClass; protected boolean isInterface; private List implementedInterfaces; - public ClassOrInterface(Modifiers modifiers, JavaClassName name, List fielddecl, GenericDeclarationList genericClassParameters, + public ClassOrInterface(Modifiers modifiers, JavaClassName name, List fielddecl, List methods, GenericDeclarationList genericClassParameters, RefTypeOrTPH superClass, Boolean isInterface, List implementedInterfaces, Token offset){ super(offset); if(modifiers != null){ @@ -32,7 +37,7 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith this.name = name; } if(fielddecl != null){ - this.fielddecl = fielddecl; + this.fields = fielddecl; } if(genericClassParameters != null){ this.genericClassParameters = genericClassParameters; @@ -45,6 +50,7 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith if(implementedInterfaces != null){ this.implementedInterfaces = implementedInterfaces; } + this.methods = methods; } // Gets class name @@ -56,9 +62,19 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith public Modifiers getModifiers(){ return this.modifiers; } - + public List getFieldDecl(){ - return this.fielddecl; + return this.fields; + } + public List getMethods(){ + return this.methods; } + public ConstraintSet getConstraints(TypeInferenceInformation info) { + ConstraintSet ret = new ConstraintSet(); + for(Method m : this.getMethods()){ + m.getConstraints(info); + } + return ret; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java index aa24508a..ca3059f5 100644 --- a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java +++ b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java @@ -1,9 +1,9 @@ package de.dhbwstuttgart.syntaxtree; import de.dhbwstuttgart.syntaxtree.modifier.fieldModifier.FieldModifier; +import de.dhbwstuttgart.syntaxtree.statement.Expression; import org.antlr.v4.runtime.Token; -import de.dhbwstuttgart.syntaxtree.statement.Expr; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; import java.util.List; @@ -16,13 +16,13 @@ import java.util.List; */ public class FieldDeclaration extends Field{ - private Expr wert; + private Expression wert; /** * Dieser Konstruktor der FieldDeclaration erstellt den Syntaxknoten vollständig. * Kein nachträgliches hinzfügen von Informationen oder aufrufen von parserPostProcessing ist notwendig. */ - public FieldDeclaration(String name, RefTypeOrTPH typ, List modifier, Expr value, Token offset){ + public FieldDeclaration(String name, RefTypeOrTPH typ, List modifier, Expression value, Token offset){ super(name, typ, modifier, offset);//Dieser Deklarator wird nicht vom Parser aufgerufen. Dadurch gibt es auch keinen Offset this.wert = value; } diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 7c9b5ada..a997453d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -6,6 +6,9 @@ import java.util.List; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.syntaxtree.modifier.methodModifier.MethodModifier; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; import de.dhbwstuttgart.core.IItemWithOffset; @@ -38,4 +41,10 @@ public class Method extends Field implements IItemWithOffset this.block = block; } + public ConstraintSet getConstraints(TypeInferenceInformation info) { + ConstraintSet ret = new ConstraintSet(); + info.setMethodContext(this); + ret.addAll(block.getConstraints(info)); + return ret; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 485cdce0..78ba13fa 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -3,7 +3,11 @@ import java.util.*; import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.parser.antlr.Java8Parser; import de.dhbwstuttgart.typecheck.JavaClassName; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; public class SourceFile extends SyntaxTreeNode{ @@ -47,4 +51,12 @@ public class SourceFile extends SyntaxTreeNode{ public List getImports(){ return this.imports; } + + public ConstraintSet getConstraints(TypeInferenceInformation info){ + ConstraintSet ret = new ConstraintSet(); + for(ClassOrInterface cl : this.KlassenVektor){ + ret.addAll(cl.getConstraints(info)); + } + return ret; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java index 21db3b1f..9eb6d5e1 100644 --- a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java +++ b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java @@ -1,9 +1,11 @@ package de.dhbwstuttgart.syntaxtree; +import java.util.ArrayList; import java.util.List; import de.dhbwstuttgart.core.IItemWithOffset; import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.misc.Pair; public abstract class SyntaxTreeNode implements IItemWithOffset{ private final Token offset; diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java index f03e0444..6b6bdccf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java @@ -1,20 +1,6 @@ package de.dhbwstuttgart.syntaxtree.operator; import org.antlr.v4.runtime.Token; -import org.apache.bcel.generic.ArithmeticInstruction; -import org.apache.bcel.generic.DADD; -import org.apache.bcel.generic.DDIV; -import org.apache.bcel.generic.FADD; -import org.apache.bcel.generic.FDIV; -import org.apache.bcel.generic.IADD; -import org.apache.bcel.generic.IDIV; -import org.apache.bcel.generic.LADD; -import org.apache.bcel.generic.LDIV; - -import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; -import de.dhbwstuttgart.syntaxtree.statement.Binary; -import de.dhbwstuttgart.syntaxtree.statement.Expr; - diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java index c30f8ea5..a90a8bcf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java @@ -1,12 +1,6 @@ package de.dhbwstuttgart.syntaxtree.operator; import org.antlr.v4.runtime.Token; -import org.apache.bcel.generic.BranchInstruction; -import org.apache.bcel.generic.IF_ICMPLT; -import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; -import de.dhbwstuttgart.syntaxtree.statement.Binary; -import de.dhbwstuttgart.syntaxtree.statement.Expr; - diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java index 71440e6e..08dfd37c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java @@ -1,9 +1,5 @@ package de.dhbwstuttgart.syntaxtree.operator; import org.antlr.v4.runtime.Token; -import org.apache.bcel.generic.BranchInstruction; -import org.apache.bcel.generic.IF_ICMPLE; -import de.dhbwstuttgart.syntaxtree.statement.Binary; -import de.dhbwstuttgart.syntaxtree.statement.Expr; diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java index effaa2b6..cbff126e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java @@ -1,10 +1,6 @@ package de.dhbwstuttgart.syntaxtree.operator; import org.antlr.v4.runtime.Token; -import org.apache.bcel.generic.BranchInstruction; -import org.apache.bcel.generic.IF_ICMPGT; -import de.dhbwstuttgart.syntaxtree.statement.Binary; -import de.dhbwstuttgart.syntaxtree.statement.Expr; diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java index c7640183..8be12e11 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java @@ -1,9 +1,5 @@ package de.dhbwstuttgart.syntaxtree.operator; import org.antlr.v4.runtime.Token; -import org.apache.bcel.generic.BranchInstruction; -import org.apache.bcel.generic.IF_ICMPGE; -import de.dhbwstuttgart.syntaxtree.statement.Binary; -import de.dhbwstuttgart.syntaxtree.statement.Expr; diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java index 9c1ee4b0..c33d0e1d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java @@ -1,10 +1,6 @@ package de.dhbwstuttgart.syntaxtree.operator; import org.antlr.v4.runtime.Token; -import org.apache.bcel.generic.ArithmeticInstruction; -import org.apache.bcel.generic.IREM; -import de.dhbwstuttgart.syntaxtree.statement.Binary; -import de.dhbwstuttgart.syntaxtree.statement.Expr; diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java index 2a34813f..421b03f6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java @@ -1,14 +1,6 @@ package de.dhbwstuttgart.syntaxtree.operator; import org.antlr.v4.runtime.Token; -import org.apache.bcel.generic.ArithmeticInstruction; -import org.apache.bcel.generic.DMUL; -import org.apache.bcel.generic.FMUL; -import org.apache.bcel.generic.IMUL; -import org.apache.bcel.generic.LMUL; - -import de.dhbwstuttgart.syntaxtree.statement.Binary; -import de.dhbwstuttgart.syntaxtree.statement.Expr; public class TimesOp extends MulOp { @@ -16,6 +8,4 @@ public class TimesOp extends MulOp { super(offset); } - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ArgumentList.java b/src/de/dhbwstuttgart/syntaxtree/statement/ArgumentList.java index d7b4a886..1790efb7 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ArgumentList.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ArgumentList.java @@ -12,7 +12,7 @@ public class ArgumentList extends SyntaxTreeNode super(offset); } - public List expr; + public List expr; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java index 9dd8a2de..695f958d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java @@ -2,34 +2,31 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.List; -public class Assign extends ExprStmt +public class Assign extends Statement { + private final Expression rightSide; + private final LocalOrFieldVar lefSide; - public Assign(RefTypeOrTPH type, Token offset) { - super(type, offset); + public Assign(LocalOrFieldVar leftHandSide, Expression value, Token offset) { + super(leftHandSide.getType(), offset); + this.rightSide = value; + this.lefSide = leftHandSide; } - public Expr expr1; - public Expr expr2; - /** - * Logger log4j - */ - - - public void set_Expr(Expr expr1,Expr expr2) - { - this.expr1 = expr1; - this.expr2 = expr2; + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + ConstraintSet ret = lefSide.getConstraints(info); + ret.addAll(rightSide.getConstraints(info)); + ret.add(new Pair(rightSide.getType(), lefSide.getType())); + return ret; } - - public String get_Name() - { - return null; - } - - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java index d38ba089..6c514995 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java @@ -1,24 +1,27 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.HashMap; +import java.util.List; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.InstructionList; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.operator.Operator; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; // neu von Felix -public class Binary extends BinaryExpr +public class Binary extends Expression { - - public Binary(int offset, int variableLength) - { - super(null); + public Binary(Expression expr1, Expression expr2, Operator op){ + super(null, null); } - public Binary(Expr expr1, Expr expr2, Operator op){ - super(null); + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); } - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java index 7d949658..24393336 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java @@ -1,6 +1,9 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.*; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; import org.apache.bcel.Constants; import org.apache.bcel.generic.ClassGen; @@ -15,10 +18,6 @@ import org.apache.bcel.generic.MethodGen; public class Block extends Statement { - private InstructionFactory _factory; - private ConstantPoolGen _cp; - private ClassGen _cg; - public Block(List statements, Token offset) { super(null, offset); this.statements = statements; @@ -28,18 +27,19 @@ public class Block extends Statement public List statements = new ArrayList<>(); - - - - public List get_Statement() + public List getStatements() { return statements; } - ///////////////////////////////////////////////////////////////////////// - // TypeReconstructionAlgorithmus - ///////////////////////////////////////////////////////////////////////// - + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + ConstraintSet ret = new ConstraintSet(); + for(Statement stmt : getStatements()){ + ret.addAll(stmt.getConstraints(info)); + } + return ret; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java index e265e7f5..22b3f9ab 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java @@ -1,34 +1,25 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.List; public class CastExpr extends Expression { - public CastExpr(RefTypeOrTPH castType, Expr expr, int offset) + public CastExpr(RefTypeOrTPH castType, Expression expr, int offset) { super(null, null); } - public Expr expr; - - - - - public String get_Name() - { - return null; - } - - + public Expression expr; - - - public void set_Expr(Expr ex) - { - this.expr = ex; + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); } - - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java index 15b4acfc..a1ff0805 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java @@ -1,6 +1,11 @@ package de.dhbwstuttgart.syntaxtree.statement; +import java.util.ArrayList; import java.util.Hashtable; +import java.util.List; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.InstructionList; @@ -15,7 +20,9 @@ public class EmptyStmt extends Statement super(null,null); } - - + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + return new ConstraintSet(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java b/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java deleted file mode 100755 index dbc0b611..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java +++ /dev/null @@ -1,11 +0,0 @@ - -package de.dhbwstuttgart.syntaxtree.statement; - -import de.dhbwstuttgart.core.IItemWithOffset; -import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; -import org.antlr.v4.runtime.Token; - - -public interface Expr extends IItemWithOffset -{ -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java deleted file mode 100644 index 05ad9090..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - -import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; -import org.antlr.v4.runtime.Token; - -public abstract class ExprStmt extends Statement implements Expr { - - public ExprStmt(RefTypeOrTPH type, Token offset) { - super(type, offset); - } -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Expression.java b/src/de/dhbwstuttgart/syntaxtree/statement/Expression.java index f68a2d48..c6378ab0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Expression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Expression.java @@ -4,11 +4,25 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; -public class Expression extends SyntaxTreeNode implements Expr +import java.util.List; + +public abstract class Expression extends SyntaxTreeNode { + private RefTypeOrTPH type; + public Expression(RefTypeOrTPH type, Token offset){ super(offset); + this.type = type; } + + public RefTypeOrTPH getType(){ + return type; + } + + public abstract ConstraintSet getConstraints(TypeInferenceInformation info); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java index aeeaf1c0..4474c58b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java @@ -4,27 +4,30 @@ import java.util.Hashtable; import java.util.List; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class ForStmt extends Statement { - private Expr head_Initializer_1; - private Expr head_Condition_1; - private Expr head_Loop_expr_1; - private Expr head_Initializer; - private Expr head_Condition; - private Expr head_Loop_expr; + private Expression head_Initializer_1; + private Expression head_Condition_1; + private Expression head_Loop_expr_1; + private Expression head_Initializer; + private Expression head_Condition; + private Expression head_Loop_expr; private Statement body_Loop_block; public ForStmt(int offset, int variableLength) { super(null,null); } - - void sc_check(List classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) - - { - - } + + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index fa131b8b..804c235d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -2,7 +2,11 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import java.util.List; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.apache.bcel.Constants; import org.apache.bcel.generic.ALOAD; import org.apache.bcel.generic.ASTORE; @@ -29,22 +33,12 @@ public class IfStmt extends Statement } public boolean hamaDebug = true; //hama: Debug Ausgaben von mir ein- bzw. ausschalten - public Expr expr; + public Expression expr; public Statement then_block; public Statement else_block; - - - - public void set_Expr(Expr exp) - { - this.expr = exp; - } - - - - public void set_Then_block(Statement blk) - { - this.then_block = blk; - } + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + return null; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java index a7dbcc9b..34e50f00 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java @@ -2,22 +2,29 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import java.util.List; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.InstructionList; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; - - -public class InstVar extends SyntaxTreeNode implements Expr +public class InstVar extends Expression { - private Expr expr; - public InstVar(Expr instanz, String name, Token offset) + private Expression expr; + public InstVar(Expression instanz, String name, Token offset) { - super(offset); + super(instanz.getType(),offset); expr = instanz; } + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java b/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java index 18a505f8..ea672575 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java @@ -1,15 +1,18 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import java.util.List; public class InstanceOf extends BinaryExpr { - public Expr expr; + public Expression expr; private RefTypeOrTPH reftype; - // private boolean is_instance = false; - public InstanceOf(int offset,int variableLength) { @@ -17,21 +20,8 @@ public class InstanceOf extends BinaryExpr // #JB# 20.04.2005 } - public void set_Expr(Expr exp) - { - this.expr = exp; + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); } - - public void set_Type(RefTypeOrTPH typ) - { - this.reftype = typ; - } - - - public String get_Name() - { - return null; - } - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index e6c55349..a6febe62 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -3,6 +3,12 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.FunN; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.List; /** * @author A10023 - Andreas Stadelmeier @@ -27,5 +33,8 @@ public class LambdaExpression extends Expression{ } - + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java new file mode 100644 index 00000000..e1b899d9 --- /dev/null +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java @@ -0,0 +1,31 @@ +package de.dhbwstuttgart.syntaxtree.statement; + +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import org.antlr.v4.runtime.Token; + +import java.util.List; + +public class LocalOrFieldVar extends Statement{ + + protected final String expression; + + public LocalOrFieldVar(String n, Token offset) + { + super(TypePlaceholder.fresh(offset),offset); + this.expression = n; + } + + public LocalOrFieldVar(Expression e1, String access) + { + super(TypePlaceholder.fresh(e1.getOffset()),e1.getOffset()); + this.expression = access; + } + + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + return null; + } +} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java index cc4953ee..1cd32ab2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java @@ -1,8 +1,12 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Enumeration; import java.util.Hashtable; +import java.util.List; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; import org.apache.bcel.Constants; import org.apache.bcel.generic.ClassGen; @@ -12,6 +16,7 @@ import org.apache.bcel.generic.LocalVariableInstruction; import org.apache.bcel.generic.ObjectType; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; /* @@ -22,26 +27,17 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; * LocalOrFieldVarOrClassname.FieldVar[.Fieldvar...] - FieldVar * Identifier - Lokale Variable oder FieldVar */ -public class LocalOrFieldVarOrClassname extends Expression +public class LocalOrFieldVarOrClassname extends LocalOrFieldVar { - - private final String expression; - private boolean isFieldAccess = false; - private boolean isClassAccess = false; - - public LocalOrFieldVarOrClassname(String n, Token offset) - { - super(TypePlaceholder.fresh(offset),offset); - this.expression = n; + public LocalOrFieldVarOrClassname(String n, Token offset) { + super(n, offset); + } + public LocalOrFieldVarOrClassname(Expression e1, String access){ + super(e1, access); } - - public LocalOrFieldVarOrClassname(Expr e1, String access) - { - super(TypePlaceholder.fresh(null),null); - this.expression = access; + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); } - - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarBunchDeclaration.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarBunchDeclaration.java index 3a724efc..6061aa16 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarBunchDeclaration.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarBunchDeclaration.java @@ -2,15 +2,21 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.Void; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; import java.util.List; -/** - * Created by janulrich on 27.02.17. - */ public class LocalVarBunchDeclaration extends Statement { public LocalVarBunchDeclaration(List declarations, Token start) { super(new Void(start), start); } + + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index b5b4271b..4497d34d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -3,7 +3,13 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.List; public class LocalVarDecl extends Statement { @@ -16,4 +22,8 @@ public class LocalVarDecl extends Statement this.name = name; } + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index 937bf3dc..19a4c2da 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -1,6 +1,10 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; +import java.util.List; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; import org.apache.bcel.Const; import org.apache.bcel.Constants; @@ -15,35 +19,25 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -public class MethodCall extends ExprStmt +public class MethodCall extends Statement { - public MethodCall(Receiver receiver, String methodName, ArgumentList argumentList, Token offset){ - super(TypePlaceholder.fresh(offset),offset); - this.set_ArgumentList(argumentList); - } - - - /** - * Diese Variable speichert die Expression, welche die Klasse von welcher die Methode aufgerufen wird darstellt. - */ + private final String name; private Receiver receiver; private ArgumentList arglist; + public MethodCall(Receiver receiver, String methodName, ArgumentList argumentList, Token offset){ + super(TypePlaceholder.fresh(offset),offset); + this.arglist = argumentList; + this.name = methodName; + } - public void set_ArgumentList(ArgumentList al) - { - this.arglist = al; + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + ConstraintSet ret = receiver.getConstraints(info); + //Overloading: + for(Method m : info.getMethods(name, arglist)){ + //TODO + } + return ret; } - - public ArgumentList getArgumentList() - { - return this.arglist; - } - - public Receiver get_Receiver() - { - return receiver; - } - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java index 9dfccc8d..ac826a78 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java @@ -15,21 +15,6 @@ public class NegativeExpr extends UnaryExpr super(offset); } private UnaryMinus neg; - public Expr expr; - - public String get_Name() - { - return null; - } - - public void set_UnaryMinus(UnaryMinus umin) - { - this.neg = umin; - } - - public void set_Expr(Expr ex) - { - this.expr = ex; - } + public Expression expr; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java index 281d7f20..75db7bb9 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java @@ -2,6 +2,10 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.List; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class NewArray extends Expression @@ -11,8 +15,11 @@ public class NewArray extends Expression super(null,null); } private RefTypeOrTPH type; - public List expr; - + public List expr; + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index 11830845..7e905be2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -3,11 +3,13 @@ import java.util.ArrayList; import java.util.List; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; - - -public class NewClass extends ExprStmt +public class NewClass extends Statement { public NewClass(int offset,int variableLength) { @@ -24,5 +26,9 @@ public class NewClass extends ExprStmt return this.arglist; } - + + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java index 51f0f0e6..0fcfd333 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java @@ -10,27 +10,5 @@ public class NotExpr extends UnaryExpr super(offset); } private UnaryNot not; - public Expr expr; - - - public String get_Name() - { - return null; - } - - public Expr get_Expr() - { - return expr; - } - - public void set_UnaryNot(UnaryNot unot) - { - this.not = unot; - } - - public void set_Expr(Expr ex) - { - this.expr = ex; - } - + public Expression expr; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java index dae69169..bec6ffbe 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java @@ -10,33 +10,6 @@ public class PositivExpr extends UnaryExpr super(offset); } protected UnaryPlus plus; - public Expr expr; - - - - public void set_UnaryPlus(UnaryPlus up) - { - this.plus = up; - } - - public void set_Expr(Expr ex) - { - this.expr = ex; - } - - public String get_Name() - { - return null; - } - - /* - public void sc_check(Menge classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) - { - if(ext) - parserlog.debug(" ---PositivExpr---"); - //Wartet noch auf Implementierung - } - */ - + public Expression expr; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java index 94411a75..50144b26 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java @@ -12,18 +12,8 @@ import org.apache.bcel.generic.InstructionList; public class PostDecExpr extends PostIncExpr { - public PostDecExpr(Expr expr) { + public PostDecExpr(Expression expr) { super(expr); } - public void set_Expr(Expr ex) - { - this.expr = ex; - } - - public String get_Name() - { - return null; - } - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java index 05b323ac..8b29ecec 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java @@ -1,7 +1,11 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Iterator; +import java.util.List; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.apache.bcel.generic.BIPUSH; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.IINC; @@ -9,26 +13,17 @@ import org.apache.bcel.generic.InstructionFactory; import org.apache.bcel.generic.InstructionList; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; - - +import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class PostIncExpr extends UnaryExpr { - public PostIncExpr(Expr expr) { + public PostIncExpr(Expression expr) { super(null); } - - public void set_Expr(Expr ex) - { - this.expr = ex; + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); } - - public String get_Name() - { - return null; - } - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java index 415b2f37..e1d311b8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java @@ -16,17 +16,4 @@ public class PreDecExpr extends UnaryExpr { super(offset); } - - - - public void set_Expr(Expr ex) - { - this.expr = ex; - } - public String get_Name() - { - return null; - } - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java index eb46b668..736dc311 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java @@ -9,19 +9,4 @@ public class PreIncExpr extends UnaryExpr { super(offset); } - - - - - public void set_Expr(Expr ex) - { - this.expr = ex; - } - - public String get_Name() - { - return null; - } - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java index b27ac0cb..e5abc75c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java @@ -1,16 +1,28 @@ package de.dhbwstuttgart.syntaxtree.statement; -public class Receiver +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.List; + +public class Receiver extends Expression { - private Expr expr; + private Expression expr; /** * Autor: J�rg B�uerle * @param expr */ - public Receiver(Expr expr) + public Receiver(Expression expr) { + super(expr.getType(), expr.getOffset()); this.expr = expr; } + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + return expr.getConstraints(info); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java index 9bdece76..48e6a8f4 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java @@ -1,7 +1,11 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; +import java.util.List; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; import org.apache.bcel.generic.ConstantPoolGen; import org.apache.bcel.generic.InstructionFactory; @@ -10,22 +14,22 @@ import org.apache.bcel.generic.ClassGen; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; - +import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class Return extends Statement { - public Return(Expr retExpr, Token offset) + private Expression retexpr; + + public Return(Expression retExpr, Token offset) { - super(null,null); - } - public Expr retexpr; - - - public Return set_ReturnExpr(Expr ret) - { - this.retexpr=ret; - return this; + super(retExpr.getType(),offset); + this.retexpr = retExpr; } + + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java index bd594dcf..bece9a8d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java @@ -2,19 +2,20 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; +import java.util.List; -public abstract class Statement extends SyntaxTreeNode + +public abstract class Statement extends Expression { public Statement(RefTypeOrTPH type, Token offset) { - super(offset); - + super(type, offset); } - - } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Super.java b/src/de/dhbwstuttgart/syntaxtree/statement/Super.java index a7777e91..8e6299b2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Super.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Super.java @@ -1,6 +1,12 @@ package de.dhbwstuttgart.syntaxtree.statement; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.List; public class Super extends Expression { @@ -9,4 +15,8 @@ public class Super extends Expression super(null,null); } + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/This.java b/src/de/dhbwstuttgart/syntaxtree/statement/This.java index 39a0aebf..3464730d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/This.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/This.java @@ -1,7 +1,13 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.List; public class This extends Expression { @@ -11,5 +17,9 @@ public class This extends Expression } public ArgumentList arglist; - + + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java index 55c15b94..06899933 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java @@ -5,12 +5,10 @@ import org.antlr.v4.runtime.Token; public abstract class UnaryExpr extends MethodCall { - public Expr expr; + public Expression expr; public UnaryExpr(Token offset) { super(null,null,null,null); } - - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java index d6dcbb46..6c100225 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java @@ -6,7 +6,7 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; public class UnaryMinus extends UnaryPlus { - public UnaryMinus(Expr expression) { + public UnaryMinus(Expression expression) { super(expression); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java index 0c1b6e35..32b74ced 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java @@ -1,11 +1,22 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; -public class UnaryPlus extends SyntaxTreeNode implements Expr +import java.util.List; + +public class UnaryPlus extends Expression { - public UnaryPlus(Expr expression){ - super(expression.getOffset()); + public UnaryPlus(Expression expression){ + super(expression.getType(),expression.getOffset()); } + + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java index ceb7648a..f5f5f079 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java @@ -1,6 +1,13 @@ package de.dhbwstuttgart.syntaxtree.statement; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.List; + public class WhileStmt extends Statement { public WhileStmt(int offset, int variableLength) @@ -8,21 +15,9 @@ public class WhileStmt extends Statement super(null,null); } - public Expr expr; + public Expression expr; public Statement loop_block; - - public void set_Expr(Expr exp) - { - this.expr = exp; - } - - public void set_Loop_block(Statement blk) - { - this.loop_block = blk; - } - - /** *
Author: Martin Pl�micke * @return @@ -33,5 +28,8 @@ public class WhileStmt extends Statement } - + @Override + public ConstraintSet getConstraints(TypeInferenceInformation info) { + throw new NotImplementedException(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/literal/Literal.java b/src/de/dhbwstuttgart/syntaxtree/statement/literal/Literal.java index d50437a7..ac6301c2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/literal/Literal.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/literal/Literal.java @@ -3,6 +3,8 @@ package de.dhbwstuttgart.syntaxtree.statement.literal; import de.dhbwstuttgart.syntaxtree.statement.Expression; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.ConstraintSet; +import de.dhbwstuttgart.typeinference.TypeInferenceInformation; import org.antlr.v4.runtime.Token; public abstract class Literal extends Expression @@ -10,4 +12,8 @@ public abstract class Literal extends Expression public Literal(RefTypeOrTPH type, Token offset) { super(type, offset); } + + public ConstraintSet getConstraints(TypeInferenceInformation info){ + return new ConstraintSet(); + } } diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintSet.java new file mode 100644 index 00000000..7f400646 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/ConstraintSet.java @@ -0,0 +1,11 @@ +package de.dhbwstuttgart.typeinference; + +public class ConstraintSet { + public void addAll(ConstraintSet constraints) { + + } + + public void add(Pair pair) { + + } +} diff --git a/src/de/dhbwstuttgart/typeinference/EinzelElement.java b/src/de/dhbwstuttgart/typeinference/EinzelElement.java new file mode 100644 index 00000000..eddd4bf9 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/EinzelElement.java @@ -0,0 +1,39 @@ +package de.dhbwstuttgart.typeinference; + +import java.util.Set; +import java.util.TreeSet; + + +public class EinzelElement implements KomplexeMenge{ + private A item; + + public EinzelElement(A element){ + item = element; + } + + public Set> getSet(){ + Set> ret = new TreeSet<>(); + ret.add(this); + return ret; + } + + @Override + public Set> cartesianProduct() { + Set> ret = new TreeSet<>(); + Set i = new TreeSet<>(); + i.add(item); + ret.add(i); + return ret; + //throw new NotImplementedException(); + } + + @Override + public String toString(){ + return item.toString(); + } + + public A getItem(){ + return item; + } + +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/typeinference/KomplexeMenge.java b/src/de/dhbwstuttgart/typeinference/KomplexeMenge.java new file mode 100644 index 00000000..f72d991d --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/KomplexeMenge.java @@ -0,0 +1,8 @@ +package de.dhbwstuttgart.typeinference; + +import java.util.Set; + +public interface KomplexeMenge{ + Set> getSet(); + Set> cartesianProduct(); +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java new file mode 100755 index 00000000..4fc1d3f2 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -0,0 +1,69 @@ +package de.dhbwstuttgart.typeinference; + +import java.util.ArrayList; +import java.util.Set; +import java.util.TreeSet; +import java.util.Vector; + + +public class OderConstraint extends OderMenge{ + private Set oderConstraintPairs; + + public OderConstraint(){ + oderConstraintPairs = new TreeSet<>(); + } + + + /** + * Liefert alle in diesem OderConstraint enthaltene Constraints. Dabei gehen die Verkn�pfungen (Oder/Und) verloren. + * @return + */ + public Set getConstraintPairs(){ + Set ret = new TreeSet<>(); + for(UndConstraint oC : this.oderConstraintPairs){ + ret.addAll(oC.getConstraintPairs()); + } + return ret; + } + + /** + * Falls die Type des toAdd-Pairs nicht vom Typ RefType bzw. TypePlaceholder sind, so werden sie in einen RefType umgewandelt. + * @param toAdd + */ + public void addConstraint(Pair toAdd){ + UndConstraint uCons = new UndConstraint(); + uCons.addConstraint(toAdd); + oderConstraintPairs.add(uCons); + } + + @Override + public String toString(){ + String ret = "["; + for(UndConstraint p : this.getUndConstraints()){ + ret += p.toString()+ "| "; + } + return ret+"]"; + } + + public Set getUndConstraints() { + return this.oderConstraintPairs; + /* + Vector ret = new Vector(); + for(Pair p : this.getConstraintPairs()){ + ret.add(new UndConstraint(p.TA1,p.TA2)); + } + return ret; + */ + } + + public void addConstraint(UndConstraint constraint) { + oderConstraintPairs.add(constraint); + } + + @Override + public Set> getSet() { + return this.oderConstraintPairs; + } + + +} diff --git a/src/de/dhbwstuttgart/typeinference/OderMenge.java b/src/de/dhbwstuttgart/typeinference/OderMenge.java new file mode 100644 index 00000000..45edf361 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/OderMenge.java @@ -0,0 +1,28 @@ +package de.dhbwstuttgart.typeinference; + +import java.util.Set; +import java.util.TreeSet; + +public abstract class OderMenge implements KomplexeMenge{ + + public abstract Set> getSet(); + + @Override + public Set> cartesianProduct() { + Set> ret = new TreeSet<>(); + for(KomplexeMenge km : this.getSet()){ + ret.addAll(km.cartesianProduct()); + } + return ret; + } + + @Override + public String toString(){ + String ret = "["; + for(KomplexeMenge i : this.getSet()){ + ret += i.toString() + " | "; + } + return ret + "]"; + } + +} diff --git a/src/de/dhbwstuttgart/typeinference/TypeInferenceInformation.java b/src/de/dhbwstuttgart/typeinference/TypeInferenceInformation.java new file mode 100644 index 00000000..8f0c0494 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/TypeInferenceInformation.java @@ -0,0 +1,31 @@ +package de.dhbwstuttgart.typeinference; + +import de.dhbwstuttgart.syntaxtree.Method; +import de.dhbwstuttgart.syntaxtree.statement.ArgumentList; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import java.util.List; + +/* +Anmerkung: +Zwei Möglichkeiten, die TypeAssumptions zu speichern. +1. Die Klassen mit bedeutenden Informationen generieren diese und übergeben sie dann dieser Klasse. +2. Oder es werden nur Referenzen auf den SyntaxTree übergeben, welche diese Klasse hier dann verarbeitet. + +Bei Änderungen des SyntaxTrees müssen beide Methoden angepasst werden. +Zweiteres hat den Vorteil, dass bei der Entwicklung leichter Dinge hinzugefügt werden können. +Die ganze Logik steckt in dieser Klasse. + */ +public class TypeInferenceInformation { + + + private Method methodContext; + + public void setMethodContext(Method methodContext) { + this.methodContext = methodContext; + } + + public List getMethods(String name, ArgumentList arglist) { + throw new NotImplementedException(); + } +} diff --git a/src/de/dhbwstuttgart/typeinference/UndConstraint.java b/src/de/dhbwstuttgart/typeinference/UndConstraint.java new file mode 100755 index 00000000..304e1cda --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/UndConstraint.java @@ -0,0 +1,53 @@ +package de.dhbwstuttgart.typeinference; + +import java.util.Collection; +import java.util.Set; +import java.util.TreeSet; +import java.util.Vector; + +import de.dhbwstuttgart.exceptions.DebugException; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus; + +/** + * Stellt ein Constraint dar, welches aus mehreren Constraint-Paaren besteht. Diese gelten alle stets gleichzeitig / sind per "Und" miteinander verknüpft. + * @author janulrich + * + */ +public class UndConstraint extends UndMenge { + + Set> set = new TreeSet<>(); + + @Override + public Set> getSet() { + return set; + } + + public Set getConstraintPairs() { + Set> ret = this.cartesianProduct(); + if(ret.size() != 1){ + //UndConstraints enthalten nur SingleConstraints, wodurch das Karthesische Produkt nur aus einem Element bestehen kann. + throw new DebugException("Fehler in ConstraintPairs-Bildung"); + } + return ret.iterator().next(); + } + + public void addConstraint(RefTypeOrTPH type, RefTypeOrTPH rT) { + Pair p = new Pair(type, rT); + addConstraint(p); + } + + public void addConstraint(Pair toAdd){ + this.set.add(new EinzelElement(toAdd)); + } + + @Override + public String toString() { + String ret = this.getConstraintPairs().toString(); + return ret; + } + + public Set> getPairs(){ + return set; + } +} diff --git a/src/de/dhbwstuttgart/typeinference/UndMenge.java b/src/de/dhbwstuttgart/typeinference/UndMenge.java new file mode 100644 index 00000000..8cc30458 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/UndMenge.java @@ -0,0 +1,44 @@ +package de.dhbwstuttgart.typeinference; + +import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +//import com.rits.cloning.Cloner; + +public abstract class UndMenge implements KomplexeMenge{ + + public abstract Set> getSet(); + + @Override + public Set> cartesianProduct() { + Set> ret = null; + for(KomplexeMenge km : this.getSet()){ + if(ret == null){ + ret = km.cartesianProduct(); + }else{ + Set> cartesianProduct = new TreeSet<>(); + for(Set r : ret)for(Set m : km.cartesianProduct()){ //Für jedes Element aus dem Karthesischen Produkt: + Set undElement = new TreeSet<>(); + undElement.addAll(r); + undElement.addAll(m); + cartesianProduct.add(undElement); + } + ret = cartesianProduct; + } + } + if(ret == null)return new TreeSet<>(); + return ret; + } + + public String toString(){ + String ret = "["; + for(KomplexeMenge item : this.getSet()){ + ret += item.toString() + " , "; + } + return ret + "]"; + } +} + diff --git a/src/de/dhbwstuttgart/typeinference/unify/Mapping.java b/src/de/dhbwstuttgart/typeinference/unify/Mapping.java deleted file mode 100644 index 53b4f83f..00000000 --- a/src/de/dhbwstuttgart/typeinference/unify/Mapping.java +++ /dev/null @@ -1,72 +0,0 @@ -package de.dhbwstuttgart.typeinference.unify; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import de.dhbwstuttgart.typeinference.Pair; -import de.dhbwstuttgart.typeinference.unify.model.PairOperator; - -public class Mapping { - - private HashMap backwardMap = new HashMap<>(); - private HashMap forwardMap = new HashMap<>(); - private Set irreversible = new HashSet<>(); - - public Mapping(Set types) { - for(de.dhbwstuttgart.syntaxtree.type.RefType t : types) { - } - } - - public de.dhbwstuttgart.typeinference.unify.model.UnifyType map(de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH type) { - return forwardMap.get(type); - } - - public de.dhbwstuttgart.typeinference.unify.model.UnifyPair map(de.dhbwstuttgart.typeinference.Pair pair) { - return new de.dhbwstuttgart.typeinference.unify.model.UnifyPair(forwardMap.get(pair.TA1), forwardMap.get(pair.TA2), mapOp(pair.GetOperator())); - } - - public Set mapTypeSet(Set types) { - return types.stream().map(this::map).collect(Collectors.toCollection(HashSet::new)); - } - - public Set mapPairSet(Set pairs) { - return pairs.stream().map(this::map).collect(Collectors.toCollection(HashSet::new)); - } - - public Optional unmap(de.dhbwstuttgart.typeinference.unify.model.UnifyType type) { - return irreversible.contains(type) ? Optional.of(backwardMap.get(type)) : Optional.empty(); - } - - public Optional unmap(de.dhbwstuttgart.typeinference.unify.model.UnifyPair mpair) { - de.dhbwstuttgart.typeinference.unify.model.UnifyType lhs = mpair.getLhsType(); - de.dhbwstuttgart.typeinference.unify.model.UnifyType rhs = mpair.getRhsType(); - - if(irreversible.contains(lhs) || irreversible.contains(rhs)) - return Optional.empty(); - return Optional.of(new Pair(backwardMap.get(lhs), backwardMap.get(rhs), unmapOp(mpair.getPairOp()))); - } - - public Optional> unmapTypeSet(Set types) { - Set result = types.stream().map(this::unmap).filter(x -> x.isPresent()).map(x -> x.get()).collect(Collectors.toCollection(HashSet::new)); - return result.size() == types.size() ? Optional.of(result) : Optional.empty(); - } - - public Optional> unmapPairSet(Set pairs) { - Set result = pairs.stream().map(this::unmap).filter(x -> x.isPresent()).map(x -> x.get()).collect(Collectors.toCollection(HashSet::new)); - return result.size() == pairs.size() ? Optional.of(result) : Optional.empty(); - } - - private PairOperator mapOp(PairOperator op) { - //TODO: Methode kann entfernt werden: - return op; - } - - private PairOperator unmapOp(PairOperator op) { - //TODO: Methode kann entfernt werden: - return op; - } - -}