SomeProgrammer
SomeProgrammer

Reputation: 1294

C++20 modules - how to get their file names?

My aim is to build a simple c++ parser which collects the name of every struct / class in a c++ program.

The problem is concerning c++20 modules. Consider the following code:

import module-name;

How can my parser know where the module originated from and collect the name of structs /classes?

Had it been an #include directive my parser would just parse the given file name...

Is there any way to get the relevant file names for a given module?

Upvotes: 2

Views: 333

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473557

The module files loaded by the compiler are all previously generated by the compiler. The compiler gives those files some name likely based on the module's given name. Exactly how that works is up to the compiler and build environment, and will likely vary among compilers.

Basically, it's not really your job. When you generate a module, you get some output files from the build system, just as you would a library or DLL. You then make those available to later builds that want to consume them, telling the compiler where it can find those module files.

Upvotes: 2

Related Questions