Skip to content

Commit b4caba7

Browse files
committed
C++: Merge the location tables
1 parent b16e710 commit b4caba7

File tree

26 files changed

+66
-103
lines changed

26 files changed

+66
-103
lines changed

cpp/ql/lib/experimental/quantum/Language.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module CryptoInput implements InputSig<Language::Location> {
88

99
class LocatableElement = Language::Locatable;
1010

11-
class UnknownLocation = Language::UnknownDefaultLocation;
11+
class UnknownLocation = Language::UnknownLocation;
1212

1313
LocatableElement dfn_to_element(DataFlow::Node node) {
1414
result = node.asExpr() or

cpp/ql/lib/semmle/code/cpp/Function.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ class BuiltInFunction extends Function {
901901
/** Gets a dummy location for the built-in function. */
902902
override Location getLocation() {
903903
suppressUnusedThis(this) and
904-
result instanceof UnknownDefaultLocation
904+
result instanceof UnknownLocation
905905
}
906906
}
907907

cpp/ql/lib/semmle/code/cpp/Location.qll

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ class Location extends @location {
5353
predicate fullLocationInfo(
5454
Container container, int startline, int startcolumn, int endline, int endcolumn
5555
) {
56-
locations_default(this, unresolveElement(container), startline, startcolumn, endline, endcolumn) or
57-
locations_expr(this, unresolveElement(container), startline, startcolumn, endline, endcolumn) or
58-
locations_stmt(this, unresolveElement(container), startline, startcolumn, endline, endcolumn)
56+
locations_default(this, unresolveElement(container), startline, startcolumn, endline, endcolumn)
5957
}
6058

6159
/**
@@ -146,30 +144,32 @@ class Locatable extends Element { }
146144
* expressions, one for statements and one for other program elements.
147145
*/
148146
class UnknownLocation extends Location {
149-
UnknownLocation() { this.getFile().getAbsolutePath() = "" }
147+
UnknownLocation() {
148+
this.getFile().getAbsolutePath() = "" and locations_default(this, _, 0, 0, 0, 0)
149+
}
150150
}
151151

152152
/**
153153
* A dummy location which is used when something doesn't have a location in
154154
* the source code but needs to have a `Location` associated with it.
155+
*
156+
* DEPRECATED: use `UnknownLocation`
155157
*/
156-
class UnknownDefaultLocation extends UnknownLocation {
157-
UnknownDefaultLocation() { locations_default(this, _, 0, 0, 0, 0) }
158-
}
158+
deprecated class UnknownDefaultLocation extends UnknownLocation { }
159159

160160
/**
161161
* A dummy location which is used when an expression doesn't have a
162162
* location in the source code but needs to have a `Location` associated
163163
* with it.
164+
*
165+
* DEPRECATED: use `UnknownLocation`
164166
*/
165-
class UnknownExprLocation extends UnknownLocation {
166-
UnknownExprLocation() { locations_expr(this, _, 0, 0, 0, 0) }
167-
}
167+
deprecated class UnknownExprLocation extends UnknownLocation { }
168168

169169
/**
170170
* A dummy location which is used when a statement doesn't have a location
171171
* in the source code but needs to have a `Location` associated with it.
172+
*
173+
* DEPRECATED: use `UnknownLocation`
172174
*/
173-
class UnknownStmtLocation extends UnknownLocation {
174-
UnknownStmtLocation() { locations_stmt(this, _, 0, 0, 0, 0) }
175-
}
175+
deprecated class UnknownStmtLocation extends UnknownLocation { }

cpp/ql/lib/semmle/code/cpp/Macro.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ predicate inMacroExpansion(Locatable element) {
259259
inmacroexpansion(unresolveElement(element), _)
260260
or
261261
macroLocation(element.getLocation()) and
262-
not topLevelMacroAccess(element)
262+
not topLevelMacroAccess(element) and
263+
not element.getLocation() instanceof UnknownLocation
263264
}
264265

265266
/**

cpp/ql/lib/semmle/code/cpp/Namespace.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Namespace extends NameQualifyingElement, @namespace {
4040
override Location getLocation() {
4141
if strictcount(this.getADeclarationEntry()) = 1
4242
then result = this.getADeclarationEntry().getLocation()
43-
else result instanceof UnknownDefaultLocation
43+
else result instanceof UnknownLocation
4444
}
4545

4646
/** Gets the simple name of this namespace. */

cpp/ql/lib/semmle/code/cpp/Specifier.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Specifier extends Element, @specifier {
1313
/** Gets a dummy location for the specifier. */
1414
override Location getLocation() {
1515
exists(this) and
16-
result instanceof UnknownDefaultLocation
16+
result instanceof UnknownLocation
1717
}
1818

1919
override string getAPrimaryQlClass() { result = "Specifier" }

cpp/ql/lib/semmle/code/cpp/TemplateParameter.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class AutoType extends TypeTemplateParameter {
105105

106106
override string getAPrimaryQlClass() { result = "AutoType" }
107107

108-
override Location getLocation() { result instanceof UnknownDefaultLocation }
108+
override Location getLocation() { result instanceof UnknownLocation }
109109
}
110110

111111
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class Type extends Locatable, @type {
290290
*/
291291
Type stripType() { result = this }
292292

293-
override Location getLocation() { result instanceof UnknownDefaultLocation }
293+
override Location getLocation() { result instanceof UnknownLocation }
294294
}
295295

296296
/**

cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ class Expr extends StmtParent, @expr {
9191
*/
9292
private Location getExprLocationOverride() {
9393
// Base case: the parent has a better location than `this`.
94-
this.getDbLocation() instanceof UnknownExprLocation and
94+
this.getDbLocation() instanceof UnknownLocation and
9595
result = this.getParent().(Expr).getDbLocation() and
9696
not result instanceof UnknownLocation
9797
or
9898
// Recursive case: the parent has a location override that's better than
9999
// what `this` has.
100-
this.getDbLocation() instanceof UnknownExprLocation and
100+
this.getDbLocation() instanceof UnknownLocation and
101101
result = this.getParent().(Expr).getExprLocationOverride() and
102102
not result instanceof UnknownLocation
103103
}

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ abstract class InstructionNode0 extends Node0Impl {
182182
override Location getLocationImpl() {
183183
if exists(instr.getAst().getLocation())
184184
then result = instr.getAst().getLocation()
185-
else result instanceof UnknownDefaultLocation
185+
else result instanceof UnknownLocation
186186
}
187187

188188
final override predicate isGLValue() { exists(getInstructionType(instr, true)) }
@@ -227,7 +227,7 @@ abstract class OperandNode0 extends Node0Impl {
227227
override Location getLocationImpl() {
228228
if exists(op.getDef().getAst().getLocation())
229229
then result = op.getDef().getAst().getLocation()
230-
else result instanceof UnknownDefaultLocation
230+
else result instanceof UnknownLocation
231231
}
232232

233233
final override predicate isGLValue() { exists(getOperandType(op, true)) }

0 commit comments

Comments
 (0)