Commit c8f49549 authored by Oriol Tintó-Prims's avatar Oriol Tintó-Prims
Browse files

We are adding the attribute is_pointer to Variables, and use this information...

We are adding the attribute is_pointer to Variables, and use this information in the tracking phase.
parent 8f00c2eb
......@@ -384,14 +384,12 @@ class Interface:
class Variable:
def __init__(self, _routine, _name, _type, _dimension):
def __init__(self, _routine, _name, _type, _dimension, _is_pointer=False):
self.id = None
self.module = None
self.routine = _routine
self.name = _name
self.type = _type
if self.type == "real":
print("A real has been declared: %s" % _name)
self.dimension = _dimension
self.is_dummy_argument = False
self.intent = None
......@@ -403,6 +401,7 @@ class Variable:
self.is_member_of = None
self.mutable = None
self.same_as = []
self.is_pointer = _is_pointer
def set_precision(self, precision):
assert isinstance(precision, int), "Precision argument in set_precision must be an integer"
......@@ -591,7 +590,7 @@ class ObtainSourcefileInfo(ReadSourceFile):
main = obj
break
for member in structure.variables:
_v_member = Variable(obj, member.name, member.type, member.dimension)
_v_member = Variable(obj, member.name, member.type, member.dimension, member.is_pointer)
_v_member.is_member_of = structure.name
main.add_variable(_v_member)
......@@ -626,7 +625,8 @@ class ObtainSourcefileInfo(ReadSourceFile):
_attributes, variable = m.groups()
# Check if the dummy argument is inside the declaration arguments
# If it is, take the type, dimension, intent and optional
_var_type, _dimension, _intent, _optional, _allocatable, _is_parameter = parse_attributes(_attributes,
_var_type, _dimension, _intent, _optional, _allocatable, _is_pointer, _is_parameter = parse_attributes(
_attributes,
variable)
variable_name = split_declaration_arguments(variable)
......@@ -635,7 +635,7 @@ class ObtainSourcefileInfo(ReadSourceFile):
raise AssertionError("Problem identifying variable declaration.")
variable_name = variable_name[0]
_v = Variable(ob, variable_name, _var_type, _dimension)
_v = Variable(ob, variable_name, _var_type, _dimension, _is_pointer)
_v.allocatable = _allocatable
_v.is_parameter = _is_parameter
......@@ -739,7 +739,8 @@ class ObtainSourcefileInfo(ReadSourceFile):
m = re.search(pattern, line)
if m:
attributes, variables = m.groups()
var_type, dimension, intent, optional, allocatable, is_parameter = parse_attributes(attributes,
var_type, dimension, intent, optional, allocatable, is_pointer, is_parameter = parse_attributes(
attributes,
variables)
variables = split_declaration_arguments(variables)
......@@ -785,12 +786,12 @@ class ObtainSourcefileInfo(ReadSourceFile):
match = re.search(pattern, line)
if match:
attributes, variables = match.groups()
var_type, dimension, intent, optional, allocatable, is_parameter = parse_attributes(attributes,
variables)
var_type, dimension, intent, optional, allocatable, is_pointer, is_parameter = parse_attributes(
attributes, variables)
variables = split_declaration_arguments(variables)
if var_type:
for variable in variables:
v = Variable(main_routine, variable, var_type, dimension)
v = Variable(main_routine, variable, var_type, dimension, is_pointer)
v.allocatable = allocatable
v.is_parameter = is_parameter
main_routine.add_variable(v)
......
......@@ -1522,6 +1522,25 @@ def is_allocatable(attributes):
return False
def is_pointer(attributes, variables):
# Description: Given a list of attributes, check if pointer is among them
# Input: List of attributes
# Output: boolean
if isinstance(attributes, str):
attributes = split_attributes(attributes)
assert isinstance(attributes, list)
if "pointer" in attributes:
pointed_object = attributes[0]
if pointed_object.count("procedure"):
pointed_object = pointed_object.replace("procedure", "")
pointed_object = close_brackets(pointed_object)
return pointed_object
if variables.count("=>"):
pointed_object = variables.split("=>")[1]
return pointed_object.strip()
return False
def parse_attributes(attributes, variables):
if isinstance(attributes, str):
attributes = split_attributes(attributes)
......@@ -1532,8 +1551,8 @@ def parse_attributes(attributes, variables):
optional = is_optional(attributes)
allocatable = is_allocatable(attributes)
parameter = is_parameter(attributes)
return var_type, dimension, intent, optional, allocatable, parameter
pointer = is_pointer(attributes, variables)
return var_type, dimension, intent, optional, allocatable, pointer, parameter
def split_declaration_arguments(string):
# Description: given a string containing arguments, return a list with arguments
......
......@@ -263,7 +263,8 @@ def retrieve_real_in_line(line, vault, current_block, check=False):
else:
dummy_var = procedure.get_variable_by_position(index)
# In case of the argument being an input, avoid binding the variables.
if not check and dummy_var.intent == "in":
# The exception is when the dummy argument has the pointer attribute.
if not check and dummy_var.intent == "in" and not dummy_var.is_pointer:
continue
if not check:
try:
......
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