Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
typestr = ''
for vtype in self.settings['extra_vartypes']:
typestr = typestr + '|' + vtype
var_type_re = re.compile(VAR_TYPE_STRING + typestr,re.IGNORECASE)
if var_type_re.search(attribstr):
rettype, retkind, retlen, retproto, rest = parse_type(attribstr,self.strings,self.settings)
self.retvar = FortranVariable(self.retvar,rettype,self,
kind=retkind,strlen=retlen,
proto=retproto)
self.args = [] # Set this in the correlation step
for arg in self.SPLIT_RE.split(line.group(3)[1:-1]):
# FIXME: This is to avoid a problem whereby sometimes an empty argument list will appear to contain the argument ''. I didn't know why it would do this (especially since sometimes it works fine) and just put this in as a quick fix. However, at some point I should try to figure out the actual root of the problem.
if arg.strip() != '': self.args.append(arg.strip())
try:
self.bindC = ford.utils.get_parens(line.group(5),-1)[0:-1]
except:
self.bindC = line.group(5)
if self.bindC:
search_from = 0
while QUOTES_RE.search(self.bindC[search_from:]):
num = int(QUOTES_RE.search(self.bindC[search_from:]).group()[1:-1])
self.bindC = self.bindC[0:search_from] + QUOTES_RE.sub(self.parent.strings[num],self.bindC[search_from:],count=1)
search_from += QUOTES_RE.search(self.bindC[search_from:]).end(0)
self.variables = []
self.enums = []
self.uses = []
self.calls = []
self.optional_list = []
self.subroutines = []
self.functions = []
self.interfaces = []
typestr = ''
for vtype in self.settings['extra_vartypes']:
typestr = typestr + '|' + vtype
var_type_re = re.compile(VAR_TYPE_STRING + typestr,re.IGNORECASE)
if var_type_re.search(attribstr):
rettype, retkind, retlen, retproto, rest = parse_type(attribstr,self.strings,self.settings)
self.retvar = FortranVariable(self.retvar,rettype,self,
kind=retkind,strlen=retlen,
proto=retproto)
self.args = [] # Set this in the correlation step
for arg in self.SPLIT_RE.split(line.group(3)[1:-1]):
# FIXME: This is to avoid a problem whereby sometimes an empty argument list will appear to contain the argument ''. I didn't know why it would do this (especially since sometimes it works fine) and just put this in as a quick fix. However, at some point I should try to figure out the actual root of the problem.
if arg.strip() != '': self.args.append(arg.strip())
try:
self.bindC = ford.utils.get_parens(line.group(5),-1)[0:-1]
except:
self.bindC = line.group(5)
if self.bindC:
search_from = 0
while QUOTES_RE.search(self.bindC[search_from:]):
num = int(QUOTES_RE.search(self.bindC[search_from:]).group()[1:-1])
self.bindC = self.bindC[0:search_from] + QUOTES_RE.sub(self.parent.strings[num],self.bindC[search_from:],count=1)
search_from += QUOTES_RE.search(self.bindC[search_from:]).end(0)
self.variables = []
self.enums = []
self.uses = []
self.calls = []
self.optional_list = []
self.subroutines = []
self.functions = []
self.interfaces = []
def parse_type(string,capture_strings,settings):
"""
Gets variable type, kind, length, and/or derived-type attributes from a
variable declaration.
"""
typestr = ''
for vtype in settings['extra_vartypes']:
typestr = typestr + '|' + vtype
var_type_re = re.compile(VAR_TYPE_STRING + typestr,re.IGNORECASE)
match = var_type_re.match(string)
if not match: raise Exception("Invalid variable declaration: {}".format(string))
vartype = match.group().lower()
if DOUBLE_PREC_RE.match(vartype): vartype = "double precision"
rest = string[match.end():].strip()
kindstr = ford.utils.get_parens(rest)
rest = rest[len(kindstr):].strip()
if len(kindstr) < 3 and vartype != "type" and vartype != "class" and not kindstr.startswith('*'):
return (vartype, None, None, None, rest)
match = VARKIND_RE.search(kindstr)
if match:
if match.group(1):
star = False
args = match.group(1).strip()
else:
star = True
args = match.group(2).strip()
args = re.sub("\s","",args)
if vartype == "type" or vartype == "class" or vartype == "procedure":
PROTO_RE = re.compile("(\*|\w+)\s*(?:\((.*)\))?")
def parse_type(string,capture_strings,settings):
"""
Gets variable type, kind, length, and/or derived-type attributes from a
variable declaration.
"""
typestr = ''
for vtype in settings['extra_vartypes']:
typestr = typestr + '|' + vtype
var_type_re = re.compile(VAR_TYPE_STRING + typestr,re.IGNORECASE)
match = var_type_re.match(string)
if not match: raise Exception("Invalid variable declaration: {}".format(string))
vartype = match.group().lower()
if DOUBLE_PREC_RE.match(vartype): vartype = "double precision"
rest = string[match.end():].strip()
kindstr = ford.utils.get_parens(rest)
rest = rest[len(kindstr):].strip()
if len(kindstr) < 3 and vartype != "type" and vartype != "class" and not kindstr.startswith('*'):
return (vartype, None, None, None, rest)
match = VARKIND_RE.search(kindstr)
if match:
if match.group(1):
star = False
args = match.group(1).strip()
else:
star = True
args = match.group(2).strip()
if args.startswith('('):
args = args[1:-1].strip()
args = re.sub("\s","",args)