use of org.codehaus.groovy.GroovyBugError in project groovy by apache.
the class CompileStack method clear.
/**
* Clears the state of the class. This method should be called
* after a MethodNode is visited. Note that a call to init will
* fail if clear is not called before
*/
public void clear() {
if (stateStack.size() > 1) {
int size = stateStack.size() - 1;
throw new GroovyBugError("the compile stack contains " + size + " more push instruction" + (size == 1 ? "" : "s") + " than pops.");
}
if (lhsStack.size() > 1) {
int size = lhsStack.size() - 1;
throw new GroovyBugError("lhs stack is supposed to be empty, but has " + size + " elements left.");
}
if (implicitThisStack.size() > 1) {
int size = implicitThisStack.size() - 1;
throw new GroovyBugError("implicit 'this' stack is supposed to be empty, but has " + size + " elements left.");
}
clear = true;
MethodVisitor mv = controller.getMethodVisitor();
// br experiment with local var table so debuggers can retrieve variable names
if (true) {
//AsmClassGenerator.CREATE_DEBUG_INFO) {
if (thisEndLabel == null)
setEndLabels();
if (!scope.isInStaticContext()) {
// write "this"
mv.visitLocalVariable("this", className, null, thisStartLabel, thisEndLabel, 0);
}
for (Iterator iterator = usedVariables.iterator(); iterator.hasNext(); ) {
BytecodeVariable v = (BytecodeVariable) iterator.next();
ClassNode t = v.getType();
if (v.isHolder())
t = ClassHelper.REFERENCE_TYPE;
String type = BytecodeHelper.getTypeDescription(t);
Label start = v.getStartLabel();
Label end = v.getEndLabel();
mv.visitLocalVariable(v.getName(), type, null, start, end, v.getIndex());
}
}
//exception table writing
for (ExceptionTableEntry ep : typedExceptions) {
mv.visitTryCatchBlock(ep.start, ep.end, ep.goal, ep.sig);
}
//exception table writing
for (ExceptionTableEntry ep : untypedExceptions) {
mv.visitTryCatchBlock(ep.start, ep.end, ep.goal, ep.sig);
}
pop();
typedExceptions.clear();
untypedExceptions.clear();
stackVariables.clear();
usedVariables.clear();
scope = null;
finallyBlocks.clear();
resetVariableIndex(false);
superBlockNamedLabels.clear();
currentBlockNamedLabels.clear();
namedLoopBreakLabel.clear();
namedLoopContinueLabel.clear();
continueLabel = null;
breakLabel = null;
thisStartLabel = null;
thisEndLabel = null;
mv = null;
}
use of org.codehaus.groovy.GroovyBugError in project groovy by apache.
the class CompileStack method removeVar.
public void removeVar(int tempIndex) {
final BytecodeVariable head = (BytecodeVariable) temporaryVariables.removeFirst();
if (head.getIndex() != tempIndex) {
temporaryVariables.addFirst(head);
MethodNode methodNode = controller.getMethodNode();
if (methodNode == null) {
methodNode = controller.getConstructorNode();
}
throw new GroovyBugError("In method " + (methodNode != null ? methodNode.getText() : "<unknown>") + ", " + "CompileStack#removeVar: tried to remove a temporary " + "variable with index " + tempIndex + " in wrong order. " + "Current temporary variables=" + temporaryVariables);
}
}
use of org.codehaus.groovy.GroovyBugError in project groovy by apache.
the class BinaryExpressionHelper method eval.
public void eval(BinaryExpression expression) {
switch(expression.getOperation().getType()) {
case // = assignment
EQUAL:
evaluateEqual(expression, false);
break;
case // ==
COMPARE_EQUAL:
evaluateCompareExpression(compareEqualMethod, expression);
break;
case COMPARE_NOT_EQUAL:
evaluateCompareExpression(compareNotEqualMethod, expression);
break;
case COMPARE_TO:
evaluateCompareTo(expression);
break;
case COMPARE_GREATER_THAN:
evaluateCompareExpression(compareGreaterThanMethod, expression);
break;
case COMPARE_GREATER_THAN_EQUAL:
evaluateCompareExpression(compareGreaterThanEqualMethod, expression);
break;
case COMPARE_LESS_THAN:
evaluateCompareExpression(compareLessThanMethod, expression);
break;
case COMPARE_LESS_THAN_EQUAL:
evaluateCompareExpression(compareLessThanEqualMethod, expression);
break;
case LOGICAL_AND:
evaluateLogicalAndExpression(expression);
break;
case LOGICAL_OR:
evaluateLogicalOrExpression(expression);
break;
case BITWISE_AND:
evaluateBinaryExpression("and", expression);
break;
case BITWISE_AND_EQUAL:
evaluateBinaryExpressionWithAssignment("and", expression);
break;
case BITWISE_OR:
evaluateBinaryExpression("or", expression);
break;
case BITWISE_OR_EQUAL:
evaluateBinaryExpressionWithAssignment("or", expression);
break;
case BITWISE_XOR:
evaluateBinaryExpression("xor", expression);
break;
case BITWISE_XOR_EQUAL:
evaluateBinaryExpressionWithAssignment("xor", expression);
break;
case PLUS:
evaluateBinaryExpression("plus", expression);
break;
case PLUS_EQUAL:
evaluateBinaryExpressionWithAssignment("plus", expression);
break;
case MINUS:
evaluateBinaryExpression("minus", expression);
break;
case MINUS_EQUAL:
evaluateBinaryExpressionWithAssignment("minus", expression);
break;
case MULTIPLY:
evaluateBinaryExpression("multiply", expression);
break;
case MULTIPLY_EQUAL:
evaluateBinaryExpressionWithAssignment("multiply", expression);
break;
case DIVIDE:
evaluateBinaryExpression("div", expression);
break;
case DIVIDE_EQUAL:
//SPG don't use divide since BigInteger implements directly
//and we want to dispatch through DefaultGroovyMethods to get a BigDecimal result
evaluateBinaryExpressionWithAssignment("div", expression);
break;
case INTDIV:
evaluateBinaryExpression("intdiv", expression);
break;
case INTDIV_EQUAL:
evaluateBinaryExpressionWithAssignment("intdiv", expression);
break;
case MOD:
evaluateBinaryExpression("mod", expression);
break;
case MOD_EQUAL:
evaluateBinaryExpressionWithAssignment("mod", expression);
break;
case POWER:
evaluateBinaryExpression("power", expression);
break;
case POWER_EQUAL:
evaluateBinaryExpressionWithAssignment("power", expression);
break;
case LEFT_SHIFT:
evaluateBinaryExpression("leftShift", expression);
break;
case LEFT_SHIFT_EQUAL:
evaluateBinaryExpressionWithAssignment("leftShift", expression);
break;
case RIGHT_SHIFT:
evaluateBinaryExpression("rightShift", expression);
break;
case RIGHT_SHIFT_EQUAL:
evaluateBinaryExpressionWithAssignment("rightShift", expression);
break;
case RIGHT_SHIFT_UNSIGNED:
evaluateBinaryExpression("rightShiftUnsigned", expression);
break;
case RIGHT_SHIFT_UNSIGNED_EQUAL:
evaluateBinaryExpressionWithAssignment("rightShiftUnsigned", expression);
break;
case KEYWORD_INSTANCEOF:
evaluateInstanceof(expression);
break;
case FIND_REGEX:
evaluateCompareExpression(findRegexMethod, expression);
break;
case MATCH_REGEX:
evaluateCompareExpression(matchRegexMethod, expression);
break;
case LEFT_SQUARE_BRACKET:
if (controller.getCompileStack().isLHS()) {
evaluateEqual(expression, false);
} else {
evaluateBinaryExpression("getAt", expression);
}
break;
case KEYWORD_IN:
evaluateCompareExpression(isCaseMethod, expression);
break;
case COMPARE_IDENTICAL:
case COMPARE_NOT_IDENTICAL:
Token op = expression.getOperation();
Throwable cause = new SyntaxException("Operator " + op + " not supported", op.getStartLine(), op.getStartColumn(), op.getStartLine(), op.getStartColumn() + 3);
throw new GroovyRuntimeException(cause);
default:
throw new GroovyBugError("Operation: " + expression.getOperation() + " not supported");
}
}
use of org.codehaus.groovy.GroovyBugError in project groovy by apache.
the class CompileStack method init.
/**
* initializes this class for a MethodNode. This method will
* automatically define variables for the method parameters
* and will create references if needed. The created variables
* can be accessed by calling getVariable().
*
*/
public void init(VariableScope el, Parameter[] parameters) {
if (!clear)
throw new GroovyBugError("CompileStack#init called without calling clear before");
clear = false;
pushVariableScope(el);
defineMethodVariables(parameters, el.isInStaticContext());
this.className = BytecodeHelper.getTypeDescription(controller.getClassNode());
}
use of org.codehaus.groovy.GroovyBugError in project groovy by apache.
the class Verifier method addDefaultParameters.
protected void addDefaultParameters(DefaultArgsAction action, MethodNode method) {
Parameter[] parameters = method.getParameters();
int counter = 0;
List paramValues = new ArrayList();
int size = parameters.length;
for (int i = size - 1; i >= 0; i--) {
Parameter parameter = parameters[i];
if (parameter != null && parameter.hasInitialExpression()) {
paramValues.add(i);
paramValues.add(new CastExpression(parameter.getType(), parameter.getInitialExpression()));
counter++;
}
}
for (int j = 1; j <= counter; j++) {
Parameter[] newParams = new Parameter[parameters.length - j];
ArgumentListExpression arguments = new ArgumentListExpression();
int index = 0;
int k = 1;
for (Parameter parameter : parameters) {
if (parameter == null) {
throw new GroovyBugError("Parameter should not be null for method " + methodNode.getName());
} else {
if (k > counter - j && parameter.hasInitialExpression()) {
arguments.addExpression(new CastExpression(parameter.getType(), parameter.getInitialExpression()));
k++;
} else if (parameter.hasInitialExpression()) {
newParams[index++] = parameter;
arguments.addExpression(new CastExpression(parameter.getType(), new VariableExpression(parameter.getName())));
k++;
} else {
newParams[index++] = parameter;
arguments.addExpression(new CastExpression(parameter.getType(), new VariableExpression(parameter.getName())));
}
}
}
action.call(arguments, newParams, method);
}
for (Parameter parameter : parameters) {
// remove default expression and store it as node metadata
parameter.putNodeMetaData(Verifier.INITIAL_EXPRESSION, parameter.getInitialExpression());
parameter.setInitialExpression(null);
}
}
Aggregations