private static JiffleType ensureScalar(Expression e) throws NodeException { JiffleType type = e.getType(); if (type == JiffleType.D) { return type; } throw new NodeException(Errors.EXPECTED_SCALAR); }
@Override public void exitConCall(ConCallContext ctx) { List<ExpressionContext> es = ctx.argumentList().expressionList().expression(); Expression[] args = new Expression[es.size()]; for (int i = 0; i < args.length; i++) { args[i] = getAsType(es.get(i), Expression.class); } try { set(ctx, new ConFunction(args)); } catch (NodeException ex) { messages.error(ctx.getStart(), ex.getError()); } }
@Override public void exitConCall(ConCallContext ctx) { List<ExpressionContext> es = ctx.argumentList().expressionList().expression(); Expression[] args = new Expression[es.size()]; for (int i = 0; i < args.length; i++) { args[i] = getAsType(es.get(i), Expression.class); } try { set(ctx, new ConFunction(args)); } catch (NodeException ex) { messages.error(ctx.getStart(), ex.getError()); } }
@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; }
private static JiffleType ensureScalar(Expression e) throws NodeException { JiffleType type = e.getType(); if (type == JiffleType.D) { return type; } throw new NodeException(Errors.EXPECTED_SCALAR); }
@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; }
public ConFunction(Expression ...args) throws NodeException { super( args[0].getType() ); // first arg (condition) must be scalar if (args[0].getType() != JiffleType.D) { throw new NodeException(Errors.CON_CONDITION_MUST_BE_SCALAR); } if (args.length > 2) { for (int i = 2; i < args.length; i++) { if (args[1].getType() != args[i].getType()) { throw new NodeException(Errors.CON_RESULTS_MUST_BE_SAME_TYPE); } } } this.args = args; }
@Override public void exitTernaryExpr(TernaryExprContext ctx) { Expression[] args = { getAsType(ctx.expression(0), Expression.class), getAsType(ctx.expression(1), Expression.class), getAsType(ctx.expression(2), Expression.class) }; try { set(ctx, new ConFunction(args)); } catch (NodeException ex) { messages.error(ctx.getStart(), ex.getError()); } }
public ConFunction(Expression ...args) throws NodeException { super( args[0].getType() ); // first arg (condition) must be scalar if (args[0].getType() != JiffleType.D) { throw new NodeException(Errors.CON_CONDITION_MUST_BE_SCALAR); } if (args.length > 2) { for (int i = 2; i < args.length; i++) { if (args[1].getType() != args[i].getType()) { throw new NodeException(Errors.CON_RESULTS_MUST_BE_SAME_TYPE); } } } this.args = args; }
@Override public void exitTernaryExpr(TernaryExprContext ctx) { Expression[] args = { getAsType(ctx.expression(0), Expression.class), getAsType(ctx.expression(1), Expression.class), getAsType(ctx.expression(2), Expression.class) }; try { set(ctx, new ConFunction(args)); } catch (NodeException ex) { messages.error(ctx.getStart(), ex.getError()); } }
public static FunctionCall of(String jiffleName, Expression ...args) throws NodeException { JiffleType[] argTypes = (args == null) ? new JiffleType[0] : new JiffleType[args.length]; for (int i = 0; i < argTypes.length; i++) { argTypes[i] = args[i].getType(); } try { FunctionInfo info = FunctionLookup.getInfo(jiffleName, argTypes); return new FunctionCall(info, args); } catch (UndefinedFunctionException ex) { throw new NodeException(Errors.UNKNOWN_FUNCTION); } }
throw new InternalCompilerException(ex.getError().toString());
public static FunctionCall of(String jiffleName, Expression ...args) throws NodeException { JiffleType[] argTypes = (args == null) ? new JiffleType[0] : new JiffleType[args.length]; for (int i = 0; i < argTypes.length; i++) { argTypes[i] = args[i].getType(); } try { FunctionInfo info = FunctionLookup.getInfo(jiffleName, argTypes); return new FunctionCall(info, args); } catch (UndefinedFunctionException ex) { throw new NodeException(Errors.UNKNOWN_FUNCTION); } }
throw new InternalCompilerException(ex.getError().toString());
public BinaryExpression(int opCode, Expression left, Expression right, boolean declarationNeeded) throws NodeException { super(getReturnType(left, right)); this.op = Operator.get(opCode); if (op == Operator.UNKNOWN) { throw new NodeException(Errors.INVALID_BINARY_EXPRESSION); } this.left = left.forceDouble(); this.right = right.forceDouble(); this.declarationNeeded = declarationNeeded; }
messages.error(ctx.getStart(), ex.getError());
public BinaryExpression(int opCode, Expression left, Expression right, boolean declarationNeeded) throws NodeException { super(getReturnType(left, right)); this.op = Operator.get(opCode); if (op == Operator.UNKNOWN) { throw new NodeException(Errors.INVALID_BINARY_EXPRESSION); } this.left = left.forceDouble(); this.right = right.forceDouble(); this.declarationNeeded = declarationNeeded; }
messages.error(ctx.getStart(), ex.getError());