AdaCore / libadalang

Ada semantic analysis library.
https://www.adacore.com
Other
147 stars 42 forks source link

warnings when parsing projects with C #334

Open briot opened 5 years ago

briot commented 5 years ago

I am not trying to parse C files :-)

But I have a few projects in the closure that include both C and Ada files, via the Languages attribute in the .gpr file. When I parse those projects via lal.UnitProvider.for_project, I get warnings on stdout (or stderr, not sure):

cjson.gpr:8:25: language unknown for "cJSON.c"

Obviously, libadalang cannot do anything with the C files, but it would be nice to just ignore them. If I remember right, GNATCOLL.Projects supports this, but you need some initialization to register the language extensions. So maybe for_project needs a parameter like a dictionary mapping language names to extensions.

raph-amiard commented 5 years ago

Thanks for the heads up. I think we just ignore the C files, but somehow GNATCOLL.Projects is still generating those warnings. We'll take a look into why it does that.

briot commented 5 years ago

Thanks for the heads up. I think we just ignore the C files, but somehow GNATCOLL.Projects is still generating those warnings. We'll take a look into why it does that.

I think it doesn’t ignore “C” files. I think the project might have an explicit list of file names, including “json.c” for instance. GNATCOLL (and libgpr) are just telling us that this file, which it knows is part of the project, has no known language. In GNATCOLL, this is done by registering extensions (“.c” and “.h”) for all languages we want (perhaps there even is a function to register some usual extensions).

Since you have no way to know the full list of languages the user wants to support, I think you might have to expose a function to let users do that. As I remember, as of 3 years ago, GNATCOLL came with a python API for the projects (extracted from GPS). If it still exists, perhaps we should simply get access to it. Then such issues are gnatcoll issues, not libadalang issues, and you are out of the loop :-)

Manu

pjljvandelaar commented 2 years ago

@briot The rejuvenation library offers some functions on top of libadalang that explicitly ignore non-Ada files: See e.g. https://github.com/TNO/Rejuvenation-Ada/blob/fac22c0979872fb2a63ab2c12efd179912e6c3f5/src/rejuvenation-simple_factory.adb#L149

P.S. When you experiment on windows, be aware that using GNAT native 12.1.2 exposes a bug in libadalang's Create_Context function that is used within the functions I just referred you to!