forked from JavaTX/JavaCompilerCore
Changes to be committed:
modified: src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: test/typeinference/JavaTXCompilerTest.java
This commit is contained in:
parent
e4fbd17a55
commit
f0610aeff1
@ -199,7 +199,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
//@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
|
||||
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
||||
RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), unaryExpr.getOffset());
|
||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.EQUALSDOT));
|
||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERDOT));
|
||||
//The type of the postfix increment expression is the type of the variable
|
||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT));
|
||||
}else{
|
||||
|
@ -99,7 +99,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// cartesian product of the sets created by pattern matching.
|
||||
List<Set<Set<UnifyPair>>> topLevelSets = new ArrayList<>();
|
||||
|
||||
System.out.println(eq2s);
|
||||
//System.out.println(eq2s);
|
||||
|
||||
if(eq1s.size() != 0) { // Do not add empty sets or the cartesian product will always be empty.
|
||||
Set<Set<UnifyPair>> wrap = new HashSet<>();
|
||||
@ -129,8 +129,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//Typen getestet werden.
|
||||
// If pairs occured that did not match one of the cartesian product cases,
|
||||
// those pairs are contradictory and the unification is impossible.
|
||||
if(!undefinedPairs.isEmpty())
|
||||
if(!undefinedPairs.isEmpty()) {
|
||||
System.out.println(undefinedPairs);
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
/* Up to here, no cartesian products are calculated.
|
||||
* filters for pairs and sets can be applied here */
|
||||
@ -164,7 +166,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Set<Set<UnifyPair>> set = newSets.remove(0);
|
||||
ArrayList<Set<UnifyPair>> newSet = new ArrayList<>(set);
|
||||
Set<Set<UnifyPair>> result = null;
|
||||
int i = 0;
|
||||
for(Set<UnifyPair> a : newSet) {
|
||||
i++;
|
||||
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
||||
elems.add(a);
|
||||
if (newSets.isEmpty()) {
|
||||
@ -197,7 +201,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
/*
|
||||
* Step 5: Substitution
|
||||
*/
|
||||
System.out.println("vor Subst: " + eqPrime);
|
||||
//System.out.println("vor Subst: " + eqPrime);
|
||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||
|
||||
/*
|
||||
@ -210,13 +214,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt.
|
||||
eqPrimePrimeSet.add(eqPrime);
|
||||
else if(eqPrimePrime.isPresent()) {
|
||||
System.out.println("nextStep: " + eqPrimePrime.get());
|
||||
//System.out.println("nextStep: " + eqPrimePrime.get());
|
||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true);
|
||||
forks.add(fork);
|
||||
fork.fork();
|
||||
}
|
||||
else {
|
||||
System.out.println("nextStep: " + eqPrime);
|
||||
//System.out.println("nextStep: " + eqPrime);
|
||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true);
|
||||
forks.add(fork);
|
||||
fork.fork();
|
||||
@ -410,7 +414,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// Init all 8 cases
|
||||
for(int i = 0; i < 8; i++)
|
||||
result.add(new HashSet<>());
|
||||
|
||||
Boolean first = true;
|
||||
for(UnifyPair pair : eq2s) {
|
||||
PairOperator pairOp = pair.getPairOp();
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
@ -418,18 +422,46 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
// Case 1: (a <. Theta')
|
||||
if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) {
|
||||
System.out.println(pair);
|
||||
Set<Set<UnifyPair>> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc);
|
||||
System.out.println(x1);
|
||||
result.get(0).add(x1);
|
||||
//System.out.println(pair);
|
||||
if (first) {
|
||||
Set<Set<UnifyPair>> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc);
|
||||
//System.out.println(x1);
|
||||
result.get(0).add(x1);
|
||||
}
|
||||
else {
|
||||
Set<UnifyPair> s1 = new HashSet<>();
|
||||
s1.add(pair);
|
||||
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||
s2.add(s1);
|
||||
result.get(0).add(s2);
|
||||
}
|
||||
|
||||
}
|
||||
// Case 2: (a <.? ? ext Theta')
|
||||
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType)
|
||||
result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc));
|
||||
if (first) {
|
||||
result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc));
|
||||
}
|
||||
else {
|
||||
Set<UnifyPair> s1 = new HashSet<>();
|
||||
s1.add(pair);
|
||||
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||
s2.add(s1);
|
||||
result.get(1).add(s2);
|
||||
}
|
||||
|
||||
// Case 3: (a <.? ? sup Theta')
|
||||
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType)
|
||||
result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc));
|
||||
if (first) {
|
||||
result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc));
|
||||
}
|
||||
else {
|
||||
Set<UnifyPair> s1 = new HashSet<>();
|
||||
s1.add(pair);
|
||||
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||
s2.add(s1);
|
||||
result.get(2).add(s2);
|
||||
}
|
||||
|
||||
// Case 4 was replaced by an inference rule
|
||||
// Case 4: (a <.? Theta')
|
||||
@ -438,7 +470,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
// Case 5: (Theta <. a)
|
||||
else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType)
|
||||
result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc));
|
||||
if (first) {
|
||||
result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc));
|
||||
}
|
||||
else {
|
||||
Set<UnifyPair> s1 = new HashSet<>();
|
||||
s1.add(pair);
|
||||
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||
s2.add(s1);
|
||||
result.get(4).add(s2);
|
||||
}
|
||||
|
||||
// Case 6 was replaced by an inference rule.
|
||||
// Case 6: (? ext Theta <.? a)
|
||||
@ -452,7 +493,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
// Case 8: (Theta <.? a)
|
||||
else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType)
|
||||
result.get(7).add(unifyCase8(lhsType, (PlaceholderType) rhsType, fc));
|
||||
if (first) {
|
||||
result.get(7).add(unifyCase8(lhsType, (PlaceholderType) rhsType, fc));
|
||||
}
|
||||
else {
|
||||
Set<UnifyPair> s1 = new HashSet<>();
|
||||
s1.add(pair);
|
||||
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||
s2.add(s1);
|
||||
result.get(7).add(s2);
|
||||
}
|
||||
// Case unknown: If a pair fits no other case, then the type unification has failed.
|
||||
// Through application of the rules, every pair should have one of the above forms.
|
||||
// Pairs that do not have one of the aboves form are contradictory.
|
||||
@ -461,6 +511,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
undefined.add(pair);
|
||||
break;
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
||||
// Filter empty sets or sets that only contain an empty set.
|
||||
|
@ -46,7 +46,11 @@ public class JavaTXCompilerTest {
|
||||
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Import.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
}
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
|
Loading…
Reference in New Issue
Block a user