diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3JavaScriptVisitor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3JavaScriptVisitor.java index 2eb853b64..5f1f84172 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3JavaScriptVisitor.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3JavaScriptVisitor.java @@ -41,6 +41,7 @@ import de.fhg.iais.roberta.syntax.expr.NullConst; import de.fhg.iais.roberta.syntax.expr.NumConst; import de.fhg.iais.roberta.syntax.expr.SensorExpr; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.StringConst; import de.fhg.iais.roberta.syntax.expr.Unary; import de.fhg.iais.roberta.syntax.expr.Var; @@ -215,6 +216,12 @@ public Void visitExprList(ExprList exprList) { return null; } + @Override + public Void visitStmtExpr(StmtExpr stmtExpr) { + stmtExpr.getStmt().visit(this); + return null; + } + @Override public Void visitActionStmt(ActionStmt actionStmt) { actionStmt.getAction().visit(this); diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3JavaVisitor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3JavaVisitor.java index dc5287add..932c8a402 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3JavaVisitor.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3JavaVisitor.java @@ -62,6 +62,7 @@ import de.fhg.iais.roberta.syntax.expr.NullConst; import de.fhg.iais.roberta.syntax.expr.NumConst; import de.fhg.iais.roberta.syntax.expr.SensorExpr; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.StringConst; import de.fhg.iais.roberta.syntax.expr.Unary; import de.fhg.iais.roberta.syntax.expr.Var; @@ -463,6 +464,12 @@ public Void visitExprStmt(ExprStmt exprStmt) { return null; } + @Override + public Void visitStmtExpr(StmtExpr stmtExpr) { + stmtExpr.getStmt().visit(this); + return null; + } + @Override public Void visitIfStmt(IfStmt ifStmt) { if ( ifStmt.isTernary() ) { diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3PythonVisitor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3PythonVisitor.java index e61f59653..f6e9fce05 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3PythonVisitor.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/Ast2Ev3PythonVisitor.java @@ -61,6 +61,7 @@ import de.fhg.iais.roberta.syntax.expr.NullConst; import de.fhg.iais.roberta.syntax.expr.NumConst; import de.fhg.iais.roberta.syntax.expr.SensorExpr; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.StringConst; import de.fhg.iais.roberta.syntax.expr.Unary; import de.fhg.iais.roberta.syntax.expr.Var; @@ -434,6 +435,12 @@ public Void visitExprStmt(ExprStmt exprStmt) { return null; } + @Override + public Void visitStmtExpr(StmtExpr stmtExpr) { + stmtExpr.getStmt().visit(this); + return null; + } + @Override public Void visitIfStmt(IfStmt ifStmt) { if ( ifStmt.isTernary() ) { diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/AstToTextlyVisitor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/AstToTextlyVisitor.java index 326837b85..8e77195c9 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/AstToTextlyVisitor.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/AstToTextlyVisitor.java @@ -47,6 +47,7 @@ import de.fhg.iais.roberta.syntax.expr.NullConst; import de.fhg.iais.roberta.syntax.expr.NumConst; import de.fhg.iais.roberta.syntax.expr.SensorExpr; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.StringConst; import de.fhg.iais.roberta.syntax.expr.Unary; import de.fhg.iais.roberta.syntax.expr.Var; @@ -949,4 +950,10 @@ public Void visitBluetoothWaitForConnectionAction(BluetoothWaitForConnectionActi // TODO Auto-generated method stub return null; } + + @Override + public Void visitStmtExpr(StmtExpr stmtExpr) { + // TODO Auto-generated method stub + return null; + } } \ No newline at end of file diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/AstToVarsVisitor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/AstToVarsVisitor.java index 4f0917b8a..0a8e3dd61 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/AstToVarsVisitor.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/codegen/ev3/AstToVarsVisitor.java @@ -15,6 +15,7 @@ import de.fhg.iais.roberta.syntax.expr.ListCreate; import de.fhg.iais.roberta.syntax.expr.MethodExpr; import de.fhg.iais.roberta.syntax.expr.NumConst; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.Var; import de.fhg.iais.roberta.syntax.expr.VarDeclaration; import de.fhg.iais.roberta.syntax.functions.GetSubFunct; @@ -295,4 +296,10 @@ public Void visitBluetoothWaitForConnectionAction(BluetoothWaitForConnectionActi // TODO Auto-generated method stub return null; } + + @Override + public Void visitStmtExpr(StmtExpr stmtExpr) { + // TODO Auto-generated method stub + return null; + } } diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/expr/StmtExpr.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/expr/StmtExpr.java new file mode 100644 index 000000000..eddce0274 --- /dev/null +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/expr/StmtExpr.java @@ -0,0 +1,66 @@ +package de.fhg.iais.roberta.syntax.expr; + +import de.fhg.iais.roberta.blockly.generated.Block; +import de.fhg.iais.roberta.syntax.BlockType; +import de.fhg.iais.roberta.syntax.Phrase; +import de.fhg.iais.roberta.syntax.sensor.Sensor; +import de.fhg.iais.roberta.syntax.stmt.Stmt; +import de.fhg.iais.roberta.util.dbc.Assert; +import de.fhg.iais.roberta.visitor.AstVisitor; + +/** + * Wraps subclasses of the class {@link Sensor} so they can be used as {@link Expr} in expressions. + */ +public class StmtExpr extends Expr { + private final Stmt stmt; + + private StmtExpr(Stmt stmt) { + super(BlockType.SENSOR_EXPR, stmt.getProperty(), stmt.getComment()); + Assert.isTrue(stmt.isReadOnly()); + this.stmt = stmt; + setReadOnly(); + } + + /** + * Create object of the class {@link StmtExpr}. + * + * @param stmt that we want to wrap, + * @return expression with wrapped sensor inside + */ + public static StmtExpr make(Stmt stmt) { + return new StmtExpr(stmt); + } + + /** + * @return stmt that is wrapped in the expression + */ + public Stmt getStmt() { + return this.stmt; + } + + @Override + public int getPrecedence() { + return 999; + } + + @Override + public Assoc getAssoc() { + return Assoc.NONE; + } + + @Override + public String toString() { + return "SensorExpr [" + this.stmt + "]"; + } + + @Override + protected V accept(AstVisitor visitor) { + return visitor.visitStmtExpr(this); + } + + @Override + public Block astToBlock() { + Phrase p = getStmt(); + return p.astToBlock(); + } +} diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/hardwarecheck/CheckVisitor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/hardwarecheck/CheckVisitor.java index ccf377be8..b8369f070 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/hardwarecheck/CheckVisitor.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/syntax/hardwarecheck/CheckVisitor.java @@ -32,6 +32,7 @@ import de.fhg.iais.roberta.syntax.expr.NullConst; import de.fhg.iais.roberta.syntax.expr.NumConst; import de.fhg.iais.roberta.syntax.expr.SensorExpr; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.StringConst; import de.fhg.iais.roberta.syntax.expr.Unary; import de.fhg.iais.roberta.syntax.expr.Var; @@ -149,6 +150,12 @@ public Void visitSensorExpr(SensorExpr sensorExpr) { return null; } + @Override + public Void visitStmtExpr(StmtExpr stmtExpr) { + stmtExpr.getStmt().visit(this); + return null; + } + @Override public Void visitEmptyList(EmptyList emptyList) { return null; diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/transformer/Jaxb2AstTransformer.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/transformer/Jaxb2AstTransformer.java index cb042dbf3..f355887e1 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/transformer/Jaxb2AstTransformer.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/transformer/Jaxb2AstTransformer.java @@ -11,6 +11,7 @@ import de.fhg.iais.roberta.blockly.generated.Statement; import de.fhg.iais.roberta.blockly.generated.Value; import de.fhg.iais.roberta.components.Category; +import de.fhg.iais.roberta.syntax.BlockType; import de.fhg.iais.roberta.syntax.BlocklyBlockProperties; import de.fhg.iais.roberta.syntax.BlocklyComment; import de.fhg.iais.roberta.syntax.BlocklyConstants; @@ -24,6 +25,7 @@ import de.fhg.iais.roberta.syntax.expr.FunctionExpr; import de.fhg.iais.roberta.syntax.expr.MethodExpr; import de.fhg.iais.roberta.syntax.expr.SensorExpr; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.Unary; import de.fhg.iais.roberta.syntax.expr.Var; import de.fhg.iais.roberta.syntax.functions.Function; @@ -255,6 +257,8 @@ public Expr convertPhraseToExpr(Phrase p) { expr = FunctionExpr.make((Function) p); } else if ( p.getKind().getCategory() == Category.METHOD ) { expr = MethodExpr.make((Method) p); + } else if ( p.getKind() == BlockType.IF_STMT && ((IfStmt) p).isTernary() ) { + expr = StmtExpr.make((Stmt) p); } else { expr = (Expr) p; } diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/InfoCollector.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/InfoCollector.java index 12382220c..4b1bbb9d6 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/InfoCollector.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/InfoCollector.java @@ -41,6 +41,7 @@ import de.fhg.iais.roberta.syntax.expr.NullConst; import de.fhg.iais.roberta.syntax.expr.NumConst; import de.fhg.iais.roberta.syntax.expr.SensorExpr; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.StringConst; import de.fhg.iais.roberta.syntax.expr.Unary; import de.fhg.iais.roberta.syntax.expr.Var; @@ -603,4 +604,10 @@ public T visitBluetoothWaitForConnectionAction(BluetoothWaitForConnectionAction< // TODO Auto-generated method stub return null; } + + @Override + public T visitStmtExpr(StmtExpr stmtExpr) { + // TODO Auto-generated method stub + return null; + } } diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/TypecheckVisitor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/TypecheckVisitor.java index 978d85e3b..eb93591a4 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/TypecheckVisitor.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/TypecheckVisitor.java @@ -45,6 +45,7 @@ import de.fhg.iais.roberta.syntax.expr.NullConst; import de.fhg.iais.roberta.syntax.expr.NumConst; import de.fhg.iais.roberta.syntax.expr.SensorExpr; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.StringConst; import de.fhg.iais.roberta.syntax.expr.Unary; import de.fhg.iais.roberta.syntax.expr.Var; @@ -654,4 +655,10 @@ public BlocklyType visitBluetoothWaitForConnectionAction(BluetoothWaitForConnect // TODO Auto-generated method stub return null; } + + @Override + public BlocklyType visitStmtExpr(StmtExpr stmtExpr) { + // TODO Auto-generated method stub + return null; + } } diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/visitor/AstVisitor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/visitor/AstVisitor.java index 82296f5d7..4c8e22ae0 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/visitor/AstVisitor.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/visitor/AstVisitor.java @@ -37,6 +37,7 @@ import de.fhg.iais.roberta.syntax.expr.NullConst; import de.fhg.iais.roberta.syntax.expr.NumConst; import de.fhg.iais.roberta.syntax.expr.SensorExpr; +import de.fhg.iais.roberta.syntax.expr.StmtExpr; import de.fhg.iais.roberta.syntax.expr.StringConst; import de.fhg.iais.roberta.syntax.expr.Unary; import de.fhg.iais.roberta.syntax.expr.Var; @@ -655,4 +656,6 @@ public interface AstVisitor { * @param bluetoothWaitForConnection to be visited */ public V visitBluetoothWaitForConnectionAction(BluetoothWaitForConnectionAction bluetoothWaitForConnection); + + public V visitStmtExpr(StmtExpr stmtExpr); }