Search in sources :

Example 1 with NotExpression

use of org.codehaus.groovy.ast.expr.NotExpression in project gradle by gradle.

the class ExpressionReplacingVisitorSupport method visitNotExpression.

@Override
public void visitNotExpression(NotExpression expr) {
    NotExpression result = new NotExpression(replaceExpr(expr.getExpression()));
    result.setType(expr.getType());
    result.setSourcePosition(expr);
    replaceVisitedExpressionWith(result);
}
Also used : NotExpression(org.codehaus.groovy.ast.expr.NotExpression)

Example 2 with NotExpression

use of org.codehaus.groovy.ast.expr.NotExpression in project hale by halestudio.

the class VertexEntityTransformation method buildVertexGraphConstructor.

/**
 * Create a constructor taking a Vertex and a Graph as an argument,
 * assigning them to the vertex and graph fields.
 *
 * @param vertexField the vertex field
 * @param graphField the graph field
 * @param superClass the vertex entity super class or <code>null</code>
 * @param typeProperty the expression specifying the name of the type
 *            property
 * @param entityName the expression specifying the entity name
 * @return a constructor taking a Vertex as an argument
 */
private ConstructorNode buildVertexGraphConstructor(FieldNode vertexField, FieldNode graphField, ClassNode superClass, Expression typeProperty, Expression entityName) {
    BlockStatement block = new BlockStatement();
    // parameter vertex
    VariableExpression vertex = new VariableExpression("vertex");
    // parameter graph
    VariableExpression graph = new VariableExpression("graph");
    if (superClass != null) {
        // super(vertex, graph)
        block.addStatement(new ExpressionStatement(new ConstructorCallExpression(ClassNode.SUPER, new ArgumentListExpression(vertex, graph))));
    } else {
        // > this.v = vertex
        block.addStatement(AbstractASTTransformUtil.assignStatement(new FieldExpression(vertexField), new VariableExpression("vertex")));
        // > this.g = graph
        block.addStatement(AbstractASTTransformUtil.assignStatement(new FieldExpression(graphField), new VariableExpression("graph")));
    }
    // vertex.setProperty(typeProperty, entityName)
    Statement notOrientStatement = new ExpressionStatement(new MethodCallExpression(vertex, "setProperty", new ArgumentListExpression(new Expression[] { typeProperty, entityName })));
    // > if (!(graph instanceof OrientGraph))
    // > this.v.setProperty(typeProperty, entityName)
    block.addStatement(new IfStatement(new NotExpression(AbstractASTTransformUtil.isInstanceOf(graph, ORIENT_GRAPH_CLASS)), notOrientStatement, new EmptyStatement()));
    return new ConstructorNode(Modifier.PUBLIC, new Parameter[] { new Parameter(VERTEX_CLASS, "vertex"), new Parameter(GRAPH_CLASS, "graph") }, new ClassNode[0], block);
}
Also used : ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) Statement(org.codehaus.groovy.ast.stmt.Statement) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) EmptyStatement(org.codehaus.groovy.ast.stmt.EmptyStatement) IfStatement(org.codehaus.groovy.ast.stmt.IfStatement) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) EmptyStatement(org.codehaus.groovy.ast.stmt.EmptyStatement) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) NotExpression(org.codehaus.groovy.ast.expr.NotExpression) FieldExpression(org.codehaus.groovy.ast.expr.FieldExpression) IfStatement(org.codehaus.groovy.ast.stmt.IfStatement) StaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) ConstructorNode(org.codehaus.groovy.ast.ConstructorNode) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) Parameter(org.codehaus.groovy.ast.Parameter)

Example 3 with NotExpression

use of org.codehaus.groovy.ast.expr.NotExpression in project groovy by apache.

the class UnaryExpressionHelper method writeNotExpression.

public void writeNotExpression(NotExpression expression) {
    Expression subExpression = expression.getExpression();
    int mark = controller.getOperandStack().getStackLength();
    subExpression.visit(controller.getAcg());
    controller.getOperandStack().castToBool(mark, true);
    BytecodeHelper.negateBoolean(controller.getMethodVisitor());
    controller.getAssertionWriter().record(expression);
}
Also used : UnaryMinusExpression(org.codehaus.groovy.ast.expr.UnaryMinusExpression) BitwiseNegationExpression(org.codehaus.groovy.ast.expr.BitwiseNegationExpression) UnaryPlusExpression(org.codehaus.groovy.ast.expr.UnaryPlusExpression) Expression(org.codehaus.groovy.ast.expr.Expression) NotExpression(org.codehaus.groovy.ast.expr.NotExpression)

Example 4 with NotExpression

use of org.codehaus.groovy.ast.expr.NotExpression in project groovy by apache.

the class StaticTypeCheckingVisitor method findInstanceOfNotReturnExpression.

/**
 * Check IfStatement matched pattern :
 * Object var1;
 * if (!(var1 instanceOf Runnable)) {
 * return
 * }
 * // Here var1 instance of Runnable
 * <p>
 * Return expression , which contains instanceOf (without not)
 * Return null, if not found
 */
