Begeonnen mit Implementierung von getChildren()
This commit is contained in:
parent
e33b9fd76e
commit
282b068552
@ -17,7 +17,6 @@ import mycompiler.myclass.Class;
|
||||
import mycompiler.myclass.ClassBody;
|
||||
import mycompiler.myclass.Constructor_Backup;
|
||||
import mycompiler.myclass.DeclId;
|
||||
import mycompiler.myclass.FieldDecl;
|
||||
import mycompiler.myclass.FormalParameter;
|
||||
import mycompiler.myclass.ImportDeclarations;
|
||||
import mycompiler.myclass.Method;
|
||||
|
@ -1508,7 +1508,8 @@ public class SourceFile
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
if(parent!=null)throw new TypinferenzException("Eine SourceFile hat keine Elternelement im Syntaxbaum");
|
||||
for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
|
||||
super.parserPostProcessing(parent);
|
||||
//for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
|
||||
}
|
||||
|
||||
|
||||
@ -1521,7 +1522,7 @@ public class SourceFile
|
||||
|
||||
@Override
|
||||
public Vector<SyntaxTreeNode> getChildren() {
|
||||
Vector<SyntaxTreeNode> ret = super.getChildren();
|
||||
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
||||
for(Class cl : this.KlassenVektor){
|
||||
ret.add(cl);
|
||||
}
|
||||
|
@ -25,9 +25,7 @@ public abstract class SyntaxTreeNode {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public Vector<SyntaxTreeNode> getChildren(){
|
||||
return new Vector<SyntaxTreeNode>();
|
||||
}
|
||||
public abstract Vector<SyntaxTreeNode> getChildren();
|
||||
|
||||
public Class getParentClass(){
|
||||
SyntaxTreeNode parent = this.getParent();
|
||||
|
@ -1,95 +0,0 @@
|
||||
// ino.module.FieldDecl.8560.package
|
||||
package mycompiler.myclass;
|
||||
// ino.end
|
||||
// ino.module.FieldDecl.8560.import
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.Typeable;
|
||||
import typinferenz.TypeInsertable;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.myexception.JVMCodeException;
|
||||
// ino.end
|
||||
import mycompiler.mystatement.Expr;
|
||||
import mycompiler.mytypereconstruction.set.CTypeAssumptionSet;
|
||||
import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption;
|
||||
|
||||
@Deprecated
|
||||
// ino.class.FieldDecl.23367.declaration
|
||||
public abstract class FieldDecl implements TypeInsertable
|
||||
// ino.end
|
||||
// ino.class.FieldDecl.23367.body
|
||||
{
|
||||
// ino.attribute.declid.23370.declaration
|
||||
protected Vector<DeclId> declid = new Vector<DeclId>(); // Vector, da 'int a, b, c, ...' auch eingeparst werden muss
|
||||
|
||||
// ino.end
|
||||
// ino.method.getTypeName.23373.declaration
|
||||
public abstract String getTypeName();
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.codegen.23376.declaration
|
||||
public abstract void codegen(ClassFile classfile, Vector paralist)
|
||||
throws JVMCodeException;
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.set_DeclId.23379.definition
|
||||
public void set_DeclId(DeclId did)
|
||||
// ino.end
|
||||
// ino.method.set_DeclId.23379.body
|
||||
{
|
||||
this.declid.addElement(did);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.get_Name.23382.definition
|
||||
public Vector<DeclId> get_Name()
|
||||
// ino.end
|
||||
// ino.method.get_Name.23382.body
|
||||
{
|
||||
return declid;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.getDeclIdVector.23385.definition
|
||||
public Vector<DeclId> getDeclIdVector()
|
||||
// ino.end
|
||||
// ino.method.getDeclIdVector.23385.body
|
||||
{
|
||||
// otth: ganzer Vektor zur�ckgeben, um ihn zu kopieren (vgl. MyCompiler - Konstruktor in Methode umwandeln)
|
||||
return declid;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.setDeclIdVector.23388.definition
|
||||
public void setDeclIdVector( Vector<DeclId> vDeclId )
|
||||
// ino.end
|
||||
// ino.method.setDeclIdVector.23388.body
|
||||
{
|
||||
// otth: kompletter Vektor setzen, um ihn zu kopieren (vgl. MyCompiler - Konstruktor in Methode umwandeln)
|
||||
declid = vDeclId;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
|
||||
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
|
||||
|
||||
/**
|
||||
* Diese Methode generiert die Assumptions für dieses Feld der Klasse classmember
|
||||
* @param classmember
|
||||
* @return
|
||||
*/
|
||||
public abstract TypeAssumptions createTypeAssumptions(Class classmember);
|
||||
|
||||
}
|
||||
// ino.end
|
@ -1,87 +0,0 @@
|
||||
package mycompiler.myclass;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.myexception.JVMCodeException;
|
||||
import mycompiler.mystatement.Expr;
|
||||
import mycompiler.mytype.Type;
|
||||
import mycompiler.mytype.TypePlaceholder;
|
||||
import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption;
|
||||
|
||||
@Deprecated
|
||||
public class FieldInitialization extends InstVarDecl {
|
||||
|
||||
|
||||
private Expr wert;
|
||||
//private Type type;
|
||||
|
||||
public void setWert(Expr initialExpression){
|
||||
this.wert = initialExpression;
|
||||
}
|
||||
public Expr getWert(){
|
||||
return this.wert;
|
||||
}
|
||||
|
||||
public String getIdentifier(){
|
||||
return this.getIdentifier().elementAt(0).name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void codegen(ClassFile classfile, Vector paralist)
|
||||
throws JVMCodeException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/*
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return super.toString() + "=" + getWert().toString();
|
||||
}
|
||||
|
||||
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
JavaCodeResult ret = new JavaCodeResult();
|
||||
ret.attach(this.getType().printJavaCode(resultSet)).attach( " ").attach( this.getName()+" = ").attach(this.getWert().printJavaCode(resultSet) ).attach( ";");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeAssumptions createTypeAssumptions(Class classmember) {
|
||||
//////////////////////////////
|
||||
//Felder:
|
||||
//////////////////////////////
|
||||
|
||||
TypeAssumptions assumptions = new TypeAssumptions();
|
||||
/*
|
||||
* TODO: Der Feld-Assumption muss ein TPH als Typ hinzugefügt werden, falls er Typlos initialisiert wurde. Dies kann auch der Type-Algorithmus der Inst/FieldVar - Klasse machen.
|
||||
* Wird das Feld mit einem Typ initialisiert so muss dieser auch in die Assumptions.
|
||||
*/
|
||||
if(this.getType() == null)this.setType(TypePlaceholder.fresh(this));
|
||||
assumptions.add(TypeAssumptions.createFieldVarAssumption(classmember.getName(), this.getName(), this.getType()));
|
||||
classmember.get_ClassBody().addField(this);
|
||||
return assumptions;
|
||||
}
|
||||
|
||||
}
|
@ -662,7 +662,7 @@ public class Method extends Field implements ITypeReplacementListener, IItemWith
|
||||
|
||||
@Override
|
||||
public Vector<SyntaxTreeNode> getChildren() {
|
||||
Vector<SyntaxTreeNode> ret = super.getChildren();
|
||||
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
||||
ret.add(this.block);
|
||||
return ret;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.mybytecode.CodeAttribute;
|
||||
import mycompiler.mybytecode.JVMCode;
|
||||
@ -32,6 +33,7 @@ import mycompiler.mytypereconstruction.unify.Unify;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
// ino.end
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.SingleConstraint;
|
||||
@ -259,5 +261,17 @@ public class Assign extends Expr
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Vector<SyntaxTreeNode> getChildren() {
|
||||
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
||||
ret.add(this.expr1);
|
||||
ret.add(this.expr2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -6,6 +6,7 @@ import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.mybytecode.CodeAttribute;
|
||||
import mycompiler.mybytecode.JVMCode;
|
||||
@ -31,6 +32,7 @@ import org.apache.log4j.Logger;
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.ConstraintsSet;
|
||||
import typinferenz.JavaCodeResult;
|
||||
@ -263,6 +265,13 @@ public class Binary extends BinaryExpr
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Vector<SyntaxTreeNode> getChildren() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.mybytecode.CodeAttribute;
|
||||
import mycompiler.myclass.Class;
|
||||
@ -30,6 +31,7 @@ import org.apache.log4j.Logger;
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.SingleConstraint;
|
||||
@ -304,5 +306,16 @@ public class Block extends Statement
|
||||
return ret.attach("}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Vector<SyntaxTreeNode> getChildren() {
|
||||
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
||||
for(Statement st : this.get_Statement()){
|
||||
ret.add(st);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -7,6 +7,7 @@ import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.mybytecode.CodeAttribute;
|
||||
import mycompiler.mybytecode.JVMCode;
|
||||
@ -40,6 +41,7 @@ import org.apache.log4j.Logger;
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.SingleConstraint;
|
||||
@ -414,5 +416,16 @@ public class IfStmt extends Statement
|
||||
ret.attach("\n}");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Vector<SyntaxTreeNode> getChildren() {
|
||||
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
||||
if(this.expr!=null)ret.add(this.expr);
|
||||
if(this.else_block!=null)ret.add(this.else_block);
|
||||
if(this.then_block!=null)ret.add(this.then_block);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -204,7 +204,7 @@ public class LocalOrFieldVar extends Expr
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
//gibt es eine Assumption für den die LocalOrFieldVar-Variablen, dann folgendes ausführen:
|
||||
Type thisTypeAssumption = assumptions.getVarType(this.get_Name());
|
||||
Type thisTypeAssumption = assumptions.getVarType(this.get_Name(), this.getParentClass());
|
||||
this.setType(thisTypeAssumption);
|
||||
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
|
||||
return ret;
|
||||
|
@ -241,7 +241,7 @@ public class MethodCall extends Expr
|
||||
parameterVector.addElement(fp);
|
||||
}
|
||||
pl.formalparameter=parameterVector;
|
||||
meth.setReturnType(returnType);
|
||||
meth.setType(returnType);
|
||||
meth.setParameterList(pl);
|
||||
meth.set_DeclId(new DeclId(assumption.getIdentifier()));
|
||||
return(meth);
|
||||
|
@ -98,7 +98,7 @@ public class LambdaTest {
|
||||
TypeAssumptions assumptions = result1.getInterferedClass().getPublicFieldAssumptions();// TypeAssumptions.getAssumptionsFor(classname);
|
||||
assertTrue("Fehler in Methode TypeAssumptions.getAssumptionsFor", assumptions!=null);
|
||||
for(String variable : variableTypeAssumptions.keySet()){
|
||||
Type assumedType = assumptions.getVarType(variable);
|
||||
Type assumedType = assumptions.getVarType(variable, result1.getInterferedClass());
|
||||
assertTrue("Der Variable muss ein TPH zugewiesen sein.", assumedType!=null && assumedType instanceof TypePlaceholder);
|
||||
//AssumedType auflösen:
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package typinferenz.assumptions;
|
||||
|
||||
import java.util.Iterator;
|
||||
import mycompiler.myclass.Class;
|
||||
import java.util.Vector;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
@ -145,9 +146,10 @@ public class TypeAssumptions {
|
||||
* Durchsucht die Assumptions des aktuellen Gültigkeitsbereichs (lokale Variablen und Felder der aktuellen Klasse) nach einem Eintrag für den übergebenen Variablennamen.
|
||||
* In den Assumptions wird dann in der Reihenfolge LocalVarAssumptions, FieldAssumption nach dem übergebenen Variablennamen gesucht.
|
||||
* @param variableName - der Identifier der gesuchten Variablen
|
||||
* @return - Der Typ für diesen Identifier.
|
||||
* @param inScope - Sucht auch die Felder der übergebenen Klasse ab. Hier kann auch null übergeben werden, dann werden nur die Lokalen Variablen dieser TypeAssumption durchsucht.
|
||||
* @return - Der Typ für diesen Identifier
|
||||
*/
|
||||
public Type getVarType(String variableName){
|
||||
public Type getVarType(String variableName, Class inScope){
|
||||
//Zuerst die Parameter durchsuchen
|
||||
for(ParameterAssumption ass : this.parameterAssumptions){//this.getParameterAssumptions(null)){
|
||||
if(ass.getIdentifier().equals(variableName))return ass.getAssumedType();
|
||||
@ -158,8 +160,8 @@ public class TypeAssumptions {
|
||||
}
|
||||
|
||||
//und zuletzt die Felder der Klasse in dessen Namensraum sich dieses AssumptionSet befindet.
|
||||
if(this.thisClassName!=null){
|
||||
for(FieldAssumption ass : this.getAssumptionsFor(this.thisClassName)){
|
||||
if(inScope!=null){
|
||||
for(FieldAssumption ass : this.getAssumptionsFor(inScope.getName())){
|
||||
if(ass.getIdentifier().equals(variableName) && ass instanceof FieldAssumption)return ass.getAssumedType();
|
||||
}
|
||||
}
|
||||
@ -246,3 +248,4 @@ public class TypeAssumptions {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class ConstructorTest {
|
||||
anzahlGeparsterKlassen++;
|
||||
}else if(cl.getName().equals("ConstructorTest2")){
|
||||
anzahlGeparsterKlassen++;
|
||||
assertTrue("ConstructorTest2.var muss vom Typ ConstructorTest1 sein.", ass.getVarType("var").printJavaCode(
|
||||
assertTrue("ConstructorTest2.var muss vom Typ ConstructorTest1 sein.", ass.getVarType("var",cl).printJavaCode(
|
||||
res.getUnifiedConstraints()).toString().equals("ConstructorTest1"));
|
||||
}else fail("Die geparsten Klassen müssen ConstructorTest1 und ConstructorTest2 heißen");
|
||||
}
|
||||
|
@ -33,10 +33,10 @@ public class ParseMultipleFilesTest {
|
||||
TypeAssumptions ass = cl.getPublicFieldAssumptions();
|
||||
if(cl.getName().equals("Klasse1")){
|
||||
anzahlGeparsterKlassen++;
|
||||
assertTrue("Klasse1.var1 muss vom Typ int sein.", ass.getVarType("var1").printJavaCode(res.getUnifiedConstraints()).toString().equals("int"));
|
||||
assertTrue("Klasse1.var1 muss vom Typ int sein.", ass.getVarType("var1",cl).printJavaCode(res.getUnifiedConstraints()).toString().equals("int"));
|
||||
}else if(cl.getName().equals("Klasse2")){
|
||||
anzahlGeparsterKlassen++;
|
||||
assertTrue("Klasse1.var1 muss vom Typ Klasse1 sein.", ass.getVarType("var1").printJavaCode(res.getUnifiedConstraints()).toString().equals("Klasse1"));
|
||||
assertTrue("Klasse1.var1 muss vom Typ Klasse1 sein.", ass.getVarType("var1",cl).printJavaCode(res.getUnifiedConstraints()).toString().equals("Klasse1"));
|
||||
}else fail("Die geparsten Klassen müssen Klasse1 und Klasse2 heißen");
|
||||
}
|
||||
assertTrue("Es müssen insgesamt 2 Klassen inferierd worden sein", anzahlGeparsterKlassen == 2);
|
||||
|
@ -1,11 +1,11 @@
|
||||
Class DEBUG [Typeinference] Erstellte Assumptions: this: WhileTestMethod Assumptions:
|
||||
[typinferenz.assumptions.MethodAssumption@52f37721, typinferenz.assumptions.MethodAssumption@6e124212]
|
||||
[typinferenz.assumptions.MethodAssumption@53be6b71, typinferenz.assumptions.MethodAssumption@7a7ff2aa]
|
||||
FieldVar Assumptions:
|
||||
[typinferenz.assumptions.FieldAssumption@70afe432]
|
||||
[typinferenz.assumptions.FieldAssumption@6614b5ba]
|
||||
LocalVar Assumptions:
|
||||
[]
|
||||
Parameter Assumptions:
|
||||
[]
|
||||
|
||||
Block DEBUG [Typeinference] Prozessing statement: WHILE null { [(var = mycompiler.mystatement.StringLiteral@2a2d0d78)]
|
||||
Block DEBUG [Typeinference] Prozessing statement: (var = mycompiler.mystatement.StringLiteral@2a2d0d78)
|
||||
Block DEBUG [Typeinference] Prozessing statement: WHILE null { [(var = mycompiler.mystatement.StringLiteral@49940c14)]
|
||||
Block DEBUG [Typeinference] Prozessing statement: (var = mycompiler.mystatement.StringLiteral@49940c14)
|
||||
|
Loading…
Reference in New Issue
Block a user