diff --git a/src/de/dhbwstuttgart/core/AClassOrInterface.java b/src/de/dhbwstuttgart/core/AClassOrInterface.java deleted file mode 100755 index db2df4fd..00000000 --- a/src/de/dhbwstuttgart/core/AClassOrInterface.java +++ /dev/null @@ -1,209 +0,0 @@ - -// ino.module.AClassOrInterface.8526.package -package de.dhbwstuttgart.core; -// ino.end - -// ino.module.AClassOrInterface.8526.import -import de.dhbwstuttgart.typeinference.Menge; - -import de.dhbwstuttgart.logger.Logger; -// ino.end - - - -import de.dhbwstuttgart.parser.JavaClassName; -import de.dhbwstuttgart.syntaxtree.Interface; -import de.dhbwstuttgart.syntaxtree.misc.UsedId; -import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; -import de.dhbwstuttgart.syntaxtree.type.RefType; -import de.dhbwstuttgart.syntaxtree.type.Type; - -// ino.class.AClassOrInterface.21186.description type=javadoc -/** - * Superklasse von Class und Interface. Beinhaltet gemeinsame Attribute - * der beiden Objekte. - * - * @author Juergen Schmiing - * - */ -// ino.end -// ino.class.AClassOrInterface.21186.declaration -public interface AClassOrInterface -// ino.end -// ino.class.AClassOrInterface.21186.body -{ - - public JavaClassName getName(); - public Menge getSuperInterfaces(); - public void setSuperInterfaces(Menge Menge); - - /* - // ino.attribute.inferencelog.21189.decldescription type=javadoc - // ino.end - // ino.attribute.inferencelog.21189.declaration - protected static Logger inferencelog = Logger.getLogger("inference"); - // ino.end - // ino.attribute.codegenlog.21192.declaration - protected static Logger codegenlog = Logger.getLogger("codegen"); - // ino.end - // ino.attribute.parserlog.21195.declaration - protected static Logger parserlog = Logger.getLogger("parser"); - // ino.end - - // ino.attribute.pkgName.21198.decldescription type=line - // Package-Name - // ino.end - // ino.attribute.pkgName.21198.declaration - protected UsedId pkgName; - // ino.end - - // ino.attribute.modifiers.21201.decldescription type=line - // Class/Interface-Name und Access-Modifiers - // ino.end - // ino.attribute.modifiers.21201.declaration - protected Modifiers modifiers; - // ino.end - // ino.attribute.name.21204.declaration - protected String name; - // ino.end - - // ino.attribute.superif.21207.decldescription type=line - // Superinterfaces. Interfaces erweitern die Liste, - // Klassen implementieren die Liste. - // ino.end - // ino.attribute.superif.21207.declaration - private Menge superif = new Menge(); - // ino.end - - // ino.method.AClassOrInterface.21210.defdescription type=line - // Konstruktoren - // ino.end - // ino.method.AClassOrInterface.21210.definition - public AClassOrInterface() - // ino.end - // ino.method.AClassOrInterface.21210.body - {} - // ino.end - - // ino.method.AClassOrInterface.21213.definition - public AClassOrInterface(String strName) - // ino.end - // ino.method.AClassOrInterface.21213.body - { - name = strName; - } - // ino.end - // ino.method.AClassOrInterface.21216.definition - public AClassOrInterface(String strName, Modifiers mod) - // ino.end - // ino.method.AClassOrInterface.21216.body - { - name = strName; - this.modifiers = mod; - } - // ino.end - - // ino.method.getPackageName.21219.defdescription type=line - // Handling fuer Packages - // ino.end - // ino.method.getPackageName.21219.definition - public UsedId getPackageName() - // ino.end - // ino.method.getPackageName.21219.body - { - return pkgName; - } - // ino.end - - // ino.method.setPackageName.21222.definition - public void setPackageName(UsedId pkgName) - // ino.end - // ino.method.setPackageName.21222.body - { - this.pkgName = pkgName; - } - // ino.end - - // ino.method.getName.21225.definition - public String getName() - // ino.end - // ino.method.getName.21225.body - { - return name; - } - // ino.end - - // ino.method.setName.21228.definition - public void setName(String strName) - // ino.end - // ino.method.setName.21228.body - { - name = strName; - } - // ino.end - - // ino.method.setModifiers.21231.definition - public void setModifiers(Modifiers mod) - // ino.end - // ino.method.setModifiers.21231.body - { - this.modifiers = mod; - } - // ino.end - - // ino.method.getModifiers.21234.definition - public Modifiers getModifiers() - // ino.end - // ino.method.getModifiers.21234.body - { - return this.modifiers; - } - // ino.end - - // ino.method.getAccessFlags.21237.defdescription type=javadoc - // ino.end - // ino.method.getAccessFlags.21237.definition - public short getAccessFlags() - // ino.end - // ino.method.getAccessFlags.21237.body - { - short ret = 0; - if (modifiers != null) { - ret = modifiers.calculate_access_flags(); - } - //if (ret != 0) - // return ret; - //else - // return (short) 32; - - //feda 04.07.07 wird bei der Codegenerierung des Class File beachtet. - - return ret; - } - // ino.end - - // ino.method.getSuperInterfaces.21240.definition - public Menge getSuperInterfaces() - // ino.end - // ino.method.getSuperInterfaces.21240.body - { - return superif; - } - // ino.end - - // ino.method.setSuperInterfaces.21243.definition - public void setSuperInterfaces(Menge superif) - // ino.end - // ino.method.setSuperInterfaces.21243.body - { - this.superif = superif; - } - // ino.end - - // ino.method.codegen.21246.declaration - public abstract void codegen(SourceFile sf) - throws JVMCodeException; - // ino.end - */ -} -// ino.end diff --git a/src/de/dhbwstuttgart/core/IItemWithOffset.java b/src/de/dhbwstuttgart/core/IItemWithOffset.java index 8dc277f9..f90debf0 100755 --- a/src/de/dhbwstuttgart/core/IItemWithOffset.java +++ b/src/de/dhbwstuttgart/core/IItemWithOffset.java @@ -1,17 +1,9 @@ -// ino.module.IItemWithOffset.8527.package package de.dhbwstuttgart.core; -// ino.end -// ino.class.IItemWithOffset.21249.declaration +import de.dhbwstuttgart.syntaxtree.SourceCodePosition; + public interface IItemWithOffset -// ino.end -// ino.class.IItemWithOffset.21249.body { - // ino.method.getOffset.21252.declaration public int getOffset(); - // ino.end - // ino.method.getVariableLength.21255.declaration public int getVariableLength(); - // ino.end } -// ino.end diff --git a/src/de/dhbwstuttgart/parser/InterfaceList.java b/src/de/dhbwstuttgart/parser/InterfaceList.java deleted file mode 100755 index 045b6ad9..00000000 --- a/src/de/dhbwstuttgart/parser/InterfaceList.java +++ /dev/null @@ -1,54 +0,0 @@ -// ino.module.InterfaceList.8615.package -package de.dhbwstuttgart.parser; -// ino.end - -// ino.module.InterfaceList.8615.import -import de.dhbwstuttgart.typeinference.Menge; - -import de.dhbwstuttgart.syntaxtree.Interface; -import de.dhbwstuttgart.syntaxtree.misc.UsedId; -import de.dhbwstuttgart.syntaxtree.type.RefType; -import de.dhbwstuttgart.syntaxtree.type.Type; - -// ino.class.InterfaceList.24383.description type=javadoc -/** - * Hilfskonstrukt fuer die Grammatik, um ungepruefte - * Typcasts fuer Mengeen zu umgehen. Wird nuer fuer den - * Parser benoetigt. - * @author SCJU - * - */ -// ino.end -// ino.class.InterfaceList.24383.declaration -public class InterfaceList -// ino.end -// ino.class.InterfaceList.24383.body -{ - // ino.attribute.superif.24386.declaration - private Menge superif = new Menge(); - // ino.end - - // ino.method.addInterface.24389.definition - public void addInterface(UsedId uid) - // ino.end - // ino.method.addInterface.24389.body - { - superif.addElement(uid); - } - // ino.end - - // ino.method.getMenge.24392.definition - public Menge getTypeMenge() - // ino.end - // ino.method.getMenge.24392.body - { - Menge ret = new Menge<>(); - for(UsedId name : superif){ - ret.add(new Interface(name.get_Name_1Element(), name.getOffset()).getType()); - } - return ret; - } - // ino.end - -} -// ino.end diff --git a/src/de/dhbwstuttgart/parser/JavaClassName.java b/src/de/dhbwstuttgart/parser/JavaClassName.java index 857680f0..666f5304 100644 --- a/src/de/dhbwstuttgart/parser/JavaClassName.java +++ b/src/de/dhbwstuttgart/parser/JavaClassName.java @@ -35,6 +35,13 @@ public class JavaClassName { } } + /** + * @return Nur den Namen der Klasse ohne den Package-Namen + */ + public String getName(){ + return name; + } + //Auto-generated hashCode: @Override public int hashCode() { diff --git a/src/de/dhbwstuttgart/syntaxtree/BasicAssumptionClass.java b/src/de/dhbwstuttgart/syntaxtree/BasicAssumptionClass.java deleted file mode 100755 index e6a319b7..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/BasicAssumptionClass.java +++ /dev/null @@ -1,33 +0,0 @@ -// ino.module.BasicAssumptionClass.8552.package -package de.dhbwstuttgart.syntaxtree; -// ino.end - -// ino.module.BasicAssumptionClass.8552.import -import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; - -// ino.class.BasicAssumptionClass.23000.declaration -public class BasicAssumptionClass extends Class -// ino.end -// ino.class.BasicAssumptionClass.23000.body -{ - - // ino.method.BasicAssumptionClass.23004.definition - public BasicAssumptionClass(String name) - // ino.end - // ino.method.BasicAssumptionClass.23004.body - { - super(name, 0); - } - // ino.end - - // ino.method.BasicAssumptionClass.23007.definition - public BasicAssumptionClass(String name, Modifiers mod) - // ino.end - // ino.method.BasicAssumptionClass.23007.body - { - super(name,mod, 0); - } - // ino.end - -} -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index f5cbb6c9..083b3fb2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -25,11 +25,8 @@ import de.dhbwstuttgart.logger.SectionLogger; import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.bytecode.DHBWConstantPoolGen; import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; -import de.dhbwstuttgart.core.AClassOrInterface; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.parser.JavaClassName; -import de.dhbwstuttgart.syntaxtree.misc.DeclId; -import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; import de.dhbwstuttgart.syntaxtree.modifier.Static; import de.dhbwstuttgart.syntaxtree.statement.Block; @@ -58,9 +55,10 @@ import org.apache.bcel.*; import java.io.*; - -// ino.class.Class.23010.declaration -public class Class extends GTVDeclarationContext implements AClassOrInterface, IItemWithOffset, Generic, GenericTypeInsertable +/** + * Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces + */ +public class Class extends GTVDeclarationContext implements IItemWithOffset, Generic, GenericTypeInsertable // ino.end // ino.class.Class.23010.body { @@ -70,9 +68,15 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I protected static Logger inferencelog = Logger.getLogger("inference"); protected static Logger codegenlog = Logger.getLogger("codegen"); protected static Logger parserlog = Logger.getLogger("parser"); - protected UsedId pkgName; + protected Logger typinferenzLog = Logger.getLogger(Class.class.getName()); protected Modifiers modifiers; - protected String name; + protected JavaClassName name; + private Menge superif; + + public Class(JavaClassName name, List methoden, List felder, Modifiers modifier, + boolean isInterface, RefType superClass, List implementedInterfaces, int offset){ + + } /** * @@ -89,9 +93,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I SectionLogger logger = Logger.getSectionLogger(this.getClass().getName(), Section.CODEGEN); logger.debug("Test"); - if(pkgName != null)throw new NotImplementedException(); short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public - _cg = new ClassGenerator(name, this.getSuperClass(), name + ".java", constants , new String[] { }, typeinferenceResults); //letzter Parameter sind implementierte Interfaces + _cg = new ClassGenerator(name.toString(), this.getSuperClass(), name.getName() + ".java", constants , new String[] { }, typeinferenceResults); //letzter Parameter sind implementierte Interfaces _cp = _cg.getConstantPool(); _factory = new DHBWInstructionFactory(_cg, _cp); @@ -120,28 +123,10 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I return new ByteCodeResult(_cg); } - - private Menge superif = new Menge(); - - public UsedId getPackageName() - { - return pkgName; - } - public void setPackageName(UsedId pkgName) - { - this.pkgName = pkgName; - } + public JavaClassName getName() { - return new JavaClassName((this.pkgName!=null ? this.pkgName.toString() +"." : "") +this.name); - } - public void setName(String strName) - { - name = strName; - } - public void setModifiers(Modifiers mod) - { - this.modifiers = mod; + return name; } public Modifiers getModifiers() { @@ -159,399 +144,27 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I return ret; } - public Menge getSuperInterfaces() + public Menge getSuperInterfaces() { return superif; } - - @Override - public void setSuperInterfaces(Menge superif) - { - this.superif = superif; - } - - public UsedId superclassid = (SourceFile.READ_OBJECT_SUPERCLASSES_FROM_JRE?UsedId.createFromQualifiedName("Object",-1):null); private Block class_block; private Hashtable parahash = new Hashtable(); // parametrisierten Attrib. werden mit den Paramet.aus paralist verk. - public static boolean isFirstLocalVarDecl; //Hilfsvariable fuer Offsets, hoth - // PL 05-07-30 eingefuegt. Vektor aller Typdeklarationen, die in der Klasse - // vorkommen. Wird in der Studienarbeit von Andreas Stadelmeier nur für Verifizierung der Tests eingesetzt. - private Menge containedTypes = new Menge(); - private Menge usedIdsToCheck = new Menge(); private TypeAssumptions typeAssumptions = null;//muss mit null Initialisiert werden. Darf nur über getTypeAssumptions abgerufen werden. - protected Logger typinferenzLog = Logger.getLogger(Class.class.getName()); - private SyntaxTreeNode parent; private Menge fielddecl = new Menge(); private GenericDeclarationList genericClassParameters; private int offset; private RefType superClass; - - public Class(String name, int offset) - { - this.name = name; - if(name.equals("java.lang.Object")){ - superclassid=null; - } - this.offset = offset; - if(!name.equals("Object") && !name.equals("java.lang.Object"))//Alle Klassen außer Object erben von Object: - this.superClass = new Class("java.lang.Object", -1).getType(); - } - // ino.end - - /** - * Erstellt eine Klasse, welche nur für die Assumptions verwendet wird. - * Sie enthält keine unnötigen Informationen, wie Offset oder ClassBody. - * @param name - * @param superClass - * @param modifiers - * @param supertypeGenPara - Eine Liste von Namen, welche die Generischen Parameter der Klasse darstellen. - */ - public Class(String name, RefType superClass, Modifiers modifiers, Menge supertypeGenPara) { - this(name,superClass,modifiers,0); - if(supertypeGenPara == null)return; - Menge gtvs = new Menge<>(); - for(Object gname : supertypeGenPara){ - if(gname instanceof String){ - GenericTypeVar newGTV=new GenericTypeVar((String)gname,this,0); - gtvs.add(newGTV); - }else if(gname instanceof GenericTypeVar){ - gtvs.add((GenericTypeVar) gname); - }else{ - GenericTypeVar newGTV=new GenericTypeVar(gname.toString(),this,0); - gtvs.add(newGTV); - - throw new RuntimeException(gname.toString()); - } - - } - this.setGenericParameter(new GenericDeclarationList(gtvs,0)); - } - - public Class(String name, RefType superClass, Modifiers mod, int offset){ - this(name,mod,offset); - if(superClass == null)this.superClass = new Class("java.lang.Object",-1).getType(); - else this.superClass = superClass; - } - - // ino.method.Class.23044.definition - public Class(String name, Modifiers mod, int offset) - // ino.end - // ino.method.Class.23044.body - { - this(name, offset); - this.modifiers = mod; - } - // ino.end - - public Class(String name, Modifiers mod, ClassBody cb, Menge ct, Menge usedIdsToCheck, - UsedId superclass, Menge superif, Menge paralist, int offset){ - this(name, mod, cb, ct, usedIdToRefType(superclass),usedIdToRefType(superif),paralist,offset); - } - public Class(String name, ClassBody cb, Menge ct, - UsedId superclass, Menge superif, Menge paralist, int offset) { - this(name,null,cb,ct,usedIdToRefType(superclass),superif,paralist,offset); - } - public Class(String name2, Modifiers modifiers2, ClassBody classBody, - Menge containedTypes2, UsedId usedId, - Menge typeMenge, Menge paraMenge, int offset2) { - this(name2, modifiers2, classBody, containedTypes2, usedIdToRefType(usedId),typeMenge, paraMenge, offset2); - } - public Class(String name2, Modifiers object, ClassBody classBody, - Menge containedTypes2, Menge typeMenge, - Menge paraMenge, int offset2) { - this(name2, object, classBody, containedTypes2,(RefType)null, typeMenge, paraMenge, offset2); - } - private static Menge usedIdToRefType(Menge superif2) { - Menge ret = new Menge<>(); - for(UsedId id : superif2)ret.add(usedIdToRefType(id)); - return ret; - } - private static RefType usedIdToRefType(UsedId superclass2) { - RefType ret = new RefType(superclass2.getSimpleName(), null, superclass2.getOffset()); - ret.set_ParaList(superclass2.get_ParaList()); - return ret; - } - - // ino.method.Class.23047.defdescription type=javadoc - /** - * Konstruktor, der die Angabe aller Parameter ermoeglicht. - * Zur Uebersichtlichkeit in der Grammatik. - */ - // ino.end - // ino.method.Class.23047.definition - public Class(String name, Modifiers mod, ClassBody cb, Menge ct, - RefType superclass, Menge Menge, Menge paralist, int offset) - // ino.end -// ino.method.Class.23047.body -{ - this(name,offset); - this.modifiers = mod; - if (cb != null) set_ClassBody(cb); - if (ct != null) setContainedTypes(ct); - if (superclass != null){ - this.superClass = superclass; - } - if (Menge != null) setSuperInterfaces(Menge); - if (paralist != null && !paralist.isEmpty()){ - Type lastPara = paralist.lastElement(); - Integer lastItemOffset = lastPara.getOffset() + lastPara.get_Name().length(); - this.setGenericParameter(new GenericDeclarationList((Menge)paralist, lastItemOffset)); - /* - //this.set_ParaList(paralist); - Menge gtvList = new Menge<>(); - int lastItemOffset = 0; - for(Type paraT : paralist){ - GenericTypeVar gtv = new GenericTypeVar(paraT.get_Name(),this, paraT.getOffset()); - gtvList.add(gtv); - lastItemOffset = paraT.getOffset() + paraT.get_Name().length(); - } - this.genericClassParameters = new GenericDeclarationList(gtvList, lastItemOffset); - */ - } - if(usedIdsToCheck!=null) this.usedIdsToCheck=usedIdsToCheck; - - // HOTI 10.5.06 - // Object darf natuerlich nicht Object als Superklasse haben - // Sonst gibt es eine endlosaufloesung - if(name.equals("java.lang.Object")){ - superclassid=null; - } - - - //parserlog.debug("Neue Klasse: " + name); - - } -// ino.end - public Menge getFields() { return fielddecl; } - - /** - * @author Andreas Stadelmeier, a10023 - * Fügt der Klasse eine Feld hinzu. - * Prüft dabei, ob es sich um einen Constructor handelt und wandelt diesen direkt um. - * @param feld - */ - public void addField(Field i) - { - - fielddecl.addElement(i); - } - - // ino.method.getUsedIdsToCheck.23050.definition - public Menge getUsedIdsToCheck() - // ino.end - // ino.method.getUsedIdsToCheck.23050.body - { - return usedIdsToCheck; - } - // ino.end - // ino.method.setContainedTypes.23053.definition - public void setContainedTypes(Menge containedTypes) - // ino.end - // ino.method.setContainedTypes.23053.body - { - this.containedTypes = containedTypes; - } - // ino.end - - // ino.method.getContainedTypes.23056.definition - public Menge getContainedTypes() - // ino.end - // ino.method.getContainedTypes.23056.body - { - return containedTypes; - } - // ino.end - - /* - // ino.method.complete_paralist.23062.definition - public Menge complete_paralist(boolean ext) - // ino.end - // ino.method.complete_paralist.23062.body - { - - //Diese Funktion vervollt�ndigt die Parameterliste f�r vererbte Klassen - Menge child = paralist; - - paralist = (Menge)superclassid.get_ParaList(); - - for(Enumeration e = child.elements();e.hasMoreElements();){ - paralist.addElement(e.nextElement()); - } - - return this.paralist; - } - // ino.end - */ - - - /** - * Generiert die ClassFile für diese Klasse. - * @param typeinferenceResult - Das ResultSet einer Typinferierung oder null, falls alle Typen eindeutig feststehen. - * @return - * @throws JVMCodeException - - // ino.method.codegen.23071.definition - public ClassFile codegen(ResultSet typeinferenceResult) - throws JVMCodeException - // ino.end - // ino.method.codegen.23071.body - { - ClassFile classfile = new ClassFile(); - String superClass; - - // Handling der Superklasse - if(superclassid != null) { - superClass = superclassid.get_codegen_UsedId(); - } else { - superClass = "java/lang/Object"; - } - - // Handling der Package - //String pkgName = ""; - //if (sf.getPackageName() != null) { - // pkgName = sf.getPackageName().get_codegen_UsedId() + "/"; - //} - - //geändert von Andreas Stadelmeier: pkgName wird nicht mehr aus dem SourceFile ausgelesen: - String packageName = ""; - if(pkgName != null) packageName = pkgName.get_Name_1Element(); - classfile.add_class(getName(), superClass, getAccessFlags()); - - // Handling fuer Superinterfaces - classfile.addSuperInterfaces(getSuperInterfaces()); - - // Generics hinzufuegen - falls erforderlich - classfile.addGenerics(this.paralist,superclassid, this.getSuperInterfaces()); - - // Body der Classfile generieren - //if(body != null) { - this.codegen(classfile, this.paralist); - //} - - // Ueberpruefung, ob Konstruktor generiert - // Falls nicht, default-Konstruktor erzeugen - if(!classfile.get_constructor_founded()) { - classfile.add_method("", "()V", null, null, null, (short)0, this.paralist, false); - } - - //classfile.codegen(); - - codegenlog.info("Compilierung erfolgreich abgeschlossen, "+ getName() + ".class erstellt."); - return classfile; - } - */ - - public void set_UsedId (UsedId uid) - // ino.end - // ino.method.set_UsedId.23074.body - { - this.superclassid = uid; - } - // ino.end - - /** - * Setzt den ClassBody dieser Klasse. Wird zum Parsen benötigt. - * Der ClassBody enthält sämtliche Felder dieser Klasse. - * Mit dem Aufruf dieser Methode werden alle Felder des ClassBody in diese Class übertragen. - * (Nur einmal während des Parsens aufrufen!) - */ - public void set_ClassBody(ClassBody body) - { - Menge tempFields=body.getFields(); - for(Field f : this.getFields()){ - - if(f instanceof Method){ //Wenn es sich um eine Methode handelt ist eine zusätzliche Prüfung erfoderlich: (Ist es ein Konstruktor?) - Method m = (Method)f; - /* - * Ermitteln ob es sich bei der Methode um einen Konstruktor handelt: - * (Parser kann nicht zwischen Methode und Konstruktor unterscheiden. - * Denn für einen Konstruktor gelten besondere Regeln: - * -Typ des Blocks eines Konstruktor ist void (kein Return-Statement) - * -Rückgabetyp der Methode/Konstruktors ist der Typ der Klasse - * -Ein Konstruktor kann nicht aufgerufen werden (nur mit new) - */ - if(m.get_Method_Name().equals(""))throw new TypeinferenceException(" ist kein gültiger Methodenname", m); - if((m.get_Method_Name().equals(this.getName()))) { - Constructor constructor = new Constructor(m, this); - tempFields.add(constructor); //Den Konstruktor anstatt der Methode anfügen - }else{ - //Handelt es sich um keinen Konstruktor, dann die Methode unverändert den Feldern hinzufügen: - tempFields.add(m); - } - }else{ - tempFields.add(f); //Ansonsten das Feld anfügen... - } - - } - this.fielddecl = tempFields; - } - - // ino.method.set_class_block.23080.definition - public void set_class_block(Block block) - // ino.end - // ino.method.set_class_block.23080.body - { - this.class_block = block; - } - // ino.end - - - - // ino.method.get_Superclass_Name.23086.definition - public JavaClassName get_Superclass_Name() - // ino.end - // ino.method.get_Superclass_Name.23086.body - { - if(superclassid!=null) - return superclassid.getQualifiedName(); - else - return null; - } - // ino.end - - - - // ino.method.get_class_block.23092.definition - public Block get_class_block() - // ino.end - // ino.method.get_class_block.23092.body - { - return class_block; - } - // ino.end - - // ino.method.does_Class_extend.23095.definition - public boolean does_Class_extend() - // ino.end - // ino.method.does_Class_extend.23095.body - { - if(superclassid==null) - return false; - else - return true; - } - // ino.end - - /* - // ino.method.set_ParaList.23098.definition - public void set_ParaList(Menge para) - // ino.end - // ino.method.set_ParaList.23098.body - { - this.paralist = para; - } - // ino.end - */ // ino.method.get_ParaList.23101.definition public List get_ParaList() @@ -628,22 +241,9 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I } typinferenzLog.debug("Erstellte Assumptions: "+assumptions, Section.TYPEINFERENCE); - /* - //Generiere Liste mit Expressions, welche zur Initialisierung von Feldern verwendet werden. - Menge fieldInitializers = new Menge(); - for(FieldDeclaration field : body.getFieldInitializations()){ - Assign fieldAssign = new Assign(0,0); - Expr expr1 = new LocalOrFieldVar(field.getName(), 0); - Expr expr2 = field.getWert(); - fieldAssign.set_Expr(expr1, expr2); - fieldInitializers.add(fieldAssign); - } - */ - - //ConstraintsSet oderConstraints = this.TYPE(this.getMethodList(), fieldInitializers, assumptions); - + //Gibt es hier eine ClassCastException stimmt etwas grundsätzlich nicht! - this.superClass = (RefType)this.superClass.TYPE(assumptions, this); + //this.superClass = (RefType)this.superClass.TYPE(assumptions, this); for(Field f:this.getFields()){ oderConstraints.add(f.TYPE(assumptions)); @@ -661,82 +261,26 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I private TypeAssumptions getPrivateFieldAssumptions() { if(this.typeAssumptions != null)return this.typeAssumptions; //Das sorgt dafür, dass die Assumptions nur einmalig generiert werden. TypeAssumptions assumptions = new TypeAssumptions(this.getName()); - //this.getMethodList(); //Diese Funktion muss zuerst ausgeführt werden. - //Assumption für this, also die aktuelle Klasse: (ist nicht mehr nötig, da jedes AssumptionSet einer Klasse (dem namen einer Klasse) zugewiesen ist. - //CLocalVarTypeAssumption thisAssumption = new CLocalVarTypeAssumption(this.name, name, 0, 0, name, "this", new RefType(name,0), 0, 0, null); - //assumptions.setThisV(thisAssumption); for(Field field : this.getFields()){ if(!field.isPublic())assumptions.add(field.createTypeAssumptions(this)); } - //Eine Assumption für den Standardkonstruktor: - // (Ein Standardkonstruktor wird immer angefügt, da es momentan keine statischen Klassen gibt) - //auskommentiert, da der Standardkonstruktor beim Parser-Postprocessing angefügt wird. - //if(assumptions.getMethodAssumptions(this.getName(), "").size()==0){ //Falls kein Konstruktor für diese Klasse definiert wurde: - // assumptions.addMethodAssumption(new RefType(this.getName(),0), "", new RefType(this.getName(),0), new Menge()); - //} - this.typeAssumptions = assumptions; //Diese müssen anschließend nicht wieder generiert werden. return assumptions; } - // ino.method.toString.23125.defdescription type=javadoc /** *
Author: Martin Pl�micke * @return */ - // ino.end - // ino.method.toString.23125.definition public String toString() - // ino.end - // ino.method.toString.23125.body { //return superclassid.toString() + body.toString(); //geaendert PL 07-07-28 - return name; - } - // ino.end - - - // ino.method.wandleRefTypeAttributes2GenericAttributes.23128.defdescription type=javadoc - /** - * Alle Methoden der Klassen überprüfen, ob sie als - * RefType deklarierte Attribute haben, die aber GenericTypeVars sind - * und ggf. ersetzen - * - * Bsp.: - * bei public E elementAt(i){...} wird E vorerst als RefType erkannt - * - */ - // ino.end - // ino.method.wandleRefTypeAttributes2GenericAttributes.23128.definition - public void wandleRefTypeAttributes2GenericAttributes() - // ino.end - // ino.method.wandleRefTypeAttributes2GenericAttributes.23128.body - { - for(Field f : this.getFields()){ - //f.wandleRefTypeAttributes2GenericAttributes(paralist); - } + return name.getName(); } - /** - * HOTI - * Liefert bei Klassen die fullyQualified angegeben wurden - * nur den schlussendlichen Bezeichner - * p.ex. de.dhbwstuttgart.typeinference.Menge => Menge - * @return - */ - // ino.end - // ino.method.getSimpleName.23140.definition - public String getSimpleName() - // ino.end - // ino.method.getSimpleName.23140.body - { - return UsedId.createFromQualifiedName(getName().toString(),-1).getSimpleName(); - } - // ino.end - public String getTypeInformation(Menge methodList, Menge fieldList){ String ret = this.name+": "; for(Expr field : fieldList){ @@ -760,12 +304,12 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I JavaCodeResult classBodyCode = new JavaCodeResult(); if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" "); - classBodyCode.attach(this.name + " extends ").attach(superclassid.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach("\n"); + classBodyCode.attach(this.name + " extends ").attach(this.superClass.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach("\n"); JavaCodeResult bodyString = new JavaCodeResult("{\n"); for(Field field : this.fielddecl)bodyString.attach( field.printJavaCode(reconstructionResult.getUnifiedConstraints()) ).attach( "\n" ); bodyString.attach("}\n"); - + classBodyCode.attach(bodyString); //Zuerst die generischen Parameter für diese Klasse berechnen: @@ -863,72 +407,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I } return ret; } - - @Override - public void parserPostProcessing(SyntaxTreeNode parent) { - //Wenn keine Superklasse, dann erbt die Klasse zwangsweise von Object: - if(superclassid == null || superclassid.get_Name().size()<1){ - int superclassidOffset = superclassid == null ? 0 : superclassid.getOffset(); - superclassid = new UsedId("Object", superclassidOffset); - } - - //Alle Methoden auf Konstruktoren durchsuchen und diese umwandeln: - Menge tempFields = new Menge(); - for(Field f : this.getFields()){ - 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, this)); - }else{ - tempFields.add(f); - } - }else{ - tempFields.add(f); - } - } - this.fielddecl = tempFields; - - //Prüfen ob ein Konstruktor vorhanden ist: - boolean constructorVorhanden = false; - for(Field f : this.getFields()){ - if(f instanceof Constructor){ - constructorVorhanden = true; - break; - } - } - if(!constructorVorhanden){//Falls kein Konstruktor vorhanden ist, muss noch der Standardkonstruktor angefügt werden: - Block konstruktorBlock = new Block(); - konstruktorBlock.statements.add(new SuperCall(konstruktorBlock)); - Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock,this.getName().toString(), this), this); - //Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(this.getName().toString(), this)); - - this.addField(standardKonstruktor); - } - - if(this.genericClassParameters == null)this.setGenericParameter(new GenericDeclarationList(new Menge(), 0)); - /*//Nicht mehr notwendig, Generische Klassenparameter werden nun immer direkt in die genericClassParameters gespeichert. - for(Type t : this.get_ParaList()){ - if(t instanceof GenericTypeVar)this.genericClassParameters.add((GenericTypeVar)t); - else this.genericClassParameters.add(new GenericTypeVar(t.get_Name(),this,-1)); - } - */ - /* - for(Type t : this.get_ParaList()){ - t.parserPostProcessing(this); - } - */ - /* - for(GenericTypeVar gtv : this.getGenericParameter()){ - gtv.setParentClass(this);; - } - */ - //TODO: Umwandlung zu RefTypes funktioniert noch nicht richtig. (siehe LambdaTest2) - //Als RefType geparste Generische Variablen umwandeln: - this.wandleRefTypeAttributes2GenericAttributes(); - - //Erst am Schluss, nachdem Methoden zu Konstruktoren umgewandelt wurden: - super.parserPostProcessing(parent); - } @Override public SyntaxTreeNode getParent() { diff --git a/src/de/dhbwstuttgart/syntaxtree/Constant.java b/src/de/dhbwstuttgart/syntaxtree/Constant.java deleted file mode 100755 index 8873e277..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/Constant.java +++ /dev/null @@ -1,204 +0,0 @@ -// ino.module.Constant.8556.package -package de.dhbwstuttgart.syntaxtree; -// ino.end - -// ino.module.Constant.8556.import -import de.dhbwstuttgart.typeinference.Menge; -import de.dhbwstuttgart.core.MyCompiler; -import de.dhbwstuttgart.parser.JavaClassName; -import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; -import de.dhbwstuttgart.syntaxtree.statement.Expr; -import de.dhbwstuttgart.syntaxtree.statement.Literal; -import de.dhbwstuttgart.syntaxtree.type.Type; -import de.dhbwstuttgart.typeinference.JavaCodeResult; -import de.dhbwstuttgart.typeinference.ResultSet; -import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; -import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; - -// ino.class.Constant.23212.description type=javadoc -/** - * Enthaelt die Eigenschaften einer Konstante (Name, Typ, Modifier, Wert) - * - * @author SCJU - * - */ -// ino.end - -// ino.class.Constant.23212.declaration -public class Constant extends Method -// ino.end -// ino.class.Constant.23212.body -{ - - // ino.attribute.name.23216.declaration - protected String name; // Name der Konstante - // ino.end - // ino.attribute.mod.23219.declaration - protected Modifiers mod = new Modifiers(); // Access-Flags - // ino.end - // ino.attribute.exp.23222.declaration - protected Expr exp; // Wert der Konstante - // ino.end - // ino.attribute.typ.23225.declaration - protected Type typ; // Typ der Konstante - // ino.end - - // ino.method.Constant.23228.definition - @Deprecated - public Constant(String name, Modifiers mod) - // ino.end - // ino.method.Constant.23228.body - { - super(0); //Nur ein Workaraound. Da Constant = Deprecated - this.name = name; - this.mod = mod; - } - // ino.end - - // ino.method.getValue.23231.defdescription type=javadoc - /** - * Gibt den Wert der Konstantendefinition zurueck. - */ - // ino.end - // ino.method.getValue.23231.definition - public Expr getValue() - // ino.end - // ino.method.getValue.23231.body - { - return exp; - } - // ino.end - - // ino.method.setValue.23234.defdescription type=javadoc - /** - * Legt den Wert der Konstantendefinition fest. - */ - // ino.end - // ino.method.setValue.23234.definition - public void setValue(Expr exp) - // ino.end - // ino.method.setValue.23234.body - { - this.exp = exp; - } - // ino.end - - // ino.method.getType.23237.defdescription type=javadoc - /** - * Gibt den Typ der Konstantendefinition zurueck. - */ - // ino.end - // ino.method.getType.23237.definition - public Type getType() - // ino.end - // ino.method.getType.23237.body - { - return typ; - } - // ino.end - - // ino.method.setType.23240.defdescription type=javadoc - /** - * Legt den Typ der Konstantendefinition fest - */ - // ino.end - // ino.method.setType.23240.definition - public void setType(Type typ) - // ino.end - // ino.method.setType.23240.body - { - this.typ = typ; - } - // ino.end - - // ino.method.getTypeName.23243.definition - public JavaClassName getTypeName() - // ino.end - // ino.method.getTypeName.23243.body - { - return new JavaClassName(name); - } - // ino.end - - // ino.method.getName.23246.definition - public String getIdentifier() - // ino.end - // ino.method.getName.23246.body - { - return name; - } - // ino.end - // ino.method.setName.23249.definition - public void setName(String name) - // ino.end - // ino.method.setName.23249.body - { - this.name = name; - } - // ino.end - - // ino.method.getModifiers.23252.definition - public Modifiers getModifiers() - // ino.end - // ino.method.getModifiers.23252.body - { - return mod; - } - // ino.end - - // ino.method.setModifiers.23255.definition - public void setModifiers(Modifiers modifiers) - // ino.end - // ino.method.setModifiers.23255.body - { - this.mod = modifiers; - } - // ino.end - - - // ino.method.getOffset.23261.definition - public int getOffset() - // ino.end - // ino.method.getOffset.23261.body - { - if(declid.size()<=0) - return MyCompiler.NO_LINENUMBER; - else{ - return declid.elementAt(0).getOffset(); - } - } - // ino.end - - // ino.method.getLineNumber.23264.definition - public int getLineNumber() - // ino.end - // ino.method.getLineNumber.23264.body - { - if(declid.size()<=0) - return MyCompiler.NO_LINENUMBER; - else{ - return declid.elementAt(0).getLineNumber(); - } - } - // ino.end - - @Override - public JavaCodeResult printJavaCode(ResultSet resultSet) { - throw new NotImplementedException(); - } - - @Override - public TypeAssumptions createTypeAssumptions(Class classmember) { - throw new NotImplementedException(); - //return null; - } - - - @Override - public int getTypeLineNumber() { - // TODO Auto-generated method stub - return 0; - } - -} -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java index cf82752c..93fae31e 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -15,7 +15,6 @@ import de.dhbwstuttgart.bytecode.DHBWConstantPoolGen; import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.bytecode.MethodGenerator; import de.dhbwstuttgart.parser.JavaClassName; -import de.dhbwstuttgart.syntaxtree.misc.DeclId; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Return; @@ -65,7 +64,7 @@ public class Constructor extends Method { InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen Class parentClass = this.getParentClass(); - MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, null), this.parameterlist.getBytecodeTypeList(cg,null) , this.parameterlist.getParameterNameArray(), "", parentClass.name, il, _cp); + MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, null), this.parameterlist.getBytecodeTypeList(cg,null) , this.parameterlist.getParameterNameArray(), "", parentClass.name.getName(), il, _cp); //FieldInitializations an Block anfügen Block block = this.get_Block(); diff --git a/src/de/dhbwstuttgart/syntaxtree/misc/ConstructorCall.java b/src/de/dhbwstuttgart/syntaxtree/ConstructorCall.java similarity index 94% rename from src/de/dhbwstuttgart/syntaxtree/misc/ConstructorCall.java rename to src/de/dhbwstuttgart/syntaxtree/ConstructorCall.java index b772db27..12987c8f 100644 --- a/src/de/dhbwstuttgart/syntaxtree/misc/ConstructorCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/ConstructorCall.java @@ -1,6 +1,5 @@ -package de.dhbwstuttgart.syntaxtree.misc; +package de.dhbwstuttgart.syntaxtree; -import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.statement.ArgumentList; import de.dhbwstuttgart.syntaxtree.statement.MethodCall; import de.dhbwstuttgart.syntaxtree.statement.Receiver; diff --git a/src/de/dhbwstuttgart/syntaxtree/Field.java b/src/de/dhbwstuttgart/syntaxtree/Field.java index b377082e..ba05d5ca 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Field.java +++ b/src/de/dhbwstuttgart/syntaxtree/Field.java @@ -4,7 +4,6 @@ import org.apache.bcel.generic.ClassGen; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.bytecode.ClassGenerator; -import de.dhbwstuttgart.syntaxtree.misc.DeclId; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; @@ -21,9 +20,8 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; public abstract class Field extends GTVDeclarationContext implements TypeInsertable, Typeable, Generic, GenericTypeInsertable{ - protected Menge declid = new Menge(); // Menge, da 'int a, b, c, ...' auch eingeparst werden muss - - private Type typ; + private String name; + protected Type typ; private int offset; @@ -42,10 +40,6 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta return this.offset; } - @Override - public void setType(Type typ) { - this.typ = typ; - } @Override public Type getType() { return typ; @@ -63,33 +57,6 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta GenericDeclarationList getGenericDeclarationList(){ return this.genericParameters; } - - public void set_DeclId(DeclId did) - { - this.declid.addElement(did); - } - - - - public Menge get_Name() - { - return declid; - } - - public Menge getDeclIdMenge() - { - // otth: ganzer Vektor zur�ckgeben, um ihn zu kopieren (vgl. MyCompiler - Konstruktor in Methode umwandeln) - return declid; - } - - public void setDeclIdMenge( Menge vDeclId ) - { - // otth: kompletter Vektor setzen, um ihn zu kopieren (vgl. MyCompiler - Konstruktor in Methode umwandeln) - declid = vDeclId; - } - - - public abstract JavaCodeResult printJavaCode(ResultSet resultSet); @@ -103,7 +70,7 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta public abstract ConstraintsSet TYPE(TypeAssumptions publicAssumptions); public String getIdentifier() { - return this.get_Name().firstElement().get_Name(); + return name; } @Override @@ -117,22 +84,6 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta return new TypeInsertPoint(this, this, resultSet.getTypeEqualTo(tph), resultSet); } - /** - * Wird im Zuge des ParserPostProcessing aufgerufen. - * Der Parser kann den Unterschied zwischen einem RefType und einer GTV nicht erkennen. - * Diese Methode ersetzt die RefTypes gegebenenfalls durch eine GTV. - * @param paralist - */ - public void wandleRefTypeAttributes2GenericAttributes(Menge paralist){ - // Zuerst Returntype untersuchen - Type type=getType(); - Type pendantReturnType = null; - if(type instanceof RefType)pendantReturnType = ((RefType)type).findGenericType(paralist, new Menge());//GenericTypeVar pendantReturnType=ClassHelper.findGenericType(type, paralist,new Menge()); - if(pendantReturnType!=null){ //Wenn generisch, dann modifizieren - setType(pendantReturnType); - } - } - public boolean isPublic() { //TODO: momentan ist jedes Feld public! return true; diff --git a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java index fe48efcd..c66ed9ce 100644 --- a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java +++ b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java @@ -9,7 +9,6 @@ import org.apache.bcel.generic.ClassGen; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.bytecode.ClassGenerator; -import de.dhbwstuttgart.syntaxtree.misc.DeclId; import de.dhbwstuttgart.syntaxtree.statement.Expr; import de.dhbwstuttgart.syntaxtree.statement.This; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; @@ -35,6 +34,7 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; public class FieldDeclaration extends Field{ private Expr wert; + private String name; //private Type type; //private Menge parameter; @@ -44,8 +44,8 @@ public class FieldDeclaration extends Field{ */ public FieldDeclaration(String name, Type typ){ super(0);//Dieser Deklarator wird nicht vom Parser aufgerufen. Dadurch gibt es auch keinen Offset - this.setType(typ); - this.set_DeclId(new DeclId(name)); + this.typ = typ; + this.name = name; } public FieldDeclaration(int offset){ @@ -60,7 +60,7 @@ public class FieldDeclaration extends Field{ } public String getIdentifier(){ - return this.get_Name().elementAt(0).name; + return name; } @@ -97,12 +97,6 @@ public class FieldDeclaration extends Field{ return assumptions; } - @Override - public void parserPostProcessing(SyntaxTreeNode parent){ - super.parserPostProcessing(parent); - if(this.getType() == null)this.setType(TypePlaceholder.fresh(this)); - } - @Override public Menge getChildren() { Menge ret = super.getChildren(); @@ -112,8 +106,9 @@ public class FieldDeclaration extends Field{ public int getVariableLength() { - return declid.elementAt(0).get_Name().length(); + return name.length(); } + @Override public ConstraintsSet TYPE(TypeAssumptions publicAssumptions) { if(this.wert == null && (this.getType() == null || this.getType() instanceof TypePlaceholder)) @@ -128,24 +123,9 @@ public class FieldDeclaration extends Field{ for(GenericTypeVar gp : this.getGenericParameter()){ gp.TYPE(localAssumptions); } - /* - if(this.getType() instanceof GenericTypeVar){ - //Falls Typ ein GTV ist muss er syntaktisch kontrolliert werden... - GenericTypeVar gtv = (GenericTypeVar) this.getType(); - } - */ //TypeCheck, falls es sich um einen RefType handelt: - Type thisType = this.getType().TYPE(localAssumptions, this); - this.setType(thisType); - /* - if(this.getType()!=null && (this.getType() instanceof RefType)){ - Type replaceType = null; - replaceType = publicAssumptions.getTypeFor((RefType)this.getType()); - if(replaceType == null)throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this); - this.setType(replaceType); - } - */ + Type thisType = this.getType(); UndConstraint c1 = ConstraintsSet.createSingleConstraint(thisType, thisType); ret.add(c1); //Damit die TypVariable des Felds in den Constraints auftaucht @@ -157,12 +137,6 @@ public class FieldDeclaration extends Field{ } return ret; } - - @Override - public void wandleRefTypeAttributes2GenericAttributes(Menge paralist){ - super.wandleRefTypeAttributes2GenericAttributes(paralist); - if(this.getWert()!=null)this.getWert().wandleRefTypeAttributes2GenericAttributes(paralist, new Menge()); //FieldDeclaration hat keine Generischen Variablen, daher leere Liste übergeben - } /** * Das besondere bei genByteCode einer FieldDeclaration ist, dass ein InstructionList zurückgegeben wird. diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index 70ebd5c7..e22a5587 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -7,7 +7,6 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; -import de.dhbwstuttgart.syntaxtree.misc.DeclId; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.JavaCodeResult; @@ -25,23 +24,13 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns // ino.end // ino.class.FormalParameter.23391.body { - // ino.attribute.type.23395.declaration private Type type; - // ino.end - // ino.attribute.declid.23398.declaration - private DeclId declid; - // ino.end - // ino.attribute.inferencelog.23401.declaration + private String name; protected static Logger inferencelog = Logger.getLogger("inference"); - // ino.end - - public FormalParameter(DeclId name){ - this.set_DeclId(name); - } public FormalParameter(String name, Type type){ - this(new DeclId(name)); - this.setType(type); + this.name = name; + this.type = type; } @Override @@ -55,45 +44,11 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns } return true; } - - - // ino.method.setType.23404.defdescription type=javadoc - /** - *
Author: J�rg B�uerle - * @param t - */ - // ino.end - // ino.method.setType.23404.definition - public void setType(Type t) - // ino.end - // ino.method.setType.23404.body - { - this.type = t; - } - // ino.end - - - // ino.method.set_DeclId.23407.definition - public void set_DeclId(DeclId did) - // ino.end - // ino.method.set_DeclId.23407.body - { - if(did == null)throw new NullPointerException(); - this.declid = did; - } - // ino.end - - - - // ino.method.get_Name.23410.definition public String getIdentifier() - // ino.end - // ino.method.get_Name.23410.body { - return declid.get_Name(); + return name; } - // ino.end @@ -129,38 +84,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns // ino.end // ino.method.getOffset.23422.body { - return declid.getOffset(); - } - // ino.end - - // ino.method.getLineNumber.23425.defdescription type=javadoc - /** - *
Author: J�rg B�uerle - * @return - */ - // ino.end - // ino.method.getLineNumber.23425.definition - public int getLineNumber() - // ino.end - // ino.method.getLineNumber.23425.body - { - return declid.getLineNumber(); - } - // ino.end - - - // ino.method.getTypeLineNumber.23431.defdescription type=javadoc - /** - *
Author: J�rg B�uerle - * @return - */ - // ino.end - // ino.method.getTypeLineNumber.23431.definition - public int getTypeLineNumber() - // ino.end - // ino.method.getTypeLineNumber.23431.body - { - return this.getLineNumber(); + return position.getOffset(); } // ino.end @@ -232,11 +156,6 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns return ret; } - - public DeclId getDeclId() { - return this.declid; - } - @Override public String getDescription(){ String ret = ""; diff --git a/src/de/dhbwstuttgart/syntaxtree/GTVDeclarationContext.java b/src/de/dhbwstuttgart/syntaxtree/GTVDeclarationContext.java index a39c9e68..96e1e2ff 100644 --- a/src/de/dhbwstuttgart/syntaxtree/GTVDeclarationContext.java +++ b/src/de/dhbwstuttgart/syntaxtree/GTVDeclarationContext.java @@ -1,7 +1,5 @@ package de.dhbwstuttgart.syntaxtree; -import de.dhbwstuttgart.typeinference.Menge; - /** * Beischreibt eine SyntaxTreeNode, welcher die Eigenschaft besitzt, * dass bei seiner Deklaration auch Generische Typvariablen deklariert wurden. diff --git a/src/de/dhbwstuttgart/syntaxtree/ImportDeclarations.java b/src/de/dhbwstuttgart/syntaxtree/ImportDeclarations.java deleted file mode 100755 index 28bc26da..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/ImportDeclarations.java +++ /dev/null @@ -1,31 +0,0 @@ -// ino.module.ImportDeclarations.8562.package -package de.dhbwstuttgart.syntaxtree; -// ino.end - -// ino.module.ImportDeclarations.8562.import -import de.dhbwstuttgart.typeinference.Menge; -// ino.end - -import de.dhbwstuttgart.syntaxtree.misc.UsedId; - - -// ino.class.ImportDeclarations.23434.description type=javadoc -/** - * HOTI 4.5.06 - * Auch wenn es nicht so aussieht, hat diese Klasse einen Sinn :-) - * Der Parser kann keine Generischen Typen darstellen, damit trotzdem - * an amap Stellen die Typsicherheit gewährleistet ist, hier eine Kapselung... - */ -// ino.end -// ino.class.ImportDeclarations.23434.declaration -public class ImportDeclarations extends Menge -// ino.end -// ino.class.ImportDeclarations.23434.body -{ - - // ino.attribute.serialVersionUID.23438.declaration - private static final long serialVersionUID = -8958366609867768133L; - // ino.end - -} -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/Interface.java b/src/de/dhbwstuttgart/syntaxtree/Interface.java deleted file mode 100755 index 660571d5..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/Interface.java +++ /dev/null @@ -1,259 +0,0 @@ -// ino.module.Interface.8582.package -package de.dhbwstuttgart.syntaxtree; -// ino.end - -// ino.module.Interface.8582.import -import de.dhbwstuttgart.typeinference.Menge; -import de.dhbwstuttgart.core.AClassOrInterface; -import de.dhbwstuttgart.syntaxtree.misc.UsedId; -import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; -import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; -import de.dhbwstuttgart.syntaxtree.type.RefType; -import de.dhbwstuttgart.syntaxtree.type.Type; -import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; - -/** - * Ein Interface ist eine abstrakte Klasse, erbt daher von Class - * @author janulrich - * - */ -public class Interface extends Class { - - public Interface(String name, int offset){ - super(name, offset); - } - - public Interface(String name, Modifiers modifiers, int offset) { - super(name,modifiers, offset); - } - - public Menge getParaList() { - // TODO Auto-generated method stub - return null; - } - - public void setInterfaceBody(InterfaceBody interfaceBody) { - // TODO Auto-generated method stub - - } - - public void setParaList(Menge paraMenge) { - // TODO Auto-generated method stub - - } - - @Override - public boolean isInterface(){ - return true; - } - -} - -// ino.class.Interface.23932.description type=javadoc -/** - * Die Klasse stellt die Definition eines Interfaces dar. - * @author SCJU - * - */ -/* -// ino.end -// ino.class.Interface.23932.declaration -public class Interface implements AClassOrInterface -// ino.end -// ino.class.Interface.23932.body -{ - - // ino.attribute.ib.23936.declaration - private InterfaceBody ib; - // ino.end - - // ino.attribute.paralist.23939.decldescription type=line - // HOTI 29. Apr 06 - // ino.end - // ino.attribute.paralist.23939.declaration - private Menge paralist = new Menge(); // Parameterliste 'interface xy{}' wird gespeichert - // ino.end - - // ino.attribute.containedTypes.23942.declaration - private Menge containedTypes; - // ino.end - - // ino.method.Interface.23945.defdescription type=line - // Konstruktoren - // ino.end - // ino.method.Interface.23945.definition - public Interface() - // ino.end - // ino.method.Interface.23945.body - { - super(); - } - // ino.end - - // ino.method.Interface.23948.definition - public Interface(String name) - // ino.end - // ino.method.Interface.23948.body - { - super(name); - } - // ino.end - - // ino.method.Interface.23951.definition - public Interface(String name, Modifiers mod) - // ino.end - // ino.method.Interface.23951.body - { - super(name, mod); - } - // ino.end - - - - - - // ino.method.getParaList.23954.definition - public Menge getParaList() - // ino.end - // ino.method.getParaList.23954.body - { - return this.paralist; - } - // ino.end - // ino.method.setParaList.23957.definition - public void setParaList(Menge paralist) - // ino.end - // ino.method.setParaList.23957.body - { - this.paralist=paralist; - } - // ino.end - // ino.method.setContainedTypes.23960.definition - public void setContainedTypes(Menge containedTypes) - // ino.end - // ino.method.setContainedTypes.23960.body - { - this.containedTypes = containedTypes; - } - // ino.end - - // ino.method.getContainedTypes.23963.definition - public Menge getContainedTypes() - // ino.end - // ino.method.getContainedTypes.23963.body - { - return containedTypes; - } - // ino.end - - // ino.method.codegen.23966.definition - public void codegen(SourceFile sf) - throws JVMCodeException - // ino.end - // ino.method.codegen.23966.body - { - codegenlog.info("Definierte Superinterfaces: " + getSuperInterfaces().size()); - codegenlog.debug("Liste der Interfaces: " + getSuperInterfaces().toString()); - codegenlog.info("Definierte Konstanten: " + ib.getConstantVektor().size()); - codegenlog.info("Definierte Methoden: " + ib.getMethodVektor().size()); - - // Erzeugen einer Classfile auf Basis des Interfaces - ClassFile classfile = new ClassFile(this, sf); - - // Handling fuer Generics - classfile.addGenerics(paralist, null, getSuperInterfaces()); - - // Handling fuer Superinterfaces - classfile.addSuperInterfaces(getSuperInterfaces()); - - // Codegen fuer Interface-Body - Menge paralist = new Menge(); - if(ib != null) ib.codegen(classfile, paralist); - - classfile.codegen(); - - codegenlog.info("Compilierung erfolgreich abgeschlossen, "+ getName() + ".class erstellt."); - } - // ino.end - - // ino.method.getInterfaceBody.23969.definition - public InterfaceBody getInterfaceBody() - // ino.end - // ino.method.getInterfaceBody.23969.body - { - return ib; - } - // ino.end - - // ino.method.setInterfaceBody.23972.definition - public void setInterfaceBody(InterfaceBody ib) - // ino.end - // ino.method.setInterfaceBody.23972.body - { - this.ib = ib; - } - // ino.end - - - // ino.end - // ino.method.isAGenericType.23978.definition - public boolean isAGenericType(RefType type) - // ino.end - // ino.method.isAGenericType.23978.body - { - if(paralist==null) - return false; - - for(int i=0;i methods=ib.MethodVektor; - - // Alle Methoden durchgehen - for(int i=0;i ConstantVektor = new Menge(); - // ino.end - // ino.attribute.MethodVektor.23990.declaration - protected Menge MethodVektor = new Menge(); - // ino.end - - // ino.method.InterfaceBody.23993.defdescription type=line - // Konstruktoren - // ino.end - // ino.method.InterfaceBody.23993.definition - public InterfaceBody() - // ino.end - // ino.method.InterfaceBody.23993.body - { - - } - // ino.end - - // ino.method.addElement.23996.defdescription type=javadoc - /** - * Fuegt ein neues Element (Konstantendefinition oder abstrakte - * Methode) ein. - */ - // ino.end - // ino.method.addElement.23996.definition - public void addElement(Field fd) - // ino.end - // ino.method.addElement.23996.body - { - if (fd instanceof Constant) { - ConstantVektor.addElement((Constant) fd); - } else if (fd instanceof Method) { - MethodVektor.addElement((Method) fd); - } - - } - // ino.end - - // ino.method.getConstantVektor.23999.definition - public Menge getConstantVektor() - // ino.end - // ino.method.getConstantVektor.23999.body - { - return ConstantVektor; - } - // ino.end - - // ino.method.setConstantVektor.24002.definition - public void setConstantVektor(Menge constantVektor) - // ino.end - // ino.method.setConstantVektor.24002.body - { - ConstantVektor = constantVektor; - } - // ino.end - - // ino.method.getMethodVektor.24005.definition - public Menge getMethodVektor() - // ino.end - // ino.method.getMethodVektor.24005.body - { - return MethodVektor; - } - // ino.end - - // ino.method.setMethodVektor.24008.definition - public void setMethodVektor(Menge methodVektor) - // ino.end - // ino.method.setMethodVektor.24008.body - { - MethodVektor = methodVektor; - } - // ino.end - - -} -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index d4f269a8..cd2ecc42 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -29,10 +29,10 @@ import de.dhbwstuttgart.bytecode.MethodGenerator; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.parser.JavaClassName; -import de.dhbwstuttgart.syntaxtree.misc.DeclId; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; import de.dhbwstuttgart.syntaxtree.modifier.Static; import de.dhbwstuttgart.syntaxtree.statement.Block; +import de.dhbwstuttgart.syntaxtree.statement.Expr; import de.dhbwstuttgart.syntaxtree.statement.Return; import de.dhbwstuttgart.syntaxtree.statement.Statement; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; @@ -66,6 +66,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable public ParameterList parameterlist = new ParameterList(); private ExceptionList exceptionlist; private Type returntype; + private String name; private int overloadedID; private boolean isAbstract = false; @@ -82,16 +83,11 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable public Method(String name, Type returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, int offset) { this(offset); - /* - * if(parameterList != null)parameterList.parserPostProcessing(this); - * if(block != null)block.parserPostProcessing(this); if(gtvDeclarations - * != null)gtvDeclarations.parserPostProcessing(this); - */ - this.set_Method_Name(name); - this.setParameterList(parameterList); - this.set_Block(block); + this.name = name; + this.parameterlist = parameterList; + this.block = block; this.setGenericParameter(gtvDeclarations); - this.setReturnType(returnType); + this.returntype = returnType; } public JavaClassName getTypeName() @@ -108,41 +104,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return block; } - - /** - *
- * Author: Jrg Buerle - * - * @param type - */ - private void setReturnType(Type type) - { - this.returntype = type; - } - - public void set_Block(Block blo) - { - if (blo.getType() == null) - blo.setType(this.returntype); - this.block = blo; - } - - public void set_Modifiers(Modifiers modif) - { - declid.firstElement().set_Modifiers(modif); - this.modifiers = modif; - } - - public void set_ExceptionList(ExceptionList exlist) - { - this.exceptionlist = exlist; - } - - public void setParameterList(ParameterList paralist) - { - this.parameterlist = paralist; - } - public ParameterList getParameterList() { return this.parameterlist; @@ -178,10 +139,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable this.overloadedID = overloadedID; } - public String get_Method_Name() + public String get_Name() { - DeclId hilf = declid.elementAt(0); - return hilf.get_Name(); + return name; } public Menge get_Type_Paralist() @@ -206,7 +166,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable public int getVariableLength() { - return get_Method_Name().length(); + return get_Name().length(); } public void setOffset(int Offset) @@ -253,16 +213,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return isAbstract; } - @Override - public void wandleRefTypeAttributes2GenericAttributes(Menge classParalist) { - } - - public void set_Method_Name(String string) { - if (declid.size() == 0) - declid.add(0, new DeclId(string)); - declid.set(0, new DeclId(string)); - } - public ConstraintsSet TYPE(TypeAssumptions ass) { ConstraintsSet ret = new ConstraintsSet(); TypeAssumptions localAss = new TypeAssumptions(); @@ -280,8 +230,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable // Die Parameter zu den Assumptions hinzufügen: if (this.parameterlist != null) for (FormalParameter param : this.parameterlist) { - - param.setType(param.getType().checkTYPE(localAss, this)); localAss.addAssumption(new ParameterAssumption(param)); } ret.add(this.block.TYPEStmt(localAss)); @@ -308,7 +256,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable public JavaCodeResult printJavaCode(ResultSet resultSet) { JavaCodeResult ret = new JavaCodeResult(); ret.attach(this.getType().printJavaCode(resultSet)).attach(" ") - .attach(this.get_Method_Name()).attach("(") + .attach(this.get_Name()).attach("(") .attach(this.getParameterList().printJavaCode(resultSet)) .attach(")\n"); ret.attach(this.block.printJavaCode(resultSet)); @@ -327,15 +275,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return ret; } - @Override - public void parserPostProcessing(SyntaxTreeNode parent) { - if (this.getType() == null) - this.setType(TypePlaceholder.fresh(this)); - if (this.returntype == null) - this.returntype = TypePlaceholder.fresh(this); - super.parserPostProcessing(parent); - } - @Override public Menge getChildren() { Menge ret = new Menge(); @@ -346,15 +285,6 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return ret; } - @Override - public void setType(Type t) { - // Methode und Block teilen sich einen ReturnType: - // this.block.setType(t); - this.returntype = t; - this.returntype.parent = this; // TODO: Dieser Hack sollte nicht - // nötig sein. (Parser ändern) - } - /** * Der Typ einer Methode ist ihr Returntype */ @@ -369,6 +299,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return ret; } public static Method createEmptyMethod(String withSignature, Class parent) { + Block block = new Block(new List()); + Method ret = new Method(withSignature, new de.dhbwstuttgart.syntaxtree.type.Void(0), new ParameterList(), block, new EmptyGenericDeclarationList(), 0); Method ret = new Method(0); DeclId DImethod = new DeclId(); DImethod.set_Name(withSignature); @@ -396,16 +328,16 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return super.equals(obj); } - public void genByteCode(ClassGenerator cg, Class classObj) { + public void genByteCode(ClassGenerator cg, Class classObj, Class parentClass) { List typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg); DHBWInstructionFactory _factory = cg.getInstructionFactory(); for(TypeinferenceResultSet t: typeInterferenceResults){ - addMethodToClassGenerator(cg, _factory, t); + addMethodToClassGenerator(cg, _factory, t, parentClass); } } - private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { + private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t, Class parentClass) { DHBWConstantPoolGen _cp = cg.getConstantPool(); InstructionList il = new InstructionList(); @@ -421,7 +353,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable Type returnType = this.getType(); - MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes.toArray(new org.apache.bcel.generic.Type[parameterlist.size()]) , argumentNames.toArray(new String[parameterlist.size()]), this.get_Method_Name(), getParentClass().name, il, _cp); + MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), + argumentTypes.toArray(new org.apache.bcel.generic.Type[parameterlist.size()]) + , argumentNames.toArray(new String[parameterlist.size()]), this.get_Name(), parentClass.name.toString(), il, _cp); cg.setMethodeGenerator(method); diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 175639d7..6e887011 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -21,12 +21,9 @@ import java.util.stream.Stream; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.Section; -import de.dhbwstuttgart.core.AClassOrInterface; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; -import de.dhbwstuttgart.syntaxtree.misc.DeclId; -import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; import de.dhbwstuttgart.syntaxtree.modifier.Public; import de.dhbwstuttgart.syntaxtree.type.FunN; @@ -105,28 +102,12 @@ public class SourceFile */ private static final boolean READ_IMPORTED_SUPERCLASSES_FROM_JRE = false; - // ino.attribute.codegenlog.21367.decldescription type=line - // Logger fuer Code-Gen - // ino.end - // ino.attribute.codegenlog.21367.declaration protected static Logger codegenlog = Logger.getLogger("codegen"); - // ino.end - // ino.attribute.inferencelog.21370.declaration protected static Logger inferencelog = Logger.getLogger("inference"); - // ino.end - // ino.attribute.pkgName.21373.declaration - private UsedId pkgName; - // ino.end + private String pkgName; - // ino.attribute.KlassenVektor.21376.declaration public Menge KlassenVektor = new Menge(); - // ino.end - - // ino.attribute.InterfaceVektor.21379.declaration - public Menge InterfaceVektor = new Menge(); - // ino.end - /** * Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei. @@ -144,22 +125,21 @@ public class SourceFile baseTypeTranslationTable.put("float","java.lang.Float"); //baseTypeTranslationTable.put("this.is.a.temporary.entry","de.dhbwstuttgart.typeinference.Menge"); auskommentiert PL 07-08-11 + //this.imports=new ImportDeclarations(); - this.imports=new ImportDeclarations(); - - this.imports.add(UsedId.createFromQualifiedName("java.lang.Integer",-1)); - this.imports.add(UsedId.createFromQualifiedName("java.lang.String",-1)); - this.imports.add(UsedId.createFromQualifiedName("java.lang.Character",-1)); - this.imports.add(UsedId.createFromQualifiedName("java.lang.Boolean",-1)); - this.imports.add(UsedId.createFromQualifiedName("java.lang.Double",-1)); - this.imports.add(UsedId.createFromQualifiedName("java.lang.Float",-1)); - this.imports.add(UsedId.createFromQualifiedName("java.lang.Long",-1)); + this.imports.add(new JavaClassName("java.lang.Integer")); + this.imports.add(new JavaClassName("java.lang.String")); + this.imports.add(new JavaClassName("java.lang.Character")); + this.imports.add(new JavaClassName("java.lang.Boolean")); + this.imports.add(new JavaClassName("java.lang.Double")); + this.imports.add(new JavaClassName("java.lang.Float")); + this.imports.add(new JavaClassName("java.lang.Long")); //this.imports.add(UsedId.createFromQualifiedName("java.lang.Byte")); // HOTI 4.5.06 Wenn die Klassen immer als "Daddy" Object haben, // muss das der JCC auch kennen if(READ_OBJECT_SUPERCLASSES_FROM_JRE){ - this.imports.add(UsedId.createFromQualifiedName("java.lang.Object",-1)); + this.imports.add(new JavaClassName("java.lang.Object")); } } @@ -172,7 +152,7 @@ public class SourceFile * Beinhaltet alle Imports des aktuell geparsten Files * in Form einer UsedId */ - private ImportDeclarations imports=new ImportDeclarations(); + private List imports; /** * Table zum Übersetzen der nicht implementierten Base-Types: @@ -184,19 +164,6 @@ public class SourceFile */ private Hashtable baseTypeTranslationTable; - /** - * Fuegt ein neues Element (Interface oder Klasse) hinzu. - * @param c - */ - public void addElement(AClassOrInterface e) - { - if (e instanceof Class) { - KlassenVektor.addElement((Class) e); - } else if (e instanceof Interface) { - InterfaceVektor.addElement((Interface) e); - } - } - /** * PL 2014-10-25 * schnitt1 checkt ob die Typeplaceholders aus in den Elemeneten aus vars enthalten sind @@ -458,14 +425,15 @@ public class SourceFile * @param imports * @param withSuptypes - Gibt an, ob auch die subklassen der Packages den Assumptions angefügt werden sollen. * @return + * TODO: Diese Methode neu erstellen */ - public TypeAssumptions makeBasicAssumptionsFromJRE(Menge imports, boolean withSubtypes) + public TypeAssumptions makeBasicAssumptionsFromJRE(List imports, boolean withSubtypes) // ino.end // ino.method.makeBasicAssumptionsFromJRE.21409.body { //return null; ///* - Menge doneImports=new Menge(); + List doneImports=new Menge<>(); //TypeinferenceResultSet basicAssumptions = new TypeinferenceResultSet(null); TypeAssumptions basicAssumptions = new TypeAssumptions(); @@ -474,16 +442,16 @@ public class SourceFile mod.addModifier(new Public()); //Für Object: - imports.add(new UsedId("java.lang.Object",-1)); + imports.add(new JavaClassName("java.lang.Object")); // Für jede einzelne Klasse while (imports.size()>0) { - UsedId importDecl = imports.get(0); + JavaClassName importDecl = imports.get(0); // Properties laden java.lang.Class x; try { - x = java.lang.Class.forName(importDecl.getQualifiedName().toString()); + x = java.lang.Class.forName(importDecl.toString()); } catch (ClassNotFoundException e) { throw new TypeinferenceException("Fehlerhafte Import-Declaration: "+e.getMessage(),this); } @@ -496,7 +464,7 @@ public class SourceFile String className=x.getName(); //Ermittle die Superklasse: - Class sClass = new Class("Object",0); + //Class sClass = new Class("Object",0); if(withSubtypes)sClass = getSuperClassOfJREClass(x, basicAssumptions); // Namen von Generische Typen erzeugen @@ -508,7 +476,6 @@ public class SourceFile //jreSpiderRegistry.put(tvs[j].getName(),gtv); } - Class parentClass = new Class(className, sClass.getType(),mod, typeGenPara); //BasicAssumptionClass myCl = new BasicAssumptionClass(className, mod); @@ -539,7 +506,7 @@ public class SourceFile } //UsedId ui = new UsedId(); //ui.set_Name(x.getSuperclass().getSimpleName()); - UsedId ui=UsedId.createFromQualifiedName(x.getSuperclass().getName(),-1); + String ui= x.getSuperclass().getName(); java.lang.Class superClass=x.getSuperclass(); java.lang.reflect.TypeVariable[] superclassTVS=superClass.getTypeParameters(); Menge supertypeGenPara = new Menge(); @@ -551,8 +518,8 @@ public class SourceFile if(supertypeGenPara.size()==0){ supertypeGenPara=null; } - ui.set_ParaList(supertypeGenPara); - ui.vParaOrg=supertypeGenPara; + //ui.set_ParaList(supertypeGenPara); + //ui.vParaOrg=supertypeGenPara; parentClass.set_UsedId(ui); } } @@ -621,6 +588,8 @@ public class SourceFile } } + Class parentClass = new Class(className, sClass.getType(),mod, typeGenPara); + basicAssumptions.add(parentClass.getPublicFieldAssumptions()); basicAssumptions.addClassAssumption(new ClassAssumption(parentClass)); imports.removeElement(importDecl); @@ -982,25 +951,10 @@ public class SourceFile } // ino.end - // ino.method.addImports.21433.definition - public void addImports(ImportDeclarations imports) - // ino.end - // ino.method.addImports.21433.body - { - this.imports.addAll(imports); - } - // ino.end - // ino.method.getImports.21436.definition public ImportDeclarations getImports() - // ino.end - // ino.method.getImports.21436.body { - if(imports==null){ - return(new ImportDeclarations()); - } return(imports); } - // ino.end // ino.method.getClassIterator.21439.definition diff --git a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java index b240168c..4dbf3885 100644 --- a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java +++ b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java @@ -21,7 +21,8 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; public abstract class SyntaxTreeNode implements IItemWithOffset{ protected SyntaxTreeNode parent; - + protected SourceCodePosition position; + /** * Wird nach dem Parsen aufgerufen. * Erfüllt folgenden Aufgaben: @@ -45,6 +46,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{ public abstract Menge getChildren(); + /* public Class getParentClass(){ SyntaxTreeNode parent = this.getParent(); if(parent instanceof Class)return (Class)parent; @@ -52,7 +54,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{ throw new DebugException("Das Wurzelelement eines Syntaxbaumes muss Class sein"); return parent.getParentClass(); } - + */ /** * Eine Beschreibung/Name des SyntaxTree-Nodes * Hat nichts mit der Description im Bytecode zu tun, diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index c02ed64f..3f063013 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -1,17 +1,26 @@ package de.dhbwstuttgart.syntaxtree.factory; +import java.lang.reflect.TypeVariable; +import java.util.ArrayList; +import java.util.List; + +import javax.lang.model.element.Modifier; + import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.Constructor; +import de.dhbwstuttgart.syntaxtree.Field; +import de.dhbwstuttgart.syntaxtree.GenericDeclarationList; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; -import de.dhbwstuttgart.syntaxtree.misc.DeclId; -import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; +import de.dhbwstuttgart.syntaxtree.modifier.Public; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.SuperCall; +import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.Menge; @@ -22,15 +31,6 @@ public class ASTFactory { public static Method createMethod(String name, ParameterList paralist, Block block, Class parent) { - Method method = new Method(0); - DeclId DImethod = new DeclId(); - DImethod.set_Name(name); - method.set_DeclId(DImethod); - method.set_Block(block); - method.setParameterList(paralist); - - block.parserPostProcessing(method); - method.parserPostProcessing(parent); return method; } @@ -66,9 +66,48 @@ public class ASTFactory { return generatedClass; } - public static Class createObjectClass() { - Class generatedClass = new Class("java.lang.Object", 0); - - return generatedClass; + public static Class createObject(){ + return createClass(java.lang.Object.class); + } + + public static Class createClass(java.lang.Class jreClass){ + JavaClassName name = new JavaClassName(jreClass.getName()); + List methoden = new ArrayList<>(); + for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){ + + } + for(java.lang.reflect.Method method : jreClass.getMethods()){ + methoden.add(createMethod(method)); + } + List felder = new ArrayList<>(); + Modifiers modifier = new Modifiers(); + modifier.addModifier(new Public()); + boolean isInterface = jreClass.isInterface(); + java.lang.Class superjreClass = jreClass.getSuperclass(); + RefType superClass; + if(superjreClass != null){ + superjreClass.getName() + }else{//Jede Klasse und jedes Interface erbt von Object: + superClass = createType(java.lang.Object.class); + } + List implementedInterfaces = new ArrayList<>(); + int offset = 0; //Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde + return new Class(name, methoden, felder, modifier, isInterface, superClass, implementedInterfaces, offset); + } + + public static Method createMethod(java.lang.reflect.Method jreMethod){ + String name = jreMethod.getName(); + Type returnType = createType(jreMethod.getReturnType()); + , ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, int offset + return new Method(); + } + + public static RefType createType(java.lang.Class jreClass){ + jreClass.getTypeParameters(); + return new RefType(jreClass.getName(), -1); + } + + public static GenericTypeVar createGeneric(TypeVariable jreTypeVar){ + return new GenericTypeVar(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/misc/DeclId.java b/src/de/dhbwstuttgart/syntaxtree/misc/DeclId.java deleted file mode 100755 index 00ecffc0..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/misc/DeclId.java +++ /dev/null @@ -1,227 +0,0 @@ -// ino.module.DeclId.8558.package -package de.dhbwstuttgart.syntaxtree.misc; -// ino.end -// ino.module.DeclId.8558.import -import de.dhbwstuttgart.typeinference.Menge; - -import de.dhbwstuttgart.logger.Logger; -// ino.end - -import de.dhbwstuttgart.core.MyCompiler; -import de.dhbwstuttgart.syntaxtree.Constant; -import de.dhbwstuttgart.syntaxtree.modifier.Final; -import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; -import de.dhbwstuttgart.syntaxtree.statement.Assign; -import de.dhbwstuttgart.syntaxtree.statement.Expr; -import de.dhbwstuttgart.syntaxtree.statement.ExprStmt; -import de.dhbwstuttgart.syntaxtree.statement.InstVar; -import de.dhbwstuttgart.syntaxtree.statement.LocalOrFieldVarOrClassname; -import de.dhbwstuttgart.syntaxtree.type.RefType; -import de.dhbwstuttgart.syntaxtree.type.Type; - - - - -// ino.class.DeclId.23280.declaration -public class DeclId -// ino.end -// ino.class.DeclId.23280.body -{ - // ino.attribute.modifiers.23283.declaration - public Modifiers modifiers; - // ino.end - // ino.attribute.name.23286.declaration - public String name; - // ino.end - // ino.attribute.wert.23289.declaration - private ExprStmt wert; - // ino.end - // ino.attribute.paratyp.23292.declaration - public Menge paratyp = null; // hier wird die Parameterzuordnung gespeichert ... 'test t = new test();' - // ino.end - // ino.attribute.m_LineNumber.23295.declaration - private int m_LineNumber = MyCompiler.NO_LINENUMBER; - // ino.end - private int m_Offset = -1; //hinzugef�gt hoth: 07.04.2006 - // ino.attribute.codegenlog.23298.decldescription type=line - // Logger fuer Code-Gen - // ino.end - // ino.attribute.codegenlog.23298.declaration - protected static Logger codegenlog = Logger.getLogger("codegen"); - // ino.end - - // ino.method.DeclId.23301.definition - public DeclId() - // ino.end - // ino.method.DeclId.23301.body - { - - } - // ino.end - - - - // ino.method.DeclId.23304.definition - public DeclId(String name) - // ino.end - // ino.method.DeclId.23304.body - { - this.name = name; - } - // ino.end - - // ino.method.set_Paratyp.23307.definition - public void set_Paratyp(Menge p) - // ino.end - // ino.method.set_Paratyp.23307.body - { - this.paratyp = p; - } - // ino.end - - // ino.method.get_Paratyp.23310.definition - public Menge get_Paratyp() - // ino.end - // ino.method.get_Paratyp.23310.body - { - return this.paratyp; - } - // ino.end - - // ino.method.set_Name.23313.definition - public void set_Name(String name) - // ino.end - // ino.method.set_Name.23313.body - { - this.name = name; - } - // ino.end - - // ino.method.set_Wert.23316.definition - public void set_Wert(ExprStmt w) - // ino.end - // ino.method.set_Wert.23316.body - { - this.wert = w; - } - // ino.end - - // ino.method.get_Name.23319.definition - public String get_Name() - // ino.end - // ino.method.get_Name.23319.body - { - return name; - } - // ino.end - - // ino.method.get_Wert.23322.definition - public ExprStmt get_Wert() - // ino.end - // ino.method.get_Wert.23322.body - { - return wert; - } - // ino.end - - // ino.method.set_Modifiers.23325.definition - public void set_Modifiers(Modifiers mod) - // ino.end - // ino.method.set_Modifiers.23325.body - { - this.modifiers = mod; - } - // ino.end - - // ino.method.get_Modifiers.23328.definition - public Modifiers get_Modifiers() - // ino.end - // ino.method.get_Modifiers.23328.body - { - return this.modifiers; - } - // ino.end - - // ino.method.get_access_flags.23331.definition - public short get_access_flags() - // ino.end - // ino.method.get_access_flags.23331.body - { - if(modifiers != null) return modifiers.calculate_access_flags(); - else return (short)0; - } - // ino.end - - - - // ino.method.set_ListType.23334.definition - public void set_ListType(Type t) - // ino.end - // ino.method.set_ListType.23334.body - { - //System.out.println("In Klasse DeclID, Methode set_ListType passiert nix!"); - } - // ino.end - - - - - // ino.method.getLineNumber.23343.definition - public int getLineNumber() - // ino.end - // ino.method.getLineNumber.23343.body - { - return m_LineNumber; - } - // ino.end - - // ino.method.setLineNumber.23346.definition - public void setLineNumber(int lineNumber) - // ino.end - // ino.method.setLineNumber.23346.body - { - m_LineNumber = lineNumber; - } - // ino.end - - // ino.method.getOffset.23349.defdescription type=line - // hinzugef�gt hoth: 07.04.2006 - // ino.end - // ino.method.getOffset.23349.definition - public int getOffset() - // ino.end - // ino.method.getOffset.23349.body - { - return m_Offset; - } - // ino.end - - // ino.method.setOffset.23352.defdescription type=line - // hinzugef�gt hoth: 07.04.2006 - // ino.end - // ino.method.setOffset.23352.definition - public void setOffset(int Offset) - // ino.end - // ino.method.setOffset.23352.body - { - m_Offset = Offset; - } - // ino.end - - // ino.method.toString.23355.defdescription type=javadoc - /** - *
Author: Martin Pl�micke - * @return - */ - // ino.end - // ino.method.toString.23355.definition - public String toString() - // ino.end - // ino.method.toString.23355.body - { - return name.toString(); - } - // ino.end - -} -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/misc/Status.java b/src/de/dhbwstuttgart/syntaxtree/misc/Status.java deleted file mode 100755 index e68b7d32..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/misc/Status.java +++ /dev/null @@ -1,25 +0,0 @@ -// ino.module.Status.8566.package -package de.dhbwstuttgart.syntaxtree.misc; -// ino.end - - -// ino.class.Status.23644.declaration -public abstract class Status -// ino.end -// ino.class.Status.23644.body -{ - // ino.attribute.userdef.23647.declaration - protected UserDef userdef; - // ino.end - - // ino.method.set_UserDef.23653.definition - public void set_UserDef( UserDef userdef) - // ino.end - // ino.method.set_UserDef.23653.body - { - this.userdef = userdef; - } - // ino.end - -} -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/misc/UsedId.java b/src/de/dhbwstuttgart/syntaxtree/misc/UsedId.java deleted file mode 100755 index 6ee71dee..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/misc/UsedId.java +++ /dev/null @@ -1,303 +0,0 @@ -// ino.module.UsedId.8567.package -package de.dhbwstuttgart.syntaxtree.misc; -// ino.end -// ino.module.UsedId.8567.import -import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; - -import de.dhbwstuttgart.core.IItemWithOffset; -import de.dhbwstuttgart.parser.JavaClassName; -import de.dhbwstuttgart.syntaxtree.type.Type; -import de.dhbwstuttgart.typeinference.JavaCodeResult; -import de.dhbwstuttgart.typeinference.ResultSet; -import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; - - -// ino.class.UsedId.23659.declaration -public class UsedId implements IItemWithOffset -// ino.end -// ino.class.UsedId.23659.body -{ - // ino.attribute.name.23663.declaration - public Menge name = new Menge(); // Menge mit Strings - // ino.end - // ino.attribute.typen.23666.declaration - private Menge typen = new Menge(); // Menge mit Typen - // ino.end - // ino.attribute.paralist.23669.declaration - private Menge paralist = null; - // ino.end - // ino.attribute.vParaOrg.23672.declaration - public Menge vParaOrg = null; // otth: originale Parameterliste - // ino.end - private int m_Offset = -1; //hinzugef�gt hoth: 07.04.2006 - - // ino.method.UsedId.23675.definition - public UsedId(int offset) - // ino.end - // ino.method.UsedId.23675.body - { - m_Offset=offset; - } - // ino.end - - public UsedId(String name, int offset) - { - this(offset); - this.set_Name(name); - } - - // ino.method.getOffset.23678.defdescription type=line - // hinzugef�gt hoth: 07.04.2006 - // ino.end - // ino.method.getOffset.23678.definition - public int getOffset() - // ino.end - // ino.method.getOffset.23678.body - { - return m_Offset; - } - // ino.end - - // ino.method.getVariableLength.23681.definition - public int getVariableLength() - // ino.end - // ino.method.getVariableLength.23681.body - { - return get_Name_1Element().length(); - } - // ino.end - - // ino.method.setOffset.23684.defdescription type=line - // hinzugef�gt hoth: 07.04.2006 - // ino.end - // ino.method.setOffset.23684.definition - public void setOffset(int Offset) - // ino.end - // ino.method.setOffset.23684.body - { - m_Offset = Offset; - } - // ino.end - - // ino.method.set_Name.23687.definition - public void set_Name( String name) - // ino.end - // ino.method.set_Name.23687.body - { - this.name.addElement(name); - } - // ino.end - - // ino.method.get_Name.23690.definition - public Menge get_Name() - // ino.end - // ino.method.get_Name.23690.body - { - return name; - } - // ino.end - - // ino.method.get_Name_1Element.23693.definition - public String get_Name_1Element() - // ino.end - // ino.method.get_Name_1Element.23693.body - { - return (String) name.elementAt(0); - } - // ino.end - - // ino.method.set_Typen.23696.definition - public void set_Typen(Menge t) - // ino.end - // ino.method.set_Typen.23696.body - { - typen=t; - } - // ino.end - - // ino.method.set_ParaList.23699.definition - public void set_ParaList(Menge pl) - // ino.end - // ino.method.set_ParaList.23699.body - { - this.paralist = pl; - } - // ino.end - - // ino.method.get_RealParaList.23702.definition - public Menge get_RealParaList() - // ino.end - // ino.method.get_RealParaList.23702.body - { - return this.paralist; - } - // ino.end - - // ino.method.get_ParaList.23705.definition - public Menge get_ParaList() - // ino.end - // ino.method.get_ParaList.23705.body - { - if(this.paralist != null) - return this.paralist; - else return new Menge(); - } - // ino.end - - // ino.method.get_vParaOrg.23708.definition - public Menge get_vParaOrg() - // ino.end - // ino.method.get_vParaOrg.23708.body - { - return this.vParaOrg; - } - // ino.end - - - // ino.method.get_Typen.23711.definition - public Menge get_Typen() - // ino.end - // ino.method.get_Typen.23711.body - { - return typen; - } - // ino.end - - // ino.method.get_codegen_UsedId.23714.definition - public String get_codegen_UsedId() - // ino.end - // ino.method.get_codegen_UsedId.23714.body - { - String name_string = new String(); - name_string += (String)name.elementAt(0); - for(int i = 1; i < name.size(); i++) - name_string += ("/" + (String)name.elementAt(i)); - return name_string; - } - // ino.end - - - - // ino.method.removeLast.23720.definition - public void removeLast() - // ino.end - // ino.method.removeLast.23720.body - { - name.removeElementAt(name.size()-1); - } - // ino.end - - // ino.method.toString.23723.defdescription type=javadoc - /** - *
Author: Martin Pl�micke - * @return - */ - // ino.end - // ino.method.toString.23723.definition - public String toString() - // ino.end - // ino.method.toString.23723.body - { - return this.get_Name_1Element();//name.toString(); //geändert von Andreas Stadelmeier - /*String s = ""; - for(int i = 0; i(); - for(int i=0;i0){ - return(name.elementAt(name.size()-1).equals("*")); - } - return(false); - } - // ino.end - - // ino.method.getPackageName.23735.definition - public UsedId getPackageName() - // ino.end - // ino.method.getPackageName.23735.body - { - UsedId uid=new UsedId(-1); - uid.name=new Menge(); - for(int i=0;i0) - return name.lastElement(); - else - return null; - } - // ino.end - - public JavaCodeResult printJavaCode(ResultSet resultSet) { - if(this.name.size()>1)throw new TypeinferenceException("Es kann maximal nur eine Superklasse pro Klasse geben", null); - JavaCodeResult ret = new JavaCodeResult(this.getQualifiedName().toString()); - if(this.paralist != null){ - ret.attach( "<" ); - Iterator it = this.paralist.iterator(); - while(it.hasNext()){ - Type para = it.next(); - ret.attach(para.printJavaCode(resultSet)); - if(it.hasNext())ret.attach(", "); - } - //ret = ret.substring(0, ret.length()-2); - ret.attach(">"); - } - return ret; - } - -} -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/misc/UserDef.java b/src/de/dhbwstuttgart/syntaxtree/misc/UserDef.java deleted file mode 100755 index 96085afe..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/misc/UserDef.java +++ /dev/null @@ -1,11 +0,0 @@ -// ino.module.UserDef.8568.package -package de.dhbwstuttgart.syntaxtree.misc; -// ino.end -// ino.class.UserDef.23741.declaration -public class UserDef extends Status -// ino.end -// ino.class.UserDef.23741.body -{ - -} -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/modifier/Modifiers.java b/src/de/dhbwstuttgart/syntaxtree/modifier/Modifiers.java index c61fd97b..92db05ed 100755 --- a/src/de/dhbwstuttgart/syntaxtree/modifier/Modifiers.java +++ b/src/de/dhbwstuttgart/syntaxtree/modifier/Modifiers.java @@ -15,13 +15,8 @@ import de.dhbwstuttgart.typeinference.ResultSet; * Die Klasse beinhaltet die Liste der Access-Modifier fuer eine Klasse, * Methode usw. */ -// ino.end -// ino.class.Modifiers.24035.declaration public class Modifiers -// ino.end -// ino.class.Modifiers.24035.body { - // ino.attribute.modifier.24038.declaration protected Menge modifier = new Menge(); // ino.end @@ -104,16 +99,11 @@ public class Modifiers modifier.addElement(new Public()); } - // ino.method.calculate_access_flags.24056.defdescription type=javadoc /** * Gibt den Bitmaskenwert fuer die enthaltenen Access-Modifier * zurueck. */ - // ino.end - // ino.method.calculate_access_flags.24056.definition public short calculate_access_flags() - // ino.end - // ino.method.calculate_access_flags.24056.body { short ret = 0; @@ -127,7 +117,6 @@ public class Modifiers } return ret; } - // ino.end public JavaCodeResult printJavaCode(ResultSet resultSet) { JavaCodeResult ret = new JavaCodeResult(); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java index 492c8003..d25a1876 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java @@ -5,6 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import java.util.List; import org.apache.bcel.Constants; import org.apache.bcel.generic.ClassGen; @@ -55,13 +56,16 @@ public class Block extends Statement // ino.end - // ino.attribute.parserlog.25044.declaration + public Block(List statements) { + this.statements = statements; + } + + + // ino.attribute.parserlog.25044.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end - // ino.attribute.statements.25047.declaration - public Menge statements = new Menge(); - // ino.end + public List statements = new Menge(); //private String sc_meth_ret_type; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java index eba80cc5..ba9c326a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java @@ -43,15 +43,11 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse protected Type type; - // ino.method.Statement.26194.definition - public Statement(int offset, int variableLength) - // ino.end - // ino.method.Statement.26194.body + public Statement(int offset) { this.offset=offset; - this.variableLength=variableLength; + //this.variableLength=variableLength; } - // ino.end // ino.method.getOffset.26197.definition public int getOffset() diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java index 18ac0fba..c9231d9f 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java @@ -15,8 +15,8 @@ import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.Constructor; +import de.dhbwstuttgart.syntaxtree.ConstructorCall; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; -import de.dhbwstuttgart.syntaxtree.misc.ConstructorCall; import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java index 2e2bc05f..40c4f3ea 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java @@ -8,8 +8,8 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.Constructor; +import de.dhbwstuttgart.syntaxtree.ConstructorCall; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; -import de.dhbwstuttgart.syntaxtree.misc.ConstructorCall; import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; diff --git a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java index 1dfef648..5278729d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java @@ -71,18 +71,15 @@ public class BoundedGenericTypeVar extends GenericTypeVar return this.endOffset; } - // ino.method.getBounds.26474.definition public Menge getBounds() - // ino.end - // ino.method.getBounds.26474.body { return bounds; } - // ino.end @Override - public ConstraintsSet TYPE(TypeAssumptions ass) { + //TODO: Die Constraints sollte nicht der TYPE Algorithmus generieren, sonder sollte der FC bekannt sein. + public ConstraintsSet TYPE(TypeAssumptions ass) { ConstraintsSet ret = super.TYPE(ass); //ass.addGenericVarAssumption(this); //Die Type methode der BoundedGenericTypeVar schreibt zusätzlich noch die Constraints für die bounds @@ -100,15 +97,6 @@ public class BoundedGenericTypeVar extends GenericTypeVar this.bounds = tempBounds; return ret; } - - // ino.method.addBound.26480.definition - public void addBound(ObjectType bound) - // ino.end - // ino.method.addBound.26480.body - { - bounds.addElement(bound); - } - // ino.end // ino.method.clone.26483.definition public BoundedGenericTypeVar clone() diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 27443bb4..b53a4018 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -19,7 +19,6 @@ import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; -import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.SuperCall; import de.dhbwstuttgart.typeinference.JavaCodeResult; @@ -79,7 +78,7 @@ public class RefType extends ObjectType implements IMatchable // ino.end // ino.method.RefType.26637.definition - public RefType(String fullyQualifiedName,SyntaxTreeNode parent, int offset) + public RefType(String fullyQualifiedName, int offset) // ino.end // ino.method.RefType.26637.body { diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Void.java b/src/de/dhbwstuttgart/syntaxtree/type/Void.java index 223d3f17..e6e19607 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Void.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Void.java @@ -17,11 +17,11 @@ public class Void extends RefType { public static final String VOID_NAME = "void"; // ino.method.Void.26861.definition - public Void(SyntaxTreeNode parent,int offset) + public Void(int offset) // ino.end // ino.method.Void.26861.body { - super(parent,offset); + super(offset); super.setName(VOID_NAME); } // ino.end diff --git a/src/de/dhbwstuttgart/typeinference/Typeable.java b/src/de/dhbwstuttgart/typeinference/Typeable.java index d0b276a9..ad305b01 100755 --- a/src/de/dhbwstuttgart/typeinference/Typeable.java +++ b/src/de/dhbwstuttgart/typeinference/Typeable.java @@ -6,10 +6,9 @@ public interface Typeable { /** * @author Andreas Stadelmeier, a10023 * Jede Expression und jedes Statement muss im Zuge des Typinferenzalgorithmus das Interfece Typable einbinden. - * Die Funktion setTypeVariable muss während des durchlaufens des Typinferenzalgorithmus einmalig für jedes Statement und jede Expression aufgerufen werden. - * Dabei kann auch eine FreshTypeVariable als Typ vergeben werden. + * Die Typen werden nur einmalig vom Parser gesetzt und können dann nur ausgelesen werden. + * Dadurch bleibt der Syntaxbaum immutable. * @param typ Der Typ der Typable-Expression/Statement */ - void setType(Type typ); Type getType(); }