Skip to content

Commit

Permalink
ternary operator block bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cvejoski committed Sep 22, 2015
1 parent 74c37ff commit 8d31128
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -215,6 +216,12 @@ public Void visitExprList(ExprList<Void> exprList) {
return null;
}

@Override
public Void visitStmtExpr(StmtExpr<Void> stmtExpr) {
stmtExpr.getStmt().visit(this);
return null;
}

@Override
public Void visitActionStmt(ActionStmt<Void> actionStmt) {
actionStmt.getAction().visit(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -463,6 +464,12 @@ public Void visitExprStmt(ExprStmt<Void> exprStmt) {
return null;
}

@Override
public Void visitStmtExpr(StmtExpr<Void> stmtExpr) {
stmtExpr.getStmt().visit(this);
return null;
}

@Override
public Void visitIfStmt(IfStmt<Void> ifStmt) {
if ( ifStmt.isTernary() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -434,6 +435,12 @@ public Void visitExprStmt(ExprStmt<Void> exprStmt) {
return null;
}

@Override
public Void visitStmtExpr(StmtExpr<Void> stmtExpr) {
stmtExpr.getStmt().visit(this);
return null;
}

@Override
public Void visitIfStmt(IfStmt<Void> ifStmt) {
if ( ifStmt.isTernary() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -949,4 +950,10 @@ public Void visitBluetoothWaitForConnectionAction(BluetoothWaitForConnectionActi
// TODO Auto-generated method stub
return null;
}

@Override
public Void visitStmtExpr(StmtExpr<Void> stmtExpr) {
// TODO Auto-generated method stub
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -295,4 +296,10 @@ public Void visitBluetoothWaitForConnectionAction(BluetoothWaitForConnectionActi
// TODO Auto-generated method stub
return null;
}

@Override
public Void visitStmtExpr(StmtExpr<Void> stmtExpr) {
// TODO Auto-generated method stub
return null;
}
}
Original file line number Diff line number Diff line change
@@ -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<V> extends Expr<V> {
private final Stmt<V> stmt;

private StmtExpr(Stmt<V> 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 <V> StmtExpr<V> make(Stmt<V> stmt) {
return new StmtExpr<V>(stmt);
}

/**
* @return stmt that is wrapped in the expression
*/
public Stmt<V> 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<V> visitor) {
return visitor.visitStmtExpr(this);
}

@Override
public Block astToBlock() {
Phrase<V> p = getStmt();
return p.astToBlock();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,6 +150,12 @@ public Void visitSensorExpr(SensorExpr<Void> sensorExpr) {
return null;
}

@Override
public Void visitStmtExpr(StmtExpr<Void> stmtExpr) {
stmtExpr.getStmt().visit(this);
return null;
}

@Override
public Void visitEmptyList(EmptyList<Void> emptyList) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -255,6 +257,8 @@ public Expr<V> convertPhraseToExpr(Phrase<V> p) {
expr = FunctionExpr.make((Function<V>) p);
} else if ( p.getKind().getCategory() == Category.METHOD ) {
expr = MethodExpr.make((Method<V>) p);
} else if ( p.getKind() == BlockType.IF_STMT && ((IfStmt<V>) p).isTernary() ) {
expr = StmtExpr.make((Stmt<V>) p);
} else {
expr = (Expr<V>) p;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -603,4 +604,10 @@ public T visitBluetoothWaitForConnectionAction(BluetoothWaitForConnectionAction<
// TODO Auto-generated method stub
return null;
}

@Override
public T visitStmtExpr(StmtExpr<T> stmtExpr) {
// TODO Auto-generated method stub
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -654,4 +655,10 @@ public BlocklyType visitBluetoothWaitForConnectionAction(BluetoothWaitForConnect
// TODO Auto-generated method stub
return null;
}

@Override
public BlocklyType visitStmtExpr(StmtExpr<BlocklyType> stmtExpr) {
// TODO Auto-generated method stub
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -655,4 +656,6 @@ public interface AstVisitor<V> {
* @param bluetoothWaitForConnection to be visited
*/
public V visitBluetoothWaitForConnectionAction(BluetoothWaitForConnectionAction<V> bluetoothWaitForConnection);

public V visitStmtExpr(StmtExpr<V> stmtExpr);
}

0 comments on commit 8d31128

Please sign in to comment.