39 '''This module contains the TypedSymbol class.
50 Abstract base class for those Symbols that have an associated datatype.
52 :param str name: name of the symbol.
53 :param datatype: data type of the symbol.
54 :type datatype: :py:class:`psyclone.psyir.symbols.DataType`
55 :param kwargs: additional keyword arguments provided by \
56 :py:class:`psyclone.psyir.symbols.Symbol`
57 :type kwargs: unwrapped dict.
60 def __init__(self, name, datatype, **kwargs):
62 super(TypedSymbol, self).__init__(name)
65 def _process_arguments(self, **kwargs):
66 ''' Process the arguments for the constructor and the specialise
67 methods. In this case the datatype argument.
69 :param kwargs: keyword arguments which can be:\n
70 :param datatype: data type of the symbol.\n
71 :type datatype: :py:class:`psyclone.psyir.symbols.DataType`\n
72 and the arguments in :py:class:`psyclone.psyir.symbols.Symbol`
73 :type kwargs: unwrapped dict.
75 :raises AttributeError: if the datatype argument is not given \
76 and it isn't already a property of this symbol.
79 if "datatype" in kwargs:
81 elif not hasattr(self,
'_datatype'):
82 raise AttributeError(f
"Missing mandatory 'datatype' attribute for "
83 f
"symbol '{self.name}'.")
85 super(TypedSymbol, self)._process_arguments(**kwargs)
89 ''' Abstract method. Must be overridden in sub-class. '''
94 :returns: datatype of the TypedSymbol.
95 :rtype: :py:class:`psyclone.psyir.symbols.DataType` or \
96 :py:class:`psyclone.psyir.symbols.DataTypeSymbol`
101 def datatype(self, value):
102 ''' Setter for the datatype of a TypedSymbol.
104 :param value: new value for datatype.
105 :type value: :py:class:`psyclone.psyir.symbols.DataType` or \
106 :py:class:`psyclone.psyir.symbols.DataTypeSymbol`
108 :raises TypeError: if value is not of the correct type.
115 if not isinstance(value, (DataType, DataTypeSymbol)):
117 f
"The datatype of a {type(self).__name__} must be specified "
118 f
"using either a DataType or a DataTypeSymbol but got: "
119 f
"'{type(value).__name__}'")
123 '''Create and return a copy of this object. Any references to the
124 original will not be affected so the copy will not be referred
125 to by any other object.
127 :returns: A symbol object with the same properties as this \
129 :rtype: :py:class:`psyclone.psyir.symbols.TypedSymbol`
138 '''Replace all properties in this object with the properties from
139 symbol_in, apart from the name (which is immutable) and visibility.
141 :param symbol_in: the symbol from which the properties are copied.
142 :type symbol_in: :py:class:`psyclone.psyir.symbols.DataSymbol`
144 :raises TypeError: if the argument is not the expected type.
147 if not isinstance(symbol_in, TypedSymbol):
148 raise TypeError(f
"Argument should be of type 'TypedSymbol' but "
149 f
"found '{type(symbol_in).__name__}'.")
151 self.
_datatype_datatype = symbol_in.datatype
154 ''' If the symbol has an Unresolved datatype, find where it is defined
155 (i.e. an external container) and obtain the properties of the symbol.
157 :returns: this TypedSymbol with its properties updated. This is for \
158 consistency with the equivalent method in the Symbol \
159 class which returns a new Symbol object.
160 :rtype: :py:class:`psyclone.psyir.symbols.TypedSymbol`
181 :returns: True if this symbol is a scalar and False otherwise.
194 :returns: True if this symbol is an array and False if it is not or
195 there is not enough symbol information to determine it.
203 ArrayType, UnsupportedFortranType)
212 :returns: shape of the symbol in column-major order (leftmost
213 index is contiguous in memory). Each entry represents
214 an array dimension. If it is 'None' the extent of that
215 dimension is unknown, otherwise it holds an integer
216 literal or a reference to an integer symbol with the
217 extent. If it is an empty list then the symbol
219 :rtype: List[Optional[:py:class:`psyclone.psyir.nodes.Literal` |
220 :py:class:`psyclone.psyir.nodes.Reference`]]
229 return self.
_datatype_datatype.partial_datatype.shape
def visibility(self, value)
def _process_arguments(self, visibility=None, interface=None)
def copy_properties(self, symbol_in)
def get_external_symbol(self)
def interface(self, value)
def copy_properties(self, symbol_in)
def datatype(self, value)
def _process_arguments(self, **kwargs)