@@ -680,11 +680,15 @@ enum class PathogenConstantValueKind : int
680
680
enum class PathogenStringConstantKind : int
681
681
{
682
682
Ascii,
683
+ // ! Never actually used. We replace this with the more appropriate UTF equivalent with WideCharBit set instead.
683
684
WideChar,
684
685
Utf8,
685
686
Utf16,
686
- Utf32
687
+ Utf32,
688
+ // ! When combined with one of the UTF values, indicates that the constant was originally a wchar_t string.
689
+ WideCharBit = 1 << 31 ,
687
690
};
691
+ PATHOGEN_FLAGS (PathogenStringConstantKind);
688
692
static_assert ((int )PathogenStringConstantKind::Ascii == StringLiteral::Ascii, "ASCII string kinds must match.");
689
693
static_assert ((int )PathogenStringConstantKind::WideChar == StringLiteral::Wide, "Wide character string kinds must match.");
690
694
static_assert ((int )PathogenStringConstantKind::Utf8 == StringLiteral::UTF8, "UTF8 string kinds must match.");
@@ -703,7 +707,7 @@ struct PathogenConstantValueInfo
703
707
bool HasUndefinedBehavior;
704
708
PathogenConstantValueKind Kind;
705
709
// ! If Kind is UnsignedInteger, SignedInteger, or FloatingPoint: This is the size of the value in bits
706
- // ! If Kind is String: This is one of PathogenStringConstantKind
710
+ // ! If Kind is String: This is one of PathogenStringConstantKind, potentially with WideCharBit set in the case of wchar_t.
707
711
// ! If Kind is Unknown, this is the Clang kind (APValue::ValueKind)
708
712
int SubKind;
709
713
// ! The value of the constant
@@ -807,7 +811,27 @@ PATHOGEN_EXPORT bool pathogen_ComputeConstantValue(CXCursor cursor, PathogenCons
807
811
{
808
812
const StringLiteral* stringLiteral = (const StringLiteral*)lValueExpr;
809
813
info->Kind = PathogenConstantValueKind::String;
810
- info->SubKind = (int )stringLiteral->getKind ();
814
+ PathogenStringConstantKind* stringKind = (PathogenStringConstantKind*)&info->SubKind ;
815
+ *stringKind = (PathogenStringConstantKind)stringLiteral->getKind ();
816
+
817
+ if (*stringKind == PathogenStringConstantKind::WideChar)
818
+ {
819
+ switch (stringLiteral->getCharByteWidth ())
820
+ {
821
+ case 1 :
822
+ *stringKind = PathogenStringConstantKind::Utf8 | PathogenStringConstantKind::WideCharBit;
823
+ break ;
824
+ case 2 :
825
+ *stringKind = PathogenStringConstantKind::Utf16 | PathogenStringConstantKind::WideCharBit;
826
+ break ;
827
+ case 4 :
828
+ *stringKind = PathogenStringConstantKind::Utf32 | PathogenStringConstantKind::WideCharBit;
829
+ break ;
830
+ default :
831
+ assert (false && " wchar_t string literal has an unexpected char width." );
832
+ break ;
833
+ }
834
+ }
811
835
812
836
PathogenConstantString* string = (PathogenConstantString*)malloc (sizeof (PathogenConstantString) + stringLiteral->getByteLength () - 1 );
813
837
string->SizeBytes = stringLiteral->getByteLength ();
0 commit comments