use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy-core by groovy.
the class BinaryExpressionHelper method loadWithSubscript.
private VariableSlotLoader loadWithSubscript(Expression expression) {
final OperandStack operandStack = controller.getOperandStack();
// subscription
if (expression instanceof BinaryExpression) {
BinaryExpression be = (BinaryExpression) expression;
if (be.getOperation().getType() == Types.LEFT_SQUARE_BRACKET) {
// right expression is the subscript expression
// we store the result of the subscription on the stack
Expression subscript = be.getRightExpression();
subscript.visit(controller.getAcg());
ClassNode subscriptType = operandStack.getTopOperand();
int id = controller.getCompileStack().defineTemporaryVariable("$subscript", subscriptType, true);
VariableSlotLoader subscriptExpression = new VariableSlotLoader(subscriptType, id, operandStack);
// do modified visit
BinaryExpression newBe = new BinaryExpression(be.getLeftExpression(), be.getOperation(), subscriptExpression);
newBe.copyNodeMetaData(be);
newBe.setSourcePosition(be);
newBe.visit(controller.getAcg());
return subscriptExpression;
}
}
// normal loading of expression
expression.visit(controller.getAcg());
return null;
}
use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy-core by groovy.
the class BinaryExpressionMultiTypeDispatcher method doPrimitiveCompare.
protected boolean doPrimitiveCompare(ClassNode leftType, ClassNode rightType, BinaryExpression binExp) {
Expression leftExp = binExp.getLeftExpression();
Expression rightExp = binExp.getRightExpression();
int operation = binExp.getOperation().getType();
int operationType = getOperandConversionType(leftType, rightType);
BinaryExpressionWriter bew = binExpWriter[operationType];
if (!bew.write(operation, true))
return false;
AsmClassGenerator acg = getController().getAcg();
OperandStack os = getController().getOperandStack();
leftExp.visit(acg);
os.doGroovyCast(bew.getNormalOpResultType());
rightExp.visit(acg);
os.doGroovyCast(bew.getNormalOpResultType());
bew.write(operation, false);
return true;
}
use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy-core by groovy.
the class BinaryExpressionMultiTypeDispatcher method doAssignmentToLocalVariable.
private boolean doAssignmentToLocalVariable(String method, BinaryExpression binExp) {
Expression left = binExp.getLeftExpression();
if (left instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) left;
Variable v = ve.getAccessedVariable();
if (v instanceof DynamicVariable)
return false;
if (v instanceof PropertyExpression)
return false;
/* field and declaration we don't return false */
} else {
return false;
}
evaluateBinaryExpression(method, binExp);
getController().getOperandStack().dup();
getController().getCompileStack().pushLHS(true);
binExp.getLeftExpression().visit(getController().getAcg());
getController().getCompileStack().popLHS();
return true;
}
use of org.codehaus.groovy.ast.expr.BinaryExpression in project grails-core by grails.
the class AbstractGrailsArtefactTransformer method addApiLookupFieldAndSetter.
protected void addApiLookupFieldAndSetter(ClassNode classNode, ClassNode implementationNode, String apiProperty, Expression initialValueExpression) {
FieldNode fieldNode = classNode.getField(apiProperty);
if (fieldNode == null || !fieldNode.getDeclaringClass().equals(classNode)) {
fieldNode = new FieldNode(apiProperty, Modifier.PRIVATE | Modifier.STATIC, implementationNode, classNode, initialValueExpression);
classNode.addField(fieldNode);
String setterName = "set" + MetaClassHelper.capitalize(apiProperty);
Parameter setterParameter = new Parameter(implementationNode, apiProperty);
BlockStatement setterBody = new BlockStatement();
setterBody.addStatement(new ExpressionStatement(new BinaryExpression(new AttributeExpression(new ClassExpression(classNode), new ConstantExpression(apiProperty)), Token.newSymbol(Types.EQUAL, 0, 0), new VariableExpression(setterParameter))));
GrailsASTUtils.addCompileStaticAnnotation(classNode.addMethod(setterName, Modifier.PUBLIC | Modifier.STATIC, ClassHelper.VOID_TYPE, new Parameter[] { setterParameter }, null, setterBody));
}
}
use of org.codehaus.groovy.ast.expr.BinaryExpression in project grails-core by grails.
the class ASTValidationErrorsHelper method addSetErrorsMethod.
protected void addSetErrorsMethod(final ClassNode paramTypeClassNode) {
final String errorsArgumentName = "$errorsArg";
MethodNode setErrorsMethod = paramTypeClassNode.getMethod(SET_ERRORS_METHOD_NAME, new Parameter[] { new Parameter(ERRORS_CLASS_NODE, errorsArgumentName) });
if (setErrorsMethod == null) {
final Expression assignErrorsExpression = new BinaryExpression(ERRORS_EXPRESSION, EQUALS_SYMBOL, new VariableExpression(errorsArgumentName));
setErrorsMethod = new MethodNode(SET_ERRORS_METHOD_NAME, Modifier.PUBLIC, ClassHelper.VOID_TYPE, new Parameter[] { new Parameter(ERRORS_CLASS_NODE, errorsArgumentName) }, GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, new ExpressionStatement(assignErrorsExpression));
paramTypeClassNode.addMethod(setErrorsMethod);
}
}
Aggregations