Skip to content

Commit 077ce6a

Browse files
authored
Merge pull request #242 from jbj/unresolveCheckResult
C++: Make unresolve dispatch on `result`
2 parents 1f9da28 + 0da452d commit 077ce6a

File tree

4 files changed

+9
-32
lines changed

4 files changed

+9
-32
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ private import semmle.code.cpp.internal.ResolveClass
1212
*/
1313
class Class extends UserType {
1414
Class() {
15-
isClass(this.underlying())
16-
}
17-
18-
override @element unresolve() {
19-
resolveClass(result) = this
15+
isClass(underlyingElement(this))
2016
}
2117

2218
/** Gets a child declaration of this class. */

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

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ private import semmle.code.cpp.internal.ResolveClass
1010
*/
1111
pragma[inline]
1212
Element mkElement(@element e) {
13-
result.unresolve() = e
13+
unresolveElement(result) = e
1414
}
1515

1616
/**
@@ -24,7 +24,10 @@ Element mkElement(@element e) {
2424
*/
2525
pragma[inline]
2626
@element unresolveElement(Element e) {
27-
result = e.unresolve()
27+
not result instanceof @usertype and
28+
result = e
29+
or
30+
e = resolveClass(result)
2831
}
2932

3033
/**
@@ -35,13 +38,12 @@ pragma[inline]
3538
* need the result for an argument to a database extensional.
3639
* See `unresolveElement` for when `e` is not `this`.
3740
*/
38-
pragma[inline]
3941
@element underlyingElement(Element e) {
4042
result = e
4143
}
4244

4345
/**
44-
* A C/C++ element with a minimal set of member predicates. Not for
46+
* A C/C++ element with no member predicates other than `toString`. Not for
4547
* general use. This class does not define a location, so classes wanting to
4648
* change their location without affecting other classes can extend
4749
* `ElementBase` instead of `Element` to create a new rootdef for `getURL`,
@@ -50,27 +52,6 @@ pragma[inline]
5052
class ElementBase extends @element {
5153
/** Gets a textual representation of this element. */
5254
string toString() { none() }
53-
54-
/**
55-
* INTERNAL: Do not use.
56-
*
57-
* Gets the `@element` that this `Element` extends. This should normally only
58-
* be called from member predicates on `this` where you need the result for
59-
* an argument to a database extensional.
60-
* See `unresolve` for when the qualifier is not `this`.
61-
*/
62-
final @element underlying() { result = this }
63-
64-
/**
65-
* INTERNAL: Do not use.
66-
*
67-
* Gets an `@element` that resolves to the `Element`. This should normally
68-
* only be called from member predicates, where the qualifier is not `this`
69-
* and you need the result for an argument to a database extensional.
70-
* See `underlying` for when the qualifier is `this`.
71-
*/
72-
pragma[inline]
73-
@element unresolve() { result = this }
7455
}
7556

7657
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private import semmle.code.cpp.internal.ResolveClass
77
* A C/C++ type.
88
*/
99
class Type extends Locatable, @type {
10-
Type() { isType(this.underlying()) }
10+
Type() { isType(underlyingElement(this)) }
1111

1212
/**
1313
* Gets the name of this type.

cpp/ql/src/semmle/code/cpp/pointsto/PointsTo.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ class PointsToExpr extends Expr
635635
{
636636
this.interesting() and
637637
exists(int set, @element thisEntity, @element resultEntity |
638-
thisEntity = this.underlying() and
638+
thisEntity = underlyingElement(this) and
639639
pointstosets(set, thisEntity) and
640640
setlocations(set, resultEntity) and
641641
resultEntity = localUnresolveElement(result)

0 commit comments

Comments
 (0)