-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiterals.qll
More file actions
135 lines (119 loc) · 3.33 KB
/
Literals.qll
File metadata and controls
135 lines (119 loc) · 3.33 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* Literals in the AST.
*/
private import AstNodes
private import Expr
private import Idents
private import Variables
private import internal.AstNodes
private import internal.TreeSitter
private import internal.Literals
private import internal.Array
private import internal.Boolean
private import internal.Null
private import internal.NullableReturnType
private import internal.Number
private import internal.String
private import internal.StringContent
private import internal.SubscriptExpression
/**
* A literal in the AST.
*/
final class Literals extends AstNode instanceof LiteralsImpl { }
/**
* A Array unknown AST node.
*/
class Array extends Literals instanceof ArrayImpl {
Expr getElements() { result = ArrayImpl.super.getElements() }
Expr getElement(int index) { result = ArrayImpl.super.getElement(index) }
}
/**
* A SubscriptExpression expression in the AST.
*/
class SubscriptExpression extends Expr instanceof SubscriptExpressionImpl {
/**
* Gets the index of the subscript expression.
*/
Expr getIndex() { result = SubscriptExpressionImpl.super.getIndex() }
/**
* Gets the object of the subscript expression.
*/
Idents getIdentifier() { result = SubscriptExpressionImpl.super.getObject() }
/**
* Gets the array that this subscript expression is indexing into.
* This is equivalent to the variable declaration that contains the
* subscript expression.
*/
Array getArray() {
exists(VariableDeclaration variable |
variable.getEnclosingCfgScope() = this.getEnclosingCfgScope() and
variable.getIdentifier().getName() = this.getIdentifier().getName()
|
result = variable.getInitializer()
)
}
}
/**
* A Boolean unknown AST node.
*/
class Boolean extends Literals instanceof BooleanImpl {
boolean getBool() {
exists(string bl | bl = BooleanImpl.super.getValue().toLowerCase() |
bl = "true" and
result = true
or
bl = "false" and
result = false
)
}
}
/**
* An alias for the Boolean literal in the AST.
*/
class BooleanLiteral = Boolean;
/**
* A Null literal in the AST.
*/
final class NullLiteral extends Literals instanceof NullImpl { }
/**
* A NullableReturnType literal in the AST.
*/
final class NullableReturnTypeLiteral extends Literals instanceof NullableReturnTypeImpl { }
/**
* A Number unknown AST node.
*/
class Number extends Literals instanceof NumberImpl {
int getValue() { result = NumberImpl.super.getValue().toInt() }
}
class String = StringLiteral;
/**
* A String literal in the AST.
*/
class StringLiteral extends Literals instanceof StringImpl {
/**
* Gets the value of the string literal.
*/
string getValue() {
result =
concat(int index, string output |
exists(StringContentLiteral content |
content = StringImpl.super.getChild(index) and
output = content.getValue()
)
or
exists(Interpolation interpolation |
interpolation = StringImpl.super.getChild(index) and
output = interpolation.getValue()
)
|
output order by index
)
}
Interpolation getInterpolation(int index) { result = StringImpl.super.getChild(index) }
}
/**
* A StringContent literal in the AST.
*/
class StringContentLiteral extends Literals instanceof StringContentImpl {
string getValue() { result = StringContentImpl.super.getValue() }
}