Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ff64aed
Python docs: Replace remaining references to old 'Object' API are rep…
markshannon Aug 27, 2019
1fe5d0c
Python docs: Remove all references to ClassExpr and FunctionExpr; we …
markshannon Aug 27, 2019
63a391a
Python docs: remove confusing reference to SSA as 'dataflow' and add …
markshannon Aug 27, 2019
6b9566a
docs: add rst versions of java slide decks and improve a few c++ slides
Aug 12, 2019
dfeab08
docs: add template slide deck
Aug 23, 2019
6dcf999
docs: make use of includes for local and global data flow slides
Aug 29, 2019
9eefeb7
docs: fix include in data flow slides
Aug 29, 2019
d592af1
docs: fix speaker note bug
Aug 29, 2019
541706e
Python docs: Fix typos and rst formatting issue.
markshannon Aug 29, 2019
4e4388d
docs: address review comments
Sep 3, 2019
b701d1d
docs: toctree path
Sep 3, 2019
32d56fb
docs: update images
Sep 4, 2019
e19799f
Update docs/language/ql-training-rst/slide-snippets/local-data-flow.rst
jf205 Sep 4, 2019
d1d19bf
docs: add ql-training page to learn-ql project
Aug 30, 2019
40be3bc
docs: rename ql-training-rst > ql-training
Aug 30, 2019
b56b28e
docs: reorganize and add some ref bookmarks to learn-ql index
Sep 2, 2019
8efcabf
docs: rework ql-training.rst
Sep 2, 2019
7e7b9e5
docs: remove VA section from writing-queries.rst
Sep 5, 2019
fcba260
docs: fix a couple of links
Sep 2, 2019
1d3cf20
docs: specify sphinx 1.7.9 in readme
Sep 5, 2019
985751b
docs: update layout.html
Sep 5, 2019
1c0db5d
Update docs/language/learn-ql/ql-training.rst
jf205 Sep 5, 2019
20df58f
Update docs/language/learn-ql/ql-training.rst
jf205 Sep 5, 2019
b1d4843
Update docs/language/README.rst
jf205 Sep 5, 2019
a2c87c9
docs: fix typo
Sep 5, 2019
be14eea
docs: slides fix for edge and ff
Sep 6, 2019
358be74
docs: updated slide background
Sep 6, 2019
cf8fbca
docs: improve slide layout for printing
Sep 6, 2019
2a3c6a9
Vale linter: fix typo
shati-patel Sep 6, 2019
f2baf43
docs: fix broken `Expr` links
Sep 9, 2019
3f4f9ec
docs: update readme
Sep 9, 2019
6b10ddf
QL HB: Fix typo [SD-3862]
Sep 9, 2019
ab77d02
QL HB: Expand bindingset example [SD-3863]
Sep 9, 2019
52583d0
QL HB: Explain use of cast [SD-3865]
Sep 9, 2019
4a6ee7f
QL HB: Add predicate call example [SD-3864]
Sep 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions docs/language/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ The QL language documentation currently consists of the following Sphinx project
- ``ql-handbook``–a user-friendly guide to the QL language
- ``ql-spec``–formal descriptions of the QL language and QLDoc comments
- ``support``–the languages and frameworks currently supported in QL analysis
- ``training``–QL for variant analysis training material
- ``ql-training-rst``–QL for variant analysis slide shows
- ``ql-training``–source files for the QL training and variant analysis examples slide decks

Each project contains:

Expand All @@ -37,8 +36,8 @@ This directory also contains any other files, such as templates and stylesheets,
that are used by multiple projects.
Images used in the QL documentation are located in the ``images`` directory.

The ``ql-training-rst`` project contains the source files, themes, and static files
used to generate the QL training presentations.
The ``ql-training`` project contains the source files, themes, and static files
used to generate the QL training and variant analysis presentations.
It uses a different configuration from the other projects, and is built using an
extension specifically designed for HTML slide shows.
For more information, see
Expand All @@ -48,9 +47,12 @@ For more information, see
Building and previewing the QL language documentation
*****************************************************

To build and preview the QL documentation locally, you need to install Sphinx.
To build and preview the QL documentation and QL training presentations locally, you need to
install Sphinx 1.7.9. More recent versions of Sphinx do not work with hieroglyph,
the Sphinx extension that we use to generate HTML slides, as explained below.
For installation options, see https://github.com/sphinx-doc/sphinx.


