Skip to content

Commit

Permalink
C++: Merge the location tables
Browse files Browse the repository at this point in the history
  • Loading branch information
jketema committed Sep 25, 2024
1 parent 9b8152a commit 654d2e8
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 100 deletions.
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/Function.qll
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,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
}
}

Expand Down
24 changes: 11 additions & 13 deletions cpp/ql/lib/semmle/code/cpp/Location.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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(this, unresolveElement(container), startline, startcolumn, endline, endcolumn)
}

/**
Expand Down Expand Up @@ -143,30 +141,30 @@ 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(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 { }
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/Namespace.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion cpp/ql/lib/semmle/code/cpp/Specifier.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions cpp/ql/lib/semmle/code/cpp/Type.qll
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class Type extends Locatable, @type {

override Location getLocation() {
suppressUnusedThis(this) and
result instanceof UnknownDefaultLocation
result instanceof UnknownLocation
}
}

Expand Down Expand Up @@ -1714,7 +1714,7 @@ class AutoType extends TemplateParameter {

override Location getLocation() {
suppressUnusedThis(this) and
result instanceof UnknownDefaultLocation
result instanceof UnknownLocation
}
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
Expand Down Expand Up @@ -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)) }
Expand Down
10 changes: 5 additions & 5 deletions cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,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() {
Expand Down Expand Up @@ -1133,7 +1133,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() {
Expand Down Expand Up @@ -1177,7 +1177,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() {
Expand Down Expand Up @@ -1271,7 +1271,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() }
Expand Down Expand Up @@ -1622,7 +1622,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() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 0 additions & 2 deletions cpp/ql/lib/semmle/code/cpp/ir/internal/IRCppLanguage.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Location = Cpp::Location;

class UnknownLocation = Cpp::UnknownLocation;

class UnknownDefaultLocation = Cpp::UnknownDefaultLocation;

class File = Cpp::File;

class AST = Cpp::Locatable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

/**
Expand Down
Loading

0 comments on commit 654d2e8

Please sign in to comment.