Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion strictdoc/backend/sdoc_source_code/grammar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SOURCE_FILE_GRAMMAR = """
SourceFileTraceabilityInfo[noskipws]:
parts += Part
g_parts += Part
;

Part[noskipws]:
Expand Down
6 changes: 4 additions & 2 deletions strictdoc/backend/sdoc_source_code/models/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ def __init__(
name: str,
line_begin: int,
line_end: int,
parts: List[Any],
child_functions: List[Any],
markers: List[FunctionRangeMarker],
attributes: Set[FunctionAttribute],
):
assert parent is not None
self.parent = parent
self.name = name
self.parts: List[Any] = parts
# Child functions are supported in programming languages that can nest
# functions, for example, Python.
self.child_functions: List[Function] = child_functions
self.markers: List[FunctionRangeMarker] = markers
self.line_begin = line_begin
self.line_end = line_end
Expand Down
4 changes: 2 additions & 2 deletions strictdoc/backend/sdoc_source_code/models/source_file_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

@auto_described
class SourceFileTraceabilityInfo:
def __init__(self, parts: List):
def __init__(self, g_parts: List):
"""
At the init time, only the backward RangeMarkers are available from
a source file. At runtime, the ForwardRangeMarkers are mixed in
from the Requirement/FileReference links. This is why the .markers
is a union.
"""

self.parts: List = parts
self.g_parts: List = g_parts
self.functions: List[Function] = []

"""
Expand Down
12 changes: 2 additions & 10 deletions strictdoc/backend/sdoc_source_code/reader_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ def read(
traceability_info.markers.append(
function_range_marker_
)
traceability_info.parts.append(
function_range_marker_
)
function_markers.append(marker_)

# The function range includes the top comment if it exists.
Expand All @@ -165,7 +162,7 @@ def read(
if function_comment_node is not None
else node_.range.start_point[0] + 1,
line_end=node_.range.end_point[0] + 1,
parts=[],
child_functions=[],
markers=function_markers,
attributes=function_attributes,
)
Expand Down Expand Up @@ -215,9 +212,6 @@ def read(
traceability_info.markers.append(
function_range_marker_
)
traceability_info.parts.append(
function_range_marker_
)
function_markers.append(marker_)

# The function range includes the top comment if it exists.
Expand All @@ -228,7 +222,7 @@ def read(
if function_comment_node is not None
else node_.range.start_point[0] + 1,
line_end=node_.range.end_point[0] + 1,
parts=[],
child_functions=[],
markers=function_markers,
attributes={FunctionAttribute.DEFINITION},
)
Expand Down Expand Up @@ -260,12 +254,10 @@ def read(
range_marker_ := marker_
):
range_marker_processor(range_marker_, parse_context)
traceability_info.parts.append(range_marker_)
elif isinstance(marker_, LineMarker) and (
line_marker_ := marker_
):
line_marker_processor(line_marker_, parse_context)
traceability_info.parts.append(line_marker_)
else:
continue
else:
Expand Down
8 changes: 3 additions & 5 deletions strictdoc/backend/sdoc_source_code/reader_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def read(
name="module",
line_begin=node_.start_point[0] + 1,
line_end=node_.end_point[0] + 1,
parts=[],
child_functions=[],
markers=[],
attributes=set(),
)
Expand Down Expand Up @@ -189,7 +189,7 @@ def read(
name=function_name,
line_begin=node_.range.start_point[0] + 1,
line_end=node_.range.end_point[0] + 1,
parts=[],
child_functions=[],
# Python functions do not need to track markers.
markers=[],
attributes=set(),
Expand All @@ -198,7 +198,7 @@ def read(

parent_function = functions_stack[-1]

parent_function.parts.append(new_function)
parent_function.child_functions.append(new_function)
functions_stack.append(new_function)
traceability_info.functions.append(new_function)
elif node_.type == "comment":
Expand Down Expand Up @@ -236,8 +236,6 @@ def read(
or functions_stack[0].name == "translation_unit"
)

traceability_info.parts = functions_stack[0].parts

source_file_traceability_info_processor(
traceability_info, parse_context
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_010_nosdoc_keyword():
reader = SourceFileTraceabilityReader()

document = reader.read(source_input)
assert len(document.parts) == 7
assert len(document.g_parts) == 7
assert len(document.markers) == 0


Expand All @@ -237,7 +237,7 @@ def test_011_nosdoc_keyword_then_normal_marker():
reader = SourceFileTraceabilityReader()

document = reader.read(source_input)
assert len(document.parts) == 12
assert len(document.g_parts) == 12
assert len(document.markers) == 2


Expand All @@ -260,7 +260,7 @@ def test_011_nosdoc_keyword_then_normal_marker_4spaces_indent():
reader = SourceFileTraceabilityReader()

document = reader.read(source_input)
assert len(document.parts) == 12
assert len(document.g_parts) == 12
assert len(document.markers) == 2


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_01_single_string():
info = reader.read(input_string)

assert isinstance(info, SourceFileTraceabilityInfo)
assert len(info.parts) == 0
assert len(info.functions) == 0
assert len(info.markers) == 0


Expand Down Expand Up @@ -72,7 +72,6 @@ def test_02_functions():
)

assert isinstance(info, SourceFileTraceabilityInfo)
assert len(info.parts) == 2
assert len(info.markers) == 2
assert info.markers[0].ng_source_line_begin == 3
assert info.markers[0].ng_range_line_begin == 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_01_single_string():
info = reader.read(input_string)

assert isinstance(info, SourceFileTraceabilityInfo)
assert len(info.parts) == 0
assert len(info.functions) == 0
assert len(info.markers) == 0


Expand Down Expand Up @@ -79,52 +79,52 @@ def hello_3_1_1():
info: SourceFileTraceabilityInfo = reader.read(input_string)

assert isinstance(info, SourceFileTraceabilityInfo)
assert len(info.parts) == 3
assert len(info.functions) == 9

function_1 = info.parts[0]
function_1 = info.functions[0]
assert isinstance(function_1, Function)
assert function_1.name == "hello_1"
assert len(function_1.parts) == 1
assert len(function_1.child_functions) == 1

function_1_1 = function_1.parts[0]
function_1_1 = function_1.child_functions[0]
assert isinstance(function_1_1, Function)
assert function_1_1.name == "hello_1_1"
assert len(function_1_1.parts) == 1
assert len(function_1_1.child_functions) == 1

function_1_1_1 = function_1_1.parts[0]
function_1_1_1 = function_1_1.child_functions[0]
assert isinstance(function_1_1_1, Function)
assert function_1_1_1.name == "hello_1_1_1"
assert len(function_1_1_1.parts) == 0
assert len(function_1_1_1.child_functions) == 0

function_2 = info.parts[1]
function_2 = info.functions[3]
assert isinstance(function_2, Function)
assert function_2.name == "hello_2"
assert len(function_2.parts) == 1
assert len(function_2.child_functions) == 1

function_2_1 = function_2.parts[0]
function_2_1 = function_2.child_functions[0]
assert isinstance(function_2_1, Function)
assert function_2_1.name == "hello_2_1"
assert len(function_2_1.parts) == 1
assert len(function_2_1.child_functions) == 1

function_2_1_1 = function_2_1.parts[0]
function_2_1_1 = function_2_1.child_functions[0]
assert isinstance(function_2_1_1, Function)
assert function_2_1_1.name == "hello_2_1_1"
assert len(function_2_1_1.parts) == 0
assert len(function_2_1_1.child_functions) == 0

function_3 = info.parts[2]
function_3 = info.functions[6]
assert isinstance(function_3, Function)
assert function_3.name == "hello_3"
assert len(function_3.parts) == 1
assert len(function_3.child_functions) == 1

function_3_1 = function_3.parts[0]
function_3_1 = function_3.child_functions[0]
assert isinstance(function_3_1, Function)
assert function_3_1.name == "hello_3_1"
assert len(function_3_1.parts) == 1
assert len(function_3_1.child_functions) == 1

function_3_1_1 = function_3_1.parts[0]
function_3_1_1 = function_3_1.child_functions[0]
assert isinstance(function_3_1_1, Function)
assert function_3_1_1.name == "hello_3_1_1"
assert len(function_3_1_1.parts) == 0
assert len(function_3_1_1.child_functions) == 0


def test_001_one_range_marker():
Expand Down
Loading