[cfe-dev] How clang handle user's include
Julien Rinaldini via cfe-dev
cfe-dev at lists.llvm.org
Fri Mar 17 11:53:07 PDT 2017
Hi,
Thanks for your answer. It helped me a lot. Indeed by looking at the code this part of clang looks very complicated.
Actually I found another way of doing what I wanted to do.
Cheers,
Julien
> On 14 Mar 2017, at 13:01, mats petersson <mats at planetcatfish.com> wrote:
>
> It's not entirely clear what you are asking - the full answer to your question would probably take a few days to write down with sufficient precision to explain "everything that happens due to #include "foo.h" inside clang. So if my explanation below isn't "enough", please provide a more specific follow-up question - I'm not sure I can give the answer, because what I've explained is nearly the full extent of my knowledge...
>
> Clang doesn't use a traditional pre-processor (as per the "old school C compiler", where you'd get a "foo.i" file of the preprocessed input), instead it parses and understand preprocessor directives in the main processing of the file. It has code that understands the file-structure of the overall compilation unit. [Whether it's a "user" or "system" include is not really important, except for a few cases of "if it's a system include don't issue warnings for <something that is considered harmless but sometimes 'wrong' in system headers)],
>
> This comment in include/clang/Lex/Preprocessor.h explains the same thing I just said:
> /// Lexers know only about tokens within a single source file, and don't
> /// know anything about preprocessor-level issues like the \#include stack,
> /// token expansion, etc.
> class Preprocessor : public RefCountedBase<Preprocessor>
>
> The Preprocessor class is used to "help" with the task of dealing with this. To the "compiler proper", it will seem like all the input came from a single file.
>
> --
> Mats
>
>
>> On 14 March 2017 at 09:17, via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>> Hi,
>>
>> I'm looking at the clang source code and I'm wandering where clang handle the include from users.
>>
>> If you have a simple C file foo.c:
>>
>> #include <stdio.h>
>> #include "foo.h"
>>
>> void foo(void) {
>> printf("foo\n");
>> }
>>
>> int main(void) {
>> foo();
>> return 0;
>> }
>>
>> and the corresponding foo.h header:
>>
>> void foo(void);
>>
>> Which part of clang "merge" (or inline) foo.c and foo.h together? If I understand well that is what is happening, right?
>>
>> Thank you for your answers!
>>
>> Cheers,
>> Julien
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170317/be292742/attachment.html>
More information about the cfe-dev
mailing list