Merge pull request #242 from jbj/unresolveCheckResult

C++: Make unresolve dispatch on `result`
This commit is contained in:
ian-semmle
2018-09-27 14:59:34 +01:00
committed by GitHub
4 changed files with 9 additions and 32 deletions

View File

@@ -12,11 +12,7 @@ private import semmle.code.cpp.internal.ResolveClass
*/
class Class extends UserType {
Class() {
isClass(this.underlying())
}
override @element unresolve() {
resolveClass(result) = this
isClass(underlyingElement(this))
}
/** Gets a child declaration of this class. */

View File

@@ -10,7 +10,7 @@ private import semmle.code.cpp.internal.ResolveClass
*/
pragma[inline]
Element mkElement(@element e) {
result.unresolve() = e
unresolveElement(result) = e
}
/**
@@ -24,7 +24,10 @@ Element mkElement(@element e) {
*/
pragma[inline]
@element unresolveElement(Element e) {
result = e.unresolve()
not result instanceof @usertype and
result = e
or
e = resolveClass(result)
}
/**
@@ -35,13 +38,12 @@ pragma[inline]
* need the result for an argument to a database extensional.
* See `unresolveElement` for when `e` is not `this`.
*/
pragma[inline]
@element underlyingElement(Element e) {
result = e
}
/**
* A C/C++ element with a minimal set of member predicates. Not for
* A C/C++ element with no member predicates other than `toString`. Not for
* general use. This class does not define a location, so classes wanting to
* change their location without affecting other classes can extend
* `ElementBase` instead of `Element` to create a new rootdef for `getURL`,
@@ -50,27 +52,6 @@ pragma[inline]
class ElementBase extends @element {
/** Gets a textual representation of this element. */
string toString() { none() }
/**
* INTERNAL: Do not use.
*
* Gets the `@element` that this `Element` extends. This should normally only
* be called from member predicates on `this` where you need the result for
* an argument to a database extensional.
* See `unresolve` for when the qualifier is not `this`.
*/
final @element underlying() { result = this }
/**
* INTERNAL: Do not use.
*
* Gets an `@element` that resolves to the `Element`. This should normally
* only be called from member predicates, where the qualifier is not `this`
* and you need the result for an argument to a database extensional.
* See `underlying` for when the qualifier is `this`.
*/
pragma[inline]
@element unresolve() { result = this }
}
/**

View File

@@ -7,7 +7,7 @@ private import semmle.code.cpp.internal.ResolveClass
* A C/C++ type.
*/
class Type extends Locatable, @type {
Type() { isType(this.underlying()) }
Type() { isType(underlyingElement(this)) }
/**
* Gets the name of this type.

View File

@@ -635,7 +635,7 @@ class PointsToExpr extends Expr
{
this.interesting() and
exists(int set, @element thisEntity, @element resultEntity |
thisEntity = this.underlying() and
thisEntity = underlyingElement(this) and
pointstosets(set, thisEntity) and
setlocations(set, resultEntity) and
resultEntity = localUnresolveElement(result)