From 584690596e138b7e39151d53499328c1f8afac8d Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Fri, 1 Mar 2024 17:34:40 +0100 Subject: [PATCH] Add filename to debug output, closes #126 --- resources/bytecode/javFiles/Op2.jav | 12 +- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 4 +- .../de/dhbwstuttgart/parser/SourceLoc.java | 4 + .../SyntaxTreeGenerator.java | 11 +- .../syntaxtree/ClassOrInterface.java | 10 +- .../de/dhbwstuttgart/syntaxtree/Record.java | 4 +- .../syntaxtree/factory/ASTFactory.java | 2 +- .../syntaxtree/factory/UnifyTypeFactory.java | 9 +- .../typeinference/assumptions/FunNClass.java | 2 +- .../typeinference/constraints/Pair.java | 7 +- .../typeinference/typeAlgo/TYPEStmt.java | 142 +++++++++--------- .../unify/interfaces/IFiniteClosure.java | 3 +- .../unify/model/FiniteClosure.java | 3 +- .../typeinference/unify/model/UnifyPair.java | 15 +- src/test/java/TestComplete.java | 7 + .../java/targetast/ASTToTypedTargetAST.java | 2 +- 16 files changed, 138 insertions(+), 99 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/parser/SourceLoc.java diff --git a/resources/bytecode/javFiles/Op2.jav b/resources/bytecode/javFiles/Op2.jav index 9d446eb2..4bf3b77e 100644 --- a/resources/bytecode/javFiles/Op2.jav +++ b/resources/bytecode/javFiles/Op2.jav @@ -1,11 +1,17 @@ import java.lang.Integer; +import java.lang.Double; import java.lang.String; public class Op2 { m(){ - var x = ""; - var a = 5+x; - + //var x = ""; + //var a = 5+x; + + Integer x = 10; + Double y = 10.5; + + var a = x - y; + return a; } } \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 8ea08a23..fae04d71 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -651,7 +651,7 @@ public class JavaTXCompiler { private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException { SourceFileContext tree = JavaTXParser.parse(sourceFile); environment.addClassesToRegistry(classRegistry, tree, sourceFile, this); - SyntaxTreeGenerator generator = new SyntaxTreeGenerator(this, classRegistry, new GenericsRegistry(null)); + SyntaxTreeGenerator generator = new SyntaxTreeGenerator(this, classRegistry, new GenericsRegistry(null), sourceFile.getName()); var classes = new ArrayList(); var sf = new SourceFile(generator.pkgName, classes, generator.imports); addSourceFile(sourceFile, sf); @@ -672,7 +672,7 @@ public class JavaTXCompiler { var tree = JavaTXParser.parse(file); classRegistry.addName(name.toString(), 0); // TODO This gets overwritten later, is it bad if we don't know this right away? environment.addClassesToRegistry(classRegistry, tree, file, this); - SyntaxTreeGenerator generator = new SyntaxTreeGenerator(this, classRegistry, new GenericsRegistry(null)); + SyntaxTreeGenerator generator = new SyntaxTreeGenerator(this, classRegistry, new GenericsRegistry(null), file.getName()); var classes = new ArrayList(); var sf = new SourceFile(generator.pkgName, classes, generator.imports); addSourceFile(file, sf); diff --git a/src/main/java/de/dhbwstuttgart/parser/SourceLoc.java b/src/main/java/de/dhbwstuttgart/parser/SourceLoc.java new file mode 100644 index 00000000..4cdd698c --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/parser/SourceLoc.java @@ -0,0 +1,4 @@ +package de.dhbwstuttgart.parser; + +public record SourceLoc(String file, int line) { +} diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index dafc1eca..40d2a323 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -92,7 +92,9 @@ public class SyntaxTreeGenerator { private final JavaTXCompiler compiler; private RefType superClass; - public SyntaxTreeGenerator(JavaTXCompiler compiler, JavaClassRegistry reg, GenericsRegistry globalGenerics) { + public final String fileName; + + public SyntaxTreeGenerator(JavaTXCompiler compiler, JavaClassRegistry reg, GenericsRegistry globalGenerics, String fileName) { // Die Generics müssen während des Bauens des AST erstellt werden, // da diese mit der Methode oder Klasse, in welcher sie deklariert werden // verknüpft sein müssen. Dennoch werden die Namen aller Generics in einer @@ -117,6 +119,7 @@ public class SyntaxTreeGenerator { this.allmodifiers.put("strictfp", 32768); this.compiler = compiler; + this.fileName = fileName; } public JavaClassRegistry getReg() { @@ -226,7 +229,7 @@ public class SyntaxTreeGenerator { } var ctor = Optional.of(this.generatePseudoConstructor(ctx.identifier().getText(), fieldInitializations, genericClassParameters, offset)); var staticCtor = Optional.of(this.generateStaticConstructor(ctx.identifier().getText(), staticFieldInitializations, genericClassParameters, offset)); - return new ClassOrInterface(modifiers, name, fielddecl, ctor, staticCtor, methods, constructors, genericClassParameters, superClass, isInterface, isFunctionalInterface, implementedInterfaces, permittedSubtypes, offset); + return new ClassOrInterface(modifiers, name, fielddecl, ctor, staticCtor, methods, constructors, genericClassParameters, superClass, isInterface, isFunctionalInterface, implementedInterfaces, permittedSubtypes, offset, fileName); } @@ -282,7 +285,7 @@ public class SyntaxTreeGenerator { implementedInterfaces.addAll(convert(recordDeclaration.typeList(), generics)); } var staticCtor = Optional.of(this.generateStaticConstructor(recordDeclaration.identifier().getText(), staticFieldInitializations, genericClassParameters, offset)); - return new Record(modifiers, name, fielddecl, Optional.empty(), staticCtor, methods, constructors, genericClassParameters, superClass, isInterface, implementedInterfaces, offset); + return new Record(modifiers, name, fielddecl, Optional.empty(), staticCtor, methods, constructors, genericClassParameters, superClass, isInterface, implementedInterfaces, offset, fileName); } private void convert(ClassBodyDeclarationContext classBody, List fields, List constructors, List methods, JavaClassName name, RefType superClass, GenericsRegistry generics) { @@ -401,7 +404,7 @@ public class SyntaxTreeGenerator { } var staticCtor = Optional.of(this.generateStaticConstructor(ctx.identifier().getText(), staticFieldInitializations, genericParams, ctx.getStart())); - return new ClassOrInterface(modifiers, name, fields, Optional.empty(), staticCtor, methods, new ArrayList<>(), genericParams, superClass, true, methods.size() == 1 ? true : false, extendedInterfaces, permittedSubtypes, ctx.getStart()); + return new ClassOrInterface(modifiers, name, fields, Optional.empty(), staticCtor, methods, new ArrayList<>(), genericParams, superClass, true, methods.size() == 1 ? true : false, extendedInterfaces, permittedSubtypes, ctx.getStart(), fileName); } private GenericDeclarationList createEmptyGenericDeclarationList(Token classNameIdentifier) { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index a4c527a0..a8777386 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -21,6 +21,8 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope { private Boolean methodAdded = false; // wird benoetigt bei in JavaTXCompiler.getConstraints() protected int modifiers; protected JavaClassName name; + private final String fileName; + private List fields = new ArrayList<>(); private Optional fieldInitializations; // PL 2018-11-24: Noetig, um Bytecode fuer initializators nur einmal zu erzeugen private Optional staticInitializer; @@ -33,7 +35,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope { private List permittedSubtypes; private List constructors; - public ClassOrInterface(int modifiers, JavaClassName name, List fielddecl, Optional fieldInitializations, Optional staticInitializer, List methods, List constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List implementedInterfaces, List permittedSubtypes, Token offset) { + public ClassOrInterface(int modifiers, JavaClassName name, List fielddecl, Optional fieldInitializations, Optional staticInitializer, List methods, List constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List implementedInterfaces, List permittedSubtypes, Token offset, String fileName) { super(offset); if (isInterface) { modifiers |= Modifier.INTERFACE | Modifier.ABSTRACT; @@ -51,6 +53,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope { this.permittedSubtypes = permittedSubtypes; this.methods = methods; this.constructors = constructors; + this.fileName = fileName; } /* @@ -70,6 +73,11 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope { this.implementedInterfaces = cl.implementedInterfaces; this.methods = new ArrayList<>(cl.methods); this.constructors = new ArrayList<>(cl.constructors); + this.fileName = cl.fileName; + } + + public String getFileName() { + return fileName; } public Optional getField(String name) { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/Record.java b/src/main/java/de/dhbwstuttgart/syntaxtree/Record.java index ee93f32e..8fe6258d 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/Record.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/Record.java @@ -13,7 +13,7 @@ import javax.swing.text.html.Option; public class Record extends ClassOrInterface { - public Record(int modifiers, JavaClassName name, List fielddecl, Optional fieldInitializations, Optional staticInitializer, List methods, List constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, List implementedInterfaces, Token offset) { - super(modifiers, name, fielddecl, fieldInitializations, staticInitializer, methods, constructors, genericClassParameters, superClass, isInterface, methods.size() == 1 ? true : false, implementedInterfaces, new ArrayList<>(), offset); + public Record(int modifiers, JavaClassName name, List fielddecl, Optional fieldInitializations, Optional staticInitializer, List methods, List constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, List implementedInterfaces, Token offset, String fileName) { + super(modifiers, name, fielddecl, fieldInitializations, staticInitializer, methods, constructors, genericClassParameters, superClass, isInterface, methods.size() == 1 ? true : false, implementedInterfaces, new ArrayList<>(), offset, fileName); } } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 308cf9a2..27ac8dbb 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -148,7 +148,7 @@ public class ASTFactory { Token offset = new NullToken(); // Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde - var cinf = new ClassOrInterface(modifier, name, felder, Optional.empty() /* eingefuegt PL 2018-11-24 */, Optional.empty(), methoden, konstruktoren, genericDeclarationList, superClass, isInterface, isFunctionalInterface, implementedInterfaces, permittedSubtypes, offset); + var cinf = new ClassOrInterface(modifier, name, felder, Optional.empty() /* eingefuegt PL 2018-11-24 */, Optional.empty(), methoden, konstruktoren, genericDeclarationList, superClass, isInterface, isFunctionalInterface, implementedInterfaces, permittedSubtypes, offset, null); cache.put(jreClass, cinf); return cinf; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 785ef52a..4037d2f4 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -8,6 +8,7 @@ import java.util.stream.Collectors; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.parser.SourceLoc; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; @@ -42,19 +43,19 @@ public class UnifyTypeFactory { return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses, classLoader), logFile); } - public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr, Token location){ + public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr, SourceLoc location){ return new UnifyPair(tl, tr, PairOperator.SMALLER, location); } - public static UnifyPair generateSmallerDotPair(UnifyType tl, UnifyType tr, Token location){ + public static UnifyPair generateSmallerDotPair(UnifyType tl, UnifyType tr, SourceLoc location){ return new UnifyPair(tl, tr, PairOperator.SMALLERDOT, location); } - public static UnifyPair generateSmallNotEqualDotPair(UnifyType tl, UnifyType tr, Token location){ + public static UnifyPair generateSmallNotEqualDotPair(UnifyType tl, UnifyType tr, SourceLoc location){ return new UnifyPair(tl, tr, PairOperator.SMALLERNEQDOT, location); } - public static UnifyPair generateEqualDotPair(UnifyType tl, UnifyType tr, Token location){ + public static UnifyPair generateEqualDotPair(UnifyType tl, UnifyType tr, SourceLoc location){ return new UnifyPair(tl, tr, PairOperator.EQUALSDOT, location); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java index 8cfb2e8e..e58aa96b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java @@ -22,7 +22,7 @@ import java.util.Optional; public class FunNClass extends ClassOrInterface { public FunNClass(List funNParams) { - super(0, new JavaClassName("Fun" + (funNParams.size() - 1)), new ArrayList<>(), Optional.empty(), Optional.empty() /* eingefuegt PL 2018-11-24 */, createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams), ASTFactory.createObjectType(), true, false, new ArrayList<>(), new ArrayList<>(), new NullToken()); + super(0, new JavaClassName("Fun" + (funNParams.size() - 1)), new ArrayList<>(), Optional.empty(), Optional.empty() /* eingefuegt PL 2018-11-24 */, createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams), ASTFactory.createObjectType(), true, false, new ArrayList<>(), new ArrayList<>(), new NullToken(), null); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java index 2a4fac90..a485ba5e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.parser.SourceLoc; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; @@ -15,7 +16,7 @@ public class Pair implements Serializable public final RefTypeOrTPHOrWildcardOrGeneric TA1; public final RefTypeOrTPHOrWildcardOrGeneric TA2; - private Token location; + private SourceLoc location; private PairOperator eOperator = PairOperator.SMALLER; private Boolean noUnification = false; @@ -37,7 +38,7 @@ public class Pair implements Serializable this.eOperator = eOp; } - public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator e0p, Token location) { + public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator e0p, SourceLoc location) { this(TA1, TA2, e0p); this.location = location; } @@ -50,7 +51,7 @@ public class Pair implements Serializable this.noUnification = noUnification; } - public Token getLocation() { + public SourceLoc getLocation() { return this.location; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index a21aba1d..b65664e1 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -7,6 +7,7 @@ import java.util.stream.Collectors; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.parser.SourceLoc; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.*; @@ -28,6 +29,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.GenericsResolver; import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import org.antlr.v4.runtime.Token; public class TYPEStmt implements StatementVisitor { @@ -43,6 +45,10 @@ public class TYPEStmt implements StatementVisitor { return constraintsSet; } + private SourceLoc loc(Token token) { + return new SourceLoc(info.getCurrentClass().getFileName(), token.getLine()); + }; + /** * Erstellt einen neuen GenericResolver Die Idee dieser Datenstruktur ist es, GTVs einen eindeutigen TPH zuzuweisen. Bei Methodenaufrufen oder anderen Zugriffen, bei denen alle benutzten GTVs jeweils einen einheitlichen TPH bekommen müssen kann diese Klasse eingesetzt werden. Wichtig ist, dass hierfür jeweils eine frische Instanz benutzt wird. * @@ -71,8 +77,8 @@ public class TYPEStmt implements StatementVisitor { // lambdaParams.add(0,tphRetType); constraintsSet.addUndConstraint(new Pair(lambdaExpression.getType(), new RefType(new JavaClassName("Fun" + (lambdaParams.size() - 1) + "$$"), lambdaParams, new NullToken()), // new FunN(lambdaParams), - PairOperator.EQUALSDOT, lambdaExpression.getOffset())); - constraintsSet.addUndConstraint(new Pair(lambdaExpression.getReturnType(), tphRetType, PairOperator.EQUALSDOT, lambdaExpression.getOffset())); + PairOperator.EQUALSDOT, loc(lambdaExpression.getOffset()))); + constraintsSet.addUndConstraint(new Pair(lambdaExpression.getReturnType(), tphRetType, PairOperator.EQUALSDOT, loc(lambdaExpression.getOffset()))); // Constraints des Bodys generieren: TYPEStmt lambdaScope = new TYPEStmt(new TypeInferenceBlockInformation(info, lambdaExpression)); @@ -84,7 +90,7 @@ public class TYPEStmt implements StatementVisitor { public void visit(Assign assign) { assign.lefSide.accept(this); assign.rightSide.accept(this); - constraintsSet.addUndConstraint(new Pair(assign.rightSide.getType(), assign.lefSide.getType(), PairOperator.SMALLERDOT, assign.getOffset())); + constraintsSet.addUndConstraint(new Pair(assign.rightSide.getType(), assign.lefSide.getType(), PairOperator.SMALLERDOT, loc(assign.getOffset()))); } @Override @@ -111,8 +117,8 @@ public class TYPEStmt implements StatementVisitor { for (FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)) { Constraint constraint = new Constraint(); GenericsResolver resolver = getResolverInstance(); - constraint.add(new Pair(fieldVar.receiver.getType(), fieldAssumption.getReceiverType(resolver), PairOperator.SMALLERDOT, fieldVar.getOffset())); // PL 2019-12-09: SMALLERDOT eingefuegt, EQUALSDOT entfernt, wenn ds Field privat ist muesste es EQUALSDOT lauten - constraint.add(new Pair(fieldVar.getType(), fieldAssumption.getType(resolver), PairOperator.EQUALSDOT, fieldVar.getOffset())); + constraint.add(new Pair(fieldVar.receiver.getType(), fieldAssumption.getReceiverType(resolver), PairOperator.SMALLERDOT, loc(fieldVar.getOffset()))); // PL 2019-12-09: SMALLERDOT eingefuegt, EQUALSDOT entfernt, wenn ds Field privat ist muesste es EQUALSDOT lauten + constraint.add(new Pair(fieldVar.getType(), fieldAssumption.getType(resolver), PairOperator.EQUALSDOT, loc(fieldVar.getOffset()))); oderConstraints.add(constraint); } if (oderConstraints.size() == 0) @@ -131,7 +137,7 @@ public class TYPEStmt implements StatementVisitor { @Override public void visit(ForEachStmt forEachStmt) { var iterableType = new RefType(ASTFactory.createClass(java.lang.Iterable.class).getClassName(), Arrays.asList(forEachStmt.statement.getType()), new NullToken()); - constraintsSet.addUndConstraint(new Pair(forEachStmt.expression.getType(), iterableType, PairOperator.SMALLERDOT, forEachStmt.getOffset())); + constraintsSet.addUndConstraint(new Pair(forEachStmt.expression.getType(), iterableType, PairOperator.SMALLERDOT, loc(forEachStmt.getOffset()))); forEachStmt.statement.accept(this); forEachStmt.expression.accept(this); forEachStmt.block.accept(this); @@ -143,14 +149,14 @@ public class TYPEStmt implements StatementVisitor { // Expression inferieren: ifStmt.expr.accept(this); // Expression muss boolean sein: - constraintsSet.addUndConstraint(new Pair(ifStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT, ifStmt.getOffset())); + constraintsSet.addUndConstraint(new Pair(ifStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT, loc(ifStmt.getOffset()))); // Blöcke inferieren: ifStmt.then_block.accept(this); // Beide Blöcke müssen den gleichen Supertyp haben, welcher den Rückgabetyp des If-Stmts darstellt //constraintsSet.addUndConstraint(new Pair(ifStmt.else_block.getType(), ifStmt.getType(), PairOperator.SMALLERDOT)); if (ifStmt.else_block != null) { ifStmt.else_block.accept(this); - constraintsSet.addUndConstraint(new Pair(ifStmt.else_block.getType(), ifStmt.getType(), PairOperator.SMALLERDOT, ifStmt.getOffset())); + constraintsSet.addUndConstraint(new Pair(ifStmt.else_block.getType(), ifStmt.getType(), PairOperator.SMALLERDOT, loc(ifStmt.getOffset()))); } } @@ -234,9 +240,9 @@ public class TYPEStmt implements StatementVisitor { if (unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT || unaryExpr.operation == UnaryExpr.Operation.POSTINCREMENT || unaryExpr.operation == UnaryExpr.Operation.PREDECREMENT || unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT) { // @see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2 // Expression muss zu Numeric Convertierbar sein. also von Numeric erben - constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERNEQDOT, unaryExpr.getOffset())); + constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERNEQDOT, loc(unaryExpr.getOffset()))); // The type of the postfix increment expression is the type of the variable - constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT, unaryExpr.getOffset())); + constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT, loc(unaryExpr.getOffset()))); } else { throw new NotImplementedException(); } @@ -263,49 +269,49 @@ public class TYPEStmt implements StatementVisitor { // PL eingefuegt 2018-07-17 if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(bytee.getName())) { numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT, binary.getOffset())); + numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT, loc(binary.getOffset()))); numericAdditionOrStringConcatenation.add(numeric); } // PL eingefuegt 2018-07-17 if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(shortt.getName())) { numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT, binary.getOffset())); + numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT, loc(binary.getOffset()))); numericAdditionOrStringConcatenation.add(numeric); } // PL eingefuegt 2018-07-17 if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(integer.getName())) { numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(integer, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset())); + numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(integer, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset()))); numericAdditionOrStringConcatenation.add(numeric); } // PL eingefuegt 2018-07-17 if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(longg.getName())) { numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(longg, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset())); + numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(longg, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset()))); numericAdditionOrStringConcatenation.add(numeric); } // PL eingefuegt 2018-07-17 if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(floatt.getName())) { numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(floatt, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset())); + numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(floatt, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset()))); numericAdditionOrStringConcatenation.add(numeric); } // PL eingefuegt 2018-07-17 if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(doublee.getName())) { numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT, binary.getOffset())); - numeric.add(new Pair(doublee, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset())); + numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT, loc(binary.getOffset()))); + numeric.add(new Pair(doublee, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset()))); numericAdditionOrStringConcatenation.add(numeric); } /* @@ -318,9 +324,9 @@ public class TYPEStmt implements StatementVisitor { // Dann kann der Ausdruck auch das aneinanderfügen zweier Strings sein: ("a" + "b") oder (1 + 2) if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(string.getName())) { Constraint stringConcat = new Constraint<>(); - stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT, binary.getOffset())); - stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT, binary.getOffset())); - stringConcat.add(new Pair(string, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset())); + stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT, loc(binary.getOffset()))); + stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT, loc(binary.getOffset()))); + stringConcat.add(new Pair(string, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset()))); numericAdditionOrStringConcatenation.add(stringConcat); } } @@ -339,10 +345,10 @@ public class TYPEStmt implements StatementVisitor { */ // Testeise eingefuegt PL 2018-05-24 // Hier sollte evtl. noch importe angefragt werden PL 2019-05-07 - constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT, binary.getOffset())); - constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT, binary.getOffset())); + constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT, loc(binary.getOffset()))); + constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT, loc(binary.getOffset()))); // Rückgabetyp ist Boolean - constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset())); + constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset()))); // auskommentiert PL 2018-05-24 // constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT)); @@ -354,7 +360,7 @@ public class TYPEStmt implements StatementVisitor { * Auszug aus https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.21 The equality operators may be used to compare two operands that are convertible (§5.1.8) to numeric type, or two operands of type boolean or Boolean, or two operands that are each of either reference type or the null type. All other cases result in a compile-time error. */ // Der Equals Operator geht mit fast allen Typen, daher werden hier keine Constraints gesetzt - constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset())); + constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset()))); } else { throw new NotImplementedException(); } @@ -363,9 +369,9 @@ public class TYPEStmt implements StatementVisitor { @Override public void visit(BoolExpression expr) { - constraintsSet.addUndConstraint(new Pair(bool, expr.getType(), PairOperator.EQUALSDOT, expr.getOffset())); - constraintsSet.addUndConstraint(new Pair(bool, expr.lexpr.getType(), PairOperator.EQUALSDOT, expr.getOffset())); - constraintsSet.addUndConstraint(new Pair(bool, expr.rexpr.getType(), PairOperator.EQUALSDOT, expr.getOffset())); + constraintsSet.addUndConstraint(new Pair(bool, expr.getType(), PairOperator.EQUALSDOT, loc(expr.getOffset()))); + constraintsSet.addUndConstraint(new Pair(bool, expr.lexpr.getType(), PairOperator.EQUALSDOT, loc(expr.getOffset()))); + constraintsSet.addUndConstraint(new Pair(bool, expr.rexpr.getType(), PairOperator.EQUALSDOT, loc(expr.getOffset()))); // TODO return; @@ -378,23 +384,23 @@ public class TYPEStmt implements StatementVisitor { // wie hier fuer double gezeigt. Im Momment auskommentiert, weil zu wenige Literaltypen // funktionieren if (literal.value instanceof Short) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), shortt, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), shortt, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof Byte) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), bytee, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), bytee, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof Float) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), floatt, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), floatt, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof Double) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), doublee, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), doublee, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof Long) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), longg, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), longg, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof Integer) { @@ -403,31 +409,31 @@ public class TYPEStmt implements StatementVisitor { HashSet clNames = info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)); Set oderConstraints = new HashSet<>(); Constraint constraint = new Constraint(); - constraint.add(new Pair(literal.getType(), integer, PairOperator.EQUALSDOT, literal.getOffset())); + constraint.add(new Pair(literal.getType(), integer, PairOperator.EQUALSDOT, loc(literal.getOffset()))); oderConstraints.add(constraint); if (clNames.stream().filter(x -> x.toString().equals("java.lang.Double")).findAny().isPresent()) { constraint = new Constraint(); - constraint.add(new Pair(literal.getType(), doublee, PairOperator.EQUALSDOT, literal.getOffset())); + constraint.add(new Pair(literal.getType(), doublee, PairOperator.EQUALSDOT, loc(literal.getOffset()))); oderConstraints.add(constraint); } if (clNames.stream().filter(x -> x.toString().equals("java.lang.Long")).findAny().isPresent()) { constraint = new Constraint(); - constraint.add(new Pair(literal.getType(), longg, PairOperator.EQUALSDOT, literal.getOffset())); + constraint.add(new Pair(literal.getType(), longg, PairOperator.EQUALSDOT, loc(literal.getOffset()))); oderConstraints.add(constraint); } if (clNames.stream().filter(x -> x.toString().equals("java.lang.Float")).findAny().isPresent()) { constraint = new Constraint(); - constraint.add(new Pair(literal.getType(), floatt, PairOperator.EQUALSDOT, literal.getOffset())); + constraint.add(new Pair(literal.getType(), floatt, PairOperator.EQUALSDOT, loc(literal.getOffset()))); oderConstraints.add(constraint); } if (clNames.stream().filter(x -> x.toString().equals("java.lang.Short")).findAny().isPresent()) { constraint = new Constraint(); - constraint.add(new Pair(literal.getType(), shortt, PairOperator.EQUALSDOT, literal.getOffset())); + constraint.add(new Pair(literal.getType(), shortt, PairOperator.EQUALSDOT, loc(literal.getOffset()))); oderConstraints.add(constraint); } if (clNames.stream().filter(x -> x.toString().equals("java.lang.Byte")).findAny().isPresent()) { constraint = new Constraint(); - constraint.add(new Pair(literal.getType(), bytee, PairOperator.EQUALSDOT, literal.getOffset())); + constraint.add(new Pair(literal.getType(), bytee, PairOperator.EQUALSDOT, loc(literal.getOffset()))); oderConstraints.add(constraint); } constraintsSet.addOderConstraint(oderConstraints); @@ -435,27 +441,27 @@ public class TYPEStmt implements StatementVisitor { return; } if (literal.value instanceof Short) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), shortt, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), shortt, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof Byte) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), bytee, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), bytee, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof Float) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), floatt, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), floatt, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof String) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), string, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), string, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof Boolean) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), bool, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), bool, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value instanceof Character) { - constraintsSet.addUndConstraint(new Pair(literal.getType(), charr, PairOperator.EQUALSDOT, literal.getOffset())); + constraintsSet.addUndConstraint(new Pair(literal.getType(), charr, PairOperator.EQUALSDOT, loc(literal.getOffset()))); return; } if (literal.value != null) { @@ -471,7 +477,7 @@ public class TYPEStmt implements StatementVisitor { @Override public void visit(Return returnExpr) { returnExpr.retexpr.accept(this); - constraintsSet.addUndConstraint(new Pair(returnExpr.getType(), info.getCurrentTypeScope().getReturnType(), PairOperator.SMALLERDOT, returnExpr.getOffset())); + constraintsSet.addUndConstraint(new Pair(returnExpr.getType(), info.getCurrentTypeScope().getReturnType(), PairOperator.SMALLERDOT, loc(returnExpr.getOffset()))); } @Override @@ -503,7 +509,7 @@ public class TYPEStmt implements StatementVisitor { params.add(new GenericRefType(gtv.getName(), aThis.getOffset())); } RefType thisType = new RefType(currentClass.getClassName(), params, aThis.getOffset()); - constraintsSet.addUndConstraint(new Pair(aThis.getType(), thisType, PairOperator.EQUALSDOT, aThis.getOffset())); + constraintsSet.addUndConstraint(new Pair(aThis.getType(), thisType, PairOperator.EQUALSDOT, loc(aThis.getOffset()))); } private static TypeScope createNullTypeScope() { @@ -526,7 +532,7 @@ public class TYPEStmt implements StatementVisitor { // Expression inferieren: whileStmt.expr.accept(this); // Expression muss boolean sein: - constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT, whileStmt.expr.getOffset())); + constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT, loc(whileStmt.expr.getOffset()))); // LoopBlock inferieren: whileStmt.loopBlock.accept(this); } @@ -586,10 +592,10 @@ public class TYPEStmt implements StatementVisitor { RefTypeOrTPHOrWildcardOrGeneric receiverType = assumption.getReceiverType(resolver); if (receiverType != null) { - methodConstraint.add(new Pair(forMethod.receiver.getType(), receiverType, PairOperator.EQUALSDOT, forMethod.getOffset()));// PL 2020-03-17 SMALLERDOT in EQUALSDOT umgewandelt, weil alle geerbten Methoden in den jeweilen Klassen enthalten sind. + methodConstraint.add(new Pair(forMethod.receiver.getType(), receiverType, PairOperator.EQUALSDOT, loc(forMethod.getOffset())));// PL 2020-03-17 SMALLERDOT in EQUALSDOT umgewandelt, weil alle geerbten Methoden in den jeweilen Klassen enthalten sind. // PL 2023-01-24: dafuer ? extends receiverType noch ergaenzt - extendsMethodConstraint.add(new Pair(forMethod.receiver.getType(), new ExtendsWildcardType(receiverType, receiverType.getOffset()), PairOperator.EQUALSDOT, forMethod.getOffset())); + extendsMethodConstraint.add(new Pair(forMethod.receiver.getType(), new ExtendsWildcardType(receiverType, receiverType.getOffset()), PairOperator.EQUALSDOT, loc(forMethod.getOffset()))); } // gegenseite Verschraenkung der beiden Mengen von Typannahmen @@ -601,8 +607,8 @@ public class TYPEStmt implements StatementVisitor { // PairOperator.EQUALSDOT)); // Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE - methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.SMALLERDOT, forMethod.getOffset())); - extendsMethodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.SMALLERDOT, forMethod.getOffset())); + methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.SMALLERDOT, loc(forMethod.getOffset()))); + extendsMethodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.SMALLERDOT, loc(forMethod.getOffset()))); // methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT)); // extendsMethodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT)); @@ -635,7 +641,7 @@ public class TYPEStmt implements StatementVisitor { RefTypeOrTPHOrWildcardOrGeneric argType = foMethod.arglist.getArguments().get(i).getType(); RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i); - ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT, foMethod.getOffset())); + ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT, loc(foMethod.getOffset()))); // Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG // ret.add(new Pair(foMethod.argTypes.get(i), assType, PairOperator.EQUALSDOT)); @@ -729,7 +735,7 @@ public class TYPEStmt implements StatementVisitor { Constraint methodConstraint = new Constraint(); // WELCHEN SINN MACHT DIESER CONSTRAINT??? // Ist er nicht immer classname <. classname und damit redundant? - methodConstraint.add(new Pair(assumption.getReturnType(resolver), forConstructor.getType(), PairOperator.SMALLERDOT, forConstructor.getOffset())); + methodConstraint.add(new Pair(assumption.getReturnType(resolver), forConstructor.getType(), PairOperator.SMALLERDOT, loc(forConstructor.getOffset()))); // WELCHEN SINN MACHT DIESER CONSTRAINT??? methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver)); return methodConstraint; @@ -753,17 +759,17 @@ public class TYPEStmt implements StatementVisitor { for (var child : switchStmt.getBlocks()) { for (var label : child.getLabels()) { if (label.getPattern() instanceof FormalParameter) { - constraintsSet.addUndConstraint(new Pair(label.getPattern().getType(), switchStmt.getSwitch().getType(), PairOperator.SMALLERDOT, label.getOffset())); + constraintsSet.addUndConstraint(new Pair(label.getPattern().getType(), switchStmt.getSwitch().getType(), PairOperator.SMALLERDOT, loc(label.getOffset()))); } } } } else { - constraintsSet.addUndConstraint(new Pair(caseExpressionType, switchStmt.getSwitch().getType(), PairOperator.EQUALSDOT, switchStmt.getSwitch().getOffset())); + constraintsSet.addUndConstraint(new Pair(caseExpressionType, switchStmt.getSwitch().getType(), PairOperator.EQUALSDOT, loc(switchStmt.getSwitch().getOffset()))); } for (var child : switchStmt.getBlocks()) { child.accept(this); - constraintsSet.addUndConstraint(new Pair(child.getType(), switchStmt.getType(), PairOperator.SMALLERDOT, switchStmt.getOffset())); + constraintsSet.addUndConstraint(new Pair(child.getType(), switchStmt.getType(), PairOperator.SMALLERDOT, loc(switchStmt.getOffset()))); } switchStack.pop(); @@ -784,7 +790,7 @@ public class TYPEStmt implements StatementVisitor { @Override public void visit(Yield aYield) { aYield.retexpr.accept(this); - constraintsSet.addUndConstraint(new Pair(aYield.getType(), switchStack.peek().getType(), PairOperator.EQUALSDOT, aYield.getOffset())); + constraintsSet.addUndConstraint(new Pair(aYield.getType(), switchStack.peek().getType(), PairOperator.EQUALSDOT, loc(aYield.getOffset()))); // TODO Auto-generated method stub } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java index 5868f0ea..dea9e53a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference.unify.interfaces; import java.util.Optional; import java.util.Set; +import de.dhbwstuttgart.parser.SourceLoc; import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; import de.dhbwstuttgart.typeinference.unify.model.FunNType; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; @@ -32,7 +33,7 @@ public interface IFiniteClosure { * Returns all types of the finite closure that are supertypes of the argument. * @return The set of supertypes of the argument. */ - public Set greater(UnifyType type, Set fBounded, Token position); + public Set greater(UnifyType type, Set fBounded, SourceLoc position); public default Set greater(UnifyType type, Set fBounded) { return this.greater(type, fBounded, null); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index f5671686..f4c8ab24 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -20,6 +20,7 @@ import com.google.common.collect.Ordering; //PL 18-02-05/18-04-05 Unifier durch Matcher ersetzt //muss greater noch ersetzt werden ja erledigt 18--04-05 +import de.dhbwstuttgart.parser.SourceLoc; import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify; import de.dhbwstuttgart.typeinference.unify.Match; @@ -261,7 +262,7 @@ implements IFiniteClosure { */ @Override //Eingefuegt PL 2018-05-24 F-Bounded Problematik - public Set greater(UnifyType type, Set fBounded, Token location) { + public Set greater(UnifyType type, Set fBounded, SourceLoc location) { Set ret; if ((ret = greaterHash.get(new hashKeyType(type))) != null) { //System.out.println(greaterHash); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 5df521cb..4c5a4f8c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.unify.model; import com.google.common.collect.ObjectArrays; +import de.dhbwstuttgart.parser.SourceLoc; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import org.antlr.v4.runtime.Token; @@ -18,8 +19,8 @@ import java.util.Set; */ public class UnifyPair { - private Token location; - + private SourceLoc location; + /** * The type on the left hand side of the pair. */ @@ -74,7 +75,7 @@ public class UnifyPair { hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); } - public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Token location) { + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, SourceLoc location) { this(lhs, rhs, op); this.location = location; } @@ -87,20 +88,20 @@ public class UnifyPair { this(lhs, rhs, op, uni, base, fBounded, null); } - public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base, Set fBounded, Token location) { + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base, Set fBounded, SourceLoc location) { this.lhs = lhs; this.rhs = rhs; pairOp = op; substitution = uni; basePair = base; this.location = location; - this.fBounded = fBounded; + //this.fBounded = fBounded; // what? // Caching hashcode hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); } - public Token getLocation() { + public SourceLoc getLocation() { if (location != null) return location; else if (basePair != null) return basePair.getLocation(); return null; @@ -254,7 +255,7 @@ public class UnifyPair { var res = "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])"; var location = this.getLocation(); if (location != null) { - res += "@" + location.getLine(); + res += "@" + location.line() + " in " + location.file(); } return res; diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index ff857464..dc15ec80 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -834,4 +834,11 @@ public class TestComplete { var instance = clazz.getDeclaredConstructor().newInstance(); assertEquals(clazz.getSuperclass().getDeclaredField("x").get(instance), 3); } + + @Test + public void testStringConcat() throws Exception { + var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Op2.jav"); + var clazz = classFiles.get("Op2"); + var instance = clazz.getDeclaredConstructor().newInstance(); + } } diff --git a/src/test/java/targetast/ASTToTypedTargetAST.java b/src/test/java/targetast/ASTToTypedTargetAST.java index b1389f0f..ae67c9cd 100644 --- a/src/test/java/targetast/ASTToTypedTargetAST.java +++ b/src/test/java/targetast/ASTToTypedTargetAST.java @@ -22,7 +22,7 @@ public class ASTToTypedTargetAST { @Test public void emptyClass() { - ClassOrInterface emptyClass = new ClassOrInterface(0, new JavaClassName("EmptyClass"), new ArrayList<>(), Optional.empty(), Optional.empty(), new ArrayList<>(), new ArrayList<>(), new GenericDeclarationList(new ArrayList<>(), new NullToken()), new RefType(new JavaClassName("Object"), new NullToken()), false, false, new ArrayList<>(), new ArrayList<>(), new NullToken()); + ClassOrInterface emptyClass = new ClassOrInterface(0, new JavaClassName("EmptyClass"), new ArrayList<>(), Optional.empty(), Optional.empty(), new ArrayList<>(), new ArrayList<>(), new GenericDeclarationList(new ArrayList<>(), new NullToken()), new RefType(new JavaClassName("Object"), new NullToken()), false, false, new ArrayList<>(), new ArrayList<>(), new NullToken(), null); ResultSet emptyResultSet = new ResultSet(new HashSet<>()); TargetStructure emptyTargetClass = new ASTToTargetAST(List.of(emptyResultSet)).convert(emptyClass); assert emptyTargetClass.getName().equals("EmptyClass");