multiple .C files in SourceManager

Hi,

I'm creating a compiler based on clang components
for a new language.

What i want to do is parse several source (.c) files
in one go.
Currently for each file I instantiate a Preprocessor,
DiagnosticsEngine, SourceManager etc.

But for error messages that depend on multiple files
(for example wrong number of function arguments for
a function that's defined in one C file and called from
the other)
I have the problem that each Symbol i have has a
clang::SourceLocation. But to resolve this, I also need
to remember which SourceManager it came from.
Would it be possible to generate sourcelocations
for all these files in one SourceManager/Pre-processor?

Anyone have an idea how much work this would be?

Regards,
Bas

Hi,
I too have a similar requirement any inputs on this one?
Thanks.

The SourceManager is meant to manage all the sources. Don't use one
SourceManager per file.

-- Sean Silva

Hi Sean,
Thanks for the reply. I’m sorry i didn’t make my requirement clear in the last mail.

As per my understanding compiler Instance operates on one file at a time and hence at a time the Source Manager contains only the information about the current file being processed.

Given the command -

clang -cc1 test1.c test2.c

While processing test1.c Source manager will not have any information about test2.c. Is my understanding correct?

Is it possible to provide Sourcemanager with information about test2.c as well while the current file being processed is test1.c?

In my current requirement i’m trying to emit warnings in case we have a call from a function in test1.c to a function in test2.c which might result in some problems. Hence would require the Source manager to have information of test2.c as well while the current file being processed is test1.c

Thanks.

Hi Sean,
Thanks for the reply. I’m sorry i didn’t make my requirement clear in the last mail.

As per my understanding compiler Instance operates on one file at a time and hence at a time the Source Manager contains only the information about the current file being processed.

Given the command -

clang -cc1 test1.c test2.c

While processing test1.c Source manager will not have any information about test2.c. Is my understanding correct?

Is it possible to provide Sourcemanager with information about test2.c as well while the current file being processed is test1.c?

In my current requirement i’m trying to emit warnings in case we have a call from a function in test1.c to a function in test2.c which might result in some problems. Hence would require the Source manager to have information of test2.c as well while the current file being processed is test1.c

Thanks.

You probably need to manually take over parsing and not use a CompilerInstance (e.g. use clang::ParseAST() directly).
Then I think you will be able to use one SourceManager for all files. But you still need to use one Preprocessor per translation unit otherwise macros from one translation unit will pollute others.