Using ``sphinx-build``
----------------------

Expand All @@ -69,11 +71,13 @@ For example, to generate the HTML output for a project in the

Add the ``-W`` flag to turn *warnings* into *errors* during the build process.
You can use errors reported during the build to debug problems in your source
code, such as broken internal links and malformed tables.
code, such as broken internal links and malformed tables. You can also check
external links using Sphinx's `external link builder
<http://www.sphinx-doc.org/en/master/usage/builders/index.html#sphinx.builders.linkcheck.CheckExternalLinksBuilder>`__.

Add the ``-a`` flag to regenerate all output files. By default, only files that
have changed are rebuilt.

Using the reStructuredText Extension for Visual Studio Code
-----------------------------------------------------------

Expand All @@ -95,8 +99,10 @@ After installing hieroglyph, you can build the QL training presentations by runn
sphinx-build -b slides . <slides-output>

generates html slide shows in the ``<slides-output>`` directory when run from
the ``ql-training-rst`` source directory.
the ``ql-training`` source directory.

For more information about creating slides for QL training and variant analysis
examples, see the `template slide deck <https://github.com/Semmle/ql/blob/master/docs/language/ql-training/template.rst>`__.

Viewing the current version of the QL language documentation
************************************************************
Expand Down
2 changes: 1 addition & 1 deletion docs/language/global-sphinx-files/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<div class="linkcontainer">
<div class="linkbar">
<a href="https://help.semmle.com/QL/learn-ql/" target="_blank">Learn QL</a>
<a href="https://help.semmle.com/QL/ql-training/training-index.html" target="_blank">QL training</a>
<a href="https://help.semmle.com/QL/learn-ql/ql-training.html" target="_blank">QL for variant analysis</a>
<a href="https://help.semmle.com/QL/ql-tools.html" target="_blank">QL tools</a>
<a href="https://help.semmle.com/QL/ql-explore-queries.html" target="_blank">Queries</a>
<a href="https://help.semmle.com/QL/ql-reference-topics.html" target="_blank">Reference</a>
Expand Down
503 changes: 502 additions & 1 deletion docs/language/learn-ql/cpp/introduce-libraries-cpp.rst

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions docs/language/learn-ql/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ QL queries are easy to write and share–visit the topics below and `our open so
You can also try out QL in the `query console <https://lgtm.com/query>`__ on `LGTM.com <https://lgtm.com>`__.
Here, you can write QL code to query open source projects directly, without having to download snapshots and libraries.

.. _getting-started:

Getting started
***************

Expand All @@ -22,6 +24,18 @@ If you are new to QL, start by looking at the following topics:
about-ql
beginner/ql-tutorials

QL training and variant analysis examples
******************************************

To start learning how to use QL in variant analysis for a specific language, see:

.. toctree::
:maxdepth: -1

ql-training

.. _writing-ql-queries:

Writing QL queries
******************

Expand Down
41 changes: 26 additions & 15 deletions docs/language/learn-ql/python/introduce-libraries-python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ The QL Python library incorporates a large number of classes, each class corresp

- **Syntactic** - classes that represent entities in the Python source code.
- **Control flow** - classes that represent entities from the control flow graphs.
- **Data flow** - classes that assist in performing data flow analyses on Python source code.
- **Type inference** - classes that represent the inferred types of entities in the Python source code.
- **Type inference** - classes that represent the inferred values and types of entities in the Python source code.
- **Taint tracking** - classes that represent the source, sinks and kinds of taint used to implement taint-tracking queries.

Syntactic classes
~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -289,41 +289,52 @@ The classes in the control-flow part of the library are:
- `ControlFlowNode <https://help.semmle.com/qldoc/python/semmle/python/Flow.qll/type.Flow$ControlFlowNode.html>`__ – A control-flow node. There is a one-to-many relation between AST nodes and control-flow nodes.
- `BasicBlock <https://help.semmle.com/qldoc/python/semmle/python/Flow.qll/type.Flow$BasicBlock.html>`__ – A non branching list of control-flow nodes.

Data flow
~~~~~~~~~

