2013-10-18 11:33:46 +00:00
|
|
|
// ino.module.NewClass.8642.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.NewClass.8642.import
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.Iterator;
|
2014-02-09 15:07:31 +00:00
|
|
|
|
2015-10-31 17:48:46 +00:00
|
|
|
import org.apache.commons.bcel6.Constants;
|
2015-09-02 15:11:32 +00:00
|
|
|
import org.apache.commons.bcel6.generic.ClassGen;
|
2015-10-31 17:48:46 +00:00
|
|
|
import org.apache.commons.bcel6.generic.InstructionConstants;
|
2015-11-13 12:11:10 +00:00
|
|
|
|
2015-10-13 17:25:51 +00:00
|
|
|
import org.apache.commons.bcel6.generic.InstructionList;
|
2015-11-06 17:27:47 +00:00
|
|
|
import org.apache.commons.bcel6.generic.ObjectType;
|
2013-10-18 11:33:46 +00:00
|
|
|
|
|
|
|
|
2015-06-16 12:58:27 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.Menge;
|
2015-10-13 17:25:51 +00:00
|
|
|
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
2014-10-09 10:01:16 +00:00
|
|
|
import de.dhbwstuttgart.logger.Logger;
|
2014-09-04 14:35:44 +00:00
|
|
|
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
|
|
|
import de.dhbwstuttgart.myexception.JVMCodeException;
|
2015-10-13 17:25:51 +00:00
|
|
|
import de.dhbwstuttgart.myexception.NotImplementedException;
|
2014-09-04 14:35:44 +00:00
|
|
|
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;
|
2015-09-22 16:43:36 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.type.FunN;
|
2014-09-02 08:33:54 +00:00
|
|
|
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.syntaxtree.type.Void;
|
|
|
|
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
|
|
|
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
|
|
|
import de.dhbwstuttgart.typeinference.ResultSet;
|
|
|
|
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
2015-11-27 15:10:35 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
2014-09-02 08:33:54 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.UndConstraint;
|
|
|
|
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
2015-11-06 17:27:47 +00:00
|
|
|
private boolean isStatement = false;
|
2013-10-18 11:33:46 +00:00
|
|
|
// 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.set_ArgumentList.25855.definition
|
|
|
|
public void set_ArgumentList(ArgumentList al)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.set_ArgumentList.25855.body
|
|
|
|
{
|
|
|
|
this.arglist = al;
|
|
|
|
}
|
|
|
|
// ino.end
|
|
|
|
|
2014-02-09 17:52:04 +00:00
|
|
|
// ino.method.toString.25867.defdescription type=javadoc
|
2013-10-18 11:33:46 +00:00
|
|
|
/**
|
2015-05-12 17:49:27 +00:00
|
|
|
* <br/>Author: Martin Pl�micke
|
2013-10-18 11:33:46 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// ino.end
|
|
|
|
// ino.method.toString.25867.definition
|
|
|
|
public String toString()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.toString.25867.body
|
|
|
|
{
|
|
|
|
String ret = "NEW ";
|
2014-02-11 15:30:38 +00:00
|
|
|
Type thisType = getType();
|
2013-10-18 11:33:46 +00:00
|
|
|
if(thisType != null)ret += thisType.toString();
|
|
|
|
else ret += this.get_Name();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.25870.definition
|
2015-04-22 19:40:22 +00:00
|
|
|
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist, Menge<GenericTypeVar> genericMethodParameters)
|
2013-10-18 11:33:46 +00:00
|
|
|
// ino.end
|
|
|
|
// ino.method.wandleRefTypeAttributes2GenericAttributes.25870.body
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
2015-05-12 17:49:27 +00:00
|
|
|
//TODO: Das hier noch vervollständigen
|
2013-10-18 11:33:46 +00:00
|
|
|
ConstraintsSet ret = new ConstraintsSet();
|
2014-04-23 15:59:39 +00:00
|
|
|
UndConstraint callConstraints = new UndConstraint();
|
2013-10-18 11:33:46 +00:00
|
|
|
|
2014-04-23 15:59:39 +00:00
|
|
|
int numArgs = 0;
|
|
|
|
if(this.arglist != null)numArgs = this.arglist.size();
|
|
|
|
ConstructorAssumption cA = assumptions.getConstructorAssumption(this.get_Name(), numArgs);
|
|
|
|
if(cA == null)throw new TypeinferenceException("Der Konstruktor "+this.get_Name()+" mit "+numArgs+" Parametern ist nicht vorhanden.", this);
|
2013-10-18 11:33:46 +00:00
|
|
|
|
2014-04-23 15:59:39 +00:00
|
|
|
for(int i=0; i<cA.getParaCount();i++){
|
|
|
|
ret.add(this.arglist.expr.elementAt(i).TYPEExpr(assumptions));
|
2014-09-08 13:12:47 +00:00
|
|
|
callConstraints.addConstraint( this.arglist.expr.elementAt(i).getType().TYPE(assumptions, this), cA.getParameterType(i).TYPE(assumptions, this));
|
2013-10-18 11:33:46 +00:00
|
|
|
}
|
2014-10-08 17:00:17 +00:00
|
|
|
Type thisT = assumptions.checkType(new RefType(this.get_Name(),this,0), (SyntaxTreeNode)this);
|
|
|
|
this.setType(thisT);
|
2013-10-18 11:33:46 +00:00
|
|
|
|
|
|
|
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
|
2014-09-14 16:38:43 +00:00
|
|
|
this.setType(new Void(this,0)); //Typ des Statments auf Void setzen.
|
2015-11-06 17:27:47 +00:00
|
|
|
this.isStatement = true;
|
2013-10-18 11:33:46 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|
|
|
JavaCodeResult ret = new JavaCodeResult("new ");
|
2014-04-23 15:59:39 +00:00
|
|
|
ret.attach(this.get_Name());
|
2013-10-18 11:33:46 +00:00
|
|
|
ret.attach("(");
|
|
|
|
if(this.arglist!=null && this.arglist.expr != null){
|
|
|
|
Iterator<Expr> 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;
|
|
|
|
}
|
2014-02-22 03:58:49 +00:00
|
|
|
@Override
|
2015-04-22 19:40:22 +00:00
|
|
|
public Menge<SyntaxTreeNode> getChildren() {
|
|
|
|
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
|
2014-02-22 03:58:49 +00:00
|
|
|
if(this.arglist!=null)for(Expr e : this.arglist.expr){
|
|
|
|
ret.add(e);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2015-06-16 12:58:27 +00:00
|
|
|
|
|
|
|
@Override
|
2015-11-27 15:10:35 +00:00
|
|
|
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
|
2015-10-31 17:48:46 +00:00
|
|
|
InstructionList il = new InstructionList();
|
2015-11-27 14:47:09 +00:00
|
|
|
//il.append(_cg.getInstructionFactory().createNew(get_Name()));
|
2015-12-08 12:34:16 +00:00
|
|
|
il.append(_cg.getInstructionFactory().createNew(this.getType().getBytecodeType(_cg, rs).toString()));
|
2015-11-27 15:53:01 +00:00
|
|
|
il.append(InstructionConstants.DUP);
|
|
|
|
|
2015-11-06 17:27:47 +00:00
|
|
|
if(arglist!=null){
|
2015-11-27 15:10:35 +00:00
|
|
|
il.append(arglist.generateBytecode(_cg, rs));
|
2016-03-30 08:09:17 +00:00
|
|
|
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "<init>",
|
2015-11-06 17:27:47 +00:00
|
|
|
org.apache.commons.bcel6.generic.Type.VOID,
|
2015-11-27 15:10:35 +00:00
|
|
|
this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL));
|
2015-11-06 17:27:47 +00:00
|
|
|
}else{
|
2016-03-30 08:09:17 +00:00
|
|
|
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(_cg, rs), "<init>",
|
2015-11-06 17:27:47 +00:00
|
|
|
org.apache.commons.bcel6.generic.Type.VOID,
|
|
|
|
new org.apache.commons.bcel6.generic.Type[]{}, Constants.INVOKESPECIAL));
|
|
|
|
}
|
|
|
|
if(this.isStatement){
|
|
|
|
il.append(InstructionConstants.POP);
|
|
|
|
}
|
|
|
|
return il;
|
2015-06-16 12:58:27 +00:00
|
|
|
}
|
2014-02-22 03:58:49 +00:00
|
|
|
|
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
}
|
|
|
|
// ino.end
|