2013-10-18 11:33:46 +00:00
|
|
|
|
// ino.module.InstVar.8634.package
|
|
|
|
|
package mycompiler.mystatement;
|
|
|
|
|
// ino.end
|
|
|
|
|
// ino.module.InstVar.8634.import
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.Hashtable;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.Vector;
|
2014-02-09 15:07:31 +00:00
|
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
|
import mycompiler.mybytecode.ClassFile;
|
|
|
|
|
import mycompiler.mybytecode.CodeAttribute;
|
|
|
|
|
import mycompiler.mybytecode.JVMCode;
|
|
|
|
|
import mycompiler.myclass.Class;
|
|
|
|
|
import mycompiler.myclass.UsedId;
|
|
|
|
|
import mycompiler.myexception.CTypeReconstructionException;
|
|
|
|
|
import mycompiler.myexception.JVMCodeException;
|
|
|
|
|
import mycompiler.mytype.GenericTypeVar;
|
|
|
|
|
import mycompiler.mytype.Pair;
|
|
|
|
|
import mycompiler.mytype.RefType;
|
|
|
|
|
import mycompiler.mytype.Type;
|
|
|
|
|
import mycompiler.mytype.TypePlaceholder;
|
|
|
|
|
import mycompiler.mytypereconstruction.CSupportData;
|
|
|
|
|
import mycompiler.mytypereconstruction.CTriple;
|
2014-02-09 15:07:31 +00:00
|
|
|
|
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
|
2013-10-18 11:33:46 +00:00
|
|
|
|
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;
|
|
|
|
|
import mycompiler.mytypereconstruction.unify.Unify;
|
2014-02-09 15:07:31 +00:00
|
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
// ino.end
|
|
|
|
|
|
2014-02-09 15:07:31 +00:00
|
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
|
import typinferenz.ConstraintsSet;
|
|
|
|
|
import typinferenz.FreshTypeVariable;
|
|
|
|
|
import typinferenz.JavaCodeResult;
|
|
|
|
|
import typinferenz.ResultSet;
|
2014-02-09 15:07:31 +00:00
|
|
|
|
import typinferenz.assumptions.TypeAssumptions;
|
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));
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
// 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 null;
|
|
|
|
|
}
|
|
|
|
|
// 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();
|
|
|
|
|
ret.add(expr.TYPEExpr(assumptions));
|
|
|
|
|
this.setTypeVariable(TypePlaceholder.fresh(this));
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|
|
|
|
return new JavaCodeResult().attach(this.expr.printJavaCode(resultSet)).attach("."+this.usedid.get_Name_1Element());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ino.end
|