Skip to content

Commit 02824fb

Browse files
committed
unified: Add getName() convenience predicates
1 parent 24d914c commit 02824fb

6 files changed

Lines changed: 87 additions & 14 deletions

File tree

unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,27 +239,27 @@ private module Input implements InputSig1, InputSig2 {
239239

240240
class Label extends string {
241241
Label() {
242-
any(LabeledStmt l).getLabelNameNode().getValue() = this or
243-
any(BreakExpr b).getLabelNameNode().getValue() = this or
244-
any(ContinueExpr c).getLabelNameNode().getValue() = this
242+
any(LabeledStmt l).getLabelName() = this or
243+
any(BreakExpr b).getLabelName() = this or
244+
any(ContinueExpr c).getLabelName() = this
245245
}
246246

247247
string toString() { result = this }
248248
}
249249

250250
private Label getLabelOfStmt(Stmt s) {
251251
exists(LabeledStmt l | s = l.getStmt() |
252-
result = l.getLabelNameNode().getValue() or
252+
result = l.getLabelName() or
253253
result = getLabelOfStmt(l)
254254
)
255255
}
256256

257257
predicate hasLabel(Ast::AstNode n, Label l) {
258258
l = getLabelOfStmt(n)
259259
or
260-
l = n.(BreakExpr).getLabelNameNode().getValue()
260+
l = n.(BreakExpr).getLabelName()
261261
or
262-
l = n.(ContinueExpr).getLabelNameNode().getValue()
262+
l = n.(ContinueExpr).getLabelName()
263263
}
264264

265265
class CallableContext = Void;

unified/ql/lib/codeql/unified/internal/FacadeAst.qll

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,81 @@ module Unified {
6565
}
6666
}
6767

68+
class AccessorDeclaration extends G::AccessorDeclaration {
69+
/** Gets the name of this accessor. */
70+
string getName() { result = this.getNameNode().getValue() }
71+
}
72+
73+
class Argument extends G::Argument {
74+
/** Gets the name of this argument. */
75+
string getName() { result = this.getNameNode().getValue() }
76+
}
77+
78+
class AssociatedTypeDeclaration extends G::AssociatedTypeDeclaration {
79+
/** Gets the name of this associated type. */
80+
string getName() { result = this.getNameNode().getValue() }
81+
}
82+
83+
class BreakExpr extends G::BreakExpr {
84+
/** Gets the label name targeted by this break. */
85+
string getLabelName() { result = this.getLabelNameNode().getValue() }
86+
}
87+
88+
class ClassLikeDeclaration extends G::ClassLikeDeclaration {
89+
/** Gets the name of this declaration. */
90+
string getName() { result = this.getNameNode().getValue() }
91+
}
92+
93+
class ConstructorDeclaration extends G::ConstructorDeclaration {
94+
/** Gets the name of this constructor. */
95+
string getName() { result = this.getNameNode().getValue() }
96+
}
97+
98+
class ContinueExpr extends G::ContinueExpr {
99+
/** Gets the label name targeted by this continue. */
100+
string getLabelName() { result = this.getLabelNameNode().getValue() }
101+
}
102+
103+
class FunctionDeclaration extends G::FunctionDeclaration {
104+
/** Gets the name of this function. */
105+
string getName() { result = this.getNameNode().getValue() }
106+
}
107+
108+
class LabeledStmt extends G::LabeledStmt {
109+
/** Gets the label name of this statement. */
110+
string getLabelName() { result = this.getLabelNameNode().getValue() }
111+
}
112+
113+
class MemberAccessExpr extends G::MemberAccessExpr {
114+
/** Gets the member name of this access. */
115+
string getMemberName() { result = this.getMemberNameNode().getValue() }
116+
}
117+
118+
class NamedPattern extends G::NamedPattern {
119+
/** Gets the name bound by this pattern. */
120+
string getName() { result = this.getNameNode().getValue() }
121+
}
122+
123+
class OperatorSyntaxDeclaration extends G::OperatorSyntaxDeclaration {
124+
/** Gets the name of this operator. */
125+
string getName() { result = this.getNameNode().getValue() }
126+
}
127+
128+
class Parameter extends G::Parameter {
129+
/** Gets the external name of this parameter. */
130+
string getExternalName() { result = this.getExternalNameNode().getValue() }
131+
}
132+
133+
class TypeAliasDeclaration extends G::TypeAliasDeclaration {
134+
/** Gets the name of this type alias. */
135+
string getName() { result = this.getNameNode().getValue() }
136+
}
137+
138+
class TypeParameter extends G::TypeParameter {
139+
/** Gets the name of this type parameter. */
140+
string getName() { result = this.getNameNode().getValue() }
141+
}
142+
68143
/** A binary expression. */
69144
class BinaryExpr extends G::BinaryExpr {
70145
/** Gets an operand of this binary expression. */
@@ -77,7 +152,7 @@ module Unified {
77152
Expr getNamedArgument(string name) {
78153
exists(Argument arg |
79154
arg = this.getAnArgument() and
80-
arg.getNameNode().getValue() = name and
155+
arg.getName() = name and
81156
result = arg.getValue()
82157
)
83158
}

unified/ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class SwiftPackageTarget extends ModuleScopeRepr, CallExpr {
8181

8282
SwiftPackageTarget() {
8383
this.getFile().getBaseName() = "Package.swift" and
84-
this.getCallee().(MemberAccessExpr).getMemberNameNode().getValue() = targetKind and
84+
this.getCallee().(MemberAccessExpr).getMemberName() = targetKind and
8585
targetKind =
8686
[
8787
"target", "executableTarget", "testTarget", "systemLibrary", "binaryTarget", "plugin",

unified/ql/lib/codeql/unified/internal/StaticNameBinding.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private NameBindingNode getNodeFromUncertainScope(AstNode n) { result.isLocalNam
163163
predicate readStep(NameBindingNode node1, string name, NameBindingNode node2) {
164164
exists(MemberAccessExpr expr |
165165
node1 = getNodeFromRef(expr.getBase()) and
166-
name = expr.getMemberNameNode().getValue() and
166+
name = expr.getMemberName() and
167167
node2 = getNodeFromRef(expr)
168168
)
169169
or

unified/ql/lib/utils/test/TestUtils.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ private import codeql.unified.internal.StaticNameBinding
44

55
private string deriveClassName(ClassLikeDeclaration cls) {
66
not exists(cls.getParent().getEnclosingClass()) and
7-
result = cls.getNameNode().getValue()
7+
result = cls.getName()
88
or
9-
result = deriveClassName(cls.getParent().getEnclosingClass()) + "." + cls.getNameNode().getValue()
9+
result = deriveClassName(cls.getParent().getEnclosingClass()) + "." + cls.getName()
1010
}
1111

1212
private string defaultName(NameDeclaration decl) {

unified/ql/test/library-tests/BasicTest/test.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import unified
22

33
query predicate nameNode(NameNode node, string value) { value = node.getValue() }
44

5-
query predicate namedPattern(NamedPattern node, string value) {
6-
value = node.getNameNode().getValue()
7-
}
5+
query predicate namedPattern(NamedPattern node, string value) { value = node.getName() }
86

97
query predicate unsupported(UnsupportedNode node, string value) { value = node.getValue() }
108

0 commit comments

Comments
 (0)