Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b8b9d6

Browse files
Matthew Gretton-Dannigfoo
authored andcommitted
Actually sort add Statement support
This commit fixes the previous one.
1 parent 5df5e6d commit 8b8b9d6

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

cpp/ql/src/semmle/code/cpp/stmts/Stmt.qll

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ class ConstexprIfStmt extends ConditionalStmt, @stmt_constexpr_if {
380380
}
381381
}
382382

383-
private class TLoop = @stmt_while or @stmt_end_test_while or @stmt_range_based_for or @stmt_for;
383+
private class TLoop = @stmt_while or @stmt_end_test_while or @range_based_for_stmt or @stmt_for;
384384

385385
/**
386386
* A C/C++ loop, that is, either a 'while' loop, a 'for' loop, or a
@@ -662,6 +662,54 @@ class LabelStmt extends Stmt, @stmt_label {
662662
override predicate mayBeGloballyImpure() { none() }
663663
}
664664

665+
/**
666+
* A C/C++ 'co_return' statement.
667+
*
668+
* For example:
669+
* ```
670+
* co_return 1+2;
671+
* ```
672+
* or
673+
* ```
674+
* co_return;
675+
* ```
676+
*/
677+
class CoReturnStmt extends Stmt, @stmt_co_return {
678+
override string getAPrimaryQlClass() { result = "CoReturnStmt" }
679+
680+
/**
681+
* Gets the expression of this 'co_return' statement.
682+
*
683+
* For example, for
684+
* ```
685+
* co_return 1+2;
686+
* ```
687+
* the result is `1+2`, and there is no result for
688+
* ```
689+
* co_return;
690+
* ```
691+
*
692+
* TODO: Really?
693+
*/
694+
Expr getExpr() { result = this.getChild(0) }
695+
696+
/**
697+
* Holds if this 'co_return' statement has an expression.
698+
*
699+
* For example, this holds for
700+
* ```
701+
* co_return 1+2;
702+
* ```
703+
* but not for
704+
* ```
705+
* co_return;
706+
* ```
707+
*/
708+
predicate hasExpr() { exists(this.getExpr()) }
709+
710+
override string toString() { result = "co_return ..." }
711+
}
712+
665713
/**
666714
* A C/C++ 'return' statement.
667715
*
@@ -771,7 +819,7 @@ class DoStmt extends Loop, @stmt_end_test_while {
771819
* ```
772820
* where `begin_expr` and `end_expr` depend on the type of `xs`.
773821
*/
774-
class RangeBasedForStmt extends Loop, @stmt_range_based_for {
822+
class RangeBasedForStmt extends Loop, @range_based_for_stmt {
775823
override string getAPrimaryQlClass() { result = "RangeBasedForStmt" }
776824

777825
/**
@@ -847,6 +895,16 @@ class RangeBasedForStmt extends Loop, @stmt_range_based_for {
847895
LocalVariable getAnIterationVariable() { result = getBeginVariable() }
848896
}
849897

898+
/**
899+
* A C/C++ 'for await' statement.
900+
*
901+
* This represents a range-based 'for await' statement.
902+
class RangeBasedForAwaitStmt extends Loop, @stmt_range_based_for_co_await {
903+
override string getAPrimaryQlClass() { result = "RangeBasedForAwaitStmt" }
904+
905+
override string toString() { result = "for co_await(...:...) ..." }
906+
}
907+
850908
/**
851909
* A C/C++ 'for' statement.
852910
*

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,8 @@ funbind(
12281228
| @builtinaddressof
12291229
| @vec_fill
12301230
| @un_log_op_expr
1231+
| @co_await
1232+
| @co_yield
12311233
;
12321234

12331235
@bin_log_op_expr = @andlogicalexpr | @orlogicalexpr;

0 commit comments

Comments
 (0)