From 312b86f15919efe4593b5121d5e64634ded8f1f9 Mon Sep 17 00:00:00 2001 From: gaojunkang Date: Mon, 29 Jul 2024 13:42:13 +0800 Subject: [PATCH] refactor: replace typo lookhead with lookahead --- examples/calculator.av | 18 +- .../aviator/AviatorEvaluatorInstance.java | 8 +- .../aviator/code/CodeGenerator.java | 80 ++-- .../aviator/code/LambdaGenerator.java | 164 +++---- .../aviator/code/NoneCodeGenerator.java | 84 ++-- .../aviator/code/OptimizeCodeGenerator.java | 190 ++++---- .../aviator/code/asm/ASMCodeGenerator.java | 224 ++++----- .../interpreter/InterpretCodeGenerator.java | 112 ++--- .../aviator/lexer/token/OperatorToken.java | 8 +- .../aviator/parser/ExpressionParser.java | 428 +++++++++--------- .../aviator/parser/FakeCodeGenerator.java | 90 ++-- 11 files changed, 703 insertions(+), 703 deletions(-) diff --git a/examples/calculator.av b/examples/calculator.av index 2d27a694..6a075d05 100644 --- a/examples/calculator.av +++ b/examples/calculator.av @@ -69,7 +69,7 @@ fn expr(parser, tokens) { term(parser, tokens); while true { - let t = parser.lookhead; + let t = parser.lookahead; if t.val == '+' { parser.move(); @@ -89,7 +89,7 @@ fn term(parser, tokens) { unary(parser, tokens); while true { - let t = parser.lookhead; + let t = parser.lookahead; if t.val == '*' { parser.move(); @@ -106,7 +106,7 @@ fn term(parser, tokens) { } fn unary(parser, tokens) { - let t = parser.lookhead; + let t = parser.lookahead; if t.val == '-' { parser.move(); unary(parser, tokens); @@ -117,12 +117,12 @@ fn unary(parser, tokens) { } fn factor(parser, tokens) { - let t = parser.lookhead; + let t = parser.lookahead; if t.val == '(' { parser.move(); expr(parser, tokens); - t = parser.lookhead; + t = parser.lookahead; if t.val != ')'{ error(t); } @@ -137,10 +137,10 @@ fn factor(parser, tokens) { fn parser(lexer) { let parser = seq.map(); - parser.lookhead = lexer(); + parser.lookahead = lexer(); parser.move = fn() { - parser.lookhead = lexer(); + parser.lookahead = lexer(); }; return parser; @@ -153,8 +153,8 @@ fn parse(s) { expr(parser, tokens); - if parser.lookhead.type != EOF { - error(parser.lookhead); + if parser.lookahead.type != EOF { + error(parser.lookahead); } return tokens; diff --git a/src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java b/src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java index 13eab1ef..bbdff43b 100644 --- a/src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java +++ b/src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java @@ -1828,12 +1828,12 @@ public StringSegments compileStringSegments(final String lexeme, final String so new ExpressionParser(this, lexer, newCodeGenerator(sourceFile, false)); Expression exp = parser.parse(false); - final Token lookhead = parser.getLookhead(); - if (lookhead == null || (lookhead.getType() != TokenType.Char - || ((CharToken) lookhead).getCh() != '}')) { + final Token lookahead = parser.getLookahead(); + if (lookahead == null || (lookahead.getType() != TokenType.Char + || ((CharToken) lookahead).getCh() != '}')) { parser.reportSyntaxError("expect '}' to complete string interpolation"); } - int expStrLen = lookhead.getStartIndex() + 1; + int expStrLen = lookahead.getStartIndex() + 1; while (expStrLen-- > 0) { prev = ch; ch = it.next(); diff --git a/src/main/java/com/googlecode/aviator/code/CodeGenerator.java b/src/main/java/com/googlecode/aviator/code/CodeGenerator.java index 32f9a341..05d5df50 100644 --- a/src/main/java/com/googlecode/aviator/code/CodeGenerator.java +++ b/src/main/java/com/googlecode/aviator/code/CodeGenerator.java @@ -29,118 +29,118 @@ */ public interface CodeGenerator { - public void onAssignment(Token lookhead); + public void onAssignment(Token lookahead); public void setParser(Parser parser); - public void onShiftRight(Token lookhead); + public void onShiftRight(Token lookahead); - public void onShiftLeft(Token lookhead); + public void onShiftLeft(Token lookahead); - public void onUnsignedShiftRight(Token lookhead); + public void onUnsignedShiftRight(Token lookahead); - public void onBitOr(Token lookhead); + public void onBitOr(Token lookahead); - public void onBitAnd(Token lookhead); + public void onBitAnd(Token lookahead); - public void onBitXor(Token lookhead); + public void onBitXor(Token lookahead); - public void onBitNot(Token lookhead); + public void onBitNot(Token lookahead); - public void onAdd(Token lookhead); + public void onAdd(Token lookahead); - public void onSub(Token lookhead); + public void onSub(Token lookahead); - public void onMult(Token lookhead); + public void onMult(Token lookahead); public void onExponent(Token loohead); - public void onDiv(Token lookhead); + public void onDiv(Token lookahead); - public void onAndLeft(Token lookhead); + public void onAndLeft(Token lookahead); - public void onAndRight(Token lookhead); + public void onAndRight(Token alookahead); - public void onTernaryBoolean(Token lookhead); + public void onTernaryBoolean(Token lookahead); - public void onTernaryLeft(Token lookhead); + public void onTernaryLeft(Token lookahead); - public void onTernaryRight(Token lookhead); + public void onTernaryRight(Token lookahead); - public void onTernaryEnd(Token lookhead); + public void onTernaryEnd(Token lookahead); - public void onJoinLeft(Token lookhead); + public void onJoinLeft(Token lookahead); - public void onJoinRight(Token lookhead); + public void onJoinRight(Token lookahead); - public void onEq(Token lookhead); + public void onEq(Token lookahead); - public void onMatch(Token lookhead); + public void onMatch(Token lookahead); - public void onNeq(Token lookhead); + public void onNeq(Token lookahead); - public void onLt(Token lookhead); + public void onLt(Token lookahead); - public void onLe(Token lookhead); + public void onLe(Token lookahead); - public void onGt(Token lookhead); + public void onGt(Token lookahead); - public void onGe(Token lookhead); + public void onGe(Token lookahead); - public void onMod(Token lookhead); + public void onMod(Token lookahead); - public void onNot(Token lookhead); + public void onNot(Token lookahead); - public void onNeg(Token lookhead); + public void onNeg(Token lookahead); public Expression getResult(boolean unboxObject); - public void onConstant(Token lookhead); + public void onConstant(Token lookahead); - public void onMethodName(Token lookhead); + public void onMethodName(Token lookahead); - public void onMethodParameter(Token lookhead); + public void onMethodParameter(Token lookahead); - public void onMethodInvoke(Token lookhead); + public void onMethodInvoke(Token lookahead); - public void onLambdaDefineStart(Token lookhead); + public void onLambdaDefineStart(Token lookahead); - public void onLambdaArgument(Token lookhead, FunctionParam param); + public void onLambdaArgument(Token lookahead, FunctionParam param); - public void onLambdaBodyStart(Token lookhead); + public void onLambdaBodyStart(Token lookahead); - public void onLambdaBodyEnd(Token lookhead); + public void onLambdaBodyEnd(Token lookahead); - public void onArray(Token lookhead); + public void onArray(Token lookahead); public void onArrayIndexStart(Token token); - public void onArrayIndexEnd(Token lookhead); + public void onArrayIndexEnd(Token lookahead); } diff --git a/src/main/java/com/googlecode/aviator/code/LambdaGenerator.java b/src/main/java/com/googlecode/aviator/code/LambdaGenerator.java index ff1f527f..8aac66b1 100644 --- a/src/main/java/com/googlecode/aviator/code/LambdaGenerator.java +++ b/src/main/java/com/googlecode/aviator/code/LambdaGenerator.java @@ -210,212 +210,212 @@ public void addParam(final FunctionParam name) { @Override - public void onShiftRight(final Token lookhead) { - this.codeGenerator.onShiftRight(lookhead); + public void onShiftRight(final Token lookahead) { + this.codeGenerator.onShiftRight(lookahead); } @Override - public void onShiftLeft(final Token lookhead) { - this.codeGenerator.onShiftLeft(lookhead); + public void onShiftLeft(final Token lookahead) { + this.codeGenerator.onShiftLeft(lookahead); } @Override - public void onUnsignedShiftRight(final Token lookhead) { - this.codeGenerator.onUnsignedShiftRight(lookhead); + public void onUnsignedShiftRight(final Token lookahead) { + this.codeGenerator.onUnsignedShiftRight(lookahead); } @Override - public void onAssignment(final Token lookhead) { - this.codeGenerator.onAssignment(lookhead); + public void onAssignment(final Token lookahead) { + this.codeGenerator.onAssignment(lookahead); } @Override - public void onBitOr(final Token lookhead) { - this.codeGenerator.onBitOr(lookhead); + public void onBitOr(final Token lookahead) { + this.codeGenerator.onBitOr(lookahead); } @Override - public void onBitAnd(final Token lookhead) { - this.codeGenerator.onBitAnd(lookhead); + public void onBitAnd(final Token lookahead) { + this.codeGenerator.onBitAnd(lookahead); } @Override - public void onBitXor(final Token lookhead) { - this.codeGenerator.onBitXor(lookhead); + public void onBitXor(final Token lookahead) { + this.codeGenerator.onBitXor(lookahead); } @Override - public void onBitNot(final Token lookhead) { - this.codeGenerator.onBitNot(lookhead); + public void onBitNot(final Token lookahead) { + this.codeGenerator.onBitNot(lookahead); } @Override - public void onAdd(final Token lookhead) { - this.codeGenerator.onAdd(lookhead); + public void onAdd(final Token lookahead) { + this.codeGenerator.onAdd(lookahead); } @Override - public void onSub(final Token lookhead) { - this.codeGenerator.onSub(lookhead); + public void onSub(final Token lookahead) { + this.codeGenerator.onSub(lookahead); } @Override - public void onMult(final Token lookhead) { - this.codeGenerator.onMult(lookhead); + public void onMult(final Token lookahead) { + this.codeGenerator.onMult(lookahead); } @Override - public void onExponent(final Token lookhead) { - this.codeGenerator.onExponent(lookhead); + public void onExponent(final Token lookahead) { + this.codeGenerator.onExponent(lookahead); } @Override - public void onDiv(final Token lookhead) { - this.codeGenerator.onDiv(lookhead); + public void onDiv(final Token lookahead) { + this.codeGenerator.onDiv(lookahead); } @Override - public void onAndLeft(final Token lookhead) { - this.codeGenerator.onAndLeft(lookhead); + public void onAndLeft(final Token lookahead) { + this.codeGenerator.onAndLeft(lookahead); } @Override - public void onAndRight(final Token lookhead) { - this.codeGenerator.onAndRight(lookhead); + public void onAndRight(final Token alookahead) { + this.codeGenerator.onAndRight(alookahead); } @Override - public void onTernaryBoolean(final Token lookhead) { - this.codeGenerator.onTernaryBoolean(lookhead); + public void onTernaryBoolean(final Token lookahead) { + this.codeGenerator.onTernaryBoolean(lookahead); } @Override - public void onTernaryLeft(final Token lookhead) { - this.codeGenerator.onTernaryLeft(lookhead); + public void onTernaryLeft(final Token lookahead) { + this.codeGenerator.onTernaryLeft(lookahead); } @Override - public void onTernaryRight(final Token lookhead) { - this.codeGenerator.onTernaryRight(lookhead); + public void onTernaryRight(final Token lookahead) { + this.codeGenerator.onTernaryRight(lookahead); } @Override - public void onTernaryEnd(final Token lookhead) { - this.codeGenerator.onTernaryEnd(lookhead); + public void onTernaryEnd(final Token lookahead) { + this.codeGenerator.onTernaryEnd(lookahead); } @Override - public void onJoinLeft(final Token lookhead) { - this.codeGenerator.onJoinLeft(lookhead); + public void onJoinLeft(final Token lookahead) { + this.codeGenerator.onJoinLeft(lookahead); } @Override - public void onJoinRight(final Token lookhead) { - this.codeGenerator.onJoinRight(lookhead); + public void onJoinRight(final Token lookahead) { + this.codeGenerator.onJoinRight(lookahead); } @Override - public void onEq(final Token lookhead) { - this.codeGenerator.onEq(lookhead); + public void onEq(final Token lookahead) { + this.codeGenerator.onEq(lookahead); } @Override - public void onMatch(final Token lookhead) { - this.codeGenerator.onMatch(lookhead); + public void onMatch(final Token lookahead) { + this.codeGenerator.onMatch(lookahead); } @Override - public void onNeq(final Token lookhead) { - this.codeGenerator.onNeq(lookhead); + public void onNeq(final Token lookahead) { + this.codeGenerator.onNeq(lookahead); } @Override - public void onLt(final Token lookhead) { - this.codeGenerator.onLt(lookhead); + public void onLt(final Token lookahead) { + this.codeGenerator.onLt(lookahead); } @Override - public void onLe(final Token lookhead) { - this.codeGenerator.onLe(lookhead); + public void onLe(final Token lookahead) { + this.codeGenerator.onLe(lookahead); } @Override - public void onGt(final Token lookhead) { - this.codeGenerator.onGt(lookhead); + public void onGt(final Token lookahead) { + this.codeGenerator.onGt(lookahead); } @Override - public void onGe(final Token lookhead) { - this.codeGenerator.onGe(lookhead); + public void onGe(final Token lookahead) { + this.codeGenerator.onGe(lookahead); } @Override - public void onMod(final Token lookhead) { - this.codeGenerator.onMod(lookhead); + public void onMod(final Token lookahead) { + this.codeGenerator.onMod(lookahead); } @Override - public void onNot(final Token lookhead) { - this.codeGenerator.onNot(lookhead); + public void onNot(final Token lookahead) { + this.codeGenerator.onNot(lookahead); } @Override - public void onNeg(final Token lookhead) { - this.codeGenerator.onNeg(lookhead); + public void onNeg(final Token lookahead) { + this.codeGenerator.onNeg(lookahead); } @@ -426,55 +426,55 @@ public Expression getResult(final boolean unboxObject) { @Override - public void onConstant(final Token lookhead) { - this.codeGenerator.onConstant(lookhead); + public void onConstant(final Token lookahead) { + this.codeGenerator.onConstant(lookahead); } @Override - public void onMethodName(final Token lookhead) { - this.codeGenerator.onMethodName(lookhead); + public void onMethodName(final Token lookahead) { + this.codeGenerator.onMethodName(lookahead); } @Override - public void onMethodParameter(final Token lookhead) { - this.codeGenerator.onMethodParameter(lookhead); + public void onMethodParameter(final Token lookahead) { + this.codeGenerator.onMethodParameter(lookahead); } @Override - public void onMethodInvoke(final Token lookhead) { - this.codeGenerator.onMethodInvoke(lookhead); + public void onMethodInvoke(final Token lookahead) { + this.codeGenerator.onMethodInvoke(lookahead); } @Override - public void onLambdaDefineStart(final Token lookhead) { - this.codeGenerator.onLambdaDefineStart(lookhead); + public void onLambdaDefineStart(final Token lookahead) { + this.codeGenerator.onLambdaDefineStart(lookahead); } @Override - public void onLambdaArgument(final Token lookhead, final FunctionParam param) { - this.codeGenerator.onLambdaArgument(lookhead, param); + public void onLambdaArgument(final Token lookahead, final FunctionParam param) { + this.codeGenerator.onLambdaArgument(lookahead, param); } @Override - public void onLambdaBodyStart(final Token lookhead) { - this.codeGenerator.onLambdaBodyStart(lookhead); + public void onLambdaBodyStart(final Token lookahead) { + this.codeGenerator.onLambdaBodyStart(lookahead); } @Override - public void onLambdaBodyEnd(final Token lookhead) { + public void onLambdaBodyEnd(final Token lookahead) { // should call parent generator - this.parentCodeGenerator.onLambdaBodyEnd(lookhead); + this.parentCodeGenerator.onLambdaBodyEnd(lookahead); } @Override - public void onArray(final Token lookhead) { - this.codeGenerator.onArray(lookhead); + public void onArray(final Token lookahead) { + this.codeGenerator.onArray(lookahead); } @Override @@ -483,8 +483,8 @@ public void onArrayIndexStart(final Token token) { } @Override - public void onArrayIndexEnd(final Token lookhead) { - this.codeGenerator.onArrayIndexEnd(lookhead); + public void onArrayIndexEnd(final Token lookahead) { + this.codeGenerator.onArrayIndexEnd(lookahead); } } diff --git a/src/main/java/com/googlecode/aviator/code/NoneCodeGenerator.java b/src/main/java/com/googlecode/aviator/code/NoneCodeGenerator.java index 59055327..a8daa669 100644 --- a/src/main/java/com/googlecode/aviator/code/NoneCodeGenerator.java +++ b/src/main/java/com/googlecode/aviator/code/NoneCodeGenerator.java @@ -20,7 +20,7 @@ public class NoneCodeGenerator implements CodeGenerator { private Parser parser; @Override - public void onAssignment(final Token lookhead) { + public void onAssignment(final Token lookahead) { } @@ -31,61 +31,61 @@ public void setParser(final Parser parser) { } @Override - public void onShiftRight(final Token lookhead) { + public void onShiftRight(final Token lookahead) { } @Override - public void onShiftLeft(final Token lookhead) { + public void onShiftLeft(final Token lookahead) { } @Override - public void onUnsignedShiftRight(final Token lookhead) { + public void onUnsignedShiftRight(final Token lookahead) { } @Override - public void onBitOr(final Token lookhead) { + public void onBitOr(final Token lookahead) { } @Override - public void onBitAnd(final Token lookhead) { + public void onBitAnd(final Token lookahead) { } @Override - public void onBitXor(final Token lookhead) { + public void onBitXor(final Token lookahead) { } @Override - public void onBitNot(final Token lookhead) { + public void onBitNot(final Token lookahead) { } @Override - public void onAdd(final Token lookhead) { + public void onAdd(final Token lookahead) { } @Override - public void onSub(final Token lookhead) { + public void onSub(final Token lookahead) { } @Override - public void onMult(final Token lookhead) { + public void onMult(final Token lookahead) { } @@ -93,120 +93,120 @@ public void onMult(final Token lookhead) { @Override - public void onExponent(final Token lookhead) { + public void onExponent(final Token lookahead) { } @Override - public void onDiv(final Token lookhead) { + public void onDiv(final Token lookahead) { } @Override - public void onAndLeft(final Token lookhead) { + public void onAndLeft(final Token lookahead) { } @Override - public void onAndRight(final Token lookhead) { + public void onAndRight(final Token alookahead) { } @Override - public void onTernaryBoolean(final Token lookhead) { + public void onTernaryBoolean(final Token lookahead) { } @Override - public void onTernaryLeft(final Token lookhead) { + public void onTernaryLeft(final Token lookahead) { } @Override - public void onTernaryRight(final Token lookhead) { + public void onTernaryRight(final Token lookahead) { } @Override - public void onTernaryEnd(final Token lookhead) { + public void onTernaryEnd(final Token lookahead) { } @Override - public void onJoinLeft(final Token lookhead) { + public void onJoinLeft(final Token lookahead) { } @Override - public void onJoinRight(final Token lookhead) { + public void onJoinRight(final Token lookahead) { } @Override - public void onEq(final Token lookhead) { + public void onEq(final Token lookahead) { } @Override - public void onMatch(final Token lookhead) { + public void onMatch(final Token lookahead) { } @Override - public void onNeq(final Token lookhead) { + public void onNeq(final Token lookahead) { } @Override - public void onLt(final Token lookhead) { + public void onLt(final Token lookahead) { } @Override - public void onLe(final Token lookhead) { + public void onLe(final Token lookahead) { } @Override - public void onGt(final Token lookhead) { + public void onGt(final Token lookahead) { } @Override - public void onGe(final Token lookhead) { + public void onGe(final Token lookahead) { } @Override - public void onMod(final Token lookhead) { + public void onMod(final Token lookahead) { } @Override - public void onNot(final Token lookhead) { + public void onNot(final Token lookahead) { } @Override - public void onNeg(final Token lookhead) { + public void onNeg(final Token lookahead) { } @@ -218,54 +218,54 @@ public Expression getResult(final boolean unboxObject) { } @Override - public void onConstant(final Token lookhead) { + public void onConstant(final Token lookahead) { } @Override - public void onMethodName(final Token lookhead) { + public void onMethodName(final Token lookahead) { } @Override - public void onMethodParameter(final Token lookhead) { + public void onMethodParameter(final Token lookahead) { } @Override - public void onMethodInvoke(final Token lookhead) { + public void onMethodInvoke(final Token lookahead) { } @Override - public void onLambdaDefineStart(final Token lookhead) { - Boolean newLexicalScope = lookhead.getMeta(Constants.SCOPE_META, false); + public void onLambdaDefineStart(final Token lookahead) { + Boolean newLexicalScope = lookahead.getMeta(Constants.SCOPE_META, false); this.infos.push(this.parser.enterScope(newLexicalScope)); } @Override - public void onLambdaArgument(final Token lookhead, final FunctionParam param) { + public void onLambdaArgument(final Token lookahead, final FunctionParam param) { } @Override - public void onLambdaBodyStart(final Token lookhead) { + public void onLambdaBodyStart(final Token lookahead) { } @Override - public void onLambdaBodyEnd(final Token lookhead) { + public void onLambdaBodyEnd(final Token lookahead) { this.parser.restoreScope(this.infos.pop()); } @Override - public void onArray(final Token lookhead) { + public void onArray(final Token lookahead) { } @@ -277,7 +277,7 @@ public void onArrayIndexStart(final Token token) { } @Override - public void onArrayIndexEnd(final Token lookhead) { + public void onArrayIndexEnd(final Token lookahead) { } diff --git a/src/main/java/com/googlecode/aviator/code/OptimizeCodeGenerator.java b/src/main/java/com/googlecode/aviator/code/OptimizeCodeGenerator.java index 29ef7f05..e9b316d0 100644 --- a/src/main/java/com/googlecode/aviator/code/OptimizeCodeGenerator.java +++ b/src/main/java/com/googlecode/aviator/code/OptimizeCodeGenerator.java @@ -319,36 +319,36 @@ private void compactTokenList() { } - private AviatorObject getAviatorObjectFromToken(final Token lookhead) { + private AviatorObject getAviatorObjectFromToken(final Token lookahead) { AviatorObject result = null; - switch (lookhead.getType()) { + switch (lookahead.getType()) { case Number: // load numbers - NumberToken numberToken = (NumberToken) lookhead; + NumberToken numberToken = (NumberToken) lookahead; Number num = numberToken.getNumber(); result = AviatorNumber.valueOf(num); break; case String: // load string result = - new AviatorString((String) lookhead.getValue(null), true, true, lookhead.getLineNo()); + new AviatorString((String) lookahead.getValue(null), true, true, lookahead.getLineNo()); break; case Pattern: // load pattern - result = new AviatorPattern((String) lookhead.getValue(null)); + result = new AviatorPattern((String) lookahead.getValue(null)); break; case Variable: - if (lookhead == Variable.TRUE) { + if (lookahead == Variable.TRUE) { result = AviatorBoolean.TRUE; - } else if (lookhead == Variable.FALSE) { + } else if (lookahead == Variable.FALSE) { result = AviatorBoolean.FALSE; - } else if (lookhead == Variable.NIL) { + } else if (lookahead == Variable.NIL) { result = AviatorNil.NIL; } break; case Char: - result = new AviatorString(String.valueOf(lookhead.getValue(null)), true, true, - lookhead.getLineNo()); + result = new AviatorString(String.valueOf(lookahead.getValue(null)), true, true, + lookahead.getLineNo()); break; } return result; @@ -617,151 +617,151 @@ private void printTokenList() { @Override - public void onAdd(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.ADD)); + public void onAdd(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.ADD)); } @Override - public void onAndLeft(final Token lookhead) { - this.tokenList.add(new DelegateToken(lookhead, DelegateTokenType.And_Left)); + public void onAndLeft(final Token lookahead) { + this.tokenList.add(new DelegateToken(lookahead, DelegateTokenType.And_Left)); } @Override - public void onAndRight(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.AND)); + public void onAndRight(final Token alookahead) { + this.tokenList.add(new OperatorToken(alookahead, OperatorType.AND)); } @Override - public void onConstant(final Token lookhead) { - this.tokenList.add(lookhead); + public void onConstant(final Token lookahead) { + this.tokenList.add(lookahead); } @Override - public void onDiv(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.DIV)); + public void onDiv(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.DIV)); } @Override - public void onArrayIndexStart(final Token lookhead) { - this.tokenList.add(new DelegateToken(lookhead, DelegateTokenType.Index_Start)); + public void onArrayIndexStart(final Token lookahead) { + this.tokenList.add(new DelegateToken(lookahead, DelegateTokenType.Index_Start)); } @Override - public void onAssignment(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, - (lookhead == null || !lookhead.getMeta(Constants.DEFINE_META, false)) + public void onAssignment(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, + (lookahead == null || !lookahead.getMeta(Constants.DEFINE_META, false)) ? OperatorType.ASSIGNMENT : OperatorType.DEFINE)); } @Override - public void onArrayIndexEnd(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.INDEX)); + public void onArrayIndexEnd(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.INDEX)); } @Override - public void onArray(final Token lookhead) { - this.tokenList.add(new DelegateToken(lookhead, DelegateTokenType.Array)); + public void onArray(final Token lookahead) { + this.tokenList.add(new DelegateToken(lookahead, DelegateTokenType.Array)); } @Override - public void onEq(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.EQ)); + public void onEq(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.EQ)); } @Override - public void onGe(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.GE)); + public void onGe(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.GE)); } @Override - public void onGt(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.GT)); + public void onGt(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.GT)); } @Override - public void onJoinLeft(final Token lookhead) { - this.tokenList.add(new DelegateToken(lookhead, DelegateTokenType.Join_Left)); + public void onJoinLeft(final Token lookahead) { + this.tokenList.add(new DelegateToken(lookahead, DelegateTokenType.Join_Left)); } @Override - public void onJoinRight(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.OR)); + public void onJoinRight(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.OR)); } @Override - public void onLe(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.LE)); + public void onLe(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.LE)); } @Override - public void onLt(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.LT)); + public void onLt(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.LT)); } @Override - public void onMatch(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.MATCH)); + public void onMatch(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.MATCH)); } @Override - public void onMethodInvoke(final Token lookhead) { - OperatorToken token = new OperatorToken(lookhead, OperatorType.FUNC); - token.setMetaMap(lookhead != null ? lookhead.getMetaMap() : null); + public void onMethodInvoke(final Token lookahead) { + OperatorToken token = new OperatorToken(lookahead, OperatorType.FUNC); + token.setMetaMap(lookahead != null ? lookahead.getMetaMap() : null); this.tokenList.add(token); } @Override - public void onMethodName(final Token lookhead) { - this.tokenList.add(new DelegateToken(lookhead, DelegateTokenType.Method_Name)); + public void onMethodName(final Token lookahead) { + this.tokenList.add(new DelegateToken(lookahead, DelegateTokenType.Method_Name)); } @Override - public void onMethodParameter(final Token lookhead) { - this.tokenList.add(new DelegateToken(lookhead, DelegateTokenType.Method_Param)); + public void onMethodParameter(final Token lookahead) { + this.tokenList.add(new DelegateToken(lookahead, DelegateTokenType.Method_Param)); } @Override - public void onLambdaDefineStart(final Token lookhead) { + public void onLambdaDefineStart(final Token lookahead) { if (this.lambdaGenerator == null) { // TODO cache? - Boolean newLexicalScope = lookhead.getMeta(Constants.SCOPE_META, false); - Boolean inheritEnv = lookhead.getMeta(Constants.INHERIT_ENV_META, false); + Boolean newLexicalScope = lookahead.getMeta(Constants.SCOPE_META, false); + Boolean inheritEnv = lookahead.getMeta(Constants.INHERIT_ENV_META, false); this.lambdaGenerator = new LambdaGenerator(this.instance, this, this.parser, this.codeGen.getClassLoader(), this.sourceFile, newLexicalScope, inheritEnv); this.lambdaGenerator.setScopeInfo(this.parser.enterScope(newLexicalScope)); @@ -772,27 +772,27 @@ public void onLambdaDefineStart(final Token lookhead) { @Override - public void onLambdaArgument(final Token lookhead, final FunctionParam param) { + public void onLambdaArgument(final Token lookahead, final FunctionParam param) { this.lambdaGenerator.addParam(param); } @Override - public void onLambdaBodyStart(final Token lookhead) { + public void onLambdaBodyStart(final Token lookahead) { this.parentCodeGenerator = this.parser.getCodeGenerator(); this.parser.setCodeGenerator(this.lambdaGenerator); } @Override - public void onLambdaBodyEnd(final Token lookhead) { + public void onLambdaBodyEnd(final Token lookahead) { // this.lambdaGenerator.compileCallMethod(); LambdaFunctionBootstrap bootstrap = this.lambdaGenerator.getLmabdaBootstrap(); if (this.lambdaBootstraps == null) { this.lambdaBootstraps = new HashMap(); } this.lambdaBootstraps.put(bootstrap.getName(), bootstrap); - DelegateToken token = new DelegateToken(lookhead, DelegateTokenType.Lambda_New); + DelegateToken token = new DelegateToken(lookahead, DelegateTokenType.Lambda_New); token.setLambdaFunctionBootstrap(bootstrap); this.tokenList.add(token); this.parser.restoreScope(this.lambdaGenerator.getScopeInfo()); @@ -802,122 +802,122 @@ public void onLambdaBodyEnd(final Token lookhead) { @Override - public void onMod(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.MOD)); + public void onMod(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.MOD)); } @Override - public void onMult(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.MULT)); + public void onMult(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.MULT)); } @Override - public void onExponent(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.Exponent)); + public void onExponent(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.Exponent)); } @Override - public void onNeg(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.NEG)); + public void onNeg(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.NEG)); } @Override - public void onNeq(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.NEQ)); + public void onNeq(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.NEQ)); } @Override - public void onNot(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.NOT)); + public void onNot(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.NOT)); } @Override - public void onSub(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.SUB)); + public void onSub(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.SUB)); } @Override - public void onTernaryBoolean(final Token lookhead) { - this.tokenList.add(new DelegateToken(lookhead, DelegateTokenType.Ternary_Boolean)); + public void onTernaryBoolean(final Token lookahead) { + this.tokenList.add(new DelegateToken(lookahead, DelegateTokenType.Ternary_Boolean)); } @Override - public void onTernaryLeft(final Token lookhead) { - this.tokenList.add(new DelegateToken(lookhead, DelegateTokenType.Ternary_Left)); + public void onTernaryLeft(final Token lookahead) { + this.tokenList.add(new DelegateToken(lookahead, DelegateTokenType.Ternary_Left)); } @Override - public void onTernaryRight(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.TERNARY)); + public void onTernaryRight(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.TERNARY)); } @Override - public void onTernaryEnd(final Token lookhead) { - this.tokenList.add(new DelegateToken(lookhead, DelegateTokenType.Ternay_End)); + public void onTernaryEnd(final Token lookahead) { + this.tokenList.add(new DelegateToken(lookahead, DelegateTokenType.Ternay_End)); } @Override - public void onBitAnd(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.BIT_AND)); + public void onBitAnd(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.BIT_AND)); } @Override - public void onBitNot(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.BIT_NOT)); + public void onBitNot(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.BIT_NOT)); } @Override - public void onBitOr(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.BIT_OR)); + public void onBitOr(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.BIT_OR)); } @Override - public void onShiftLeft(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.SHIFT_LEFT)); + public void onShiftLeft(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.SHIFT_LEFT)); } @Override - public void onShiftRight(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.SHIFT_RIGHT)); + public void onShiftRight(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.SHIFT_RIGHT)); } @Override - public void onUnsignedShiftRight(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.U_SHIFT_RIGHT)); + public void onUnsignedShiftRight(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.U_SHIFT_RIGHT)); } @Override - public void onBitXor(final Token lookhead) { - this.tokenList.add(new OperatorToken(lookhead, OperatorType.BIT_XOR)); + public void onBitXor(final Token lookahead) { + this.tokenList.add(new OperatorToken(lookahead, OperatorType.BIT_XOR)); } diff --git a/src/main/java/com/googlecode/aviator/code/asm/ASMCodeGenerator.java b/src/main/java/com/googlecode/aviator/code/asm/ASMCodeGenerator.java index de5e5171..cae88d0d 100644 --- a/src/main/java/com/googlecode/aviator/code/asm/ASMCodeGenerator.java +++ b/src/main/java/com/googlecode/aviator/code/asm/ASMCodeGenerator.java @@ -292,8 +292,8 @@ private Label makeLabel() { * @see com.googlecode.aviator.code.CodeGenerator#onAdd(com.googlecode.aviator .lexer.token.Token) */ @Override - public void onAdd(final Token lookhead) { - visitBinOperator(lookhead, OperatorType.ADD, "add"); + public void onAdd(final Token lookahead) { + visitBinOperator(lookahead, OperatorType.ADD, "add"); } private void loadOpType(final OperatorType opType) { @@ -322,8 +322,8 @@ private void popOperand(final int n) { * @see com.googlecode.aviator.code.CodeGenerator#onSub(com.googlecode.aviator .lexer.token.Token) */ @Override - public void onSub(final Token lookhead) { - visitBinOperator(lookhead, OperatorType.SUB, "sub"); + public void onSub(final Token lookahead) { + visitBinOperator(lookahead, OperatorType.SUB, "sub"); } /* @@ -333,19 +333,19 @@ public void onSub(final Token lookhead) { * .lexer.token.Token) */ @Override - public void onMult(final Token lookhead) { - visitBinOperator(lookhead, OperatorType.MULT, "mult"); + public void onMult(final Token lookahead) { + visitBinOperator(lookahead, OperatorType.MULT, "mult"); } @Override - public void onExponent(final Token lookhead) { - visitBinOperator(lookhead, OperatorType.Exponent, "exponent"); + public void onExponent(final Token lookahead) { + visitBinOperator(lookahead, OperatorType.Exponent, "exponent"); } @Override - public void onAssignment(final Token lookhead) { - visitLineNumber(lookhead); - OperatorType opType = lookhead.getMeta(Constants.DEFINE_META, false) ? OperatorType.DEFINE + public void onAssignment(final Token lookahead) { + visitLineNumber(lookahead); + OperatorType opType = lookahead.getMeta(Constants.DEFINE_META, false) ? OperatorType.DEFINE : OperatorType.ASSIGNMENT; loadEnv(); if (!OperationRuntime.hasRuntimeContext(this.compileEnv, opType)) { @@ -369,8 +369,8 @@ public void onAssignment(final Token lookhead) { * @see com.googlecode.aviator.code.CodeGenerator#onDiv(com.googlecode.aviator .lexer.token.Token) */ @Override - public void onDiv(final Token lookhead) { - visitBinOperator(lookhead, OperatorType.DIV, "div"); + public void onDiv(final Token lookahead) { + visitBinOperator(lookahead, OperatorType.DIV, "div"); } /* @@ -379,17 +379,17 @@ public void onDiv(final Token lookhead) { * @see com.googlecode.aviator.code.CodeGenerator#onMod(com.googlecode.aviator .lexer.token.Token) */ @Override - public void onMod(final Token lookhead) { - visitBinOperator(lookhead, OperatorType.MOD, "mod"); + public void onMod(final Token lookahead) { + visitBinOperator(lookahead, OperatorType.MOD, "mod"); } /** * Do logic operation "&&" left operand */ @Override - public void onAndLeft(final Token lookhead) { + public void onAndLeft(final Token lookahead) { loadEnv(); - visitLeftBranch(lookhead, IFEQ, OperatorType.AND); + visitLeftBranch(lookahead, IFEQ, OperatorType.AND); } private void visitBoolean() { @@ -404,13 +404,13 @@ private void pushLabel0(final Label l0) { * Do logic operation "&&" right operand */ @Override - public void onAndRight(final Token lookhead) { - visitRightBranch(lookhead, IFEQ, OperatorType.AND); + public void onAndRight(final Token lookahead) { + visitRightBranch(lookahead, IFEQ, OperatorType.AND); this.popOperand(2); // boolean object and environment this.pushOperand(); } - private void visitRightBranch(final Token lookhead, final int ints, + private void visitRightBranch(final Token lookahead, final int ints, final OperatorType opType) { this.checkExecutionTimeout(); if (!OperationRuntime.hasRuntimeContext(this.compileEnv, opType)) { @@ -425,7 +425,7 @@ private void visitRightBranch(final Token lookhead, final int ints, this.mv.visitInsn(POP); Label l1 = makeLabel(); - visitLineNumber(lookhead); + visitLineNumber(lookahead); this.mv.visitJumpInsn(GOTO, l1); visitLabel(popLabel0()); // Result is false @@ -434,7 +434,7 @@ private void visitRightBranch(final Token lookhead, final int ints, visitLabel(l1); } else { loadOpType(opType); - visitLineNumber(lookhead); + visitLineNumber(lookahead); this.mv.visitMethodInsn(INVOKESTATIC, "com/googlecode/aviator/runtime/op/OperationRuntime", "eval", "(Lcom/googlecode/aviator/runtime/type/AviatorObject;Ljava/util/Map;Lcom/googlecode/aviator/runtime/type/AviatorObject;Lcom/googlecode/aviator/lexer/token/OperatorType;)Lcom/googlecode/aviator/runtime/type/AviatorObject;"); @@ -449,9 +449,9 @@ private void visitRightBranch(final Token lookhead, final int ints, private final Stack