diff options
Diffstat (limited to 'src/main/javassist/compiler')
-rw-r--r-- | src/main/javassist/compiler/Javac.java | 15 | ||||
-rw-r--r-- | src/main/javassist/compiler/Parser.java | 21 |
2 files changed, 31 insertions, 5 deletions
diff --git a/src/main/javassist/compiler/Javac.java b/src/main/javassist/compiler/Javac.java index 88ed0ab5..7a9dbe83 100644 --- a/src/main/javassist/compiler/Javac.java +++ b/src/main/javassist/compiler/Javac.java @@ -569,12 +569,21 @@ public class Javac { * have been invoked. */ public void compileExpr(String src) throws CompileError { - Parser p = new Parser(new Lex(src)); - ASTree e = p.parseExpression(stable); + ASTree e = parseExpr(src, stable); compileExpr(e); } /** + * Parsers an expression. + */ + public static ASTree parseExpr(String src, SymbolTable st) + throws CompileError + { + Parser p = new Parser(new Lex(src)); + return p.parseExpression(st); + } + + /** * Compiles an exression. <code>recordParams()</code> must be * called before invoking this method. * @@ -585,6 +594,6 @@ public class Javac { */ public void compileExpr(ASTree e) throws CompileError { if (e != null) - e.accept(gen); + gen.compileExpr(e); } } diff --git a/src/main/javassist/compiler/Parser.java b/src/main/javassist/compiler/Parser.java index ed6e9dd3..e1a0d5b2 100644 --- a/src/main/javassist/compiler/Parser.java +++ b/src/main/javassist/compiler/Parser.java @@ -852,6 +852,23 @@ public final class Parser implements TokenId { case '!' : case '~' : t = lex.get(); + if (t == '-') { + int t2 = lex.lookAhead(); + switch (t2) { + case LongConstant : + case IntConstant : + case CharConstant : + lex.get(); + return new IntConst(-lex.getLong(), t2); + case DoubleConstant : + case FloatConstant : + lex.get(); + return new DoubleConst(-lex.getDouble(), t2); + default : + break; + } + } + return Expr.make(t, parseUnaryExpr(tbl)); case '(' : return parseCast(tbl); @@ -977,12 +994,12 @@ public final class Parser implements TokenId { * a class name and a member name in an expression for static member * access. For example, * java.lang.Integer.toString(3) in regular Java - * must be written like this: + * can be written like this: * java.lang.Integer#toString(3) for this compiler. */ private ASTree parsePostfix(SymbolTable tbl) throws CompileError { int token = lex.lookAhead(); - switch (token) { + switch (token) { // see also parseUnaryExpr() case LongConstant : case IntConstant : case CharConstant : |