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;
}
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);
}
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;
}
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);
}
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);
}
Aggregations