From acca48bd8fb530881c4300c8c04202ff369424c5 Mon Sep 17 00:00:00 2001 From: Shati Patel Date: Mon, 9 Sep 2019 15:23:31 +0100 Subject: [PATCH 1/4] QL HB: Fix typo [SD-3862] --- docs/language/ql-handbook/types.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/language/ql-handbook/types.rst b/docs/language/ql-handbook/types.rst index 1643da2bd7b..8bf5e77505b 100644 --- a/docs/language/ql-handbook/types.rst +++ b/docs/language/ql-handbook/types.rst @@ -106,7 +106,7 @@ base types. A class can extend multiple types. See :ref:`multiple-inheritance` below. -To be a valid, a class: +To be valid, a class: - Must not extend itself. - Must not extend a :ref:`final` class. - Must not extend types that are incompatible. (See :ref:`type-compatibility`.) From 4f2c9fa3cbceafb3541fd6652fe772fd61f64596 Mon Sep 17 00:00:00 2001 From: Shati Patel Date: Mon, 9 Sep 2019 15:35:13 +0100 Subject: [PATCH 2/4] QL HB: Expand bindingset example [SD-3863] --- docs/language/ql-handbook/predicates.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/language/ql-handbook/predicates.rst b/docs/language/ql-handbook/predicates.rst index 091488f64b3..d2da73be3ce 100644 --- a/docs/language/ql-handbook/predicates.rst +++ b/docs/language/ql-handbook/predicates.rst @@ -262,6 +262,10 @@ multiple binding set annotations, for example:: x + 1 = y } + from int x, int y + where y = 42 and plusOne(x, y) + select x, y + Multiple binding sets specified this way are independent of each other. The above example means: - If ``x`` is bound, then ``x`` and ``y`` are bound. - If ``y`` is bound, then ``x`` and ``y`` are bound. From f5de1dc999b2dcfb2f987d2407040b3cf138e9a2 Mon Sep 17 00:00:00 2001 From: Shati Patel Date: Mon, 9 Sep 2019 15:47:04 +0100 Subject: [PATCH 3/4] QL HB: Explain use of cast [SD-3865] --- docs/language/ql-handbook/types.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/language/ql-handbook/types.rst b/docs/language/ql-handbook/types.rst index 8bf5e77505b..c1438d16dca 100644 --- a/docs/language/ql-handbook/types.rst +++ b/docs/language/ql-handbook/types.rst @@ -147,7 +147,11 @@ predicate from the :ref:`above ` class:: 1.(OneTwoThree).getAString() -This call returns the results ``"One, two or three: 1"``. +This call returns the result ``"One, two or three: 1"``. + +The expression ``(OneTwoThree)`` is a :ref:`cast `. It ensures that ``1`` has type +``OneTwoThree`` instead of just ``int``. Therefore, it has access to the member predicate +``getAString()``. Member predicates are especially useful because you can chain them together. For example, you can use ``toUpperCase()``, a built-in function defined for ``string``:: From cfa51a0e8be1c6b109e91f1e15120ba362f9f42c Mon Sep 17 00:00:00 2001 From: Shati Patel Date: Mon, 9 Sep 2019 15:58:30 +0100 Subject: [PATCH 4/4] QL HB: Add predicate call example [SD-3864] --- docs/language/ql-handbook/queries.rst | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/language/ql-handbook/queries.rst b/docs/language/ql-handbook/queries.rst index 3f0db3acdf3..1c21482af35 100644 --- a/docs/language/ql-handbook/queries.rst +++ b/docs/language/ql-handbook/queries.rst @@ -83,7 +83,7 @@ For example:: result = x * y } -This predicates returns the following results: +This predicate returns the following results: +---+---+--------+ | x | y | result | @@ -96,8 +96,14 @@ This predicates returns the following results: +---+---+--------+ A benefit of writing a query predicate instead of a select clause is that you can call the -predicate in other parts of the code too. In contrast, the select clause is like an anonymous -predicate, so you can't call it later. +predicate in other parts of the code too. For example, you can call ``getProduct`` inside +the body of a :ref:`class `:: + + class MultipleOfThree extends int { + MultipleOfThree() { this = getProduct(_, _) } + } + +In contrast, the select clause is like an anonymous predicate, so you can't call it later. It can also be helpful to add a ``query`` annotation to a predicate while you debug code. That way you can explicitly see the set of tuples that the predicate evaluates to.