forked from JavaTX/JavaCompilerCore
Add filename to debug output, closes #126
This commit is contained in:
parent
9c6372c3ba
commit
584690596e
@ -1,11 +1,17 @@
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
|
import java.lang.Double;
|
||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
|
|
||||||
public class Op2 {
|
public class Op2 {
|
||||||
m(){
|
m(){
|
||||||
var x = "";
|
//var x = "";
|
||||||
var a = 5+x;
|
//var a = 5+x;
|
||||||
|
|
||||||
|
Integer x = 10;
|
||||||
|
Double y = 10.5;
|
||||||
|
|
||||||
|
var a = x - y;
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -651,7 +651,7 @@ public class JavaTXCompiler {
|
|||||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||||
SourceFileContext tree = JavaTXParser.parse(sourceFile);
|
SourceFileContext tree = JavaTXParser.parse(sourceFile);
|
||||||
environment.addClassesToRegistry(classRegistry, tree, sourceFile, this);
|
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<ClassOrInterface>();
|
var classes = new ArrayList<ClassOrInterface>();
|
||||||
var sf = new SourceFile(generator.pkgName, classes, generator.imports);
|
var sf = new SourceFile(generator.pkgName, classes, generator.imports);
|
||||||
addSourceFile(sourceFile, sf);
|
addSourceFile(sourceFile, sf);
|
||||||
@ -672,7 +672,7 @@ public class JavaTXCompiler {
|
|||||||
var tree = JavaTXParser.parse(file);
|
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?
|
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);
|
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<ClassOrInterface>();
|
var classes = new ArrayList<ClassOrInterface>();
|
||||||
var sf = new SourceFile(generator.pkgName, classes, generator.imports);
|
var sf = new SourceFile(generator.pkgName, classes, generator.imports);
|
||||||
addSourceFile(file, sf);
|
addSourceFile(file, sf);
|
||||||
|
4
src/main/java/de/dhbwstuttgart/parser/SourceLoc.java
Normal file
4
src/main/java/de/dhbwstuttgart/parser/SourceLoc.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package de.dhbwstuttgart.parser;
|
||||||
|
|
||||||
|
public record SourceLoc(String file, int line) {
|
||||||
|
}
|
@ -92,7 +92,9 @@ public class SyntaxTreeGenerator {
|
|||||||
private final JavaTXCompiler compiler;
|
private final JavaTXCompiler compiler;
|
||||||
private RefType superClass;
|
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,
|
// Die Generics müssen während des Bauens des AST erstellt werden,
|
||||||
// da diese mit der Methode oder Klasse, in welcher sie deklariert 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
|
// 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.allmodifiers.put("strictfp", 32768);
|
||||||
|
|
||||||
this.compiler = compiler;
|
this.compiler = compiler;
|
||||||
|
this.fileName = fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaClassRegistry getReg() {
|
public JavaClassRegistry getReg() {
|
||||||
@ -226,7 +229,7 @@ public class SyntaxTreeGenerator {
|
|||||||
}
|
}
|
||||||
var ctor = Optional.of(this.generatePseudoConstructor(ctx.identifier().getText(), fieldInitializations, genericClassParameters, offset));
|
var ctor = Optional.of(this.generatePseudoConstructor(ctx.identifier().getText(), fieldInitializations, genericClassParameters, offset));
|
||||||
var staticCtor = Optional.of(this.generateStaticConstructor(ctx.identifier().getText(), staticFieldInitializations, 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));
|
implementedInterfaces.addAll(convert(recordDeclaration.typeList(), generics));
|
||||||
}
|
}
|
||||||
var staticCtor = Optional.of(this.generateStaticConstructor(recordDeclaration.identifier().getText(), staticFieldInitializations, genericClassParameters, offset));
|
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<Field> fields, List<Constructor> constructors, List<Method> methods, JavaClassName name, RefType superClass, GenericsRegistry generics) {
|
private void convert(ClassBodyDeclarationContext classBody, List<Field> fields, List<Constructor> constructors, List<Method> 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()));
|
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) {
|
private GenericDeclarationList createEmptyGenericDeclarationList(Token classNameIdentifier) {
|
||||||
|
@ -21,6 +21,8 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
private Boolean methodAdded = false; // wird benoetigt bei in JavaTXCompiler.getConstraints()
|
private Boolean methodAdded = false; // wird benoetigt bei in JavaTXCompiler.getConstraints()
|
||||||
protected int modifiers;
|
protected int modifiers;
|
||||||
protected JavaClassName name;
|
protected JavaClassName name;
|
||||||
|
private final String fileName;
|
||||||
|
|
||||||
private List<Field> fields = new ArrayList<>();
|
private List<Field> fields = new ArrayList<>();
|
||||||
private Optional<Constructor> fieldInitializations; // PL 2018-11-24: Noetig, um Bytecode fuer initializators nur einmal zu erzeugen
|
private Optional<Constructor> fieldInitializations; // PL 2018-11-24: Noetig, um Bytecode fuer initializators nur einmal zu erzeugen
|
||||||
private Optional<Method> staticInitializer;
|
private Optional<Method> staticInitializer;
|
||||||
@ -33,7 +35,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
private List<RefType> permittedSubtypes;
|
private List<RefType> permittedSubtypes;
|
||||||
private List<Constructor> constructors;
|
private List<Constructor> constructors;
|
||||||
|
|
||||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List<RefType> implementedInterfaces, List<RefType> permittedSubtypes, Token offset) {
|
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List<RefType> implementedInterfaces, List<RefType> permittedSubtypes, Token offset, String fileName) {
|
||||||
super(offset);
|
super(offset);
|
||||||
if (isInterface) {
|
if (isInterface) {
|
||||||
modifiers |= Modifier.INTERFACE | Modifier.ABSTRACT;
|
modifiers |= Modifier.INTERFACE | Modifier.ABSTRACT;
|
||||||
@ -51,6 +53,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
this.permittedSubtypes = permittedSubtypes;
|
this.permittedSubtypes = permittedSubtypes;
|
||||||
this.methods = methods;
|
this.methods = methods;
|
||||||
this.constructors = constructors;
|
this.constructors = constructors;
|
||||||
|
this.fileName = fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -70,6 +73,11 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
this.implementedInterfaces = cl.implementedInterfaces;
|
this.implementedInterfaces = cl.implementedInterfaces;
|
||||||
this.methods = new ArrayList<>(cl.methods);
|
this.methods = new ArrayList<>(cl.methods);
|
||||||
this.constructors = new ArrayList<>(cl.constructors);
|
this.constructors = new ArrayList<>(cl.constructors);
|
||||||
|
this.fileName = cl.fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Field> getField(String name) {
|
public Optional<Field> getField(String name) {
|
||||||
|
@ -13,7 +13,7 @@ import javax.swing.text.html.Option;
|
|||||||
|
|
||||||
public class Record extends ClassOrInterface {
|
public class Record extends ClassOrInterface {
|
||||||
|
|
||||||
public Record(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset) {
|
public Record(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, List<RefType> 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);
|
super(modifiers, name, fielddecl, fieldInitializations, staticInitializer, methods, constructors, genericClassParameters, superClass, isInterface, methods.size() == 1 ? true : false, implementedInterfaces, new ArrayList<>(), offset, fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ public class ASTFactory {
|
|||||||
|
|
||||||
Token offset = new NullToken(); // Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde
|
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);
|
cache.put(jreClass, cinf);
|
||||||
return cinf;
|
return cinf;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.SourceLoc;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
@ -42,19 +43,19 @@ public class UnifyTypeFactory {
|
|||||||
return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses, classLoader), logFile);
|
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);
|
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);
|
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);
|
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);
|
return new UnifyPair(tl, tr, PairOperator.EQUALSDOT, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class FunNClass extends ClassOrInterface {
|
public class FunNClass extends ClassOrInterface {
|
||||||
public FunNClass(List<GenericRefType> funNParams) {
|
public FunNClass(List<GenericRefType> 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.SourceLoc;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
@ -15,7 +16,7 @@ public class Pair implements Serializable
|
|||||||
public final RefTypeOrTPHOrWildcardOrGeneric TA1;
|
public final RefTypeOrTPHOrWildcardOrGeneric TA1;
|
||||||
public final RefTypeOrTPHOrWildcardOrGeneric TA2;
|
public final RefTypeOrTPHOrWildcardOrGeneric TA2;
|
||||||
|
|
||||||
private Token location;
|
private SourceLoc location;
|
||||||
|
|
||||||
private PairOperator eOperator = PairOperator.SMALLER;
|
private PairOperator eOperator = PairOperator.SMALLER;
|
||||||
private Boolean noUnification = false;
|
private Boolean noUnification = false;
|
||||||
@ -37,7 +38,7 @@ public class Pair implements Serializable
|
|||||||
this.eOperator = eOp;
|
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(TA1, TA2, e0p);
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
@ -50,7 +51,7 @@ public class Pair implements Serializable
|
|||||||
this.noUnification = noUnification;
|
this.noUnification = noUnification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Token getLocation() {
|
public SourceLoc getLocation() {
|
||||||
return this.location;
|
return this.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import java.util.stream.Collectors;
|
|||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.SourceLoc;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
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.GenericsResolver;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
public class TYPEStmt implements StatementVisitor {
|
public class TYPEStmt implements StatementVisitor {
|
||||||
|
|
||||||
@ -43,6 +45,10 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
return constraintsSet;
|
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.
|
* 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);
|
// lambdaParams.add(0,tphRetType);
|
||||||
constraintsSet.addUndConstraint(new Pair(lambdaExpression.getType(), new RefType(new JavaClassName("Fun" + (lambdaParams.size() - 1) + "$$"), lambdaParams, new NullToken()),
|
constraintsSet.addUndConstraint(new Pair(lambdaExpression.getType(), new RefType(new JavaClassName("Fun" + (lambdaParams.size() - 1) + "$$"), lambdaParams, new NullToken()),
|
||||||
// new FunN(lambdaParams),
|
// new FunN(lambdaParams),
|
||||||
PairOperator.EQUALSDOT, lambdaExpression.getOffset()));
|
PairOperator.EQUALSDOT, loc(lambdaExpression.getOffset())));
|
||||||
constraintsSet.addUndConstraint(new Pair(lambdaExpression.getReturnType(), tphRetType, PairOperator.EQUALSDOT, lambdaExpression.getOffset()));
|
constraintsSet.addUndConstraint(new Pair(lambdaExpression.getReturnType(), tphRetType, PairOperator.EQUALSDOT, loc(lambdaExpression.getOffset())));
|
||||||
|
|
||||||
// Constraints des Bodys generieren:
|
// Constraints des Bodys generieren:
|
||||||
TYPEStmt lambdaScope = new TYPEStmt(new TypeInferenceBlockInformation(info, lambdaExpression));
|
TYPEStmt lambdaScope = new TYPEStmt(new TypeInferenceBlockInformation(info, lambdaExpression));
|
||||||
@ -84,7 +90,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
public void visit(Assign assign) {
|
public void visit(Assign assign) {
|
||||||
assign.lefSide.accept(this);
|
assign.lefSide.accept(this);
|
||||||
assign.rightSide.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
|
@Override
|
||||||
@ -111,8 +117,8 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
for (FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)) {
|
for (FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)) {
|
||||||
Constraint constraint = new Constraint();
|
Constraint constraint = new Constraint();
|
||||||
GenericsResolver resolver = getResolverInstance();
|
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.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, fieldVar.getOffset()));
|
constraint.add(new Pair(fieldVar.getType(), fieldAssumption.getType(resolver), PairOperator.EQUALSDOT, loc(fieldVar.getOffset())));
|
||||||
oderConstraints.add(constraint);
|
oderConstraints.add(constraint);
|
||||||
}
|
}
|
||||||
if (oderConstraints.size() == 0)
|
if (oderConstraints.size() == 0)
|
||||||
@ -131,7 +137,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(ForEachStmt forEachStmt) {
|
public void visit(ForEachStmt forEachStmt) {
|
||||||
var iterableType = new RefType(ASTFactory.createClass(java.lang.Iterable.class).getClassName(), Arrays.asList(forEachStmt.statement.getType()), new NullToken());
|
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.statement.accept(this);
|
||||||
forEachStmt.expression.accept(this);
|
forEachStmt.expression.accept(this);
|
||||||
forEachStmt.block.accept(this);
|
forEachStmt.block.accept(this);
|
||||||
@ -143,14 +149,14 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
// Expression inferieren:
|
// Expression inferieren:
|
||||||
ifStmt.expr.accept(this);
|
ifStmt.expr.accept(this);
|
||||||
// Expression muss boolean sein:
|
// 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:
|
// Blöcke inferieren:
|
||||||
ifStmt.then_block.accept(this);
|
ifStmt.then_block.accept(this);
|
||||||
// Beide Blöcke müssen den gleichen Supertyp haben, welcher den Rückgabetyp des If-Stmts darstellt
|
// 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));
|
//constraintsSet.addUndConstraint(new Pair(ifStmt.else_block.getType(), ifStmt.getType(), PairOperator.SMALLERDOT));
|
||||||
if (ifStmt.else_block != null) {
|
if (ifStmt.else_block != null) {
|
||||||
ifStmt.else_block.accept(this);
|
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) {
|
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
|
// @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
|
// 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
|
// 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 {
|
} else {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -263,49 +269,49 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
// PL eingefuegt 2018-07-17
|
// PL eingefuegt 2018-07-17
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(bytee.getName())) {
|
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(bytee.getName())) {
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT, 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, binary.getOffset()));
|
numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||||
numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT, binary.getOffset()));
|
numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
// PL eingefuegt 2018-07-17
|
// PL eingefuegt 2018-07-17
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(shortt.getName())) {
|
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(shortt.getName())) {
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT, 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, binary.getOffset()));
|
numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||||
numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT, binary.getOffset()));
|
numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
// PL eingefuegt 2018-07-17
|
// PL eingefuegt 2018-07-17
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(integer.getName())) {
|
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(integer.getName())) {
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT, 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, binary.getOffset()));
|
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||||
numeric.add(new Pair(integer, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset()));
|
numeric.add(new Pair(integer, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
// PL eingefuegt 2018-07-17
|
// PL eingefuegt 2018-07-17
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(longg.getName())) {
|
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(longg.getName())) {
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT, 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, binary.getOffset()));
|
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||||
numeric.add(new Pair(longg, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset()));
|
numeric.add(new Pair(longg, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
// PL eingefuegt 2018-07-17
|
// PL eingefuegt 2018-07-17
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(floatt.getName())) {
|
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(floatt.getName())) {
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT, 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, binary.getOffset()));
|
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||||
numeric.add(new Pair(floatt, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset()));
|
numeric.add(new Pair(floatt, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
// PL eingefuegt 2018-07-17
|
// PL eingefuegt 2018-07-17
|
||||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(doublee.getName())) {
|
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(doublee.getName())) {
|
||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT, 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, binary.getOffset()));
|
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||||
numeric.add(new Pair(doublee, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset()));
|
numeric.add(new Pair(doublee, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
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)
|
// 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())) {
|
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(string.getName())) {
|
||||||
Constraint<Pair> stringConcat = new Constraint<>();
|
Constraint<Pair> stringConcat = new Constraint<>();
|
||||||
stringConcat.add(new Pair(binary.lexpr.getType(), string, 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, binary.getOffset()));
|
stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
stringConcat.add(new Pair(string, binary.getType(), PairOperator.EQUALSDOT, binary.getOffset()));
|
stringConcat.add(new Pair(string, binary.getType(), PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||||
numericAdditionOrStringConcatenation.add(stringConcat);
|
numericAdditionOrStringConcatenation.add(stringConcat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,10 +345,10 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
*/
|
*/
|
||||||
// Testeise eingefuegt PL 2018-05-24
|
// Testeise eingefuegt PL 2018-05-24
|
||||||
// Hier sollte evtl. noch importe angefragt werden PL 2019-05-07
|
// 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.lexpr.getType(), number, PairOperator.SMALLERNEQDOT, loc(binary.getOffset())));
|
||||||
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT, binary.getOffset()));
|
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT, loc(binary.getOffset())));
|
||||||
// Rückgabetyp ist Boolean
|
// 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
|
// auskommentiert PL 2018-05-24
|
||||||
// constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT));
|
// 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.
|
* 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
|
// 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 {
|
} else {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -363,9 +369,9 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(BoolExpression expr) {
|
public void visit(BoolExpression expr) {
|
||||||
|
|
||||||
constraintsSet.addUndConstraint(new Pair(bool, expr.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, 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, expr.getOffset()));
|
constraintsSet.addUndConstraint(new Pair(bool, expr.rexpr.getType(), PairOperator.EQUALSDOT, loc(expr.getOffset())));
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
return;
|
return;
|
||||||
@ -378,23 +384,23 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
// wie hier fuer double gezeigt. Im Momment auskommentiert, weil zu wenige Literaltypen
|
// wie hier fuer double gezeigt. Im Momment auskommentiert, weil zu wenige Literaltypen
|
||||||
// funktionieren
|
// funktionieren
|
||||||
if (literal.value instanceof Short) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Byte) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Float) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Double) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Long) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Integer) {
|
if (literal.value instanceof Integer) {
|
||||||
@ -403,31 +409,31 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
HashSet<JavaClassName> clNames = info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new));
|
HashSet<JavaClassName> clNames = info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new));
|
||||||
Set<Constraint> oderConstraints = new HashSet<>();
|
Set<Constraint> oderConstraints = new HashSet<>();
|
||||||
Constraint constraint = new Constraint();
|
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);
|
oderConstraints.add(constraint);
|
||||||
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Double")).findAny().isPresent()) {
|
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Double")).findAny().isPresent()) {
|
||||||
constraint = new Constraint();
|
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);
|
oderConstraints.add(constraint);
|
||||||
}
|
}
|
||||||
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Long")).findAny().isPresent()) {
|
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Long")).findAny().isPresent()) {
|
||||||
constraint = new Constraint();
|
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);
|
oderConstraints.add(constraint);
|
||||||
}
|
}
|
||||||
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Float")).findAny().isPresent()) {
|
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Float")).findAny().isPresent()) {
|
||||||
constraint = new Constraint();
|
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);
|
oderConstraints.add(constraint);
|
||||||
}
|
}
|
||||||
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Short")).findAny().isPresent()) {
|
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Short")).findAny().isPresent()) {
|
||||||
constraint = new Constraint();
|
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);
|
oderConstraints.add(constraint);
|
||||||
}
|
}
|
||||||
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Byte")).findAny().isPresent()) {
|
if (clNames.stream().filter(x -> x.toString().equals("java.lang.Byte")).findAny().isPresent()) {
|
||||||
constraint = new Constraint();
|
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);
|
oderConstraints.add(constraint);
|
||||||
}
|
}
|
||||||
constraintsSet.addOderConstraint(oderConstraints);
|
constraintsSet.addOderConstraint(oderConstraints);
|
||||||
@ -435,27 +441,27 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Short) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Byte) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Float) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof String) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Boolean) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Character) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value != null) {
|
if (literal.value != null) {
|
||||||
@ -471,7 +477,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Return returnExpr) {
|
public void visit(Return returnExpr) {
|
||||||
returnExpr.retexpr.accept(this);
|
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
|
@Override
|
||||||
@ -503,7 +509,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
params.add(new GenericRefType(gtv.getName(), aThis.getOffset()));
|
params.add(new GenericRefType(gtv.getName(), aThis.getOffset()));
|
||||||
}
|
}
|
||||||
RefType thisType = new RefType(currentClass.getClassName(), params, 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() {
|
private static TypeScope createNullTypeScope() {
|
||||||
@ -526,7 +532,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
// Expression inferieren:
|
// Expression inferieren:
|
||||||
whileStmt.expr.accept(this);
|
whileStmt.expr.accept(this);
|
||||||
// Expression muss boolean sein:
|
// 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:
|
// LoopBlock inferieren:
|
||||||
whileStmt.loopBlock.accept(this);
|
whileStmt.loopBlock.accept(this);
|
||||||
}
|
}
|
||||||
@ -586,10 +592,10 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric receiverType = assumption.getReceiverType(resolver);
|
RefTypeOrTPHOrWildcardOrGeneric receiverType = assumption.getReceiverType(resolver);
|
||||||
if (receiverType != null) {
|
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
|
// 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
|
// gegenseite Verschraenkung der beiden Mengen von Typannahmen
|
||||||
@ -601,8 +607,8 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
// PairOperator.EQUALSDOT));
|
// PairOperator.EQUALSDOT));
|
||||||
// Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
// Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||||
|
|
||||||
methodConstraint.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, 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));
|
// methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT));
|
||||||
// extendsMethodConstraint.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 argType = foMethod.arglist.getArguments().get(i).getType();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i);
|
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
|
// Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG
|
||||||
// ret.add(new Pair(foMethod.argTypes.get(i), assType, PairOperator.EQUALSDOT));
|
// ret.add(new Pair(foMethod.argTypes.get(i), assType, PairOperator.EQUALSDOT));
|
||||||
@ -729,7 +735,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
Constraint methodConstraint = new Constraint();
|
Constraint methodConstraint = new Constraint();
|
||||||
// WELCHEN SINN MACHT DIESER CONSTRAINT???
|
// WELCHEN SINN MACHT DIESER CONSTRAINT???
|
||||||
// Ist er nicht immer classname <. classname und damit redundant?
|
// 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???
|
// WELCHEN SINN MACHT DIESER CONSTRAINT???
|
||||||
methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver));
|
methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver));
|
||||||
return methodConstraint;
|
return methodConstraint;
|
||||||
@ -753,17 +759,17 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
for (var child : switchStmt.getBlocks()) {
|
for (var child : switchStmt.getBlocks()) {
|
||||||
for (var label : child.getLabels()) {
|
for (var label : child.getLabels()) {
|
||||||
if (label.getPattern() instanceof FormalParameter) {
|
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 {
|
} 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()) {
|
for (var child : switchStmt.getBlocks()) {
|
||||||
child.accept(this);
|
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();
|
switchStack.pop();
|
||||||
@ -784,7 +790,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Yield aYield) {
|
public void visit(Yield aYield) {
|
||||||
aYield.retexpr.accept(this);
|
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
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference.unify.interfaces;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.SourceLoc;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
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.
|
* Returns all types of the finite closure that are supertypes of the argument.
|
||||||
* @return The set of supertypes of the argument.
|
* @return The set of supertypes of the argument.
|
||||||
*/
|
*/
|
||||||
public Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded, Token position);
|
public Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded, SourceLoc position);
|
||||||
public default Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded) {
|
public default Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded) {
|
||||||
return this.greater(type, fBounded, null);
|
return this.greater(type, fBounded, null);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import com.google.common.collect.Ordering;
|
|||||||
|
|
||||||
//PL 18-02-05/18-04-05 Unifier durch Matcher ersetzt
|
//PL 18-02-05/18-04-05 Unifier durch Matcher ersetzt
|
||||||
//muss greater noch ersetzt werden ja erledigt 18--04-05
|
//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.MartelliMontanariUnify;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.Match;
|
import de.dhbwstuttgart.typeinference.unify.Match;
|
||||||
@ -261,7 +262,7 @@ implements IFiniteClosure {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
//Eingefuegt PL 2018-05-24 F-Bounded Problematik
|
//Eingefuegt PL 2018-05-24 F-Bounded Problematik
|
||||||
public Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded, Token location) {
|
public Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded, SourceLoc location) {
|
||||||
Set<UnifyType> ret;
|
Set<UnifyType> ret;
|
||||||
if ((ret = greaterHash.get(new hashKeyType(type))) != null) {
|
if ((ret = greaterHash.get(new hashKeyType(type))) != null) {
|
||||||
//System.out.println(greaterHash);
|
//System.out.println(greaterHash);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.model;
|
package de.dhbwstuttgart.typeinference.unify.model;
|
||||||
|
|
||||||
import com.google.common.collect.ObjectArrays;
|
import com.google.common.collect.ObjectArrays;
|
||||||
|
import de.dhbwstuttgart.parser.SourceLoc;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
@ -18,8 +19,8 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class UnifyPair {
|
public class UnifyPair {
|
||||||
|
|
||||||
private Token location;
|
private SourceLoc location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type on the left hand side of the pair.
|
* 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();
|
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(lhs, rhs, op);
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
@ -87,20 +88,20 @@ public class UnifyPair {
|
|||||||
this(lhs, rhs, op, uni, base, fBounded, null);
|
this(lhs, rhs, op, uni, base, fBounded, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set<UnifyPair> uni, UnifyPair base, Set<UnifyType> fBounded, Token location) {
|
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set<UnifyPair> uni, UnifyPair base, Set<UnifyType> fBounded, SourceLoc location) {
|
||||||
this.lhs = lhs;
|
this.lhs = lhs;
|
||||||
this.rhs = rhs;
|
this.rhs = rhs;
|
||||||
pairOp = op;
|
pairOp = op;
|
||||||
substitution = uni;
|
substitution = uni;
|
||||||
basePair = base;
|
basePair = base;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.fBounded = fBounded;
|
//this.fBounded = fBounded; // what?
|
||||||
|
|
||||||
// Caching hashcode
|
// Caching hashcode
|
||||||
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
|
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Token getLocation() {
|
public SourceLoc getLocation() {
|
||||||
if (location != null) return location;
|
if (location != null) return location;
|
||||||
else if (basePair != null) return basePair.getLocation();
|
else if (basePair != null) return basePair.getLocation();
|
||||||
return null;
|
return null;
|
||||||
@ -254,7 +255,7 @@ public class UnifyPair {
|
|||||||
var res = "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])";
|
var res = "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])";
|
||||||
var location = this.getLocation();
|
var location = this.getLocation();
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
res += "@" + location.getLine();
|
res += "@" + location.line() + " in " + location.file();
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -834,4 +834,11 @@ public class TestComplete {
|
|||||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
assertEquals(clazz.getSuperclass().getDeclaredField("x").get(instance), 3);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class ASTToTypedTargetAST {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyClass() {
|
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<>());
|
ResultSet emptyResultSet = new ResultSet(new HashSet<>());
|
||||||
TargetStructure emptyTargetClass = new ASTToTargetAST(List.of(emptyResultSet)).convert(emptyClass);
|
TargetStructure emptyTargetClass = new ASTToTargetAST(List.of(emptyResultSet)).convert(emptyClass);
|
||||||
assert emptyTargetClass.getName().equals("EmptyClass");
|
assert emptyTargetClass.getName().equals("EmptyClass");
|
||||||
|
Loading…
Reference in New Issue
Block a user