The ``SsaVariable`` class represents `static single assignment form <http://en.wikipedia.org/wiki/Static_single_assignment_form>`__ variables (SSA variables). There is a one-to-many relation between variables and SSA variables. The ``SsaVariable`` class provides an accurate and fast means of tracking data flow from definition to use; the ``SsaVariable`` class is an important element for building data flow analyses, including type inference.

Type-inference classes
----------------------

The QL library for Python also supplies some classes for accessing the inferred types of values. The classes ``Object`` and ``ClassObject`` allow you to query the possible classes that an expression may have at runtime. For example, which ``ClassObjects`` are iterable can be determined using the query:
The QL library for Python also supplies some classes for accessing the inferred types of values. The classes ``Value`` and ``ClassValue`` allow you to query the possible classes that an expression may have at runtime. For example, which ``ClassValue``\ s are iterable can be determined using the query:

**Find iterable ``ClassObjects``**
**Find iterable "ClassValue"s**

.. code-block:: ql

import python

from ClassObject cls
from ClassValue cls
where cls.hasAttribute("__iter__")
select cls

➤ `See this in the query console <https://lgtm.com/query/688180005/>`__ This query returns a list of classes for the projects analyzed. If you want to include the results for `builtin classes <http://docs.python.org/library/stdtypes.html>`__, which do not have any Python source code, show the non-source results.
➤ `See this in the query console <https://lgtm.com/query/5151030165280978402/>`__ This query returns a list of classes for the projects analyzed. If you want to include the results for `builtin classes <http://docs.python.org/library/stdtypes.html>`__, which do not have any Python source code, show the non-source results.

Summary
~~~~~~~

- `Object <https://help.semmle.com/qldoc/python/semmle/python/types/Object.qll/type.Object$Object.html>`__
- `Value <https://help.semmle.com/qldoc/python/semmle/python/objects/ObjectAPI.qll/type.ObjectAPI$Value.html>`__

- ``ClassObject``
- ``FunctionObject``
- ``ModuleObject``
- ``ClassValue``
- ``CallableValue``
- ``ModuleValue``

These classes are explained in more detail in :doc:`Tutorial: Points-to analysis and type inference <pointsto-type-infer>`.

Taint-tracking classes
----------------------

The QL library for Python also supplies classes to specify taint-tracking analyses. The ``Configuration`` class can be overrridden to specify a taint-tracking analysis, by specifying source, sinks, sanitizers and additional flow steps. For those analyses that require additional types of taint to be tracked the ``TaintKind`` class can be overridden.


Summary
~~~~~~~

- `TaintKind <https://help.semmle.com/qldoc/python/semmle/python/security/TaintTracking.qll/type.TaintTracking$TaintKind.html>`__
- `Configuration <https://help.semmle.com/qldoc/python/semmle/python/security/TaintTracking.qll/type.TaintTracking$TaintTracking$Configuration.html>`__

These classes are explained in more detail in :doc:`Tutorial: Taint tracking and data flow analysis in Python <taint-tracking>`.


What next?
----------

