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 selected Intel-specific preprocessor macro expansions #341

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
05f93a7
allow for whitespace in PP directives, better def arg regex
emanspeaks Dec 11, 2023
f297da5
add draft of unit test
emanspeaks Jan 3, 2024
d23088d
Merge branch 'master' into ifort-fpp-fixes
emanspeaks Jan 3, 2024
37752c8
revert changes to try to fix unit tests
emanspeaks Jan 3, 2024
4367f32
everything working but the def regex
emanspeaks Jan 3, 2024
1b3735e
working regex that is at least backwards compatible
emanspeaks Jan 3, 2024
3ddeb00
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 3, 2024
6e63f04
working version of macro expansion w/ tests
emanspeaks Jan 3, 2024
e1ce5eb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 3, 2024
0b6fbaa
housekeeping
emanspeaks Jan 3, 2024
ccb4d37
replace \s* with [ ]*
emanspeaks Jan 3, 2024
b7c3572
attempt to remedy regex warnings
emanspeaks Jan 4, 2024
efed76f
second attempt to fix regex warnings
emanspeaks Jan 4, 2024
c62ef0f
remove ambiguous define arg matching
emanspeaks Jan 4, 2024
107180d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 4, 2024
0ecc55d
additional support for Intel FPP
emanspeaks Jan 7, 2024
0de9e0e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 7, 2024
1ea9700
fix issue with json schema
emanspeaks Jan 7, 2024
755370e
addl logical operators for intel fpp
emanspeaks Jan 7, 2024
9b67c67
parse intel fpp operators separately
emanspeaks Jan 7, 2024
ad4de4c
init commit of cherry-picked changes from #341
emanspeaks Jan 21, 2024
5cf36e3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 21, 2024
6245d85
Merge branch 'generic-macro-expansions' into ifort-fpp-fixes
emanspeaks Jan 21, 2024
c975006
rebase intel-specific changes on top of PR #350
emanspeaks Jan 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ All the ``fortls`` settings with their default arguments can be found below
"pp_suffixes": [],
"include_dirs": [],
"pp_defs": {},
"pp_parse_intel": false,

"symbol_skip_mem": false,

Expand Down Expand Up @@ -198,6 +199,13 @@ Additional **preprocessor definitions** from what are specified in files found i

.. note:: Definitions in ``pp_defs`` will override definitions from ``include_dirs``

pp_parse_intel
**************

Parses Intel compiler directive defines and conditionals of the form
``!DEC$``, ``!DIR$``, ``CDIR$``, ``CDEC$``, ``*DIR$``, ``*DEC$``, or ``!MS$``.
Only defines, undefines, and if defined statements are evaluated.


Limitations
***********
Expand Down
9 changes: 8 additions & 1 deletion fortls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ def locate_config(root: str) -> str | None:
pp_suffixes = None
pp_defs = {}
include_dirs = set()
pp_parse_intel = False
if args.debug_rootpath:
# Check for config files
config_path = locate_config(args.debug_rootpath)
Expand All @@ -482,6 +483,7 @@ def locate_config(root: str) -> str | None:
config_dict = json.load(fhandle)
pp_suffixes = config_dict.get("pp_suffixes", None)
pp_defs = config_dict.get("pp_defs", {})
pp_parse_intel = config_dict.get("pp_parse_intel", False)
include_dirs = set()
for path in config_dict.get("include_dirs", set()):
include_dirs.update(
Expand All @@ -501,7 +503,12 @@ def locate_config(root: str) -> str | None:
error_exit(f"Reading file failed: {err_str}")
print(f" Detected format: {'fixed' if file_obj.fixed else 'free'}")
print("\n=========\nParser Output\n=========\n")
file_ast = file_obj.parse(debug=True, pp_defs=pp_defs, include_dirs=include_dirs)
file_ast = file_obj.parse(
debug=True,
pp_defs=pp_defs,
include_dirs=include_dirs,
pp_parse_intel=pp_parse_intel,
)
print("\n=========\nObject Tree\n=========\n")
for obj in file_ast.get_scopes():
print("{}: {}".format(obj.get_type(), obj.FQSN))
Expand Down
6 changes: 6 additions & 0 deletions fortls/fortls.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@
"default": {},
"type": "object"
},
"pp_parse_intel": {
"title": "Pp Parse Intel",
"description": "Parses Intel compiler directive defines and conditionals.",
"default": false,
"type": "boolean"
},
"symbol_skip_mem": {
"title": "Symbol Skip Mem",
"description": "Do not include type members in document symbol results",
Expand Down
5 changes: 5 additions & 0 deletions fortls/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ def cli(name: str = "fortls") -> argparse.ArgumentParser:
"Preprocessor definitions are normally included via INCLUDE_DIRS"
),
)
group.add_argument(
"--pp_parse_intel",
action="store_true",
help="Parses Intel compiler directive defines and conditionals.",
)

