use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.
the class MarkupBuilderCodeTransformer method transform.
@Override
public Expression transform(final Expression exp) {
if (exp instanceof BinaryExpression) {
return transformBinaryExpression((BinaryExpression) exp);
}
if (exp instanceof MethodCallExpression) {
return transformMethodCall((MethodCallExpression) exp);
}
if (exp instanceof ClosureExpression) {
ClosureExpression cl = (ClosureExpression) exp;
cl.getCode().visit(this);
return cl;
}
if (exp instanceof VariableExpression) {
VariableExpression var = (VariableExpression) exp;
if (var.getAccessedVariable() instanceof DynamicVariable) {
MethodCallExpression callGetModel = new MethodCallExpression(new VariableExpression("this"), "getModel", ArgumentListExpression.EMPTY_ARGUMENTS);
callGetModel.setImplicitThis(true);
callGetModel.setSourcePosition(exp);
String varName = var.getName();
if ("model".equals(varName) || "unescaped".equals(varName)) {
return callGetModel;
}
MethodCallExpression mce = new MethodCallExpression(callGetModel, "get", new ArgumentListExpression(new ConstantExpression(varName)));
mce.setSourcePosition(exp);
mce.setImplicitThis(false);
MethodCallExpression yield = new MethodCallExpression(new VariableExpression("this"), "tryEscape", new ArgumentListExpression(mce));
yield.setImplicitThis(true);
yield.setSourcePosition(exp);
yield.putNodeMetaData(TARGET_VARIABLE, varName);
return autoEscape ? yield : mce;
}
}
return super.transform(exp);
}
use of org.codehaus.groovy.ast.expr.BinaryExpression in project gcontracts by andresteingress.
the class Assertion method and.
public void and(T other) {
Validate.notNull(other);
BooleanExpression newBooleanExpression = new BooleanExpression(new BinaryExpression(booleanExpression(), Token.newSymbol(Types.LOGICAL_AND, -1, -1), other.booleanExpression()));
newBooleanExpression.setSourcePosition(booleanExpression());
renew(newBooleanExpression);
}
use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.
the class Verifier method moveOptimizedConstantsInitialization.
private static boolean moveOptimizedConstantsInitialization(final ClassNode node) {
if (node.isInterface() && !Traits.isTrait(node))
return false;
final int mods = Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_PUBLIC;
String name = SWAP_INIT;
BlockStatement methodCode = new BlockStatement();
methodCode.addStatement(new SwapInitStatement());
boolean swapInitRequired = false;
for (FieldNode fn : node.getFields()) {
if (!fn.isStatic() || !fn.isSynthetic() || !fn.getName().startsWith("$const$"))
continue;
if (fn.getInitialExpression() == null)
continue;
final FieldExpression fe = new FieldExpression(fn);
if (fn.getType().equals(ClassHelper.REFERENCE_TYPE))
fe.setUseReferenceDirectly(true);
ConstantExpression init = (ConstantExpression) fn.getInitialExpression();
init = new ConstantExpression(init.getValue(), true);
ExpressionStatement statement = new ExpressionStatement(new BinaryExpression(fe, Token.newSymbol(Types.EQUAL, fn.getLineNumber(), fn.getColumnNumber()), init));
fn.setInitialValueExpression(null);
methodCode.addStatement(statement);
swapInitRequired = true;
}
if (swapInitRequired) {
node.addSyntheticMethod(name, mods, ClassHelper.VOID_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, methodCode);
}
return swapInitRequired;
}
use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.
the class AssertionWriter method addVariableNames.
private void addVariableNames(Expression expression, List<String> list) {
if (expression instanceof BooleanExpression) {
BooleanExpression boolExp = (BooleanExpression) expression;
addVariableNames(boolExp.getExpression(), list);
} else if (expression instanceof BinaryExpression) {
BinaryExpression binExp = (BinaryExpression) expression;
addVariableNames(binExp.getLeftExpression(), list);
addVariableNames(binExp.getRightExpression(), list);
} else if (expression instanceof VariableExpression) {
VariableExpression varExp = (VariableExpression) expression;
list.add(varExp.getName());
}
}
use of org.codehaus.groovy.ast.expr.BinaryExpression in project groovy by apache.
the class BinaryExpressionHelper method evaluateInstanceof.
private void evaluateInstanceof(BinaryExpression expression) {
OperandStack operandStack = controller.getOperandStack();
expression.getLeftExpression().visit(controller.getAcg());
operandStack.box();
Expression rightExp = expression.getRightExpression();
ClassNode classType;
if (rightExp instanceof ClassExpression) {
ClassExpression classExp = (ClassExpression) rightExp;
classType = classExp.getType();
} else {
throw new RuntimeException("Right hand side of the instanceof keyword must be a class name, not: " + rightExp);
}
String classInternalName = BytecodeHelper.getClassInternalName(classType);
controller.getMethodVisitor().visitTypeInsn(INSTANCEOF, classInternalName);
operandStack.replace(ClassHelper.boolean_TYPE);
}
Aggregations