updates to strukture.

This commit is contained in:
Aldaron7 2018-06-06 21:22:09 +02:00
parent 24f93f0bcb
commit 413cb48a96
26 changed files with 81 additions and 47 deletions

View File

@ -18,13 +18,13 @@ import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.Construct;
import de.dhbwstuttgart.strucTypes.InferredTypes;
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.SourceFile;

View File

@ -14,6 +14,7 @@ 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;

View File

@ -22,15 +22,15 @@ import javafx.util.Pair;
public class RuleSetStrucType extends RuleSet {
public Optional<Set<UnifyPair>> reduce(UnifyPair pair) {
public Optional<Set<UnifyPair>> strucTypeReduce(UnifyPair pair) {
return super.reduce2(pair);
}
public Optional<UnifyPair> adapt1(UnifyPair pair, IFiniteClosure fc) {
public Optional<UnifyPair> strucTypeAdapt1(UnifyPair pair, IFiniteClosure fc) {
return super.adapt(pair, fc);
}
public Optional<Set<UnifyPair>> adapt2(Set<UnifyPair> pairs, IFiniteClosure 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());
@ -105,23 +105,23 @@ public class RuleSetStrucType extends RuleSet {
return Optional.empty();
}
public boolean erase1(UnifyPair pair, IFiniteClosure fc) {
public boolean strucTypeErase1(UnifyPair pair, IFiniteClosure fc) {
return super.erase1(pair, fc);
}
public boolean erase2(UnifyPair pair) {
public boolean strucTypeErase2(UnifyPair pair) {
return super.erase3(pair);
}
public Optional<UnifyPair> swap(UnifyPair pair) {
public Optional<UnifyPair> strucTypeSwap(UnifyPair pair) {
return super.swap(pair);
}
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs) {
public Optional<Set<UnifyPair>> strucTypeSubst(Set<UnifyPair> pairs) {
return super.subst(pairs);
}
public Optional<Set<UnifyPair>> refl(Set<UnifyPair> 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());

View File

@ -12,6 +12,7 @@ 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;
@ -102,7 +103,7 @@ public class Solve {
throw new InconsistentConstraintsException();
}
return new SolvedClass(this.clsA.accept(new InferTypes(inferredTypes, tNew)), tNew,
this.constraints, this.generatedInterfaces);
cs, this.generatedInterfaces);
}

View File

@ -1,7 +1,9 @@
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;

View File

@ -37,14 +37,14 @@ public class StrucTypeUnify {
UnifyPair pair = pairQueue.pollFirst();
// reduce
Optional<Set<UnifyPair>> optSet = rules.reduce(pair);
Optional<Set<UnifyPair>> optSet = rules.strucTypeReduce(pair);
if (optSet.isPresent()) {
optSet.get().forEach(p -> swapAddOrErase(p, fc, pairQueue));
continue;
}
// adapt1
Optional<UnifyPair> opt = rules.adapt1(pair, fc);
Optional<UnifyPair> opt = rules.strucTypeAdapt1(pair, fc);
if (opt.isPresent()) {
this.swapAddOrErase(opt.get(), fc, pairQueue);
@ -56,19 +56,19 @@ public class StrucTypeUnify {
}
// adapt2
Optional<Set<UnifyPair>> adapt2 = rules.adapt2(resultSet, fc);
Optional<Set<UnifyPair>> adapt2 = rules.strucTypeAdapt2(resultSet, fc);
if(adapt2.isPresent()){
resultSet = this.applyTypeUnificationRules(adapt2.get(), fc);
}
// subst
Optional<Set<UnifyPair>> subst = rules.subst(resultSet);
Optional<Set<UnifyPair>> subst = rules.strucTypeSubst(resultSet);
if(subst.isPresent()){
resultSet = this.applyTypeUnificationRules(subst.get(), fc);
}
// refl
Optional<Set<UnifyPair>> refl = rules.refl(resultSet);
Optional<Set<UnifyPair>> refl = rules.strucTypeRefl(resultSet);
if(refl.isPresent()){
resultSet = this.applyTypeUnificationRules(refl.get(), fc);
}
@ -78,11 +78,11 @@ public class StrucTypeUnify {
private void swapAddOrErase(UnifyPair pair, IFiniteClosure fc, Collection<UnifyPair> collection) {
// swap
Optional<UnifyPair> opt = rules.swap(pair);
Optional<UnifyPair> opt = rules.strucTypeSwap(pair);
UnifyPair unifyPair = opt.isPresent() ? opt.get() : pair;
// erase
if (rules.erase1(unifyPair, fc) || rules.erase2(unifyPair))
if (rules.strucTypeErase1(unifyPair, fc) || rules.strucTypeErase2(unifyPair))
return;
collection.add(unifyPair);
}

View File

@ -9,6 +9,7 @@ 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;

View File

@ -3,7 +3,7 @@ package de.dhbwstuttgart.strucTypes.constraint;
import java.util.HashSet;
import java.util.Set;
import de.dhbwstuttgart.strucTypes.InferredTypes;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
public class ConstraintsSet {

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.strucTypes.constraint;
import de.dhbwstuttgart.strucTypes.InferredTypes;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;

View File

@ -5,7 +5,7 @@ import java.util.List;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.strucTypes.InferredTypes;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.strucTypes.visitor.InferTypes;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;

View File

@ -1,7 +1,7 @@
package de.dhbwstuttgart.strucTypes.constraint;
import de.dhbwstuttgart.strucTypes.InferredTypes;
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;

View File

@ -5,28 +5,23 @@ public class IllegalInterfaceTypeException extends RuntimeException {
private static final long serialVersionUID = 1L;
public IllegalInterfaceTypeException() {
// TODO Auto-generated constructor stub
}
public IllegalInterfaceTypeException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public IllegalInterfaceTypeException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
public IllegalInterfaceTypeException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public IllegalInterfaceTypeException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}
}

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.strucTypes;
package de.dhbwstuttgart.strucTypes.model;
import java.util.Collection;
import java.util.HashMap;

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.strucTypes.printutils;
import de.dhbwstuttgart.strucTypes.InferredTypes;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
public class PrintInferredTypes {

View File

@ -7,7 +7,7 @@ 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.InferredTypes;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;

View File

@ -10,7 +10,7 @@ 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.InferredTypes;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Constructor;
import de.dhbwstuttgart.syntaxtree.Field;
@ -121,7 +121,6 @@ public class InferTypes implements ASTReturnVisitor {
List<GenericTypeVar> values = new ArrayList<>();
genericTypeVars.forEach(gtv -> values.add(gtv.accept(this)));
return new GenericDeclarationList(values, genericTypeVars.getOffset());
}
@Override

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.strucTypes;
package de.dhbwstuttgart.strucTypes.visitor;
import java.util.ArrayList;
import java.util.List;
@ -8,8 +8,7 @@ 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.visitor.DefaultASTVisitor;
import de.dhbwstuttgart.strucTypes.visitor.TypeExtract;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
@ -69,6 +68,7 @@ public class TYPEExpr extends DefaultASTVisitor {
// 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 {
@ -84,6 +84,7 @@ public class TYPEExpr extends DefaultASTVisitor {
fieldVar.getType());
this.constraints.addConstraint(fieldConstraint);
}
this.constraints.inferTypes(fieldTypeVisitor.getGrtToTphMap());
}
/**
@ -166,10 +167,6 @@ public class TYPEExpr extends DefaultASTVisitor {
} else {
type.accept(typeExtract);
// implement generics nicht nötig
// ClassOrInterface orDefault =
// typedClasses.getOrDefault(type.getName(),
// ClassOrInterfaceFactory.createClass(type).get());
// orDefault.accept(typeExtract);
}
this.createNewClassSubTypeConstraints(newClass, typeExtract);
}
@ -191,7 +188,7 @@ public class TYPEExpr extends DefaultASTVisitor {
.getFormalparalist();
for (int i = 0; i < argumentsSize; i++) {
// Bei Fields wird kein GenericRefType sondern Object als Typ
// geparst.
// geparst. Workaround über den Konstruktor.
// SubTypeConstraint subTypeConstraint = new
// SubTypeConstraint(arguments.get(i).getType(),
// fields.get(i).getType());

View File

@ -6,9 +6,9 @@ import java.util.List;
import java.util.Optional;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.strucTypes.InferredTypes;
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;

View File

@ -3,7 +3,7 @@ package de.dhbwstuttgart.strucTypes.visitor;
import java.util.HashSet;
import java.util.Set;
import de.dhbwstuttgart.strucTypes.InferredTypes;
import de.dhbwstuttgart.strucTypes.model.InferredTypes;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;

View 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);
}
}
}

View File

@ -8,11 +8,11 @@ import java.util.Set;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.strucTypes.Construct;
import de.dhbwstuttgart.strucTypes.InferredTypes;
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;

View File

@ -11,11 +11,11 @@ import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.strucTypes.Construct;
import de.dhbwstuttgart.strucTypes.InferredTypes;
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;

View File

@ -8,13 +8,13 @@ import java.util.Set;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.strucTypes.Construct;
import de.dhbwstuttgart.strucTypes.InferredTypes;
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;

View File

@ -36,7 +36,7 @@ public class TestRuleSetStrucType {
pairs.add(p4);
RuleSetStrucType rules = new RuleSetStrucType();
Optional<Set<UnifyPair>> opt = rules.refl(pairs);
Optional<Set<UnifyPair>> opt = rules.strucTypeRefl(pairs);
// System.out.println(opt.get());
Assert.assertTrue("Refl: " + opt.get(),opt.isPresent());
}

View File

@ -8,13 +8,13 @@ import java.util.Set;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.strucTypes.Construct;
import de.dhbwstuttgart.strucTypes.InferredTypes;
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;

View File

@ -5,9 +5,9 @@ import java.io.IOException;
import java.util.ArrayList;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.strucTypes.InferredTypes;
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;