Search in sources :

Example 1 with Expression

use of org.neo4j.codegen.Expression in project neo4j by neo4j.

the class MethodSourceWriter method newArray.

@Override
public void newArray(TypeReference type, Expression... constants) {
    append("new ").append(type.fullName()).append("[]{");
    String sep = "";
    for (Expression constant : constants) {
        append(sep);
        constant.accept(this);
        sep = ", ";
    }
    append("}");
}
Also used : Expression(org.neo4j.codegen.Expression)

Example 2 with Expression

use of org.neo4j.codegen.Expression in project neo4j by neo4j.

the class MethodSourceWriter method boolOp.

private void boolOp(Expression[] expressions, String op) {
    String sep = "";
    for (Expression expression : expressions) {
        append(sep);
        expression.accept(this);
        sep = op;
    }
}
Also used : Expression(org.neo4j.codegen.Expression)

Example 3 with Expression

use of org.neo4j.codegen.Expression in project neo4j by neo4j.

the class ByteCodeExpressionVisitor method and.

@Override
public void and(Expression... expressions) {
    assert expressions.length == 2 : "only supports and(lhs, rhs)";
    Expression lhs = expressions[0], rhs = expressions[1];
    /*
         * something like:
         *
         * LOAD lhs
         * IF FALSE GOTO 0
         * LOAD rhs
         * IF FALSE GOTO 0
         * LOAD TRUE
         * GOTO 1
         * 0:
         *  LOAD FALSE
         * 1:
         *  ...continue doing stuff
         */
    lhs.accept(this);
    Label l0 = new Label();
    methodVisitor.visitJumpInsn(IFEQ, l0);
    rhs.accept(this);
    methodVisitor.visitJumpInsn(IFEQ, l0);
    methodVisitor.visitInsn(ICONST_1);
    Label l1 = new Label();
    methodVisitor.visitJumpInsn(GOTO, l1);
    methodVisitor.visitLabel(l0);
    methodVisitor.visitInsn(ICONST_0);
    methodVisitor.visitLabel(l1);
}
Also used : Expression(org.neo4j.codegen.Expression) Label(org.objectweb.asm.Label)

Example 4 with Expression

use of org.neo4j.codegen.Expression in project neo4j by neo4j.

the class ByteCodeExpressionVisitor method or.

@Override
public void or(Expression... expressions) {
    assert expressions.length == 2 : "only supports or(lhs, rhs)";
    Expression lhs = expressions[0], rhs = expressions[1];
    /*
         * something like:
         *
         * LOAD lhs
         * IF TRUE GOTO 0
         * LOAD rhs
         * IF FALSE GOTO 1
         *
         * 0:
         *  LOAD TRUE
         *  GOTO 2
         * 1:
         *  LOAD FALSE
         * 2:
         *  ...continue doing stuff
         */
    lhs.accept(this);
    Label l0 = new Label();
    methodVisitor.visitJumpInsn(IFNE, l0);
    rhs.accept(this);
    Label l1 = new Label();
    methodVisitor.visitJumpInsn(IFEQ, l1);
    methodVisitor.visitLabel(l0);
    methodVisitor.visitInsn(ICONST_1);
    Label l2 = new Label();
    methodVisitor.visitJumpInsn(GOTO, l2);
    methodVisitor.visitLabel(l1);
    methodVisitor.visitInsn(ICONST_0);
    methodVisitor.visitLabel(l2);
}
Also used : Expression(org.neo4j.codegen.Expression) Label(org.objectweb.asm.Label)

Example 5 with Expression

use of org.neo4j.codegen.Expression in project neo4j by neo4j.

the class ClassByteCodeWriter method done.

@Override
public void done() {
    if (!staticFields.isEmpty()) {
        MethodVisitor methodVisitor = classVisitor.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
        ByteCodeExpressionVisitor expressionVisitor = new ByteCodeExpressionVisitor(methodVisitor);
        methodVisitor.visitCode();
        for (Map.Entry<FieldReference, Expression> entry : staticFields.entrySet()) {
            FieldReference field = entry.getKey();
            Expression value = entry.getValue();
            value.accept(expressionVisitor);
            methodVisitor.visitFieldInsn(PUTSTATIC, byteCodeName(field.owner()), field.name(), typeName(field.type()));
        }
        methodVisitor.visitInsn(RETURN);
        methodVisitor.visitMaxs(0, 0);
        methodVisitor.visitEnd();
    }
    classVisitor.visitEnd();
}
Also used : FieldReference(org.neo4j.codegen.FieldReference) Expression(org.neo4j.codegen.Expression) HashMap(java.util.HashMap) Map(java.util.Map) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

Expression (org.neo4j.codegen.Expression)6 Label (org.objectweb.asm.Label)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FieldReference (org.neo4j.codegen.FieldReference)1 MethodVisitor (org.objectweb.asm.MethodVisitor)1