""" Fortran single line statements. ----- Permission to use, modify, and distribute this software is given under the terms of the NumPy License. See http://scipy.org. NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. Author: Pearu Peterson Created: May 2006 ----- """ __all__ = ['GeneralAssignment', 'Assignment','PointerAssignment','Assign','Call','Goto','ComputedGoto','AssignedGoto', 'Continue','Return','Stop','Print','Read','Read0','Read1','Write','Flush','Wait', 'Contains','Allocate','Deallocate','ModuleProcedure','Access','Public','Private', 'Close','Cycle','Backspace','Endfile','Rewind','Open','Format','Save', 'Data','Nullify','Use','Exit','Parameter','Equivalence','Dimension','Target', 'Pointer','Protected','Volatile','Value','ArithmeticIf','Intrinsic', 'Inquire','Sequence','External','Namelist','Common','Optional','Intent', 'Entry','Import','ForallStmt','SpecificBinding','GenericBinding', 'FinalBinding','Allocatable','Asynchronous','Bind','Else','ElseIf', 'Case','WhereStmt','ElseWhere','Enumerator','FortranName','Threadsafe', 'Depend','Check','CallStatement','CallProtoArgument','Pause'] import re import sys from base_classes import Statement, Variable # Auxiliary tools from utils import split_comma, specs_split_comma, AnalyzeError, ParseError,\ get_module_file, parse_bind, parse_result, is_name class StatementWithNamelist(Statement): """ [ :: ] """ def process_item(self): if self.item.has_map(): self.isvalid = False return if hasattr(self,'stmtname'): clsname = self.stmtname else: clsname = self.__class__.__name__ line = self.item.get_line()[len(clsname):].lstrip() if line.startswith('::'): line = line[2:].lstrip() self.items = items = [] for item in split_comma(line): if not is_name(item): self.isvalid = False return items.append(item) return def tofortran(self,isfix=None): if hasattr(self,'stmtname'): clsname = self.stmtname.upper() else: clsname = self.__class__.__name__.upper() s = ', '.join(self.items) if s: s = ' ' + s return self.get_indent_tab(isfix=isfix) + clsname + s # Execution statements class GeneralAssignment(Statement): """ = => """ match = re.compile(r'\w[^=]*\s*=\>?').match item_re = re.compile(r'(?P\w[^=]*)\s*(?P=\>?)\s*(?P.*)\Z',re.I).match _repr_attr_names = ['variable','sign','expr'] + Statement._repr_attr_names def process_item(self): m = self.item_re(self.item.get_line()) if not m: self.isvalid = False return self.sign = sign = m.group('sign') if isinstance(self, Assignment) and sign != '=': self.isvalid = False return elif isinstance(self, PointerAssignment) and sign != '=>': self.isvalid = False return else: if sign=='=>': self.__class__ = PointerAssignment else: self.__class__ = Assignment apply_map = self.item.apply_map self.variable = apply_map(m.group('variable').replace(' ','')) self.expr = apply_map(m.group('expr')) return def tofortran(self, isfix=None): return self.get_indent_tab(isfix=isfix) + '%s %s %s' \ % (self.variable, self.sign, self.expr) def analyze(self): return class Assignment(GeneralAssignment): pass class PointerAssignment(GeneralAssignment): pass class Assign(Statement): """ ASSIGN