diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-11-30 23:21:26 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-11-30 23:21:26 +0000 |
commit | 1a4761edca58c6b559de825b9abfb66f7f1ba94a (patch) | |
tree | bd17d1a3341870f9378db26a09045b3bb2db8426 /lib/Basic | |
parent | 8d39c3ddfc17d9e768a17eb0ce9f11c33bf9d50a (diff) |
Promote ModuleMap::Module to a namespace-scope class in the Basic
library, since modules cut across all of the libraries. Rename
serialization::Module to serialization::ModuleFile to side-step the
annoying naming conflict. Prune a bunch of ModuleMap.h includes that
are no longer needed (most files only needed the Module type).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145538 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic')
-rw-r--r-- | lib/Basic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/Basic/Module.cpp | 91 |
2 files changed, 92 insertions, 0 deletions
diff --git a/lib/Basic/CMakeLists.txt b/lib/Basic/CMakeLists.txt index ff348896e3..fe16ee99ab 100644 --- a/lib/Basic/CMakeLists.txt +++ b/lib/Basic/CMakeLists.txt @@ -9,6 +9,7 @@ add_clang_library(clangBasic FileSystemStatCache.cpp IdentifierTable.cpp LangOptions.cpp + Module.cpp SourceLocation.cpp SourceManager.cpp TargetInfo.cpp diff --git a/lib/Basic/Module.cpp b/lib/Basic/Module.cpp new file mode 100644 index 0000000000..04f9befd1a --- /dev/null +++ b/lib/Basic/Module.cpp @@ -0,0 +1,91 @@ +//===--- Module.h - Describe a module ---------------------------*- 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 Module class, which describes a module in the source +// code. +// +//===----------------------------------------------------------------------===// +#include "clang/Basic/Module.h" +#include "clang/Basic/FileManager.h" +#include "llvm/Support/raw_ostream.h" +using namespace clang; + +Module::~Module() { + for (llvm::StringMap<Module *>::iterator I = SubModules.begin(), + IEnd = SubModules.end(); + I != IEnd; ++I) { + delete I->getValue(); + } + +} + +std::string Module::getFullModuleName() const { + llvm::SmallVector<StringRef, 2> Names; + + // Build up the set of module names (from innermost to outermost). + for (const Module *M = this; M; M = M->Parent) + Names.push_back(M->Name); + + std::string Result; + for (llvm::SmallVector<StringRef, 2>::reverse_iterator I = Names.rbegin(), + IEnd = Names.rend(); + I != IEnd; ++I) { + if (!Result.empty()) + Result += '.'; + + Result += *I; + } + + return Result; +} + +StringRef Module::getTopLevelModuleName() const { + const Module *Top = this; + while (Top->Parent) + Top = Top->Parent; + + return Top->Name; +} + +void Module::print(llvm::raw_ostream &OS, unsigned Indent) const { + OS.indent(Indent); + if (IsFramework) + OS << "framework "; + if (IsExplicit) + OS << "explicit "; + OS << "module " << Name << " {\n"; + + if (UmbrellaHeader) { + OS.indent(Indent + 2); + OS << "umbrella \""; + OS.write_escaped(UmbrellaHeader->getName()); + OS << "\"\n"; + } + + for (unsigned I = 0, N = Headers.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "header \""; + OS.write_escaped(Headers[I]->getName()); + OS << "\"\n"; + } + + for (llvm::StringMap<Module *>::const_iterator MI = SubModules.begin(), + MIEnd = SubModules.end(); + MI != MIEnd; ++MI) + MI->getValue()->print(OS, Indent + 2); + + OS.indent(Indent); + OS << "}\n"; +} + +void Module::dump() const { + print(llvm::errs()); +} + + |