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

Separation of metafunction and runtime regex code. #1219

Merged
merged 5 commits into from
Aug 11, 2024

Conversation

MaxSagebaum
Copy link
Contributor

@MaxSagebaum MaxSagebaum commented Aug 9, 2024

Closes #1199.

This MR separates include/cpp2regex.h2 into include/cpp2regex.h2 and source/regex.h2. cpp2regex.h2 contains all "runtime" functions for the regular expression matching. regex.h2 contains the parsing and generation functionality.

Instead of a separate file in ./source
@hsutter
Copy link
Owner

hsutter commented Aug 10, 2024

Thanks! I've taken a pass at this to simplify (I hope), by moving all the metafunction stuff directly into ./source/reflect.h2 instead of into a new ./source file.

Before I go further: Does that first step look okay?

Then my second step would be to remember a global flag if @regex is ever used, and then have to_cpp1 emit a flag to enable including the regex runtime support, only in that case.

@MaxSagebaum
Copy link
Contributor Author

Looks good.

The global flag is probably the simplest way to implement this. But when we want to allow users, to write their own metafunctions. This functionality is probably required.

@hsutter
Copy link
Owner

hsutter commented Aug 10, 2024

Good point... better than a global flag is a function by which a metafunction can add a runtime #include or import. I'll pursue that direction...

The run-time support library stays in `cpp2util.h` and can use the `cpp2::regex::` subnamespace there

The compile-time parts stay in `reflect.h2` and use the `cpp2::meta::` namespace there

Eventually this can be generalized for user-written metafunctions when those are supported, but for right now this keeps things consistent for the metafunctions supplied in-the-box with cppfront
For metafunctions that require runtime support via #includes to be injected into lowered Cpp1 programs

Also cleanup while I'm at it:
- remove headers from `common.h` that are now already included via `cpp2util.h`
- line up some thing that got un-lined-up (OCD)
@hsutter
Copy link
Owner

hsutter commented Aug 10, 2024

OK, I've now finished adding to this PR, and I've updated the description to "closes #1199" which I think is accurate.

I think this is ready to merge. Could you please take a look to see if you spot anything more, and if you don't find anything I'll merge it. Thanks again!

@MaxSagebaum
Copy link
Contributor Author

Looks good. Adding the includes looks really simple. Would have needed quite some time to figure this out.

@hsutter
Copy link
Owner

hsutter commented Aug 11, 2024

Looks good. Adding the includes looks really simple. Would have needed quite some time to figure this out.

You share credit for that!

Your comment above:

But when we want to allow users, to write their own metafunctions. This functionality is probably required.

directly motivated this line in the PR to solve the problem in #1199:

t.add_runtime_support_include( "cpp2regex.h" );

Thanks!

@hsutter hsutter merged commit d70601e into hsutter:main Aug 11, 2024
23 of 29 checks passed
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

Successfully merging this pull request may close these issues.

[SUGGESTION] Only include cpp2regex.h when @regex is used to improve compile time
2 participants