Skip to content

Commit e27e3ae

Browse files
authored
Merge pull request github#18610 from jbj/bigint-language-reference
QL reference: more BigInt updates
2 parents d6f9eb2 + 455eb5b commit e27e3ae

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

docs/codeql/ql-language-reference/expressions.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ the **aggregation variables**.
194194

195195
Ordered aggregates (namely ``min``, ``max``, ``rank``, ``concat``, and ``strictconcat``) are
196196
ordered by their ``<expression>`` values by default. The ordering is either numeric (for
197-
integers and floating point numbers) or lexicographic (for strings). Lexicographic ordering is
197+
numeric types) or lexicographic (for strings). Lexicographic ordering is
198198
based on the `Unicode value <https://en.wikipedia.org/wiki/List_of_Unicode_characters#Basic_Latin>`_
199199
of each character.
200200

@@ -684,7 +684,7 @@ Unary operations
684684
****************
685685

686686
A unary operation is a minus sign (``-``) or a plus sign (``+``) followed by an expression of type
687-
``int`` or ``float``. For example:
687+
``int``, ``float`` or ``QlBuiltins::BigInt``. For example:
688688

689689
.. code-block:: ql
690690
@@ -731,10 +731,11 @@ You can use the following binary operators in QL:
731731
+------------------------+--------+
732732

733733
If both expressions are numbers, these operators act as standard arithmetic operators. For
734-
example, ``10.6 - 3.2`` has value ``7.4``, ``123.456 * 0`` has value ``0``, and ``9 % 4`` has
734+
example, ``10.6 - 3.2`` has value ``7.4``, ``123.456 * 0`` has value ``0.0``, and ``9 % 4`` has
735735
value ``1`` (the remainder after dividing ``9`` by ``4``).
736-
If both operands are integers, then the result is an integer. Otherwise the result is a
737-
floating-point number.
736+
If both operands are subtypes of ``int`` or ``QlBuiltins::BigInt``, then the result type is
737+
``int`` or ``QlBuiltins::BigInt``, respectively. Otherwise, if both operands are subtypes of
738+
``float``, then the result type is ``float``.
738739

739740
You can also use ``+`` as a string concatenation operator. In this case, at least one of the
740741
expressions must be a string—the other expression is implicitly converted to a string using the

docs/codeql/ql-language-reference/name-resolution.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ were defined in the :ref:`QL tutorials <ql-tutorials>`:
305305
The module namespace of ``Villagers`` has entries for:
306306
- The module ``S``.
307307
- Any modules exported by ``tutorial``.
308+
- The built-in top-level module ``QlBuiltins``.
308309

309310
The module namespace of ``S`` also has entries for the module ``S`` itself, and for any
310311
modules exported by ``tutorial``.
@@ -314,7 +315,7 @@ modules exported by ``tutorial``.
314315
The type namespace of ``Villagers`` has entries for:
315316
- The class ``Child``.
316317
- The types exported by the module ``tutorial``.
317-
- The built-in types, namely ``int``, ``float``, ``string``, ``date``, and ``boolean``.
318+
- The built-in top-level types, namely ``int``, ``float``, ``string``, ``date``, and ``boolean``.
318319

319320
The type namespace of ``S`` has entries for:
320321
- All the above types.

