forked from JavaTX/JavaCompilerCore
462 lines
17 KiB
Java
462 lines
17 KiB
Java
|
// ino.module.LocalOrFieldVar.8637.package
|
|||
|
package mycompiler.mystatement;
|
|||
|
// ino.end
|
|||
|
// ino.module.LocalOrFieldVar.8637.import
|
|||
|
import java.util.Enumeration;
|
|||
|
import java.util.Hashtable;
|
|||
|
import java.util.Vector;
|
|||
|
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.myexception.SCExcept;
|
|||
|
import mycompiler.myexception.SCStatementException;
|
|||
|
import mycompiler.mytype.GenericTypeVar;
|
|||
|
import mycompiler.mytype.RefType;
|
|||
|
import mycompiler.mytype.Type;
|
|||
|
import mycompiler.mytype.TypePlaceholder;
|
|||
|
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.CTypeAssumption;
|
|||
|
import mycompiler.mytypereconstruction.typeassumptionkey.CInstVarKey;
|
|||
|
import mycompiler.mytypereconstruction.typeassumptionkey.CLocalVarKey;
|
|||
|
import org.apache.log4j.Logger;
|
|||
|
// ino.end
|
|||
|
|
|||
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
|||
|
import typinferenz.JavaCodeResult;
|
|||
|
import typinferenz.SingleConstraint;
|
|||
|
import typinferenz.ConstraintsSet;
|
|||
|
import typinferenz.FreshTypeVariable;
|
|||
|
import typinferenz.ResultSet;
|
|||
|
import typinferenz.TypeAssumptions;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// ino.class.LocalOrFieldVar.25503.declaration
|
|||
|
public class LocalOrFieldVar extends Expr
|
|||
|
// ino.end
|
|||
|
// ino.class.LocalOrFieldVar.25503.body
|
|||
|
{
|
|||
|
|
|||
|
// ino.attribute.parserlog.25507.declaration
|
|||
|
protected static Logger parserlog = Logger.getLogger("parser");
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.LocalOrFieldVar.25510.definition
|
|||
|
public LocalOrFieldVar(int offset, int variableLength)
|
|||
|
// ino.end
|
|||
|
// ino.method.LocalOrFieldVar.25510.body
|
|||
|
{
|
|||
|
super(offset,variableLength);
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.LocalOrFieldVar.25513.definition
|
|||
|
public LocalOrFieldVar(String n, int offset)
|
|||
|
// ino.end
|
|||
|
// ino.method.LocalOrFieldVar.25513.body
|
|||
|
{
|
|||
|
super(offset,n.length());
|
|||
|
usedid = new UsedId(offset);
|
|||
|
usedid.set_Name(n);
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.sc_check.25516.definition
|
|||
|
public void sc_check(Vector<Class> classname, Hashtable ch, Hashtable<String, String> bh, boolean ext, Hashtable parach, Hashtable<String, Hashtable> parabh)
|
|||
|
throws SCStatementException
|
|||
|
// ino.end
|
|||
|
// ino.method.sc_check.25516.body
|
|||
|
{
|
|||
|
Vector<String> typen = new Vector<String>();
|
|||
|
SCStatementException except=null;
|
|||
|
Vector name = usedid.get_Name();
|
|||
|
Class klasse = null;
|
|||
|
Class hilfe = null;
|
|||
|
String hilfstr;
|
|||
|
Hashtable parahilf=null;
|
|||
|
for(Enumeration el = name.elements(); el.hasMoreElements();)
|
|||
|
{
|
|||
|
String name1 = (String) el.nextElement();
|
|||
|
if(klasse!=null) //hier geht's rein, wenn eine Instanzvariable gefunden wurde
|
|||
|
{
|
|||
|
if(!el.hasMoreElements()) //es folgen keine weiteren Strings mehr -> name1 muss der Variablen-Name sein.
|
|||
|
{
|
|||
|
this.setType(new Type(klasse.is_member(name1),getOffset()));
|
|||
|
if(klasse.get_ParaHash().containsKey(name1))
|
|||
|
{
|
|||
|
/* Typ der Klasse ist parametrisierbar, nach Zuweisung schauen */
|
|||
|
if(parahilf!=null){
|
|||
|
this.setType((Type)parahilf.get(name1));
|
|||
|
for(Enumeration e3=parahilf.keys();e3.hasMoreElements();)
|
|||
|
{
|
|||
|
// System.out.println("parahilf.typen "+ (String)e3.nextElement());
|
|||
|
// System.out.print("+++++++++ "+type.get_Type()+" ");
|
|||
|
parserlog.debug(string_rec(parahilf));
|
|||
|
// System.out.println();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if(this.getType().getName()==null)
|
|||
|
{
|
|||
|
SCExcept exc = new SCExcept();
|
|||
|
except = new SCStatementException();
|
|||
|
exc.set_error("Variable "+name1+" nicht gefunden");
|
|||
|
exc.set_statement("LocalOrFieldVar");
|
|||
|
except.addException(exc);
|
|||
|
throw except;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
typen.addElement(this.getType().getName());
|
|||
|
}
|
|||
|
}
|
|||
|
else //es folgen Strings -> weitere Klassen m<>ssen auf die Variable <20>berpr<70>ft werden
|
|||
|
{
|
|||
|
this.setType(new Type(klasse.is_member(name1),getOffset()));
|
|||
|
if( this.getType().getName() == null )
|
|||
|
{
|
|||
|
SCExcept exc=new SCExcept();
|
|||
|
except=new SCStatementException();
|
|||
|
exc.set_error("Variable "+name1+" nicht gefunden");
|
|||
|
exc.set_statement("LocalOrFieldVar");
|
|||
|
except.addException(exc);
|
|||
|
throw except;
|
|||
|
}
|
|||
|
else{
|
|||
|
typen.addElement(this.getType().getName());
|
|||
|
}
|
|||
|
for(Enumeration<Class> el1 = classname.elements();el1.hasMoreElements();){
|
|||
|
hilfe=el1.nextElement();
|
|||
|
hilfstr=hilfe.getName();
|
|||
|
|
|||
|
if(this.getType().getName().equals(hilfstr)){
|
|||
|
klasse = hilfe; }
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else if(!el.hasMoreElements()) //es steht nur der Variablenname im Vector name,
|
|||
|
{ //also MUSS die Variable in dieser Klasse deklariert sein
|
|||
|
if(bh.containsKey(name1))
|
|||
|
{
|
|||
|
this.setType(new Type( (String)bh.get(name1),getOffset()));
|
|||
|
typen.addElement(this.getType().getName());
|
|||
|
if(bh.containsKey(name1))
|
|||
|
{
|
|||
|
// System.out.println("type enthalten in bh: "+name1+ " - " +type.get_Type());
|
|||
|
}
|
|||
|
/************/
|
|||
|
if(parabh.containsKey(name1))
|
|||
|
{
|
|||
|
parahilf = (Hashtable) parabh.get(name1);
|
|||
|
parserlog.debug(string_rec(parahilf));
|
|||
|
}
|
|||
|
}
|
|||
|
else if(ch.containsKey(name1))
|
|||
|
{
|
|||
|
this.setType(new Type((String)ch.get(name1),getOffset()));
|
|||
|
typen.addElement(this.getType().getName());
|
|||
|
if(ch.contains(this.getType().getName()))
|
|||
|
{
|
|||
|
// System.out.println("type enthalten in ch: " + name1 + " - " +type.get_Type());
|
|||
|
}
|
|||
|
|
|||
|
if(parach.containsKey(name1))
|
|||
|
{
|
|||
|
parahilf = (Hashtable) parach.get(name1);
|
|||
|
// System.out.print("parahilf: "); string_rec(parahilf); System.out.println();
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SCExcept exc=new SCExcept();
|
|||
|
except=new SCStatementException();
|
|||
|
exc.set_error("Variable "+name1+" nicht gefunden");
|
|||
|
exc.set_statement("LocalOrFieldVar");
|
|||
|
except.addException(exc);
|
|||
|
throw except;
|
|||
|
}
|
|||
|
}
|
|||
|
else //es folgen Strings im Vector, also handelt es sich um eine Instanzvar.
|
|||
|
{ //wir m<>ssen in Blockhash und Classhash nach der zugeh<65>rigen Klasse suchen.
|
|||
|
if(bh.containsKey(name1))
|
|||
|
{
|
|||
|
this.setType(new Type((String)bh.get(name1),getOffset())); //Attribut "type" von Basisklasse Expr
|
|||
|
|
|||
|
for(Enumeration<Class> el1 = classname.elements();el1.hasMoreElements();)
|
|||
|
{
|
|||
|
hilfe = el1.nextElement();
|
|||
|
hilfstr = hilfe.getName();
|
|||
|
if(this.getType().getName().equals(hilfstr)){
|
|||
|
klasse = hilfe;}
|
|||
|
}
|
|||
|
typen.addElement(this.getType().getName());
|
|||
|
|
|||
|
if(bh.containsKey(name1))
|
|||
|
parserlog.debug("type enthalten in bh: "+name1+ " - " + this.getType().getName() );
|
|||
|
/***********************/
|
|||
|
if(parabh.containsKey(name1)){
|
|||
|
parahilf = (Hashtable) parabh.get(name1);
|
|||
|
// System.out.print("parahilf: "); string_rec(parahilf); System.out.println();
|
|||
|
}
|
|||
|
}
|
|||
|
else if(ch.containsKey(name1))
|
|||
|
{
|
|||
|
this.setType(new Type((String)ch.get(name1),getOffset())); //Attribut "type" von Basisklasse Expr
|
|||
|
for(Enumeration<Class> el1 = classname.elements();el1.hasMoreElements();)
|
|||
|
{
|
|||
|
hilfe = el1.nextElement();
|
|||
|
hilfstr = hilfe.getName();
|
|||
|
parserlog.debug(this.getType().getName()+" ********* "+hilfstr);
|
|||
|
if(this.getType().getName().equals(hilfstr)){
|
|||
|
klasse = hilfe;}
|
|||
|
}
|
|||
|
typen.addElement(this.getType().getName());
|
|||
|
|
|||
|
if(ch.containsKey(name1))
|
|||
|
{
|
|||
|
// System.out.println("type enthalten in ch: "+name1+ " - " +type.get_Type());
|
|||
|
}
|
|||
|
/*****************/
|
|||
|
if(parach.containsKey(name1)){
|
|||
|
parahilf = (Hashtable) parach.get(name1);
|
|||
|
// System.out.print("parahilf: "); string_rec(parahilf); System.out.println();
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SCExcept exc=new SCExcept();
|
|||
|
except=new SCStatementException();
|
|||
|
exc.set_error("Variable "+name1+" nicht gefunden");
|
|||
|
exc.set_statement("LocalOrFieldVar");
|
|||
|
except.addException(exc);
|
|||
|
throw except;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
usedid.set_Typen(typen);
|
|||
|
parserlog.debug("SC -> Semantik-Check in LocalOrFieldVar erfolgreich!");
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.set_UsedId.25519.definition
|
|||
|
public void set_UsedId(UsedId u)
|
|||
|
// ino.end
|
|||
|
// ino.method.set_UsedId.25519.body
|
|||
|
{
|
|||
|
this.usedid=u;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// ino.method.get_Name.25522.definition
|
|||
|
public String get_Name()
|
|||
|
// ino.end
|
|||
|
// ino.method.get_Name.25522.body
|
|||
|
{
|
|||
|
return usedid.get_Name_1Element();
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// ino.method.codegen.25525.definition
|
|||
|
public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
|
|||
|
throws JVMCodeException
|
|||
|
// ino.end
|
|||
|
// ino.method.codegen.25525.body
|
|||
|
{
|
|||
|
Vector name_vector = get_Name_Vector();
|
|||
|
Vector type_vector = get_Type_Vector();
|
|||
|
String local_name = null;
|
|||
|
String class_name = null;
|
|||
|
String type = null;
|
|||
|
|
|||
|
for(int i=0; i < name_vector.size(); i++)
|
|||
|
{
|
|||
|
local_name = (String)name_vector.elementAt(i);
|
|||
|
try {// TEST SCJU. ArrayIndexoutofBounds umgehen!
|
|||
|
type = JVMCode.get_codegen_Type((String)type_vector.elementAt(i), paralist);
|
|||
|
} catch (Throwable e) {type = null; }
|
|||
|
|
|||
|
int index = code.get_indexOf_Var(local_name);
|
|||
|
if(index != -1)
|
|||
|
{
|
|||
|
// LocalVar
|
|||
|
try
|
|||
|
{
|
|||
|
String local_type = code.get_TypeOf_Var(local_name).getName();
|
|||
|
code.add_code(JVMCode.nload_n(local_type, index));
|
|||
|
}
|
|||
|
catch(JVMCodeException e)
|
|||
|
{
|
|||
|
// out of nstore_n
|
|||
|
String local_type = code.get_TypeOf_Var(local_name).getName();
|
|||
|
code.add_code(JVMCode.nload(local_type));
|
|||
|
code.add_code_byte((byte)index);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// FieldVar
|
|||
|
code.add_code(JVMCode.aload_0);
|
|||
|
code.add_code(JVMCode.getfield);
|
|||
|
code.add_code_short(classfile.add_field_ref(local_name, class_name, type));
|
|||
|
}
|
|||
|
try {
|
|||
|
// TEST SCJU. ArrayIndexoutofBounds umgehen!
|
|||
|
class_name = (String)type_vector.elementAt(i);
|
|||
|
} catch (Throwable e) { }
|
|||
|
}
|
|||
|
|
|||
|
// Falls noetig, Unboxing auf primitiven Typ!
|
|||
|
if (this.getTypeVariable() instanceof RefType) {
|
|||
|
RefType rt = (RefType) this.getTypeVariable();
|
|||
|
if (! rt.getPrimitiveFlag()) return;
|
|||
|
|
|||
|
if (rt.getName().equalsIgnoreCase("java.lang.Integer")) { // Int Unboxen
|
|||
|
code.add_code(JVMCode.invokevirtual);
|
|||
|
code.add_code_short(classfile.add_method_ref("java/lang/Integer", "intValue", "()I"));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.TRExp.25528.defdescription type=javadoc
|
|||
|
/**
|
|||
|
* Implementierung des Algorithmus 5.37 von Martin Pl<EFBFBD>micke
|
|||
|
* <br/>Author: J<EFBFBD>rg B<EFBFBD>uerle
|
|||
|
* @param sigma
|
|||
|
* @param V
|
|||
|
* @param supportData
|
|||
|
* @return
|
|||
|
*/
|
|||
|
// ino.end
|
|||
|
// ino.method.TRExp.25528.definition
|
|||
|
public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
|
|||
|
// ino.end
|
|||
|
// ino.method.TRExp.25528.body
|
|||
|
{
|
|||
|
CTypeAssumption assum = null;
|
|||
|
// --------------------------
|
|||
|
// Lokale Variable aufsteigend
|
|||
|
// in den Bl<42>cken suchen:
|
|||
|
// --------------------------
|
|||
|
for(int depth=supportData.getCurrentBlockDepth(); assum==null && depth>0; depth--){
|
|||
|
CLocalVarKey localKey = new CLocalVarKey(
|
|||
|
supportData.getCurrentClass(),
|
|||
|
supportData.getCurrentMethod(),
|
|||
|
supportData.getCurrentMethodParaCount(),
|
|||
|
supportData.getCurrentMethodOverloadedID(),
|
|||
|
supportData.getBlockId(depth),
|
|||
|
this.get_Name());
|
|||
|
assum = V.getElement(localKey);
|
|||
|
}
|
|||
|
// --------------------------
|
|||
|
// Falls keine gefunden, Feldvariable suchen:
|
|||
|
// --------------------------
|
|||
|
if(assum==null){
|
|||
|
CInstVarKey instKey = new CInstVarKey(
|
|||
|
supportData.getCurrentClass(),
|
|||
|
this.get_Name());
|
|||
|
assum = V.getElement(instKey);
|
|||
|
}
|
|||
|
//--------------------------
|
|||
|
// Falls nichts gefunden:
|
|||
|
// --------------------------
|
|||
|
if(assum==null){
|
|||
|
//--------------------------
|
|||
|
// 15.04.2007 feda
|
|||
|
// Wenn nichts gefunden dann neuen Typ anlegen. Verdacht auf Klassenmethode mit static
|
|||
|
//--------------------------
|
|||
|
CTripleSet retSet = new CTripleSet();
|
|||
|
retSet.addElement(new CTriple(sigma, new RefType(this.get_Name(),this.getOffset()) , V));
|
|||
|
CTripleSet retSet2 = super.registerType(retSet, supportData);
|
|||
|
return retSet2;
|
|||
|
}else{
|
|||
|
//--------------------------
|
|||
|
// Ergebnismenge bauen:
|
|||
|
// --------------------------
|
|||
|
CTripleSet retSet = new CTripleSet();
|
|||
|
retSet.addElement(new CTriple(sigma, assum.getAssumedType(), V));
|
|||
|
CTripleSet retSet2 = super.registerType(retSet, supportData);
|
|||
|
return retSet2;
|
|||
|
}
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
// ino.method.TRStatement.25531.definition
|
|||
|
public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
|
|||
|
// ino.end
|
|||
|
// ino.method.TRStatement.25531.body
|
|||
|
{
|
|||
|
throw CTypeReconstructionException.createNotImplementedException();
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.toString.25534.defdescription type=javadoc
|
|||
|
/**
|
|||
|
* <br/>Author: Martin Pl<EFBFBD>micke
|
|||
|
* @return
|
|||
|
*/
|
|||
|
// ino.end
|
|||
|
// ino.method.toString.25534.definition
|
|||
|
public String toString()
|
|||
|
// ino.end
|
|||
|
// ino.method.toString.25534.body
|
|||
|
{
|
|||
|
if(getTypeVariable()==null)return usedid.toString();
|
|||
|
return usedid.toString() + ": " + getTypeVariable().toString();
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.25537.definition
|
|||
|
public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist, Vector<GenericTypeVar> genericMethodParameters)
|
|||
|
// ino.end
|
|||
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.25537.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();
|
|||
|
//gibt es eine Assumption f<>r den die LocalOrFieldVar-Variablen, dann folgendes ausf<73>hren:
|
|||
|
Type thisTypeAssumption = assumptions.getVarType(this.get_Name());
|
|||
|
this.setTypeVariable(thisTypeAssumption);
|
|||
|
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
public String getTypeInformation(){
|
|||
|
return this.getTypeVariable()+" "+this.get_Name();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
@Override
|
|||
|
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|||
|
return new JavaCodeResult(this.get_Name());
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
// ino.end
|