@@ -446,7 +446,27 @@ class ConstexprIfStmt extends ConditionalStmt, @stmt_constexpr_if {
446
446
* }
447
447
* ```
448
448
*/
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
+
450
470
/**
451
471
* Gets the 'then' statement of this '(not) consteval if' statement.
452
472
*
@@ -515,7 +535,9 @@ class ConstevalOrNotConstevalIfStmt extends Stmt, @stmt_consteval_or_not_constev
515
535
* ```
516
536
* there is no result.
517
537
*/
518
- Stmt getCompileTimeEvaluatedBranch ( ) { none ( ) }
538
+ Stmt getCompileTimeEvaluatedBranch ( ) {
539
+ if this .isNot ( ) then result = this .getElse ( ) else result = this .getThen ( )
540
+ }
519
541
520
542
/**
521
543
* 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
544
566
* ```
545
567
* there is no result.
546
568
*/
547
- Stmt getRuntimeEvaluatedBranch ( ) { none ( ) }
569
+ Stmt getRuntimeEvaluatedBranch ( ) {
570
+ if this .isNot ( ) then result = this .getThen ( ) else result = this .getElse ( )
571
+ }
548
572
549
573
/**
550
574
* 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
561
585
predicate hasRuntimeEvaluatedBranch ( ) { exists ( this .getRuntimeEvaluatedBranch ( ) ) }
562
586
}
563
587
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
-
602
588
private class TLoop = @stmt_while or @stmt_end_test_while or @stmt_range_based_for or @stmt_for;
603
589
604
590
/**
0 commit comments