protected BinaryExpression findInstanceOfNotReturnExpression(final IfStatement ifElse) {
    Statement elseBlock = ifElse.getElseBlock();
    if (!(elseBlock instanceof EmptyStatement)) {
        return null;
    }
    Expression conditionExpression = ifElse.getBooleanExpression().getExpression();
    if (!(conditionExpression instanceof NotExpression)) {
        return null;
    }
    NotExpression notExpression = (NotExpression) conditionExpression;
    Expression expression = notExpression.getExpression();
    if (!(expression instanceof BinaryExpression)) {
        return null;
    }
    BinaryExpression instanceOfExpression = (BinaryExpression) expression;
    int op = instanceOfExpression.getOperation().getType();
    if (op != KEYWORD_INSTANCEOF) {
        return null;
    }
    if (notReturningBlock(ifElse.getIfBlock())) {
        return null;
    }
    return instanceOfExpression;
}
Also used : BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) UnaryMinusExpression(org.codehaus.groovy.ast.expr.UnaryMinusExpression) ClosureListExpression(org.codehaus.groovy.ast.expr.ClosureListExpression) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) MethodReferenceExpression(org.codehaus.groovy.ast.expr.MethodReferenceExpression) TernaryExpression(org.codehaus.groovy.ast.expr.TernaryExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) PrefixExpression(org.codehaus.groovy.ast.expr.PrefixExpression) PostfixExpression(org.codehaus.groovy.ast.expr.PostfixExpression) Expression(org.codehaus.groovy.ast.expr.Expression) UnaryPlusExpression(org.codehaus.groovy.ast.expr.UnaryPlusExpression) AnnotationConstantExpression(org.codehaus.groovy.ast.expr.AnnotationConstantExpression) BitwiseNegationExpression(org.codehaus.groovy.ast.expr.BitwiseNegationExpression) MapExpression(org.codehaus.groovy.ast.expr.MapExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) StaticTypeCheckingSupport.evaluateExpression(org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.evaluateExpression) NotExpression(org.codehaus.groovy.ast.expr.NotExpression) FieldExpression(org.codehaus.groovy.ast.expr.FieldExpression) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) MethodPointerExpression(org.codehaus.groovy.ast.expr.MethodPointerExpression) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) CastExpression(org.codehaus.groovy.ast.expr.CastExpression) StaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression) LambdaExpression(org.codehaus.groovy.ast.expr.LambdaExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) RangeExpression(org.codehaus.groovy.ast.expr.RangeExpression) SpreadExpression(org.codehaus.groovy.ast.expr.SpreadExpression) ArrayExpression(org.codehaus.groovy.ast.expr.ArrayExpression) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) ElvisOperatorExpression(org.codehaus.groovy.ast.expr.ElvisOperatorExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) DeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) AttributeExpression(org.codehaus.groovy.ast.expr.AttributeExpression) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) ForStatement(org.codehaus.groovy.ast.stmt.ForStatement) IfStatement(org.codehaus.groovy.ast.stmt.IfStatement) TryCatchStatement(org.codehaus.groovy.ast.stmt.TryCatchStatement) CaseStatement(org.codehaus.groovy.ast.stmt.CaseStatement) WhileStatement(org.codehaus.groovy.ast.stmt.WhileStatement) EmptyStatement(org.codehaus.groovy.ast.stmt.EmptyStatement) CatchStatement(org.codehaus.groovy.ast.stmt.CatchStatement) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) Statement(org.codehaus.groovy.ast.stmt.Statement) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement) EmptyStatement(org.codehaus.groovy.ast.stmt.EmptyStatement) NotExpression(org.codehaus.groovy.ast.expr.NotExpression) ClosureSignatureHint(groovy.transform.stc.ClosureSignatureHint)

Example 5 with NotExpression

use of org.codehaus.groovy.ast.expr.NotExpression in project groovy by apache.

the class StaticTypesUnaryExpressionHelper method writeNotExpression.

