Reference Guide  2.5.0
psyclone.psyir.symbols.datatypes.UnsupportedFortranType Class Reference
Inheritance diagram for psyclone.psyir.symbols.datatypes.UnsupportedFortranType:
Collaboration diagram for psyclone.psyir.symbols.datatypes.UnsupportedFortranType:

Public Member Functions

def __init__ (self, declaration_txt, partial_datatype=None)
 
def __str__ (self)
 
def partial_datatype (self)
 
def type_text (self)
 
def __eq__ (self, other)
 
- Public Member Functions inherited from psyclone.psyir.symbols.datatypes.UnsupportedType
def __init__ (self, declaration_txt)
 
def declaration (self)
 

Detailed Description

Indicates that a Fortran declaration is not supported by the PSyIR.

:param str declaration_txt: string containing the original variable
    declaration.
:param partial_datatype: a PSyIR datatype representing the subset
    of type attributes that are supported.
:type partial_datatype: Optional[
    :py:class:`psyclone.psyir.symbols.DataType` or
    :py:class:`psyclone.psyir.symbols.DataTypeSymbol`]

Definition at line 126 of file datatypes.py.

Member Function Documentation

◆ __eq__()

def psyclone.psyir.symbols.datatypes.UnsupportedFortranType.__eq__ (   self,
  other 
)
:param Any other: the object to check equality to.

:returns: whether this type is equal to the 'other' type.
:rtype: bool

Reimplemented from psyclone.psyir.symbols.datatypes.DataType.

Definition at line 225 of file datatypes.py.

225  def __eq__(self, other):
226  '''
227  :param Any other: the object to check equality to.
228 
229  :returns: whether this type is equal to the 'other' type.
230  :rtype: bool
231  '''
232  if not super().__eq__(other):
233  return False
234 
235  return other.type_text == self.type_text
236 
237 

References psyclone.psyir.symbols.datatypes.UnsupportedFortranType.type_text().

Here is the call graph for this function:

◆ __str__()

def psyclone.psyir.symbols.datatypes.UnsupportedFortranType.__str__ (   self)
 Abstract method that must be implemented in subclass. 

Reimplemented from psyclone.psyir.symbols.datatypes.UnsupportedType.

Definition at line 153 of file datatypes.py.

153  def __str__(self):
154  return f"UnsupportedFortranType('{self._declaration}')"
155 

◆ partial_datatype()

def psyclone.psyir.symbols.datatypes.UnsupportedFortranType.partial_datatype (   self)
:returns: partial datatype information if it can be determined,
    else None.
:rtype: Optional[:py:class:`psyclone.symbols.DataType`]

Definition at line 157 of file datatypes.py.

157  def partial_datatype(self):
158  '''
159  :returns: partial datatype information if it can be determined,
160  else None.
161  :rtype: Optional[:py:class:`psyclone.symbols.DataType`]
162  '''
163  return self._partial_datatype
164 

References psyclone.psyir.symbols.datatypes.UnsupportedFortranType._partial_datatype.

◆ type_text()

def psyclone.psyir.symbols.datatypes.UnsupportedFortranType.type_text (   self)
Parses the original Fortran declaration and uses the resulting
parse tree to extract the type information. This is returned in
text form and also cached.

TODO #2137 - alter Unsupported(Fortran)Type so that it is only the
type information that is stored as a string. i.e. remove the name
of the variable being declared. Once that is done this method
won't be required.

Note that UnsupportedFortranType is also used to hold things like
'SAVE :: /my_common/' and thus it is not always possible/appropriate
to extract a type expression.

:returns: the Fortran code specifying the type.
:rtype: str

:raises NotImplementedError: if declaration text cannot be
    extracted from the original Fortran declaration.

Definition at line 166 of file datatypes.py.

166  def type_text(self):
167  '''
168  Parses the original Fortran declaration and uses the resulting
169  parse tree to extract the type information. This is returned in
170  text form and also cached.
171 
172  TODO #2137 - alter Unsupported(Fortran)Type so that it is only the
173  type information that is stored as a string. i.e. remove the name
174  of the variable being declared. Once that is done this method
175  won't be required.
176 
177  Note that UnsupportedFortranType is also used to hold things like
178  'SAVE :: /my_common/' and thus it is not always possible/appropriate
179  to extract a type expression.
180 
181  :returns: the Fortran code specifying the type.
182  :rtype: str
183 
184  :raises NotImplementedError: if declaration text cannot be
185  extracted from the original Fortran declaration.
186 
187  '''
188  if self._type_text:
189  return self._type_text
190 
191  # Encapsulate fparser2 functionality here.
192  # pylint:disable=import-outside-toplevel
193  from fparser.common.readfortran import FortranStringReader
194  from fparser.common.sourceinfo import FortranFormat
195  from fparser.two import Fortran2003
196  from fparser.two.parser import ParserFactory
197  string_reader = FortranStringReader(self._declaration)
198  # Set reader to free format.
199  string_reader.set_format(FortranFormat(True, False))
200  ParserFactory().create(std="f2008")
201  try:
202  ptree = Fortran2003.Specification_Part(
203  string_reader)
204  except Exception as err:
205  raise NotImplementedError(
206  f"Cannot extract the declaration part from UnsupportedFortran"
207  f"Type '{self._declaration}' because parsing (attempting to "
208  f"match a Fortran2003.Specification_Part) failed.") from err
209  node = ptree.children[0]
210  if isinstance(node, (Fortran2003.Declaration_Construct,
211  Fortran2003.Type_Declaration_Stmt)):
212  self._type_text = str(node.children[0])
213  elif isinstance(node, Fortran2003.Save_Stmt):
214  self._type_text = "SAVE"
215  elif isinstance(node, Fortran2003.Common_Stmt):
216  self._type_text = "COMMON"
217  else:
218  raise NotImplementedError(
219  f"Cannot extract the declaration part from UnsupportedFortran"
220  f"Type '{self._declaration}'. Only Declaration_Construct, "
221  f"Type_Declaration_Stmt, Save_Stmt and Common_Stmt are "
222  f"supported but got '{type(node).__name__}' from the parser.")
223  return self._type_text
224 

References psyclone.psyir.symbols.datatypes.UnsupportedType._declaration, and psyclone.psyir.symbols.datatypes.UnsupportedFortranType._type_text.

Here is the caller graph for this function:

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