use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class ASTNode method setName.
@SuppressWarnings({ "SuspiciousMethodCalls" })
protected void setName(char[] name) {
if (isNumber(name, start, offset)) {
egressType = (literal = handleNumericConversion(name, start, offset)).getClass();
if (((fields |= NUMERIC | LITERAL | IDENTIFIER) & INVERT) != 0) {
try {
literal = ~((Integer) literal);
} catch (ClassCastException e) {
throw new CompileException("bitwise (~) operator can only be applied to integers", expr, start);
}
}
return;
}
this.literal = new String(name, start, offset);
int end = start + offset;
Scan: for (int i = start; i < end; i++) {
switch(name[i]) {
case '.':
if (firstUnion == 0) {
firstUnion = i;
}
break;
case '[':
case '(':
if (firstUnion == 0) {
firstUnion = i;
}
if (endOfName == 0) {
endOfName = i;
if (i < name.length && name[i + 1] == ']')
fields |= ARRAY_TYPE_LITERAL;
break Scan;
}
}
}
if ((fields & INLINE_COLLECTION) != 0) {
return;
}
if (firstUnion > start) {
fields |= DEEP_PROPERTY | IDENTIFIER;
} else {
fields |= IDENTIFIER;
}
}
use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class ForNode method buildForEach.
private boolean buildForEach(char[] condition, int start, int offset, int blockStart, int blockEnd, int fields, ParserContext pCtx) {
int end = start + offset;
int cursor = nextCondPart(condition, start, end, false);
boolean varsEscape = false;
try {
ParserContext spCtx = pCtx;
if (pCtx != null) {
spCtx = pCtx.createSubcontext().createColoringSubcontext();
} else {
spCtx = new ParserContext();
}
this.initializer = (ExecutableStatement) subCompileExpression(condition, start, cursor - start - 1, spCtx);
if (pCtx != null) {
pCtx.pushVariableScope();
}
try {
expectType(this.condition = (ExecutableStatement) subCompileExpression(condition, start = cursor, (cursor = nextCondPart(condition, start, end, false)) - start - 1, spCtx), Boolean.class, ((fields & COMPILE_IMMEDIATE) != 0));
} catch (CompileException e) {
if (e.getExpr().length == 0) {
e.setExpr(expr);
while (start < expr.length && ParseTools.isWhitespace(expr[start])) {
start++;
}
e.setCursor(start);
}
throw e;
}
this.after = (ExecutableStatement) subCompileExpression(condition, start = cursor, (nextCondPart(condition, start, end, true)) - start, spCtx);
if (spCtx != null && (fields & COMPILE_IMMEDIATE) != 0 && spCtx.isVariablesEscape()) {
if (pCtx != spCtx)
pCtx.addVariables(spCtx.getVariables());
varsEscape = true;
} else if (spCtx != null && pCtx != null) {
pCtx.addVariables(spCtx.getVariables());
}
this.compiledBlock = (ExecutableStatement) subCompileExpression(expr, blockStart, blockEnd, spCtx);
} catch (NegativeArraySizeException e) {
throw new CompileException("wrong syntax; did you mean to use 'foreach'?", expr, start);
}
return varsEscape;
}
use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class ProtoParser method calculateDecl.
private void calculateDecl() {
if (tk2 != null) {
try {
if (pCtx.hasProtoImport(tk1)) {
type = Proto.class;
} else {
type = ParseTools.findClass(null, tk1, pCtx);
}
name = tk2;
} catch (ClassNotFoundException e) {
if (interpreted) {
type = DeferredTypeResolve.class;
deferredName = tk1;
name = tk2;
} else {
throw new CompileException("could not resolve class: " + tk1, expr, cursor, e);
}
}
} else {
type = Object.class;
name = tk1;
}
tk1 = null;
tk2 = null;
}
use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class AbstractParser method arithmeticFunctionReduction.
/**
* Reduce the current operations on the stack.
*
* @param operator the operator
* @return a stack control code
*/
protected int arithmeticFunctionReduction(int operator) {
ASTNode tk;
int operator2;
/**
* If the next token is an operator, we check to see if it has a higher
* precdence.
*/
if ((tk = nextToken()) != null) {
if (isArithmeticOperator(operator2 = tk.getOperator()) && PTABLE[operator2] > PTABLE[operator]) {
stk.xswap();
/**
* The current arith. operator is of higher precedence the last.
*/
tk = nextToken();
/**
* Check to see if we're compiling or executing interpretively. If we're compiling, we really
* need to stop if this is not a literal.
*/
if (compileMode && !tk.isLiteral()) {
splitAccumulator.push(tk, new OperatorNode(operator2, expr, st));
return OP_OVERFLOW;
}
dStack.push(operator = operator2, tk.getReducedValue(ctx, ctx, variableFactory));
while (true) {
// look ahead again
if ((tk = nextToken()) != null && (operator2 = tk.getOperator()) != -1 && operator2 != 37 && PTABLE[operator2] > PTABLE[operator]) {
if (dStack.isReduceable()) {
stk.copyx2(dStack);
}
/**
* This operator is of higher precedence, or the same level precedence. push to the RHS.
*/
dStack.push(operator = operator2, nextToken().getReducedValue(ctx, ctx, variableFactory));
continue;
} else if (tk != null && operator2 != -1 && operator2 != 37) {
if (PTABLE[operator2] == PTABLE[operator]) {
if (!dStack.isEmpty())
dreduce();
else {
while (stk.isReduceable()) {
stk.xswap_op();
}
}
/**
* This operator is of the same level precedence. push to the RHS.
*/
dStack.push(operator = operator2, nextToken().getReducedValue(ctx, ctx, variableFactory));
continue;
} else {
/**
* The operator doesn't have higher precedence. Therfore reduce the LHS.
*/
while (dStack.size() > 1) {
dreduce();
}
operator = tk.getOperator();
// Reduce the lesser or equal precedence operations.
while (stk.size() != 1 && stk.peek2() instanceof Integer && ((operator2 = (Integer) stk.peek2()) < PTABLE.length) && PTABLE[operator2] >= PTABLE[operator]) {
stk.xswap_op();
}
}
} else {
if (dStack.size() > 1) {
dreduce();
}
if (stk.isReduceable())
stk.xswap();
break;
}
if ((tk = nextToken()) != null) {
switch(operator) {
case AND:
{
if (!(stk.peekBoolean()))
return OP_TERMINATE;
else {
splitAccumulator.add(tk);
return AND;
}
}
case OR:
{
if ((stk.peekBoolean()))
return OP_TERMINATE;
else {
splitAccumulator.add(tk);
return OR;
}
}
default:
stk.push(operator, tk.getReducedValue(ctx, ctx, variableFactory));
}
}
}
} else if (!tk.isOperator()) {
throw new CompileException("unexpected token: " + tk.getName(), expr, st);
} else {
reduce();
splitAccumulator.push(tk);
}
}
// keep XSWAPing and reducing, until there is nothing left.
if (stk.isReduceable()) {
while (true) {
reduce();
if (stk.isReduceable()) {
stk.xswap();
} else {
break;
}
}
}
return OP_RESET_FRAME;
}
use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class AbstractParser method reduce.
/**
* This method is called when we reach the point where we must subEval a trinary operation in the expression.
* (ie. val1 op val2). This is not the same as a binary operation, although binary operations would appear
* to have 3 structures as well. A binary structure (or also a junction in the expression) compares the
* current state against 2 downrange structures (usually an op and a val).
*/
protected void reduce() {
Object v1, v2;
int operator;
try {
switch(operator = (Integer) stk.pop()) {
case ADD:
case SUB:
case DIV:
case MULT:
case MOD:
case EQUAL:
case NEQUAL:
case GTHAN:
case LTHAN:
case GETHAN:
case LETHAN:
case POWER:
stk.op(operator);
break;
case AND:
v1 = stk.pop();
stk.push(((Boolean) stk.pop()) && ((Boolean) v1));
break;
case OR:
v1 = stk.pop();
stk.push(((Boolean) stk.pop()) || ((Boolean) v1));
break;
case CHOR:
v1 = stk.pop();
if (!isEmpty(v2 = stk.pop()) || !isEmpty(v1)) {
stk.clear();
stk.push(!isEmpty(v2) ? v2 : v1);
return;
} else
stk.push(null);
break;
case REGEX:
stk.push(java.util.regex.Pattern.compile(java.lang.String.valueOf(stk.pop())).matcher(java.lang.String.valueOf(stk.pop())).matches());
break;
case INSTANCEOF:
stk.push(((Class) stk.pop()).isInstance(stk.pop()));
break;
case CONVERTABLE_TO:
stk.push(org.mvel2.DataConversion.canConvert(stk.peek2().getClass(), (Class) stk.pop2()));
break;
case CONTAINS:
stk.push(containsCheck(stk.peek2(), stk.pop2()));
break;
case BW_AND:
stk.push(asInt(stk.peek2()) & asInt(stk.pop2()));
break;
case BW_OR:
stk.push(asInt(stk.peek2()) | asInt(stk.pop2()));
break;
case BW_XOR:
stk.push(asInt(stk.peek2()) ^ asInt(stk.pop2()));
break;
case BW_SHIFT_LEFT:
stk.push(asInt(stk.peek2()) << asInt(stk.pop2()));
break;
case BW_USHIFT_LEFT:
int iv2 = asInt(stk.peek2());
if (iv2 < 0)
iv2 *= -1;
stk.push(iv2 << asInt(stk.pop2()));
break;
case BW_SHIFT_RIGHT:
stk.push(asInt(stk.peek2()) >> asInt(stk.pop2()));
break;
case BW_USHIFT_RIGHT:
stk.push(asInt(stk.peek2()) >>> asInt(stk.pop2()));
break;
case SOUNDEX:
stk.push(soundex(java.lang.String.valueOf(stk.pop())).equals(soundex(java.lang.String.valueOf(stk.pop()))));
break;
case SIMILARITY:
stk.push(similarity(java.lang.String.valueOf(stk.pop()), java.lang.String.valueOf(stk.pop())));
break;
}
} catch (ClassCastException e) {
throw new CompileException("syntax error or incompatable types", expr, st, e);
} catch (ArithmeticException e) {
throw new CompileException("arithmetic error: " + e.getMessage(), expr, st, e);
} catch (Exception e) {
throw new CompileException("failed to subEval expression", expr, st, e);
}
}
Aggregations