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

Support full function-like macro expansions and allow for whitespace in PP directives #350

Closed

Conversation

emanspeaks
Copy link
Contributor

This is a refactor of #341 to separate out the vendor-agnostic changes. (See earlier conversation there for some context.)

Closes #297
Addresses spaces on either side of the hash in preprocessor lines.

Additionally, provides more robust handling of define directives as well as support for function-like macros inherited from C-style preprocessors.

Copy link

codecov bot commented Jan 21, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (71d5f40) 87.51% compared to head (5cf36e3) 87.70%.

Files Patch % Lines
fortls/langserver.py 87.50% 1 Missing ⚠️
fortls/parsers/internal/parser.py 97.95% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #350      +/-   ##
==========================================
+ Coverage   87.51%   87.70%   +0.19%     
==========================================
  Files          35       35              
  Lines        4756     4791      +35     
==========================================
+ Hits         4162     4202      +40     
+ Misses        594      589       -5     

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

emanspeaks added a commit to emanspeaks/fortls that referenced this pull request Jan 21, 2024
Copy link
Member

@gnikit gnikit left a comment

Choose a reason for hiding this comment

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

Thank you for your efforts on this.
After review, I have a few suggestions:

  • It appears there are some style changes in the diffs not essential to this PR.
    Could we revert these to maintain consistency with the original code?
  • Regarding the REGEX modifications, I've observed instances of unnecessary group
    captures and alterations in expression matching that may introduce side effects.
    I recommend we take another look at these to ensure accuracy and reliability.
  • I've attempted to provide a more Pythonic approach for certain additions
    to the code, aiming for clarity and conciseness.

Overall, great work. With a few adjustments based on the feedback,
I believe this will be ready for merge. Looking forward to the final touches.

fortls/__init__.py Show resolved Hide resolved
fortls/parsers/internal/parser.py Show resolved Hide resolved
fortls/parsers/internal/parser.py Show resolved Hide resolved
Comment on lines +2079 to +2081

out_line = text
out_line = replace_defined(out_line)
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK these changes can be reverted

@@ -2038,6 +2043,7 @@ def replace_ops(expr: str):
expr = expr.replace("!=", " <> ")
expr = expr.replace("!", " not ")
expr = expr.replace(" <> ", " != ")

Copy link
Member

Choose a reason for hiding this comment

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

I think this is a remainder from cherry-picking, o need for this diff.

Suggested change

Copy link
Member

Choose a reason for hiding this comment

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

I think this test is redundant and does not perform any additional checks that are not covered by the ewrite() function macro e.g.

"```fortran90\n#define ewrite(priority, format)"
" if (priority <= 3) write((priority), format)\n```"

Am I missing something?

Comment on lines +2320 to +2331
def append_multiline_macro(pp_defs: dict, def_name: str, line: str):
def_value = pp_defs[def_name]
def_args = None
if isinstance(def_value, tuple):
def_args, def_value = def_value

def_value += line

if def_args is not None:
def_value = (def_args, def_value)

pp_defs[def_name] = def_value
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def append_multiline_macro(pp_defs: dict, def_name: str, line: str):
def_value = pp_defs[def_name]
def_args = None
if isinstance(def_value, tuple):
def_args, def_value = def_value
def_value += line
if def_args is not None:
def_value = (def_args, def_value)
pp_defs[def_name] = def_value
def append_multiline_macro(def_value: str | tuple, line: str):
def_args = None
if isinstance(def_value, tuple):
def_args, def_value = def_value
def_value += line
if def_args is not None:
return (def_args, def_value)
return def_value

fortls/langserver.py Show resolved Hide resolved
fortls/langserver.py Show resolved Hide resolved
fortls/langserver.py Show resolved Hide resolved
@gnikit
Copy link
Member

gnikit commented Mar 11, 2024

I will have another pass at the added python code once the diffs clearup a bit.

@gnikit
Copy link
Member

gnikit commented Apr 13, 2024

I have taken the commits from this PR + the suggestions and merged them to #368. The PR just got merged in master, so I am closing this. Thanks for the code @emanspeaks . I will be issuing a major release soon.

@gnikit gnikit closed this Apr 13, 2024
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.

Leave blank spaces in front of C preprocessing directives
2 participants