[clang-tools-extra] r264001 - Fixed some cases in the modularize assistant mode where header file names didn't translate to valid module names.
John Thompson via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 21 16:05:15 PDT 2016
Author: jtsoftware
Date: Mon Mar 21 18:05:14 2016
New Revision: 264001
URL: http://llvm.org/viewvc/llvm-project?rev=264001&view=rev
Log:
Fixed some cases in the modularize assistant mode where header file names didn't translate to valid module names.
Modified:
clang-tools-extra/trunk/modularize/ModuleAssistant.cpp
clang-tools-extra/trunk/test/modularize/NoProblemsAssistant.modularize
Modified: clang-tools-extra/trunk/modularize/ModuleAssistant.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/ModuleAssistant.cpp?rev=264001&r1=264000&r2=264001&view=diff
==============================================================================
--- clang-tools-extra/trunk/modularize/ModuleAssistant.cpp (original)
+++ clang-tools-extra/trunk/modularize/ModuleAssistant.cpp Mon Mar 21 18:05:14 2016
@@ -99,7 +99,7 @@ bool Module::output(llvm::raw_fd_ostream
E = HeaderFileNames.end();
I != E; ++I) {
OS.indent(Indent);
- if (IsProblem)
+ if (IsProblem || strstr((*I).c_str(), ".inl"))
OS << "exclude header \"" << *I << "\"\n";
else
OS << "header \"" << *I << "\"\n";
@@ -157,6 +157,18 @@ ensureNoCollisionWithReservedName(llvm::
return SafeName;
}
+// Convert module name to a non-keyword.
+// Prepends a '_' to the name if and only if the name is a keyword.
+static std::string
+ensureVaidModuleName(llvm::StringRef MightBeInvalidName) {
+ std::string SafeName = MightBeInvalidName;
+ std::replace(SafeName.begin(), SafeName.end(), '-', '_');
+ std::replace(SafeName.begin(), SafeName.end(), '.', '_');
+ if (isdigit(SafeName[0]))
+ SafeName = "_" + SafeName;
+ return SafeName;
+}
+
// Add one module, given a header file path.
static bool addModuleDescription(Module *RootModule,
llvm::StringRef HeaderFilePath,
@@ -195,6 +207,7 @@ static bool addModuleDescription(Module
continue;
std::string Stem = llvm::sys::path::stem(*I);
Stem = ensureNoCollisionWithReservedName(Stem);
+ Stem = ensureVaidModuleName(Stem);
Module *SubModule = CurrentModule->findSubModule(Stem);
if (!SubModule) {
SubModule = new Module(Stem, IsProblemFile);
Modified: clang-tools-extra/trunk/test/modularize/NoProblemsAssistant.modularize
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/modularize/NoProblemsAssistant.modularize?rev=264001&r1=264000&r2=264001&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/modularize/NoProblemsAssistant.modularize (original)
+++ clang-tools-extra/trunk/test/modularize/NoProblemsAssistant.modularize Mon Mar 21 18:05:14 2016
@@ -7,6 +7,7 @@ SubModule1/Header1.h
SubModule1/Header2.h
SubModule2/Header3.h
SubModule2/Header4.h
+SubModule2/Header5-dash.dot.h
SubModule2.h
# CHECK: // Output/NoProblemsAssistant.txt
@@ -39,6 +40,10 @@ SubModule2.h
# CHECK-NEXT: header "SubModule2/Header4.h"
# CHECK-NEXT: export *
# CHECK-NEXT: }
+# CHECK-NEXT: module Header5_dash_dot {
+# CHECK-NEXT: header "SubModule2/Header5-dash.dot.h"
+# CHECK-NEXT: export *
+# CHECK-NEXT: }
# CHECK-NEXT: header "SubModule2.h"
# CHECK-NEXT: export *
# CHECK-NEXT: }
More information about the cfe-commits
mailing list