Skip to content

Commit 2aefcbd

Browse files
author
Shati Patel
committed
Docs: Update C/C++
1 parent 6cf8f06 commit 2aefcbd

File tree

9 files changed

+55
-53
lines changed

9 files changed

+55
-53
lines changed

docs/language/learn-ql/cpp/conversions-classes.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Tutorial: Conversions and classes
44
Overview
55
--------
66

7-
This topic contains worked examples of how to write queries using the standard QL library classes for C/C++ conversions and classes.
7+
This topic contains worked examples of how to write queries using the CodeQL library classes for C/C++ conversions and classes.
88

99
Conversions
1010
-----------
1111

12-
Let us take a look at the QL ``Conversion`` class in the standard library:
12+
Let us take a look at the ``Conversion`` class in the standard library:
1313

1414
- ``Expr``
1515

@@ -128,26 +128,26 @@ Unlike the earlier versions of the query, this query would return each side of t
128128

129129
Note
130130

131-
In general, QL predicates named ``getAXxx`` exploit the ability to return multiple results (multiple instances of ``Xxx``) whereas plain ``getXxx`` predicates usually return at most one specific instance of ``Xxx``.
131+
In general, predicates named ``getAXxx`` exploit the ability to return multiple results (multiple instances of ``Xxx``) whereas plain ``getXxx`` predicates usually return at most one specific instance of ``Xxx``.
132132

133133
Classes
134134
-------
135135

136-
Next we're going to look at C++ classes, using the following QL classes:
136+
Next we're going to look at C++ classes, using the following CodeQL classes:
137137

138138
- ``Type``
139139

140-
- ``UserType``—includes classes, typedefs and enums
140+
- ``UserType``—includes classes, typedefs, and enums
141141

142142
- ``Class``—a class or struct
143143

144-
- ``Struct``—a struct, which is treated as a subtype of Class in QL.
144+
- ``Struct``—a struct, which is treated as a subtype of ``Class``
145145
- ``TemplateClass``—a C++ class template
146146

147147
Finding derived classes
148148
~~~~~~~~~~~~~~~~~~~~~~~
149149

150-
We want to create a query that checks for destructors that should be ``virtual``. Specifically, when a class and a class derived from it both have destructors, the base class destructor should generally be virtual. This ensures that the derived class destructor is always invoked. A ``Destructor`` in QL is a subtype of ``MemberFunction``:
150+
We want to create a query that checks for destructors that should be ``virtual``. Specifically, when a class and a class derived from it both have destructors, the base class destructor should generally be virtual. This ensures that the derived class destructor is always invoked. In the CodeQL library, ``Destructor`` is a subtype of ``MemberFunction``:
151151

152152
- ``Function``
153153

@@ -221,13 +221,13 @@ Our last change is to use ``Function.isVirtual()`` to find cases where the base
221221

222222
That completes the query.
223223

224-
There is a similar built-in LGTM `query <https://lgtm.com/rules/2158670642/>`__ that finds classes in a C/C++ project with virtual functions but no virtual destructor. You can take a look at the QL code for this query by clicking **Open in query console** at the top of that page.
224+
There is a similar built-in LGTM `query <https://lgtm.com/rules/2158670642/>`__ that finds classes in a C/C++ project with virtual functions but no virtual destructor. You can take a look at the code for this query by clicking **Open in query console** at the top of that page.
225225

226226
What next?
227227
----------
228228

229229
- Explore other ways of querying classes using examples from the `C/C++ cookbook <https://help.semmle.com/wiki/label/CBCPP/class>`__.
230230
- Take a look at the :doc:`Analyzing data flow in C/C++ <dataflow>` tutorial.
231-
- Try the worked examples in the following topics: :doc:`Example: Checking that constructors initialize all private fields <private-field-initialization>` and :doc:`Example: Checking for allocations equal to 'strlen(string)' without space for a null terminator <zero-space-terminator>`.
231+
- Try the worked examples in the following topics: :doc:`Example: Checking that constructors initialize all private fields <private-field-initialization>`, and :doc:`Example: Checking for allocations equal to 'strlen(string)' without space for a null terminator <zero-space-terminator>`.
232232
- 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/ql-spec/language.html>`__.
233233
- Learn more about the query console in `Using the query console <https://lgtm.com/help/lgtm/using-query-console>`__.

