You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/ql-language-reference/modules.rst
+56-29Lines changed: 56 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,10 @@
4
4
5
5
Modules
6
6
#######
7
-
8
-
Modules provide a way of organizing QL code by grouping together related types, predicates, and other modules.
9
7
10
-
You can import modules into other files, which avoids duplication, and helps
8
+
Modules provide a way of organizing QL code by grouping together related types, predicates, and other modules.
9
+
10
+
You can import modules into other files, which avoids duplication, and helps
11
11
structure your code into more manageable pieces.
12
12
13
13
.. _defining-module:
@@ -16,7 +16,7 @@ Defining a module
16
16
*****************
17
17
18
18
There are various ways to define modules—here is an example of the simplest way, declaring an
19
-
:ref:`explicit module <explicit-modules>` named ``Example`` containing
19
+
:ref:`explicit module <explicit-modules>` named ``Example`` containing
20
20
a class ``OneTwoThree``:
21
21
22
22
.. code-block:: ql
@@ -27,17 +27,17 @@ a class ``OneTwoThree``:
27
27
this = 1 or this = 2 or this = 3
28
28
}
29
29
}
30
-
}
30
+
}
31
31
32
32
The name of a module can be any `identifier <https://codeql.github.com/docs/ql-language-reference/ql-language-specification/#identifiers>`_
33
-
that starts with an uppercase or lowercase letter.
33
+
that starts with an uppercase or lowercase letter.
34
34
35
35
``.ql`` or ``.qll`` files also implicitly define modules.
36
36
For more information, see ":ref:`kinds-of-modules`."
37
37
38
38
You can also annotate a module. For more information, see of ":ref:`annotations-overview`."
39
39
40
-
Note that you can only annotate :ref:`explicit modules <explicit-modules>`.
40
+
Note that you can only annotate :ref:`explicit modules <explicit-modules>`.
41
41
File modules cannot be annotated.
42
42
43
43
.. _kinds-of-modules:
@@ -48,7 +48,7 @@ Kinds of modules
48
48
File modules
49
49
============
50
50
51
-
Each query file (extension ``.ql``) and library file (extension ``.qll``) implicitly defines
51
+
Each query file (extension ``.ql``) and library file (extension ``.qll``) implicitly defines
52
52
a module. The module has the same name as the file, but any spaces in the file name are replaced
53
53
by underscores (``_``). The contents of the file form the :ref:`body of the module <module-bodies>`.
54
54
@@ -57,7 +57,7 @@ by underscores (``_``). The contents of the file form the :ref:`body of the modu
57
57
Library modules
58
58
---------------
59
59
60
-
A library module is defined by a ``.qll`` file. It can contain any of the
60
+
A library module is defined by a ``.qll`` file. It can contain any of the
61
61
elements listed in :ref:`module-bodies` below, apart from select clauses.
62
62
63
63
For example, consider the following QL library:
@@ -75,19 +75,19 @@ For example, consider the following QL library:
75
75
This file defines a library module named ``OneTwoThreeLib``. The body of this module
76
76
defines the class ``OneTwoThree``.
77
77
78
-
.. _query-modules:
78
+
.. _query-modules:
79
79
80
80
Query modules
81
81
-------------
82
82
83
-
A query module is defined by a ``.ql`` file. It can contain any of the elements listed
84
-
in :ref:`module-bodies` below.
83
+
A query module is defined by a ``.ql`` file. It can contain any of the elements listed
84
+
in :ref:`module-bodies` below.
85
85
86
86
Query modules are slightly different from other modules:
87
87
88
88
- A query module can't be imported.
89
-
- A query module must have at least one query in its
90
-
:ref:`namespace <namespaces>`. This is usually a :ref:`select clause <select-clauses>`,
89
+
- A query module must have at least one query in its
90
+
:ref:`namespace <namespaces>`. This is usually a :ref:`select clause <select-clauses>`,
91
91
but can also be a :ref:`query predicate <query-predicates>`.
92
92
93
93
For example:
@@ -97,7 +97,7 @@ For example:
97
97
.. code-block:: ql
98
98
99
99
import OneTwoThreeLib
100
-
100
+
101
101
from OneTwoThree ott
102
102
where ott = 1 or ott = 2
103
103
select ott
@@ -110,13 +110,13 @@ This file defines a query module named ``OneTwoQuery``. The body of this module
110
110
Explicit modules
111
111
================
112
112
113
-
You can also define a module within another module. This is an explicit module definition.
113
+
You can also define a module within another module. This is an explicit module definition.
114
114
115
-
An explicit module is defined with the keyword ``module`` followed by
116
-
the module name, and then the module body enclosed in braces. It can contain any
117
-
of the elements listed in ":ref:`module-bodies`" below, apart from select clauses.
115
+
An explicit module is defined with the keyword ``module`` followed by
116
+
the module name, and then the module body enclosed in braces. It can contain any
117
+
of the elements listed in ":ref:`module-bodies`" below, apart from select clauses.
118
118
119
-
For example, you could add the following QL snippet to the library file **OneTwoThreeLib.qll**
119
+
For example, you could add the following QL snippet to the library file **OneTwoThreeLib.qll**
120
120
defined :ref:`above <library-modules>`:
121
121
122
122
.. code-block:: ql
@@ -129,7 +129,7 @@ defined :ref:`above <library-modules>`:
129
129
}
130
130
}
131
131
}
132
-
132
+
133
133
This defines an explicit module named ``M``. The body of this module defines
134
134
the class ``OneTwo``.
135
135
@@ -226,7 +226,7 @@ Module bodies
226
226
*************
227
227
228
228
The body of a module is the code inside the module definition, for example
229
-
the class ``OneTwo`` in the :ref:`explicit module <explicit-modules>` ``M``.
229
+
the class ``OneTwo`` in the :ref:`explicit module <explicit-modules>` ``M``.
230
230
231
231
In general, the body of a module can contain the following constructs:
232
232
@@ -243,11 +243,11 @@ In general, the body of a module can contain the following constructs:
243
243
Importing modules
244
244
*****************
245
245
246
-
The main benefit of storing code in a module is that you can reuse it in other modules.
247
-
To access the contents of an external module, you can import the module using an
246
+
The main benefit of storing code in a module is that you can reuse it in other modules.
247
+
To access the contents of an external module, you can import the module using an
248
248
:ref:`import statement <import-statements>`.
249
249
250
-
When you import a module this brings all the names in its namespace, apart from :ref:`private` names,
250
+
When you import a module this brings all the names in its namespace, apart from :ref:`private` names,
251
251
into the :ref:`namespace <namespaces>` of the current module.
252
252
253
253
.. _import-statements:
@@ -263,7 +263,7 @@ Import statements are used for importing modules. They are of the form:
263
263
import <module_expression2>
264
264
265
265
Import statements are usually listed at the beginning of the module. Each
266
-
import statement imports one module. You can import multiple modules by
266
+
import statement imports one module. You can import multiple modules by
267
267
including multiple import statements (one for each module you want to import).
268
268
269
269
An import statement can also be :ref:`annotated <annotations-overview>` with
@@ -272,14 +272,14 @@ An import statement can also be :ref:`annotated <annotations-overview>` with
272
272
only reachable through deprecated imports in a given context then usage of the
273
273
name in that context will generate deprecation warnings.
274
274
275
-
You can import a module under a different name using the ``as`` keyword,
275
+
You can import a module under a different name using the ``as`` keyword,
276
276
for example ``import javascript as js``.
277
277
278
278
The ``<module_expression>`` itself can be a module name, a selection, or a qualified
279
279
reference. For more information, see ":ref:`name-resolution`."
280
280
281
281
For information about how import statements are looked up, see "`Module resolution <https://codeql.github.com/docs/ql-language-reference/ql-language-specification/#module-resolution>`__"
282
-
in the QL language specification.
282
+
in the QL language specification.
283
283
284
284
Built-in modules
285
285
****************
@@ -353,7 +353,7 @@ Sets
353
353
354
354
The built-in ``InternSets`` module is parameterized by ``Key`` and ``Value`` types
355
355
and a ``Value getAValue(Key key)`` relation. The module groups the ``Value``
356
-
column by ``Key`` and creates a set for each group of values related by a key.
356
+
column by ``Key`` and creates a set for each group of values related by a key.
357
357
358
358
The ``InternSets`` module exports a functional ``Set getSet(Key key)`` relation
359
359
that relates keys with the set of value related to the given key by
@@ -424,3 +424,30 @@ The above query therefore evalutes to:
424
424
+----+----+
425
425
| 4 | 4 |
426
426
+----+----+
427
+
428
+
.. index:: BigInt
429
+
.. _bigint:
430
+
431
+
BigInt
432
+
======
433
+
434
+
The built-in ``QlBuiltins`` module provides an **experimental** type ``BigInt`` of arbitrary-precision integers.
435
+
436
+
This type is not available in the CodeQL CLI by default, but you can enable it by passing the ``--allow-experimental=bigint``
437
+
option to the CodeQL CLI. Consequently, BigInts are currently disallowed in query results and dbscheme columns.
438
+
439
+
Unlike ``int`` and ``float``, there is no automatic conversion between ``BigInt`` and other numeric types.
440
+
Instead, big integers can be constructed using the ``.toBigInt()`` methods of ``int`` and ``string``.
441
+
442
+
The other built-in operations are:
443
+
444
+
* comparisons between ``BigInt``\s: ``=``, ``!=``, ``<``, ``<=``, ``>``, ``>=``,
445
+
* conversions from ``BigInt``\s to strings or integers (if within range): ``.toString()``, ``.toInt()``,
Copy file name to clipboardExpand all lines: docs/codeql/ql-language-reference/ql-language-specification.rst
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -359,7 +359,7 @@ Kinds of types
359
359
360
360
Types in QL are either *primitive* types, *database* types, *class* types, *character* types, *class domain* types, type *parameters*, or *instantiation-nested* types.
361
361
362
-
The primitive types are ``boolean``, ``date``, ``float``, ``int``, and ``string``.
362
+
The primitive types are ``boolean``, ``date``, ``float``, ``int``, ``string``, and ``QlBuiltins::BigInt``.
363
363
364
364
Database types are supplied as part of the database. Each database type has a *name*, which is an identifier starting with an at sign (``@``, U+0040) followed by lower-case letter. Database types have some number of *base types*, which are other database types. In a valid database, the base types relation is non-cyclic.
365
365
@@ -433,7 +433,7 @@ Values are the fundamental data that QL programs compute over. This section spec
433
433
Kinds of values
434
434
~~~~~~~~~~~~~~~
435
435
436
-
There are six kinds of values in QL: one kind for each of the five primitive types, and *entities*. Each value has a type.
436
+
There are seven kinds of values in QL: one kind for each of the six primitive types, and *entities*. Each value has a type.
437
437
438
438
A boolean value is of type ``boolean``, and may have one of two distinct values: ``true`` or ``false``.
439
439
@@ -445,6 +445,8 @@ An integer value is of type ``int``. Each value is a 32-bit two's complement int
445
445
446
446
A string is a finite sequence of 16-bit characters. The characters are interpreted as Unicode code points.
447
447
448
+
A :ref:`big integer <bigint>` value is of type ``QlBuiltins::BigInt``. Each value is a signed arbitrary-precision integer.
449
+
448
450
The database includes a number of opaque entity values. Each such value has a type that is one of the database types, and an identifying integer. An entity value is written as the name of its database type followed by its identifying integer in parentheses. For example, ``@tree(12)``, ``@person(16)``, and ``@location(38132)`` are entity values. The identifying integers are left opaque to programmers in this specification, so an implementation of QL is free to use some other set of countable labels to identify its entities.
449
451
450
452
Ordering
@@ -458,7 +460,7 @@ For dates, the ordering is chronological.
458
460
459
461
For floats, the ordering is as specified in IEEE 754 when one exists, except that NaN is considered equal to itself and is ordered after all other floats, and negative zero is considered to be strictly less than positive zero.
460
462
461
-
For integers, the ordering is as for two's complement integers.
463
+
For integers (and :ref:`big integers <bigint>`), the ordering is numerical.
0 commit comments