forked from JavaTX/JavaCompilerCore
278 lines
8.9 KiB
Java
Executable File
278 lines
8.9 KiB
Java
Executable File
// ino.module.Assign.8622.package
|
||
package mycompiler.mystatement;
|
||
// ino.end
|
||
// ino.module.Assign.8622.import
|
||
import java.util.Enumeration;
|
||
import java.util.Hashtable;
|
||
import java.util.Iterator;
|
||
import java.util.Vector;
|
||
|
||
import mycompiler.SyntaxTreeNode;
|
||
import mycompiler.mybytecode.ClassFile;
|
||
import mycompiler.mybytecode.CodeAttribute;
|
||
import mycompiler.mybytecode.JVMCode;
|
||
import mycompiler.myclass.Class;
|
||
import mycompiler.myexception.CTypeReconstructionException;
|
||
import mycompiler.myexception.JVMCodeException;
|
||
import mycompiler.myexception.SCExcept;
|
||
import mycompiler.myexception.SCStatementException;
|
||
import mycompiler.mytype.GenericTypeVar;
|
||
import mycompiler.mytype.Pair;
|
||
import mycompiler.mytype.Type;
|
||
import mycompiler.mytype.TypePlaceholder;
|
||
import mycompiler.mytype.Void;
|
||
import mycompiler.mytypereconstruction.CMultiplyTuple;
|
||
import mycompiler.mytypereconstruction.CSupportData;
|
||
import mycompiler.mytypereconstruction.CTriple;
|
||
import mycompiler.mytypereconstruction.set.CMultiplyTupleSet;
|
||
import mycompiler.mytypereconstruction.set.CSubstitutionSet;
|
||
import mycompiler.mytypereconstruction.set.CTripleSet;
|
||
import mycompiler.mytypereconstruction.set.CTypeAssumptionSet;
|
||
import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption;
|
||
import mycompiler.mytypereconstruction.unify.Unify;
|
||
|
||
import org.apache.log4j.Logger;
|
||
|
||
|
||
// ino.end
|
||
import typinferenz.JavaCodeResult;
|
||
import typinferenz.SingleConstraint;
|
||
import typinferenz.ConstraintsSet;
|
||
import typinferenz.FreshTypeVariable;
|
||
import typinferenz.ResultSet;
|
||
import typinferenz.assumptions.TypeAssumptions;
|
||
|
||
|
||
|
||
|
||
// ino.class.Assign.24926.declaration
|
||
public class Assign extends Expr
|
||
// ino.end
|
||
// ino.class.Assign.24926.body
|
||
{
|
||
// ino.method.Assign.24930.definition
|
||
public Assign(int offset,int variableLength)
|
||
// ino.end
|
||
// ino.method.Assign.24930.body
|
||
{
|
||
super(offset,variableLength);
|
||
}
|
||
// ino.end
|
||
|
||
|
||
// ino.attribute.expr1.24933.declaration
|
||
public Expr expr1;
|
||
// ino.end
|
||
// ino.attribute.expr2.24936.declaration
|
||
public Expr expr2;
|
||
// ino.end
|
||
|
||
// ino.attribute.parserlog.24939.decldescription type=javadoc
|
||
/**
|
||
* Logger log4j
|
||
*/
|
||
// ino.end
|
||
// ino.attribute.parserlog.24939.declaration
|
||
protected static Logger parserlog = Logger.getLogger("parser");
|
||
// ino.end
|
||
|
||
|
||
// ino.method.set_Expr.24942.definition
|
||
public void set_Expr(Expr expr1,Expr expr2)
|
||
// ino.end
|
||
// ino.method.set_Expr.24942.body
|
||
{
|
||
this.expr1 = expr1;
|
||
this.expr2 = expr2;
|
||
}
|
||
// ino.end
|
||
|
||
|
||
|
||
|
||
|
||
// ino.method.get_Name.24948.definition
|
||
public String get_Name()
|
||
// ino.end
|
||
// ino.method.get_Name.24948.body
|
||
{
|
||
return null;
|
||
}
|
||
// ino.end
|
||
|
||
|
||
|
||
// ino.method.codegen.24951.definition
|
||
public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
|
||
throws JVMCodeException
|
||
// ino.end
|
||
// ino.method.codegen.24951.body
|
||
{
|
||
// AutoBoxing-Feature: Literale koennen nur als Objekt zugewiesen werden
|
||
if (expr2 instanceof Literal) ((Literal)expr2).setPrimitiveFlag(false);
|
||
|
||
|
||
if(expr1 instanceof LocalOrFieldVar)
|
||
{
|
||
LocalOrFieldVar local = (LocalOrFieldVar)expr1;
|
||
Vector name_vector = local.get_Name_Vector();
|
||
Vector type_vector = local.get_Type_Vector();
|
||
String local_name = null;
|
||
String class_name = null;
|
||
String type = null;
|
||
for(int i=0; i < name_vector.size()-1; i++)
|
||
{
|
||
local_name = (String)name_vector.elementAt(i);
|
||
type = JVMCode.get_codegen_Type((String)type_vector.elementAt(i), paralist);
|
||
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 nload_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));
|
||
}
|
||
class_name = (String)type_vector.elementAt(i);
|
||
}
|
||
expr2.codegen(classfile, code, paralist);
|
||
local_name = (String)name_vector.lastElement();
|
||
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.nstore_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.nstore(local_type));
|
||
code.add_code_byte((byte)index);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// FieldVar
|
||
code.add_code(JVMCode.putfield);
|
||
code.add_code_short(classfile.add_field_ref(local_name, class_name, JVMCode.get_codegen_Type(expr2.getTypeName(), paralist)));
|
||
}
|
||
}
|
||
else if(expr1 instanceof InstVar)
|
||
{
|
||
InstVar instvar = (InstVar)expr1;
|
||
String instvar_name = instvar.get_codegen_UsedId();
|
||
code.add_code(JVMCode.aload_0);
|
||
expr2.codegen(classfile, code, paralist);
|
||
code.add_code(JVMCode.putfield);
|
||
code.add_code_short(classfile.add_field_ref(instvar_name, null, null));
|
||
}
|
||
else throw new JVMCodeException("JVMCodeException: Assign: void test codegen(ClassFile classfile, Code_attribute code)");
|
||
}
|
||
// ino.end
|
||
|
||
/**
|
||
* @author AI10023 - Andreas Stadelmeier
|
||
*/
|
||
@Override
|
||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||
ConstraintsSet ret = new ConstraintsSet();
|
||
ret.add(expr1.TYPEExpr(assumptions));
|
||
ret.add(expr2.TYPEExpr(assumptions));
|
||
//this.setTypeVariable( TypePlaceholder.fresh(this));
|
||
this.setType(TypePlaceholder.fresh(this));
|
||
ret.add(new SingleConstraint(expr2.getType(), expr1.getType())); //expr2.type <. expr1.type
|
||
ret.add(new SingleConstraint(expr1.getType(), this.getType()));
|
||
return ret;
|
||
}
|
||
|
||
/**
|
||
* Spezifikation:
|
||
* TYPEStmt( Ass, stmt ) =
|
||
* let (stmt : rty, ConS) = TYPEExpr( Ass, stmt )
|
||
* in (stmt : Void, ConS)
|
||
*/
|
||
@Override
|
||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){
|
||
ConstraintsSet ret = this.TYPEExpr(assumptions); //TypeExpr aufrufen
|
||
this.setType(new Void(0)); //Typ des Statments auf Void setzen.
|
||
return ret;
|
||
}
|
||
|
||
|
||
|
||
// ino.method.toString.24960.defdescription type=javadoc
|
||
/**
|
||
* <br/>Author: Martin Pl<50>micke
|
||
* @return
|
||
*/
|
||
// ino.end
|
||
// ino.method.toString.24960.definition
|
||
public String toString()
|
||
// ino.end
|
||
// ino.method.toString.24960.body
|
||
{
|
||
if(getType() == null)return "(" + expr1.toString() + " = " + expr2.toString() + ")";
|
||
return getType().toString() + "(" + expr1.toString() + " = " + expr2.toString() + ")";
|
||
}
|
||
// ino.end
|
||
|
||
|
||
// ino.method.wandleRefTypeAttributes2GenericAttributes.24963.definition
|
||
public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist, Vector<GenericTypeVar> genericMethodParameters)
|
||
// ino.end
|
||
// ino.method.wandleRefTypeAttributes2GenericAttributes.24963.body
|
||
{
|
||
}
|
||
// ino.end
|
||
|
||
public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable)
|
||
{
|
||
expr1.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable);
|
||
expr2.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable);
|
||
}
|
||
|
||
@Override
|
||
public String getTypeInformation(){
|
||
return "(" + expr1.getTypeInformation() + " = " + expr2.getTypeInformation() + ") : "+this.getType();
|
||
}
|
||
|
||
@Override
|
||
public JavaCodeResult printJavaCode(ResultSet resultSet){
|
||
JavaCodeResult ret = new JavaCodeResult().attach(this.expr1.printJavaCode(resultSet) ).attach( " = " ).attach( this.expr2.printJavaCode(resultSet));
|
||
return ret;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
@Override
|
||
public Vector<SyntaxTreeNode> getChildren() {
|
||
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
||
ret.add(this.expr1);
|
||
ret.add(this.expr2);
|
||
return ret;
|
||
}
|
||
|
||
}
|
||
// ino.end
|