<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.hoenzb
{mso-style-name:hoenzb;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Manuel,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Thanks for the feedback.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Are these the sort of comments you had in mind?:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Index: modularize/Modularize.cpp<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">===================================================================<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--- modularize/Modularize.cpp (revision 176883)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+++ modularize/Modularize.cpp (working copy)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">@@ -34,6 +34,29 @@<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">// note: '(symbol)' in (file) at (row):(column) not always provided<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// Future directions:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// Basically, we want to add new checks for whatever we can check with respect<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// checking headers for module'ability.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// Some ideas:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// 1. Group duplicate definition messages into a single list.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// 2. Try to figure out the preprocessor conditional directives that<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// contribute to problems.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// 3. Check for correct and consistent usage of extern "C" {} and other<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// directives. Warn about #include inside extern "C" {}.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// 4. What else?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// General clean-up and refactoring:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// 1. (From Manuel Klimek:) The Location class seems to be something that we might<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// want to design to be applicable to a wider range of tools, and stick it<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// somewhere into Tooling/ in mainline<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">//===----------------------------------------------------------------------===//<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">#include "llvm/Config/config.h"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">@@ -58,6 +81,9 @@<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">using namespace clang;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">using llvm::StringRef;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// FIXME: The Location class seems to be something that we might<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// want to design to be applicable to a wider range of tools, and stick it<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+// somewhere into Tooling/ in mainline<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">struct Location {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> const FileEntry *File;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> unsigned Line, Column;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">@@ -346,8 +372,9 @@<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> EntityMap Entities;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> ClangTool Tool(*Compilations, Headers);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> int HadErrors = Tool.run(new ModularizeFrontendActionFactory(Entities));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">-<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> // Check for the same entity being defined in multiple places.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+ // FIXME: Could they be grouped into a list?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> for (EntityMap::iterator E = Entities.begin(), EEnd = Entities.end();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> E != EEnd; ++E) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> Location Tag, Value, Macro;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">@@ -375,6 +402,8 @@<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> // Complain about any headers that have contents that differ based on how<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> // they are included.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+ // FIXME: Could we provide information about which preprocessor conditionals<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">+ // are involved?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> for (llvm::DenseMap<const FileEntry *, HeaderContents>::iterator<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> H = Entities.HeaderContentMismatches.begin(),<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> HEnd = Entities.HeaderContentMismatches.end();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">-John<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> cfe-commits-bounces@cs.uiuc.edu [mailto:cfe-commits-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>Manuel Klimek<br>
<b>Sent:</b> Wednesday, March 13, 2013 11:31 AM<br>
<b>To:</b> John Thompson<br>
<b>Cc:</b> cfe-commits@cs.uiuc.edu<br>
<b>Subject:</b> Re: [clang-tools-extra] r176847 - Initial check in of Doug's modularize tool for checking header readiness for modules, plus some changes per review feedback: Removed system headers, changed to use stream output, added file name in message.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Wed, Mar 13, 2013 at 11:19 AM, John Thompson <<a href="mailto:john.thompson.jtsoftware@gmail.com" target="_blank">john.thompson.jtsoftware@gmail.com</a>> wrote:<o:p></o:p></p>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">Manuel,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Did I check in too soon?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">My thinking is that it would be better to make incremental changes to the code (originating from Doug Gregor with permission) with respect to the review comments. Since it's a new tool and not part of the main clang tree, as long as it
builds and runs okay it should be okay to iteratively get it in shape, right?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Otherwise please accept my apologies, as I've been away from Clang development for a while.<o:p></o:p></p>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">In general the idea is to wait for a "looks good", especially when checking in new things.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I'm all for unblocking iterations in-tree (I'm more in favor of that than others in the community), so feel free to loop me in directly if you have something new for clang-extra that you'd like to get unblocked on.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">In this particular case, I'd appreciate it if we could add comments about the direction we'd want to take it to the top of the file / to the classes. I worry that since this is pretty well known people will look at it to copy from :)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">For example, the Location class seems to be something that we might want to design to be applicable to a wider range of tools, and stick it somewhere into Tooling/ in mainline, and I think a comment indicating that would be nice...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">/Manuel<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">-John<o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">On Wed, Mar 13, 2013 at 10:42 AM, Manuel Klimek <<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>> wrote:<o:p></o:p></p>
<div>
<p class="MsoNormal">The review thread I found didn't contain a "looks good"; did I miss that?<o:p></o:p></p>
<div>
<p class="MsoNormal">I'd at least want this to be full of FIXMEs and comments explaining the direction we want to take this to.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Mon, Mar 11, 2013 at 7:07 PM, John Thompson <<a href="mailto:John.Thompson.JTSoftware@gmail.com" target="_blank">John.Thompson.JTSoftware@gmail.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Author: jtsoftware<br>
Date: Mon Mar 11 21:07:30 2013<br>
New Revision: 176847<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=176847&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=176847&view=rev</a><br>
Log:<br>
Initial check in of Doug's modularize tool for checking header readiness for modules, plus some changes per review feedback: Removed system headers, changed to use stream output, added file name in message.<br>
<br>
Added:<br>
clang-tools-extra/trunk/modularize/<br>
clang-tools-extra/trunk/modularize/CMakeLists.txt<br>
clang-tools-extra/trunk/modularize/Makefile<br>
clang-tools-extra/trunk/modularize/Modularize.cpp<br>
Modified:<br>
clang-tools-extra/trunk/CMakeLists.txt<br>
clang-tools-extra/trunk/Makefile<br>
<br>
Modified: clang-tools-extra/trunk/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=176847&r1=176846&r2=176847&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=176847&r1=176846&r2=176847&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/CMakeLists.txt (original)<br>
+++ clang-tools-extra/trunk/CMakeLists.txt Mon Mar 11 21:07:30 2013<br>
@@ -2,6 +2,7 @@ add_subdirectory(remove-cstr-calls)<br>
add_subdirectory(tool-template)<br>
add_subdirectory(clang-format)<br>
add_subdirectory(cpp11-migrate)<br>
+add_subdirectory(modularize)<br>
<br>
# Add the common testsuite after all the tools.<br>
add_subdirectory(test)<br>
<br>
Modified: clang-tools-extra/trunk/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/Makefile?rev=176847&r1=176846&r2=176847&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/Makefile?rev=176847&r1=176846&r2=176847&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/Makefile (original)<br>
+++ clang-tools-extra/trunk/Makefile Mon Mar 11 21:07:30 2013<br>
@@ -11,7 +11,7 @@ CLANG_LEVEL := ../..<br>
<br>
include $(CLANG_LEVEL)/../../Makefile.config<br>
<br>
-PARALLEL_DIRS := remove-cstr-calls tool-template clang-format cpp11-migrate<br>
+PARALLEL_DIRS := remove-cstr-calls tool-template clang-format cpp11-migrate modularize<br>
<br>
include $(CLANG_LEVEL)/Makefile<br>
<br>
<br>
Added: clang-tools-extra/trunk/modularize/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/CMakeLists.txt?rev=176847&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/CMakeLists.txt?rev=176847&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/modularize/CMakeLists.txt (added)<br>
+++ clang-tools-extra/trunk/modularize/CMakeLists.txt Mon Mar 11 21:07:30 2013<br>
@@ -0,0 +1,16 @@<br>
+set(LLVM_LINK_COMPONENTS<br>
+ ${LLVM_TARGETS_TO_BUILD}<br>
+ asmparser<br>
+ support<br>
+ mc<br>
+ )<br>
+<br>
+add_clang_executable(modularize<br>
+ Modularize.cpp<br>
+ )<br>
+<br>
+target_link_libraries(modularize<br>
+ clangTooling<br>
+ clangBasic<br>
+ clangRewriteFrontend<br>
+ )<br>
<br>
Added: clang-tools-extra/trunk/modularize/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Makefile?rev=176847&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Makefile?rev=176847&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/modularize/Makefile (added)<br>
+++ clang-tools-extra/trunk/modularize/Makefile Mon Mar 11 21:07:30 2013<br>
@@ -0,0 +1,24 @@<br>
+##===- tools/modularize/Makefile ---------------------------*- Makefile -*-===##<br>
+#<br>
+# The LLVM Compiler Infrastructure<br>
+#<br>
+# This file is distributed under the University of Illinois Open Source<br>
+# License. See LICENSE.TXT for details.<br>
+#<br>
+##===----------------------------------------------------------------------===##<br>
+<br>
+CLANG_LEVEL := ../../..<br>
+<br>
+TOOLNAME = modularize<br>
+NO_INSTALL = 0<br>
+<br>
+# No plugins, optimize startup time.<br>
+TOOL_NO_EXPORTS = 1<br>
+<br>
+LINK_COMPONENTS := mcparser bitreader support mc<br>
+USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a \<br>
+ clangTooling.a clangParse.a clangSema.a clangAnalysis.a \<br>
+ clangEdit.a clangAST.a clangLex.a clangBasic.a<br>
+<br>
+include $(CLANG_LEVEL)/Makefile<br>
+<br>
<br>
Added: clang-tools-extra/trunk/modularize/Modularize.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Modularize.cpp?rev=176847&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Modularize.cpp?rev=176847&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/modularize/Modularize.cpp (added)<br>
+++ clang-tools-extra/trunk/modularize/Modularize.cpp Mon Mar 11 21:07:30 2013<br>
@@ -0,0 +1,400 @@<br>
+//===- tools/clang/Modularize.cpp - Check modularized headers -------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file implements a tool that checks whether a set of headers provides<br>
+// the consistent definitions required to use modules. For example, it detects<br>
+// whether the same entity (say, a NULL macro or size_t typedef) is defined in<br>
+// multiple headers or whether a header produces different definitions under<br>
+// different circumstances. These conditions cause modules built from the<br>
+// headers to behave poorly, and should be fixed before introducing a module<br>
+// map.<br>
+//<br>
+// Modularize takes as argument a file name for a file containing the<br>
+// newline-separated list of headers to check with respect to each other.<br>
+// Modularize also accepts regular front-end arguments.<br>
+//<br>
+// Usage: modularize (include-files_list) [(front-end-options) ...]<br>
+//<br>
+// Modularize will do normal parsing, reporting normal errors and warnings,<br>
+// but will also report special error messages like the following:<br>
+//<br>
+// error: '(symbol)' defined at both (file):(row):(column) and<br>
+// (file):(row):(column)<br>
+//<br>
+// error: header '(file)' has different contents dependening on how it was<br>
+// included<br>
+//<br>
+// The latter might be followed by messages like the following:<br>
+//<br>
+// note: '(symbol)' in (file) at (row):(column) not always provided<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/Config/config.h"<br>
+#include "llvm/Support/FileSystem.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include "clang/Basic/SourceManager.h"<br>
+#include "clang/Lex/Preprocessor.h"<br>
+#include "clang/AST/ASTConsumer.h"<br>
+#include "clang/AST/ASTContext.h"<br>
+#include "clang/AST/RecursiveASTVisitor.h"<br>
+#include "clang/Frontend/CompilerInstance.h"<br>
+#include "clang/Frontend/FrontendActions.h"<br>
+#include "clang/Tooling/CompilationDatabase.h"<br>
+#include "clang/Tooling/Tooling.h"<br>
+#include <vector><br>
+#include <string><br>
+#include <fstream><br>
+#include <algorithm><br>
+#include <iterator><br>
+<br>
+using namespace clang::tooling;<br>
+using namespace clang;<br>
+using llvm::StringRef;<br>
+<br>
+struct Location {<br>
+ const FileEntry *File;<br>
+ unsigned Line, Column;<br>
+<br>
+ Location() : File(), Line(), Column() { }<br>
+<br>
+ Location(SourceManager &SM, SourceLocation Loc) : File(), Line(), Column() {<br>
+ Loc = SM.getExpansionLoc(Loc);<br>
+ if (Loc.isInvalid())<br>
+ return;<br>
+<br>
+ std::pair<FileID, unsigned> Decomposed = SM.getDecomposedLoc(Loc);<br>
+ File = SM.getFileEntryForID(Decomposed.first);<br>
+ if (!File)<br>
+ return;<br>
+<br>
+ Line = SM.getLineNumber(Decomposed.first, Decomposed.second);<br>
+ Column = SM.getColumnNumber(Decomposed.first, Decomposed.second);<br>
+ }<br>
+<br>
+ operator bool() const { return File != 0; }<br>
+<br>
+ friend bool operator==(const Location &X, const Location &Y) {<br>
+ return X.File == Y.File && X.Line == Y.Line && X.Column == Y.Column;<br>
+ }<br>
+<br>
+ friend bool operator!=(const Location &X, const Location &Y) {<br>
+ return !(X == Y);<br>
+ }<br>
+<br>
+ friend bool operator<(const Location &X, const Location &Y) {<br>
+ if (X.File != Y.File)<br>
+ return X.File < Y.File;<br>
+ if (X.Line != Y.Line)<br>
+ return X.Line < Y.Line;<br>
+ return X.Column < Y.Column;<br>
+ }<br>
+ friend bool operator>(const Location &X, const Location &Y) {<br>
+ return Y < X;<br>
+ }<br>
+ friend bool operator<=(const Location &X, const Location &Y) {<br>
+ return !(Y < X);<br>
+ }<br>
+ friend bool operator>=(const Location &X, const Location &Y) {<br>
+ return !(X < Y);<br>
+ }<br>
+<br>
+};<br>
+<br>
+<br>
+struct Entry {<br>
+ enum Kind {<br>
+ Tag,<br>
+ Value,<br>
+ Macro<br>
+ } Kind;<br>
+<br>
+ Location Loc;<br>
+};<br>
+<br>
+struct HeaderEntry {<br>
+ std::string Name;<br>
+ Location Loc;<br>
+<br>
+ friend bool operator==(const HeaderEntry &X, const HeaderEntry &Y) {<br>
+ return X.Loc == Y.Loc && X.Name == Y.Name;<br>
+ }<br>
+ friend bool operator!=(const HeaderEntry &X, const HeaderEntry &Y) {<br>
+ return !(X == Y);<br>
+ }<br>
+ friend bool operator<(const HeaderEntry &X, const HeaderEntry &Y) {<br>
+ return X.Loc < Y.Loc || (X.Loc == Y.Loc && X.Name < Y.Name);<br>
+ }<br>
+ friend bool operator>(const HeaderEntry &X, const HeaderEntry &Y) {<br>
+ return Y < X;<br>
+ }<br>
+ friend bool operator<=(const HeaderEntry &X, const HeaderEntry &Y) {<br>
+ return !(Y < X);<br>
+ }<br>
+ friend bool operator>=(const HeaderEntry &X, const HeaderEntry &Y) {<br>
+ return !(X < Y);<br>
+ }<br>
+};<br>
+<br>
+typedef std::vector<HeaderEntry> HeaderContents;<br>
+<br>
+class EntityMap : public llvm::StringMap<llvm::SmallVector<Entry, 2> > {<br>
+ llvm::DenseMap<const FileEntry *, HeaderContents> CurHeaderContents;<br>
+ llvm::DenseMap<const FileEntry *, HeaderContents> AllHeaderContents;<br>
+<br>
+public:<br>
+ llvm::DenseMap<const FileEntry *, HeaderContents> HeaderContentMismatches;<br>
+<br>
+ void add(const std::string &Name, enum Entry::Kind Kind, Location Loc) {<br>
+ // Record this entity in its header.<br>
+ HeaderEntry HE = { Name, Loc };<br>
+ CurHeaderContents[Loc.File].push_back(HE);<br>
+<br>
+ // Check whether we've seen this entry before.<br>
+ llvm::SmallVector<Entry, 2> &Entries = (*this)[Name];<br>
+ for (unsigned I = 0, N = Entries.size(); I != N; ++I) {<br>
+ if (Entries[I].Kind == Kind && Entries[I].Loc == Loc)<br>
+ return;<br>
+ }<br>
+<br>
+ // We have not seen this entry before; record it.<br>
+ Entry E = { Kind, Loc };<br>
+ Entries.push_back(E);<br>
+ }<br>
+<br>
+ void mergeCurHeaderContents() {<br>
+ for (llvm::DenseMap<const FileEntry *, HeaderContents>::iterator<br>
+ H = CurHeaderContents.begin(), HEnd = CurHeaderContents.end();<br>
+ H != HEnd; ++H) {<br>
+ // Sort contents.<br>
+ std::sort(H->second.begin(), H->second.end());<br>
+<br>
+ // Check whether we've seen this header before.<br>
+ llvm::DenseMap<const FileEntry *, HeaderContents>::iterator KnownH<br>
+ = AllHeaderContents.find(H->first);<br>
+ if (KnownH == AllHeaderContents.end()) {<br>
+ // We haven't seen this header before; record its contents.<br>
+ AllHeaderContents.insert(*H);<br>
+ continue;<br>
+ }<br>
+<br>
+ // If the header contents are the same, we're done.<br>
+ if (H->second == KnownH->second)<br>
+ continue;<br>
+<br>
+ // Determine what changed.<br>
+ std::set_symmetric_difference(H->second.begin(), H->second.end(),<br>
+ KnownH->second.begin(),<br>
+ KnownH->second.end(),<br>
+ std::back_inserter(HeaderContentMismatches[H->first]));<br>
+ }<br>
+<br>
+ CurHeaderContents.clear();<br>
+ }<br>
+};<br>
+<br>
+class CollectEntitiesVisitor<br>
+ : public RecursiveASTVisitor<CollectEntitiesVisitor><br>
+{<br>
+ SourceManager &SM;<br>
+ EntityMap &Entities;<br>
+<br>
+public:<br>
+ CollectEntitiesVisitor(SourceManager &SM, EntityMap &Entities)<br>
+ : SM(SM), Entities(Entities) { }<br>
+<br>
+ bool TraverseStmt(Stmt *S) { return true; }<br>
+ bool TraverseType(QualType T) { return true; }<br>
+ bool TraverseTypeLoc(TypeLoc TL) { return true; }<br>
+ bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) { return true; }<br>
+ bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { return true; }<br>
+ bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo) { return true; }<br>
+ bool TraverseTemplateName(TemplateName Template) { return true; }<br>
+ bool TraverseTemplateArgument(const TemplateArgument &Arg) { return true; }<br>
+ bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) { return true; }<br>
+ bool TraverseTemplateArguments(const TemplateArgument *Args,<br>
+ unsigned NumArgs) { return true; }<br>
+ bool TraverseConstructorInitializer(CXXCtorInitializer *Init) { return true; }<br>
+ bool TraverseLambdaCapture(LambdaExpr::Capture C) { return true; }<br>
+<br>
+ bool VisitNamedDecl(NamedDecl *ND) {<br>
+ // We only care about file-context variables.<br>
+ if (!ND->getDeclContext()->isFileContext())<br>
+ return true;<br>
+<br>
+ // Skip declarations that tend to be properly multiply-declared.<br>
+ if (isa<NamespaceDecl>(ND) || isa<UsingDirectiveDecl>(ND) ||<br>
+ isa<NamespaceAliasDecl>(ND) ||<br>
+ isa<ClassTemplateSpecializationDecl>(ND) ||<br>
+ isa<UsingDecl>(ND) || isa<UsingShadowDecl>(ND) ||<br>
+ isa<FunctionDecl>(ND) || isa<FunctionTemplateDecl>(ND) ||<br>
+ (isa<TagDecl>(ND) &&<br>
+ !cast<TagDecl>(ND)->isThisDeclarationADefinition()))<br>
+ return true;<br>
+<br>
+ std::string Name = ND->getNameAsString();<br>
+ if (Name.empty())<br>
+ return true;<br>
+<br>
+ Location Loc(SM, ND->getLocation());<br>
+ if (!Loc)<br>
+ return true;<br>
+<br>
+ Entities.add(Name, isa<TagDecl>(ND)? Entry::Tag : Entry::Value, Loc);<br>
+ return true;<br>
+ }<br>
+};<br>
+<br>
+class CollectEntitiesConsumer : public ASTConsumer {<br>
+ EntityMap &Entities;<br>
+ Preprocessor &PP;<br>
+<br>
+public:<br>
+ CollectEntitiesConsumer(EntityMap &Entities, Preprocessor &PP)<br>
+ : Entities(Entities), PP(PP) { }<br>
+<br>
+ virtual void HandleTranslationUnit(ASTContext &Ctx) {<br>
+ SourceManager &SM = Ctx.getSourceManager();<br>
+<br>
+ // Collect declared entities.<br>
+ CollectEntitiesVisitor(SM, Entities)<br>
+ .TraverseDecl(Ctx.getTranslationUnitDecl());<br>
+<br>
+ // Collect macro definitions.<br>
+ for (Preprocessor::macro_iterator M = PP.macro_begin(),<br>
+ MEnd = PP.macro_end();<br>
+ M != MEnd; ++M) {<br>
+ Location Loc(SM, M->second->getLocation());<br>
+ if (!Loc)<br>
+ continue;<br>
+<br>
+ Entities.add(M->first->getName().str(), Entry::Macro, Loc);<br>
+ }<br>
+<br>
+ // Merge header contents.<br>
+ Entities.mergeCurHeaderContents();<br>
+ }<br>
+};<br>
+<br>
+class CollectEntitiesAction : public SyntaxOnlyAction {<br>
+ EntityMap &Entities;<br>
+<br>
+protected:<br>
+ virtual clang::ASTConsumer *CreateASTConsumer(CompilerInstance &CI,<br>
+ StringRef InFile) {<br>
+ return new CollectEntitiesConsumer(Entities, CI.getPreprocessor());<br>
+ }<br>
+<br>
+public:<br>
+ CollectEntitiesAction(EntityMap &Entities) : Entities(Entities) { }<br>
+};<br>
+<br>
+class ModularizeFrontendActionFactory : public FrontendActionFactory {<br>
+ EntityMap &Entities;<br>
+<br>
+public:<br>
+ ModularizeFrontendActionFactory(EntityMap &Entities) : Entities(Entities) { }<br>
+<br>
+ virtual CollectEntitiesAction *create() {<br>
+ return new CollectEntitiesAction(Entities);<br>
+ }<br>
+};<br>
+<br>
+int main(int argc, const char **argv) {<br>
+ // Figure out command-line arguments.<br>
+ if (argc < 2) {<br>
+ llvm::errs() << "Usage: modularize <file containing header names> <arguments>\n";<br>
+ return 1;<br>
+ }<br>
+<br>
+ // Load the list of headers.<br>
+ std::string File = argv[1];<br>
+ llvm::SmallVector<std::string, 8> Headers;<br>
+ {<br>
+ std::ifstream In(File.c_str());<br>
+ if (!In) {<br>
+ llvm::errs() << "Unable to open header list file \"" << File.c_str() << "\"\n";<br>
+ return 2;<br>
+ }<br>
+<br>
+ std::string Line;<br>
+ while (std::getline(In, Line)) {<br>
+ if (Line.empty() || Line[0] == '#')<br>
+ continue;<br>
+<br>
+ Headers.push_back(Line);<br>
+ }<br>
+ }<br>
+<br>
+ // Create the compilation database.<br>
+ llvm::OwningPtr<CompilationDatabase> Compilations;<br>
+ {<br>
+ std::vector<std::string> Arguments;<br>
+ for (int I = 2; I < argc; ++I)<br>
+ Arguments.push_back(argv[I]);<br>
+ SmallString<256> PathBuf;<br>
+ llvm::sys::fs::current_path(PathBuf);<br>
+ Compilations.reset(new FixedCompilationDatabase(Twine(PathBuf), Arguments));<br>
+ }<br>
+<br>
+ // Parse all of the headers, detecting duplicates.<br>
+ EntityMap Entities;<br>
+ ClangTool Tool(*Compilations, Headers);<br>
+ int HadErrors = Tool.run(new ModularizeFrontendActionFactory(Entities));<br>
+<br>
+ // Check for the same entity being defined in multiple places.<br>
+ for (EntityMap::iterator E = Entities.begin(), EEnd = Entities.end();<br>
+ E != EEnd; ++E) {<br>
+ Location Tag, Value, Macro;<br>
+ for (unsigned I = 0, N = E->second.size(); I != N; ++I) {<br>
+ Location *Which;<br>
+ switch (E->second[I].Kind) {<br>
+ case Entry::Tag: Which = &Tag; break;<br>
+ case Entry::Value: Which = &Value; break;<br>
+ case Entry::Macro: Which = &Macro; break;<br>
+ }<br>
+<br>
+ if (!Which->File) {<br>
+ *Which = E->second[I].Loc;<br>
+ continue;<br>
+ }<br>
+<br>
+ llvm::errs() << "error: '" << E->first().str().c_str()<br>
+ << "' defined at both " << Which->File->getName()<br>
+ << ":" << Which->Line << ":" << Which->Column<br>
+ << " and " << E->second[I].Loc.File->getName() << ":"<br>
+ << E->second[I].Loc.Line << ":" << E->second[I].Loc.Column << "\n";<br>
+ HadErrors = 1;<br>
+ }<br>
+ }<br>
+<br>
+ // Complain about any headers that have contents that differ based on how<br>
+ // they are included.<br>
+ for (llvm::DenseMap<const FileEntry *, HeaderContents>::iterator<br>
+ H = Entities.HeaderContentMismatches.begin(),<br>
+ HEnd = Entities.HeaderContentMismatches.end();<br>
+ H != HEnd; ++H) {<br>
+ if (H->second.empty()) {<br>
+ llvm::errs() << "internal error: phantom header content mismatch\n";<br>
+ continue;<br>
+ }<br>
+<br>
+ HadErrors = 1;<br>
+ llvm::errs() << "error: header '" << H->first->getName()<br>
+ << "' has different contents dependening on how it was included\n";<br>
+ for (unsigned I = 0, N = H->second.size(); I != N; ++I) {<br>
+ llvm::errs() << "note: '" << H->second[I].Name.c_str()<br>
+ << "' in " << H->second[I].Loc.File->getName() << " at "<br>
+ << H->second[I].Loc.Line << ":" << H->second[I].Loc.Column<br>
+ << " not always provided\n";<br>
+ }<br>
+ }<br>
+<br>
+ return HadErrors;<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><span class="hoenzb"><span style="color:#888888">-- </span></span><span style="color:#888888"><br>
<span class="hoenzb">John Thompson</span><br>
<span class="hoenzb"><a href="mailto:John.Thompson.JTSoftware@gmail.com" target="_blank">John.Thompson.JTSoftware@gmail.com</a></span></span><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>