Skip to content

Commit 4f49de1

Browse files
authored
Merge pull request #2005 from strictdoc-project/stanislaw/source_code_cleanup
Code climate: backend/sdoc_source_code: rename parts -> functions
2 parents 4a0f59a + 48fed23 commit 4f49de1

File tree

8 files changed

+36
-45
lines changed

8 files changed

+36
-45
lines changed

strictdoc/backend/sdoc_source_code/grammar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SOURCE_FILE_GRAMMAR = """
22
SourceFileTraceabilityInfo[noskipws]:
3-
parts += Part
3+
g_parts += Part
44
;
55
66
Part[noskipws]:

strictdoc/backend/sdoc_source_code/models/function.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ def __init__(
1515
name: str,
1616
line_begin: int,
1717
line_end: int,
18-
parts: List[Any],
18+
child_functions: List[Any],
1919
markers: List[FunctionRangeMarker],
2020
attributes: Set[FunctionAttribute],
2121
):
2222
assert parent is not None
2323
self.parent = parent
2424
self.name = name
25-
self.parts: List[Any] = parts
25+
# Child functions are supported in programming languages that can nest
26+
# functions, for example, Python.
27+
self.child_functions: List[Function] = child_functions
2628
self.markers: List[FunctionRangeMarker] = markers
2729
self.line_begin = line_begin
2830
self.line_end = line_end

strictdoc/backend/sdoc_source_code/models/source_file_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
@auto_described
1717
class SourceFileTraceabilityInfo:
18-
def __init__(self, parts: List):
18+
def __init__(self, g_parts: List):
1919
"""
2020
At the init time, only the backward RangeMarkers are available from
2121
a source file. At runtime, the ForwardRangeMarkers are mixed in
2222
from the Requirement/FileReference links. This is why the .markers
2323
is a union.
2424
"""
2525

26-
self.parts: List = parts
26+
self.g_parts: List = g_parts
2727
self.functions: List[Function] = []
2828

2929
"""

strictdoc/backend/sdoc_source_code/reader_c.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ def read(
152152
traceability_info.markers.append(
153153
function_range_marker_
154154
)
155-
traceability_info.parts.append(
156-
function_range_marker_
157-
)
158155
function_markers.append(marker_)
159156

160157
# The function range includes the top comment if it exists.
@@ -165,7 +162,7 @@ def read(
165162
if function_comment_node is not None
166163
else node_.range.start_point[0] + 1,
167164
line_end=node_.range.end_point[0] + 1,
168-
parts=[],
165+
child_functions=[],
169166
markers=function_markers,
170167
attributes=function_attributes,
171168
)
@@ -215,9 +212,6 @@ def read(
215212
traceability_info.markers.append(
216213
function_range_marker_
217214
)
218-
traceability_info.parts.append(
219-
function_range_marker_
220-
)
221215
function_markers.append(marker_)
222216

223217
# The function range includes the top comment if it exists.
@@ -228,7 +222,7 @@ def read(
228222
if function_comment_node is not None
229223
else node_.range.start_point[0] + 1,
230224
line_end=node_.range.end_point[0] + 1,
231-
parts=[],
225+
child_functions=[],
232226
markers=function_markers,
233227
attributes={FunctionAttribute.DEFINITION},
234228
)
@@ -260,12 +254,10 @@ def read(
260254
range_marker_ := marker_
261255
):
262256
range_marker_processor(range_marker_, parse_context)
263-
traceability_info.parts.append(range_marker_)
264257
elif isinstance(marker_, LineMarker) and (
265258
line_marker_ := marker_
266259
):
267260
line_marker_processor(line_marker_, parse_context)
268-
traceability_info.parts.append(line_marker_)
269261
else:
270262
continue
271263
else:

strictdoc/backend/sdoc_source_code/reader_python.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def read(
6666
name="module",
6767
line_begin=node_.start_point[0] + 1,
6868
line_end=node_.end_point[0] + 1,
69-
parts=[],
69+
child_functions=[],
7070
markers=[],
7171
attributes=set(),
7272
)
@@ -189,7 +189,7 @@ def read(
189189
name=function_name,
190190
line_begin=node_.range.start_point[0] + 1,
191191
line_end=node_.range.end_point[0] + 1,
192-
parts=[],
192+
child_functions=[],
193193
# Python functions do not need to track markers.
194194
markers=[],
195195
attributes=set(),
@@ -198,7 +198,7 @@ def read(
198198

199199
parent_function = functions_stack[-1]
200200

201-
parent_function.parts.append(new_function)
201+
parent_function.child_functions.append(new_function)
202202
functions_stack.append(new_function)
203203
traceability_info.functions.append(new_function)
204204
elif node_.type == "comment":
@@ -236,8 +236,6 @@ def read(
236236
or functions_stack[0].name == "translation_unit"
237237
)
238238

239-
traceability_info.parts = functions_stack[0].parts
240-
241239
source_file_traceability_info_processor(
242240
traceability_info, parse_context
243241
)

tests/unit/strictdoc/backend/sdoc_source_code/test_dsl_source_file_syntax.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def test_010_nosdoc_keyword():
214214
reader = SourceFileTraceabilityReader()
215215

216216
document = reader.read(source_input)
217-
assert len(document.parts) == 7
217+
assert len(document.g_parts) == 7
218218
assert len(document.markers) == 0
219219

220220

@@ -237,7 +237,7 @@ def test_011_nosdoc_keyword_then_normal_marker():
237237
reader = SourceFileTraceabilityReader()
238238

239239
document = reader.read(source_input)
240-
assert len(document.parts) == 12
240+
assert len(document.g_parts) == 12
241241
assert len(document.markers) == 2
242242

243243

@@ -260,7 +260,7 @@ def test_011_nosdoc_keyword_then_normal_marker_4spaces_indent():
260260
reader = SourceFileTraceabilityReader()
261261

262262
document = reader.read(source_input)
263-
assert len(document.parts) == 12
263+
assert len(document.g_parts) == 12
264264
assert len(document.markers) == 2
265265

266266

tests/unit/strictdoc/backend/sdoc_source_code/test_dsl_source_file_syntax_c.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_01_single_string():
3838
info = reader.read(input_string)
3939

4040
assert isinstance(info, SourceFileTraceabilityInfo)
41-
assert len(info.parts) == 0
41+
assert len(info.functions) == 0
4242
assert len(info.markers) == 0
4343

4444

@@ -72,7 +72,6 @@ def test_02_functions():
7272
)
7373

7474
assert isinstance(info, SourceFileTraceabilityInfo)
75-
assert len(info.parts) == 2
7675
assert len(info.markers) == 2
7776
assert info.markers[0].ng_source_line_begin == 3
7877
assert info.markers[0].ng_range_line_begin == 3

tests/unit/strictdoc/backend/sdoc_source_code/test_dsl_source_file_syntax_python.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_01_single_string():
3939
info = reader.read(input_string)
4040

4141
assert isinstance(info, SourceFileTraceabilityInfo)
42-
assert len(info.parts) == 0
42+
assert len(info.functions) == 0
4343
assert len(info.markers) == 0
4444

4545

@@ -79,52 +79,52 @@ def hello_3_1_1():
7979
info: SourceFileTraceabilityInfo = reader.read(input_string)
8080

8181
assert isinstance(info, SourceFileTraceabilityInfo)
82-
assert len(info.parts) == 3
82+
assert len(info.functions) == 9
8383

84-
function_1 = info.parts[0]
84+
function_1 = info.functions[0]
8585
assert isinstance(function_1, Function)
8686
assert function_1.name == "hello_1"
87-
assert len(function_1.parts) == 1
87+
assert len(function_1.child_functions) == 1
8888

89-
function_1_1 = function_1.parts[0]
89+
function_1_1 = function_1.child_functions[0]
9090
assert isinstance(function_1_1, Function)
9191
assert function_1_1.name == "hello_1_1"
92-
assert len(function_1_1.parts) == 1
92+
assert len(function_1_1.child_functions) == 1
9393

94-
function_1_1_1 = function_1_1.parts[0]
94+
function_1_1_1 = function_1_1.child_functions[0]
9595
assert isinstance(function_1_1_1, Function)
9696
assert function_1_1_1.name == "hello_1_1_1"
97-
assert len(function_1_1_1.parts) == 0
97+
assert len(function_1_1_1.child_functions) == 0
9898

99-
function_2 = info.parts[1]
99+
function_2 = info.functions[3]
100100
assert isinstance(function_2, Function)
101101
assert function_2.name == "hello_2"
102-
assert len(function_2.parts) == 1
102+
assert len(function_2.child_functions) == 1
103103

104-
function_2_1 = function_2.parts[0]
104+
function_2_1 = function_2.child_functions[0]
105105
assert isinstance(function_2_1, Function)
106106
assert function_2_1.name == "hello_2_1"
107-
assert len(function_2_1.parts) == 1
107+
assert len(function_2_1.child_functions) == 1
108108

109-
function_2_1_1 = function_2_1.parts[0]
109+
function_2_1_1 = function_2_1.child_functions[0]
110110
assert isinstance(function_2_1_1, Function)
111111
assert function_2_1_1.name == "hello_2_1_1"
112-
assert len(function_2_1_1.parts) == 0
112+
assert len(function_2_1_1.child_functions) == 0
113113

114-
function_3 = info.parts[2]
114+
function_3 = info.functions[6]
115115
assert isinstance(function_3, Function)
116116
assert function_3.name == "hello_3"
117-
assert len(function_3.parts) == 1
117+
assert len(function_3.child_functions) == 1
118118

119-
function_3_1 = function_3.parts[0]
119+
function_3_1 = function_3.child_functions[0]
120120
assert isinstance(function_3_1, Function)
121121
assert function_3_1.name == "hello_3_1"
122-
assert len(function_3_1.parts) == 1
122+
assert len(function_3_1.child_functions) == 1
123123

124-
function_3_1_1 = function_3_1.parts[0]
124+
function_3_1_1 = function_3_1.child_functions[0]
125125
assert isinstance(function_3_1_1, Function)
126126
assert function_3_1_1.name == "hello_3_1_1"
127-
assert len(function_3_1_1.parts) == 0
127+
assert len(function_3_1_1.child_functions) == 0
128128

129129

130130
def test_001_one_range_marker():

0 commit comments

Comments
 (0)