parserPostProcessing implementiert

This commit is contained in:
JanUlrich 2014-02-12 02:12:12 +01:00
parent 8cbd22f562
commit 605c554ffb
19 changed files with 29144 additions and 102 deletions

View File

@ -694,12 +694,12 @@ extendsinterfaces : EXTENDS interfacetype
classbodydeclarations : classbodydeclaration
{
ClassBody CB = new ClassBody();
CB.set_FieldDecl( $1 );
CB.addField( $1 );
$$=CB;
}
| classbodydeclarations classbodydeclaration
{
$1.set_FieldDecl($2);
$1.addField($2);
$$ = $1;
}

File diff suppressed because one or more lines are too long

View File

@ -5,9 +5,11 @@ package mycompiler;
// ino.module.AClassOrInterface.8526.import
import java.util.Vector;
import mycompiler.myclass.UsedId;
import mycompiler.myexception.JVMCodeException;
import mycompiler.mymodifier.Modifiers;
import org.apache.log4j.Logger;
// ino.end
@ -21,14 +23,17 @@ import org.apache.log4j.Logger;
*/
// ino.end
// ino.class.AClassOrInterface.21186.declaration
public abstract class AClassOrInterface
public interface AClassOrInterface
// ino.end
// ino.class.AClassOrInterface.21186.body
{
public String getName();
public Vector<UsedId> getSuperInterfaces();
public void setSuperInterfaces(Vector<UsedId> vector);
/*
// ino.attribute.inferencelog.21189.decldescription type=javadoc
/**
* Log4j - Loggerinstanzen
*/
// ino.end
// ino.attribute.inferencelog.21189.declaration
protected static Logger inferencelog = Logger.getLogger("inference");
@ -151,9 +156,6 @@ public abstract class AClassOrInterface
// ino.end
// ino.method.getAccessFlags.21237.defdescription type=javadoc
/**
* Liefert die AccessFlags fuer den Bytecode zurueck.
*/
// ino.end
// ino.method.getAccessFlags.21237.definition
public short getAccessFlags()
@ -197,5 +199,6 @@ public abstract class AClassOrInterface
public abstract void codegen(SourceFile sf)
throws JVMCodeException;
// ino.end
*/
}
// ino.end

View File

@ -479,7 +479,6 @@ public class MyCompiler implements MyCompilerAPI
// ino.end
// ino.method.init.21295.body
{
m_AbstractSyntaxTree = null;
TypePlaceholder.deleteRegistry();
// Log4J fuer die Ausgabe vorbereiten

View File

@ -51,7 +51,7 @@ import typinferenz.assumptions.TypeAssumptions;
// ino.class.SourceFile.21355.declaration
public class SourceFile
implements SyntaxTreeNode
extends SyntaxTreeNode
// ino.end
// ino.class.SourceFile.21355.body
{
@ -316,7 +316,6 @@ public class SourceFile
}
}
} // Schleifenende durch Klassenvektor
for(int i=0; i<InterfaceVektor.size();i++){
Interface intf= InterfaceVektor.get(i);
if(intf.getSuperInterfaces()!=null){
@ -330,7 +329,6 @@ public class SourceFile
}
}
}
Vector tto = (Vector)vFC.clone();
Unify.printMenge( "FC", vFC, 6 );
@ -1505,6 +1503,7 @@ 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);
}
@ -1517,8 +1516,11 @@ public class SourceFile
@Override
public Vector<SyntaxTreeNode> getChildren() {
// TODO Auto-generated method stub
return null;
Vector<SyntaxTreeNode> ret = super.getChildren();
for(Class cl : this.KlassenVektor){
ret.add(cl);
}
return ret;
}

View File

