51
51
#include < cstdint>
52
52
#include < memory>
53
53
#include < optional>
54
+ #include < variant>
54
55
55
56
namespace clang {
56
57
@@ -2765,27 +2766,27 @@ class CXXPseudoDestructorExpr : public Expr {
2765
2766
// / \endcode
2766
2767
class TypeTraitExpr final
2767
2768
: public Expr,
2768
- private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
2769
+ private llvm::TrailingObjects<TypeTraitExpr, APValue, TypeSourceInfo *> {
2769
2770
// / The location of the type trait keyword.
2770
2771
SourceLocation Loc;
2771
2772
2772
2773
// / The location of the closing parenthesis.
2773
2774
SourceLocation RParenLoc;
2774
2775
2775
- // Note: The TypeSourceInfos for the arguments are allocated after the
2776
- // TypeTraitExpr.
2777
-
2778
2776
TypeTraitExpr (QualType T, SourceLocation Loc, TypeTrait Kind,
2779
- ArrayRef<TypeSourceInfo *> Args,
2780
- SourceLocation RParenLoc,
2781
- bool Value);
2777
+ ArrayRef<TypeSourceInfo *> Args, SourceLocation RParenLoc,
2778
+ std::variant<bool , APValue> Value);
2782
2779
2783
2780
TypeTraitExpr (EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {}
2784
2781
2785
2782
size_t numTrailingObjects (OverloadToken<TypeSourceInfo *>) const {
2786
2783
return getNumArgs ();
2787
2784
}
2788
2785
2786
+ size_t numTrailingObjects (OverloadToken<APValue>) const {
2787
+ return TypeTraitExprBits.IsBooleanTypeTrait ? 0 : 1 ;
2788
+ }
2789
+
2789
2790
public:
2790
2791
friend class ASTStmtReader ;
2791
2792
friend class ASTStmtWriter ;
@@ -2798,19 +2799,34 @@ class TypeTraitExpr final
2798
2799
SourceLocation RParenLoc,
2799
2800
bool Value);
2800
2801
2802
+ static TypeTraitExpr *Create (const ASTContext &C, QualType T,
2803
+ SourceLocation Loc, TypeTrait Kind,
2804
+ ArrayRef<TypeSourceInfo *> Args,
2805
+ SourceLocation RParenLoc, APValue Value);
2806
+
2801
2807
static TypeTraitExpr *CreateDeserialized (const ASTContext &C,
2808
+ bool IsStoredAsBool,
2802
2809
unsigned NumArgs);
2803
2810
2804
2811
// / Determine which type trait this expression uses.
2805
2812
TypeTrait getTrait () const {
2806
2813
return static_cast <TypeTrait>(TypeTraitExprBits.Kind );
2807
2814
}
2808
2815
2809
- bool getValue () const {
2810
- assert (!isValueDependent ());
2816
+ bool isStoredAsBoolean () const {
2817
+ return TypeTraitExprBits.IsBooleanTypeTrait ;
2818
+ }
2819
+
2820
+ bool getBoolValue () const {
2821
+ assert (!isValueDependent () && TypeTraitExprBits.IsBooleanTypeTrait );
2811
2822
return TypeTraitExprBits.Value ;
2812
2823
}
2813
2824
2825
+ const APValue &getAPValue () const {
2826
+ assert (!isValueDependent () && !TypeTraitExprBits.IsBooleanTypeTrait );
2827
+ return *getTrailingObjects<APValue>();
2828
+ }
2829
+
2814
2830
// / Determine the number of arguments to this type trait.
2815
2831
unsigned getNumArgs () const { return TypeTraitExprBits.NumArgs ; }
2816
2832
0 commit comments