FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/cpp/ql/lib/semmle/code/cpp/Initializer.qll at codeql-cli/v2.27.1 · github/codeql · GitHub
github
codeql
Repository navigation
Code
Issues
1k
(1k)
Pull requests
483
(483)
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
cpp
/
ql
/
lib
/
semmle
/
code
/
cpp
/
Initializer.qll
Copy path
More file actions
More file actions
Latest commit
History
History
History
68 lines (57 loc) · 2.14 KB
Breadcrumbs
codeql
/
cpp
/
ql
/
lib
/
semmle
/
code
/
cpp
/
Initializer.qll
Copy path
File metadata and controls
68 lines (57 loc) · 2.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Provides the `Initializer` class, representing C/C++ declaration initializers.
*/
import
semmle.code.cpp.controlflow.ControlFlowGraph
/**
* A C/C++ declaration initializer. For example the initializers `1`, `2` and
* `3` in the following code:
* ```
* int myVariable = 1;
*
* enum myEnum {
* MYENUMCONST = 2
* };
*
* void myFunction(int param = 3) {
* ...
* }
* ```
* But _not_ `4` in the following code:
* ```
* int myUninitializedVariable;
* myUninitializedVariable = 4;
* ```
* Instead, this is an `Assignment`.
*/
class
Initializer
extends
ControlFlowNode
,
@initialiser
{
override
Location
getLocation
(
)
{
initialisers
(
underlyingElement
(
this
)
,
_
,
_
,
result
)
}
override
string
getAPrimaryQlClass
(
)
{
result
=
"Initializer"
}
/** Holds if this initializer is explicit in the source. */
override
predicate
fromSource
(
)
{
not
this
.
getLocation
(
)
instanceof
UnknownLocation
}
override
string
toString
(
)
{
if
exists
(
this
.
getDeclaration
(
)
)
then
result
=
"initializer for "
+
max
(
this
.
getDeclaration
(
)
.
getName
(
)
)
else
result
=
"initializer"
}
/** Gets the variable or enum constant being initialized. */
Declaration
getDeclaration
(
)
{
initialisers
(
underlyingElement
(
this
)
,
unresolveElement
(
result
)
,
_
,
_
)
}
/** Gets the initializing expression. */
Expr
getExpr
(
)
{
initialisers
(
underlyingElement
(
this
)
,
_
,
unresolveElement
(
result
)
,
_
)
}
/** Gets the function containing this control-flow node. */
override
Function
getControlFlowScope
(
)
{
result
=
this
.
getExpr
(
)
.
getEnclosingFunction
(
)
}
override
Stmt
getEnclosingStmt
(
)
{
result
=
this
.
getExpr
(
)
.
getEnclosingStmt
(
)
}
/** Holds if the initializer used the C++ braced initializer notation. */
predicate
isBraced
(
)
{
braced_initialisers
(
underlyingElement
(
this
)
)
}
/** Holds if this initializer is generated by the compiler. */
predicate
isCompilerGenerated
(
)
{
exists
(
Variable
v
|
v
=
this
.
getDeclaration
(
)
and
// We require the variable to be an orphan to not mark the initializer
// from a desugared ranged for loop as compiler generated.
orphaned_variables
(
unresolveElement
(
v
)
,
_
)
and
v
.
isCompilerGenerated
(
)
)
}
}
Back
|
FazBrowse Home
|
New Git URL