2011-11-12 03:10:28 +08:00
|
|
|
//===--- ModuleMap.cpp - Describe the layout of modules ---------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the ModuleMap implementation, which describes the layout
|
|
|
|
// of a module as it relates to headers.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Lex/ModuleMap.h"
|
|
|
|
#include "clang/Lex/Lexer.h"
|
|
|
|
#include "clang/Lex/LiteralSupport.h"
|
|
|
|
#include "clang/Lex/LexDiagnostic.h"
|
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/TargetInfo.h"
|
|
|
|
#include "clang/Basic/TargetOptions.h"
|
|
|
|
#include "llvm/Support/Allocator.h"
|
2011-12-07 03:39:29 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2011-11-12 03:10:28 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
2011-11-12 05:55:48 +08:00
|
|
|
#include "llvm/Support/PathV2.h"
|
2011-11-12 03:10:28 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
|
using namespace clang;
|
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
Module::ExportDecl
|
|
|
|
ModuleMap::resolveExport(Module *Mod,
|
|
|
|
const Module::UnresolvedExportDecl &Unresolved,
|
|
|
|
bool Complain) {
|
2011-12-06 01:28:06 +08:00
|
|
|
// We may have just a wildcard.
|
|
|
|
if (Unresolved.Id.empty()) {
|
|
|
|
assert(Unresolved.Wildcard && "Invalid unresolved export");
|
|
|
|
return Module::ExportDecl(0, true);
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
// Find the starting module.
|
|
|
|
Module *Context = lookupModuleUnqualified(Unresolved.Id[0].first, Mod);
|
|
|
|
if (!Context) {
|
|
|
|
if (Complain)
|
|
|
|
Diags->Report(Unresolved.Id[0].second,
|
|
|
|
diag::err_mmap_missing_module_unqualified)
|
|
|
|
<< Unresolved.Id[0].first << Mod->getFullModuleName();
|
|
|
|
|
|
|
|
return Module::ExportDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dig into the module path.
|
|
|
|
for (unsigned I = 1, N = Unresolved.Id.size(); I != N; ++I) {
|
|
|
|
Module *Sub = lookupModuleQualified(Unresolved.Id[I].first,
|
|
|
|
Context);
|
|
|
|
if (!Sub) {
|
|
|
|
if (Complain)
|
|
|
|
Diags->Report(Unresolved.Id[I].second,
|
|
|
|
diag::err_mmap_missing_module_qualified)
|
|
|
|
<< Unresolved.Id[I].first << Context->getFullModuleName()
|
|
|
|
<< SourceRange(Unresolved.Id[0].second, Unresolved.Id[I-1].second);
|
|
|
|
|
|
|
|
return Module::ExportDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
Context = Sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Module::ExportDecl(Context, Unresolved.Wildcard);
|
|
|
|
}
|
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
ModuleMap::ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC,
|
2012-01-30 14:01:29 +08:00
|
|
|
const LangOptions &LangOpts, const TargetInfo *Target)
|
2012-02-03 02:42:48 +08:00
|
|
|
: LangOpts(LangOpts), Target(Target), BuiltinIncludeDir(0)
|
2011-12-31 12:05:44 +08:00
|
|
|
{
|
2011-11-12 03:10:28 +08:00
|
|
|
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(new DiagnosticIDs);
|
|
|
|
Diags = llvm::IntrusiveRefCntPtr<DiagnosticsEngine>(
|
|
|
|
new DiagnosticsEngine(DiagIDs));
|
|
|
|
Diags->setClient(DC.clone(*Diags), /*ShouldOwnClient=*/true);
|
|
|
|
SourceMgr = new SourceManager(*Diags, FileMgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
ModuleMap::~ModuleMap() {
|
2011-11-17 10:05:44 +08:00
|
|
|
for (llvm::StringMap<Module *>::iterator I = Modules.begin(),
|
|
|
|
IEnd = Modules.end();
|
|
|
|
I != IEnd; ++I) {
|
|
|
|
delete I->getValue();
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
delete SourceMgr;
|
|
|
|
}
|
|
|
|
|
2012-01-30 14:01:29 +08:00
|
|
|
void ModuleMap::setTarget(const TargetInfo &Target) {
|
|
|
|
assert((!this->Target || this->Target == &Target) &&
|
|
|
|
"Improper target override");
|
|
|
|
this->Target = &Target;
|
|
|
|
}
|
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
Module *ModuleMap::findModuleForHeader(const FileEntry *File) {
|
2011-11-12 06:18:48 +08:00
|
|
|
llvm::DenseMap<const FileEntry *, Module *>::iterator Known
|
|
|
|
= Headers.find(File);
|
2011-12-31 12:05:44 +08:00
|
|
|
if (Known != Headers.end()) {
|
|
|
|
// If a header corresponds to an unavailable module, don't report
|
|
|
|
// that it maps to anything.
|
|
|
|
if (!Known->second->isAvailable())
|
|
|
|
return 0;
|
|
|
|
|
2011-11-12 06:18:48 +08:00
|
|
|
return Known->second;
|
2011-12-31 12:05:44 +08:00
|
|
|
}
|
2011-11-12 06:18:48 +08:00
|
|
|
|
2011-11-17 07:02:25 +08:00
|
|
|
const DirectoryEntry *Dir = File->getDir();
|
|
|
|
llvm::SmallVector<const DirectoryEntry *, 2> SkippedDirs;
|
|
|
|
StringRef DirName = Dir->getName();
|
2011-12-06 09:10:29 +08:00
|
|
|
|
|
|
|
// Keep walking up the directory hierarchy, looking for a directory with
|
|
|
|
// an umbrella header.
|
|
|
|
do {
|
|
|
|
llvm::DenseMap<const DirectoryEntry *, Module *>::iterator KnownDir
|
|
|
|
= UmbrellaDirs.find(Dir);
|
2011-11-17 07:02:25 +08:00
|
|
|
if (KnownDir != UmbrellaDirs.end()) {
|
|
|
|
Module *Result = KnownDir->second;
|
2011-12-07 00:17:15 +08:00
|
|
|
|
|
|
|
// Search up the module stack until we find a module with an umbrella
|
2011-12-09 01:39:04 +08:00
|
|
|
// directory.
|
2011-12-07 00:17:15 +08:00
|
|
|
Module *UmbrellaModule = Result;
|
2011-12-09 01:39:04 +08:00
|
|
|
while (!UmbrellaModule->getUmbrellaDir() && UmbrellaModule->Parent)
|
2011-12-07 00:17:15 +08:00
|
|
|
UmbrellaModule = UmbrellaModule->Parent;
|
2011-12-31 12:05:44 +08:00
|
|
|
|
2011-12-07 00:17:15 +08:00
|
|
|
if (UmbrellaModule->InferSubmodules) {
|
2011-12-06 09:10:29 +08:00
|
|
|
// Infer submodules for each of the directories we found between
|
|
|
|
// the directory of the umbrella header and the directory where
|
|
|
|
// the actual header is located.
|
2011-12-08 06:05:21 +08:00
|
|
|
bool Explicit = UmbrellaModule->InferExplicitSubmodules;
|
2011-12-06 09:10:29 +08:00
|
|
|
|
2011-12-09 10:04:43 +08:00
|
|
|
for (unsigned I = SkippedDirs.size(); I != 0; --I) {
|
2011-12-06 09:10:29 +08:00
|
|
|
// Find or create the module that corresponds to this directory name.
|
|
|
|
StringRef Name = llvm::sys::path::stem(SkippedDirs[I-1]->getName());
|
|
|
|
Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
|
2011-12-08 06:05:21 +08:00
|
|
|
Explicit).first;
|
2011-12-06 09:10:29 +08:00
|
|
|
|
|
|
|
// Associate the module and the directory.
|
|
|
|
UmbrellaDirs[SkippedDirs[I-1]] = Result;
|
|
|
|
|
|
|
|
// If inferred submodules export everything they import, add a
|
|
|
|
// wildcard to the set of exports.
|
2011-12-07 00:17:15 +08:00
|
|
|
if (UmbrellaModule->InferExportWildcard && Result->Exports.empty())
|
2011-12-06 09:10:29 +08:00
|
|
|
Result->Exports.push_back(Module::ExportDecl(0, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Infer a submodule with the same name as this header file.
|
|
|
|
StringRef Name = llvm::sys::path::stem(File->getName());
|
|
|
|
Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
|
2011-12-08 06:05:21 +08:00
|
|
|
Explicit).first;
|
2011-12-06 09:10:29 +08:00
|
|
|
|
|
|
|
// If inferred submodules export everything they import, add a
|
|
|
|
// wildcard to the set of exports.
|
2011-12-07 00:17:15 +08:00
|
|
|
if (UmbrellaModule->InferExportWildcard && Result->Exports.empty())
|
2011-12-06 09:10:29 +08:00
|
|
|
Result->Exports.push_back(Module::ExportDecl(0, true));
|
|
|
|
} else {
|
|
|
|
// Record each of the directories we stepped through as being part of
|
|
|
|
// the module we found, since the umbrella header covers them all.
|
|
|
|
for (unsigned I = 0, N = SkippedDirs.size(); I != N; ++I)
|
|
|
|
UmbrellaDirs[SkippedDirs[I]] = Result;
|
|
|
|
}
|
2011-11-17 07:02:25 +08:00
|
|
|
|
2011-12-06 09:10:29 +08:00
|
|
|
Headers[File] = Result;
|
2011-12-31 12:05:44 +08:00
|
|
|
|
|
|
|
// If a header corresponds to an unavailable module, don't report
|
|
|
|
// that it maps to anything.
|
|
|
|
if (!Result->isAvailable())
|
|
|
|
return 0;
|
|
|
|
|
2011-11-17 07:02:25 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkippedDirs.push_back(Dir);
|
2011-12-06 09:10:29 +08:00
|
|
|
|
|
|
|
// Retrieve our parent path.
|
|
|
|
DirName = llvm::sys::path::parent_path(DirName);
|
|
|
|
if (DirName.empty())
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Resolve the parent path to a directory entry.
|
|
|
|
Dir = SourceMgr->getFileManager().getDirectory(DirName);
|
|
|
|
} while (Dir);
|
2011-11-17 07:02:25 +08:00
|
|
|
|
2011-11-12 06:18:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
bool ModuleMap::isHeaderInUnavailableModule(const FileEntry *Header) {
|
|
|
|
llvm::DenseMap<const FileEntry *, Module *>::iterator Known
|
|
|
|
= Headers.find(Header);
|
|
|
|
if (Known != Headers.end())
|
|
|
|
return !Known->second->isAvailable();
|
|
|
|
|
|
|
|
const DirectoryEntry *Dir = Header->getDir();
|
|
|
|
llvm::SmallVector<const DirectoryEntry *, 2> SkippedDirs;
|
|
|
|
StringRef DirName = Dir->getName();
|
|
|
|
|
|
|
|
// Keep walking up the directory hierarchy, looking for a directory with
|
|
|
|
// an umbrella header.
|
|
|
|
do {
|
|
|
|
llvm::DenseMap<const DirectoryEntry *, Module *>::iterator KnownDir
|
|
|
|
= UmbrellaDirs.find(Dir);
|
|
|
|
if (KnownDir != UmbrellaDirs.end()) {
|
|
|
|
Module *Found = KnownDir->second;
|
|
|
|
if (!Found->isAvailable())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Search up the module stack until we find a module with an umbrella
|
|
|
|
// directory.
|
|
|
|
Module *UmbrellaModule = Found;
|
|
|
|
while (!UmbrellaModule->getUmbrellaDir() && UmbrellaModule->Parent)
|
|
|
|
UmbrellaModule = UmbrellaModule->Parent;
|
|
|
|
|
|
|
|
if (UmbrellaModule->InferSubmodules) {
|
|
|
|
for (unsigned I = SkippedDirs.size(); I != 0; --I) {
|
|
|
|
// Find or create the module that corresponds to this directory name.
|
|
|
|
StringRef Name = llvm::sys::path::stem(SkippedDirs[I-1]->getName());
|
|
|
|
Found = lookupModuleQualified(Name, Found);
|
|
|
|
if (!Found)
|
|
|
|
return false;
|
|
|
|
if (!Found->isAvailable())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Infer a submodule with the same name as this header file.
|
|
|
|
StringRef Name = llvm::sys::path::stem(Header->getName());
|
|
|
|
Found = lookupModuleQualified(Name, Found);
|
|
|
|
if (!Found)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !Found->isAvailable();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkippedDirs.push_back(Dir);
|
|
|
|
|
|
|
|
// Retrieve our parent path.
|
|
|
|
DirName = llvm::sys::path::parent_path(DirName);
|
|
|
|
if (DirName.empty())
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Resolve the parent path to a directory entry.
|
|
|
|
Dir = SourceMgr->getFileManager().getDirectory(DirName);
|
|
|
|
} while (Dir);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
Module *ModuleMap::findModule(StringRef Name) {
|
2011-11-12 07:20:24 +08:00
|
|
|
llvm::StringMap<Module *>::iterator Known = Modules.find(Name);
|
|
|
|
if (Known != Modules.end())
|
|
|
|
return Known->getValue();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
Module *ModuleMap::lookupModuleUnqualified(StringRef Name, Module *Context) {
|
|
|
|
for(; Context; Context = Context->Parent) {
|
|
|
|
if (Module *Sub = lookupModuleQualified(Name, Context))
|
|
|
|
return Sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
return findModule(Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) {
|
|
|
|
if (!Context)
|
|
|
|
return findModule(Name);
|
|
|
|
|
2012-01-05 07:32:19 +08:00
|
|
|
return Context->findSubmodule(Name);
|
2011-12-02 09:47:07 +08:00
|
|
|
}
|
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
std::pair<Module *, bool>
|
2011-12-01 01:33:56 +08:00
|
|
|
ModuleMap::findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
|
|
|
|
bool IsExplicit) {
|
|
|
|
// Try to find an existing module with this name.
|
2012-01-05 07:32:19 +08:00
|
|
|
if (Module *Sub = lookupModuleQualified(Name, Parent))
|
|
|
|
return std::make_pair(Sub, false);
|
2011-12-01 01:33:56 +08:00
|
|
|
|
|
|
|
// Create a new module with this name.
|
|
|
|
Module *Result = new Module(Name, SourceLocation(), Parent, IsFramework,
|
|
|
|
IsExplicit);
|
2012-01-05 07:32:19 +08:00
|
|
|
if (!Parent)
|
2011-12-01 01:33:56 +08:00
|
|
|
Modules[Name] = Result;
|
|
|
|
return std::make_pair(Result, true);
|
|
|
|
}
|
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
Module *
|
2011-11-17 09:41:17 +08:00
|
|
|
ModuleMap::inferFrameworkModule(StringRef ModuleName,
|
2011-12-07 03:39:29 +08:00
|
|
|
const DirectoryEntry *FrameworkDir,
|
2012-01-28 03:52:33 +08:00
|
|
|
bool IsSystem,
|
2011-12-07 03:39:29 +08:00
|
|
|
Module *Parent) {
|
2011-11-17 09:41:17 +08:00
|
|
|
// Check whether we've already found this module.
|
2011-12-07 03:39:29 +08:00
|
|
|
if (Module *Mod = lookupModuleQualified(ModuleName, Parent))
|
|
|
|
return Mod;
|
|
|
|
|
|
|
|
FileManager &FileMgr = SourceMgr->getFileManager();
|
2011-11-17 09:41:17 +08:00
|
|
|
|
|
|
|
// Look for an umbrella header.
|
|
|
|
llvm::SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName());
|
|
|
|
llvm::sys::path::append(UmbrellaName, "Headers");
|
|
|
|
llvm::sys::path::append(UmbrellaName, ModuleName + ".h");
|
2011-12-07 03:39:29 +08:00
|
|
|
const FileEntry *UmbrellaHeader = FileMgr.getFile(UmbrellaName);
|
2011-11-17 09:41:17 +08:00
|
|
|
|
|
|
|
// FIXME: If there's no umbrella header, we could probably scan the
|
|
|
|
// framework to load *everything*. But, it's not clear that this is a good
|
|
|
|
// idea.
|
|
|
|
if (!UmbrellaHeader)
|
|
|
|
return 0;
|
|
|
|
|
2011-12-07 03:39:29 +08:00
|
|
|
Module *Result = new Module(ModuleName, SourceLocation(), Parent,
|
|
|
|
/*IsFramework=*/true, /*IsExplicit=*/false);
|
2012-01-28 03:52:33 +08:00
|
|
|
if (IsSystem)
|
|
|
|
Result->IsSystem = IsSystem;
|
|
|
|
|
2012-01-05 07:32:19 +08:00
|
|
|
if (!Parent)
|
2011-12-07 03:39:29 +08:00
|
|
|
Modules[ModuleName] = Result;
|
2012-01-05 07:32:19 +08:00
|
|
|
|
2011-12-09 02:00:48 +08:00
|
|
|
// umbrella header "umbrella-header-name"
|
2011-12-09 01:39:04 +08:00
|
|
|
Result->Umbrella = UmbrellaHeader;
|
2011-11-17 09:41:17 +08:00
|
|
|
Headers[UmbrellaHeader] = Result;
|
2011-12-13 07:55:05 +08:00
|
|
|
UmbrellaDirs[UmbrellaHeader->getDir()] = Result;
|
2011-12-06 01:40:25 +08:00
|
|
|
|
|
|
|
// export *
|
|
|
|
Result->Exports.push_back(Module::ExportDecl(0, true));
|
|
|
|
|
2011-12-06 09:10:29 +08:00
|
|
|
// module * { export * }
|
|
|
|
Result->InferSubmodules = true;
|
|
|
|
Result->InferExportWildcard = true;
|
|
|
|
|
2011-12-07 03:39:29 +08:00
|
|
|
// Look for subframeworks.
|
|
|
|
llvm::error_code EC;
|
2011-12-09 00:13:24 +08:00
|
|
|
llvm::SmallString<128> SubframeworksDirName
|
|
|
|
= StringRef(FrameworkDir->getName());
|
2011-12-07 03:39:29 +08:00
|
|
|
llvm::sys::path::append(SubframeworksDirName, "Frameworks");
|
2011-12-09 00:13:24 +08:00
|
|
|
llvm::SmallString<128> SubframeworksDirNameNative;
|
|
|
|
llvm::sys::path::native(SubframeworksDirName.str(),
|
|
|
|
SubframeworksDirNameNative);
|
|
|
|
for (llvm::sys::fs::directory_iterator
|
|
|
|
Dir(SubframeworksDirNameNative.str(), EC), DirEnd;
|
2011-12-07 03:39:29 +08:00
|
|
|
Dir != DirEnd && !EC; Dir.increment(EC)) {
|
|
|
|
if (!StringRef(Dir->path()).endswith(".framework"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (const DirectoryEntry *SubframeworkDir
|
|
|
|
= FileMgr.getDirectory(Dir->path())) {
|
|
|
|
// FIXME: Do we want to warn about subframeworks without umbrella headers?
|
|
|
|
inferFrameworkModule(llvm::sys::path::stem(Dir->path()), SubframeworkDir,
|
2012-01-28 03:52:33 +08:00
|
|
|
IsSystem, Result);
|
2011-12-07 03:39:29 +08:00
|
|
|
}
|
|
|
|
}
|
2012-01-14 00:54:27 +08:00
|
|
|
|
2011-11-17 09:41:17 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2011-12-06 09:10:29 +08:00
|
|
|
void ModuleMap::setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader){
|
|
|
|
Headers[UmbrellaHeader] = Mod;
|
2011-12-09 01:39:04 +08:00
|
|
|
Mod->Umbrella = UmbrellaHeader;
|
2011-12-09 10:04:43 +08:00
|
|
|
UmbrellaDirs[UmbrellaHeader->getDir()] = Mod;
|
2011-12-06 09:10:29 +08:00
|
|
|
}
|
|
|
|
|
2011-12-09 03:11:24 +08:00
|
|
|
void ModuleMap::setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir) {
|
|
|
|
Mod->Umbrella = UmbrellaDir;
|
|
|
|
UmbrellaDirs[UmbrellaDir] = Mod;
|
|
|
|
}
|
|
|
|
|
2011-12-06 09:10:29 +08:00
|
|
|
void ModuleMap::addHeader(Module *Mod, const FileEntry *Header) {
|
|
|
|
Mod->Headers.push_back(Header);
|
|
|
|
Headers[Header] = Mod;
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:06:37 +08:00
|
|
|
const FileEntry *
|
2011-12-01 07:21:26 +08:00
|
|
|
ModuleMap::getContainingModuleMapFile(Module *Module) {
|
2011-11-30 03:06:37 +08:00
|
|
|
if (Module->DefinitionLoc.isInvalid() || !SourceMgr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return SourceMgr->getFileEntryForID(
|
|
|
|
SourceMgr->getFileID(Module->DefinitionLoc));
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
void ModuleMap::dump() {
|
|
|
|
llvm::errs() << "Modules:";
|
|
|
|
for (llvm::StringMap<Module *>::iterator M = Modules.begin(),
|
|
|
|
MEnd = Modules.end();
|
|
|
|
M != MEnd; ++M)
|
2011-11-30 02:17:59 +08:00
|
|
|
M->getValue()->print(llvm::errs(), 2);
|
2011-11-12 03:10:28 +08:00
|
|
|
|
|
|
|
llvm::errs() << "Headers:";
|
|
|
|
for (llvm::DenseMap<const FileEntry *, Module *>::iterator
|
|
|
|
H = Headers.begin(),
|
|
|
|
HEnd = Headers.end();
|
|
|
|
H != HEnd; ++H) {
|
|
|
|
llvm::errs() << " \"" << H->first->getName() << "\" -> "
|
|
|
|
<< H->second->getFullModuleName() << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
bool ModuleMap::resolveExports(Module *Mod, bool Complain) {
|
|
|
|
bool HadError = false;
|
|
|
|
for (unsigned I = 0, N = Mod->UnresolvedExports.size(); I != N; ++I) {
|
|
|
|
Module::ExportDecl Export = resolveExport(Mod, Mod->UnresolvedExports[I],
|
|
|
|
Complain);
|
2011-12-06 01:28:06 +08:00
|
|
|
if (Export.getPointer() || Export.getInt())
|
2011-12-02 09:47:07 +08:00
|
|
|
Mod->Exports.push_back(Export);
|
|
|
|
else
|
|
|
|
HadError = true;
|
|
|
|
}
|
|
|
|
Mod->UnresolvedExports.clear();
|
|
|
|
return HadError;
|
|
|
|
}
|
|
|
|
|
2011-12-06 00:33:54 +08:00
|
|
|
Module *ModuleMap::inferModuleFromLocation(FullSourceLoc Loc) {
|
|
|
|
if (Loc.isInvalid())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Use the expansion location to determine which module we're in.
|
|
|
|
FullSourceLoc ExpansionLoc = Loc.getExpansionLoc();
|
|
|
|
if (!ExpansionLoc.isFileID())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
const SourceManager &SrcMgr = Loc.getManager();
|
|
|
|
FileID ExpansionFileID = ExpansionLoc.getFileID();
|
|
|
|
|
2012-01-07 01:19:32 +08:00
|
|
|
while (const FileEntry *ExpansionFile
|
|
|
|
= SrcMgr.getFileEntryForID(ExpansionFileID)) {
|
|
|
|
// Find the module that owns this header (if any).
|
|
|
|
if (Module *Mod = findModuleForHeader(ExpansionFile))
|
|
|
|
return Mod;
|
|
|
|
|
|
|
|
// No module owns this header, so look up the inclusion chain to see if
|
|
|
|
// any included header has an associated module.
|
|
|
|
SourceLocation IncludeLoc = SrcMgr.getIncludeLoc(ExpansionFileID);
|
|
|
|
if (IncludeLoc.isInvalid())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ExpansionFileID = SrcMgr.getFileID(IncludeLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-12-06 00:33:54 +08:00
|
|
|
}
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// Module map file parser
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
/// \brief A token in a module map file.
|
|
|
|
struct MMToken {
|
|
|
|
enum TokenKind {
|
2011-12-31 12:05:44 +08:00
|
|
|
Comma,
|
2011-11-12 03:10:28 +08:00
|
|
|
EndOfFile,
|
|
|
|
HeaderKeyword,
|
|
|
|
Identifier,
|
|
|
|
ExplicitKeyword,
|
2011-12-02 09:47:07 +08:00
|
|
|
ExportKeyword,
|
2011-11-18 06:09:43 +08:00
|
|
|
FrameworkKeyword,
|
2011-11-12 03:10:28 +08:00
|
|
|
ModuleKeyword,
|
2011-12-02 09:47:07 +08:00
|
|
|
Period,
|
2011-11-12 03:10:28 +08:00
|
|
|
UmbrellaKeyword,
|
2011-12-31 12:05:44 +08:00
|
|
|
RequiresKeyword,
|
2011-12-02 09:47:07 +08:00
|
|
|
Star,
|
2011-11-12 03:10:28 +08:00
|
|
|
StringLiteral,
|
|
|
|
LBrace,
|
2012-01-28 03:52:33 +08:00
|
|
|
RBrace,
|
|
|
|
LSquare,
|
|
|
|
RSquare
|
2011-11-12 03:10:28 +08:00
|
|
|
} Kind;
|
|
|
|
|
|
|
|
unsigned Location;
|
|
|
|
unsigned StringLength;
|
|
|
|
const char *StringData;
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
Kind = EndOfFile;
|
|
|
|
Location = 0;
|
|
|
|
StringLength = 0;
|
|
|
|
StringData = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is(TokenKind K) const { return Kind == K; }
|
|
|
|
|
|
|
|
SourceLocation getLocation() const {
|
|
|
|
return SourceLocation::getFromRawEncoding(Location);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef getString() const {
|
|
|
|
return StringRef(StringData, StringLength);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ModuleMapParser {
|
|
|
|
Lexer &L;
|
|
|
|
SourceManager &SourceMgr;
|
|
|
|
DiagnosticsEngine &Diags;
|
|
|
|
ModuleMap ⤅
|
|
|
|
|
2011-11-12 05:55:48 +08:00
|
|
|
/// \brief The directory that this module map resides in.
|
|
|
|
const DirectoryEntry *Directory;
|
2012-02-03 02:42:48 +08:00
|
|
|
|
|
|
|
/// \brief The directory containing Clang-supplied headers.
|
|
|
|
const DirectoryEntry *BuiltinIncludeDir;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
/// \brief Whether an error occurred.
|
|
|
|
bool HadError;
|
|
|
|
|
|
|
|
/// \brief Default target information, used only for string literal
|
|
|
|
/// parsing.
|
|
|
|
TargetInfo *Target;
|
|
|
|
|
|
|
|
/// \brief Stores string data for the various string literals referenced
|
|
|
|
/// during parsing.
|
|
|
|
llvm::BumpPtrAllocator StringData;
|
|
|
|
|
|
|
|
/// \brief The current token.
|
|
|
|
MMToken Tok;
|
|
|
|
|
|
|
|
/// \brief The active module.
|
2011-12-01 07:21:26 +08:00
|
|
|
Module *ActiveModule;
|
2011-11-12 03:10:28 +08:00
|
|
|
|
|
|
|
/// \brief Consume the current token and return its location.
|
|
|
|
SourceLocation consumeToken();
|
|
|
|
|
|
|
|
/// \brief Skip tokens until we reach the a token with the given kind
|
|
|
|
/// (or the end of the file).
|
|
|
|
void skipUntil(MMToken::TokenKind K);
|
2011-12-07 10:23:45 +08:00
|
|
|
|
|
|
|
typedef llvm::SmallVector<std::pair<std::string, SourceLocation>, 2>
|
|
|
|
ModuleId;
|
|
|
|
bool parseModuleId(ModuleId &Id);
|
2011-11-12 03:10:28 +08:00
|
|
|
void parseModuleDecl();
|
2011-12-31 12:05:44 +08:00
|
|
|
void parseRequiresDecl();
|
2011-12-09 02:00:48 +08:00
|
|
|
void parseHeaderDecl(SourceLocation UmbrellaLoc);
|
2011-12-09 03:11:24 +08:00
|
|
|
void parseUmbrellaDirDecl(SourceLocation UmbrellaLoc);
|
2011-12-02 09:47:07 +08:00
|
|
|
void parseExportDecl();
|
2011-12-06 06:27:44 +08:00
|
|
|
void parseInferredSubmoduleDecl(bool Explicit);
|
2011-11-12 03:10:28 +08:00
|
|
|
|
2011-12-09 10:04:43 +08:00
|
|
|
const DirectoryEntry *getOverriddenHeaderSearchDir();
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
public:
|
|
|
|
explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr,
|
|
|
|
DiagnosticsEngine &Diags,
|
2011-11-12 05:55:48 +08:00
|
|
|
ModuleMap &Map,
|
2012-02-03 02:42:48 +08:00
|
|
|
const DirectoryEntry *Directory,
|
|
|
|
const DirectoryEntry *BuiltinIncludeDir)
|
2011-11-12 05:55:48 +08:00
|
|
|
: L(L), SourceMgr(SourceMgr), Diags(Diags), Map(Map),
|
2012-02-03 02:42:48 +08:00
|
|
|
Directory(Directory), BuiltinIncludeDir(BuiltinIncludeDir),
|
|
|
|
HadError(false), ActiveModule(0)
|
2011-11-12 03:10:28 +08:00
|
|
|
{
|
|
|
|
TargetOptions TargetOpts;
|
|
|
|
TargetOpts.Triple = llvm::sys::getDefaultTargetTriple();
|
|
|
|
Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
|
|
|
|
|
|
|
|
Tok.clear();
|
|
|
|
consumeToken();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool parseModuleMapFile();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation ModuleMapParser::consumeToken() {
|
|
|
|
retry:
|
|
|
|
SourceLocation Result = Tok.getLocation();
|
|
|
|
Tok.clear();
|
|
|
|
|
|
|
|
Token LToken;
|
|
|
|
L.LexFromRawLexer(LToken);
|
|
|
|
Tok.Location = LToken.getLocation().getRawEncoding();
|
|
|
|
switch (LToken.getKind()) {
|
|
|
|
case tok::raw_identifier:
|
|
|
|
Tok.StringData = LToken.getRawIdentifierData();
|
|
|
|
Tok.StringLength = LToken.getLength();
|
|
|
|
Tok.Kind = llvm::StringSwitch<MMToken::TokenKind>(Tok.getString())
|
|
|
|
.Case("header", MMToken::HeaderKeyword)
|
|
|
|
.Case("explicit", MMToken::ExplicitKeyword)
|
2011-12-02 09:47:07 +08:00
|
|
|
.Case("export", MMToken::ExportKeyword)
|
2011-11-18 06:09:43 +08:00
|
|
|
.Case("framework", MMToken::FrameworkKeyword)
|
2011-11-12 03:10:28 +08:00
|
|
|
.Case("module", MMToken::ModuleKeyword)
|
2011-12-31 12:05:44 +08:00
|
|
|
.Case("requires", MMToken::RequiresKeyword)
|
2011-11-12 03:10:28 +08:00
|
|
|
.Case("umbrella", MMToken::UmbrellaKeyword)
|
|
|
|
.Default(MMToken::Identifier);
|
|
|
|
break;
|
2011-12-31 12:05:44 +08:00
|
|
|
|
|
|
|
case tok::comma:
|
|
|
|
Tok.Kind = MMToken::Comma;
|
|
|
|
break;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
case tok::eof:
|
|
|
|
Tok.Kind = MMToken::EndOfFile;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case tok::l_brace:
|
|
|
|
Tok.Kind = MMToken::LBrace;
|
|
|
|
break;
|
|
|
|
|
2012-01-28 03:52:33 +08:00
|
|
|
case tok::l_square:
|
|
|
|
Tok.Kind = MMToken::LSquare;
|
|
|
|
break;
|
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
case tok::period:
|
|
|
|
Tok.Kind = MMToken::Period;
|
|
|
|
break;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
case tok::r_brace:
|
|
|
|
Tok.Kind = MMToken::RBrace;
|
|
|
|
break;
|
|
|
|
|
2012-01-28 03:52:33 +08:00
|
|
|
case tok::r_square:
|
|
|
|
Tok.Kind = MMToken::RSquare;
|
|
|
|
break;
|
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
case tok::star:
|
|
|
|
Tok.Kind = MMToken::Star;
|
|
|
|
break;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
case tok::string_literal: {
|
|
|
|
// Parse the string literal.
|
|
|
|
LangOptions LangOpts;
|
|
|
|
StringLiteralParser StringLiteral(<oken, 1, SourceMgr, LangOpts, *Target);
|
|
|
|
if (StringLiteral.hadError)
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
// Copy the string literal into our string data allocator.
|
|
|
|
unsigned Length = StringLiteral.GetStringLength();
|
|
|
|
char *Saved = StringData.Allocate<char>(Length + 1);
|
|
|
|
memcpy(Saved, StringLiteral.GetString().data(), Length);
|
|
|
|
Saved[Length] = 0;
|
|
|
|
|
|
|
|
// Form the token.
|
|
|
|
Tok.Kind = MMToken::StringLiteral;
|
|
|
|
Tok.StringData = Saved;
|
|
|
|
Tok.StringLength = Length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case tok::comment:
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Diags.Report(LToken.getLocation(), diag::err_mmap_unknown_token);
|
|
|
|
HadError = true;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleMapParser::skipUntil(MMToken::TokenKind K) {
|
|
|
|
unsigned braceDepth = 0;
|
2012-01-28 03:52:33 +08:00
|
|
|
unsigned squareDepth = 0;
|
2011-11-12 03:10:28 +08:00
|
|
|
do {
|
|
|
|
switch (Tok.Kind) {
|
|
|
|
case MMToken::EndOfFile:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case MMToken::LBrace:
|
2012-01-28 03:52:33 +08:00
|
|
|
if (Tok.is(K) && braceDepth == 0 && squareDepth == 0)
|
2011-11-12 03:10:28 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
++braceDepth;
|
|
|
|
break;
|
2012-01-28 03:52:33 +08:00
|
|
|
|
|
|
|
case MMToken::LSquare:
|
|
|
|
if (Tok.is(K) && braceDepth == 0 && squareDepth == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
++squareDepth;
|
|
|
|
break;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
case MMToken::RBrace:
|
|
|
|
if (braceDepth > 0)
|
|
|
|
--braceDepth;
|
|
|
|
else if (Tok.is(K))
|
|
|
|
return;
|
|
|
|
break;
|
2012-01-28 03:52:33 +08:00
|
|
|
|
|
|
|
case MMToken::RSquare:
|
|
|
|
if (squareDepth > 0)
|
|
|
|
--squareDepth;
|
|
|
|
else if (Tok.is(K))
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
default:
|
2012-01-28 03:52:33 +08:00
|
|
|
if (braceDepth == 0 && squareDepth == 0 && Tok.is(K))
|
2011-11-12 03:10:28 +08:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
consumeToken();
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2011-12-07 10:23:45 +08:00
|
|
|
/// \brief Parse a module-id.
|
|
|
|
///
|
|
|
|
/// module-id:
|
|
|
|
/// identifier
|
|
|
|
/// identifier '.' module-id
|
|
|
|
///
|
|
|
|
/// \returns true if an error occurred, false otherwise.
|
|
|
|
bool ModuleMapParser::parseModuleId(ModuleId &Id) {
|
|
|
|
Id.clear();
|
|
|
|
do {
|
|
|
|
if (Tok.is(MMToken::Identifier)) {
|
|
|
|
Id.push_back(std::make_pair(Tok.getString(), Tok.getLocation()));
|
|
|
|
consumeToken();
|
|
|
|
} else {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_module_name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Tok.is(MMToken::Period))
|
|
|
|
break;
|
|
|
|
|
|
|
|
consumeToken();
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-28 03:52:33 +08:00
|
|
|
namespace {
|
|
|
|
/// \brief Enumerates the known attributes.
|
|
|
|
enum AttributeKind {
|
|
|
|
/// \brief An unknown attribute.
|
|
|
|
AT_unknown,
|
|
|
|
/// \brief The 'system' attribute.
|
|
|
|
AT_system
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
/// \brief Parse a module declaration.
|
|
|
|
///
|
|
|
|
/// module-declaration:
|
2012-01-28 03:52:33 +08:00
|
|
|
/// 'explicit'[opt] 'framework'[opt] 'module' module-id attributes[opt]
|
|
|
|
/// { module-member* }
|
|
|
|
///
|
|
|
|
/// attributes:
|
|
|
|
/// attribute attributes
|
|
|
|
/// attribute
|
|
|
|
///
|
|
|
|
/// attribute:
|
|
|
|
/// [ identifier ]
|
2011-11-12 03:10:28 +08:00
|
|
|
///
|
|
|
|
/// module-member:
|
2011-12-31 12:05:44 +08:00
|
|
|
/// requires-declaration
|
2011-11-12 03:10:28 +08:00
|
|
|
/// header-declaration
|
2011-12-07 10:23:45 +08:00
|
|
|
/// submodule-declaration
|
2011-12-02 09:47:07 +08:00
|
|
|
/// export-declaration
|
2011-12-06 06:27:44 +08:00
|
|
|
///
|
|
|
|
/// submodule-declaration:
|
|
|
|
/// module-declaration
|
|
|
|
/// inferred-submodule-declaration
|
2011-11-12 03:10:28 +08:00
|
|
|
void ModuleMapParser::parseModuleDecl() {
|
2011-11-18 06:09:43 +08:00
|
|
|
assert(Tok.is(MMToken::ExplicitKeyword) || Tok.is(MMToken::ModuleKeyword) ||
|
|
|
|
Tok.is(MMToken::FrameworkKeyword));
|
2011-12-07 01:16:41 +08:00
|
|
|
// Parse 'explicit' or 'framework' keyword, if present.
|
2011-12-07 10:23:45 +08:00
|
|
|
SourceLocation ExplicitLoc;
|
2011-11-12 03:10:28 +08:00
|
|
|
bool Explicit = false;
|
2011-12-07 01:16:41 +08:00
|
|
|
bool Framework = false;
|
2011-11-18 06:09:43 +08:00
|
|
|
|
|
|
|
// Parse 'explicit' keyword, if present.
|
2011-12-07 01:16:41 +08:00
|
|
|
if (Tok.is(MMToken::ExplicitKeyword)) {
|
2011-12-07 10:23:45 +08:00
|
|
|
ExplicitLoc = consumeToken();
|
2011-11-12 03:10:28 +08:00
|
|
|
Explicit = true;
|
|
|
|
}
|
2011-12-07 01:16:41 +08:00
|
|
|
|
|
|
|
// Parse 'framework' keyword, if present.
|
|
|
|
if (Tok.is(MMToken::FrameworkKeyword)) {
|
|
|
|
consumeToken();
|
|
|
|
Framework = true;
|
|
|
|
}
|
2011-11-12 03:10:28 +08:00
|
|
|
|
|
|
|
// Parse 'module' keyword.
|
|
|
|
if (!Tok.is(MMToken::ModuleKeyword)) {
|
2011-12-07 03:57:48 +08:00
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_module);
|
2011-11-12 03:10:28 +08:00
|
|
|
consumeToken();
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
consumeToken(); // 'module' keyword
|
2011-12-06 06:27:44 +08:00
|
|
|
|
|
|
|
// If we have a wildcard for the module name, this is an inferred submodule.
|
|
|
|
// Parse it.
|
|
|
|
if (Tok.is(MMToken::Star))
|
|
|
|
return parseInferredSubmoduleDecl(Explicit);
|
2011-11-12 03:10:28 +08:00
|
|
|
|
|
|
|
// Parse the module name.
|
2011-12-07 10:23:45 +08:00
|
|
|
ModuleId Id;
|
|
|
|
if (parseModuleId(Id)) {
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ActiveModule) {
|
|
|
|
if (Id.size() > 1) {
|
|
|
|
Diags.Report(Id.front().second, diag::err_mmap_nested_submodule_id)
|
|
|
|
<< SourceRange(Id.front().second, Id.back().second);
|
|
|
|
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (Id.size() == 1 && Explicit) {
|
|
|
|
// Top-level modules can't be explicit.
|
|
|
|
Diags.Report(ExplicitLoc, diag::err_mmap_explicit_top_level);
|
|
|
|
Explicit = false;
|
|
|
|
ExplicitLoc = SourceLocation();
|
2011-11-12 03:10:28 +08:00
|
|
|
HadError = true;
|
|
|
|
}
|
2011-12-07 10:23:45 +08:00
|
|
|
|
|
|
|
Module *PreviousActiveModule = ActiveModule;
|
|
|
|
if (Id.size() > 1) {
|
|
|
|
// This module map defines a submodule. Go find the module of which it
|
|
|
|
// is a submodule.
|
|
|
|
ActiveModule = 0;
|
|
|
|
for (unsigned I = 0, N = Id.size() - 1; I != N; ++I) {
|
|
|
|
if (Module *Next = Map.lookupModuleQualified(Id[I].first, ActiveModule)) {
|
|
|
|
ActiveModule = Next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ActiveModule) {
|
|
|
|
Diags.Report(Id[I].second, diag::err_mmap_missing_module_qualified)
|
|
|
|
<< Id[I].first << ActiveModule->getTopLevelModule();
|
|
|
|
} else {
|
|
|
|
Diags.Report(Id[I].second, diag::err_mmap_expected_module_name);
|
|
|
|
}
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef ModuleName = Id.back().first;
|
|
|
|
SourceLocation ModuleNameLoc = Id.back().second;
|
2011-11-12 03:10:28 +08:00
|
|
|
|
2012-01-28 03:52:33 +08:00
|
|
|
// Parse the optional attribute list.
|
|
|
|
bool IsSystem = false;
|
|
|
|
while (Tok.is(MMToken::LSquare)) {
|
|
|
|
// Consume the '['.
|
|
|
|
SourceLocation LSquareLoc = consumeToken();
|
|
|
|
|
|
|
|
// Check whether we have an attribute name here.
|
|
|
|
if (!Tok.is(MMToken::Identifier)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_attribute);
|
|
|
|
skipUntil(MMToken::RSquare);
|
|
|
|
if (Tok.is(MMToken::RSquare))
|
|
|
|
consumeToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode the attribute name.
|
|
|
|
AttributeKind Attribute
|
|
|
|
= llvm::StringSwitch<AttributeKind>(Tok.getString())
|
|
|
|
.Case("system", AT_system)
|
|
|
|
.Default(AT_unknown);
|
|
|
|
switch (Attribute) {
|
|
|
|
case AT_unknown:
|
|
|
|
Diags.Report(Tok.getLocation(), diag::warn_mmap_unknown_attribute)
|
|
|
|
<< Tok.getString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AT_system:
|
|
|
|
IsSystem = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
// Consume the ']'.
|
|
|
|
if (!Tok.is(MMToken::RSquare)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_rsquare);
|
|
|
|
Diags.Report(LSquareLoc, diag::note_mmap_lsquare_match);
|
|
|
|
skipUntil(MMToken::RSquare);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.is(MMToken::RSquare))
|
|
|
|
consumeToken();
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
// Parse the opening brace.
|
|
|
|
if (!Tok.is(MMToken::LBrace)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_lbrace)
|
|
|
|
<< ModuleName;
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SourceLocation LBraceLoc = consumeToken();
|
|
|
|
|
|
|
|
// Determine whether this (sub)module has already been defined.
|
2012-01-05 07:32:19 +08:00
|
|
|
if (Module *Existing = Map.lookupModuleQualified(ModuleName, ActiveModule)) {
|
2012-01-05 08:12:00 +08:00
|
|
|
if (Existing->DefinitionLoc.isInvalid() && !ActiveModule) {
|
|
|
|
// Skip the module definition.
|
|
|
|
skipUntil(MMToken::RBrace);
|
|
|
|
if (Tok.is(MMToken::RBrace))
|
|
|
|
consumeToken();
|
|
|
|
else {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_rbrace);
|
|
|
|
Diags.Report(LBraceLoc, diag::note_mmap_lbrace_match);
|
|
|
|
HadError = true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
Diags.Report(ModuleNameLoc, diag::err_mmap_module_redefinition)
|
|
|
|
<< ModuleName;
|
2012-01-05 07:32:19 +08:00
|
|
|
Diags.Report(Existing->DefinitionLoc, diag::note_mmap_prev_definition);
|
2011-11-12 03:10:28 +08:00
|
|
|
|
|
|
|
// Skip the module definition.
|
|
|
|
skipUntil(MMToken::RBrace);
|
|
|
|
if (Tok.is(MMToken::RBrace))
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start defining this module.
|
2012-01-05 07:32:19 +08:00
|
|
|
ActiveModule = Map.findOrCreateModule(ModuleName, ActiveModule, Framework,
|
|
|
|
Explicit).first;
|
|
|
|
ActiveModule->DefinitionLoc = ModuleNameLoc;
|
2012-01-28 03:52:33 +08:00
|
|
|
if (IsSystem)
|
|
|
|
ActiveModule->IsSystem = true;
|
2011-11-12 03:10:28 +08:00
|
|
|
|
|
|
|
bool Done = false;
|
|
|
|
do {
|
|
|
|
switch (Tok.Kind) {
|
|
|
|
case MMToken::EndOfFile:
|
|
|
|
case MMToken::RBrace:
|
|
|
|
Done = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMToken::ExplicitKeyword:
|
2011-12-07 01:16:41 +08:00
|
|
|
case MMToken::FrameworkKeyword:
|
2011-11-12 03:10:28 +08:00
|
|
|
case MMToken::ModuleKeyword:
|
|
|
|
parseModuleDecl();
|
|
|
|
break;
|
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
case MMToken::ExportKeyword:
|
|
|
|
parseExportDecl();
|
|
|
|
break;
|
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
case MMToken::RequiresKeyword:
|
|
|
|
parseRequiresDecl();
|
|
|
|
break;
|
|
|
|
|
2011-12-09 03:11:24 +08:00
|
|
|
case MMToken::UmbrellaKeyword: {
|
|
|
|
SourceLocation UmbrellaLoc = consumeToken();
|
|
|
|
if (Tok.is(MMToken::HeaderKeyword))
|
|
|
|
parseHeaderDecl(UmbrellaLoc);
|
|
|
|
else
|
|
|
|
parseUmbrellaDirDecl(UmbrellaLoc);
|
2011-11-12 03:10:28 +08:00
|
|
|
break;
|
2011-12-09 03:11:24 +08:00
|
|
|
}
|
2011-11-12 03:10:28 +08:00
|
|
|
|
2011-12-09 02:00:48 +08:00
|
|
|
case MMToken::HeaderKeyword:
|
|
|
|
parseHeaderDecl(SourceLocation());
|
2011-11-12 03:10:28 +08:00
|
|
|
break;
|
2011-12-09 02:00:48 +08:00
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
default:
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_member);
|
|
|
|
consumeToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!Done);
|
|
|
|
|
|
|
|
if (Tok.is(MMToken::RBrace))
|
|
|
|
consumeToken();
|
|
|
|
else {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_rbrace);
|
|
|
|
Diags.Report(LBraceLoc, diag::note_mmap_lbrace_match);
|
|
|
|
HadError = true;
|
|
|
|
}
|
|
|
|
|
2011-12-07 10:23:45 +08:00
|
|
|
// We're done parsing this module. Pop back to the previous module.
|
|
|
|
ActiveModule = PreviousActiveModule;
|
2011-11-12 03:10:28 +08:00
|
|
|
}
|
2011-12-07 01:16:41 +08:00
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
/// \brief Parse a requires declaration.
|
|
|
|
///
|
|
|
|
/// requires-declaration:
|
|
|
|
/// 'requires' feature-list
|
|
|
|
///
|
|
|
|
/// feature-list:
|
|
|
|
/// identifier ',' feature-list
|
|
|
|
/// identifier
|
|
|
|
void ModuleMapParser::parseRequiresDecl() {
|
|
|
|
assert(Tok.is(MMToken::RequiresKeyword));
|
|
|
|
|
|
|
|
// Parse 'requires' keyword.
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
// Parse the feature-list.
|
|
|
|
do {
|
|
|
|
if (!Tok.is(MMToken::Identifier)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_feature);
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Consume the feature name.
|
|
|
|
std::string Feature = Tok.getString();
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
// Add this feature.
|
2012-01-30 14:01:29 +08:00
|
|
|
ActiveModule->addRequirement(Feature, Map.LangOpts, *Map.Target);
|
2011-12-31 12:05:44 +08:00
|
|
|
|
|
|
|
if (!Tok.is(MMToken::Comma))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Consume the comma.
|
|
|
|
consumeToken();
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2011-12-07 01:16:41 +08:00
|
|
|
/// \brief Append to \p Paths the set of paths needed to get to the
|
|
|
|
/// subframework in which the given module lives.
|
|
|
|
void appendSubframeworkPaths(Module *Mod, llvm::SmallVectorImpl<char> &Path) {
|
|
|
|
// Collect the framework names from the given module to the top-level module.
|
|
|
|
llvm::SmallVector<StringRef, 2> Paths;
|
|
|
|
for (; Mod; Mod = Mod->Parent) {
|
|
|
|
if (Mod->IsFramework)
|
|
|
|
Paths.push_back(Mod->Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Paths.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Add Frameworks/Name.framework for each subframework.
|
|
|
|
for (unsigned I = Paths.size() - 1; I != 0; --I) {
|
|
|
|
llvm::sys::path::append(Path, "Frameworks");
|
|
|
|
llvm::sys::path::append(Path, Paths[I-1] + ".framework");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-03 02:42:48 +08:00
|
|
|
/// \brief Determine whether the given file name is the name of a builtin
|
|
|
|
/// header, supplied by Clang to replace, override, or augment existing system
|
|
|
|
/// headers.
|
|
|
|
static bool isBuiltinHeader(StringRef FileName) {
|
|
|
|
return llvm::StringSwitch<bool>(FileName)
|
|
|
|
.Case("float.h", true)
|
|
|
|
.Case("iso646.h", true)
|
|
|
|
.Case("limits.h", true)
|
|
|
|
.Case("stdalign.h", true)
|
|
|
|
.Case("stdarg.h", true)
|
|
|
|
.Case("stdbool.h", true)
|
|
|
|
.Case("stddef.h", true)
|
|
|
|
.Case("stdint.h", true)
|
|
|
|
.Case("tgmath.h", true)
|
|
|
|
.Case("unwind.h", true)
|
|
|
|
.Default(false);
|
|
|
|
}
|
|
|
|
|
2011-12-09 02:00:48 +08:00
|
|
|
/// \brief Parse a header declaration.
|
2011-11-12 03:10:28 +08:00
|
|
|
///
|
2011-12-09 02:00:48 +08:00
|
|
|
/// header-declaration:
|
|
|
|
/// 'umbrella'[opt] 'header' string-literal
|
|
|
|
void ModuleMapParser::parseHeaderDecl(SourceLocation UmbrellaLoc) {
|
|
|
|
assert(Tok.is(MMToken::HeaderKeyword));
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
bool Umbrella = UmbrellaLoc.isValid();
|
2011-11-12 03:10:28 +08:00
|
|
|
|
|
|
|
// Parse the header name.
|
|
|
|
if (!Tok.is(MMToken::StringLiteral)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_header)
|
2011-12-09 02:00:48 +08:00
|
|
|
<< "header";
|
2011-11-12 03:10:28 +08:00
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
2011-12-07 10:23:45 +08:00
|
|
|
std::string FileName = Tok.getString();
|
2011-11-12 03:10:28 +08:00
|
|
|
SourceLocation FileNameLoc = consumeToken();
|
2011-12-09 02:00:48 +08:00
|
|
|
|
2011-12-09 03:11:24 +08:00
|
|
|
// Check whether we already have an umbrella.
|
|
|
|
if (Umbrella && ActiveModule->Umbrella) {
|
|
|
|
Diags.Report(FileNameLoc, diag::err_mmap_umbrella_clash)
|
|
|
|
<< ActiveModule->getFullModuleName();
|
2011-11-12 05:55:48 +08:00
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
2011-11-18 06:09:43 +08:00
|
|
|
|
2011-11-12 05:55:48 +08:00
|
|
|
// Look for this file.
|
2011-12-07 10:23:45 +08:00
|
|
|
const FileEntry *File = 0;
|
2012-02-03 02:42:48 +08:00
|
|
|
const FileEntry *BuiltinFile = 0;
|
2011-11-12 05:55:48 +08:00
|
|
|
llvm::SmallString<128> PathName;
|
2011-12-07 10:23:45 +08:00
|
|
|
if (llvm::sys::path::is_absolute(FileName)) {
|
|
|
|
PathName = FileName;
|
|
|
|
File = SourceMgr.getFileManager().getFile(PathName);
|
2011-12-09 10:04:43 +08:00
|
|
|
} else if (const DirectoryEntry *Dir = getOverriddenHeaderSearchDir()) {
|
|
|
|
PathName = Dir->getName();
|
|
|
|
llvm::sys::path::append(PathName, FileName);
|
|
|
|
File = SourceMgr.getFileManager().getFile(PathName);
|
2011-12-07 10:23:45 +08:00
|
|
|
} else {
|
|
|
|
// Search for the header file within the search directory.
|
2011-12-09 10:04:43 +08:00
|
|
|
PathName = Directory->getName();
|
2011-12-07 10:23:45 +08:00
|
|
|
unsigned PathLength = PathName.size();
|
2011-11-30 05:59:16 +08:00
|
|
|
|
2011-12-07 01:16:41 +08:00
|
|
|
if (ActiveModule->isPartOfFramework()) {
|
|
|
|
appendSubframeworkPaths(ActiveModule, PathName);
|
2011-12-07 10:23:45 +08:00
|
|
|
|
|
|
|
// Check whether this file is in the public headers.
|
2011-11-30 05:59:16 +08:00
|
|
|
llvm::sys::path::append(PathName, "Headers");
|
2011-12-07 10:23:45 +08:00
|
|
|
llvm::sys::path::append(PathName, FileName);
|
|
|
|
File = SourceMgr.getFileManager().getFile(PathName);
|
|
|
|
|
|
|
|
if (!File) {
|
|
|
|
// Check whether this file is in the private headers.
|
|
|
|
PathName.resize(PathLength);
|
|
|
|
llvm::sys::path::append(PathName, "PrivateHeaders");
|
|
|
|
llvm::sys::path::append(PathName, FileName);
|
|
|
|
File = SourceMgr.getFileManager().getFile(PathName);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Lookup for normal headers.
|
|
|
|
llvm::sys::path::append(PathName, FileName);
|
|
|
|
File = SourceMgr.getFileManager().getFile(PathName);
|
2012-02-03 02:42:48 +08:00
|
|
|
|
|
|
|
// If this is a system module with a top-level header, this header
|
|
|
|
// may have a counterpart (or replacement) in the set of headers
|
|
|
|
// supplied by Clang. Find that builtin header.
|
|
|
|
if (ActiveModule->IsSystem && !Umbrella && BuiltinIncludeDir &&
|
|
|
|
BuiltinIncludeDir != Directory && isBuiltinHeader(FileName)) {
|
|
|
|
llvm::SmallString<128> BuiltinPathName(BuiltinIncludeDir->getName());
|
|
|
|
llvm::sys::path::append(BuiltinPathName, FileName);
|
|
|
|
BuiltinFile = SourceMgr.getFileManager().getFile(BuiltinPathName);
|
|
|
|
|
|
|
|
// If Clang supplies this header but the underlying system does not,
|
|
|
|
// just silently swap in our builtin version. Otherwise, we'll end
|
|
|
|
// up adding both (later).
|
|
|
|
if (!File && BuiltinFile) {
|
|
|
|
File = BuiltinFile;
|
|
|
|
BuiltinFile = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 01:16:41 +08:00
|
|
|
}
|
2011-11-30 05:59:16 +08:00
|
|
|
}
|
2011-11-18 06:09:43 +08:00
|
|
|
|
2011-11-12 05:55:48 +08:00
|
|
|
// FIXME: We shouldn't be eagerly stat'ing every file named in a module map.
|
|
|
|
// Come up with a lazy way to do this.
|
2011-12-07 10:23:45 +08:00
|
|
|
if (File) {
|
2011-11-12 05:55:48 +08:00
|
|
|
if (const Module *OwningModule = Map.Headers[File]) {
|
|
|
|
Diags.Report(FileNameLoc, diag::err_mmap_header_conflict)
|
|
|
|
<< FileName << OwningModule->getFullModuleName();
|
|
|
|
HadError = true;
|
2011-12-09 02:00:48 +08:00
|
|
|
} else if (Umbrella) {
|
|
|
|
const DirectoryEntry *UmbrellaDir = File->getDir();
|
|
|
|
if ((OwningModule = Map.UmbrellaDirs[UmbrellaDir])) {
|
|
|
|
Diags.Report(UmbrellaLoc, diag::err_mmap_umbrella_clash)
|
|
|
|
<< OwningModule->getFullModuleName();
|
|
|
|
HadError = true;
|
|
|
|
} else {
|
|
|
|
// Record this umbrella header.
|
|
|
|
Map.setUmbrellaHeader(ActiveModule, File);
|
|
|
|
}
|
2011-11-12 05:55:48 +08:00
|
|
|
} else {
|
2011-12-09 02:00:48 +08:00
|
|
|
// Record this header.
|
2011-12-06 09:10:29 +08:00
|
|
|
Map.addHeader(ActiveModule, File);
|
2012-02-03 02:42:48 +08:00
|
|
|
|
|
|
|
// If there is a builtin counterpart to this file, add it now.
|
|
|
|
if (BuiltinFile)
|
|
|
|
Map.addHeader(ActiveModule, BuiltinFile);
|
2011-11-12 05:55:48 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Diags.Report(FileNameLoc, diag::err_mmap_header_not_found)
|
2011-12-09 03:11:24 +08:00
|
|
|
<< Umbrella << FileName;
|
|
|
|
HadError = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Parse an umbrella directory declaration.
|
|
|
|
///
|
|
|
|
/// umbrella-dir-declaration:
|
|
|
|
/// umbrella string-literal
|
|
|
|
void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
|
|
|
|
// Parse the directory name.
|
|
|
|
if (!Tok.is(MMToken::StringLiteral)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_header)
|
|
|
|
<< "umbrella";
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string DirName = Tok.getString();
|
|
|
|
SourceLocation DirNameLoc = consumeToken();
|
|
|
|
|
|
|
|
// Check whether we already have an umbrella.
|
|
|
|
if (ActiveModule->Umbrella) {
|
|
|
|
Diags.Report(DirNameLoc, diag::err_mmap_umbrella_clash)
|
|
|
|
<< ActiveModule->getFullModuleName();
|
2011-11-12 05:55:48 +08:00
|
|
|
HadError = true;
|
2011-12-09 03:11:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for this file.
|
|
|
|
const DirectoryEntry *Dir = 0;
|
|
|
|
if (llvm::sys::path::is_absolute(DirName))
|
|
|
|
Dir = SourceMgr.getFileManager().getDirectory(DirName);
|
|
|
|
else {
|
|
|
|
llvm::SmallString<128> PathName;
|
|
|
|
PathName = Directory->getName();
|
|
|
|
llvm::sys::path::append(PathName, DirName);
|
|
|
|
Dir = SourceMgr.getFileManager().getDirectory(PathName);
|
2011-11-12 05:55:48 +08:00
|
|
|
}
|
2011-12-09 03:11:24 +08:00
|
|
|
|
|
|
|
if (!Dir) {
|
|
|
|
Diags.Report(DirNameLoc, diag::err_mmap_umbrella_dir_not_found)
|
|
|
|
<< DirName;
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Module *OwningModule = Map.UmbrellaDirs[Dir]) {
|
|
|
|
Diags.Report(UmbrellaLoc, diag::err_mmap_umbrella_clash)
|
|
|
|
<< OwningModule->getFullModuleName();
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record this umbrella directory.
|
|
|
|
Map.setUmbrellaDir(ActiveModule, Dir);
|
2011-11-12 03:10:28 +08:00
|
|
|
}
|
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
/// \brief Parse a module export declaration.
|
|
|
|
///
|
|
|
|
/// export-declaration:
|
|
|
|
/// 'export' wildcard-module-id
|
|
|
|
///
|
|
|
|
/// wildcard-module-id:
|
|
|
|
/// identifier
|
|
|
|
/// '*'
|
|
|
|
/// identifier '.' wildcard-module-id
|
|
|
|
void ModuleMapParser::parseExportDecl() {
|
|
|
|
assert(Tok.is(MMToken::ExportKeyword));
|
|
|
|
SourceLocation ExportLoc = consumeToken();
|
|
|
|
|
|
|
|
// Parse the module-id with an optional wildcard at the end.
|
|
|
|
ModuleId ParsedModuleId;
|
|
|
|
bool Wildcard = false;
|
|
|
|
do {
|
|
|
|
if (Tok.is(MMToken::Identifier)) {
|
|
|
|
ParsedModuleId.push_back(std::make_pair(Tok.getString(),
|
|
|
|
Tok.getLocation()));
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
if (Tok.is(MMToken::Period)) {
|
|
|
|
consumeToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Tok.is(MMToken::Star)) {
|
|
|
|
Wildcard = true;
|
2011-12-06 01:28:06 +08:00
|
|
|
consumeToken();
|
2011-12-02 09:47:07 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_export_module_id);
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
Module::UnresolvedExportDecl Unresolved = {
|
|
|
|
ExportLoc, ParsedModuleId, Wildcard
|
|
|
|
};
|
|
|
|
ActiveModule->UnresolvedExports.push_back(Unresolved);
|
|
|
|
}
|
|
|
|
|
2011-12-06 06:27:44 +08:00
|
|
|
void ModuleMapParser::parseInferredSubmoduleDecl(bool Explicit) {
|
|
|
|
assert(Tok.is(MMToken::Star));
|
|
|
|
SourceLocation StarLoc = consumeToken();
|
|
|
|
bool Failed = false;
|
|
|
|
|
|
|
|
// Inferred modules must be submodules.
|
|
|
|
if (!ActiveModule) {
|
|
|
|
Diags.Report(StarLoc, diag::err_mmap_top_level_inferred_submodule);
|
|
|
|
Failed = true;
|
|
|
|
}
|
|
|
|
|
2011-12-09 03:11:24 +08:00
|
|
|
// Inferred modules must have umbrella directories.
|
|
|
|
if (!Failed && !ActiveModule->getUmbrellaDir()) {
|
2011-12-06 06:27:44 +08:00
|
|
|
Diags.Report(StarLoc, diag::err_mmap_inferred_no_umbrella);
|
|
|
|
Failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for redefinition of an inferred module.
|
2011-12-07 01:34:58 +08:00
|
|
|
if (!Failed && ActiveModule->InferSubmodules) {
|
2011-12-06 06:27:44 +08:00
|
|
|
Diags.Report(StarLoc, diag::err_mmap_inferred_redef);
|
2011-12-07 01:34:58 +08:00
|
|
|
if (ActiveModule->InferredSubmoduleLoc.isValid())
|
|
|
|
Diags.Report(ActiveModule->InferredSubmoduleLoc,
|
2011-12-06 06:27:44 +08:00
|
|
|
diag::note_mmap_prev_definition);
|
|
|
|
Failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there were any problems with this inferred submodule, skip its body.
|
|
|
|
if (Failed) {
|
|
|
|
if (Tok.is(MMToken::LBrace)) {
|
|
|
|
consumeToken();
|
|
|
|
skipUntil(MMToken::RBrace);
|
|
|
|
if (Tok.is(MMToken::RBrace))
|
|
|
|
consumeToken();
|
|
|
|
}
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that we have an inferred submodule.
|
2011-12-07 01:34:58 +08:00
|
|
|
ActiveModule->InferSubmodules = true;
|
|
|
|
ActiveModule->InferredSubmoduleLoc = StarLoc;
|
|
|
|
ActiveModule->InferExplicitSubmodules = Explicit;
|
2011-12-06 06:27:44 +08:00
|
|
|
|
|
|
|
// Parse the opening brace.
|
|
|
|
if (!Tok.is(MMToken::LBrace)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_lbrace_wildcard);
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SourceLocation LBraceLoc = consumeToken();
|
|
|
|
|
|
|
|
// Parse the body of the inferred submodule.
|
|
|
|
bool Done = false;
|
|
|
|
do {
|
|
|
|
switch (Tok.Kind) {
|
|
|
|
case MMToken::EndOfFile:
|
|
|
|
case MMToken::RBrace:
|
|
|
|
Done = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMToken::ExportKeyword: {
|
|
|
|
consumeToken();
|
|
|
|
if (Tok.is(MMToken::Star))
|
2011-12-07 01:34:58 +08:00
|
|
|
ActiveModule->InferExportWildcard = true;
|
2011-12-06 06:27:44 +08:00
|
|
|
else
|
|
|
|
Diags.Report(Tok.getLocation(),
|
|
|
|
diag::err_mmap_expected_export_wildcard);
|
|
|
|
consumeToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MMToken::ExplicitKeyword:
|
|
|
|
case MMToken::ModuleKeyword:
|
|
|
|
case MMToken::HeaderKeyword:
|
|
|
|
case MMToken::UmbrellaKeyword:
|
|
|
|
default:
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_wildcard_member);
|
|
|
|
consumeToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!Done);
|
|
|
|
|
|
|
|
if (Tok.is(MMToken::RBrace))
|
|
|
|
consumeToken();
|
|
|
|
else {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_rbrace);
|
|
|
|
Diags.Report(LBraceLoc, diag::note_mmap_lbrace_match);
|
|
|
|
HadError = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-09 10:04:43 +08:00
|
|
|
/// \brief If there is a specific header search directory due the presence
|
|
|
|
/// of an umbrella directory, retrieve that directory. Otherwise, returns null.
|
|
|
|
const DirectoryEntry *ModuleMapParser::getOverriddenHeaderSearchDir() {
|
|
|
|
for (Module *Mod = ActiveModule; Mod; Mod = Mod->Parent) {
|
|
|
|
// If we have an umbrella directory, use that.
|
|
|
|
if (Mod->hasUmbrellaDir())
|
|
|
|
return Mod->getUmbrellaDir();
|
|
|
|
|
|
|
|
// If we have a framework directory, stop looking.
|
|
|
|
if (Mod->IsFramework)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
/// \brief Parse a module map file.
|
|
|
|
///
|
|
|
|
/// module-map-file:
|
|
|
|
/// module-declaration*
|
|
|
|
bool ModuleMapParser::parseModuleMapFile() {
|
|
|
|
do {
|
|
|
|
switch (Tok.Kind) {
|
|
|
|
case MMToken::EndOfFile:
|
|
|
|
return HadError;
|
|
|
|
|
2011-12-07 10:23:45 +08:00
|
|
|
case MMToken::ExplicitKeyword:
|
2011-11-12 03:10:28 +08:00
|
|
|
case MMToken::ModuleKeyword:
|
2011-11-18 06:09:43 +08:00
|
|
|
case MMToken::FrameworkKeyword:
|
2011-11-12 03:10:28 +08:00
|
|
|
parseModuleDecl();
|
|
|
|
break;
|
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
case MMToken::Comma:
|
2011-12-02 09:47:07 +08:00
|
|
|
case MMToken::ExportKeyword:
|
2011-11-12 03:10:28 +08:00
|
|
|
case MMToken::HeaderKeyword:
|
|
|
|
case MMToken::Identifier:
|
|
|
|
case MMToken::LBrace:
|
2012-01-28 03:52:33 +08:00
|
|
|
case MMToken::LSquare:
|
2011-12-02 09:47:07 +08:00
|
|
|
case MMToken::Period:
|
2011-11-12 03:10:28 +08:00
|
|
|
case MMToken::RBrace:
|
2012-01-28 03:52:33 +08:00
|
|
|
case MMToken::RSquare:
|
2011-12-31 12:05:44 +08:00
|
|
|
case MMToken::RequiresKeyword:
|
2011-12-02 09:47:07 +08:00
|
|
|
case MMToken::Star:
|
2011-11-12 03:10:28 +08:00
|
|
|
case MMToken::StringLiteral:
|
|
|
|
case MMToken::UmbrellaKeyword:
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_module);
|
|
|
|
HadError = true;
|
|
|
|
consumeToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModuleMap::parseModuleMapFile(const FileEntry *File) {
|
2012-01-30 14:01:29 +08:00
|
|
|
assert(Target != 0 && "Missing target information");
|
2011-11-12 03:10:28 +08:00
|
|
|
FileID ID = SourceMgr->createFileID(File, SourceLocation(), SrcMgr::C_User);
|
|
|
|
const llvm::MemoryBuffer *Buffer = SourceMgr->getBuffer(ID);
|
|
|
|
if (!Buffer)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Parse this module map file.
|
2011-12-31 12:05:44 +08:00
|
|
|
Lexer L(ID, SourceMgr->getBuffer(ID), *SourceMgr, MMapLangOpts);
|
|
|
|
Diags->getClient()->BeginSourceFile(MMapLangOpts);
|
2012-02-03 02:42:48 +08:00
|
|
|
ModuleMapParser Parser(L, *SourceMgr, *Diags, *this, File->getDir(),
|
|
|
|
BuiltinIncludeDir);
|
2011-11-12 03:10:28 +08:00
|
|
|
bool Result = Parser.parseModuleMapFile();
|
|
|
|
Diags->getClient()->EndSourceFile();
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|