getConstraints() eingeführt
This commit is contained in:
parent
a44baeaa34
commit
4c4c0d5ada
@ -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<SourceFile> 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 {
|
||||
|
@ -203,12 +203,28 @@ public class SyntaxTreeGenerator{
|
||||
JavaClassName name = convert(ctx.Identifier());
|
||||
Block class_block = null;
|
||||
List<Field> fielddecl = convertFields(ctx.classBody());
|
||||
List<Method> methods = convertMethods(ctx.classBody());
|
||||
GenericDeclarationList genericClassParameters = null;
|
||||
Token offset = ctx.getStart();
|
||||
RefTypeOrTPH superClass = null;
|
||||
Boolean isInterface = false;
|
||||
List<RefTypeOrTPH> 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<Method> convertMethods(Java8Parser.ClassBodyContext classBodyContext) {
|
||||
List<Method> 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<Field> 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();
|
||||
}
|
||||
|
||||
|
@ -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<Field> fielddecl = new ArrayList<>();
|
||||
private List<Field> fields = new ArrayList<>();
|
||||
private List<Method> methods = new ArrayList<>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private Token offset;
|
||||
private RefTypeOrTPH superClass;
|
||||
protected boolean isInterface;
|
||||
private List<RefTypeOrTPH> implementedInterfaces;
|
||||
|
||||
public ClassOrInterface(Modifiers modifiers, JavaClassName name, List<Field> fielddecl, GenericDeclarationList genericClassParameters,
|
||||
public ClassOrInterface(Modifiers modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, GenericDeclarationList genericClassParameters,
|
||||
RefTypeOrTPH superClass, Boolean isInterface, List<RefTypeOrTPH> 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<Field> getFieldDecl(){
|
||||
return this.fielddecl;
|
||||
return this.fields;
|
||||
}
|
||||
public List<Method> getMethods(){
|
||||
return this.methods;
|
||||
}
|
||||
|
||||
public ConstraintSet getConstraints(TypeInferenceInformation info) {
|
||||
ConstraintSet ret = new ConstraintSet();
|
||||
for(Method m : this.getMethods()){
|
||||
m.getConstraints(info);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -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<FieldModifier> modifier, Expr value, Token offset){
|
||||
public FieldDeclaration(String name, RefTypeOrTPH typ, List<FieldModifier> 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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<JavaClassName> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public class ArgumentList extends SyntaxTreeNode
|
||||
super(offset);
|
||||
}
|
||||
|
||||
public List<Expr> expr;
|
||||
public List<Expression> expr;
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Statement> statements, Token offset) {
|
||||
super(null, offset);
|
||||
this.statements = statements;
|
||||
@ -28,18 +27,19 @@ public class Block extends Statement
|
||||
|
||||
public List<Statement> statements = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
|
||||
public List<Statement> get_Statement()
|
||||
public List<Statement> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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<ClassOrInterface> classname, Hashtable ch, Hashtable<String, String> bh, boolean ext, Hashtable parach, Hashtable<String, Hashtable> parabh)
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConstraintSet getConstraints(TypeInferenceInformation info) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<LocalVarDecl> declarations, Token start) {
|
||||
super(new Void(start), start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintSet getConstraints(TypeInferenceInformation info) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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> expr;
|
||||
|
||||
public List<Expression> expr;
|
||||
|
||||
|
||||
@Override
|
||||
public ConstraintSet getConstraints(TypeInferenceInformation info) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<Class> classname, Hashtable ch, Hashtable<String, String> bh, boolean ext, Hashtable parach, Hashtable<String, Hashtable> parabh)
|
||||
{
|
||||
if(ext)
|
||||
parserlog.debug(" ---PositivExpr---");
|
||||
//Wartet noch auf Implementierung
|
||||
}
|
||||
*/
|
||||
|
||||
public Expression expr;
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
public class UnaryMinus extends UnaryPlus
|
||||
{
|
||||
|
||||
public UnaryMinus(Expr expression) {
|
||||
public UnaryMinus(Expression expression) {
|
||||
super(expression);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <br/>Author: Martin Pl�micke
|
||||
* @return
|
||||
@ -33,5 +28,8 @@ public class WhileStmt extends Statement
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ConstraintSet getConstraints(TypeInferenceInformation info) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
11
src/de/dhbwstuttgart/typeinference/ConstraintSet.java
Normal file
11
src/de/dhbwstuttgart/typeinference/ConstraintSet.java
Normal file
@ -0,0 +1,11 @@
|
||||
package de.dhbwstuttgart.typeinference;
|
||||
|
||||
public class ConstraintSet {
|
||||
public void addAll(ConstraintSet constraints) {
|
||||
|
||||
}
|
||||
|
||||
public void add(Pair pair) {
|
||||
|
||||
}
|
||||
}
|
39
src/de/dhbwstuttgart/typeinference/EinzelElement.java
Normal file
39
src/de/dhbwstuttgart/typeinference/EinzelElement.java
Normal file
@ -0,0 +1,39 @@
|
||||
package de.dhbwstuttgart.typeinference;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
||||
public class EinzelElement<A> implements KomplexeMenge<A>{
|
||||
private A item;
|
||||
|
||||
public EinzelElement(A element){
|
||||
item = element;
|
||||
}
|
||||
|
||||
public Set<KomplexeMenge<A>> getSet(){
|
||||
Set<KomplexeMenge<A>> ret = new TreeSet<>();
|
||||
ret.add(this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Set<A>> cartesianProduct() {
|
||||
Set<Set<A>> ret = new TreeSet<>();
|
||||
Set<A> 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;
|
||||
}
|
||||
|
||||
}
|
8
src/de/dhbwstuttgart/typeinference/KomplexeMenge.java
Normal file
8
src/de/dhbwstuttgart/typeinference/KomplexeMenge.java
Normal file
@ -0,0 +1,8 @@
|
||||
package de.dhbwstuttgart.typeinference;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface KomplexeMenge<A>{
|
||||
Set<? extends KomplexeMenge<A>> getSet();
|
||||
Set<Set<A>> cartesianProduct();
|
||||
}
|
69
src/de/dhbwstuttgart/typeinference/OderConstraint.java
Executable file
69
src/de/dhbwstuttgart/typeinference/OderConstraint.java
Executable file
@ -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<Pair>{
|
||||
private Set<UndConstraint> oderConstraintPairs;
|
||||
|
||||
public OderConstraint(){
|
||||
oderConstraintPairs = new TreeSet<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Liefert alle in diesem OderConstraint enthaltene Constraints. Dabei gehen die Verkn<EFBFBD>pfungen (Oder/Und) verloren.
|
||||
* @return
|
||||
*/
|
||||
public Set<Pair> getConstraintPairs(){
|
||||
Set<Pair> 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<UndConstraint> getUndConstraints() {
|
||||
return this.oderConstraintPairs;
|
||||
/*
|
||||
Vector<UndConstraint> ret = new Vector<UndConstraint>();
|
||||
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<? extends KomplexeMenge<Pair>> getSet() {
|
||||
return this.oderConstraintPairs;
|
||||
}
|
||||
|
||||
|
||||
}
|
28
src/de/dhbwstuttgart/typeinference/OderMenge.java
Normal file
28
src/de/dhbwstuttgart/typeinference/OderMenge.java
Normal file
@ -0,0 +1,28 @@
|
||||
package de.dhbwstuttgart.typeinference;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public abstract class OderMenge<A> implements KomplexeMenge<A>{
|
||||
|
||||
public abstract Set<? extends KomplexeMenge<A>> getSet();
|
||||
|
||||
@Override
|
||||
public Set<Set<A>> cartesianProduct() {
|
||||
Set<Set<A>> ret = new TreeSet<>();
|
||||
for(KomplexeMenge<A> km : this.getSet()){
|
||||
ret.addAll(km.cartesianProduct());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
String ret = "[";
|
||||
for(KomplexeMenge<A> i : this.getSet()){
|
||||
ret += i.toString() + " | ";
|
||||
}
|
||||
return ret + "]";
|
||||
}
|
||||
|
||||
}
|
@ -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<Method> getMethods(String name, ArgumentList arglist) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
53
src/de/dhbwstuttgart/typeinference/UndConstraint.java
Executable file
53
src/de/dhbwstuttgart/typeinference/UndConstraint.java
Executable file
@ -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<Pair> {
|
||||
|
||||
Set<EinzelElement<Pair>> set = new TreeSet<>();
|
||||
|
||||
@Override
|
||||
public Set<? extends KomplexeMenge<Pair>> getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
public Set<Pair> getConstraintPairs() {
|
||||
Set<Set<Pair>> 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<Pair>(toAdd));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = this.getConstraintPairs().toString();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Set<EinzelElement<Pair>> getPairs(){
|
||||
return set;
|
||||
}
|
||||
}
|
44
src/de/dhbwstuttgart/typeinference/UndMenge.java
Normal file
44
src/de/dhbwstuttgart/typeinference/UndMenge.java
Normal file
@ -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<A> implements KomplexeMenge<A>{
|
||||
|
||||
public abstract Set<? extends KomplexeMenge<A>> getSet();
|
||||
|
||||
@Override
|
||||
public Set<Set<A>> cartesianProduct() {
|
||||
Set<Set<A>> ret = null;
|
||||
for(KomplexeMenge<A> km : this.getSet()){
|
||||
if(ret == null){
|
||||
ret = km.cartesianProduct();
|
||||
}else{
|
||||
Set<Set<A>> cartesianProduct = new TreeSet<>();
|
||||
for(Set<A> r : ret)for(Set<A> m : km.cartesianProduct()){ //Für jedes Element aus dem Karthesischen Produkt:
|
||||
Set<A> 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<A> item : this.getSet()){
|
||||
ret += item.toString() + " , ";
|
||||
}
|
||||
return ret + "]";
|
||||
}
|
||||
}
|
||||
|
@ -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<de.dhbwstuttgart.typeinference.unify.model.UnifyType, de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH> backwardMap = new HashMap<>();
|
||||
private HashMap<de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH, de.dhbwstuttgart.typeinference.unify.model.UnifyType> forwardMap = new HashMap<>();
|
||||
private Set<de.dhbwstuttgart.typeinference.unify.model.UnifyType> irreversible = new HashSet<>();
|
||||
|
||||
public Mapping(Set<de.dhbwstuttgart.syntaxtree.type.RefType> 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<de.dhbwstuttgart.typeinference.unify.model.UnifyType> mapTypeSet(Set<de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH> types) {
|
||||
return types.stream().map(this::map).collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
public Set<de.dhbwstuttgart.typeinference.unify.model.UnifyPair> mapPairSet(Set<de.dhbwstuttgart.typeinference.Pair> pairs) {
|
||||
return pairs.stream().map(this::map).collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
public Optional<de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH> unmap(de.dhbwstuttgart.typeinference.unify.model.UnifyType type) {
|
||||
return irreversible.contains(type) ? Optional.of(backwardMap.get(type)) : Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Pair> 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<Set<de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH>> unmapTypeSet(Set<de.dhbwstuttgart.typeinference.unify.model.UnifyType> types) {
|
||||
Set<de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH> 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<Set<de.dhbwstuttgart.typeinference.Pair>> unmapPairSet(Set<de.dhbwstuttgart.typeinference.unify.model.UnifyPair> pairs) {
|
||||
Set<de.dhbwstuttgart.typeinference.Pair> 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user