use of org.mule.mvel2.CompileException in project mvel by mvel.
the class ProtoParser method parse.
public Proto parse() {
Proto proto = new Proto(protoName, pCtx);
Mainloop: while (cursor < endOffset) {
cursor = ParseTools.skipWhitespace(expr, cursor);
int start = cursor;
if (tk2 == null) {
while (cursor < endOffset && isIdentifierPart(expr[cursor])) cursor++;
if (cursor > start) {
tk1 = new String(expr, start, cursor - start);
if ("def".equals(tk1) || "function".equals(tk1)) {
cursor++;
cursor = ParseTools.skipWhitespace(expr, cursor);
start = cursor;
while (cursor < endOffset && isIdentifierPart(expr[cursor])) cursor++;
if (start == cursor) {
throw new CompileException("attempt to declare an anonymous function as a prototype member", expr, start);
}
FunctionParser parser = new FunctionParser(new String(expr, start, cursor - start), cursor, endOffset, expr, 0, pCtx, null);
proto.declareReceiver(parser.getName(), parser.parse());
cursor = parser.getCursor() + 1;
tk1 = null;
continue;
}
}
cursor = ParseTools.skipWhitespace(expr, cursor);
}
if (cursor > endOffset) {
throw new CompileException("unexpected end of statement in proto declaration: " + protoName, expr, start);
}
switch(expr[cursor]) {
case ';':
cursor++;
calculateDecl();
if (interpreted && type == DeferredTypeResolve.class) {
/**
* If this type could not be immediately resolved, it may be a look-ahead case, so
* we defer resolution of the type until later and place it in the wait queue.
*/
enqueueReceiverForLateResolution(deferredName, proto.declareReceiver(name, Proto.ReceiverType.DEFERRED, null), null);
} else {
proto.declareReceiver(name, type, null);
}
break;
case '=':
cursor++;
cursor = ParseTools.skipWhitespace(expr, cursor);
start = cursor;
Loop: while (cursor < endOffset) {
switch(expr[cursor]) {
case '{':
case '[':
case '(':
case '\'':
case '"':
cursor = balancedCaptureWithLineAccounting(expr, cursor, endOffset, expr[cursor], pCtx);
break;
case ';':
break Loop;
}
cursor++;
}
calculateDecl();
String initString = new String(expr, start, cursor++ - start);
if (interpreted && type == DeferredTypeResolve.class) {
enqueueReceiverForLateResolution(deferredName, proto.declareReceiver(name, Proto.ReceiverType.DEFERRED, null), initString);
} else {
proto.declareReceiver(name, type, (ExecutableStatement) subCompileExpression(initString, pCtx));
}
break;
default:
start = cursor;
while (cursor < endOffset && isIdentifierPart(expr[cursor])) cursor++;
if (cursor > start) {
tk2 = new String(expr, start, cursor - start);
}
}
}
cursor++;
/**
* Check if the function is manually terminated.
*/
if (splitAccumulator != null && ParseTools.isStatementNotManuallyTerminated(expr, cursor)) {
/**
* Add an EndOfStatement to the split accumulator in the parser.
*/
splitAccumulator.add(new EndOfStatement(pCtx));
}
return proto;
}
use of org.mule.mvel2.CompileException in project mvel by mvel.
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 mvel.
the class TypesAndInferenceTests method testSetAccessorOverloadedEqualsStrictMode2.
public void testSetAccessorOverloadedEqualsStrictMode2() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("foo", Foo.class);
try {
CompiledExpression expr = new ExpressionCompiler("foo.aValue = 'bar'", ctx).compile();
} catch (CompileException e) {
assertTrue(false);
}
}
use of org.mule.mvel2.CompileException in project mvel by mvel.
the class Fuzzer method main.
public static void main(String[] args) throws IOException {
DecimalFormat df = new DecimalFormat("###,###.##");
StringAppender append = new StringAppender();
int len;
long start = currentTimeMillis();
long time;
double rate;
int seed;
boolean flip = false;
Random rand = new Random(System.currentTimeMillis());
Random rand1 = new Random(System.currentTimeMillis() + 1);
Random rand2 = new Random(rand1.nextInt());
Random rand3 = new Random(rand.nextInt(SALTS.length - 1));
Random rand4 = new Random(rand3.nextInt());
for (int run = 0; run < MAX; run++) {
len = (int) (random() * 500) + 10;
append.reset();
for (int i = 0; i < len; i++) {
append.append(CHAR_TABLE[((SALTS[((rand.nextInt(1000)) + 1) % SALTS.length]) * ((flip = !flip) ? rand1.nextInt(1000) : rand2.nextInt(1000)) + 1) % CHAR_TABLE.length]);
SALTS[rand3.nextInt(SALTS.length - 1)] ^= rand4.nextInt(1000) + 1;
}
try {
MVEL.eval(append.toString());
} catch (UnresolveablePropertyException e) {
// ignore
} catch (CompileException e) {
// ignore
} catch (ArithmeticException e) {
// ignore
} catch (ScriptRuntimeException e) {
// ignore
} catch (Exception e) {
System.out.println("untrapped error!\n---\n" + append.toString() + "\n---\n");
System.out.flush();
e.printStackTrace();
System.err.flush();
}
if (run % 25000 == 0 && run != 0) {
long l = time = (currentTimeMillis() - start) / 1000;
if (l == 0) {
l = 1;
}
rate = run / l;
System.out.println("Run: " + df.format(run) + " times; " + df.format(time) + "secs; " + df.format(rate) + " avg. per second.");
}
}
}
use of org.mule.mvel2.CompileException in project mvel by mvel.
the class ASMAccessorOptimizer method writeLiteralOrSubexpression.
private Class writeLiteralOrSubexpression(Object stmt, Class desiredTarget, Class knownIngressType) {
if (stmt instanceof ExecutableLiteral) {
Object literalValue = ((ExecutableLiteral) stmt).getLiteral();
// Handle the case when the literal is null MVEL-312
if (literalValue == null) {
mv.visitInsn(ACONST_NULL);
return null;
}
Class type = literalValue == null ? desiredTarget : literalValue.getClass();
assert debug("*** type:" + type + ";desired:" + desiredTarget);
if (type == Integer.class && desiredTarget == int.class) {
intPush(((ExecutableLiteral) stmt).getInteger32());
type = int.class;
} else if (desiredTarget != null && desiredTarget != type) {
assert debug("*** Converting because desiredType(" + desiredTarget.getClass() + ") is not: " + type);
if (!DataConversion.canConvert(type, desiredTarget)) {
throw new CompileException("was expecting type: " + desiredTarget.getName() + "; but found type: " + type.getName(), expr, st);
}
writeOutLiteralWrapped(convert(literalValue, desiredTarget));
} else {
writeOutLiteralWrapped(literalValue);
}
return type;
} else {
literal = false;
addSubstatement((ExecutableStatement) stmt);
Class type;
if (knownIngressType == null) {
type = ((ExecutableStatement) stmt).getKnownEgressType();
} else {
type = knownIngressType;
}
if (desiredTarget != null && type != desiredTarget) {
if (desiredTarget.isPrimitive()) {
if (type == null)
throw new OptimizationFailure("cannot optimize expression: " + new String(expr) + ": cannot determine ingress type for primitive output");
checkcast(type);
unwrapPrimitive(desiredTarget);
}
}
return type;
}
}
Aggregations