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.
This commit is contained in:
Jonas Jensen
2019-05-06 11:24:28 +02:00
parent 662d55fd72
commit 56e88cbac0
2 changed files with 10 additions and 7 deletions

View File

@@ -31,7 +31,7 @@ abstract class Declaration extends Locatable, @declaration {
* namespace of the structure. * namespace of the structure.
*/ */
Namespace getNamespace() { Namespace getNamespace() {
result = this.(Q::Declaration).getNamespace() result = underlyingElement(this).(Q::Declaration).getNamespace()
or or
exists (Parameter p exists (Parameter p
| p = this and result = p.getFunction().getNamespace()) | p = this and result = p.getFunction().getNamespace())
@@ -53,7 +53,7 @@ abstract class Declaration extends Locatable, @declaration {
* "namespace1::namespace2::TemplateClass1<int>::Class2::memberName"`. * "namespace1::namespace2::TemplateClass1<int>::Class2::memberName"`.
*/ */
string getQualifiedName() { string getQualifiedName() {
result = this.(Q::Declaration).getQualifiedName() result = underlyingElement(this).(Q::Declaration).getQualifiedName()
} }
/** /**
@@ -84,7 +84,8 @@ abstract class Declaration extends Locatable, @declaration {
* `hasQualifiedName("std", "vector", "size")`. * `hasQualifiedName("std", "vector", "size")`.
*/ */
predicate hasQualifiedName(string namespaceQualifier, string typeQualifier, string baseName) { predicate hasQualifiedName(string namespaceQualifier, string typeQualifier, string baseName) {
this.(Q::Declaration).hasQualifiedName(namespaceQualifier, typeQualifier, baseName) underlyingElement(this).(Q::Declaration)
.hasQualifiedName(namespaceQualifier, typeQualifier, baseName)
} }
/** /**
@@ -115,7 +116,7 @@ abstract class Declaration extends Locatable, @declaration {
* To test whether this declaration has a particular name in the global * To test whether this declaration has a particular name in the global
* namespace, use `hasGlobalName`. * namespace, use `hasGlobalName`.
*/ */
string getName() { result = this.(Q::Declaration).getName() } string getName() { result = underlyingElement(this).(Q::Declaration).getName() }
/** Holds if this declaration has the given name. */ /** Holds if this declaration has the given name. */
predicate hasName(string name) { name = this.getName() } predicate hasName(string name) { name = this.getName() }

View File

@@ -55,7 +55,9 @@ class Parameter extends LocalScopeVariable, @parameter {
* In other words, this predicate holds precisely when the result of * In other words, this predicate holds precisely when the result of
* `getName()` is not "p#i" (where `i` is the index of the parameter). * `getName()` is not "p#i" (where `i` is the index of the parameter).
*/ */
predicate isNamed() { exists(this.(Q::Parameter).getANamedDeclarationEntry()) } predicate isNamed() {
exists(underlyingElement(this).(Q::Parameter).getANamedDeclarationEntry())
}
/** /**
* Gets the function to which this parameter belongs, if it is a function * Gets the function to which this parameter belongs, if it is a function
@@ -96,12 +98,12 @@ class Parameter extends LocalScopeVariable, @parameter {
*/ */
override Location getLocation() { override Location getLocation() {
exists(VariableDeclarationEntry vde | exists(VariableDeclarationEntry vde |
vde = this.(Q::Parameter).getAnEffectiveDeclarationEntry() and vde = underlyingElement(this).(Q::Parameter).getAnEffectiveDeclarationEntry() and
result = vde.getLocation() result = vde.getLocation()
| |
vde.isDefinition() vde.isDefinition()
or or
not this.(Q::Parameter).getAnEffectiveDeclarationEntry().isDefinition() not underlyingElement(this).(Q::Parameter).getAnEffectiveDeclarationEntry().isDefinition()
) )
} }
} }