Skip to content

Commit c276d0b

Browse files
Merge pull request #1770 from geoffw0/qldoceg7
CPP: Add syntax examples to QLDoc in various files
2 parents 30921d5 + 675e1cc commit c276d0b

File tree

6 files changed

+81
-22
lines changed

6 files changed

+81
-22
lines changed

cpp/ql/src/semmle/code/cpp/Comments.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import semmle.code.cpp.Location
22
import semmle.code.cpp.Element
33

44
/**
5-
* A C/C++ comment.
5+
* A C/C++ comment. For example the comment in the following code:
6+
* ```
7+
* // C++ style single-line comment
8+
* ```
9+
* or a C style comment (which starts with `/*`).
610
*/
711
class Comment extends Locatable, @comment {
812
override string toString() { result = this.getContents() }
@@ -21,7 +25,10 @@ class CStyleComment extends Comment {
2125
}
2226

2327
/**
24-
* A CPP style comment (one which starts with `//`).
28+
* A CPP style comment. For example the comment in the following code:
29+
* ```
30+
* // C++ style single-line comment
31+
* ```
2532
*/
2633
class CppStyleComment extends Comment {
2734
CppStyleComment() {

cpp/ql/src/semmle/code/cpp/Field.qll

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@ import semmle.code.cpp.Enum
33
import semmle.code.cpp.exprs.Access
44

55
/**
6-
* A C structure member or C++ non-static member variable.
6+
* A C structure member or C++ non-static member variable. For example the
7+
* member variable `m` in the following code (but not `s`):
8+
* ```
9+
* class MyClass {
10+
* public:
11+
* int m;
12+
* static int s;
13+
* };
14+
* ```
15+
*
16+
* This does not include static member variables in C++. To include static member
17+
* variables, use `MemberVariable` instead of `Field`.
718
*/
819
class Field extends MemberVariable {
920

@@ -33,12 +44,13 @@ class Field extends MemberVariable {
3344
/**
3445
* Holds if the field can be initialized as part of an initializer list. For
3546
* example, in:
36-
*
47+
* ```
3748
* struct S {
3849
* unsigned int a : 5;
3950
* unsigned int : 5;
4051
* unsigned int b : 5;
4152
* };
53+
* ```
4254
*
4355
* Fields `a` and `b` are initializable, but the unnamed bitfield is not.
4456
*/
@@ -65,9 +77,13 @@ class Field extends MemberVariable {
6577
}
6678

6779
/**
68-
* A C structure member or C++ member variable declared with an explicit size in bits.
69-
*
70-
* Syntactically, this looks like `int x : 3` in `struct S { int x : 3; };`.
80+
* A C structure member or C++ member variable declared with an explicit size
81+
* in bits. For example the member variable `x` in the following code:
82+
* ```
83+
* struct MyStruct {
84+
* int x : 3;
85+
* };
86+
* ```
7187
*/
7288
class BitField extends Field {
7389
BitField() { bitfield(underlyingElement(this),_,_) }

cpp/ql/src/semmle/code/cpp/FriendDecl.qll

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import semmle.code.cpp.Declaration
22
private import semmle.code.cpp.internal.ResolveClass
33

44
/**
5-
* A C++ friend declaration [N4140 11.3].
6-
* For example:
5+
* A C++ friend declaration [N4140 11.3]. For example the two friend
6+
* declarations in class `A` of the following code:
7+
* ```
8+
* class A {
9+
* friend void f(int);
10+
* friend class X;
11+
* };
712
*
8-
* class A {
9-
* friend void f(int);
10-
* friend class X;
11-
* };
12-
*
13-
* void f(int x) { ... }
14-
* class X { ... };
13+
* void f(int x) { ... }
14+
* class X { ... };
15+
* ```
1516
*/
1617
class FriendDecl extends Declaration, @frienddecl {
1718
/**

cpp/ql/src/semmle/code/cpp/Include.qll

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import semmle.code.cpp.Preprocessor
22

33
/**
44
* A C/C++ `#include`, `#include_next`, or `#import` preprocessor
5-
* directive.
5+
* directive. The following example contains four different `Include`
6+
* directives:
7+
* ```
8+
* #include "header.h"
9+
* #include <string>
10+
* #include_next <header2.h>
11+
* #import <header3.h>
12+
* ```
613
*/
714
class Include extends PreprocessorDirective, @ppd_include {
815
override string toString() { result = "#include " + this.getIncludeText() }
@@ -37,7 +44,10 @@ class Include extends PreprocessorDirective, @ppd_include {
3744

3845
/**
3946
* A `#include_next` preprocessor directive (a non-standard extension to
40-
* C/C++).
47+
* C/C++). For example the following code contains one `IncludeNext` directive:
48+
* ```
49+
* #include_next <header2.h>
50+
* ```
4151
*/
4252
class IncludeNext extends Include, @ppd_include_next {
4353
override string toString() {
@@ -47,7 +57,11 @@ class IncludeNext extends Include, @ppd_include_next {
4757

4858
/**
4959
* A `#import` preprocessor directive (used heavily in Objective C, and
50-
* supported by GCC as an extension in C).
60+
* supported by GCC as an extension in C). For example the following code
61+
* contains one `Import` directive:
62+
* ```
63+
* #import <header3.h>
64+
* ```
5165
*/
5266
class Import extends Include, @ppd_objc_import {
5367
override string toString() {

cpp/ql/src/semmle/code/cpp/Macro.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import cpp
22

33
/**
4-
* A macro.
4+
* A macro. For example, the macro `MYMACRO` in the following code:
5+
* ```
6+
* #define MYMACRO 1
7+
* ```
58
*/
69
class Macro extends PreprocessorDirective, @ppd_define {
710

cpp/ql/src/semmle/code/cpp/exprs/Lambda.qll

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import semmle.code.cpp.exprs.Expr
22
import semmle.code.cpp.Class
33

44
/**
5-
* A C++11 lambda expression, such as `[&amp;, =y](int x) mutable -> double {return z = (y += x);}`.
5+
* A C++11 lambda expression, for example the expression initializing `a` in
6+
* the following code:
7+
* ```
8+
* auto a = [x, y](int z) -> int {
9+
* return x + y + z;
10+
* };
11+
* ```
612
*
713
* The type given by `getType()` will be an instance of `Closure`.
814
*/
@@ -71,6 +77,12 @@ class LambdaExpression extends Expr, @lambdaexpr {
7177

7278
/**
7379
* A class written by the compiler to be the type of a C++11 lambda expression.
80+
* For example the variable `a` in the following code has a closure type:
81+
* ```
82+
* auto a = [x, y](int z) -> int {
83+
* return x + y + z;
84+
* };
85+
* ```
7486
*/
7587
class Closure extends Class {
7688
Closure() {
@@ -96,7 +108,13 @@ class Closure extends Class {
96108
}
97109

98110
/**
99-
* Information about a value captured as part of a lambda expression.
111+
* Information about a value captured as part of a lambda expression. For
112+
* example in the following code, information about `x` and `y` is captured:
113+
* ```
114+
* auto a = [x, y](int z) -> int {
115+
* return x + y + z;
116+
* };
117+
* ```
100118
*/
101119
class LambdaCapture extends Locatable, @lambdacapture {
102120
override string toString() {

0 commit comments

Comments
 (0)