@@ -446,7 +446,27 @@ class ConstexprIfStmt extends ConditionalStmt, @stmt_constexpr_if {
446446 * }
447447 * ```
448448 */
449- class ConstevalOrNotConstevalIfStmt extends Stmt , @stmt_consteval_or_not_consteval_if {
449+ class ConstevalIfStmt extends Stmt , @stmt_consteval_or_not_consteval_if {
450+ override string getAPrimaryQlClass ( ) { result = "ConstevalIfStmt" }
451+
452+ override string toString ( ) {
453+ if this .isNot ( ) then result = "if ! consteval ..." else result = "if consteval ..."
454+ }
455+
456+ /**
457+ * Holds if this is a 'not consteval if' statement.
458+ *
459+ * For example, this holds for
460+ * ```cpp
461+ * if ! consteval { return true; }
462+ * ```
463+ * but not for
464+ * ```cpp
465+ * if consteval { return true; }
466+ * ```
467+ */
468+ predicate isNot ( ) { this instanceof @stmt_not_consteval_if }
469+
450470 /**
451471 * Gets the 'then' statement of this '(not) consteval if' statement.
452472 *
@@ -515,7 +535,9 @@ class ConstevalOrNotConstevalIfStmt extends Stmt, @stmt_consteval_or_not_constev
515535 * ```
516536 * there is no result.
517537 */
518- Stmt getCompileTimeEvaluatedBranch ( ) { none ( ) }
538+ Stmt getCompileTimeEvaluatedBranch ( ) {
539+ if this .isNot ( ) then result = this .getElse ( ) else result = this .getThen ( )
540+ }
519541
520542 /**
521543 * Holds if this '(not) constexpr if' statement has a compile time evaluated statement.
@@ -544,7 +566,9 @@ class ConstevalOrNotConstevalIfStmt extends Stmt, @stmt_consteval_or_not_constev
544566 * ```
545567 * there is no result.
546568 */
547- Stmt getRuntimeEvaluatedBranch ( ) { none ( ) }
569+ Stmt getRuntimeEvaluatedBranch ( ) {
570+ if this .isNot ( ) then result = this .getThen ( ) else result = this .getElse ( )
571+ }
548572
549573 /**
550574 * Holds if this '(not) constexpr if' statement has a runtime evaluated statement.
@@ -561,44 +585,6 @@ class ConstevalOrNotConstevalIfStmt extends Stmt, @stmt_consteval_or_not_constev
561585 predicate hasRuntimeEvaluatedBranch ( ) { exists ( this .getRuntimeEvaluatedBranch ( ) ) }
562586}
563587
564- /**
565- * A C/C++ 'consteval if'. For example, the `if consteval` statement
566- * in the following code:
567- * ```cpp
568- * if consteval {
569- * ...
570- * }
571- * ```
572- */
573- class ConstevalIfStmt extends ConstevalOrNotConstevalIfStmt , @stmt_consteval_if {
574- override string getAPrimaryQlClass ( ) { result = "ConstevalIfStmt" }
575-
576- override string toString ( ) { result = "if consteval ..." }
577-
578- override Stmt getCompileTimeEvaluatedBranch ( ) { result = this .getThen ( ) }
579-
580- override Stmt getRuntimeEvaluatedBranch ( ) { result = this .getElse ( ) }
581- }
582-
583- /**
584- * A C/C++ 'not consteval if'. For example, the `if ! consteval` statement
585- * in the following code:
586- * ```cpp
587- * if ! consteval {
588- * ...
589- * }
590- * ```
591- */
592- class NotConstevalIfStmt extends ConstevalOrNotConstevalIfStmt , @stmt_not_consteval_if {
593- override string getAPrimaryQlClass ( ) { result = "NotConstevalIfStmt" }
594-
595- override string toString ( ) { result = "if ! consteval ..." }
596-
597- override Stmt getCompileTimeEvaluatedBranch ( ) { result = this .getElse ( ) }
598-
599- override Stmt getRuntimeEvaluatedBranch ( ) { result = this .getThen ( ) }
600- }
601-
602588private class TLoop = @stmt_while or @stmt_end_test_while or @stmt_range_based_for or @stmt_for;
603589
604590/**
0 commit comments