Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3ba2714da |
@@ -422,6 +422,43 @@ public class JavaTXCompiler {
|
||||
return typeInference(List.of(file));
|
||||
}
|
||||
|
||||
public static String constraintSetToDot(ConstraintSet<Pair> c){
|
||||
|
||||
Iterator<String> colors = List.of(
|
||||
"#FF0000", "#FF7F00", "#FFFF00", "#7FFF00", "#00FF00", "#00FF7F", "#00FFFF", "#007FFF",
|
||||
"#0000FF", "#7F00FF", "#FF00FF", "#FF007F", "#BF0000", "#BF5F00", "#BFBF00", "#5FBF00",
|
||||
"#00BF00", "#00BF5F", "#00BFBF", "#005FBF", "#0000BF", "#5F00BF", "#BF00BF", "#BF005F",
|
||||
"#800000", "#804000", "#808000", "#408000", "#008000", "#008040", "#008080", "#004080",
|
||||
"#000080", "#400080", "#800080", "#800040", "#FF4040", "#FF8040", "#FFFF40", "#80FF40",
|
||||
"#40FF40", "#40FF80", "#40FFFF", "#4080FF", "#4040FF", "#8040FF", "#FF40FF", "#FF4080",
|
||||
"#BF4040", "#BF8040", "#BFBF40", "#80BF40", "#40BF40", "#40BF80", "#40BFBF", "#4080BF",
|
||||
"#4040BF", "#8040BF", "#BF40BF", "#BF4080", "#FF8080", "#FFBF80", "#FFFF80", "#BFFF80",
|
||||
"#80FF80", "#80FFBF", "#80FFFF", "#80BFFF", "#8080FF", "#BF80FF", "#FF80FF", "#FF80BF").iterator();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("diagraph G{");
|
||||
|
||||
//and constraints to dot
|
||||
sb.append(c.getUndConstraints().stream().map(Pair::toDot).collect(Collectors.joining("\n")));
|
||||
|
||||
//or constraints to dot
|
||||
for (var orConstSet : c.getOderConstraints()){
|
||||
for(var cons : orConstSet){
|
||||
String color = colors.next();
|
||||
sb.append(cons.stream().map(x -> x.toDot(color)).collect(Collectors.joining("\n")));
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("}");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String q(String s) {
|
||||
return "\"" + s.replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
|
||||
public List<ResultSet> typeInference(List<File> files) throws ClassNotFoundException, IOException {
|
||||
Set<ClassOrInterface> allClasses = new HashSet<>();
|
||||
|
||||
@@ -438,6 +475,36 @@ public class JavaTXCompiler {
|
||||
TYPE ty = new TYPE(definedClasses, allClasses);
|
||||
var cons = ty.getConstraints();
|
||||
|
||||
var ANDconstraints = cons.getUndConstraints();
|
||||
var ORConstraints = cons.getOderConstraints();
|
||||
|
||||
var orIterator = ORConstraints.iterator();
|
||||
|
||||
while(orIterator.hasNext()){
|
||||
Set<Constraint<Pair>> y = orIterator.next();
|
||||
if (y.isEmpty()) orIterator.remove();
|
||||
else if (y.size() == 1){
|
||||
ANDconstraints.addAll(y.iterator().next()); // add the OR constraint to the AND constraint since we only have one option
|
||||
orIterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
String dot = constraintSetToDot(cons);
|
||||
|
||||
|
||||
ANDconstraints.forEach(System.out::println);
|
||||
|
||||
for (var orc : ORConstraints){
|
||||
System.out.println();
|
||||
System.out.println("------");
|
||||
System.out.println();
|
||||
for(var hashs : orc){
|
||||
System.out.print(hashs);
|
||||
System.out.print("\n | \n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
PlaceholderRegistry placeholderRegistry = new PlaceholderRegistry();
|
||||
|
||||
|
||||
@@ -85,11 +85,12 @@ public class Constraint<A extends IConstraintElement> extends HashSet<A> impleme
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + "\nisInherited = " + isInherited
|
||||
+ " isOveridden = " + isImplemented
|
||||
+ " msc[" + methodSignatureConstraint.size() + "] = " + methodSignatureConstraint
|
||||
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||
+ "\n";
|
||||
return super.toString();
|
||||
// + "\nisInherited = " + isInherited
|
||||
// + " isOveridden = " + isImplemented
|
||||
// + " msc[" + methodSignatureConstraint.size() + "] = " + methodSignatureConstraint
|
||||
// //" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||
// + "\n";
|
||||
}
|
||||
|
||||
public String toStringBase() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import de.dhbwstuttgart.server.packet.dataContainers.ISerializableData;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.KeyStorage;
|
||||
import de.dhbwstuttgart.server.packet.dataContainers.serialized.SerialMap;
|
||||
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -13,6 +14,8 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
|
||||
import static de.dhbwstuttgart.core.JavaTXCompiler.q;
|
||||
|
||||
|
||||
public class Pair implements Serializable, IConstraintElement, ISerializableData {
|
||||
public final RefTypeOrTPHOrWildcardOrGeneric TA1;
|
||||
@@ -173,5 +176,27 @@ public class Pair implements Serializable, IConstraintElement, ISerializableData
|
||||
if (location != null) pair.location = SourceLoc.fromSerial(location);
|
||||
return pair;
|
||||
}
|
||||
|
||||
public String toDot(String color) {
|
||||
|
||||
return q(this.TA1.toString()) +
|
||||
" -> " +
|
||||
q(this.TA2.toString()) +
|
||||
" [label=" +
|
||||
q(this.GetOperator().toString()) +
|
||||
",color=" + q(color) + "]" +
|
||||
";\n";
|
||||
}
|
||||
|
||||
public String toDot() {
|
||||
|
||||
return q(this.TA1.toString()) +
|
||||
" -> " +
|
||||
q(this.TA2.toString()) +
|
||||
" [label=" +
|
||||
q(this.GetOperator().toString()) +
|
||||
"]" +
|
||||
";\n";
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@@ -35,8 +35,8 @@ public class TYPE {
|
||||
this.definedClasses = definedClasses;
|
||||
}
|
||||
|
||||
public ConstraintSet getConstraints() {
|
||||
ConstraintSet ret = new ConstraintSet();
|
||||
public ConstraintSet<Pair> getConstraints() {
|
||||
ConstraintSet<Pair> ret = new ConstraintSet<>();
|
||||
for (ClassOrInterface cl : definedClasses) {
|
||||
Set<ClassOrInterface> allClasses = TypeUnifyTaskHelper.getPresizedHashSet(allAvailableClasses.size());
|
||||
allClasses.addAll(allAvailableClasses);
|
||||
@@ -45,9 +45,9 @@ public class TYPE {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
||||
ConstraintSet ret = new ConstraintSet();
|
||||
ConstraintSet methConstrains;
|
||||
private ConstraintSet<Pair> getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
||||
ConstraintSet<Pair> ret = new ConstraintSet<>();
|
||||
ConstraintSet<Pair> methConstrains;
|
||||
for(Method m : cl.getMethods()){
|
||||
ret.addAll(methConstrains = getConstraintsMethod(m,info, cl));
|
||||
m.constraints.addAll(methConstrains);
|
||||
@@ -86,11 +86,11 @@ public class TYPE {
|
||||
}
|
||||
*/
|
||||
|
||||
private ConstraintSet getConstraintsMethod(Method m, TypeInferenceInformation info, ClassOrInterface currentClass) {
|
||||
if(m.block == null)return new ConstraintSet(); //Abstrakte Methoden generieren keine Constraints
|
||||
private ConstraintSet<Pair> getConstraintsMethod(Method m, TypeInferenceInformation info, ClassOrInterface currentClass) {
|
||||
if(m.block == null)return new ConstraintSet<Pair>(); //Abstrakte Methoden generieren keine Constraints
|
||||
TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m);
|
||||
TYPEStmt methodScope = new TYPEStmt(blockInfo);
|
||||
ConstraintSet constraintSet = new ConstraintSet();
|
||||
ConstraintSet<Pair> constraintSet = new ConstraintSet<>();
|
||||
|
||||
if (m.name.equals("main") && Modifier.isStatic(m.modifier) && m.getParameterList().getFormalparalist().size() == 1) {
|
||||
// Add constraint for main method
|
||||
|
||||
Reference in New Issue
Block a user