Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _cleanup(self):
self.process_attribs()
self.all_procs = {}
for p in self.routines:
self.all_procs[p.name.lower()] = p
for interface in self.interfaces:
if not interface.abstract:
self.all_procs[interface.name.lower()] = interface
if interface.generic:
for proc in interface.iterator('subroutines', 'functions'):
self.all_procs[proc.name.lower()] = proc
self.variables = [v for v in self.variables if 'external' not in v.attribs]
class FortranProgram(FortranCodeUnit):
"""
An object representing the main Fortran program.
"""
def _initialize(self,line):
self.name = line.group(1)
if self.name == None: self.name = ''
self.variables = []
self.enums = []
self.subroutines = []
self.functions = []
self.interfaces = []
self.types = []
self.uses = []
self.calls = []
self.absinterfaces = []
self.attr_dict = dict()
if proc.name.lower() == self.args[i].lower():
self.args[i] = proc
self.interfaces.remove(intr)
self.args[i].parent = self
break
if type(self.args[i]) == str:
if self.args[i][0].lower() in 'ijklmn':
vartype = 'integer'
else:
vartype = 'real'
self.args[i] = FortranVariable(self.args[i],vartype,self)
self.args[i].doc = ''
self.process_attribs()
self.variables = [v for v in self.variables if 'external' not in v.attribs]
class FortranFunction(FortranCodeUnit):
"""
An object representing a Fortran function and holding all of said function's
contents.
"""
def _initialize(self,line):
self.proctype = 'Function'
self.name = line.group(2)
attribstr = line.group(1)
self.module = False
self.mp = False
if not attribstr: attribstr = ""
self.attribs = []
if attribstr.lower().find("impure") >= 0:
self.attribs.append("impure")
attribstr = re.sub("impure","",attribstr,0,re.IGNORECASE)
if attribstr.lower().find("pure") >= 0:
settings['predocmark'],settings['docmark_alt'],
settings['predocmark_alt'],fixed,preprocessor,
settings['macro'],settings['include'])
FortranContainer.__init__(self,source,"")
readobj = open(self.path,'r')
self.raw_src = readobj.read()
if self.fixed:
self.src = highlight(self.raw_src,FortranFixedLexer(),
HtmlFormatter(lineanchors='ln', cssclass='hl'))
else:
self.src = highlight(self.raw_src,FortranLexer(),
HtmlFormatter(lineanchors='ln', cssclass='hl'))
class FortranModule(FortranCodeUnit):
"""
An object representing individual modules within your source code. These
objects contains lists of all of the module's contents, as well as its
dependencies.
"""
ONLY_RE = re.compile('^\s*,\s*only\s*:\s*(?=[^,])',re.IGNORECASE)
RENAME_RE = re.compile('(\w+)\s*=>\s*(\w+)',re.IGNORECASE)
def _initialize(self,line):
self.name = line.group(1)
self.uses = []
self.variables = []
self.enums = []
self.public_list = []
self.private_list = []
self.protected_list = []
for var in self.variables:
if var.name.lower() == self.retvar.lower():
self.retvar = var
self.variables.remove(var)
break
else:
if self.retvar[0].lower() in 'ijklmn':
vartype = 'integer'
else:
vartype = 'real'
self.retvar = FortranVariable(self.retvar,vartype,self)
self.process_attribs()
self.variables = [v for v in self.variables if 'external' not in v.attribs]
class FortranSubmoduleProcedure(FortranCodeUnit):
"""
An object representing a the implementation of a Module Function or
Module Subroutine in a sumbmodule.
"""
def _initialize(self,line):
self.proctype = 'Module Procedure'
self.name = line.group(2)
self.variables = []
self.enums = []
self.uses = []
self.calls = []
self.subroutines = []
self.functions = []
self.interfaces = []
self.absinterfaces = []
self.types = []
self.submodules.append(FortranSubmodule(source,
self.SUBMODULE_RE.match(line),self))
self.num_lines += self.submodules[-1].num_lines - 1
else:
raise Exception("Found SUBMODULE in {}".format(type(self).__name__[7:].upper()))
elif self.PROGRAM_RE.match(line):
if hasattr(self,'programs'):
self.programs.append(FortranProgram(source,
self.PROGRAM_RE.match(line),self))
self.num_lines += self.programs[-1].num_lines - 1
else:
raise Exception("Found PROGRAM in {}".format(type(self).__name__[7:].upper()))
if len(self.programs) > 1:
raise Exception("Multiple PROGRAM units in same source file.")
elif self.SUBROUTINE_RE.match(line):
if isinstance(self,FortranCodeUnit) and not incontains: continue
if hasattr(self,'subroutines'):
self.subroutines.append(FortranSubroutine(source,
self.SUBROUTINE_RE.match(line),self,
permission))
self.num_lines += self.subroutines[-1].num_lines - 1
else:
raise Exception("Found SUBROUTINE in {}".format(type(self).__name__[7:].upper()))
elif self.FUNCTION_RE.match(line):
if isinstance(self,FortranCodeUnit) and not incontains: continue
if hasattr(self,'functions'):
self.functions.append(FortranFunction(source,
self.FUNCTION_RE.match(line),self,
permission))
self.num_lines += self.functions[-1].num_lines - 1
else:
raise Exception("Found FUNCTION in {}".format(type(self).__name__[7:].upper()))
self.num_lines += self.programs[-1].num_lines - 1
else:
raise Exception("Found PROGRAM in {}".format(type(self).__name__[7:].upper()))
if len(self.programs) > 1:
raise Exception("Multiple PROGRAM units in same source file.")
elif self.SUBROUTINE_RE.match(line):
if isinstance(self,FortranCodeUnit) and not incontains: continue
if hasattr(self,'subroutines'):
self.subroutines.append(FortranSubroutine(source,
self.SUBROUTINE_RE.match(line),self,
permission))
self.num_lines += self.subroutines[-1].num_lines - 1
else:
raise Exception("Found SUBROUTINE in {}".format(type(self).__name__[7:].upper()))
elif self.FUNCTION_RE.match(line):
if isinstance(self,FortranCodeUnit) and not incontains: continue
if hasattr(self,'functions'):
self.functions.append(FortranFunction(source,
self.FUNCTION_RE.match(line),self,
permission))
self.num_lines += self.functions[-1].num_lines - 1
else:
raise Exception("Found FUNCTION in {}".format(type(self).__name__[7:].upper()))
elif self.TYPE_RE.match(line) and blocklevel == 0:
if hasattr(self,'types'):
self.types.append(FortranType(source,self.TYPE_RE.match(line),
self,permission))
self.num_lines += self.types[-1].num_lines - 1
else:
raise Exception("Found derived TYPE in {}".format(type(self).__name__[7:].upper()))
elif self.INTERFACE_RE.match(line) and blocklevel == 0:
if hasattr(self,'interfaces'):
if proc.name.lower() == self.args[i].lower():
self.args[i] = proc
self.interfaces.remove(intr)
self.args[i].parent = self
break
if type(self.args[i]) == str:
if self.args[i][0].lower() in 'ijklmn':
vartype = 'integer'
else:
vartype = 'real'
self.args[i] = FortranVariable(self.args[i],vartype,self)
self.args[i].doc = ''
self.process_attribs()
self.variables = [v for v in self.variables if 'external' not in v.attribs]
class FortranFunction(FortranCodeUnit):
"""
An object representing a Fortran function and holding all of said function's
contents.
"""
def _initialize(self,line):
self.proctype = 'Function'
self.name = line.group(2)
attribstr = line.group(1)
self.module = False
self.mp = False
if not attribstr: attribstr = ""
self.attribs = []
if attribstr.lower().find("impure") >= 0:
self.attribs.append("impure")
attribstr = re.sub("impure","",attribstr,0,re.IGNORECASE)
if attribstr.lower().find("pure") >= 0:
# will be added later, during correlation.
self.process_attribs()
self.variables = [v for v in self.variables if 'external' not in v.attribs]
self.all_procs = {}
for p in self.routines:
self.all_procs[p.name.lower()] = p
for interface in self.interfaces:
if not interface.abstract:
self.all_procs[interface.name.lower()] = interface
if interface.generic:
for proc in interface.iterator('subroutines', 'functions'):
self.all_procs[proc.name.lower()] = proc
class FortranSubroutine(FortranCodeUnit):
"""
An object representing a Fortran subroutine and holding all of said
subroutine's contents.
"""
def _initialize(self,line):
self.proctype = 'Subroutine'
self.name = line.group(2)
attribstr = line.group(1)
self.module = False
self.mp = False
if not attribstr: attribstr = ""
self.attribs = []
if attribstr.find("impure") >= 0:
self.attribs.append("impure")
attribstr = attribstr.replace("impure","",1)
if attribstr.find("pure") >= 0:
del self.protected_list
def _cleanup(self):
# Create list of all local procedures. Ones coming from other modules
# will be added later, during correlation.
self.process_attribs()
self.variables = [v for v in self.variables if 'external' not in v.attribs]
self.all_procs = {}
for p in self.functions + self.subroutines:
self.all_procs[p.name.lower()] = p
for interface in self.interfaces:
if not interface.abstract:
self.all_procs[interface.name.lower()] = interface
class FortranSubroutine(FortranCodeUnit):
"""
An object representing a Fortran subroutine and holding all of said
subroutine's contents.
"""
def _initialize(self,line):
self.proctype = 'Subroutine'
self.name = line.group(2)
attribstr = line.group(1)
self.module = False
self.mp = False
if not attribstr: attribstr = ""
self.attribs = []
if attribstr.find("impure") >= 0:
self.attribs.append("impure")
attribstr = attribstr.replace("impure","",1)
if attribstr.find("pure") >= 0:
settings['predocmark'],settings['docmark_alt'],
settings['predocmark_alt'],fixed,
settings['fixed_length_limit'].lower()=='true',preprocessor,
settings['macro'],settings['include'])
FortranContainer.__init__(self,source,"")
readobj = open(self.path,'r')
self.raw_src = readobj.read()
if self.fixed:
self.src = highlight(self.raw_src,FortranFixedLexer(),
HtmlFormatter(lineanchors='ln', cssclass='hl'))
else:
self.src = highlight(self.raw_src,FortranLexer(),
HtmlFormatter(lineanchors='ln', cssclass='hl'))
class FortranModule(FortranCodeUnit):
"""
An object representing individual modules within your source code. These
objects contains lists of all of the module's contents, as well as its
dependencies.
"""
ONLY_RE = re.compile('^\s*,\s*only\s*:\s*(?=[^,])',re.IGNORECASE)
RENAME_RE = re.compile('(\w+)\s*=>\s*(\w+)',re.IGNORECASE)
def _initialize(self,line):
self.name = line.group(1)
self.uses = []
self.variables = []
self.enums = []
self.public_list = []
self.private_list = []
self.protected_list = []