2013-10-18 11:33:46 +00:00
|
|
|
|
// ino.module.LocalOrFieldVar.8637.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.LocalOrFieldVar.8637.import
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.Hashtable;
|
|
|
|
|
import java.util.Vector;
|
2014-02-09 15:07:31 +00:00
|
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
|
import org.apache.log4j.Logger;
|
2014-09-04 14:35:44 +00:00
|
|
|
|
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.myexception.SCExcept;
|
|
|
|
|
import de.dhbwstuttgart.myexception.SCStatementException;
|
2014-09-02 08:33:54 +00:00
|
|
|
|
import de.dhbwstuttgart.syntaxtree.Class;
|
2014-09-04 14:35:44 +00:00
|
|
|
|
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
2014-09-02 08:33:54 +00:00
|
|
|
|
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.ResultSet;
|
|
|
|
|
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
|
|
|
|
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
|
|
|
|
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
2014-09-05 09:49:31 +00:00
|
|
|
|
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
|
2013-10-18 11:33:46 +00:00
|
|
|
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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.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
|
|
|
|
|
{
|
2014-09-02 16:49:19 +00:00
|
|
|
|
String local_type = code.get_TypeOf_Var(local_name).getName().toString();
|
2013-10-18 11:33:46 +00:00
|
|
|
|
code.add_code(JVMCode.nload_n(local_type, index));
|
|
|
|
|
}
|
|
|
|
|
catch(JVMCodeException e)
|
|
|
|
|
{
|
|
|
|
|
// out of nstore_n
|
2014-09-02 16:49:19 +00:00
|
|
|
|
String local_type = code.get_TypeOf_Var(local_name).getName().toString();
|
2013-10-18 11:33:46 +00:00
|
|
|
|
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!
|
2014-02-11 15:30:38 +00:00
|
|
|
|
if (this.getType() instanceof RefType) {
|
|
|
|
|
RefType rt = (RefType) this.getType();
|
2013-10-18 11:33:46 +00:00
|
|
|
|
if (! rt.getPrimitiveFlag()) return;
|
|
|
|
|
|
2014-09-02 16:49:19 +00:00
|
|
|
|
if (rt.getName().toString().equalsIgnoreCase("java.lang.Integer")) { // Int Unboxen
|
2013-10-18 11:33:46 +00:00
|
|
|
|
code.add_code(JVMCode.invokevirtual);
|
|
|
|
|
code.add_code_short(classfile.add_method_ref("java/lang/Integer", "intValue", "()I"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 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
|
|
|
|
|
{
|
2014-02-11 15:30:38 +00:00
|
|
|
|
if(getType()==null)return usedid.toString();
|
|
|
|
|
return usedid.toString() + ": " + getType().toString();
|
2013-10-18 11:33:46 +00:00
|
|
|
|
}
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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:
|
2014-02-19 22:04:48 +00:00
|
|
|
|
Type thisTypeAssumption = assumptions.getVarType(this.get_Name(), this.getParentClass());
|
2014-04-15 12:56:20 +00:00
|
|
|
|
if(thisTypeAssumption == null)throw new TypeinferenceException("Eine Variable "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this);
|
2014-02-11 15:30:38 +00:00
|
|
|
|
this.setType(thisTypeAssumption);
|
2013-10-18 11:33:46 +00:00
|
|
|
|
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getTypeInformation(){
|
2014-02-11 15:30:38 +00:00
|
|
|
|
return this.getType()+" "+this.get_Name();
|
2013-10-18 11:33:46 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|
|
|
|
return new JavaCodeResult(this.get_Name());
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-22 03:58:49 +00:00
|
|
|
|
@Override
|
|
|
|
|
public Vector<SyntaxTreeNode> getChildren() {
|
|
|
|
|
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
|
}
|
|
|
|
|
// ino.end
|