Commit 13d8fcd1 authored by erodrigu's avatar erodrigu
Browse files

Update text and blocks after finishing the loop

parent 6af488bc
......@@ -86,7 +86,7 @@ def add_sbits_to_rpe_variables(vault):
# Allocatable
for variable in allocatable:
insert_variable_precision_specification_to_allocatable(variable, var_counter)
insert_variable_precision_specification_to_allocatable(variable, var_counter, vault)
# Non allocatable that appear in a namelist
na_in_namelist, na_not_in_namelist = Splitter.split_by_appearance_in_namelist(non_allocatable)
......@@ -97,7 +97,7 @@ def add_sbits_to_rpe_variables(vault):
# Variables inside routines
for variable in not_in_main:
if not isinstance(variable.procedure, BasicStructures.DerivedType) and variable.intent != "in":
insert_variable_precision_to_routine_variable(variable, var_counter)
insert_variable_precision_to_routine_variable(variable, var_counter, vault)
# Adding sbits assignation and apply_truncation after routine calls
insert_variable_precision_after_subroutine_call(vault, var_counter)
......@@ -151,21 +151,16 @@ def insert_variable_precision_specification(variable, module, insertion_line, co
var_name = member_name if member_name else variable.name
# Add apply_truncation
new_line = condition + " CALL apply_truncation(%s)" % var_name
module.lines.insert(insertion_line, new_line)
module.lines[insertion_line] += "\n" + condition + " CALL apply_truncation(%s)" % var_name
# Add sbits
new_line = condition + " %s%%sbits = emulator_variable_precisions(%i)" % (var_name, variable.id)
module.lines.insert(insertion_line, new_line)
module.lines[insertion_line] += "\n" + condition + " %s%%sbits = emulator_variable_precisions(%i)" % (var_name, variable.id)
# Add variable usage specification
new_line = condition + " variable_is_used(%i) = .true." % variable.id
module.lines.insert(insertion_line, new_line)
module.rebuild_text()
module.lines[insertion_line] += "\n" + condition + " variable_is_used(%i) = .true." % variable.id
def insert_variable_precision_specification_to_allocatable(variable, counter_object):
def insert_variable_precision_specification_to_allocatable(variable, counter_object, vault):
for module in [variable.module] + variable.procedure.module.used_by:
for line_index, line in enumerate(module.lines):
if re.search(RegexPattern.allocation_variable_name % variable.name, line, re.I):
......@@ -176,8 +171,12 @@ def insert_variable_precision_specification_to_allocatable(variable, counter_obj
for arg in arguments:
cleaned_arg = Getter.remove_indexing(arg)
if cleaned_arg.count(variable.name):
# Remove array arguments (if any) and get only the member and var: foo%var(2:3) --> foo%var
# Get variable name without indexing (foo(n)%var --> foo%var)
member_name = arg.split(variable.name)[0] + variable.name
member_type = Getter.get_type_of_contents(member_name, module.blocks[line_index], vault)
# Fix only if it's an rpe_var
if member_type != 'rpe_var':
member_name = None
break
if not member_name:
continue
......@@ -185,10 +184,15 @@ def insert_variable_precision_specification_to_allocatable(variable, counter_obj
# Check that we did not match a member with the same name: a_i will also match %a_i
if re.search(RegexPattern.allocation_member_name % variable.name, line.replace(" ",""), re.I):
continue
variable.id = counter_object.count
variable.mutable = True
counter_object.up()
insert_variable_precision_specification(variable, module, line_index + 1, member_name=member_name)
insert_variable_precision_specification(variable, module, line_index, member_name=member_name)
module.rebuild_text()
module.update_blocks(vault)
return
......@@ -203,10 +207,12 @@ def insert_variable_precision_specification_to_namelist_parameter(variable, coun
variable.id = counter_object.count
variable.mutable = True
counter_object.up()
insert_variable_precision_specification(variable, module, index + 1)
insert_variable_precision_specification(variable, module, index)
module.rebuild_text()
module.update_blocks(vault)
def insert_variable_precision_to_routine_variable(variable, counter_object):
def insert_variable_precision_to_routine_variable(variable, counter_object, vault):
module, first_use_line = find_first_use(variable)
if module:
variable.id = counter_object.count
......@@ -222,6 +228,8 @@ def insert_variable_precision_to_routine_variable(variable, counter_object):
if variable.is_member_of:
member_name = BasicFunctions.remove_if_condition(_line).split(variable.name)[0] + variable.name
insert_variable_precision_specification(variable, module, first_use_line, condition, member_name)
module.rebuild_text()
module.update_blocks(vault)
else:
warnings.warn("Variable %s not found %s in routine %s" % (
variable.name, variable.procedure.module.name, variable.procedure.name))
......@@ -246,6 +254,7 @@ def insert_variable_precision_after_subroutine_call(vault, counter):
module.lines[_index] = line.replace(temporal_call[1],
_add_argument_truncation(temporal_call, subroutine_calls, counter))
module.rebuild_text()
module.update_blocks(vault)
# End fo rpe insertion
......
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