@ -2,7 +2,9 @@ package mycompiler;
import java.util.Vector;
public interface SyntaxTreeNode {
public abstract class SyntaxTreeNode {
private SyntaxTreeNode parent;
/**
* Wird nach dem Parsen aufgerufen.
@ -11,8 +13,16 @@ public interface SyntaxTreeNode {
* 2. Verknüpft die Knoten des Syntaxbaums. (setzt Parent)
*
*/
public void parserPostProcessing(SyntaxTreeNode parent);
public void parserPostProcessing(SyntaxTreeNode parent) {
this.parent = parent;
for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
}
public SyntaxTreeNode getParent();
public Vector<SyntaxTreeNode> getChildren();
public SyntaxTreeNode getParent() {
return this.parent;
}
public Vector<SyntaxTreeNode> getChildren(){
return new Vector<SyntaxTreeNode>();
}
}

View File

@ -53,6 +53,7 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
@ -66,10 +67,66 @@ import typinferenz.assumptions.TypeAssumptions;
// ino.class.Class.23010.declaration
public class Class extends AClassOrInterface implements SyntaxTreeNode
public class Class extends SyntaxTreeNode implements AClassOrInterface
// ino.end
// ino.class.Class.23010.body
{
/**
* Log4j - Loggerinstanzen
*/
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 Modifiers modifiers;
protected String name;
private Vector<UsedId> superif = new Vector<UsedId>();
public UsedId getPackageName()
{
return pkgName;
}
public void setPackageName(UsedId pkgName)
{
this.pkgName = pkgName;
}
public String getName()
{
return name;
}
public void setName(String strName)
{
name = strName;
}
public void setModifiers(Modifiers mod)
{
this.modifiers = mod;
}
public Modifiers getModifiers()
{
return this.modifiers;
}
/**
* Liefert die AccessFlags fuer den Bytecode zurueck.
*/
public short getAccessFlags()
{
short ret = 0;
if (modifiers != null) {
ret = modifiers.calculate_access_flags();
}
return ret;
}
public Vector<UsedId> getSuperInterfaces()
{
return superif;
}
public void setSuperInterfaces(Vector<UsedId> superif)
{
this.superif = superif;
}
// ino.attribute.superclassid.23014.decldescription type=line
// private Status status;
// ino.end
@ -123,7 +180,7 @@ public class Class extends AClassOrInterface implements SyntaxTreeNode
// ino.end
// ino.method.Class.23041.body
{
super(name);
this.name = name;
if(name.equals("java.lang.Object")){
superclassid=null;
}
@ -135,7 +192,8 @@ public class Class extends AClassOrInterface implements SyntaxTreeNode
// ino.end
// ino.method.Class.23044.body
{
super(name, mod);
this.name = name;
this.modifiers = mod;
if(name.equals("java.lang.Object")){
superclassid=null;
}
@ -154,7 +212,8 @@ public class Class extends AClassOrInterface implements SyntaxTreeNode
// ino.end
// ino.method.Class.23047.body
{
super(name, mod);
this.name = name;
this.modifiers = mod;
if (cb != null) set_ClassBody(cb);
if (ct != null) setContainedTypes(ct);
if (superclass != null) set_UsedId(superclass);
@ -522,7 +581,7 @@ public class Class extends AClassOrInterface implements SyntaxTreeNode
//Generiere Liste mit Expressions, welche zur Initialisierung von Feldern verwendet werden.
Vector<Expr> fieldInitializers = new Vector<Expr>();
for(FieldInitialization field : body.getFieldInitializations()){
for(FieldDeclaration field : body.getFieldInitializations()){
Assign fieldAssign = new Assign(0,0);
Expr expr1 = new LocalOrFieldVar(field.getName(), 0);
Expr expr2 = field.getWert();
@ -1134,6 +1193,7 @@ public class Class extends AClassOrInterface implements SyntaxTreeNode
@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
this.parent = parent;
for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
}
@Override
@ -1143,8 +1203,11 @@ public class Class extends AClassOrInterface implements SyntaxTreeNode
@Override
public Vector<SyntaxTreeNode> getChildren() {
// TODO Auto-generated method stub
return null;
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
for(Field f : this.body.getFields()){
ret.add(f);
}
return ret;
}
}

View File

@ -92,24 +92,21 @@ Paratyp gesetzt."); }
// ino.method.get_FieldDeclVector.23182.definition
public Vector<Field> getFields()
// ino.end
// ino.method.get_FieldDeclVector.23182.body
{
return fielddecl;
}
// ino.end
// ino.method.set_FieldDecl.23185.definition
public void set_FieldDecl(Field i)
// ino.end
// ino.method.set_FieldDecl.23185.body
/**
* @author Andreas Stadelmeier, a10023
* Fügt der Klasse eine Feld hinzu.
* @param feld
*/
public void addField(Field i)
{
fielddecl.addElement(i);
}
// ino.end
// ino.method.is_declared.23188.defdescription type=line
//
// ********************************************************************************************
@ -364,19 +361,8 @@ public void istParameterOK( Vector Parameter, Vector<Class> KlassenVektor )
private Vector<FieldInitialization> fieldInitialisations = new Vector<FieldInitialization>();
/**
* @author Andreas Stadelmeier, a10023
* Fügt der Klasse eine Feldinitialisation hinzu.
* Eine Feldinitialisation steht für eine Felddeklaration mit gleichzeitiger Wertzuweisung
* Beispiel: 'public Feld FeldVar = FeldWert;'
* @param feld
*/
public void addFieldInitialization(FieldInitialization feld) {
this.fieldInitialisations.add(feld);
}
public Vector<FieldInitialization> getFieldInitializations(){
return this.fieldInitialisations;
}
public JavaCodeResult printJavaCode(ResultSet resultSet) {
@ -385,6 +371,17 @@ public void istParameterOK( Vector Parameter, Vector<Class> KlassenVektor )
return ret.attach("}\n");
}
@Deprecated
public Vector<FieldDeclaration> getFieldInitializations() {
Vector<FieldDeclaration> ret = new Vector<FieldDeclaration>();
for(Field f:this.getFields()){
if(f instanceof FieldDeclaration)ret.add((FieldDeclaration)f);
}
return ret;
}
}
// ino.end

View File

@ -13,11 +13,13 @@ import typinferenz.Typeable;
import typinferenz.TypeInsertable;
import typinferenz.assumptions.TypeAssumptions;
public abstract class Field implements TypeInsertable, Typeable, SyntaxTreeNode{
// ino.attribute.declid.23370.declaration
public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Typeable{
protected Vector<DeclId> declid = new Vector<DeclId>(); // Vector, da 'int a, b, c, ...' auch eingeparst werden muss
private Type typ;
private SyntaxTreeNode parent;
@Override
public void setType(Type typ) {
@ -28,52 +30,34 @@ public abstract class Field implements TypeInsertable, Typeable, SyntaxTreeNode{
return typ;
}
// 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<EFBFBD>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
@ -86,4 +70,6 @@ public abstract class Field implements TypeInsertable, Typeable, SyntaxTreeNode{
* @return
*/
public abstract TypeAssumptions createTypeAssumptions(Class classmember);
}

View File

@ -2,18 +2,27 @@ package mycompiler.myclass;
import java.util.Vector;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.assumptions.TypeAssumptions;
import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile;
import mycompiler.myexception.JVMCodeException;
import mycompiler.mystatement.Expr;
import mycompiler.mytype.Type;
import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
/**
* Eine Feldinitialisation steht für eine Felddeklaration mit gleichzeitiger Wertzuweisung
* Beispiel: 'public Feld FeldVar = FeldWert;'
* @author janulrich
*
*/
public class FieldDeclaration extends Field{
private Expr wert;
private Expr wert;
//private Type type;
public void setWert(Expr initialExpression){
@ -27,36 +36,66 @@ public class FieldDeclaration extends Field{
return this.get_Name().elementAt(0).name;
}
@Override
public void codegen(ClassFile classfile, Vector paralist)
throws JVMCodeException {
// TODO Auto-generated method stub
}
@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()));
return assumptions;
}
@Override
public void parserPostProcessing(SyntaxTreeNode parent){
super.parserPostProcessing(parent);
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
ret.add(this.wert);
return ret;
}
@Override
public void replaceType(CReplaceTypeEvent e) {
// TODO Auto-generated method stub
}
@Override
public int getTypeLineNumber() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void codegen(ClassFile classfile, Vector paralist)
throws JVMCodeException {
// TODO Auto-generated method stub
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
// TODO Auto-generated method stub
return null;
}
@Override
public TypeAssumptions createTypeAssumptions(Class classmember) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -80,7 +80,7 @@ public class FieldInitialization extends InstVarDecl {
*/
if(this.getType() == null)this.setType(TypePlaceholder.fresh(this));
assumptions.add(TypeAssumptions.createFieldVarAssumption(classmember.getName(), this.getName(), this.getType()));
classmember.get_ClassBody().addFieldInitialization(this);
classmember.get_ClassBody().addField(this);
return assumptions;
}

View File

@ -8,6 +8,7 @@ import java.util.Iterator;
import java.util.Vector;
import mycompiler.IItemWithOffset;
import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile;
import mycompiler.MyCompiler;
import mycompiler.myexception.JVMCodeException;
@ -650,5 +651,30 @@ public class Method extends Field implements ITypeReplacementListener, IItemWith
return assumptions;
}
@Override
public void parserPostProcessing(SyntaxTreeNode parent){
super.parserPostProcessing(parent);
if(this.getType()==null)this.setType(TypePlaceholder.fresh(this));
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = super.getChildren();
ret.add(this.block);
return ret;
}
@Override
public void setType(Type t){
// Methode und Block teilen sich einen ReturnType:
this.block.setType(t);
}
@Override
public Type getType(){
//Methode und Block teilen sich einen ReturnType:
return this.block.getType();
}
}
// ino.end

View File

@ -4,6 +4,7 @@ package mycompiler.myinterface;
// ino.module.Interface.8582.import
import java.util.Vector;
import mycompiler.AClassOrInterface;
import mycompiler.mybytecode.ClassFile;
import mycompiler.myclass.ClassHelper;
@ -11,6 +12,7 @@ import mycompiler.myclass.Constant;
import mycompiler.myclass.FormalParameter;
import mycompiler.myclass.Method;
import mycompiler.myclass.ParameterList;
import mycompiler.myclass.UsedId;
import mycompiler.myexception.JVMCodeException;
import mycompiler.mymodifier.Modifiers;
import mycompiler.mytype.GenericTypeVar;
@ -33,7 +35,7 @@ import mycompiler.SourceFile;
*/
// ino.end
// ino.class.Interface.23932.declaration
public class Interface extends AClassOrInterface
public class Interface implements AClassOrInterface
// ino.end
// ino.class.Interface.23932.body
{
@ -247,5 +249,9 @@ public class Interface extends AClassOrInterface
}
// ino.end
}
// ino.end

View File

@ -1163,14 +1163,14 @@ case 51:
// line 695 "./../src/mycompiler/myparser/JavaParser.jay"
{
ClassBody CB = new ClassBody();
CB.set_FieldDecl( ((Field)yyVals[0+yyTop]) );
CB.addField( ((Field)yyVals[0+yyTop]) );
yyVal=CB;
}
break;
case 52:
// line 701 "./../src/mycompiler/myparser/JavaParser.jay"
{
((ClassBody)yyVals[-1+yyTop]).set_FieldDecl(((Field)yyVals[0+yyTop]));
((ClassBody)yyVals[-1+yyTop]).addField(((Field)yyVals[0+yyTop]));
yyVal = ((ClassBody)yyVals[-1+yyTop]);
}
break;

View File

@ -694,12 +694,12 @@ extendsinterfaces : EXTENDS interfacetype
classbodydeclarations : classbodydeclaration
{
ClassBody CB = new ClassBody();
CB.set_FieldDecl( $1 );
CB.addField( $1 );
$$=CB;
}
| classbodydeclarations classbodydeclaration
{
$1.set_FieldDecl($2);
$1.addField($2);
$$ = $1;
}

View File

@ -37,7 +37,7 @@ import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption;
// ino.class.Statement.26184.declaration
public abstract class Statement implements IItemWithOffset, Typeable, ITypeReplacementListener, SyntaxTreeNode
public abstract class Statement extends SyntaxTreeNode implements IItemWithOffset, Typeable, ITypeReplacementListener
// ino.end
// ino.class.Statement.26184.body
{
@ -50,6 +50,7 @@ public abstract class Statement implements IItemWithOffset, Typeable, ITypeRepla
// ino.end
protected Type type;
private SyntaxTreeNode parent;
// ino.method.Statement.26194.definition
public Statement(int offset, int variableLength)
@ -144,6 +145,7 @@ public abstract class Statement implements IItemWithOffset, Typeable, ITypeRepla
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
}
// ino.end

View File

@ -6,6 +6,8 @@ package mycompiler.mytype;
import java.util.Vector;
// ino.end
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
@ -131,6 +133,7 @@ public class GenericTypeVar extends Type
}
return new JavaCodeResult(this.name);
}
}
// ino.end

