2014-02-11 01:47:39 +00:00
|
|
|
|
package mycompiler.myclass;
|
|
|
|
|
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
2014-02-12 21:10:33 +00:00
|
|
|
|
import typinferenz.ConstraintsSet;
|
2014-02-11 01:47:39 +00:00
|
|
|
|
import typinferenz.JavaCodeResult;
|
2014-02-12 21:10:33 +00:00
|
|
|
|
import typinferenz.OderConstraint;
|
2014-02-11 01:47:39 +00:00
|
|
|
|
import typinferenz.ResultSet;
|
2014-02-12 21:10:33 +00:00
|
|
|
|
import typinferenz.SingleConstraint;
|
2014-02-19 13:16:28 +00:00
|
|
|
|
import typinferenz.assumptions.FieldAssumption;
|
2014-02-11 01:47:39 +00:00
|
|
|
|
import typinferenz.assumptions.TypeAssumptions;
|
2014-03-18 19:18:57 +00:00
|
|
|
|
import typinferenz.exceptions.TypinferenzException;
|
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;
|
|
|
|
|
|
2014-03-09 11:10:03 +00:00
|
|
|
|
public FieldDeclaration(int offset){
|
|
|
|
|
super(offset);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-11 01:47:39 +00:00
|
|
|
|
public void setWert(Expr initialExpression){
|
|
|
|
|
this.wert = initialExpression;
|
|
|
|
|
}
|
|
|
|
|
public Expr getWert(){
|
|
|
|
|
return this.wert;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 04:20:54 +00:00
|
|
|
|
public String getIdentifier(){
|
2014-02-11 01:47:39 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2014-03-17 16:55:55 +00:00
|
|
|
|
if(getWert()!=null)return super.toString() + "=" + getWert().toString();
|
|
|
|
|
return super.toString();
|
2014-02-12 01:12:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|
|
|
|
JavaCodeResult ret = new JavaCodeResult();
|
2014-02-19 04:20:54 +00:00
|
|
|
|
JavaCodeResult toAttach = this.getType().printJavaCode(resultSet).attach(" ").attach( this.getIdentifier());
|
2014-02-12 21:10:33 +00:00
|
|
|
|
if(this.wert!=null)toAttach.attach(" = ").attach(this.getWert().printJavaCode(resultSet) );
|
|
|
|
|
toAttach.attach( ";");
|
|
|
|
|
ret.attach(toAttach);
|
2014-02-12 01:12:12 +00:00
|
|
|
|
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:
|
|
|
|
|
//////////////////////////////
|
|
|
|
|
TypeAssumptions assumptions = new TypeAssumptions();
|
|
|
|
|
/*
|
2014-03-18 19:18:57 +00:00
|
|
|
|
* 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.
|
2014-02-12 01:12:12 +00:00
|
|
|
|
* Wird das Feld mit einem Typ initialisiert so muss dieser auch in die Assumptions.
|
|
|
|
|
*/
|
2014-02-19 13:16:28 +00:00
|
|
|
|
if(this.getType() == null)throw new TypinferenzException("Der Typ eines Feldes darf nicht null sein");
|
2014-02-19 04:20:54 +00:00
|
|
|
|
//assumptions.add(TypeAssumptions.createFieldVarAssumption(classmember.getName(), this.getName(), this.getType()));
|
2014-02-19 13:16:28 +00:00
|
|
|
|
assumptions.addFieldAssumption(new FieldAssumption(this,classmember));
|
2014-02-12 01:12:12 +00:00
|
|
|
|
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-19 13:16:28 +00:00
|
|
|
|
if(this.getType() == null)this.setType(TypePlaceholder.fresh(this));
|
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>();
|
2014-02-12 21:10:33 +00:00
|
|
|
|
if(this.wert!=null)ret.add(this.wert);
|
2014-02-12 01:12:12 +00:00
|
|
|
|
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
|
|
|
|
}
|
2014-02-12 21:10:33 +00:00
|
|
|
|
|
|
|
|
|
public int getVariableLength()
|
|
|
|
|
{
|
|
|
|
|
return declid.elementAt(0).get_Name().length();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public ConstraintsSet TYPE(TypeAssumptions publicAssumptions) {
|
|
|
|
|
ConstraintsSet ret = new ConstraintsSet();
|
|
|
|
|
SingleConstraint c1 = new SingleConstraint(this.getType(), this.getType());
|
|
|
|
|
ret.add(c1); //Damit die TypVariable des Felds in den Constraints auftaucht
|
|
|
|
|
|
|
|
|
|
if(this.wert!=null){
|
|
|
|
|
//Falls bei der Deklaration ein Wert zugewiesen wird, verh<72>lt sich das Constraintserzeugen wie bei dem Assign-Statement:
|
|
|
|
|
ret.add(this.wert.TYPEExpr(publicAssumptions));
|
|
|
|
|
ret.add(new SingleConstraint(this.wert.getType(), this.getType()));
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2014-02-19 04:20:54 +00:00
|
|
|
|
|
2014-02-11 01:47:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|