JavaPatternMatching/src/mycompiler/myclass/FieldDeclaration.java

102 lines
2.6 KiB
Java
Raw Normal View History

2014-02-11 01:47:39 +00:00
package mycompiler.myclass;
import java.util.Vector;
2014-02-12 01:12:12 +00:00
2014-02-11 01:47:39 +00:00
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.assumptions.TypeAssumptions;
2014-02-12 01:12:12 +00:00
import mycompiler.SyntaxTreeNode;
2014-02-11 01:47:39 +00:00
import mycompiler.mybytecode.ClassFile;
import mycompiler.myexception.JVMCodeException;
import mycompiler.mystatement.Expr;
import mycompiler.mytype.Type;
2014-02-12 01:12:12 +00:00
import mycompiler.mytype.TypePlaceholder;
2014-02-11 01:47:39 +00:00
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
2014-02-12 01:12:12 +00:00
/**
* Eine Feldinitialisation steht f<EFBFBD>r eine Felddeklaration mit gleichzeitiger Wertzuweisung
* Beispiel: 'public Feld FeldVar = FeldWert;'
* @author janulrich
*
*/
2014-02-11 01:47:39 +00:00
public class FieldDeclaration extends Field{
2014-02-12 01:12:12 +00:00
private Expr wert;
2014-02-11 01:47:39 +00:00
//private Type type;
public void setWert(Expr initialExpression){
this.wert = initialExpression;
}
public Expr getWert(){
return this.wert;
}
public String getName(){
return this.get_Name().elementAt(0).name;
}
@Override
2014-02-12 01:12:12 +00:00
public void codegen(ClassFile classfile, Vector paralist)
throws JVMCodeException {
2014-02-11 01:47:39 +00:00
// TODO Auto-generated method stub
2014-02-12 01:12:12 +00:00
}
2014-02-11 01:47:39 +00:00
@Override
2014-02-12 01:12:12 +00:00
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;
2014-02-11 01:47:39 +00:00
}
2014-02-12 01:12:12 +00:00
@Override
public TypeAssumptions createTypeAssumptions(Class classmember) {
//////////////////////////////
//Felder:
//////////////////////////////
2014-02-11 01:47:39 +00:00
2014-02-12 01:12:12 +00:00
TypeAssumptions assumptions = new TypeAssumptions();
/*
* TODO: Der Feld-Assumption muss ein TPH als Typ hinzugef<EFBFBD>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;
}
2014-02-11 01:47:39 +00:00
@Override
2014-02-12 01:12:12 +00:00
public void parserPostProcessing(SyntaxTreeNode parent){
super.parserPostProcessing(parent);
2014-02-11 01:47:39 +00:00
}
2014-02-12 01:12:12 +00:00
2014-02-11 01:47:39 +00:00
@Override
2014-02-12 01:12:12 +00:00
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
ret.add(this.wert);
return ret;
}
@Override
public void replaceType(CReplaceTypeEvent e) {
2014-02-11 01:47:39 +00:00
// TODO Auto-generated method stub
2014-02-12 01:12:12 +00:00
2014-02-11 01:47:39 +00:00
}
@Override
2014-02-12 01:12:12 +00:00
public int getTypeLineNumber() {
2014-02-11 01:47:39 +00:00
// TODO Auto-generated method stub
2014-02-12 01:12:12 +00:00
return 0;
2014-02-11 01:47:39 +00:00
}
}