use of jetbrick.template.parser.grammer.JetTemplateParser.ConstantContext 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.ConstantContext 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);
}
Aggregations