Coverage for skema/program_analysis/CAST/fortran/util.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-30 17:15 +0000

1from typing import List 

2from skema.program_analysis.CAST2FN.model.cast import AstNode, CASTLiteralValue, SourceRef 

3 

4DUMMY_SOURCE_REF = [SourceRef("", -1, -1, -1, -1)] 

5DUMMY_SOURCE_CODE_DATA_TYPE = ["Fortran", "Fotran95", "None"] 

6 

7def generate_dummy_source_refs(node: AstNode) -> AstNode: 

8 """Walks a tree of AstNodes replacing any null SourceRefs with a dummy value""" 

9 if isinstance(node, CASTLiteralValue) and not node.source_code_data_type: 

10 node.source_code_data_type = DUMMY_SOURCE_CODE_DATA_TYPE 

11 if not node.source_refs: 

12 node.source_refs = DUMMY_SOURCE_REF 

13 

14 for attribute_str in node.attribute_map: 

15 attribute = getattr(node, attribute_str) 

16 if isinstance(attribute, AstNode): 

17 generate_dummy_source_refs(attribute) 

18 elif isinstance(attribute, List): 

19 for element in attribute: 

20 if isinstance(element, AstNode): 

21 generate_dummy_source_refs(element) 

22 

23 return node 

24