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

CPP expression parser for makedep #594

Merged
merged 2 commits into from
Apr 15, 2024

Conversation

marshallward
Copy link
Member

This patch adds a relatively robust parser for C preprocessor expressions inside of an #if statement.

The following are supported:

  • Nearly all operators, including arithmetic, logical, and bitwise,

  • Parentheses within expressions,

  • defined() evaluations.

The following are explicitly not supported:

  • Function macros,

  • Multiline preprocessors.

No doubt there are other lingering issues, but this is comprehensive enough to handle both MOM6 as well as current and legacy FMS source codes.

Existing Makefile.dep output files appear to be mostly unchanged. One rule (data_override.o) had its arguments reordered but is otherwise unchanged. mpp_data.o had its rule corrected to use mpp_util_mpi.inc rather than mpp_util_nocomm.inc.

Some fixes and adjustments were made to the overall makedep source:

  • Input macros (-D) are now stored as key-value dicts, rather than simply a list of macro names.

  • Input macros are now passed to all scan_fortran_file() calls, rather than just the Fortran source.

  • Input macros are now correctly passed to FMS makedep. Previously, these were omitted from the Makefile generation.

  • Previously, #if blocks were always set to True, even though the comments indicated that they were always set to False. Given that neither of these was ever correct, it's amazing that we were able to survive this long without prior incident.

The motivation for this PR comes from issues with Makefile generation in FMS. Older versions of FMS were unable to correctly resolve their dependencies in fft.f90 on certain systems (perhaps caused by filesystem peculiarities). Newer versions of FMS were unable to handle the #if block default from True to False. Inevitably, we threw up our hands and solved the underlying problem.

This patch adds a relatively robust parser for C preprocessor
expressions inside of an #if statement.

The following are supported:

* Nearly all operators, including arithmetic, logical, and bitwise,

* Parentheses within expressions,

* defined() evaluations.

The following are explicitly not supported:

* Function macros,

* Multiline preprocessors.

No doubt there are other lingering issues, but this is comprehensive
enough to handle both MOM6 as well as current and legacy FMS source
codes.

Existing Makefile.dep output files appear to be mostly unchanged.  One
rule (data_override.o) had its arguments reordered but is otherwise
unchanged.  mpp_data.o had its rule corrected to use mpp_util_mpi.inc
rather than mpp_util_nocomm.inc.

Some fixes and adjustments were made to the overall makedep source:

* Input macros (-D) are now stored as key-value dicts, rather than
  simply a list of macro names.

* Input macros are now passed to all scan_fortran_file() calls, rather
  than just the Fortran source.

* Input macros are now correctly passed to FMS makedep.  Previously,
  these were omitted from the Makefile generation.

* Previously, #if blocks were always set to True, even though the
  comments indicated that they were always set to False.  Given that
  neither of these was ever correct, it's amazing that we were able to
  survive this long without prior incident.

The motivation for this PR comes from issues with Makefile generation in
FMS.  Older versions of FMS were unable to correctly resolve their
dependencies in fft.f90 on certain systems (perhaps caused
by filesystem peculiarities).  Newer versions of FMS were unable to
handle the #if block default from True to False.  Inevitably, we threw
up our hands and solved the underlying problem.
@marshallward marshallward changed the title kCPP expression parser for makedep CPP expression parser for makedep Apr 3, 2024
Copy link

codecov bot commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.12%. Comparing base (b98acd8) to head (6acc2ff).
Report is 1 commits behind head on dev/gfdl.

❗ Current head 6acc2ff differs from pull request most recent head 3fcae7d. Consider uploading reports for the commit 3fcae7d to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##           dev/gfdl     #594      +/-   ##
============================================
+ Coverage     37.07%   37.12%   +0.05%     
============================================
  Files           271      271              
  Lines         80968    80797     -171     
  Branches      15118    15082      -36     
============================================
- Hits          30021    29998      -23     
+ Misses        45324    45198     -126     
+ Partials       5623     5601      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@adcroft adcroft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition for expanded compatibility.

@adcroft adcroft merged commit 6f1c79e into NOAA-GFDL:dev/gfdl Apr 15, 2024
12 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.

2 participants