Versuch, MethodGen in Method.java zu implementieren

This commit is contained in:
Fikus, Evelyn (WWI2012D) 2015-06-16 14:23:32 +02:00
parent c6502600cc
commit 253ba6518b

View File

@ -1,5 +1,6 @@
// ino.module.Method.8564.package
package de.dhbwstuttgart.syntaxtree;
// ino.end
// ino.module.Method.8564.import
import java.util.Enumeration;
@ -42,13 +43,12 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
// ino.class.Method.23482.declaration
/**
* 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.
* 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.
*
* @author janulrich
*
*/
@ -71,14 +71,14 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// 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
* 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>();
// private Menge<GenericTypeVar> genericMethodParameters=new
// Menge<GenericTypeVar>();
// ino.end
// ino.attribute.overloadedID.23503.declaration
@ -99,18 +99,20 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// 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){
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);
* 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);
@ -120,65 +122,40 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
}
/*
// 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.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.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
@ -195,6 +172,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
else
return this.getType().getName();
}
// ino.end
// ino.method.get_Block.23536.definition
@ -204,11 +182,14 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
return block;
}
// ino.end
// ino.method.setReturnType.23539.defdescription type=javadoc
/**
* <br/>Author: Jrg Buerle
* <br/>
* Author: Jrg Buerle
*
* @param type
*/
// ino.end
@ -219,6 +200,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
this.returntype = type;
}
// ino.end
// ino.method.set_Block.23542.definition
@ -226,9 +208,11 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// ino.end
// ino.method.set_Block.23542.body
{
if(blo.getType() == null)blo.setType(this.returntype);
if (blo.getType() == null)
blo.setType(this.returntype);
this.block = blo;
}
// ino.end
// ino.method.set_Modifiers.23545.definition
@ -239,6 +223,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
declid.firstElement().set_Modifiers(modif);
// this.modi = modif;
}
// ino.end
// ino.method.set_ExceptionList.23548.definition
@ -248,6 +233,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
this.exceptionlist = exlist;
}
// ino.end
// ino.method.setParameterList.23551.definition
@ -257,6 +243,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
this.parameterlist = paralist;
}
// ino.end
// ino.method.getParameterList.23554.definition
@ -267,11 +254,13 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// 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
@ -285,6 +274,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
else
return this.getParameterList().getParameterCount();
}
// ino.end
// ino.method.get_ExceptionList.23560.definition
@ -295,6 +285,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// otth: gibt die Exceptionliste zurueck
return this.exceptionlist;
}
// ino.end
// ino.method.getOverloadedID.23563.definition
@ -304,6 +295,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
return (overloadedID);
}
// ino.end
// ino.method.setOverloadedID.23566.definition
@ -313,12 +305,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
this.overloadedID = overloadedID;
}
// ino.end
// ino.method.get_Method_Name.23575.definition
public String get_Method_Name()
// ino.end
@ -327,6 +316,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
DeclId hilf = declid.elementAt(0);
return hilf.get_Name();
}
// ino.end
// ino.method.get_Type_Paralist.23578.definition
@ -336,10 +326,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
return types_in_parameterlist;
}
// ino.end
// ino.method.getLineNumber.23584.definition
public int getLineNumber()
// ino.end
@ -347,6 +336,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
return m_LineNumber;
}
// ino.end
// ino.method.setLineNumber.23587.definition
@ -356,6 +346,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
m_LineNumber = lineNumber;
}
// ino.end
// ino.method.getOffset.23590.defdescription type=line
@ -368,6 +359,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
return m_Offset;
}
// ino.end
// ino.method.getVariableLength.23593.definition
@ -377,6 +369,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
return get_Method_Name().length();
}
// ino.end
// ino.method.setOffset.23596.defdescription type=line
@ -389,12 +382,14 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
m_Offset = Offset;
}
// ino.end
// ino.end
// ino.method.getTypeLineNumber.23602.defdescription type=javadoc
/**
* <br>Author: Jrg Buerle
* <br>
* Author: Jrg Buerle
*
* @return
*/
// ino.end
@ -405,11 +400,14 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
return this.getLineNumber();
}
// ino.end
// ino.method.toString.23605.defdescription type=javadoc
/**
* <br/>Author: Martin Plïÿýmicke
* <br/>
* Author: Martin Plïÿýmicke
*
* @return
*/
// ino.end
@ -418,14 +416,16 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// ino.end
// ino.method.toString.23605.body
{
return this.getType() + " "+ this.get_Name() +( (block!=null)?block.toString():"");
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.
* Legt fuer die ByteCodeGen fest, ob Bytecode innerhalb der Methode
* generiert wird.
*/
// ino.end
// ino.method.setAbstract.23608.definition
@ -435,12 +435,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
{
isAbstract = b;
}
// ino.end
// ino.method.isAbstract.23611.defdescription type=javadoc
/**
* Gibt zurueck, ob ByteCode innerhabl der Methode
* generiert wird.
* Gibt zurueck, ob ByteCode innerhabl der Methode generiert wird.
*/
// ino.end
// ino.method.isAbstract.23611.definition
@ -452,50 +452,47 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
}
@Override
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> classParalist)
{
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);
}
* 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));
public void set_Method_Name(String string) {
if (declid.size() == 0)
declid.add(0, new DeclId(string));
declid.set(0, new DeclId(string));
}
public ConstraintsSet TYPE(TypeAssumptions ass) {
ConstraintsSet ret = new ConstraintsSet();
TypeAssumptions localAss = new TypeAssumptions();
@ -511,34 +508,36 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// TypeCheck, falls es sich um einen RefType handelt:
this.returntype = this.returntype.checkTYPE(localAss, this);
/*
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;
}
* 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){
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);
}
* 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));
}
ret.add(this.block.TYPEStmt(localAss));
//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)));
// 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)));
return ret;
}
@ -547,14 +546,21 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
* @return die TypInformationen der Statements dieser Methode.
*/
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();
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();
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
JavaCodeResult ret = new JavaCodeResult();
ret.attach(this.getType().printJavaCode(resultSet)).attach(" ").attach(this.get_Method_Name()).attach("(").attach(this.getParameterList().printJavaCode(resultSet)).attach(")\n");
ret.attach(this.getType().printJavaCode(resultSet)).attach(" ")
.attach(this.get_Method_Name()).attach("(")
.attach(this.getParameterList().printJavaCode(resultSet))
.attach(")\n");
ret.attach(this.block.printJavaCode(resultSet));
return ret;
@ -570,102 +576,105 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
ret.addAssumption(new MethodAssumption(this, parentClass));
return ret;
/*
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;
* 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;
*/
}
@Override
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:
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);
if (this.returntype == null)
this.returntype = TypePlaceholder.fresh(this);
super.parserPostProcessing(parent);
/*
this.returntype.parserPostProcessing(this);
if(this.parameterlist != null){
for(FormalParameter fp : this.parameterlist){
fp.parserPostProcessing(this);
}
}
for(GenericTypeVar gtv : this.getGenericParameter()){
gtv.parserPostProcessing(this);
}
* this.returntype.parserPostProcessing(this); if(this.parameterlist !=
* null){ for(FormalParameter fp : this.parameterlist){
* fp.parserPostProcessing(this); } } for(GenericTypeVar gtv :
* this.getGenericParameter()){ gtv.parserPostProcessing(this); }
*/
}
@ -684,7 +693,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// Methode und Block teilen sich einen ReturnType:
// this.block.setType(t);
this.returntype = t;
this.returntype.parent = this; //TODO: Dieser Hack sollte nicht nÃÂtig sein. (Parser ändern)
this.returntype.parent = this; // TODO: Dieser Hack sollte nicht
// nÃÂtig sein. (Parser ändern)
}
/**
@ -710,32 +720,41 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
@Override
public boolean equals(Object obj) {
if(!(obj instanceof Method))return false;
if (!(obj instanceof Method))
return false;
Method equals = (Method) obj;
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;
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;
return super.equals(obj);
}
@Override
public void genByteCode(ClassGen cg) {
//ConstantPoolGen _cp = cg.getConstantPool();
ConstantPoolGen _cp = cg.getConstantPool();
// InstructionFactory _factory = new InstructionFactory(cg, _cp);
//InstructionList il = new InstructionList();
InstructionList il = new InstructionList();
Class parentClass = this.getParentClass();
//TODO: Hier return type und Argument-Typen dynamisch generieren. return type mittels method.getReturnType() ermitteln
// TODO: Hier return type und Argument-Typen dynamisch generieren.
// return type mittels method.getReturnType() ermitteln
//Über Constructor iterieren, um alle Methoden zu bekommen
for(Method methode : ){
//Über Statements iterieren um den Block abzurufen
for (Statement statements : block.get_Statement()) {
statements.genByteCode(cg);
}
}
MethodGen method = new MethodGen(Constants.ACC_PUBLIC,
org.apache.bcel.generic.Type.getReturnType(Method method.getType()
.get_Name()), org.apache.bcel.generic.Type.NO_ARGS,
new String[] {}, "<init>", parentClass.name, il, _cp);
// Über Statements iterieren um den Block abzurufen
// GenByteCode Constructor
@ -745,7 +764,5 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// il.dispose();
}
}
// ino.end