<div class="gmail_quote">On Fri Sep 26 2014 at 8:39:37 PM M.Sc. Stefan Kemnitz <<a href="mailto:kemnitz.stefan@gmail.com">kemnitz.stefan@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div> </div><div>i am working on a plugin for clang that will show me some custom diagnostics.</div><div><br></div><div>I extended the "Hello World"-plugin PrintFunctionNames so that it emits an errors if it finds a function declaration ( its just a toy plugin )</div><div>Everything works fine if i execute it from command line with clang.</div><div><br></div><div>-------------------------------------------------------------------------------------</div><div>$ clang -Xclang -load -Xclang <pluginpath>/PrintFunctionNames.so -Xclang -add-plugin -Xclang print-fns main.cpp</div><div><div>top-level-decl: "foo"</div><div>/home/incubus/test/clang-plugins/main.cpp:3:1: error: use of undeclared identifier 'foo'</div><div>void foo()</div><div>^</div><div>/home/incubus/test/clang-plugins/main.cpp:12:5: error: use of undeclared identifier 'bar'</div><div>    bar();</div><div>    ^</div><div>top-level-decl: "main"</div><div>/home/incubus/test/clang-plugins/main.cpp:8:1: error: use of undeclared identifier 'main'</div><div>int main(int argc, char** argv){</div><div>^</div><div>3 errors generated.</div></div><div>---------------------------------------------------------------------------------------</div><div><br></div><div>the first and third error are from my plugin and the second is from clang itself.</div><div><br></div><div>Now i want to do the same thing through libclang.</div><div>I am using the vim plugin YouCompleteMe to send all of the flags that were passed to clang, to libclang.</div><div><br></div><div>I followed the path of execution to </div><div>clang_parseTranslationUnit -> clang_parseTranslationUnit2 -> clang_parseTranslationUnit_impl -></div><div> ASTUnit::LoadFromCommandLine -> ASTUnit::LoadFromCompilerInvocation -> ASTUnit::Parse </div><div><br></div><div>were the parsing process is started.</div><div><br></div><div>in FrontendAction::BeginSourceFile  the method FrontendAction::CreateWrappedASTConsumer is called which creates ASTConsumers from the plugins.</div><div>I found out that the Consumer is not created because the FrontendPluginRegistry does not contain any plugins.</div><div>This is due to the fact that the plugin was never loaded.</div><div><br></div><div>I searched the codebase for the loading routines and found out that the only loading is in clang::ExecuteCompilerInvocation.</div><div>I know that clang_parseTranslationUnit is supposed to Parse the translation unit not to execute the whole compiler.</div><div><br></div><div>My question is:</div><div><br></div><div>Is there any way to load the plugin earlier so that it can be executed while parsing?</div><div>Or if it is not possible. Is there some other way to add custom error messages that will be emitted when running clang_parseTranslationUnit?</div></div></blockquote><div><br></div><div>I think the right solution is to add a way to load plugins when running with libclang.</div><div>I see 2 options:<br>1. add a call to libclang to allow loading of plugins</div><div>+ less complexity in the driver<br></div><div>- libclang tools need to get explicit support for this</div><div>2. make the driver allow loading clang plugins</div><div>+ "just works" with any editor integration<br></div><div>- more complexity in the driver</div><div><br></div><div>I'm leaning towards (2). If you want to give implementing it a try, I'd be happy to review patches...</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"><div dir="ltr"><div><br></div><div><br></div><div>Greetings Stefan Kemnitz</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><div><br></div><div><br></div><div><br></div><div><br></div></div>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">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/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div>