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 7 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
11 changes: 7 additions & 4 deletions fortls/regex_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@
FREE_FORMAT_TEST: Pattern = compile(r"[ ]{1,4}[a-z]", I)
# Preprocessor matching rules
DEFINED: Pattern = compile(r"defined[ ]*\(?[ ]*([a-z_]\w*)[ ]*\)?", I)
PP_REGEX: Pattern = compile(r"#(if |ifdef|ifndef|else|elif|endif)")
PP_DEF: Pattern = compile(r"#(define|undef)[ ]*([\w]+)(\((\w+(,[ ]*)?)+\))?", I)
PP_REGEX: Pattern = compile(r"#\s*(if |ifdef|ifndef|else|elif|endif)")
PP_DEF: Pattern = compile(
r"#\s*(define|undef)\s*(\w+)(\(\s*(\w+\s*,?[\s\w,]*)*\s*\))?",
Fixed Show fixed Hide fixed
I,
)
PP_DEF_TEST: Pattern = compile(r"(![ ]*)?defined[ ]*\([ ]*(\w*)[ ]*\)$", I)
PP_INCLUDE: Pattern = compile(r"#include[ ]*([\"\w\.]*)", I)
PP_ANY: Pattern = compile(r"(^#:?\w+)")
PP_INCLUDE: Pattern = compile(r"#\s*include\s*([\"\w\.]*)", I)
PP_ANY: Pattern = compile(r"(^\s*#\s*\w*:?\w+)")
# Context matching rules
CALL: Pattern = compile(r"[ ]*CALL[ ]+[\w%]*$", I)
INT_STMNT: Pattern = compile(r"^[ ]*[a-z]*$", I)
Expand Down
3 changes: 2 additions & 1 deletion test/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def test_version_update_pypi():
s = LangServer(conn=JSONRPC2Connection(ReadWriter(stdin, stdout)), settings=args)
s.root_path = (Path(__file__).parent / "test_source").resolve()
did_update = s._update_version_pypi(test=True)
assert did_update
isconda = os.path.exists(os.path.join(sys.prefix, "conda-meta"))
assert not did_update if isconda else did_update

s.disable_autoupdate = True
did_update = s._update_version_pypi()
Expand Down
17 changes: 17 additions & 0 deletions test/test_preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def check_return(result_array, checks):
string += hover_req(file_path, 30, 23)
file_path = root_dir / "preproc_if_elif_skip.F90"
string += hover_req(file_path, 30, 23)
# file_path = root_dir / "preproc_spacing_arg_defs.F90"
# string += hover_req(file_path, 11, 20)
# string += hover_req(file_path, 19, 25)
config = str(root_dir / ".pp_conf.json")
errcode, results = run_request(string, ["--config", config])
assert errcode == 0
Expand All @@ -68,6 +71,20 @@ def check_return(result_array, checks):
"```fortran90\nINTEGER, PARAMETER :: res = 0+1+0+0\n```",
"```fortran90\nINTEGER, PARAMETER :: res = 0+0+0+1\n```",
"```fortran90\nINTEGER, PARAMETER :: res = 1+0+0+0\n```",
# "```fortran90\nPROCEDURE :: test_type_print_test\n```",
# "```fortran90\nINTEGER, PARAMETER :: argtest = me%test_int + 4\n```",
)
assert len(ref_results) == len(results) - 1
check_return(results[1:], ref_results)


def test_FortranFile_pp():
from fortls import FortranFile

root_dir = test_dir / "pp"
file_path = root_dir / "preproc.F90"
ff = FortranFile(file_path)
ff.load_from_disk()
include_dirs = {root_dir / "include"}
file_ast = ff.parse(include_dirs=include_dirs, debug=True)
assert file_ast
5 changes: 5 additions & 0 deletions test/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def test_workspace_symbols():
def check_return(result_array):
# Expected objects
objs = (
["argtest", 13, 19],
["test", 6, 7],
["test_abstract", 2, 0],
["test_associate_block", 2, 0],
Expand All @@ -196,7 +197,11 @@ def check_return(result_array):
["test_str1", 13, 5],
["test_str2", 13, 5],
["test_sub", 6, 8],
["test_type", 5, 5],
["test_type_set_test", 6, 22],
["test_vis_mod", 2, 0],
["the_test", 13, 15],
["wrap_test_type_set_test", 6, 30],
)
assert len(result_array) == len(objs)
for i, obj in enumerate(objs):
Expand Down
22 changes: 22 additions & 0 deletions test/test_source/pp/include/indent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
!! sample code adapted from json-fortran/json_macros.inc

# define SPACING_TEST
# define FILE_ENCODING ,encoding='UTF-8'

# ifdef __GFORTRAN__
! gfortran uses cpp in old-school compatibility mode so
! the # stringify and ## concatenate operators don't work
! but we can use C/C++ style comment to ensure PROCEDURE is
! correctly tokenized and prepended with 'wrap_' when the
! macro is expanded
# define MAYBEWRAP(PROCEDURE) PROCEDURE , wrap_/**/PROCEDURE
# else
! Intel's fpp does support the more contemporary ## concatenation
! operator, but doesn't treat the C/C++ comments the same way.
! If you use the gfortran approach and pass the -noB switch to
! fpp, the macro will expand, but with a space between wrap_ and
! whatever PROCEDURE expands to
# define MAYBEWRAP(PROCEDURE) PROCEDURE
# endif

# define MACROARGS( x , y ) x + y
39 changes: 39 additions & 0 deletions test/test_source/pp/preproc_spacing_arg_defs.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
program preprocessor_spacing_arg_defs
implicit none

#include "indent.h"

type :: test_type
private
integer, public :: test_int

contains
generic, public :: set_test => MAYBEWRAP(test_type_set_test)
procedure :: MAYBEWRAP(test_type_set_test)

end type test_type

type(test_type) :: the_test

call the_test%set_test()

integer, parameter :: argtest = MACROARGS(me%test_int, 4)

contains
subroutine test_type_set_test(me)
implicit none

class(test_type), intent(inout) :: me

me%test_int = 3
end subroutine test_type_set_test

subroutine wrap_test_type_set_test(me)
implicit none

class(test_type), intent(inout) :: me

me%test_int = 5
end subroutine wrap_test_type_set_test

end program preprocessor_spacing_arg_defs
Loading