Skip to content

Commit

Permalink
pr #2231. Addressing reviewer's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rupertford committed Jul 27, 2023
1 parent 037e20c commit f7755ba
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 90 deletions.
52 changes: 27 additions & 25 deletions src/psyclone/psyir/frontend/fparser2.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,25 @@ def _first_type_match(nodelist, typekind):
raise ValueError # Type not found


def _find_or_create_imported_symbol(location, name, scope_limit=None,
**kargs):
def _find_or_create_unresolved_symbol(location, name, scope_limit=None,
**kargs):
'''Returns the symbol with the name 'name' from a symbol table
associated with this node or one of its ancestors. If a symbol is found
and the `symbol_type` keyword argument is supplied then the type of the
existing symbol is compared with the specified type. If it is not already
an instance of this type, then the symbol is specialised (in place).
If the symbol is not found and there are no ContainerSymbols with wildcard
imports then an exception is raised. However, if there are one or more
If the symbol is not found and there are no ContainerSymbols with
wildcard imports and no interfaces with unknown content then an
exception is raised. However, if there are one or more
ContainerSymbols with wildcard imports (which could therefore be
bringing the symbol into scope) then a new Symbol with the
specified visibility but of unknown interface is created and
inserted in the most local SymbolTable that has such an import.
The scope_limit variable further limits the symbol table search so
that the search through ancestor nodes stops when the scope_limit node
is reached i.e. ancestors of the scope_limit node are not searched.
bringing the symbol into scope) or one or more interfaces with
unknown content then a new Symbol with the specified visibility
but of unknown interface is created and inserted in the most local
SymbolTable that has such an import. The scope_limit variable
further limits the symbol table search so that the search through
ancestor nodes stops when the scope_limit node is reached
i.e. ancestors of the scope_limit node are not searched.
:param location: PSyIR node from which to operate.
:type location: :py:class:`psyclone.psyir.nodes.Node`
Expand Down Expand Up @@ -266,14 +268,14 @@ def _find_or_create_imported_symbol(location, name, scope_limit=None,
if not isinstance(location, Node):
raise TypeError(
f"The location argument '{location}' provided to "
f"_find_or_create_imported_symbol() is not of type `Node`.")
f"_find_or_create_unresolved_symbol() is not of type `Node`.")

if scope_limit is not None:
# Validate the supplied scope_limit
if not isinstance(scope_limit, Node):
raise TypeError(
f"The scope_limit argument '{scope_limit}' provided to "
f"_find_or_create_imported_symbol() is not of type `Node`.")
f"_find_or_create_unresolved_symbol() is not of type `Node`.")

# Check that the scope_limit Node is an ancestor of this
# Reference Node and raise an exception if not.
Expand All @@ -289,8 +291,8 @@ def _find_or_create_imported_symbol(location, name, scope_limit=None,
# supplied node so raise an exception.
raise ValueError(
f"The scope_limit node '{scope_limit}' provided to "
f"_find_or_create_imported_symbol() is not an ancestor of this"
f" node '{location}'.")
f"_find_or_create_unresolved_symbol() is not an ancestor of "
f"this node '{location}'.")

# Keep a reference to the most local SymbolTable with a wildcard
# import in case we need to create a Symbol.
Expand Down Expand Up @@ -698,7 +700,7 @@ def _kind_find_or_create(name, symbol_table):
except KeyError:
# The SymbolTable does not contain an entry for this kind parameter
# so look to see if it is imported and if not create one.
kind_symbol = _find_or_create_imported_symbol(
kind_symbol = _find_or_create_unresolved_symbol(
symbol_table.node, lower_name,
symbol_type=DataSymbol,
datatype=default_integer_type(),
Expand Down Expand Up @@ -1732,7 +1734,7 @@ def _process_type_spec(self, parent, type_spec):
f"other than 'type' are not yet supported.")
type_name = str(walk(type_spec, Fortran2003.Type_Name)[0])
# Do we already have a Symbol for this derived type?
type_symbol = _find_or_create_imported_symbol(parent, type_name)
type_symbol = _find_or_create_unresolved_symbol(parent, type_name)
# pylint: disable=unidiomatic-typecheck
if type(type_symbol) == Symbol:
# We do but we didn't know what kind of symbol it was. Create
Expand Down Expand Up @@ -2419,8 +2421,8 @@ def process_declarations(self, parent, nodes, arg_list,
# If a suitable unqualified use statement is found then
# this call creates a Symbol and inserts it in the
# appropriate symbol table.
_find_or_create_imported_symbol(parent, name,
visibility=vis)
_find_or_create_unresolved_symbol(parent, name,
visibility=vis)
except SymbolError as err:
# Improve the error message with context-specific info
raise SymbolError(
Expand Down Expand Up @@ -2943,7 +2945,7 @@ def _do_construct_handler(self, node, parent):
loop_var = str(ctrl[0].items[1][0])
variable_name = str(loop_var)
try:
data_symbol = _find_or_create_imported_symbol(
data_symbol = _find_or_create_unresolved_symbol(
parent, variable_name, symbol_type=DataSymbol,
datatype=DeferredType())
except SymbolError as err:
Expand Down Expand Up @@ -3500,7 +3502,7 @@ def _array_syntax_to_indexed(self, parent, loop_vars):
range_idx = 0
for idx, child in enumerate(array.indices):
if isinstance(child, Range):
symbol = _find_or_create_imported_symbol(
symbol = _find_or_create_unresolved_symbol(
array, loop_vars[range_idx],
symbol_type=DataSymbol, datatype=DeferredType())
array.children[idx] = Reference(symbol)
Expand Down Expand Up @@ -3646,7 +3648,7 @@ def _where_construct_handler(self, node, parent):
parent=member.parent)
else:
# The array access is to a symbol of ArrayType
symbol = _find_or_create_imported_symbol(
symbol = _find_or_create_unresolved_symbol(
size_node, first_array.name, symbol_type=DataSymbol,
datatype=DeferredType())
new_ref = Reference(symbol)
Expand Down Expand Up @@ -3824,7 +3826,7 @@ def _data_ref_handler(self, node, parent):
# that first.
if isinstance(node.children[0], Fortran2003.Name):
# Base of reference is a scalar entity and must be a DataSymbol.
base_sym = _find_or_create_imported_symbol(
base_sym = _find_or_create_unresolved_symbol(
parent, node.children[0].string.lower(),
symbol_type=DataSymbol, datatype=DeferredType())
base_indices = []
Expand All @@ -3834,7 +3836,7 @@ def _data_ref_handler(self, node, parent):
# Base of reference is an array access. Lookup the corresponding
# symbol.
part_ref = node.children[0]
base_sym = _find_or_create_imported_symbol(
base_sym = _find_or_create_unresolved_symbol(
parent, part_ref.children[0].string.lower(),
symbol_type=DataSymbol, datatype=DeferredType())
# Processing the array-index expressions requires access to the
Expand Down Expand Up @@ -4140,7 +4142,7 @@ def _name_handler(self, node, parent):
:rtype: :py:class:`psyclone.psyir.nodes.Reference`
'''
symbol = _find_or_create_imported_symbol(parent, node.string)
symbol = _find_or_create_unresolved_symbol(parent, node.string)
return Reference(symbol, parent=parent)

