This commit is contained in:
JanUlrich 2015-06-16 14:23:01 +02:00
commit 3be6aef821
20 changed files with 7389 additions and 393 deletions

View File

@ -3,7 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry excluding=".classpath|.cvsignore|.externalToolBuilders/|.project|.settings/|Papers/|bin/|doc/|examples/|lib/|notizen/|src/|test/|tools/" including="log4j.xml" kind="src" path=""/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="lib/junit-4.0.jar" sourcepath="/home/janulrich/.m2/repository/junit/junit/4.0/junit-4.0-sources.jar"/>
<classpathentry kind="lib" path="lib/cloning.jar"/>
<classpathentry kind="lib" path="lib/bcel-5.2.jar"/>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
filesCopiedToWebInfLib=

View File

@ -1,6 +1,8 @@
package de.dhbwstuttgart.logger;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Handler;
import java.util.logging.Level;
@ -14,6 +16,8 @@ public class Logger {
private String name;
private final HashMap<Section, java.util.logging.Logger> logger;
private static final LogHistory LOG_HISTORY = new LogHistory();
protected Logger(String name, LoggerConfiguration config) {
this.name = name;
this.logger = new HashMap<>();
@ -26,12 +30,6 @@ public class Logger {
});
}
}
/*
public static LoggerConfiguration getConfiguration(){
return Logger.standardConfiguration;
}
*/
/**
* Logt eine Debug Message, welche zusätzlich einer bestimmten Section zugewiesen wird.
@ -72,17 +70,11 @@ public class Logger {
}
protected void output(String msg , Level logLevel, Section section){
Logger.LOG_HISTORY.add(new LogLine(msg, this.name, section, logLevel));
if(logger.containsKey(section)){
java.util.logging.Logger log = logger.get(section);
log.log(logLevel, msg);
}
/*
if(output != null){
output.println(msg);
}else if(standardOutput != null){
standardOutput.println(msg);
}
*/
}
public void info(String message, Section s) {
@ -100,6 +92,12 @@ public class Logger {
Logger.standardConfiguration = config;
}
public static String getWholeLog(){
String ret = "";
Logger.LOG_HISTORY.sort((log1, log2)->log1.timestamp.compareTo(log2.timestamp));
ret += Logger.LOG_HISTORY.toString();
return ret;
}
}
class OutputHandler extends Handler{
@ -123,3 +121,44 @@ class OutputHandler extends Handler{
public void close() throws SecurityException {
}
}
class LogHistory extends ArrayList<LogLine>{
private static final long serialVersionUID = -1785228323497318261L;
@Override
public String toString(){
String ret = "";
for(LogLine l : this){
ret += l.toString() + "\n";
}
return ret;
}
}
class LogLine {
Date timestamp;
String message;
String name;
Section section;
Level level;
LogLine(String msg, String loggerName, Section section, Level logLevel){
this.timestamp = new Date();
this.message = msg;
this.name = loggerName;
this.section = section;
this.level = logLevel;
}
public String toString(){
String ret = "";
ret += name + ": ";
ret += message;
ret += " - " + section.name();
return ret;
}
public String toJSON(){
return "";
}
}

View File

@ -1,17 +1,11 @@
// ino.module.StringLiteral.8653.package
package de.dhbwstuttgart.syntaxtree.statement;
// ino.end
// ino.module.StringLiteral.8653.import
import java.util.Hashtable;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.CharacterType;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
@ -19,20 +13,11 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
// ino.class.StringLiteral.26227.declaration
public class StringLiteral extends Literal
// ino.end
// ino.class.StringLiteral.26227.body
{
// ino.attribute.string.26231.declaration
private String string;
// ino.end
// ino.attribute.parserlog.26234.declaration
protected static Logger parserlog = Logger.getLogger("parser");
@ -107,6 +92,11 @@ public class StringLiteral extends Literal
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
return ret;
}
@Override
public String toString(){
return "\""+this.string+"\"";
}
}
// ino.end

View File

