mirror of
https://github.com/github/codeql.git
synced 2026-03-22 15:36:48 +01:00
53 lines
962 B
Plaintext
53 lines
962 B
Plaintext
import cpp
|
|
|
|
newtype TMaybeStmtParent = TStmtParent(StmtParent p) or TNoStmtParent()
|
|
|
|
class MaybeStmtParent extends TMaybeStmtParent {
|
|
abstract string toString();
|
|
abstract Location getLocation();
|
|
}
|
|
|
|
class YesMaybeStmtParent extends MaybeStmtParent {
|
|
StmtParent p;
|
|
|
|
YesMaybeStmtParent() {
|
|
this = TStmtParent(p)
|
|
}
|
|
|
|
override string toString() {
|
|
result = p.toString()
|
|
}
|
|
|
|
override Location getLocation() {
|
|
result = p.getLocation()
|
|
}
|
|
|
|
StmtParent getStmtParent() {
|
|
result = p
|
|
}
|
|
}
|
|
|
|
class NoMaybeStmtParent extends MaybeStmtParent {
|
|
NoMaybeStmtParent() {
|
|
this = TNoStmtParent()
|
|
}
|
|
|
|
override string toString() {
|
|
result = "<none>"
|
|
}
|
|
|
|
override Location getLocation() {
|
|
result instanceof UnknownLocation
|
|
}
|
|
}
|
|
|
|
MaybeStmtParent parent(Stmt s) {
|
|
if exists(s.getParent())
|
|
then result.(YesMaybeStmtParent).getStmtParent() = s.getParent()
|
|
else result instanceof NoMaybeStmtParent
|
|
}
|
|
|
|
from Stmt s
|
|
select s, parent(s)
|
|
|