forked from JavaTX/JavaCompilerCore
Merge
This commit is contained in:
commit
3be6aef821
@ -3,7 +3,7 @@
|
|||||||
<classpathentry kind="src" path="src"/>
|
<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 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="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/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/cloning.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/bcel-5.2.jar"/>
|
<classpathentry kind="lib" path="lib/bcel-5.2.jar"/>
|
||||||
|
2
.settings/com.google.gwt.eclipse.core.prefs
Normal file
2
.settings/com.google.gwt.eclipse.core.prefs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
filesCopiedToWebInfLib=
|
@ -1,6 +1,8 @@
|
|||||||
package de.dhbwstuttgart.logger;
|
package de.dhbwstuttgart.logger;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -14,6 +16,8 @@ public class Logger {
|
|||||||
private String name;
|
private String name;
|
||||||
private final HashMap<Section, java.util.logging.Logger> logger;
|
private final HashMap<Section, java.util.logging.Logger> logger;
|
||||||
|
|
||||||
|
private static final LogHistory LOG_HISTORY = new LogHistory();
|
||||||
|
|
||||||
protected Logger(String name, LoggerConfiguration config) {
|
protected Logger(String name, LoggerConfiguration config) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.logger = new HashMap<>();
|
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.
|
* 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){
|
protected void output(String msg , Level logLevel, Section section){
|
||||||
|
Logger.LOG_HISTORY.add(new LogLine(msg, this.name, section, logLevel));
|
||||||
if(logger.containsKey(section)){
|
if(logger.containsKey(section)){
|
||||||
java.util.logging.Logger log = logger.get(section);
|
java.util.logging.Logger log = logger.get(section);
|
||||||
log.log(logLevel, msg);
|
log.log(logLevel, msg);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if(output != null){
|
|
||||||
output.println(msg);
|
|
||||||
}else if(standardOutput != null){
|
|
||||||
standardOutput.println(msg);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void info(String message, Section s) {
|
public void info(String message, Section s) {
|
||||||
@ -100,6 +92,12 @@ public class Logger {
|
|||||||
Logger.standardConfiguration = config;
|
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{
|
class OutputHandler extends Handler{
|
||||||
@ -123,3 +121,44 @@ class OutputHandler extends Handler{
|
|||||||
public void close() throws SecurityException {
|
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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
// ino.module.StringLiteral.8653.package
|
|
||||||
package de.dhbwstuttgart.syntaxtree.statement;
|
package de.dhbwstuttgart.syntaxtree.statement;
|
||||||
// ino.end
|
|
||||||
// ino.module.StringLiteral.8653.import
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import de.dhbwstuttgart.typeinference.Menge;
|
import de.dhbwstuttgart.typeinference.Menge;
|
||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.logger.Logger;
|
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.SyntaxTreeNode;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.CharacterType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||||
@ -19,20 +13,11 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
|||||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
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
|
public class StringLiteral extends Literal
|
||||||
// ino.end
|
|
||||||
// ino.class.StringLiteral.26227.body
|
|
||||||
{
|
{
|
||||||
// ino.attribute.string.26231.declaration
|
|
||||||
private String string;
|
private String string;
|
||||||
// ino.end
|
|
||||||
|
|
||||||
// ino.attribute.parserlog.26234.declaration
|
// ino.attribute.parserlog.26234.declaration
|
||||||
protected static Logger parserlog = Logger.getLogger("parser");
|
protected static Logger parserlog = Logger.getLogger("parser");
|
||||||
@ -107,6 +92,11 @@ public class StringLiteral extends Literal
|
|||||||
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
|
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "\""+this.string+"\"";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
package de.dhbwstuttgart.typeinference;
|
package de.dhbwstuttgart.typeinference;
|
||||||
|
|
||||||
public class ConstraintPair {
|
public class ConstraintPair extends Pair{
|
||||||
|
|
||||||
private Pair p;
|
|
||||||
|
|
||||||
public ConstraintPair(ConstraintType t1, ConstraintType t2){
|
public ConstraintPair(ConstraintType t1, ConstraintType t2){
|
||||||
p = new Pair(t1.getType(), t2.getType());
|
super(t1.getType(), t2.getType());
|
||||||
}
|
|
||||||
|
|
||||||
public Pair getPair(){
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,85 +1,44 @@
|
|||||||
package de.dhbwstuttgart.typeinference;
|
package de.dhbwstuttgart.typeinference;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Vector;
|
||||||
import de.dhbwstuttgart.typeinference.Menge;
|
import de.dhbwstuttgart.logger.Logger;
|
||||||
import de.dhbwstuttgart.logger.*;
|
import de.dhbwstuttgart.logger.*;
|
||||||
import de.dhbwstuttgart.typeinference.unify.Unifier;
|
import de.dhbwstuttgart.typeinference.unify.Unifier;
|
||||||
|
|
||||||
|
public class ConstraintsSet extends UndMenge<Pair> implements Iterable<OderConstraint>{
|
||||||
public class ConstraintsSet extends UndMenge<Pair>{
|
|
||||||
private static final Logger log = Logger.getLogger(ConstraintsSet.class.getName());
|
private static final Logger log = Logger.getLogger(ConstraintsSet.class.getName());
|
||||||
|
private Menge<OderConstraint> constraintsSet;
|
||||||
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;
|
|
||||||
|
|
||||||
public ConstraintsSet(){
|
public ConstraintsSet(){
|
||||||
constraintsSet = new UndConstraint();
|
constraintsSet = new Menge<OderConstraint>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ConstraintsSet CSet){
|
public void add(ConstraintsSet CSet){
|
||||||
constraintsSet.addItems(CSet.getConstraints());
|
for(OderConstraint element : CSet)
|
||||||
|
add(element);
|
||||||
}
|
}
|
||||||
public void add(OderConstraint constraint){
|
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
|
@Override
|
||||||
public String toString(){
|
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) {
|
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){
|
for(OderConstraint constraint : this){
|
||||||
constraint.filterWrongConstraints(unify);
|
constraint.filterWrongConstraints(unify);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,9 +46,8 @@ public class ConstraintsSet extends UndMenge<Pair>{
|
|||||||
* @param unifier
|
* @param unifier
|
||||||
*/
|
*/
|
||||||
public void unifyUndConstraints(Unifier unifier) {
|
public void unifyUndConstraints(Unifier unifier) {
|
||||||
/*
|
Vector<UndConstraint> uCons = this.filterUndConstraints();
|
||||||
Menge<UndConstraint> uCons = this.filterUndConstraints();
|
Vector<Pair> alleUndConstraints = new Vector<>();
|
||||||
Menge<Pair> alleUndConstraints = new Menge<>();
|
|
||||||
for(UndConstraint undConstraint : uCons){
|
for(UndConstraint undConstraint : uCons){
|
||||||
alleUndConstraints.addAll(undConstraint.getConstraintPairs());
|
alleUndConstraints.addAll(undConstraint.getConstraintPairs());
|
||||||
}
|
}
|
||||||
@ -103,7 +61,6 @@ public class ConstraintsSet extends UndMenge<Pair>{
|
|||||||
Menge<Menge<Pair>> unifyResult = unifier.apply(undConstraintsUndPairs);
|
Menge<Menge<Pair>> unifyResult = unifier.apply(undConstraintsUndPairs);
|
||||||
return unifyResult;
|
return unifyResult;
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,15 +68,23 @@ public class ConstraintsSet extends UndMenge<Pair>{
|
|||||||
* UndConstraints, welche sich nicht innerhalb eines OderConstraints befinden, herausgefiltert
|
* UndConstraints, welche sich nicht innerhalb eines OderConstraints befinden, herausgefiltert
|
||||||
* @return [u1, ... , uN]
|
* @return [u1, ... , uN]
|
||||||
*/
|
*/
|
||||||
private Menge<UndConstraint> filterUndConstraints() {
|
private Vector<UndConstraint> filterUndConstraints() {
|
||||||
/*
|
Vector<UndConstraint> ret = new Vector<>();
|
||||||
Menge<UndConstraint> ret = new Menge<>();
|
|
||||||
for(OderConstraint con : constraintsSet){
|
for(OderConstraint con : constraintsSet){
|
||||||
UndConstraint filtered = con.filterUndConstraints();
|
UndConstraint filtered = con.filterUndConstraints();
|
||||||
if(filtered != null)ret.add(filtered);
|
if(filtered != null)ret.add(filtered);
|
||||||
}
|
}
|
||||||
return ret;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
src/de/dhbwstuttgart/typeinference/EinzelElement.java
Normal file
33
src/de/dhbwstuttgart/typeinference/EinzelElement.java
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
6
src/de/dhbwstuttgart/typeinference/KomplexeMenge.java
Normal file
6
src/de/dhbwstuttgart/typeinference/KomplexeMenge.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference;
|
||||||
|
|
||||||
|
public interface KomplexeMenge<A>{
|
||||||
|
Menge<? extends KomplexeMenge<A>> getSet();
|
||||||
|
Menge<Menge<A>> cartesianProduct();
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package de.dhbwstuttgart.typeinference;
|
package de.dhbwstuttgart.typeinference;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.Menge;
|
import java.util.Vector;
|
||||||
|
|
||||||
import de.dhbwstuttgart.logger.Logger;
|
import de.dhbwstuttgart.logger.Logger;
|
||||||
import de.dhbwstuttgart.logger.Section;
|
import de.dhbwstuttgart.logger.Section;
|
||||||
@ -10,41 +10,41 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.Unifier;
|
import de.dhbwstuttgart.typeinference.unify.Unifier;
|
||||||
|
|
||||||
public class OderConstraint extends OderMenge<Pair>{
|
public class OderConstraint extends OderMenge<Pair>{
|
||||||
//private Menge<UndConstraint> oderConstraintPairs;
|
private Menge<UndConstraint> oderConstraintPairs;
|
||||||
|
|
||||||
private final static Logger logger = Logger.getLogger(OderConstraint.class.getName());
|
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 p1
|
||||||
* @param p2
|
* @param p2
|
||||||
*/
|
*/
|
||||||
public OderConstraint(ConstraintType p1, ConstraintType p2){
|
public OderConstraint(ConstraintType p1, ConstraintType p2){
|
||||||
if(p1 == null || p2 == null)throw new NullPointerException();
|
if(p1 == null || p2 == null)throw new NullPointerException();
|
||||||
ConstraintPair constraintPair = new ConstraintPair(p1,p2);
|
ConstraintPair constraintPair = new ConstraintPair(p1,p2);
|
||||||
|
oderConstraintPairs = new Menge<UndConstraint>();
|
||||||
this.addConstraint(constraintPair);
|
this.addConstraint(constraintPair);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OderConstraint(){
|
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
|
* @return
|
||||||
|
*/
|
||||||
public Menge<Pair> getConstraintPairs(){
|
public Menge<Pair> getConstraintPairs(){
|
||||||
Menge<Pair> ret = new Menge<Pair>();
|
Menge<Pair> ret = new Menge<Pair>();
|
||||||
for(UndConstraint oC : this.oderConstraintPairs){
|
for(UndConstraint oC : this.oderConstraintPairs){
|
||||||
ret.addAll(oC.getConstraintPairs());
|
ret.addAll(oC.getConstraintPairs());
|
||||||
}
|
}
|
||||||
return ret;
|
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 p1
|
||||||
* @param p2
|
* @param p2
|
||||||
*/
|
*/
|
||||||
@ -57,19 +57,37 @@ public class OderConstraint extends OderMenge<Pair>{
|
|||||||
* @param toAdd
|
* @param toAdd
|
||||||
*/
|
*/
|
||||||
public void addConstraint(ConstraintPair toAdd){
|
public void addConstraint(ConstraintPair toAdd){
|
||||||
//oderConstraintPairs.add(new SingleConstraint(toAdd));
|
oderConstraintPairs.add(new SingleConstraint(toAdd));
|
||||||
this.addItem(toAdd.getPair());
|
|
||||||
}
|
}
|
||||||
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 für filter implementieren
|
public Vector<UndConstraint> getUndConstraints() {
|
||||||
void filterWrongConstraints(Unifier unifier) {
|
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<>();
|
Menge<UndConstraint> filteredConstraints = new Menge<>();
|
||||||
for(UndConstraint cons : this.getUndConstraints()){
|
for(UndConstraint cons : this.getUndConstraints()){
|
||||||
Menge<Menge<Pair>> unifierResult = unifier.apply(cons.getItems());
|
Menge<Menge<Pair>> unifierResult = unifier.apply(cons.getConstraintPairs());
|
||||||
if(!unifierResult.isEmpty()){
|
if(!unifierResult.isEmpty()){
|
||||||
filteredConstraints.add(cons);
|
filteredConstraints.add(cons);
|
||||||
}else{
|
}else{
|
||||||
@ -77,38 +95,19 @@ public class OderConstraint extends OderMenge<Pair>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.oderConstraintPairs = filteredConstraints;
|
this.oderConstraintPairs = filteredConstraints;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UndConstraint filterUndConstraints() {
|
UndConstraint filterUndConstraints() {
|
||||||
return null;
|
|
||||||
/*
|
|
||||||
if(this.oderConstraintPairs.size()==1){
|
if(this.oderConstraintPairs.size()==1){
|
||||||
return this.oderConstraintPairs.firstElement();
|
return this.oderConstraintPairs.firstElement();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public Menge<? extends KomplexeMenge<Pair>> getSet() {
|
||||||
String ret = "[";
|
return this.oderConstraintPairs;
|
||||||
for(UndConstraint p : this.getUndConstraints()){
|
|
||||||
ret += p.toString()+ " | ";
|
|
||||||
}
|
|
||||||
return ret+"]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
@ -11,68 +11,26 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.unify.Unifier;
|
import de.dhbwstuttgart.typeinference.unify.Unifier;
|
||||||
|
|
||||||
/*
|
public abstract class OderMenge<A> implements KomplexeMenge<A>{
|
||||||
* KomplexeMenge
|
|
||||||
* OderMenge
|
public abstract Menge<? extends KomplexeMenge<A>> getSet();
|
||||||
* 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));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Menge<Menge<A>> cartesianProduct() {
|
public Menge<Menge<A>> cartesianProduct() {
|
||||||
Menge<Menge<A>> ret = new Menge<>();
|
Menge<Menge<A>> ret = new Menge<>();
|
||||||
for(KomplexeMenge<A> km : this.set){
|
for(KomplexeMenge<A> km : this.getSet()){
|
||||||
ret.addAll(km.cartesianProduct());
|
ret.addAll(km.cartesianProduct());
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Menge<OderMenge<A>> getOrSets() {
|
public String toString(){
|
||||||
Menge<OderMenge<A>> ret = new Menge<>();
|
String ret = "[";
|
||||||
ret.add(this);
|
for(KomplexeMenge<A> i : this.getSet()){
|
||||||
for(KomplexeMenge<A> i : set){
|
ret += i.toString() + " | ";
|
||||||
ret.addAll(i.getOrSets());
|
|
||||||
}
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package de.dhbwstuttgart.typeinference;
|
package de.dhbwstuttgart.typeinference;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.Menge;
|
import java.util.Vector;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
@ -11,77 +11,60 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Beschreibung von Herrn Plümicke:
|
* Beschreibung von Herrn Plümicke:
|
||||||
* "The set of constraints consists of constraints of the form ø R ø' , where ø and
|
* "The set of constraints consists of constraints of the form θ R θ' , where θ and
|
||||||
* ø' are Java types and R (R â { < , <? , = }) is a subtyping condition."
|
* θ' are Java types and R (R ∈ { < , <? , = }) is a subtyping condition."
|
||||||
*
|
*
|
||||||
* @author AI10023 - Andreas Stadelmeier
|
* @author AI10023 - Andreas Stadelmeier
|
||||||
*
|
*
|
||||||
* Die Klasse stellt ein OderConstraint-Set dar, welches nur aus einem Constraint besteht.
|
* Die Klasse stellt ein OderConstraint-Set dar, welches nur aus einem Constraint besteht.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SingleConstraint extends EinzelElement<Pair>{
|
public class SingleConstraint extends UndConstraint{
|
||||||
//private Pair constraintPair; //entspricht ø condition ø'
|
|
||||||
|
private Pair constraintPair; //entspricht θ condition θ'
|
||||||
//private R condition; //entspricht der condition (R)
|
//private R condition; //entspricht der condition (R)
|
||||||
|
|
||||||
public SingleConstraint(ConstraintType p1, ConstraintType p2){
|
public SingleConstraint(ConstraintType p1, ConstraintType p2){
|
||||||
super(new ConstraintPair(p1,p2).getPair());
|
|
||||||
//super(p1,p2);
|
//super(p1,p2);
|
||||||
//ConstraintPair constraintPair = new ConstraintPair(p1,p2);//super.getConstraintPairs().firstElement();
|
ConstraintPair constraintPair = new ConstraintPair(p1,p2);//super.getConstraintPairs().firstElement();
|
||||||
//this.addConstraint(constraintPair);
|
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) {
|
public SingleConstraint(ConstraintPair toAdd) {
|
||||||
super(toAdd.getPair());
|
this.addConstraint(toAdd);
|
||||||
//this.addConstraint(toAdd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pair getPair(){
|
public Pair getPair(){
|
||||||
return this.getItems().firstElement();
|
return constraintPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
@Override //Methode überschreiben, damit immer nur ein Vector mit nur einem Element zurückgeliefert wird.
|
||||||
@Override //Methode überschreiben, damit immer nur ein Menge mit nur einem Element zurückgeliefert wird.
|
|
||||||
public Menge<Pair> getConstraintPairs(){
|
public Menge<Pair> getConstraintPairs(){
|
||||||
Menge<Pair> ret = new Menge<Pair>();
|
Menge<Pair> ret = new Menge<Pair>();
|
||||||
ret.add(constraintPair);
|
ret.add(constraintPair);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
public void addConstraint(ConstraintPair toAdd){
|
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 p1 = toAdd.TA1;
|
||||||
Type p2 = toAdd.getPair().TA2;
|
Type p2 = toAdd.TA2;
|
||||||
if(p1==null || p2 == null)throw new NullPointerException();
|
if(p1==null || p2 == null)throw new NullPointerException();
|
||||||
this.addItem(toAdd.getPair());
|
|
||||||
|
|
||||||
//Hier werden die GTVs zu TPH gewandelt.
|
constraintPair = new Pair(p1,p2);
|
||||||
//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 dü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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return ""+constraintPair.TA1.toString()+" < "+constraintPair.TA2.toString();
|
return ""+constraintPair.TA1.toString()+" < "+constraintPair.TA2.toString();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
@ -1,48 +1,63 @@
|
|||||||
package de.dhbwstuttgart.typeinference;
|
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.syntaxtree.type.Type;
|
||||||
|
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.typeinference.unify.Unifier;
|
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
|
* @author janulrich
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class UndConstraint extends UndMenge<Pair> implements Iterable<Pair>{
|
public class UndConstraint extends UndMenge<Pair> {
|
||||||
|
|
||||||
public UndConstraint(ConstraintType p1, ConstraintType p2) {
|
Menge<EinzelElement<Pair>> set = new Menge<>();
|
||||||
//super(p1, p2);
|
|
||||||
this.addItem(new SingleConstraint(p1,p2).getPair());
|
|
||||||
}
|
|
||||||
|
|
||||||
public UndConstraint() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
public Menge<UndConstraint> getUndConstraints() {
|
public Menge<? extends KomplexeMenge<Pair>> getSet() {
|
||||||
Menge<UndConstraint> ret = new Menge<UndConstraint>();
|
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);
|
ret.add(this);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
//String ret = super.toString();
|
//String ret = super.toString();
|
||||||
//return ret.replace('|', ',');
|
//return ret.replace('|', ',');
|
||||||
String ret = "[";
|
String ret = "[";
|
||||||
for(Pair p : this.getItems()){
|
for(Pair p : this.getConstraintPairs()){
|
||||||
ret += p.toString()+ ", ";
|
ret += p.toString()+ ", ";
|
||||||
}
|
}
|
||||||
return ret+"]";
|
return ret+"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
void filterWrongConstraints(Unifier unifier) {
|
void filterWrongConstraints(Unifier unifier) {
|
||||||
//In einem UndConstraint gibt es keine falschen Constraints
|
//In einem UndConstraint gibt es keine falschen Constraints
|
||||||
@ -52,18 +67,5 @@ public class UndConstraint extends UndMenge<Pair> implements Iterable<Pair>{
|
|||||||
UndConstraint filterUndConstraints(){
|
UndConstraint filterUndConstraints(){
|
||||||
return this;
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,31 +5,15 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
import com.rits.cloning.Cloner;
|
import com.rits.cloning.Cloner;
|
||||||
|
|
||||||
public class UndMenge<A> implements KomplexeMenge<A>{
|
public abstract class UndMenge<A> implements KomplexeMenge<A>{
|
||||||
Menge<KomplexeMenge<A>> set = new Menge<>();
|
|
||||||
|
public abstract Menge<? extends KomplexeMenge<A>> getSet();
|
||||||
@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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Menge<Menge<A>> cartesianProduct() {
|
public Menge<Menge<A>> cartesianProduct() {
|
||||||
Menge<Menge<A>> ret = null;
|
Menge<Menge<A>> ret = null;
|
||||||
Cloner cloner = new Cloner();
|
Cloner cloner = new Cloner();
|
||||||
for(KomplexeMenge<A> km : this.set){
|
for(KomplexeMenge<A> km : this.getSet()){
|
||||||
if(ret == null){
|
if(ret == null){
|
||||||
ret = km.cartesianProduct();
|
ret = km.cartesianProduct();
|
||||||
}else{
|
}else{
|
||||||
@ -43,82 +27,16 @@ public class UndMenge<A> implements KomplexeMenge<A>{
|
|||||||
ret = cartesianProduct;
|
ret = cartesianProduct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
if(ret == null)return new Menge<Menge<A>>();
|
||||||
}
|
|
||||||
|
|
||||||
@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());
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
String ret = "[";
|
String ret = "[";
|
||||||
for(KomplexeMenge<A> item : set){
|
for(KomplexeMenge<A> item : this.getSet()){
|
||||||
ret += item.toString() + "\n";
|
ret += item.toString() + " , ";
|
||||||
}
|
}
|
||||||
return ret + "]";
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -56,7 +56,7 @@ public class Unify
|
|||||||
{
|
{
|
||||||
|
|
||||||
// ino.attribute.inferencelog.28052.declaration
|
// 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
|
// ino.end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -630,6 +630,8 @@ public class Unify
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Schritt 4, Teil 2: Kartesisches Produkt bilden.
|
//Schritt 4, Teil 2: Kartesisches Produkt bilden.
|
||||||
|
|
||||||
|
/*
|
||||||
//TODO: Vor der Bildung des Karthesischen Produkts unmögliche Kombinationen ausfiltern
|
//TODO: Vor der Bildung des Karthesischen Produkts unmögliche Kombinationen ausfiltern
|
||||||
//cartProduktSets kontrollieren:
|
//cartProduktSets kontrollieren:
|
||||||
ConstraintsSet cSet = new ConstraintsSet();
|
ConstraintsSet cSet = new ConstraintsSet();
|
||||||
@ -638,34 +640,35 @@ public class Unify
|
|||||||
for(Menge<Pair> pairs : vecvecpair){
|
for(Menge<Pair> pairs : vecvecpair){
|
||||||
UndConstraint uCons = new UndConstraint();
|
UndConstraint uCons = new UndConstraint();
|
||||||
for(Pair p : pairs){
|
for(Pair p : pairs){
|
||||||
uCons.addItem(p);
|
uCons.addConstraint(new ConstraintPair(p));
|
||||||
}
|
}
|
||||||
orConstraints.addItems(uCons);
|
orConstraints.addConstraint(uCons);
|
||||||
}
|
}
|
||||||
cSet.addItems(orConstraints);
|
cSet.addItems(orConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SectionLogger log = Logger.getSectionLogger(Unify.class.getName(), Section.UNIFY);
|
||||||
|
|
||||||
if(filter){
|
if(filter){
|
||||||
Unifier filterUnify = (pairs)->{
|
Unifier filterUnify = (pairs)->{
|
||||||
Menge<Menge<Pair>> retValue = new Menge<>();
|
String pairsString = pairs.toString();
|
||||||
retValue = Unify.unifyFiltered(pairs,fc_tto,false);
|
Menge<Menge<Pair>> retValue = new Menge<>();
|
||||||
//Unify.unify(pairs, fc_tto, (i)->{});
|
retValue = Unify.unifyFiltered(pairs,fc_tto,false);
|
||||||
return retValue;};
|
//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);
|
cSet.filterWrongConstraints(filterUnify);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
for (Menge<Menge<Pair>> vecvecpair : cartProduktSets){
|
Menge<Menge<Pair>> bigCartProductErg = cSet.cartesianProduct();
|
||||||
OderConstraint orConstraints = new OderConstraint();
|
if(filter)log.debug("Karthesisches Produkt nach Filterung: "+bigCartProductErg);
|
||||||
for(Menge<Pair> pairs : vecvecpair){
|
|
||||||
UndConstraint uCons = new UndConstraint();
|
|
||||||
for(Pair p : pairs){
|
|
||||||
uCons.addConstraint(new ConstraintPair(p.TA1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
///*
|
||||||
//Hier wird aus den in Schritt 4, Teil 1 erzeugten Vektoren das Kartesische Produkt gebildet.
|
//Hier wird aus den in Schritt 4, Teil 1 erzeugten Vektoren das Kartesische Produkt gebildet.
|
||||||
Menge<Pair> helpvp;
|
Menge<Pair> helpvp;
|
||||||
Menge<Menge<Pair>> bigCartProductErg = new Menge<Menge<Pair>>();
|
Menge<Menge<Pair>> bigCartProductErg = new Menge<Menge<Pair>>();
|
||||||
@ -685,7 +688,8 @@ public class Unify
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//*/
|
||||||
|
|
||||||
//Schritt 5: Einsetzen der Subst Regel
|
//Schritt 5: Einsetzen der Subst Regel
|
||||||
//Hier werden die TPHs substituiert, und dann nach geänderten und nicht geänderten Sets sortiert.
|
//Hier werden die TPHs substituiert, und dann nach geänderten und nicht geänderten Sets sortiert.
|
||||||
Menge<Menge<Pair>> changedSets = new Menge<Menge<Pair>>();
|
Menge<Menge<Pair>> changedSets = new Menge<Menge<Pair>>();
|
||||||
|
@ -4,17 +4,54 @@ import static org.junit.Assert.*;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.EinzelElement;
|
||||||
|
import de.dhbwstuttgart.typeinference.KomplexeMenge;
|
||||||
import de.dhbwstuttgart.typeinference.Menge;
|
import de.dhbwstuttgart.typeinference.Menge;
|
||||||
import de.dhbwstuttgart.typeinference.OderMenge;
|
import de.dhbwstuttgart.typeinference.OderMenge;
|
||||||
import de.dhbwstuttgart.typeinference.UndMenge;
|
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 {
|
public class KarthesischesProduktTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
OderMenge<String> oM1 = new OderMenge<>();
|
TestOderMenge oM1 = new TestOderMenge();
|
||||||
OderMenge<String> oM2 = new OderMenge<>();
|
TestOderMenge oM2 = new TestOderMenge();
|
||||||
UndMenge<String> oM3 = new UndMenge<>();
|
TestUndMenge oM3 = new TestUndMenge();
|
||||||
oM1.addItem("Menge 1, Item 1");
|
oM1.addItem("Menge 1, Item 1");
|
||||||
oM1.addItem("Menge 1, Item 2");
|
oM1.addItem("Menge 1, Item 2");
|
||||||
oM2.addItem("Menge 2, Item 1");
|
oM2.addItem("Menge 2, Item 1");
|
||||||
@ -27,9 +64,9 @@ public class KarthesischesProduktTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test2(){
|
public void test2(){
|
||||||
UndMenge<String> oM1 = new UndMenge<>();
|
TestUndMenge oM1 = new TestUndMenge();
|
||||||
UndMenge<String> oM2 = new UndMenge<>();
|
TestUndMenge oM2 = new TestUndMenge();
|
||||||
UndMenge<String> oM3 = new UndMenge<>();
|
TestUndMenge oM3 = new TestUndMenge();
|
||||||
oM1.addItem("Menge 1, Item 1");
|
oM1.addItem("Menge 1, Item 1");
|
||||||
oM1.addItem("Menge 1, Item 2");
|
oM1.addItem("Menge 1, Item 2");
|
||||||
oM2.addItem("Menge 2, Item 1");
|
oM2.addItem("Menge 2, Item 1");
|
||||||
@ -42,9 +79,9 @@ public class KarthesischesProduktTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test3(){
|
public void test3(){
|
||||||
OderMenge<String> oM1 = new OderMenge<>();
|
TestOderMenge oM1 = new TestOderMenge();
|
||||||
UndMenge<String> oM2 = new UndMenge<>();
|
TestUndMenge oM2 = new TestUndMenge();
|
||||||
UndMenge<String> oM3 = new UndMenge<>();
|
TestUndMenge oM3 = new TestUndMenge();
|
||||||
oM1.addItem("Menge 1, Item 1");
|
oM1.addItem("Menge 1, Item 1");
|
||||||
oM1.addItem("Menge 1, Item 2");
|
oM1.addItem("Menge 1, Item 2");
|
||||||
oM2.addItem("Menge 2, Item 1");
|
oM2.addItem("Menge 2, Item 1");
|
||||||
@ -57,9 +94,9 @@ public class KarthesischesProduktTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test4(){
|
public void test4(){
|
||||||
OderMenge<String> oM1 = new OderMenge<>();
|
TestOderMenge oM1 = new TestOderMenge();
|
||||||
UndMenge<String> oM2 = new UndMenge<>();
|
TestUndMenge oM2 = new TestUndMenge();
|
||||||
UndMenge<String> oM3 = new UndMenge<>();
|
TestUndMenge oM3 = new TestUndMenge();
|
||||||
oM2.addItem("Menge 2, Item 1");
|
oM2.addItem("Menge 2, Item 1");
|
||||||
oM2.addItem("Menge 2, Item 2");
|
oM2.addItem("Menge 2, Item 2");
|
||||||
oM3.addItems(oM1);
|
oM3.addItems(oM1);
|
||||||
@ -70,9 +107,20 @@ public class KarthesischesProduktTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test5(){
|
public void test5(){
|
||||||
OderMenge<String> oM1 = new OderMenge<>();
|
TestOderMenge oM1 = new TestOderMenge();
|
||||||
UndMenge<String> oM2 = new UndMenge<>();
|
TestUndMenge oM2 = new TestUndMenge();
|
||||||
UndMenge<String> oM3 = new UndMenge<>();
|
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(oM1);
|
||||||
oM3.addItems(oM2);
|
oM3.addItems(oM2);
|
||||||
//System.out.println("undMenge:"+oM3.cartesianProduct());
|
//System.out.println("undMenge:"+oM3.cartesianProduct());
|
||||||
|
11
test/plugindevelopment/TypeInsertTests/LambdaTest28.jav
Normal file
11
test/plugindevelopment/TypeInsertTests/LambdaTest28.jav
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class Klasse{
|
||||||
|
main(param){
|
||||||
|
return param.methode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Klasse1{
|
||||||
|
<A> A methode(){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
18
test/plugindevelopment/TypeInsertTests/LambdaTest28.java
Normal file
18
test/plugindevelopment/TypeInsertTests/LambdaTest28.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
test/unify/UnifyFilter.jav
Normal file
16
test/unify/UnifyFilter.jav
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
class Test{
|
||||||
|
void methode(){
|
||||||
|
var;
|
||||||
|
var.methode();
|
||||||
|
var.methode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Klasse1 {
|
||||||
|
void methode(){
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Klasse2 {
|
||||||
|
void methode(){
|
||||||
|
}
|
||||||
|
}
|
6956
test/unify/UnifyFilter.jav.log
Normal file
6956
test/unify/UnifyFilter.jav.log
Normal file
File diff suppressed because one or more lines are too long
54
test/unify/UnifyFilter.java
Normal file
54
test/unify/UnifyFilter.java
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user