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"
|
2013-02-09 06:30:41 +08:00
|
|
|
#include "clang/Basic/CharInfo.h"
|
2011-11-12 03:10:28 +08:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2012-10-24 06:26:28 +08:00
|
|
|
#include "clang/Basic/DiagnosticOptions.h"
|
2011-11-12 03:10:28 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/TargetInfo.h"
|
|
|
|
#include "clang/Basic/TargetOptions.h"
|
2013-03-14 05:13:51 +08:00
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
2014-12-10 11:09:48 +08:00
|
|
|
#include "clang/Lex/HeaderSearchOptions.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Lex/LexDiagnostic.h"
|
|
|
|
#include "clang/Lex/Lexer.h"
|
|
|
|
#include "clang/Lex/LiteralSupport.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2011-11-12 03:10:28 +08:00
|
|
|
#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"
|
2013-06-12 06:15:02 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2011-11-12 03:10:28 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-09-27 22:50:15 +08:00
|
|
|
#include <stdlib.h>
|
2013-01-23 07:49:45 +08:00
|
|
|
#if defined(LLVM_ON_UNIX)
|
2013-01-27 00:29:36 +08:00
|
|
|
#include <limits.h>
|
2013-01-23 07:49:45 +08:00
|
|
|
#endif
|
2011-11-12 03:10:28 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
Module::ExportDecl
|
|
|
|
ModuleMap::resolveExport(Module *Mod,
|
|
|
|
const Module::UnresolvedExportDecl &Unresolved,
|
2013-02-20 03:58:45 +08:00
|
|
|
bool Complain) const {
|
2011-12-06 01:28:06 +08:00
|
|
|
// We may have just a wildcard.
|
|
|
|
if (Unresolved.Id.empty()) {
|
|
|
|
assert(Unresolved.Wildcard && "Invalid unresolved export");
|
2014-05-18 07:10:59 +08:00
|
|
|
return Module::ExportDecl(nullptr, true);
|
2011-12-06 01:28:06 +08:00
|
|
|
}
|
|
|
|
|
2013-03-21 05:10:35 +08:00
|
|
|
// Resolve the module-id.
|
|
|
|
Module *Context = resolveModuleId(Unresolved.Id, Mod, Complain);
|
|
|
|
if (!Context)
|
|
|
|
return Module::ExportDecl();
|
|
|
|
|
|
|
|
return Module::ExportDecl(Context, Unresolved.Wildcard);
|
|
|
|
}
|
|
|
|
|
|
|
|
Module *ModuleMap::resolveModuleId(const ModuleId &Id, Module *Mod,
|
|
|
|
bool Complain) const {
|
2011-12-02 09:47:07 +08:00
|
|
|
// Find the starting module.
|
2013-03-21 05:10:35 +08:00
|
|
|
Module *Context = lookupModuleUnqualified(Id[0].first, Mod);
|
2011-12-02 09:47:07 +08:00
|
|
|
if (!Context) {
|
|
|
|
if (Complain)
|
2013-12-17 18:31:37 +08:00
|
|
|
Diags.Report(Id[0].second, diag::err_mmap_missing_module_unqualified)
|
2013-03-21 05:10:35 +08:00
|
|
|
<< Id[0].first << Mod->getFullModuleName();
|
|
|
|
|
2014-05-18 07:10:59 +08:00
|
|
|
return nullptr;
|
2011-12-02 09:47:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dig into the module path.
|
2013-03-21 05:10:35 +08:00
|
|
|
for (unsigned I = 1, N = Id.size(); I != N; ++I) {
|
|
|
|
Module *Sub = lookupModuleQualified(Id[I].first, Context);
|
2011-12-02 09:47:07 +08:00
|
|
|
if (!Sub) {
|
|
|
|
if (Complain)
|
2013-12-17 18:31:37 +08:00
|
|
|
Diags.Report(Id[I].second, diag::err_mmap_missing_module_qualified)
|
2013-03-21 05:10:35 +08:00
|
|
|
<< Id[I].first << Context->getFullModuleName()
|
|
|
|
<< SourceRange(Id[0].second, Id[I-1].second);
|
|
|
|
|
2014-05-18 07:10:59 +08:00
|
|
|
return nullptr;
|
2011-12-02 09:47:07 +08:00
|
|
|
}
|
2013-03-21 05:10:35 +08:00
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
Context = Sub;
|
|
|
|
}
|
2013-03-21 05:10:35 +08:00
|
|
|
|
|
|
|
return Context;
|
2011-12-02 09:47:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-17 18:31:37 +08:00
|
|
|
ModuleMap::ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags,
|
2013-03-14 05:13:51 +08:00
|
|
|
const LangOptions &LangOpts, const TargetInfo *Target,
|
|
|
|
HeaderSearch &HeaderInfo)
|
2013-12-17 18:31:37 +08:00
|
|
|
: SourceMgr(SourceMgr), Diags(Diags), LangOpts(LangOpts), Target(Target),
|
2014-05-18 07:10:59 +08:00
|
|
|
HeaderInfo(HeaderInfo), BuiltinIncludeDir(nullptr),
|
|
|
|
CompilingModule(nullptr), SourceModule(nullptr) {}
|
2011-11-12 03:10:28 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-10-13 05:15:50 +08:00
|
|
|
/// \brief "Sanitize" a filename so that it can be used as an identifier.
|
|
|
|
static StringRef sanitizeFilenameAsIdentifier(StringRef Name,
|
|
|
|
SmallVectorImpl<char> &Buffer) {
|
|
|
|
if (Name.empty())
|
|
|
|
return Name;
|
|
|
|
|
2013-02-09 06:30:41 +08:00
|
|
|
if (!isValidIdentifier(Name)) {
|
2012-10-13 05:15:50 +08:00
|
|
|
// If we don't already have something with the form of an identifier,
|
|
|
|
// create a buffer with the sanitized name.
|
|
|
|
Buffer.clear();
|
2013-02-09 06:30:41 +08:00
|
|
|
if (isDigit(Name[0]))
|
2012-10-13 05:15:50 +08:00
|
|
|
Buffer.push_back('_');
|
|
|
|
Buffer.reserve(Buffer.size() + Name.size());
|
|
|
|
for (unsigned I = 0, N = Name.size(); I != N; ++I) {
|
2013-02-09 06:30:41 +08:00
|
|
|
if (isIdentifierBody(Name[I]))
|
2012-10-13 05:15:50 +08:00
|
|
|
Buffer.push_back(Name[I]);
|
|
|
|
else
|
|
|
|
Buffer.push_back('_');
|
|
|
|
}
|
|
|
|
|
|
|
|
Name = StringRef(Buffer.data(), Buffer.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
while (llvm::StringSwitch<bool>(Name)
|
|
|
|
#define KEYWORD(Keyword,Conditions) .Case(#Keyword, true)
|
|
|
|
#define ALIAS(Keyword, AliasOf, Conditions) .Case(Keyword, true)
|
|
|
|
#include "clang/Basic/TokenKinds.def"
|
|
|
|
.Default(false)) {
|
|
|
|
if (Name.data() != Buffer.data())
|
|
|
|
Buffer.append(Name.begin(), Name.end());
|
|
|
|
Buffer.push_back('_');
|
|
|
|
Name = StringRef(Buffer.data(), Buffer.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
2013-05-03 01:58:30 +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);
|
|
|
|
}
|
|
|
|
|
2013-12-20 20:09:36 +08:00
|
|
|
ModuleMap::HeadersMap::iterator
|
|
|
|
ModuleMap::findKnownHeader(const FileEntry *File) {
|
2012-10-15 14:28:11 +08:00
|
|
|
HeadersMap::iterator Known = Headers.find(File);
|
2013-12-11 20:13:00 +08:00
|
|
|
if (Known == Headers.end() && File->getDir() == BuiltinIncludeDir &&
|
|
|
|
isBuiltinHeader(llvm::sys::path::filename(File->getName()))) {
|
|
|
|
HeaderInfo.loadTopLevelSystemModules();
|
2013-12-20 20:09:36 +08:00
|
|
|
return Headers.find(File);
|
2013-12-11 20:13:00 +08:00
|
|
|
}
|
2013-12-20 20:09:36 +08:00
|
|
|
return Known;
|
|
|
|
}
|
|
|
|
|
2014-04-10 08:39:10 +08:00
|
|
|
ModuleMap::KnownHeader
|
|
|
|
ModuleMap::findHeaderInUmbrellaDirs(const FileEntry *File,
|
|
|
|
SmallVectorImpl<const DirectoryEntry *> &IntermediateDirs) {
|
|
|
|
const DirectoryEntry *Dir = File->getDir();
|
|
|
|
assert(Dir && "file in no directory");
|
|
|
|
|
|
|
|
// Note: as an egregious but useful hack we use the real path here, because
|
|
|
|
// frameworks moving from top-level frameworks to embedded frameworks tend
|
|
|
|
// to be symlinked from the top-level location to the embedded location,
|
|
|
|
// and we need to resolve lookups as if we had found the embedded location.
|
|
|
|
StringRef DirName = SourceMgr.getFileManager().getCanonicalName(Dir);
|
|
|
|
|
|
|
|
// Keep walking up the directory hierarchy, looking for a directory with
|
|
|
|
// an umbrella header.
|
|
|
|
do {
|
|
|
|
auto KnownDir = UmbrellaDirs.find(Dir);
|
|
|
|
if (KnownDir != UmbrellaDirs.end())
|
|
|
|
return KnownHeader(KnownDir->second, NormalHeader);
|
|
|
|
|
|
|
|
IntermediateDirs.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 KnownHeader();
|
|
|
|
}
|
|
|
|
|
2014-10-25 04:23:01 +08:00
|
|
|
// Returns true if RequestingModule directly uses RequestedModule.
|
2013-12-20 20:09:36 +08:00
|
|
|
static bool directlyUses(const Module *RequestingModule,
|
|
|
|
const Module *RequestedModule) {
|
|
|
|
return std::find(RequestingModule->DirectUses.begin(),
|
|
|
|
RequestingModule->DirectUses.end(),
|
|
|
|
RequestedModule) != RequestingModule->DirectUses.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool violatesPrivateInclude(Module *RequestingModule,
|
|
|
|
const FileEntry *IncFileEnt,
|
|
|
|
ModuleMap::ModuleHeaderRole Role,
|
|
|
|
Module *RequestedModule) {
|
2014-10-25 04:23:01 +08:00
|
|
|
bool IsPrivateRole = Role & ModuleMap::PrivateHeader;
|
|
|
|
#ifndef NDEBUG
|
2013-12-20 20:09:36 +08:00
|
|
|
// Check for consistency between the module header role
|
|
|
|
// as obtained from the lookup and as obtained from the module.
|
|
|
|
// This check is not cheap, so enable it only for debugging.
|
2014-10-25 04:23:01 +08:00
|
|
|
bool IsPrivate = false;
|
2014-12-02 08:08:08 +08:00
|
|
|
SmallVectorImpl<Module::Header> *HeaderList[] =
|
|
|
|
{&RequestedModule->Headers[Module::HK_Private],
|
|
|
|
&RequestedModule->Headers[Module::HK_PrivateTextual]};
|
2014-10-27 03:39:46 +08:00
|
|
|
for (auto *Hdrs : HeaderList)
|
2014-10-25 04:23:01 +08:00
|
|
|
IsPrivate |=
|
2014-12-02 08:08:08 +08:00
|
|
|
std::find_if(Hdrs->begin(), Hdrs->end(), [&](const Module::Header &H) {
|
|
|
|
return H.Entry == IncFileEnt;
|
|
|
|
}) != Hdrs->end();
|
2014-10-25 04:23:01 +08:00
|
|
|
assert(IsPrivate == IsPrivateRole && "inconsistent headers and roles");
|
|
|
|
#endif
|
|
|
|
return IsPrivateRole &&
|
2013-12-20 20:09:36 +08:00
|
|
|
RequestedModule->getTopLevelModule() != RequestingModule;
|
|
|
|
}
|
|
|
|
|
2014-05-06 05:44:13 +08:00
|
|
|
static Module *getTopLevelOrNull(Module *M) {
|
|
|
|
return M ? M->getTopLevelModule() : nullptr;
|
|
|
|
}
|
|
|
|
|
2013-12-20 20:09:36 +08:00
|
|
|
void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
|
|
|
|
SourceLocation FilenameLoc,
|
|
|
|
StringRef Filename,
|
|
|
|
const FileEntry *File) {
|
|
|
|
// No errors for indirect modules. This may be a bit of a problem for modules
|
|
|
|
// with no source files.
|
2014-05-06 05:44:13 +08:00
|
|
|
if (getTopLevelOrNull(RequestingModule) != getTopLevelOrNull(SourceModule))
|
2013-12-20 20:09:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (RequestingModule)
|
|
|
|
resolveUses(RequestingModule, /*Complain=*/false);
|
|
|
|
|
2014-05-06 05:44:13 +08:00
|
|
|
bool Excluded = false;
|
2014-05-18 07:10:59 +08:00
|
|
|
Module *Private = nullptr;
|
|
|
|
Module *NotUsed = nullptr;
|
2013-12-20 20:09:36 +08:00
|
|
|
|
2014-05-06 05:44:13 +08:00
|
|
|
HeadersMap::iterator Known = findKnownHeader(File);
|
|
|
|
if (Known != Headers.end()) {
|
|
|
|
for (const KnownHeader &Header : Known->second) {
|
|
|
|
// If 'File' is part of 'RequestingModule' we can definitely include it.
|
|
|
|
if (Header.getModule() == RequestingModule)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Remember private headers for later printing of a diagnostic.
|
|
|
|
if (violatesPrivateInclude(RequestingModule, File, Header.getRole(),
|
|
|
|
Header.getModule())) {
|
|
|
|
Private = Header.getModule();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If uses need to be specified explicitly, we are only allowed to return
|
|
|
|
// modules that are explicitly used by the requesting module.
|
|
|
|
if (RequestingModule && LangOpts.ModulesDeclUse &&
|
|
|
|
!directlyUses(RequestingModule, Header.getModule())) {
|
|
|
|
NotUsed = Header.getModule();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have found a module that we can happily use.
|
|
|
|
return;
|
2013-12-20 20:09:36 +08:00
|
|
|
}
|
2014-10-23 10:01:19 +08:00
|
|
|
|
|
|
|
Excluded = true;
|
2013-12-20 20:09:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have found a header, but it is private.
|
2014-05-18 07:10:59 +08:00
|
|
|
if (Private) {
|
2013-12-20 20:09:36 +08:00
|
|
|
Diags.Report(FilenameLoc, diag::error_use_of_private_header_outside_module)
|
|
|
|
<< Filename;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have found a module, but we don't use it.
|
2014-05-18 07:10:59 +08:00
|
|
|
if (NotUsed) {
|
2013-12-20 20:09:36 +08:00
|
|
|
Diags.Report(FilenameLoc, diag::error_undeclared_use_of_module)
|
|
|
|
<< RequestingModule->getFullModuleName() << Filename;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-06 05:44:13 +08:00
|
|
|
if (Excluded || isHeaderInUmbrellaDirs(File))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// At this point, only non-modular includes remain.
|
|
|
|
|
|
|
|
if (LangOpts.ModulesStrictDeclUse) {
|
|
|
|
Diags.Report(FilenameLoc, diag::error_undeclared_use_of_module)
|
|
|
|
<< RequestingModule->getFullModuleName() << Filename;
|
|
|
|
} else if (RequestingModule) {
|
|
|
|
diag::kind DiagID = RequestingModule->getTopLevelModule()->IsFramework ?
|
|
|
|
diag::warn_non_modular_include_in_framework_module :
|
|
|
|
diag::warn_non_modular_include_in_module;
|
|
|
|
Diags.Report(FilenameLoc, DiagID) << RequestingModule->getFullModuleName();
|
|
|
|
}
|
2013-12-20 20:09:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ModuleMap::KnownHeader
|
|
|
|
ModuleMap::findModuleForHeader(const FileEntry *File,
|
2014-10-23 07:50:56 +08:00
|
|
|
Module *RequestingModule,
|
|
|
|
bool IncludeTextualHeaders) {
|
2013-12-20 20:09:36 +08:00
|
|
|
HeadersMap::iterator Known = findKnownHeader(File);
|
2013-12-11 20:13:00 +08:00
|
|
|
|
2014-10-23 07:50:56 +08:00
|
|
|
auto MakeResult = [&](ModuleMap::KnownHeader R) -> ModuleMap::KnownHeader {
|
2014-10-25 04:23:01 +08:00
|
|
|
if (!IncludeTextualHeaders && (R.getRole() & ModuleMap::TextualHeader))
|
2014-10-23 07:50:56 +08:00
|
|
|
return ModuleMap::KnownHeader();
|
|
|
|
return R;
|
|
|
|
};
|
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
if (Known != Headers.end()) {
|
2014-10-25 04:23:01 +08:00
|
|
|
ModuleMap::KnownHeader Result;
|
2013-10-22 16:09:47 +08:00
|
|
|
|
|
|
|
// Iterate over all modules that 'File' is part of to find the best fit.
|
|
|
|
for (SmallVectorImpl<KnownHeader>::iterator I = Known->second.begin(),
|
|
|
|
E = Known->second.end();
|
|
|
|
I != E; ++I) {
|
2013-12-11 20:13:00 +08:00
|
|
|
// Cannot use a module if it is unavailable.
|
|
|
|
if (!I->getModule()->isAvailable())
|
2013-10-22 16:09:47 +08:00
|
|
|
continue;
|
2011-12-31 12:05:44 +08:00
|
|
|
|
2013-10-22 16:09:47 +08:00
|
|
|
// If 'File' is part of 'RequestingModule', 'RequestingModule' is the
|
|
|
|
// module we are looking for.
|
|
|
|
if (I->getModule() == RequestingModule)
|
2014-10-23 07:50:56 +08:00
|
|
|
return MakeResult(*I);
|
2013-10-22 16:09:47 +08:00
|
|
|
|
|
|
|
// If uses need to be specified explicitly, we are only allowed to return
|
|
|
|
// modules that are explicitly used by the requesting module.
|
|
|
|
if (RequestingModule && LangOpts.ModulesDeclUse &&
|
2013-12-20 20:09:36 +08:00
|
|
|
!directlyUses(RequestingModule, I->getModule()))
|
2013-10-22 16:09:47 +08:00
|
|
|
continue;
|
2013-12-11 20:13:00 +08:00
|
|
|
|
2014-10-25 04:23:01 +08:00
|
|
|
// Prefer a public header over a private header.
|
|
|
|
if (!Result || (Result.getRole() & ModuleMap::PrivateHeader))
|
|
|
|
Result = *I;
|
2013-10-22 16:09:47 +08:00
|
|
|
}
|
2014-10-23 07:50:56 +08:00
|
|
|
return MakeResult(Result);
|
2011-12-31 12:05:44 +08:00
|
|
|
}
|
2013-05-03 01:58:30 +08:00
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<const DirectoryEntry *, 2> SkippedDirs;
|
2014-04-10 08:39:10 +08:00
|
|
|
KnownHeader H = findHeaderInUmbrellaDirs(File, SkippedDirs);
|
|
|
|
if (H) {
|
|
|
|
Module *Result = H.getModule();
|
|
|
|
|
|
|
|
// Search up the module stack until we find a module with an umbrella
|
|
|
|
// directory.
|
|
|
|
Module *UmbrellaModule = Result;
|
|
|
|
while (!UmbrellaModule->getUmbrellaDir() && UmbrellaModule->Parent)
|
|
|
|
UmbrellaModule = UmbrellaModule->Parent;
|
|
|
|
|
|
|
|
if (UmbrellaModule->InferSubmodules) {
|
2014-08-09 08:57:23 +08:00
|
|
|
const FileEntry *UmbrellaModuleMap =
|
|
|
|
getModuleMapFileForUniquing(UmbrellaModule);
|
|
|
|
|
2014-04-10 08:39:10 +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.
|
|
|
|
bool Explicit = UmbrellaModule->InferExplicitSubmodules;
|
|
|
|
|
|
|
|
for (unsigned I = SkippedDirs.size(); I != 0; --I) {
|
|
|
|
// Find or create the module that corresponds to this directory name.
|
2012-10-13 05:15:50 +08:00
|
|
|
SmallString<32> NameBuf;
|
|
|
|
StringRef Name = sanitizeFilenameAsIdentifier(
|
2014-04-10 08:39:10 +08:00
|
|
|
llvm::sys::path::stem(SkippedDirs[I-1]->getName()), NameBuf);
|
2014-08-09 08:57:23 +08:00
|
|
|
Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
|
|
|
|
Explicit).first;
|
|
|
|
InferredModuleAllowedBy[Result] = UmbrellaModuleMap;
|
2014-04-24 05:10:46 +08:00
|
|
|
Result->IsInferred = true;
|
2014-04-10 08:39:10 +08:00
|
|
|
|
|
|
|
// Associate the module and the directory.
|
|
|
|
UmbrellaDirs[SkippedDirs[I-1]] = Result;
|
|
|
|
|
|
|
|
// If inferred submodules export everything they import, add a
|
2011-12-06 09:10:29 +08:00
|
|
|
// wildcard to the set of exports.
|
2011-12-07 00:17:15 +08:00
|
|
|
if (UmbrellaModule->InferExportWildcard && Result->Exports.empty())
|
2014-05-18 07:10:59 +08:00
|
|
|
Result->Exports.push_back(Module::ExportDecl(nullptr, true));
|
2011-12-06 09:10:29 +08:00
|
|
|
}
|
2011-12-31 12:05:44 +08:00
|
|
|
|
2014-04-10 08:39:10 +08:00
|
|
|
// Infer a submodule with the same name as this header file.
|
|
|
|
SmallString<32> NameBuf;
|
|
|
|
StringRef Name = sanitizeFilenameAsIdentifier(
|
2014-04-15 02:00:01 +08:00
|
|
|
llvm::sys::path::stem(File->getName()), NameBuf);
|
2014-08-09 08:57:23 +08:00
|
|
|
Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
|
|
|
|
Explicit).first;
|
|
|
|
InferredModuleAllowedBy[Result] = UmbrellaModuleMap;
|
2014-04-24 05:10:46 +08:00
|
|
|
Result->IsInferred = true;
|
2014-04-10 08:39:10 +08:00
|
|
|
Result->addTopHeader(File);
|
|
|
|
|
|
|
|
// If inferred submodules export everything they import, add a
|
|
|
|
// wildcard to the set of exports.
|
|
|
|
if (UmbrellaModule->InferExportWildcard && Result->Exports.empty())
|
2014-05-18 07:10:59 +08:00
|
|
|
Result->Exports.push_back(Module::ExportDecl(nullptr, true));
|
2014-04-10 08:39:10 +08:00
|
|
|
} 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
|
|
|
}
|
2014-04-10 08:39:10 +08:00
|
|
|
|
|
|
|
Headers[File].push_back(KnownHeader(Result, NormalHeader));
|
|
|
|
|
|
|
|
// If a header corresponds to an unavailable module, don't report
|
|
|
|
// that it maps to anything.
|
|
|
|
if (!Result->isAvailable())
|
|
|
|
return KnownHeader();
|
|
|
|
|
2014-10-23 07:50:56 +08:00
|
|
|
return MakeResult(Headers[File].back());
|
2014-04-10 08:39:10 +08:00
|
|
|
}
|
2014-10-23 07:50:56 +08:00
|
|
|
|
2013-06-21 05:14:14 +08:00
|
|
|
return KnownHeader();
|
2011-11-12 06:18:48 +08:00
|
|
|
}
|
|
|
|
|
2013-02-20 03:58:45 +08:00
|
|
|
bool ModuleMap::isHeaderInUnavailableModule(const FileEntry *Header) const {
|
2014-05-18 07:10:59 +08:00
|
|
|
return isHeaderUnavailableInModule(Header, nullptr);
|
2014-04-08 21:13:04 +08:00
|
|
|
}
|
|
|
|
|
2014-04-18 22:36:51 +08:00
|
|
|
bool
|
|
|
|
ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
|
|
|
|
const Module *RequestingModule) const {
|
2013-02-20 03:58:45 +08:00
|
|
|
HeadersMap::const_iterator Known = Headers.find(Header);
|
2013-10-22 16:09:47 +08:00
|
|
|
if (Known != Headers.end()) {
|
|
|
|
for (SmallVectorImpl<KnownHeader>::const_iterator
|
|
|
|
I = Known->second.begin(),
|
|
|
|
E = Known->second.end();
|
|
|
|
I != E; ++I) {
|
2014-04-08 21:13:04 +08:00
|
|
|
if (I->isAvailable() && (!RequestingModule ||
|
|
|
|
I->getModule()->isSubModuleOf(RequestingModule)))
|
2013-10-22 16:09:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-04-08 21:13:04 +08:00
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
const DirectoryEntry *Dir = Header->getDir();
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<const DirectoryEntry *, 2> SkippedDirs;
|
2011-12-31 12:05:44 +08:00
|
|
|
StringRef DirName = Dir->getName();
|
|
|
|
|
2014-04-08 21:13:04 +08:00
|
|
|
auto IsUnavailable = [&](const Module *M) {
|
|
|
|
return !M->isAvailable() && (!RequestingModule ||
|
|
|
|
M->isSubModuleOf(RequestingModule));
|
|
|
|
};
|
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
// Keep walking up the directory hierarchy, looking for a directory with
|
|
|
|
// an umbrella header.
|
2014-04-08 21:13:04 +08:00
|
|
|
do {
|
2013-02-20 03:58:45 +08:00
|
|
|
llvm::DenseMap<const DirectoryEntry *, Module *>::const_iterator KnownDir
|
2011-12-31 12:05:44 +08:00
|
|
|
= UmbrellaDirs.find(Dir);
|
|
|
|
if (KnownDir != UmbrellaDirs.end()) {
|
|
|
|
Module *Found = KnownDir->second;
|
2014-04-08 21:13:04 +08:00
|
|
|
if (IsUnavailable(Found))
|
2011-12-31 12:05:44 +08:00
|
|
|
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.
|
2012-10-13 05:15:50 +08:00
|
|
|
SmallString<32> NameBuf;
|
|
|
|
StringRef Name = sanitizeFilenameAsIdentifier(
|
|
|
|
llvm::sys::path::stem(SkippedDirs[I-1]->getName()),
|
|
|
|
NameBuf);
|
2011-12-31 12:05:44 +08:00
|
|
|
Found = lookupModuleQualified(Name, Found);
|
|
|
|
if (!Found)
|
|
|
|
return false;
|
2014-04-08 21:13:04 +08:00
|
|
|
if (IsUnavailable(Found))
|
2011-12-31 12:05:44 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Infer a submodule with the same name as this header file.
|
2012-10-13 05:15:50 +08:00
|
|
|
SmallString<32> NameBuf;
|
|
|
|
StringRef Name = sanitizeFilenameAsIdentifier(
|
|
|
|
llvm::sys::path::stem(Header->getName()),
|
|
|
|
NameBuf);
|
2011-12-31 12:05:44 +08:00
|
|
|
Found = lookupModuleQualified(Name, Found);
|
|
|
|
if (!Found)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-08 21:13:04 +08:00
|
|
|
return IsUnavailable(Found);
|
2011-12-31 12:05:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
Use the same SourceManager for ModuleMaps and compilations.
This allows using virtual file mappings on the original SourceManager to
map in virtual module.map files. Without this patch, the ModuleMap
search will find a module.map file (as the FileEntry exists in the
FileManager), but will be unable to get the content from the
SourceManager (as ModuleMap previously created its own SourceManager).
Two problems needed to be fixed which this patch exposed:
1. Storing the inferred module map
When writing out a module, the ASTWriter stores the names of the files
in the main source manager; when loading the AST again, the ASTReader
errs out if such a file is found missing, unless it is overridden.
Previously CompilerInstance's compileModule method would store the
inferred module map to a temporary file; the problem with this approach
is that now that the module map is handled by the main source manager,
the ASTWriter stores the name of the temporary module map as source to
the compilation; later, when the module is loaded, the temporary file
has already been deleted, which leads to a compilation error. This patch
changes the inferred module map to instead inject a virtual file into
the source manager. This both saves some disk IO, and works with how the
ASTWriter/ASTReader handle overridden source files.
2. Changing test input in test/Modules/Inputs/*
Now that the module map file is handled by the main source manager, the
VerifyDiagnosticConsumer will not ignore diagnostics created while
parsing the module map file. The module test test/Modules/renamed.m uses
-I test/Modules/Inputs and triggers recursive loading of all module maps
in test/Modules/Inputs, some of which had conflicting names, thus
leading errors while parsing the module maps. Those diagnostics already
occur on trunk, but before this patch they would not break the test, as
they were ignored by the VerifyDiagnosticConsumer. This patch thus
changes the module maps that have been recently introduced which broke
the invariant of compatible modules maps in test/Modules/Inputs.
llvm-svn: 193314
2013-10-24 15:51:24 +08:00
|
|
|
Dir = SourceMgr.getFileManager().getDirectory(DirName);
|
2011-12-31 12:05:44 +08:00
|
|
|
} while (Dir);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-20 03:58:45 +08:00
|
|
|
Module *ModuleMap::findModule(StringRef Name) const {
|
|
|
|
llvm::StringMap<Module *>::const_iterator Known = Modules.find(Name);
|
2011-11-12 07:20:24 +08:00
|
|
|
if (Known != Modules.end())
|
|
|
|
return Known->getValue();
|
2014-05-18 07:10:59 +08:00
|
|
|
|
|
|
|
return nullptr;
|
2011-11-12 07:20:24 +08:00
|
|
|
}
|
|
|
|
|
2013-02-20 03:58:45 +08:00
|
|
|
Module *ModuleMap::lookupModuleUnqualified(StringRef Name,
|
|
|
|
Module *Context) const {
|
2011-12-02 09:47:07 +08:00
|
|
|
for(; Context; Context = Context->Parent) {
|
|
|
|
if (Module *Sub = lookupModuleQualified(Name, Context))
|
|
|
|
return Sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
return findModule(Name);
|
|
|
|
}
|
|
|
|
|
2013-02-20 03:58:45 +08:00
|
|
|
Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) const{
|
2011-12-02 09:47:07 +08:00
|
|
|
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>
|
2014-08-09 08:57:23 +08:00
|
|
|
ModuleMap::findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
|
2011-12-01 01:33:56 +08:00
|
|
|
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.
|
2014-08-09 08:57:23 +08:00
|
|
|
Module *Result = new Module(Name, SourceLocation(), Parent,
|
2014-04-15 02:00:01 +08:00
|
|
|
IsFramework, IsExplicit);
|
2013-09-24 17:14:14 +08:00
|
|
|
if (LangOpts.CurrentModule == Name) {
|
|
|
|
SourceModule = Result;
|
|
|
|
SourceModuleName = Name;
|
|
|
|
}
|
2013-05-09 07:46:46 +08:00
|
|
|
if (!Parent) {
|
2011-12-01 01:33:56 +08:00
|
|
|
Modules[Name] = Result;
|
2013-05-09 07:46:46 +08:00
|
|
|
if (!LangOpts.CurrentModule.empty() && !CompilingModule &&
|
|
|
|
Name == LangOpts.CurrentModule) {
|
|
|
|
CompilingModule = Result;
|
|
|
|
}
|
|
|
|
}
|
2011-12-01 01:33:56 +08:00
|
|
|
return std::make_pair(Result, true);
|
|
|
|
}
|
|
|
|
|
2013-01-15 01:57:51 +08:00
|
|
|
/// \brief For a framework module, infer the framework against which we
|
|
|
|
/// should link.
|
|
|
|
static void inferFrameworkLink(Module *Mod, const DirectoryEntry *FrameworkDir,
|
|
|
|
FileManager &FileMgr) {
|
|
|
|
assert(Mod->IsFramework && "Can only infer linking for framework modules");
|
|
|
|
assert(!Mod->isSubFramework() &&
|
|
|
|
"Can only infer linking for top-level frameworks");
|
|
|
|
|
|
|
|
SmallString<128> LibName;
|
|
|
|
LibName += FrameworkDir->getName();
|
|
|
|
llvm::sys::path::append(LibName, Mod->Name);
|
|
|
|
if (FileMgr.getFile(LibName)) {
|
|
|
|
Mod->LinkLibraries.push_back(Module::LinkLibrary(Mod->Name,
|
|
|
|
/*IsFramework=*/true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-01 07:21:26 +08:00
|
|
|
Module *
|
2012-11-07 03:39:40 +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;
|
|
|
|
|
Use the same SourceManager for ModuleMaps and compilations.
This allows using virtual file mappings on the original SourceManager to
map in virtual module.map files. Without this patch, the ModuleMap
search will find a module.map file (as the FileEntry exists in the
FileManager), but will be unable to get the content from the
SourceManager (as ModuleMap previously created its own SourceManager).
Two problems needed to be fixed which this patch exposed:
1. Storing the inferred module map
When writing out a module, the ASTWriter stores the names of the files
in the main source manager; when loading the AST again, the ASTReader
errs out if such a file is found missing, unless it is overridden.
Previously CompilerInstance's compileModule method would store the
inferred module map to a temporary file; the problem with this approach
is that now that the module map is handled by the main source manager,
the ASTWriter stores the name of the temporary module map as source to
the compilation; later, when the module is loaded, the temporary file
has already been deleted, which leads to a compilation error. This patch
changes the inferred module map to instead inject a virtual file into
the source manager. This both saves some disk IO, and works with how the
ASTWriter/ASTReader handle overridden source files.
2. Changing test input in test/Modules/Inputs/*
Now that the module map file is handled by the main source manager, the
VerifyDiagnosticConsumer will not ignore diagnostics created while
parsing the module map file. The module test test/Modules/renamed.m uses
-I test/Modules/Inputs and triggers recursive loading of all module maps
in test/Modules/Inputs, some of which had conflicting names, thus
leading errors while parsing the module maps. Those diagnostics already
occur on trunk, but before this patch they would not break the test, as
they were ignored by the VerifyDiagnosticConsumer. This patch thus
changes the module maps that have been recently introduced which broke
the invariant of compatible modules maps in test/Modules/Inputs.
llvm-svn: 193314
2013-10-24 15:51:24 +08:00
|
|
|
FileManager &FileMgr = SourceMgr.getFileManager();
|
2012-11-07 03:39:40 +08:00
|
|
|
|
|
|
|
// If the framework has a parent path from which we're allowed to infer
|
|
|
|
// a framework module, do so.
|
2014-04-15 02:00:01 +08:00
|
|
|
const FileEntry *ModuleMapFile = nullptr;
|
2012-11-07 03:39:40 +08:00
|
|
|
if (!Parent) {
|
2013-01-10 09:43:00 +08:00
|
|
|
// Determine whether we're allowed to infer a module map.
|
2013-01-26 08:55:12 +08:00
|
|
|
|
2013-01-10 09:43:00 +08:00
|
|
|
// Note: as an egregious but useful hack we use the real path here, because
|
|
|
|
// we might be looking at an embedded framework that symlinks out to a
|
|
|
|
// top-level framework, and we need to infer as if we were naming the
|
|
|
|
// top-level framework.
|
2013-01-26 08:55:12 +08:00
|
|
|
StringRef FrameworkDirName
|
Use the same SourceManager for ModuleMaps and compilations.
This allows using virtual file mappings on the original SourceManager to
map in virtual module.map files. Without this patch, the ModuleMap
search will find a module.map file (as the FileEntry exists in the
FileManager), but will be unable to get the content from the
SourceManager (as ModuleMap previously created its own SourceManager).
Two problems needed to be fixed which this patch exposed:
1. Storing the inferred module map
When writing out a module, the ASTWriter stores the names of the files
in the main source manager; when loading the AST again, the ASTReader
errs out if such a file is found missing, unless it is overridden.
Previously CompilerInstance's compileModule method would store the
inferred module map to a temporary file; the problem with this approach
is that now that the module map is handled by the main source manager,
the ASTWriter stores the name of the temporary module map as source to
the compilation; later, when the module is loaded, the temporary file
has already been deleted, which leads to a compilation error. This patch
changes the inferred module map to instead inject a virtual file into
the source manager. This both saves some disk IO, and works with how the
ASTWriter/ASTReader handle overridden source files.
2. Changing test input in test/Modules/Inputs/*
Now that the module map file is handled by the main source manager, the
VerifyDiagnosticConsumer will not ignore diagnostics created while
parsing the module map file. The module test test/Modules/renamed.m uses
-I test/Modules/Inputs and triggers recursive loading of all module maps
in test/Modules/Inputs, some of which had conflicting names, thus
leading errors while parsing the module maps. Those diagnostics already
occur on trunk, but before this patch they would not break the test, as
they were ignored by the VerifyDiagnosticConsumer. This patch thus
changes the module maps that have been recently introduced which broke
the invariant of compatible modules maps in test/Modules/Inputs.
llvm-svn: 193314
2013-10-24 15:51:24 +08:00
|
|
|
= SourceMgr.getFileManager().getCanonicalName(FrameworkDir);
|
2013-01-10 09:43:00 +08:00
|
|
|
|
2014-07-15 03:45:12 +08:00
|
|
|
// In case this is a case-insensitive filesystem, make sure the canonical
|
|
|
|
// directory name matches ModuleName exactly. Modules are case-sensitive.
|
|
|
|
// FIXME: we should be able to give a fix-it hint for the correct spelling.
|
|
|
|
if (llvm::sys::path::stem(FrameworkDirName) != ModuleName)
|
|
|
|
return nullptr;
|
|
|
|
|
2012-11-07 03:39:40 +08:00
|
|
|
bool canInfer = false;
|
2013-01-10 09:43:00 +08:00
|
|
|
if (llvm::sys::path::has_parent_path(FrameworkDirName)) {
|
2012-11-07 03:39:40 +08:00
|
|
|
// Figure out the parent path.
|
2013-01-10 09:43:00 +08:00
|
|
|
StringRef Parent = llvm::sys::path::parent_path(FrameworkDirName);
|
2012-11-07 03:39:40 +08:00
|
|
|
if (const DirectoryEntry *ParentDir = FileMgr.getDirectory(Parent)) {
|
|
|
|
// Check whether we have already looked into the parent directory
|
|
|
|
// for a module map.
|
2013-02-20 03:58:45 +08:00
|
|
|
llvm::DenseMap<const DirectoryEntry *, InferredDirectory>::const_iterator
|
2012-11-07 03:39:40 +08:00
|
|
|
inferred = InferredDirectories.find(ParentDir);
|
|
|
|
if (inferred == InferredDirectories.end()) {
|
|
|
|
// We haven't looked here before. Load a module map, if there is
|
|
|
|
// one.
|
2014-03-20 04:23:34 +08:00
|
|
|
bool IsFrameworkDir = Parent.endswith(".framework");
|
|
|
|
if (const FileEntry *ModMapFile =
|
|
|
|
HeaderInfo.lookupModuleMapFile(ParentDir, IsFrameworkDir)) {
|
2014-12-10 11:09:48 +08:00
|
|
|
parseModuleMapFile(ModMapFile, IsSystem, ParentDir);
|
2012-11-07 03:39:40 +08:00
|
|
|
inferred = InferredDirectories.find(ParentDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inferred == InferredDirectories.end())
|
|
|
|
inferred = InferredDirectories.insert(
|
|
|
|
std::make_pair(ParentDir, InferredDirectory())).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inferred->second.InferModules) {
|
|
|
|
// We're allowed to infer for this directory, but make sure it's okay
|
|
|
|
// to infer this particular module.
|
2013-01-10 09:43:00 +08:00
|
|
|
StringRef Name = llvm::sys::path::stem(FrameworkDirName);
|
2012-11-07 03:39:40 +08:00
|
|
|
canInfer = std::find(inferred->second.ExcludedModules.begin(),
|
|
|
|
inferred->second.ExcludedModules.end(),
|
|
|
|
Name) == inferred->second.ExcludedModules.end();
|
|
|
|
|
|
|
|
if (inferred->second.InferSystemModules)
|
|
|
|
IsSystem = true;
|
2014-04-15 02:00:01 +08:00
|
|
|
ModuleMapFile = inferred->second.ModuleMapFile;
|
2012-11-07 03:39:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're not allowed to infer a framework module, don't.
|
|
|
|
if (!canInfer)
|
2014-05-18 07:10:59 +08:00
|
|
|
return nullptr;
|
2014-04-15 02:00:01 +08:00
|
|
|
} else
|
2014-08-09 08:57:23 +08:00
|
|
|
ModuleMapFile = getModuleMapFileForUniquing(Parent);
|
2012-11-07 03:39:40 +08:00
|
|
|
|
|
|
|
|
2011-11-17 09:41:17 +08:00
|
|
|
// Look for an umbrella header.
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName());
|
2013-06-29 00:25:46 +08:00
|
|
|
llvm::sys::path::append(UmbrellaName, "Headers", 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)
|
2014-05-18 07:10:59 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2014-08-09 08:57:23 +08:00
|
|
|
Module *Result = new Module(ModuleName, SourceLocation(), Parent,
|
2011-12-07 03:39:29 +08:00
|
|
|
/*IsFramework=*/true, /*IsExplicit=*/false);
|
2014-08-09 08:57:23 +08:00
|
|
|
InferredModuleAllowedBy[Result] = ModuleMapFile;
|
|
|
|
Result->IsInferred = true;
|
2013-09-24 17:14:14 +08:00
|
|
|
if (LangOpts.CurrentModule == ModuleName) {
|
|
|
|
SourceModule = Result;
|
|
|
|
SourceModuleName = ModuleName;
|
|
|
|
}
|
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;
|
2013-10-22 16:09:47 +08:00
|
|
|
Headers[UmbrellaHeader].push_back(KnownHeader(Result, NormalHeader));
|
2011-12-13 07:55:05 +08:00
|
|
|
UmbrellaDirs[UmbrellaHeader->getDir()] = Result;
|
2011-12-06 01:40:25 +08:00
|
|
|
|
|
|
|
// export *
|
2014-05-18 07:10:59 +08:00
|
|
|
Result->Exports.push_back(Module::ExportDecl(nullptr, 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.
|
2014-06-12 22:02:15 +08:00
|
|
|
std::error_code EC;
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<128> SubframeworksDirName
|
2011-12-09 00:13:24 +08:00
|
|
|
= StringRef(FrameworkDir->getName());
|
2011-12-07 03:39:29 +08:00
|
|
|
llvm::sys::path::append(SubframeworksDirName, "Frameworks");
|
2013-09-11 19:23:15 +08:00
|
|
|
llvm::sys::path::native(SubframeworksDirName);
|
2011-12-09 00:13:24 +08:00
|
|
|
for (llvm::sys::fs::directory_iterator
|
2013-09-11 19:23:15 +08:00
|
|
|
Dir(SubframeworksDirName.str(), EC), DirEnd;
|
2011-12-07 03:39:29 +08:00
|
|
|
Dir != DirEnd && !EC; Dir.increment(EC)) {
|
|
|
|
if (!StringRef(Dir->path()).endswith(".framework"))
|
|
|
|
continue;
|
2012-09-27 22:50:15 +08:00
|
|
|
|
2011-12-07 03:39:29 +08:00
|
|
|
if (const DirectoryEntry *SubframeworkDir
|
|
|
|
= FileMgr.getDirectory(Dir->path())) {
|
2012-09-27 22:50:15 +08:00
|
|
|
// Note: as an egregious but useful hack, we use the real path here and
|
|
|
|
// check whether it is actually a subdirectory of the parent directory.
|
|
|
|
// This will not be the case if the 'subframework' is actually a symlink
|
|
|
|
// out to a top-level framework.
|
2013-01-26 08:55:12 +08:00
|
|
|
StringRef SubframeworkDirName = FileMgr.getCanonicalName(SubframeworkDir);
|
|
|
|
bool FoundParent = false;
|
|
|
|
do {
|
|
|
|
// Get the parent directory name.
|
|
|
|
SubframeworkDirName
|
|
|
|
= llvm::sys::path::parent_path(SubframeworkDirName);
|
|
|
|
if (SubframeworkDirName.empty())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (FileMgr.getDirectory(SubframeworkDirName) == FrameworkDir) {
|
|
|
|
FoundParent = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (true);
|
2012-09-27 22:50:15 +08:00
|
|
|
|
2013-01-26 08:55:12 +08:00
|
|
|
if (!FoundParent)
|
|
|
|
continue;
|
2012-09-27 22:50:15 +08:00
|
|
|
|
2011-12-07 03:39:29 +08:00
|
|
|
// FIXME: Do we want to warn about subframeworks without umbrella headers?
|
2012-10-13 05:15:50 +08:00
|
|
|
SmallString<32> NameBuf;
|
|
|
|
inferFrameworkModule(sanitizeFilenameAsIdentifier(
|
|
|
|
llvm::sys::path::stem(Dir->path()), NameBuf),
|
|
|
|
SubframeworkDir, IsSystem, Result);
|
2011-12-07 03:39:29 +08:00
|
|
|
}
|
|
|
|
}
|
2012-01-14 00:54:27 +08:00
|
|
|
|
2013-01-15 01:57:51 +08:00
|
|
|
// If the module is a top-level framework, automatically link against the
|
|
|
|
// framework.
|
|
|
|
if (!Result->isSubFramework()) {
|
|
|
|
inferFrameworkLink(Result, FrameworkDir, FileMgr);
|
|
|
|
}
|
|
|
|
|
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){
|
2013-10-22 16:09:47 +08:00
|
|
|
Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
|
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;
|
|
|
|
}
|
|
|
|
|
2014-12-02 08:08:08 +08:00
|
|
|
static Module::HeaderKind headerRoleToKind(ModuleMap::ModuleHeaderRole Role) {
|
2014-10-26 21:12:35 +08:00
|
|
|
switch ((int)Role) {
|
2014-12-02 08:08:08 +08:00
|
|
|
default: llvm_unreachable("unknown header role");
|
|
|
|
case ModuleMap::NormalHeader:
|
|
|
|
return Module::HK_Normal;
|
|
|
|
case ModuleMap::PrivateHeader:
|
|
|
|
return Module::HK_Private;
|
|
|
|
case ModuleMap::TextualHeader:
|
|
|
|
return Module::HK_Textual;
|
|
|
|
case ModuleMap::PrivateHeader | ModuleMap::TextualHeader:
|
|
|
|
return Module::HK_PrivateTextual;
|
2014-10-26 21:12:35 +08:00
|
|
|
}
|
2014-12-02 08:08:08 +08:00
|
|
|
}
|
2014-10-25 04:23:01 +08:00
|
|
|
|
2014-12-02 08:08:08 +08:00
|
|
|
void ModuleMap::addHeader(Module *Mod, Module::Header Header,
|
|
|
|
ModuleHeaderRole Role) {
|
2014-10-25 04:23:01 +08:00
|
|
|
if (!(Role & TextualHeader)) {
|
2013-05-09 07:46:46 +08:00
|
|
|
bool isCompilingModuleHeader = Mod->getTopLevelModule() == CompilingModule;
|
2014-12-02 08:08:08 +08:00
|
|
|
HeaderInfo.MarkFileModuleHeader(Header.Entry, Role,
|
|
|
|
isCompilingModuleHeader);
|
2013-03-14 05:13:51 +08:00
|
|
|
}
|
2014-12-02 08:08:08 +08:00
|
|
|
Headers[Header.Entry].push_back(KnownHeader(Mod, Role));
|
2011-12-06 09:10:29 +08:00
|
|
|
|
2014-12-02 08:08:08 +08:00
|
|
|
Mod->Headers[headerRoleToKind(Role)].push_back(std::move(Header));
|
|
|
|
}
|
2014-10-23 10:01:19 +08:00
|
|
|
|
2014-12-02 08:08:08 +08:00
|
|
|
void ModuleMap::excludeHeader(Module *Mod, Module::Header Header) {
|
2014-10-23 10:01:19 +08:00
|
|
|
// Add this as a known header so we won't implicitly add it to any
|
|
|
|
// umbrella directory module.
|
|
|
|
// FIXME: Should we only exclude it from umbrella modules within the
|
|
|
|
// specified module?
|
2014-12-02 08:08:08 +08:00
|
|
|
(void) Headers[Header.Entry];
|
|
|
|
|
|
|
|
Mod->Headers[Module::HK_Excluded].push_back(std::move(Header));
|
2014-10-23 10:01:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-30 03:06:37 +08:00
|
|
|
const FileEntry *
|
2014-08-13 00:42:33 +08:00
|
|
|
ModuleMap::getContainingModuleMapFile(const Module *Module) const {
|
Use the same SourceManager for ModuleMaps and compilations.
This allows using virtual file mappings on the original SourceManager to
map in virtual module.map files. Without this patch, the ModuleMap
search will find a module.map file (as the FileEntry exists in the
FileManager), but will be unable to get the content from the
SourceManager (as ModuleMap previously created its own SourceManager).
Two problems needed to be fixed which this patch exposed:
1. Storing the inferred module map
When writing out a module, the ASTWriter stores the names of the files
in the main source manager; when loading the AST again, the ASTReader
errs out if such a file is found missing, unless it is overridden.
Previously CompilerInstance's compileModule method would store the
inferred module map to a temporary file; the problem with this approach
is that now that the module map is handled by the main source manager,
the ASTWriter stores the name of the temporary module map as source to
the compilation; later, when the module is loaded, the temporary file
has already been deleted, which leads to a compilation error. This patch
changes the inferred module map to instead inject a virtual file into
the source manager. This both saves some disk IO, and works with how the
ASTWriter/ASTReader handle overridden source files.
2. Changing test input in test/Modules/Inputs/*
Now that the module map file is handled by the main source manager, the
VerifyDiagnosticConsumer will not ignore diagnostics created while
parsing the module map file. The module test test/Modules/renamed.m uses
-I test/Modules/Inputs and triggers recursive loading of all module maps
in test/Modules/Inputs, some of which had conflicting names, thus
leading errors while parsing the module maps. Those diagnostics already
occur on trunk, but before this patch they would not break the test, as
they were ignored by the VerifyDiagnosticConsumer. This patch thus
changes the module maps that have been recently introduced which broke
the invariant of compatible modules maps in test/Modules/Inputs.
llvm-svn: 193314
2013-10-24 15:51:24 +08:00
|
|
|
if (Module->DefinitionLoc.isInvalid())
|
2014-05-18 07:10:59 +08:00
|
|
|
return nullptr;
|
2011-11-30 03:06:37 +08:00
|
|
|
|
Use the same SourceManager for ModuleMaps and compilations.
This allows using virtual file mappings on the original SourceManager to
map in virtual module.map files. Without this patch, the ModuleMap
search will find a module.map file (as the FileEntry exists in the
FileManager), but will be unable to get the content from the
SourceManager (as ModuleMap previously created its own SourceManager).
Two problems needed to be fixed which this patch exposed:
1. Storing the inferred module map
When writing out a module, the ASTWriter stores the names of the files
in the main source manager; when loading the AST again, the ASTReader
errs out if such a file is found missing, unless it is overridden.
Previously CompilerInstance's compileModule method would store the
inferred module map to a temporary file; the problem with this approach
is that now that the module map is handled by the main source manager,
the ASTWriter stores the name of the temporary module map as source to
the compilation; later, when the module is loaded, the temporary file
has already been deleted, which leads to a compilation error. This patch
changes the inferred module map to instead inject a virtual file into
the source manager. This both saves some disk IO, and works with how the
ASTWriter/ASTReader handle overridden source files.
2. Changing test input in test/Modules/Inputs/*
Now that the module map file is handled by the main source manager, the
VerifyDiagnosticConsumer will not ignore diagnostics created while
parsing the module map file. The module test test/Modules/renamed.m uses
-I test/Modules/Inputs and triggers recursive loading of all module maps
in test/Modules/Inputs, some of which had conflicting names, thus
leading errors while parsing the module maps. Those diagnostics already
occur on trunk, but before this patch they would not break the test, as
they were ignored by the VerifyDiagnosticConsumer. This patch thus
changes the module maps that have been recently introduced which broke
the invariant of compatible modules maps in test/Modules/Inputs.
llvm-svn: 193314
2013-10-24 15:51:24 +08:00
|
|
|
return SourceMgr.getFileEntryForID(
|
|
|
|
SourceMgr.getFileID(Module->DefinitionLoc));
|
2011-11-30 03:06:37 +08:00
|
|
|
}
|
|
|
|
|
2014-08-13 00:42:33 +08:00
|
|
|
const FileEntry *ModuleMap::getModuleMapFileForUniquing(const Module *M) const {
|
2014-08-09 08:57:23 +08:00
|
|
|
if (M->IsInferred) {
|
|
|
|
assert(InferredModuleAllowedBy.count(M) && "missing inferred module map");
|
|
|
|
return InferredModuleAllowedBy.find(M)->second;
|
|
|
|
}
|
|
|
|
return getContainingModuleMapFile(M);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleMap::setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap) {
|
|
|
|
assert(M->IsInferred && "module not inferred");
|
|
|
|
InferredModuleAllowedBy[M] = ModMap;
|
|
|
|
}
|
|
|
|
|
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:";
|
2012-10-15 14:28:11 +08:00
|
|
|
for (HeadersMap::iterator H = Headers.begin(), HEnd = Headers.end();
|
2011-11-12 03:10:28 +08:00
|
|
|
H != HEnd; ++H) {
|
2013-10-22 16:09:47 +08:00
|
|
|
llvm::errs() << " \"" << H->first->getName() << "\" -> ";
|
|
|
|
for (SmallVectorImpl<KnownHeader>::const_iterator I = H->second.begin(),
|
|
|
|
E = H->second.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (I != H->second.begin())
|
|
|
|
llvm::errs() << ",";
|
|
|
|
llvm::errs() << I->getModule()->getFullModuleName();
|
|
|
|
}
|
|
|
|
llvm::errs() << "\n";
|
2011-11-12 03:10:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-24 17:14:14 +08:00
|
|
|
bool ModuleMap::resolveUses(Module *Mod, bool Complain) {
|
|
|
|
bool HadError = false;
|
|
|
|
for (unsigned I = 0, N = Mod->UnresolvedDirectUses.size(); I != N; ++I) {
|
|
|
|
Module *DirectUse =
|
|
|
|
resolveModuleId(Mod->UnresolvedDirectUses[I], Mod, Complain);
|
|
|
|
if (DirectUse)
|
|
|
|
Mod->DirectUses.push_back(DirectUse);
|
|
|
|
else
|
|
|
|
HadError = true;
|
|
|
|
}
|
|
|
|
Mod->UnresolvedDirectUses.clear();
|
|
|
|
return HadError;
|
|
|
|
}
|
|
|
|
|
2013-03-21 05:10:35 +08:00
|
|
|
bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) {
|
|
|
|
bool HadError = false;
|
|
|
|
for (unsigned I = 0, N = Mod->UnresolvedConflicts.size(); I != N; ++I) {
|
|
|
|
Module *OtherMod = resolveModuleId(Mod->UnresolvedConflicts[I].Id,
|
|
|
|
Mod, Complain);
|
|
|
|
if (!OtherMod) {
|
|
|
|
HadError = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Module::Conflict Conflict;
|
|
|
|
Conflict.Other = OtherMod;
|
|
|
|
Conflict.Message = Mod->UnresolvedConflicts[I].Message;
|
|
|
|
Mod->Conflicts.push_back(Conflict);
|
|
|
|
}
|
|
|
|
Mod->UnresolvedConflicts.clear();
|
|
|
|
return HadError;
|
|
|
|
}
|
|
|
|
|
2011-12-06 00:33:54 +08:00
|
|
|
Module *ModuleMap::inferModuleFromLocation(FullSourceLoc Loc) {
|
|
|
|
if (Loc.isInvalid())
|
2014-05-18 07:10:59 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2011-12-06 00:33:54 +08:00
|
|
|
// Use the expansion location to determine which module we're in.
|
|
|
|
FullSourceLoc ExpansionLoc = Loc.getExpansionLoc();
|
|
|
|
if (!ExpansionLoc.isFileID())
|
2014-05-18 07:10:59 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2011-12-06 00:33:54 +08:00
|
|
|
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).
|
2013-06-21 05:14:14 +08:00
|
|
|
if (Module *Mod = findModuleForHeader(ExpansionFile).getModule())
|
2012-01-07 01:19:32 +08:00
|
|
|
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())
|
2014-05-18 07:10:59 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2012-01-07 01:19:32 +08:00
|
|
|
ExpansionFileID = SrcMgr.getFileID(IncludeLoc);
|
|
|
|
}
|
2014-05-18 07:10:59 +08:00
|
|
|
|
|
|
|
return nullptr;
|
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,
|
2013-03-20 08:22:05 +08:00
|
|
|
ConfigMacros,
|
2013-03-21 05:10:35 +08:00
|
|
|
Conflict,
|
2011-11-12 03:10:28 +08:00
|
|
|
EndOfFile,
|
|
|
|
HeaderKeyword,
|
|
|
|
Identifier,
|
2013-10-29 06:18:19 +08:00
|
|
|
Exclaim,
|
2012-10-15 14:28:11 +08:00
|
|
|
ExcludeKeyword,
|
2011-11-12 03:10:28 +08:00
|
|
|
ExplicitKeyword,
|
2011-12-02 09:47:07 +08:00
|
|
|
ExportKeyword,
|
2013-09-11 15:20:44 +08:00
|
|
|
ExternKeyword,
|
2011-11-18 06:09:43 +08:00
|
|
|
FrameworkKeyword,
|
2013-01-15 01:21:00 +08:00
|
|
|
LinkKeyword,
|
2011-11-12 03:10:28 +08:00
|
|
|
ModuleKeyword,
|
2011-12-02 09:47:07 +08:00
|
|
|
Period,
|
2013-06-21 05:14:14 +08:00
|
|
|
PrivateKeyword,
|
2011-11-12 03:10:28 +08:00
|
|
|
UmbrellaKeyword,
|
2013-09-24 17:14:14 +08:00
|
|
|
UseKeyword,
|
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,
|
2014-10-23 07:50:56 +08:00
|
|
|
TextualKeyword,
|
2011-11-12 03:10:28 +08:00
|
|
|
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;
|
2014-05-18 07:10:59 +08:00
|
|
|
StringData = nullptr;
|
2011-11-12 03:10:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is(TokenKind K) const { return Kind == K; }
|
|
|
|
|
|
|
|
SourceLocation getLocation() const {
|
|
|
|
return SourceLocation::getFromRawEncoding(Location);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef getString() const {
|
|
|
|
return StringRef(StringData, StringLength);
|
|
|
|
}
|
|
|
|
};
|
2012-11-07 03:39:40 +08:00
|
|
|
|
|
|
|
/// \brief The set of attributes that can be attached to a module.
|
2012-12-21 03:22:21 +08:00
|
|
|
struct Attributes {
|
2014-03-02 13:58:18 +08:00
|
|
|
Attributes() : IsSystem(), IsExternC(), IsExhaustive() { }
|
2012-11-07 03:39:40 +08:00
|
|
|
|
|
|
|
/// \brief Whether this is a system module.
|
|
|
|
unsigned IsSystem : 1;
|
2013-03-20 08:22:05 +08:00
|
|
|
|
2014-03-02 13:58:18 +08:00
|
|
|
/// \brief Whether this is an extern "C" module.
|
|
|
|
unsigned IsExternC : 1;
|
|
|
|
|
2013-03-20 08:22:05 +08:00
|
|
|
/// \brief Whether this is an exhaustive set of configuration macros.
|
|
|
|
unsigned IsExhaustive : 1;
|
2012-11-07 03:39:40 +08:00
|
|
|
};
|
2011-11-12 03:10:28 +08:00
|
|
|
|
2012-11-07 03:39:40 +08:00
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
class ModuleMapParser {
|
|
|
|
Lexer &L;
|
|
|
|
SourceManager &SourceMgr;
|
2012-10-16 00:45:32 +08:00
|
|
|
|
|
|
|
/// \brief Default target information, used only for string literal
|
|
|
|
/// parsing.
|
|
|
|
const TargetInfo *Target;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
DiagnosticsEngine &Diags;
|
|
|
|
ModuleMap ⤅
|
2014-04-15 02:00:01 +08:00
|
|
|
|
|
|
|
/// \brief The current module map file.
|
|
|
|
const FileEntry *ModuleMapFile;
|
2011-11-12 03:10:28 +08:00
|
|
|
|
2014-12-10 11:09:48 +08:00
|
|
|
/// \brief The directory that file names in this module map file should
|
|
|
|
/// be resolved relative to.
|
2011-11-12 05:55:48 +08:00
|
|
|
const DirectoryEntry *Directory;
|
2012-02-03 02:42:48 +08:00
|
|
|
|
|
|
|
/// \brief The directory containing Clang-supplied headers.
|
|
|
|
const DirectoryEntry *BuiltinIncludeDir;
|
|
|
|
|
2013-06-22 00:28:10 +08:00
|
|
|
/// \brief Whether this module map is in a system header directory.
|
|
|
|
bool IsSystem;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
/// \brief Whether an error occurred.
|
|
|
|
bool HadError;
|
2012-10-16 00:45:32 +08:00
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
/// \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
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
typedef SmallVector<std::pair<std::string, SourceLocation>, 2> ModuleId;
|
2011-12-07 10:23:45 +08:00
|
|
|
bool parseModuleId(ModuleId &Id);
|
2011-11-12 03:10:28 +08:00
|
|
|
void parseModuleDecl();
|
2013-09-11 15:20:44 +08:00
|
|
|
void parseExternModuleDecl();
|
2011-12-31 12:05:44 +08:00
|
|
|
void parseRequiresDecl();
|
2013-06-21 05:14:14 +08:00
|
|
|
void parseHeaderDecl(clang::MMToken::TokenKind,
|
|
|
|
SourceLocation LeadingLoc);
|
2011-12-09 03:11:24 +08:00
|
|
|
void parseUmbrellaDirDecl(SourceLocation UmbrellaLoc);
|
2011-12-02 09:47:07 +08:00
|
|
|
void parseExportDecl();
|
2013-09-24 17:14:14 +08:00
|
|
|
void parseUseDecl();
|
2013-01-15 01:21:00 +08:00
|
|
|
void parseLinkDecl();
|
2013-03-20 08:22:05 +08:00
|
|
|
void parseConfigMacros();
|
2013-03-21 05:10:35 +08:00
|
|
|
void parseConflict();
|
2012-11-07 03:39:40 +08:00
|
|
|
void parseInferredModuleDecl(bool Framework, bool Explicit);
|
2012-12-21 03:22:21 +08:00
|
|
|
bool parseOptionalAttributes(Attributes &Attrs);
|
2011-12-09 10:04:43 +08:00
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
public:
|
|
|
|
explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr,
|
2012-10-16 00:45:32 +08:00
|
|
|
const TargetInfo *Target,
|
2011-11-12 03:10:28 +08:00
|
|
|
DiagnosticsEngine &Diags,
|
2011-11-12 05:55:48 +08:00
|
|
|
ModuleMap &Map,
|
2014-04-15 02:00:01 +08:00
|
|
|
const FileEntry *ModuleMapFile,
|
2012-02-03 02:42:48 +08:00
|
|
|
const DirectoryEntry *Directory,
|
2013-06-22 00:28:10 +08:00
|
|
|
const DirectoryEntry *BuiltinIncludeDir,
|
|
|
|
bool IsSystem)
|
2012-10-16 00:45:32 +08:00
|
|
|
: L(L), SourceMgr(SourceMgr), Target(Target), Diags(Diags), Map(Map),
|
2014-04-15 02:00:01 +08:00
|
|
|
ModuleMapFile(ModuleMapFile), Directory(Directory),
|
|
|
|
BuiltinIncludeDir(BuiltinIncludeDir), IsSystem(IsSystem),
|
2014-05-18 07:10:59 +08:00
|
|
|
HadError(false), ActiveModule(nullptr)
|
2011-11-12 03:10:28 +08:00
|
|
|
{
|
|
|
|
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()) {
|
2014-05-17 12:53:25 +08:00
|
|
|
case tok::raw_identifier: {
|
|
|
|
StringRef RI = LToken.getRawIdentifier();
|
|
|
|
Tok.StringData = RI.data();
|
|
|
|
Tok.StringLength = RI.size();
|
|
|
|
Tok.Kind = llvm::StringSwitch<MMToken::TokenKind>(RI)
|
2013-03-20 08:22:05 +08:00
|
|
|
.Case("config_macros", MMToken::ConfigMacros)
|
2013-03-21 05:10:35 +08:00
|
|
|
.Case("conflict", MMToken::Conflict)
|
2012-10-15 14:28:11 +08:00
|
|
|
.Case("exclude", MMToken::ExcludeKeyword)
|
2011-11-12 03:10:28 +08:00
|
|
|
.Case("explicit", MMToken::ExplicitKeyword)
|
2011-12-02 09:47:07 +08:00
|
|
|
.Case("export", MMToken::ExportKeyword)
|
2013-09-11 15:20:44 +08:00
|
|
|
.Case("extern", MMToken::ExternKeyword)
|
2011-11-18 06:09:43 +08:00
|
|
|
.Case("framework", MMToken::FrameworkKeyword)
|
2013-03-20 08:22:05 +08:00
|
|
|
.Case("header", MMToken::HeaderKeyword)
|
2013-01-15 01:21:00 +08:00
|
|
|
.Case("link", MMToken::LinkKeyword)
|
2011-11-12 03:10:28 +08:00
|
|
|
.Case("module", MMToken::ModuleKeyword)
|
2013-06-21 05:14:14 +08:00
|
|
|
.Case("private", MMToken::PrivateKeyword)
|
2011-12-31 12:05:44 +08:00
|
|
|
.Case("requires", MMToken::RequiresKeyword)
|
2014-10-23 07:50:56 +08:00
|
|
|
.Case("textual", MMToken::TextualKeyword)
|
2011-11-12 03:10:28 +08:00
|
|
|
.Case("umbrella", MMToken::UmbrellaKeyword)
|
2013-09-24 17:14:14 +08:00
|
|
|
.Case("use", MMToken::UseKeyword)
|
2011-11-12 03:10:28 +08:00
|
|
|
.Default(MMToken::Identifier);
|
|
|
|
break;
|
2014-05-17 12:53:25 +08:00
|
|
|
}
|
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;
|
|
|
|
|
2013-10-29 06:18:19 +08:00
|
|
|
case tok::exclaim:
|
|
|
|
Tok.Kind = MMToken::Exclaim;
|
|
|
|
break;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
case tok::string_literal: {
|
2012-03-06 11:21:47 +08:00
|
|
|
if (LToken.hasUDSuffix()) {
|
|
|
|
Diags.Report(LToken.getLocation(), diag::err_invalid_string_udl);
|
|
|
|
HadError = true;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
// Parse the string literal.
|
|
|
|
LangOptions LangOpts;
|
2014-06-26 12:58:39 +08:00
|
|
|
StringLiteralParser StringLiteral(LToken, SourceMgr, LangOpts, *Target);
|
2011-11-12 03:10:28 +08:00
|
|
|
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 {
|
2013-12-06 17:25:54 +08:00
|
|
|
if (Tok.is(MMToken::Identifier) || Tok.is(MMToken::StringLiteral)) {
|
2011-12-07 10:23:45 +08:00
|
|
|
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.
|
2013-03-20 08:22:05 +08:00
|
|
|
AT_system,
|
2014-03-02 13:58:18 +08:00
|
|
|
/// \brief The 'extern_c' attribute.
|
|
|
|
AT_extern_c,
|
2013-03-20 08:22:05 +08:00
|
|
|
/// \brief The 'exhaustive' attribute.
|
|
|
|
AT_exhaustive
|
2012-01-28 03:52:33 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
/// \brief Parse a module declaration.
|
|
|
|
///
|
|
|
|
/// module-declaration:
|
2013-09-11 15:20:44 +08:00
|
|
|
/// 'extern' 'module' module-id string-literal
|
2012-01-28 03:52:33 +08:00
|
|
|
/// 'explicit'[opt] 'framework'[opt] 'module' module-id attributes[opt]
|
|
|
|
/// { module-member* }
|
|
|
|
///
|
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
|
2013-01-15 01:21:00 +08:00
|
|
|
/// link-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) ||
|
2013-09-11 15:20:44 +08:00
|
|
|
Tok.is(MMToken::FrameworkKeyword) || Tok.is(MMToken::ExternKeyword));
|
|
|
|
if (Tok.is(MMToken::ExternKeyword)) {
|
|
|
|
parseExternModuleDecl();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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))
|
2012-11-07 03:39:40 +08:00
|
|
|
return parseInferredModuleDecl(Framework, 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;
|
|
|
|
}
|
2012-11-07 03:39:40 +08:00
|
|
|
|
2011-12-07 10:23:45 +08:00
|
|
|
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.
|
2014-05-18 07:10:59 +08:00
|
|
|
ActiveModule = nullptr;
|
2014-08-13 00:42:33 +08:00
|
|
|
const Module *TopLevelModule = nullptr;
|
2011-12-07 10:23:45 +08:00
|
|
|
for (unsigned I = 0, N = Id.size() - 1; I != N; ++I) {
|
|
|
|
if (Module *Next = Map.lookupModuleQualified(Id[I].first, ActiveModule)) {
|
2014-08-13 00:42:33 +08:00
|
|
|
if (I == 0)
|
|
|
|
TopLevelModule = Next;
|
2011-12-07 10:23:45 +08:00
|
|
|
ActiveModule = Next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ActiveModule) {
|
|
|
|
Diags.Report(Id[I].second, diag::err_mmap_missing_module_qualified)
|
2014-03-13 07:36:42 +08:00
|
|
|
<< Id[I].first
|
|
|
|
<< ActiveModule->getTopLevelModule()->getFullModuleName();
|
2011-12-07 10:23:45 +08:00
|
|
|
} else {
|
|
|
|
Diags.Report(Id[I].second, diag::err_mmap_expected_module_name);
|
|
|
|
}
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
2014-08-13 00:42:33 +08:00
|
|
|
|
|
|
|
if (ModuleMapFile != Map.getContainingModuleMapFile(TopLevelModule)) {
|
|
|
|
assert(ModuleMapFile != Map.getModuleMapFileForUniquing(TopLevelModule) &&
|
|
|
|
"submodule defined in same file as 'module *' that allowed its "
|
|
|
|
"top-level module");
|
|
|
|
Map.addAdditionalModuleMapFile(TopLevelModule, ModuleMapFile);
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 10:23:45 +08:00
|
|
|
|
|
|
|
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.
|
2012-12-21 03:22:21 +08:00
|
|
|
Attributes Attrs;
|
2012-11-07 03:39:40 +08:00
|
|
|
parseOptionalAttributes(Attrs);
|
2012-01-28 03:52:33 +08:00
|
|
|
|
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.
|
2014-08-09 08:57:23 +08:00
|
|
|
ActiveModule = Map.findOrCreateModule(ModuleName, ActiveModule, Framework,
|
|
|
|
Explicit).first;
|
2012-01-05 07:32:19 +08:00
|
|
|
ActiveModule->DefinitionLoc = ModuleNameLoc;
|
2013-06-22 00:28:10 +08:00
|
|
|
if (Attrs.IsSystem || IsSystem)
|
2012-01-28 03:52:33 +08:00
|
|
|
ActiveModule->IsSystem = true;
|
2014-03-02 13:58:18 +08:00
|
|
|
if (Attrs.IsExternC)
|
|
|
|
ActiveModule->IsExternC = true;
|
2014-12-02 08:08:08 +08:00
|
|
|
ActiveModule->Directory = Directory;
|
2014-03-02 13:58:18 +08:00
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
bool Done = false;
|
|
|
|
do {
|
|
|
|
switch (Tok.Kind) {
|
|
|
|
case MMToken::EndOfFile:
|
|
|
|
case MMToken::RBrace:
|
|
|
|
Done = true;
|
|
|
|
break;
|
2013-03-20 08:22:05 +08:00
|
|
|
|
|
|
|
case MMToken::ConfigMacros:
|
|
|
|
parseConfigMacros();
|
|
|
|
break;
|
|
|
|
|
2013-03-21 05:10:35 +08:00
|
|
|
case MMToken::Conflict:
|
|
|
|
parseConflict();
|
|
|
|
break;
|
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
case MMToken::ExplicitKeyword:
|
2013-09-11 15:20:44 +08:00
|
|
|
case MMToken::ExternKeyword:
|
2011-12-07 01:16:41 +08:00
|
|
|
case MMToken::FrameworkKeyword:
|
2011-11-12 03:10:28 +08:00
|
|
|
case MMToken::ModuleKeyword:
|
|
|
|
parseModuleDecl();
|
|
|
|
break;
|
2013-09-11 15:20:44 +08:00
|
|
|
|
2011-12-02 09:47:07 +08:00
|
|
|
case MMToken::ExportKeyword:
|
|
|
|
parseExportDecl();
|
|
|
|
break;
|
2013-09-24 17:14:14 +08:00
|
|
|
|
|
|
|
case MMToken::UseKeyword:
|
|
|
|
parseUseDecl();
|
|
|
|
break;
|
2011-12-02 09:47:07 +08:00
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
case MMToken::RequiresKeyword:
|
|
|
|
parseRequiresDecl();
|
|
|
|
break;
|
|
|
|
|
2014-10-25 04:23:01 +08:00
|
|
|
case MMToken::TextualKeyword:
|
|
|
|
parseHeaderDecl(MMToken::TextualKeyword, consumeToken());
|
2014-10-23 07:50:56 +08:00
|
|
|
break;
|
|
|
|
|
2011-12-09 03:11:24 +08:00
|
|
|
case MMToken::UmbrellaKeyword: {
|
|
|
|
SourceLocation UmbrellaLoc = consumeToken();
|
|
|
|
if (Tok.is(MMToken::HeaderKeyword))
|
2013-06-21 05:14:14 +08:00
|
|
|
parseHeaderDecl(MMToken::UmbrellaKeyword, UmbrellaLoc);
|
2011-12-09 03:11:24 +08:00
|
|
|
else
|
|
|
|
parseUmbrellaDirDecl(UmbrellaLoc);
|
2011-11-12 03:10:28 +08:00
|
|
|
break;
|
2011-12-09 03:11:24 +08:00
|
|
|
}
|
2014-10-25 04:23:01 +08:00
|
|
|
|
|
|
|
case MMToken::ExcludeKeyword:
|
|
|
|
parseHeaderDecl(MMToken::ExcludeKeyword, consumeToken());
|
2012-10-15 14:28:11 +08:00
|
|
|
break;
|
2014-10-25 04:23:01 +08:00
|
|
|
|
|
|
|
case MMToken::PrivateKeyword:
|
|
|
|
parseHeaderDecl(MMToken::PrivateKeyword, consumeToken());
|
2013-06-21 05:14:14 +08:00
|
|
|
break;
|
2014-10-25 04:23:01 +08:00
|
|
|
|
2011-12-09 02:00:48 +08:00
|
|
|
case MMToken::HeaderKeyword:
|
2014-10-25 04:23:01 +08:00
|
|
|
parseHeaderDecl(MMToken::HeaderKeyword, consumeToken());
|
2011-11-12 03:10:28 +08:00
|
|
|
break;
|
2013-01-15 01:21:00 +08:00
|
|
|
|
|
|
|
case MMToken::LinkKeyword:
|
|
|
|
parseLinkDecl();
|
|
|
|
break;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-15 01:57:51 +08:00
|
|
|
// If the active module is a top-level framework, and there are no link
|
|
|
|
// libraries, automatically link against the framework.
|
|
|
|
if (ActiveModule->IsFramework && !ActiveModule->isSubFramework() &&
|
|
|
|
ActiveModule->LinkLibraries.empty()) {
|
|
|
|
inferFrameworkLink(ActiveModule, Directory, SourceMgr.getFileManager());
|
|
|
|
}
|
|
|
|
|
2014-04-19 06:07:31 +08:00
|
|
|
// If the module meets all requirements but is still unavailable, mark the
|
|
|
|
// whole tree as unavailable to prevent it from building.
|
|
|
|
if (!ActiveModule->IsAvailable && !ActiveModule->IsMissingRequirement &&
|
|
|
|
ActiveModule->Parent) {
|
|
|
|
ActiveModule->getTopLevelModule()->markUnavailable();
|
|
|
|
ActiveModule->getTopLevelModule()->MissingHeaders.append(
|
|
|
|
ActiveModule->MissingHeaders.begin(), ActiveModule->MissingHeaders.end());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-09-11 15:20:44 +08:00
|
|
|
/// \brief Parse an extern module declaration.
|
|
|
|
///
|
|
|
|
/// extern module-declaration:
|
|
|
|
/// 'extern' 'module' module-id string-literal
|
|
|
|
void ModuleMapParser::parseExternModuleDecl() {
|
|
|
|
assert(Tok.is(MMToken::ExternKeyword));
|
|
|
|
consumeToken(); // 'extern' keyword
|
|
|
|
|
|
|
|
// Parse 'module' keyword.
|
|
|
|
if (!Tok.is(MMToken::ModuleKeyword)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_module);
|
|
|
|
consumeToken();
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
consumeToken(); // 'module' keyword
|
|
|
|
|
|
|
|
// Parse the module name.
|
|
|
|
ModuleId Id;
|
|
|
|
if (parseModuleId(Id)) {
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the referenced module map file name.
|
|
|
|
if (!Tok.is(MMToken::StringLiteral)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_mmap_file);
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::string FileName = Tok.getString();
|
|
|
|
consumeToken(); // filename
|
|
|
|
|
|
|
|
StringRef FileNameRef = FileName;
|
|
|
|
SmallString<128> ModuleMapFileName;
|
|
|
|
if (llvm::sys::path::is_relative(FileNameRef)) {
|
|
|
|
ModuleMapFileName += Directory->getName();
|
|
|
|
llvm::sys::path::append(ModuleMapFileName, FileName);
|
|
|
|
FileNameRef = ModuleMapFileName.str();
|
|
|
|
}
|
|
|
|
if (const FileEntry *File = SourceMgr.getFileManager().getFile(FileNameRef))
|
2014-12-10 11:09:48 +08:00
|
|
|
Map.parseModuleMapFile(
|
|
|
|
File, /*IsSystem=*/false,
|
|
|
|
Map.HeaderInfo.getHeaderSearchOpts().ModuleMapFileHomeIsCwd
|
|
|
|
? Directory
|
|
|
|
: File->getDir());
|
2013-09-11 15:20:44 +08:00
|
|
|
}
|
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
/// \brief Parse a requires declaration.
|
|
|
|
///
|
|
|
|
/// requires-declaration:
|
|
|
|
/// 'requires' feature-list
|
|
|
|
///
|
|
|
|
/// feature-list:
|
2013-10-29 06:18:19 +08:00
|
|
|
/// feature ',' feature-list
|
|
|
|
/// feature
|
|
|
|
///
|
|
|
|
/// feature:
|
|
|
|
/// '!'[opt] identifier
|
2011-12-31 12:05:44 +08:00
|
|
|
void ModuleMapParser::parseRequiresDecl() {
|
|
|
|
assert(Tok.is(MMToken::RequiresKeyword));
|
|
|
|
|
|
|
|
// Parse 'requires' keyword.
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
// Parse the feature-list.
|
|
|
|
do {
|
2013-10-29 06:18:19 +08:00
|
|
|
bool RequiredState = true;
|
|
|
|
if (Tok.is(MMToken::Exclaim)) {
|
|
|
|
RequiredState = false;
|
|
|
|
consumeToken();
|
|
|
|
}
|
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
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.
|
2013-10-29 06:18:19 +08:00
|
|
|
ActiveModule->addRequirement(Feature, RequiredState,
|
|
|
|
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.
|
2012-02-06 19:13:08 +08:00
|
|
|
static void appendSubframeworkPaths(Module *Mod,
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVectorImpl<char> &Path) {
|
2011-12-07 01:16:41 +08:00
|
|
|
// Collect the framework names from the given module to the top-level module.
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<StringRef, 2> Paths;
|
2011-12-07 01:16:41 +08:00
|
|
|
for (; Mod; Mod = Mod->Parent) {
|
|
|
|
if (Mod->IsFramework)
|
|
|
|
Paths.push_back(Mod->Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Paths.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Add Frameworks/Name.framework for each subframework.
|
2013-06-29 00:25:46 +08:00
|
|
|
for (unsigned I = Paths.size() - 1; I != 0; --I)
|
|
|
|
llvm::sys::path::append(Path, "Frameworks", Paths[I-1] + ".framework");
|
2011-12-07 01:16:41 +08:00
|
|
|
}
|
|
|
|
|
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:
|
2014-10-23 07:50:56 +08:00
|
|
|
/// 'textual'[opt] 'header' string-literal
|
2014-10-25 04:23:01 +08:00
|
|
|
/// 'private' 'textual'[opt] 'header' string-literal
|
|
|
|
/// 'exclude' 'header' string-literal
|
|
|
|
/// 'umbrella' 'header' string-literal
|
2014-10-23 07:50:56 +08:00
|
|
|
///
|
|
|
|
/// FIXME: Support 'private textual header'.
|
2013-06-21 05:14:14 +08:00
|
|
|
void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind LeadingToken,
|
|
|
|
SourceLocation LeadingLoc) {
|
2014-10-25 04:23:01 +08:00
|
|
|
// We've already consumed the first token.
|
|
|
|
ModuleMap::ModuleHeaderRole Role = ModuleMap::NormalHeader;
|
|
|
|
if (LeadingToken == MMToken::PrivateKeyword) {
|
|
|
|
Role = ModuleMap::PrivateHeader;
|
|
|
|
// 'private' may optionally be followed by 'textual'.
|
|
|
|
if (Tok.is(MMToken::TextualKeyword)) {
|
|
|
|
LeadingToken = Tok.Kind;
|
|
|
|
consumeToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (LeadingToken == MMToken::TextualKeyword)
|
|
|
|
Role = ModuleMap::ModuleHeaderRole(Role | ModuleMap::TextualHeader);
|
|
|
|
|
|
|
|
if (LeadingToken != MMToken::HeaderKeyword) {
|
|
|
|
if (!Tok.is(MMToken::HeaderKeyword)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_header)
|
|
|
|
<< (LeadingToken == MMToken::PrivateKeyword ? "private" :
|
|
|
|
LeadingToken == MMToken::ExcludeKeyword ? "exclude" :
|
|
|
|
LeadingToken == MMToken::TextualKeyword ? "textual" : "umbrella");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
consumeToken();
|
|
|
|
}
|
2011-12-09 02:00:48 +08:00
|
|
|
|
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;
|
|
|
|
}
|
2014-12-02 08:08:08 +08:00
|
|
|
Module::UnresolvedHeaderDirective Header;
|
2013-12-17 18:31:37 +08:00
|
|
|
Header.FileName = Tok.getString();
|
|
|
|
Header.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.
|
2013-06-21 05:14:14 +08:00
|
|
|
if (LeadingToken == MMToken::UmbrellaKeyword && ActiveModule->Umbrella) {
|
2013-12-17 18:31:37 +08:00
|
|
|
Diags.Report(Header.FileNameLoc, diag::err_mmap_umbrella_clash)
|
2011-12-09 03:11:24 +08:00
|
|
|
<< 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.
|
2014-05-18 07:10:59 +08:00
|
|
|
const FileEntry *File = nullptr;
|
|
|
|
const FileEntry *BuiltinFile = nullptr;
|
2014-12-02 08:08:08 +08:00
|
|
|
SmallString<128> RelativePathName;
|
2013-12-17 18:31:37 +08:00
|
|
|
if (llvm::sys::path::is_absolute(Header.FileName)) {
|
2014-12-02 08:08:08 +08:00
|
|
|
RelativePathName = Header.FileName;
|
|
|
|
File = SourceMgr.getFileManager().getFile(RelativePathName);
|
2011-12-07 10:23:45 +08:00
|
|
|
} else {
|
|
|
|
// Search for the header file within the search directory.
|
2014-12-02 08:08:08 +08:00
|
|
|
SmallString<128> FullPathName(Directory->getName());
|
|
|
|
unsigned FullPathLength = FullPathName.size();
|
2011-11-30 05:59:16 +08:00
|
|
|
|
2011-12-07 01:16:41 +08:00
|
|
|
if (ActiveModule->isPartOfFramework()) {
|
2014-12-02 08:08:08 +08:00
|
|
|
appendSubframeworkPaths(ActiveModule, RelativePathName);
|
2011-12-07 10:23:45 +08:00
|
|
|
|
|
|
|
// Check whether this file is in the public headers.
|
2014-12-02 08:08:08 +08:00
|
|
|
llvm::sys::path::append(RelativePathName, "Headers", Header.FileName);
|
|
|
|
llvm::sys::path::append(FullPathName, RelativePathName.str());
|
|
|
|
File = SourceMgr.getFileManager().getFile(FullPathName);
|
2011-12-07 10:23:45 +08:00
|
|
|
|
|
|
|
if (!File) {
|
|
|
|
// Check whether this file is in the private headers.
|
2014-12-02 08:08:08 +08:00
|
|
|
// FIXME: Should we retain the subframework paths here?
|
|
|
|
RelativePathName.clear();
|
|
|
|
FullPathName.resize(FullPathLength);
|
|
|
|
llvm::sys::path::append(RelativePathName, "PrivateHeaders",
|
|
|
|
Header.FileName);
|
|
|
|
llvm::sys::path::append(FullPathName, RelativePathName.str());
|
|
|
|
File = SourceMgr.getFileManager().getFile(FullPathName);
|
2011-12-07 10:23:45 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Lookup for normal headers.
|
2014-12-02 08:08:08 +08:00
|
|
|
llvm::sys::path::append(RelativePathName, Header.FileName);
|
|
|
|
llvm::sys::path::append(FullPathName, RelativePathName.str());
|
|
|
|
File = SourceMgr.getFileManager().getFile(FullPathName);
|
|
|
|
|
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.
|
2013-06-21 05:14:14 +08:00
|
|
|
if (ActiveModule->IsSystem && LeadingToken != MMToken::UmbrellaKeyword &&
|
|
|
|
BuiltinIncludeDir && BuiltinIncludeDir != Directory &&
|
2013-12-17 18:31:37 +08:00
|
|
|
isBuiltinHeader(Header.FileName)) {
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<128> BuiltinPathName(BuiltinIncludeDir->getName());
|
2013-12-17 18:31:37 +08:00
|
|
|
llvm::sys::path::append(BuiltinPathName, Header.FileName);
|
2012-02-03 02:42:48 +08:00
|
|
|
BuiltinFile = SourceMgr.getFileManager().getFile(BuiltinPathName);
|
2014-12-02 08:08:08 +08:00
|
|
|
|
2012-02-03 02:42:48 +08:00
|
|
|
// 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;
|
2014-12-02 08:08:08 +08:00
|
|
|
RelativePathName = BuiltinPathName;
|
2014-05-18 07:10:59 +08:00
|
|
|
BuiltinFile = nullptr;
|
2012-02-03 02:42:48 +08:00
|
|
|
}
|
|
|
|
}
|
2011-12-07 01:16:41 +08:00
|
|
|
}
|
2011-11-30 05:59:16 +08:00
|
|
|
}
|
2014-12-02 08:08:08 +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) {
|
2013-10-22 16:09:47 +08:00
|
|
|
if (LeadingToken == MMToken::UmbrellaKeyword) {
|
2011-12-09 02:00:48 +08:00
|
|
|
const DirectoryEntry *UmbrellaDir = File->getDir();
|
2012-10-15 14:28:11 +08:00
|
|
|
if (Module *UmbrellaModule = Map.UmbrellaDirs[UmbrellaDir]) {
|
2013-06-21 05:14:14 +08:00
|
|
|
Diags.Report(LeadingLoc, diag::err_mmap_umbrella_clash)
|
2012-10-15 14:28:11 +08:00
|
|
|
<< UmbrellaModule->getFullModuleName();
|
2011-12-09 02:00:48 +08:00
|
|
|
HadError = true;
|
|
|
|
} else {
|
|
|
|
// Record this umbrella header.
|
|
|
|
Map.setUmbrellaHeader(ActiveModule, File);
|
|
|
|
}
|
2014-10-23 10:01:19 +08:00
|
|
|
} else if (LeadingToken == MMToken::ExcludeKeyword) {
|
2014-12-02 10:13:09 +08:00
|
|
|
Module::Header H = {RelativePathName.str(), File};
|
|
|
|
Map.excludeHeader(ActiveModule, H);
|
2011-11-12 05:55:48 +08:00
|
|
|
} else {
|
2014-10-20 08:15:49 +08:00
|
|
|
// If there is a builtin counterpart to this file, add it now, before
|
|
|
|
// the "real" header, so we build the built-in one first when building
|
|
|
|
// the module.
|
2014-12-02 10:13:09 +08:00
|
|
|
if (BuiltinFile) {
|
2014-12-02 08:08:08 +08:00
|
|
|
// FIXME: Taking the name from the FileEntry is unstable and can give
|
|
|
|
// different results depending on how we've previously named that file
|
|
|
|
// in this build.
|
2014-12-02 10:13:09 +08:00
|
|
|
Module::Header H = { BuiltinFile->getName(), BuiltinFile };
|
|
|
|
Map.addHeader(ActiveModule, H, Role);
|
|
|
|
}
|
2014-10-20 08:15:49 +08:00
|
|
|
|
2014-10-25 04:23:01 +08:00
|
|
|
// Record this header.
|
2014-12-02 10:13:09 +08:00
|
|
|
Module::Header H = { RelativePathName.str(), File };
|
|
|
|
Map.addHeader(ActiveModule, H, Role);
|
2011-11-12 05:55:48 +08:00
|
|
|
}
|
2013-06-21 05:14:14 +08:00
|
|
|
} else if (LeadingToken != MMToken::ExcludeKeyword) {
|
2012-11-16 03:47:16 +08:00
|
|
|
// Ignore excluded header files. They're optional anyway.
|
2013-12-17 18:31:37 +08:00
|
|
|
|
|
|
|
// If we find a module that has a missing header, we mark this module as
|
|
|
|
// unavailable and store the header directive for displaying diagnostics.
|
|
|
|
Header.IsUmbrella = LeadingToken == MMToken::UmbrellaKeyword;
|
2014-04-19 06:07:31 +08:00
|
|
|
ActiveModule->markUnavailable();
|
2013-12-17 18:31:37 +08:00
|
|
|
ActiveModule->MissingHeaders.push_back(Header);
|
2011-12-09 03:11:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \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.
|
2014-05-18 07:10:59 +08:00
|
|
|
const DirectoryEntry *Dir = nullptr;
|
2011-12-09 03:11:24 +08:00
|
|
|
if (llvm::sys::path::is_absolute(DirName))
|
|
|
|
Dir = SourceMgr.getFileManager().getDirectory(DirName);
|
|
|
|
else {
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<128> PathName;
|
2011-12-09 03:11:24 +08:00
|
|
|
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 {
|
2014-10-23 07:50:56 +08:00
|
|
|
// FIXME: Support string-literal module names here.
|
2011-12-02 09:47:07 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-24 17:14:14 +08:00
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_module_id);
|
2011-12-02 09:47:07 +08:00
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
Module::UnresolvedExportDecl Unresolved = {
|
|
|
|
ExportLoc, ParsedModuleId, Wildcard
|
|
|
|
};
|
|
|
|
ActiveModule->UnresolvedExports.push_back(Unresolved);
|
|
|
|
}
|
|
|
|
|
2013-09-24 17:14:14 +08:00
|
|
|
/// \brief Parse a module uses declaration.
|
|
|
|
///
|
|
|
|
/// uses-declaration:
|
|
|
|
/// 'uses' wildcard-module-id
|
|
|
|
void ModuleMapParser::parseUseDecl() {
|
|
|
|
assert(Tok.is(MMToken::UseKeyword));
|
|
|
|
consumeToken();
|
|
|
|
// Parse the module-id.
|
|
|
|
ModuleId ParsedModuleId;
|
2013-12-06 17:25:54 +08:00
|
|
|
parseModuleId(ParsedModuleId);
|
2013-09-24 17:14:14 +08:00
|
|
|
|
|
|
|
ActiveModule->UnresolvedDirectUses.push_back(ParsedModuleId);
|
|
|
|
}
|
|
|
|
|
2013-01-15 01:21:00 +08:00
|
|
|
/// \brief Parse a link declaration.
|
|
|
|
///
|
|
|
|
/// module-declaration:
|
|
|
|
/// 'link' 'framework'[opt] string-literal
|
|
|
|
void ModuleMapParser::parseLinkDecl() {
|
|
|
|
assert(Tok.is(MMToken::LinkKeyword));
|
|
|
|
SourceLocation LinkLoc = consumeToken();
|
|
|
|
|
|
|
|
// Parse the optional 'framework' keyword.
|
|
|
|
bool IsFramework = false;
|
|
|
|
if (Tok.is(MMToken::FrameworkKeyword)) {
|
|
|
|
consumeToken();
|
|
|
|
IsFramework = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the library name
|
|
|
|
if (!Tok.is(MMToken::StringLiteral)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_library_name)
|
|
|
|
<< IsFramework << SourceRange(LinkLoc);
|
|
|
|
HadError = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LibraryName = Tok.getString();
|
|
|
|
consumeToken();
|
|
|
|
ActiveModule->LinkLibraries.push_back(Module::LinkLibrary(LibraryName,
|
|
|
|
IsFramework));
|
|
|
|
}
|
|
|
|
|
2013-03-20 08:22:05 +08:00
|
|
|
/// \brief Parse a configuration macro declaration.
|
|
|
|
///
|
|
|
|
/// module-declaration:
|
|
|
|
/// 'config_macros' attributes[opt] config-macro-list?
|
|
|
|
///
|
|
|
|
/// config-macro-list:
|
|
|
|
/// identifier (',' identifier)?
|
|
|
|
void ModuleMapParser::parseConfigMacros() {
|
|
|
|
assert(Tok.is(MMToken::ConfigMacros));
|
|
|
|
SourceLocation ConfigMacrosLoc = consumeToken();
|
|
|
|
|
|
|
|
// Only top-level modules can have configuration macros.
|
|
|
|
if (ActiveModule->Parent) {
|
|
|
|
Diags.Report(ConfigMacrosLoc, diag::err_mmap_config_macro_submodule);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the optional attributes.
|
|
|
|
Attributes Attrs;
|
|
|
|
parseOptionalAttributes(Attrs);
|
|
|
|
if (Attrs.IsExhaustive && !ActiveModule->Parent) {
|
|
|
|
ActiveModule->ConfigMacrosExhaustive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we don't have an identifier, we're done.
|
2014-10-23 07:50:56 +08:00
|
|
|
// FIXME: Support macros with the same name as a keyword here.
|
2013-03-20 08:22:05 +08:00
|
|
|
if (!Tok.is(MMToken::Identifier))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Consume the first identifier.
|
|
|
|
if (!ActiveModule->Parent) {
|
|
|
|
ActiveModule->ConfigMacros.push_back(Tok.getString().str());
|
|
|
|
}
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
do {
|
|
|
|
// If there's a comma, consume it.
|
|
|
|
if (!Tok.is(MMToken::Comma))
|
|
|
|
break;
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
// We expect to see a macro name here.
|
2014-10-23 07:50:56 +08:00
|
|
|
// FIXME: Support macros with the same name as a keyword here.
|
2013-03-20 08:22:05 +08:00
|
|
|
if (!Tok.is(MMToken::Identifier)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_config_macro);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Consume the macro name.
|
|
|
|
if (!ActiveModule->Parent) {
|
|
|
|
ActiveModule->ConfigMacros.push_back(Tok.getString().str());
|
|
|
|
}
|
|
|
|
consumeToken();
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2013-03-21 05:10:35 +08:00
|
|
|
/// \brief Format a module-id into a string.
|
|
|
|
static std::string formatModuleId(const ModuleId &Id) {
|
|
|
|
std::string result;
|
|
|
|
{
|
|
|
|
llvm::raw_string_ostream OS(result);
|
|
|
|
|
|
|
|
for (unsigned I = 0, N = Id.size(); I != N; ++I) {
|
|
|
|
if (I)
|
|
|
|
OS << ".";
|
|
|
|
OS << Id[I].first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Parse a conflict declaration.
|
|
|
|
///
|
|
|
|
/// module-declaration:
|
|
|
|
/// 'conflict' module-id ',' string-literal
|
|
|
|
void ModuleMapParser::parseConflict() {
|
|
|
|
assert(Tok.is(MMToken::Conflict));
|
|
|
|
SourceLocation ConflictLoc = consumeToken();
|
|
|
|
Module::UnresolvedConflict Conflict;
|
|
|
|
|
|
|
|
// Parse the module-id.
|
|
|
|
if (parseModuleId(Conflict.Id))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Parse the ','.
|
|
|
|
if (!Tok.is(MMToken::Comma)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_conflicts_comma)
|
|
|
|
<< SourceRange(ConflictLoc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
// Parse the message.
|
|
|
|
if (!Tok.is(MMToken::StringLiteral)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_conflicts_message)
|
|
|
|
<< formatModuleId(Conflict.Id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Conflict.Message = Tok.getString().str();
|
|
|
|
consumeToken();
|
|
|
|
|
|
|
|
// Add this unresolved conflict.
|
|
|
|
ActiveModule->UnresolvedConflicts.push_back(Conflict);
|
|
|
|
}
|
|
|
|
|
2013-01-15 01:21:00 +08:00
|
|
|
/// \brief Parse an inferred module declaration (wildcard modules).
|
2012-11-07 03:39:40 +08:00
|
|
|
///
|
|
|
|
/// module-declaration:
|
|
|
|
/// 'explicit'[opt] 'framework'[opt] 'module' * attributes[opt]
|
|
|
|
/// { inferred-module-member* }
|
|
|
|
///
|
|
|
|
/// inferred-module-member:
|
|
|
|
/// 'export' '*'
|
|
|
|
/// 'exclude' identifier
|
|
|
|
void ModuleMapParser::parseInferredModuleDecl(bool Framework, bool Explicit) {
|
2011-12-06 06:27:44 +08:00
|
|
|
assert(Tok.is(MMToken::Star));
|
|
|
|
SourceLocation StarLoc = consumeToken();
|
|
|
|
bool Failed = false;
|
2012-11-07 03:39:40 +08:00
|
|
|
|
2011-12-06 06:27:44 +08:00
|
|
|
// Inferred modules must be submodules.
|
2012-11-07 03:39:40 +08:00
|
|
|
if (!ActiveModule && !Framework) {
|
2011-12-06 06:27:44 +08:00
|
|
|
Diags.Report(StarLoc, diag::err_mmap_top_level_inferred_submodule);
|
|
|
|
Failed = true;
|
|
|
|
}
|
2012-11-07 03:39:40 +08:00
|
|
|
|
|
|
|
if (ActiveModule) {
|
|
|
|
// Inferred modules must have umbrella directories.
|
2014-04-22 03:49:57 +08:00
|
|
|
if (!Failed && ActiveModule->IsAvailable &&
|
|
|
|
!ActiveModule->getUmbrellaDir()) {
|
2012-11-07 03:39:40 +08:00
|
|
|
Diags.Report(StarLoc, diag::err_mmap_inferred_no_umbrella);
|
|
|
|
Failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for redefinition of an inferred module.
|
|
|
|
if (!Failed && ActiveModule->InferSubmodules) {
|
|
|
|
Diags.Report(StarLoc, diag::err_mmap_inferred_redef);
|
|
|
|
if (ActiveModule->InferredSubmoduleLoc.isValid())
|
|
|
|
Diags.Report(ActiveModule->InferredSubmoduleLoc,
|
|
|
|
diag::note_mmap_prev_definition);
|
|
|
|
Failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for the 'framework' keyword, which is not permitted here.
|
|
|
|
if (Framework) {
|
|
|
|
Diags.Report(StarLoc, diag::err_mmap_inferred_framework_submodule);
|
|
|
|
Framework = false;
|
|
|
|
}
|
|
|
|
} else if (Explicit) {
|
|
|
|
Diags.Report(StarLoc, diag::err_mmap_explicit_inferred_framework);
|
|
|
|
Explicit = false;
|
2011-12-06 06:27:44 +08:00
|
|
|
}
|
2012-11-07 03:39:40 +08:00
|
|
|
|
2011-12-06 06:27:44 +08:00
|
|
|
// 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;
|
|
|
|
}
|
2012-11-07 03:39:40 +08:00
|
|
|
|
|
|
|
// Parse optional attributes.
|
2012-12-21 03:22:21 +08:00
|
|
|
Attributes Attrs;
|
2012-11-07 03:39:40 +08:00
|
|
|
parseOptionalAttributes(Attrs);
|
|
|
|
|
|
|
|
if (ActiveModule) {
|
|
|
|
// Note that we have an inferred submodule.
|
|
|
|
ActiveModule->InferSubmodules = true;
|
|
|
|
ActiveModule->InferredSubmoduleLoc = StarLoc;
|
|
|
|
ActiveModule->InferExplicitSubmodules = Explicit;
|
|
|
|
} else {
|
|
|
|
// We'll be inferring framework modules for this directory.
|
|
|
|
Map.InferredDirectories[Directory].InferModules = true;
|
|
|
|
Map.InferredDirectories[Directory].InferSystemModules = Attrs.IsSystem;
|
2014-04-15 02:00:01 +08:00
|
|
|
Map.InferredDirectories[Directory].ModuleMapFile = ModuleMapFile;
|
2014-03-07 05:59:38 +08:00
|
|
|
// FIXME: Handle the 'framework' keyword.
|
2012-11-07 03:39:40 +08:00
|
|
|
}
|
|
|
|
|
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;
|
2012-11-07 03:39:40 +08:00
|
|
|
|
|
|
|
case MMToken::ExcludeKeyword: {
|
|
|
|
if (ActiveModule) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_inferred_member)
|
2014-05-18 07:10:59 +08:00
|
|
|
<< (ActiveModule != nullptr);
|
2012-11-07 03:39:40 +08:00
|
|
|
consumeToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
consumeToken();
|
2014-10-23 07:50:56 +08:00
|
|
|
// FIXME: Support string-literal module names here.
|
2012-11-07 03:39:40 +08:00
|
|
|
if (!Tok.is(MMToken::Identifier)) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_missing_exclude_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Map.InferredDirectories[Directory].ExcludedModules
|
|
|
|
.push_back(Tok.getString());
|
|
|
|
consumeToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MMToken::ExportKeyword:
|
|
|
|
if (!ActiveModule) {
|
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_inferred_member)
|
2014-05-18 07:10:59 +08:00
|
|
|
<< (ActiveModule != nullptr);
|
2012-11-07 03:39:40 +08:00
|
|
|
consumeToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-06 06:27:44 +08:00
|
|
|
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;
|
2012-11-07 03:39:40 +08:00
|
|
|
|
2011-12-06 06:27:44 +08:00
|
|
|
case MMToken::ExplicitKeyword:
|
|
|
|
case MMToken::ModuleKeyword:
|
|
|
|
case MMToken::HeaderKeyword:
|
2013-06-21 05:14:14 +08:00
|
|
|
case MMToken::PrivateKeyword:
|
2011-12-06 06:27:44 +08:00
|
|
|
case MMToken::UmbrellaKeyword:
|
|
|
|
default:
|
2012-11-07 03:39:40 +08:00
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_inferred_member)
|
2014-05-18 07:10:59 +08:00
|
|
|
<< (ActiveModule != nullptr);
|
2011-12-06 06:27:44 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-07 03:39:40 +08:00
|
|
|
/// \brief Parse optional attributes.
|
|
|
|
///
|
|
|
|
/// attributes:
|
|
|
|
/// attribute attributes
|
|
|
|
/// attribute
|
|
|
|
///
|
|
|
|
/// attribute:
|
|
|
|
/// [ identifier ]
|
|
|
|
///
|
|
|
|
/// \param Attrs Will be filled in with the parsed attributes.
|
|
|
|
///
|
|
|
|
/// \returns true if an error occurred, false otherwise.
|
2012-12-21 03:22:21 +08:00
|
|
|
bool ModuleMapParser::parseOptionalAttributes(Attributes &Attrs) {
|
2012-11-07 03:39:40 +08:00
|
|
|
bool HadError = 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();
|
|
|
|
HadError = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode the attribute name.
|
|
|
|
AttributeKind Attribute
|
|
|
|
= llvm::StringSwitch<AttributeKind>(Tok.getString())
|
2013-03-20 08:22:05 +08:00
|
|
|
.Case("exhaustive", AT_exhaustive)
|
2014-03-02 13:58:18 +08:00
|
|
|
.Case("extern_c", AT_extern_c)
|
2012-11-07 03:39:40 +08:00
|
|
|
.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:
|
|
|
|
Attrs.IsSystem = true;
|
|
|
|
break;
|
2013-03-20 08:22:05 +08:00
|
|
|
|
2014-03-02 13:58:18 +08:00
|
|
|
case AT_extern_c:
|
|
|
|
Attrs.IsExternC = true;
|
|
|
|
break;
|
|
|
|
|
2013-03-20 08:22:05 +08:00
|
|
|
case AT_exhaustive:
|
|
|
|
Attrs.IsExhaustive = true;
|
|
|
|
break;
|
2012-11-07 03:39:40 +08:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
HadError = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.is(MMToken::RSquare))
|
|
|
|
consumeToken();
|
|
|
|
}
|
|
|
|
|
|
|
|
return HadError;
|
|
|
|
}
|
|
|
|
|
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:
|
2013-09-11 15:20:44 +08:00
|
|
|
case MMToken::ExternKeyword:
|
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;
|
2013-01-15 01:21:00 +08:00
|
|
|
|
2011-12-31 12:05:44 +08:00
|
|
|
case MMToken::Comma:
|
2013-03-20 08:22:05 +08:00
|
|
|
case MMToken::ConfigMacros:
|
2013-03-21 05:10:35 +08:00
|
|
|
case MMToken::Conflict:
|
2013-10-29 06:18:19 +08:00
|
|
|
case MMToken::Exclaim:
|
2012-10-15 14:28:11 +08:00
|
|
|
case MMToken::ExcludeKeyword:
|
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:
|
2013-01-15 01:21:00 +08:00
|
|
|
case MMToken::LinkKeyword:
|
2012-01-28 03:52:33 +08:00
|
|
|
case MMToken::LSquare:
|
2011-12-02 09:47:07 +08:00
|
|
|
case MMToken::Period:
|
2013-06-21 05:14:14 +08:00
|
|
|
case MMToken::PrivateKeyword:
|
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:
|
2014-10-23 09:03:45 +08:00
|
|
|
case MMToken::TextualKeyword:
|
2011-11-12 03:10:28 +08:00
|
|
|
case MMToken::UmbrellaKeyword:
|
2013-09-24 17:14:14 +08:00
|
|
|
case MMToken::UseKeyword:
|
2011-11-12 03:10:28 +08:00
|
|
|
Diags.Report(Tok.getLocation(), diag::err_mmap_expected_module);
|
|
|
|
HadError = true;
|
|
|
|
consumeToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2014-12-10 11:09:48 +08:00
|
|
|
bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
|
|
|
|
const DirectoryEntry *Dir) {
|
2013-01-10 09:43:00 +08:00
|
|
|
llvm::DenseMap<const FileEntry *, bool>::iterator Known
|
|
|
|
= ParsedModuleMap.find(File);
|
|
|
|
if (Known != ParsedModuleMap.end())
|
|
|
|
return Known->second;
|
|
|
|
|
2014-05-18 07:10:59 +08:00
|
|
|
assert(Target && "Missing target information");
|
2014-03-07 14:40:32 +08:00
|
|
|
auto FileCharacter = IsSystem ? SrcMgr::C_System : SrcMgr::C_User;
|
|
|
|
FileID ID = SourceMgr.createFileID(File, SourceLocation(), FileCharacter);
|
Use the same SourceManager for ModuleMaps and compilations.
This allows using virtual file mappings on the original SourceManager to
map in virtual module.map files. Without this patch, the ModuleMap
search will find a module.map file (as the FileEntry exists in the
FileManager), but will be unable to get the content from the
SourceManager (as ModuleMap previously created its own SourceManager).
Two problems needed to be fixed which this patch exposed:
1. Storing the inferred module map
When writing out a module, the ASTWriter stores the names of the files
in the main source manager; when loading the AST again, the ASTReader
errs out if such a file is found missing, unless it is overridden.
Previously CompilerInstance's compileModule method would store the
inferred module map to a temporary file; the problem with this approach
is that now that the module map is handled by the main source manager,
the ASTWriter stores the name of the temporary module map as source to
the compilation; later, when the module is loaded, the temporary file
has already been deleted, which leads to a compilation error. This patch
changes the inferred module map to instead inject a virtual file into
the source manager. This both saves some disk IO, and works with how the
ASTWriter/ASTReader handle overridden source files.
2. Changing test input in test/Modules/Inputs/*
Now that the module map file is handled by the main source manager, the
VerifyDiagnosticConsumer will not ignore diagnostics created while
parsing the module map file. The module test test/Modules/renamed.m uses
-I test/Modules/Inputs and triggers recursive loading of all module maps
in test/Modules/Inputs, some of which had conflicting names, thus
leading errors while parsing the module maps. Those diagnostics already
occur on trunk, but before this patch they would not break the test, as
they were ignored by the VerifyDiagnosticConsumer. This patch thus
changes the module maps that have been recently introduced which broke
the invariant of compatible modules maps in test/Modules/Inputs.
llvm-svn: 193314
2013-10-24 15:51:24 +08:00
|
|
|
const llvm::MemoryBuffer *Buffer = SourceMgr.getBuffer(ID);
|
2011-11-12 03:10:28 +08:00
|
|
|
if (!Buffer)
|
2013-01-10 09:43:00 +08:00
|
|
|
return ParsedModuleMap[File] = true;
|
2014-03-20 04:23:34 +08:00
|
|
|
|
2011-11-12 03:10:28 +08:00
|
|
|
// Parse this module map file.
|
Use the same SourceManager for ModuleMaps and compilations.
This allows using virtual file mappings on the original SourceManager to
map in virtual module.map files. Without this patch, the ModuleMap
search will find a module.map file (as the FileEntry exists in the
FileManager), but will be unable to get the content from the
SourceManager (as ModuleMap previously created its own SourceManager).
Two problems needed to be fixed which this patch exposed:
1. Storing the inferred module map
When writing out a module, the ASTWriter stores the names of the files
in the main source manager; when loading the AST again, the ASTReader
errs out if such a file is found missing, unless it is overridden.
Previously CompilerInstance's compileModule method would store the
inferred module map to a temporary file; the problem with this approach
is that now that the module map is handled by the main source manager,
the ASTWriter stores the name of the temporary module map as source to
the compilation; later, when the module is loaded, the temporary file
has already been deleted, which leads to a compilation error. This patch
changes the inferred module map to instead inject a virtual file into
the source manager. This both saves some disk IO, and works with how the
ASTWriter/ASTReader handle overridden source files.
2. Changing test input in test/Modules/Inputs/*
Now that the module map file is handled by the main source manager, the
VerifyDiagnosticConsumer will not ignore diagnostics created while
parsing the module map file. The module test test/Modules/renamed.m uses
-I test/Modules/Inputs and triggers recursive loading of all module maps
in test/Modules/Inputs, some of which had conflicting names, thus
leading errors while parsing the module maps. Those diagnostics already
occur on trunk, but before this patch they would not break the test, as
they were ignored by the VerifyDiagnosticConsumer. This patch thus
changes the module maps that have been recently introduced which broke
the invariant of compatible modules maps in test/Modules/Inputs.
llvm-svn: 193314
2013-10-24 15:51:24 +08:00
|
|
|
Lexer L(ID, SourceMgr.getBuffer(ID), SourceMgr, MMapLangOpts);
|
2014-04-15 02:00:01 +08:00
|
|
|
ModuleMapParser Parser(L, SourceMgr, Target, Diags, *this, File, Dir,
|
2013-06-22 00:28:10 +08:00
|
|
|
BuiltinIncludeDir, IsSystem);
|
2011-11-12 03:10:28 +08:00
|
|
|
bool Result = Parser.parseModuleMapFile();
|
2013-01-10 09:43:00 +08:00
|
|
|
ParsedModuleMap[File] = Result;
|
2011-11-12 03:10:28 +08:00
|
|
|
return Result;
|
|
|
|
}
|