C++: Merge the location tables

This commit is contained in:
Jeroen Ketema
2024-09-25 13:40:27 +02:00
parent b16e710d3b
commit b4caba7c0e
26 changed files with 66 additions and 103 deletions

View File

@@ -901,7 +901,7 @@ class BuiltInFunction extends Function {
/** Gets a dummy location for the built-in function. */
override Location getLocation() {
suppressUnusedThis(this) and
result instanceof UnknownDefaultLocation
result instanceof UnknownLocation
}
}

View File

@@ -53,9 +53,7 @@ class Location extends @location {
predicate fullLocationInfo(
Container container, int startline, int startcolumn, int endline, int endcolumn
) {
locations_default(this, unresolveElement(container), startline, startcolumn, endline, endcolumn) or
locations_expr(this, unresolveElement(container), startline, startcolumn, endline, endcolumn) or
locations_stmt(this, unresolveElement(container), startline, startcolumn, endline, endcolumn)
locations_default(this, unresolveElement(container), startline, startcolumn, endline, endcolumn)
}
/**
@@ -146,30 +144,32 @@ class Locatable extends Element { }
* expressions, one for statements and one for other program elements.
*/
class UnknownLocation extends Location {
UnknownLocation() { this.getFile().getAbsolutePath() = "" }
UnknownLocation() {
this.getFile().getAbsolutePath() = "" and locations_default(this, _, 0, 0, 0, 0)
}
}
/**
* A dummy location which is used when something doesn't have a location in
* the source code but needs to have a `Location` associated with it.
*
* DEPRECATED: use `UnknownLocation`
*/
class UnknownDefaultLocation extends UnknownLocation {
UnknownDefaultLocation() { locations_default(this, _, 0, 0, 0, 0) }
}
deprecated class UnknownDefaultLocation extends UnknownLocation { }
/**
* A dummy location which is used when an expression doesn't have a
* location in the source code but needs to have a `Location` associated
* with it.
*
* DEPRECATED: use `UnknownLocation`
*/
class UnknownExprLocation extends UnknownLocation {
UnknownExprLocation() { locations_expr(this, _, 0, 0, 0, 0) }
}
deprecated class UnknownExprLocation extends UnknownLocation { }
/**
* A dummy location which is used when a statement doesn't have a location
* in the source code but needs to have a `Location` associated with it.
*
* DEPRECATED: use `UnknownLocation`
*/
class UnknownStmtLocation extends UnknownLocation {
UnknownStmtLocation() { locations_stmt(this, _, 0, 0, 0, 0) }
}
deprecated class UnknownStmtLocation extends UnknownLocation { }

View File

@@ -259,7 +259,8 @@ predicate inMacroExpansion(Locatable element) {
inmacroexpansion(unresolveElement(element), _)
or
macroLocation(element.getLocation()) and
not topLevelMacroAccess(element)
not topLevelMacroAccess(element) and
not element.getLocation() instanceof UnknownLocation
}
/**

View File

@@ -40,7 +40,7 @@ class Namespace extends NameQualifyingElement, @namespace {
override Location getLocation() {
if strictcount(this.getADeclarationEntry()) = 1
then result = this.getADeclarationEntry().getLocation()
else result instanceof UnknownDefaultLocation
else result instanceof UnknownLocation
}
/** Gets the simple name of this namespace. */

View File

@@ -13,7 +13,7 @@ class Specifier extends Element, @specifier {
/** Gets a dummy location for the specifier. */
override Location getLocation() {
exists(this) and
result instanceof UnknownDefaultLocation
result instanceof UnknownLocation
}
override string getAPrimaryQlClass() { result = "Specifier" }

View File

@@ -105,7 +105,7 @@ class AutoType extends TypeTemplateParameter {
override string getAPrimaryQlClass() { result = "AutoType" }
override Location getLocation() { result instanceof UnknownDefaultLocation }
override Location getLocation() { result instanceof UnknownLocation }
}
/**

View File

@@ -290,7 +290,7 @@ class Type extends Locatable, @type {
*/
Type stripType() { result = this }
override Location getLocation() { result instanceof UnknownDefaultLocation }
override Location getLocation() { result instanceof UnknownLocation }
}
/**

View File

@@ -91,13 +91,13 @@ class Expr extends StmtParent, @expr {
*/
private Location getExprLocationOverride() {
// Base case: the parent has a better location than `this`.
this.getDbLocation() instanceof UnknownExprLocation and
this.getDbLocation() instanceof UnknownLocation and
result = this.getParent().(Expr).getDbLocation() and
not result instanceof UnknownLocation
or
// Recursive case: the parent has a location override that's better than
// what `this` has.
this.getDbLocation() instanceof UnknownExprLocation and
this.getDbLocation() instanceof UnknownLocation and
result = this.getParent().(Expr).getExprLocationOverride() and
not result instanceof UnknownLocation
}

View File

@@ -182,7 +182,7 @@ abstract class InstructionNode0 extends Node0Impl {
override Location getLocationImpl() {
if exists(instr.getAst().getLocation())
then result = instr.getAst().getLocation()
else result instanceof UnknownDefaultLocation
else result instanceof UnknownLocation
}
final override predicate isGLValue() { exists(getInstructionType(instr, true)) }
@@ -227,7 +227,7 @@ abstract class OperandNode0 extends Node0Impl {
override Location getLocationImpl() {
if exists(op.getDef().getAst().getLocation())
then result = op.getDef().getAst().getLocation()
else result instanceof UnknownDefaultLocation
else result instanceof UnknownLocation
}
final override predicate isGLValue() { exists(getOperandType(op, true)) }

View File

@@ -847,7 +847,7 @@ class BodyLessParameterNodeImpl extends Node, TBodyLessParameterNodeImpl {
result = unique( | | p.getLocation())
or
count(p.getLocation()) != 1 and
result instanceof UnknownDefaultLocation
result instanceof UnknownLocation
}
final override string toStringImpl() {
@@ -1115,7 +1115,7 @@ private module RawIndirectNodes {
final override Location getLocationImpl() {
if exists(this.getOperand().getLocation())
then result = this.getOperand().getLocation()
else result instanceof UnknownDefaultLocation
else result instanceof UnknownLocation
}
override string toStringImpl() {
@@ -1161,7 +1161,7 @@ private module RawIndirectNodes {
final override Location getLocationImpl() {
if exists(this.getInstruction().getLocation())
then result = this.getInstruction().getLocation()
else result instanceof UnknownDefaultLocation
else result instanceof UnknownLocation
}
override string toStringImpl() {
@@ -1257,7 +1257,7 @@ class FinalParameterNode extends Node, TFinalParameterNode {
result = unique( | | p.getLocation())
or
not exists(unique( | | p.getLocation())) and
result instanceof UnknownDefaultLocation
result instanceof UnknownLocation
}
override string toStringImpl() { result = stars(this) + p.toString() }
@@ -1629,7 +1629,7 @@ class VariableNode extends Node, TGlobalLikeVariableNode {
result = unique( | | v.getLocation())
or
not exists(unique( | | v.getLocation())) and
result instanceof UnknownDefaultLocation
result instanceof UnknownLocation
}
override string toStringImpl() { result = stars(this) + v.toString() }

View File

@@ -516,7 +516,7 @@ class FinalParameterUse extends UseImpl, TFinalParameterUse {
result = unique( | | p.getLocation())
or
not exists(unique( | | p.getLocation())) and
result instanceof UnknownDefaultLocation
result instanceof UnknownLocation
}
override BaseIRVariable getBaseSourceVariable() { result.getIRVariable().getAst() = p }

View File

@@ -45,7 +45,7 @@ module InstructionConsistency {
private class MissingIRFunction extends OptionalIRFunction, TMissingIRFunction {
override string toString() { result = "<Missing IRFunction>" }
override Language::Location getLocation() { result instanceof Language::UnknownDefaultLocation }
override Language::Location getLocation() { result instanceof Language::UnknownLocation }
}
private OptionalIRFunction getInstructionIRFunction(Instruction instr) {

View File

@@ -26,7 +26,7 @@ class ValueNumber extends TValueNumber {
l.getFile().getAbsolutePath(), l.getStartLine(), l.getStartColumn(), l.getEndLine(),
l.getEndColumn()
)
else result instanceof Language::UnknownDefaultLocation
else result instanceof Language::UnknownLocation
}
/**

View File

@@ -45,7 +45,7 @@ module InstructionConsistency {
private class MissingIRFunction extends OptionalIRFunction, TMissingIRFunction {
override string toString() { result = "<Missing IRFunction>" }
override Language::Location getLocation() { result instanceof Language::UnknownDefaultLocation }
override Language::Location getLocation() { result instanceof Language::UnknownLocation }
}
private OptionalIRFunction getInstructionIRFunction(Instruction instr) {

View File

@@ -26,7 +26,7 @@ class ValueNumber extends TValueNumber {
l.getFile().getAbsolutePath(), l.getStartLine(), l.getStartColumn(), l.getEndLine(),
l.getEndColumn()
)
else result instanceof Language::UnknownDefaultLocation
else result instanceof Language::UnknownLocation
}
/**

View File

@@ -45,7 +45,7 @@ module InstructionConsistency {
private class MissingIRFunction extends OptionalIRFunction, TMissingIRFunction {
override string toString() { result = "<Missing IRFunction>" }
override Language::Location getLocation() { result instanceof Language::UnknownDefaultLocation }
override Language::Location getLocation() { result instanceof Language::UnknownLocation }
}
private OptionalIRFunction getInstructionIRFunction(Instruction instr) {

View File

@@ -26,7 +26,7 @@ class ValueNumber extends TValueNumber {
l.getFile().getAbsolutePath(), l.getStartLine(), l.getStartColumn(), l.getEndLine(),
l.getEndColumn()
)
else result instanceof Language::UnknownDefaultLocation
else result instanceof Language::UnknownLocation
}
/**

View File

@@ -76,7 +76,7 @@ class GVN extends TValueNumber {
l.getFile().getAbsolutePath(), l.getStartLine(), l.getStartColumn(), l.getEndLine(),
l.getEndColumn()
)
else result instanceof UnknownDefaultLocation
else result instanceof UnknownLocation
}
final string getKind() {

View File

@@ -22,8 +22,6 @@ class Location = Cpp::Location;
class UnknownLocation = Cpp::UnknownLocation;
class UnknownDefaultLocation = Cpp::UnknownDefaultLocation;
class File = Cpp::File;
class AST = Cpp::Locatable;

View File

@@ -89,7 +89,7 @@ class ZeroBound extends Bound instanceof IRBound::ZeroBound {
result = super.getInstruction(delta).getUnconvertedResultExpression()
}
override Location getLocation() { result instanceof UnknownDefaultLocation }
override Location getLocation() { result instanceof UnknownLocation }
}
/**

View File

@@ -61,7 +61,7 @@ class ZeroBound extends Bound, TBoundZero {
result.(ConstantValueInstruction).getValue().toInt() = delta
}
override Location getLocation() { result instanceof UnknownDefaultLocation }
override Location getLocation() { result instanceof UnknownLocation }
}
/**