forked from JavaTX/JavaCompilerCore
238 lines
7.6 KiB
Java
Executable File
238 lines
7.6 KiB
Java
Executable File
// ino.module.InstVar.8634.package
|
||
package de.dhbwstuttgart.syntaxtree.statement;
|
||
// ino.end
|
||
// ino.module.InstVar.8634.import
|
||
import java.util.Enumeration;
|
||
import java.util.Hashtable;
|
||
import java.util.Iterator;
|
||
import java.util.Vector;
|
||
|
||
import org.apache.log4j.Logger;
|
||
|
||
import de.dhbwstuttgart.bytecode.ClassFile;
|
||
import de.dhbwstuttgart.bytecode.CodeAttribute;
|
||
import de.dhbwstuttgart.bytecode.JVMCode;
|
||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||
import de.dhbwstuttgart.syntaxtree.Class;
|
||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||
import de.dhbwstuttgart.typeinference.FreshTypeVariable;
|
||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||
import de.dhbwstuttgart.typeinference.Pair;
|
||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||
import de.dhbwstuttgart.typeinference.unify.Unify;
|
||
|
||
|
||
|
||
|
||
// ino.class.InstVar.25392.declaration
|
||
public class InstVar extends Expr
|
||
// ino.end
|
||
// ino.class.InstVar.25392.body
|
||
{
|
||
// ino.attribute.expr.25396.declaration
|
||
private Expr expr;
|
||
// ino.end
|
||
// ino.attribute.usedid.25399.declaration
|
||
private UsedId usedid;
|
||
// ino.end
|
||
// ino.attribute.type.25402.declaration
|
||
protected String type; //???? BRAUCHT MAN DEN???
|
||
// ino.end
|
||
// ino.attribute.parserlog.25405.declaration
|
||
protected static Logger parserlog = Logger.getLogger("parser");
|
||
// ino.end
|
||
|
||
// ino.method.InstVar.25408.definition
|
||
public InstVar(Expr e, String n, int offset)
|
||
// ino.end
|
||
// ino.method.InstVar.25408.body
|
||
{
|
||
super(offset,n.length());
|
||
expr = e;
|
||
usedid = new UsedId(getOffset());
|
||
usedid.set_Name(n);
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.InstVar.25411.definition
|
||
public InstVar(String n, String t, int offset)
|
||
// ino.end
|
||
// ino.method.InstVar.25411.body
|
||
{
|
||
super(offset,n.length());
|
||
usedid = new UsedId(getOffset());
|
||
usedid.set_Name(n);
|
||
type = t;
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.InstVar.25414.defdescription type=javadoc
|
||
/**
|
||
* macht aus einem UsedId mit einem Vector von Strings eine InstVar
|
||
* <br/>Author: Martin Pl<50>micke PL 05-08-17
|
||
* @param ui
|
||
* @return
|
||
*/
|
||
// ino.end
|
||
// ino.method.InstVar.25414.definition
|
||
public InstVar(UsedId ui, int offset,int variableLength)
|
||
// ino.end
|
||
// ino.method.InstVar.25414.body
|
||
{
|
||
super(offset,variableLength);
|
||
Iterator namen = ui.get_Name().iterator();
|
||
LocalOrFieldVar innerLOFV = new LocalOrFieldVar((String)namen.next(),getOffset());
|
||
//innerLOFV.setType(TypePlaceholder.fresh(this));
|
||
InstVar INSTVA = new InstVar(innerLOFV, (String)namen.next(),offset);
|
||
//INSTVA.setType(TypePlaceholder.fresh(this));
|
||
while(namen.hasNext()) {
|
||
INSTVA = new InstVar(INSTVA, (String)namen.next(),offset);
|
||
//INSTVA.setType(TypePlaceholder.fresh(this));
|
||
}
|
||
expr = INSTVA.expr;
|
||
usedid = INSTVA.usedid;
|
||
}
|
||
// ino.end
|
||
|
||
@Override
|
||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||
super.parserPostProcessing(parent);
|
||
if(this.getType()==null)this.set_Type(TypePlaceholder.fresh(this));
|
||
}
|
||
|
||
// ino.method.sc_check.25417.definition
|
||
public void sc_check(Vector<Class> classname, Hashtable ch, Hashtable<String, String> bh, boolean ext, Hashtable parach, Hashtable<String, Hashtable> parabh)
|
||
// ino.end
|
||
// ino.method.sc_check.25417.body
|
||
{
|
||
if(ext)
|
||
parserlog.debug(" ---InstVar---");
|
||
Vector name = usedid.get_Name();
|
||
|
||
for(Enumeration el = name.elements(); el.hasMoreElements();)
|
||
{
|
||
String name1 = (String) el.nextElement();
|
||
|
||
if(bh.containsKey(name1))
|
||
{
|
||
this.type = (String)bh.get(name1); //type wird von Expr geerbt
|
||
if(ext)
|
||
parserlog.debug("Variable " + name1 + " im Block gefunden.");
|
||
}
|
||
else if(ch.containsKey(name1))
|
||
{
|
||
this.type = (String)ch.get(name1);
|
||
if(ext)
|
||
parserlog.debug("Variable " + name1 + " in Class gefunden.");
|
||
}
|
||
else
|
||
if(ext)
|
||
parserlog.debug("Typfehler: -->InstVar.sc_check() "+ name1);
|
||
}
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.get_Name.25420.definition
|
||
public String get_Name()
|
||
// ino.end
|
||
// ino.method.get_Name.25420.body
|
||
{
|
||
return this.usedid.get_Name_1Element();
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.get_codegen_UsedId.25423.definition
|
||
public String get_codegen_UsedId()
|
||
// ino.end
|
||
// ino.method.get_codegen_UsedId.25423.body
|
||
{ return usedid.get_codegen_UsedId(); }
|
||
// ino.end
|
||
|
||
// ino.method.codegen.25426.definition
|
||
public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
|
||
throws JVMCodeException
|
||
// ino.end
|
||
// ino.method.codegen.25426.body
|
||
{
|
||
String instvar_name = usedid.get_codegen_UsedId();
|
||
|
||
code.add_code(JVMCode.aload_0);
|
||
code.add_code(JVMCode.getfield);
|
||
code.add_code_short(classfile.add_field_ref(instvar_name, null, null));
|
||
}
|
||
// ino.end
|
||
|
||
|
||
|
||
|
||
|
||
// ino.method.toString.25441.defdescription type=javadoc
|
||
/**
|
||
* <br/>Author: Martin Pl<50>micke
|
||
* @return
|
||
*/
|
||
// ino.end
|
||
// ino.method.toString.25441.definition
|
||
public String toString()
|
||
// ino.end
|
||
// ino.method.toString.25441.body
|
||
{
|
||
return super.type.toString() + " " + usedid.toString();
|
||
}
|
||
// ino.end
|
||
|
||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25444.definition
|
||
public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist, Vector<GenericTypeVar> genericMethodParameters)
|
||
// ino.end
|
||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25444.body
|
||
{
|
||
}
|
||
// ino.end
|
||
|
||
@Override
|
||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||
ConstraintsSet ret = new ConstraintsSet();
|
||
if(this.expr == null){
|
||
this.expr = new This(0, 0);
|
||
}
|
||
ret.add(expr.TYPEExpr(assumptions));
|
||
this.setType(TypePlaceholder.fresh(this));
|
||
OderConstraint oderConstraint = new OderConstraint();
|
||
for(FieldAssumption fa : assumptions.getFieldVars(this.get_Name())){
|
||
UndConstraint undConstraint = new UndConstraint();
|
||
undConstraint.addConstraint(fa.getAssumedType().TYPE(assumptions, this),this.getType().TYPE(assumptions, this));
|
||
undConstraint.addConstraint(this.expr.getType().TYPE(assumptions, this),fa.getParentClass().getType().TYPE(assumptions, this));
|
||
oderConstraint.addConstraint(undConstraint);
|
||
}
|
||
ret.add(oderConstraint);
|
||
return ret;
|
||
}
|
||
|
||
@Override
|
||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||
JavaCodeResult ret = new JavaCodeResult();
|
||
if(this.expr != null)ret.attach(this.expr.printJavaCode(resultSet)).attach(".");
|
||
return ret.attach(this.usedid.get_Name_1Element());
|
||
}
|
||
|
||
@Override
|
||
public Vector<SyntaxTreeNode> getChildren() {
|
||
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
||
ret.add(this.expr);
|
||
return ret;
|
||
}
|
||
}
|
||
// ino.end
|