docs/language/learn-ql/cpp/dataflow.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Analyzing data flow in C/C++
44
Overview
55
--------
66

7-
This topic describes how data flow analysis is implemented in the QL for C/C++ library and includes examples to help you write your own data flow queries.
8-
The following sections describe how to utilize the QL libraries for local data flow, global data flow and taint tracking.
7+
This topic describes how data flow analysis is implemented in the CodeQL libraries for C/C++ and includes examples to help you write your own data flow queries.
8+
The following sections describe how to utilize the libraries for local data flow, global data flow, and taint tracking.
99

10-
For a more general introduction to modeling data flow in QL, see :doc:`Introduction to data flow analysis in QL <../intro-to-data-flow>`.
10+
For a more general introduction to modeling data flow, see :doc:`Introduction to data flow analysis with CodeQL <../intro-to-data-flow>`.
1111

1212
Local data flow
1313
---------------

docs/language/learn-ql/cpp/expressions-types.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Tutorial: Expressions, types and statements
44
Overview
55
--------
66

7-
This topic contains worked examples of how to write queries using the standard QL library classes for C/C++ expressions, types, and statements.
7+
This topic contains worked examples of how to write queries using the standard CodeQL library classes for C/C++ expressions, types, and statements.
88

99
Expressions and types
1010
---------------------
1111

12-
Each part of an expression in C becomes an instance of the QL ``Expr`` class. For example, the C code ``x = x + 1`` becomes an ``AssignExpr``, an ``AddExpr``, two instances of ``VariableAccess`` and a ``Literal``. All of these QL classes extend ``Expr``.
12+
Each part of an expression in C becomes an instance of the ``Expr`` class. For example, the C code ``x = x + 1`` becomes an ``AssignExpr``, an ``AddExpr``, two instances of ``VariableAccess`` and a ``Literal``. All of these CodeQL classes extend ``Expr``.
1313

1414
Finding assignments to zero
1515
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -26,15 +26,15 @@ In the following example we find instances of ``AssignExpr`` which assign the co
2626
2727
➤ `See this in the query console <https://lgtm.com/query/1505908086530/>`__
2828

29-
The ``where`` clause in this example gets the expression on the right side of the assignment, ``getRValue()``, and compares it with zero. Notice that there are no checks to make sure that the right side of the assignment is an integer or that it has a value (that is, it is compile-time constant, rather than a variable). For expressions where either of these assumptions is wrong, the associated QL predicate simply does not return anything and the ``where`` clause will not produce a result. You could think of it as if there is an implicit ``exists(e.getRValue().getValue().toInt())`` at the beginning of this line.
29+
The ``where`` clause in this example gets the expression on the right side of the assignment, ``getRValue()``, and compares it with zero. Notice that there are no checks to make sure that the right side of the assignment is an integer or that it has a value (that is, it is compile-time constant, rather than a variable). For expressions where either of these assumptions is wrong, the associated predicate simply does not return anything and the ``where`` clause will not produce a result. You could think of it as if there is an implicit ``exists(e.getRValue().getValue().toInt())`` at the beginning of this line.
3030

3131
It is also worth noting that the query above would find this C code:
3232

