This()-Aufruf anfügen. Änderungen an Constructor vornehmen. Keine lauffähige Version

This commit is contained in:
JanUlrich 2015-02-25 16:34:29 +01:00
parent 9261518e5a
commit 9e99a5b20b
10 changed files with 1130 additions and 981 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1444,6 +1444,9 @@ statement :statementwithouttrailingsubstatement
$$=$1;
}
|forstatement
{
$$=$1;
}| explicitconstructorinvocation
{
$$=$1;
}

View File

@ -1170,7 +1170,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
super.parserPostProcessing(parent);
//Wenn keine Superklasse, dann erbt die Klasse zwangsweise von Object:
if(superclassid == null || superclassid.get_Name().size()<1){
@ -1183,7 +1182,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
for(Field f : this.getFields()){
if(f instanceof Method && !(f instanceof Constructor)){
Method method = (Method)f;
if(method.get_Method_Name().equals(this.getName()) ){
if(method.get_Method_Name().equals(this.getName().toString()) ){
tempFields.add(new Constructor(method));
}else{
tempFields.add(f);
@ -1214,9 +1213,11 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
else this.genericClassParameters.add(new GenericTypeVar(t.get_Name(),this,-1));
}
*/
/*
for(Type t : this.get_ParaList()){
t.parserPostProcessing(this);
}
*/
/*
for(GenericTypeVar gtv : this.getGenericParameter()){
gtv.setParentClass(this);;
@ -1225,6 +1226,9 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
//TODO: Umwandlung zu RefTypes funktioniert noch nicht richtig. (siehe LambdaTest2)
//Als RefType geparste Generische Variablen umwandeln:
this.wandleRefTypeAttributes2GenericAttributes();
//Erst am Schluss, nachdem Methoden zu Konstruktoren umgewandelt wurden:
super.parserPostProcessing(parent);
}
@Override
@ -1235,9 +1239,11 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
@Override
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
for(Field f : this.getFields()){
ret.add(f);
}
//for(Field f : this.getFields()){
// ret.add(f);
//}
ret.addAll(this.getFields());
ret.addAll(this.get_ParaList());
ret.addAll(this.getGenericParameter());
return ret;
}

View File

@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.statement.Block;
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;
@ -19,6 +20,8 @@ import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class Constructor extends Method {
private Method methode;
@ -27,6 +30,11 @@ public class Constructor extends Method {
* Parser kann nicht zwischen einem Konstruktor und einer Methode unterscheiden.
* Diese Klasse beherbegt den als Methode geparsten Konstruktor und wandelt sein verhalten zu dem eines Konstruktors ab.
*/
public Constructor(Method methode){
super(methode.get_Method_Name(), methode.getParameterList(),methode.get_Block(), methode.getGenericDeclarationList(), methode.getOffset());
}
/*
public Constructor(Method methode){
super(methode.getOffset());
this.methode = methode;
@ -34,21 +42,60 @@ public class Constructor extends Method {
this.methode.setType(this.methode.getParentClass().getType());
}
/*
@Override
public void setGenericMethodParameters(
Vector<GenericTypeVar> genericMethodParameters) {
this.methode.setGenericMethodParameters(genericMethodParameters);
public Vector<GenericTypeVar> getGenericParameter() {
return this.methode.getGenericParameter();
}
@Override
public Vector<GenericTypeVar> getGenericMethodParameters() {
return this.methode.getGenericMethodParameters();
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
ResultSet resultSet) {
return this.methode.createTypeInsertPoint(tph, resultSet);
}
*/
@Override
public boolean isPublic() {
return this.methode.isPublic();
}
@Override
public String getGenericVarDeclarationString(String genericVarDeclaration) {
return this.methode.getGenericVarDeclarationString(genericVarDeclaration);
}
@Override
public int getGenericVarDeclarationOffset() {
return this.methode.getGenericVarDeclarationOffset();
}
@Override
public void setGenericParameter(GenericDeclarationList params) {
this.methode.setGenericParameter(params);
}
@Override
public GTVDeclarationContext getGTVDeclarationContext() {
return this;
}
@Override
public void addTypeInsertPoints(TypeInsertSet insertSet, ResultSet result) {
this.methode.addTypeInsertPoints(insertSet, result);
}
@Override
public boolean seesType(Type tA2) {
return this.methode.seesType(tA2);
}
@Override
public JavaClassName getTypeName() {
@ -310,7 +357,7 @@ public class Constructor extends Method {
public Class getParentClass() {
return this.methode.getParentClass();
}
*/
}

View File

@ -61,6 +61,10 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta
return ret;
}
GenericDeclarationList getGenericDeclarationList(){
return this.genericParameters;
}
public void set_DeclId(DeclId did)
{
this.declid.addElement(did);

View File

@ -98,6 +98,19 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
super(offset);
}
public Method(String name, 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);
}
/*
// ino.method.setGenericMethodParameters.23521.definition
public void setGenericMethodParameters(Vector<GenericTypeVar> genericMethodParameters)
@ -503,15 +516,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
}
*/
}
// ino.end
// ino.method.set_Method_Name.23617.definition
public void set_Method_Name(String string)
// ino.end
// ino.method.set_Method_Name.23617.body
{
if(declid.size()==0)declid.add(0, new DeclId(string));
declid.set(0,new DeclId(string));
}
// ino.end
@ -584,7 +594,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
*/
@Override
public TypeAssumptions createTypeAssumptions(Class classmember) {
Class parentClass = this.getParentClass();
Class parentClass = classmember;//this.getParentClass();
TypeAssumptions ret = new TypeAssumptions();
ret.addAssumption(new MethodAssumption(this, parentClass));
return ret;
@ -673,7 +683,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
super.parserPostProcessing(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;
//Class parentClass = (Class)parent;
if(this.returntype == null)this.returntype = TypePlaceholder.fresh(this);
this.returntype.parserPostProcessing(this);
if(this.parameterlist != null){
@ -690,9 +700,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
ret.add(this.block);
for(FormalParameter param : this.parameterlist){
ret.add(param);
}
ret.add(this.parameterlist);
ret.addAll(this.getGenericParameter());
return ret;
}

View File

@ -20,7 +20,7 @@ import de.dhbwstuttgart.typeinference.ResultSet;
// ino.class.ParameterList.23620.declaration
public class ParameterList implements Iterable<FormalParameter>
public class ParameterList extends SyntaxTreeNode implements Iterable<FormalParameter>
// ino.end
// ino.class.ParameterList.23620.body
{
@ -168,5 +168,22 @@ public class ParameterList implements Iterable<FormalParameter>
if(this.formalparameter!=null)return this.formalparameter.equals(equals.formalparameter);
return true;
}
@Override
public int getOffset() {
if(formalparameter == null || formalparameter.size()==0)return 0;
return formalparameter.firstElement().getOffset();
}
@Override
public int getVariableLength() {
return 0;
}
@Override
public Vector<? extends SyntaxTreeNode> getChildren() {
return formalparameter;
}
}
// ino.end

View File

@ -38,7 +38,7 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
return this.parent;
}
public abstract Vector<SyntaxTreeNode> getChildren();
public abstract Vector<? extends SyntaxTreeNode> getChildren();
public Class getParentClass(){
SyntaxTreeNode parent = this.getParent();

View File

@ -31,6 +31,13 @@ public class MethodCall extends Expr
// ino.end
// ino.class.MethodCall.25623.body
{
public MethodCall(Receiver receiver, String methodName, ArgumentList argumentList, int offset){
this(offset, 0);
this.set_Receiver(receiver);
this.set_Name(methodName);
this.set_ArgumentList(argumentList);
}
// ino.method.MethodCall.25627.definition
public MethodCall(int offset, int variableLength)
// ino.end

View File

@ -13,6 +13,7 @@ import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.SCStatementException;
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;
@ -22,6 +23,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -125,7 +127,27 @@ public class This extends Expr
return ret;
}
public String toString()
/**
* This kann auch als Konstruktoraufruf in einem Konstruktor-Block vorkommen.
*/
@Override
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
//Kontrollieren, dass sich this(...) in einem Konstruktor und dort als erstes Statement befindet:
SyntaxTreeNode p = this.getGTVDeclarationContext();
if(p instanceof Constructor &&
((Constructor)p).get_Block().statements.firstElement().equals(this)){
//Constraints generieren:
MethodCall constructorCall = new MethodCall(new Receiver(this), this.getParentClass().getName().toString(), arglist, this.getOffset());
ret.add(constructorCall.TYPEStmt(assumptions));
return ret;
}else{
//Ansonsten Fehler ausgeben:
throw new TypeinferenceException("This()-Aufruf hier nicht möglich", this);
}
}
public String toString()
// ino.end
// ino.method.toString.25738.body
{