// ino.module.NewClass.8642.package package mycompiler.mystatement; // ino.end // ino.module.NewClass.8642.import import java.util.Enumeration; 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.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.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.CParaTypeAssumption; import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; import org.apache.log4j.Logger; // ino.end import typinferenz.JavaCodeResult; import typinferenz.Overloading; import typinferenz.SingleConstraint; import typinferenz.ConstraintsSet; import typinferenz.FreshTypeVariable; import typinferenz.FunN; import typinferenz.ResultSet; import typinferenz.TypeAssumptions; // ino.class.NewClass.25830.declaration public class NewClass extends Expr // ino.end // ino.class.NewClass.25830.body { // ino.method.NewClass.25834.definition public NewClass(int offset,int variableLength) // ino.end // ino.method.NewClass.25834.body { super(offset,variableLength); } // ino.end // ino.attribute.arglist.25837.declaration private ArgumentList arglist; // ino.end // ino.attribute.parserlog.25840.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end // ino.method.getArgumentList.25843.definition public ArgumentList getArgumentList() // ino.end // ino.method.getArgumentList.25843.body { return this.arglist; } // ino.end // ino.method.get_Name.25846.definition public String get_Name() // ino.end // ino.method.get_Name.25846.body { return this.usedid.get_Name_1Element(); } // ino.end // ino.method.set_UsedId.25849.definition public void set_UsedId( UsedId t) // ino.end // ino.method.set_UsedId.25849.body { this.usedid = t; } // ino.end // ino.method.sc_check.25852.definition public void sc_check(Vector classname, Hashtable bh, Hashtable ch, boolean ext, Hashtable parach, Hashtable parabh) throws SCStatementException // ino.end // ino.method.sc_check.25852.body { if(ext) parserlog.debug(" ---NewClass---"); Class cl; String usedid = this.usedid.get_Name_1Element(); String next = null; for(Enumeration el = classname.elements(); el.hasMoreElements();) { cl = el.nextElement(); next = (String)cl.getName(); if(ext) parserlog.debug("Vergleiche "+usedid+" mit "+next); if(usedid.equals(next)) { this.set_Type(new Type(next,getOffset())); break; } else next = null; } if(next == null) { if(ext) parserlog.error("Typfehler --> NewClass.sc_check()" ); SCStatementException stex = new SCStatementException(); SCExcept ex = new SCExcept(); ex.set_error("Typfehler"); ex.set_statement("NewClass: Klasse "+usedid+" existiert nicht im Vector classname."); stex.addException(ex); throw stex; } if(ext) parserlog.debug("Klasse "+usedid+" im class-Vector gefunden"); } // ino.end // ino.method.set_ArgumentList.25855.definition public void set_ArgumentList(ArgumentList al) // ino.end // ino.method.set_ArgumentList.25855.body { this.arglist = al; } // ino.end // ino.method.codegen.25858.definition public void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) throws JVMCodeException // ino.end // ino.method.codegen.25858.body { String class_name = this.get_UsedId().get_codegen_UsedId(); String arg; // Argumentliste verarbeiten if (arglist != null) { arg = arglist.get_codegen_ArgumentList(paralist); } else { arg = "()"; } code.add_code(JVMCode.new_); code.add_code_short(classfile.add_CONSTANT_Class_info(class_name)); code.add_code(JVMCode.dup); // Vor invokespecial die Parameter auf den Stack legen if (arglist != null) { // Die einzelnen Argumente generieren for (int i=0; i< arglist.expr.size(); i++) { arglist.expr.elementAt(i).codegen(classfile, code, paralist); } } code.add_code(JVMCode.invokespecial); code.add_code_short(classfile.add_method_ref(class_name, "", arg + "V")); } // ino.end // ino.method.TRStatement.25861.defdescription type=javadoc /** * Implementierung des Algorithmus 5.26 von Martin Pl�micke *
Author: J�rg B�uerle * @param sigma * @param V * @param supportData * @return */ // ino.end // ino.method.TRStatement.25861.definition public CTripleSet TRStatement(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) // ino.end // ino.method.TRStatement.25861.body { CTripleSet returnSet = this.TRExp(sigma, V, supportData).deepCopy(); Iterator tripleIt = returnSet.getIterator(); while(tripleIt.hasNext()){ tripleIt.next().setResultType(new Void(getOffset())); } return returnSet; } // ino.end // ino.method.TRExp.25864.defdescription type=javadoc /** * Implementierung des Algorithmus 5.31 von Martin Pl�micke *
Author: J�rg B�uerle * @param sigma * @param V * @param supportData * @return */ // ino.end // ino.method.TRExp.25864.definition public CTripleSet TRExp(CSubstitutionSet sigma, CTypeAssumptionSet V, CSupportData supportData) // ino.end // ino.method.TRExp.25864.body { String constructorName = (String)this.usedid.getQualifiedName(); Vector typeParaList = this.usedid.get_RealParaList(); //eingefuegt 05-07-26 PL CTripleSet resultSet = new CTripleSet(); // -------------------------- // Standard-Konstruktor: // -------------------------- if(this.arglist==null || this.arglist.expr.size()==0){ //resultSet.addElement(new CTriple(sigma, new RefType(constructorName), V)); //eingefuegt 05-07-26 PL resultSet.addElement(new CTriple(sigma, new RefType(constructorName, typeParaList,getOffset()), V)); //return resultSet; 05-07-31 auskommentiert siehe nach else } // -------------------------- // Konstruktor mit Argumenten: // -------------------------- else { Vector expressions = new Vector(); if(this.arglist!=null){ expressions.addAll(this.arglist.expr); } // -------------------------- // TRTuple rufen: // -------------------------- CMultiplyTupleSet tupleSet = this.TRTuple(new CMultiplyTuple(sigma, new Vector(), V), expressions, supportData); Iterator tupleIt = tupleSet.getIterator(); Vector exceptions=new Vector(); int successfulls=0; while(tupleIt.hasNext()){ CMultiplyTuple tuple = tupleIt.next(); int paraCount = 0; if(this.arglist!=null){ paraCount = this.arglist.expr.size(); } MethodCall constructorCall=new MethodCall(getOffset(),getVariableLength()); try{ CTripleSet callAppSet = constructorCall.TRMCallApp(tuple, constructorName, "", paraCount, true, supportData); resultSet.unite(callAppSet); successfulls++; }catch(CTypeReconstructionException tre){ exceptions.addElement(tre); } } if(successfulls==0){ if(exceptions.size()==1){ throw exceptions.elementAt(0); } throw new CTypeReconstructionException("NewClass: Es konnte keine Assumption gefunden werden, die auf die Anforderung passt.",exceptions,this); } } //CTripleSet resultSet2 = super.unifyAndRegisterType(resultSet, supportData); CTripleSet resultSet2 = super.registerType(resultSet, supportData); return resultSet2; } // ino.end // ino.method.toString.25867.defdescription type=javadoc /** *
Author: Martin Pl�micke * @return */ // ino.end // ino.method.toString.25867.definition public String toString() // ino.end // ino.method.toString.25867.body { String ret = "NEW "; Type thisType = getTypeVariable(); if(thisType != null)ret += thisType.toString(); else ret += this.get_Name(); return ret; } // ino.end // ino.method.wandleRefTypeAttributes2GenericAttributes.25870.definition public void wandleRefTypeAttributes2GenericAttributes(Vector paralist, Vector genericMethodParameters) // ino.end // ino.method.wandleRefTypeAttributes2GenericAttributes.25870.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()); } if(this.getArgumentList()!=null){ for(Expr n : this.getArgumentList().expr) { n.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); }} } @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { //TODO: Das hier noch vervollständigen ConstraintsSet ret = new ConstraintsSet(); this.set_Type(TypePlaceholder.fresh(this)); //Die Auskommentierten Zeilen gehören zu MethodRefNew //Vector argumentTypeList = new Vector(); //for(Expr expr : this.arglist.expr){ // argumentTypeList.add(expr.getTypeVariable()); //} //FunN funN= new FunN(null,argumentTypeList); //Constraint newClassTypeConstraint = new Constraint(null,null); //ret.add(newClassTypeConstraint); if(this.arglist != null && this.arglist.expr != null)for(Expr arg : this.arglist.expr){ ret.add(arg.TYPEExpr(assumptions)); } //Ein new-Aufruf ist nichts anderes als ein MethodCall der Methode MethodCall newAufruf = new MethodCall(0,0); this.setTypeVariable(new RefType(this.get_Name(),0)); newAufruf.type = new RefType(this.get_Name(),0); newAufruf.set_Name(""); newAufruf.set_Receiver(null); ret.add(new Overloading(assumptions, newAufruf, this.getTypeVariable()).generateConsstraints()); 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.set_Type(new Void(0)); //Typ des Statments auf Void setzen. return ret; } @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { JavaCodeResult ret = new JavaCodeResult("new "); ret.attach(this.getTypeVariable().printJavaCode(resultSet)); ret.attach("("); if(this.arglist!=null && this.arglist.expr != null){ Iterator it = this.arglist.expr.iterator(); while(it.hasNext()){ Expr arg = it.next(); ret.attach(arg.printJavaCode(resultSet)); if(it.hasNext())ret.attach(", "); } //ret = ret.substring(0, ret.length()-2); } ret.attach(")"); return ret; } } // ino.end