Aufräumen

This commit is contained in:
JanUlrich 2016-04-07 14:39:07 +02:00
parent 3a8f1252a4
commit 44318ee5d8
15 changed files with 117 additions and 16 deletions

View File

@ -279,7 +279,8 @@ public class SourceFile
Set<Set<UnifyPair>> xConstraints = unifyConstraints.cartesianProduct();
typinferenzLog.debug("Finite Closure: "+finiteClosure, Section.TYPEINFERENCE);
typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints, Section.TYPEINFERENCE);
//finiteClosure.generateFullyNamedTypes(globalAssumptions);

View File

@ -49,13 +49,13 @@ public class UnifyTypeFactory {
RefType superClass = cAss.getAssumedClass().getSuperClass();
if(superClass != null){
UnifyType tr = UnifyTypeFactory.convert(superClass);
pairs.add(smaller(tl, tr));
pairs.add(generateSmallerPair(tl, tr));
}
}
return new FiniteClosure(pairs);
}
public static UnifyPair smaller(UnifyType tl, UnifyType tr){
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){
return new UnifyPair(tl, tr, PairOperator.SMALLER);
}
@ -135,7 +135,7 @@ public class UnifyTypeFactory {
public static UnifyPair convert(Pair p) {
if(!p.OperatorSmaller())throw new NotImplementedException();
UnifyPair ret = smaller(UnifyTypeFactory.convert(p.TA1)
UnifyPair ret = generateSmallerPair(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2));
return ret;
}

View File

@ -6,7 +6,7 @@ import java.util.Vector;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.logger.*;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus;
public class ConstraintsSet extends UndMenge<Pair> implements Iterable<OderConstraint>{
private static final Logger log = Logger.getLogger(ConstraintsSet.class.getName());

View File

@ -8,7 +8,7 @@ import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus;
public class OderConstraint extends OderMenge<Pair>{
private Set<UndConstraint> oderConstraintPairs;

View File

@ -10,7 +10,7 @@ import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus;
public abstract class OderMenge<A> implements KomplexeMenge<A>{

View File

@ -6,7 +6,7 @@ import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus;
/**
* Stellt ein Constraint dar, welches aus mehreren Constraint-Paaren besteht. Diese gelten alle stets gleichzeitig / sind per "Und" miteinander verknüpft.

View File

@ -5,7 +5,7 @@ import java.util.Set;
import java.util.Vector;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.*;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class UnifyConstraintsSet extends UndMenge<UnifyPair> implements Iterable<UnifyOderConstraint>{
@ -37,7 +37,7 @@ public class UnifyConstraintsSet extends UndMenge<UnifyPair> implements Iterable
return constraintsSet.iterator();
}
public void filterWrongConstraints(Unifier unify) {
public void filterWrongConstraints(Unifikationsalgorithmus unify) {
/*
* Das ConstraintsSet enthält nur OderConstraints, welche UND-Verknüpft sind.
* Hier werden Constraints in den OderConstraints kontrolliert:
@ -51,7 +51,7 @@ public class UnifyConstraintsSet extends UndMenge<UnifyPair> implements Iterable
* Nimmt alle UndConstraints und filtert mithilfe dieser die falschen Constraints aus den OderConstraints
* @param unifier
*/
public void unifyUndConstraints(Unifier unifier) {
public void unifyUndConstraints(Unifikationsalgorithmus unifier) {
Vector<UnifyUndConstraint> uCons = this.filterUndConstraints();
Vector<UnifyPair> alleUndConstraints = new Vector<>();
for(UnifyUndConstraint undConstraint : uCons){

View File

@ -8,7 +8,7 @@ import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class UnifyOderConstraint extends OderMenge<UnifyPair>{
@ -83,7 +83,7 @@ public class UnifyOderConstraint extends OderMenge<UnifyPair>{
* welche keinen Sinn ergeben, also beim unifizieren scheitern.
* @param unifier - Wird für die Unifizierung benutzt
*/
void filterWrongConstraints(Unifier unifier) {
void filterWrongConstraints(Unifikationsalgorithmus unifier) {
Set<UnifyUndConstraint> filteredConstraints = new Menge<>();
for(UnifyUndConstraint cons : this.getUndConstraints()){
Set<Set<UnifyPair>> unifierResult = unifier.apply(cons.getConstraintPairs());

View File

@ -6,7 +6,7 @@ import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
/**

View File

@ -4,7 +4,7 @@ import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public interface Unifier {
public interface Unifikationsalgorithmus {
public Set<Set<UnifyPair>> apply (Set<UnifyPair> E);

View File

@ -383,4 +383,9 @@ public class FiniteClosure implements IFiniteClosure {
permuteParams(candidates, idx+1, result, current);
}
}
@Override
public String toString(){
return this.inheritanceGraph.toString();
}
}

View File

@ -0,0 +1,18 @@
import java.util.Vector;
class Overloading2{
String method(Vector<String> v) {
return v;
}
Integer method(Vector<Integer> v) {
return v;
}
public static void main(String[] args){
Overloading2 t;
t = new Overloading2();
t.method(new Vector<String>());
}
}

View File

@ -0,0 +1,71 @@
package bytecode.types;
import static org.junit.Assert.*;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class Overloading2Test extends SourceFileBytecodeTest{
@Override
protected void init() {
testName = "Overloading2";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void testString() {
try{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
File file = new File(rootDirectory);
URL url = file.toURL();
URL[] urls = new URL[]{url};
Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%String%");
Class[] params = new Class[1];
params[0] = stringVector;
Method method = cls.getDeclaredMethod("method", params);
method.invoke(obj, stringVector.newInstance());
assertTrue(true);
}catch(Exception e){
throw new RuntimeException(e);
}
}
@Test
public void testInteger() {
try{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
Class integerVector = classLoader.loadClass("java%util%Vector%%java%lang%Integer%");
Class[] params = new Class[1];
params[0] = integerVector;
Method method = cls.getDeclaredMethod("method", params);
method.invoke(obj, integerVector.newInstance());
assertTrue(true);
}catch(Exception e){
throw new RuntimeException(e);
}
}
}

View File

@ -102,12 +102,13 @@ public class MultipleTypesInsertTester extends TypeInsertTester{
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}finally{
writeLog(sourceFileToInfere+".log");
}
for(String containString : mustContain){
TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString));
}
writeLog(sourceFileToInfere+".log");
}
private static void writeLog(String toFile){

View File

@ -30,6 +30,11 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
public class UnifyTypeFactoryTest {
private static TypeFactory tf = new TypeFactory();
@Test
public void convertUnifyTypes(){
//UnifyType ut =
}
@Test
public void convertConstraintSet(){
ConstraintsSet cons = new ConstraintsSet();