use of verdict.vdm.vdm_lustre.ExpressionList in project VERDICT by ge-high-assurance.
the class VDM2Lustre method visitExpression.
protected Expression visitExpression(Expression expr) {
Expression u_Expr = new Expression();
// Binary Operators
if (expr != null) {
BinaryOperation op = expr.getEqual();
if (op != null) {
u_Expr.setEqual(binaryOP(op));
}
op = expr.getNotEqual();
if (op != null) {
u_Expr.setNotEqual(binaryOP(op));
}
op = expr.getImplies();
if (op != null) {
u_Expr.setImplies(binaryOP(op));
}
op = expr.getAnd();
if (op != null) {
u_Expr.setAnd(binaryOP(op));
}
op = expr.getOr();
if (op != null) {
u_Expr.setOr(binaryOP(op));
}
op = expr.getXor();
if (op != null) {
u_Expr.setXor(binaryOP(op));
}
op = expr.getArrow();
if (op != null) {
u_Expr.setArrow(binaryOP(op));
}
op = expr.getLessThanOrEqualTo();
if (op != null) {
u_Expr.setLessThanOrEqualTo(binaryOP(op));
}
op = expr.getLessThan();
if (op != null) {
u_Expr.setLessThan(binaryOP(op));
}
op = expr.getGreaterThan();
if (op != null) {
u_Expr.setGreaterThan(binaryOP(op));
}
op = expr.getGreaterThanOrEqualTo();
if (op != null) {
u_Expr.setGreaterThanOrEqualTo(binaryOP(op));
}
op = expr.getMinus();
if (op != null) {
u_Expr.setMinus(binaryOP(op));
}
op = expr.getPlus();
if (op != null) {
u_Expr.setPlus(binaryOP(op));
}
op = expr.getDiv();
if (op != null) {
u_Expr.setDiv(binaryOP(op));
}
op = expr.getTimes();
if (op != null) {
u_Expr.setTimes(binaryOP(op));
}
op = expr.getMod();
if (op != null) {
u_Expr.setMod(binaryOP(op));
}
op = expr.getCartesianExpression();
if (op != null) {
u_Expr.setCartesianExpression(binaryOP(op));
}
IfThenElse cond_op = expr.getConditionalExpression();
if (cond_op != null) {
Expression cond_expr = cond_op.getCondition();
cond_expr = visitExpression(cond_expr);
Expression then_expr = cond_op.getThenBranch();
then_expr = visitExpression(then_expr);
Expression else_expr = cond_op.getElseBranch();
else_expr = visitExpression(else_expr);
cond_op.setCondition(cond_expr);
cond_op.setThenBranch(then_expr);
cond_op.setElseBranch(else_expr);
u_Expr.setConditionalExpression(cond_op);
}
// Record Literal
RecordLiteral recordLiteral = expr.getRecordLiteral();
if (recordLiteral != null) {
Expression fieldExpr;
for (FieldDefinition fieldDef : recordLiteral.getFieldDefinition()) {
fieldExpr = fieldDef.getFieldValue();
visitExpression(fieldExpr);
}
u_Expr.setRecordLiteral(recordLiteral);
}
// Record Project
RecordProjection recordProj = expr.getRecordProjection();
if (recordProj != null) {
Expression recordRef = recordProj.getRecordReference();
recordRef = visitExpression(recordRef);
recordProj.setRecordReference(recordRef);
u_Expr.setRecordProjection(recordProj);
}
// Unary Operators
Expression notExpr = expr.getNot();
if (notExpr != null) {
notExpr = visitExpression(notExpr);
u_Expr.setNot(notExpr);
}
Expression negExpr = expr.getNegative();
if (negExpr != null) {
negExpr = visitExpression(negExpr);
u_Expr.setNegative(negExpr);
;
}
Expression preExpr = expr.getPre();
if (preExpr != null) {
preExpr = visitExpression(preExpr);
u_Expr.setPre(preExpr);
}
Expression toIntExpr = expr.getToInt();
if (toIntExpr != null) {
toIntExpr = visitExpression(toIntExpr);
u_Expr.setToInt(toIntExpr);
}
Expression toRealExpr = expr.getToReal();
if (toRealExpr != null) {
toRealExpr = visitExpression(toRealExpr);
u_Expr.setToReal(toRealExpr);
}
Boolean b = expr.isBoolLiteral();
if (b != null) {
u_Expr.setBoolLiteral(b);
}
BigInteger int_value = expr.getIntLiteral();
if (int_value != null) {
u_Expr.setIntLiteral(int_value);
}
BigDecimal real_value = expr.getRealLiteral();
if (real_value != null) {
u_Expr.setRealLiteral(real_value);
}
// Identifier
String identifier = expr.getIdentifier();
if (identifier != null) {
if (eventDeclarations.containsKey(identifier)) {
u_Expr = eventExpression(expr, false);
} else {
u_Expr.setIdentifier(identifier);
}
}
// NodeCall
NodeCall nodeCall = expr.getCall();
if (nodeCall != null) {
u_Expr.setCall(nodeCall);
List<Expression> arguments = new Vector<Expression>();
for (Expression argExpr : nodeCall.getArgument()) {
argExpr = visitExpression(argExpr);
arguments.add(argExpr);
}
nodeCall.getArgument().clear();
nodeCall.getArgument().addAll(arguments);
u_Expr.setCall(nodeCall);
}
// Event Expression
Expression event = expr.getEvent();
if (event != null) {
u_Expr = eventExpression(event, true);
// System.out.println(expr + "^^^ Updated to Event ^^^ " + event);
}
ExpressionList expList = expr.getExpressionList();
if (expList != null) {
ExpressionList uList = new ExpressionList();
for (Expression aexpr : expList.getExpression()) {
expr = visitExpression(aexpr);
uList.getExpression().add(expr);
}
expList.getExpression().clear();
u_Expr.setExpressionList(uList);
}
// ExpressionList arrayExpList = expr.getArrayExpression();
//
// if(expList != null) {
// List<Expression> uList = new ArrayList<Expression>();
// for(Expression aexpr: arrayExpList.getExpression()) {
// expr = visitExpression(aexpr);
// uList.add(expr);
// }
// arrayExpList.getExpression().clear();
// arrayExpList.getExpression().addAll(uList);
// u_Expr.setArrayExpression(arrayExpList);
// }
}
return u_Expr;
}
use of verdict.vdm.vdm_lustre.ExpressionList in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitNaryExpr.
/**
* Extract a nary expression.
*/
@Override
public void exitNaryExpr(LustreParser.NaryExprContext ctx) {
ExpressionList expressionList = new ExpressionList();
ctx.expr().forEach(e -> expressionList.getExpression().add(e.expression));
ctx.expression = new Expression();
switch(ctx.op.getText()) {
case "#":
ctx.expression.setDiese(expressionList);
break;
case "nor":
ctx.expression.setNor(expressionList);
break;
}
}
use of verdict.vdm.vdm_lustre.ExpressionList in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitTupleExpr.
/**
* Extract a tuple expression.
*/
@Override
public void exitTupleExpr(LustreParser.TupleExprContext ctx) {
ExpressionList expressionList = new ExpressionList();
ctx.expr().forEach(e -> expressionList.getExpression().add(e.expression));
ctx.expression = new Expression();
ctx.expression.setTupleExpression(expressionList);
}
use of verdict.vdm.vdm_lustre.ExpressionList in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitListExpr.
/**
* Extract a list expression.
*/
@Override
public void exitListExpr(LustreParser.ListExprContext ctx) {
ExpressionList expressionList = new ExpressionList();
ctx.expr().forEach(e -> expressionList.getExpression().add(e.expression));
ctx.expression = new Expression();
ctx.expression.setExpressionList(expressionList);
}
use of verdict.vdm.vdm_lustre.ExpressionList in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitArrayExpr.
/**
* Extract an array expression.
*/
@Override
public void exitArrayExpr(LustreParser.ArrayExprContext ctx) {
ExpressionList expressionList = new ExpressionList();
ctx.expr().forEach(e -> expressionList.getExpression().add(e.expression));
ctx.expression = new Expression();
ctx.expression.setArrayExpression(expressionList);
}
Aggregations