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
import sys
def parsedec(l):
if "::" in l:
l = l.split("::")[-1]
def parsedec(line):
if "::" in line:
line = line.split("::")[-1]
else:
l = l.split("(kind=prec)")[-1]
l = l.split('=')[0]
line = line.split("(kind=prec)")[-1]
line = line.split('=')[0]
return [
re.sub(
'\(.*?\)',
'',
i.strip()
) for i in l.split(',')]
) for i in line.split(',')]
def expand_switch(block):
prec = re.sub(
"END FUNCTION (.*)", r"END FUNCTION \1prec",
re.sub(
"^( *)FUNCTION (.*?)\((.*?)\)",
"^( *)FUNCTION (.*?)\((.*?)\)",
r"\1FUNCTION \2prec(\3) result(\2)",
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:
cond = cond[0]
prec = prec.replace("!BEGIN SWITCHEROO\n"+cond+"\n!CODE", "")
......@@ -35,32 +38,40 @@ def expand_switch(block):
cond = ".false."
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)
lines = body.splitlines()
realvars = []
cmplxvars = []
while len(lines) > 0:
l = lines.pop(0).strip()
if len(l) == 0: continue
if l.startswith("implicit ") or l.startswith("use "):
iface += ' ' + l + '\n'
elif l.startswith("real(kind=prec)"):
iface += ' ' + l + '\n'
realvars += parsedec(l)
elif l.startswith("complex(kind=prec)"):
iface += ' ' + l + '\n'
cmplxvars += parsedec(l)
elif l.startswith("integer"):
iface += ' ' + l + '\n'
line = lines.pop(0).strip()
if len(line) == 0:
continue
if line.startswith("implicit ") or line.startswith("use "):
iface += ' ' + line + '\n'
elif line.startswith("real(kind=prec)"):
iface += ' ' + line + '\n'
realvars += parsedec(line)
elif line.startswith("complex(kind=prec)"):
iface += ' ' + line + '\n'
cmplxvars += parsedec(line)
elif line.startswith("integer"):
iface += ' ' + line + '\n'
else:
break
argsex = re.sub('[&\n ]','',args).split(',')
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 = [
("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
]
ind = ', &\n ' + (' '*len(" %s = %s16" % (func, func)))
......@@ -71,14 +82,19 @@ def expand_switch(block):
iface += " endif\n"
iface += " END FUNCTION "+func
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:
buf=fp.read()
buf = fp.read()
print re.sub(
"!BEGIN SWITCHEROO.*?!END SWITCHEROO",
lambda m : expand_switch(m.group()),
lambda m: expand_switch(m.group()),
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