@ -1,15 +1,9 @@
package de.dhbwstuttgart.typeinference;
public class ConstraintPair {
public class ConstraintPair extends Pair{
private Pair p;
public ConstraintPair(ConstraintType t1, ConstraintType t2){
p = new Pair(t1.getType(), t2.getType());
}
public Pair getPair(){
return p;
super(t1.getType(), t2.getType());
}
}

View File

@ -1,85 +1,44 @@
package de.dhbwstuttgart.typeinference;
import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge;
import java.util.Vector;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.*;
import de.dhbwstuttgart.typeinference.unify.Unifier;
public class ConstraintsSet extends UndMenge<Pair>{
public class ConstraintsSet extends UndMenge<Pair> implements Iterable<OderConstraint>{
private static final Logger log = Logger.getLogger(ConstraintsSet.class.getName());
public void add(ConstraintsSet CSet){
for(KomplexeMenge<Pair> i : CSet.set){
this.addItems(i);
}
}
public void add(KomplexeMenge<Pair> constraint){
this.addItems(constraint);
}
/*
private UndConstraint constraintsSet;
private Menge<OderConstraint> constraintsSet;
public ConstraintsSet(){
constraintsSet = new UndConstraint();
constraintsSet = new Menge<OderConstraint>();
}
public void add(ConstraintsSet CSet){
constraintsSet.addItems(CSet.getConstraints());
for(OderConstraint element : CSet)
add(element);
}
public void add(OderConstraint constraint){
constraintsSet.addItems(constraint);
constraintsSet.add(constraint);
}
public UndConstraint getConstraints(){
return constraintsSet;
}
*/
/**
* Liefert alle Constraint-Variationen
* @return
*/
/*
public Menge<Menge<UndConstraint>> getConstraints(){
Menge<Menge<UndConstraint>> ret = new Menge<Menge<UndConstraint>>();
for(OderConstraint con : constraintsSet){
ret.add(con.getUndConstraints());
}
ret = new KarthesischesProdukt<UndConstraint>().berechneKarthesischesProdukt(ret);
return ret;
}
@Override
public String toString(){
return constraintsSet.toString();
String ret ="";
for(OderConstraint constraint : this){
ret += constraint.toString()+"\n";
}
return ret;
}
public Iterator<OderConstraint> iterator() {
return constraintsSet.iterator();
}
*/
public void filterWrongConstraints(Unifier unify) {
Menge<KomplexeMenge<Pair>> newSet = new Menge<KomplexeMenge<Pair>>();
for(OderMenge<Pair> orSet : this.getOrSets()){
Menge<Menge<Pair>> res = unify.apply(orSet.getItems());
if(res.size()>0){
newSet.add(orSet);
}else{
Logger.getLogger("Filter").debug("Ausgesondertes Constraint: "+orSet, Section.TYPEINFERENCE);
}
}
for(KomplexeMenge<Pair> i : set){
newSet.addAll(i.getAndSets());
}
this.set = newSet;
/*
for(OderConstraint constraint : this){
constraint.filterWrongConstraints(unify);
}
*/
}
/**
@ -87,9 +46,8 @@ public class ConstraintsSet extends UndMenge<Pair>{
* @param unifier
*/
public void unifyUndConstraints(Unifier unifier) {
/*
Menge<UndConstraint> uCons = this.filterUndConstraints();
Menge<Pair> alleUndConstraints = new Menge<>();
Vector<UndConstraint> uCons = this.filterUndConstraints();
Vector<Pair> alleUndConstraints = new Vector<>();
for(UndConstraint undConstraint : uCons){
alleUndConstraints.addAll(undConstraint.getConstraintPairs());
}
@ -103,7 +61,6 @@ public class ConstraintsSet extends UndMenge<Pair>{
Menge<Menge<Pair>> unifyResult = unifier.apply(undConstraintsUndPairs);
return unifyResult;
});
*/
}
/**
@ -111,15 +68,23 @@ public class ConstraintsSet extends UndMenge<Pair>{
* UndConstraints, welche sich nicht innerhalb eines OderConstraints befinden, herausgefiltert
* @return [u1, ... , uN]
*/
private Menge<UndConstraint> filterUndConstraints() {
/*
Menge<UndConstraint> ret = new Menge<>();
private Vector<UndConstraint> filterUndConstraints() {
Vector<UndConstraint> ret = new Vector<>();
for(OderConstraint con : constraintsSet){
UndConstraint filtered = con.filterUndConstraints();
if(filtered != null)ret.add(filtered);
}
return ret;
*/
return null;
}
public void add(UndConstraint singleConstraint) {
OderConstraint toAdd = new OderConstraint();
toAdd.addConstraint(singleConstraint);
constraintsSet.add(toAdd);
}
@Override
public Menge<? extends KomplexeMenge<Pair>> getSet() {
return this.constraintsSet;
}
}

View File

@ -0,0 +1,33 @@
package de.dhbwstuttgart.typeinference;
import com.rits.cloning.Cloner;
public class EinzelElement<A> implements KomplexeMenge<A>{
private A item;
public EinzelElement(A element){
item = element;
}
public Menge<KomplexeMenge<A>> getSet(){
Menge<KomplexeMenge<A>> ret = new Menge<>();
ret.add(this);
return ret;
}
@Override
public Menge<Menge<A>> cartesianProduct() {
Cloner cloner = new Cloner();
Menge<Menge<A>> ret = new Menge<>();
Menge<A> i = new Menge<A>();
i.add(cloner.deepClone(item));
ret.add(i);
return ret;
}
@Override
public String toString(){
return item.toString();
}
}

View File

@ -0,0 +1,6 @@
package de.dhbwstuttgart.typeinference;
public interface KomplexeMenge<A>{
Menge<? extends KomplexeMenge<A>> getSet();
Menge<Menge<A>> cartesianProduct();
}

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.typeinference;
import de.dhbwstuttgart.typeinference.Menge;
import java.util.Vector;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.Section;
@ -10,41 +10,41 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier;
public class OderConstraint extends OderMenge<Pair>{
//private Menge<UndConstraint> oderConstraintPairs;
private Menge<UndConstraint> oderConstraintPairs;
private final static Logger logger = Logger.getLogger(OderConstraint.class.getName());
/**
* Erstellt ein neues Oder Constraint und fügt bereits ein Constraint hinzu.
* Erstellt ein neues Oder Constraint und f<EFBFBD>gt bereits ein Constraint hinzu.
* @param p1
* @param p2
*/
public OderConstraint(ConstraintType p1, ConstraintType p2){
if(p1 == null || p2 == null)throw new NullPointerException();
ConstraintPair constraintPair = new ConstraintPair(p1,p2);
oderConstraintPairs = new Menge<UndConstraint>();
this.addConstraint(constraintPair);
}
public OderConstraint(){
oderConstraintPairs = new Menge<UndConstraint>();
}
/**
* Liefert alle in diesem OderConstraint enthaltene Constraints. Dabei gehen die Verknüpfungen (Oder/Und) verloren.
* Liefert alle in diesem OderConstraint enthaltene Constraints. Dabei gehen die Verkn<EFBFBD>pfungen (Oder/Und) verloren.
* @return
*/
public Menge<Pair> getConstraintPairs(){
Menge<Pair> ret = new Menge<Pair>();
for(UndConstraint oC : this.oderConstraintPairs){
ret.addAll(oC.getConstraintPairs());
}
return ret;
return this.g
}
*/
/**
* Fügt ein Pair(p1, p2) dem Constraint hinzu
* F<EFBFBD>gt ein Pair(p1, p2) dem Constraint hinzu
* @param p1
* @param p2
*/
@ -57,19 +57,37 @@ public class OderConstraint extends OderMenge<Pair>{
* @param toAdd
*/
public void addConstraint(ConstraintPair toAdd){
//oderConstraintPairs.add(new SingleConstraint(toAdd));
this.addItem(toAdd.getPair());
oderConstraintPairs.add(new SingleConstraint(toAdd));
}
public void addConstraint(UndConstraint methodConstraint) {
this.addItems(methodConstraint);//oderConstraintPairs.add(methodConstraint);
@Override
public String toString(){
String ret = "[";
for(UndConstraint p : this.getUndConstraints()){
ret += p.toString()+ "| ";
}
return ret+"]";
}
//TODO: Funktionalität ¼r filter implementieren
void filterWrongConstraints(Unifier unifier) {
public Vector<UndConstraint> getUndConstraints() {
return this.oderConstraintPairs;
/*
Vector<UndConstraint> ret = new Vector<UndConstraint>();
for(Pair p : this.getConstraintPairs()){
ret.add(new UndConstraint(p.TA1,p.TA2));
}
return ret;
*/
}
public void addConstraint(UndConstraint methodConstraint) {
oderConstraintPairs.add(methodConstraint);
}
void filterWrongConstraints(Unifier unifier) {
Menge<UndConstraint> filteredConstraints = new Menge<>();
for(UndConstraint cons : this.getUndConstraints()){
Menge<Menge<Pair>> unifierResult = unifier.apply(cons.getItems());
Menge<Menge<Pair>> unifierResult = unifier.apply(cons.getConstraintPairs());
if(!unifierResult.isEmpty()){
filteredConstraints.add(cons);
}else{
@ -77,38 +95,19 @@ public class OderConstraint extends OderMenge<Pair>{
}
}
this.oderConstraintPairs = filteredConstraints;
*/
}
UndConstraint filterUndConstraints() {
return null;
/*
if(this.oderConstraintPairs.size()==1){
return this.oderConstraintPairs.firstElement();
}
return null;
*/
}
/*
@Override
public String toString(){
String ret = "[";
for(UndConstraint p : this.getUndConstraints()){
ret += p.toString()+ " | ";
}
return ret+"]";
public Menge<? extends KomplexeMenge<Pair>> getSet() {
return this.oderConstraintPairs;
}
public Menge<UndConstraint> getUndConstraints() {
return this.set;
Menge<UndConstraint> ret = new Menge<UndConstraint>();
for(Pair p : this.getConstraintPairs()){
ret.add(new UndConstraint(p.TA1,p.TA2));
}
return ret;
}
*/
}

View File

@ -11,68 +11,26 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier;
/*
* KomplexeMenge
* OderMenge
* Menge
* Item
*/
interface KomplexeMenge<A>{
void addItems(KomplexeMenge<A> item);
void addItem(A item);
Menge<Menge<A>> cartesianProduct();
Menge<A> getItems();
Menge<OderMenge<A>> getOrSets();
Menge<UndMenge<A>> getAndSets();
}
public class OderMenge<A> implements KomplexeMenge<A>{
Menge<KomplexeMenge<A>> set = new Menge<>();
@Override
public void addItems(KomplexeMenge<A> item) {
set.add(item);
}
public Menge<A> getItems(){
Menge<A> ret = new Menge<>();
for(KomplexeMenge<A> i : set){
ret.addAll(i.getItems());
}
return ret;
}
@Override
public void addItem(A item) {
set.add(new EinzelElement<A>(item));
}
public abstract class OderMenge<A> implements KomplexeMenge<A>{
public abstract Menge<? extends KomplexeMenge<A>> getSet();
@Override
public Menge<Menge<A>> cartesianProduct() {
Menge<Menge<A>> ret = new Menge<>();
for(KomplexeMenge<A> km : this.set){
for(KomplexeMenge<A> km : this.getSet()){
ret.addAll(km.cartesianProduct());
}
return ret;
}
@Override
public Menge<OderMenge<A>> getOrSets() {
Menge<OderMenge<A>> ret = new Menge<>();
ret.add(this);
for(KomplexeMenge<A> i : set){
ret.addAll(i.getOrSets());
public String toString(){
String ret = "[";
for(KomplexeMenge<A> i : this.getSet()){
ret += i.toString() + " | ";
}
return ret;
return ret + "]";
}
@Override
public Menge<UndMenge<A>> getAndSets() {
Menge<UndMenge<A>> ret = new Menge<>();
for(KomplexeMenge<A> i : set){
ret.addAll(i.getAndSets());
}
return ret;
}
}

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.typeinference;
import de.dhbwstuttgart.typeinference.Menge;
import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.RefType;
@ -11,77 +11,60 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
/**
* Beschreibung von Herrn Plümicke:
* "The set of constraints consists of constraints of the form θ R θ' , where θ and
* θ' are Java types and R (R ∈ { < , <? , = }) is a subtyping condition."
* Beschreibung von Herrn Plümicke:
* "The set of constraints consists of constraints of the form θ R θ' , where θ and
* θ' are Java types and R (R { < , <? , = }) is a subtyping condition."
*
* @author AI10023 - Andreas Stadelmeier
*
* Die Klasse stellt ein OderConstraint-Set dar, welches nur aus einem Constraint besteht.
*
*/
public class SingleConstraint extends EinzelElement<Pair>{
//private Pair constraintPair; //entspricht θ condition θ'
public class SingleConstraint extends UndConstraint{
private Pair constraintPair; //entspricht θ condition θ'
//private R condition; //entspricht der condition (R)
public SingleConstraint(ConstraintType p1, ConstraintType p2){
super(new ConstraintPair(p1,p2).getPair());
//super(p1,p2);
//ConstraintPair constraintPair = new ConstraintPair(p1,p2);//super.getConstraintPairs().firstElement();
//this.addConstraint(constraintPair);
ConstraintPair constraintPair = new ConstraintPair(p1,p2);//super.getConstraintPairs().firstElement();
this.addConstraint(constraintPair);
}
@Override
public Menge<? extends KomplexeMenge<Pair>> getSet() {
Menge<EinzelElement<Pair>> ret = new Menge<>();
ret.add(new EinzelElement<>(constraintPair));
return ret;
}
public SingleConstraint(ConstraintPair toAdd) {
super(toAdd.getPair());
//this.addConstraint(toAdd);
this.addConstraint(toAdd);
}
public Pair getPair(){
return this.getItems().firstElement();
return constraintPair;
}
/*
@Override //Methode überschreiben, damit immer nur ein Menge mit nur einem Element zurückgeliefert wird.
@Override //Methode überschreiben, damit immer nur ein Vector mit nur einem Element zurückgeliefert wird.
public Menge<Pair> getConstraintPairs(){
Menge<Pair> ret = new Menge<Pair>();
ret.add(constraintPair);
return ret;
}
*/
public void addConstraint(ConstraintPair toAdd){
//if(constraintPair != null)throw new DebugException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich.");
if(constraintPair != null)throw new DebugException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich.");
Type p1 = toAdd.getPair().TA1;
Type p2 = toAdd.getPair().TA2;
Type p1 = toAdd.TA1;
Type p2 = toAdd.TA2;
if(p1==null || p2 == null)throw new NullPointerException();
this.addItem(toAdd.getPair());
//Hier werden die GTVs zu TPH gewandelt.
//if(p1 instanceof RefType)((RefType)p1).GTV2TPH();
//if(p2 instanceof RefType)((RefType)p2).GTV2TPH();
//if((p1 instanceof GenericTypeVar))p1 = ((GenericTypeVar)p1).getTypePlaceHolder();//throw new DebugException("GenericTypeVar sind in den Constraints nicht erlaubt");//
//if((p2 instanceof GenericTypeVar))p2 = ((GenericTypeVar)p2).getTypePlaceHolder();//throw new DebugException("GenericTypeVar sind in den Constraints nicht erlaubt");//
// BaseTypes werden in RefTypes umgewandelt. Constraints ƒÂ¼rfen nur RefTypes oder TypePlaceholder enthalten, da sonst der Unify-Algorithmus nicht funktioniert.
//if(!(p1 instanceof RefType) && !(p1 instanceof TypePlaceholder) && !(p1 instanceof GenericTypeVar))p1 = new RefType(p1);
//if(!(p2 instanceof RefType) && !(p2 instanceof TypePlaceholder) && !(p2 instanceof GenericTypeVar))p2 = new RefType(p2);
//if(!(TypePlaceholder.class.isInstance(p1)) || !(RefType.class.isInstance(p1)) || !(TypePlaceholder.class.isInstance(p2)) || !(RefType.class.isInstance(p2)))
//{//Wenn die beiden übergebenen Typen weder RefTypes noch TypePlaceholder sind:
// throw new TypinferenzException("Ein Constraint darf nur aus TypePlaceholdern und Reftypes bestehen");
//}
//if(!(p1 instanceof RefType) && !(p1 instanceof TypePlaceholder))throw new DebugException("Fehler: "+p2+" kann nicht in TPH oder RefType umgewandelt werden");
//if(!(p2 instanceof RefType) && !(p2 instanceof TypePlaceholder))throw new DebugException("Fehler: "+p2+" kann nicht in TPH oder RefType umgewandelt werden");
//constraintPair = new Pair(p1,p2);
constraintPair = new Pair(p1,p2);
}
/*
@Override
public String toString(){
return ""+constraintPair.TA1.toString()+" < "+constraintPair.TA2.toString();
}
*/
}

View File

@ -1,48 +1,63 @@
package de.dhbwstuttgart.typeinference;
import java.util.Iterator;
import java.util.Collection;
import java.util.Vector;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.unify.Unifier;
/**
* Stellt ein Constraint dar, welches aus mehreren Constraint-Paaren besteht. Diese gelten alle stets gleichzeitig / sind per "Und" miteinander verknüpft.
* Stellt ein Constraint dar, welches aus mehreren Constraint-Paaren besteht. Diese gelten alle stets gleichzeitig / sind per "Und" miteinander verknüpft.
* @author janulrich
*
*/
public class UndConstraint extends UndMenge<Pair> implements Iterable<Pair>{
public class UndConstraint extends UndMenge<Pair> {
public UndConstraint(ConstraintType p1, ConstraintType p2) {
//super(p1, p2);
this.addItem(new SingleConstraint(p1,p2).getPair());
}
public UndConstraint() {
super();
}
/*
Menge<EinzelElement<Pair>> set = new Menge<>();
@Override
public Menge<UndConstraint> getUndConstraints() {
Menge<UndConstraint> ret = new Menge<UndConstraint>();
public Menge<? extends KomplexeMenge<Pair>> getSet() {
return set;
}
public Menge<Pair> getConstraintPairs() {
Menge<Menge<Pair>> ret = this.cartesianProduct();
if(ret.size() != 1){
//UndConstraints enthalten nur SingleConstraints, wodurch das Karthesische Produkt nur aus einem Element bestehen kann.
throw new DebugException("Fehler in ConstraintPairs-Bildung");
}
return ret.firstElement();
}
public void addConstraint(ConstraintType type, ConstraintType rT) {
Pair p = new ConstraintPair(type, rT);
this.set.add(new EinzelElement<Pair>(p));
}
/*
public UndConstraint(ConstraintType p1, ConstraintType p2) {
super(p1, p2);
}
@Override
public Vector<UndConstraint> getUndConstraints() {
Vector<UndConstraint> ret = new Vector<UndConstraint>();
ret.add(this);
return ret;
}
*/
@Override
public String toString(){
//String ret = super.toString();
//return ret.replace('|', ',');
String ret = "[";
for(Pair p : this.getItems()){
for(Pair p : this.getConstraintPairs()){
ret += p.toString()+ ", ";
}
return ret+"]";
}
/*
@Override
void filterWrongConstraints(Unifier unifier) {
//In einem UndConstraint gibt es keine falschen Constraints
@ -52,18 +67,5 @@ public class UndConstraint extends UndMenge<Pair> implements Iterable<Pair>{
UndConstraint filterUndConstraints(){
return this;
}
*/
@Override
public Iterator<Pair> iterator() {
return this.getItems().iterator();
}
public void addConstraint(ConstraintType type, ConstraintType type2) {
this.addItem(new ConstraintPair(type,type2).getPair());
}
public void addConstraint(ConstraintPair constraintPair) {
this.addItem(constraintPair.getPair());
}
*/
}

View File

@ -5,31 +5,15 @@ import java.util.Iterator;
import com.rits.cloning.Cloner;
public class UndMenge<A> implements KomplexeMenge<A>{
Menge<KomplexeMenge<A>> set = new Menge<>();
@Override
public void addItems(KomplexeMenge<A> item) {
set.add(item);
}
public void addItem(A item){
set.add(new EinzelElement<A>(item));
}
public Menge<A> getItems(){
Menge<A> ret = new Menge<>();
for(KomplexeMenge<A> i : set){
ret.addAll(i.getItems());
}
return ret;
}
public abstract class UndMenge<A> implements KomplexeMenge<A>{
public abstract Menge<? extends KomplexeMenge<A>> getSet();
@Override
public Menge<Menge<A>> cartesianProduct() {
Menge<Menge<A>> ret = null;
Cloner cloner = new Cloner();
for(KomplexeMenge<A> km : this.set){
for(KomplexeMenge<A> km : this.getSet()){
if(ret == null){
ret = km.cartesianProduct();
}else{
@ -43,82 +27,16 @@ public class UndMenge<A> implements KomplexeMenge<A>{
ret = cartesianProduct;
}
}
return ret;
}
@Override
public Menge<OderMenge<A>> getOrSets() {
Menge<OderMenge<A>> ret = new Menge<>();
for(KomplexeMenge<A> i : set){
ret.addAll(i.getOrSets());
}
return ret;
}
@Override
public Menge<UndMenge<A>> getAndSets() {
Menge<UndMenge<A>> ret = new Menge<>();
ret.add(this);
for(KomplexeMenge<A> i : set){
ret.addAll(i.getAndSets());
}
if(ret == null)return new Menge<Menge<A>>();
return ret;
}
public String toString(){
String ret = "[";
for(KomplexeMenge<A> item : set){
ret += item.toString() + "\n";
for(KomplexeMenge<A> item : this.getSet()){
ret += item.toString() + " , ";
}
return ret + "]";
}
}
class EinzelElement<A> implements KomplexeMenge<A>{
private A item;
public EinzelElement(A element){
item = element;
}
@Override
public void addItems(KomplexeMenge<A> item) {
}
@Override
public Menge<A> getItems() {
Menge<A> ret = new Menge<>();
ret.add(item);
return ret;
}
@Override
public void addItem(A item) {
}
@Override
public Menge<Menge<A>> cartesianProduct() {
Cloner cloner = new Cloner();
Menge<Menge<A>> ret = new Menge<>();
Menge<A> i = new Menge<A>();
i.add(cloner.deepClone(item));
ret.add(i);
return ret;
}
@Override
public Menge<OderMenge<A>> getOrSets() {
Menge<OderMenge<A>> ret = new Menge<>();
return ret;
}
@Override
public Menge<UndMenge<A>> getAndSets() {
Menge<UndMenge<A>> ret = new Menge<>();
return ret;
}
}

View File

@ -56,7 +56,7 @@ public class Unify
{
// ino.attribute.inferencelog.28052.declaration
protected static SectionLogger inferencelog = Logger.getSectionLogger("inference", Section.UNIFY);
protected static SectionLogger inferencelog = Logger.getSectionLogger(Unify.class.getName(), Section.UNIFY);
// ino.end
/**
@ -630,6 +630,8 @@ public class Unify
}
}
//Schritt 4, Teil 2: Kartesisches Produkt bilden.
/*
//TODO: Vor der Bildung des Karthesischen Produkts unmÃgliche Kombinationen ausfiltern
//cartProduktSets kontrollieren:
ConstraintsSet cSet = new ConstraintsSet();
@ -638,34 +640,35 @@ public class Unify
for(Menge<Pair> pairs : vecvecpair){
UndConstraint uCons = new UndConstraint();
for(Pair p : pairs){
uCons.addItem(p);
uCons.addConstraint(new ConstraintPair(p));
}
orConstraints.addItems(uCons);
orConstraints.addConstraint(uCons);
}
cSet.addItems(orConstraints);
}
SectionLogger log = Logger.getSectionLogger(Unify.class.getName(), Section.UNIFY);
if(filter){
Unifier filterUnify = (pairs)->{
Menge<Menge<Pair>> retValue = new Menge<>();
retValue = Unify.unifyFiltered(pairs,fc_tto,false);
//Unify.unify(pairs, fc_tto, (i)->{});
return retValue;};
Unifier filterUnify = (pairs)->{
String pairsString = pairs.toString();
Menge<Menge<Pair>> retValue = new Menge<>();
retValue = Unify.unifyFiltered(pairs,fc_tto,false);
//Unify.unify(pairs, fc_tto, (i)->{});
log.debug("Filtere Constraints:\n"+pairsString);
log.debug("Ergebnis: "+ retValue);
return retValue;};
log.debug("Filtere mithilfe von 'filterWrongConstraints': "+cSet);
cSet.filterWrongConstraints(filterUnify);
}
/*
for (Menge<Menge<Pair>> vecvecpair : cartProduktSets){
OderConstraint orConstraints = new OderConstraint();
for(Menge<Pair> pairs : vecvecpair){
UndConstraint uCons = new UndConstraint();
for(Pair p : pairs){
uCons.addConstraint(new ConstraintPair(p.TA1));
}
}
}
Menge<Menge<Pair>> bigCartProductErg = cSet.cartesianProduct();
if(filter)log.debug("Karthesisches Produkt nach Filterung: "+bigCartProductErg);
*/
///*
//Hier wird aus den in Schritt 4, Teil 1 erzeugten Vektoren das Kartesische Produkt gebildet.
Menge<Pair> helpvp;
Menge<Menge<Pair>> bigCartProductErg = new Menge<Menge<Pair>>();
@ -685,7 +688,8 @@ public class Unify
}
}
}
//*/
//Schritt 5: Einsetzen der Subst Regel
//Hier werden die TPHs substituiert, und dann nach geänderten und nicht geänderten Sets sortiert.
Menge<Menge<Pair>> changedSets = new Menge<Menge<Pair>>();

View File

@ -4,17 +4,54 @@ import static org.junit.Assert.*;
import org.junit.Test;
import de.dhbwstuttgart.typeinference.EinzelElement;
import de.dhbwstuttgart.typeinference.KomplexeMenge;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.OderMenge;
import de.dhbwstuttgart.typeinference.UndMenge;
class TestOderMenge extends OderMenge<String>{
Menge<TestUndMenge> set = new Menge<>();
@Override
public Menge<? extends KomplexeMenge<String>> getSet() {
return set;
}
public void addItem(String string) {
TestUndMenge toAdd = new TestUndMenge();
toAdd.addItem(string);
set.add(toAdd);
}
public void addItems(TestUndMenge undMenge) {
set.add(undMenge);
}
}
class TestUndMenge extends UndMenge<String>{
Menge<KomplexeMenge<String>> set = new Menge<>();
@Override
public Menge<? extends KomplexeMenge<String>> getSet() {
return set;
}
public void addItem(String string) {
set.add(new EinzelElement<String>(string));
}
public void addItems(KomplexeMenge<String> oderMenge) {
set.add(oderMenge);
}
}
public class KarthesischesProduktTest {
@Test
public void test() {
OderMenge<String> oM1 = new OderMenge<>();
OderMenge<String> oM2 = new OderMenge<>();
UndMenge<String> oM3 = new UndMenge<>();
TestOderMenge oM1 = new TestOderMenge();
TestOderMenge oM2 = new TestOderMenge();
TestUndMenge oM3 = new TestUndMenge();
oM1.addItem("Menge 1, Item 1");
oM1.addItem("Menge 1, Item 2");
oM2.addItem("Menge 2, Item 1");
@ -27,9 +64,9 @@ public class KarthesischesProduktTest {
@Test
public void test2(){
UndMenge<String> oM1 = new UndMenge<>();
UndMenge<String> oM2 = new UndMenge<>();
UndMenge<String> oM3 = new UndMenge<>();
TestUndMenge oM1 = new TestUndMenge();
TestUndMenge oM2 = new TestUndMenge();
TestUndMenge oM3 = new TestUndMenge();
oM1.addItem("Menge 1, Item 1");
oM1.addItem("Menge 1, Item 2");
oM2.addItem("Menge 2, Item 1");
@ -42,9 +79,9 @@ public class KarthesischesProduktTest {
@Test
public void test3(){
OderMenge<String> oM1 = new OderMenge<>();
UndMenge<String> oM2 = new UndMenge<>();
UndMenge<String> oM3 = new UndMenge<>();
TestOderMenge oM1 = new TestOderMenge();
TestUndMenge oM2 = new TestUndMenge();
TestUndMenge oM3 = new TestUndMenge();
oM1.addItem("Menge 1, Item 1");
oM1.addItem("Menge 1, Item 2");
oM2.addItem("Menge 2, Item 1");
@ -57,9 +94,9 @@ public class KarthesischesProduktTest {
@Test
public void test4(){
OderMenge<String> oM1 = new OderMenge<>();
UndMenge<String> oM2 = new UndMenge<>();
UndMenge<String> oM3 = new UndMenge<>();
TestOderMenge oM1 = new TestOderMenge();
TestUndMenge oM2 = new TestUndMenge();
TestUndMenge oM3 = new TestUndMenge();
oM2.addItem("Menge 2, Item 1");
oM2.addItem("Menge 2, Item 2");
oM3.addItems(oM1);
@ -70,9 +107,20 @@ public class KarthesischesProduktTest {
@Test
public void test5(){
OderMenge<String> oM1 = new OderMenge<>();
UndMenge<String> oM2 = new UndMenge<>();
UndMenge<String> oM3 = new UndMenge<>();
TestOderMenge oM1 = new TestOderMenge();
TestUndMenge oM2 = new TestUndMenge();
TestUndMenge oM3 = new TestUndMenge();
oM3.addItems(oM1);
oM3.addItems(oM2);
//System.out.println("undMenge:"+oM3.cartesianProduct());
assertTrue(oM3.cartesianProduct().size()==0);
}
@Test
public void test6(){
TestOderMenge oM1 = new TestOderMenge();
TestOderMenge oM2 = new TestOderMenge();
TestUndMenge oM3 = new TestUndMenge();
oM3.addItems(oM1);
oM3.addItems(oM2);
//System.out.println("undMenge:"+oM3.cartesianProduct());

View File

@ -0,0 +1,11 @@
class Klasse{
main(param){
return param.methode();
}
}
class Klasse1{
<A> A methode(){
return null;
}
}

View File

@ -0,0 +1,18 @@
package plugindevelopment.TypeInsertTests;
import de.dhbwstuttgart.typeinference.Menge;
import org.junit.Test;
public class LambdaTest28 {
private static final String TEST_FILE = "LambdaTest28.jav";
@Test
public void run(){
Menge<String> mustContain = new Menge<String>();
//mustContain.add("A a");
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}

View File

@ -0,0 +1,16 @@
class Test{
void methode(){
var;
var.methode();
var.methode();
}
}
class Klasse1 {
void methode(){
}
}
class Klasse2 {
void methode(){
}
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,54 @@
package unify;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import org.junit.Test;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
public class UnifyFilter {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/unify/";
private final String testFile = "UnifyFilter.jav";
@Test
public void test(){
MyCompilerAPI compiler = MyCompiler.getAPI(new LoggerConfiguration().setOutput(Section.UNIFY, System.out));
try {
compiler.parse(new File(this.rootDirectory+testFile));
Menge<TypeinferenceResultSet> ergebnis = compiler.typeReconstruction();
//Nichts weiter unternehmen. Nur die Ausgabe des Unifikationsalgorithmus anzeigen.
String log = Logger.getWholeLog();
//System.out.println(log);
writeLogFile(log);
} catch (Exception e){
e.printStackTrace();
}
}
private void writeLogFile(String log){
try {
PrintWriter writer = new PrintWriter(rootDirectory+testFile+".log", "UTF-8");
writer.write(log);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}