@Override public void exitListAppendStmt(JiffleParser.ListAppendStmtContext ctx) { String varName = ctx.ID().getText(); Expression expression = getAsType(ctx.expression(), Expression.class); set(ctx, new ListAppend(new Variable(varName, JiffleType.LIST), expression)); }
@Override public void exitListAppendStmt(JiffleParser.ListAppendStmtContext ctx) { String varName = ctx.ID().getText(); Expression expression = getAsType(ctx.expression(), Expression.class); set(ctx, new ListAppend(new Variable(varName, JiffleType.LIST), expression)); }
private BinaryExpression offsetVariable(String pos, String offsetVar) throws NodeException { return new BinaryExpression( PLUS, FunctionCall.of(pos), new Variable(offsetVar, JiffleType.D)); }
@Test public void lifeToroid() throws Exception { Set<GetSourceValue> sourcePositions = getSourcePositions("life-toroid.jfl", "world"); GetSourceValue absolute = new GetSourceValue( "world", new ImagePos( Band.DEFAULT, new Pixel( new Variable("xx", JiffleType.D), new Variable("yy", JiffleType.D)))); GetSourceValue original = new GetSourceValue("world", ImagePos.DEFAULT); assertThat(sourcePositions, hasItems(absolute, original)); }
@Override public void exitInitBlock(InitBlockContext ctx) { List<BinaryExpression> inits = new ArrayList<>(); List<VarDeclarationContext> decls = ctx.varDeclaration(); if (decls != null) { try { for (VarDeclarationContext dc : decls) { String name = dc.ID().getText(); ExpressionContext exprCtx = dc.expression(); final Expression value; if (exprCtx == null) { value = new DefaultScalarValue(); } else { value = getAsType(exprCtx, Expression.class); } inits.add(new BinaryExpression(ASSIGN, new Variable(name, JiffleType.D), value)); } } catch (NodeException ex) { messages.error(ctx.getStart(), ex.getError()); } } set(ctx, new GlobalVars(inits)); initBlockContext = ctx; }
@Override public void exitInitBlock(InitBlockContext ctx) { List<BinaryExpression> inits = new ArrayList<>(); List<VarDeclarationContext> decls = ctx.varDeclaration(); if (decls != null) { try { for (VarDeclarationContext dc : decls) { String name = dc.ID().getText(); ExpressionContext exprCtx = dc.expression(); final Expression value; if (exprCtx == null) { value = new DefaultScalarValue(); } else { value = getAsType(exprCtx, Expression.class); } inits.add(new BinaryExpression(ASSIGN, new Variable(name, JiffleType.D), value)); } } catch (NodeException ex) { messages.error(ctx.getStart(), ex.getError()); } } set(ctx, new GlobalVars(inits)); initBlockContext = ctx; }
@Override public void exitForeachStmt(JiffleParser.ForeachStmtContext ctx) { String varName = ctx.ID().getText(); JiffleParser.RangeContext range = ctx.loopSet().range(); Variable loopVariable = new Variable(varName, JiffleType.D); Statement statement = getAsType(ctx.statement(), Statement.class); if (ctx.loopSet().ID() != null) { Variable listVariable = new Variable(ctx.loopSet().ID().getText(), JiffleType.LIST); set(ctx, new LoopInVariable(loopVariable, listVariable, statement)); } else if (range != null) { Expression low = getAsType(range.expression(0), Expression.class); Expression high = getAsType(range.expression(1), Expression.class); set(ctx, new LoopInRange(loopVariable, low, high, statement)); } else { ListLiteral listLiteral = getAsType(ctx.loopSet().listLiteral(), ListLiteral.class); set(ctx, new LoopInLiteralList(loopVariable, listLiteral, statement)); } }
@Override public void exitForeachStmt(JiffleParser.ForeachStmtContext ctx) { String varName = ctx.ID().getText(); JiffleParser.RangeContext range = ctx.loopSet().range(); Variable loopVariable = new Variable(varName, JiffleType.D); Statement statement = getAsType(ctx.statement(), Statement.class); if (ctx.loopSet().ID() != null) { Variable listVariable = new Variable(ctx.loopSet().ID().getText(), JiffleType.LIST); set(ctx, new LoopInVariable(loopVariable, listVariable, statement)); } else if (range != null) { Expression low = getAsType(range.expression(0), Expression.class); Expression high = getAsType(range.expression(1), Expression.class); set(ctx, new LoopInRange(loopVariable, low, high, statement)); } else { ListLiteral listLiteral = getAsType(ctx.loopSet().listLiteral(), ListLiteral.class); set(ctx, new LoopInLiteralList(loopVariable, listLiteral, statement)); } }