3333
.. code-block:: cpp
3434
3535
yPtr = NULL;
3636
37-
This is because the snapshot contains a representation of the code base after the preprocessor transforms have run (for more information, see `Database generation <https://lgtm.com/help/lgtm/generate-database>`__). This means that any macro invocations, such as the ``NULL`` define used here, are expanded during the creation of the snapshot. If you want to write queries about macros then there are some special library classes that have been designed specifically for this purpose (for example, the ``Macro``, ``MacroInvocation`` classes and predicates like ``Element.isInMacroExpansion()``). In this case, it is good that macros are expanded, but we do not want to find assignments to pointers.
37+
This is because the database contains a representation of the code base after the preprocessor transforms have run (for more information, see `Database generation <https://lgtm.com/help/lgtm/generate-database>`__). This means that any macro invocations, such as the ``NULL`` define used here, are expanded during the creation of the database. If you want to write queries about macros then there are some special library classes that have been designed specifically for this purpose (for example, the ``Macro``, ``MacroInvocation`` classes and predicates like ``Element.isInMacroExpansion()``). In this case, it is good that macros are expanded, but we do not want to find assignments to pointers.
3838

3939
Finding assignments of 0 to an integer
4040
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/language/learn-ql/cpp/function-classes.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Tutorial: Function classes
44
Overview
55
--------
66

7-
The standard QL library for C and C++ represents functions using the ``Function`` class (see :doc:`Introducing the C/C++ libraries <introduce-libraries-cpp>`).
7+
The standard CodeQL library for C and C++ represents functions using the ``Function`` class (see :doc:`Introducing the C/C++ libraries <introduce-libraries-cpp>`).
88

99
The example queries in this topic explore some of the most useful library predicates for querying functions.
1010

1111
Finding all static functions
1212
----------------------------
1313

14-
Using the member predicate ``Function.isStatic()`` we can list all of the static functions in a snapshot:
14+
Using the member predicate ``Function.isStatic()`` we can list all the static functions in a database:
1515

1616
.. code-block:: ql
1717
@@ -26,7 +26,7 @@ This query is very general, so there are probably too many results to be interes
2626
Finding functions that are not called
2727
-------------------------------------
2828

29-
It might be more interesting to find functions that are not called, using the standard QL ``FunctionCall`` class from the **abstract syntax tree** category (see :doc:`Introducing the C/C++ libraries <introduce-libraries-cpp>`). The ``FunctionCall`` class can be used to identify places where a function is actually used, and it is related to ``Function`` through the ``FunctionCall.getTarget()`` predicate.
29+
It might be more interesting to find functions that are not called, using the standard CodeQL ``FunctionCall`` class from the **abstract syntax tree** category (see :doc:`Introducing the C/C++ libraries <introduce-libraries-cpp>`). The ``FunctionCall`` class can be used to identify places where a function is actually used, and it is related to ``Function`` through the ``FunctionCall.getTarget()`` predicate.
3030

3131
.. code-block:: ql
3232
@@ -58,9 +58,9 @@ You can modify the query to remove functions where a function pointer is used to
5858

5959
This query returns fewer results. However, if you examine the results then you can probably still find potential refinements.
6060

61-
For example, there is a more complicated LGTM `query <https://lgtm.com/rules/2152580467/>`__ that finds unused static functions. To see the QL code for this query, click **Open in query console** at the top of the page.
61+
For example, there is a more complicated LGTM `query <https://lgtm.com/rules/2152580467/>`__ that finds unused static functions. To see the code for this query, click **Open in query console** at the top of the page.
6262

63-
You can explore the definition of an element in the standard QL libraries and see what predicates are available. Use the keyboard **F3** button to open the definition of any element. Alternatively, hover over the element and click **Jump to definition** in the tooltip displayed. The library file is opened in a new tab with the definition highlighted.
63+
You can explore the definition of an element in the standard libraries and see what predicates are available. Use the keyboard **F3** button to open the definition of any element. Alternatively, hover over the element and click **Jump to definition** in the tooltip displayed. The library file is opened in a new tab with the definition highlighted.
6464

6565
Finding a specific function
6666
---------------------------

0 commit comments

Comments
 (0)