classUnary
final class Unary
implements Scalar
uses Snapshot
@visibility public.A prefix operator applied to a simple_expr: +x, -x, ~x, !x (Item_func_neg, Item_func_bit_neg, Item_func_not).
The operator binds tighter than every binary operator but looser than COLLATE, so -a COLLATE c negates the collated value (MYSQL-PRECEDENCE-001).
Rule: MYSQL-UNARY-001. Facts: unary plus has the facts of its operand (the server drops it); unary minus follows MYSQL-NUMERIC-RESULT-001; ~ is a bit operator; ! is a truth value. Each is NULL when the operand is, and takes a single value. Terminates: the operand is a strict part. Source: https://dev.mysql.com/doc/refman/8.4/en/arithmetic-functions.html#operator_unary-minus, https://dev.mysql.com/doc/refman/8.4/en/bit-functions.html#operator_bitwise-invert, https://dev.mysql.com/doc/refman/8.4/en/logical-operators.html#operator_not. Status: Implemented.
(new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t WHERE !a = 1')->toString() // => 'SELECT a FROM t WHERE ! a = 1'Properties§
public UnaryOperator $operatorpublic Scalar $operandMethods§
public function __construct(public UnaryOperator $operator, public Scalar $operand)Parameters
$operator | UnaryOperator | The operator |
$operand | Scalar | The operand |
Calls 4
- static-call Check::input() line 47
- method-call Precedence::opening() line 47
- new Precedence line 47
- class-const Precedence::PREFIX() line 47
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operand and the type of the result.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 12
- new Operands line 55
- method-call Operands::single() line 56
- method-call Derivation::scalar() line 56
- new NumericResult line 57
- class-const UnaryOperator::Plus() line 60
- new ScalarFact line 60
- class-const UnaryOperator::Minus() line 61
- method-call NumericResult::negation() line 61
- class-const UnaryOperator::Invert() line 62
- method-call NumericResult::bits() line 62
- class-const UnaryOperator::Not() line 63
- method-call Operands::truth() line 63
public function render(Output $out): voidWrites the operator and the operand.
Parameters
$out | Output |
Test cases 1
Calls 1
- method-call Output::symbol() line 72
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 5
PrimaryRuleTest::testUnitLowersTheTightNegationOfHighNotPrecedencecallsPrecedenceTest::testAdmitsAcceptsTheNonterminalsOfASlotcallsPrecedenceTest::testFitsAcceptsALeftOperandThatKeepsItsPlacecallsPrecedenceTest::testOpeningIsTheWeakestLevelOnTheLeftEdgecallsBinaryCastTest::testRenderCastsAPrefixOperandWithoutParenthesescalls