3.2.4.4 Unary Operations

C++ Function: gccjit::rvalue gccjit::context::new_unary_op (enum gcc_jit_unary_op, gccjit::type result_type, gccjit::rvalue rvalue, gccjit::location loc)

Build a unary operation out of an input rvalue.

Parameter loc is optional.

This is a thin wrapper around the C API’s gcc_jit_context_new_unary_op() and the available unary operations are documented there.

There are shorter ways to spell the various specific kinds of unary operation:

C++ Function: gccjit::rvalue gccjit::context::new_minus (gccjit::type result_type, gccjit::rvalue a, gccjit::location loc)

Negate an arithmetic value; for example:

gccjit::rvalue negpi = ctxt.new_minus (t_double, pi);

builds the equivalent of this C expression:

-pi
C++ Function: gccjit::rvalue new_bitwise_negate (gccjit::type result_type, gccjit::rvalue a, gccjit::location loc)

Bitwise negation of an integer value (one’s complement); for example:

gccjit::rvalue mask = ctxt.new_bitwise_negate (t_int, a);

builds the equivalent of this C expression:

~a
C++ Function: gccjit::rvalue new_logical_negate (gccjit::type result_type, gccjit::rvalue a, gccjit::location loc)

Logical negation of an arithmetic or pointer value; for example:

gccjit::rvalue guard = ctxt.new_logical_negate (t_bool, cond);

builds the equivalent of this C expression:

!cond

The most concise way to spell them is with overloaded operators:

C++ Function: gccjit::rvalue operator- (gccjit::rvalue a)
gccjit::rvalue negpi = -pi;
C++ Function: gccjit::rvalue operator~ (gccjit::rvalue a)
gccjit::rvalue mask = ~a;
C++ Function: gccjit::rvalue operator! (gccjit::rvalue a)
gccjit::rvalue guard = !cond;