|
20 | 20 | #include "clang/Basic/TokenKinds.h"
|
21 | 21 | #include "clang/Lex/HeaderSearch.h"
|
22 | 22 | #include "clang/Lex/LexDiagnostic.h"
|
| 23 | +#include "clang/Lex/LiteralSupport.h" |
23 | 24 | #include "clang/Lex/MacroInfo.h"
|
24 | 25 | #include "clang/Lex/PPCallbacks.h"
|
25 | 26 | #include "clang/Lex/Preprocessor.h"
|
@@ -754,15 +755,52 @@ void Preprocessor::HandlePragmaIncludeAlias(Token &Tok) {
|
754 | 755 | getHeaderSearchInfo().AddIncludeAlias(OriginalSource, ReplaceFileName);
|
755 | 756 | }
|
756 | 757 |
|
| 758 | +// Lex a component of a module name: either an identifier or a string literal; |
| 759 | +// for components that can be expressed both ways, the two forms are equivalent. |
| 760 | +static bool LexModuleNameComponent( |
| 761 | + Preprocessor &PP, Token &Tok, |
| 762 | + std::pair<IdentifierInfo *, SourceLocation> &ModuleNameComponent, |
| 763 | + bool First) { |
| 764 | + PP.LexUnexpandedToken(Tok); |
| 765 | + if (Tok.is(tok::string_literal) && !Tok.hasUDSuffix()) { |
| 766 | + StringLiteralParser Literal(Tok, PP); |
| 767 | + if (Literal.hadError) |
| 768 | + return true; |
| 769 | + ModuleNameComponent = std::make_pair( |
| 770 | + PP.getIdentifierInfo(Literal.GetString()), Tok.getLocation()); |
| 771 | + } else if (!Tok.isAnnotation() && Tok.getIdentifierInfo()) { |
| 772 | + ModuleNameComponent = |
| 773 | + std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 774 | + } else { |
| 775 | + PP.Diag(Tok.getLocation(), diag::err_pp_expected_module_name) << First; |
| 776 | + return true; |
| 777 | + } |
| 778 | + return false; |
| 779 | +} |
| 780 | + |
| 781 | +static bool LexModuleName( |
| 782 | + Preprocessor &PP, Token &Tok, |
| 783 | + llvm::SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> |
| 784 | + &ModuleName) { |
| 785 | + while (true) { |
| 786 | + std::pair<IdentifierInfo*, SourceLocation> NameComponent; |
| 787 | + if (LexModuleNameComponent(PP, Tok, NameComponent, ModuleName.empty())) |
| 788 | + return true; |
| 789 | + ModuleName.push_back(NameComponent); |
| 790 | + |
| 791 | + PP.LexUnexpandedToken(Tok); |
| 792 | + if (Tok.isNot(tok::period)) |
| 793 | + return false; |
| 794 | + } |
| 795 | +} |
| 796 | + |
757 | 797 | void Preprocessor::HandlePragmaModuleBuild(Token &Tok) {
|
758 | 798 | SourceLocation Loc = Tok.getLocation();
|
759 | 799 |
|
760 |
| - LexUnexpandedToken(Tok); |
761 |
| - if (Tok.isAnnotation() || !Tok.getIdentifierInfo()) { |
762 |
| - Diag(Tok.getLocation(), diag::err_pp_expected_module_name) << true; |
| 800 | + std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc; |
| 801 | + if (LexModuleNameComponent(*this, Tok, ModuleNameLoc, true)) |
763 | 802 | return;
|
764 |
| - } |
765 |
| - IdentifierInfo *ModuleName = Tok.getIdentifierInfo(); |
| 803 | + IdentifierInfo *ModuleName = ModuleNameLoc.first; |
766 | 804 |
|
767 | 805 | LexUnexpandedToken(Tok);
|
768 | 806 | if (Tok.isNot(tok::eod)) {
|
@@ -1383,26 +1421,6 @@ struct PragmaMessageHandler : public PragmaHandler {
|
1383 | 1421 | }
|
1384 | 1422 | };
|
1385 | 1423 |
|
1386 |
| -static bool LexModuleName( |
1387 |
| - Preprocessor &PP, Token &Tok, |
1388 |
| - llvm::SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> |
1389 |
| - &ModuleName) { |
1390 |
| - while (true) { |
1391 |
| - PP.LexUnexpandedToken(Tok); |
1392 |
| - if (Tok.isAnnotation() || !Tok.getIdentifierInfo()) { |
1393 |
| - PP.Diag(Tok.getLocation(), diag::err_pp_expected_module_name) |
1394 |
| - << ModuleName.empty(); |
1395 |
| - return true; |
1396 |
| - } |
1397 |
| - |
1398 |
| - ModuleName.emplace_back(Tok.getIdentifierInfo(), Tok.getLocation()); |
1399 |
| - |
1400 |
| - PP.LexUnexpandedToken(Tok); |
1401 |
| - if (Tok.isNot(tok::period)) |
1402 |
| - return false; |
1403 |
| - } |
1404 |
| -} |
1405 |
| - |
1406 | 1424 | /// Handle the clang \#pragma module import extension. The syntax is:
|
1407 | 1425 | /// \code
|
1408 | 1426 | /// #pragma clang module import some.module.name
|
@@ -1473,7 +1491,7 @@ struct PragmaModuleBeginHandler : public PragmaHandler {
|
1473 | 1491 | // be loaded or implicitly loadable.
|
1474 | 1492 | // FIXME: We could create the submodule here. We'd need to know whether
|
1475 | 1493 | // it's supposed to be explicit, but not much else.
|
1476 |
| - Module *M = PP.getHeaderSearchInfo().getModuleMap().findModule(Current); |
| 1494 | + Module *M = PP.getHeaderSearchInfo().lookupModule(Current); |
1477 | 1495 | if (!M) {
|
1478 | 1496 | PP.Diag(ModuleName.front().second,
|
1479 | 1497 | diag::err_pp_module_begin_no_module_map) << Current;
|
|
0 commit comments