183 lines
5.0 KiB
Java
183 lines
5.0 KiB
Java
package de.dhbwstuttgart.syntaxtree;
|
||
|
||
import org.apache.bcel.generic.ClassGen;
|
||
|
||
import de.dhbwstuttgart.typeinference.Menge;
|
||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||
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.GenericTypeInsertable;
|
||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||
import de.dhbwstuttgart.typeinference.TypeInsertable;
|
||
import de.dhbwstuttgart.typeinference.Typeable;
|
||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||
|
||
public abstract class Field extends GTVDeclarationContext implements TypeInsertable, Typeable, Generic, GenericTypeInsertable{
|
||
|
||
protected Menge<DeclId> declid = new Menge<DeclId>(); // Menge, da 'int a, b, c, ...' auch eingeparst werden muss
|
||
|
||
private Type typ;
|
||
|
||
private int offset;
|
||
|
||
private GenericDeclarationList genericParameters;
|
||
|
||
public Field(int offset){
|
||
this.offset = offset;
|
||
}
|
||
|
||
@Override
|
||
public void setOffset(int offset){
|
||
this.offset = offset;
|
||
}
|
||
@Override
|
||
public int getOffset(){
|
||
return this.offset;
|
||
}
|
||
|
||
@Override
|
||
public void setType(Type typ) {
|
||
this.typ = typ;
|
||
}
|
||
@Override
|
||
public Type getType() {
|
||
return typ;
|
||
}
|
||
|
||
|
||
@Override
|
||
public Menge<GenericTypeVar> getGenericParameter() {
|
||
Menge<GenericTypeVar> ret = new Menge<>();
|
||
if(this.genericParameters == null)return ret;
|
||
ret.addAll(this.genericParameters.getMenge());
|
||
return ret;
|
||
}
|
||
|
||
GenericDeclarationList getGenericDeclarationList(){
|
||
return this.genericParameters;
|
||
}
|
||
|
||
public void set_DeclId(DeclId did)
|
||
{
|
||
this.declid.addElement(did);
|
||
}
|
||
|
||
|
||
|
||
public Menge<DeclId> get_Name()
|
||
{
|
||
return declid;
|
||
}
|
||
|
||
public Menge<DeclId> getDeclIdMenge()
|
||
{
|
||
// otth: ganzer Vektor zur�ckgeben, um ihn zu kopieren (vgl. MyCompiler - Konstruktor in Methode umwandeln)
|
||
return declid;
|
||
}
|
||
|
||
public void setDeclIdMenge( Menge<DeclId> vDeclId )
|
||
{
|
||
// otth: kompletter Vektor setzen, um ihn zu kopieren (vgl. MyCompiler - Konstruktor in Methode umwandeln)
|
||
declid = vDeclId;
|
||
}
|
||
|
||
|
||
|
||
|
||
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
|
||
|
||
/**
|
||
* Diese Methode generiert die Assumptions für dieses Feld der Klasse classmember
|
||
* @param classmember
|
||
* @return
|
||
*/
|
||
public abstract TypeAssumptions createTypeAssumptions(Class classmember);
|
||
|
||
public abstract ConstraintsSet TYPE(TypeAssumptions publicAssumptions);
|
||
|
||
public String getIdentifier() {
|
||
return this.get_Name().firstElement().get_Name();
|
||
}
|
||
|
||
@Override
|
||
public String getDescription(){
|
||
return this.getIdentifier();
|
||
}
|
||
|
||
@Override
|
||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
|
||
ResultSet resultSet) {
|
||
return new TypeInsertPoint(this, this, resultSet.getTypeEqualTo(tph), resultSet);
|
||
}
|
||
|
||
/**
|
||
* Wird im Zuge des ParserPostProcessing aufgerufen.
|
||
* Der Parser kann den Unterschied zwischen einem RefType und einer GTV nicht erkennen.
|
||
* Diese Methode ersetzt die RefTypes gegebenenfalls durch eine GTV.
|
||
* @param paralist
|
||
*/
|
||
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist){
|
||
// Zuerst Returntype untersuchen
|
||
Type type=getType();
|
||
Type pendantReturnType = null;
|
||
if(type instanceof RefType)pendantReturnType = ((RefType)type).findGenericType(paralist, new Menge<GenericTypeVar>());//GenericTypeVar pendantReturnType=ClassHelper.findGenericType(type, paralist,new Menge<GenericTypeVar>());
|
||
if(pendantReturnType!=null){ //Wenn generisch, dann modifizieren
|
||
setType(pendantReturnType);
|
||
}
|
||
}
|
||
|
||
public boolean isPublic() {
|
||
//TODO: momentan ist jedes Feld public!
|
||
return true;
|
||
}
|
||
|
||
@Override
|
||
public String getGenericVarDeclarationString(String genericVarDeclaration) {
|
||
if(this.genericParameters != null){
|
||
return ", "+genericVarDeclaration;
|
||
}else{
|
||
return "<"+genericVarDeclaration+">";
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public int getGenericVarDeclarationOffset(){
|
||
// Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn
|
||
if(this.genericParameters != null){
|
||
return this.genericParameters.getEndOffset();
|
||
}else{
|
||
return this.offset;
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public Menge<SyntaxTreeNode> getChildren() {
|
||
Menge<SyntaxTreeNode> ret = new Menge<>();
|
||
if(this.getType()!=null)ret.add(this.getType());
|
||
ret.addAll(this.getGenericParameter());
|
||
return ret;
|
||
}
|
||
|
||
@Override
|
||
public void setGenericParameter(GenericDeclarationList params) {
|
||
this.genericParameters = params;
|
||
}
|
||
@Override
|
||
public boolean isClass() {
|
||
return false;
|
||
}
|
||
|
||
/**
|
||
* F<>gt das das Feld zu ClassGen hinzu
|
||
* @param cg
|
||
*/
|
||
public abstract void genByteCode(ClassGen cg);
|
||
}
|
||
|