Merge mit Master
This commit is contained in:
commit
636149d664
@ -1,12 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<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="BCEL"/>
|
||||
<classpathentry excluding=".classpath|.cvsignore|.externalToolBuilders/|.project|.settings/|Papers/|bin/|doc/|examples/|lib/|notizen/|src/|test/|tools/|BCEL/" 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.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-6.0-SNAPSHOT.jar"/>
|
||||
<classpathentry kind="lib" path="lib/guava-10.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/bcel-6.0-SNAPSHOT.jar" sourcepath="/home/janulrich/Downloads/bcel-5.2-src.zip"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
50
src/de/dhbwstuttgart/logger/Timestamp.java
Normal file
50
src/de/dhbwstuttgart/logger/Timestamp.java
Normal file
@ -0,0 +1,50 @@
|
||||
package de.dhbwstuttgart.logger;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
|
||||
public class Timestamp{
|
||||
String name;
|
||||
|
||||
Stack<Long> timestamps = new Stack<>();
|
||||
Long accumulatedTime = 0L;
|
||||
|
||||
Timestamp(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void start(){
|
||||
timestamps.push(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public Long stop(){
|
||||
if(timestamps.isEmpty())return 0L;
|
||||
Long timeStart = timestamps.pop();
|
||||
Long currentTime = getTime();
|
||||
Long difference = currentTime-timeStart;
|
||||
accumulatedTime += difference;
|
||||
return difference;
|
||||
}
|
||||
|
||||
public Long currentTime(){
|
||||
if(timestamps.isEmpty())return 0L;
|
||||
Long timeStart = timestamps.peek();
|
||||
Long currentTime = getTime();
|
||||
return currentTime-timeStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Timestamp))return false;
|
||||
return this.name.equals(((Timestamp)obj).name);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String ret = "Zeit für Aktivität "+this.name+": "+this.accumulatedTime;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Long getTime(){
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
}
|
74
src/de/dhbwstuttgart/logger/Timewatch.java
Normal file
74
src/de/dhbwstuttgart/logger/Timewatch.java
Normal file
@ -0,0 +1,74 @@
|
||||
package de.dhbwstuttgart.logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Stack;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
|
||||
public class Timewatch {
|
||||
|
||||
private static final Timewatch time = new Timewatch();
|
||||
private final Timestamp startTime;
|
||||
|
||||
private Timers timers = new Timers();
|
||||
|
||||
private Timewatch(){
|
||||
//Privater Konstruktor
|
||||
startTime = new Timestamp("Timewatch Global");
|
||||
startTime.start();
|
||||
}
|
||||
|
||||
public static Timewatch getTimewatch() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public String dumpTimeData(){
|
||||
String ret = "Momentan insgesamt verstrichene Zeit: "+this.startTime.currentTime() +"\n";
|
||||
ret += timers.toString();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Timestamp start(String name){
|
||||
if(!timers.contains(name)){
|
||||
Timestamp ret = new Timestamp(name);
|
||||
timers.add(ret);
|
||||
ret.start();
|
||||
return ret;
|
||||
}else{
|
||||
//Timer läuft noch... einfach neue Instanz starten:
|
||||
Timestamp ret = timers.get(name);
|
||||
ret.start();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Timers{
|
||||
private Menge<Timestamp> timers = new Menge<>();
|
||||
|
||||
public Timestamp get(String name) {
|
||||
for(Timestamp timer:timers){
|
||||
if(timer.name.equals(name))return timer;
|
||||
}
|
||||
throw new DebugException("Fehler in Timewatch: Der gesuchte Timer "+name+" ist nicht vorhanden.");
|
||||
}
|
||||
|
||||
public void add(Timestamp timer) {
|
||||
timers.add(timer);
|
||||
}
|
||||
|
||||
public boolean contains(String name) {
|
||||
return timers.contains(new Timestamp(name));
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String ret ="";
|
||||
for(Timestamp timer : timers){
|
||||
ret += timer.toString() + "\n";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -1227,10 +1227,10 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
//Alle Methoden auf Konstruktoren durchsuchen und diese umwandeln:
|
||||
Menge<Field> tempFields = new Menge<Field>();
|
||||
for(Field f : this.getFields()){
|
||||
if(f instanceof Method && !(f instanceof Constructor)){
|
||||
if(f instanceof Method && !(f instanceof Constructor)){ //Der Check, ob f ein Konstruktor ist eigentlich obsolet, da der Parser keinen Konstruktor generiert
|
||||
Method method = (Method)f;
|
||||
if(method.get_Method_Name().equals(this.getName().toString()) ){
|
||||
tempFields.add(new Constructor(method));
|
||||
tempFields.add(new Constructor(method, this));
|
||||
}else{
|
||||
tempFields.add(f);
|
||||
}
|
||||
|
@ -38,11 +38,12 @@ public class Constructor extends Method {
|
||||
* Parser kann nicht zwischen einem Konstruktor und einer Methode unterscheiden.
|
||||
* Diese Klasse beherbegt den als Methode geparsten Konstruktor und wandelt sein verhalten zu dem eines Konstruktors ab.
|
||||
*/
|
||||
public Constructor(Method methode){
|
||||
public Constructor(Method methode, Class parent){
|
||||
super(methode.get_Method_Name(), methode.getType(), methode.getParameterList(),methode.get_Block(), methode.getGenericDeclarationList(), methode.getOffset());
|
||||
//Sicherstellen, dass das erste Statement in der Methode ein SuperCall ist:
|
||||
if(this.get_Block().get_Statement().size() <1 || ! (this.get_Block().get_Statement().firstElement() instanceof SuperCall)){
|
||||
this.get_Block().statements.add(0, new SuperCall(this.get_Block()));
|
||||
this.parserPostProcessing(parent);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@ -121,6 +122,8 @@ public class Constructor extends Method {
|
||||
return this.getType().getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -810,7 +810,7 @@ public class SourceFile
|
||||
// In streamconstraintsclone sind die Mengen von Paar enthalten die unifiziert werden muessen
|
||||
Stream<Menge<Pair>> streamconstraintsclone = indexeset.stream().map(x -> x.stream()
|
||||
.map(i -> constraintsClone.elementAt(i))
|
||||
.collect(Menge::new, Menge::add, Menge::addAll));
|
||||
.<Menge<Pair>>collect(Menge::new, Menge::add, Menge::addAll));
|
||||
//Menge<Menge<Pair>> vecconstraintsclone = streamconstraintsclone.collect(Menge::new, Menge::add, Menge::addAll);
|
||||
System.out.println();
|
||||
//Schritt 4: Unifikation
|
||||
@ -1779,7 +1779,7 @@ public class SourceFile
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
if(parent!=null)throw new DebugException("Eine SourceFile hat kein Elternelement im Syntaxbaum");
|
||||
super.parserPostProcessing(parent);
|
||||
super.parserPostProcessing(this);
|
||||
//for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
|
||||
}
|
||||
|
||||
|
@ -30,12 +30,14 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
*
|
||||
*/
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
if(parent == null)throw new NullPointerException();
|
||||
this.parent = parent;
|
||||
for(SyntaxTreeNode node : this.getChildren())
|
||||
if(node!=null)node.parserPostProcessing(this);
|
||||
}
|
||||
|
||||
public SyntaxTreeNode getParent() {
|
||||
//if(this.parent == null)throw new NullPointerException();
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
@ -123,10 +125,10 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
}
|
||||
|
||||
public GTVDeclarationContext getGTVDeclarationContext(){
|
||||
if(this.getParent()==null)return null;
|
||||
if(this.getParent()==null)
|
||||
throw new NullPointerException();//throw new DebugException("getGTVDeclarationContext auf unzulässiger Klasse aufgerufen");
|
||||
return this.getParent().getGTVDeclarationContext();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.misc;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
|
||||
@ -16,10 +17,10 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
public class ConstructorCall extends MethodCall
|
||||
{
|
||||
public ConstructorCall(Receiver receiver, String methodName, ArgumentList argumentList, int offset){
|
||||
super(offset, 0);
|
||||
this.set_Receiver(receiver);
|
||||
this.set_Name(methodName);
|
||||
this.set_ArgumentList(argumentList);
|
||||
super(receiver, methodName, argumentList,offset);
|
||||
//this.set_Receiver(receiver);
|
||||
//this.set_Name(methodName);
|
||||
//this.set_ArgumentList(argumentList);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -38,4 +39,10 @@ public class ConstructorCall extends MethodCall
|
||||
ret.add(constraintsFromMethodAssumption(cAss, assumptions));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
super.parserPostProcessing(parent);
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.bcel.classfile.BootstrapMethod;
|
||||
import org.apache.bcel.classfile.ConstantPool;
|
||||
import org.apache.bcel.generic.BIPUSH;
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
@ -227,20 +228,25 @@ public class LambdaExpression extends Expr{
|
||||
public InstructionList genByteCode(ClassGen cg) {
|
||||
ConstantPoolGen cp = cg.getConstantPool();
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
/*
|
||||
* Bytecode:
|
||||
* 0: invokedynamic #2, 0 //#2 führt zu einem InvokeDynamic im KP - wildes Referenzieren
|
||||
* 5: astore_1 //Speichert wahrscheinlich den String meiner TestEXPR
|
||||
* 6: return
|
||||
* Invokedynamic 186 (0xBA)
|
||||
* - Auf dem Operanten Stack liegen die Argumente
|
||||
*
|
||||
* InvokeDynamik_Info Structure auf den der Indexzeiger zeigen muss: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.10
|
||||
*
|
||||
* Ablauf:
|
||||
* 1. Methode erstellen, mit dem Inhalt der Lambda-Expression //Dabei wird das This-Stat
|
||||
* 2. Invokedynamic-Call erzeugen
|
||||
*
|
||||
*/
|
||||
new BootstrapMethod();
|
||||
|
||||
//---Variante 1 mit opcode----
|
||||
short opcode = 186;//opcode - was genau ist das?
|
||||
il.append(new INVOKEDYNAMIC(opcode, 0));//Invokedynamic lässt sich bei mir weder automatisch noch manuell importieren
|
||||
short opcode = 186;
|
||||
int index = 0; //indexbyte 1 und 2 müssen ein Zeiger auf ein call site specifier im Konstantenpool sein (InvokeDynamic_Info).
|
||||
il.append(new INVOKEDYNAMIC(opcode, index));
|
||||
|
||||
//---Variante 2 mit Konstantenpool-Referenz---
|
||||
//int cpSize = cp.getSize()-1;//Vermutlich ist die benötigte Referenz das aktuellste Element?
|
||||
//il.append(new INVOKEDYNAMIC((short) cpSize, 0));
|
||||
return il;
|
||||
}
|
||||
|
||||
|
@ -299,11 +299,13 @@ public class MethodCall extends Expr
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
super.parserPostProcessing(parent);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGen _cg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -65,7 +65,10 @@ public class SuperCall extends ThisCall
|
||||
((Constructor)p).get_Block().statements.firstElement().equals(this)){
|
||||
//Constraints generieren:
|
||||
|
||||
if(this.arglist == null)this.arglist = new ArgumentList();
|
||||
|
||||
MethodCall constructorCall = new ConstructorCall(new Receiver(new This(this)), className, arglist, this.getOffset());
|
||||
constructorCall.parserPostProcessing(this);
|
||||
ret.add(constructorCall.TYPEStmt(assumptions));
|
||||
return ret;
|
||||
}else{
|
||||
|
@ -5,6 +5,11 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
import org.apache.bcel.generic.InstructionFactory;
|
||||
import org.apache.bcel.generic.InstructionHandle;
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
import org.apache.bcel.generic.MethodGen;
|
||||
import org.apache.bcel.generic.ObjectType;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
@ -143,9 +148,11 @@ public class This extends Expr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genByteCode(ClassGen _cg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public InstructionList genByteCode(ClassGen _cg) {
|
||||
InstructionList il = new InstructionList();
|
||||
InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(org.apache.bcel.generic.Type.OBJECT, 0));
|
||||
InstructionHandle ih_1 = il.append(InstructionFactory.createReturn(org.apache.bcel.generic.Type.OBJECT));
|
||||
return il;
|
||||
}
|
||||
|
||||
}
|
||||
|
18
src/de/dhbwstuttgart/typeinference/DeepCloneable.java
Normal file
18
src/de/dhbwstuttgart/typeinference/DeepCloneable.java
Normal file
@ -0,0 +1,18 @@
|
||||
package de.dhbwstuttgart.typeinference;
|
||||
|
||||
public interface DeepCloneable{
|
||||
public <A> A deepClone();
|
||||
}
|
||||
|
||||
/*
|
||||
public class CloneableMenge<A extends DeepCloneable> extends Menge<A>{
|
||||
|
||||
public CloneableMenge<A> deepClone(){
|
||||
CloneableMenge<A> ret = new CloneableMenge<>();
|
||||
for(A i : this){
|
||||
ret.add(i.deepClone());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
*/
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
public class Menge<A> extends Vector<A> implements Set<A>{
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,14 @@
|
||||
package de.dhbwstuttgart.typeinference;
|
||||
// ino.end
|
||||
// ino.module.Pair.8673.import
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
// ino.end
|
||||
|
||||
@ -24,7 +31,7 @@ import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
// Klasse, die ein Paar in der Menge Eq speichern kann
|
||||
// ino.end
|
||||
// ino.class.Pair.26540.declaration
|
||||
public class Pair
|
||||
public class Pair implements Serializable, DeepCloneable
|
||||
// ino.end
|
||||
// ino.class.Pair.26540.body
|
||||
{
|
||||
@ -405,5 +412,24 @@ public class Pair
|
||||
ret.add(this.TA2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Pair deepClone() {
|
||||
/*
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(this);
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
return (Pair) ois.readObject();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
return clone();
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -1,18 +1,19 @@
|
||||
package de.dhbwstuttgart.typeinference;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
//import com.rits.cloning.Cloner;
|
||||
|
||||
public abstract class UndMenge<A> implements KomplexeMenge<A>{
|
||||
public abstract class UndMenge<A extends DeepCloneable> 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();
|
||||
//Cloner cloner = new Cloner();
|
||||
for(KomplexeMenge<A> km : this.getSet()){
|
||||
if(ret == null){
|
||||
ret = km.cartesianProduct();
|
||||
@ -20,7 +21,7 @@ public abstract class UndMenge<A> implements KomplexeMenge<A>{
|
||||
Menge<Menge<A>> cartesianProduct = new Menge<>();
|
||||
for(Menge<A> r : ret)for(Menge<A> m : km.cartesianProduct()){ //Für jedes Element aus dem Karthesischen Produkt:
|
||||
Menge<A> undElement = new Menge<A>();
|
||||
undElement.addAll(cloner.deepClone(r));
|
||||
undElement.addAll(Unify.deepClone(r));
|
||||
undElement.addAll(m);
|
||||
cartesianProduct.add(undElement);
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
@ -20,6 +23,8 @@ import com.rits.cloning.Cloner;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
import de.dhbwstuttgart.logger.SectionLogger;
|
||||
import de.dhbwstuttgart.logger.Timestamp;
|
||||
import de.dhbwstuttgart.logger.Timewatch;
|
||||
import de.dhbwstuttgart.core.MyCompiler;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.myexception.MatchException;
|
||||
@ -40,6 +45,7 @@ import de.dhbwstuttgart.syntaxtree.type.ObjectType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.DeepCloneable;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
|
||||
@ -130,8 +136,11 @@ public class Unify
|
||||
//public static Menge<Menge<Pair>> unifyWC (Menge<Pair> E, FC_TTO fc_tto)
|
||||
public static Menge<Menge<Pair>> unifyFiltered (Menge<Pair> E, FC_TTO fc_tto, boolean filter)
|
||||
{
|
||||
SectionLogger log = Logger.getSectionLogger(Unify.class.getName(), Section.UNIFY);
|
||||
|
||||
//Schritt 1: Aufrufen der Regeln durch sub_unify.
|
||||
Menge<Pair> Eq = sub_unify(E,fc_tto);
|
||||
log.debug("Eq Set nach Schritt 1: "+Eq);
|
||||
/* Schritt 2: Rausfiltern der Typen die entweder beides Typvariablen sind oder nicht.
|
||||
* Sobald ein Paar auftauch, bei denen kein Typ mehr eine Typvariable ist, kann dieses Paar
|
||||
* nicht mehr unifiziert werden, deshalb abbruch.*/
|
||||
@ -635,7 +644,7 @@ public class Unify
|
||||
}
|
||||
}
|
||||
//Schritt 4, Teil 2: Kartesisches Produkt bilden.
|
||||
|
||||
log.debug("Unify Sets nach Schritt 4 vor dem Erstellen des Karthesischen Produkts: "+cartProduktSets);
|
||||
/*
|
||||
//TODO: Vor der Bildung des Karthesischen Produkts unmögliche Kombinationen ausfiltern
|
||||
//cartProduktSets kontrollieren:
|
||||
@ -661,17 +670,18 @@ public class Unify
|
||||
if(filter)log.debug("Karthesisches Produkt nach Filterung: "+bigCartProductErg3);
|
||||
Sets.cartesianProduct(bigCartProductErg3);
|
||||
*/
|
||||
SectionLogger log = Logger.getSectionLogger(Unify.class.getName(), Section.UNIFY);
|
||||
|
||||
if(filter){
|
||||
Cloner cloner = new Cloner();
|
||||
//Cloner cloner = new Cloner();
|
||||
Menge<Menge<Menge<Pair>>> temp = new Menge<>(); //hier werden gefilterte Constraints gesammelt
|
||||
Menge<Pair> undMenge = new Menge<Pair>(); //Die Menge von Pairs, welche in jedem Kartesischen Produkt enthalten sind.
|
||||
undMenge.addAll(cloner.deepClone(Eq1));
|
||||
//undMenge.addAll(cloner.deepClone(Eq1));
|
||||
undMenge.addAll(Unify.deepClone(Eq1));
|
||||
Menge<Menge<Menge<Pair>>> oderConstraints = new Menge<>();//Die zu filternden Constraints
|
||||
for (Menge<Menge<Pair>> vecvecpair : cartProduktSets){
|
||||
if(vecvecpair.size() == 1){//gibt es nur eine UndMenge in diesem Set, dann kommt diese in jedem Karthesischen Produkt vor:
|
||||
undMenge.addAll(cloner.deepClone(vecvecpair.firstElement()));
|
||||
//undMenge.addAll(cloner.deepClone(vecvecpair.firstElement()));
|
||||
undMenge.addAll(Unify.deepClone(vecvecpair.firstElement()));
|
||||
temp.add(vecvecpair);
|
||||
}else{//gibt es mehrere Mengen, kann gefiltert werden:
|
||||
oderConstraints.add(vecvecpair); //die Menge zu den zu filternden OderConstraints anfügen
|
||||
@ -682,8 +692,10 @@ public class Unify
|
||||
Menge<Menge<Pair>> filteredOCons = new Menge<>(); //diese Menge sammelt nur Cons
|
||||
for(Menge<Pair> pairs : oderConstraint){
|
||||
Menge<Pair> testMenge = new Menge<Pair>();
|
||||
testMenge.addAll(cloner.deepClone(undMenge));
|
||||
testMenge.addAll(cloner.deepClone(pairs));
|
||||
//testMenge.addAll(cloner.deepClone(undMenge));
|
||||
//testMenge.addAll(cloner.deepClone(pairs));
|
||||
testMenge.addAll(Unify.deepClone(undMenge));
|
||||
testMenge.addAll(Unify.deepClone(pairs));
|
||||
Menge<Menge<Pair>> test = Unify.unifyFiltered(testMenge, fc_tto, false);
|
||||
if(test.size()>0){
|
||||
filteredOCons.add(pairs);
|
||||
@ -755,6 +767,9 @@ public class Unify
|
||||
int counter = 0;
|
||||
for(Menge<Pair> vecpair : bigCartProductErg)
|
||||
{
|
||||
//Klone die Menge vecpair, bevor substituiert wird. Viele Paare sind doppelt referenziert und müssen vor dem Substituieren geklont werden
|
||||
vecpair = vecpair.stream().map(x -> x.clone()).collect(Menge::new, Menge::add, Menge::addAll);
|
||||
|
||||
counter++;
|
||||
if(counter > 1000){
|
||||
System.out.println(counter + " von "+bigCartProductErg.size());
|
||||
@ -2461,7 +2476,19 @@ throws MatchException
|
||||
inferencelog.debug("Nummer: " + nTypnrInPair);
|
||||
inferencelog.debug("TV: " + a.getName());
|
||||
inferencelog.debug("Bedingung: " + bMitVorbedingung);
|
||||
|
||||
/*
|
||||
Cloner cloner = new Cloner();
|
||||
cloner.setDumpClonedClasses(true);
|
||||
SectionLogger log = Logger.getSectionLogger("Subst-Methode", Section.UNIFY);
|
||||
Timewatch timer = Timewatch.getTimewatch();
|
||||
de.dhbwstuttgart.logger.Timestamp timestamp = timer.start("Unify-Subst");
|
||||
P = cloner.deepClone(P);
|
||||
a = cloner.deepClone(a);
|
||||
o = cloner.deepClone(o);
|
||||
long time = timestamp.stop();
|
||||
log.debug("Benötigte Zeit für DeepClone: "+time);
|
||||
*/
|
||||
|
||||
// richtiger Typ aus Pair raussuchen
|
||||
Type T = null;
|
||||
if( nTypnrInPair == 1 )
|
||||
@ -2483,7 +2510,7 @@ throws MatchException
|
||||
{
|
||||
// Parameterliste durchgehen
|
||||
Menge vTemp = ((RefType)T).get_ParaList();
|
||||
Boolean ret = true; //EINGEFUEGT PL 14-01-16: Return darf erst am Ende zurückgegeben werden und nicht in den ifs
|
||||
boolean ret = true; //EINGEFUEGT PL 14-01-16: Return darf erst am Ende zurückgegeben werden und nicht in den ifs
|
||||
//sonst werden nicht alle Elemente der Forschleife durchlaufen
|
||||
for( int i = 0; i < vTemp.size(); i++ )
|
||||
{
|
||||
@ -3624,5 +3651,12 @@ tempKlasse.get_Superclass_Name() ); System.out.println( "P. S.:
|
||||
return T instanceof FreshWildcardType;
|
||||
}
|
||||
|
||||
public static <A extends DeepCloneable> Menge<A> deepClone(Menge<A> m){
|
||||
Timewatch watch = Timewatch.getTimewatch();
|
||||
Timestamp timer = watch.start("Unify - deepClone");
|
||||
Menge<A> ret = m.stream().<A>map((Function<A,A>)(x -> x.deepClone())).<Menge<A>>collect(Menge::new, Menge::add, Menge::addAll);
|
||||
timer.stop();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
11
test/bytecode/Return.jav
Normal file
11
test/bytecode/Return.jav
Normal file
@ -0,0 +1,11 @@
|
||||
class Assign{
|
||||
|
||||
method() {a;
|
||||
a = 20;
|
||||
b;
|
||||
b=59;
|
||||
return a + b;
|
||||
}
|
||||
|
||||
|
||||
}
|
45
test/bytecode/Return.java
Normal file
45
test/bytecode/Return.java
Normal file
@ -0,0 +1,45 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import plugindevelopment.TypeInsertTester;
|
||||
import de.dhbwstuttgart.core.MyCompiler;
|
||||
import de.dhbwstuttgart.core.MyCompilerAPI;
|
||||
import de.dhbwstuttgart.logger.LoggerConfiguration;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
import de.dhbwstuttgart.parser.JavaParser.yyException;
|
||||
import de.dhbwstuttgart.typeinference.ByteCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
|
||||
|
||||
public class Return {
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "Assign.jav";
|
||||
public final static String outputFile = "Assign.class";
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
|
||||
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
||||
try {
|
||||
compiler.parse(new File(rootDirectory + testFile));
|
||||
compiler.typeReconstruction();
|
||||
ByteCodeResult bytecode = compiler.generateBytecode();
|
||||
System.out.println(bytecode);
|
||||
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
|
||||
} catch (IOException | yyException e) {
|
||||
e.printStackTrace();
|
||||
TestCase.fail();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
8
test/bytecode/Test.java
Normal file
8
test/bytecode/Test.java
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Diese Klasse testet die generierte EmptyClass.class-Datei
|
||||
*/
|
||||
class Test{
|
||||
public static void main(String[] args){
|
||||
new EmptyClass();
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
class Matrix2{
|
||||
<EN, T2, EM extends EN, R extends EM, DF extends T2> Fun1<Fun1<EN, Fun2<R, Matrix2, T2>>, DF> op = (m)->(f)->{return f.apply(this,m);};
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package plugindevelopment.TypeInsertTests;
|
||||
package plugindevelopment.TypeInsertTests.LargeSourceCodeTests;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import plugindevelopment.TypeInsertTests.MultipleTypesInsertTester;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -12,6 +12,7 @@ import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.logger.LoggerConfiguration;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
import de.dhbwstuttgart.logger.SectionLogger;
|
||||
import de.dhbwstuttgart.logger.Timewatch;
|
||||
import de.dhbwstuttgart.parser.JavaParser.yyException;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||||
@ -69,12 +70,7 @@ public class MultipleTypesInsertTester extends TypeInsertTester{
|
||||
for(String containString : mustContain){
|
||||
TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString));
|
||||
}
|
||||
try {
|
||||
Files.write(Logger.getWholeLog().getBytes(),new File(rootDirectory+sourceFileToInfere+".log"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
TestCase.fail();
|
||||
}
|
||||
writeLog(sourceFileToInfere+".log");
|
||||
}
|
||||
|
||||
public static void testSingleInsert(String sourceFileToInfere, Menge<String> mustContain){
|
||||
@ -106,8 +102,19 @@ public class MultipleTypesInsertTester extends TypeInsertTester{
|
||||
for(String containString : mustContain){
|
||||
TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString));
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
try {
|
||||
Files.write(Logger.getWholeLog().getBytes(),new File(rootDirectory+sourceFileToInfere+".log"));
|
||||
=======
|
||||
writeLog(sourceFileToInfere+".log");
|
||||
}
|
||||
|
||||
private static void writeLog(String toFile){
|
||||
String log = Logger.getWholeLog()+"\n";
|
||||
log+=Timewatch.getTimewatch().dumpTimeData();
|
||||
try {
|
||||
Files.write(log.getBytes(),new File(rootDirectory+toFile));
|
||||
>>>>>>> master
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
TestCase.fail();
|
||||
|
Loading…
Reference in New Issue
Block a user