<div class="gmail_quote">On Thu, Jun 28, 2012 at 1:31 AM, Philip Dunstan <span dir="ltr"><<a href="mailto:phil@philipdunstan.com" target="_blank">phil@philipdunstan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Manuel Klimek wrote<br>
><br>
> On Sun, Jun 24, 2012 at 4:53 PM, Philip Dunstan <phil@>wrote:<br>
<div class="im">><br>
>> Replace function parameters that specify a shared_ptr instance by<br>
>> value with shared_ptr by const reference.<br>
>><br>
>> Should I be changing the type from shared_ptr<X> to const shared_ptr<X>&<br>
>> or<br>
>> is there a way to do this by modifying the AST to make the parameter<br>
>> const<br>
>> and by reference and then re-emit the source?<br>
>><br>
><br>
> If you can match the location of the shared_ptr and the type, you can emit<br>
> a replacement to "const X&" (no need to go through the AST here). Is there<br>
> a part of the matching that's problematic?<br>
><br>
<br>
</div>Nothing problematic. It just feels like I might lose something with a simple<br>
string replacement. I am not sure what might so wrong, so I might just be<br>
being a little over cautious here.<br></blockquote><div><br></div><div>We've been doing simple string replacements for large scale code transformations on google's repo for about 1.5 years now :)</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Manuel Klimek wrote<br>
<div class="im">><br>
>> It appears that I need to specify all of the system c++ include files<br>
>> when<br>
>> I run the tool on a file, but I don't need to provide them when I compile<br>
>> the with the clang compiler that I have built from the tooling branch. Is<br>
>> this expected behavior?<br>
><br>
</div><div class="im">> Hm, this should work in principle. Can you add '-v' output to both the<br>
> tool<br>
> run and the clang run from your self-built clang compiler and attach them?<br>
><br>
<br>
</div>I've added the outputs with '-v'. The first is clang built from the tooling<br>
branch, the second is my tool built against the same tooling branch. The<br>
only difference looks like the include path from the clang build directory,<br>
and explicitly specifying this has fixed the errors from the tool. Who<br>
should be responsible for adding this path to the tools header search list?<br></blockquote><div><br></div><div>Hah, you're cheating :)</div><div>Clang tools need the clang builtin headers just like clang. So the best way to run them is to put them into the same binary directory where clang is located.</div>
<div><br></div><div>Or you convince Chandler on IRC that we want to have the builtin headers compiled into the binary for tools ;)</div><div><br></div><div>Cheers,</div><div>/Manuel</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
> /home/phil/Development/tooling/build/Debug+Asserts/bin/clang++ -c<br>
> testdata.cpp -v -std=c++11<br>
clang version 3.2 (branches/tooling 158516)<br>
Target: x86_64-unknown-linux-gnu<br>
Thread model: posix<br>
"/home/phil/Development/tooling/build/Debug+Asserts/bin/clang" -cc1 -triple<br>
x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name<br>
testdata.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno<br>
-masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64<br>
-target-linker-version 2.22 -momit-leaf-frame-pointer -v -coverage-file<br>
testdata.o -resource-dir<br>
/home/phil/Development/tooling/build/Debug+Asserts/bin/../lib/clang/3.2<br>
-fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6<br>
-internal-isystem<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu<br>
-internal-isystem<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward<br>
-internal-isystem /usr/local/include -internal-isystem<br>
/home/phil/Development/tooling/build/Debug+Asserts/bin/../lib/clang/3.2/include<br>
-internal-externc-isystem /usr/include/x86_64-linux-gnu<br>
-internal-externc-isystem /include -internal-externc-isystem /usr/include<br>
-std=c++11 -fdeprecated-macro -fdebug-compilation-dir<br>
/home/phil/Development/clang_tools/add-override-specifier -ferror-limit 19<br>
-fmessage-length 138 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc<br>
-fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions<br>
-fdiagnostics-show-option -fcolor-diagnostics -o testdata.o -x c++<br>
testdata.cpp<br>
clang -cc1 version 3.2 based upon LLVM 3.2svn default target<br>
x86_64-unknown-linux-gnu<br>
ignoring nonexistent directory "/include"<br>
#include "..." search starts here:<br>
#include <...> search starts here:<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6<br>
<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward<br>
/usr/local/include<br>
<br>
/home/phil/Development/tooling/build/Debug+Asserts/bin/../lib/clang/3.2/include<br>
/usr/include/x86_64-linux-gnu<br>
/usr/include<br>
End of search list.<br>
<br>
<br>
> ./add-override-specifier testdata.cpp -- -v -std=c++11<br>
Processing:<br>
/home/phil/Development/clang_tools/add-override-specifier/testdata.cpp.<br>
clang version 3.2 (branches/tooling 158516)<br>
Target: x86_64-unknown-linux-gnu<br>
Thread model: posix<br>
clang Invocation:<br>
<br>
"/home/phil/Development/clang_tools/add-override-specifier/add-override-specifier"<br>
"-cc1" "-triple" "x86_64-unknown-linux-gnu" "-fsyntax-only" "-disable-free"<br>
"-main-file-name" "testdata.cpp" "-mrelocation-model" "static"<br>
"-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases"<br>
"-munwind-tables" "-target-cpu" "x86-64" "-target-linker-version" "2.22"<br>
"-momit-leaf-frame-pointer" "-v" "-resource-dir"<br>
"/home/phil/Development/clang_tools/add-override-specifier/../lib/clang/3.2"<br>
"-fmodule-cache-path" "/var/tmp/clang-module-cache" "-internal-isystem"<br>
"/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6"<br>
"-internal-isystem"<br>
"/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu"<br>
"-internal-isystem"<br>
"/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward"<br>
"-internal-isystem" "/usr/local/include" "-internal-isystem"<br>
"/home/phil/Development/clang_tools/add-override-specifier/../lib/clang/3.2/include"<br>
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"<br>
"-internal-externc-isystem" "/include" "-internal-externc-isystem"<br>
"/usr/include" "-std=c++11" "-fdeprecated-macro" "-fdebug-compilation-dir"<br>
"/home/phil/Development/clang_tools/add-override-specifier" "-ferror-limit"<br>
"19" "-fmessage-length" "138" "-mstackrealign" "-fgnu-runtime"<br>
"-fobjc-runtime-has-arc" "-fobjc-runtime-has-weak" "-fobjc-fragile-abi"<br>
"-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option"<br>
"-fcolor-diagnostics" "-x" "c++"<br>
"/home/phil/Development/clang_tools/add-override-specifier/testdata.cpp"<br>
<br>
clang -cc1 version 3.2 based upon LLVM 3.2svn default target<br>
x86_64-unknown-linux-gnu<br>
ignoring nonexistent directory<br>
"/home/phil/Development/clang_tools/add-override-specifier/../lib/clang/3.2/include"<br>
ignoring nonexistent directory "/include"<br>
#include "..." search starts here:<br>
#include <...> search starts here:<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6<br>
<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward<br>
/usr/local/include<br>
/usr/include/x86_64-linux-gnu<br>
/usr/include<br>
End of search list.<br>
In file included from<br>
/home/phil/Development/clang_tools/add-override-specifier/testdata.cpp:1:<br>
In file included from<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/iostream:39:<br>
In file included from<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/ostream:39:<br>
In file included from<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/ios:38:<br>
In file included from<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/iosfwd:41:<br>
In file included from<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/bits/postypes.h:41:<br>
In file included from<br>
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/cwchar:45:<br>
/usr/include/wchar.h:40:11: fatal error: 'stdarg.h' file not found<br>
# include <stdarg.h><br>
^<br>
1 error generated.<br>
Error while processing<br>
/home/phil/Development/clang_tools/add-override-specifier/testdata.cpp.<br>
<br>
<br>
<br>
<br>
Manuel Klimek wrote<br>
<div class="im">><br>
> A different solution would be to use the CompilationDatabase. If your<br>
> project uses cmake, it works out of the box; if not, the easiest thing is<br>
> to create a compilation database. See the docs here:<br>
> <a href="http://clang.llvm.org/docs/JSONCompilationDatabase.html" target="_blank">http://clang.llvm.org/docs/JSONCompilationDatabase.html</a><br>
><br>
</div>I will definitely look into this. We use scons rather than cmake, but it<br>
should no problem extracting this information.<br>
<br>
<br>
<br>
Manuel Klimek wrote<br>
<div class="im">><br>
> I simply do match on the path / name of the files for that. Usually<br>
> project<br>
> files have easily detectable paths.<br>
> Also note that what I do is key whether I want to replace something on the<br>
> file of the original declaration of the 'thing' I want to replace, so that<br>
> you don't get inconsistent states.<br>
><br>
</div>Interesting. That is good to know.<br>
<br>
<br>
Manuel Klimek wrote<br>
<div class="im">><br>
> That's what the refactoring support in the tooling library is for:<br>
> <a href="http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Tooling/Refactoring.h?view=markup" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Tooling/Refactoring.h?view=markup</a><br>
><br>
> The idea is that you run over all TUs you want to refactor in the same<br>
> process. We're working on getting this multi-threaded so that it scales<br>
> better.<br>
><br>
> Another possibility is to output simple diffs from your tool, and use a<br>
> little python script to slurp in the changes, unique them and apply them<br>
> (that's what we currently do for really large scale MapReduce style<br>
> refactorings).<br>
><br>
</div>Thanks, I will definitely look into that<br>
<div class="im"><br>
Phil<br>
--<br>
Philip Dunstan<br>
<a href="mailto:phil@philipdunstan.com">phil@philipdunstan.com</a><br>
<a href="http://www.philipdunstan.com" target="_blank">www.philipdunstan.com</a><br>
<br>
<br>
<br>
--<br>
</div>View this message in context: <a href="http://clang-developers.42468.n3.nabble.com/Source-to-source-transformations-questions-in-branches-tooling-tp4024920p4025005.html" target="_blank">http://clang-developers.42468.n3.nabble.com/Source-to-source-transformations-questions-in-branches-tooling-tp4024920p4025005.html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the Clang Developers mailing list archive at Nabble.com.<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br>