JavaPatternMatching/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java

323 lines
10 KiB
Java
Raw Normal View History

2013-10-18 11:33:46 +00:00
// ino.module.InstVar.8634.package
2014-09-02 08:33:54 +00:00
package de.dhbwstuttgart.syntaxtree.statement;
2013-10-18 11:33:46 +00:00
// ino.end
// ino.module.InstVar.8634.import
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
2013-10-18 11:33:46 +00:00
import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute;
import mycompiler.mybytecode.JVMCode;
import mycompiler.myexception.CTypeReconstructionException;
import mycompiler.myexception.JVMCodeException;
import mycompiler.mytypereconstruction.CSupportData;
import mycompiler.mytypereconstruction.CTriple;
import mycompiler.mytypereconstruction.set.CSubstitutionSet;
import mycompiler.mytypereconstruction.set.CTripleSet;
import mycompiler.mytypereconstruction.set.CTypeAssumptionSet;
import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption;
import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption;
import mycompiler.mytypereconstruction.typeassumptionkey.CInstVarKey;
2013-10-18 11:33:46 +00:00
import org.apache.log4j.Logger;
// ino.end
2014-09-02 08:33:54 +00:00
2014-09-02 09:07:16 +00:00
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.core.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Pair;
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.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
2014-09-02 09:07:16 +00:00
import de.dhbwstuttgart.typeinference.unify.Unify;
2013-10-18 11:33:46 +00:00
// 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<EFBFBD>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));
2013-10-18 11:33:46 +00:00
InstVar INSTVA = new InstVar(innerLOFV, (String)namen.next(),offset);
//INSTVA.setType(TypePlaceholder.fresh(this));
2013-10-18 11:33:46 +00:00
while(namen.hasNext()) {
INSTVA = new InstVar(INSTVA, (String)namen.next(),offset);
//INSTVA.setType(TypePlaceholder.fresh(this));
2013-10-18 11:33:46 +00:00
}
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
2013-10-18 11:33:46 +00:00
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();
2013-10-18 11:33:46 +00:00
}
// 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.TRStatement.25429.definition
public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
// ino.end
// ino.method.TRStatement.25429.body
{
throw CTypeReconstructionException.createNotImplementedException();
}
// ino.end
// ino.method.handleInstVarAssum.25438.defdescription type=javadoc
/**
* Unifiziert den R<EFBFBD>ckgabetyp des Receivers mit dem der gefundenen Klasse
* <br/>Author: J<EFBFBD>rg B<EFBFBD>uerle
* @param triple Triple des Receivers
* @param thetaZero Typ der gefundenen Klasse
* @param thetaC Typ der InstanzVariable
* @param resultSet
* @param supportData
*/
// ino.end
// ino.method.handleInstVarAssum.25438.definition
private void handleInstVarAssum(CTriple triple, Type thetaZero, Type thetaC, CTripleSet resultSet, CSupportData supportData)
// ino.end
// ino.method.handleInstVarAssum.25438.body
{
// --------------------------
// ReturnType mit Integer unifizieren:
// --------------------------
Vector<Vector<Pair>> unifierPossibilities = Unify.unify(triple.getResultType(), thetaZero, supportData.getFiniteClosure());
// --------------------------
// Wenn Unifier vorhanden, dann
// anwenden und Triple hinzuf<75>gen:
// --------------------------
if(unifierPossibilities.size()!=0){
// --------------------------
// Subset bauen:
// --------------------------
CTripleSet subSet = new CTripleSet();
// --------------------------
// Alle m<>glichen Unifier anwenden:
// --------------------------
for(int i=0; i<unifierPossibilities.size(); i++){
CSubstitutionSet unifier = new CSubstitutionSet(unifierPossibilities.elementAt(i));
CTriple subTriple = triple.cloneAndApplyUnify(unifier);
subTriple.setResultType(thetaC);
subSet.addElement(subTriple);
}
resultSet.unite(subSet);
}
}
// ino.end
// ino.method.toString.25441.defdescription type=javadoc
/**
* <br/>Author: Martin Pl<EFBFBD>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
public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable)
{
if(this.get_UsedId().get_Name_1Element().equals(NameVariable))
{
//wenn Variable mit gleichem Namen gefunden->schreibe Offset
localAssumption.addOffset(this.get_UsedId().getOffset());
}
}
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
if(this.expr == null){
this.expr = new This(0, 0);
}
2013-10-18 11:33:46 +00:00
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(),this.getType());
undConstraint.addConstraint(this.expr.getType(),fa.getParentClass().getType());
oderConstraint.addConstraint(undConstraint);
}
ret.add(oderConstraint);
return ret;
2013-10-18 11:33:46 +00:00
}
@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());
2013-10-18 11:33:46 +00:00
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
ret.add(this.expr);
return ret;
}
2013-10-18 11:33:46 +00:00
}
// ino.end