From 4c9d6969054169d7891c12c78fe4224dedd9cbca Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 1 Oct 2014 17:12:16 +0200 Subject: [PATCH] =?UTF-8?q?FC=20enth=C3=A4lt=20superklassen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 2 +- .settings/org.eclipse.jdt.core.prefs | 7 ++-- bin/.gitignore | 4 +- src/de/dhbwstuttgart/core/MyCompiler.java | 2 - src/de/dhbwstuttgart/syntaxtree/Class.java | 5 +-- .../dhbwstuttgart/syntaxtree/SourceFile.java | 42 ++++++++++++++----- .../typeinference/ConstraintsSet.java | 8 ++++ .../typeinference/OderConstraint.java | 13 ++++++ .../assumptions/TypeAssumptions.java | 4 ++ 9 files changed, 64 insertions(+), 23 deletions(-) diff --git a/.classpath b/.classpath index 11f44fce..822c05c8 100755 --- a/.classpath +++ b/.classpath @@ -3,7 +3,7 @@ - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 794d6ee6..2e8ab188 100755 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bin/.gitignore b/bin/.gitignore index 56a30e6a..8c252d62 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,6 +1,4 @@ -/bytecode/ /de/ /mycompiler/ -/parser/ -/plugindevelopment/ /syntaxTree/ +/plugindevelopment/ diff --git a/src/de/dhbwstuttgart/core/MyCompiler.java b/src/de/dhbwstuttgart/core/MyCompiler.java index dd384b93..f6f1c363 100755 --- a/src/de/dhbwstuttgart/core/MyCompiler.java +++ b/src/de/dhbwstuttgart/core/MyCompiler.java @@ -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; diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index a2554592..6bc3878f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -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; } diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 51387bd8..5ed9db31 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -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> xConstraints = new Vector>();// = oderConstraints.getConstraints(); for(Vector 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 jreSpiderRegistry=new Hashtable(); Vector typeGenPara = new Vector(); @@ -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 diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index 889cf0a6..a3f44659 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -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{ private Vector constraintsSet; @@ -50,6 +52,12 @@ public class ConstraintsSet implements Iterable{ return constraintsSet.iterator(); } + public void filterWrongConstraints(Unifier unify) { + for(OderConstraint constraint : this){ + constraint.filterWrongConstraints(unify); + } + } + } diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index 62eb2096..47e21a0a 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -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 oderConstraintPairs; @@ -78,5 +79,17 @@ public class OderConstraint{ public void addConstraint(UndConstraint methodConstraint) { oderConstraintPairs.add(methodConstraint); } + + public void filterWrongConstraints(Unifier unify) { + Vector 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; + } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 2a4d7521..b733e110 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -371,6 +371,10 @@ public class TypeAssumptions { this.genericVarAssumptions.add(new GenericVarAssumption(genericTypeVar)); } + public Vector 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.