Commit e5de981d authored by sparonuz's avatar sparonuz
Browse files

[run_@r14986]: Internal subrpogram declaration was not correctely parsed, then...

[run_@r14986]: Internal subrpogram declaration was not correctely parsed, then wrong index was returned by function find_first_use
parent 8782985c
...@@ -517,27 +517,28 @@ def find_first_use(variable): ...@@ -517,27 +517,28 @@ def find_first_use(variable):
indices = find_subprogram_lines(subprogram, module) indices = find_subprogram_lines(subprogram, module)
# Search for first use, avoiding subprogram declaration and end lines # Search for first use, avoiding subprogram declaration and end lines
# We will need to add indices[0] - 1 to the line_index return value since that's our starting index
for line_index, line in enumerate(module.lines[indices[0] + 1:indices[1]]): for line_index, line in enumerate(module.lines[indices[0] + 1:indices[1]]):
# Skip all declarations to avoids false positive that will block compilation. # Skip all declarations to avoids false positive that will block compilation.
if line.count("::") or line.lower().count("implicit none") or line.find("use ") == 0: if line.count("::") or line.lower().count("implicit none") or line.find("use ") == 0:
continue continue
# Scroll subprogram's lines searching for the first use # Scroll subprogram's lines searching for the first use
if re.search(RegexPattern.variable_name_occurrence % variable.name, line, re.IGNORECASE): if re.search(RegexPattern.name_occurrence % variable.name, line, re.IGNORECASE):
# Check the variable is not mentioned in a ".NOT.PRESENT" statement # Check the variable is not mentioned in a ".NOT.PRESENT" statement
if _check_if_condition(line, variable.name): if _check_if_condition(line, variable.name):
continue continue
# The variable is found # The variable is found
if where_level > 0: if where_level > 0:
# Inside a where statement # Inside a where statement
return module, indices[0] + where_statement_start return module, indices[0] + where_statement_start + 1
else: else:
# In a (nested) loop # In a (nested) loop
if loop_level > 0: if loop_level > 0:
return module, indices[0] + loop_start return module, indices[0] + loop_start + 1
# On a normal line # On a normal line
else: else:
return module, indices[0] + line_index return module, indices[0] + line_index + 1
# Whenever a 'do loop' starts increment nesting index # Whenever a 'do loop' starts increment nesting index
elif re.search(r"^ *do *[\w]* *=", line, re.IGNORECASE): elif re.search(r"^ *do *[\w]* *=", line, re.IGNORECASE):
if loop_level == 0: if loop_level == 0:
......
...@@ -35,7 +35,7 @@ def parse_sources(file_list, vault, extension): ...@@ -35,7 +35,7 @@ def parse_sources(file_list, vault, extension):
for index, module in enumerate(vault.modules): for index, module in enumerate(vault.modules):
find_interfaces(module, vault) find_interfaces(module, vault)
# # Fill vault variable list: # Fill vault variable list:
for procedures in vault.procedures_dictionary.values(): for procedures in vault.procedures_dictionary.values():
for proc in procedures: for proc in procedures:
if not isinstance(proc, BasicStructures.Interface): if not isinstance(proc, BasicStructures.Interface):
...@@ -135,7 +135,8 @@ def find_subprogram_declaration(module, _subprogram_start, _subprogram_end, obj_ ...@@ -135,7 +135,8 @@ def find_subprogram_declaration(module, _subprogram_start, _subprogram_end, obj_
# TODO: manage cases in which a routine contains other functions declarations. # TODO: manage cases in which a routine contains other functions declarations.
stop_index = [index stop_index = [index
for index, line in enumerate(module.lines[_subprogram_start:_subprogram_end + 1]) for index, line in enumerate(module.lines[_subprogram_start:_subprogram_end + 1])
if re.match(r"\bcontains\b", line, re.I) or re.match(r"\binterface\b", line, re.I)] if re.match(RegexPattern.name_occurrence % 'contains', line, re.I)
or re.match(RegexPattern.name_occurrence % 'interface', line, re.I)]
# A declaration found stop the search there # A declaration found stop the search there
if stop_index: if stop_index:
_subprogram_end = _subprogram_start - 1 + stop_index[0] _subprogram_end = _subprogram_start - 1 + stop_index[0]
...@@ -291,11 +292,11 @@ def find_subroutines(module, vault): ...@@ -291,11 +292,11 @@ def find_subroutines(module, vault):
used_modules, subprogram_type=BasicStructures.SubRoutine) used_modules, subprogram_type=BasicStructures.SubRoutine)
# Check if subroutines are defined inside this scope # Check if subroutines are defined inside this scope
subroutine_lines = module.lines[subroutine_start+1:subroutine_end-1] subroutine_lines = module.lines[subroutine_start+1:subroutine_end-1]
internal_sbr = [re.search(RegexPattern.subroutine_declaration, l, re.I) for l in subroutine_lines internal_subprogram = [re.search(RegexPattern.subprogram_declaration, l, re.I) for l in subroutine_lines
if re.search(RegexPattern.subroutine_declaration, l, re.I)] if re.search(RegexPattern.subprogram_declaration, l, re.I)]
if internal_sbr: if internal_subprogram:
sbr_names = [i_s.group(1) for i_s in internal_sbr] subprogram_names = [i_s.group(2) for i_s in internal_subprogram]
subroutine.declares = sbr_names subroutine.declares = subprogram_names
vault.add_procedure(subroutine) vault.add_procedure(subroutine)
......
...@@ -8,7 +8,7 @@ number_exp_DPE_notation = r'\s*\d+\.?\d*[e|d][+|-]*\d+[\w]*' ...@@ -8,7 +8,7 @@ number_exp_DPE_notation = r'\s*\d+\.?\d*[e|d][+|-]*\d+[\w]*'
#### VARIABLE #### VARIABLE
variable = r"^\w+$" variable = r"^\w+$"
variable_name_occurrence = r'\W*%s\W*' name_occurrence = r'\W*%s\W*'
#### ARRAY #### ARRAY
# Matches simple array, and sliced array # Matches simple array, and sliced array
array = r"\w+\s*\(\s*[\w,:\d\s+\-\*=]+\s*\)" array = r"\w+\s*\(\s*[\w,:\d\s+\-\*=]+\s*\)"
...@@ -82,7 +82,9 @@ pointers_assignation = r"(.*::|)\s*(.*)=>\s*(.*)" ...@@ -82,7 +82,9 @@ pointers_assignation = r"(.*::|)\s*(.*)=>\s*(.*)"
function_declaration = r'function\b(?!(?<=\bend function)\s*)\s+(\w+)' function_declaration = r'function\b(?!(?<=\bend function)\s*)\s+(\w+)'
end_function_declaration = r'^\s*end\s*function' end_function_declaration = r'^\s*end\s*function'
subprogram_declaration = r'(subroutine|function)\s+\w+\s*\(.*\)' # - group 1 => subprogram type
# - group 2 => subprogram name
subprogram_declaration = r'(subroutine|function)\s+(\w+)\s*\(.*\)'
subroutine_declaration = r'subroutine\b(?!(?<=\bend subroutine)\s*)\s+(\w+)' subroutine_declaration = r'subroutine\b(?!(?<=\bend subroutine)\s*)\s+(\w+)'
subprogram_name_declaration = r"((subroutine|function) +\b)%s\b" subprogram_name_declaration = r"((subroutine|function) +\b)%s\b"
subprogram_name_end_declaration = r"(end\s+(subroutine|function)\s+\b)%s\b" subprogram_name_end_declaration = r"(end\s+(subroutine|function)\s+\b)%s\b"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment