<div dir="ltr">+richard<div><br></div><div>why are those not instantiated when a FrontendAction is run?</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 4, 2014 at 6:06 PM, Kim Gräsman <span dir="ltr"><<a href="mailto:kim.grasman@gmail.com" target="_blank">kim.grasman@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Manuel,<div><br></div><div class="gmail_extra"><div class="gmail_quote"><div class="">On Mon, Aug 4, 2014 at 2:43 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div><div><div><br></div></div></div><div>Can we somehow get this into the tooling infrastructure? I'd consider it a bug if fdelayed-template-parsing leads to ASTs that don't have the templates; from reading the docs, it seems like all it should do is parse them at the end of the translation unit, or am I missing something?</div>
</div></div></div></blockquote><div><br></div></div><div>This is what we did in IWYU, right after our original AST traversal:</div><div><br></div><div>+ void InstantiateLateParsedFunctions() {</div><div>+ const vector<FunctionDecl*>& late_parsed_decls = LateParsedFunctionDecls();</div>
<div>+ clang::Sema& sema = compiler()->getSema();</div><div>+</div><div>+ // If we have any late-parsed functions, make sure the</div><div>+ // -fdelayed-template-parsing flag is on. Otherwise we don't know where</div>
<div>+ // they came from.</div><div>+ CHECK_((compiler()->getLangOpts().DelayedTemplateParsing ||</div><div>+ late_parsed_decls.empty()) &&</div><div>+ "Should not have late-parsed decls without "</div>
<div>+ "-fdelayed-template-parsing.");</div><div>+</div><div>+ for (Each<FunctionDecl*> it(&late_parsed_decls); !it.AtEnd(); ++it) {</div><div>+ FunctionDecl* decl = *it;</div><div>+ if (decl->isLateTemplateParsed()) {</div>
<div>+ // Force parsing and AST building of the yet-uninstantiated function</div><div>+ // template body.</div><div>+ clang::LateParsedTemplate* lpt = sema.LateParsedTemplateMap[decl];</div><div>+ sema.LateTemplateParser(sema.OpaqueParser, *lpt);</div>
<div>+</div><div>+ // Traverse the AST fragment again to run IWYU analysis on the new</div><div>+ // nodes.</div><div>+ TraverseDecl(decl);</div><div>+ }</div><div>+ }</div><div>+ }</div><div>
<br></div><div>After parsing, you'd have to run a second pass of your matcher AST visitor. I could get away with just visiting the instantiated Decl (or so I hope), but that might not be enough for your needs.</div><div>
<br></div><div>I'm still not sure this is 100% right, of course.<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div><div>- Kim</div></font></span></div>
</div></div>
</blockquote></div><br></div>