View File

@ -162,13 +162,17 @@ public class RefType extends Type implements IMatchable
}
// ino.end
/**
* Wandelt die Parameter des RefTypes in TPHs um, sofern es sich um Generische Variablen handelt.
* @return
*/
// ino.method.GenericTypeVar2TypePlaceholder.26652.definition
public CSubstitutionSet GenericTypeVar2TypePlaceholder ()
// ino.end
// ino.method.GenericTypeVar2TypePlaceholder.26652.body
{
throw new NotImplementedException();
/*
//throw new NotImplementedException();
///*
CSubstitutionSet sub = new CSubstitutionSet();
if(parameter != null)
{
@ -176,7 +180,7 @@ public class RefType extends Type implements IMatchable
{
if (parameter.elementAt(i) instanceof GenericTypeVar)
{
TypePlaceholder tlv = TypePlaceholder.fresh();
TypePlaceholder tlv = TypePlaceholder.fresh(); //TODO: Hier wird ein TypePlaceholder ohne ITypeReplacementListener erstellt. Kann Probleme verursachen
sub.addElement(new CSubstitutionGenVar((GenericTypeVar)parameter.elementAt(i), tlv));
parameter.set(i, tlv);
}
@ -188,7 +192,7 @@ public class RefType extends Type implements IMatchable
}
}
return sub;
*/
//*/
}
// ino.end

View File

@ -87,7 +87,7 @@ public class TypePlaceholder extends Type implements IReplaceTypeEventProvider
*/
// ino.end
// ino.method.fresh.26800.definition
private static TypePlaceholder fresh()
public static TypePlaceholder fresh()
// ino.end
// ino.method.fresh.26800.body
{