[cfe-commits] r145411 - in /cfe/trunk: include/clang/Lex/ModuleMap.h lib/Lex/ModuleMap.cpp

Douglas Gregor dgregor at apple.com
Tue Nov 29 10:17:59 PST 2011


Author: dgregor
Date: Tue Nov 29 12:17:59 2011
New Revision: 145411

URL: http://llvm.org/viewvc/llvm-project?rev=145411&view=rev
Log:
Expose the printing of module maps as part of the ModuleMap::Module
interface. No functionality change.

Modified:
    cfe/trunk/include/clang/Lex/ModuleMap.h
    cfe/trunk/lib/Lex/ModuleMap.cpp

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=145411&r1=145410&r2=145411&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Tue Nov 29 12:17:59 2011
@@ -94,13 +94,20 @@
       return false;
     }
     
-    
     /// \brief Retrieve the full name of this module, including the path from
     /// its top-level module.
     std::string getFullModuleName() const;
     
     /// \brief Retrieve the name of the top-level module.
+    ///
     StringRef getTopLevelModuleName() const;
+    
+    /// \brief Print the module map for this module to the given stream. 
+    ///
+    void print(llvm::raw_ostream &OS, unsigned Indent = 0) const;
+    
+    /// \brief Dump the contents of this module to the given output stream.
+    void dump() const;
   };
   
 private:

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=145411&r1=145410&r2=145411&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Tue Nov 29 12:17:59 2011
@@ -68,6 +68,41 @@
   return Top->Name;
 }
 
+static void indent(llvm::raw_ostream &OS, unsigned Spaces) {
+  OS << std::string(' ', Spaces);
+}
+
+void ModuleMap::Module::print(llvm::raw_ostream &OS, unsigned Indent) const {
+  indent(OS, Indent);
+  if (IsFramework)
+    OS << "framework ";
+  if (IsExplicit)
+    OS << "explicit ";
+  OS << Name << " {\n";
+  
+  if (UmbrellaHeader) {
+    indent(OS, Indent + 2);
+    OS << "umbrella \"" << UmbrellaHeader->getName() << "\"\n";
+  }
+  
+  for (unsigned I = 0, N = Headers.size(); I != N; ++I) {
+    indent(OS, Indent + 2);
+    OS << "header \"" << Headers[I]->getName() << "\"\n";
+  }
+  
+  for (llvm::StringMap<Module *>::const_iterator MI = SubModules.begin(), 
+                                              MIEnd = SubModules.end();
+       MI != MIEnd; ++MI)
+    MI->getValue()->print(OS, Indent + 2);
+  
+  indent(OS, Indent);
+  OS << "}\n";
+}
+
+void ModuleMap::Module::dump() const {
+  print(llvm::errs());
+}
+
 //----------------------------------------------------------------------------//
 // Module map
 //----------------------------------------------------------------------------//
@@ -171,45 +206,12 @@
   return Result;
 }
 
-static void indent(llvm::raw_ostream &OS, unsigned Spaces) {
-  OS << std::string(' ', Spaces);
-}
-
-static void dumpModule(llvm::raw_ostream &OS, ModuleMap::Module *M, 
-                       unsigned Indent) {
-  indent(OS, Indent);
-  if (M->IsFramework)
-    OS << "framework ";
-  if (M->IsExplicit)
-    OS << "explicit ";
-  OS << M->Name << " {\n";
-  
-  if (M->UmbrellaHeader) {
-    indent(OS, Indent + 2);
-    OS << "umbrella \"" << M->UmbrellaHeader->getName() << "\"\n";
-  }
-  
-  for (unsigned I = 0, N = M->Headers.size(); I != N; ++I) {
-    indent(OS, Indent + 2);
-    OS << "header \"" << M->Headers[I]->getName() << "\"\n";
-  }
-  
-  for (llvm::StringMap<ModuleMap::Module *>::iterator 
-            MI = M->SubModules.begin(), 
-         MIEnd = M->SubModules.end();
-       MI != MIEnd; ++MI)
-    dumpModule(llvm::errs(), MI->getValue(), Indent + 2);
-  
-  indent(OS, Indent);
-  OS << "}\n";
-}
-
 void ModuleMap::dump() {
   llvm::errs() << "Modules:";
   for (llvm::StringMap<Module *>::iterator M = Modules.begin(), 
                                         MEnd = Modules.end(); 
        M != MEnd; ++M)
-    dumpModule(llvm::errs(), M->getValue(), 2);
+    M->getValue()->print(llvm::errs(), 2);
   
   llvm::errs() << "Headers:";
   for (llvm::DenseMap<const FileEntry *, Module *>::iterator 





More information about the cfe-commits mailing list