68 Fortran block statements. 134 __all__.extend(statements.__all__)
135 __all__.extend(typedecl_statements.__all__)
140 Class encapsulating information about any Implicit statements 141 contained within a scoping block. 144 a = AttributeHolder(implicit_rules={})
148 Returns an object of the correct type (Integer or Real) using 149 Fortran's implicit typing rules for the supplied variable name. 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`. 159 implicit_rules = self.
a.implicit_rules
160 if implicit_rules
is None:
162 "Implicit rules mapping is null " "while getting %r type" % (name)
164 line = name[0].lower()
165 if line
in implicit_rules:
166 return implicit_rules[line]
169 line =
"default_integer" 171 line =
"default_real" 172 var = implicit_rules.get(line,
None)
174 if line[8:] ==
"real":
175 implicit_rules[line] = var =
Real(self, self.item.copy(
"real"))
177 implicit_rules[line] = var =
Integer(self, self.item.copy(
"integer"))
182 Constructs a pyf representation of this class. 184 :param str tab: White space to prepend to output. 185 :returns: pyf code for this implicit statement. 188 implicit_rules = self.
a.implicit_rules
189 if implicit_rules
is None:
190 return tab +
"IMPLICIT NONE\n" 194 for char, itype
in list(implicit_rules.items()):
195 if char.startswith(
"default"):
197 type_str = itype.tostr()
198 if type_str
in items:
199 items[type_str].append(char)
201 items[type_str] = [char]
203 return tab +
"! default IMPLICIT rules apply\n" 206 for itype, letter_list
in list(items.items()):
208 impl_list.append(itype +
" (%s)" % (
", ".join(letter_list)))
209 stmt +=
" " +
", ".join(impl_list)
210 return tab + stmt +
"\n" 215 a = AttributeHolder(use={}, use_provides={})
217 def get_entity(self, name):
218 for modname, modblock
in list(self.top.a.module.items()):
219 for stmt
in modblock.content:
220 if getattr(stmt,
"name",
"") == name:
224 def topyf(self, tab=" "):
225 sys.stderr.write(
"HasUseStmt.topyf not implemented\n")
231 a = AttributeHolder(private_id_list=[], public_id_list=[])
233 def topyf(self, tab=" "):
234 private_list = self.
a.private_id_list
235 public_list = self.
a.public_id_list
237 if "" in private_list:
238 lines.append(tab +
"PRIVATE\n")
239 if "" in public_list:
240 lines.append(tab +
"PUBLIC\n")
241 for a
in private_list:
244 lines.append(tab +
"PRIVATE :: %s\n" % (a))
245 for a
in public_list:
248 lines.append(tab +
"PUBLIC :: %s\n" % (a))
249 return "".join(lines)
255 variables={}, variable_names=[]
258 def get_variable_by_name(self, name):
259 variables = self.
a.variables
260 if name
in variables:
261 var = variables[name]
263 var = variables[name] = Variable(self, name)
264 self.
a.variable_names.append(name)
267 def topyf(self, tab="", only_variables=None):
269 if only_variables
is None:
270 only_variables = list(self.
a.variables.keys())
271 for name
in only_variables:
272 var = self.
a.variables[name]
273 s += tab + str(var) +
"\n" 279 a = AttributeHolder(type_decls={})
281 def topyf(self, tab=""):
283 for name, stmt
in list(self.
a.type_decls.items()):
284 s += stmt.topyf(tab=
" " + tab)
287 def get_type_decl_by_kind(self, kind):
288 type_decls = self.
a.type_decls
289 type_decl = type_decls.get(kind,
None)
290 if type_decl
is None:
291 return self.get_entity(kind)
297 known_attributes = []
298 a = AttributeHolder(attributes=[])
300 def topyf(self, tab=""):
302 for attr
in self.
a.attributes:
303 s += tab + attr +
"\n" 306 def update_attributes(self, *attrs):
307 attributes = self.
a.attributes
309 if len(attrs) == 1
and isinstance(attrs[0], (tuple, list)):
313 if uattr
not in attributes:
314 if isinstance(known_attributes, (list, tuple)):
315 if uattr
not in known_attributes:
316 self.warning(
"unknown attribute %r" % (attr))
317 elif not known_attributes(uattr):
318 self.warning(
"unknown attribute %r" % (attr))
319 attributes.append(uattr)
321 self.warning(
"multiple specification of attribute %r" % (attr))
327 a = AttributeHolder(module_procedures=[])
335 Dummy End statement for BeginSource. 338 match = staticmethod(
lambda s:
False)
343 Fortran source content. 346 match = staticmethod(
lambda s:
True)
347 end_stmt_cls = EndSource
348 a = AttributeHolder(module={}, external_subprogram={}, blockdata={})
350 def tofortran(self, isfix=None):
354 tab = self.get_indent_tab(isfix=isfix) +
"!" 355 return tab + BeginStatement.tofortran(self, isfix=isfix)
358 return self.blocktype.upper() +
" " + self.
name 360 def process_item(self):
361 self.
name = self.reader.name
363 self.fill(end_flag=
True)
367 for stmt
in self.content:
368 if isinstance(stmt, Module):
370 self.
a.module[stmt.name] = stmt
371 elif isinstance(stmt, SubProgramStatement):
373 self.
a.external_subprogram[stmt.name] = stmt
374 elif isinstance(stmt, BlockData):
376 self.
a.blockdata[stmt.name] = stmt
381 def get_classes(self):
382 if self.reader.format.is_pyf:
383 return [PythonModule] + program_unit
386 def process_subitem(self, item):
391 if self.reader.format.is_f77:
392 line = item.get_line()
394 message = item.reader.format_message(
396 "assuming the end of undefined PROGRAM statement",
400 logger.warning(message)
403 p.content.extend(self.content)
405 self.content[:] = [p]
407 return BeginStatement.process_subitem(self, item)
409 def topyf(self, tab=""):
411 for name, stmt
in list(self.
a.module.items()):
412 s += stmt.topyf(tab=tab)
413 for name, stmt
in list(self.
a.external_subprogram.items()):
414 s += stmt.topyf(tab=tab)
415 for name, stmt
in list(self.
a.blockdata.items()):
416 s += stmt.topyf(tab=tab)
424 match = re.compile(
r"end(\s*module\s*\w*|)\Z", re.I).match
442 match = re.compile(
r"module\s*\w+\Z", re.I).match
443 end_stmt_cls = EndModule
446 module_subprogram={},
453 known_attributes = [
"PUBLIC",
"PRIVATE"]
455 def get_classes(self):
456 return access_spec + specification_part + module_subprogram_part
458 def process_item(self):
459 name = self.item.get_line().replace(
" ",
"")
460 name = name[len(self.blocktype) :].strip()
462 return BeginStatement.process_item(self)
464 def get_provides(self):
465 return self.
a.module_provides
467 def get_interface(self):
468 return self.
a.module_interface
471 content = self.content[:]
474 stmt = content.pop(0)
475 if isinstance(stmt, Contains):
476 for stmt
in filter_stmts(content, SubProgramStatement):
478 self.
a.module_subprogram[stmt.name] = stmt
479 stmt = content.pop(0)
480 while isinstance(stmt, Comment):
481 stmt = content.pop(0)
482 if not isinstance(stmt, EndModule):
483 stmt.error(
"Expected END MODULE statement (analyzer).")
488 logger.info(
"Not analyzed content: %s" % content)
491 module_provides = self.
a.module_provides
492 for name, var
in list(self.
a.variables.items()):
494 if name
in module_provides:
496 "module data object name conflict with %s, " +
"overriding." 498 self.warning(message % (name))
499 module_provides[name] = var
503 def topyf(self, tab=""):
504 s = tab +
"MODULE " + self.
name +
"\n" 505 s += HasImplicitStmt.topyf(self, tab=tab +
" ")
506 s += AccessSpecs.topyf(self, tab=tab +
" ")
507 s += HasAttributes.topyf(self, tab=tab +
" ")
508 s += HasTypeDecls.topyf(self, tab=tab +
" ")
509 s += HasVariables.topyf(self, tab=tab +
" ")
510 for name, stmt
in list(self.
a.module_interface.items()):
511 s += stmt.topyf(tab=tab +
" ")
512 s += tab +
" CONTAINS\n" 513 for name, stmt
in list(self.
a.module_subprogram.items()):
514 s += stmt.topyf(tab=tab +
" ")
515 s += tab +
"END MODULE " + self.
name +
"\n" 518 def check_private(self, name):
519 if name
in self.
a.public_id_list:
521 if name
in self.
a.private_id_list:
523 if "" in self.
a.public_id_list:
525 if "" in self.
a.private_id_list:
535 match = re.compile(
r"end(\s*python\s*module\s*\w*|)\Z", re.I).match
542 END [PYTHON MODULE [name]] 546 match = re.compile(
r"python\s*module\s*\w+\Z", re.I).match
547 end_stmt_cls = EndPythonModule
549 def get_classes(self):
550 return [Interface, Function, Subroutine, Module]
552 def process_item(self):
553 self.
name = self.item.get_line().replace(
" ",
"")
554 self.
name = self.
name[len(self.blocktype) :].strip()
555 return BeginStatement.process_item(self)
566 match = re.compile(
r"end(\s*program\s*\w*|)\Z", re.I).match
580 match = re.compile(
r"program\s*\w*\Z", re.I).match
581 end_stmt_cls = EndProgram
583 def get_classes(self):
584 return specification_part + execution_part + internal_subprogram_part
586 def process_item(self):
587 if self.item
is not None:
588 name = self.item.get_line().replace(
" ",
"")
589 name = name[len(self.blocktype) :].strip()
592 return BeginStatement.process_item(self)
600 END [BLOCK DATA [<block-data-name>]] 603 match = re.compile(
r"end(\s*block\s*data\s*\w*|)\Z", re.I).match
604 blocktype =
"blockdata" 609 BLOCK DATA [<block-data-name>] 612 end_stmt_cls = EndBlockData
613 match = re.compile(
r"block\s*data\s*\w*\Z", re.I).match
615 def process_item(self):
616 self.
name = self.item.get_line()[5:].lstrip()[4:].lstrip()
617 return BeginStatement.process_item(self)
619 def get_classes(self):
620 return specification_part
627 match = re.compile(
r"end\s*interface\s*(\w+\s*\(.*\)|\w*)\Z", re.I).match
628 blocktype =
"interface" 640 INTERFACE [<generic-spec>] | ABSTRACT INTERFACE 641 END INTERFACE [<generic-spec>] 643 <generic-spec> = <generic-name> 644 | OPERATOR ( <defined-operator> ) 646 | <dtio-generic-spec> 647 <dtio-generic-spec> = READ ( FORMATTED ) 648 | READ ( UNFORMATTED ) 649 | WRITE ( FORMATTED ) 650 | WRITE ( UNFORMATTED ) 654 modes = [
"free",
"fix",
"pyf"]
655 pattern =
r"(interface\s*(\w+\s*\(.*\)|\w*)|abstract\s*interface)\Z" 656 match = re.compile(pattern, re.I).match
657 end_stmt_cls = EndInterface
658 blocktype =
"interface" 660 a = AttributeHolder(interface_provides={})
662 def get_classes(self):
663 line = intrinsic_type_spec + interface_specification
664 if self.reader.format.mode ==
"pyf":
665 return [Subroutine, Function] + line
668 def process_item(self):
669 line = self.item.get_line()
670 line = self.item.apply_map(line)
677 return BeginStatement.process_item(self)
681 return "ABSTRACT INTERFACE" 685 content = self.content[:]
688 stmt = content.pop(0)
693 logger.info(
"Not analyzed content: %s" % content)
696 if self.
name in self.parent.a.variables:
697 var = self.parent.a.variables.pop(self.
name)
700 if isinstance(self.parent, Module):
701 parent_interface = self.parent.get_interface()
702 if self.
name in parent_interface:
703 p = parent_interface[self.
name]
704 last = p.content.pop()
705 assert isinstance(last, EndInterface), repr(last.__class__)
706 p.content += self.content
707 p.update_attributes(self.
a.attributes)
709 parent_interface[self.
name] = self
712 def topyf(self, tab=""):
713 s = tab + self.
tostr() +
"\n" 714 s += HasImplicitStmt.topyf(self, tab=tab +
" ")
715 s += HasAttributes.topyf(self, tab=tab +
" ")
716 s += HasUseStmt.topyf(self, tab=tab +
" ")
717 s += tab +
"END" + self.
tostr() +
"\n" 735 [<prefix>] <FUNCTION|SUBROUTINE> <name> [( <args> )] [<suffix>] 738 a = AttributeHolder(internal_subprogram={})
739 known_attributes = [
"RECURSIVE",
"PURE",
"ELEMENTAL"]
741 def process_item(self):
742 clsname = self.__class__.__name__.lower()
744 line = item.get_line()
746 i = line.lower().find(clsname)
747 assert i != -1, repr((clsname, line))
748 self.
prefix = line[:i].rstrip()
749 self.
name = line[i : m.end()].lstrip()[len(clsname) :].strip()
750 line = line[m.end() :].lstrip()
752 if line.startswith(
"("):
754 assert i != -1, repr(line)
755 line2 = item.apply_map(line[: i + 1])
756 for a
in line2[1:-1].split(
","):
761 line = line[i + 1 :].lstrip()
762 suffix = item.apply_map(line)
763 self.bind, suffix = parse_bind(suffix, item)
765 if isinstance(self, Function):
766 self.
result, suffix = parse_result(suffix, item)
768 assert self.bind
is None, repr(self.bind)
769 self.bind, suffix = parse_result(suffix, item)
772 assert not suffix, repr(suffix)
775 return BeginStatement.process_item(self)
778 clsname = self.__class__.__name__.upper()
783 assert isinstance(self, Function), repr(self.__class__.__name__)
788 suf +=
" RESULT ( %s )" % (self.
result)
790 suf +=
" BIND ( %s )" % (
", ".join(self.bind))
791 return "%s %s(%s)%s" % (s, self.
name,
", ".join(self.
args), suf)
793 def get_classes(self):
795 f2py_stmt + specification_part + execution_part + internal_subprogram_part
799 content = self.content[:]
804 variables = self.
a.variables
806 assert a
not in variables
808 variables[a] = Variable(self, a)
810 variables[a] = Variable(self, a)
812 message =
"argument must be a name or * but got %r" 813 raise AnalyzeError(message % (a))
815 if isinstance(self, Function):
816 var = variables[self.
result] = Variable(self, self.
result)
821 stmt = content.pop(0)
822 if isinstance(stmt, Contains):
823 for stmt
in filter_stmts(content, SubProgramStatement):
825 self.
a.internal_subprogram[stmt.name] = stmt
826 stmt = content.pop(0)
827 while isinstance(stmt, Comment):
828 stmt = content.pop(0)
829 assert isinstance(stmt, self.end_stmt_cls), repr(stmt)
830 elif isinstance(stmt, self.end_stmt_cls):
833 if hasattr(stmt,
"analyze"):
836 message =
"Failed to parse: {0}" 837 raise AnalyzeError(message.format(str(stmt)))
840 logger.info(
"Not analyzed content: %s" % content)
843 parent_provides = self.parent.get_provides()
844 if parent_provides
is not None:
845 if self.
name in parent_provides:
846 message =
"module subprogram name conflict with %s, " +
"overriding." 847 self.warning(message % (self.
name))
849 parent_provides[self.
name] = self
853 "C1241 violation: prefix cannot specify both " 854 +
"ELEMENTAL and RECURSIVE" 856 self.warning(message)
859 def topyf(self, tab=""):
860 s = tab + self.__class__.__name__.upper()
861 s +=
" " + self.
name +
" (%s)" % (
", ".join(self.
args))
862 if isinstance(self, Function)
and self.
result != self.
name:
863 s +=
" RESULT (%s)" % (self.
result)
865 s += HasImplicitStmt.topyf(self, tab=tab +
" ")
866 s += AccessSpecs.topyf(self, tab=tab +
" ")
867 s += HasTypeDecls.topyf(self, tab=tab +
" ")
868 s += HasVariables.topyf(self, tab=tab +
" ", only_variables=self.
args)
869 s += tab +
"END " + self.__class__.__name__.upper() +
" " + self.
name +
"\n" 875 def is_private(self):
876 return self.parent.check_private(self.
name)
878 def is_recursive(self):
879 return "RECURSIVE" in self.
a.attributes
882 return "PURE" in self.
a.attributes
884 def is_elemental(self):
885 return "ELEMENTAL" in self.
a.attributes
890 END [SUBROUTINE [name]] 894 r"end\s*(?:subroutine\s*(?:(?P<name>\w+)\s*)?)?$", re.IGNORECASE
900 [<prefix>] SUBROUTINE <name> [( [<dummy-arg-list>] ) 901 [<proc-language-binding-spec>]] 904 end_stmt_cls = EndSubroutine
905 pattern =
r"(recursive|pure|elemental|\s)*subroutine\s*\w+" 906 match = re.compile(pattern, re.I).match
907 _repr_attr_names = [
"prefix",
"bind",
"suffix",
"args"] + Statement._repr_attr_names
915 END [FUNCTION [name]] 918 match = re.compile(
r"end(\s*function\s*\w*|)\Z", re.I).match
923 [<prefix>] FUNCTION <name> ( [<dummy-arg-list>] ) [<suffix>] 924 <prefix> = <prefix-spec> [<prefix-spec>]... 925 <prefix-spec> = <declaration-type-spec> 926 | RECURSIVE | PURE | ELEMENTAL 927 <suffix> = <proc-language-binding-spec> [RESULT ( <result-name> )] 928 | RESULT ( <result-name> ) [<proc-language-binding-spec>] 931 end_stmt_cls = EndFunction
932 pattern =
r"(recursive|pure|elemental|\s)*function\s*\w+" 933 match = re.compile(pattern, re.I).match
940 ] + Statement._repr_attr_names
942 def subroutine_wrapper_code(self):
943 name =
"f2pywrap_" + self.
name 944 args = [
"f2pyvalue_" + self.
result] + self.
args 945 var = self.
a.variables[self.
result]
946 typedecl = var.get_typedecl().astypedecl()
949 lines.append(
"%sSUBROUTINE %s(%s)" % (tab, name,
", ".join(args)))
950 if isinstance(self.parent, Module):
951 lines.append(
"%s USE %s" % (tab, self.parent.name))
953 if isinstance(typedecl, TypeStmt):
954 type_decl = typedecl.get_type_decl(typedecl.name)
955 if type_decl.parent
is self:
956 for line
in str(type_decl).split(
"\n"):
957 lines.append(
"%s %s" % (tab, line.lstrip()))
958 lines.append(
"%s EXTERNAL %s" % (tab, self.
name))
959 lines.append(
"%s %s %s" % (tab, str(typedecl).lstrip(), self.
name))
960 lines.append(
"%s %s %s" % (tab, str(typedecl).lstrip(), args[0]))
961 lines.append(
"!f2py intent(out) %s" % (args[0]))
963 v = self.
a.variables[a]
964 lines.append(
"%s %s" % (tab, str(v).lstrip()))
966 "%s %s = %s(%s)" % (tab, args[0], self.
name,
", ".join(self.
args))
968 lines.append(
"%sEND SUBROUTINE %s" % (tab, name))
969 return "\n".join(lines)
971 def subroutine_wrapper(self):
973 from .api
import parse
976 while len(block.content) == 1:
977 block = block.content[0]
986 <prefix> <declaration-type-spec> <function|subroutine> ... 989 match = re.compile(
r"(pure|elemental|recursive|\s)+\b", re.I).match
991 def process_item(self):
992 line = self.
item.get_line()
994 prefix = line[: m.end()].rstrip()
995 rest = self.
item.get_line()[m.end() :].lstrip()
998 self.
item.clone(rest)
1001 if self.
parent.__class__
not in [Function, Subroutine]:
1004 prefix = prefix +
" " + self.
parent.prefix
1005 self.
parent.prefix = prefix.strip()
1014 match = re.compile(
r"end\s*select\s*\w*\Z", re.I).match
1015 blocktype =
"select" 1020 Base class for the Select (case/type) statement 1024 end_stmt_cls = EndSelect
1028 """Populate the state of this Select object by parsing the 1029 associated line of code""" 1034 line = item.get_line()[6:].lstrip()[4:].lstrip()[1:-1].strip()
1035 self.
expr = item.apply_map(line)
1037 return BeginStatement.process_item(self)
1042 [<case-construct-name> :] SELECT CASE ( <case-expr> ) 1046 match = re.compile(
r"select\s*case\s*\(.*\)\Z", re.I).match
1049 return "SELECT CASE ( %s )" % (self.
expr)
1052 """Return the list of classes that this instance may 1054 return [Case] + execution_part_construct
1059 [<case-construct-name> :] SELECT TYPE ( <case-expr> ) 1063 match = re.compile(
r"select\s*type\s*\(.*\)\Z", re.I).match
1066 return "SELECT TYPE ( %s )" % (self.
expr)
1069 """Return the list of classes that this instance may 1071 return [TypeIs, ClassIs] + execution_part_construct
1079 END WHERE [<where-construct-name>] 1082 match = re.compile(
r"end\s*\where\s*\w*\Z", re.I).match
1087 [<where-construct-name> :] WHERE ( <mask-expr> ) 1088 <mask-expr> = <logical-expr> 1091 match = re.compile(
r"where\s*\([^)]*\)\Z", re.I).match
1092 end_stmt_cls = EndWhere
1096 return "WHERE ( %s )" % (self.
expr)
1098 def process_item(self):
1099 self.
expr = self.item.get_line()[5:].lstrip()[1:-1].strip()
1101 return BeginStatement.process_item(self)
1103 def get_classes(self):
1104 return [Assignment, WhereStmt, WhereConstruct, ElseWhere]
1107 WhereConstruct = Where
1115 END FORALL [<forall-construct-name>] 1118 match = re.compile(
r"end\s*forall\s*\w*\Z", re.I).match
1123 [<forall-construct-name> :] FORALL <forall-header> 1124 [<forall-body-construct>]... 1125 <forall-body-construct> = <forall-assignment-stmt> 1128 | <forall-construct> 1130 <forall-header> = ( <forall-triplet-spec-list> [, <scalar-mask-expr>] ) 1131 <forall-triplet-spec> = <index-name> = <subscript> : <subscript> 1133 <subscript|stride> = <scalar-int-expr> 1134 <forall-assignment-stmt> = <assignment-stmt> | <pointer-assignment-stmt> 1137 end_stmt_cls = EndForall
1138 match = re.compile(
r"forall\s*\(.*\)\Z", re.I).match
1141 def process_item(self):
1142 self.
specs = self.item.get_line()[6:].lstrip()[1:-1].strip()
1143 return BeginStatement.process_item(self)
1146 return "FORALL (%s)" % (self.
specs)
1148 def get_classes(self):
1158 ForallConstruct = Forall
1166 END IF [<if-construct-name>] 1169 match = re.compile(
r"end\s*if\s*\w*\Z", re.I).match
1175 [<if-construct-name> :] IF ( <scalar-logical-expr> ) THEN 1177 IfThen instance has the following attributes: 1181 match = re.compile(
r"if\s*\(.*\)\s*then\Z", re.I).match
1182 end_stmt_cls = EndIfThen
1186 return "IF (%s) THEN" % (self.
expr)
1188 def process_item(self):
1190 line = item.get_line()[2:-4].strip()
1191 assert line[0] ==
"(" and line[-1] ==
")", repr(line)
1192 self.
expr = item.apply_map(line[1:-1].strip())
1194 return BeginStatement.process_item(self)
1196 def get_classes(self):
1197 return [Else, ElseIf] + execution_part_construct
1200 class If(BeginStatement):
1202 IF ( <scalar-logical-expr> ) action-stmt 1205 match = re.compile(
r"if\s*\(", re.I).match
1207 def process_item(self):
1209 mode = self.reader.format.mode
1211 classes = [cls
for cls
in classes
if mode
in cls.modes]
1213 line = item.get_line()[2:].lstrip()
1215 expr = line[1:i].strip()
1216 line = line[i + 1 :].strip()
1217 if line.lower() ==
"then":
1220 self.
expr = item.apply_map(expr)
1223 newitem = self.get_item()
1225 newitem = item.copy(line, apply_map=
True)
1226 newline = newitem.get_line()
1228 if cls.
match(newline):
1229 stmt = cls(self, newitem)
1231 self.content.append(stmt)
1234 self.put_item(newitem)
1239 assert len(self.content) == 1, repr(self.content)
1240 return "IF (%s) %s" % (self.
expr, str(self.content[0]).lstrip())
1242 def tofortran(self, isfix=None):
1243 return self.get_indent_tab(isfix=isfix) + self.
tostr()
1245 def get_classes(self):
1254 END DO [<do-construct-name>] 1257 match = re.compile(
r"end\s*do\s*(?:(?P<name>\w+)\s*)?\Z", re.IGNORECASE).match
1262 Parses the next line assuming it is an "End do" statement. 1264 Overrides method in `EndStatement`. 1267 line = item.get_line()
1268 matched = self.
match(line)
1270 found_label = getattr(self.item,
"label",
None)
1271 expected_label = getattr(self.parent,
"endlabel",
None)
1274 if found_label != expected_label:
1276 'When entering the "do" block {start} was' 1277 +
" given as the end label but {end} was found." 1279 self.warning(message.format(start=expected_label, end=found_label))
1283 'A label was specified when entering the "do" ' 1284 +
" block ({label}) but none was found at the end." 1286 self.warning(message.format(label=expected_label))
1289 found_name = matched.group(
"name")
or None 1290 expected_name = self.parent.construct_name
1293 if found_name != expected_name:
1295 'The "do" block was specified with the name' 1296 +
' "{open}" but was closed with the name' 1299 self.warning(message.format(open=expected_name, close=found_name))
1303 'A name ("{name}") was specified for the "do" ' 1304 +
"block but was not given when closing the block." 1306 self.warning(message.format(name=expected_name))
1311 'The name "{name}" was used when closing a "do"' 1312 +
"block but none was specified when opening it." 1314 self.warning(message.format(name=found_name))
1316 return EndStatement.process_item(self)
1319 class Do(BeginStatement):
1321 [<do-construct-name> :] DO label [loopcontrol] 1322 [<do-construct-name> :] DO [loopcontrol] 1326 match = re.compile(
r"do\b\s*\d*", re.I).match
1327 pattern =
r"do\b\s*(?:(?P<label>\d+)\s*)?(?:,\s*)?(?P<loopcontrol>.+)?\Z" 1328 item_re = re.compile(pattern, re.IGNORECASE).match
1329 end_stmt_cls = EndDo
1336 lst.append(str(part))
1337 return " ".join(lst)
1341 Parses the next line assuming it is a "Do" statement. 1343 Overrides method in `BeginStatement`. 1346 line = item.get_line()
1348 if matched.group(
"label"):
1349 self.
endlabel = int(matched.group(
"label").strip())
1353 if matched.group(
"loopcontrol"):
1354 self.
loopcontrol = item.apply_map(matched.group(
"loopcontrol").strip())
1357 return BeginStatement.process_item(self)
1359 def process_subitem(self, item):
1365 if isinstance(self.parent, Do)
and label == self.parent.endlabel:
1368 return BeginStatement.process_subitem(self, item)
or result
1370 def get_classes(self):
1371 return execution_part_construct
1379 END ASSOCIATE [<associate-construct-name>] 1382 match = re.compile(
r"end\s*associate\s*\w*\Z", re.I).match
1387 [<associate-construct-name> :] ASSOCIATE ( <association-list> ) 1390 <association> = <associate-name> => <selector> 1391 <selector> = <expr> | <variable> 1394 match = re.compile(
r"associate\s*\(.*\)\Z", re.I).match
1395 end_stmt_cls = EndAssociate
1397 def process_item(self):
1398 line = self.item.get_line()[9:].lstrip()
1400 return BeginStatement.process_item(self)
1405 def get_classes(self):
1406 return execution_part_construct
1414 END TYPE [<type-name>] 1417 match = re.compile(
r"end\s*type\s*\w*\Z", re.I).match
1422 BeginStatement, HasVariables, HasAttributes, HasModuleProcedures, AccessSpecs
1425 TYPE [[, <typ-attr-spec-list>] ::] <type-name> [( <type-param-name-list> )] 1426 <typ-attr-spec> = <access-spec> | EXTENDS ( <parent-type-name> ) 1427 | ABSTRACT | BIND(C) 1430 match = re.compile(
r"type\b\s*").match
1431 end_stmt_cls = EndType
1433 a = AttributeHolder(
1439 pattern =
r"\A(PUBLIC|PRIVATE|SEQUENCE|ABSTRACT|BIND\s*\(.*\))\Z" 1440 known_attributes = re.compile(pattern, re.I).match
1442 def process_item(self):
1443 line = self.item.get_line()[4:].lstrip()
1444 if line.startswith(
"("):
1450 for s
in line[:i].split(
","):
1454 line = line[i + 2 :].lstrip()
1458 self.
name = line[:i].rstrip()
1459 assert line[-1] ==
")", repr(line)
1460 self.
params = split_comma(line[i + 1 : -1].lstrip())
1464 if not is_name(self.
name):
1467 return BeginStatement.process_item(self)
1472 s +=
", ".join([
""] + self.
specs) +
" ::" 1473 s +=
" " + self.
name 1475 s +=
" (" +
", ".join(self.
params) +
")" 1478 def get_classes(self):
1480 [Integer] + private_or_sequence + component_part + type_bound_procedure_part
1484 for spec
in self.
specs:
1487 assert spec.endswith(
")"), repr(spec)
1488 s = spec[:i].rstrip().upper()
1489 n = spec[i + 1 : -1].strip()
1494 args, rest = parse_bind(spec)
1495 assert not rest, repr(rest)
1496 spec =
"BIND(%s)" % (
", ".join(args))
1498 spec =
"%s(%s)" % (s, n)
1503 component_names = self.
a.component_names
1504 content = self.content[:]
1506 stmt = content.pop(0)
1512 message =
"Not analyzed content: %s" % content
1513 logging.getLogger(__class__).info(message)
1515 parameters = self.
a.parameters
1516 components = self.
a.components
1517 component_names = self.
a.component_names
1518 for name
in self.
a.variable_names:
1519 var = self.
a.variables[name]
1521 parameters[name] = var
1523 component_names.append(name)
1524 components[name] = var
1526 self.parent.a.type_decls[self.
name] = self
1528 parent_provides = self.parent.get_provides()
1529 if parent_provides
is not None:
1531 if self.
name in parent_provides:
1532 message =
"type declaration name conflict with {}, " +
"overriding." 1533 self.warning(message.format(self.
name))
1534 parent_provides[self.
name] = self
1538 def topyf(self, tab=""):
1540 if self.
a.extends
is not None:
1541 s +=
", EXTENDS(%s) ::" % (self.
a.extends)
1542 s +=
" " + self.
name 1543 if self.
a.parameters:
1544 s +=
" (%s)" % (
", ".join(self.
a.parameters))
1546 s += AccessSpecs.topyf(self, tab=tab +
" ")
1547 s += HasAttributes.topyf(self, tab=tab +
" ")
1548 s += HasVariables.topyf(self, tab=tab +
" ")
1549 s += tab +
"END TYPE " + self.
name +
"\n" 1554 def is_public(self):
1557 def is_private(self):
1558 if "PUBLIC" in self.
a.attributes:
1560 if "PRIVATE" in self.
a.attributes:
1562 return self.parent.check_private(self.
name)
1576 match = re.compile(
r"end\s*enum\Z", re.I).match
1583 <enumerator-def-stmt> 1584 [<enumerator-def-stmt>]... 1588 end_stmt_cls = EndEnum
1589 match = re.compile(
r"enum\s*,\s*bind\s*\(\s*c\s*\)\Z", re.I).match
1591 def process_item(self):
1592 return BeginStatement.process_item(self)
1594 def get_classes(self):
1600 f2py_stmt = [Threadsafe, FortranName, Depend, Check, CallStatement, CallProtoArgument]
1602 access_spec = [Public, Private]
1604 interface_specification = [Function, Subroutine, ModuleProcedure]
1606 module_subprogram_part = [Contains, Function, Subroutine]
1608 specification_stmt = access_spec + [
1629 intrinsic_type_spec = [
1641 derived_type_spec = []
1642 type_spec = intrinsic_type_spec + derived_type_spec
1643 declaration_type_spec = intrinsic_type_spec + [TypeStmt, Class]
1645 type_declaration_stmt = declaration_type_spec
1647 private_or_sequence = [Private, Sequence]
1649 component_part = declaration_type_spec + [ModuleProcedure]
1651 proc_binding_stmt = [SpecificBinding, GenericBinding, FinalBinding]
1653 type_bound_procedure_part = [Contains, Private] + proc_binding_stmt
1691 executable_construct = [
1701 execution_part_construct = executable_construct + [Format, Entry, Data]
1703 execution_part = execution_part_construct[:]
1706 for cls
in [EndFunction, EndProgram, EndSubroutine]:
1708 execution_part.remove(cls)
1712 internal_subprogram = [Function, Subroutine]
1714 internal_subprogram_part = [Contains] + internal_subprogram
1718 declaration_construct = (
1729 + specification_stmt
1730 + type_declaration_stmt
1734 implicit_part = [Implicit, Parameter, Format, Entry]
1736 specification_part = [Use, Import] + implicit_part + declaration_construct
1739 external_subprogram = [Function, Subroutine]
1742 [Program] + specification_part + execution_part + internal_subprogram_part
1745 program_unit = main_program + external_subprogram + [Module, BlockData]
def update_attributes(self, attrs)
def subroutine_wrapper_code(self)
def get_type_by_name(self, name)