# Symbols options ----------------------------------------------------------
group = parser.add_argument_group("Symbols options")
Expand Down
28 changes: 24 additions & 4 deletions fortls/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,11 +751,18 @@
return None
# Search in Preprocessor defined variables
if def_name in def_file.pp_defs:
def_value = def_file.pp_defs.get(def_name)
def_arg_str = ""
if isinstance(def_value, tuple):
def_arg_str, def_value = def_value
def_arg_str = ", ".join([x.strip() for x in def_arg_str.split(",")])
def_arg_str = f"({def_arg_str})"

var = Variable(
def_file.ast,
def_line + 1,
def_name,
f"#define {def_name} {def_file.pp_defs.get(def_name)}",
f"#define {def_name}{def_arg_str} {def_value}",
[],
)
return var
Expand Down Expand Up @@ -1316,7 +1323,9 @@
# Update inheritance (currently file only)
# tmp_file.ast.resolve_links(self.obj_tree, self.link_version)
elif file_obj.preproc:
file_obj.preprocess(pp_defs=self.pp_defs)
file_obj.preprocess(

Check warning on line 1326 in fortls/langserver.py

View check run for this annotation

Codecov / codecov/patch

fortls/langserver.py#L1326

Added line #L1326 was not covered by tests
pp_defs=self.pp_defs, pp_parse_intel=self.pp_parse_intel
)
self.pp_defs = {**self.pp_defs, **file_obj.pp_defs}

def serve_onOpen(self, request: dict):
Expand Down Expand Up @@ -1389,7 +1398,9 @@
if not file_changed:
return False, None
ast_new = file_obj.parse(
pp_defs=self.pp_defs, include_dirs=self.include_dirs
pp_defs=self.pp_defs,
include_dirs=self.include_dirs,
pp_parse_intel=self.pp_parse_intel,
)
# Add the included read in pp_defs from to the ones specified in the
# configuration file
Expand Down Expand Up @@ -1422,6 +1433,7 @@
pp_suffixes: list[str],
include_dirs: set[str],
sort: bool,
pp_parse_intel: bool,
):
"""Initialise a Fortran file

Expand All @@ -1437,6 +1449,8 @@
Preprocessor only include directories, not used by normal parser
sort : bool
Whether or not keywords should be sorted
pp_parse_intel : bool
Parse Intel FPP directives

Returns
-------
Expand All @@ -1453,7 +1467,11 @@
# This is a bypass.
# For more see on SO: shorturl.at/hwAG1
set_keyword_ordering(sort)
file_ast = file_obj.parse(pp_defs=pp_defs, include_dirs=include_dirs)
file_ast = file_obj.parse(
pp_defs=pp_defs,
include_dirs=include_dirs,
pp_parse_intel=pp_parse_intel,
)
except:
log.error("Error while parsing file %s", filepath, exc_info=True)
return "Error during parsing"
Expand All @@ -1476,6 +1494,7 @@
self.pp_suffixes,
self.include_dirs,
self.sort_keywords,
self.pp_parse_intel,
),
)
pool.close()
Expand Down Expand Up @@ -1632,6 +1651,7 @@
def _load_config_file_preproc(self, config_dict: dict) -> None:
self.pp_suffixes = config_dict.get("pp_suffixes", None)
self.pp_defs = config_dict.get("pp_defs", {})
self.pp_parse_intel = config_dict.get("pp_parse_intel", False)
if isinstance(self.pp_defs, list):
self.pp_defs = {key: "" for key in self.pp_defs}

Expand Down
Loading