public static Expression logicalNot ( final Expression baseExpr ) { baseExpr . checkAssignableTo ( Type . BOOLEAN_TYPE ) ; checkArgument ( baseExpr . resultType ( ) . equals ( Type . BOOLEAN_TYPE ) , "not a boolean expression" ) ; return new Expression ( Type . BOOLEAN_TYPE , baseExpr . features ( ) ) { @ Override protected void doGen ( CodeBuilder mv ) { baseExpr . gen ( mv ) ; // Surprisingly, java bytecode uses a branch (instead of 'xor 1' or something) to implement // this. This is most likely useful for allowing true to be represented by any non-zero // number. Label ifTrue = mv . newLabel ( ) ; Label end = mv . newLabel ( ) ; mv . ifZCmp ( Opcodes . IFNE , ifTrue ) ; // if not 0 goto ifTrue mv . pushBoolean ( true ) ; mv . goTo ( end ) ; mv . mark ( ifTrue ) ; mv . pushBoolean ( false ) ; mv . mark ( end ) ; } } ; }
Returns an expression that evaluates to the logical negation of the given boolean valued expression .