Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return []
def __len__(self):
return 0
def __contains__(self, item):
return False
def __getattr__(self, name):
return []
def __str__(self):
return self.name
class GenericSource(FortranBase):
"""
Represent a non-Fortran source file. The contents of the file will
not be analyzed, but documentation can be extracted.
"""
def __init__(self, filename, settings):
self.obj = 'sourcefile'
self.parobj = None
self.parent = None
self.hierarchy = []
self.settings = settings
self.num_lines = 0
extra_filetypes = settings['extra_filetypes'][filename.split('.')[-1]]
comchar = extra_filetypes[0]
if (len(extra_filetypes)>1):
self.lexer_str = extra_filetypes[1]
elif attr[0:6] == 'intent':
var.intent = attr[7:-1]
elif DIM_RE.match(attr) and ('pointer' in attr or 'allocatable' in attr):
i = attr.index('(')
var.attribs.append(attr[0:i])
var.dimension = attr[i:]
elif attr == 'parameter':
var.attribs.append(attr)
var.initial = self.param_dict[var.name.lower()]
else:
var.attribs.append(attr)
del self.attr_dict
class FortranCommon(FortranBase):
"""
An object representing a common block. This is a legacy feature.
"""
def _initialize(self,line):
self.name = line.group(1)
if not self.name: self.name = ''
self.other_uses = []
self.variables = [v.strip() for v in ford.utils.paren_split(',',line.group(2))]
self.visible = True
def correlate(self,project):
for i in range(len(self.variables)):
if self.variables[i] in self.parent.all_vars:
self.variables[i] = self.parent.all_vars[self.variables[i]]
try:
self.parent.variables.remove(self.variables[i])
else:
if proc.name and proc.name.lower() == self.bindings[i].name.lower():
self.bindings[i] = proc
break
#else:
# self.bindings[i] = FortranSpoof(self.bindings[i], self.parent, 'BOUNDPROC')
elif not self.deferred:
for i in range(len(self.bindings)):
if self.bindings[i].lower() in self.all_procs:
self.bindings[i] = self.all_procs[self.bindings[i].lower()]
break
#else:
# self.bindings[i] = FortranSpoof(self.bindings[i], self.parent, 'BOUNDPROC')
class FortranModuleProcedure(FortranBase):
"""
An object representing a module procedure in an interface. Not to be
confused with type of module procedure which is the implementation of
a module function or module subroutine in a submodule.
"""
def __init__(self,name,parent=None,inherited_permission=None):
if (inherited_permission!=None):
self.permission = inherited_permission.lower()
else:
self.permission = None
self.parent = parent
if self.parent:
self.parobj = self.parent.obj
self.settings = self.parent.settings
else:
self.parobj = None
self.bindings[i] = proc
break
#else:
# self.bindings[i] = FortranSpoof(self.bindings[i], self.parent, 'BOUNDPROC')
elif not self.deferred:
for i in range(len(self.bindings)):
if self.bindings[i].lower() in self.all_procs:
self.bindings[i] = self.all_procs[self.bindings[i].lower()]
break
#else:
# self.bindings[i] = FortranSpoof(self.bindings[i], self.parent, 'BOUNDPROC')
# Sort content
self.sort()
class FortranModuleProcedure(FortranBase):
"""
An object representing a module procedure in an interface. Not to be
confused with type of module procedure which is the implementation of
a module function or module subroutine in a submodule.
"""
def __init__(self,name,parent=None,inherited_permission=None):
if (inherited_permission!=None):
self.permission = inherited_permission.lower()
else:
self.permission = None
self.parent = parent
if self.parent:
self.parobj = self.parent.obj
self.settings = self.parent.settings
else:
self.parobj = None
def __init__(self,source,first_line,parent=None,inherited_permission=None,
strings=[]):
self.num_lines = 0
if not isinstance(self,FortranSourceFile): self.num_lines += 1
if type(self) != FortranSourceFile:
FortranBase.__init__(self,source,first_line,parent,inherited_permission,
strings)
incontains = False
if type(self) is FortranSubmodule:
permission = "private"
else:
permission = "public"
typestr = ''
for vtype in self.settings['extra_vartypes']:
typestr = typestr + '|' + vtype
self.VARIABLE_RE = re.compile(self.VARIABLE_STRING.format(typestr),re.IGNORECASE)
blocklevel = 0
associatelevel = 0
for line in source:
if line[0:2] == "!" + self.settings['docmark']:
def get_name(self,item):
"""
Return the name for this item registered with this NameSelector.
If no name has previously been registered, then generate a new
one.
"""
if not isinstance(item,ford.sourceform.FortranBase):
raise Exception('{} is not of a type derived from FortranBase'.format(str(item)))
if item in self._items:
return self._items[item]
else:
if item.get_dir() not in self._counts:
self._counts[item.get_dir()] = {}
if item.name in self._counts[item.get_dir()]:
num = self._counts[item.get_dir()][item.name] + 1
else:
num = 1
self._counts[item.get_dir()][item.name] = num
name = item.name.lower().replace('<','lt')
# name is already lower
name = name.replace('>','gt')
name = name.replace('/','SLASH')
for proc in (self.functions + self.subroutines):
proc.visible = True
item = copy.copy(self)
item.procedure = proc
item.procedure.parent = item
del item.functions
del item.modprocs
del item.subroutines
item.name = proc.name
item.permission = proc.permission
contents.append(item)
self.contents = contents
class FortranFinalProc(FortranBase):
"""
An object representing a finalization procedure for a derived type
within Fortran.
"""
def __init__(self, name, parent, source=None):
self.name = name
self.parent = parent
self.procedure = None
self.obj = 'finalproc'
self.parobj = self.parent.obj
self.display = self.parent.display
self.settings = self.parent.settings
self.doc = []
if source:
line = source.__next__()
while line[0:2] == "!" + self.settings['docmark']:
for proc in self.routines:
proc.visible = False
item = copy.copy(self)
item.procedure = proc
item.procedure.parent = item
del item.functions
del item.modprocs
del item.subroutines
item.name = proc.name
item.permission = proc.permission
contents.append(item)
self.contents = contents
class FortranFinalProc(FortranBase):
"""
An object representing a finalization procedure for a derived type
within Fortran.
"""
def __init__(self, name, parent, source=None):
self.name = name
self.parent = parent
self.procedure = None
self.obj = 'finalproc'
self.parobj = self.parent.obj
self.display = self.parent.display
self.settings = self.parent.settings
self.doc = []
if source:
line = source.__next__()
while line[0:2] == "!" + self.settings['docmark']:
source.pass_back(line)
self.hierarchy = []
cur = self.parent
while cur:
self.hierarchy.append(cur)
cur = cur.parent
self.hierarchy.reverse()
def correlate(self,project):
self.all_procs = self.parent.all_procs
if self.name.lower() in self.all_procs:
self.procedure = self.all_procs[self.name.lower()]
class FortranVariable(FortranBase):
"""
An object representing a variable within Fortran.
"""
def __init__(self,name,vartype,parent,attribs=[],intent="",
optional=False,permission="public",parameter=False,kind=None,
strlen=None,proto=None,doc=[],points=False,initial=None):
self.name = name
self.vartype = vartype.lower()
self.parent = parent
if self.parent:
self.parobj = self.parent.obj
self.settings = self.parent.settings
else:
self.parobj = None
self.settings = None
self.obj = type(self).__name__[7:].lower()
def get_name(self,item):
"""
Return the name for this item registered with this NameSelector.
If no name has previously been registered, then generate a new
one.
"""
if not isinstance(item,ford.sourceform.FortranBase):
raise Exception('{} is not of a type derived from FortranBase'.format(str(item)))
if item in self._items:
return self._items[item]
else:
if item.get_dir() not in self._counts:
self._counts[item.get_dir()] = {}
if item.name in self._counts[item.get_dir()]:
num = self._counts[item.get_dir()][item.name] + 1
else:
num = 1
self._counts[item.get_dir()][item.name] = num
name = item.name.lower().replace('<','lt')
name = item.name.lower().replace('>','gt')
name = item.name.lower().replace('/','SLASH')
if name == '': name = '__unnamed__'