C++: add SemLocation so SemBound is copy-shareable

This commit is contained in:
Robert Marsh
2023-03-15 10:38:47 -04:00
parent 623e39031c
commit 45fdf69461
4 changed files with 31 additions and 7 deletions

View File

@@ -5,7 +5,7 @@
private import SemanticExpr
private import SemanticExprSpecific::SemanticExprConfig as Specific
private import SemanticSSA
private import semmle.code.cpp.Location // TODO: SemLocation?
private import SemanticLocation // TODO: SemLocation?
/**
* A valid base for an expression bound.
@@ -15,7 +15,7 @@ private import semmle.code.cpp.Location // TODO: SemLocation?
class SemBound instanceof Specific::Bound {
final string toString() { result = super.toString() }
final Location getLocation() { result = super.getLocation() }
final SemLocation getLocation() { result = super.getLocation() }
final SemExpr getExpr(int delta) { result = Specific::getBoundExpr(this, delta) }
}

View File

@@ -0,0 +1,24 @@
private import semmle.code.cpp.Location
class SemLocation instanceof Location {
/**
* Gets a textual representation of this element.
*
* The format is "file://filePath:startLine:startColumn:endLine:endColumn".
*/
string toString() {
result = super.toString()
}
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `filepath`.
* For more information, see
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
}

View File

@@ -4,7 +4,7 @@ private import experimental.semmle.code.cpp.semantic.analysis.FloatDelta
private import RangeUtils
private import experimental.semmle.code.cpp.semantic.SemanticBound as SemanticBound
private import semmle.code.cpp.ir.IR as IR
private import semmle.code.cpp.Location // TODO: SemLocation?
private import experimental.semmle.code.cpp.semantic.SemanticLocation
module ConstantBounds implements BoundSig<FloatDelta> {
class SemBound instanceof SemanticBound::SemBound {
@@ -16,7 +16,7 @@ module ConstantBounds implements BoundSig<FloatDelta> {
string toString() { result = super.toString() }
Location getLocation() { result = super.getLocation() }
SemLocation getLocation() { result = super.getLocation() }
SemExpr getExpr(float delta) { result = super.getExpr(delta) }
}
@@ -36,7 +36,7 @@ private module RelativeBounds implements BoundSig<FloatDelta> {
string toString() { result = super.toString() }
Location getLocation() { result = super.getLocation() }
SemLocation getLocation() { result = super.getLocation() }
SemExpr getExpr(float delta) { result = super.getExpr(delta) }
}

View File

@@ -73,7 +73,7 @@ import experimental.semmle.code.cpp.semantic.SemanticCFG
import experimental.semmle.code.cpp.semantic.SemanticType
import experimental.semmle.code.cpp.semantic.SemanticOpcode
private import ConstantAnalysis
private import semmle.code.cpp.Location
import experimental.semmle.code.cpp.semantic.SemanticLocation
/**
* Holds if `typ` is a small integral type with the given lower and upper bounds.
@@ -231,7 +231,7 @@ signature module BoundSig<DeltaSig D> {
class SemBound {
string toString();
Location getLocation();
SemLocation getLocation();
SemExpr getExpr(D::Delta delta);
}