docs/codeql/ql-language-reference/ql-language-specification.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ An integer literal is a possibly negated sequence of decimal digits (``0`` throu
718718
Float literals (float)
719719
~~~~~~~~~~~~~~~~~~~~~~
720720

721-
A floating-point literals is a possibly negated two non-negative integers literals separated by a dot (``.``, U+002E). Here are some examples of float literals:
721+
A floating-point literal is a possibly negated pair of non-negative integer literals separated by a dot (``.``, U+002E). Here are some examples of float literals:
722722

723723
::
724724

@@ -1243,7 +1243,7 @@ A unary operation is the application of ``+`` or ``-`` to another expression:
12431243

12441244
The ``+`` or ``-`` in the operation is called the *operator*, and the expression is called the *operand*. The typing environment of the operand is the same as for the unary operation.
12451245

1246-
For a valid unary operation, the operand must be of type ``int`` or ``float``. The operation has the same type as its operand.
1246+
For a valid unary operation, the operand must be of type ``int``, ``float`` or ``QlBuiltins::BigInt``. The operation has the same type as its operand.
12471247

12481248
If the operator is ``+``, then the values of the expression are the same as the values of the operand. If the operator is ``-``, then the values of the expression are the arithmetic negations of the values of the operand.
12491249

@@ -1260,9 +1260,9 @@ A binary operation is written as a *left operand* followed by a *binary operator
12601260
| expr "/" expr
12611261
| expr "%" expr
12621262

1263-
The typing environment for the two environments is the same as for the operation. If the operator is ``+``, then either both operands must be subtypes of ``int`` or ``float``, or at least one operand must be a subtype of ``string``. If the operator is anything else, then each operand must be a subtype of ``int`` or ``float``.
1263+
The typing environment for the two environments is the same as for the operation. If the operator is ``+``, then either both operands must be subtypes of one of ``int``, ``float`` or ``QlBuiltins::BigInt``, or at least one operand must be a subtype of ``string``. If the operator is anything else, then both operands must be subtypes of one of ``int``, ``float`` or ``QlBuiltins::BigInt``.
12641264

1265-
The type of the operation is ``string`` if either operand is a subtype of ``string``. Otherwise, the type of the operation is ``int`` if both operands are subtypes of ``int``. Otherwise, the type of the operation is ``float``.
1265+
The type of the operation is ``string`` if either operand is a subtype of ``string``. Otherwise, the type of the operation is ``int`` or ``QlBuiltins::BigInt`` if both operands are subtypes of ``int`` or ``QlBuiltins::BigInt``, respectively. Otherwise, the type of the operation is ``float``.
12661266

12671267
If the result is of type ``string``, then the *left values* of the operation are the values of a "call with results" expression with the left operand as the receiver, ``toString`` as the predicate name, and no arguments (see "`Calls with results <#calls-with-results>`__"). Otherwise the left values are the values of the left operand. Likewise, the *right values* are either the values from calling ``toString`` on the right operand, or the values of the right operand as it is.
12681268

@@ -1272,6 +1272,8 @@ The binary operation has one value for each combination of a left value and a ri
12721272

12731273
- Otherwise, if both operand types are subtypes of ``int``, then the value of the operation is the result of applying the two's-complement 32-bit integer operation corresponding to the QL binary operator.
12741274

1275+
- Otherwise, if both operand types are subtypes of ``QlBuiltins::BigInt``, then the value of the operation is the result of applying the arbitrary-range integer operation corresponding to the QL binary operator.
1276+
12751277
- Otherwise, both operand types must be subtypes of ``float``. If either operand is of type ``int`` then they are converted to a float. The value of the operation is then the result of applying the IEEE 754 floating-point operator that corresponds to the QL binary operator: addition for ``+``, subtraction for ``-``, multiplication for ``*``, division for ``/``, or remainder for ``%``.
12761278

12771279
Variables
@@ -1443,10 +1445,10 @@ The number and types of the aggregation expressions are restricted as follows:
14431445
- A ``max``, ``min``, ``rank`` or ``unique`` aggregation must have a single expression.
14441446
- The type of the expression in a ``max``, ``min`` or ``rank`` aggregation without an ordering directive expression must be an orderable type.
14451447
- A ``count`` or ``strictcount`` aggregation must not have an expression.
1446-
- A ``sum``, ``strictsum`` or ``avg`` aggregation must have a single aggregation expression, which must have a type which is a subtype of ``float``.
1448+
- A ``sum``, ``strictsum`` or ``avg`` aggregation must have a single aggregation expression, which must have a type which is a subtype of ``float`` or ``QlBuiltins::BigInt``.
14471449
- A ``concat`` or ``strictconcat`` aggregation must have two expressions. Both expressions must have types which are subtypes of ``string``.
14481450

1449-
The type of a ``count``, ``strictcount`` aggregation is ``int``. The type of an ``avg`` aggregation is ``float``. The type of a ``concat`` or ``strictconcat`` aggregation is ``string``. The type of a ``sum`` or ``strictsum`` aggregation is ``int`` if the aggregation expression is a subtype of ``int``, otherwise it is ``float``. The type of a ``rank``, ``min`` or ``max`` aggregation is the type of the single expression.
1451+
The type of a ``count``, ``strictcount`` aggregation is ``int``. The type of an ``avg`` aggregation is ``float``. The type of a ``concat`` or ``strictconcat`` aggregation is ``string``. The type of a ``sum`` or ``strictsum`` aggregation is ``int`` if the aggregation expression is a subtype of ``int``; otherwise it is ``QlBuiltins::BigInt`` if the aggregation expression is a subtype of ``QlBuiltins::BigInt``; otherwise it is ``float``. The type of a ``rank``, ``min`` or ``max`` aggregation is the type of the single expression.
14501452

14511453
An ordering directive may only be specified for a ``max``, ``min``, ``rank``, ``concat`` or ``strictconcat`` aggregation. The type of the expression in an ordering directive must be an orderable type.
14521454

@@ -1462,7 +1464,7 @@ If the aggregation id is ``max``, ``min`` or ``rank`` and there was no ordering
14621464

14631465
The values of the aggregation expression are given by applying the aggregation function to each set of tuples obtained by picking exactly one aggregation tuple for each range tuple.
14641466

1465-
- If the aggregation id is ``avg``, and the set is non-empty, then the resulting value is the average of the value for the aggregation variable in each tuple in the set, weighted by the number of tuples in the set, after converting the value to a floating-point number.
1467+
- If the aggregation id is ``avg``, and the set is non-empty, then the resulting value is the average of the value for the aggregation variable in each tuple in the set, weighted by the number of tuples in the set, after converting the value to its appropriate base type of ``float`` or ``QlBuiltins::BigInt``, then converting the final result to ``float``.
14661468

14671469
- If the aggregation id is ``count``, then the resulting value is the number of tuples in the set. If there are no tuples in the set, then the value is the integer ``0``.
14681470

0 commit comments

Comments
 (0)