mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
C++: Support C++20 range-based for initializers
This commit is contained in:
@@ -960,25 +960,38 @@ class TranslatedRangeBasedForStmt extends TranslatedStmt, ConditionContext {
|
||||
override RangeBasedForStmt stmt;
|
||||
|
||||
override TranslatedElement getChild(int id) {
|
||||
id = 0 and result = this.getRangeVariableDeclStmt()
|
||||
id = 0 and result = this.getInitialization()
|
||||
or
|
||||
id = 1 and result = this.getRangeVariableDeclStmt()
|
||||
or
|
||||
// Note: `__begin` and `__end` are declared by the same `DeclStmt`
|
||||
id = 1 and result = this.getBeginEndVariableDeclStmt()
|
||||
id = 2 and result = this.getBeginEndVariableDeclStmt()
|
||||
or
|
||||
id = 2 and result = this.getCondition()
|
||||
id = 3 and result = this.getCondition()
|
||||
or
|
||||
id = 3 and result = this.getUpdate()
|
||||
id = 4 and result = this.getUpdate()
|
||||
or
|
||||
id = 4 and result = this.getVariableDeclStmt()
|
||||
id = 5 and result = this.getVariableDeclStmt()
|
||||
or
|
||||
id = 5 and result = this.getBody()
|
||||
id = 6 and result = this.getBody()
|
||||
}
|
||||
|
||||
private predicate hasInitialization() { exists(stmt.getInitialization()) }
|
||||
|
||||
private TranslatedStmt getInitialization() {
|
||||
result = getTranslatedStmt(stmt.getInitialization())
|
||||
}
|
||||
|
||||
override Instruction getFirstInstruction(EdgeKind kind) {
|
||||
result = this.getRangeVariableDeclStmt().getFirstInstruction(kind)
|
||||
if this.hasInitialization()
|
||||
then result = this.getInitialization().getFirstInstruction(kind)
|
||||
else result = this.getFirstRangeVariableDeclStmtInstruction(kind)
|
||||
}
|
||||
|
||||
override Instruction getChildSuccessor(TranslatedElement child, EdgeKind kind) {
|
||||
child = this.getInitialization() and
|
||||
result = this.getFirstRangeVariableDeclStmtInstruction(kind)
|
||||
or
|
||||
child = this.getRangeVariableDeclStmt() and
|
||||
result = this.getBeginEndVariableDeclStmt().getFirstInstruction(kind)
|
||||
or
|
||||
@@ -1018,6 +1031,10 @@ class TranslatedRangeBasedForStmt extends TranslatedStmt, ConditionContext {
|
||||
)
|
||||
}
|
||||
|
||||
private Instruction getFirstRangeVariableDeclStmtInstruction(EdgeKind kind) {
|
||||
result = this.getRangeVariableDeclStmt().getFirstInstruction(kind)
|
||||
}
|
||||
|
||||
private TranslatedDeclStmt getBeginEndVariableDeclStmt() {
|
||||
exists(IRVariableDeclarationEntry entry |
|
||||
entry.getStmt() = stmt.getBeginEndDeclaration() and
|
||||
|
||||
Reference in New Issue
Block a user