aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/Preprocessor.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-11-30 04:26:53 +0000
committerDouglas Gregor <dgregor@apple.com>2011-11-30 04:26:53 +0000
commit1805b8a42f1a636f6f8c0adb276cc610ac009a2b (patch)
tree2052b5a8313073eaf8423df83b1eae53a6f43400 /clang/lib/Lex/Preprocessor.cpp
parent5196bc6b39b5890697f9f2b0bbde1233a0b26dda (diff)
downloadllvm-1805b8a42f1a636f6f8c0adb276cc610ac009a2b.zip
llvm-1805b8a42f1a636f6f8c0adb276cc610ac009a2b.tar.gz
llvm-1805b8a42f1a636f6f8c0adb276cc610ac009a2b.tar.bz2
Teach the preprocessor how to handle module import declarations that
involve submodules (e.g., importing std.vector), rather than always importing the top-level module. llvm-svn: 145478
Diffstat (limited to 'clang/lib/Lex/Preprocessor.cpp')
-rw-r--r--clang/lib/Lex/Preprocessor.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index aeba32f..b011130 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -546,6 +546,8 @@ void Preprocessor::HandleIdentifier(Token &Identifier) {
if (II.getTokenID() == tok::kw___import_module__ &&
!InMacroArgs && !DisableMacroExpansion) {
ModuleImportLoc = Identifier.getLocation();
+ ModuleImportPath.clear();
+ ModuleImportExpectsIdentifier = true;
CurLexerKind = CLK_LexAfterModuleImport;
}
}
@@ -567,19 +569,31 @@ void Preprocessor::LexAfterModuleImport(Token &Result) {
// The token sequence
//
- // __import_module__ identifier
+ // __import_module__ identifier (. identifier)*
//
// indicates a module import directive. We already saw the __import_module__
- // keyword, so now we're looking for the identifier.
- if (Result.getKind() != tok::identifier)
+ // keyword, so now we're looking for the identifiers.
+ if (ModuleImportExpectsIdentifier && Result.getKind() == tok::identifier) {
+ // We expected to see an identifier here, and we did; continue handling
+ // identifiers.
+ ModuleImportPath.push_back(std::make_pair(Result.getIdentifierInfo(),
+ Result.getLocation()));
+ ModuleImportExpectsIdentifier = false;
+ CurLexerKind = CLK_LexAfterModuleImport;
return;
+ }
- // Load the module.
- llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
- Path.push_back(std::make_pair(Result.getIdentifierInfo(),
- Result.getLocation()));
-
- (void)TheModuleLoader.loadModule(ModuleImportLoc, Path);
+ // If we're expecting a '.' or a ';', and we got a '.', then wait until we
+ // see the next identifier.
+ if (!ModuleImportExpectsIdentifier && Result.getKind() == tok::period) {
+ ModuleImportExpectsIdentifier = true;
+ CurLexerKind = CLK_LexAfterModuleImport;
+ return;
+ }
+
+ // If we have a non-empty module path, load the named module.
+ if (!ModuleImportPath.empty())
+ (void)TheModuleLoader.loadModule(ModuleImportLoc, ModuleImportPath);
}
void Preprocessor::AddCommentHandler(CommentHandler *Handler) {