FC enthält superklassen

This commit is contained in:
JanUlrich 2014-10-01 17:12:16 +02:00
parent d636d29ab5
commit 4c9d696905
9 changed files with 64 additions and 23 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"/>
<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/log4j-1.2.12.jar"/>
<classpathentry kind="lib" path="lib/junit-4.0.jar"/>
<classpathentry kind="lib" path="lib/antlr-4.4-complete.jar"/>

View File

@ -1,12 +1,13 @@
eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.8

4
bin/.gitignore vendored
View File

@ -1,6 +1,4 @@
/bytecode/
/de/
/mycompiler/
/parser/
/plugindevelopment/
/syntaxTree/
/plugindevelopment/

View File

@ -16,8 +16,6 @@ import java.util.Vector;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
import com.sun.org.apache.xerces.internal.impl.xs.identity.Field;
import de.dhbwstuttgart.bytecode.ClassFile;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;

View File

@ -33,7 +33,6 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
import de.dhbwstuttgart.typeinference.unify.Unify;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
// ino.class.Class.23010.declaration
@ -163,8 +162,8 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
}
// ino.end
public Class(String name, RefType superClass, int offset){
this(name,offset);
public Class(String name, RefType superClass, Modifiers mod, int offset){
this(name,mod,offset);
this.superClass = superClass;
}

View File

@ -46,8 +46,6 @@ import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
import de.dhbwstuttgart.typeinference.unify.Unify;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
@ -299,7 +297,7 @@ public class SourceFile
*/
// ino.end
// ino.method.makeFC.21403.definition
public FC_TTO makeFC( )
public FC_TTO makeFC( TypeAssumptions ass )
// ino.end
// ino.method.makeFC.21403.body
{
@ -311,6 +309,11 @@ public class SourceFile
globalAssumptions.add(this.getPublicFieldAssumptions());
// 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen
for(ClassAssumption cAss : ass.getClassAssumptions()){
Pair p = new Pair(cAss.getAssumedClass().getType(), cAss.getAssumedClass().getSuperClass());
vFC.add(p);
}
for( int i = 0; i < KlassenVektor.size(); i++ )
{
Class tempKlasse = KlassenVektor.elementAt(i);
@ -650,9 +653,6 @@ public class SourceFile
//Logger initialisieren:
Logger typinferenzLog = Logger.getLogger("Typeinference");
//FiniteClosure generieren:
FC_TTO finiteClosure = this.makeFC();
//Alle Assumptions für diese SourceFile sammeln:
for(Class klasse : this.KlassenVektor){
globalAssumptions.add(klasse.getPublicFieldAssumptions());
@ -663,6 +663,11 @@ public class SourceFile
globalAssumptions.add(importAssumptions);
typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions);
//FiniteClosure generieren:
FC_TTO finiteClosure = this.makeFC(globalAssumptions);
System.out.println("FiniteClosure: \n"+finiteClosure);
ConstraintsSet oderConstraints = new ConstraintsSet();
//Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln:
for(Class klasse : KlassenVektor){
@ -672,6 +677,9 @@ public class SourceFile
////////////////
//Karthesisches Produkt bilden:
////////////////
//Unmögliche ConstraintsSets aussortieren durch Unifizierung
oderConstraints.filterWrongConstraints((pairs)->{return Unify.unify(pairs,finiteClosure);});
//Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden):
Vector<Vector<Pair>> xConstraints = new Vector<Vector<Pair>>();// = oderConstraints.getConstraints();
for(Vector<UndConstraint> uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt.
@ -1115,9 +1123,12 @@ public class SourceFile
//String className=x.getSimpleName();
String className=x.getName();
//Ermittle die Superklasse:
Class sClass;
sClass = getSuperClassOfJREClass(x, basicAssumptions);
Class parentClass = new Class(className, sClass.getType(),mod , 0);
Class parentClass = new Class(className, mod, 0);
// Generische Typen erzeugen
Hashtable<String,GenericTypeVar> jreSpiderRegistry=new Hashtable<String,GenericTypeVar>();
Vector<GenericTypeVar> typeGenPara = new Vector<GenericTypeVar>();
@ -1242,9 +1253,16 @@ public class SourceFile
}
// ino.end
private Class getSuperClassOfJREClass(java.lang.Class<?> x, TypeAssumptions ass) {
Class ret;
java.lang.Class s = x.getSuperclass();
if(s == null)return new Class("java.lang.Object",new Modifiers(), 0);
Class ss = this.getSuperClassOfJREClass(s, ass);
ret = new Class(x.getName(),ss.getType(),new Modifiers(),0);
return ret;
}
// ino.method.isBaseType.21412.definition
// ino.method.isBaseType.21412.definition
private boolean isBaseType(String type)
// ino.end
// ino.method.isBaseType.21412.body
@ -1273,10 +1291,12 @@ public class SourceFile
// ino.end
// ino.method.createTypeFromJavaGenericType.21415.body
{
/* auskommentiert, da die Klassen von Sun in der Open JDK 1.8 nicht unterstützt werden.
if(type instanceof TypeVariableImpl){
TypeVariableImpl tvi=((TypeVariableImpl)type);
TypeVariableImpl tvi=((TypeVariableImpl)type);
return(new GenericTypeVar(jreSpiderRegistry.get(tvi.getName()).getName().toString(),parentClass,-1));
}else{
*/
//String jccNameForClass=baseTypeTranslationTable.get(cl.getSimpleName());
String jccNameForClass=baseTypeTranslationTable.get(cl.getName());
if(cl.getSimpleName().equalsIgnoreCase("void")){
@ -1289,7 +1309,7 @@ public class SourceFile
//return(new RefType(cl.getSimpleName()));
return(new RefType(cl.getName(),parentClass,-1));
}
}
//}
}
// ino.end

View File

@ -3,6 +3,8 @@ package de.dhbwstuttgart.typeinference;
import java.util.Iterator;
import java.util.Vector;
import de.dhbwstuttgart.typeinference.unify.Unifier;
public class ConstraintsSet implements Iterable<OderConstraint>{
private Vector<OderConstraint> constraintsSet;
@ -50,6 +52,12 @@ public class ConstraintsSet implements Iterable<OderConstraint>{
return constraintsSet.iterator();
}
public void filterWrongConstraints(Unifier unify) {
for(OderConstraint constraint : this){
constraint.filterWrongConstraints(unify);
}
}
}

View File

@ -5,6 +5,7 @@ import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier;
public class OderConstraint{
private Vector<UndConstraint> oderConstraintPairs;
@ -78,5 +79,17 @@ public class OderConstraint{
public void addConstraint(UndConstraint methodConstraint) {
oderConstraintPairs.add(methodConstraint);
}
public void filterWrongConstraints(Unifier unify) {
Vector<UndConstraint> filteredConstraints = new Vector<>();
for(UndConstraint cons : this.getUndConstraints()){
if(!unify.unify(cons.getConstraintPairs()).isEmpty()){
filteredConstraints.add(cons);
}else{
System.out.println("Ausgesondertes Constraint: "+cons);
}
}
this.oderConstraintPairs = filteredConstraints;
}
}

View File

@ -371,6 +371,10 @@ public class TypeAssumptions {
this.genericVarAssumptions.add(new GenericVarAssumption(genericTypeVar));
}
public Vector<ClassAssumption> getClassAssumptions() {
return this.classAssumptions;
}
/**
* Prüft einen Typ auf das vorhandensein in den BasicAssumptions.
* Dabei werden alle Konstruktoren nach diesem Typ durchsucht. Denn jede Klasse hat einen Konstruktor und der muss in den TypeAssumptions vorhanden sein.