fparser Reference Guide  0.0.14
fparser.one.block_statements.HasImplicitStmt Class Reference
Inheritance diagram for fparser.one.block_statements.HasImplicitStmt:

Public Member Functions

def get_type_by_name (self, name)
 
def topyf (self, tab=" ")
 

Static Public Attributes

 a
 
 implicit_rules
 

Detailed Description

Class encapsulating information about any Implicit statements
contained within a scoping block.

Definition at line 138 of file block_statements.py.

Member Function Documentation

◆ get_type_by_name()

def fparser.one.block_statements.HasImplicitStmt.get_type_by_name (   self,
  name 
)
Returns an object of the correct type (Integer or Real) using
Fortran's implicit typing rules for the supplied variable name.

:param str name: The variable name.
:returns: Object describing the variable.
:rtype: Either :py:class:`fparser.one.typedecl_statements.Real` \
or :py:class:`fparser.one.typedecl_statements.Integer`.

Definition at line 146 of file block_statements.py.

References fparser.one.block_statements.HasImplicitStmt.a, fparser.common.base_classes.Statement.a, fparser.two.Fortran2003.Comment.item, and fparser.common.base_classes.Statement.item.

146  def get_type_by_name(self, name):
147  """
148  Returns an object of the correct type (Integer or Real) using
149  Fortran's implicit typing rules for the supplied variable name.
150 
151  :param str name: The variable name.
152  :returns: Object describing the variable.
153  :rtype: Either :py:class:`fparser.one.typedecl_statements.Real` \
154  or :py:class:`fparser.one.typedecl_statements.Integer`.
155 
156  """
157  # The implicit_rules dict is populated by the analyze() method
158  # of one.typedecl_statements.Implicit
159  implicit_rules = self.a.implicit_rules
160  if implicit_rules is None:
161  raise AnalyzeError(
162  "Implicit rules mapping is null " "while getting %r type" % (name)
163  )
164  line = name[0].lower()
165  if line in implicit_rules:
166  return implicit_rules[line]
167  # default rules:
168  if line in "ijklmn":
169  line = "default_integer"
170  else:
171  line = "default_real"
172  var = implicit_rules.get(line, None)
173  if var is None:
174  if line[8:] == "real":
175  implicit_rules[line] = var = Real(self, self.item.copy("real"))
176  else:
177  implicit_rules[line] = var = Integer(self, self.item.copy("integer"))
178  return var
179 

◆ topyf()

def fparser.one.block_statements.HasImplicitStmt.topyf (   self,
  tab = "  " 
)
Constructs a pyf representation of this class.

:param str tab: White space to prepend to output.
:returns: pyf code for this implicit statement.
:rtype: str

Definition at line 180 of file block_statements.py.

References fparser.one.block_statements.HasImplicitStmt.a, and fparser.common.base_classes.Statement.a.

180  def topyf(self, tab=" "):
181  """
182  Constructs a pyf representation of this class.
183 
184  :param str tab: White space to prepend to output.
185  :returns: pyf code for this implicit statement.
186  :rtype: str
187  """
188  implicit_rules = self.a.implicit_rules
189  if implicit_rules is None:
190  return tab + "IMPLICIT NONE\n"
191  # Construct a dict where the keys are types and the items are
192  # the list of initial letters mapped to that type
193  items = {}
194  for char, itype in list(implicit_rules.items()):
195  if char.startswith("default"):
196  continue
197  type_str = itype.tostr()
198  if type_str in items:
199  items[type_str].append(char)
200  else:
201  items[type_str] = [char]
202  if not items:
203  return tab + "! default IMPLICIT rules apply\n"
204  stmt = "IMPLICIT"
205  impl_list = []
206  for itype, letter_list in list(items.items()):
207  letter_list.sort()
208  impl_list.append(itype + " (%s)" % (", ".join(letter_list)))
209  stmt += " " + ", ".join(impl_list)
210  return tab + stmt + "\n"
211 
212 

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