Search in sources :

Example 6 with ExpressionContext

use of jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext in project jetbrick-template-1x by subchen.

the class JetTemplateCodeVisitor method visitHash_map_entry_list.

@Override
public Code visitHash_map_entry_list(Hash_map_entry_listContext ctx) {
    List<ExpressionContext> expression_list = ctx.expression();
    SegmentListCode code = new SegmentListCode(expression_list.size());
    for (ExpressionContext expression : expression_list) {
        code.addChild((SegmentCode) expression.accept(this));
    }
    return code;
}
Also used : ExpressionContext(jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext) SegmentListCode(jetbrick.template.parser.code.SegmentListCode)

Example 7 with ExpressionContext

use of jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext in project jetbrick-template-1x by subchen.

the class JetTemplateCodeVisitor method visitExpr_math_unary_suffix.

@Override
public Code visitExpr_math_unary_suffix(Expr_math_unary_suffixContext ctx) {
    ExpressionContext expression = ctx.expression();
    SegmentCode code = (SegmentCode) expression.accept(this);
    String op = ctx.getChild(1).getText();
    assert_not_null_constantContext(expression);
    // ++, --
    if (expression.getChildCount() == 1 && expression.getChild(0) instanceof ConstantContext) {
        throw reportError("Invalid argument to operation " + op + ", required: variable, found Value", expression);
    }
    // 类型检查
    Class<?> resultKlass = PromotionUtils.get_unary_inc_dec(code.getKlass(), op);
    if (resultKlass == null) {
        throw reportError("The UnaryOperator \"" + op + "\" is not applicable for the operand " + code.getKlassName(), ctx.getChild(1));
    }
    String source = "(" + code.toString() + op + ")";
    return new SegmentCode(code.getTypedKlass(), source, ctx);
}
Also used : ExpressionContext(jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext) SegmentCode(jetbrick.template.parser.code.SegmentCode) ConstantContext(jetbrick.template.parser.grammer.JetTemplateParser.ConstantContext)

Example 8 with ExpressionContext

use of jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext in project jetbrick-template-1x by subchen.

the class JetTemplateCodeVisitor method visitExpression_list.

@Override
public Code visitExpression_list(Expression_listContext ctx) {
    List<ExpressionContext> expression_list = ctx.expression();
    SegmentListCode code = new SegmentListCode(expression_list.size());
    for (ExpressionContext expression : expression_list) {
        SegmentCode c = (SegmentCode) expression.accept(this);
        assert_not_void_expression(c);
        code.addChild(c);
    }
    return code;
}
Also used : ExpressionContext(jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext) SegmentCode(jetbrick.template.parser.code.SegmentCode) SegmentListCode(jetbrick.template.parser.code.SegmentListCode)

Example 9 with ExpressionContext

use of jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext in project jetbrick-template-1x by subchen.

the class JetTemplateCodeVisitor method visitExpr_math_unary_prefix.

@Override
public Code visitExpr_math_unary_prefix(Expr_math_unary_prefixContext ctx) {
    ExpressionContext expression = ctx.expression();
    SegmentCode code = (SegmentCode) expression.accept(this);
    String op = ctx.getChild(0).getText();
    assert_not_null_constantContext(expression);
    // 类型检查
    Class<?> resultKlass;
    if (op.length() == 1) {
        // +, -, ~
        resultKlass = PromotionUtils.get_unary_basic(code.getKlass(), op);
    } else {
        // ++, --
        if (expression.getChildCount() == 1 && expression.getChild(0) instanceof ConstantContext) {
            throw reportError("Invalid argument to operation " + op + ", required: variable, found Value", expression);
        }
        resultKlass = PromotionUtils.get_unary_inc_dec(code.getKlass(), op);
    }
    if (resultKlass == null) {
        throw reportError("The UnaryOperator \"" + op + "\" is not applicable for the operand " + code.getKlassName(), ctx.getChild(0));
    }
    String source = "(" + op + code.toString() + ")";
    return new SegmentCode(code.getTypedKlass(), source, ctx);
}
Also used : ExpressionContext(jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext) SegmentCode(jetbrick.template.parser.code.SegmentCode) ConstantContext(jetbrick.template.parser.grammer.JetTemplateParser.ConstantContext)

Example 10 with ExpressionContext

use of jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext in project jetbrick-template-1x by subchen.

the class JetTemplateCodeVisitor method visitContinue_directive.

@Override
public Code visitContinue_directive(Continue_directiveContext ctx) {
    assert_inside_of_for_directive(ctx, "#continue");
    ExpressionContext expression = ctx.expression();
    String source;
    if (expression != null) {
        SegmentCode c = (SegmentCode) expression.accept(this);
        source = get_if_expression_source(c);
    } else {
        source = "true";
    }
    source = "if (" + source + ") continue; // line: " + ctx.getStart().getLine();
    return scopeCode.createLineCode(source);
}
Also used : ExpressionContext(jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext) SegmentCode(jetbrick.template.parser.code.SegmentCode)

Aggregations

ExpressionContext (jetbrick.template.parser.grammer.JetTemplateParser.ExpressionContext)10 SegmentCode (jetbrick.template.parser.code.SegmentCode)9 SegmentListCode (jetbrick.template.parser.code.SegmentListCode)3 ConstantContext (jetbrick.template.parser.grammer.JetTemplateParser.ConstantContext)2 BlockCode (jetbrick.template.parser.code.BlockCode)1 Expr_constantContext (jetbrick.template.parser.grammer.JetTemplateParser.Expr_constantContext)1 Expression_listContext (jetbrick.template.parser.grammer.JetTemplateParser.Expression_listContext)1 TypedKlass (jetbrick.template.parser.support.TypedKlass)1