Compare commits
30 Commits
targetByte
...
strucTypes
Author | SHA1 | Date | |
---|---|---|---|
|
23786184ad | ||
|
55f6fe47ac | ||
|
4919dd34b2 | ||
|
aac113e12e | ||
|
e9d5d5f7c7 | ||
|
092ee53f74 | ||
|
413cb48a96 | ||
|
24f93f0bcb | ||
|
f44f08b895 | ||
|
e972282620 | ||
|
f7160c10f4 | ||
|
7a5940ac65 | ||
|
86e94b8cc0 | ||
|
25a5e79509 | ||
|
7e1d6fad01 | ||
|
c7e0281d53 | ||
|
23ae5d5745 | ||
|
427a87598c | ||
|
403430d0c4 | ||
|
d9ab487253 | ||
|
6f85c2b376 | ||
|
a17342458e | ||
|
ab46709390 | ||
|
48e22982c8 | ||
|
3ed300268f | ||
|
ebacb72dcb | ||
|
663ce36e22 | ||
|
ce2b4e0303 | ||
|
52dd0e6276 | ||
|
f29faa2680 |
Binary file not shown.
@ -1,15 +1,32 @@
|
||||
package de.dhbwstuttgart.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.strucTypes.Construct;
|
||||
import de.dhbwstuttgart.strucTypes.Solve;
|
||||
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
@ -24,233 +41,140 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class JavaTXCompiler {
|
||||
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
|
||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
this(Arrays.asList(sourceFile));
|
||||
}
|
||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
this(Arrays.asList(sourceFile));
|
||||
}
|
||||
|
||||
public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
||||
this(sourceFile);
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
||||
environment = new CompilationEnvironment(sources);
|
||||
for (File s : sources) {
|
||||
sourceFiles.put(s, parse(s));
|
||||
}
|
||||
}
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||
for (File forSourceFile : sourceFiles.keySet())
|
||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
}
|
||||
allClasses.addAll(importedClasses);
|
||||
|
||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
for (JavaClassName name : forSourceFile.getImports()) {
|
||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
allClasses.addAll(importedClasses);
|
||||
}
|
||||
return allClasses;
|
||||
}
|
||||
|
||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||
for(SourceFile sf : this.sourceFiles.values()) {
|
||||
allClasses.addAll(getAvailableClasses(sf));
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
|
||||
for (List<Constraint<UnifyPair>> xCons : cardProd ){
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
for (Constraint<UnifyPair> constraint : xCons) {
|
||||
xConsSet.addAll(constraint);
|
||||
}
|
||||
//.collect(Collectors.toCollection(ArrayList::new))))
|
||||
System.out.println(xConsSet);
|
||||
Set<String> paraTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist()
|
||||
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
||||
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
||||
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
||||
|
||||
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
||||
|
||||
|
||||
xConsSet = xConsSet.stream().map(x -> {
|
||||
//Hier muss ueberlegt werden, ob
|
||||
//1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
|
||||
// mit disableWildcardtable() werden.
|
||||
//2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
|
||||
//in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
|
||||
//PL 2018-04-23
|
||||
if ((x.getLhsType() instanceof PlaceholderType)) {
|
||||
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
||||
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
||||
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||
}
|
||||
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
||||
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
||||
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||
}
|
||||
}
|
||||
if ((x.getRhsType() instanceof PlaceholderType)) {
|
||||
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
||||
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
||||
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||
}
|
||||
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
||||
((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
||||
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||
}
|
||||
}
|
||||
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
|
||||
}).map( y -> {
|
||||
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
||||
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
||||
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
||||
}
|
||||
if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
||||
((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance());
|
||||
}
|
||||
}
|
||||
return y; } )
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
varianceInheritance(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure);
|
||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
results.addAll(result);
|
||||
}
|
||||
|
||||
|
||||
return results.stream().map((unifyPairs ->
|
||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Vererbt alle Variancen
|
||||
* @param eq The set of constraints
|
||||
*/
|
||||
private void varianceInheritance(Set<UnifyPair> eq) {
|
||||
Set<PlaceholderType> usedTPH = new HashSet<>();
|
||||
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
||||
Set<PlaceholderType> pair = new HashSet<>();
|
||||
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
||||
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
||||
return pair;
|
||||
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
||||
|
||||
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
||||
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
||||
while(!phSetVariance.isEmpty()) {
|
||||
PlaceholderType a = phSetVariance.remove(0);
|
||||
usedTPH.add(a);
|
||||
//HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
||||
//ht.put(a, a.getVariance());
|
||||
Set<UnifyPair> eq1 = new HashSet<>(eq);
|
||||
eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)));
|
||||
eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());});
|
||||
eq1 = new HashSet<>(eq);
|
||||
eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
||||
eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());});
|
||||
phSetVariance = new ArrayList<>(phSet);
|
||||
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||
constraints.map((Pair p) -> {
|
||||
if (p.TA1 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
|
||||
}
|
||||
if (p.TA2 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), new GenericsRegistry(null));
|
||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void generateBytecode() throws ClassNotFoundException, IOException {
|
||||
for(File f : sourceFiles.keySet()) {
|
||||
HashMap<String,byte[]> classFiles = new HashMap<>();
|
||||
SourceFile sf = sourceFiles.get(f);
|
||||
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult);
|
||||
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
||||
bytecodeGen.visit(sf);
|
||||
this.writeClassFile(bytecodeGen.getClassFiles());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeClassFile(HashMap<String, byte[]> classFiles) throws IOException {
|
||||
FileOutputStream output;
|
||||
for(String name : classFiles.keySet()) {
|
||||
byte[] bytecode = classFiles.get(name);
|
||||
System.out.println("generating "+name+ ".class file ...");
|
||||
output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class"));
|
||||
output.write(bytecode);
|
||||
output.close();
|
||||
System.out.println(name+".class file generated");
|
||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
||||
environment = new CompilationEnvironment(sources);
|
||||
for (File s : sources) {
|
||||
sourceFiles.put(s, parse(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins
|
||||
// FC
|
||||
for (File forSourceFile : sourceFiles.keySet())
|
||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht
|
||||
// beachtet
|
||||
ClassOrInterface importedClass = ASTFactory
|
||||
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
}
|
||||
allClasses.addAll(importedClasses);
|
||||
|
||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
for (JavaClassName name : forSourceFile.getImports()) {
|
||||
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht
|
||||
// beachtet
|
||||
ClassOrInterface importedClass = ASTFactory
|
||||
.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
allClasses.addAll(importedClasses);
|
||||
}
|
||||
return allClasses;
|
||||
}
|
||||
|
||||
public List<SolvedClass> strucTypeInference()
|
||||
throws ImpossibleSubTypeException, ClassNotFoundException, InconsistentConstraintsException {
|
||||
List<SolvedClass> solvedClasses = new ArrayList<>();
|
||||
for (SourceFile sourceFile : sourceFiles.values()) {
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
ConstraintsSet strucTypeConstraints = strucTYPE.getConstraints();
|
||||
InferredTypes inferredTypes = strucTYPE.getInferredTypes();
|
||||
|
||||
Construct construct = new Construct(strucTypeConstraints, inferredTypes);
|
||||
List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
inferredTypes = construct.getInferredTypes();
|
||||
|
||||
IFiniteClosure fc = UnifyTypeFactory.generateFC(this.getAvailableClasses(sourceFile));
|
||||
Solve solve = new Solve(subTypeConstraints, clsA, fc, inferredTypes, constructedInterfaces);
|
||||
SolvedClass solvedClass = solve.getSolvedClass();
|
||||
solvedClasses.add(solvedClass);
|
||||
}
|
||||
return solvedClasses;
|
||||
}
|
||||
|
||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins
|
||||
// FC
|
||||
for (SourceFile sf : this.sourceFiles.values()) {
|
||||
allClasses.addAll(getAvailableClasses(sf));
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
for (Constraint<UnifyPair> constraint : xCons) {
|
||||
xConsSet.addAll(constraint);
|
||||
}
|
||||
|
||||
System.out.println(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
System.out.println("RESULT: " + result.size());
|
||||
results.addAll(result);
|
||||
}
|
||||
return results.stream()
|
||||
.map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons)))))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||
constraints.map((Pair p) -> {
|
||||
if (p.TA1 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
|
||||
}
|
||||
if (p.TA2 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile),
|
||||
new GenericsRegistry(null));
|
||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
@ -17,4 +18,9 @@ public class AssignToLocal extends AssignLeftSide {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToLocal accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -427,6 +427,9 @@ public class SyntaxTreeGenerator{
|
||||
GenericsRegistry ret = new GenericsRegistry(this.globalGenerics);
|
||||
ret.putAll(generics);
|
||||
if(ctx == null || ctx.typeParameterList() == null)return ret;
|
||||
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
|
||||
ret.put(tp.Identifier().getText(), new GenericContext(parentClass, parentMethod));
|
||||
}
|
||||
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
|
||||
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
|
||||
}
|
||||
|
@ -77,7 +77,6 @@ public class TypeGenerator {
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics);
|
||||
|
||||
GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop());
|
||||
generics.put(name, new GenericContext(parentClass, parentMethod));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -92,7 +91,7 @@ public class TypeGenerator {
|
||||
return ret;
|
||||
}
|
||||
if(typeBoundContext.classOrInterfaceType() != null){
|
||||
ret.add(convert(typeBoundContext.classOrInterfaceType()));
|
||||
ret.add(convert(typeBoundContext.classOrInterfaceType(), reg, generics));
|
||||
if(typeBoundContext.additionalBound() != null)
|
||||
for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
|
||||
ret.add(convert(addCtx.interfaceType()));
|
||||
@ -103,8 +102,9 @@ public class TypeGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext) {
|
||||
throw new NotImplementedException();
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = classOrInterfaceTypeContext.classType_lfno_classOrInterfaceType();
|
||||
return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),classOrInterfaceTypeContext.getStart(), reg, generics);
|
||||
}
|
||||
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) {
|
||||
@ -114,8 +114,7 @@ public class TypeGenerator {
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
if(referenceTypeContext.classOrInterfaceType() != null){
|
||||
if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){
|
||||
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType();
|
||||
return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
||||
return convert(referenceTypeContext.classOrInterfaceType(), reg, generics);//return convertTypeName(referenceTypeContext.getText(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
158
src/de/dhbwstuttgart/strucTypes/Construct.java
Normal file
158
src/de/dhbwstuttgart/strucTypes/Construct.java
Normal file
@ -0,0 +1,158 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.IllegalInterfaceTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class Construct extends DefaultASTVisitor {
|
||||
|
||||
private Set<SubTypeConstraint> subTypeConstraints = new HashSet<>();
|
||||
private ConstraintsSet constraintsSet = new ConstraintsSet();
|
||||
private Set<RefTypeOrTPHOrWildcardOrGeneric> newInterf = new HashSet<>();
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
private List<ClassOrInterface> constructedInterfaces = new ArrayList<>();
|
||||
|
||||
public Construct(ConstraintsSet constraintsSet, InferredTypes inferredTypes) throws ImpossibleSubTypeException {
|
||||
this.constraintsSet = constraintsSet;
|
||||
this.inferredTypes = inferredTypes;
|
||||
this.gatherSubTypeConstraints(constraintsSet);
|
||||
for (SubTypeConstraint constraint : this.subTypeConstraints) {
|
||||
constraint.checkConstraintPossible();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getConstructedInterfaces() {
|
||||
this.newInterf.forEach(i -> i.accept(this));
|
||||
return constructedInterfaces;
|
||||
}
|
||||
|
||||
public InferredTypes getInferredTypes() {
|
||||
return inferredTypes;
|
||||
}
|
||||
|
||||
public Set<SubTypeConstraint> getSubTypeConstraints() {
|
||||
this.subTypeConstraints.forEach(sc -> sc.inferTypes(this.inferredTypes));
|
||||
return subTypeConstraints;
|
||||
}
|
||||
|
||||
// public Set<UnifyPair> getSubTypeConstraintsAsUnifyPairs() {
|
||||
// return subTypeConstraints.stream().map(SubTypeConstraint::getAsUnifyPair).collect(Collectors.toSet());
|
||||
// }
|
||||
|
||||
private void gatherSubTypeConstraints(ConstraintsSet constraintsSet) {
|
||||
this.subTypeConstraints.addAll(constraintsSet.getSubTypeConstraints());
|
||||
constraintsSet.getFieldConstraints().forEach(fc -> this.newInterf.add(fc.getClassType()));
|
||||
constraintsSet.getMethodConstraints().forEach(mc -> {
|
||||
this.subTypeConstraints.addAll(mc.getArguments());
|
||||
this.newInterf.add(mc.getClassType());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
JavaClassName name = new JavaClassName( typePlaceholder.getName());
|
||||
this.constructedInterfaces.add(this.constructInterface(typePlaceholder, name));
|
||||
}
|
||||
|
||||
// check nur TPH in newInterf
|
||||
@Override
|
||||
public void visit(RefType refType) {
|
||||
throw new IllegalInterfaceTypeException(
|
||||
String.format("%s is not a valid type to generate an interface for.", refType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
System.out.println(String.format("%s is not a valid type to generate an interface for.", genericRefType));
|
||||
}
|
||||
|
||||
private ClassOrInterface constructInterface(TypePlaceholder i, JavaClassName name) {
|
||||
List<Field> fielddecl = new ArrayList<>();
|
||||
List<Method> methods = new ArrayList<>();
|
||||
List<GenericTypeVar> generics = new ArrayList<>();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> parameterInhTyterm = new ArrayList<>();
|
||||
final Token offset = new NullToken();
|
||||
|
||||
// Schleife über alle FieldConstraints mit ClassType i
|
||||
this.constraintsSet.getFieldConstraints().stream().filter(fc -> fc.getClassType().equals(i)).forEach(fc -> {
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(offset);
|
||||
// Typ für field: GenericRefType
|
||||
GenericRefType grt = new GenericRefType(tph.getName(), offset);
|
||||
parameterInhTyterm.add(fc.getFieldType());
|
||||
generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset));
|
||||
Field field = new Field(fc.getFieldName(), grt, Modifier.PUBLIC, offset);
|
||||
fielddecl.add(field);
|
||||
});
|
||||
|
||||
// Schleife über alle MethodConstraints mit ClassType i
|
||||
this.constraintsSet.getMethodConstraints().stream().filter(mc -> mc.getClassType().equals(i)).forEach(mc -> {
|
||||
TypePlaceholder returnType = TypePlaceholder.fresh(offset);
|
||||
parameterInhTyterm.add(mc.getReturnType());
|
||||
generics.add(new GenericTypeVar(returnType.getName(), new ArrayList<>(), offset, offset));
|
||||
Block block = new Block(new ArrayList<>(), offset);
|
||||
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), offset);
|
||||
List<FormalParameter> params = new ArrayList<>();
|
||||
mc.getArguments().stream().map(a -> a.getSupertype()).forEach(supertype -> {
|
||||
// Typ für argument: GenericRefType
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(offset);
|
||||
GenericRefType grt = new GenericRefType(tph.getName(), offset);
|
||||
params.add(new FormalParameter("arg" + tph.getName(), grt, offset));
|
||||
parameterInhTyterm.add(supertype);
|
||||
generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset));
|
||||
});
|
||||
ParameterList parameterList = new ParameterList(params, offset);
|
||||
// returnType für method: GenericRefType
|
||||
Method method = new Method(Modifier.PUBLIC, mc.getMethodName(),
|
||||
new GenericRefType(returnType.getName(), offset), parameterList, block, gtvDeclarations, offset);
|
||||
methods.add(method);
|
||||
});
|
||||
|
||||
RefType inh_tyterm = new RefType(name, parameterInhTyterm, offset);
|
||||
TypePlaceholder x = TypePlaceholder.fresh(offset);
|
||||
this.subTypeConstraints.add(new SubTypeConstraint(x, inh_tyterm));
|
||||
this.inferredTypes.put(i, x);
|
||||
|
||||
final int modifiers = Modifier.PUBLIC;
|
||||
final RefType superClass = this.createSuperClass();
|
||||
final boolean isInterface = true;
|
||||
final List<Constructor> constructors = new ArrayList<>();
|
||||
final List<RefType> implementedInterfaces = new ArrayList<>();
|
||||
GenericDeclarationList genericClassParameters = new GenericDeclarationList(generics, i.getOffset());
|
||||
ClassOrInterface constructedInterface = new ClassOrInterface(modifiers, name, fielddecl, methods, constructors,
|
||||
genericClassParameters, superClass, isInterface, implementedInterfaces, offset);
|
||||
return constructedInterface;
|
||||
}
|
||||
|
||||
private RefType createSuperClass() {
|
||||
JavaClassName name = new JavaClassName(Object.class.getName());
|
||||
GenericDeclarationList genericsOfClass = new GenericDeclarationList(new ArrayList<>(), new NullToken());
|
||||
return ClassOrInterface.generateTypeOfClass(name, genericsOfClass, new NullToken());
|
||||
}
|
||||
|
||||
}
|
182
src/de/dhbwstuttgart/strucTypes/RuleSetStrucType.java
Normal file
182
src/de/dhbwstuttgart/strucTypes/RuleSetStrucType.java
Normal file
@ -0,0 +1,182 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
|
||||
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
import javafx.util.Pair;
|
||||
|
||||
public class RuleSetStrucType extends RuleSet {
|
||||
|
||||
public Optional<Set<UnifyPair>> strucTypeReduce(UnifyPair pair) {
|
||||
return super.reduce2(pair);
|
||||
}
|
||||
|
||||
public Optional<UnifyPair> strucTypeAdapt1(UnifyPair pair, IFiniteClosure fc) {
|
||||
return super.adapt(pair, fc);
|
||||
}
|
||||
|
||||
public Optional<Set<UnifyPair>> strucTypeAdapt2(Set<UnifyPair> pairs, IFiniteClosure fc) {
|
||||
// Filter SMALLERDOT Pairs
|
||||
final Set<UnifyPair> pairsSmallerDot = pairs.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))
|
||||
.collect(Collectors.toSet());
|
||||
List<Pair<UnifyPair, UnifyPair>> tupleOfPotentialLinkings = new ArrayList<>();
|
||||
for (UnifyPair pair : pairsSmallerDot) {
|
||||
// check outerLeftPair pair has Form (D<theta.1,..,theta.n> <. TPH S1)
|
||||
UnifyType typeD = pair.getLhsType();
|
||||
if (!(pair.getRhsType() instanceof PlaceholderType) || !(typeD instanceof ReferenceType)) {
|
||||
continue;
|
||||
}
|
||||
// filter potential outer Pairs for Linking
|
||||
pairsSmallerDot.stream()
|
||||
// check outerRightPair p has Form (TPH Sn <. D'<theta'.1,...,theta'.m>)
|
||||
.filter(p -> (p.getLhsType() instanceof PlaceholderType)
|
||||
&& (p.getRhsType() instanceof ReferenceType))
|
||||
.filter(p -> {
|
||||
UnifyType typeD1 = p.getRhsType();
|
||||
// check not(D<theta.1,..,theta.n> <=* D'<theta'.1,..,theta'.m>)
|
||||
if (fc.getAncestors(typeD).contains(typeD1))
|
||||
return false;
|
||||
Optional<UnifyType> opt = fc.getLeftHandedType(typeD.getName());
|
||||
if (!opt.isPresent())
|
||||
return false;
|
||||
|
||||
UnifyType typeDgen = opt.get();
|
||||
Set<UnifyType> greater = fc.getAncestors(typeDgen);
|
||||
opt = greater.stream().filter(x -> x.getName().equals(typeD1.getName())).findAny();
|
||||
// check (D<T1,..,Tn> <=* D'<ty1',...,tym'>)
|
||||
if (!opt.isPresent())
|
||||
return false;
|
||||
// UnifyType typeD1gen = opt.get();
|
||||
return true;
|
||||
}).map(p -> new Pair<>(pair, p)).forEach(tupleOfPotentialLinkings::add);
|
||||
}
|
||||
|
||||
// Build Linking between the Pairs. Empty if no Linking is possible.
|
||||
for (Pair<UnifyPair, UnifyPair> tuple : tupleOfPotentialLinkings) {
|
||||
UnifyPair outerLeftPair = tuple.getKey();
|
||||
UnifyPair outerRightPair = tuple.getValue();
|
||||
Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(outerLeftPair, outerRightPair,
|
||||
pairsSmallerDot);
|
||||
if (!opt.isPresent())
|
||||
continue;
|
||||
// Linking has been found
|
||||
UnifyType typeD = outerLeftPair.getLhsType();
|
||||
UnifyType typeD1 = outerRightPair.getRhsType();
|
||||
// present already checked s.o.
|
||||
UnifyType typeDgen = fc.getLeftHandedType(typeD.getName()).get();
|
||||
// present already checked s.o.
|
||||
UnifyType typeD1gen = fc.getAncestors(typeDgen).stream().filter(x -> x.getName().equals(typeD1.getName()))
|
||||
.findAny().get();
|
||||
TypeParams typeDParams = typeD.getTypeParams();
|
||||
TypeParams typeDgenParams = typeDgen.getTypeParams();
|
||||
|
||||
Unifier unifD1gen = Unifier.identity();
|
||||
for (int i = 0; i < typeDParams.size(); i++)
|
||||
unifD1gen.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
|
||||
Optional<Unifier> sigmaopt = new MartelliMontanariUnify().unify(unifD1gen.apply(typeD1gen), typeD);
|
||||
|
||||
if (!sigmaopt.isPresent())
|
||||
continue;
|
||||
// replace outerLeftPair.lhs and outerRightPair.rhs witch new Types
|
||||
Unifier sigma = sigmaopt.get();
|
||||
pairs.remove(outerLeftPair);
|
||||
pairs.remove(outerRightPair);
|
||||
pairs.add(UnifyTypeFactory.generateSmallerDotPair(sigma.apply(typeD), outerLeftPair.getRhsType()));
|
||||
pairs.add(UnifyTypeFactory.generateSmallerDotPair(outerRightPair.getLhsType(), sigma.apply(typeD1)));
|
||||
// TODO pairs.add mit sigma als Pair
|
||||
return Optional.of(pairs);
|
||||
}
|
||||
// No Linking found
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public boolean strucTypeErase1(UnifyPair pair, IFiniteClosure fc) {
|
||||
return super.erase1(pair, fc);
|
||||
}
|
||||
|
||||
public boolean strucTypeErase2(UnifyPair pair) {
|
||||
return super.erase3(pair);
|
||||
}
|
||||
|
||||
public Optional<UnifyPair> strucTypeSwap(UnifyPair pair) {
|
||||
return super.swap(pair);
|
||||
}
|
||||
|
||||
public Optional<Set<UnifyPair>> strucTypeSubst(Set<UnifyPair> pairs) {
|
||||
return super.subst(pairs);
|
||||
}
|
||||
|
||||
public Optional<Set<UnifyPair>> strucTypeRefl(Set<UnifyPair> pairs) {
|
||||
// Filter SMALLERDOT Pairs
|
||||
final Set<UnifyPair> pairsSmallerDot = pairs.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))
|
||||
.collect(Collectors.toSet());
|
||||
// System.out.println("Pairs to test: " + pairsSmallerDot);
|
||||
// Filter Tuples of Pairs for a potential Linking (t<T1,T1<T2,...,Tn<t)
|
||||
List<Pair<UnifyPair, UnifyPair>> tupleOfPotentialLinkings = new ArrayList<>();
|
||||
for (UnifyPair pair : pairsSmallerDot) {
|
||||
if (!(pair.getRhsType() instanceof PlaceholderType)) {
|
||||
// System.out.println("Pair not suitable for outerLeftPair: " + pair);
|
||||
continue;
|
||||
}
|
||||
// System.out.println("Try to find tuple of potential linkings for pair " + pair);
|
||||
pairsSmallerDot.stream().filter(p -> {
|
||||
// System.out.println(" Pair pair: " + pair);
|
||||
// System.out.println("Pair p: " + p);
|
||||
// System.out.println("p.lhs instnceof PH: " + (p.getLhsType() instanceof PlaceholderType));
|
||||
// System.out.println("p.rhs equals pair.lhs: " + (p.getRhsType().equals(pair.getLhsType())));
|
||||
return (p.getLhsType() instanceof PlaceholderType) && (p.getRhsType().equals(pair.getLhsType()));
|
||||
}).map(p -> {
|
||||
// System.out.println("Pair to map: " + p);
|
||||
return new Pair<>(pair, p);
|
||||
}).forEach(tupleOfPotentialLinkings::add);
|
||||
// System.out.println("tuple of potential linkings: " + tupleOfPotentialLinkings);
|
||||
}
|
||||
// Build Linking between the Pairs. Empty if no Linking is possible.
|
||||
for (Pair<UnifyPair, UnifyPair> tuple : tupleOfPotentialLinkings) {
|
||||
UnifyPair outerLeftPair = tuple.getKey();
|
||||
UnifyPair outerRightPair = tuple.getValue();
|
||||
// System.out.println("Try linking pair: " + outerLeftPair + ", " + outerRightPair);
|
||||
Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(outerLeftPair, outerRightPair,
|
||||
pairsSmallerDot);
|
||||
// Remove Pairs of the Linking incl. outerLeft and outerRight, add
|
||||
// EQUALSDOT Pairs instead.
|
||||
if (opt.isPresent()) {
|
||||
// System.out.println("Linking found: " + opt.get());
|
||||
pairs.remove(outerLeftPair);
|
||||
pairs.remove(outerRightPair);
|
||||
pairs.removeAll(opt.get());
|
||||
// Get all Placeholder in Linking.
|
||||
Set<UnifyType> placeholderInLinking = new HashSet<>();
|
||||
opt.get().forEach(p -> {
|
||||
placeholderInLinking.add(p.getLhsType());
|
||||
placeholderInLinking.add(p.getRhsType());
|
||||
});
|
||||
// Generate and add new EQUALSDOT Pairs of Placeholder and
|
||||
// outermost UnifyType to the result.
|
||||
final UnifyType outermostUnifyType = outerLeftPair.getLhsType();
|
||||
placeholderInLinking.forEach(placeholder -> pairs
|
||||
.add(UnifyTypeFactory.generateEqualDotPair(placeholder, outermostUnifyType)));
|
||||
return Optional.of(pairs);
|
||||
}
|
||||
// System.out.println("No Linking found");
|
||||
}
|
||||
// No Linking was found.
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
129
src/de/dhbwstuttgart/strucTypes/Solve.java
Normal file
129
src/de/dhbwstuttgart/strucTypes/Solve.java
Normal file
@ -0,0 +1,129 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.TypeExtract;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.TypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class Solve {
|
||||
|
||||
private Set<SubTypeConstraint> constraints = new HashSet<>();
|
||||
private IFiniteClosure fc;
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
private ClassOrInterface clsA;
|
||||
private List<ClassOrInterface> generatedInterfaces = new ArrayList<>();
|
||||
|
||||
public Solve(Set<SubTypeConstraint> constraints, ClassOrInterface clsA, IFiniteClosure fc,
|
||||
InferredTypes inferredTypes, List<ClassOrInterface> generatedInterfaces) {
|
||||
this.constraints = constraints;
|
||||
this.fc = fc;
|
||||
this.inferredTypes = inferredTypes;
|
||||
this.clsA = clsA;
|
||||
this.generatedInterfaces = generatedInterfaces;
|
||||
}
|
||||
|
||||
public SolvedClass getSolvedClass() throws InconsistentConstraintsException {
|
||||
Set<UnifyPair> constraintsUnifyPair = this.constraints.stream().map(SubTypeConstraint::getAsUnifyPair)
|
||||
.collect(Collectors.toSet());
|
||||
StrucTypeUnify strucTypeUnify = new StrucTypeUnify(constraintsUnifyPair, this.fc);
|
||||
Set<UnifyPair> subst = strucTypeUnify.unify();
|
||||
|
||||
Map<String, TypePlaceholder> tphs = this.generateTPHMap(constraints);
|
||||
InferredTypes sigma = new InferredTypes();
|
||||
sigma.putAll(inferredTypes);
|
||||
sigma.putAll(
|
||||
StrucTypeUnifyUtils.convertEqualsdot(
|
||||
subst.stream()
|
||||
.filter(p -> p.getLhsType() instanceof PlaceholderType
|
||||
&& p.getPairOp().equals(PairOperator.EQUALSDOT))
|
||||
.collect(Collectors.toSet()),
|
||||
tphs));
|
||||
|
||||
Set<SubTypeConstraint> cs = StrucTypeUnifyUtils.convertSmallerdot(
|
||||
subst.stream().filter(p -> PairOperator.SMALLERDOT.equals(p.getPairOp())).collect(Collectors.toSet()),
|
||||
tphs);
|
||||
|
||||
List<GenericTypeVar> values = new ArrayList<>();
|
||||
// extract typeplaceholder (type variables) of clsA
|
||||
TypeVar typeVar = new TypeVar(inferredTypes);
|
||||
clsA.accept(typeVar);
|
||||
final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> bounds = new ArrayList<>();
|
||||
final NullToken offset = new NullToken();
|
||||
// add type variables of clsA as GenericTypeVar to values of
|
||||
// tNew
|
||||
typeVar.getTypeVars().stream().map(tph -> new GenericTypeVar(tph.getName(), bounds, offset, offset))
|
||||
.forEach(gtv -> {
|
||||
if (values.stream().map(GenericTypeVar::getName).noneMatch(gtv.getName()::equals)) {
|
||||
values.add(gtv);
|
||||
};
|
||||
});
|
||||
// add type variables of cs as GenericRefType to values of
|
||||
// tNew
|
||||
cs.stream().flatMap(c -> Stream.of(c.getSubtype(), c.getSupertype())).filter(t -> t instanceof TypePlaceholder)
|
||||
.map(tph -> new GenericTypeVar(((TypePlaceholder) tph).getName(), bounds, offset, offset))
|
||||
.forEach(gtv -> {
|
||||
if (values.stream().map(GenericTypeVar::getName).noneMatch(gtv.getName()::equals)) {
|
||||
values.add(gtv);
|
||||
};
|
||||
});
|
||||
// add generics of all superclasses and superinterfaces of clsA to
|
||||
// values of tNew
|
||||
TypeExtract typeExtract = new TypeExtract();
|
||||
clsA.accept(typeExtract);
|
||||
typeExtract.getGenerics().forEach(gtv -> {
|
||||
if (values.stream().map(GenericTypeVar::getName).noneMatch(gtv.getName()::equals)) {
|
||||
values.add(gtv);
|
||||
};
|
||||
});
|
||||
GenericDeclarationList tNew = new GenericDeclarationList(values, offset);
|
||||
|
||||
if (!consistent(cs)) {
|
||||
throw new InconsistentConstraintsException();
|
||||
}
|
||||
return new SolvedClass(this.clsA.accept(new InferTypes(inferredTypes, tNew)), tNew,
|
||||
cs, this.generatedInterfaces);
|
||||
|
||||
}
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(Set<SubTypeConstraint> constraints) {
|
||||
Map<String, TypePlaceholder> tphs = new HashMap<>();
|
||||
constraints.stream().forEach(c -> {
|
||||
if (c.getSubtype() instanceof TypePlaceholder) {
|
||||
TypePlaceholder subtype = (TypePlaceholder) c.getSubtype();
|
||||
tphs.put(subtype.getName(), subtype);
|
||||
}
|
||||
if (c.getSupertype() instanceof TypePlaceholder) {
|
||||
TypePlaceholder supertype = (TypePlaceholder) c.getSupertype();
|
||||
tphs.put(supertype.getName(), supertype);
|
||||
}
|
||||
});
|
||||
return tphs;
|
||||
}
|
||||
|
||||
private boolean consistent(Set<SubTypeConstraint> cs) {
|
||||
// TODO update inconsistencies
|
||||
return true;
|
||||
}
|
||||
}
|
63
src/de/dhbwstuttgart/strucTypes/StrucTYPE.java
Normal file
63
src/de/dhbwstuttgart/strucTypes/StrucTYPE.java
Normal file
@ -0,0 +1,63 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.TYPEExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class StrucTYPE extends DefaultASTVisitor {
|
||||
|
||||
private ClassOrInterface clsA;
|
||||
private ConstraintsSet constraintsSet = new ConstraintsSet();
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
|
||||
public StrucTYPE(ClassOrInterface clsA) {
|
||||
this.clsA = clsA;
|
||||
}
|
||||
|
||||
public ConstraintsSet getConstraints() {
|
||||
TYPEExpr typeExpr = new TYPEExpr();
|
||||
this.clsA.accept(typeExpr);
|
||||
this.clsA.getMethods().forEach(m -> m.accept(this));
|
||||
this.evaluateTypeExpr(typeExpr);
|
||||
return this.constraintsSet;
|
||||
}
|
||||
|
||||
public InferredTypes getInferredTypes() {
|
||||
return this.inferredTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
// Es gibt nur ein Return Statement
|
||||
Expression retexpr = ((Return) method.block.statements.get(0)).retexpr;
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric methodReturnType = method.getReturnType();
|
||||
RefTypeOrTPHOrWildcardOrGeneric retExprType = retexpr.getType();
|
||||
|
||||
// ordnet dem Methodentyp den Returntyp zu [sigma(Mt)]
|
||||
if (methodReturnType instanceof TypePlaceholder) {
|
||||
this.inferredTypes.put((TypePlaceholder) methodReturnType, retExprType);
|
||||
}
|
||||
if (methodReturnType instanceof RefType && retExprType instanceof TypePlaceholder) {
|
||||
this.inferredTypes.put((TypePlaceholder) retExprType, methodReturnType);
|
||||
}
|
||||
}
|
||||
|
||||
private void evaluateTypeExpr(TYPEExpr typeExpr) {
|
||||
this.inferredTypes.putAll(typeExpr.getInferredTypes());
|
||||
this.inferredTypes.resolveTransitiveTypes();
|
||||
|
||||
ConstraintsSet constraints = typeExpr.getConstraints();
|
||||
constraints.inferTypes(this.inferredTypes);
|
||||
this.constraintsSet.addConstraintsSet(constraints);
|
||||
}
|
||||
|
||||
}
|
89
src/de/dhbwstuttgart/strucTypes/StrucTypeUnify.java
Normal file
89
src/de/dhbwstuttgart/strucTypes/StrucTypeUnify.java
Normal file
@ -0,0 +1,89 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class StrucTypeUnify {
|
||||
|
||||
private Set<UnifyPair> pairs;
|
||||
private IFiniteClosure fc;
|
||||
private RuleSetStrucType rules = new RuleSetStrucType();
|
||||
|
||||
public StrucTypeUnify(Set<UnifyPair> unifyPairs, IFiniteClosure finiteClosure) {
|
||||
this.pairs = unifyPairs;
|
||||
this.fc = finiteClosure;
|
||||
}
|
||||
|
||||
public Set<UnifyPair> unify() {
|
||||
Set<UnifyPair> pairs = this.applyTypeUnificationRules(this.pairs, fc);
|
||||
return pairs;
|
||||
}
|
||||
|
||||
|
||||
private Set<UnifyPair> applyTypeUnificationRules(Set<UnifyPair> pairs, IFiniteClosure fc) {
|
||||
Set<UnifyPair> resultSet = new HashSet<>();
|
||||
|
||||
LinkedList<UnifyPair> pairQueue = new LinkedList<>();
|
||||
|
||||
pairs.forEach(p -> this.swapAddOrErase(p, fc, pairQueue));
|
||||
|
||||
while (!pairQueue.isEmpty()) {
|
||||
UnifyPair pair = pairQueue.pollFirst();
|
||||
|
||||
// reduce
|
||||
Optional<Set<UnifyPair>> optSet = rules.strucTypeReduce(pair);
|
||||
if (optSet.isPresent()) {
|
||||
optSet.get().forEach(p -> swapAddOrErase(p, fc, pairQueue));
|
||||
continue;
|
||||
}
|
||||
|
||||
// adapt1
|
||||
Optional<UnifyPair> opt = rules.strucTypeAdapt1(pair, fc);
|
||||
|
||||
if (opt.isPresent()) {
|
||||
this.swapAddOrErase(opt.get(), fc, pairQueue);
|
||||
continue;
|
||||
}
|
||||
|
||||
// none of the above rules applied
|
||||
resultSet.add(pair);
|
||||
}
|
||||
|
||||
// adapt2
|
||||
Optional<Set<UnifyPair>> adapt2 = rules.strucTypeAdapt2(resultSet, fc);
|
||||
if(adapt2.isPresent()){
|
||||
resultSet = this.applyTypeUnificationRules(adapt2.get(), fc);
|
||||
}
|
||||
|
||||
// subst
|
||||
Optional<Set<UnifyPair>> subst = rules.strucTypeSubst(resultSet);
|
||||
if(subst.isPresent()){
|
||||
resultSet = this.applyTypeUnificationRules(subst.get(), fc);
|
||||
}
|
||||
|
||||
// refl
|
||||
Optional<Set<UnifyPair>> refl = rules.strucTypeRefl(resultSet);
|
||||
if(refl.isPresent()){
|
||||
resultSet = this.applyTypeUnificationRules(refl.get(), fc);
|
||||
}
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
private void swapAddOrErase(UnifyPair pair, IFiniteClosure fc, Collection<UnifyPair> collection) {
|
||||
// swap
|
||||
Optional<UnifyPair> opt = rules.strucTypeSwap(pair);
|
||||
UnifyPair unifyPair = opt.isPresent() ? opt.get() : pair;
|
||||
|
||||
// erase
|
||||
if (rules.strucTypeErase1(unifyPair, fc) || rules.strucTypeErase2(unifyPair))
|
||||
return;
|
||||
collection.add(unifyPair);
|
||||
}
|
||||
}
|
66
src/de/dhbwstuttgart/strucTypes/StrucTypeUnifyUtils.java
Normal file
66
src/de/dhbwstuttgart/strucTypes/StrucTypeUnifyUtils.java
Normal file
@ -0,0 +1,66 @@
|
||||
package de.dhbwstuttgart.strucTypes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class StrucTypeUnifyUtils {
|
||||
|
||||
public static Optional<Set<UnifyPair>> linkPairs(UnifyPair outerLeft, UnifyPair outerRight,
|
||||
Collection<UnifyPair> pairs) {
|
||||
|
||||
Set<UnifyPair> resultLinking = new HashSet<>();
|
||||
|
||||
if (outerLeft.getRhsType().equals(outerRight.getLhsType())) {
|
||||
resultLinking.add(outerLeft);
|
||||
return Optional.of(resultLinking);
|
||||
}
|
||||
|
||||
List<UnifyPair> nextLinks = pairs.stream().filter(p -> outerLeft.getRhsType().equals(p.getLhsType()))
|
||||
.collect(Collectors.toList());
|
||||
for (UnifyPair nextLink : nextLinks) {
|
||||
Optional<Set<UnifyPair>> opt = linkPairs(nextLink, outerRight, pairs);
|
||||
if (opt.isPresent()) {
|
||||
resultLinking = opt.get();
|
||||
resultLinking.add(nextLink);
|
||||
return Optional.of(resultLinking);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static InferredTypes convertEqualsdot(Set<UnifyPair> pairs, Map<String, TypePlaceholder> tphs) {
|
||||
InferredTypes inferredTypes = new InferredTypes();
|
||||
if (!pairs.stream().allMatch(
|
||||
p -> PairOperator.EQUALSDOT.equals(p.getPairOp()) && p.getLhsType() instanceof PlaceholderType)) {
|
||||
throw new IllegalArgumentException("Not all UnifyPairs were EQUALSDOT pairs.");
|
||||
}
|
||||
for (UnifyPair pair : pairs) {
|
||||
TypePlaceholder lhs = (TypePlaceholder) UnifyTypeFactory.convert(pair.getLhsType(), tphs);
|
||||
RefTypeOrTPHOrWildcardOrGeneric rhs = UnifyTypeFactory.convert(pair.getRhsType(), tphs);
|
||||
inferredTypes.put(lhs, rhs);
|
||||
}
|
||||
return inferredTypes;
|
||||
}
|
||||
|
||||
public static Set<SubTypeConstraint> convertSmallerdot(Set<UnifyPair> pairs, Map<String, TypePlaceholder> tphs) {
|
||||
if (!pairs.stream().allMatch(p -> PairOperator.SMALLERDOT.equals(p.getPairOp()))) {
|
||||
throw new IllegalArgumentException("Not all UnifyPairs were SMALLERDOT pairs.");
|
||||
}
|
||||
return pairs.stream().map(p -> new SubTypeConstraint(UnifyTypeFactory.convert(p.getLhsType(), tphs),
|
||||
UnifyTypeFactory.convert(p.getRhsType(), tphs))).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package de.dhbwstuttgart.strucTypes.constraint;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
|
||||
public class ConstraintsSet {
|
||||
|
||||
private Set<SubTypeConstraint> subTypeConstraints;
|
||||
private Set<FieldConstraint> fieldConstraints;
|
||||
private Set<MethodConstraint> methodConstraints;
|
||||
|
||||
public ConstraintsSet() {
|
||||
this.subTypeConstraints = new HashSet<>();
|
||||
this.fieldConstraints = new HashSet<>();
|
||||
this.methodConstraints = new HashSet<>();
|
||||
}
|
||||
|
||||
public Set<SubTypeConstraint> getSubTypeConstraints() {
|
||||
return subTypeConstraints;
|
||||
}
|
||||
|
||||
public Set<FieldConstraint> getFieldConstraints() {
|
||||
return fieldConstraints;
|
||||
}
|
||||
|
||||
public Set<MethodConstraint> getMethodConstraints() {
|
||||
return methodConstraints;
|
||||
}
|
||||
|
||||
public void addConstraint(SubTypeConstraint constraint) {
|
||||
this.subTypeConstraints.add(constraint);
|
||||
}
|
||||
|
||||
public void addConstraint(FieldConstraint constraint) {
|
||||
this.fieldConstraints.add(constraint);
|
||||
}
|
||||
|
||||
public void addConstraint(MethodConstraint constraint) {
|
||||
this.methodConstraints.add(constraint);
|
||||
}
|
||||
|
||||
public void addConstraintsSet(ConstraintsSet constraintsSet) {
|
||||
constraintsSet.getSubTypeConstraints().forEach(this::addConstraint);
|
||||
constraintsSet.getFieldConstraints().forEach(this::addConstraint);
|
||||
constraintsSet.getMethodConstraints().forEach(this::addConstraint);
|
||||
}
|
||||
|
||||
public void inferTypes(InferredTypes inferredTypes) {
|
||||
this.subTypeConstraints.forEach(c -> c.inferTypes(inferredTypes));
|
||||
this.fieldConstraints.forEach(c -> c.inferTypes(inferredTypes));
|
||||
this.methodConstraints.forEach(c -> c.inferTypes(inferredTypes));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package de.dhbwstuttgart.strucTypes.constraint;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
/**
|
||||
* fc(c, f, c') : Klasse/Typ c hat ein Feld f mit Typ c'
|
||||
*
|
||||
* @author mvr
|
||||
*
|
||||
*/
|
||||
public class FieldConstraint {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric classType;
|
||||
private String fieldName;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric fieldType;
|
||||
|
||||
public FieldConstraint(RefTypeOrTPHOrWildcardOrGeneric classType, String fieldName,
|
||||
RefTypeOrTPHOrWildcardOrGeneric fieldType) {
|
||||
this.classType = classType;
|
||||
this.fieldName = fieldName;
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getClassType() {
|
||||
return classType;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getFieldType() {
|
||||
return fieldType;
|
||||
}
|
||||
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
public void inferTypes(InferredTypes inferredTypes) {
|
||||
// if (inferredTypes.containsKey(classType)) {
|
||||
// this.classType = inferredTypes.get(classType);
|
||||
// }
|
||||
// if (inferredTypes.containsKey(fieldType)) {
|
||||
// this.fieldType = inferredTypes.get(fieldType);
|
||||
// }
|
||||
InferTypes inferTypes = new InferTypes(inferredTypes);
|
||||
classType = classType.accept(inferTypes);
|
||||
fieldType = fieldType.accept(inferTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("F(%s, %s, %s)", this.classType, this.fieldName, this.fieldType);
|
||||
}
|
||||
|
||||
}
|
114
src/de/dhbwstuttgart/strucTypes/constraint/MethodConstraint.java
Normal file
114
src/de/dhbwstuttgart/strucTypes/constraint/MethodConstraint.java
Normal file
@ -0,0 +1,114 @@
|
||||
package de.dhbwstuttgart.strucTypes.constraint;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* mc(c, m, C, (c', C')) : Klasse/Typ c hat Methode m mit Argumenten von Typ C
|
||||
* mit Rückgabewert c' und Subtyp-Constraints C <. C' wobei C = {c1,... , cn)
|
||||
*
|
||||
* @author mvr
|
||||
*
|
||||
*/
|
||||
public class MethodConstraint {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric classType;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
private String methodName;
|
||||
private List<SubTypeConstraint> arguments;
|
||||
|
||||
public MethodConstraint(RefTypeOrTPHOrWildcardOrGeneric classType, String methodName,
|
||||
List<SubTypeConstraint> arguments, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||
this.classType = classType;
|
||||
this.returnType = returnType;
|
||||
this.methodName = methodName;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getClassType() {
|
||||
return classType;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public List<SubTypeConstraint> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public void addArguments(SubTypeConstraint... subTypeConstraints) {
|
||||
for (SubTypeConstraint subTypeConstraint : subTypeConstraints) {
|
||||
this.arguments.add(subTypeConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
public void addArguments(RefTypeOrTPHOrWildcardOrGeneric... parameters) {
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric parameter : parameters) {
|
||||
Token offset = parameter.getOffset();
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(offset);
|
||||
SubTypeConstraint subTypeConstraint = new SubTypeConstraint(parameter, tph);
|
||||
this.arguments.add(subTypeConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
public void inferTypes(InferredTypes inferredTypes) {
|
||||
// if (inferredTypes.containsKey(classType)) {
|
||||
// this.classType = inferredTypes.get(classType);
|
||||
// }
|
||||
// if (inferredTypes.containsKey(returnType)) {
|
||||
// this.returnType = inferredTypes.get(returnType);
|
||||
// }
|
||||
InferTypes inferTypes = new InferTypes(inferredTypes);
|
||||
classType = classType.accept(inferTypes);
|
||||
returnType = returnType.accept(inferTypes);
|
||||
arguments.forEach(c -> c.inferTypes(inferredTypes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("M(");
|
||||
sb.append(this.classType);
|
||||
sb.append(", ");
|
||||
sb.append(this.methodName);
|
||||
sb.append(", [");
|
||||
List<SubTypeConstraint> arguments = this.arguments;
|
||||
if (!arguments.isEmpty()) {
|
||||
Iterator<SubTypeConstraint> iterator = arguments.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric subtype = iterator.next().getSubtype();
|
||||
sb.append(subtype.toString());
|
||||
if (iterator.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("],(");
|
||||
sb.append(this.returnType);
|
||||
sb.append(", [");
|
||||
if (!arguments.isEmpty()) {
|
||||
Iterator<SubTypeConstraint> iterator = arguments.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric supertype = iterator.next().getSupertype();
|
||||
sb.append(supertype.toString());
|
||||
if (iterator.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("]))");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package de.dhbwstuttgart.strucTypes.constraint;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
|
||||
/**
|
||||
* c <. c' : c ist subtyp von c'
|
||||
*
|
||||
* @author mvr
|
||||
*
|
||||
*/
|
||||
public class SubTypeConstraint {
|
||||
|
||||
private RefTypeOrTPHOrWildcardOrGeneric subtype;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric supertype;
|
||||
|
||||
public SubTypeConstraint(RefTypeOrTPHOrWildcardOrGeneric subtype, RefTypeOrTPHOrWildcardOrGeneric supertype) {
|
||||
this.subtype = subtype;
|
||||
this.supertype = supertype;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getSubtype() {
|
||||
return subtype;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getSupertype() {
|
||||
return supertype;
|
||||
}
|
||||
|
||||
public void inferTypes(InferredTypes inferredTypes) {
|
||||
// if (inferredTypes.containsKey(subtype)) {
|
||||
// this.subtype = inferredTypes.get(subtype);
|
||||
// }
|
||||
// if (inferredTypes.containsKey(supertype)) {
|
||||
// this.supertype = inferredTypes.get(supertype);
|
||||
// }
|
||||
InferTypes inferTypes = new InferTypes(inferredTypes);
|
||||
subtype = subtype.accept(inferTypes);
|
||||
supertype = supertype.accept(inferTypes);
|
||||
}
|
||||
|
||||
|
||||
public boolean checkConstraintPossible() throws ImpossibleSubTypeException {
|
||||
if (this.subtype instanceof RefType && this.supertype instanceof RefType) {
|
||||
Class<?> subClass = this.createClass(((RefType) this.subtype).getName().toString());
|
||||
Class<?> superClass = this.createClass(((RefType) this.supertype).getName().toString());
|
||||
if (subClass != null && superClass != null) {
|
||||
if (superClass.isAssignableFrom(subClass))
|
||||
return true;
|
||||
else
|
||||
throw new ImpossibleSubTypeException(
|
||||
String.format("%s ist kein subtyp von %s", subClass.getName(), superClass.getName()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public UnifyPair getAsUnifyPair(){
|
||||
UnifyType tl = UnifyTypeFactory.convert(this.subtype);
|
||||
UnifyType tr = UnifyTypeFactory.convert(this.supertype);
|
||||
return UnifyTypeFactory.generateSmallerDotPair(tl, tr);
|
||||
}
|
||||
|
||||
private Class<?> createClass(String name) {
|
||||
try {
|
||||
return ClassLoader.getSystemClassLoader().loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((subtype == null) ? 0 : subtype.hashCode());
|
||||
result = prime * result + ((supertype == null) ? 0 : supertype.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
SubTypeConstraint other = (SubTypeConstraint) obj;
|
||||
if (subtype == null) {
|
||||
if (other.subtype != null)
|
||||
return false;
|
||||
} else if (!subtype.equals(other.subtype))
|
||||
return false;
|
||||
if (supertype == null) {
|
||||
if (other.supertype != null)
|
||||
return false;
|
||||
} else if (!supertype.equals(other.supertype))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s <* %s", this.subtype, this.supertype);
|
||||
}
|
||||
|
||||
}
|
503
src/de/dhbwstuttgart/strucTypes/diagram/Trans.ucls
Normal file
503
src/de/dhbwstuttgart/strucTypes/diagram/Trans.ucls
Normal file
@ -0,0 +1,503 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<class-diagram version="1.2.2" icons="false" always-add-relationships="false" generalizations="true" realizations="true"
|
||||
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||
<class id="1" language="java" name="de.dhbwstuttgart.strucTypes.StrucTYPE" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/StrucTYPE.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="136" y="291"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="2" language="java" name="de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/ConstraintsSet.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="593" y="277"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="3" language="java" name="de.dhbwstuttgart.strucTypes.model.InferredTypes" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/model/InferredTypes.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="626" y="450"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="4" language="java" name="de.dhbwstuttgart.strucTypes.visitor.TYPEExpr" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/TYPEExpr.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="242" y="464"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="5" language="java" name="de.dhbwstuttgart.strucTypes.visitor.DefaultASTVisitor" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/DefaultASTVisitor.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="601" y="86"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="6" language="java" name="de.dhbwstuttgart.strucTypes.Construct" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/Construct.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="1019" y="494"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="7" language="java" name="de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/SubTypeConstraint.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="220" x="1088" y="164"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="8" language="java" name="de.dhbwstuttgart.strucTypes.exception.IllegalInterfaceTypeException"
|
||||
project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/exception/IllegalInterfaceTypeException.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="218" x="1151" y="371"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="9" language="java" name="de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException"
|
||||
project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/exception/ImpossibleSubTypeException.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="218" x="1156" y="472"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="10" language="java" name="de.dhbwstuttgart.strucTypes.Solve" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/Solve.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="587" y="685"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<interface id="11" language="java" name="de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure"
|
||||
project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="665" y="849"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</interface>
|
||||
<class id="12" language="java" name="de.dhbwstuttgart.strucTypes.StrucTypeUnify" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/StrucTypeUnify.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="334" y="859"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="13" language="java" name="de.dhbwstuttgart.strucTypes.StrucTypeUnifyUtils" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/StrucTypeUnifyUtils.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="315" y="642"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="14" language="java" name="de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException"
|
||||
project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/exception/InconsistentConstraintsException.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="1241" y="600"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="15" language="java" name="de.dhbwstuttgart.strucTypes.model.SolvedClass" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/model/SolvedClass.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="782" y="572"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="16" language="java" name="de.dhbwstuttgart.strucTypes.visitor.InferTypes" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/InferTypes.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="864" y="690"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="17" language="java" name="de.dhbwstuttgart.strucTypes.visitor.TypeExtract" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/TypeExtract.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="198" x="-2" y="553"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="18" language="java" name="de.dhbwstuttgart.strucTypes.visitor.TypeVar" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/TypeVar.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="198" x="-2" y="640"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="19" language="java" name="de.dhbwstuttgart.typeinference.unify.model.UnifyPair" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="292" y="767"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="20" language="java" name="de.dhbwstuttgart.strucTypes.constraint.FieldConstraint" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/FieldConstraint.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="862" y="72"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="21" language="java" name="de.dhbwstuttgart.strucTypes.constraint.MethodConstraint" project="JavaTXcompiler"
|
||||
file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/constraint/MethodConstraint.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="1110" y="77"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</class>
|
||||
<interface id="22" language="java" name="de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor"
|
||||
project="JavaTXcompiler" file="/JavaTXcompiler/src/de/dhbwstuttgart/strucTypes/visitor/ASTReturnVisitor.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="60" width="198" x="1031" y="703"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</display>
|
||||
</interface>
|
||||
<association id="23">
|
||||
<end type="SOURCE" refId="1" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="24" name="constraintsSet"/>
|
||||
<multiplicity id="25" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="26">
|
||||
<end type="SOURCE" refId="2" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="27" name="fieldConstraints"/>
|
||||
<multiplicity id="28" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="20" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="29">
|
||||
<end type="SOURCE" refId="4"/>
|
||||
<end type="TARGET" refId="17"/>
|
||||
</dependency>
|
||||
<generalization id="30">
|
||||
<end type="SOURCE" refId="1"/>
|
||||
<end type="TARGET" refId="5"/>
|
||||
</generalization>
|
||||
<generalization id="31">
|
||||
<end type="SOURCE" refId="4"/>
|
||||
<end type="TARGET" refId="5"/>
|
||||
</generalization>
|
||||
<generalization id="32">
|
||||
<end type="SOURCE" refId="17"/>
|
||||
<end type="TARGET" refId="5"/>
|
||||
</generalization>
|
||||
<association id="33">
|
||||
<end type="SOURCE" refId="15" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="34" name="constraints"/>
|
||||
<multiplicity id="35" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="36">
|
||||
<end type="SOURCE" refId="4" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="37" name="constraints"/>
|
||||
<multiplicity id="38" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="39">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="13"/>
|
||||
</dependency>
|
||||
<dependency id="40">
|
||||
<end type="SOURCE" refId="6"/>
|
||||
<end type="TARGET" refId="9"/>
|
||||
</dependency>
|
||||
<association id="41">
|
||||
<end type="SOURCE" refId="17" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="42" name="grtToTphMap"/>
|
||||
<multiplicity id="43" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="44">
|
||||
<end type="SOURCE" refId="7"/>
|
||||
<end type="TARGET" refId="16"/>
|
||||
</dependency>
|
||||
<association id="45">
|
||||
<end type="SOURCE" refId="17" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="46" name="subTypeConstraints"/>
|
||||
<multiplicity id="47" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="48">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="18"/>
|
||||
</dependency>
|
||||
<association id="49">
|
||||
<end type="SOURCE" refId="2" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="50" name="subTypeConstraints"/>
|
||||
<multiplicity id="51" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="52">
|
||||
<end type="SOURCE" refId="21" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="53" name="arguments"/>
|
||||
<multiplicity id="54" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="55">
|
||||
<end type="SOURCE" refId="4"/>
|
||||
<end type="TARGET" refId="7"/>
|
||||
</dependency>
|
||||
<association id="56">
|
||||
<end type="SOURCE" refId="6" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="57" name="subTypeConstraints"/>
|
||||
<multiplicity id="58" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="59">
|
||||
<end type="SOURCE" refId="21"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<dependency id="60">
|
||||
<end type="SOURCE" refId="21"/>
|
||||
<end type="TARGET" refId="16"/>
|
||||
</dependency>
|
||||
<dependency id="61">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="12"/>
|
||||
</dependency>
|
||||
<dependency id="62">
|
||||
<end type="SOURCE" refId="20"/>
|
||||
<end type="TARGET" refId="16"/>
|
||||
</dependency>
|
||||
<association id="63">
|
||||
<end type="SOURCE" refId="10" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="64" name="fc"/>
|
||||
<multiplicity id="65" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="11" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<generalization id="66">
|
||||
<end type="SOURCE" refId="6"/>
|
||||
<end type="TARGET" refId="5"/>
|
||||
</generalization>
|
||||
<association id="67">
|
||||
<end type="SOURCE" refId="6" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="68" name="inferredTypes"/>
|
||||
<multiplicity id="69" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="70">
|
||||
<end type="SOURCE" refId="1"/>
|
||||
<end type="TARGET" refId="4"/>
|
||||
</dependency>
|
||||
<association id="71">
|
||||
<end type="SOURCE" refId="4" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="72" name="inferredTypes"/>
|
||||
<multiplicity id="73" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="74">
|
||||
<end type="SOURCE" refId="2"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<association id="75">
|
||||
<end type="SOURCE" refId="3" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="76" name="EMPTY"/>
|
||||
<multiplicity id="77" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="78">
|
||||
<end type="SOURCE" refId="13"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<dependency id="79">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="16"/>
|
||||
</dependency>
|
||||
<dependency id="80">
|
||||
<end type="SOURCE" refId="6"/>
|
||||
<end type="TARGET" refId="8"/>
|
||||
</dependency>
|
||||
<association id="81">
|
||||
<end type="SOURCE" refId="1" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="82" name="inferredTypes"/>
|
||||
<multiplicity id="83" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="84">
|
||||
<end type="SOURCE" refId="10" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="85" name="inferredTypes"/>
|
||||
<multiplicity id="86" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="87">
|
||||
<end type="SOURCE" refId="18" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="88" name="inferredTypes"/>
|
||||
<multiplicity id="89" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="90">
|
||||
<end type="SOURCE" refId="16" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="91" name="inferredTypes"/>
|
||||
<multiplicity id="92" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="93">
|
||||
<end type="SOURCE" refId="12" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="94" name="fc"/>
|
||||
<multiplicity id="95" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="11" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="96">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="14"/>
|
||||
</dependency>
|
||||
<realization id="97">
|
||||
<end type="SOURCE" refId="16"/>
|
||||
<end type="TARGET" refId="22"/>
|
||||
</realization>
|
||||
<dependency id="98">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="15"/>
|
||||
</dependency>
|
||||
<association id="99">
|
||||
<end type="SOURCE" refId="6" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="100" name="constraintsSet"/>
|
||||
<multiplicity id="101" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="102">
|
||||
<end type="SOURCE" refId="20"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<association id="103">
|
||||
<end type="SOURCE" refId="10" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="104" name="constraints"/>
|
||||
<multiplicity id="105" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="106">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="19"/>
|
||||
</dependency>
|
||||
<association id="107">
|
||||
<end type="SOURCE" refId="12" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="108" name="pairs"/>
|
||||
<multiplicity id="109" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="19" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<dependency id="110">
|
||||
<end type="SOURCE" refId="10"/>
|
||||
<end type="TARGET" refId="17"/>
|
||||
</dependency>
|
||||
<dependency id="111">
|
||||
<end type="SOURCE" refId="7"/>
|
||||
<end type="TARGET" refId="3"/>
|
||||
</dependency>
|
||||
<association id="112">
|
||||
<end type="SOURCE" refId="2" navigable="false" variant="ASSOCIATION">
|
||||
<attribute id="113" name="methodConstraints"/>
|
||||
<multiplicity id="114" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="21" navigable="true" variant="ASSOCIATION"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="false"
|
||||
sort-features="false" accessors="false" visibility="false">
|
||||
<attributes public="false" package="false" protected="false" private="false" static="false"/>
|
||||
<operations public="false" package="false" protected="false" private="false" static="false"/>
|
||||
</classifier-display>
|
||||
<association-display labels="true" multiplicity="true"/>
|
||||
</class-diagram>
|
@ -0,0 +1,27 @@
|
||||
package de.dhbwstuttgart.strucTypes.exception;
|
||||
|
||||
public class IllegalInterfaceTypeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public IllegalInterfaceTypeException() {
|
||||
}
|
||||
|
||||
public IllegalInterfaceTypeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public IllegalInterfaceTypeException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public IllegalInterfaceTypeException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public IllegalInterfaceTypeException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package de.dhbwstuttgart.strucTypes.exception;
|
||||
|
||||
public class ImpossibleSubTypeException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ImpossibleSubTypeException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ImpossibleSubTypeException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public ImpossibleSubTypeException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ImpossibleSubTypeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ImpossibleSubTypeException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package de.dhbwstuttgart.strucTypes.exception;
|
||||
|
||||
public class InconsistentConstraintsException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InconsistentConstraintsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InconsistentConstraintsException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package de.dhbwstuttgart.strucTypes.model;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
|
||||
public class ClassOrInterfaceFactory {
|
||||
|
||||
public static Optional<ClassOrInterface> createClass(JavaClassName name) {
|
||||
try {
|
||||
return Optional.of(ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString())));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static Optional<ClassOrInterface> createClass(RefType refType) {
|
||||
return ClassOrInterfaceFactory.createClass(refType.getName());
|
||||
}
|
||||
}
|
107
src/de/dhbwstuttgart/strucTypes/model/InferredTypes.java
Normal file
107
src/de/dhbwstuttgart/strucTypes/model/InferredTypes.java
Normal file
@ -0,0 +1,107 @@
|
||||
package de.dhbwstuttgart.strucTypes.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class InferredTypes implements Map<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric> {
|
||||
|
||||
private Map<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric> inferredTypes = new HashMap<>();
|
||||
|
||||
public static final InferredTypes EMPTY = new InferredTypes();
|
||||
|
||||
public void resolveTransitiveTypes() {
|
||||
Set<RefTypeOrTPHOrWildcardOrGeneric> keySet = this.inferredTypes.keySet();
|
||||
for (RefTypeOrTPHOrWildcardOrGeneric key : keySet) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric value = this.inferredTypes.get(key);
|
||||
if (value instanceof TypePlaceholder && keySet.contains(value)) {
|
||||
this.inferredTypes.put(key, this.inferredTypes.get(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return inferredTypes.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return inferredTypes.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return inferredTypes.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return inferredTypes.containsValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric get(Object key) {
|
||||
return inferredTypes.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric put(RefTypeOrTPHOrWildcardOrGeneric key, RefTypeOrTPHOrWildcardOrGeneric value) {
|
||||
return inferredTypes.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric remove(Object key) {
|
||||
return inferredTypes.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends RefTypeOrTPHOrWildcardOrGeneric, ? extends RefTypeOrTPHOrWildcardOrGeneric> m) {
|
||||
inferredTypes.putAll(m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
inferredTypes.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RefTypeOrTPHOrWildcardOrGeneric> keySet() {
|
||||
return inferredTypes.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RefTypeOrTPHOrWildcardOrGeneric> values() {
|
||||
return inferredTypes.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<java.util.Map.Entry<RefTypeOrTPHOrWildcardOrGeneric, RefTypeOrTPHOrWildcardOrGeneric>> entrySet() {
|
||||
return inferredTypes.entrySet();
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric infer(RefTypeOrTPHOrWildcardOrGeneric type){
|
||||
return inferredTypes.get(type) != null ? inferredTypes.get(type) : type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "[";
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> iterator = this.inferredTypes.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = iterator.next();
|
||||
s += type + " -> " + inferredTypes.get(type);
|
||||
if (iterator.hasNext()) {
|
||||
s += ", ";
|
||||
}
|
||||
}
|
||||
s += "]";
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
58
src/de/dhbwstuttgart/strucTypes/model/SolvedClass.java
Normal file
58
src/de/dhbwstuttgart/strucTypes/model/SolvedClass.java
Normal file
@ -0,0 +1,58 @@
|
||||
package de.dhbwstuttgart.strucTypes.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
|
||||
public class SolvedClass extends ClassOrInterface {
|
||||
|
||||
private Set<SubTypeConstraint> constraints = new HashSet<>();
|
||||
private List<ClassOrInterface> generatedInterfaces = new ArrayList<>();
|
||||
|
||||
public SolvedClass(int modifiers, JavaClassName name, List<Field> fielddecl,
|
||||
List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset,
|
||||
Set<SubTypeConstraint> constraints, List<ClassOrInterface> generatedInterfaces) {
|
||||
super(modifiers, name, fielddecl, methods, constructors, genericClassParameters, superClass, isInterface,
|
||||
implementedInterfaces, offset);
|
||||
this.constraints = constraints;
|
||||
this.generatedInterfaces = generatedInterfaces;
|
||||
}
|
||||
|
||||
public SolvedClass(ClassOrInterface classOrInterface, Set<SubTypeConstraint> constraints,
|
||||
List<ClassOrInterface> generatedInterfaces) {
|
||||
this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(),
|
||||
classOrInterface.getMethods(), classOrInterface.getConstructors(), classOrInterface.getGenerics(),
|
||||
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
|
||||
classOrInterface.getOffset(), constraints, generatedInterfaces);
|
||||
}
|
||||
|
||||
public SolvedClass(ClassOrInterface classOrInterface, GenericDeclarationList generics,
|
||||
Set<SubTypeConstraint> constraints, List<ClassOrInterface> generatedInterfaces) {
|
||||
this(classOrInterface.getModifiers(), classOrInterface.getClassName(), classOrInterface.getFieldDecl(),
|
||||
classOrInterface.getMethods(), classOrInterface.getConstructors(), generics,
|
||||
classOrInterface.getSuperClass(), classOrInterface.isInterface, classOrInterface.getSuperInterfaces(),
|
||||
classOrInterface.getOffset(), constraints, generatedInterfaces);
|
||||
}
|
||||
|
||||
public Set<SubTypeConstraint> getConstraints() {
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getGeneratedInterfaces() {
|
||||
return generatedInterfaces;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package de.dhbwstuttgart.strucTypes.printutils;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.FieldConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.MethodConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
public class PrintConstraints {
|
||||
|
||||
public void print(ConstraintsSet constraintsSet) {
|
||||
printSubTypeConstraints(constraintsSet.getSubTypeConstraints());
|
||||
printFieldConstraints(constraintsSet.getFieldConstraints());
|
||||
printMethodConstraints(constraintsSet.getMethodConstraints());
|
||||
}
|
||||
|
||||
public void printSubTypeConstraints(Set<SubTypeConstraint> constraints) {
|
||||
System.out.println("\n SubTypeConstraints:");
|
||||
constraints.forEach(System.out::println);
|
||||
// constraints.forEach(c -> System.out
|
||||
// .println(String.format("%s <* %s", c.getSubtype().toString(),
|
||||
// c.getSupertype().toString())));
|
||||
}
|
||||
|
||||
public void printSubTypeConstraintsAsUnifyPair(Set<UnifyPair> constraints){
|
||||
System.out.println("\n SubTypeConstraints:");
|
||||
constraints.forEach(System.out::println);
|
||||
}
|
||||
|
||||
public void printFieldConstraints(Set<FieldConstraint> constraints) {
|
||||
System.out.println("\n FieldConstraints:");
|
||||
constraints.forEach(System.out::println);
|
||||
// constraints.forEach(c -> System.out.println(String.format("F(%s, %s,
|
||||
// %s)", c.getClassType().toString(),
|
||||
// c.getFieldName(), c.getFieldType().toString())));
|
||||
}
|
||||
|
||||
public void printMethodConstraints(Set<MethodConstraint> constraints) {
|
||||
System.out.println("\n MethodConstraints:");
|
||||
constraints.forEach(System.out::println);
|
||||
// constraints.forEach(c -> {
|
||||
// StringBuilder sb = new StringBuilder("M(");
|
||||
// sb.append(c.getClassType().toString());
|
||||
// sb.append(", ");
|
||||
// sb.append(c.getMethodName());
|
||||
// sb.append(", [");
|
||||
// List<SubTypeConstraint> arguments = c.getArguments();
|
||||
// if (!arguments.isEmpty()) {
|
||||
// Iterator<SubTypeConstraint> iterator = arguments.iterator();
|
||||
// while (iterator.hasNext()) {
|
||||
// RefTypeOrTPHOrWildcardOrGeneric subtype =
|
||||
// iterator.next().getSubtype();
|
||||
// sb.append(subtype.toString());
|
||||
// if (iterator.hasNext()) {
|
||||
// sb.append(", ");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// sb.append("],(");
|
||||
// sb.append(c.getReturnType().toString());
|
||||
// sb.append(", [");
|
||||
// if (!arguments.isEmpty()) {
|
||||
// Iterator<SubTypeConstraint> iterator = arguments.iterator();
|
||||
// while (iterator.hasNext()) {
|
||||
// RefTypeOrTPHOrWildcardOrGeneric supertype =
|
||||
// iterator.next().getSupertype();
|
||||
// sb.append(supertype.toString());
|
||||
// if (iterator.hasNext()) {
|
||||
// sb.append(", ");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// sb.append("]))");
|
||||
// System.out.println(sb.toString());
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package de.dhbwstuttgart.strucTypes.printutils;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
|
||||
public class PrintInferredTypes {
|
||||
|
||||
public static void print(InferredTypes inferredTypes){
|
||||
System.out.println("\n Inferred Types:");
|
||||
inferredTypes.keySet().forEach(key -> System.out.println("[" + key + " -> " + inferredTypes.get(key) + "]"));
|
||||
}
|
||||
}
|
@ -0,0 +1,405 @@
|
||||
package de.dhbwstuttgart.strucTypes.printutils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class SyntaxTreePrinter implements ASTVisitor {
|
||||
|
||||
private InferredTypes inferredTypes;
|
||||
|
||||
public SyntaxTreePrinter() {
|
||||
this(InferredTypes.EMPTY);
|
||||
}
|
||||
|
||||
public SyntaxTreePrinter(InferredTypes inferredTypes) {
|
||||
this.inferredTypes = inferredTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SourceFile sourceFile) {
|
||||
sourceFile.KlassenVektor.forEach(cl -> cl.accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
JavaClassName className = classOrInterface.getClassName();
|
||||
List<Field> fields = classOrInterface.getFieldDecl();
|
||||
List<Method> methods = classOrInterface.getMethods();
|
||||
RefType superClass = classOrInterface.getSuperClass();
|
||||
Collection<RefType> implementedInterfaces = classOrInterface.getSuperInterfaces();
|
||||
GenericDeclarationList generics = classOrInterface.getGenerics();
|
||||
|
||||
System.out.print("\nclass: " + className);
|
||||
Iterator<GenericTypeVar> iterator = generics.iterator();
|
||||
if (iterator.hasNext()) {
|
||||
System.out.print(" <");
|
||||
while (iterator.hasNext()) {
|
||||
GenericTypeVar g = iterator.next();
|
||||
g.accept(this);
|
||||
if (iterator.hasNext()) {
|
||||
System.out.print(", ");
|
||||
}
|
||||
}
|
||||
System.out.print(">");
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
fields.forEach(f -> f.accept(this));
|
||||
methods.forEach(m -> m.accept(this));
|
||||
|
||||
System.out.print("\n superClass: ");
|
||||
superClass.accept(this);
|
||||
System.out.println();
|
||||
|
||||
if (!implementedInterfaces.isEmpty()) {
|
||||
System.out.println("\n implemented Interfaces: ");
|
||||
implementedInterfaces.forEach(i -> i.accept(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Field field) {
|
||||
String name = field.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = field.getType();
|
||||
System.out.print("field: " + name + " : ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
String name = method.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType();
|
||||
ParameterList parameterList = method.getParameterList();
|
||||
System.out.print("\n method: " + name + " : ");
|
||||
returnType.accept(this);
|
||||
System.out.println();
|
||||
parameterList.accept(this);
|
||||
method.block.accept(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
block.statements.forEach(s -> s.accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
List<Expression> arguments = argumentList.getArguments();
|
||||
if (!arguments.isEmpty()) {
|
||||
System.out.println("arguments: ");
|
||||
arguments.forEach(a -> a.accept(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ParameterList formalParameters) {
|
||||
List<FormalParameter> formalparalist = formalParameters.getFormalparalist();
|
||||
formalparalist.forEach(p -> p.accept(this));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FormalParameter formalParameter) {
|
||||
String name = formalParameter.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = formalParameter.getType();
|
||||
System.out.print("parameter: " + name + " : ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
String name = methodCall.name;
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = methodCall.getType();
|
||||
ArgumentList argumentList = methodCall.getArgumentList();
|
||||
Receiver receiver = methodCall.receiver;
|
||||
System.out.print("methodCall: " + name + " : ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
argumentList.accept(this);
|
||||
System.out.print("receiver: ");
|
||||
receiver.accept(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = aReturn.getType();
|
||||
System.out.print("returnType: ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
aReturn.retexpr.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
String name = localVar.name;
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = localVar.getType();
|
||||
System.out.print("localVar: " + name + " : ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVarDecl localVarDecl) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
String name = fieldVar.fieldVarName;
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = fieldVar.getType();
|
||||
Expression receiver = fieldVar.receiver;
|
||||
System.out.print("fieldVar: " + name + " : ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
System.out.println("receiver: ");
|
||||
receiver.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr castExpr) {
|
||||
Expression expr = castExpr.expr;
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = castExpr.getType();
|
||||
System.out.print("castExpr: ");
|
||||
expr.accept(this);
|
||||
System.out.print("typeCastExpr: ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewClass newClass) {
|
||||
String name = newClass.name;
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = newClass.getType();
|
||||
ArgumentList argumentList = newClass.getArgumentList();
|
||||
System.out.print("new: " + name + " : ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
argumentList.accept(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
ArgumentList arglist = aThis.arglist;
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = aThis.getType();
|
||||
System.out.print("this : ");
|
||||
type.accept(this);
|
||||
if (arglist != null)
|
||||
arglist.accept(this);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RefType refType) {
|
||||
System.out.print(refType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
if (inferredTypes.get(typePlaceholder) != null) {
|
||||
inferredTypes.get(typePlaceholder).accept(this);
|
||||
} else {
|
||||
System.out.print(typePlaceholder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewArray newArray) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ReturnVoid aReturn) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StaticClassName staticClassName) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Super aSuper) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Assign assign) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStmt forStmt) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
System.out.println("binary");
|
||||
// binary.lexpr.accept(this);
|
||||
// System.out.println(binary.operation);
|
||||
// binary.rexpr.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EmptyStmt emptyStmt) {
|
||||
System.out.println("empty statement");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric type = literal.getType();
|
||||
System.out.print("literal: ");
|
||||
type.accept(this);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InstanceOf instanceOf) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperCall superCall) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionReceiver expressionReceiver) {
|
||||
Expression expr = expressionReceiver.expr;
|
||||
// RefTypeOrTPHOrWildcardOrGeneric type = expressionReceiver.getType();
|
||||
// System.out.print("expressionReceiverType: ");
|
||||
// type.accept(this);
|
||||
// System.out.print(" expressionReceiver: ");
|
||||
expr.accept(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericTypeVar genericTypeVar) {
|
||||
System.out.print(genericTypeVar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericDeclarationList genericTypeVars) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constructor field) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
System.out.println("GRT " + genericRefType.getParsedName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
137
src/de/dhbwstuttgart/strucTypes/visitor/ASTReturnVisitor.java
Normal file
137
src/de/dhbwstuttgart/strucTypes/visitor/ASTReturnVisitor.java
Normal file
@ -0,0 +1,137 @@
|
||||
package de.dhbwstuttgart.strucTypes.visitor;
|
||||
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public interface ASTReturnVisitor {
|
||||
|
||||
// ASTVisitor
|
||||
SourceFile visit(SourceFile sourceFile);
|
||||
|
||||
GenericTypeVar visit(GenericTypeVar genericTypeVar);
|
||||
|
||||
FormalParameter visit(FormalParameter formalParameter);
|
||||
|
||||
GenericDeclarationList visit(GenericDeclarationList genericTypeVars);
|
||||
|
||||
Field visit(Field field);
|
||||
|
||||
Method visit(Method method);
|
||||
|
||||
Constructor visit(Constructor constructor);
|
||||
|
||||
ParameterList visit(ParameterList formalParameters);
|
||||
|
||||
ClassOrInterface visit(ClassOrInterface classOrInterface);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType);
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType);
|
||||
//StatementVisitor
|
||||
ArgumentList visit(ArgumentList argumentList);
|
||||
|
||||
LambdaExpression visit(LambdaExpression lambdaExpression);
|
||||
|
||||
Assign visit(Assign assign);
|
||||
|
||||
BinaryExpr visit(BinaryExpr binary);
|
||||
|
||||
Block visit(Block block);
|
||||
|
||||
CastExpr visit(CastExpr castExpr);
|
||||
|
||||
EmptyStmt visit(EmptyStmt emptyStmt);
|
||||
|
||||
FieldVar visit(FieldVar fieldVar);
|
||||
|
||||
ForStmt visit(ForStmt forStmt);
|
||||
|
||||
IfStmt visit(IfStmt ifStmt);
|
||||
|
||||
InstanceOf visit(InstanceOf instanceOf);
|
||||
|
||||
LocalVar visit(LocalVar localVar);
|
||||
|
||||
LocalVarDecl visit(LocalVarDecl localVarDecl);
|
||||
|
||||
MethodCall visit(MethodCall methodCall);
|
||||
|
||||
NewClass visit(NewClass newClass);
|
||||
|
||||
NewArray visit(NewArray newArray);
|
||||
|
||||
Return visit(Return aReturn);
|
||||
|
||||
ReturnVoid visit(ReturnVoid aReturn);
|
||||
|
||||
StaticClassName visit(StaticClassName staticClassName);
|
||||
|
||||
Super visit(Super aSuper);
|
||||
|
||||
This visit(This aThis);
|
||||
|
||||
WhileStmt visit(WhileStmt whileStmt);
|
||||
|
||||
DoStmt visit(DoStmt doStmt);
|
||||
|
||||
AssignToField visit(AssignToField assignLeftSide);
|
||||
|
||||
AssignToLocal visit(AssignToLocal assignLeftSide);
|
||||
|
||||
SuperCall visit(SuperCall superCall);
|
||||
|
||||
ExpressionReceiver visit(ExpressionReceiver expressionReceiver);
|
||||
|
||||
UnaryExpr visit(UnaryExpr unaryExpr);
|
||||
|
||||
Literal visit(Literal literal);
|
||||
|
||||
}
|
309
src/de/dhbwstuttgart/strucTypes/visitor/DefaultASTVisitor.java
Normal file
309
src/de/dhbwstuttgart/strucTypes/visitor/DefaultASTVisitor.java
Normal file
@ -0,0 +1,309 @@
|
||||
package de.dhbwstuttgart.strucTypes.visitor;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public abstract class DefaultASTVisitor implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Assign assign) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr castExpr) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EmptyStmt emptyStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStmt forStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InstanceOf instanceOf) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVarDecl localVarDecl) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewClass methodCall) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewArray newArray) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ReturnVoid aReturn) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StaticClassName staticClassName) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Super aSuper) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperCall superCall) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionReceiver expressionReceiver) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SourceFile sourceFile) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericTypeVar genericTypeVar) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FormalParameter formalParameter) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericDeclarationList genericTypeVars) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Field field) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method field) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constructor field) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ParameterList formalParameters) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RefType refType) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
}
|
389
src/de/dhbwstuttgart/strucTypes/visitor/InferTypes.java
Normal file
389
src/de/dhbwstuttgart/strucTypes/visitor/InferTypes.java
Normal file
@ -0,0 +1,389 @@
|
||||
package de.dhbwstuttgart.strucTypes.visitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Inferiert alle TypePlaceholder durch inferredTypes und erstzt sie durch
|
||||
* GenericTypeVar, falls der Name des Typeplaceholder mit dem Namen eines
|
||||
* generics in der GenericdeclarationList generics <EFBFBD>bereinstimmt.
|
||||
*
|
||||
* @author mvr
|
||||
*
|
||||
*/
|
||||
public class InferTypes implements ASTReturnVisitor {
|
||||
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
private GenericDeclarationList generics = new GenericDeclarationList(new ArrayList<>(), new NullToken());
|
||||
|
||||
public InferTypes(InferredTypes inferredTypes) {
|
||||
this.inferredTypes = inferredTypes;
|
||||
}
|
||||
|
||||
public InferTypes(InferredTypes inferredTypes, GenericDeclarationList generics) {
|
||||
this.inferredTypes = inferredTypes;
|
||||
this.generics = generics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceFile visit(SourceFile sourceFile) {
|
||||
return new SourceFile(sourceFile.getPkgName(),
|
||||
sourceFile.getClasses().stream().map(c -> c.accept(this)).collect(Collectors.toList()),
|
||||
sourceFile.getImports());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constructor visit(Constructor constructor) {
|
||||
int modifier = constructor.modifier;
|
||||
String name = constructor.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = constructor.getReturnType().accept(this);
|
||||
ParameterList parameterList = constructor.getParameterList().accept(this);
|
||||
Block codeInsideConstructor = constructor.block.accept(this);
|
||||
GenericDeclarationList gtvDeclarations = ((GenericDeclarationList) constructor.getGenerics()).accept(this);
|
||||
Token offset = constructor.getOffset();
|
||||
List<Statement> fieldInitializations = new ArrayList<>();
|
||||
return new Constructor(modifier, name, returnType, parameterList, codeInsideConstructor, gtvDeclarations,
|
||||
offset, fieldInitializations);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericTypeVar visit(GenericTypeVar genericTypeVar) {
|
||||
return new GenericTypeVar(
|
||||
genericTypeVar.getName(), genericTypeVar.getBounds().stream()
|
||||
.map(b -> (RefTypeOrTPHOrWildcardOrGeneric) b.accept(this)).collect(Collectors.toList()),
|
||||
genericTypeVar.getOffset(), new NullToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalParameter visit(FormalParameter formalParameter) {
|
||||
return new FormalParameter(formalParameter.getName(), formalParameter.getType().accept(this),
|
||||
formalParameter.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericDeclarationList visit(GenericDeclarationList genericTypeVars) {
|
||||
List<GenericTypeVar> values = new ArrayList<>();
|
||||
genericTypeVars.forEach(gtv -> values.add(gtv.accept(this)));
|
||||
return new GenericDeclarationList(values, genericTypeVars.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field visit(Field field) {
|
||||
return new Field(field.getName(), field.getType().accept(this), field.modifier, field.getOffset());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method visit(Method method) {
|
||||
int modifier = method.modifier;
|
||||
String name = method.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType().accept(this);
|
||||
ParameterList parameterList = method.getParameterList().accept(this);
|
||||
Block block = method.block.accept(this);
|
||||
GenericDeclarationList gtvDeclarations = ((GenericDeclarationList) method.getGenerics()).accept(this);
|
||||
Token offset = method.getOffset();
|
||||
return new Method(modifier, name, returnType, parameterList, block, gtvDeclarations, offset);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterList visit(ParameterList formalParameters) {
|
||||
for (FormalParameter formalParameter : formalParameters) {
|
||||
formalParameter.accept(this);
|
||||
}
|
||||
return new ParameterList(
|
||||
formalParameters.getFormalparalist().stream().map(p -> p.accept(this)).collect(Collectors.toList()),
|
||||
formalParameters.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassOrInterface visit(ClassOrInterface classOrInterface) {
|
||||
int modifiers = classOrInterface.getModifiers();
|
||||
JavaClassName name = classOrInterface.getClassName();
|
||||
List<Field> fielddecl = classOrInterface.getFieldDecl().stream().map(f -> f.accept(this))
|
||||
.collect(Collectors.toList());
|
||||
List<Method> methods = classOrInterface.getMethods().stream().map(m -> m.accept(this))
|
||||
.collect(Collectors.toList());
|
||||
List<Constructor> constructors = classOrInterface.getConstructors().stream()
|
||||
.map(c -> (Constructor) c.accept(this)).collect(Collectors.toList());
|
||||
GenericDeclarationList genericClassParameters = classOrInterface.getGenerics().accept(this);
|
||||
RefType superClass = (RefType) classOrInterface.getSuperClass().accept(this);
|
||||
Boolean isInterface = classOrInterface.isInterface;
|
||||
List<RefType> implementedInterfaces = classOrInterface.getSuperInterfaces().stream()
|
||||
.map(i -> (RefType) i.accept(this)).collect(Collectors.toList());
|
||||
Token offset = classOrInterface.getOffset();
|
||||
return new ClassOrInterface(modifiers, name, fielddecl, methods, constructors, genericClassParameters,
|
||||
superClass, isInterface, implementedInterfaces, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefType visit(RefType refType) {
|
||||
|
||||
return refType.getParaList() == null ? refType
|
||||
: new RefType(refType.getName(), refType.getParaList().stream()
|
||||
.map(p -> (RefTypeOrTPHOrWildcardOrGeneric) p.accept(this)).collect(Collectors.toList()),
|
||||
refType.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperWildcardType visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric inferredType = inferredTypes.infer(typePlaceholder);
|
||||
if (inferredType instanceof TypePlaceholder) {
|
||||
TypePlaceholder inferredTypeTPH = (TypePlaceholder) inferredType;
|
||||
if (generics.contains(inferredTypeTPH.getName())) {
|
||||
return new GenericRefType(inferredTypeTPH.getName(), typePlaceholder.getOffset());
|
||||
}
|
||||
}
|
||||
return inferredType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtendsWildcardType visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric inferredType = inferredTypes.infer(genericRefType);
|
||||
return inferredType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentList visit(ArgumentList argumentList) {
|
||||
return new ArgumentList(argumentList.getArguments().stream().map(expr -> (Expression) expr.accept(this))
|
||||
.collect(Collectors.toList()), argumentList.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaExpression visit(LambdaExpression lambdaExpression) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Assign visit(Assign assign) {
|
||||
return assign;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryExpr visit(BinaryExpr binary) {
|
||||
return binary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block visit(Block block) {
|
||||
return new Block(
|
||||
block.getStatements().stream().map(s -> (Statement) s.accept(this)).collect(Collectors.toList()),
|
||||
block.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastExpr visit(CastExpr castExpr) {
|
||||
return new CastExpr(castExpr.getType().accept(this), castExpr.expr == null ? null : castExpr.expr.accept(this),
|
||||
castExpr.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptyStmt visit(EmptyStmt emptyStmt) {
|
||||
return emptyStmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVar visit(FieldVar fieldVar) {
|
||||
return new FieldVar(fieldVar.receiver == null ? null : fieldVar.receiver.accept(this), fieldVar.fieldVarName,
|
||||
fieldVar.getType().accept(this), fieldVar.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForStmt visit(ForStmt forStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfStmt visit(IfStmt ifStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceOf visit(InstanceOf instanceOf) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVar visit(LocalVar localVar) {
|
||||
return new LocalVar(localVar.name, localVar.getType().accept(this), localVar.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVarDecl visit(LocalVarDecl localVarDecl) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodCall visit(MethodCall methodCall) {
|
||||
methodCall.getType().accept(this);
|
||||
methodCall.getArgumentList().accept(this);
|
||||
return new MethodCall(methodCall.getType().accept(this),
|
||||
methodCall.receiver == null ? null : methodCall.receiver.accept(this), methodCall.name,
|
||||
methodCall.getArgumentList().accept(this), methodCall.getOffset());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewClass visit(NewClass newClass) {
|
||||
return new NewClass(newClass.getType().accept(this), newClass.getArgumentList().accept(this),
|
||||
newClass.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewArray visit(NewArray newArray) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Return visit(Return aReturn) {
|
||||
return new Return(aReturn.retexpr == null ? null : aReturn.retexpr.accept(this), aReturn.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnVoid visit(ReturnVoid aReturn) {
|
||||
return aReturn;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaticClassName visit(StaticClassName staticClassName) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Super visit(Super aSuper) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public This visit(This aThis) {
|
||||
// als Typ wird immer ein neuer TypePlaceholder zugeordnet.
|
||||
return aThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhileStmt visit(WhileStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoStmt visit(DoStmt whileStmt) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToField visit(AssignToField assignLeftSide) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToLocal visit(AssignToLocal assignLeftSide) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperCall visit(SuperCall superCall) {
|
||||
if (superCall.getArgumentList().getArguments() == null) {
|
||||
return superCall;
|
||||
}
|
||||
return new SuperCall(superCall.getArgumentList().accept(this), superCall.getOffset());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionReceiver visit(ExpressionReceiver expressionReceiver) {
|
||||
return new ExpressionReceiver(expressionReceiver.expr == null ? null : expressionReceiver.expr.accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnaryExpr visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Literal visit(Literal literal) {
|
||||
return literal;
|
||||
|
||||
}
|
||||
|
||||
}
|
253
src/de/dhbwstuttgart/strucTypes/visitor/TYPEExpr.java
Normal file
253
src/de/dhbwstuttgart/strucTypes/visitor/TYPEExpr.java
Normal file
@ -0,0 +1,253 @@
|
||||
package de.dhbwstuttgart.strucTypes.visitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.FieldConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.MethodConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class TYPEExpr extends DefaultASTVisitor {
|
||||
|
||||
private ClassOrInterface aThis;
|
||||
private ConstraintsSet constraints = new ConstraintsSet();
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
|
||||
public TYPEExpr() {
|
||||
}
|
||||
|
||||
public ConstraintsSet getConstraints() {
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
public InferredTypes getInferredTypes() {
|
||||
return inferredTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
this.aThis = classOrInterface;
|
||||
classOrInterface.getMethods().forEach(m -> m.accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalVar localVar) {
|
||||
// keine neuen Constraints. Typisierung bereits im SyntaxTree vorhanden.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
fieldVar.receiver.accept(this);
|
||||
|
||||
// Löst Typen zwischen Feld und Feldvariable auf
|
||||
boolean receiverIsThis = this.inferFieldVarTypes(fieldVar);
|
||||
|
||||
// Ermittelt den Typ ty von fieldVar.receiver und fields(f)
|
||||
TypeExtract fieldTypeVisitor = new TypeExtract();
|
||||
// unterscheide fieldVar.receiver == this
|
||||
if (receiverIsThis) {
|
||||
this.aThis.accept(fieldTypeVisitor);
|
||||
} else {
|
||||
fieldVar.receiver.getType().accept(fieldTypeVisitor);
|
||||
}
|
||||
|
||||
if (!fieldTypeVisitor.isTypeVariable() && fieldTypeVisitor.getField(fieldVar.fieldVarName).isPresent()) {
|
||||
fieldTypeVisitor.getField(fieldVar.fieldVarName)
|
||||
.ifPresent(f -> this.inferredTypes.put((TypePlaceholder) fieldVar.getType(), f.getType()));
|
||||
} // keine neuen Constraints
|
||||
else {
|
||||
FieldConstraint fieldConstraint = new FieldConstraint(fieldVar.receiver.getType(), fieldVar.fieldVarName,
|
||||
fieldVar.getType());
|
||||
this.constraints.addConstraint(fieldConstraint);
|
||||
}
|
||||
this.constraints.inferTypes(fieldTypeVisitor.getGrtToTphMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst die Typenzugehörigkeit zwischen fieldVar mit receiver this und dem
|
||||
* korrespondierenden Feld in der Instanz auf.
|
||||
*
|
||||
* @param fieldVar
|
||||
* @return true, wenn ein passendes Feld in der Instanz gefunden wird.
|
||||
*/
|
||||
private boolean inferFieldVarTypes(FieldVar fieldVar) {
|
||||
if (fieldVar.receiver instanceof This) {
|
||||
this.aThis.getFieldDecl().stream().filter(f -> f.getName().equals(fieldVar.fieldVarName))
|
||||
// keine statische Polymorphie zugelassen
|
||||
.findFirst()
|
||||
.ifPresent(f -> this.inferredTypes.put((TypePlaceholder) fieldVar.getType(), f.getType()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
methodCall.receiver.accept(this);
|
||||
methodCall.arglist.accept(this);
|
||||
|
||||
// ermittelt den Typ ty0 von methodCall.receiver und mtype(m, ty0)
|
||||
TypeExtract methodTypeVisitor = new TypeExtract();
|
||||
// unterscheide methodcall.receiver == this
|
||||
if (methodCall.receiver instanceof ExpressionReceiver
|
||||
&& ((ExpressionReceiver) methodCall.receiver).expr instanceof This) {
|
||||
this.aThis.accept(methodTypeVisitor);
|
||||
} else {
|
||||
methodCall.receiver.getType().accept(methodTypeVisitor);
|
||||
}
|
||||
|
||||
List<Expression> arguments = methodCall.getArgumentList().getArguments();
|
||||
Optional<Method> method = methodTypeVisitor.getMethod(methodCall.name, arguments.size());
|
||||
if (!methodTypeVisitor.isTypeVariable() && method.isPresent()) {
|
||||
Method m = method.get();
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
this.constraints.addConstraint(new SubTypeConstraint(arguments.get(i).getType(),
|
||||
m.getParameterList().getParameterAt(i).getType()));
|
||||
}
|
||||
this.inferredTypes.put((TypePlaceholder) methodCall.getType(), m.getReturnType());
|
||||
|
||||
} else {
|
||||
MethodConstraint methodConstraint = new MethodConstraint(methodCall.receiver.getType(), methodCall.name,
|
||||
new ArrayList<SubTypeConstraint>(), methodCall.getType());
|
||||
arguments.forEach(e -> methodConstraint.addArguments(e.getType()));
|
||||
this.constraints.addConstraint(methodConstraint);
|
||||
}
|
||||
// System.out.println("\ninferred grt:");
|
||||
// System.out.println("map: " + methodTypeVisitor.getGrtToTphMap());
|
||||
// System.out.println("generics: " + methodTypeVisitor.getGenerics());
|
||||
this.constraints.inferTypes(methodTypeVisitor.getGrtToTphMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
argumentList.getArguments().forEach(a -> a.accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr castExpr) {
|
||||
castExpr.expr.accept(this);
|
||||
if (((RefType) castExpr.getType()).getName().equals(this.aThis.getClassName())) {
|
||||
// keine neuen Constraints
|
||||
} else {
|
||||
// implement generics nicht nötig
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NewClass newClass) {
|
||||
newClass.getArgumentList().accept(this);
|
||||
RefType type = (RefType) newClass.getType();
|
||||
TypeExtract typeExtract = new TypeExtract();
|
||||
if (type.getName().equals(this.aThis.getClassName())) {
|
||||
this.aThis.accept(typeExtract);
|
||||
} else {
|
||||
type.accept(typeExtract);
|
||||
// implement generics nicht nötig
|
||||
}
|
||||
this.createNewClassSubTypeConstraints(newClass, typeExtract);
|
||||
}
|
||||
|
||||
private void createNewClassSubTypeConstraints(NewClass newClass, TypeExtract typeExtract) {
|
||||
final List<Expression> arguments = newClass.getArgumentList().getArguments();
|
||||
final List<Field> fields = typeExtract.getFields();
|
||||
final int argumentsSize = arguments.size();
|
||||
final int fieldsSize = fields.size();
|
||||
if (argumentsSize != fieldsSize) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"The number of fields (%d) in %s doesn't match the number of arguments (%d) passed to its constructor.",
|
||||
fieldsSize, newClass.name, argumentsSize));
|
||||
}
|
||||
|
||||
// List of Generics of newClass
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> paraList = ((RefType) newClass.getType()).getParaList();
|
||||
List<FormalParameter> formalparalist = typeExtract.getConstructors().get(0).getParameterList()
|
||||
.getFormalparalist();
|
||||
for (int i = 0; i < argumentsSize; i++) {
|
||||
// Bei Fields wird kein GenericRefType sondern Object als Typ
|
||||
// geparst. Workaround über den Konstruktor.
|
||||
// SubTypeConstraint subTypeConstraint = new
|
||||
// SubTypeConstraint(arguments.get(i).getType(),
|
||||
// fields.get(i).getType());
|
||||
|
||||
// Es darf nur einen Konstruktor mit allen Feldern geben.
|
||||
RefTypeOrTPHOrWildcardOrGeneric supertype = formalparalist.get(i).getType();
|
||||
supertype = supertype instanceof GenericRefType ? paraList.remove(0) : supertype;
|
||||
SubTypeConstraint subTypeConstraint = new SubTypeConstraint(arguments.get(i).getType(), supertype);
|
||||
this.constraints.addConstraint(subTypeConstraint);
|
||||
}
|
||||
typeExtract.getSubTypeConstraints().forEach(this.constraints::addConstraint);
|
||||
// System.out.println("\ninferred grt:");
|
||||
// System.out.println("map: " + typeExtract.getGrtToTphMap());
|
||||
// System.out.println("generics: " + typeExtract.getGenerics());
|
||||
this.constraints.inferTypes(typeExtract.getGrtToTphMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
// TPH von This mit Klasse in inferredTypes verknüpfen
|
||||
if (this.aThis != null) {
|
||||
this.inferredTypes.put((TypePlaceholder) aThis.getType(), ClassOrInterface
|
||||
.generateTypeOfClass(this.aThis.getClassName(), this.aThis.getGenerics(), this.aThis.getOffset()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionReceiver expressionReceiver) {
|
||||
expressionReceiver.expr.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
method.block.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
// Es gibt nur ein Statement: Return
|
||||
block.getStatements().forEach(s -> s.accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
aReturn.retexpr.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
}
|
||||
|
||||
}
|
167
src/de/dhbwstuttgart/strucTypes/visitor/TypeExtract.java
Normal file
167
src/de/dhbwstuttgart/strucTypes/visitor/TypeExtract.java
Normal file
@ -0,0 +1,167 @@
|
||||
package de.dhbwstuttgart.strucTypes.visitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.model.ClassOrInterfaceFactory;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Extrahiert die typisierten Felder und Methoden von ClassOrInterface bzw. von
|
||||
* RefType rekursiv über alle Superklassen und implementierten Interfaces.
|
||||
*
|
||||
* @author mvr
|
||||
*
|
||||
*/
|
||||
public class TypeExtract extends DefaultASTVisitor {
|
||||
|
||||
private List<Field> fields = new ArrayList<>();
|
||||
private List<Method> methods = new ArrayList<>();
|
||||
private List<Constructor> constructors = new ArrayList<>();
|
||||
private List<GenericTypeVar> generics = new ArrayList<>();
|
||||
private InferredTypes grtToTphMap = InferredTypes.EMPTY;
|
||||
private List<SubTypeConstraint> subTypeConstraints = new ArrayList<>();
|
||||
private boolean typeVariable = false;
|
||||
private boolean initialClass = true;
|
||||
|
||||
public List<Field> getFields() {
|
||||
return this.fields;
|
||||
}
|
||||
|
||||
public List<Method> getMethods() {
|
||||
return this.methods;
|
||||
}
|
||||
|
||||
public List<Constructor> getConstructors() {
|
||||
return constructors;
|
||||
}
|
||||
|
||||
public List<GenericTypeVar> getGenerics() {
|
||||
return generics;
|
||||
}
|
||||
|
||||
public InferredTypes getGrtToTphMap() {
|
||||
return grtToTphMap;
|
||||
}
|
||||
|
||||
public List<SubTypeConstraint> getSubTypeConstraints() {
|
||||
return subTypeConstraints;
|
||||
}
|
||||
|
||||
public Optional<Field> getField(String fieldName) {
|
||||
return this.fields.stream().filter(f -> f.getName().equals(fieldName))
|
||||
// keine statische Polymorphie zugelassen
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public Optional<Method> getMethod(String methodName, int parameterCount) {
|
||||
return this.methods.stream()
|
||||
.filter(m -> m.getName().equals(methodName)
|
||||
&& m.getParameterList().getFormalparalist().size() == parameterCount)
|
||||
// keine statische Polymorphie zugelassen
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public boolean isTypeVariable() {
|
||||
return this.typeVariable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
classOrInterface.getFieldDecl().forEach(f -> f.accept(this));
|
||||
classOrInterface.getMethods().forEach(m -> m.accept(this));
|
||||
classOrInterface.getConstructors().forEach(c -> {
|
||||
if (c != null && this.initialClass)
|
||||
c.accept(this);
|
||||
});
|
||||
classOrInterface.getGenerics().accept(this);
|
||||
this.initialClass = false;
|
||||
// superClass(Object) -> Object => unendliche Rekursionstiefe!
|
||||
if (!classOrInterface.getClassName().equals(new JavaClassName("java.lang.Object"))) {
|
||||
classOrInterface.getSuperClass().accept(this);
|
||||
classOrInterface.getSuperInterfaces().forEach(i -> i.accept(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RefType refType) {
|
||||
this.typeVariable = false;
|
||||
Optional<ClassOrInterface> createClass = ClassOrInterfaceFactory.createClass(refType);
|
||||
// refType und createClass haben evtl. unterschiedliche
|
||||
// Klassenparameter (refType -> tph| createClass -> gtv). Diese werden
|
||||
// in grtToTphMap gespeichert.
|
||||
if (createClass.isPresent()) {
|
||||
ClassOrInterface cls = createClass.get();
|
||||
cls.getGenerics().accept(this);
|
||||
Iterator<GenericTypeVar> iteratorGtv = cls.getGenerics().iterator();
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> iteratorTPH = refType.getParaList().iterator();
|
||||
while (iteratorGtv.hasNext()) {
|
||||
GenericTypeVar nextGtv = iteratorGtv.next();
|
||||
GenericRefType grt = new GenericRefType(nextGtv.getName(), nextGtv.getOffset());
|
||||
RefTypeOrTPHOrWildcardOrGeneric nextTPH = iteratorTPH.next();
|
||||
if (nextTPH instanceof TypePlaceholder) {
|
||||
TypePlaceholder tph = (TypePlaceholder) nextTPH;
|
||||
this.grtToTphMap.put(grt, tph);
|
||||
}
|
||||
}
|
||||
cls.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Field field) {
|
||||
this.fields.add(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
this.methods.add(method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
this.typeVariable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constructor constructor) {
|
||||
this.constructors.add(constructor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericDeclarationList genericTypeVars) {
|
||||
genericTypeVars.forEach(gtv -> gtv.accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericTypeVar genericTypeVar) {
|
||||
if (!this.generics.contains(genericTypeVar)) {
|
||||
this.generics.add(genericTypeVar);
|
||||
// Aus den bounds können die Subtypconstraints abgeleitet werden.
|
||||
RefTypeOrTPHOrWildcardOrGeneric bound = genericTypeVar.getBounds().get(0);
|
||||
if (!((bound instanceof RefType)
|
||||
&& ((RefType) bound).getName().equals(new JavaClassName("java.lang.Object")))) {
|
||||
this.subTypeConstraints.add(new SubTypeConstraint(
|
||||
new GenericRefType(genericTypeVar.getName(), genericTypeVar.getOffset()), bound));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GenericRefType genericRefType) {
|
||||
}
|
||||
}
|
38
src/de/dhbwstuttgart/strucTypes/visitor/TypeVar.java
Normal file
38
src/de/dhbwstuttgart/strucTypes/visitor/TypeVar.java
Normal file
@ -0,0 +1,38 @@
|
||||
package de.dhbwstuttgart.strucTypes.visitor;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Extrahiert alle TypePlaceholder.
|
||||
*
|
||||
* @author mvr
|
||||
*
|
||||
*/
|
||||
public class TypeVar extends AbstractASTWalker {
|
||||
|
||||
private Set<TypePlaceholder> typeVars = new HashSet<>();
|
||||
private InferredTypes inferredTypes = new InferredTypes();
|
||||
|
||||
public TypeVar(InferredTypes inferredTypes) {
|
||||
this.inferredTypes = inferredTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypePlaceholder typePlaceholder) {
|
||||
super.visit(typePlaceholder);
|
||||
RefTypeOrTPHOrWildcardOrGeneric inferredType = this.inferredTypes.infer(typePlaceholder);
|
||||
if (inferredType instanceof TypePlaceholder) {
|
||||
this.typeVars.add((TypePlaceholder) inferredType);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<TypePlaceholder> getTypeVars() {
|
||||
return typeVars;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
@ -12,6 +13,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -26,7 +28,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
private List<Method> methods = new ArrayList<>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private RefType superClass;
|
||||
protected boolean isInterface;
|
||||
public boolean isInterface;
|
||||
private List<RefType> implementedInterfaces;
|
||||
private List<Constructor> constructors;
|
||||
|
||||
@ -34,6 +36,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
||||
super(offset);
|
||||
this.modifiers = modifiers;
|
||||
if(isInterface)this.modifiers += Modifier.INTERFACE;
|
||||
this.name = name;
|
||||
this.fields = fielddecl;
|
||||
this.genericClassParameters = genericClassParameters;
|
||||
@ -102,8 +105,13 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassOrInterface accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
public Collection<RefType> getSuperInterfaces() {
|
||||
public List<RefType> getSuperInterfaces() {
|
||||
return implementedInterfaces;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
|
||||
import java.util.List;
|
||||
@ -35,4 +36,9 @@ public class Constructor extends Method {
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constructor accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -40,5 +41,10 @@ public class Field extends SyntaxTreeNode implements TypeScope{
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -26,4 +27,9 @@ public class FormalParameter extends SyntaxTreeNode
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalParameter accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@ -21,6 +23,10 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
||||
gtvs = values;
|
||||
this.offsetOfLastElement = endOffset;
|
||||
}
|
||||
|
||||
public boolean contains(String genericTypeVarName){
|
||||
return gtvs.stream().anyMatch(gtv-> gtv.getName().equals(genericTypeVarName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<GenericTypeVar> iterator() {
|
||||
@ -32,6 +38,12 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GenericDeclarationList accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.gtvs.toString();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -61,4 +62,9 @@ public class GenericTypeVar extends SyntaxTreeNode
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericTypeVar accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
@ -69,4 +70,9 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -39,4 +41,9 @@ public class ParameterList extends SyntaxTreeNode implements Iterable<FormalPara
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterList accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
//import sun.security.x509.X509CertInfo;
|
||||
@ -43,4 +44,9 @@ public class SourceFile extends SyntaxTreeNode{
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceFile accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
//import org.antlr.v4.runtime.misc.Pair;
|
||||
@ -20,4 +21,6 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
}
|
||||
|
||||
public abstract void accept(ASTVisitor visitor);
|
||||
|
||||
public abstract <T> T accept(ASTReturnVisitor visitor);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
@ -30,4 +31,9 @@ public class ArgumentList extends SyntaxTreeNode
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentList accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
@ -26,4 +27,9 @@ public class Assign extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Assign accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
|
||||
public class AssignToField extends AssignLeftSide{
|
||||
@ -13,4 +14,9 @@ public class AssignToField extends AssignLeftSide{
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignToField accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -11,6 +12,11 @@ public class BinaryExpr extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryExpr accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
public enum Operator{
|
||||
ADD, // +
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import java.util.*;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -28,6 +29,11 @@ public class Block extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -22,4 +23,9 @@ public class CastExpr extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastExpr accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -15,4 +16,9 @@ public class DoStmt extends WhileStmt
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -19,4 +20,9 @@ public class EmptyStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptyStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -18,4 +19,9 @@ public class ExpressionReceiver extends Receiver
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionReceiver accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
@ -28,4 +29,9 @@ public class FieldVar extends Expression {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVar accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
@ -26,4 +27,9 @@ public class ForStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -27,4 +28,9 @@ public class IfStmt extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
|
||||
@ -21,4 +22,9 @@ public class InstanceOf extends BinaryExpr
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceOf accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -39,4 +40,9 @@ public class LambdaExpression extends Expression implements TypeScope {
|
||||
//return type.getParaList().get(0);
|
||||
return methodBody.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaExpression accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -21,4 +22,9 @@ public class Literal extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Literal accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -24,4 +25,9 @@ public class LocalVar extends Statement{
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVar accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -28,4 +29,9 @@ public class LocalVarDecl extends Statement
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVarDecl accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -38,4 +39,9 @@ public class MethodCall extends Statement
|
||||
public ArgumentList getArgumentList() {
|
||||
return arglist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodCall accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
|
||||
|
||||
public class NewArray extends Expression
|
||||
@ -21,4 +22,9 @@ public class NewArray extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewArray accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
@ -37,4 +38,9 @@ public class NewClass extends MethodCall
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewClass accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -18,4 +19,9 @@ public class Return extends Statement
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Return accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
@ -12,4 +13,9 @@ public class ReturnVoid extends Return{
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnVoid accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
@ -17,4 +18,9 @@ public class StaticClassName extends Receiver {
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaticClassName accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
|
||||
public class Super extends Expression
|
||||
{
|
||||
@ -18,4 +19,9 @@ public class Super extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Super accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
@ -25,4 +26,9 @@ public class SuperCall extends MethodCall
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperCall accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
|
||||
public class This extends Expression
|
||||
{
|
||||
@ -19,4 +20,9 @@ public class This extends Expression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public This accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression;
|
||||
@ -32,6 +33,11 @@ public class UnaryExpr extends JavaInternalExpression
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnaryExpr accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class WhileStmt extends Statement
|
||||
{
|
||||
public final Expression expr;
|
||||
public final Statement loopBlock;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public WhileStmt(Expression expr, Statement loopBlock, Token offset)
|
||||
{
|
||||
super(TypePlaceholder.fresh(offset), offset);
|
||||
this.expr = expr;
|
||||
this.loopBlock = loopBlock;
|
||||
}
|
||||
public class WhileStmt extends Statement {
|
||||
public final Expression expr;
|
||||
public final Statement loopBlock;
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
public WhileStmt(Expression expr, Statement loopBlock, Token offset) {
|
||||
super(TypePlaceholder.fresh(offset), offset);
|
||||
this.expr = expr;
|
||||
this.loopBlock = loopBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhileStmt accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -49,4 +50,9 @@ public class ExtendsWildcardType extends WildcardType{
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,18 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
public class GenericRefType extends RefType
|
||||
{
|
||||
private String name;
|
||||
|
||||
public GenericRefType(String name, Token offset)
|
||||
{
|
||||
super(offset);
|
||||
super(new JavaClassName(name),offset);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -32,5 +34,35 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
GenericRefType other = (GenericRefType) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -45,10 +46,11 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += super.hashCode();
|
||||
hash += this.name.hashCode();//Nur den Name hashen. Sorgt für langsame, aber funktionierende HashMaps
|
||||
return hash;
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((parameter == null) ? 0 : parameter.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public RefType(JavaClassName fullyQualifiedName, List<RefTypeOrTPHOrWildcardOrGeneric> parameter, Token offset)
|
||||
@ -68,43 +70,27 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
return this.parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author: Jrg Buerle<br/>
|
||||
* @return
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(obj instanceof RefType){
|
||||
boolean ret = true;
|
||||
|
||||
if(!super.equals(obj))
|
||||
return false;
|
||||
|
||||
if(parameter==null || parameter.size()==0){
|
||||
ret &= (((RefType)obj).getParaList()==null || ((RefType)obj).getParaList().size()==0);
|
||||
}
|
||||
else{
|
||||
if(((RefType)obj).getParaList()==null){
|
||||
ret = false;
|
||||
}
|
||||
else if(parameter.size() != ((RefType)obj).getParaList().size())
|
||||
{
|
||||
ret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i<parameter.size(); i++)
|
||||
{
|
||||
ret &= parameter.get(i).equals(((RefType)obj).getParaList().get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
RefType other = (RefType) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (parameter == null) {
|
||||
if (other.parameter != null)
|
||||
return false;
|
||||
} else if (!parameter.equals(other.parameter))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ -121,5 +107,10 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -59,4 +60,9 @@ public class SuperWildcardType extends WildcardType{
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.visitor.ASTReturnVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
@ -82,4 +83,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
public void accept(ResultSetVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric accept(ASTReturnVisitor visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public class OutputGenerator implements ASTVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterface classOrInterface) {
|
||||
if((Modifier.INTERFACE & classOrInterface.getModifiers()) == 1){
|
||||
if(Modifier.isInterface(classOrInterface.getModifiers())){
|
||||
out.append("interface ");
|
||||
}else{
|
||||
out.append("class ");
|
||||
|
@ -35,11 +35,7 @@ import java.io.IOException;
|
||||
*
|
||||
*/
|
||||
public class RuleSet implements IRuleSet{
|
||||
|
||||
RuleSet() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<UnifyPair> reduceUp(UnifyPair pair) {
|
||||
|
38
test/strucType/TestASTPrinter.java
Normal file
38
test/strucType/TestASTPrinter.java
Normal file
@ -0,0 +1,38 @@
|
||||
package strucType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
|
||||
public class TestASTPrinter {
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
||||
|
||||
@Test
|
||||
public void testASTPrinter() throws Exception {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
String print = ASTPrinter.print(sourceFile);
|
||||
System.out.println(print);
|
||||
String print2 = ASTTypePrinter.print(sourceFile);
|
||||
System.out.println(print2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
73
test/strucType/TestConstruct.java
Normal file
73
test/strucType/TestConstruct.java
Normal file
@ -0,0 +1,73 @@
|
||||
package strucType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.Construct;
|
||||
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
public class TestConstruct {
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
||||
public final PrintConstraints printConstraints = new PrintConstraints();
|
||||
|
||||
@org.junit.Test
|
||||
public void test() throws ClassNotFoundException, IOException, ImpossibleSubTypeException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
// Print SourceFile Infos
|
||||
sourceFile.accept(new SyntaxTreePrinter());
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
|
||||
final ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||
|
||||
System.out.println("\n--StrucTYPE--");
|
||||
printConstraints.print(constraints);
|
||||
PrintInferredTypes.print(inferredTypesType);
|
||||
|
||||
Construct construct = new Construct(constraints, inferredTypesType);
|
||||
|
||||
final List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
final Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
// Set<UnifyPair> subTypeConstraints = construct.getSubTypeConstraintsAsUnifyPairs();
|
||||
final InferredTypes inferredTypesConstruct = construct.getInferredTypes();
|
||||
final SyntaxTreePrinter syntaxTreePrinterInferred = new SyntaxTreePrinter(inferredTypesConstruct);
|
||||
|
||||
System.out.println("\n--Construct--");
|
||||
System.out.println("\nConstructed Interfaces:");
|
||||
constructedInterfaces.forEach(i -> i.accept(syntaxTreePrinterInferred));
|
||||
printConstraints.printSubTypeConstraints(subTypeConstraints);
|
||||
PrintInferredTypes.print(inferredTypesConstruct);
|
||||
System.out.println("\n--Inferred SysntaxTree--");
|
||||
sourceFile.accept(syntaxTreePrinterInferred);
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
}
|
103
test/strucType/TestInferTypesVisitor.java
Normal file
103
test/strucType/TestInferTypesVisitor.java
Normal file
@ -0,0 +1,103 @@
|
||||
package strucType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.Construct;
|
||||
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
public class TestInferTypesVisitor {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
||||
public final PrintConstraints printConstraints = new PrintConstraints();
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() throws ClassNotFoundException, IOException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
//Print SourceFile Infos
|
||||
sourceFile.accept(new InferTypes(new InferredTypes()));
|
||||
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() throws ClassNotFoundException, IOException, ImpossibleSubTypeException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
// Print SourceFile Infos
|
||||
SyntaxTreePrinter syntaxTreePrinter = new SyntaxTreePrinter();
|
||||
sourceFile.accept(syntaxTreePrinter);
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
|
||||
final ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||
|
||||
System.out.println("\n--StrucTYPE--");
|
||||
printConstraints.print(constraints);
|
||||
PrintInferredTypes.print(inferredTypesType);
|
||||
|
||||
Construct construct = new Construct(constraints, inferredTypesType);
|
||||
|
||||
final List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
final Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
final InferredTypes inferredTypesConstruct = construct.getInferredTypes();
|
||||
|
||||
System.out.println("\n--Construct--");
|
||||
System.out.println("\nConstructed Interfaces:");
|
||||
constructedInterfaces.forEach(i -> i.accept(syntaxTreePrinter));
|
||||
printConstraints.printSubTypeConstraints(subTypeConstraints);
|
||||
PrintInferredTypes.print(inferredTypesConstruct);
|
||||
System.out.println("\n--Inferred SysntaxTree--");
|
||||
sourceFile = sourceFile.accept(new InferTypes(inferredTypesConstruct));
|
||||
sourceFile.accept(syntaxTreePrinter);
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
66
test/strucType/TestInterface.java
Normal file
66
test/strucType/TestInterface.java
Normal file
@ -0,0 +1,66 @@
|
||||
package strucType;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.visitor.TypeExtract;
|
||||
|
||||
public class TestInterface {
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/strucType/javFiles/";
|
||||
|
||||
|
||||
@org.junit.Test
|
||||
public void test() throws ClassNotFoundException, IOException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testInterface.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
compiler.sourceFiles.keySet().forEach(f->{
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
compiler.sourceFiles.get(f).getClasses().forEach(c-> c.accept(new TypeExtract()));
|
||||
System.out.println();
|
||||
});
|
||||
// this.printSyntaxTree(compiler);
|
||||
System.out.println("test end");
|
||||
}
|
||||
|
||||
// private void printSyntaxTree(JavaTXCompiler compiler){
|
||||
// Collection<SourceFile> sourceFiles= compiler.sourceFiles.values();
|
||||
// for (SourceFile sourceFile : sourceFiles) {
|
||||
// List<ClassOrInterface> klassenVektor = sourceFile.KlassenVektor;
|
||||
// for (ClassOrInterface classOrInterface : klassenVektor) {
|
||||
// JavaClassName className = classOrInterface.getClassName();
|
||||
// System.out.println("class: "+ className);
|
||||
// List<Field> fields = classOrInterface.getFieldDecl();
|
||||
// List<Method> methods = classOrInterface.getMethods();
|
||||
// for (Field field : fields) {
|
||||
// String fName = field.getName();
|
||||
// RefTypeOrTPHOrWildcardOrGeneric fType = field.getType();
|
||||
// System.out.println("field: "+ fName + " : " + fType);
|
||||
// }
|
||||
// for (Method method : methods) {
|
||||
// String mName = method.getName();
|
||||
// RefTypeOrTPHOrWildcardOrGeneric mReturnType = method.getReturnType();
|
||||
// System.out.println("method: " + mName + " : " + mReturnType);
|
||||
// ParameterList mParameterList = method.getParameterList();
|
||||
// for (FormalParameter formalParameter : mParameterList) {
|
||||
// String paraName = formalParameter.getName();
|
||||
// RefTypeOrTPHOrWildcardOrGeneric paraType = formalParameter.getType();
|
||||
// System.out.println("parameter: " + paraName + " : " + paraType);
|
||||
// }
|
||||
// RefTypeOrTPHOrWildcardOrGeneric blockType = method.block.getType();
|
||||
// System.out.println("blockType: " + blockType);
|
||||
// List<Statement> blockStatements = method.block.getStatements();
|
||||
// for (Statement statement : blockStatements) {
|
||||
// RefTypeOrTPHOrWildcardOrGeneric statementType = statement.getType();
|
||||
// System.out.println("statementType: " + statementType);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
98
test/strucType/TestPaperExample.java
Normal file
98
test/strucType/TestPaperExample.java
Normal file
@ -0,0 +1,98 @@
|
||||
package strucType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.Construct;
|
||||
import de.dhbwstuttgart.strucTypes.Solve;
|
||||
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
|
||||
public class TestPaperExample {
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/";
|
||||
public final PrintConstraints printConstraints = new PrintConstraints();
|
||||
|
||||
@org.junit.Test
|
||||
public void test()
|
||||
throws ClassNotFoundException, IOException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "javFiles/testPaperExample.jav"));
|
||||
trans(files);
|
||||
files.clear();
|
||||
// files.add(new File(rootDirectory + "constructed/A.java"));
|
||||
// files.add(new File(rootDirectory +
|
||||
// "typedtestclasses/MyInteger.java"));
|
||||
files.add(new File(rootDirectory + "javFiles/testMain.jav"));
|
||||
trans(files);
|
||||
}
|
||||
|
||||
private void trans(ArrayList<File> files)
|
||||
throws IOException, ClassNotFoundException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
// Print SourceFile Infos
|
||||
SyntaxTreePrinter syntaxtreeprinter = new SyntaxTreePrinter();
|
||||
sourceFile.accept(syntaxtreeprinter);
|
||||
// List<ClassOrInterface> typedClasses =
|
||||
// compiler.sourceFiles.values().stream().flatMap(sf->sf.getClasses().stream()).collect(Collectors.toList());
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
|
||||
System.out.println("\n--StrucTYPE--");
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
|
||||
final ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||
|
||||
printConstraints.print(constraints);
|
||||
PrintInferredTypes.print(inferredTypesType);
|
||||
|
||||
System.out.println("\n--Construct--");
|
||||
Construct construct = new Construct(constraints, inferredTypesType);
|
||||
|
||||
final List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
final Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
final InferredTypes inferredTypesConstruct = construct.getInferredTypes();
|
||||
|
||||
System.out.println("\nConstructed Interfaces:");
|
||||
constructedInterfaces.forEach(i -> i.accept(syntaxtreeprinter));
|
||||
printConstraints.printSubTypeConstraints(subTypeConstraints);
|
||||
PrintInferredTypes.print(inferredTypesConstruct);
|
||||
|
||||
System.out.println("\n--Solve--");
|
||||
// Alle Klassen aus allen SourceFiles
|
||||
List<ClassOrInterface> availableClasses = compiler.getAvailableClasses(sourceFile);
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(availableClasses);
|
||||
System.out.println("\nFinite Closure:");
|
||||
System.out.println(finiteClosure);
|
||||
Solve solve = new Solve(subTypeConstraints, clsA, finiteClosure, inferredTypesConstruct,
|
||||
constructedInterfaces);
|
||||
SolvedClass solvedClass = solve.getSolvedClass();
|
||||
System.out.println("\nSolved Class:");
|
||||
solvedClass.accept(syntaxtreeprinter);
|
||||
System.out.println("\nRemaining Constraints:");
|
||||
printConstraints.printSubTypeConstraints(solvedClass.getConstraints());
|
||||
PrintInferredTypes.print(inferredTypesConstruct);
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
}
|
43
test/strucType/TestRuleSetStrucType.java
Normal file
43
test/strucType/TestRuleSetStrucType.java
Normal file
@ -0,0 +1,43 @@
|
||||
package strucType;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.RuleSetStrucType;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class TestRuleSetStrucType {
|
||||
|
||||
@Test
|
||||
public void testRefl() {
|
||||
|
||||
Set<UnifyPair> pairs = new HashSet<>();
|
||||
|
||||
ReferenceType t = new ReferenceType("t");
|
||||
PlaceholderType T1 = new PlaceholderType("T1");
|
||||
PlaceholderType T2 = new PlaceholderType("T2");
|
||||
PlaceholderType T3 = new PlaceholderType("T3");
|
||||
|
||||
UnifyPair p1 = UnifyTypeFactory.generateSmallerDotPair(t, T1);
|
||||
UnifyPair p2 = UnifyTypeFactory.generateSmallerDotPair(T1, T3);
|
||||
UnifyPair p3 = UnifyTypeFactory.generateSmallerDotPair(T1, T2);
|
||||
UnifyPair p4 = UnifyTypeFactory.generateSmallerDotPair(T2, t);
|
||||
|
||||
pairs.add(p1);
|
||||
pairs.add(p2);
|
||||
pairs.add(p3);
|
||||
pairs.add(p4);
|
||||
|
||||
RuleSetStrucType rules = new RuleSetStrucType();
|
||||
Optional<Set<UnifyPair>> opt = rules.strucTypeRefl(pairs);
|
||||
// System.out.println(opt.get());
|
||||
Assert.assertTrue("Refl: " + opt.get(),opt.isPresent());
|
||||
}
|
||||
}
|
89
test/strucType/TestSolve.java
Normal file
89
test/strucType/TestSolve.java
Normal file
@ -0,0 +1,89 @@
|
||||
package strucType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.Construct;
|
||||
import de.dhbwstuttgart.strucTypes.Solve;
|
||||
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.SubTypeConstraint;
|
||||
import de.dhbwstuttgart.strucTypes.exception.ImpossibleSubTypeException;
|
||||
import de.dhbwstuttgart.strucTypes.exception.InconsistentConstraintsException;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.model.SolvedClass;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
|
||||
public class TestSolve {
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
||||
public final PrintConstraints printConstraints = new PrintConstraints();
|
||||
|
||||
@org.junit.Test
|
||||
public void test() throws ClassNotFoundException, IOException, ImpossibleSubTypeException, InconsistentConstraintsException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
// Print SourceFile Infos
|
||||
SyntaxTreePrinter syntaxtreeprinter = new SyntaxTreePrinter();
|
||||
sourceFile.accept(syntaxtreeprinter);
|
||||
|
||||
System.out.println("\n--StrucTYPE--");
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
|
||||
final ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||
final InferredTypes inferredTypesType = strucTYPE.getInferredTypes();
|
||||
|
||||
printConstraints.print(constraints);
|
||||
PrintInferredTypes.print(inferredTypesType);
|
||||
|
||||
System.out.println("\n--Construct--");
|
||||
Construct construct = new Construct(constraints, inferredTypesType);
|
||||
|
||||
final List<ClassOrInterface> constructedInterfaces = construct.getConstructedInterfaces();
|
||||
final Set<SubTypeConstraint> subTypeConstraints = construct.getSubTypeConstraints();
|
||||
// Set<UnifyPair> subTypeConstraints = construct.getSubTypeConstraintsAsUnifyPairs();
|
||||
final InferredTypes inferredTypesConstruct = construct.getInferredTypes();
|
||||
|
||||
System.out.println("\nConstructed Interfaces:");
|
||||
constructedInterfaces.forEach(i -> i.accept(syntaxtreeprinter));
|
||||
printConstraints.printSubTypeConstraints(subTypeConstraints);
|
||||
PrintInferredTypes.print(inferredTypesConstruct);
|
||||
|
||||
System.out.println("\n--Solve--");
|
||||
// Alle Klassen aus allen SourceFiles
|
||||
List<ClassOrInterface> availableClasses = compiler.getAvailableClasses(sourceFile);
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(availableClasses);
|
||||
// System.out.println("\nFinite Closure:");
|
||||
// System.out.println(finiteClosure);
|
||||
Solve solve = new Solve(subTypeConstraints, clsA, finiteClosure, inferredTypesConstruct, constructedInterfaces);
|
||||
SolvedClass solvedClass = solve.getSolvedClass();
|
||||
System.out.println("\nSolved Class:");
|
||||
solvedClass.accept(syntaxtreeprinter);
|
||||
System.out.println("\nRemaining Constraints:");
|
||||
printConstraints.printSubTypeConstraints(solvedClass.getConstraints());
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
}
|
51
test/strucType/TestStrucType.java
Normal file
51
test/strucType/TestStrucType.java
Normal file
@ -0,0 +1,51 @@
|
||||
package strucType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.StrucTYPE;
|
||||
import de.dhbwstuttgart.strucTypes.constraint.ConstraintsSet;
|
||||
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintConstraints;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.PrintInferredTypes;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
public class TestStrucType {
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/test/strucType/javFiles/";
|
||||
private final PrintConstraints printConstraints = new PrintConstraints();
|
||||
|
||||
@org.junit.Test
|
||||
public void test() throws ClassNotFoundException, IOException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
SourceFile sourceFile = compiler.sourceFiles.get(f);
|
||||
// Print SourceFile Infos
|
||||
sourceFile.accept(new SyntaxTreePrinter());
|
||||
ClassOrInterface clsA = sourceFile.getClasses().get(0);
|
||||
|
||||
StrucTYPE strucTYPE = new StrucTYPE(clsA);
|
||||
|
||||
ConstraintsSet constraints = strucTYPE.getConstraints();
|
||||
printConstraints.print(constraints);
|
||||
|
||||
InferredTypes inferredTypes = strucTYPE.getInferredTypes();
|
||||
PrintInferredTypes.print(inferredTypes);
|
||||
|
||||
System.out.println("____________________________________________________________________________");
|
||||
}
|
||||
}
|
||||
}
|
46
test/strucType/TestStrucTypeUnifyUtils.java
Normal file
46
test/strucType/TestStrucTypeUnifyUtils.java
Normal file
@ -0,0 +1,46 @@
|
||||
package strucType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.strucTypes.StrucTypeUnifyUtils;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class TestStrucTypeUnifyUtils {
|
||||
|
||||
@Test
|
||||
public void testLinkPairs() {
|
||||
List<UnifyPair> pairs = new ArrayList<>();
|
||||
|
||||
ReferenceType t = new ReferenceType("t");
|
||||
PlaceholderType T1 = new PlaceholderType("T1");
|
||||
PlaceholderType T2 = new PlaceholderType("T2");
|
||||
PlaceholderType T3 = new PlaceholderType("T3");
|
||||
|
||||
UnifyPair p1 = UnifyTypeFactory.generateSmallerDotPair(t, T1);
|
||||
UnifyPair p2 = UnifyTypeFactory.generateSmallerDotPair(T1, T3);
|
||||
UnifyPair p3 = UnifyTypeFactory.generateSmallerDotPair(T1, T2);
|
||||
UnifyPair p4 = UnifyTypeFactory.generateSmallerDotPair(T2, t);
|
||||
|
||||
pairs.add(p1);
|
||||
pairs.add(p2);
|
||||
pairs.add(p3);
|
||||
pairs.add(p4);
|
||||
|
||||
Optional<Set<UnifyPair>> opt = StrucTypeUnifyUtils.linkPairs(p1, p4, pairs);
|
||||
|
||||
Assert.assertTrue(opt.isPresent());
|
||||
Assert.assertTrue(p3 + "is not in LinkedPairs: " + opt.get(), opt.get().contains(p3));
|
||||
Assert.assertEquals("Expected size = 1; Actual size = " + opt.get().size(), 1, opt.get().size());
|
||||
}
|
||||
|
||||
|
||||
}
|
71
test/strucType/TestSyntaxTreePrinter.java
Normal file
71
test/strucType/TestSyntaxTreePrinter.java
Normal file
@ -0,0 +1,71 @@
|
||||
package strucType;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.strucTypes.printutils.SyntaxTreePrinter;
|
||||
|
||||
public class TestSyntaxTreePrinter {
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/strucType/javFiles/";
|
||||
|
||||
|
||||
@org.junit.Test
|
||||
public void test() throws ClassNotFoundException, IOException {
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
files.add(new File(rootDirectory + "testLocalVar.jav"));
|
||||
files.add(new File(rootDirectory + "testCast.jav"));
|
||||
files.add(new File(rootDirectory + "testNew.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldVar.jav"));
|
||||
files.add(new File(rootDirectory + "testFieldMethod.jav"));
|
||||
files.add(new File(rootDirectory + "testPaperExample.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(files);
|
||||
compiler.sourceFiles.keySet().forEach(f->{
|
||||
String name = f.getName();
|
||||
System.out.println("Filename: " + name);
|
||||
compiler.sourceFiles.get(f).accept(new SyntaxTreePrinter());
|
||||
System.out.println("________________________________________");
|
||||
});
|
||||
// this.printSyntaxTree(compiler);
|
||||
System.out.println("test end");
|
||||
}
|
||||
|
||||
// private void printSyntaxTree(JavaTXCompiler compiler){
|
||||
// Collection<SourceFile> sourceFiles= compiler.sourceFiles.values();
|
||||
// for (SourceFile sourceFile : sourceFiles) {
|
||||
// List<ClassOrInterface> klassenVektor = sourceFile.KlassenVektor;
|
||||
// for (ClassOrInterface classOrInterface : klassenVektor) {
|
||||
// JavaClassName className = classOrInterface.getClassName();
|
||||
// System.out.println("class: "+ className);
|
||||
// List<Field> fields = classOrInterface.getFieldDecl();
|
||||
// List<Method> methods = classOrInterface.getMethods();
|
||||
// for (Field field : fields) {
|
||||
// String fName = field.getName();
|
||||
// RefTypeOrTPHOrWildcardOrGeneric fType = field.getType();
|
||||
// System.out.println("field: "+ fName + " : " + fType);
|
||||
// }
|
||||
// for (Method method : methods) {
|
||||
// String mName = method.getName();
|
||||
// RefTypeOrTPHOrWildcardOrGeneric mReturnType = method.getReturnType();
|
||||
// System.out.println("method: " + mName + " : " + mReturnType);
|
||||
// ParameterList mParameterList = method.getParameterList();
|
||||
// for (FormalParameter formalParameter : mParameterList) {
|
||||
// String paraName = formalParameter.getName();
|
||||
// RefTypeOrTPHOrWildcardOrGeneric paraType = formalParameter.getType();
|
||||
// System.out.println("parameter: " + paraName + " : " + paraType);
|
||||
// }
|
||||
// RefTypeOrTPHOrWildcardOrGeneric blockType = method.block.getType();
|
||||
// System.out.println("blockType: " + blockType);
|
||||
// List<Statement> blockStatements = method.block.getStatements();
|
||||
// for (Statement statement : blockStatements) {
|
||||
// RefTypeOrTPHOrWildcardOrGeneric statementType = statement.getType();
|
||||
// System.out.println("statementType: " + statementType);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
15
test/strucType/constructed/A.java
Normal file
15
test/strucType/constructed/A.java
Normal file
@ -0,0 +1,15 @@
|
||||
package strucType.constructed;
|
||||
|
||||
import strucType.constructed.L;
|
||||
import strucType.constructed.O;
|
||||
|
||||
public class A<Z extends L<AD, U>, AD extends O<P, V>, M extends U, N extends V, U, P, V> {
|
||||
|
||||
public A() {
|
||||
}
|
||||
|
||||
public P mt(Z x, M y, N z) {
|
||||
return x.sub(y).add(z);
|
||||
}
|
||||
|
||||
}
|
7
test/strucType/constructed/L.java
Normal file
7
test/strucType/constructed/L.java
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public interface L<R, T> {
|
||||
|
||||
public R sub(T x);
|
||||
|
||||
}
|
7
test/strucType/constructed/O.java
Normal file
7
test/strucType/constructed/O.java
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.constructed;
|
||||
|
||||
public interface O<R, T> {
|
||||
|
||||
public R add(T x);
|
||||
|
||||
}
|
13
test/strucType/javFiles/testCast.jav
Normal file
13
test/strucType/javFiles/testCast.jav
Normal file
@ -0,0 +1,13 @@
|
||||
package strucType.input;
|
||||
import strucType.typedtestclasses.A;
|
||||
import strucType.typedtestclasses.A2;
|
||||
import strucType.typedtestclasses.C;
|
||||
|
||||
class Cast
|
||||
{
|
||||
mA(A x){return (A2) x; }
|
||||
|
||||
mC(a) { return (C) mC2(a); }
|
||||
|
||||
mC2(c) { return (C) c; }
|
||||
}
|
10
test/strucType/javFiles/testFieldMethod.jav
Normal file
10
test/strucType/javFiles/testFieldMethod.jav
Normal file
@ -0,0 +1,10 @@
|
||||
package strucType.input;
|
||||
import java.lang.Integer;
|
||||
|
||||
class M
|
||||
{
|
||||
f;
|
||||
mM(x, y) { return x.m2(f.mF(x.g, y)); }
|
||||
mInt(Integer x) { return x.doubleValue(); }
|
||||
|
||||
}
|
14
test/strucType/javFiles/testFieldVar.jav
Normal file
14
test/strucType/javFiles/testFieldVar.jav
Normal file
@ -0,0 +1,14 @@
|
||||
package strucType.input;
|
||||
import strucType.typedtestclasses.A;
|
||||
|
||||
class F
|
||||
{
|
||||
f;
|
||||
A a;
|
||||
|
||||
mF() { return f; }
|
||||
|
||||
mA() { return a; }
|
||||
|
||||
mX(x) { return x.f; }
|
||||
}
|
7
test/strucType/javFiles/testInterface.jav
Normal file
7
test/strucType/javFiles/testInterface.jav
Normal file
@ -0,0 +1,7 @@
|
||||
package strucType.input;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class A implements List
|
||||
{
|
||||
}
|
6
test/strucType/javFiles/testLocalVar.jav
Normal file
6
test/strucType/javFiles/testLocalVar.jav
Normal file
@ -0,0 +1,6 @@
|
||||
package strucType.input;
|
||||
|
||||
class C<K,L extends K>
|
||||
{
|
||||
L m(L x) { return x }
|
||||
}
|
8
test/strucType/javFiles/testMain.jav
Normal file
8
test/strucType/javFiles/testMain.jav
Normal file
@ -0,0 +1,8 @@
|
||||
package strucType.input;
|
||||
|
||||
import strucType.typedtestclasses.MyInteger;
|
||||
import strucType.constructed.A;
|
||||
|
||||
class Main {
|
||||
main() { return new A().mt(new MyInteger(2), new MyInteger(1), new MyInteger(3)); }
|
||||
}
|
16
test/strucType/javFiles/testMethod.jav
Normal file
16
test/strucType/javFiles/testMethod.jav
Normal file
@ -0,0 +1,16 @@
|
||||
package strucType.input;
|
||||
import strucType.typedtestclasses.A;
|
||||
import strucType.typedtestclasses.A2;
|
||||
|
||||
class M
|
||||
{
|
||||
mM(x) { return mA(x); }
|
||||
|
||||
mA(x) { return x.getA(); }
|
||||
|
||||
m(A a) { return a; }
|
||||
|
||||
A m2(a) { return a; }
|
||||
|
||||
|
||||
}
|
13
test/strucType/javFiles/testNew.jav
Normal file
13
test/strucType/javFiles/testNew.jav
Normal file
@ -0,0 +1,13 @@
|
||||
package strucType.input;
|
||||
import strucType.typedtestclasses.A;
|
||||
import strucType.typedtestclasses.B;
|
||||
class N
|
||||
{
|
||||
a;
|
||||
|
||||
N(a){ a = a; }
|
||||
|
||||
mA(){ return new A(a); }
|
||||
mB(x){ return new B(x,a); }
|
||||
mN(a) {return new N(a); }
|
||||
}
|
6
test/strucType/javFiles/testPaperExample.jav
Normal file
6
test/strucType/javFiles/testPaperExample.jav
Normal file
@ -0,0 +1,6 @@
|
||||
package strucType.input;
|
||||
|
||||
class A
|
||||
{
|
||||
mt(x, y, z) { return x.sub(y).add(z); }
|
||||
}
|
19
test/strucType/typedtestclasses/A.java
Normal file
19
test/strucType/typedtestclasses/A.java
Normal file
@ -0,0 +1,19 @@
|
||||
package strucType.typedtestclasses;
|
||||
|
||||
public class A {
|
||||
|
||||
public A a;
|
||||
|
||||
public A(A a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public A getA() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public <E> B<E> getB(B<E> b) {
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
9
test/strucType/typedtestclasses/A2.java
Normal file
9
test/strucType/typedtestclasses/A2.java
Normal file
@ -0,0 +1,9 @@
|
||||
package strucType.typedtestclasses;
|
||||
|
||||
public class A2 extends A {
|
||||
|
||||
public A2(A a) {
|
||||
super(a);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user