Expr und ExprStmt ändern

This commit is contained in:
JanUlrich 2016-09-20 15:18:13 +02:00
parent bc812ad083
commit a1227a8b1b
9 changed files with 80 additions and 267 deletions

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.ClassGen;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.core.IItemWithOffset;
@ -146,4 +147,5 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
return offset; return offset;
} }
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
} }

View File

@ -14,7 +14,11 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
public class ArgumentList extends SyntaxTreeNode public class ArgumentList extends SyntaxTreeNode
{ {
public Menge<Expr> expr = new Menge<Expr>(); public ArgumentList(int offset) {
super(offset);
}
public Menge<Expr> expr = new Menge<Expr>();
public Object get_firstElement() public Object get_firstElement()

View File

@ -1,7 +1,6 @@
// ino.module.Assign.8622.package
package de.dhbwstuttgart.syntaxtree.statement; package de.dhbwstuttgart.syntaxtree.statement;
// ino.end
// ino.module.Assign.8622.import
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
@ -37,60 +36,31 @@ import de.dhbwstuttgart.typeinference.unify.TypeUnify;
// ino.class.Assign.24926.declaration public class Assign extends ExprStmt
public class Assign extends Expr
// ino.end
// ino.class.Assign.24926.body
{ {
// ino.method.Assign.24930.definition
public Assign(int offset,int variableLength)
// ino.end
// ino.method.Assign.24930.body
{
super(offset,variableLength);
}
// ino.end
public Assign(Type type, int offset) {
super(type, offset);
}
// ino.attribute.expr1.24933.declaration public Expr expr1;
public Expr expr1;
// ino.end
// ino.attribute.expr2.24936.declaration
public Expr expr2; public Expr expr2;
// ino.end
// ino.attribute.parserlog.24939.decldescription type=javadoc
/** /**
* Logger log4j * Logger log4j
*/ */
// ino.end
// ino.attribute.parserlog.24939.declaration
protected static Logger parserlog = Logger.getLogger("parser"); protected static Logger parserlog = Logger.getLogger("parser");
// ino.end
// ino.method.set_Expr.24942.definition
public void set_Expr(Expr expr1,Expr expr2) public void set_Expr(Expr expr1,Expr expr2)
// ino.end
// ino.method.set_Expr.24942.body
{ {
this.expr1 = expr1; this.expr1 = expr1;
this.expr2 = expr2; this.expr2 = expr2;
} }
// ino.end
// ino.method.get_Name.24948.definition
public String get_Name() public String get_Name()
// ino.end
// ino.method.get_Name.24948.body
{ {
return null; return null;
} }
// ino.end
/** /**
@ -102,7 +72,7 @@ public class Assign extends Expr
ret.add(expr1.TYPEExpr(assumptions)); ret.add(expr1.TYPEExpr(assumptions));
ret.add(expr2.TYPEExpr(assumptions)); ret.add(expr2.TYPEExpr(assumptions));
//this.setTypeVariable( TypePlaceholder.fresh(this)); //this.setTypeVariable( TypePlaceholder.fresh(this));
this.setType(TypePlaceholder.fresh(this)); //this.setType(TypePlaceholder.fresh(this));
ret.add(ConstraintsSet.createSingleConstraint(expr2.getType().TYPE(assumptions, this), expr1.getType().TYPE(assumptions, this))); //expr2.type <. expr1.type ret.add(ConstraintsSet.createSingleConstraint(expr2.getType().TYPE(assumptions, this), expr1.getType().TYPE(assumptions, this))); //expr2.type <. expr1.type
ret.add(ConstraintsSet.createSingleConstraint(expr1.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this))); ret.add(ConstraintsSet.createSingleConstraint(expr1.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
return ret; return ret;
@ -117,7 +87,7 @@ public class Assign extends Expr
@Override @Override
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){ public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){
ConstraintsSet ret = this.TYPEExpr(assumptions); //TypeExpr aufrufen ConstraintsSet ret = this.TYPEExpr(assumptions); //TypeExpr aufrufen
this.setType(new Void(this,0)); //Typ des Statments auf Void setzen. //this.setType(new Void(0)); //Typ des Statments auf Void setzen.
return ret; return ret;
} }

View File

@ -51,7 +51,7 @@ public class BoolLiteral extends Literal
super(-1,-1); super(-1,-1);
// #JB# 20.04.2005 // #JB# 20.04.2005
// ########################################################### // ###########################################################
this.setType(new RefType("Boolean",this,this.getOffset())); this.setType(new RefType("java.lang.Boolean",this.getOffset()));
//this.setType(new Type("boolean")); //this.setType(new Type("boolean"));
// ########################################################### // ###########################################################
} }
@ -99,7 +99,6 @@ public class BoolLiteral extends Literal
@Override @Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
this.type = assumptions.checkType(new RefType("java.lang.Boolean",this,-1), this);
return new ConstraintsSet(); return new ConstraintsSet();
} }
@ -118,15 +117,6 @@ public class BoolLiteral extends Literal
} }
@Override
public void wandleRefTypeAttributes2GenericAttributes(
Menge<Type> paralist,
Menge<GenericTypeVar> genericMethodParameters) {
// TODO Auto-generated method stub
}
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());

View File

@ -26,16 +26,17 @@ import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
// ino.class.CastExpr.25126.declaration // ino.class.CastExpr.25126.declaration
public class CastExpr extends UnaryExpr public class CastExpr extends Expr
// ino.end // ino.end
// ino.class.CastExpr.25126.body // ino.class.CastExpr.25126.body
{ {
// ino.method.CastExpr.25130.definition // ino.method.CastExpr.25130.definition
public CastExpr(int offset,int variableLength) public CastExpr(Type castType, Expr expr,int offset)
// ino.end // ino.end
// ino.method.CastExpr.25130.body // ino.method.CastExpr.25130.body
{ {
super(offset,variableLength); super(offset);
this.type = castType;
} }
// ino.end // ino.end
@ -106,7 +107,7 @@ public class CastExpr extends UnaryExpr
@Override @Override
public JavaCodeResult printJavaCode(ResultSet resultSet) { public JavaCodeResult printJavaCode(ResultSet resultSet) {
return new JavaCodeResult("(("+this.usedid+")").attach(this.expr.printJavaCode(resultSet)).attach(")"); return new JavaCodeResult("(("+this.+")").attach(this.expr.printJavaCode(resultSet)).attach(")");
} }

View File

@ -0,0 +1,36 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Iterator;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
public abstract class Executeable extends SyntaxTreeNode implements Typeable
{
private Type type;
public Executeable(Type type,int offset) {
super(offset);
this.type = type;
}
public Type getType(){
return type;
}
public abstract InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs);
public abstract String getTypeInformation();
}

View File

@ -1,7 +1,6 @@
// ino.module.Expr.8630.package
package de.dhbwstuttgart.syntaxtree.statement; package de.dhbwstuttgart.syntaxtree.statement;
// ino.end
// ino.module.Expr.8630.import
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
@ -10,7 +9,7 @@ import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
@ -18,81 +17,14 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
public abstract class Expr extends Executeable
// ino.class.Expr.25225.declaration
public abstract class Expr extends ExprStmt
// ino.end
// ino.class.Expr.25225.body
{ {
// ino.method.Expr.25229.definition
public Expr(int offset, int variableLength)
// ino.end
// ino.method.Expr.25229.body
{
super(offset, variableLength);
}
// ino.end
// ino.attribute.usedid.25232.declaration public Expr(Type type, int offset) {
public UsedId usedid; //String type; ab sofort in die Klasse ExprStmt verlegt. last1 17.03.02 super(type, offset);
// ino.end }
// ino.method.set_Type.25235.definition
public void set_Type(Type type)
// ino.end
// ino.method.set_Type.25235.body
{
this.setType(type);
}
// ino.end
// ino.method.set_UsedId.25238.definition public abstract String get_Name();
public void set_UsedId(UsedId ui)
// ino.end
// ino.method.set_UsedId.25238.body
{
this.usedid = ui;
}
// ino.end
// ino.method.get_UsedId.25241.definition
public UsedId get_UsedId()
// ino.end
// ino.method.get_UsedId.25241.body
{
return usedid;
}
// ino.end
// ino.method.get_Name_Menge.25244.definition
public Menge get_Name_Menge()
// ino.end
// ino.method.get_Name_Menge.25244.body
{
return usedid.get_Name();
}
// ino.end
// ino.method.get_Type_Menge.25247.definition
public Menge get_Type_Menge()
// ino.end
// ino.method.get_Type_Menge.25247.body
{
return usedid.get_Typen();
}
// ino.end
// ino.method.get_Name.25253.declaration
public abstract String get_Name();
// ino.end
/** /**
* @author AI10023 - Andreas Stadelmeier * @author AI10023 - Andreas Stadelmeier
@ -100,17 +32,4 @@ public abstract class Expr extends ExprStmt
* Jede Expression wird im Zuge des Algorithmus durch die TYPEExpr-Funktion angesprochen. * Jede Expression wird im Zuge des Algorithmus durch die TYPEExpr-Funktion angesprochen.
*/ */
public abstract ConstraintsSet TYPEExpr(TypeAssumptions assumptions); public abstract ConstraintsSet TYPEExpr(TypeAssumptions assumptions);
/**
* @author AI10023 - Andreas Stadelmeier
* Die Funktion überschreiben, damit sie von Expressions nicht mehr spezifiziert werden muss.
* Denn Expressions ¼ssen diese Funktion nicht implementieren.
*/
@Override
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){
throw new NotImplementedException(); //wird die TYPEStmt-Methode innerhalb einer Expr aufgerufen, dann ist etwas schief gelaufen.
}
//public abstract InstructionList genByteCode(ClassGen _cg, TypeAssumptions ass);
} }
// ino.end

71
src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java Executable file → Normal file
View File

@ -1,69 +1,14 @@
// ino.module.ExprStmt.8631.package
package de.dhbwstuttgart.syntaxtree.statement; package de.dhbwstuttgart.syntaxtree.statement;
// ino.end
// ino.module.ExprStmt.8631.import
import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
// ino.class.ExprStmt.25265.declaration public abstract class ExprStmt extends Executeable{
public abstract class ExprStmt extends Statement
// ino.end
// ino.class.ExprStmt.25265.body
{
// ino.method.ExprStmt.25270.definition
public ExprStmt(int offset, int variableLength)
// ino.end
// ino.method.ExprStmt.25270.body
{
super(offset,variableLength);
}
// ino.end
// ino.attribute.type.25273.declaration
//protected Type type; // Type type;
// ino.end
// ino.attribute.inferencelog.25276.declaration
protected static Logger inferencelog = Logger.getLogger("inference");
// ino.end
// ino.method.getTypeName.25279.definition
public String getTypeName()
// ino.end
// ino.method.getTypeName.25279.body
{
if (getType()!=null)
return getType().getName().toString();
else
return null;
}
// ino.end
// ino.method.getTypeLineNumber.25291.defdescription type=javadoc
/**
* <br>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
* @return
*/
// ino.end
// ino.method.getTypeLineNumber.25291.definition
public int getTypeLineNumber()
// ino.end
// ino.method.getTypeLineNumber.25291.body
{
return MyCompiler.NO_LINENUMBER;
}
// ino.end
public ExprStmt(Type type,int offset) {
super(type,offset);
}
public abstract ConstraintsSet TYPEExpr(TypeAssumptions assumptions);
public abstract ConstraintsSet TYPEStmt(TypeAssumptions assumptions);
} }
// ino.end

View File

@ -1,7 +1,6 @@
// ino.module.Statement.8652.package // ino.module.Statement.8652.package
package de.dhbwstuttgart.syntaxtree.statement; package de.dhbwstuttgart.syntaxtree.statement;
// ino.end
// ino.module.Statement.8652.import
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
@ -28,43 +27,15 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
// ino.class.Statement.26184.declaration public abstract class Statement extends Executeable
public abstract class Statement extends SyntaxTreeNode implements IItemWithOffset, Typeable
// ino.end
// ino.class.Statement.26184.body
{ {
// ino.attribute.offset.26188.declaration
protected int offset;
// ino.end
// ino.attribute.variableLength.26191.declaration
private int variableLength;
// ino.end
protected Type type;
public Statement(int offset) public Statement(Type type,int offset)
{ {
this.offset=offset; super(type,offset);
//this.variableLength=variableLength;
} }
// ino.method.getOffset.26197.definition
public int getOffset()
// ino.end
// ino.method.getOffset.26197.body
{
return offset;
}
// ino.end
// ino.method.getVariableLength.26200.definition
public int getVariableLength()
// ino.end
// ino.method.getVariableLength.26200.body
{
return variableLength;
}
/** /**
* @author AI10023 - Andreas Stadelmeier * @author AI10023 - Andreas Stadelmeier
@ -73,12 +44,6 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
*/ */
public abstract ConstraintsSet TYPEStmt(TypeAssumptions assumptions); public abstract ConstraintsSet TYPEStmt(TypeAssumptions assumptions);
public Type getType(){
return type;
}
/** /**
* @author Andreas Stadelmeier, a10023 * @author Andreas Stadelmeier, a10023
* Sollte von jedem Statement überschrieben werden. * Sollte von jedem Statement überschrieben werden.
@ -86,23 +51,9 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
* @return * @return
*/ */
public String getTypeInformation(){ public String getTypeInformation(){
return this.printJavaCode(new ResultSet(new Menge<Pair>()))+" : "+type.toString(); return this.printJavaCode(new ResultSet(new Menge<Pair>()))+" : "+this.getType().toString();
} }
/**
* @author AI10023 - Andreas Stadelmeier
* Jedem Statement und jeder Expression wird im Zuge des Typinferenzalgorithmus eine Typvariable zugewiesen.
* Daher ¼ssen alle Statements und Expressions die Methoden setTypeVariable und getTypeVariable implementieren.
*/
public void setType(Type t)
{
this.type=t;
}
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
@Override @Override
public String getDescription(){ public String getDescription(){
return this.printJavaCode(new ResultSet(new Menge<Pair>())).toString(); return this.printJavaCode(new ResultSet(new Menge<Pair>())).toString();
@ -116,10 +67,5 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
} }
public abstract InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs);
} }
// ino.end