Commit df5bb2fe authored by erodrigu's avatar erodrigu
Browse files

Fixed error with hardcoded arrays and check for functions inside IF condition

parent 3b521007
......@@ -172,6 +172,9 @@ def get_type_of_contents(contents, procedure, vault):
if contents[0] == "-" or contents[0] == "+":
contents = contents[1:]
if contents.find("rpe_var(") == 0:
return "rpe_var"
if contents.lower()[0] in ["'", '"'] or contents.lower()[:4].strip() == 'trim':
return "char"
if contents.count("'") or contents.count("\""):
......
......@@ -418,15 +418,26 @@ class ImplementRPE:
line = self._fix_external_call(s_call, line)
return line
def _check_and_fix_call(self, line, serach_line, block):
subprogram_call = \
CallManager.get_procedure_inline(serach_line, self.vault, block)
# If something was found check if can be fixed
if subprogram_call:
temp = self._fix_arguments(line, subprogram_call)
return line.replace(serach_line, temp)
return line
def fix_subprogram_calls(self, module):
# Returns arguments of subprograms call and corresponding type and dummy
for _index, line in enumerate(module.lines):
# Returns arguments of subprograms call and corresponding type and dummy
subprogram_call = \
CallManager.get_procedure_inline(line, self.vault, module.blocks[_index])
# If something was found check if can be fixed
if subprogram_call:
module.lines[_index] = line.replace(line, self._fix_arguments(line, subprogram_call))
if line.replace(" ", "").lower().strip().find("if(") == 0:
line = self._check_and_fix_call(line, line, module.blocks[_index])
temporal_call = BasicFunctions.remove_if_condition(line)
line = self._check_and_fix_call(line, temporal_call, module.blocks[_index])
module.lines[_index] = line
def _find_kind_of_parameter_declaration(self, argument, procedure):
"""Return the nature of the parameter declaration. Depending on the type, the fix will be different"""
......
......@@ -268,7 +268,7 @@ def add_rpe_to_argument(argument, string):
# Check we are not casting more than once
if not string.count("rpe(" + argument + ")") == string.count(argument):
if NatureDeterminer.is_an_hardcoded_array(argument):
string = add_rpe_to_array_arguments(argument)
string = string.replace(argument, add_rpe_to_array_arguments(argument))
else:
string = replace_variable_exact_match(argument, "rpe(" + argument + ")", string)
return string
......@@ -321,16 +321,19 @@ def add_real_to_array_arguments(argument):
def add_rpe_to_array_arguments(argument):
simple_array = argument.replace("(/", "")
simple_array = simple_array.replace("/)", "")
if re.search(RegexPattern.hardcoded_array_parenthesis, argument): arg1, arg2 = "(/", "/)"
if re.search(RegexPattern.hardcoded_array_brackets, argument): arg1, arg2 = "[", "]"
simple_array = argument.replace(arg1, "")
simple_array = simple_array.replace(arg2, "")
clean_numbers = CallManager.find_call_arguments("(" + simple_array + ")")
# Open the array
ret_val = "(/"
ret_val = arg1
for number in clean_numbers:
# Cast all array numbers
ret_val += "rpe_var( 52, " + number + " ), "
# Remove last comma and closes array
ret_val = ret_val[:-2] + "/)"
ret_val = ret_val[:-2] + arg2
return ret_val
......
......@@ -26,6 +26,8 @@ structure_with_member_array = r"\w+%" + array
# Matches with the (/old, style, vec /) or the new [array, style]
# hardcoded_array = r"(\(\/|\[)(\s*[\w\s,%.()\+\-=*]*\s*)(\/\)|\])"
hardcoded_array = r"\s*(\(\/|\[)(.*)(\/\)|\])"
hardcoded_array_parenthesis = r"\s*(\(\/)(.*)(\/\))"
hardcoded_array_brackets = r"\s*(\[)(.*)(\])"
# In write statement there can be a statement like
# WRITE(numout,9402) jj, (ilci(ji,jj), ilcj(ji,jj),ji=il1,il2)
# the second argument has the type of the first el of the array
......
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