forked from JavaTX/JavaCompilerCore
Field anpassen
This commit is contained in:
parent
d651a6cdff
commit
717fd5d53e
@ -13,9 +13,6 @@ import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.logger.LoggerConfiguration;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
import de.dhbwstuttgart.parser.JavaParser;
|
||||
import de.dhbwstuttgart.parser.Scanner;
|
||||
import de.dhbwstuttgart.parser.JavaParser.yyException;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassBody;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
|
@ -9,6 +9,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
* Dieser kann auch den Packagenamen mit beinhalten: de.dhbwstuttgart.typeinference.Menge
|
||||
*
|
||||
* @author janulrich
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JavaClassName {
|
||||
@ -16,7 +17,12 @@ public class JavaClassName {
|
||||
private String name;
|
||||
private PackageName packageName;
|
||||
|
||||
public JavaClassName(String name){
|
||||
/**
|
||||
*
|
||||
* TODO: JavaClassName sollten aus den Assumptions generiert werden.
|
||||
* Diese wissen, welche Typen und Typnamen existieren und können direkt auf Korrektheit prüfen.
|
||||
*/
|
||||
private JavaClassName(String name){
|
||||
if(name == null)throw new NullPointerException();
|
||||
|
||||
String[] names = name.split("[.]");
|
||||
|
@ -67,144 +67,17 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
protected static Logger codegenlog = Logger.getLogger("codegen");
|
||||
protected static Logger parserlog = Logger.getLogger("parser");
|
||||
protected Logger typinferenzLog = Logger.getLogger(Class.class.getName());
|
||||
|
||||
protected Modifiers modifiers;
|
||||
protected JavaClassName name;
|
||||
|
||||
public Class(JavaClassName name, List<Method> methoden, List<Field> felder, Modifiers modifier,
|
||||
boolean isInterface, RefType superClass, List<RefType> implementedInterfaces, int offset){
|
||||
super(offset);
|
||||
}
|
||||
|
||||
protected List<RefType> implementedInterfaces = new ArrayList<>();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param resultSet - Fehlende Typen im Syntaxbaum werden nach diesem ResultSet aufgelöst
|
||||
* @return
|
||||
*/
|
||||
public ByteCodeResult genByteCode(TypeinferenceResults typeinferenceResults) {
|
||||
InstructionFactory _factory;
|
||||
DHBWConstantPoolGen _cp;
|
||||
ClassGenerator _cg;
|
||||
|
||||
Menge<ByteCodeResult> results = new Menge<ByteCodeResult>();
|
||||
|
||||
SectionLogger logger = Logger.getSectionLogger(this.getClass().getName(), Section.CODEGEN);
|
||||
logger.debug("Test");
|
||||
|
||||
if(pkgName != null)throw new NotImplementedException();
|
||||
short constants = Const.ACC_PUBLIC; //Per Definition ist jede Methode public
|
||||
if(isInterface())constants+=Const.ACC_INTERFACE;
|
||||
|
||||
_cg = new ClassGenerator(name, this.getSuperClass(), this.getGenericParameter(), name + ".java", constants , new String[] { }, typeinferenceResults); //letzter Parameter sind implementierte Interfaces
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new DHBWInstructionFactory(_cg, _cp);
|
||||
|
||||
//Die Felder in Methoden Felder und Konstruktoren aufteilen:
|
||||
Menge<FieldDeclaration> fieldDeclarations = new Menge<>();
|
||||
Menge<Constructor> constructors = new Menge<>();
|
||||
Menge<Method> methods = new Menge<>();
|
||||
for(Field field : this.fielddecl){
|
||||
if(field instanceof Constructor)constructors.add((Constructor)field);
|
||||
if(field instanceof Method && ! (field instanceof Constructor))methods.add((Method)field);
|
||||
if(field instanceof FieldDeclaration)fieldDeclarations.add((FieldDeclaration)field);
|
||||
//field.genByteCode(_cg);
|
||||
}
|
||||
|
||||
//Zuerst die Methoden und Felder abarbeiten:
|
||||
for(Method m : methods){
|
||||
m.genByteCode(_cg, this, typeinferenceResults);
|
||||
}
|
||||
InstructionList fieldInitializations = new InstructionList();
|
||||
for(FieldDeclaration f : fieldDeclarations){
|
||||
//Die Felder können noch nicht überladen werden. Hier ist nur die erste der Lösungen möglich:
|
||||
fieldInitializations.append(f.genByteCode(_cg, typeinferenceResults.getTypeReconstructions().get(0)));
|
||||
}
|
||||
//Die Konstruktoren müssen die Feld initialisierungswerte beinhalten:
|
||||
for(Constructor c : constructors){
|
||||
c.genByteCode(_cg, fieldInitializations);
|
||||
}
|
||||
|
||||
return new ByteCodeResult(_cg);
|
||||
}
|
||||
|
||||
public JavaClassName getName()
|
||||
{
|
||||
return new JavaClassName((this.pkgName!=null ? this.pkgName.toString() +"." : "") +this.name);
|
||||
}
|
||||
public void setName(String strName)
|
||||
{
|
||||
name = new JavaClassName(strName);
|
||||
}
|
||||
public void setModifiers(Modifiers mod)
|
||||
{
|
||||
this.modifiers = mod;
|
||||
}
|
||||
public Modifiers getModifiers()
|
||||
{
|
||||
return this.modifiers;
|
||||
}
|
||||
/**
|
||||
* Liefert die AccessFlags fuer den Bytecode zurueck.
|
||||
*/
|
||||
public short getAccessFlags()
|
||||
{
|
||||
short ret = 0;
|
||||
if (modifiers != null) {
|
||||
ret = modifiers.calculate_access_flags();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Menge<RefType> getSuperInterfaces()
|
||||
{
|
||||
return superif;
|
||||
}
|
||||
|
||||
private Block class_block;
|
||||
|
||||
private Hashtable<String,String> parahash = new Hashtable<String,String>(); // parametrisierten Attrib. werden mit den Paramet.aus paralist verk.
|
||||
|
||||
|
||||
private TypeAssumptions typeAssumptions = null;//muss mit null Initialisiert werden. Darf nur über getTypeAssumptions abgerufen werden.
|
||||
|
||||
private Menge<Field> fielddecl = new Menge<Field>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private int offset;
|
||||
private RefType superClass;
|
||||
|
||||
public Menge<Field> getFields()
|
||||
{
|
||||
return fielddecl;
|
||||
}
|
||||
|
||||
// ino.method.get_ParaList.23101.definition
|
||||
public List<? extends Type> get_ParaList()
|
||||
// ino.end
|
||||
// ino.method.get_ParaList.23101.body
|
||||
{
|
||||
//if(this.paralist == null)return new Menge<Type>();
|
||||
return this.getGenericParameter().getGTVList();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.set_ParaHash.23104.definition
|
||||
public void set_ParaHash(Hashtable<String,String> hash)
|
||||
// ino.end
|
||||
// ino.method.set_ParaHash.23104.body
|
||||
{
|
||||
this.parahash = hash;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.get_ParaHash.23107.definition
|
||||
public Hashtable<String,String> get_ParaHash()
|
||||
// ino.end
|
||||
// ino.method.get_ParaHash.23107.body
|
||||
{
|
||||
return this.parahash;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// TypeReconstructionAlgorithmus
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
@ -220,15 +93,8 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
* @return Liste aller bisher berechneten, m�glichen Typkombinationen
|
||||
* @throws CTypeReconstructionException
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.TRProg.23110.definition
|
||||
public ConstraintsSet typeReconstruction(TypeAssumptions globalAssumptions)
|
||||
// ino.end
|
||||
// ino.method.TRProg.23110.body
|
||||
{
|
||||
/*
|
||||
|
||||
*/
|
||||
//////////////////////////////
|
||||
// Und los geht's:
|
||||
//////////////////////////////
|
||||
@ -280,7 +146,7 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
|
||||
this.typeAssumptions = assumptions; //Diese müssen anschlieÃend nicht wieder generiert werden.
|
||||
return assumptions;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <br/>Author: Martin Pl�micke
|
||||
|
@ -1,290 +0,0 @@
|
||||
// ino.module.ClassBody.8554.package
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
// ino.end
|
||||
// ino.module.ClassBody.8554.import
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
// ino.end
|
||||
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
|
||||
|
||||
|
||||
|
||||
// ino.class.ClassBody.23143.declaration
|
||||
public class ClassBody
|
||||
{
|
||||
// ino.attribute.fielddecl.23146.declaration
|
||||
private Menge<Field>fielddecl = new Menge<Field>();
|
||||
// ino.end
|
||||
// ino.attribute.kill.23155.declaration
|
||||
public Hashtable<Type,Type> kill = new Hashtable<Type,Type>();
|
||||
// ino.end
|
||||
|
||||
// ino.attribute.parserlog.23158.declaration
|
||||
protected static Logger parserlog = Logger.getLogger("parser");
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.complete_parahashtable.23173.defdescription type=block
|
||||
/* public void set_paratype(Menge classlist, UsedId superclass, Menge
|
||||
pl,Hashtable ph,boolean ext){ DeclId decl;
|
||||
FieldDecl field;
|
||||
System.out.println("++ ParaCheck: Fielddecl's: "+fielddecl.toString());
|
||||
|
||||
for(Enumeration e=fielddecl.elements();e.hasMoreElements();){
|
||||
field = (FieldDecl)e.nextElement();
|
||||
for(Enumeration e1=field.get_Name().elements();e1.hasMoreElements();){
|
||||
decl=(DeclId)e1.nextElement();
|
||||
|
||||
if(superclass != null){
|
||||
System.out.println("superclass.get_ParaList: "
|
||||
+superclass.get_ParaList().toString());
|
||||
for(Enumeration e2 =
|
||||
superclass.get_ParaList().elements();e2.hasMoreElements();){
|
||||
System.out.println("paralist.elements:: "+((Type)e2.nextElement()).get_Type());
|
||||
}
|
||||
}
|
||||
if(decl.get_Paratyp()!=null){
|
||||
System.out.println("++ ParaCheck: Name:
|
||||
"+decl.get_Name()+"\tParatyp: "+decl.get_Paratyp()); }
|
||||
else System.out.println("++ ParaCheck: Name: "+decl.get_Name()+"\tkein
|
||||
Paratyp gesetzt."); }
|
||||
}
|
||||
}
|
||||
*/
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
|
||||
public Menge<Field> getFields()
|
||||
{
|
||||
return fielddecl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Andreas Stadelmeier, a10023
|
||||
* Fügt der Klasse eine Feld hinzu.
|
||||
* @param feld
|
||||
*/
|
||||
public void addField(Field i)
|
||||
{
|
||||
fielddecl.addElement(i);
|
||||
}
|
||||
|
||||
|
||||
// ino.method.string_rec.23191.definition
|
||||
static String string_rec(Hashtable ht)
|
||||
// ino.end
|
||||
// ino.method.string_rec.23191.body
|
||||
{
|
||||
String record=("[");
|
||||
for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){
|
||||
String s = (String)k.nextElement();
|
||||
Object o = e.nextElement();
|
||||
|
||||
record=record.concat(" "+s);
|
||||
|
||||
if(o instanceof Type){
|
||||
record=record.concat(" = "+((Type)o).getName());
|
||||
}
|
||||
|
||||
else if(o instanceof Hashtable){
|
||||
record=record.concat("= ");
|
||||
record=record.concat(string_rec((Hashtable)o));
|
||||
if(e.hasMoreElements())
|
||||
record=record.concat(", ");
|
||||
}
|
||||
else if(o instanceof String){
|
||||
record=record.concat(" = "+o);
|
||||
if(e.hasMoreElements())
|
||||
record=record.concat(", ");
|
||||
}
|
||||
else {
|
||||
record=("[FEHLER: string_rec: unbekannter Typ!!!!!!");
|
||||
}
|
||||
}
|
||||
record=record.concat("]");
|
||||
return(record);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.string_rec.23194.defdescription type=block
|
||||
/*static void string_rec(Menge v){
|
||||
String record=("{");
|
||||
for(Enumeration e=v.elements();e.hasMoreElements();){
|
||||
Type t = (Type)e.nextElement();
|
||||
record=record.concat(" "+t.getName());
|
||||
|
||||
if(e.hasMoreElements())
|
||||
record=record.concat(",");
|
||||
}
|
||||
record=record.concat("}");
|
||||
parserlog.debug(record);
|
||||
}*/
|
||||
// ino.end
|
||||
// ino.method.string_rec.23194.definition
|
||||
static String string_rec(String st, Hashtable ht)
|
||||
// ino.end
|
||||
// ino.method.string_rec.23194.body
|
||||
{
|
||||
String record=(st);
|
||||
record=record.concat("[");
|
||||
for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){
|
||||
String s = (String)k.nextElement();
|
||||
Object o = e.nextElement();
|
||||
|
||||
record=record.concat(" "+s);
|
||||
|
||||
if(o instanceof Type){
|
||||
record=record.concat(" = "+((Type)o).getName());
|
||||
}
|
||||
|
||||
else if(o instanceof Hashtable){
|
||||
record=record.concat("= ");
|
||||
record=record.concat(string_rec((Hashtable)o));
|
||||
if(e.hasMoreElements())
|
||||
record=record.concat(", ");
|
||||
}
|
||||
else if(o instanceof String){
|
||||
record=record.concat(" = "+o);
|
||||
if(e.hasMoreElements())
|
||||
record=record.concat(", ");
|
||||
}
|
||||
else {
|
||||
record=("FEHLER: string_rec: unbekannter Typ!!!!!! " +o);
|
||||
}
|
||||
}
|
||||
record=record.concat("]");
|
||||
return(record);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.string_rec.23197.definition
|
||||
static String string_rec(String st,Menge v)
|
||||
// ino.end
|
||||
// ino.method.string_rec.23197.body
|
||||
{
|
||||
String record=(st);
|
||||
record=record.concat("{");
|
||||
for(Enumeration e=v.elements();e.hasMoreElements();){
|
||||
Type t = (Type)e.nextElement();
|
||||
record=record.concat(" "+t.getName());
|
||||
if(e.hasMoreElements())
|
||||
record=record.concat(", ");
|
||||
}
|
||||
record=record.concat("}");
|
||||
return(record);
|
||||
}
|
||||
// ino.end
|
||||
// ino.method.istParameterOK.23200.defdescription type=line
|
||||
//
|
||||
// ********************************************************************************************
|
||||
//
|
||||
// ino.end
|
||||
/*
|
||||
// ino.method.istParameterOK.23200.definition
|
||||
public void istParameterOK( Menge Parameter, Menge<Class> KlassenVektor )
|
||||
// ino.end
|
||||
// ino.method.istParameterOK.23200.body
|
||||
{
|
||||
// otth: prueft rekursiv, ob Parameter im Klassenvektor vorkommt, falls RefType, oder ob TypePlaceholder nicht vorkommt
|
||||
|
||||
for( int i = 0; i < Parameter.size(); i++)
|
||||
{
|
||||
Type TempParameter = (Type)(Parameter.elementAt(i));
|
||||
|
||||
// an dieser Stelle: Parametername
|
||||
if ( TempParameter instanceof RefType )
|
||||
{
|
||||
// t im Klassenvektor suchen --> muss deklariert sein
|
||||
boolean bGefunden = false;
|
||||
for( int k = 0; k < KlassenVektor.size(); k++)
|
||||
{
|
||||
if( KlassenVektor.elementAt(k).getName().equals(((RefType)TempParameter).getTypeName()) )
|
||||
{
|
||||
// Namen gleich --> Parameterliste rekursiv pruefen
|
||||
if( ((RefType)TempParameter).get_ParaList() != null )
|
||||
{
|
||||
if( ((RefType)TempParameter).get_ParaList().size() != KlassenVektor.elementAt(k).get_ParaList().size() )
|
||||
{
|
||||
parserlog.error( "SEMANTIK-CHECK-FEHLER: Parameteranzahl von\n" + TempParameter.getName() + " stimmt mit der Klassendefinition\n" + KlassenVektor.elementAt(k).getName() + " nicht �berein.", Section.OLD );
|
||||
System.exit( 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
istParameterOK( ((RefType)TempParameter).get_ParaList(), KlassenVektor );
|
||||
bGefunden = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// OK ...
|
||||
bGefunden = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Parameter wurde nicht gefunden:
|
||||
if( !bGefunden )
|
||||
{
|
||||
parserlog.error( "SEMANTIK-CHECK-FEHLER: Parameter " + TempParameter.getName() + " ist noch nicht als Klasse definiert." );
|
||||
System.exit( 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Tylose Variablen d�rfen nicht deklariert sein
|
||||
for( int k = 0; k < KlassenVektor.size(); k++)
|
||||
{
|
||||
if( KlassenVektor.elementAt(k).getName().equals(TempParameter.getName()) )
|
||||
{
|
||||
parserlog.error( "SEMANTIK-CHECK-FEHLER: Parameter " + TempParameter.getName() + " ist bereits als Klasse definiert." );
|
||||
System.exit( 1 );
|
||||
}
|
||||
}
|
||||
// nicht gefunden
|
||||
}
|
||||
} // end otth; end if: t = RefType
|
||||
}
|
||||
// ino.end
|
||||
*/
|
||||
|
||||
// ino.method.toString.23203.defdescription type=javadoc
|
||||
/**
|
||||
* <br/>Author: Martin Pl�micke
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.toString.23203.definition
|
||||
public String toString()
|
||||
// ino.end
|
||||
// ino.method.toString.23203.body
|
||||
{
|
||||
return fielddecl.toString();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
JavaCodeResult ret = new JavaCodeResult("{\n");
|
||||
for(Field field : this.fielddecl)ret.attach( field.printJavaCode(resultSet) ).attach( "\n" );
|
||||
return ret.attach("}\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
@ -104,15 +104,6 @@ public class Constructor extends Method {
|
||||
gtv.parserPostProcessing(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*public Constructor(Method methode){
|
||||
super(methode.getOffset());
|
||||
this.methode = methode;
|
||||
this.setDeclIdMenge(methode.getDeclIdMenge());
|
||||
this.methode.setType(this.methode.getParentClass().getType());
|
||||
}*/
|
||||
|
||||
|
||||
@Override
|
||||
public JavaClassName getTypeName() {
|
||||
@ -123,61 +114,3 @@ public class Constructor extends Method {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
// ino.class.Constructor.23267.declaration
|
||||
public class Constructor_Backup extends Method
|
||||
// ino.end
|
||||
// ino.class.Constructor.23267.body
|
||||
{
|
||||
// ino.method.Constructor.23271.definition
|
||||
public Constructor_Backup()
|
||||
// ino.end
|
||||
// ino.method.Constructor.23271.body
|
||||
{
|
||||
this.setParameterList(null);
|
||||
// #JB# 04.06.2005
|
||||
// ###########################################################
|
||||
DeclId decl = new DeclId();
|
||||
decl.set_Name("<init>");
|
||||
this.set_DeclId(decl);
|
||||
// ###########################################################
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.get_codegen_Param_Type.23274.definition
|
||||
public String get_codegen_Param_Type(Menge paralist)
|
||||
// ino.end
|
||||
// ino.method.get_codegen_Param_Type.23274.body
|
||||
{
|
||||
String ret = new String();
|
||||
if(this.getParameterList() == null)
|
||||
{
|
||||
ret += "()";
|
||||
}
|
||||
else
|
||||
{
|
||||
ret += this.getParameterList().get_codegen_ParameterList(paralist);
|
||||
}
|
||||
ret += "V";
|
||||
return ret;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.codegen.23277.definition
|
||||
public void codegen(ClassFile classfile, Menge paralist)
|
||||
throws JVMCodeException
|
||||
// ino.end
|
||||
// ino.method.codegen.23277.body
|
||||
{
|
||||
classfile.set_constructor_founded(true);
|
||||
classfile.add_method("<init>", this.get_codegen_Param_Type(paralist), this.getParameterList(), null, get_Block(), declid.firstElement().get_access_flags(), paralist, false);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
}
|
||||
*/
|
||||
|
@ -26,8 +26,10 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta
|
||||
|
||||
private GenericDeclarationList genericParameters;
|
||||
|
||||
public Field(int offset){
|
||||
public Field(String name, Type type, int offset){
|
||||
super(offset);
|
||||
this.name = name;
|
||||
this.typ = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,36 +34,20 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
public class FieldDeclaration extends Field{
|
||||
|
||||
private Expr wert;
|
||||
private String name;
|
||||
//private Type type;
|
||||
//private Menge<GenericTypeVar> parameter;
|
||||
|
||||
|
||||
/**
|
||||
* Dieser Konstruktor der FieldDeclaration erstellt den Syntaxknoten vollständig.
|
||||
* Kein nachträgliches hinzfügen von Informationen oder aufrufen von parserPostProcessing ist notwendig.
|
||||
*/
|
||||
public FieldDeclaration(String name, Type typ){
|
||||
super(0);//Dieser Deklarator wird nicht vom Parser aufgerufen. Dadurch gibt es auch keinen Offset
|
||||
this.typ = typ;
|
||||
this.name = name;
|
||||
public FieldDeclaration(String name, Type typ, Expr value){
|
||||
super(name, typ, 0);//Dieser Deklarator wird nicht vom Parser aufgerufen. Dadurch gibt es auch keinen Offset
|
||||
this.wert = value;
|
||||
}
|
||||
|
||||
public FieldDeclaration(int offset){
|
||||
super(offset);
|
||||
}
|
||||
|
||||
public void setWert(Expr initialExpression){
|
||||
this.wert = initialExpression;
|
||||
}
|
||||
public Expr getWert(){
|
||||
return this.wert;
|
||||
}
|
||||
|
||||
public String getIdentifier(){
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@ -103,11 +87,6 @@ public class FieldDeclaration extends Field{
|
||||
if(this.wert!=null)ret.add(this.wert);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int getVariableLength()
|
||||
{
|
||||
return name.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintsSet TYPE(TypeAssumptions publicAssumptions) {
|
||||
|
@ -1,9 +1,9 @@
|
||||
// ino.module.FormalParameter.8561.package
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
// ino.end
|
||||
|
||||
// ino.module.FormalParameter.8561.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
|
||||
@ -19,10 +19,7 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
|
||||
|
||||
// ino.class.FormalParameter.23391.declaration
|
||||
public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeInsertable
|
||||
// ino.end
|
||||
// ino.class.FormalParameter.23391.body
|
||||
{
|
||||
private Type type;
|
||||
private String name;
|
||||
@ -51,33 +48,10 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ino.method.getType.23413.definition
|
||||
public Type getType()
|
||||
// ino.end
|
||||
// ino.method.getType.23413.body
|
||||
{
|
||||
return type;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.getTypeName.23416.definition
|
||||
public String getTypeName()
|
||||
// ino.end
|
||||
// ino.method.getTypeName.23416.body
|
||||
{ if(this.getType() == null)return "";
|
||||
return this.getType().getName().toString();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
//private Type typeVariable;
|
||||
|
||||
public String getTypeInformation() {
|
||||
return getType().toString() + " " +this.getIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
@ -96,33 +70,6 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setOffset(int offset) {
|
||||
//Das Offset steht in declId
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Menge<SyntaxTreeNode> getChildren() {
|
||||
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
|
||||
if(type != null)ret.add(this.type);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
super.parserPostProcessing(parent);
|
||||
if(this.type==null)this.type = TypePlaceholder.fresh(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
|
||||
ResultSet resultSet) {
|
||||
@ -131,15 +78,6 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
|
||||
return new TypeInsertPoint(this, this, t, resultSet);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getVariableLength() {
|
||||
int ret = 0;
|
||||
ret += this.getTypeName().length();
|
||||
ret +=this.getIdentifier().length();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription(){
|
||||
String ret = "";
|
||||
@ -148,6 +86,4 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
|
||||
}
|
||||
return ret+this.getIdentifier();
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -6,33 +6,22 @@ import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import de.dhbwstuttgart.parser.GenericVarDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
|
||||
|
||||
/**
|
||||
* Stellt eine Deklarations-Liste von Generischen Variablen dar.
|
||||
* Kann vor Methoden und Klassen auftauchen. (<....>)
|
||||
* @author janulrich
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<GenericTypeVar>{
|
||||
|
||||
private int offsetOfLastElement;
|
||||
private List<GenericTypeVar> gtvs = new Menge<>();
|
||||
|
||||
<<<<<<< HEAD
|
||||
public GenericDeclarationList(List<GenericTypeVar> values, int endOffset) {
|
||||
super(endOffset);
|
||||
gtvs = values;
|
||||
=======
|
||||
public GenericDeclarationList(){
|
||||
this(new Menge<GenericTypeVar>(), -1);
|
||||
}
|
||||
|
||||
public GenericDeclarationList(Menge<GenericTypeVar> values, int endOffset) {
|
||||
this.addAll(values);
|
||||
>>>>>>> refactoring
|
||||
this.offsetOfLastElement = endOffset;
|
||||
}
|
||||
|
||||
@ -45,11 +34,6 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
|
||||
return getEndOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVariableLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<GenericTypeVar> iterator() {
|
||||
return this.gtvs.iterator();
|
||||
|
@ -69,19 +69,28 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
private Type returntype;
|
||||
private String name;
|
||||
|
||||
private int overloadedID;
|
||||
private boolean isAbstract = false;
|
||||
private Menge<String> types_in_parameterlist = new Menge<String>();
|
||||
private int m_LineNumber = MyCompiler.NO_LINENUMBER;
|
||||
private int m_Offset = -1; // hinzugef�gt hoth: 07.04.2006
|
||||
private Modifiers modifiers;
|
||||
|
||||
protected static Logger inferencelog = Logger.getLogger("inference");
|
||||
protected static Logger parserlog = Logger.getLogger("parser");
|
||||
|
||||
public Method(int offset) {
|
||||
super(offset);
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param returnType
|
||||
* @param params
|
||||
* @param block - use null to create abstract method
|
||||
* @param offset
|
||||
*/
|
||||
public Method(String name, Type returnType, ParameterList params, Block block, int offset) {
|
||||
this(name, returnType, params, new ExceptionList(), block, offset);
|
||||
}
|
||||
|
||||
public Method(String name, Type returnType, ParameterList params, ExceptionList exceptions, Block block, int offset){
|
||||
super(name, generateMethodType(returnType, params), offset);
|
||||
}
|
||||
|
||||
public Method(String name, Type returnType, ParameterList parameterList, Block block,
|
||||
GenericDeclarationList gtvDeclarations, int offset) {
|
||||
this(offset);
|
||||
@ -295,12 +304,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
// Methode und Block teilen sich einen ReturnType:
|
||||
return this.returntype;
|
||||
}
|
||||
public static Method createEmptyMethod(Block withBlock, String withSignature, Class parent) {
|
||||
public static Method createEmptyMethod(Block withBlock, String withSignature) {
|
||||
Method ret = Method.createEmptyMethod(withSignature, parent);
|
||||
ret.set_Block(withBlock);
|
||||
return ret;
|
||||
}
|
||||
public static Method createEmptyMethod(String withSignature, Class parent) {
|
||||
public static Method createEmptyMethod(String withSignature) {
|
||||
Block block = new Block(new List<Statement>());
|
||||
Method ret = new Method(withSignature, new de.dhbwstuttgart.syntaxtree.type.Void(0), new ParameterList(), block, new EmptyGenericDeclarationList(), 0);
|
||||
DImethod.set_Name(withSignature);
|
||||
|
@ -0,0 +1,9 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
/**
|
||||
* Generiert Hilfsmethoden für die Unary und Binary Operatoren
|
||||
* Diese Methoden stellen die möglichen Operationen +,-,++, etc dar
|
||||
*/
|
||||
public class PrimitiveMethodsGenerator {
|
||||
|
||||
}
|
@ -164,9 +164,6 @@ public class Binary extends BinaryExpr
|
||||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25027.body
|
||||
{
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
|
@ -16,14 +16,9 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
|
||||
|
@ -17,7 +17,6 @@ import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.ConstructorCall;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
|
@ -17,7 +17,6 @@ import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
|
@ -10,7 +10,6 @@ import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.ConstructorCall;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
@ -47,15 +46,7 @@ public class ThisCall extends MethodCall
|
||||
{
|
||||
return this.arglist;
|
||||
}
|
||||
|
||||
public void set_UsedId(UsedId ui)
|
||||
{
|
||||
this.usedid = ui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
throw new TypeinferenceException("this(...)-Aufruf kann nicht als Ausdruck verwendet werden",this);
|
||||
|
@ -4,42 +4,42 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
// ino.module.UnaryExpr.8655.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
|
||||
|
||||
|
||||
|
||||
// ino.class.UnaryExpr.26298.declaration
|
||||
public abstract class UnaryExpr extends Expr
|
||||
// ino.end
|
||||
// ino.class.UnaryExpr.26298.body
|
||||
public abstract class UnaryExpr extends MethodCall
|
||||
{
|
||||
public Expr expr;
|
||||
|
||||
// ino.method.UnaryExpr.26302.definition
|
||||
public UnaryExpr(int offset,int variableLength)
|
||||
// ino.end
|
||||
// ino.method.UnaryExpr.26302.body
|
||||
{
|
||||
super(offset,variableLength);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
|
||||
/**
|
||||
* TODO
|
||||
* Je nach Typisierung wird eine andere Methode aufgerufen
|
||||
* Alle Parameter müssen in ihren primitiven Datentyp umgewandelt werden
|
||||
* Der Bytecodegenerator muss anhand der ermittelten Typen den korrekten Bytecode produzieren
|
||||
* Es werden nie Typen generiert, die nicht Containertypen von primitiven Datentypen sind.
|
||||
* Das lassen die generierten Constraints nicht zu.
|
||||
*/
|
||||
return super.genByteCode(cg, rs);
|
||||
}
|
||||
|
||||
private Menge<RefType> getNumericTypes(){
|
||||
Menge<RefType> ret = new Menge<>();
|
||||
ret.add(new RefType("Integer",this,-1));
|
||||
ret.add(new RefType("Long",this,-1));
|
||||
ret.add(new RefType("Double",this,-1));
|
||||
ret.add(new RefType("Float",this,-1));
|
||||
return ret ;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
if(this.getType() == null)this.setType(TypePlaceholder.fresh(this));
|
||||
@ -63,7 +63,6 @@ public abstract class UnaryExpr extends Expr
|
||||
this.setType(new de.dhbwstuttgart.syntaxtree.type.Void(this, -1).TYPE(assumptions, this));
|
||||
return ret;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
Loading…
Reference in New Issue
Block a user