def _parenthesis_handler(self, node, parent):
Expand Down Expand Up @@ -4184,7 +4186,7 @@ def _part_ref_handler(self, node, parent):
# We can't say for sure that the symbol we create here should be a
# DataSymbol as fparser2 often identifies function calls as
# part-references instead of function-references.
symbol = _find_or_create_imported_symbol(parent, reference_name)
symbol = _find_or_create_unresolved_symbol(parent, reference_name)

if isinstance(symbol, RoutineSymbol):
call_or_array = Call(symbol, parent=parent)
Expand Down
9 changes: 5 additions & 4 deletions src/psyclone/tests/psyir/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -----------------------------------------------------------------------------
# BSD 3-Clause License
#
# Copyright (c) 2019-2020, Science and Technology Facilities Council.
# Copyright (c) 2019-2023, Science and Technology Facilities Council.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,14 +32,15 @@
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Author A. R. Porter, STFC Daresbury Lab
# Modified R. W. Ford, STFC Daresbury Lab


''' Module which performs pytest set-up specific to the PSyIR tests. '''

from __future__ import absolute_import
import pytest
from psyclone.psyir.symbols import DataSymbol, INTEGER_TYPE

import psyclone.psyir.frontend.fparser2 as fp2
from psyclone.psyir.symbols import DataSymbol, INTEGER_TYPE


@pytest.fixture(scope="function")
Expand All @@ -52,6 +53,6 @@ def disable_declaration_check(monkeypatch):
'''
monkeypatch.setattr(
fp2, "_find_or_create_imported_symbol",
fp2, "_find_or_create_unresolved_symbol",
lambda _1, name, _2=None: DataSymbol(name,
INTEGER_TYPE))
Loading

0 comments on commit f7755ba

Please sign in to comment.