Skip to content

Commit 2686335

Browse files
authored
Merge pull request #1 from shati-patel/fix-spec-bugs-edits
Editorial review for QL language updates
2 parents 0bd8c55 + bc6b1e8 commit 2686335

File tree

4 files changed

+53
-50
lines changed

4 files changed

+53
-50
lines changed

docs/codeql/ql-language-reference/about-the-ql-language.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ When you write this process in QL, it closely resembles the above structure. Not
4444
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>`."
4545
The explanations and examples help you understand how the language works, and how to write more advanced QL code.
4646

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>`."
4848

4949
QL and object orientation
5050
-------------------------

docs/codeql/ql-language-reference/lexical-syntax.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ For an overview of the lexical syntax, see "`Lexical syntax
1616
Comments
1717
********
1818

19-
All standard one-line and multiline comments, as described in the "`QL language specification
20-
<ql-language-specification#comments>`_," are ignored by the QL
19+
All standard one-line and multiline comments are ignored by the QL
2120
compiler and are only visible in the source code.
2221
You can also write another kind of comment, namely **QLDoc comments**. These comments describe
23-
QL entities and are displayed as pop-up information in QL editors. For information about QLDoc
24-
comments, see the ":doc:`QLDoc comment specification <qldoc-comment-specification>`."
22+
QL entities and are displayed as pop-up information in QL editors.
2523

2624
The following example uses these three different kinds of comments:
2725

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

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ The store
390390

391391
QL programs evaluate in the context of a *store*. This section specifies several definitions related to the store.
392392

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:
394394

395395
::
396396

@@ -406,10 +406,10 @@ An named tuple *directly satisfies* a predicate or type with a given tuple if th
406406
A value ``v`` is in a type ``t`` under any of the following conditions:
407407

408408
- 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``.
410410

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.
413413

414414
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.
415415

@@ -460,9 +460,9 @@ A multiline comment is a *comment start*, followed by a *comment body*, followed
460460
*/
461461

462462
QLDoc (qldoc)
463-
~~~~~~~~
463+
~~~~~~~~~~~~~
464464

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:
466466

467467
::
468468

@@ -472,7 +472,7 @@ A QLDoc comment is a *qldoc comment start*, followed by a *comment body*, follow
472472
It had a qldoc comment.
473473
*/
474474

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.
476476

477477
Keywords
478478
~~~~~~~~
@@ -759,27 +759,27 @@ A predicate may have several different binding sets, which can be stated by usin
759759
QLDoc
760760
-----
761761

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
763763
declaration is said to be declared.
764764

765765
Ambiguous QLDoc
766-
~~~~~~~~~~~
766+
~~~~~~~~~~~~~~~
767767

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
769769
it is parsed as part of the first declaration.
770770

771771
Inheriting QLDoc
772-
~~~~~~~~~~~
772+
~~~~~~~~~~~~~~~~
773773

774-
If no qldoc is provided then in may be inherited.
774+
If no QLDoc is provided then it may be inherited.
775775

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-hand side of the alias.
777777

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.
780780

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.
783783

784784
Content
785785
~~~~~~~
@@ -791,12 +791,12 @@ The content of a QLDoc comment is interpreted as `CommonMark <https://commonmark
791791

792792
The content of a QLDoc comment may contain metadata tags as follows:
793793

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.
795795

796796
Metadata
797797
~~~~~~~~
798798

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.
800800

801801
Top-level entities
802802
------------------
@@ -929,11 +929,11 @@ Fields
929929

930930
A field declaration introduces a mapping from the field name to the field declaration in the class's declared field environment.
931931

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.
933933

934934
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.
935935

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``.
937937

938938
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.
939939

@@ -1173,12 +1173,12 @@ A valid call with results *resolves* to a set of predicates. The ways a call can
11731173

11741174
- 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.
11751175

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.
11771177

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.
11791179

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.
11821182

11831183
A valid call must only resolve to a single predicate.
11841184

@@ -1194,7 +1194,7 @@ If the resolved predicate is built in, then the call may not include a closure.
11941194

11951195
- The number 1 if the predicate has a result, otherwise 0.
11961196

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``.
11981198

11991199
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.
12001200

@@ -1352,7 +1352,8 @@ The grammar given in this section is disambiguated first by precedence, and seco
13521352
- binary ``+`` and ``-``
13531353

13541354
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.
13561357

13571358
Formulas
13581359
--------
@@ -1948,38 +1949,42 @@ The store is first initialized with the *database content* of all built-in predi
19481949

19491950
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:
19501951

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+
19611964
For each such tuple remove any components that correspond to fields and add it to the predicate in the store.
19621965

19631966
- To populate an abstract predicate, do nothing.
19641967

19651968
- 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.
19661969

19671970
- To populate the type ``C.extends`` for a class ``C``, identify each named tuple that has the following properties:
1971+
19681972
- The value of ``this`` is in all non-class base types of ``C``.
19691973
- 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+
19711976
For each such tuple add it to ``C.extends``.
19721977

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'``.
19781983

19791984
- To populate the type ``C.class`` for a non-abstract class type ``C``, add each tuple in ``C.C`` to ``C.class``.
19801985

19811986
- 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``.
19831988
- 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.
19841989

19851990

0 commit comments

Comments
 (0)