@Override
public void writeNotExpression(final NotExpression expression) {
    Expression subExpression = expression.getExpression();
    TypeChooser typeChooser = controller.getTypeChooser();
    if (isPrimitiveBoolean(typeChooser.resolveType(subExpression, controller.getClassNode()))) {
        subExpression.visit(controller.getAcg());
        controller.getOperandStack().doGroovyCast(boolean_TYPE);
        bytecodeX(mv -> {
            Label ne = new Label();
            mv.visitJumpInsn(IFNE, ne);
            mv.visitInsn(ICONST_1);
            Label out = new Label();
            mv.visitJumpInsn(GOTO, out);
            mv.visitLabel(ne);
            mv.visitInsn(ICONST_0);
            mv.visitLabel(out);
        }).visit(controller.getAcg());
        controller.getOperandStack().remove(1);
    } else {
        super.writeNotExpression(expression);
    }
}
Also used : ClassHelper.isPrimitiveDouble(org.codehaus.groovy.ast.ClassHelper.isPrimitiveDouble) WriterController(org.codehaus.groovy.classgen.asm.WriterController) Label(org.objectweb.asm.Label) I2B(org.objectweb.asm.Opcodes.I2B) IFNE(org.objectweb.asm.Opcodes.IFNE) I2C(org.objectweb.asm.Opcodes.I2C) IXOR(org.objectweb.asm.Opcodes.IXOR) ClassHelper.isPrimitiveShort(org.codehaus.groovy.ast.ClassHelper.isPrimitiveShort) ClassHelper.boolean_TYPE(org.codehaus.groovy.ast.ClassHelper.boolean_TYPE) ClassHelper.isPrimitiveFloat(org.codehaus.groovy.ast.ClassHelper.isPrimitiveFloat) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) Expression(org.codehaus.groovy.ast.expr.Expression) INEG(org.objectweb.asm.Opcodes.INEG) UnaryMinusExpression(org.codehaus.groovy.ast.expr.UnaryMinusExpression) ICONST_1(org.objectweb.asm.Opcodes.ICONST_1) UnaryPlusExpression(org.codehaus.groovy.ast.expr.UnaryPlusExpression) ICONST_0(org.objectweb.asm.Opcodes.ICONST_0) ClassNode(org.codehaus.groovy.ast.ClassNode) ClassHelper.isPrimitiveInt(org.codehaus.groovy.ast.ClassHelper.isPrimitiveInt) ClassHelper.isPrimitiveLong(org.codehaus.groovy.ast.ClassHelper.isPrimitiveLong) ClassHelper.isPrimitiveBoolean(org.codehaus.groovy.ast.ClassHelper.isPrimitiveBoolean) ICONST_M1(org.objectweb.asm.Opcodes.ICONST_M1) NotExpression(org.codehaus.groovy.ast.expr.NotExpression) TypeChooser(org.codehaus.groovy.classgen.asm.TypeChooser) UnaryExpressionHelper(org.codehaus.groovy.classgen.asm.UnaryExpressionHelper) FNEG(org.objectweb.asm.Opcodes.FNEG) BitwiseNegationExpression(org.codehaus.groovy.ast.expr.BitwiseNegationExpression) GeneralUtils.bytecodeX(org.codehaus.groovy.ast.tools.GeneralUtils.bytecodeX) LXOR(org.objectweb.asm.Opcodes.LXOR) ClassHelper.isPrimitiveChar(org.codehaus.groovy.ast.ClassHelper.isPrimitiveChar) ClassHelper.isPrimitiveByte(org.codehaus.groovy.ast.ClassHelper.isPrimitiveByte) LNEG(org.objectweb.asm.Opcodes.LNEG) GOTO(org.objectweb.asm.Opcodes.GOTO) I2S(org.objectweb.asm.Opcodes.I2S) DNEG(org.objectweb.asm.Opcodes.DNEG) TypeChooser(org.codehaus.groovy.classgen.asm.TypeChooser) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) Expression(org.codehaus.groovy.ast.expr.Expression) UnaryMinusExpression(org.codehaus.groovy.ast.expr.UnaryMinusExpression) UnaryPlusExpression(org.codehaus.groovy.ast.expr.UnaryPlusExpression) NotExpression(org.codehaus.groovy.ast.expr.NotExpression) BitwiseNegationExpression(org.codehaus.groovy.ast.expr.BitwiseNegationExpression) Label(org.objectweb.asm.Label)

Aggregations

NotExpression (org.codehaus.groovy.ast.expr.NotExpression)5 BitwiseNegationExpression (org.codehaus.groovy.ast.expr.BitwiseNegationExpression)3 Expression (org.codehaus.groovy.ast.expr.Expression)3 UnaryMinusExpression (org.codehaus.groovy.ast.expr.UnaryMinusExpression)3 UnaryPlusExpression (org.codehaus.groovy.ast.expr.UnaryPlusExpression)3 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)2 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)2 EmptyExpression (org.codehaus.groovy.ast.expr.EmptyExpression)2 FieldExpression (org.codehaus.groovy.ast.expr.FieldExpression)2 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)2 StaticMethodCallExpression (org.codehaus.groovy.ast.expr.StaticMethodCallExpression)2 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)2 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)2 EmptyStatement (org.codehaus.groovy.ast.stmt.EmptyStatement)2 ExpressionStatement (org.codehaus.groovy.ast.stmt.ExpressionStatement)2 IfStatement (org.codehaus.groovy.ast.stmt.IfStatement)2 ReturnStatement (org.codehaus.groovy.ast.stmt.ReturnStatement)2 Statement (org.codehaus.groovy.ast.stmt.Statement)2 ClosureSignatureHint (groovy.transform.stc.ClosureSignatureHint)1 ClassHelper.boolean_TYPE (org.codehaus.groovy.ast.ClassHelper.boolean_TYPE)1