@@ -4,7 +4,20 @@ import semmle.code.cpp.Initializer
44private import semmle.code.cpp.internal.ResolveClass
55
66/**
7- * A C/C++ variable.
7+ * A C/C++ variable. For example in the following code there are four
8+ * variables, `a`, `b`, `c` and `d`:
9+ * ```
10+ * extern int a;
11+ * int a;
12+ *
13+ * void myFunction(int b) {
14+ * int c;
15+ * }
16+ *
17+ * namespace N {
18+ * int d;
19+ * }
20+ * ```
821 *
922 * For local variables, there is a one-to-one correspondence between
1023 * `Variable` and `VariableDeclarationEntry`.
@@ -162,7 +175,21 @@ class Variable extends Declaration, @variable {
162175}
163176
164177/**
165- * A particular declaration or definition of a C/C++ variable.
178+ * A particular declaration or definition of a C/C++ variable. For example in
179+ * the following code there are five variable declaration entries - two for
180+ * `a`, and one each for `b`, `c` and `d`:
181+ * ```
182+ * extern int a;
183+ * int a;
184+ *
185+ * void myFunction(int b) {
186+ * int c;
187+ * }
188+ *
189+ * namespace N {
190+ * int d;
191+ * }
192+ * ```
166193 */
167194class VariableDeclarationEntry extends DeclarationEntry , @var_decl {
168195 override Variable getDeclaration ( ) { result = getVariable ( ) }
@@ -183,13 +210,13 @@ class VariableDeclarationEntry extends DeclarationEntry, @var_decl {
183210 * because the parameter may have a different name in the declaration
184211 * than in the definition. For example:
185212 *
186- * ```
187- * // Declaration. Parameter is named "x".
188- * int f(int x);
213+ * ```
214+ * // Declaration. Parameter is named "x".
215+ * int f(int x);
189216 *
190- * // Definition. Parameter is named "y".
191- * int f(int y) { return y; }
192- * ```
217+ * // Definition. Parameter is named "y".
218+ * int f(int y) { return y; }
219+ * ```
193220 */
194221 override string getName ( ) { var_decls ( underlyingElement ( this ) , _, _, result , _) and result != "" }
195222
@@ -215,7 +242,13 @@ class VariableDeclarationEntry extends DeclarationEntry, @var_decl {
215242
216243/**
217244 * A parameter as described within a particular declaration or definition
218- * of a C/C++ function.
245+ * of a C/C++ function. For example the declaration of `a` in the following
246+ * code:
247+ * ```
248+ * void myFunction(int a) {
249+ * int b;
250+ * }
251+ * ```
219252 */
220253class ParameterDeclarationEntry extends VariableDeclarationEntry {
221254 ParameterDeclarationEntry ( ) { param_decl_bind ( underlyingElement ( this ) , _, _) }
@@ -272,8 +305,16 @@ class ParameterDeclarationEntry extends VariableDeclarationEntry {
272305
273306/**
274307 * A C/C++ variable with block scope [N4140 3.3.3]. In other words, a local
275- * variable or a function parameter. Local variables can be static; use the
276- * `isStatic` member predicate to detect those.
308+ * variable or a function parameter. For example, the variables `a` and `b` in
309+ * the following code:
310+ * ```
311+ * void myFunction(int a) {
312+ * int b;
313+ * }
314+ * ```
315+ *
316+ * Local variables can be static; use the `isStatic` member predicate to
317+ * detect those.
277318 */
278319class LocalScopeVariable extends Variable , @localscopevariable {
279320 /** Gets the function to which this variable belongs. */
@@ -292,6 +333,13 @@ deprecated class StackVariable extends Variable {
292333/**
293334 * A C/C++ local variable. In other words, any variable that has block
294335 * scope [N4140 3.3.3], but is not a parameter of a `Function` or `CatchBlock`.
336+ * For example the variable `b` in the following code:
337+ * ```
338+ * void myFunction(int a) {
339+ * int b;
340+ * }
341+ * ```
342+ *
295343 * Local variables can be static; use the `isStatic` member predicate to detect
296344 * those.
297345 *
@@ -310,7 +358,15 @@ class LocalVariable extends LocalScopeVariable, @localvariable {
310358}
311359
312360/**
313- * A C/C++ variable which has global scope or namespace scope.
361+ * A C/C++ variable which has global scope or namespace scope. For example the
362+ * variables `a` and `b` in the following code:
363+ * ```
364+ * int a;
365+ *
366+ * namespace N {
367+ * int b;
368+ * }
369+ * ```
314370 */
315371class GlobalOrNamespaceVariable extends Variable , @globalvariable {
316372 override string getName ( ) { globalvariables ( underlyingElement ( this ) , _, result ) }
@@ -321,7 +377,15 @@ class GlobalOrNamespaceVariable extends Variable, @globalvariable {
321377}
322378
323379/**
324- * A C/C++ variable which has namespace scope.
380+ * A C/C++ variable which has namespace scope. For example the variable `b`
381+ * in the following code:
382+ * ```
383+ * int a;
384+ *
385+ * namespace N {
386+ * int b;
387+ * }
388+ * ```
325389 */
326390class NamespaceVariable extends GlobalOrNamespaceVariable {
327391 NamespaceVariable ( ) {
@@ -330,7 +394,15 @@ class NamespaceVariable extends GlobalOrNamespaceVariable {
330394}
331395
332396/**
333- * A C/C++ variable which has global scope.
397+ * A C/C++ variable which has global scope. For example the variable `a`
398+ * in the following code:
399+ * ```
400+ * int a;
401+ *
402+ * namespace N {
403+ * int b;
404+ * }
405+ * ```
334406 *
335407 * Note that variables declared in anonymous namespaces have namespace scope,
336408 * even though they are accessed in the same manner as variables declared in
@@ -341,7 +413,15 @@ class GlobalVariable extends GlobalOrNamespaceVariable {
341413}
342414
343415/**
344- * A C structure member or C++ member variable.
416+ * A C structure member or C++ member variable. For example the member
417+ * variables `m` and `s` in the following code:
418+ * ```
419+ * class MyClass {
420+ * public:
421+ * int m;
422+ * static int s;
423+ * };
424+ * ```
345425 *
346426 * This includes static member variables in C++. To exclude static member
347427 * variables, use `Field` instead of `MemberVariable`.
@@ -395,7 +475,12 @@ deprecated class FunctionPointerMemberVariable extends MemberVariable {
395475}
396476
397477/**
398- * A C++14 variable template.
478+ * A C++14 variable template. For example, in the following code the variable
479+ * template `v` defines a family of variables:
480+ * ```
481+ * template<class T>
482+ * T v;
483+ * ```
399484 */
400485class TemplateVariable extends Variable {
401486 TemplateVariable ( ) { is_variable_template ( underlyingElement ( this ) ) }
@@ -410,7 +495,24 @@ class TemplateVariable extends Variable {
410495 * A non-static local variable or parameter that is not part of an
411496 * uninstantiated template. Uninstantiated templates are purely syntax, and
412497 * only on instantiation will they be complete with information about types,
413- * conversions, call targets, etc.
498+ * conversions, call targets, etc. For example in the following code, the
499+ * variables `a` in `myFunction` and `b` in the instantiation
500+ * `myTemplateFunction<int>`, but not `b` in the template
501+ * `myTemplateFunction<T>`:
502+ * ```
503+ * void myFunction() {
504+ * T a;
505+ * }
506+ *
507+ * template<type T>
508+ * void myTemplateFunction() {
509+ * T b;
510+ * }
511+ *
512+ * ...
513+ *
514+ * myTemplateFunction<int>();
515+ * ```
414516 */
415517class SemanticStackVariable extends LocalScopeVariable {
416518 SemanticStackVariable ( ) {
0 commit comments