[cfe-dev] Tooling vs -fdelayed-template-parsing WAS: Clang-cl.exe and the VC++ preprocessor

Manuel Klimek klimek at google.com
Mon Aug 4 10:14:44 PDT 2014


+richard

why are those not instantiated when a FrontendAction is run?


On Mon, Aug 4, 2014 at 6:06 PM, Kim Gräsman <kim.grasman at gmail.com> wrote:

> Hi Manuel,
>
> On Mon, Aug 4, 2014 at 2:43 PM, Manuel Klimek <klimek at google.com> wrote:
>
>>
>> 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?
>>
>
> This is what we did in IWYU, right after our original AST traversal:
>
> +  void InstantiateLateParsedFunctions() {
> +    const vector<FunctionDecl*>& late_parsed_decls =
> LateParsedFunctionDecls();
> +    clang::Sema& sema = compiler()->getSema();
> +
> +    // If we have any late-parsed functions, make sure the
> +    // -fdelayed-template-parsing flag is on. Otherwise we don't know
> where
> +    // they came from.
> +    CHECK_((compiler()->getLangOpts().DelayedTemplateParsing ||
> +            late_parsed_decls.empty()) &&
> +           "Should not have late-parsed decls without "
> +           "-fdelayed-template-parsing.");
> +
> +    for (Each<FunctionDecl*> it(&late_parsed_decls); !it.AtEnd(); ++it) {
> +      FunctionDecl* decl = *it;
> +      if (decl->isLateTemplateParsed()) {
> +        // Force parsing and AST building of the yet-uninstantiated
> function
> +        // template body.
> +        clang::LateParsedTemplate* lpt = sema.LateParsedTemplateMap[decl];
> +        sema.LateTemplateParser(sema.OpaqueParser, *lpt);
> +
> +        // Traverse the AST fragment again to run IWYU analysis on the new
> +        // nodes.
> +        TraverseDecl(decl);
> +      }
> +    }
> +  }
>
> 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.
>
> I'm still not sure this is 100% right, of course.
>
> - Kim
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140804/0e33c9c9/attachment.html>


More information about the cfe-dev mailing list