Skip to content

Commit ba5e479

Browse files
authored
Merge pull request #111 from gnikit/gnikit/issue109
Rename Fortran classes used for AST
2 parents c986bb4 + cb49437 commit ba5e479

13 files changed

+345
-215
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Added
88

9+
- Added multiple unittests for diagnostic messages
910
- Added `pre-commit` hook to the project
1011
([#106](https://github.com/gnikit/fortls/issues/106))
1112
- Added Code of Conduct
@@ -14,6 +15,8 @@
1415

1516
### Changed
1617

18+
- Changed the naming convention for Fortran Objects
19+
([#109](https://github.com/gnikit/fortls/issues/109))
1720
- Formatted all files with `pre-commit`
1821

1922
## 2.3.1

fortls/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .interface import commandline_args
1111
from .jsonrpc import JSONRPC2Connection, ReadWriter, path_from_uri
1212
from .langserver import LangServer
13-
from .parse_fortran import fortran_file
13+
from .parse_fortran import FortranFile
1414
from .version import __version__
1515

1616
__all__ = ["__version__"]
@@ -484,7 +484,7 @@ def debug_server_parser(args):
484484
#
485485
print("\nTesting parser")
486486
print(' File = "{}"'.format(args.debug_filepath))
487-
file_obj = fortran_file(args.debug_filepath, pp_suffixes)
487+
file_obj = FortranFile(args.debug_filepath, pp_suffixes)
488488
err_str, _ = file_obj.load_from_disk()
489489
if err_str:
490490
error_exit(f"Reading file failed: {err_str}")

fortls/ftypes.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
@dataclass
11-
class VAR_info:
11+
class VarInfo:
1212
"""Holds information about a Fortran VARIABLE"""
1313

1414
var_type: str #: Type of variable e.g. ``INTEGER``, ``REAL``, etc.
@@ -18,7 +18,7 @@ class VAR_info:
1818

1919

2020
@dataclass
21-
class SELECT_info:
21+
class SelectInfo:
2222
"""Holds information about a SELECT construct"""
2323

2424
type: int #: Type of SELECT e.g. normal, select type, select kind, select rank
@@ -27,7 +27,7 @@ class SELECT_info:
2727

2828

2929
@dataclass
30-
class CLASS_info:
30+
class ClassInfo:
3131
"""Holds information about a Fortran CLASS"""
3232

3333
name: str #: Class name
@@ -36,7 +36,7 @@ class CLASS_info:
3636

3737

3838
@dataclass
39-
class USE_info:
39+
class UseInfo:
4040
"""Holds information about a Fortran USE statement"""
4141

4242
mod_name: str #: Module name
@@ -47,7 +47,7 @@ class USE_info:
4747

4848

4949
@dataclass
50-
class GEN_info:
50+
class GenProcDefInfo:
5151
"""Holds information about a GENERIC PROCEDURE DEFINITION"""
5252

5353
bound_name: str #: Procedure name
@@ -56,31 +56,31 @@ class GEN_info:
5656

5757

5858
@dataclass
59-
class SMOD_info:
59+
class SmodInfo:
6060
"""Holds information about Fortran SUBMODULES"""
6161

6262
name: str #: Submodule name
6363
parent: str #: Submodule i.e. module, parent
6464

6565

6666
@dataclass
67-
class INT_info:
67+
class InterInfo:
6868
"""Holds information about a Fortran INTERFACE"""
6969

7070
name: str #: Interface name
7171
abstract: bool #: Whether or not the interface is abstract
7272

7373

7474
@dataclass
75-
class VIS_info:
75+
class VisInfo:
7676
"""Holds information about the VISIBILITY of a module's contents"""
7777

7878
type: int #: Visibility type 0: PUBLIC 1: PRIVATE TODO: convert to boolean
7979
obj_names: list[str] #: Module variables, procedures, etc. with that visibility
8080

8181

8282
@dataclass
83-
class INCLUDE_info:
83+
class IncludeInfo:
8484
"""Holds information about a Fortran INCLUDE statement"""
8585

8686
line_number: int #: Line number of include
@@ -90,7 +90,7 @@ class INCLUDE_info:
9090

9191

9292
@dataclass
93-
class SUB_info:
93+
class SubInfo:
9494
"""Holds information about a Fortran SUBROUTINE"""
9595

9696
name: str #: Procedure name
@@ -102,7 +102,7 @@ class SUB_info:
102102

103103

104104
@dataclass
105-
class RESULT_sig:
105+
class ResultSig:
106106
"""Holds information about the RESULT section of a Fortran FUNCTION"""
107107

108108
name: str = field(default=None) #: Variable name of result
@@ -112,11 +112,11 @@ class RESULT_sig:
112112

113113

114114
@dataclass
115-
class FUN_sig(SUB_info):
115+
class FunSig(SubInfo):
116116
"""Holds information about a Fortran FUNCTION"""
117117

118118
#: Function's result with default ``result.name = name``
119-
result: RESULT_sig = field(default_factory=RESULT_sig)
119+
result: ResultSig = field(default_factory=ResultSig)
120120

121121
def __post_init__(self):
122122
if not self.result.name:

fortls/intrinsics.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
from fortls.helper_functions import map_keywords
55
from fortls.objects import (
6-
fortran_ast,
7-
fortran_function,
8-
fortran_module,
9-
fortran_obj,
10-
fortran_subroutine,
11-
fortran_type,
12-
fortran_var,
6+
FortranAST,
7+
FortranObj,
8+
Function,
9+
Module,
10+
Subroutine,
11+
Type,
12+
Variable,
1313
)
1414

15-
none_ast = fortran_ast()
15+
none_ast = FortranAST()
1616
lowercase_intrinsics = False
1717

1818

@@ -21,7 +21,7 @@ def set_lowercase_intrinsics():
2121
lowercase_intrinsics = True
2222

2323

24-
class fortran_intrinsic_obj(fortran_obj):
24+
class Intrinsic(FortranObj):
2525
def __init__(self, name, type, doc_str=None, args="", parent=None):
2626
self.name = name
2727
self.type = type
@@ -87,7 +87,7 @@ def create_int_object(name, json_obj, type):
8787
if lowercase_intrinsics:
8888
name = name.lower()
8989
args = args.lower()
90-
return fortran_intrinsic_obj(name, type, doc_str=doc_str, args=args)
90+
return Intrinsic(name, type, doc_str=doc_str, args=args)
9191

9292
def create_object(json_obj, enc_obj=None):
9393
if enc_obj is not None:
@@ -105,14 +105,14 @@ def create_object(json_obj, enc_obj=None):
105105
name = name.lower()
106106
args = args.lower()
107107
if json_obj["type"] == 0:
108-
mod_tmp = fortran_module(none_ast, 0, name)
108+
mod_tmp = Module(none_ast, 0, name)
109109
if "use" in json_obj:
110110
mod_tmp.add_use(json_obj["use"], 0)
111111
return mod_tmp
112112
elif json_obj["type"] == 1:
113-
return fortran_subroutine(none_ast, 0, name, args=args)
113+
return Subroutine(none_ast, 0, name, args=args)
114114
elif json_obj["type"] == 2:
115-
return fortran_function(
115+
return Function(
116116
none_ast,
117117
0,
118118
name,
@@ -122,11 +122,9 @@ def create_object(json_obj, enc_obj=None):
122122
# keyword_info=keyword_info,
123123
)
124124
elif json_obj["type"] == 3:
125-
return fortran_var(
126-
none_ast, 0, name, json_obj["desc"], keywords, keyword_info
127-
)
125+
return Variable(none_ast, 0, name, json_obj["desc"], keywords, keyword_info)
128126
elif json_obj["type"] == 4:
129-
return fortran_type(none_ast, 0, name, keywords)
127+
return Type(none_ast, 0, name, keywords)
130128
else:
131129
raise ValueError
132130

fortls/langserver.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@
4141
set_keyword_ordering,
4242
)
4343
from fortls.intrinsics import (
44-
fortran_intrinsic_obj,
44+
Intrinsic,
4545
get_intrinsic_keywords,
4646
load_intrinsics,
4747
set_lowercase_intrinsics,
4848
)
4949
from fortls.json_templates import change_json, symbol_json, uri_json
5050
from fortls.jsonrpc import JSONRPC2Connection, path_from_uri, path_to_uri
5151
from fortls.objects import (
52+
FortranAST,
53+
Variable,
5254
climb_type_tree,
5355
find_in_scope,
5456
find_in_workspace,
55-
fortran_ast,
56-
fortran_var,
5757
get_use_tree,
5858
)
59-
from fortls.parse_fortran import fortran_file, get_line_context
59+
from fortls.parse_fortran import FortranFile, get_line_context
6060
from fortls.regex_patterns import src_file_exts
6161
from fortls.version import __version__
6262

@@ -70,7 +70,7 @@ def __init__(self, conn, settings: dict):
7070
self.conn: JSONRPC2Connection = conn
7171
self.running: bool = True
7272
self.root_path: str = None
73-
self.workspace: dict[str, fortran_file] = {}
73+
self.workspace: dict[str, FortranFile] = {}
7474
self.obj_tree: dict = {}
7575
self.link_version = 0
7676
self._version = version.parse(__version__)
@@ -496,7 +496,7 @@ def build_comp(
496496
params: dict = request["params"]
497497
uri: str = params["textDocument"]["uri"]
498498
path: str = path_from_uri(uri)
499-
file_obj: fortran_file = self.workspace.get(path)
499+
file_obj: FortranFile = self.workspace.get(path)
500500
if file_obj is None:
501501
return None
502502
# Check line
@@ -673,7 +673,7 @@ def build_comp(
673673

674674
def get_definition(
675675
self,
676-
def_file: fortran_file,
676+
def_file: FortranFile,
677677
def_line: int,
678678
def_char: int,
679679
hover_req: bool = False,
@@ -716,7 +716,7 @@ def get_definition(
716716
return None
717717
# Search in Preprocessor defined variables
718718
if def_name in def_file.pp_defs:
719-
var = fortran_var(
719+
var = Variable(
720720
def_file.ast,
721721
def_line + 1,
722722
def_name,
@@ -778,7 +778,7 @@ def get_definition(
778778
):
779779
var_type = f"{FORTRAN_LITERAL}STRING"
780780
if var_type:
781-
return fortran_var(
781+
return Variable(
782782
curr_scope.file_ast,
783783
def_line + 1,
784784
def_name,
@@ -897,7 +897,7 @@ def get_all_references(
897897
self,
898898
def_obj,
899899
type_mem: bool,
900-
file_obj: fortran_file = None,
900+
file_obj: FortranFile = None,
901901
):
902902
# Search through all files
903903
def_name: str = def_obj.name.lower()
@@ -1124,7 +1124,7 @@ def serve_implementation(self, request: dict):
11241124
if var_obj is None:
11251125
return None
11261126
# Intrinsics do not have implementations we can access
1127-
if isinstance(var_obj, fortran_intrinsic_obj):
1127+
if isinstance(var_obj, Intrinsic):
11281128
return None
11291129
# Construct implementation reference
11301130
if var_obj.parent.get_type() == CLASS_TYPE_ID:
@@ -1147,7 +1147,7 @@ def serve_rename(self, request: dict):
11471147
def_obj = self.get_definition(file_obj, def_line, def_char)
11481148
if def_obj is None:
11491149
return None
1150-
if isinstance(def_obj, fortran_intrinsic_obj):
1150+
if isinstance(def_obj, Intrinsic):
11511151
self.post_message("Rename failed: Cannot rename intrinsics", Severity.warn)
11521152
return None
11531153
# Determine global accesibility and type membership
@@ -1335,11 +1335,11 @@ def update_workspace_file(
13351335
file_obj = self.workspace.get(filepath)
13361336
if read_file:
13371337
if file_obj is None:
1338-
file_obj = fortran_file(filepath, self.pp_suffixes)
1338+
file_obj = FortranFile(filepath, self.pp_suffixes)
13391339
# Create empty file if not yet saved to disk
13401340
if not os.path.isfile(filepath):
13411341
if allow_empty:
1342-
file_obj.ast = fortran_ast(file_obj)
1342+
file_obj.ast = FortranAST(file_obj)
13431343
self.workspace[filepath] = file_obj
13441344
return False, None
13451345
else:
@@ -1405,7 +1405,7 @@ def file_init(
14051405
fortran_file | str
14061406
A Fortran file object or a string containing the error message
14071407
"""
1408-
file_obj = fortran_file(filepath, pp_suffixes)
1408+
file_obj = FortranFile(filepath, pp_suffixes)
14091409
err_str, _ = file_obj.load_from_disk()
14101410
if err_str:
14111411
return err_str
@@ -1704,7 +1704,7 @@ def _load_intrinsics(self) -> None:
17041704

17051705
def _create_ref_link(self, obj) -> dict:
17061706
"""Create a link reference to an object"""
1707-
obj_file: fortran_file = obj.file_ast.file
1707+
obj_file: FortranFile = obj.file_ast.file
17081708
sline, (schar, echar) = obj_file.find_word_in_code_line(obj.sline - 1, obj.name)
17091709
if schar < 0:
17101710
schar = echar = 0

0 commit comments

Comments
 (0)