// ino.module.PreIncExpr.8649.package package mycompiler.mystatement; // ino.end // ino.module.PreIncExpr.8649.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.PreIncExpr.26089.declaration public class PreIncExpr extends UnaryExpr // ino.end // ino.class.PreIncExpr.26089.body { // ino.method.PreIncExpr.26093.definition public PreIncExpr(int offset,int variableLength) // ino.end // ino.method.PreIncExpr.26093.body { super(offset,variableLength); } // ino.end // ino.attribute.expr.26096.declaration public Expr expr; // ino.end // ino.attribute.parserlog.26099.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end // ino.method.set_Expr.26102.definition public void set_Expr(Expr ex) // ino.end // ino.method.set_Expr.26102.body { this.expr = ex; } // ino.end // ino.method.get_Name.26105.definition public String get_Name() // ino.end // ino.method.get_Name.26105.body { return null; } // ino.end // ino.method.sc_check.26108.definition public void sc_check(Vector classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) throws SCStatementException // ino.end // ino.method.sc_check.26108.body { SCStatementException ex=null; if(ext) parserlog.debug(" ---PreIncExpr---"); 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().getName()==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("PreIncExpr"); 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("PreIncExpr"); if(ex==null) ex = new SCStatementException(); ex.addException(exc); } } if(ex!=null) throw ex; } // ino.end // ino.method.codegen.26111.definition public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) throws JVMCodeException // ino.end // ino.method.codegen.26111.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.iadd); 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.iadd); code.add_code(JVMCode.putfield); code.add_code_short(index); } else throw new JVMCodeException("JVMCodeException: PreIncExpr: void codegen(ClassFile classfile, Code_attribute code)"); } // ino.end // ino.method.TRExp.26114.defdescription type=javadoc /** * Achtung Workaround: RefType "Integer" sollte irgendwann gegen BaseType * IntegerType ausgetauscht werden. *
Author: J�rg B�uerle * @param sigma * @param V * @param supportData * @return */ // ino.end // ino.method.TRExp.26114.definition public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) // ino.end // ino.method.TRExp.26114.body { CTripleSet returnSet = new CTripleSet(); // -------------------------- // TRExpr f�r Expr rufen: // -------------------------- CTripleSet exprSet = expr.TRExp(sigma, V, supportData); // -------------------------- // Alle Triple durchgehen: // -------------------------- Iterator exprIt = exprSet.getIterator(); while(exprIt.hasNext()){ CTriple exprTriple = exprIt.next(); // -------------------------- // ReturnType mit Integer unifizieren: // -------------------------- Vector> unifierPossibilities = Unify.unify(exprTriple.getResultType(), new RefType("java.lang.Integer",getOffset()), supportData.getFiniteClosure()); // -------------------------- // Wenn Unifier vorhanden, dann // anwenden und Triple hinzuf�gen: // -------------------------- if(unifierPossibilities.size()!=0){ // -------------------------- // Subset bauen: // -------------------------- CTripleSet subSet = new CTripleSet(); // -------------------------- // Alle m�glichen Unifier anwenden: // -------------------------- for(int i=0; i tripleIt = tripleSet.getIterator(); while(tripleIt.hasNext()){ tripleIt.next().setResultType(new Void(getOffset())); } return tripleSet; } // ino.end // ino.method.wandleRefTypeAttributes2GenericAttributes.26120.definition public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) // ino.end // ino.method.wandleRefTypeAttributes2GenericAttributes.26120.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