Commit 118fc1f5 authored by sparonuz's avatar sparonuz
Browse files

[Issue#128]: This solves Issue#128.

parent f2620e85
import AutoRPE.UtilsRPE.Error as Error
def generate_dict_key(el_types, el_dimensions, uniform=False):
import AutoRPE.UtilsRPE.VariablePrecision as VariablePrecision
# Create a key agnostic on the real type
if uniform:
# Perform a copy not to modify the args in input
el_types = el_types[:]
for index, t in enumerate(el_types):
if t in list(VariablePrecision.real_id) + ["rpe_var"]:
el_types[index] = "uniform_real"
key = [len(el_types)] + \
el_types + \
el_dimensions
return hash(str(key))
class ReadSourceFile:
def __init__(self, _filename):
# Init variables
......@@ -225,17 +241,23 @@ class Interface:
self.module = module
self.subprogram = []
self.key = {}
self.agnostic_key = {}
def add_key(self, module_procedure):
mandatory_da = [dummy for dummy in module_procedure.dummy_arguments if not dummy.is_optional]
key = [len(mandatory_da)] + \
[da.type for da in mandatory_da] + \
[da.dimension for da in mandatory_da]
mandatory_da_type = [da.type for da in mandatory_da]
mandatory_da_dim = [da.dimension for da in mandatory_da]
key = generate_dict_key(mandatory_da_type, mandatory_da_dim)
agnostic_key = generate_dict_key(mandatory_da_type, mandatory_da_dim, uniform=True)
# Create a unique key from interface argument starting from attribute
try:
self.key[hash(str(key))] += [module_procedure.name]
self.key[key] += [module_procedure.name]
except KeyError:
self.key[key] = [module_procedure.name]
try:
self.agnostic_key[agnostic_key] = [module_procedure.name]
except KeyError:
self.key[hash(str(key))] = [module_procedure.name]
self.agnostic_key[agnostic_key] += [module_procedure.name]
def add_procedure(self, subprogram):
assert isinstance(subprogram, SubRoutine) or isinstance(subprogram, Function)
......
......@@ -353,9 +353,20 @@ def get_interface_from_arguments(arguments, interface, procedure=None, vault=Non
argument_types = [get_type_of_contents(argument, procedure, vault) for argument in arguments]
argument_dim = [get_dimension_of_contents(argument, procedure, vault) for argument in arguments]
keyword_arguments = [_x.split("=")[0].strip() if is_keyword_argument(_x) else False for _x in arguments]
try:
get_interface_from_key(interface, argument_types, argument_dim)
except Error.InterfaceNotFound:
pass
return get_interface_from_arguments_and_info(argument_types, interface, argument_dim, keyword_arguments)
def get_interface_from_key(interface, argument_types, argument_dimensions):
key = BasicStructures.generate_dict_key(argument_types, argument_dimensions, uniform=True)
if key in interface.agnostic_key:
return interface.agnostic_key[key]
raise Error.InterfaceNotFound("No matching routine found for interface : %s" % interface.name)
def get_interface_from_arguments_and_info(argument_types, interface, argument_dimensions, keyword_arguments):
# This function is intended to take the argument info (types and dimensions) and return the subroutine
# inside the interface that matches it.
......
......@@ -251,7 +251,8 @@ def create_subprogram(module, header, routine_name, dummy_arguments, var_declara
_v.is_parameter = False
subprogram.add_variable(_v)
subprogram.dummy_arguments.append(_v)
# Order dummy_arguments by position
subprogram.dummy_arguments.sort(key=lambda x: x.position)
if subprogram_type == BasicStructures.Function:
# In case of function declaration like INTEGER FUNCTION name() without return variable declaration
if not [var for var in subprogram.variables if var.is_retval]:
......
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