C++: Revert object-orientation of unresolveElement

The change to make `unresolveElement` a member predicate was helpful for
the optimiser when it dispatched on `this`, but now that it "dispatches"
on `result` it's just an unnecessary pollution of the `ElementBase`
namespace.
This commit is contained in:
Jonas Jensen
2018-09-27 10:35:04 +02:00
parent c61b311682
commit 0da452d59a
4 changed files with 9 additions and 33 deletions

View File

@@ -12,7 +12,7 @@ private import semmle.code.cpp.internal.ResolveClass
*/
class Class extends UserType {
Class() {
isClass(this.underlying())
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,32 +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]
final @element unresolve() {
not result instanceof @usertype and
result = this
or
this = resolveClass(result)
}
}
/**

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)