-
Notifications
You must be signed in to change notification settings - Fork 126
feat: boolean macro parsing #1232
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
feat: boolean macro parsing #1232
Conversation
- macro_in_list now handles NAME=VALUE format macros - parse_if_condition now handles 'defined MACRO' without parentheses - Added macro_is_truthy for proper #if MACRO evaluation per CPP semantics
Tests that: - Undefined macros evaluate to false - MACRO=0 evaluates to false - MACRO=1 evaluates to true - MACRO=non-zero evaluates to true - Empty macro (defined without value) evaluates to true
Tests macros defined inside source via #define with all formats: - #if MACRO (truthy evaluation) - #ifdef MACRO (existence check) - #if defined(MACRO) (with parentheses) - #if defined MACRO (without parentheses) - #if !defined MACRO (negated) - #if MACRO == value (equality) - #if MACRO != value (inequality)
|
Thank you @perazz . I confirmed that this PR fixed the issue with What was the issue? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the C preprocessor (CPP) macro parsing capabilities to fix compatibility with stdlib's macros.inc. The changes implement proper support for NAME=VALUE macro format, defined MACRO syntax without parentheses, and improved truthiness evaluation following CPP semantics.
Changes:
- Enhanced
macro_in_listto handleNAME=VALUEformat macros - Extended
parse_if_conditionto supportdefined MACROsyntax without parentheses - Added
macro_is_truthyfunction for proper#if MACROevaluation per CPP semantics
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/fpm_source_parsing.f90 | Updated macro detection logic to be case-sensitive and handle value assignments; added support for defined MACRO without parentheses; implemented macro_is_truthy for proper CPP truthiness evaluation |
| test/fpm_test/test_source_parsing.f90 | Added comprehensive tests for macro case sensitivity, truthiness evaluation, and various CPP conditional formats |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
The new macros defined with values were checked as booleans |
Per CPP standard, macro names and values should be compared case-sensitively. This makes get_macro_value and parse_macro_comparison consistent with macro_in_list.
Per standard CPP, #define MACRO followed by #if MACRO evaluates to #if (empty) which is equivalent to #if 0 (false).
5fd3004 to
98d0e75
Compare
Add locally_defined parameter to macro_is_truthy: - locally_defined=.false. (fpm.toml/command line): empty = true (like -DMACRO) - locally_defined=.true. (#define in source): empty = false (CPP error) This matches exact CPP behavior: - gcc -DMACRO treats it as -DMACRO=1 (truthy) - #define MACRO in source with #if MACRO is a CPP error (empty expression)
98d0e75 to
1572a70
Compare
|
@perazz any thoughts of minting a release soon? I created a draft release three days ago, but it's already out of date with a dozen new commits hitting the |
|
Thank you @rouson, sorry I did not receive a notification for your release draft and had overlooked it (please ensure you ping me when you need me). Extremely busy time, but I should be able to complete this release this weekend. |
Summary
macro_in_listnow handlesNAME=VALUEformat macros (e.g.,STDLIB_BITSET=1)parse_if_conditionnow handlesdefined MACROwithout parentheses (in addition todefined(MACRO))macro_is_truthyfor proper#if MACROevaluation per CPP semanticsFix the
example_packages/metapackage_stdlibbuild which uses stdlib'smacros.incwith#if !defined STDLIB_BITSETsyntax.cc: @jvdp1