[cfe-commits] r145462 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h include/clang/Frontend/CompilerInstance.h include/clang/Lex/ModuleLoader.h include/clang/Sema/Sema.h lib/Frontend/CompilerInstance.cpp lib/Lex/PPDirectives.cpp lib/Lex/Preprocessor.cpp lib/Parse/Parser.cpp lib/Sema/SemaDecl.cpp
Douglas Gregor
dgregor at apple.com
Tue Nov 29 16:36:36 PST 2011
Author: dgregor
Date: Tue Nov 29 18:36:36 2011
New Revision: 145462
URL: http://llvm.org/viewvc/llvm-project?rev=145462&view=rev
Log:
Switch the module-loading interfaces and parser from a simple
top-level module name to a module path (e.g., std.vector). We're still
missing a number of pieces for this actually to do something.
Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/include/clang/Lex/ModuleLoader.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=145462&r1=145461&r2=145462&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Tue Nov 29 18:36:36 2011
@@ -781,9 +781,7 @@
/// \returns True if an error occurred, false otherwise.
bool serialize(raw_ostream &OS);
- virtual ModuleKey loadModule(SourceLocation ImportLoc,
- IdentifierInfo &ModuleName,
- SourceLocation ModuleNameLoc) {
+ virtual ModuleKey loadModule(SourceLocation ImportLoc, ModuleIdPath Path) {
// ASTUnit doesn't know how to load modules (not that this matters).
return 0;
}
Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=145462&r1=145461&r2=145462&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Tue Nov 29 18:36:36 2011
@@ -12,12 +12,14 @@
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Lex/ModuleLoader.h"
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/OwningPtr.h"
#include <cassert>
#include <list>
#include <string>
+#include <utility>
namespace llvm {
class raw_fd_ostream;
@@ -624,9 +626,7 @@
/// }
- virtual ModuleKey loadModule(SourceLocation ImportLoc,
- IdentifierInfo &ModuleName,
- SourceLocation ModuleNameLoc);
+ virtual ModuleKey loadModule(SourceLocation ImportLoc, ModuleIdPath Path);
};
} // end namespace clang
Modified: cfe/trunk/include/clang/Lex/ModuleLoader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleLoader.h?rev=145462&r1=145461&r2=145462&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleLoader.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleLoader.h Tue Nov 29 18:36:36 2011
@@ -15,6 +15,7 @@
#define LLVM_CLANG_LEX_MODULE_LOADER_H
#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/ArrayRef.h"
namespace clang {
@@ -24,6 +25,10 @@
/// interpreted by the module loader itself.
typedef void *ModuleKey;
+/// \brief A sequence of identifier/location pairs used to describe a particular
+/// module or submodule, e.g., std.vector.
+typedef llvm::ArrayRef<std::pair<IdentifierInfo*, SourceLocation> > ModuleIdPath;
+
/// \brief Abstract interface for a module loader.
///
/// This abstract interface describes a module loader, which is responsible
@@ -39,15 +44,13 @@
/// parameters.
///
/// \param ImportLoc The location of the 'import' keyword.
- /// \param ModuleName The name of the module to be loaded.
- /// \param ModuleNameLoc The location of the module name.
+ /// \param Path The identifiers (and their locations) of the module
+ /// "path", e.g., "std.vector" would be split into "std" and "vector".
///
/// \returns If successful, a non-NULL module key describing this module.
/// Otherwise, returns NULL to indicate that the module could not be
/// loaded.
- virtual ModuleKey loadModule(SourceLocation ImportLoc,
- IdentifierInfo &ModuleName,
- SourceLocation ModuleNameLoc) = 0;
+ virtual ModuleKey loadModule(SourceLocation ImportLoc, ModuleIdPath Path) = 0;
};
}
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=145462&r1=145461&r2=145462&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Nov 29 18:36:36 2011
@@ -29,6 +29,7 @@
#include "clang/AST/DeclarationName.h"
#include "clang/AST/ExternalASTSource.h"
#include "clang/AST/TypeLoc.h"
+#include "clang/Lex/ModuleLoader.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TemplateKinds.h"
#include "clang/Basic/TypeTraits.h"
@@ -1109,12 +1110,8 @@
///
/// \param ImportLoc The location of the '__import_module__' keyword.
///
- /// \param ModuleName The name of the module.
- ///
- /// \param ModuleNameLoc The location of the module name.
- DeclResult ActOnModuleImport(SourceLocation ImportLoc,
- IdentifierInfo &ModuleName,
- SourceLocation ModuleNameLoc);
+ /// \param Path The module access path.
+ DeclResult ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
/// \brief Diagnose that \p New is a module-private redeclaration of
/// \p Old.
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=145462&r1=145461&r2=145462&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue Nov 29 18:36:36 2011
@@ -1068,9 +1068,8 @@
llvm::sys::Path(TempModuleMapFileName).eraseFromDisk();
}
-ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc,
- IdentifierInfo &ModuleName,
- SourceLocation ModuleNameLoc) {
+ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc,
+ ModuleIdPath Path) {
// Determine what file we're searching from.
SourceManager &SourceMgr = getSourceManager();
SourceLocation ExpandedImportLoc = SourceMgr.getExpansionLoc(ImportLoc);
@@ -1079,13 +1078,19 @@
if (!CurFile)
CurFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
+ StringRef ModuleName = Path[0].first->getName();
+ SourceLocation ModuleNameLoc = Path[0].second;
+
// Search for a module with the given name.
ModuleMap::Module *Module = 0;
std::string ModuleFileName;
const FileEntry *ModuleFile
- = PP->getHeaderSearchInfo().lookupModule(ModuleName.getName(), Module,
+ = PP->getHeaderSearchInfo().lookupModule(ModuleName, Module,
&ModuleFileName);
+ // FIXME: Verify that the rest of the module path actually corresponds to
+ // a submodule, and pass that information through.
+
bool BuildingModule = false;
if (!ModuleFile && Module) {
// The module is not cached, but we have a module map from which we can
@@ -1095,23 +1100,22 @@
SmallVectorImpl<std::string> &ModuleBuildPath
= getPreprocessorOpts().ModuleBuildPath;
SmallVectorImpl<std::string>::iterator Pos
- = std::find(ModuleBuildPath.begin(), ModuleBuildPath.end(),
- ModuleName.getName());
+ = std::find(ModuleBuildPath.begin(), ModuleBuildPath.end(), ModuleName);
if (Pos != ModuleBuildPath.end()) {
llvm::SmallString<256> CyclePath;
for (; Pos != ModuleBuildPath.end(); ++Pos) {
CyclePath += *Pos;
CyclePath += " -> ";
}
- CyclePath += ModuleName.getName();
+ CyclePath += ModuleName;
getDiagnostics().Report(ModuleNameLoc, diag::err_module_cycle)
- << ModuleName.getName() << CyclePath;
+ << ModuleName << CyclePath;
return 0;
}
getDiagnostics().Report(ModuleNameLoc, diag::warn_module_build)
- << ModuleName.getName();
+ << ModuleName;
BuildingModule = true;
compileModule(*this, Module, ModuleFileName);
ModuleFile = FileMgr->getFile(ModuleFileName);
@@ -1121,7 +1125,7 @@
getDiagnostics().Report(ModuleNameLoc,
BuildingModule? diag::err_module_not_built
: diag::err_module_not_found)
- << ModuleName.getName()
+ << ModuleName
<< SourceRange(ImportLoc, ModuleNameLoc);
return 0;
}
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=145462&r1=145461&r2=145462&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Nov 29 18:36:36 2011
@@ -1279,13 +1279,17 @@
// If we are supposed to import a module rather than including the header,
// do so now.
if (SuggestedModule) {
- // FIXME: Actually load the submodule that we were given.
- while (SuggestedModule->Parent)
- SuggestedModule = SuggestedModule->Parent;
-
- TheModuleLoader.loadModule(IncludeTok.getLocation(),
- Identifiers.get(SuggestedModule->Name),
- FilenameTok.getLocation());
+ // Compute the module access path corresponding to this module.
+ // FIXME: Should we have a second loadModule() overload to avoid this
+ // extra lookup step?
+ llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
+ for (ModuleMap::Module *Mod = SuggestedModule; Mod; Mod = Mod->Parent)
+ Path.push_back(std::make_pair(getIdentifierInfo(Mod->Name),
+ FilenameTok.getLocation()));
+ std::reverse(Path.begin(), Path.end());
+
+ // Load the module.
+ TheModuleLoader.loadModule(IncludeTok.getLocation(), Path);
return;
}
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=145462&r1=145461&r2=145462&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Nov 29 18:36:36 2011
@@ -575,9 +575,11 @@
return;
// Load the module.
- (void)TheModuleLoader.loadModule(ModuleImportLoc,
- *Result.getIdentifierInfo(),
- Result.getLocation());
+ llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
+ Path.push_back(std::make_pair(Result.getIdentifierInfo(),
+ Result.getLocation()));
+
+ (void)TheModuleLoader.loadModule(ModuleImportLoc, Path);
}
void Preprocessor::AddCommentHandler(CommentHandler *Handler) {
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=145462&r1=145461&r2=145462&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Tue Nov 29 18:36:36 2011
@@ -1570,16 +1570,29 @@
"Improper start to module import");
SourceLocation ImportLoc = ConsumeToken();
- // Parse the module name.
- if (!Tok.is(tok::identifier)) {
- Diag(Tok, diag::err_module_expected_ident);
- SkipUntil(tok::semi);
- return DeclGroupPtrTy();
- }
+ llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
+
+ // Parse the module path.
+ do {
+ if (!Tok.is(tok::identifier)) {
+ Diag(Tok, diag::err_module_expected_ident);
+ SkipUntil(tok::semi);
+ return DeclGroupPtrTy();
+ }
+
+ // Record this part of the module path.
+ Path.push_back(std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()));
+ ConsumeToken();
+
+ if (Tok.is(tok::period)) {
+ ConsumeToken();
+ continue;
+ }
+
+ break;
+ } while (true);
- IdentifierInfo &ModuleName = *Tok.getIdentifierInfo();
- SourceLocation ModuleNameLoc = ConsumeToken();
- DeclResult Import = Actions.ActOnModuleImport(ImportLoc, ModuleName, ModuleNameLoc);
+ DeclResult Import = Actions.ActOnModuleImport(ImportLoc, Path);
ExpectAndConsumeSemi(diag::err_module_expected_semi);
if (Import.isInvalid())
return DeclGroupPtrTy();
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=145462&r1=145461&r2=145462&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 18:36:36 2011
@@ -9891,11 +9891,8 @@
return New;
}
-DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc,
- IdentifierInfo &ModuleName,
- SourceLocation ModuleNameLoc) {
- ModuleKey Module = PP.getModuleLoader().loadModule(ImportLoc,
- ModuleName, ModuleNameLoc);
+DeclResult Sema::ActOnModuleImport(SourceLocation ImportLoc, ModuleIdPath Path) {
+ ModuleKey Module = PP.getModuleLoader().loadModule(ImportLoc, Path);
if (!Module)
return true;
More information about the cfe-commits
mailing list