CodeCompass icon indicating copy to clipboard operation
CodeCompass copied to clipboard

Inclusion relationship via -include flag.

Open bruntib opened this issue 7 years ago • 1 comments

An inclusion relationship can also be added by -include flag.

The question is: should CppHeaderInclusion table contain these relations too? If yes, then which file includes the header provided by this -include flag?

This question affects the incremental parsing feature as well, since this is a dependency, just like an explicit #include.

bruntib avatar Oct 04 '18 16:10 bruntib

Yeah, the issue is that for inclusions we currently use the preprocessor directive matching/callbacks and not something that directly lists from Clang what headers were used (e.g. SourceManager's file table or something).

-include appears for a particular build action. The file that is compiled with the -include foo.h gets an implicit first line #include "foo.h" (note that "-search is wider than <-search), but this line is not emitted into the preprocessor state as -include does more than just inclusion: it inherently replaces the <builtin> stack (either because the included file is resolved to a PCH and it contains a pp state, or by running a parse and considering symbols from this file as the builtin). This flag is very nasty, as specifying multiple only results in a warning and the first one considered, while the rest of the -includes are ignored.

Relationship-wise mapping the included FID to the FID of the file whose build command contains the directive conforms to how we considered header inclusions so far. Hopefully this will be resilient enough as we don't track multiple builds for the same file. (In previous versions the include table had 3 columns and one specified in context of which build action was the include discovered... then again, because we skip parsing a file multiple times, it's useless anyways.)

whisperity avatar Oct 05 '18 19:10 whisperity