Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle header files #17

Open
certik opened this issue Dec 13, 2023 · 0 comments
Open

How to handle header files #17

certik opened this issue Dec 13, 2023 · 0 comments

Comments

@certik
Copy link
Contributor

certik commented Dec 13, 2023

Header files should be handled like "import" in Python or "use" in Fortran. A header file, together with an optional associated cpp file, will create one ASR module, that will be saved to a .mod file. Then when an include happens, the mod file is loaded. So we will have access to all the source code (whether in .h or in .cpp).

Our parser should thus parse include lines into an HeaderInclude AST node, like an import statement.

This will allow very fast compilation and robust error messages. It will not allow circular dependencies and other corner cases (such as various preprocessor macro tricks), but as a user I do not want those anyway. We will eventually allow a preprocessor, but it would work like the preprocessor in LFortran, on a per file basis.

Parsing will thus be strictly local only, each .h or .cpp file can be fully parsed to AST, no need to look elsewhere. Then in AST->ASR, intrinsic C++ header files (and supported 3rd party libraries) are handled directly (we do not actually include any header file) and user defined header files are handled by compiling those as ASR modules first, and then loading them as ASR modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant