//===--- ModuleMap.cpp - Describe the layout of modules ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the ModuleMap implementation, which describes the layout
// of a module as it relates to headers.
//
//===----------------------------------------------------------------------===//
#include "clang/Lex/ModuleMap.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/LiteralSupport.h"
#include "clang/Lex/LexDiagnostic.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/PathV2.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
using namespace clang;
Module::ExportDecl
ModuleMap::resolveExport(Module *Mod,
const Module::UnresolvedExportDecl &Unresolved,
bool Complain) {
// We may have just a wildcard.
if (Unresolved.Id.empty()) {
assert(Unresolved.Wildcard && "Invalid unresolved export");
return Module::ExportDecl(0, true);
}
// Find the starting module.
Module *Context = lookupModuleUnqualified(Unresolved.Id[0].first, Mod);
if (!Context) {
if (Complain)
Diags->Report(Unresolved.Id[0].second,
diag::err_mmap_missing_module_unqualified)
<< Unresolved.Id[0].first << Mod->getFullModuleName();
return Module::ExportDecl();
}
// Dig into the module path.
for (unsigned I = 1, N = Unresolved.Id.size(); I != N; ++I) {
Module *Sub = lookupModuleQualified(Unresolved.Id[I].first,
Context);
if (!Sub) {
if (Complain)
Diags->Report(Unresolved.Id[I].second,
diag::err_mmap_missing_module_qualified)
<< Unresolved.Id[I].first << Context->getFullModuleName()
<< SourceRange(Unresolved.Id[0].second, Unresolved.Id[I-1].second);
return Module::ExportDecl();
}
Context = Sub;
}
return Module::ExportDecl(Context, Unresolved.Wildcard);
}
ModuleMap::ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC,
const LangOptions &LangOpts)
: LangOpts(LangOpts)
{
llvm::IntrusiveRefCntPtr<DiagnosticIDs>