fparser Reference Guide  0.0.14
fparser.two.symbol_table.ModuleUse Class Reference

Public Member Functions

def __init__ (self, name, only_list=None, rename_list=None)
 
def update (self, other)
 
def name (self)
 
def symbol_names (self)
 
def only_list (self)
 
def rename_list (self)
 
def wildcard_import (self)
 
def get_declared_name (self, name)
 

Detailed Description

Class capturing information on all USE statements referring to a given
Fortran module.

A USE statement can rename an imported symbol so as to avoid a clash in
the local scope, e.g. `USE my_mod, alocal => amod` where `amod` is the
name of the symbol declared in `my_mod`. This renaming can also occur
inside an Only_List, e.g. `USE my_mod, only: alocal => amod`.

:param str name: the name of the module.
:param only_list: list of 2-tuples giving the (local-name, module-name) \
    of symbols that appear in an Only_List. If a symbol is not re-named \
    then module-name can be None.
:type only_list: Optional[List[Tuple[str, str | NoneType]]]
:param rename_list: list of 2-tuples given the (local-name, module-name) \
    of symbols that appear in a Rename_List.
:type rename_list: Optional[List[Tuple[str, str]]]

:raises TypeError: if any of the supplied parameters are of the wrong type.

Definition at line 261 of file symbol_table.py.

Member Function Documentation

◆ get_declared_name()

def fparser.two.symbol_table.ModuleUse.get_declared_name (   self,
  name 
)
:returns: the name of the supplied symbol as declared in the module.
:rtype: str

Definition at line 485 of file symbol_table.py.

References fparser.two.symbol_table.ModuleUse._local_to_module_map.

485  def get_declared_name(self, name):
486  """
487  :returns: the name of the supplied symbol as declared in the module.
488  :rtype: str
489  """
490  return self._local_to_module_map.get(name, name)
491 
492 

◆ name()

def fparser.two.symbol_table.ModuleUse.name (   self)
:returns: the name of the Fortran module.
:rtype: str

Definition at line 439 of file symbol_table.py.

References fparser.two.symbol_table.ModuleUse._name.

439  def name(self):
440  """
441  :returns: the name of the Fortran module.
442  :rtype: str
443  """
444  return self._name
445 
Here is the caller graph for this function:

◆ only_list()

def fparser.two.symbol_table.ModuleUse.only_list (   self)
:returns: the local names that appear in an Only_List or None if there \
  is no such list.
:rtype: Optional[List[str]]

Definition at line 456 of file symbol_table.py.

References fparser.two.symbol_table.ModuleUse._only_set.

456  def only_list(self):
457  """
458  :returns: the local names that appear in an Only_List or None if there \
459  is no such list.
460  :rtype: Optional[List[str]]
461  """
462  if self._only_set is None:
463  return None
464  return list(self._only_set)
465 

◆ rename_list()

def fparser.two.symbol_table.ModuleUse.rename_list (   self)
:returns: the local names that appear in a Rename_List or None if there \
  is no such list.
:rtype: Optional[List[str]]

Definition at line 467 of file symbol_table.py.

References fparser.two.symbol_table.ModuleUse._rename_set.

467  def rename_list(self):
468  """
469  :returns: the local names that appear in a Rename_List or None if there \
470  is no such list.
471  :rtype: Optional[List[str]]
472  """
473  if self._rename_set is None:
474  return None
475  return list(self._rename_set)
476 

◆ symbol_names()

def fparser.two.symbol_table.ModuleUse.symbol_names (   self)
:returns: the names of all symbols associated with USE(s) of this \
  module.
:rtype: List[str]

Definition at line 447 of file symbol_table.py.

References fparser.two.symbol_table.ModuleUse._symbols.

447  def symbol_names(self):
448  """
449  :returns: the names of all symbols associated with USE(s) of this \
450  module.
451  :rtype: List[str]
452  """
453  return list(self._symbols.keys())
454 

◆ update()

def fparser.two.symbol_table.ModuleUse.update (   self,
  other 
)
Update the current information with the information on the USE held
in 'other'.

:param other: the other Use instance from which to update this one.
:type other: :py:class:`fparser.two.symbol_table.Use`

:raises TypeError: if 'other' is of the wrong type.
:raises ValueError: if 'other' is for a module with a different \
            name to the current one.

