2013-10-18 11:33:46 +00:00
|
|
|
// ino.module.Method.8564.package
|
2014-09-02 08:33:54 +00:00
|
|
|
package de.dhbwstuttgart.syntaxtree;
|
2015-06-16 12:23:32 +00:00
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
// ino.end
|
|
|
|
// ino.module.Method.8564.import
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.Iterator;
|
2014-02-09 15:07:31 +00:00
|
|
|
|
2015-06-16 09:55:15 +00:00
|
|
|
import org.apache.bcel.Constants;
|
2015-05-27 13:57:15 +00:00
|
|
|
import org.apache.bcel.generic.ClassGen;
|
2015-06-16 09:55:15 +00:00
|
|
|
import org.apache.bcel.generic.ConstantPoolGen;
|
|
|
|
import org.apache.bcel.generic.InstructionFactory;
|
|
|
|
import org.apache.bcel.generic.InstructionHandle;
|
|
|
|
import org.apache.bcel.generic.InstructionList;
|
|
|
|
import org.apache.bcel.generic.MethodGen;
|
2013-10-18 11:33:46 +00:00
|
|
|
|
2015-05-27 13:57:15 +00:00
|
|
|
import de.dhbwstuttgart.typeinference.Menge;
|
|
|
|
import de.dhbwstuttgart.logger.Logger;
|
2014-09-02 08:33:54 +00:00
|
|
|
import de.dhbwstuttgart.core.IItemWithOffset;
|
|
|
|
import de.dhbwstuttgart.core.MyCompiler;
|
2014-09-04 14:35:44 +00:00
|
|
|
import de.dhbwstuttgart.myexception.JVMCodeException;
|
|
|
|
import de.dhbwstuttgart.myexception.SCMethodException;
|
|
|
|
import de.dhbwstuttgart.myexception.SCStatementException;
|
2014-09-05 09:49:31 +00:00
|
|
|
import de.dhbwstuttgart.parser.JavaClassName;
|
2014-09-02 08:33:54 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
2014-09-05 09:49:31 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
2014-09-02 08:33:54 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
|
|
|
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
2015-06-16 09:55:15 +00:00
|
|
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
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.typeinference.ConstraintsSet;
|
|
|
|
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
|
|
|
import de.dhbwstuttgart.typeinference.ResultSet;
|
|
|
|
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
|
|
|
import de.dhbwstuttgart.typeinference.TypeInsertable;
|
|
|
|
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
|
|
|
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
|
|
|
|
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
|
|
|
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
|
|
|
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
2013-10-18 11:33:46 +00:00
|
|
|
|
|
|
|
// ino.class.Method.23482.declaration
|
2014-02-14 16:31:55 +00:00
|
|
|
/**
|
2015-06-16 12:23:32 +00:00
|
|
|
* Stellt eine Methode dar. Problem: Parser kann nicht zwischen Methode und
|
|
|
|
* Konstruktor unterscheiden. Daher kann diese Klasse beides sein. Dies wird mit
|
|
|
|
* dem ParserPostProcessing behoben.
|
|
|
|
*
|
2014-02-14 16:31:55 +00:00
|
|
|
* @author janulrich
|
|
|
|
*
|
|
|
|
*/
|
2014-03-09 13:12:48 +00:00
|
|
|
public class Method extends Field implements IItemWithOffset, TypeInsertable
|
2013-10-18 11:33:46 +00:00
|
|
|
// ino.end
|
|
|
|
// ino.class.Method.23482.body
|
|
|
|
{
|
2015-06-16 12:23:32 +00:00
|
|
|
// ino.attribute.block.23488.declaration
|
|
|
|
private Block block;
|
|
|
|
// ino.end
|
|
|
|
// ino.attribute.parameterlist.23491.declaration
|
|
|
|
public ParameterList parameterlist = new ParameterList();
|
|
|
|
// ino.end
|
|
|
|
// ino.attribute.exceptionlist.23494.declaration
|
|
|
|
private ExceptionList exceptionlist;
|
|
|
|
// ino.end
|
|
|
|
// ino.attribute.returntype.23497.declaration
|
|
|
|
private Type returntype;
|
|
|
|
// ino.end
|
2015-06-16 12:58:27 +00:00
|
|
|
protected MethodGen method;
|
2015-06-16 12:23:32 +00:00
|
|
|
// ino.attribute.genericMethodParameters.23500.decldescription type=javadoc
|
|
|
|
/**
|
|
|
|
* HOTI 4.5.06 Dieser Vektor beinhaltet alle Generischen Typen und v.a. die
|
|
|
|
* F-Bounded-Generics, die die Methode besitzt size()==0, falls es keine
|
|
|
|
* gibt
|
|
|
|
*/
|
|
|
|
// ino.end
|
|
|
|
// ino.attribute.genericMethodParameters.23500.declaration
|
|
|
|
// private Menge<GenericTypeVar> genericMethodParameters=new
|
|
|
|
// Menge<GenericTypeVar>();
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.attribute.overloadedID.23503.declaration
|
|
|
|
private int overloadedID;
|
|
|
|
// ino.end
|
|
|
|
// ino.attribute.isAbstract.23506.declaration
|
|
|
|
private boolean isAbstract = false;
|
|
|
|
// ino.end
|
|
|
|
// ino.attribute.types_in_parameterlist.23509.declaration
|
|
|
|
private Menge<String> types_in_parameterlist = new Menge<String>();
|
|
|
|
// ino.end
|
|
|
|
// ino.attribute.m_LineNumber.23512.declaration
|
|
|
|
private int m_LineNumber = MyCompiler.NO_LINENUMBER;
|
|
|
|
// ino.end
|
|
|
|
private int m_Offset = -1; // hinzugef�gt hoth: 07.04.2006
|
|
|
|
// ino.attribute.inferencelog.23515.declaration
|
|
|
|
protected static Logger inferencelog = Logger.getLogger("inference");
|
|
|
|
// ino.end
|
|
|
|
// ino.attribute.parserlog.23518.declaration
|
|
|
|
protected static Logger parserlog = Logger.getLogger("parser");
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
public Method(int offset) {
|
|
|
|
super(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Method(String name, Type returnType, ParameterList parameterList,
|
|
|
|
Block block, GenericDeclarationList gtvDeclarations, int offset) {
|
|
|
|
this(offset);
|
|
|
|
/*
|
|
|
|
* if(parameterList != null)parameterList.parserPostProcessing(this);
|
|
|
|
* if(block != null)block.parserPostProcessing(this); if(gtvDeclarations
|
|
|
|
* != null)gtvDeclarations.parserPostProcessing(this);
|
|
|
|
*/
|
|
|
|
this.set_Method_Name(name);
|
|
|
|
this.setParameterList(parameterList);
|
|
|
|
this.set_Block(block);
|
|
|
|
this.setGenericParameter(gtvDeclarations);
|
|
|
|
this.setReturnType(returnType);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* // ino.method.setGenericMethodParameters.23521.definition public void
|
|
|
|
* setGenericMethodParameters(Menge<GenericTypeVar> genericMethodParameters)
|
|
|
|
* // ino.end // ino.method.setGenericMethodParameters.23521.body {
|
|
|
|
* this.genericMethodParameters=genericMethodParameters; } // ino.end //
|
|
|
|
* ino.method.getGenericMethodParameters.23524.definition public
|
|
|
|
* Menge<GenericTypeVar> getGenericMethodParameters() // ino.end //
|
|
|
|
* ino.method.getGenericMethodParameters.23524.body {
|
|
|
|
* return(genericMethodParameters); } // ino.end
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* // ino.method.sc_init_parameterlist.23530.definition public void
|
|
|
|
* sc_init_parameterlist(boolean ext) // ino.end //
|
|
|
|
* ino.method.sc_init_parameterlist.23530.body { DeclId hilf=null;
|
|
|
|
* Menge<FormalParameter> list; FormalParameter para; String typeofpara; int
|
|
|
|
* i=1; if(this.getParameterList()!=null) //es gibt Parameter, dann: {
|
|
|
|
* hilf=declid.elementAt(0); if(ext)
|
|
|
|
* parserlog.debug("Semantik-Check hat in Methode "
|
|
|
|
* +hilf.get_Name()+" bergabewerte gefunden:");
|
|
|
|
* list=this.getParameterList().sc_get_Formalparalist(); //Menge
|
|
|
|
* Formalparalist aus FormalParameterList wird zwischen gesichert
|
|
|
|
* for(Enumeration<FormalParameter> el2=list.elements();
|
|
|
|
* el2.hasMoreElements();) { para=el2.nextElement();
|
|
|
|
* typeofpara=para.getTypeName(); if(ext)
|
|
|
|
* parserlog.debug(" "+i+". Parameter hat Typ "+typeofpara);
|
|
|
|
* types_in_parameterlist.addElement(typeofpara); //Typ der Parameter werden
|
|
|
|
* im Menge abgelegt i++; } } else //keine Parameter vorhanden: { if(ext) {
|
|
|
|
* hilf=declid.elementAt(0);
|
|
|
|
* parserlog.debug("Semantik-Check hat in Methode "
|
|
|
|
* +hilf.get_Name()+" keine bergabewerte gefunden."); } } if(ext) {
|
|
|
|
* parserlog.debug("Semantik-Check hat in Methode "+hilf.get_Name()+" "+
|
|
|
|
* types_in_parameterlist.size()+" bergabeparameter gefunden.");
|
|
|
|
* parserlog.debug
|
|
|
|
* (" namentlich: "+types_in_parameterlist.toString()); } } //
|
|
|
|
* ino.end
|
|
|
|
*/
|
|
|
|
// ino.method.getTypeName.23533.defdescription type=line
|
|
|
|
// Eine der beiden Funktionen ist ueberflssig. Wer sich daran strt kann die
|
|
|
|
// get_ReturnType() auf eigene Gefahr lschen.
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.getTypeName.23533.definition
|
|
|
|
public JavaClassName getTypeName()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getTypeName.23533.body
|
|
|
|
{
|
|
|
|
if (this.getType() == null)
|
|
|
|
return null;
|
|
|
|
else
|
|
|
|
return this.getType().getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.get_Block.23536.definition
|
|
|
|
public Block get_Block()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.get_Block.23536.body
|
|
|
|
{
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.setReturnType.23539.defdescription type=javadoc
|
|
|
|
/**
|
|
|
|
* <br/>
|
|
|
|
* Author: Jrg Buerle
|
|
|
|
*
|
|
|
|
* @param type
|
|
|
|
*/
|
|
|
|
// ino.end
|
|
|
|
// ino.method.setReturnType.23539.definition
|
|
|
|
private void setReturnType(Type type)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.setReturnType.23539.body
|
|
|
|
{
|
|
|
|
this.returntype = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.set_Block.23542.definition
|
|
|
|
public void set_Block(Block blo)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.set_Block.23542.body
|
|
|
|
{
|
|
|
|
if (blo.getType() == null)
|
|
|
|
blo.setType(this.returntype);
|
|
|
|
this.block = blo;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.set_Modifiers.23545.definition
|
|
|
|
public void set_Modifiers(Modifiers modif)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.set_Modifiers.23545.body
|
|
|
|
{
|
|
|
|
declid.firstElement().set_Modifiers(modif);
|
|
|
|
// this.modi = modif;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.set_ExceptionList.23548.definition
|
|
|
|
public void set_ExceptionList(ExceptionList exlist)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.set_ExceptionList.23548.body
|
|
|
|
{
|
|
|
|
this.exceptionlist = exlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.setParameterList.23551.definition
|
|
|
|
public void setParameterList(ParameterList paralist)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.setParameterList.23551.body
|
|
|
|
{
|
|
|
|
this.parameterlist = paralist;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.getParameterList.23554.definition
|
|
|
|
public ParameterList getParameterList()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getParameterList.23554.body
|
|
|
|
{
|
|
|
|
// otth: gibt die Parameterliste zurueck
|
|
|
|
return this.parameterlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.getParameterCount.23557.defdescription type=javadoc
|
|
|
|
/**
|
|
|
|
* Author: Jrg Buerle<br/>
|
|
|
|
*
|
|
|
|
* @return Die Anzahl der Methoden-Paramater
|
|
|
|
*/
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getParameterCount.23557.definition
|
|
|
|
public int getParameterCount()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getParameterCount.23557.body
|
|
|
|
{
|
|
|
|
if (this.getParameterList() == null)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return this.getParameterList().getParameterCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.get_ExceptionList.23560.definition
|
|
|
|
public ExceptionList get_ExceptionList()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.get_ExceptionList.23560.body
|
|
|
|
{
|
|
|
|
// otth: gibt die Exceptionliste zurueck
|
|
|
|
return this.exceptionlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.getOverloadedID.23563.definition
|
|
|
|
public int getOverloadedID()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getOverloadedID.23563.body
|
|
|
|
{
|
|
|
|
return (overloadedID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.setOverloadedID.23566.definition
|
|
|
|
public void setOverloadedID(int overloadedID)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.setOverloadedID.23566.body
|
|
|
|
{
|
|
|
|
this.overloadedID = overloadedID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.get_Method_Name.23575.definition
|
|
|
|
public String get_Method_Name()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.get_Method_Name.23575.body
|
|
|
|
{
|
|
|
|
DeclId hilf = declid.elementAt(0);
|
|
|
|
return hilf.get_Name();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.get_Type_Paralist.23578.definition
|
|
|
|
public Menge get_Type_Paralist()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.get_Type_Paralist.23578.body
|
|
|
|
{
|
|
|
|
return types_in_parameterlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.getLineNumber.23584.definition
|
|
|
|
public int getLineNumber()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getLineNumber.23584.body
|
|
|
|
{
|
|
|
|
return m_LineNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.setLineNumber.23587.definition
|
|
|
|
public void setLineNumber(int lineNumber)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.setLineNumber.23587.body
|
|
|
|
{
|
|
|
|
m_LineNumber = lineNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.getOffset.23590.defdescription type=line
|
|
|
|
// hinzugef�gt hoth: 07.04.2006
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getOffset.23590.definition
|
|
|
|
public int getOffset()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getOffset.23590.body
|
|
|
|
{
|
|
|
|
return m_Offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.getVariableLength.23593.definition
|
|
|
|
public int getVariableLength()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getVariableLength.23593.body
|
|
|
|
{
|
|
|
|
return get_Method_Name().length();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.setOffset.23596.defdescription type=line
|
|
|
|
// hinzugef�gt hoth: 07.04.2006
|
|
|
|
// ino.end
|
|
|
|
// ino.method.setOffset.23596.definition
|
|
|
|
public void setOffset(int Offset)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.setOffset.23596.body
|
|
|
|
{
|
|
|
|
m_Offset = Offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.getTypeLineNumber.23602.defdescription type=javadoc
|
|
|
|
/**
|
|
|
|
* <br>
|
|
|
|
* Author: Jrg Buerle
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getTypeLineNumber.23602.definition
|
|
|
|
public int getTypeLineNumber()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.getTypeLineNumber.23602.body
|
|
|
|
{
|
|
|
|
return this.getLineNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.toString.23605.defdescription type=javadoc
|
|
|
|
/**
|
|
|
|
* <br/>
|
|
|
|
* Author: Martin Pl�micke
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// ino.end
|
|
|
|
// ino.method.toString.23605.definition
|
|
|
|
public String toString()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.toString.23605.body
|
|
|
|
{
|
|
|
|
return this.getType() + " " + this.get_Name()
|
|
|
|
+ ((block != null) ? block.toString() : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.setAbstract.23608.defdescription type=javadoc
|
|
|
|
/**
|
|
|
|
* Legt fuer die ByteCodeGen fest, ob Bytecode innerhalb der Methode
|
|
|
|
* generiert wird.
|
|
|
|
*/
|
|
|
|
// ino.end
|
|
|
|
// ino.method.setAbstract.23608.definition
|
|
|
|
public void setAbstract(boolean b)
|
|
|
|
// ino.end
|
|
|
|
// ino.method.setAbstract.23608.body
|
|
|
|
{
|
|
|
|
isAbstract = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ino.end
|
|
|
|
|
|
|
|
// ino.method.isAbstract.23611.defdescription type=javadoc
|
|
|
|
/**
|
|
|
|
* Gibt zurueck, ob ByteCode innerhabl der Methode generiert wird.
|
|
|
|
*/
|
|
|
|
// ino.end
|
|
|
|
// ino.method.isAbstract.23611.definition
|
|
|
|
public boolean isAbstract()
|
|
|
|
// ino.end
|
|
|
|
// ino.method.isAbstract.23611.body
|
|
|
|
{
|
|
|
|
return isAbstract;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void wandleRefTypeAttributes2GenericAttributes(
|
|
|
|
Menge<Type> classParalist) {
|
|
|
|
/*
|
|
|
|
* Menge<Type> paralist = new Menge<Type>();//Mit den Generischen Typen
|
|
|
|
* der Methode paralist.addAll(classParalist);
|
|
|
|
* paralist.addAll(this.genericMethodParameters);
|
|
|
|
*
|
|
|
|
* // Zuerst Returntype untersuchen Type returnType=getType(); Type
|
|
|
|
* pendantReturnType = null; if(returnType instanceof
|
|
|
|
* RefType)pendantReturnType =
|
|
|
|
* ((RefType)returnType).findGenericType(paralist, new
|
|
|
|
* Menge<GenericTypeVar>()); //GenericTypeVar
|
|
|
|
* pendantReturnType=ClassHelper.findGenericType(returnType,
|
|
|
|
* paralist,genericMethodParameters); if(pendantReturnType!=null){
|
|
|
|
* //Wenn generisch, dann modifizieren setReturnType(pendantReturnType);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // Dann parameterlist untersuchen for(int
|
|
|
|
* par=0;par<getParameterCount();par++){ FormalParameter
|
|
|
|
* fp=parameterlist.formalparameter.get(par); Type fpType=fp.getType();
|
|
|
|
* // Nur wenn es sich um ein RefType-Field handelt Type pendantPara =
|
|
|
|
* null; if(fpType instanceof RefType)pendantPara =
|
|
|
|
* ((RefType)fpType).findGenericType(paralist, new
|
|
|
|
* Menge<GenericTypeVar>()); //GenericTypeVar
|
|
|
|
* pendantPara=ClassHelper.findGenericType
|
|
|
|
* (fpType,paralist,genericMethodParameters); if(pendantPara!=null){
|
|
|
|
* //Wenn generisch, dann modifizieren fp.setType(pendantPara); } }
|
|
|
|
*
|
|
|
|
* // Zuletzt alle Lokalen Variablendeklarationen durchgehen
|
|
|
|
* if(block!=null){
|
|
|
|
* block.wandleRefTypeAttributes2GenericAttributes(paralist
|
|
|
|
* ,genericMethodParameters); }
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
public void set_Method_Name(String string) {
|
|
|
|
if (declid.size() == 0)
|
|
|
|
declid.add(0, new DeclId(string));
|
|
|
|
declid.set(0, new DeclId(string));
|
|
|
|
}
|
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
public ConstraintsSet TYPE(TypeAssumptions ass) {
|
2014-06-18 07:06:08 +00:00
|
|
|
ConstraintsSet ret = new ConstraintsSet();
|
|
|
|
TypeAssumptions localAss = new TypeAssumptions();
|
2015-06-16 12:23:32 +00:00
|
|
|
localAss.add(ass); // Die globalen Assumptions anhängen
|
|
|
|
// Generische Parameterdeklarationen den Assumptions anfügen:
|
|
|
|
for (GenericTypeVar gtv : this.getGenericParameter()) {
|
2014-07-16 16:38:55 +00:00
|
|
|
localAss.add(gtv.createAssumptions());
|
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
for (GenericTypeVar gtv : this.getGenericParameter()) {
|
2014-06-18 07:06:08 +00:00
|
|
|
ret.add(gtv.TYPE(localAss));
|
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
|
|
|
|
// TypeCheck, falls es sich um einen RefType handelt:
|
2014-10-08 17:00:17 +00:00
|
|
|
this.returntype = this.returntype.checkTYPE(localAss, this);
|
2014-06-18 09:30:14 +00:00
|
|
|
/*
|
2015-06-16 12:23:32 +00:00
|
|
|
* if(this.returntype!=null && (this.returntype instanceof RefType)&&
|
|
|
|
* !(this.returntype instanceof mycompiler.mytype.Void)){//Sonderfall
|
|
|
|
* der Methode: Ihr Typ darf Void definiert werden. Type replaceType =
|
|
|
|
* null; replaceType = ass.getTypeFor((RefType)this.returntype);
|
|
|
|
* if(replaceType == null)throw new
|
|
|
|
* TypeinferenceException("Der Typ "+this
|
|
|
|
* .getType().getName()+" ist nicht korrekt",this); this.returntype =
|
|
|
|
* replaceType; }
|
|
|
|
*/
|
|
|
|
// Die Parameter zu den Assumptions hinzufügen:
|
|
|
|
if (this.parameterlist != null)
|
|
|
|
for (FormalParameter param : this.parameterlist) {
|
|
|
|
|
|
|
|
param.setType(param.getType().checkTYPE(localAss, this));
|
|
|
|
/*
|
|
|
|
* if(param.getType() instanceof RefType) { Type replaceType =
|
|
|
|
* null; replaceType = ass.getTypeFor((RefType)param.getType());
|
|
|
|
* if(replaceType == null) throw new
|
|
|
|
* TypeinferenceException("Der Typ "
|
|
|
|
* +param.getType().getName()+" ist nicht korrekt",param);
|
|
|
|
* param.setType(replaceType); }
|
|
|
|
*/
|
|
|
|
|
|
|
|
localAss.addAssumption(new ParameterAssumption(param));
|
2014-04-15 12:56:20 +00:00
|
|
|
}
|
2014-02-19 16:32:43 +00:00
|
|
|
ret.add(this.block.TYPEStmt(localAss));
|
2015-06-16 12:23:32 +00:00
|
|
|
// eine Verknüpfung mit der Type Assumption aus dem Assumption Set
|
|
|
|
// und dem ermittelten Typ der Methode:
|
|
|
|
ret.add(new SingleConstraint(this.block.getType().TYPE(localAss, this),
|
|
|
|
this.returntype.TYPE(localAss, this)));
|
2013-10-18 11:33:46 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
/**
|
|
|
|
* @author Andreas Stadelmeier, a10023
|
|
|
|
* @return die TypInformationen der Statements dieser Methode.
|
|
|
|
*/
|
2015-06-16 12:23:32 +00:00
|
|
|
public String getTypeInformation() {
|
|
|
|
if (this.parameterlist != null)
|
|
|
|
return "Methode " + this.get_Name() + " Parameter: "
|
|
|
|
+ this.parameterlist.getTypeInformation() + ", Block: "
|
|
|
|
+ this.block.getTypeInformation();
|
|
|
|
return "Methode " + this.get_Name() + " : " + this.getType()
|
|
|
|
+ ", Block: " + this.block.getTypeInformation();
|
2013-10-18 11:33:46 +00:00
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
@Override
|
|
|
|
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|
|
|
JavaCodeResult ret = new JavaCodeResult();
|
2015-06-16 12:23:32 +00:00
|
|
|
ret.attach(this.getType().printJavaCode(resultSet)).attach(" ")
|
|
|
|
.attach(this.get_Method_Name()).attach("(")
|
|
|
|
.attach(this.getParameterList().printJavaCode(resultSet))
|
|
|
|
.attach(")\n");
|
2013-10-18 11:33:46 +00:00
|
|
|
ret.attach(this.block.printJavaCode(resultSet));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
|
2014-04-23 23:53:35 +00:00
|
|
|
/**
|
|
|
|
* Liefert die MethodAssumption zu dieser Methode
|
|
|
|
*/
|
2013-10-18 11:33:46 +00:00
|
|
|
@Override
|
|
|
|
public TypeAssumptions createTypeAssumptions(Class classmember) {
|
2015-06-16 12:23:32 +00:00
|
|
|
Class parentClass = classmember;// this.getParentClass();
|
2014-02-18 16:47:40 +00:00
|
|
|
TypeAssumptions ret = new TypeAssumptions();
|
2014-04-09 12:12:55 +00:00
|
|
|
ret.addAssumption(new MethodAssumption(this, parentClass));
|
2014-02-14 16:31:55 +00:00
|
|
|
return ret;
|
|
|
|
/*
|
2015-06-16 12:23:32 +00:00
|
|
|
* TypeAssumptions assumptions = new TypeAssumptions(); this.assumedType
|
|
|
|
* = null; //if((this.get_Method_Name().equals(classmember.getName()) ||
|
|
|
|
* this.get_Method_Name().equals("<init>")) &&
|
|
|
|
* ((this.getType().equals(new mycompiler.mytype.Void(0))) ||
|
|
|
|
* this.getType() instanceof TypePlaceholder)){
|
|
|
|
* if((this.get_Method_Name().equals(classmember.getName()) ||
|
|
|
|
* this.get_Method_Name().equals("<init>"))) {
|
|
|
|
* this.set_Method_Name("<init>"); this.assumedType = new
|
|
|
|
* RefType(classmember.getName(),0);
|
|
|
|
* this.setReturnType(this.assumedType); this.assumedType = new
|
|
|
|
* RefType("void",0); //Return constructorReturnStatement = new
|
|
|
|
* Return(0,0); //constructorReturnStatement.retexpr =
|
|
|
|
* //this.block.statements.add(constructorReturnStatement); } //hoth:
|
|
|
|
* 06.04.2006 //durchlaufe Block und suche nach Objektvariablen fuer
|
|
|
|
* Offset-Markierung Iterator<CTypeAssumption> fieldVarIterator =
|
|
|
|
* assumptions.iterator(); while (fieldVarIterator.hasNext()) { //Wenn
|
|
|
|
* ObjektVariable CTypeAssumption dieAssum = fieldVarIterator.next();
|
|
|
|
* if(dieAssum instanceof CInstVarTypeAssumption) {
|
|
|
|
* Class.isFirstLocalVarDecl=false; if(this.get_Block() != null)
|
|
|
|
* this.get_Block
|
|
|
|
* ().addOffsetsToAssumption(dieAssum,dieAssum.getIdentifier(),true); }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* //methodList.addElement(method);
|
|
|
|
*
|
|
|
|
* //F�r V_fields_methods: CMethodTypeAssumption methodAssum
|
|
|
|
* = new CMethodTypeAssumption(classmember.getType(),
|
|
|
|
* this.get_Method_Name(), this.getType(),
|
|
|
|
* this.getParameterCount(),this.getLineNumber(),this.getOffset(),new
|
|
|
|
* Menge<Integer>(),this.getGenericMethodParameters()); // Typannahme
|
|
|
|
* bauen...
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* //Methode in V_Fields_methods ablegen //Dabei wird die
|
|
|
|
* OverloadedMethodID ermittelt !! //=> Method setzenuct
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* assumptions.add(methodAssum);
|
|
|
|
* this.setOverloadedID(methodAssum.getHashSetKey
|
|
|
|
* ().getOverloadedMethodID());
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* //F�r die V_i: CTypeAssumptionSet localAssum = new
|
|
|
|
* CTypeAssumptionSet();
|
|
|
|
*
|
|
|
|
* //Bauen... ParameterList parameterList = this.getParameterList();
|
|
|
|
* if(parameterList!=null){ for(int i=0;
|
|
|
|
* i<parameterList.sc_get_Formalparalist().size(); i++){ FormalParameter
|
|
|
|
* para = parameterList.sc_get_Formalparalist().elementAt(i); //
|
|
|
|
* F�r V_fields_methods: CParaTypeAssumption paraAssum = new
|
|
|
|
* CParaTypeAssumption(classmember.getName(), this.get_Method_Name(),
|
|
|
|
* this.getParameterCount(), this.getOverloadedID(),para.get_Name(),
|
|
|
|
* para.getType(), para.getLineNumber(),para.getOffset(),new
|
|
|
|
* Menge<Integer>()); //fuege Offsets fuer Parameter hinzu, hoth:
|
|
|
|
* 06.04.2006 Class.isFirstLocalVarDecl=false;
|
|
|
|
*
|
|
|
|
* if(this.get_Block() != null)
|
|
|
|
* this.get_Block().addOffsetsToAssumption(paraAssum
|
|
|
|
* ,paraAssum.getIdentifier(),true);
|
|
|
|
*
|
|
|
|
* methodAssum.addParaAssumption(paraAssum);
|
|
|
|
*
|
|
|
|
* // F�r die V_i: CLocalVarTypeAssumption varAssum = new
|
|
|
|
* CLocalVarTypeAssumption(classmember.getName(),
|
|
|
|
* this.get_Method_Name(), this.getParameterCount(),
|
|
|
|
* this.getOverloadedID(),"1", para.get_Name(),para.getType(),
|
|
|
|
* para.getLineNumber(),para.getOffset(),new Menge<Integer>());
|
|
|
|
* localAssum.addElement(varAssum);
|
|
|
|
* //rememberLocals.addElement(varAssum); } } //...und
|
|
|
|
* hinzuf�gen:
|
|
|
|
*
|
|
|
|
* assumptions.add(localAssum);//Assumptions für lokale Variablen den
|
|
|
|
* Assumptions hinzufügen
|
|
|
|
*
|
|
|
|
* //Hier wird der Typ der als Assumption eingetragen wird in die
|
|
|
|
* Variable assumedType dieser Klasse geschrieben: if(this.assumedType
|
|
|
|
* == null) // Falls der Typ nicht schon gesetzt ist. Das ist der Fall,
|
|
|
|
* falls die Methode ein Konstruktor ist this.assumedType =
|
|
|
|
* methodAssum.getAssumedType();
|
|
|
|
*
|
|
|
|
* return assumptions;
|
|
|
|
*/
|
2013-10-18 11:33:46 +00:00
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
|
2014-02-12 01:12:12 +00:00
|
|
|
@Override
|
2015-06-16 12:23:32 +00:00
|
|
|
public void parserPostProcessing(SyntaxTreeNode parent) {
|
|
|
|
if (this.getType() == null)
|
|
|
|
this.setType(TypePlaceholder.fresh(this));
|
|
|
|
// Bei dem Elterntyp der Methode darf es sich nur um eine Klasse
|
|
|
|
// handeln, daher Cast ohne Prüfung:
|
|
|
|
// Class parentClass = (Class)parent;
|
|
|
|
if (this.returntype == null)
|
|
|
|
this.returntype = TypePlaceholder.fresh(this);
|
2015-02-25 17:29:44 +00:00
|
|
|
super.parserPostProcessing(parent);
|
|
|
|
/*
|
2015-06-16 12:23:32 +00:00
|
|
|
* this.returntype.parserPostProcessing(this); if(this.parameterlist !=
|
|
|
|
* null){ for(FormalParameter fp : this.parameterlist){
|
|
|
|
* fp.parserPostProcessing(this); } } for(GenericTypeVar gtv :
|
|
|
|
* this.getGenericParameter()){ gtv.parserPostProcessing(this); }
|
|
|
|
*/
|
2014-02-12 01:12:12 +00:00
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
|
2014-02-12 01:12:12 +00:00
|
|
|
@Override
|
2015-04-22 19:40:22 +00:00
|
|
|
public Menge<SyntaxTreeNode> getChildren() {
|
|
|
|
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
|
2014-02-12 01:12:12 +00:00
|
|
|
ret.add(this.block);
|
2015-02-25 15:34:29 +00:00
|
|
|
ret.add(this.parameterlist);
|
2014-09-09 09:15:10 +00:00
|
|
|
ret.addAll(this.getGenericParameter());
|
2015-02-25 17:29:44 +00:00
|
|
|
ret.add(this.returntype);
|
2014-02-12 01:12:12 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
|
2014-02-12 01:12:12 +00:00
|
|
|
@Override
|
2015-06-16 12:23:32 +00:00
|
|
|
public void setType(Type t) {
|
2014-02-12 01:12:12 +00:00
|
|
|
// Methode und Block teilen sich einen ReturnType:
|
2015-06-16 12:23:32 +00:00
|
|
|
// this.block.setType(t);
|
2014-02-19 04:20:54 +00:00
|
|
|
this.returntype = t;
|
2015-06-16 12:23:32 +00:00
|
|
|
this.returntype.parent = this; // TODO: Dieser Hack sollte nicht
|
|
|
|
// nötig sein. (Parser ändern)
|
2014-02-12 01:12:12 +00:00
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
|
2014-02-19 16:32:43 +00:00
|
|
|
/**
|
|
|
|
* Der Typ einer Methode ist ihr Returntype
|
|
|
|
*/
|
2014-02-12 01:12:12 +00:00
|
|
|
@Override
|
2015-06-16 12:23:32 +00:00
|
|
|
public Type getType() {
|
|
|
|
// Methode und Block teilen sich einen ReturnType:
|
2014-02-19 05:09:59 +00:00
|
|
|
return this.returntype;
|
2014-02-12 01:12:12 +00:00
|
|
|
}
|
2015-06-16 15:44:27 +00:00
|
|
|
public static Method createEmptyMethod(Block withBlock, String withSignature, Class parent) {
|
|
|
|
Method ret = Method.createEmptyMethod(withSignature, parent);
|
|
|
|
ret.set_Block(withBlock);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
public static Method createEmptyMethod(String withSignature, Class parent) {
|
2014-03-09 11:10:03 +00:00
|
|
|
Method ret = new Method(0);
|
2014-02-19 04:20:54 +00:00
|
|
|
DeclId DImethod = new DeclId();
|
|
|
|
DImethod.set_Name(withSignature);
|
|
|
|
ret.set_DeclId(DImethod);
|
|
|
|
Block tempBlock = new Block();
|
2015-06-16 12:23:32 +00:00
|
|
|
// tempBlock.setType(new RefType(parent.getName(),0));
|
2014-02-19 04:20:54 +00:00
|
|
|
ret.set_Block(tempBlock);
|
2014-02-19 16:32:43 +00:00
|
|
|
ret.parserPostProcessing(parent);
|
2014-02-19 04:20:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-06-16 12:23:32 +00:00
|
|
|
|
2014-03-19 14:14:50 +00:00
|
|
|
@Override
|
2015-06-16 12:23:32 +00:00
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (!(obj instanceof Method))
|
|
|
|
return false;
|
2014-03-19 14:14:50 +00:00
|
|
|
Method equals = (Method) obj;
|
2015-06-16 12:23:32 +00:00
|
|
|
if ((this.returntype != null && equals.returntype == null))
|
|
|
|
return false;
|
|
|
|
if ((this.returntype == null && equals.returntype != null))
|
|
|
|
return false;
|
|
|
|
if (this.returntype != null && equals.returntype != null)
|
|
|
|
if (!this.returntype.equals(equals.returntype))
|
|
|
|
return false;
|
|
|
|
if (!this.parameterlist.equals(equals.parameterlist))
|
|
|
|
return false;
|
2014-03-19 14:14:50 +00:00
|
|
|
return super.equals(obj);
|
|
|
|
}
|
2015-05-27 13:57:15 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void genByteCode(ClassGen cg) {
|
2015-06-18 09:17:42 +00:00
|
|
|
ConstantPoolGen _cp = cg.getConstantPool();
|
|
|
|
InstructionFactory _factory = new InstructionFactory(cg, _cp);
|
|
|
|
InstructionList il = new InstructionList();
|
|
|
|
Class parentClass = this.getParentClass();
|
|
|
|
|
|
|
|
MethodGen method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, this.get_Method_Name(), parentClass.name, il, _cp);
|
2015-06-16 12:58:27 +00:00
|
|
|
|
2015-06-18 09:17:42 +00:00
|
|
|
Block block = this.get_Block();
|
|
|
|
InstructionList blockInstructions = block.genByteCode(cg);
|
2015-06-16 12:58:27 +00:00
|
|
|
|
2015-06-18 09:17:42 +00:00
|
|
|
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
|
|
|
|
|
|
|
|
if (block.get_Statement().size() == 0) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
|
|
|
|
else {
|
|
|
|
if (!(block.get_Statement().lastElement() instanceof Return)) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
|
2015-06-16 12:23:32 +00:00
|
|
|
}
|
2015-06-16 11:08:11 +00:00
|
|
|
|
2015-06-18 09:17:42 +00:00
|
|
|
method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)
|
|
|
|
|
|
|
|
cg.addMethod(method.getMethod());
|
|
|
|
|
2015-05-27 13:57:15 +00:00
|
|
|
}
|
|
|
|
|
2013-10-18 11:33:46 +00:00
|
|
|
}
|
|
|
|
// ino.end
|