Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def process_item(self):
line = self.item.get_line()
line = self.item.apply_map(line)
self.isabstract = line.startswith('abstract')
if self.isabstract:
self.generic_spec = ''
else:
self.generic_spec = line[len(self.blocktype):].strip()
self.name = self.generic_spec # XXX
return BeginStatement.process_item(self)
return BeginStatement.process_item(self)
def tostr(self):
return 'ASSOCIATE (%s)' % (self.associations)
def get_classes(self):
return execution_part_construct
# Type
class EndType(EndStatement):
"""
END TYPE []
"""
match = re.compile(r'end\s*type\s*\w*\Z', re.I).match
blocktype = 'type'
class Type(BeginStatement, HasVariables, HasAttributes, AccessSpecs):
"""
TYPE [ [ , ] :: ] [ ( ) ]
= | EXTENDS ( )
| ABSTRACT | BIND(C)
"""
match = re.compile(r'type\b\s*').match
end_stmt_cls = EndType
a = AttributeHolder(extends = None,
parameters = {},
component_names = [], # specifies component order for sequence types
components = {}
)
known_attributes = re.compile(r'\A(PUBLIC|PRIVATE|SEQUENCE|ABSTRACT|BIND\s*\(.*\))\Z',re.I).match
def process_item(self):
# and here we fix that:
if self.reader.isf77:
line = item.get_line()
if line=='end':
message = item.reader.format_message(\
'WARNING',
'assuming the end of undefined PROGRAM statement',
item.span[0],item.span[1])
logger.warning(message)
# print >> sys.stderr, message
p = Program(self)
p.content.extend(self.content)
p.content.append(EndProgram(p,item))
self.content[:] = [p]
return
return BeginStatement.process_subitem(self, item)
def tostr(self):
return 'IF (%s) THEN' % (self.expr)
def process_item(self):
item = self.item
line = item.get_line()[2:-4].strip()
assert line[0]=='(' and line[-1]==')',repr(line)
self.expr = item.apply_map(line[1:-1].strip())
self.construct_name = item.name
return BeginStatement.process_item(self)
def get_classes(self):
return [Else, ElseIf] + execution_part_construct
class If(BeginStatement):
"""
IF ( ) action-stmt
"""
match = re.compile(r'if\s*\(',re.I).match
def process_item(self):
item = self.item
mode = self.reader.mode
classes = self.get_classes()
classes = [cls for cls in classes if mode in cls.modes]
line = item.get_line()[2:].lstrip()
i = line.find(')')
expr = line[1:i].strip()
line = line[i+1:].strip()
self.construct_name = self.item.name
return BeginStatement.process_item(self)
def get_classes(self):
return [Case] + execution_part_construct
# Where
class EndWhere(EndStatement):
"""
END WHERE [ ]
"""
match = re.compile(r'end\s*\where\s*\w*\Z',re.I).match
class Where(BeginStatement):
"""
[ : ] WHERE ( )
=
"""
match = re.compile(r'where\s*\([^)]*\)\Z',re.I).match
end_stmt_cls = EndWhere
name = ''
def tostr(self):
return 'WHERE ( %s )' % (self.expr)
def process_item(self):
self.expr = self.item.get_line()[5:].lstrip()[1:-1].strip()
self.construct_name = self.item.name
return BeginStatement.process_item(self)
def get_classes(self):
return [Assignment, WhereStmt,
return
if self.parent.__class__ not in [Function, Subroutine]:
self.isvalid = False
return
prefix = prefix + ' ' + self.parent.prefix
self.parent.prefix = prefix.strip()
self.ignore = True
return
# SelectCase
class EndSelect(EndStatement):
match = re.compile(r'end\s*select\s*\w*\Z', re.I).match
blocktype = 'select'
class Select(BeginStatement):
"""
[ : ] SELECT CASE ( )
"""
match = re.compile(r'select\s*case\s*\(.*\)\Z',re.I).match
end_stmt_cls = EndSelect
name = ''
def tostr(self):
return 'SELECT CASE ( %s )' % (self.expr)
def process_item(self):
self.expr = self.item.get_line()[6:].lstrip()[4:].lstrip()[1:-1].strip()
self.construct_name = self.item.name
return BeginStatement.process_item(self)
def get_classes(self):
return [Case] + execution_part_construct
def topyf(self, tab=''): # XXXX
s = ''
for name, stmt in list(self.a.module.items()):
s += stmt.topyf(tab=tab)
for name, stmt in list(self.a.external_subprogram.items()):
s += stmt.topyf(tab=tab)
for name, stmt in list(self.a.blockdata.items()):
s += stmt.topyf(tab=tab)
return s
# Module
class EndModule(EndStatement):
match = re.compile(r'end(\s*module\s*\w*|)\Z', re.I).match
class Module(BeginStatement, HasAttributes,
HasImplicitStmt, HasUseStmt, HasVariables,
HasTypeDecls, AccessSpecs):
"""
MODULE
..
END [MODULE [name]]
"""
match = re.compile(r'module\s*\w+\Z', re.I).match
end_stmt_cls = EndModule
a = AttributeHolder(module_subprogram = {},
module_provides = {}, # all symbols that are public and so
# can be imported via USE statement
# by other blocks
module_interface = {}
)
def tofortran(self,isfix=None):
return self.get_indent_tab(isfix=isfix) + self.tostr()
def get_classes(self):
return action_stmt
# Do
class EndDo(EndStatement):
"""
END DO [ ]
"""
match = re.compile(r'end\s*do\s*\w*\Z', re.I).match
blocktype = 'do'
class Do(BeginStatement):
"""
[ : ] DO label [loopcontrol]
[ : ] DO [loopcontrol]
"""
match = re.compile(r'do\b\s*\d*',re.I).match
item_re = re.compile(r'do\b\s*(?P<label>\d*)\s*,?\s*(?P.*)\Z',re.I).match
end_stmt_cls = EndDo
name = ''
def tostr(self):
l = ['DO']
for part in [self.endlabel, self.loopcontrol]:
if part:
l.append(str(part))</label>
p.update_attributes(self.a.attributes)
else:
parent_interface[self.name] = self
return
def topyf(self, tab=''):
s = tab + self.tostr() + '\n'
s += HasImplicitStmt.topyf(self, tab=tab+' ')
s += HasAttributes.topyf(self, tab=tab+' ')
s += HasUseStmt.topyf(self, tab=tab+' ')
s += tab + 'END' + self.tostr() + '\n'
return s
# Subroutine
class SubProgramStatement(BeginStatement, ProgramBlock,
HasImplicitStmt, HasAttributes,
HasUseStmt,
HasVariables, HasTypeDecls, AccessSpecs
):
"""
[ ] [ ( ) ] [ ]
"""
a = AttributeHolder(internal_subprogram = {})
known_attributes = ['RECURSIVE', 'PURE', 'ELEMENTAL']
def process_item(self):
clsname = self.__class__.__name__.lower()
item = self.item
line = item.get_line()
m = self.match(line)
def get_classes(self):
return [GeneralAssignment, WhereStmt, WhereConstruct,
ForallConstruct, ForallStmt]
ForallConstruct = Forall
# IfThen
class EndIfThen(EndStatement):
"""
END IF [ ]
"""
match = re.compile(r'end\s*if\s*\w*\Z', re.I).match
blocktype = 'if'
class IfThen(BeginStatement):
"""
[ :] IF ( ) THEN
IfThen instance has the following attributes:
expr
"""
match = re.compile(r'if\s*\(.*\)\s*then\Z',re.I).match
end_stmt_cls = EndIfThen
name = ''
def tostr(self):
return 'IF (%s) THEN' % (self.expr)
def process_item(self):
item = self.item