forked from JavaTX/JavaCompilerCore
302 lines
11 KiB
Java
302 lines
11 KiB
Java
|
// ino.module.PostDecExpr.8646.package
|
|||
|
package mycompiler.mystatement;
|
|||
|
// ino.end
|
|||
|
// ino.module.PostDecExpr.8646.import
|
|||
|
import java.util.Hashtable;
|
|||
|
import java.util.Iterator;
|
|||
|
import java.util.Vector;
|
|||
|
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.RefType;
|
|||
|
import mycompiler.mytype.Type;
|
|||
|
import mycompiler.mytype.Void;
|
|||
|
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.unify.Unify;
|
|||
|
import org.apache.log4j.Logger;
|
|||
|
// ino.end
|
|||
|
|
|||
|
import typinferenz.ConstraintsSet;
|
|||
|
import typinferenz.JavaCodeResult;
|
|||
|
import typinferenz.ResultSet;
|
|||
|
import typinferenz.TypeAssumptions;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// ino.class.PostDecExpr.25987.declaration
|
|||
|
public class PostDecExpr extends UnaryExpr
|
|||
|
// ino.end
|
|||
|
// ino.class.PostDecExpr.25987.body
|
|||
|
{
|
|||
|
// ino.method.PostDecExpr.25991.definition
|
|||
|
public PostDecExpr(int offset,int variableLength)
|
|||
|
// ino.end
|
|||
|
// ino.method.PostDecExpr.25991.body
|
|||
|
{
|
|||
|
super(offset,variableLength);
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
// ino.attribute.expr.25994.declaration
|
|||
|
public Expr expr;
|
|||
|
// ino.end
|
|||
|
// ino.attribute.parserlog.25997.declaration
|
|||
|
protected static Logger parserlog = Logger.getLogger("parser");
|
|||
|
// ino.end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// ino.method.set_Expr.26000.definition
|
|||
|
public void set_Expr(Expr ex)
|
|||
|
// ino.end
|
|||
|
// ino.method.set_Expr.26000.body
|
|||
|
{
|
|||
|
this.expr = ex;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.get_Name.26003.definition
|
|||
|
public String get_Name()
|
|||
|
// ino.end
|
|||
|
// ino.method.get_Name.26003.body
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.sc_check.26006.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.26006.body
|
|||
|
{
|
|||
|
SCStatementException ex=null;
|
|||
|
if(ext)
|
|||
|
parserlog.debug(" ---PostDecExpr---");
|
|||
|
try
|
|||
|
{
|
|||
|
expr.sc_check(classname,ch,bh,ext,parach, parabh);
|
|||
|
this.setType(new Type(expr.getTypeName(),getOffset()));
|
|||
|
}
|
|||
|
catch (SCStatementException except)
|
|||
|
{
|
|||
|
ex=except;
|
|||
|
}
|
|||
|
if(this.getType()==null)
|
|||
|
{
|
|||
|
if(ext)
|
|||
|
parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! --- NoTypeDefError :-)");
|
|||
|
if(ex==null)
|
|||
|
ex=new SCStatementException();
|
|||
|
SCExcept exc = new SCExcept();
|
|||
|
exc.set_error("Kein Typ vorhanden - NoTypeDefError");
|
|||
|
exc.set_statement("PostDecExpr");
|
|||
|
ex.addException(exc);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if(!this.getType().getName().equals("int"))
|
|||
|
{
|
|||
|
if (ext)
|
|||
|
parserlog.error("Semantik-Check hat einen Typ-Fehler gefunden!!! -- wird auf anderen Typ als int angewendet.");
|
|||
|
SCExcept exc = new SCExcept();
|
|||
|
exc.set_error("-- Operator wird auf "+this.getType()+" angewendet.");
|
|||
|
exc.set_statement("PostDecExpr");
|
|||
|
if(ex==null)
|
|||
|
ex = new SCStatementException();
|
|||
|
ex.addException(exc);
|
|||
|
}
|
|||
|
}
|
|||
|
if(ex!=null)
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.codegen.26009.definition
|
|||
|
public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
|
|||
|
throws JVMCodeException
|
|||
|
// ino.end
|
|||
|
// ino.method.codegen.26009.body
|
|||
|
{
|
|||
|
if(expr instanceof LocalOrFieldVar) {
|
|||
|
String local_name = (String)((LocalOrFieldVar)expr).get_Name_Vector().lastElement();
|
|||
|
|
|||
|
int index = code.get_indexOf_Var(local_name);
|
|||
|
if(index != -1) {
|
|||
|
code.add_code(JVMCode.iinc);
|
|||
|
code.add_code_byte(index);
|
|||
|
code.add_code_byte(-1);
|
|||
|
}
|
|||
|
else {
|
|||
|
if(expr instanceof LocalOrFieldVar) {
|
|||
|
LocalOrFieldVar local = (LocalOrFieldVar)expr;
|
|||
|
Vector name_vector = local.get_Name_Vector();
|
|||
|
Vector type_vector = local.get_Type_Vector();
|
|||
|
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);
|
|||
|
|
|||
|
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);
|
|||
|
}
|
|||
|
|
|||
|
local_name = (String)name_vector.lastElement();
|
|||
|
index = classfile.add_field_ref(local_name, class_name, JVMCode.get_codegen_Type("int", paralist));
|
|||
|
|
|||
|
code.add_code(JVMCode.dup);
|
|||
|
code.add_code(JVMCode.getfield);
|
|||
|
code.add_code_short(index);
|
|||
|
code.add_code(JVMCode.iconst_1);
|
|||
|
code.add_code(JVMCode.isub);
|
|||
|
code.add_code(JVMCode.putfield);
|
|||
|
code.add_code_short(index);
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else if(expr instanceof InstVar) {
|
|||
|
InstVar instvar = (InstVar)expr;
|
|||
|
String instvar_name = instvar.get_codegen_UsedId();
|
|||
|
int index = classfile.add_field_ref(instvar_name, null, null);
|
|||
|
code.add_code(JVMCode.aload_0);
|
|||
|
code.add_code(JVMCode.dup);
|
|||
|
code.add_code(JVMCode.getfield);
|
|||
|
code.add_code_short(index);
|
|||
|
code.add_code(JVMCode.iconst_1);
|
|||
|
code.add_code(JVMCode.isub);
|
|||
|
code.add_code(JVMCode.putfield);
|
|||
|
code.add_code_short(index);
|
|||
|
}
|
|||
|
else throw new JVMCodeException("JVMCodeException: PostDecExpr: void codegen(ClassFile classfile, Code_attribute code)");
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.TRExp.26012.defdescription type=javadoc
|
|||
|
/**
|
|||
|
* Achtung Workaround: RefType "Integer" sollte irgendwann gegen BaseType
|
|||
|
* <code>IntegerType</code> ausgetauscht werden.
|
|||
|
* <br/>Author: J<EFBFBD>rg B<EFBFBD>uerle
|
|||
|
* @param sigma
|
|||
|
* @param V
|
|||
|
* @param supportData
|
|||
|
* @return
|
|||
|
*/
|
|||
|
// ino.end
|
|||
|
// ino.method.TRExp.26012.definition
|
|||
|
public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
|
|||
|
// ino.end
|
|||
|
// ino.method.TRExp.26012.body
|
|||
|
{
|
|||
|
CTripleSet returnSet = new CTripleSet();
|
|||
|
// --------------------------
|
|||
|
// TRExpr f<>r Expr rufen:
|
|||
|
// --------------------------
|
|||
|
CTripleSet exprSet = expr.TRExp(sigma, V, supportData);
|
|||
|
// --------------------------
|
|||
|
// Alle Triple durchgehen:
|
|||
|
// --------------------------
|
|||
|
Iterator<CTriple> exprIt = exprSet.getIterator();
|
|||
|
while(exprIt.hasNext()){
|
|||
|
CTriple exprTriple = exprIt.next();
|
|||
|
// --------------------------
|
|||
|
// ReturnType mit Integer unifizieren:
|
|||
|
// --------------------------
|
|||
|
Vector<Vector<Pair>> unifierPossibilities = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Integer",getOffset()), 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 intTriple = exprTriple.cloneAndApplyUnify(unifier);
|
|||
|
subSet.addElement(intTriple);
|
|||
|
}
|
|||
|
returnSet.unite(subSet);
|
|||
|
}
|
|||
|
}
|
|||
|
if(returnSet.getCardinality()==0){
|
|||
|
throw new CTypeReconstructionException("PostDecExpr.TRExp(): Keiner der m<>glichen Typen l<>sst sich mit Typ \"Integer\" unifizieren.",this);
|
|||
|
}
|
|||
|
return returnSet;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
// ino.method.TRStatement.26015.definition
|
|||
|
public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData)
|
|||
|
// ino.end
|
|||
|
// ino.method.TRStatement.26015.body
|
|||
|
{
|
|||
|
CTripleSet tripleSet = this.TRExp(sigma, V, supportData).deepCopy();
|
|||
|
Iterator<CTriple> tripleIt = tripleSet.getIterator();
|
|||
|
while(tripleIt.hasNext()){
|
|||
|
tripleIt.next().setResultType(new Void(getOffset()));
|
|||
|
}
|
|||
|
return tripleSet;
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.26018.definition
|
|||
|
public void wandleRefTypeAttributes2GenericAttributes(Vector<Type> paralist, Vector<GenericTypeVar> genericMethodParameters)
|
|||
|
// ino.end
|
|||
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.26018.body
|
|||
|
{
|
|||
|
}
|
|||
|
// ino.end
|
|||
|
|
|||
|
public void addOffsetsToExpression(CTypeAssumption localAssumption,String NameVariable,boolean isMemberVariable)
|
|||
|
{
|
|||
|
expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable);
|
|||
|
}
|
|||
|
|
|||
|
@Override
|
|||
|
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
|||
|
// TODO Auto-generated method stub
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
@Override
|
|||
|
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|||
|
// TODO Auto-generated method stub
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
// ino.end
|