Definition at line 378 of file symbol_table.py.

References fparser.two.symbol_table.ModuleUse._local_to_module_map, fparser.two.symbol_table.ModuleUse._only_set, fparser.two.symbol_table.ModuleUse._rename_set, fparser.two.symbol_table.ModuleUse._symbols, fparser.two.symbol_table.ModuleUse._wildcard_import, fparser.common.base_classes.Variable.name, fparser.one.typedecl_statements.TypeDeclarationStatement.name, fparser.common.readfortran.Line.name, fparser.one.block_statements.BeginSource.name, fparser.two.symbol_table.ModuleUse.name(), fparser.one.block_statements.Module.name, fparser.one.block_statements.PythonModule.name, fparser.one.block_statements.BlockData.name, fparser.common.readfortran.FortranReaderBase.name(), fparser.one.block_statements.Interface.name, fparser.one.block_statements.SubProgramStatement.name, fparser.common.base_classes.BeginStatement.name, fparser.one.statements.Cycle.name, fparser.common.base_classes.EndStatement.name, fparser.one.block_statements.Select.name, fparser.one.block_statements.Where.name, fparser.one.block_statements.Forall.name, fparser.one.block_statements.IfThen.name, fparser.one.statements.Use.name, fparser.one.block_statements.Do.name, fparser.one.statements.Exit.name, fparser.one.block_statements.Type.name, fparser.one.statements.Entry.name, fparser.one.statements.SpecificBinding.name, fparser.one.statements.Else.name, fparser.one.statements.ElseIf.name, fparser.one.statements.Case.name, fparser.one.statements.TypeIs.name, fparser.one.statements.ClassIs.name, and fparser.one.statements.ElseWhere.name.

378  def update(self, other):
379  """
380  Update the current information with the information on the USE held
381  in 'other'.
382 
383  :param other: the other Use instance from which to update this one.
384  :type other: :py:class:`fparser.two.symbol_table.Use`
385 
386  :raises TypeError: if 'other' is of the wrong type.
387  :raises ValueError: if 'other' is for a module with a different \
388  name to the current one.
389 
390  """
391  if not isinstance(other, ModuleUse):
392  raise TypeError(
393  f"update() must be supplied with an instance of "
394  f"ModuleUse but got '{type(other).__name__}'"
395  )
396 
397  if self.name != other.name:
398  raise ValueError(
399  f"The ModuleUse supplied to update() is for module "
400  f"'{other.name}' but this ModuleUse is for module "
401  f"'{self.name}'"
402  )
403 
404  # Take the union of the only and rename lists and update the list
405  # of symbols.
406  if other.only_list:
407  for local_name in other.only_list:
408  if local_name not in self._symbols:
409  self._symbols[local_name] = SymbolTable.Symbol(
410  local_name, "unknown"
411  )
412  # pylint: disable=protected-access
413  if self._only_set is None:
414  self._only_set = other._only_set
415  else:
416  self._only_set = self._only_set.union(other._only_set)
417  # pylint: enable=protected-access
418 
419  if other.rename_list:
420  for local_name in other.rename_list:
421  if local_name not in self._symbols:
422  self._symbols[local_name] = SymbolTable.Symbol(
423  local_name, "unknown"
424  )
425  # pylint: disable=protected-access
426  if self._rename_set is None:
427  self._rename_set = other._rename_set
428  else:
429  self._rename_set = self._rename_set.union(other._rename_set)
430  # pylint: enable=protected-access
431 
432  # pylint: disable=protected-access
433  self._local_to_module_map.update(other._local_to_module_map)
434  # pylint: enable=protected-access
435 
436  self._wildcard_import = self._wildcard_import or other.wildcard_import
437 
Here is the call graph for this function:

◆ wildcard_import()

def fparser.two.symbol_table.ModuleUse.wildcard_import (   self)
:returns: whether there is a wildcard import from this module.
:rtype: bool

Definition at line 478 of file symbol_table.py.

References fparser.two.symbol_table.ModuleUse._wildcard_import.

478  def wildcard_import(self):
479  """
480  :returns: whether there is a wildcard import from this module.
481  :rtype: bool
482  """
483  return self._wildcard_import
484 

The documentation for this class was generated from the following file: