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/about-the-ql-language.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ When you write this process in QL, it closely resembles the above structure. Not
44
44
For more information about the important concepts and syntactic constructs of QL, see the individual reference topics such as ":doc:`Expressions <expressions>`" and ":doc:`Recursion <recursion>`."
45
45
The explanations and examples help you understand how the language works, and how to write more advanced QL code.
46
46
47
-
For formal specifications of the QL language and QLDoc comments, see the ":doc:`QL language specification <ql-language-specification>`" and ":doc:`QLDoc comment specification <qldoc-comment-specification>`."
47
+
For a formal specification of the QL language, see the ":doc:`QL language specification <ql-language-specification>`."
Copy file name to clipboardExpand all lines: docs/codeql/ql-language-reference/ql-language-specification.rst
+49-44Lines changed: 49 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -390,7 +390,7 @@ The store
390
390
391
391
QL programs evaluate in the context of a *store*. This section specifies several definitions related to the store.
392
392
393
-
A *fact* is a predicate or type along with an named tuple. A fact is written as the predicate name or type name followed immediately by the tuple. Here are some examples of facts:
393
+
A *fact* is a predicate or type along with a named tuple. A fact is written as the predicate name or type name followed immediately by the tuple. Here are some examples of facts:
394
394
395
395
::
396
396
@@ -406,10 +406,10 @@ An named tuple *directly satisfies* a predicate or type with a given tuple if th
406
406
A value ``v`` is in a type ``t`` under any of the following conditions:
407
407
408
408
- The type of ``v`` is ``t`` and ``t`` is a primitive type.
409
-
- There is tuple with ``this`` component ``v`` that directly satisfies ``t``.
409
+
- There is a tuple with ``this`` component ``v`` that directly satisfies ``t``.
410
410
411
-
An ordered tuple ``v`` *directly satisfies* a predicate with a given if there is a fact in the store with the given predicate and a named tuple ``v'``
412
-
such that taking the ordered formed by the ``this`` component of ``v'`` followed by component for each argument equals the ordered tuple.
411
+
An ordered tuple ``v`` *directly satisfies* a predicate with a given tuple if there is a fact in the store with the given predicate and a named tuple ``v'``
412
+
such that taking the ordered tuple formed by the ``this`` component of ``v'`` followed by the component for each argument equals the ordered tuple.
413
413
414
414
An ordered tuple *satisfies a predicate* ``p`` under the following circumstances. If ``p`` is not a member predicate, then the tuple satisfies the predicate whenever the named tuple satisfies the tuple.
415
415
@@ -460,9 +460,9 @@ A multiline comment is a *comment start*, followed by a *comment body*, followed
460
460
*/
461
461
462
462
QLDoc (qldoc)
463
-
~~~~~~~~
463
+
~~~~~~~~~~~~~
464
464
465
-
A QLDoc comment is a *qldoc comment start*, followed by a *comment body*, followed by a *qldoc comment end*. A comment start is a slash (``/``, U+002F) followed by two asterisks (``*``, U+002A), and a qldoc comment end is an asterisk followed by a slash. A qldoc comment body is any sequence of characters that does not include a comment end. Here is an example qldoc comment:
465
+
A QLDoc comment is a *qldoc comment start*, followed by a *qldoc comment body*, followed by a *qldoc comment end*. A comment start is a slash (``/``, U+002F) followed by two asterisks (``*``, U+002A), and a qldoc comment end is an asterisk followed by a slash. A qldoc comment body is any sequence of characters that does not include a comment end. Here is an example QLDoc comment:
466
466
467
467
::
468
468
@@ -472,7 +472,7 @@ A QLDoc comment is a *qldoc comment start*, followed by a *comment body*, follow
472
472
It had a qldoc comment.
473
473
*/
474
474
475
-
The ‘content’ of a QLDoc comment is the comment body of the comment, omitting the initial /**, the trailing */, and the leading whitespace followed by * on each internal line.
475
+
The "content" of a QLDoc comment is the comment body of the comment, omitting the initial ``/**``, the trailing ``*/``, and the leading whitespace followed by ``*`` on each internal line.
476
476
477
477
Keywords
478
478
~~~~~~~~
@@ -759,27 +759,27 @@ A predicate may have several different binding sets, which can be stated by usin
759
759
QLDoc
760
760
-----
761
761
762
-
QLDoc is used for documenting ql entities and bindings. QLDoc that is used as part of the
762
+
QLDoc is used for documenting QL entities and bindings. QLDoc that is used as part of the
763
763
declaration is said to be declared.
764
764
765
765
Ambiguous QLDoc
766
-
~~~~~~~~~~~
766
+
~~~~~~~~~~~~~~~
767
767
768
-
If QLDoc could be parsed as part a file module or as part of the first declaration in the file then
768
+
If QLDoc can be parsed as part of a file module or as part of the first declaration in the file then
769
769
it is parsed as part of the first declaration.
770
770
771
771
Inheriting QLDoc
772
-
~~~~~~~~~~~
772
+
~~~~~~~~~~~~~~~~
773
773
774
-
If no qldoc is provided then in may be inherited.
774
+
If no QLDoc is provided then it may be inherited.
775
775
776
-
In the case of an alias then it may be inherited from the right-hand-side of the alias.
776
+
In the case of an alias then it may be inherited from the right-handside of the alias.
777
777
778
-
In the case of a member predicate we collect all member predicates that it overrides with declared QLDoc. Then if there is a member predicate in that collection that
779
-
that overrides every other member predicate in that collection then the QLDoc of that member predicate is used as the QLDoc.
778
+
In the case of a member predicate we collect all member predicates that it overrides with declared QLDoc. If there is a member predicate in that collection that
779
+
overrides every other member predicate in that collection, then the QLDoc of that member predicate is used as the QLDoc.
780
780
781
-
In the case of a field we collect all fields that it overrides with declared QLDoc. Then if there is a field in that collection that
782
-
that overrides every other field in that collection then its QLDoc of that field used as the QLDoc.
781
+
In the case of a field we collect all fields that it overrides with declared QLDoc. If there is a field in that collection that
782
+
overrides every other field in that collection, then the QLDoc of that field is used as the QLDoc.
783
783
784
784
Content
785
785
~~~~~~~
@@ -791,12 +791,12 @@ The content of a QLDoc comment is interpreted as `CommonMark <https://commonmark
791
791
792
792
The content of a QLDoc comment may contain metadata tags as follows:
793
793
794
-
The tag begins with any number of whitespace characters, followed by an '@' sign. At this point there may be any number of non-whitespace characters, which form the key of the tag. Then, a single whitespace character which separates the key from the value. The value of the tag is formed by the remainder of the line, and any subsequent lines until another '@' tag is seen, or the end of the content is reached. Any sequence of consecutive whitespace characters in the value are replaced by a single space.
794
+
The tag begins with any number of whitespace characters, followed by an ``@`` sign. At this point there may be any number of non-whitespace characters, which form the key of the tag. Then, a single whitespace character which separates the key from the value. The value of the tag is formed by the remainder of the line, and any subsequent lines until another ``@`` tag is seen, or the end of the content is reached. Any sequence of consecutive whitespace characters in the value are replaced by a single space.
795
795
796
796
Metadata
797
797
~~~~~~~~
798
798
799
-
If the query file starts with whitespace followed by a qldoc comment then the tags from that qldoc comment form the query metadata.
799
+
If the query file starts with whitespace followed by a QLDoc comment, then the tags from that QLDoc comment form the query metadata.
800
800
801
801
Top-level entities
802
802
------------------
@@ -929,11 +929,11 @@ Fields
929
929
930
930
A field declaration introduces a mapping from the field name to the field declaration in the class's declared field environment.
931
931
932
-
A field ``f`` with enclosing class ``C`` *overrides* a field ``f'`` with enclosing class ``D`` when ``f`` is annotated override, ``C`` inherits from ``D``, ``p'`` is visible in ``C``, and both ``p`` and ``p'`` have the same name.
932
+
A field ``f`` with enclosing class ``C`` *overrides* a field ``f'`` with enclosing class ``D`` when ``f`` is annotated ``override``, ``C`` inherits from ``D``, ``p'`` is visible in ``C``, and both ``p`` and ``p'`` have the same name.
933
933
934
934
A valid class may not inherit from two different classes that include a field with the same name, unless either one of the fields overrides the other, or the class defines a field that overrides both of them.
935
935
936
-
A valid field must override another field if it is annotated override.
936
+
A valid field must override another field if it is annotated ``override``.
937
937
938
938
When field ``f`` overrides field ``g`` the type of ``f`` must be a subtype of the type of ``g``. ``f`` may not be a final field.
939
939
@@ -1173,12 +1173,12 @@ A valid call with results *resolves* to a set of predicates. The ways a call can
1173
1173
1174
1174
- If the call has a super expression as the receiver, then it resolves to a member predicate in a class the enclosing class inherits from. If the super expression is unqualified, then the super-class is the single class that the current class inherits from. If there is not exactly one such class, then the program is invalid. Otherwise the super-class is the class named by the qualifier of the super expression. The predicate is resolved by looking up its name and arity in the exported predicate environment of the super-class.
1175
1175
1176
-
- If the type of the receiver is the same as the the enclosing class the predicate is resolved by looking up its name and arity in the ``visible`` predicate environment of the class.
1176
+
- If the type of the receiver is the same as the enclosing class, the predicate is resolved by looking up its name and arity in the visible predicate environment of the class.
1177
1177
1178
-
- If the type of the receiver is not the same as the the enclosing class the predicate is resolved by looking up its name and arity in the ``exported`` predicate environment of the class or domain type.
1178
+
- If the type of the receiver is not the same as the enclosing class, the predicate is resolved by looking up its name and arity in the exported predicate environment of the class or domain type.
1179
1179
1180
-
If all the predicates that the call resolves to are declared on a primitive type we then restrict to the set of predicates where each argument of the call is a subtype of the corresponding predicate argument type.
1181
-
Then we find all predicates ``p`` from this new set such that there is not another predicate ``p'``where each argument of ``p'`` is a subtype of the corresponding argument in ``p``. We then say the call resolves to this set instead.
1180
+
If all the predicates that the call resolves to are declared on a primitive type, we then restrict to the set of predicates where each argument of the call is a subtype of the corresponding predicate argument type.
1181
+
Then we find all predicates ``p`` from this new set such that there is not another predicate ``p'``where each argument of ``p'`` is a subtype of the corresponding argument in ``p``. We then say the call resolves to this set instead.
1182
1182
1183
1183
A valid call must only resolve to a single predicate.
1184
1184
@@ -1194,7 +1194,7 @@ If the resolved predicate is built in, then the call may not include a closure.
1194
1194
1195
1195
- The number 1 if the predicate has a result, otherwise 0.
1196
1196
1197
-
If the call includes a closure then all declared predicate arguments, the enclosing type of the declaration if it exists and the result type of the declaration if it exists must be compatible. If one of those types is a subtype of ``int`` all the other arguments must be a subtype of ``int``.
1197
+
If the call includes a closure, then all declared predicate arguments, the enclosing type of the declaration (if it exists), and the result type of the declaration (if it exists) must be compatible. If one of those types is a subtype of ``int``, then all the other arguments must be a subtype of ``int``.
1198
1198
1199
1199
If the call resolves to a member predicate, then the *receiver values* are as follows. If the call has a receiver, then the receiver values are the values of that receiver. If the call does not have a receiver, then the single receiver value is the value of ``this`` in the contextual named tuple.
1200
1200
@@ -1352,7 +1352,8 @@ The grammar given in this section is disambiguated first by precedence, and seco
1352
1352
- binary ``+`` and ``-``
1353
1353
1354
1354
Whenever a sequence of tokens can be interpreted either as a call to a predicate with result (with specified closure), or as a binary operation with operator ``+`` or ``*``, the syntax is interpreted as a call to a predicate with result.
1355
-
Whenever a sequence of tokens can be interpreted either as either arithmetic with a parenthesized variable or a prefix cast of a unary operation the syntax is interpreted as a cast.
1355
+
1356
+
Whenever a sequence of tokens can be interpreted either as arithmetic with a parenthesized variable or as a prefix cast of a unary operation, the syntax is interpreted as a cast.
1356
1357
1357
1358
Formulas
1358
1359
--------
@@ -1948,38 +1949,42 @@ The store is first initialized with the *database content* of all built-in predi
1948
1949
1949
1950
Each layer of the stratification is *populated* in order. To populate a layer, each predicate in the layer is repeatedly populated until the store stops changing. The way that a predicate is populated is as follows:
1950
1951
1951
-
- To populate a predicate that has a formula as a body, find all named tuples with identify each named tuple ``t`` that has the following properties:
1952
-
- The tuple matches the body formula.
1953
-
- The variables should be the predicate's arguments.
1954
-
- If the predicate has a result, then the tuples should additionally have a value for ``result``
1955
-
- If the predicate is a member predicate or characteristic predicate of a class ``C`` then the tuples should additionally have a value for ``this`` and each visible field on the class.
1956
-
- The values corresponding to the arguments should all be a member of the declared types of the arguments.
1957
-
- The values corresponding to ``result`` should all be a member of the result type.
1958
-
- The values corresponding to the fields should all be a member of the declared types of the fields.
1959
-
- If the predicate is a member predicate of a class ``C`` and not a characteristic predicate, then the tuples should additionally extend some tuple in ``C.class``.
1960
-
- If the predicate is a characteristic predicate of a class ``C``, then there should be a tuple ``t'``in ``C.extends`` such that for each visible field in ``C`` any field that is equal to or overrides a field in that ``t'`` should have the same value in ``t``. ``this`` should also map to the same value in ``t`` and ``t``.
1952
+
- To populate a predicate that has a formula as a body, find each named tuple ``t`` that has the following properties:
1953
+
1954
+
- The tuple matches the body formula.
1955
+
- The variables should be the predicate's arguments.
1956
+
- If the predicate has a result, then the tuples should additionally have a value for ``result``.
1957
+
- If the predicate is a member predicate or characteristic predicate of a class ``C`` then the tuples should additionally have a value for ``this`` and each visible field on the class.
1958
+
- The values corresponding to the arguments should all be a member of the declared types of the arguments.
1959
+
- The values corresponding to ``result`` should all be a member of the result type.
1960
+
- The values corresponding to the fields should all be a member of the declared types of the fields.
1961
+
- If the predicate is a member predicate of a class ``C`` and not a characteristic predicate, then the tuples should additionally extend some tuple in ``C.class``.
1962
+
- If the predicate is a characteristic predicate of a class ``C``, then there should be a tuple ``t'`` in ``C.extends`` such that for each visible field in ``C``, any field that is equal to or overrides a field in ``t'`` should have the same value in ``t``. ``this`` should also map to the same value in ``t`` and ``t'``.
1963
+
1961
1964
For each such tuple remove any components that correspond to fields and add it to the predicate in the store.
1962
1965
1963
1966
- To populate an abstract predicate, do nothing.
1964
1967
1965
1968
- The population of predicates with a higher-order body is left only partially specified. A number of tuples are added to the given predicate in the store. The tuples that are added must be fully determined by the QL program and by the state of the store.
1966
1969
1967
1970
- To populate the type ``C.extends`` for a class ``C``, identify each named tuple that has the following properties:
1971
+
1968
1972
- The value of ``this`` is in all non-class base types of ``C``.
1969
1973
- The keys of the tuple are ``this`` and the union of the public fields from each base type.
1970
-
- For each class base type ``B`` of ``C`` there is a named tuple with with variables from the public fields of ``B`` and ``this`` that is the given tuple and some tuple in ``B.B`` both extend.
1974
+
- For each class base type ``B`` of ``C`` there is a named tuple with variables from the public fields of ``B`` and ``this`` that the given tuple and some tuple in ``B.B`` both extend.
1975
+
1971
1976
For each such tuple add it to ``C.extends``.
1972
1977
1973
-
- To populate the type ``C.C`` for a class ``C``, if ``C`` has a characteristic predicate, then add all tuples from that predicate to the store.
1974
-
Otherwise add all tuples ``t`` such that:
1975
-
- The variables of ``t`` should be ``this`` and the visible fields of ``C``.
1976
-
- The values corresponding to the fields should all be a member of the declared types of the fields.
1977
-
- If the predicate is a characteristic predicate of a class ``C``, then there should be a tuple ``t'``in ``C.extends`` such that for each visible field in ``C`` any field that is equal to or overrides a field in that ``t'`` should have the same value in ``t``. ``this`` should also map to the same value in ``t`` and ``t``.
1978
+
- To populate the type ``C.C`` for a class ``C``, if ``C`` has a characteristic predicate, then add all tuples from that predicate to the store. Otherwise add all tuples ``t`` such that:
1979
+
1980
+
- The variables of ``t`` should be ``this`` and the visible fields of ``C``.
1981
+
- The values corresponding to the fields should all be a member of the declared types of the fields.
1982
+
- If the predicate is a characteristic predicate of a class ``C``, then there should be a tuple ``t'``in ``C.extends`` such that for each visible field in ``C``, any field that is equal to or overrides a field in ``t'`` should have the same value in ``t``. ``this`` should also map to the same value in ``t`` and ``t'``.
1978
1983
1979
1984
- To populate the type ``C.class`` for a non-abstract class type ``C``, add each tuple in ``C.C`` to ``C.class``.
1980
1985
1981
1986
- To populate the type ``C.class`` for an abstract class type ``C``, identify each named tuple that has the following properties:
1982
-
- It is a member of ``C.C``
1987
+
- It is a member of ``C.C``.
1983
1988
- For each class ``D`` that has ``C`` as a base type then there is a named tuple with variables from the public fields of ``C`` and ``this`` that the given tuple and a tuple in ``D.class`` both extend.
0 commit comments