|
20 | 20 | #include "clang/AST/RecordLayout.h"
|
21 | 21 | #include "clang/AST/Reflection.h"
|
22 | 22 | #include "clang/Basic/SourceManager.h"
|
| 23 | +#include "clang/Lex/Lexer.h" |
23 | 24 | #include "clang/Lex/Preprocessor.h"
|
24 | 25 | #include "clang/Sema/Metafunction.h"
|
25 | 26 | #include "clang/Sema/ParsedTemplate.h"
|
@@ -392,7 +393,7 @@ static constexpr Metafunction Metafunctions[] = {
|
392 | 393 | { Metafunction::MFRK_bool, 1, 1, is_special_member },
|
393 | 394 | { Metafunction::MFRK_metaInfo, 2, 2, reflect_result },
|
394 | 395 | { Metafunction::MFRK_metaInfo, 5, 5, reflect_invoke },
|
395 |
| - { Metafunction::MFRK_metaInfo, 9, 9, data_member_spec }, |
| 396 | + { Metafunction::MFRK_metaInfo, 10, 10, data_member_spec }, |
396 | 397 | { Metafunction::MFRK_metaInfo, 3, 3, define_class },
|
397 | 398 | { Metafunction::MFRK_sizeT, 1, 1, offset_of },
|
398 | 399 | { Metafunction::MFRK_sizeT, 1, 1, size_of },
|
@@ -527,6 +528,7 @@ static void getTypeName(std::string &Result, ASTContext &C, QualType QT,
|
527 | 528 | bool BasicOnly) {
|
528 | 529 | PrintingPolicy PP = C.getPrintingPolicy();
|
529 | 530 | PP.SuppressTagKeyword = true;
|
| 531 | + PP.SuppressScope = true; |
530 | 532 |
|
531 | 533 | encodeName(Result, QT.getAsString(PP), BasicOnly);
|
532 | 534 | }
|
@@ -1779,27 +1781,20 @@ bool can_substitute(APValue &Result, Sema &S, EvalFn Evaluator,
|
1779 | 1781 |
|
1780 | 1782 | for (uint64_t k = 0; k < nArgs; ++k) {
|
1781 | 1783 | llvm::APInt Idx(S.Context.getTypeSize(S.Context.getSizeType()), k, false);
|
1782 |
| - Expr *IdxExpr = IntegerLiteral::Create(S.Context, Idx, |
1783 |
| - S.Context.getSizeType(), |
1784 |
| - Args[1]->getExprLoc()); |
1785 |
| - |
1786 |
| - ArraySubscriptExpr *SubscriptExpr = |
1787 |
| - new (S.Context) ArraySubscriptExpr(Args[1], IdxExpr, |
1788 |
| - S.Context.MetaInfoTy, |
1789 |
| - VK_LValue, OK_Ordinary, |
1790 |
| - Range.getBegin()); |
1791 |
| - |
1792 |
| - ImplicitCastExpr *RVExpr = ImplicitCastExpr::Create(S.Context, |
1793 |
| - S.Context.MetaInfoTy, |
1794 |
| - CK_LValueToRValue, |
1795 |
| - SubscriptExpr, |
1796 |
| - nullptr, VK_PRValue, |
1797 |
| - FPOptionsOverride()); |
1798 |
| - if (RVExpr->isValueDependent() || RVExpr->isTypeDependent()) |
| 1784 | + Expr *Synthesized = IntegerLiteral::Create(S.Context, Idx, |
| 1785 | + S.Context.getSizeType(), |
| 1786 | + Args[1]->getExprLoc()); |
| 1787 | + |
| 1788 | + Synthesized = new (S.Context) ArraySubscriptExpr(Args[1], Synthesized, |
| 1789 | + S.Context.MetaInfoTy, |
| 1790 | + VK_LValue, OK_Ordinary, |
| 1791 | + Range.getBegin()); |
| 1792 | + if (Synthesized->isValueDependent() || Synthesized->isTypeDependent()) |
1799 | 1793 | return true;
|
1800 | 1794 |
|
1801 | 1795 | APValue Unwrapped;
|
1802 |
| - if (!Evaluator(Unwrapped, RVExpr, true) || !Unwrapped.isReflection() || |
| 1796 | + if (!Evaluator(Unwrapped, Synthesized, true) || |
| 1797 | + !Unwrapped.isReflection() || |
1803 | 1798 | !CanActAsTemplateArg(Unwrapped.getReflection()))
|
1804 | 1799 | return true;
|
1805 | 1800 |
|
@@ -1852,27 +1847,20 @@ bool substitute(APValue &Result, Sema &S, EvalFn Evaluator, QualType ResultTy,
|
1852 | 1847 |
|
1853 | 1848 | for (uint64_t k = 0; k < nArgs; ++k) {
|
1854 | 1849 | llvm::APInt Idx(S.Context.getTypeSize(S.Context.getSizeType()), k, false);
|
1855 |
| - Expr *IdxExpr = IntegerLiteral::Create(S.Context, Idx, |
1856 |
| - S.Context.getSizeType(), |
1857 |
| - Args[1]->getExprLoc()); |
1858 |
| - |
1859 |
| - ArraySubscriptExpr *SubscriptExpr = |
1860 |
| - new (S.Context) ArraySubscriptExpr(Args[1], IdxExpr, |
1861 |
| - S.Context.MetaInfoTy, |
1862 |
| - VK_LValue, OK_Ordinary, |
1863 |
| - Range.getBegin()); |
1864 |
| - |
1865 |
| - ImplicitCastExpr *RVExpr = ImplicitCastExpr::Create(S.Context, |
1866 |
| - S.Context.MetaInfoTy, |
1867 |
| - CK_LValueToRValue, |
1868 |
| - SubscriptExpr, |
1869 |
| - nullptr, VK_PRValue, |
1870 |
| - FPOptionsOverride()); |
1871 |
| - if (RVExpr->isValueDependent() || RVExpr->isTypeDependent()) |
| 1850 | + Expr *Synthesized = IntegerLiteral::Create(S.Context, Idx, |
| 1851 | + S.Context.getSizeType(), |
| 1852 | + Args[1]->getExprLoc()); |
| 1853 | + |
| 1854 | + Synthesized = new (S.Context) ArraySubscriptExpr(Args[1], Synthesized, |
| 1855 | + S.Context.MetaInfoTy, |
| 1856 | + VK_LValue, OK_Ordinary, |
| 1857 | + Range.getBegin()); |
| 1858 | + if (Synthesized->isValueDependent() || Synthesized->isTypeDependent()) |
1872 | 1859 | return true;
|
1873 | 1860 |
|
1874 | 1861 | APValue Unwrapped;
|
1875 |
| - if (!Evaluator(Unwrapped, RVExpr, true) || !Unwrapped.isReflection() || |
| 1862 | + if (!Evaluator(Unwrapped, Synthesized, true) || |
| 1863 | + !Unwrapped.isReflection() || |
1876 | 1864 | !CanActAsTemplateArg(Unwrapped.getReflection()))
|
1877 | 1865 | return true;
|
1878 | 1866 |
|
@@ -3363,34 +3351,41 @@ bool data_member_spec(APValue &Result, Sema &S, EvalFn Evaluator,
|
3363 | 3351 | size_t nameLen = Scratch.getInt().getExtValue();
|
3364 | 3352 | Name.emplace(nameLen, '\0');
|
3365 | 3353 |
|
| 3354 | + // Evaluate the character type. |
| 3355 | + if (!Evaluator(Scratch, Args[ArgIdx++], true)) |
| 3356 | + return true; |
| 3357 | + QualType CharTy = Scratch.getReflectedType(); |
| 3358 | + |
| 3359 | + // Evaluate the data contents. |
3366 | 3360 | for (uint64_t k = 0; k < nameLen; ++k) {
|
3367 | 3361 | llvm::APInt Idx(S.Context.getTypeSize(S.Context.getSizeType()), k, false);
|
3368 |
| - Expr *IdxExpr = IntegerLiteral::Create(S.Context, Idx, |
3369 |
| - S.Context.getSizeType(), |
3370 |
| - Args[ArgIdx]->getExprLoc()); |
3371 |
| - |
3372 |
| - ArraySubscriptExpr *SubscriptExpr = |
3373 |
| - new (S.Context) ArraySubscriptExpr(Args[ArgIdx], IdxExpr, |
3374 |
| - S.Context.CharTy, |
3375 |
| - VK_LValue, OK_Ordinary, |
3376 |
| - Range.getBegin()); |
3377 |
| - |
3378 |
| - ImplicitCastExpr *RVExpr = ImplicitCastExpr::Create(S.Context, |
3379 |
| - S.Context.CharTy, |
3380 |
| - CK_LValueToRValue, |
3381 |
| - SubscriptExpr, |
3382 |
| - nullptr, VK_PRValue, |
3383 |
| - FPOptionsOverride()); |
3384 |
| - if (RVExpr->isValueDependent() || RVExpr->isTypeDependent()) |
| 3362 | + Expr *Synthesized = IntegerLiteral::Create(S.Context, Idx, |
| 3363 | + S.Context.getSizeType(), |
| 3364 | + Args[ArgIdx]->getExprLoc()); |
| 3365 | + |
| 3366 | + Synthesized = new (S.Context) ArraySubscriptExpr(Args[ArgIdx], |
| 3367 | + Synthesized, CharTy, |
| 3368 | + VK_LValue, OK_Ordinary, |
| 3369 | + Range.getBegin()); |
| 3370 | + if (Synthesized->isValueDependent() || Synthesized->isTypeDependent()) |
3385 | 3371 | return true;
|
3386 | 3372 |
|
3387 |
| - if (!Evaluator(Scratch, RVExpr, true)) |
| 3373 | + if (!Evaluator(Scratch, Synthesized, true)) |
3388 | 3374 | return true;
|
| 3375 | + |
3389 | 3376 | (*Name)[k] = static_cast<char>(Scratch.getInt().getExtValue());
|
3390 | 3377 | }
|
3391 | 3378 | ArgIdx++;
|
3392 | 3379 | } else {
|
3393 |
| - ArgIdx += 2; |
| 3380 | + ArgIdx += 3; |
| 3381 | + } |
| 3382 | + |
| 3383 | + // Validate the name as an identifier. |
| 3384 | + if (Name) { |
| 3385 | + Lexer Lex(Range.getBegin(), S.getLangOpts(), Name->data(), Name->data(), |
| 3386 | + Name->data() + Name->size(), false); |
| 3387 | + if (!Lex.validateAndRewriteIdentifier(*Name)) |
| 3388 | + return true; |
3394 | 3389 | }
|
3395 | 3390 |
|
3396 | 3391 | // Evaluate whether an alignment was provided.
|
@@ -3581,28 +3576,20 @@ bool define_class(APValue &Result, Sema &S, EvalFn Evaluator, QualType ResultTy,
|
3581 | 3576 | for (size_t k = 0; k < NumMembers; ++k) {
|
3582 | 3577 | // Extract the reflection from the list of member specs.
|
3583 | 3578 | llvm::APInt Idx(S.Context.getTypeSize(S.Context.getSizeType()), k, false);
|
3584 |
| - Expr *IdxExpr = IntegerLiteral::Create(S.Context, Idx, |
3585 |
| - S.Context.getSizeType(), |
3586 |
| - Args[2]->getExprLoc()); |
3587 |
| - |
3588 |
| - ArraySubscriptExpr *SubscriptExpr = |
3589 |
| - new (S.Context) ArraySubscriptExpr(Args[2], IdxExpr, |
3590 |
| - S.Context.MetaInfoTy, |
3591 |
| - VK_LValue, OK_Ordinary, |
3592 |
| - Range.getBegin()); |
3593 |
| - |
3594 |
| - ImplicitCastExpr *RVExpr = ImplicitCastExpr::Create(S.Context, |
3595 |
| - S.Context.MetaInfoTy, |
3596 |
| - CK_LValueToRValue, |
3597 |
| - SubscriptExpr, |
3598 |
| - nullptr, VK_PRValue, |
3599 |
| - FPOptionsOverride()); |
3600 |
| - if (RVExpr->isValueDependent() || RVExpr->isTypeDependent()) { |
| 3579 | + Expr *Synthesized = IntegerLiteral::Create(S.Context, Idx, |
| 3580 | + S.Context.getSizeType(), |
| 3581 | + Args[2]->getExprLoc()); |
| 3582 | + |
| 3583 | + Synthesized = new (S.Context) ArraySubscriptExpr(Args[2], Synthesized, |
| 3584 | + S.Context.MetaInfoTy, |
| 3585 | + VK_LValue, OK_Ordinary, |
| 3586 | + Range.getBegin()); |
| 3587 | + if (Synthesized->isValueDependent() || Synthesized->isTypeDependent()) { |
3601 | 3588 | RestoreDC();
|
3602 | 3589 | return true;
|
3603 | 3590 | }
|
3604 | 3591 |
|
3605 |
| - if (!Evaluator(Scratch, RVExpr, true) || |
| 3592 | + if (!Evaluator(Scratch, Synthesized, true) || |
3606 | 3593 | Scratch.getReflection().getKind() !=
|
3607 | 3594 | ReflectionValue::RK_data_member_spec) {
|
3608 | 3595 | RestoreDC();
|
|
0 commit comments