Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit 162f61a6 authored by ulrich_y's avatar ulrich_y
Browse files

2/3: PEP compliant switcheroo.py (#17 and #6)

parent 9be2e322
No related branches found
No related tags found
No related merge requests found
...@@ -2,32 +2,35 @@ import re ...@@ -2,32 +2,35 @@ import re
import sys import sys
def parsedec(l): def parsedec(line):
if "::" in l: if "::" in line:
l = l.split("::")[-1] line = line.split("::")[-1]
else: else:
l = l.split("(kind=prec)")[-1] line = line.split("(kind=prec)")[-1]
l = l.split('=')[0] line = line.split('=')[0]
return [ return [
re.sub( re.sub(
'\(.*?\)', '\(.*?\)',
'', '',
i.strip() i.strip()
) for i in l.split(',')] ) for i in line.split(',')]
def expand_switch(block): def expand_switch(block):
prec = re.sub( prec = re.sub(
"END FUNCTION (.*)", r"END FUNCTION \1prec", "END FUNCTION (.*)", r"END FUNCTION \1prec",
re.sub( re.sub(
"^( *)FUNCTION (.*?)\((.*?)\)", "^( *)FUNCTION (.*?)\((.*?)\)",
r"\1FUNCTION \2prec(\3) result(\2)", r"\1FUNCTION \2prec(\3) result(\2)",
block, block,
flags=re.S|re.M flags=re.S | re.M
) )
) )
cond = re.findall("!BEGIN SWITCHEROO\n(.*?)\n!CODE", block, flags=re.M|re.S) cond = re.findall(
"!BEGIN SWITCHEROO\n(.*?)\n!CODE",
block, flags=re.M | re.S
)
if len(cond) == 1: if len(cond) == 1:
cond = cond[0] cond = cond[0]
prec = prec.replace("!BEGIN SWITCHEROO\n"+cond+"\n!CODE", "") prec = prec.replace("!BEGIN SWITCHEROO\n"+cond+"\n!CODE", "")
...@@ -35,32 +38,40 @@ def expand_switch(block): ...@@ -35,32 +38,40 @@ def expand_switch(block):
cond = ".false." cond = ".false."
interfaces = [] interfaces = []
for func, args, body in re.findall("^ *FUNCTION (.*?)\((.*?)\)(.*?)END FUNCTION", block,flags=re.M|re.S): for func, args, body in re.findall(
"^ *FUNCTION (.*?)\((.*?)\)(.*?)END FUNCTION",
block,flags=re.M | re.S
):
iface = " FUNCTION %s(%s)\n" % (func, args) iface = " FUNCTION %s(%s)\n" % (func, args)
lines = body.splitlines() lines = body.splitlines()
realvars = [] realvars = []
cmplxvars = [] cmplxvars = []
while len(lines) > 0: while len(lines) > 0:
l = lines.pop(0).strip() line = lines.pop(0).strip()
if len(l) == 0: continue if len(line) == 0:
if l.startswith("implicit ") or l.startswith("use "): continue
iface += ' ' + l + '\n' if line.startswith("implicit ") or line.startswith("use "):
elif l.startswith("real(kind=prec)"): iface += ' ' + line + '\n'
iface += ' ' + l + '\n' elif line.startswith("real(kind=prec)"):
realvars += parsedec(l) iface += ' ' + line + '\n'
elif l.startswith("complex(kind=prec)"): realvars += parsedec(line)
iface += ' ' + l + '\n' elif line.startswith("complex(kind=prec)"):
cmplxvars += parsedec(l) iface += ' ' + line + '\n'
elif l.startswith("integer"): cmplxvars += parsedec(line)
iface += ' ' + l + '\n' elif line.startswith("integer"):
iface += ' ' + line + '\n'
else: else:
break break
argsex = re.sub('[&\n ]','',args).split(',') argsex = re.sub('[&\n ]','',args).split(',')
if not all([i in realvars or i in cmplxvars for i in argsex]): if not all([i in realvars or i in cmplxvars for i in argsex]):
sys.stderr.write("Some args are not defined. Please check your code\n") sys.stderr.write(
"Some args are not defined. Please check your code\n"
)
args16 = [ args16 = [
("real(%s, kind=16)" if i in realvars else "cmplx(%s, kind=16)") % i (
"real(%s, kind=16)" if i in realvars else "cmplx(%s, kind=16)"
) % i
for i in argsex for i in argsex
] ]
ind = ', &\n ' + (' '*len(" %s = %s16" % (func, func))) ind = ', &\n ' + (' '*len(" %s = %s16" % (func, func)))
...@@ -71,14 +82,19 @@ def expand_switch(block): ...@@ -71,14 +82,19 @@ def expand_switch(block):
iface += " endif\n" iface += " endif\n"
iface += " END FUNCTION "+func iface += " END FUNCTION "+func
interfaces.append(iface) interfaces.append(iface)
return prec.replace('prec', '16') + '\n\n' + prec.replace('prec', '8') + '\n\n\n' + '\n\n'.join(interfaces) return (
prec.replace('prec', '16') + '\n\n' +
prec.replace('prec', '8') + '\n\n\n' +
'\n\n'.join(interfaces)
)
with open(sys.argv[1]) as fp: with open(sys.argv[1]) as fp:
buf=fp.read() buf = fp.read()
print re.sub( print re.sub(
"!BEGIN SWITCHEROO.*?!END SWITCHEROO", "!BEGIN SWITCHEROO.*?!END SWITCHEROO",
lambda m : expand_switch(m.group()), lambda m: expand_switch(m.group()),
buf, buf,
flags=re.M|re.S flags=re.M | re.S
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment