From a1227a8b1b48b5a26b9bfe591c79ba09f7811904 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 20 Sep 2016 15:18:13 +0200 Subject: [PATCH] =?UTF-8?q?Expr=20und=20ExprStmt=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/SyntaxTreeNode.java | 2 + .../syntaxtree/statement/ArgumentList.java | 6 +- .../syntaxtree/statement/Assign.java | 48 ++------- .../syntaxtree/statement/BoolLiteral.java | 12 +-- .../syntaxtree/statement/CastExpr.java | 9 +- .../syntaxtree/statement/Executeable.java | 36 +++++++ .../syntaxtree/statement/Expr.java | 97 ++----------------- .../syntaxtree/statement/ExprStmt.java | 71 ++------------ .../syntaxtree/statement/Statement.java | 66 ++----------- 9 files changed, 80 insertions(+), 267 deletions(-) create mode 100755 src/de/dhbwstuttgart/syntaxtree/statement/Executeable.java mode change 100755 => 100644 src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java diff --git a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java index f023e17f..523b3cc1 100644 --- a/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java +++ b/src/de/dhbwstuttgart/syntaxtree/SyntaxTreeNode.java @@ -4,6 +4,7 @@ import java.util.List; import org.apache.bcel.generic.ClassGen; +import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.core.IItemWithOffset; @@ -146,4 +147,5 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{ return offset; } + public abstract JavaCodeResult printJavaCode(ResultSet resultSet); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ArgumentList.java b/src/de/dhbwstuttgart/syntaxtree/statement/ArgumentList.java index f393ad12..a5b92aea 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ArgumentList.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ArgumentList.java @@ -14,7 +14,11 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; public class ArgumentList extends SyntaxTreeNode { - public Menge expr = new Menge(); + public ArgumentList(int offset) { + super(offset); + } + + public Menge expr = new Menge(); public Object get_firstElement() diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java index 44c3d20e..496d09cf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java @@ -1,7 +1,6 @@ -// ino.module.Assign.8622.package + package de.dhbwstuttgart.syntaxtree.statement; -// ino.end -// ino.module.Assign.8622.import + import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; @@ -37,60 +36,31 @@ import de.dhbwstuttgart.typeinference.unify.TypeUnify; -// ino.class.Assign.24926.declaration -public class Assign extends Expr -// ino.end -// ino.class.Assign.24926.body +public class Assign extends ExprStmt { - // 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; - // ino.end - // ino.attribute.expr2.24936.declaration + public Expr expr1; public Expr expr2; - // ino.end - - // ino.attribute.parserlog.24939.decldescription type=javadoc /** * Logger log4j */ - // ino.end - // ino.attribute.parserlog.24939.declaration protected static Logger parserlog = Logger.getLogger("parser"); - // ino.end - // ino.method.set_Expr.24942.definition public void set_Expr(Expr expr1,Expr expr2) - // ino.end - // ino.method.set_Expr.24942.body { this.expr1 = expr1; this.expr2 = expr2; } - // ino.end - - - - - // ino.method.get_Name.24948.definition public String get_Name() - // ino.end - // ino.method.get_Name.24948.body { return null; } - // ino.end /** @@ -102,7 +72,7 @@ public class Assign extends Expr ret.add(expr1.TYPEExpr(assumptions)); ret.add(expr2.TYPEExpr(assumptions)); //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(expr1.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this))); return ret; @@ -117,7 +87,7 @@ public class Assign extends Expr @Override public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){ 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; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java index 600c278a..8f96a203 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java @@ -51,7 +51,7 @@ public class BoolLiteral extends Literal super(-1,-1); // #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")); // ########################################################### } @@ -99,7 +99,6 @@ public class BoolLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.type = assumptions.checkType(new RefType("java.lang.Boolean",this,-1), this); return new ConstraintsSet(); } @@ -118,15 +117,6 @@ public class BoolLiteral extends Literal } - - @Override - public void wandleRefTypeAttributes2GenericAttributes( - Menge paralist, - Menge genericMethodParameters) { - // TODO Auto-generated method stub - - } - @Override public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java index b20676d5..cb7d499d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java @@ -26,16 +26,17 @@ import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; // ino.class.CastExpr.25126.declaration -public class CastExpr extends UnaryExpr +public class CastExpr extends Expr // ino.end // ino.class.CastExpr.25126.body { // ino.method.CastExpr.25130.definition - public CastExpr(int offset,int variableLength) + public CastExpr(Type castType, Expr expr,int offset) // ino.end // ino.method.CastExpr.25130.body { - super(offset,variableLength); + super(offset); + this.type = castType; } // ino.end @@ -106,7 +107,7 @@ public class CastExpr extends UnaryExpr @Override 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(")"); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Executeable.java b/src/de/dhbwstuttgart/syntaxtree/statement/Executeable.java new file mode 100755 index 00000000..bd367c7d --- /dev/null +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Executeable.java @@ -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(); +} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java b/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java index d7e7a0df..510d38f0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java @@ -1,7 +1,6 @@ -// ino.module.Expr.8630.package + package de.dhbwstuttgart.syntaxtree.statement; -// ino.end -// ino.module.Expr.8630.import + import java.util.Hashtable; import java.util.Iterator; @@ -10,7 +9,7 @@ import org.apache.bcel.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; 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.TypePlaceholder; import de.dhbwstuttgart.typeinference.ConstraintsSet; @@ -18,81 +17,14 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; - -// ino.class.Expr.25225.declaration -public abstract class Expr extends ExprStmt -// ino.end -// ino.class.Expr.25225.body +public abstract class Expr extends Executeable { - // 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 UsedId usedid; //String type; ab sofort in die Klasse ExprStmt verlegt. last1 17.03.02 - // 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 + public Expr(Type type, int offset) { + super(type, offset); + } - // ino.method.set_UsedId.25238.definition - 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 - + public abstract String get_Name(); /** * @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. */ public abstract ConstraintsSet TYPEExpr(TypeAssumptions assumptions); - - /** - * @author AI10023 - Andreas Stadelmeier - * Die Funktion überschreiben, damit sie von Expressions nicht mehr spezifiziert werden muss. - * Denn Expressions mü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 diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java old mode 100755 new mode 100644 index 1a657afb..51372c17 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java @@ -1,69 +1,14 @@ -// ino.module.ExprStmt.8631.package 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.TypePlaceholder; -import de.dhbwstuttgart.typeinference.Pair; -import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.ConstraintsSet; +import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; -// ino.class.ExprStmt.25265.declaration -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 - /** - *
Author: J�rg B�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 abstract class ExprStmt extends Executeable{ + public ExprStmt(Type type,int offset) { + super(type,offset); + } + public abstract ConstraintsSet TYPEExpr(TypeAssumptions assumptions); + public abstract ConstraintsSet TYPEStmt(TypeAssumptions assumptions); } -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java index 478bdbf3..f8103e0d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java @@ -1,7 +1,6 @@ // ino.module.Statement.8652.package package de.dhbwstuttgart.syntaxtree.statement; -// ino.end -// ino.module.Statement.8652.import + import java.util.Enumeration; import java.util.Hashtable; @@ -28,43 +27,15 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; -// ino.class.Statement.26184.declaration -public abstract class Statement extends SyntaxTreeNode implements IItemWithOffset, Typeable -// ino.end -// ino.class.Statement.26184.body +public abstract class Statement extends Executeable { - // 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; - //this.variableLength=variableLength; + super(type,offset); } - // 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 @@ -73,12 +44,6 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse */ public abstract ConstraintsSet TYPEStmt(TypeAssumptions assumptions); - - - public Type getType(){ - return type; - } - /** * @author Andreas Stadelmeier, a10023 * Sollte von jedem Statement überschrieben werden. @@ -86,23 +51,9 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse * @return */ public String getTypeInformation(){ - return this.printJavaCode(new ResultSet(new Menge()))+" : "+type.toString(); + return this.printJavaCode(new ResultSet(new Menge()))+" : "+this.getType().toString(); } - - /** - * @author AI10023 - Andreas Stadelmeier - * Jedem Statement und jeder Expression wird im Zuge des Typinferenzalgorithmus eine Typvariable zugewiesen. - * Daher mü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 public String getDescription(){ return this.printJavaCode(new ResultSet(new Menge())).toString(); @@ -116,10 +67,5 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse } - public abstract InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs); -} - - - -// ino.end +} \ No newline at end of file