2009-09-05 00:18:45 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
from util import *
|
|
|
|
from irpf90_t import *
|
|
|
|
from variables import variables
|
|
|
|
from preprocessed_text import preprocessed_text
|
|
|
|
from subroutines import subroutines
|
|
|
|
import regexps
|
2009-09-05 15:37:23 +02:00
|
|
|
import error
|
2009-09-05 00:18:45 +02:00
|
|
|
|
|
|
|
def find_variables_in_line(line):
|
|
|
|
assert isinstance(line,Line)
|
|
|
|
result = []
|
|
|
|
buffer = regexps.re_string.sub('',line.text)
|
|
|
|
for v in variables.keys():
|
|
|
|
var = variables[v]
|
|
|
|
if var.regexp.search(buffer) is not None:
|
|
|
|
result.append(var.name)
|
|
|
|
return result
|
|
|
|
|
2009-09-05 15:37:23 +02:00
|
|
|
def find_subroutine_in_line(line):
|
|
|
|
assert isinstance(line,Call)
|
2009-09-05 16:05:00 +02:00
|
|
|
buffer = line.text.split('(')[0]
|
|
|
|
buffer = buffer.split()[1]
|
|
|
|
return buffer
|
2009-09-05 15:37:23 +02:00
|
|
|
|
2009-09-05 16:05:00 +02:00
|
|
|
def check_touch(line,vars,main_vars):
|
2009-09-05 15:37:23 +02:00
|
|
|
def fun(main_var):
|
|
|
|
if main_var not in variables:
|
|
|
|
error.fail(line,"Variable %s unknown"%(main_var,))
|
|
|
|
x = variables[main_var]
|
|
|
|
return [main_var]+x.others
|
2009-09-05 16:05:00 +02:00
|
|
|
all_others = make_single(flatten( map(fun,main_vars) ))
|
2009-09-05 15:37:23 +02:00
|
|
|
all_others.sort()
|
|
|
|
if len(all_others) == len(vars):
|
2009-09-05 16:05:00 +02:00
|
|
|
vars.sort()
|
2009-09-05 15:37:23 +02:00
|
|
|
for x,y in zip(vars,all_others):
|
|
|
|
if x != y:
|
|
|
|
message = "The following entities should be touched:\n"
|
|
|
|
message = "\n".join([message]+map(lambda x: "- %s"%(x,),all_others))
|
|
|
|
error.fail(line,message)
|
2009-09-05 00:18:45 +02:00
|
|
|
|
|
|
|
def get_parsed_text():
|
2009-09-05 16:05:00 +02:00
|
|
|
main_result = []
|
2009-09-05 00:18:45 +02:00
|
|
|
for filename, text in preprocessed_text:
|
2009-09-05 16:05:00 +02:00
|
|
|
result = []
|
2009-09-05 00:18:45 +02:00
|
|
|
varlist = []
|
|
|
|
for line in filter(
|
|
|
|
lambda x: type(x) not in [ Doc, Begin_doc, End_doc ],
|
|
|
|
text):
|
|
|
|
if type(line) in [ \
|
|
|
|
Empty_line,
|
|
|
|
Continue,
|
|
|
|
Return,
|
|
|
|
Begin_shell,
|
|
|
|
End_shell,
|
|
|
|
Openmp,
|
|
|
|
Use,
|
|
|
|
Enddo,
|
|
|
|
End_select,
|
|
|
|
Endif,
|
|
|
|
Implicit,
|
|
|
|
Program,
|
|
|
|
Subroutine,
|
|
|
|
Function,
|
|
|
|
End,
|
|
|
|
]:
|
2009-09-05 16:05:00 +02:00
|
|
|
result.append( ([],line) )
|
2009-09-05 00:18:45 +02:00
|
|
|
elif type(line) in [End, End_provider]:
|
2009-09-05 16:05:00 +02:00
|
|
|
result.append( ([],line) )
|
2009-09-05 00:18:45 +02:00
|
|
|
varlist = []
|
|
|
|
elif isinstance(line,Provide):
|
|
|
|
l = line.text.split()[1:]
|
|
|
|
varlist += l
|
2009-09-05 16:05:00 +02:00
|
|
|
result.append( (l,Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
2009-09-05 15:37:23 +02:00
|
|
|
elif isinstance(line,Call):
|
|
|
|
sub = find_subroutine_in_line(line)
|
2009-09-05 16:05:00 +02:00
|
|
|
if sub not in subroutines:
|
2009-09-05 15:37:23 +02:00
|
|
|
t = Simple_line
|
|
|
|
else:
|
2009-09-05 16:05:00 +02:00
|
|
|
if subroutines[sub].touches == []:
|
|
|
|
t = Simple_line
|
|
|
|
else:
|
|
|
|
t = Provide_all
|
|
|
|
result.append( ([],t(line.i,line.text,line.filename)) )
|
2009-09-05 15:37:23 +02:00
|
|
|
elif isinstance(line,Free):
|
|
|
|
vars = line.text.split()
|
|
|
|
if len(vars) < 2:
|
|
|
|
error.fail(line,"Syntax error")
|
|
|
|
vars = vars[1:]
|
|
|
|
result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
|
|
|
for var in vars:
|
2009-09-05 16:05:00 +02:00
|
|
|
result.append( ([],Simple_line(line.i," call free_%s"%var,
|
2009-09-05 15:37:23 +02:00
|
|
|
line.filename)) )
|
|
|
|
elif isinstance(line,Touch):
|
|
|
|
vars = line.text.split()
|
|
|
|
if len(vars) < 2:
|
|
|
|
error.fail(line,"Syntax error")
|
2009-09-05 16:05:00 +02:00
|
|
|
vars = map(lower,vars[1:])
|
2009-09-05 15:37:23 +02:00
|
|
|
def fun(x):
|
|
|
|
if x not in variables:
|
|
|
|
error.fail(line,"Variable %s unknown"%(x,))
|
|
|
|
main = variables[x].same_as
|
|
|
|
if main is None:
|
|
|
|
main = x
|
|
|
|
return main
|
|
|
|
main_vars = make_single( map(fun, vars) )
|
2009-09-05 16:05:00 +02:00
|
|
|
check_touch(line,vars,main_vars)
|
2009-09-05 15:37:23 +02:00
|
|
|
txt = " ".join(vars)
|
2009-09-05 16:05:00 +02:00
|
|
|
result += [ ([],Simple_line(line.i,"!",line.filename)),
|
2009-09-05 15:37:23 +02:00
|
|
|
([],Simple_line(line.i,"! >>> TOUCH %s"%(txt,),line.filename)) ]
|
|
|
|
def fun(x):
|
|
|
|
if x not in variables:
|
|
|
|
error.fail(line,"Variable %s unknown"%(x,))
|
|
|
|
return [ ([],Simple_line(line.i," call touch_%s"%(x,),line.filename)),
|
|
|
|
([],Simple_line(line.i," %s_is_built = .True."%(x,),line.filename)) ]
|
2009-09-05 16:05:00 +02:00
|
|
|
result += flatten(map( fun, main_vars ))
|
2009-09-05 15:37:23 +02:00
|
|
|
def fun(x):
|
|
|
|
if x not in variables:
|
|
|
|
error.fail(line,"Variable %s unknown"%(x,))
|
2009-09-05 16:05:00 +02:00
|
|
|
return ([],Simple_line(line.i," %s_is_built = .True."%(x,),line.filename))
|
|
|
|
result += map( fun, main_vars[:-1] )
|
2009-09-05 15:37:23 +02:00
|
|
|
result += [ ([],Provide_all(line.i,"! <<< END TOUCH",line.filename)) ]
|
2009-09-05 00:18:45 +02:00
|
|
|
else:
|
|
|
|
l = find_variables_in_line(line)
|
|
|
|
varlist += l
|
2009-09-05 16:05:00 +02:00
|
|
|
result.append( (l,line) )
|
|
|
|
main_result.append( (filename, result) )
|
|
|
|
return main_result
|
2009-09-05 00:18:45 +02:00
|
|
|
|
|
|
|
parsed_text = get_parsed_text()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2009-09-05 16:05:00 +02:00
|
|
|
for line in parsed_text[12][1]:
|
|
|
|
print line[1],'!',line[0]
|