- Experiment with the worked examples in the QL for Python tutorial topics: :doc:`Functions <functions>`, :doc:`Statements and expressions <statements-expressions>`, :doc:`Control flow <control-flow>` and :doc:`Points-to analysis and type inference <pointsto-type-infer>`.
- Experiment with the worked examples in the QL for Python tutorial topics: :doc:`Functions <functions>`, :doc:`Statements and expressions <statements-expressions>`, :doc:`Control flow <control-flow>`, :doc:`Points-to analysis and type inference <pointsto-type-infer>` and :doc:`Taint tracking and data flow analysis in Python <taint-tracking>`.
- Find out more about QL in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__ and `QL language specification <https://help.semmle.com/QL/QLLanguageSpecification.html>`__.
14 changes: 3 additions & 11 deletions docs/language/learn-ql/python/statements-expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ Each kind of Python expression has its own class. Here is the full class hierarc
- ``BoolExpr`` – Short circuit logical operations, ``x and y``, ``x or y``
- ``Bytes`` – A bytes literal, ``b"x"`` or (in Python 2) ``"x"``
- ``Call`` – A function call, ``f(arg)``
- ``ClassExpr`` – An artificial expression representing the right hand side a ``ClassDef`` assignment
- ``Compare`` – A comparison operation, ``0 < x < 10``
- ``Dict`` – A dictionary literal, ``{'a': 2}``
- ``DictComp`` – A dictionary comprehension, ``{k: v for ...}``
- ``Ellipsis`` – An ellipsis expression, ``...``
- ``FunctionExpr`` – An artificial expression representing the right hand side a ``FunctionDef`` assignment
- ``GeneratorExp`` – A generator expression
- ``IfExp`` – A conditional expression, ``x if cond else y``
- ``ImportExpr`` – An artificial expression representing the module imported
Expand Down Expand Up @@ -255,9 +253,9 @@ checks that the value of the attribute (the expression to the left of the dot in
Class and function definitions
------------------------------

As Python is a dynamically typed language, class, and function definitions are executable statements. This means that a class statement is both a statement and a scope containing statements. To represent this cleanly the class definition is broken into a number of parts. At runtime, when a class definition is executed a class object is created and then assigned to a variable of the same name in the scope enclosing the class. This class is created from a code-object representing the source code for the body of the class. To represent this the ``ClassDef`` class (which represents a ``class`` statement) subclasses ``Assign``. The right hand side of the ``ClassDef`` is a ``ClassExpr`` representing the creation of the class. The ``Class`` class, which represents the body of the class, can be accessed via the ``ClassExpr.getInnerScope()``
As Python is a dynamically typed language, class, and function definitions are executable statements. This means that a class statement is both a statement and a scope containing statements. To represent this cleanly the class definition is broken into a number of parts. At runtime, when a class definition is executed a class object is created and then assigned to a variable of the same name in the scope enclosing the class. This class is created from a code-object representing the source code for the body of the class. To represent this the ``ClassDef`` class (which represents a ``class`` statement) subclasses ``Assign``. The ``Class`` class, which represents the body of the class, can be accessed via the ``ClassDef.getDefinedClass()``

``FunctionDef``, ``FunctionExpr`` and ``Function`` are handled similarly.
``FunctionDef``, ``Function`` are handled similarly.

Here is the relevant part of the class hierarchy:

Expand All @@ -268,12 +266,6 @@ Here is the relevant part of the class hierarchy:
- ``ClassDef``
- ``FunctionDef``

- ``Expr``

- ``ClassExp``

- ``FunctionExpr``

- ``Scope``

- ``Class``
Expand All @@ -283,4 +275,4 @@ What next?
----------

- Experiment with the worked examples in the QL for Python tutorial topics: :doc:`Control flow <control-flow>`, :doc:`Points-to analysis and type inference <pointsto-type-infer>`.
- Find out more about QL in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__ and `QL language specification <https://help.semmle.com/QL/QLLanguageSpecification.html>`__.
- Find out more about QL in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__ and `QL language specification <https://help.semmle.com/QL/QLLanguageSpecification.html>`__.
6 changes: 3 additions & 3 deletions docs/language/learn-ql/python/taint-tracking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The sink is defined by using a custom ``TaintTracking::Sink`` class.
class UnsafeSink extends TaintTracking::Sink {

UnsafeSink() {
exists(FunctionObject unsafe |
exists(FunctionValue unsafe |
unsafe.getName() = "unsafe" and
unsafe.getACall().(CallNode).getAnArg() = this
)
Expand Down Expand Up @@ -172,7 +172,7 @@ Thus, our example query becomes:
class UnsafeSink extends TaintTracking::Sink {

UnsafeSink() {
exists(FunctionObject unsafe |
exists(FunctionValue unsafe |
unsafe.getName() = "unsafe" and
unsafe.getACall().(CallNode).getAnArg() = this
)
Expand Down Expand Up @@ -255,4 +255,4 @@ What next?
----------

- Experiment with the worked examples in the QL for Python tutorial topics: :doc:`Control flow <control-flow>`, and :doc:`Points-to analysis and type inference <pointsto-type-infer>`.
- Find out more about QL in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__ and `QL language specification <https://help.semmle.com/QL/QLLanguageSpecification.html>`__.
- Find out more about QL in the `QL language handbook <https://help.semmle.com/QL/ql-handbook/index.html>`__ and `QL language specification <https://help.semmle.com/QL/QLLanguageSpecification.html>`__.
Loading