Skip to content

Commit 56e88cb

Browse files
committed
C++: Use underlyingElement for QualifiedName calls
Since the types in `QualifiedName.qll` are raw db types, callers need to use `underlyingElement` and `unresolveElement` as appropriate. This has no effect right now but will be needed when we switch the AST type hierarchy to `newtype`s.
1 parent 662d55f commit 56e88cb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class Declaration extends Locatable, @declaration {
3131
* namespace of the structure.
3232
*/
3333
Namespace getNamespace() {
34-
result = this.(Q::Declaration).getNamespace()
34+
result = underlyingElement(this).(Q::Declaration).getNamespace()
3535
or
3636
exists (Parameter p
3737
| p = this and result = p.getFunction().getNamespace())
@@ -53,7 +53,7 @@ abstract class Declaration extends Locatable, @declaration {
5353
* "namespace1::namespace2::TemplateClass1<int>::Class2::memberName"`.
5454
*/
5555
string getQualifiedName() {
56-
result = this.(Q::Declaration).getQualifiedName()
56+
result = underlyingElement(this).(Q::Declaration).getQualifiedName()
5757
}
5858

5959
/**
@@ -84,7 +84,8 @@ abstract class Declaration extends Locatable, @declaration {
8484
* `hasQualifiedName("std", "vector", "size")`.
8585
*/
8686
predicate hasQualifiedName(string namespaceQualifier, string typeQualifier, string baseName) {
87-
this.(Q::Declaration).hasQualifiedName(namespaceQualifier, typeQualifier, baseName)
87+
underlyingElement(this).(Q::Declaration)
88+
.hasQualifiedName(namespaceQualifier, typeQualifier, baseName)
8889
}
8990

9091
/**
@@ -115,7 +116,7 @@ abstract class Declaration extends Locatable, @declaration {
115116
* To test whether this declaration has a particular name in the global
116117
* namespace, use `hasGlobalName`.
117118
*/
118-
string getName() { result = this.(Q::Declaration).getName() }
119+
string getName() { result = underlyingElement(this).(Q::Declaration).getName() }
119120

120121
/** Holds if this declaration has the given name. */
121122
predicate hasName(string name) { name = this.getName() }

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class Parameter extends LocalScopeVariable, @parameter {
5555
* In other words, this predicate holds precisely when the result of
5656
* `getName()` is not "p#i" (where `i` is the index of the parameter).
5757
*/
58-
predicate isNamed() { exists(this.(Q::Parameter).getANamedDeclarationEntry()) }
58+
predicate isNamed() {
59+
exists(underlyingElement(this).(Q::Parameter).getANamedDeclarationEntry())
60+
}
5961

6062
/**
6163
* Gets the function to which this parameter belongs, if it is a function
@@ -96,12 +98,12 @@ class Parameter extends LocalScopeVariable, @parameter {
9698
*/
9799
override Location getLocation() {
98100
exists(VariableDeclarationEntry vde |
99-
vde = this.(Q::Parameter).getAnEffectiveDeclarationEntry() and
101+
vde = underlyingElement(this).(Q::Parameter).getAnEffectiveDeclarationEntry() and
100102
result = vde.getLocation()
101103
|
102104
vde.isDefinition()
103105
or
104-
not this.(Q::Parameter).getAnEffectiveDeclarationEntry().isDefinition()
106+
not underlyingElement(this).(Q::Parameter).getAnEffectiveDeclarationEntry().isDefinition()
105107
)
106108
}
107109
}

0 commit comments

Comments
 (0)