Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa8a2c0

Browse files
author
alexet
committed
QLSpec: Fix predicate resolution
1 parent ce905c0 commit fa8a2c0

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -862,20 +862,20 @@ A valid class may not inherit from a final class, from itself, or from more than
862862
Class environments
863863
~~~~~~~~~~~~~~~~~~
864864

865-
For each of modules, types, predicates, and fields a class *inherits*, *declares*, and *exports* an environment. These are defined as follows (with X denoting the type of entity we are currently considering):
865+
For each of member predicates and fields a class *inherits* and *declares*, and *exports* an environment. These are defined as follows (with X denoting the type of entity we are currently considering):
866866

867-
- The *inherited X environment* of a class is the union of the exported X environments of its base types.
867+
- The *inherited X environment* of a class is the union of the exported X environments of types it inherits from, excluding any elements that are ``overridden`` by another element.
868868

869869
- The *declared X environment* of a class is the multimap of X declarations in the class itself.
870870

871871
- The *exported X environment* of a class is the overriding union of its declared X environment (excluding ``private`` declaration entries) with its inherited X environment.
872872

873-
- The *external X environment* of a class is the visible X environment of the enclosing module.
874-
875-
- The *visible X environment* is the overriding union of the declared X environment and the inherited X environment; overriding unioned with the external X environment.
873+
- The *visible X environment* is the overriding union of the declared X environment and the inherited X environment.
876874

877875
The program is invalid if any of these environments is not definite.
878876

877+
For each of member predicates and fields a domain type *exports* an environment. This is the union of the exported ``X`` environments of types the class inherits from, excluding any elements that are ``overridden`` by another element.
878+
879879
Members
880880
~~~~~~~
881881

@@ -899,7 +899,7 @@ Member predicates
899899

900900
A predicate that is a member of a class is called a *member predicate*. The name of the predicate is the identifier just before the open parenthesis.
901901

902-
A member predicate adds a mapping from the predicate name and arity to the predicate declaration in the class's declared predicate environment.
902+
A member predicate adds a mapping from the predicate name and arity to the predicate declaration in the class's declared member predicate environment.
903903

904904
A valid member predicate can be annotated with ``abstract``, ``cached``, ``final``, ``private``, ``deprecated``, and ``override``.
905905

@@ -922,7 +922,7 @@ A valid class must include a non-private predicate named ``toString`` with no ar
922922
A valid class may not inherit from two different classes that include a predicate with the same name and number of arguments, unless either one of the predicates overrides the other, or the class defines a predicate that overrides both of them.
923923

924924
The typing environment for a member predicate or character is the same as if it were a non-member predicate, except that it additionally maps ``this`` to a type and also maps any fields on a class to a type. If the member is a character, then the typing environment maps ``this`` to the class domain type of the class. Otherwise, it maps ``this`` to the class type of the class itself.
925-
It any field to the type of the field.
925+
The typing environment also maps any field to the type of the field.
926926

927927
Fields
928928
^^^^^^
@@ -1163,13 +1163,24 @@ The expressions in parentheses are the *arguments* of the call. The expression b
11631163

11641164
The type environment for the arguments is the same as for the call.
11651165

1166-
A valid call with results must *resolve* to exactly one predicate. The ways a call can resolve are as follows:
1166+
A valid call with results *resolves* to a set of predicates. The ways a call can resolve are as follows:
1167+
1168+
- If the call has no receiver and the predicate name is a simple identifier, then the predicate is resolved by looking up its name and arity in the visible member-predicate environment of the enclosing class.
1169+
1170+
- If the call has no receiver and the predicate name is a simple identifier, then the predicate is resolved by looking up its name and arity in the visible predicate environment of the enclosing module.
1171+
1172+
- If the call has no receiver and the predicate name is a selection identifier, then the qualifier is resolved as a module (see "`Module resolution <#module-resolution>`__"). The identifier is then resolved in the exported predicate environment of the qualifier module.
1173+
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+
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.
11671177

1168-
- If the call has no receiver, then it can resolve to a non-member predicate. If the predicate name is a simple identifier, then the predicate is resolved by looking up its name and arity in the visible predicate environment of the enclosing class or module.
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.
11691179

1170-
If the predicate name is a selection identifier, then the qualifier is resolved as a module (see "`Module resolution <#module-resolution>`__"). The identifier is then resolved in the exported predicate environment of the qualifier module.
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.
11711182

1172-
- 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. If there is more than one such predicate, then the predicate call is not valid.
1183+
A valid call must only resolve to a single predicate.
11731184

11741185
For each argument other than a don't-care expression, the type of the argument must be compatible with the type of the corresponding argument type of the predicate, otherwise the call is invalid.
11751186

0 commit comments

Comments
 (0)