mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-11-09 07:33:43 +01:00
Optimizations
Version:1.1.56
This commit is contained in:
parent
1c5d5caf10
commit
5565591b8f
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python -u
|
||||
#!/usr/bin/python -O
|
||||
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
|
||||
# the Implicit Reference to Parameters (IRP) method.
|
||||
# Copyright (C) 2009 Anthony SCEMAMA
|
||||
|
@ -32,7 +32,7 @@ from util import *
|
||||
|
||||
|
||||
def do_print_short(file,var):
|
||||
assert isinstance(var,Variable)
|
||||
assert type(var) == Variable
|
||||
print >>file, "%s : %s :: %s %s"%( \
|
||||
var.line.filename[0].ljust(25),
|
||||
var.type.ljust(25),
|
||||
@ -41,7 +41,7 @@ def do_print_short(file,var):
|
||||
|
||||
######################################################################
|
||||
def process_doc(file,line):
|
||||
assert isinstance(line,str)
|
||||
assert type(line) == str
|
||||
line = line.strip()
|
||||
if line == "":
|
||||
line = ".br"
|
||||
@ -49,24 +49,24 @@ def process_doc(file,line):
|
||||
|
||||
######################################################################
|
||||
def process_deps(file,l):
|
||||
assert isinstance(l,list)
|
||||
assert type(l) == list
|
||||
for v in l:
|
||||
print >>file, "%s\n.br"%(v,)
|
||||
|
||||
######################################################################
|
||||
def process_types(file,var):
|
||||
assert isinstance(var,Variable)
|
||||
assert type(var) == Variable
|
||||
vars = [var.name] + var.others
|
||||
for var in vars:
|
||||
name = var
|
||||
var = variables[var]
|
||||
type = var.type
|
||||
Type = var.type
|
||||
dim = build_dim(var.dim)
|
||||
print >>file, "%s\t:: %s\t%s"%(type,name,dim)
|
||||
print >>file, "%s\t:: %s\t%s"%(Type,name,dim)
|
||||
|
||||
######################################################################
|
||||
def do_print(var):
|
||||
assert isinstance(var,Variable)
|
||||
assert type(var) == Variable
|
||||
filename = var.line.filename[0]
|
||||
name = var.name
|
||||
file = open("%s%s.l"%(mandir,var.name), "w")
|
||||
|
@ -46,7 +46,7 @@ class Fmodule(object):
|
||||
|
||||
def prog_name(self):
|
||||
if '_prog_name' not in self.__dict__:
|
||||
buffer = filter(lambda x: isinstance(x[1],Program),self.text)
|
||||
buffer = filter(lambda x: type(x[1]) == Program,self.text)
|
||||
if buffer == []:
|
||||
self._prog_name = None
|
||||
else:
|
||||
@ -111,11 +111,11 @@ class Fmodule(object):
|
||||
result = []
|
||||
inside = False
|
||||
for vars,line in text:
|
||||
if isinstance(line,Begin_provider):
|
||||
if type(line) == Begin_provider:
|
||||
inside = True
|
||||
if not inside:
|
||||
result.append( (vars,line) )
|
||||
if isinstance(line,End_provider):
|
||||
if type(line) == End_provider:
|
||||
inside = False
|
||||
return result
|
||||
|
||||
@ -125,7 +125,7 @@ class Fmodule(object):
|
||||
for vars,line in text:
|
||||
if type(line) in [ Subroutine, Function ]:
|
||||
variable_list = list(vars)
|
||||
elif isinstance(line,End):
|
||||
elif type(line) == End:
|
||||
result += map(lambda x: ([],Use(line.i,x,line.filename)), build_use(variable_list))
|
||||
else:
|
||||
variable_list += vars
|
||||
@ -143,11 +143,11 @@ class Fmodule(object):
|
||||
if inside:
|
||||
result.append( (vars,line) )
|
||||
else:
|
||||
if isinstance(line,Use):
|
||||
if type(line) == Use:
|
||||
use.append( (vars,line) )
|
||||
elif isinstance(line,Declaration):
|
||||
elif type(line) == Declaration:
|
||||
dec.append( (vars,line) )
|
||||
if isinstance(line,End):
|
||||
if type(line) == End:
|
||||
inside = False
|
||||
return use, dec, result
|
||||
|
||||
|
@ -68,7 +68,7 @@ def find_funcs_in_line(line):
|
||||
|
||||
|
||||
def find_subroutine_in_line(line):
|
||||
assert isinstance(line,Call)
|
||||
assert type(line) == Call
|
||||
buffer = line.text.split('(')[0]
|
||||
buffer = buffer.split()[1]
|
||||
return buffer
|
||||
@ -102,7 +102,7 @@ def update_variables():
|
||||
error.fail(line,"Variable %s unknown"%(v,))
|
||||
variables[v]._is_touched = True
|
||||
|
||||
for line in filter(lambda x: isinstance(x,Free),text):
|
||||
for line in filter(lambda x: type(x) == Free,text):
|
||||
vars = line.text_lower.split()
|
||||
if len(vars) < 2:
|
||||
error.fail(line,"Syntax error")
|
||||
@ -111,10 +111,10 @@ def update_variables():
|
||||
error.fail(line,"Variable %s unknown"%(v,))
|
||||
variables[v].is_freed = True
|
||||
|
||||
for line in filter(lambda x: isinstance(x,Irp_read),text):
|
||||
for line in filter(lambda x: type(x) == Irp_read,text):
|
||||
variables[line.filename]._is_read = True
|
||||
|
||||
for line in filter(lambda x: isinstance(x,Irp_write),text):
|
||||
for line in filter(lambda x: type (x) == Irp_write,text):
|
||||
variables[line.filename]._is_written = True
|
||||
|
||||
################################################################################
|
||||
@ -124,9 +124,9 @@ def get_parsed_text():
|
||||
varlist = []
|
||||
result = []
|
||||
append = result.append
|
||||
for line in filter(
|
||||
lambda x: type(x) not in [ Doc, Begin_doc, End_doc ],
|
||||
text):
|
||||
for line in text: #filter(
|
||||
# lambda x: type(x) not in [ Doc, Begin_doc, End_doc ],
|
||||
# text):
|
||||
if type(line) in [ \
|
||||
Empty_line,
|
||||
Continue,
|
||||
@ -145,42 +145,31 @@ def get_parsed_text():
|
||||
End,
|
||||
]:
|
||||
append( ([],line) )
|
||||
elif isinstance(line,End_provider):
|
||||
elif type(line) in [ Begin_provider, Cont_provider ]:
|
||||
if type(line) == Begin_provider:
|
||||
varlist = []
|
||||
buffer = map(strip,line.text_lower.replace(']','').split(','))
|
||||
assert len(buffer) > 1
|
||||
v = buffer[1]
|
||||
varlist.append(v)
|
||||
variable_list = find_variables_in_line(line)
|
||||
try:
|
||||
variable_list.remove(variables[v].same_as)
|
||||
except ValueError:
|
||||
print v, variables[v].same_as
|
||||
raise
|
||||
append( (variable_list,line) )
|
||||
elif type(line) == End_provider:
|
||||
varlist = []
|
||||
append( ([],line) )
|
||||
elif isinstance(line,Provide):
|
||||
elif type(line) == Provide:
|
||||
l = line.text_lower.split()[1:]
|
||||
l = filter(lambda x: x not in varlist, l)
|
||||
for v in l:
|
||||
if v not in variables.keys():
|
||||
error.fail(line,"Variable %s is unknown"%(v))
|
||||
append( (l,Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
elif isinstance(line,Call):
|
||||
l = find_variables_in_line(line)
|
||||
l = filter(lambda x: x not in varlist, l)
|
||||
sub = find_subroutine_in_line(line)
|
||||
if sub not in subroutines:
|
||||
t = Simple_line
|
||||
append( (l,Simple_line(line.i,line.text,line.filename)) )
|
||||
else:
|
||||
append( (l,line) )
|
||||
if subroutines[sub].touches != []:
|
||||
append( ([],Provide_all(line.i,"",line.filename)) )
|
||||
elif isinstance(line,Free):
|
||||
vars = line.text_lower.split()
|
||||
vars = vars[1:]
|
||||
append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
use = map(lambda x: " use %s"%(variables[x].fmodule),vars)
|
||||
for var in vars:
|
||||
result += map(lambda x: ([],Use(line.i,x,line.filename)),
|
||||
make_single(use))
|
||||
result += map(lambda x: ([],Simple_line(line.i,x,line.filename)),
|
||||
variables[var].free)
|
||||
elif isinstance(line,Irp_read):
|
||||
append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
elif isinstance(line,Irp_write):
|
||||
append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
elif isinstance(line,Touch):
|
||||
elif type(line) in [ Touch, SoftTouch ]:
|
||||
vars = line.text_lower.split()
|
||||
if len(vars) < 2:
|
||||
error.fail(line,"Syntax error")
|
||||
@ -204,24 +193,37 @@ def get_parsed_text():
|
||||
error.fail(line,"Variable %s unknown"%(x,))
|
||||
return ([],Simple_line(line.i," %s_is_built = .True."%(x,),line.filename))
|
||||
result += map( fun, main_vars[:-1] )
|
||||
if isinstance(line,SoftTouch):
|
||||
if type(line) == SoftTouch:
|
||||
append ( ([],Simple_line(line.i,"! <<< END TOUCH (Soft)",line.filename)) )
|
||||
else:
|
||||
append ( ([],Provide_all(line.i,"! <<< END TOUCH",line.filename)) )
|
||||
elif type(line) in [ Begin_provider, Cont_provider ]:
|
||||
if isinstance(line,Begin_provider):
|
||||
varlist = []
|
||||
buffer = map(strip,line.text_lower.replace(']','').split(','))
|
||||
assert len(buffer) > 1
|
||||
v = buffer[1]
|
||||
varlist.append(v)
|
||||
variable_list = find_variables_in_line(line)
|
||||
try:
|
||||
variable_list.remove(variables[v].same_as)
|
||||
except ValueError:
|
||||
print v, variables[v].same_as
|
||||
raise
|
||||
append( (variable_list,line) )
|
||||
elif type(line) == Call:
|
||||
l = find_variables_in_line(line)
|
||||
l = filter(lambda x: x not in varlist, l)
|
||||
sub = find_subroutine_in_line(line)
|
||||
if sub not in subroutines:
|
||||
t = Simple_line
|
||||
append( (l,Simple_line(line.i,line.text,line.filename)) )
|
||||
else:
|
||||
append( (l,line) )
|
||||
if subroutines[sub].touches != []:
|
||||
append( ([],Provide_all(line.i,"",line.filename)) )
|
||||
elif type(line) == Free:
|
||||
vars = line.text_lower.split()
|
||||
vars = vars[1:]
|
||||
append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
use = map(lambda x: " use %s"%(variables[x].fmodule),vars)
|
||||
for var in vars:
|
||||
result += map(lambda x: ([],Use(line.i,x,line.filename)),
|
||||
make_single(use))
|
||||
result += map(lambda x: ([],Simple_line(line.i,x,line.filename)),
|
||||
variables[var].free)
|
||||
elif type(line) == Irp_read:
|
||||
append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
elif type(line) == Irp_write:
|
||||
append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
elif type(line) in [ Begin_doc, End_doc, Doc ]:
|
||||
pass
|
||||
else:
|
||||
l = find_variables_in_line(line)
|
||||
l = filter(lambda x: x not in varlist, l)
|
||||
@ -241,7 +243,7 @@ parsed_text = get_parsed_text()
|
||||
######################################################################
|
||||
|
||||
def move_to_top(text,t):
|
||||
assert isinstance(text,list)
|
||||
assert type(text) == list
|
||||
assert t in [ Declaration, Implicit, Use, Cont_provider ]
|
||||
|
||||
inside = False
|
||||
@ -252,7 +254,7 @@ def move_to_top(text,t):
|
||||
inside = True
|
||||
elif type(line) in [ End_provider, End ]:
|
||||
inside = False
|
||||
elif isinstance(line,t):
|
||||
elif type(line) == t:
|
||||
if inside:
|
||||
text.pop(i)
|
||||
begin += 1
|
||||
@ -322,7 +324,7 @@ def move_variables():
|
||||
or old_elsevars != []:
|
||||
error.fail(line,"End if missing")
|
||||
varlist = []
|
||||
elif isinstance(line,Provide_all):
|
||||
elif type(line) == Provide_all:
|
||||
append( (vars,line) )
|
||||
else:
|
||||
varlist += vars
|
||||
@ -380,7 +382,7 @@ def build_sub_needs():
|
||||
sub = subroutines[subname]
|
||||
sub.needs = []
|
||||
sub.to_provide = vars
|
||||
elif isinstance(line,End):
|
||||
elif type(line) == End:
|
||||
sub.needs = make_single(sub.needs)
|
||||
sub = None
|
||||
if sub is not None:
|
||||
@ -395,7 +397,7 @@ def add_subroutine_needs():
|
||||
result = []
|
||||
append = result.append
|
||||
for vars,line in text:
|
||||
if isinstance(line,Call):
|
||||
if type(line) == Call:
|
||||
subname = find_subname(line)
|
||||
vars = subroutines[subname].to_provide
|
||||
append( (vars,line) )
|
||||
@ -411,18 +413,18 @@ def build_needs():
|
||||
for filename, text in parsed_text:
|
||||
var = None
|
||||
for vars,line in text:
|
||||
if isinstance(line,Begin_provider):
|
||||
if type(line) == Begin_provider:
|
||||
buffer = map(strip,line.text_lower.replace(']',',').split(','))
|
||||
var = variables[buffer[1]]
|
||||
var.needs = []
|
||||
var.to_provide = vars
|
||||
elif isinstance(line,End_provider):
|
||||
elif type(line) == End_provider:
|
||||
var.needs = make_single(var.needs)
|
||||
var.to_provide = make_single(var.to_provide)
|
||||
var = None
|
||||
if var is not None:
|
||||
var.needs += vars
|
||||
if isinstance(line,Call):
|
||||
if type(line) == Call:
|
||||
subname = find_subname(line)
|
||||
var.needs += subroutines[subname].needs
|
||||
elif type(line) in [ \
|
||||
@ -478,14 +480,14 @@ def check_opt():
|
||||
for filename, text in parsed_text:
|
||||
do_level = 0
|
||||
for vars,line in text:
|
||||
if not isinstance(line,Provide_all):
|
||||
if not type(line) == Provide_all:
|
||||
if do_level > 0 and vars != []:
|
||||
print "Optimization: %s line %d"%(line.filename,line.i)
|
||||
for v in vars:
|
||||
print " PROVIDE ",v
|
||||
if isinstance(line,Do):
|
||||
if type(line) == Do:
|
||||
do_level += 1
|
||||
elif isinstance(line,Enddo):
|
||||
elif type(line) == Enddo:
|
||||
do_level -= 1
|
||||
check_opt()
|
||||
|
||||
|
@ -88,10 +88,10 @@ simple_dict_keys = simple_dict.keys()
|
||||
|
||||
def get_type (i, filename, line, is_doc):
|
||||
'''Find the type of a text line'''
|
||||
assert isinstance(i,int)
|
||||
assert isinstance(filename,str)
|
||||
assert isinstance(line,str)
|
||||
assert isinstance(is_doc,bool)
|
||||
assert type(i) == int
|
||||
assert type(filename) == str
|
||||
assert type(line) == str
|
||||
assert type(is_doc) == bool
|
||||
|
||||
line = line.rstrip()
|
||||
lower_line0 = line.lstrip().lower()
|
||||
@ -165,8 +165,8 @@ instead of
|
||||
######################################################################
|
||||
def get_text(lines,filename):
|
||||
'''Read the input file and transform it to labeled lines'''
|
||||
assert isinstance(filename,str)
|
||||
assert isinstance(lines,list)
|
||||
assert type(filename) == str
|
||||
assert type(lines) == list
|
||||
|
||||
result = []
|
||||
is_doc = False
|
||||
@ -183,9 +183,9 @@ def execute_shell(text):
|
||||
result = []
|
||||
for line in text:
|
||||
if inside:
|
||||
if isinstance(line,Begin_shell):
|
||||
if type(line) == Begin_shell:
|
||||
error.fail(line,"Nested Begin_shell")
|
||||
elif isinstance(line,End_shell):
|
||||
elif type(line) == End_shell:
|
||||
inside = False
|
||||
# Write script file
|
||||
scriptname = "%s%s_shell_%d"%(irpdir,line.filename,line.i)
|
||||
@ -206,7 +206,7 @@ def execute_shell(text):
|
||||
else:
|
||||
script.append(line.text+'\n')
|
||||
else:
|
||||
if isinstance(line,Begin_shell):
|
||||
if type(line) == Begin_shell:
|
||||
inside = True
|
||||
begin = line.i
|
||||
script = []
|
||||
@ -223,7 +223,7 @@ def execute_shell(text):
|
||||
elif len(buffer) < 2:
|
||||
fail(line,"Missing",']')
|
||||
shell = buffer[0].strip()
|
||||
elif isinstance(line,End_shell):
|
||||
elif type(line) == End_shell:
|
||||
error.fail(line,"Begin_shell missing")
|
||||
else:
|
||||
result.append(line)
|
||||
@ -248,18 +248,18 @@ def execute_templates(text):
|
||||
result = []
|
||||
for line in text:
|
||||
if inside == 0:
|
||||
if isinstance(line,Begin_template):
|
||||
if type(line) == Begin_template:
|
||||
script = []
|
||||
inside = TEMPLATE
|
||||
script = "template = \"\"\"\n"
|
||||
else:
|
||||
result.append(line)
|
||||
elif inside == TEMPLATE:
|
||||
if isinstance(line,Begin_template):
|
||||
if type(line) == Begin_template:
|
||||
fail(line,"template", "Nested Begin_Template")
|
||||
elif isinstance(line,End_template):
|
||||
elif type(line) == End_template:
|
||||
fail(line,"template","Missing Subst")
|
||||
elif isinstance(line,Subst):
|
||||
elif type(line) == Subst:
|
||||
inside = SUBST
|
||||
script += "\"\"\"\n"
|
||||
variables = get_variables(line)
|
||||
@ -268,11 +268,11 @@ def execute_templates(text):
|
||||
else:
|
||||
script += line.text+"\n"
|
||||
else: # inside == SUBST
|
||||
if isinstance(line,Begin_template):
|
||||
if type(line) == Begin_template:
|
||||
fail(line,"subst","Nested Begin_template")
|
||||
elif isinstance(line,Subst):
|
||||
elif type(line) == Subst:
|
||||
fail(line,"subst","Subst already defined")
|
||||
elif isinstance(line,End_template):
|
||||
elif type(line) == End_template:
|
||||
inside = 0
|
||||
subst = subst.rstrip()
|
||||
if subst[-2:] == ';;':
|
||||
@ -313,7 +313,7 @@ def execute_templates(text):
|
||||
######################################################################
|
||||
def form(text):
|
||||
'''Find if the text is in fixed form or in free form'''
|
||||
assert isinstance(text,list)
|
||||
assert type(text) == list
|
||||
if len(text) == 0:
|
||||
return Free_form
|
||||
assert isinstance(text[0],Line)
|
||||
@ -370,7 +370,7 @@ def remove_comments(text,form):
|
||||
for line in text:
|
||||
if type(line) in [ Openmp, Doc] :
|
||||
result.append(line)
|
||||
elif isinstance(line,Empty_line):
|
||||
elif type(line) == Empty_line:
|
||||
pass
|
||||
else:
|
||||
newline = line.text.lstrip()
|
||||
@ -384,7 +384,7 @@ def remove_comments(text,form):
|
||||
for line in text:
|
||||
if type(line) in [ Openmp, Doc ]:
|
||||
result.append(line)
|
||||
elif isinstance(line,Empty_line):
|
||||
elif type(line) == Empty_line:
|
||||
pass
|
||||
else:
|
||||
newline = line.text.lstrip()
|
||||
@ -424,7 +424,7 @@ def remove_continuation(text,form):
|
||||
rev_text.reverse()
|
||||
for line in rev_text:
|
||||
is_continuation = False
|
||||
if isinstance(line,Simple_line):
|
||||
if type(line) == Simple_line:
|
||||
if len(line.text) >= 6:
|
||||
if line.text[5] != ' ':
|
||||
is_continuation = True
|
||||
@ -442,7 +442,7 @@ def irp_simple_statements(text):
|
||||
'''Processes simple statements'''
|
||||
|
||||
def process_irp_rw(line,rw,t):
|
||||
assert isinstance(line,t)
|
||||
assert type(line) == t
|
||||
buffer = line.text.split()
|
||||
if len(buffer) == 2:
|
||||
dummy, variable = buffer
|
||||
@ -465,15 +465,15 @@ def irp_simple_statements(text):
|
||||
return result
|
||||
|
||||
def process_irp_read (line):
|
||||
assert isinstance(line,Irp_read)
|
||||
assert type(line) == Irp_read
|
||||
return process_irp_rw(line,'read' ,Irp_read )
|
||||
|
||||
def process_irp_write(line):
|
||||
assert isinstance(line,Irp_write)
|
||||
assert type(line) == Irp_write
|
||||
return process_irp_rw(line,'writ' ,Irp_write)
|
||||
|
||||
def process_return(line):
|
||||
assert isinstance(line,Return)
|
||||
assert type(line) == Return
|
||||
if command_line.do_assert or command_line.do_debug:
|
||||
newline = Simple_line(line.i," call irp_leave(irp_here)",line.filename)
|
||||
result = [newline, line]
|
||||
@ -483,7 +483,7 @@ def irp_simple_statements(text):
|
||||
|
||||
def debug_conditions(line):
|
||||
'''Find condition in assert statement for debug'''
|
||||
assert isinstance(line,Assert)
|
||||
assert type(line) == Assert
|
||||
match = re_test.search(line.text)
|
||||
result = []
|
||||
if match is not None:
|
||||
@ -495,7 +495,7 @@ def irp_simple_statements(text):
|
||||
return result
|
||||
|
||||
def process_assert(line):
|
||||
assert isinstance(line,Assert)
|
||||
assert type(line) == Assert
|
||||
if command_line.do_assert:
|
||||
condition = "(%s"%(line.text.split('(',1)[1])
|
||||
if condition == "":
|
||||
@ -537,7 +537,7 @@ def irp_simple_statements(text):
|
||||
return result
|
||||
|
||||
def process_begin_provider(line):
|
||||
assert isinstance(line,Begin_provider)
|
||||
assert type(line) == Begin_provider
|
||||
buffer = line.lower.replace('['," ")
|
||||
buffer = buffer.replace(']',"")
|
||||
buffer = buffer.split(',')
|
||||
@ -556,7 +556,7 @@ def irp_simple_statements(text):
|
||||
return result
|
||||
|
||||
def process_cont_provider(line):
|
||||
assert isinstance(line,Cont_provider)
|
||||
assert type(line) == Cont_provider
|
||||
buffer = line.lower.replace('['," ")
|
||||
buffer = buffer.replace(']',"")
|
||||
buffer = buffer.split(',')
|
||||
@ -568,7 +568,7 @@ def irp_simple_statements(text):
|
||||
return [ Cont_provider(i,line.text,(f,varname)) ]
|
||||
|
||||
def process_subroutine(line):
|
||||
assert isinstance(line,Subroutine)
|
||||
assert type(line) == Subroutine
|
||||
subname = find_subname(line)
|
||||
length = len(subname)
|
||||
i = line.i
|
||||
@ -582,7 +582,7 @@ def irp_simple_statements(text):
|
||||
return result
|
||||
|
||||
def process_function(line):
|
||||
assert isinstance(line,Function)
|
||||
assert type(line) == Function
|
||||
buffer = line.text.split('(')
|
||||
subname = find_subname(line)
|
||||
length = len(subname)
|
||||
@ -598,7 +598,7 @@ def irp_simple_statements(text):
|
||||
|
||||
|
||||
def process_program(line):
|
||||
assert isinstance(line,Program)
|
||||
assert type(line) == Program
|
||||
program_name = line.lower.split()[1]
|
||||
result = [ Program(0,"",program_name) ] + \
|
||||
process_subroutine( Subroutine(line.i,"subroutine %s"%(program_name,),line.filename) )
|
||||
@ -621,7 +621,7 @@ def irp_simple_statements(text):
|
||||
for line in text:
|
||||
buffer = [ line ]
|
||||
for t in d.keys():
|
||||
if isinstance(line,t):
|
||||
if type(line) == t:
|
||||
buffer = d[t](line)
|
||||
break
|
||||
result += buffer
|
||||
@ -633,7 +633,7 @@ def change_includes(text):
|
||||
'''Deals with include files'''
|
||||
result = []
|
||||
for line in text:
|
||||
if (isinstance(line,Include)):
|
||||
if type(line) == Include:
|
||||
txt = line.text.replace('"',"'").split("'")
|
||||
if len(txt) != 3:
|
||||
print txt
|
||||
@ -652,7 +652,7 @@ def change_includes(text):
|
||||
######################################################################
|
||||
def process_old_style_do(text):
|
||||
'''Changes old-style do loops to new style'''
|
||||
assert isinstance(text,list)
|
||||
assert type(text) == list
|
||||
|
||||
def change_matching_enddo(begin,number):
|
||||
for i in range(begin+1,len(text)):
|
||||
@ -667,7 +667,7 @@ def process_old_style_do(text):
|
||||
result = []
|
||||
for i in range(len(text)):
|
||||
line = text[i]
|
||||
if isinstance(line,Do):
|
||||
if type(line) == Do:
|
||||
buffer = line.text.split()
|
||||
if buffer[1].isdigit():
|
||||
number = buffer.pop(1)
|
||||
@ -687,10 +687,10 @@ if (test) then
|
||||
result
|
||||
endif'''
|
||||
|
||||
assert isinstance(text,list)
|
||||
assert type(text) == list
|
||||
result = []
|
||||
for line in text:
|
||||
if isinstance(line,If):
|
||||
if type(line) == If:
|
||||
if line.lower.endswith("then"):
|
||||
result.append(line)
|
||||
else:
|
||||
@ -737,15 +737,15 @@ def check_begin_end(text):
|
||||
d = { 'do' : Do, 'enddo': Enddo,
|
||||
'if' : If, 'endif': Endif,
|
||||
'_doc': Begin_doc, 'end_doc': End_doc}
|
||||
assert isinstance(text,list)
|
||||
assert type(text) == list
|
||||
|
||||
def find_matching_end_ifdo(begin,x):
|
||||
level = 1
|
||||
for i in range(begin+1,len(text)):
|
||||
line = text[i]
|
||||
if isinstance(line,d[x]):
|
||||
if type(line) == d[x]:
|
||||
level += 1
|
||||
elif isinstance(line,d["end%s"%(x,)]):
|
||||
elif type(line) == d["end%s"%(x,)]:
|
||||
level -= 1
|
||||
if level == 0:
|
||||
return True
|
||||
@ -756,7 +756,7 @@ def check_begin_end(text):
|
||||
def find_matching_end_subfunpro(begin,x):
|
||||
for i in range(begin+1,len(text)):
|
||||
line = text[i]
|
||||
if isinstance(line,x):
|
||||
if type(line) == x:
|
||||
return
|
||||
if type(line) in [ Subroutine, Function, Begin_provider ]:
|
||||
error.fail(text[begin],"Subroutine/Function/Provider is not closed")
|
||||
@ -765,25 +765,25 @@ def check_begin_end(text):
|
||||
|
||||
level = 0
|
||||
for i,line in enumerate(text):
|
||||
if isinstance(line,Begin_doc):
|
||||
if type(line) == Begin_doc:
|
||||
find_matching_end_ifdo(i,'_doc')
|
||||
for i,line in enumerate(text):
|
||||
if isinstance(line,Do):
|
||||
if type(line) == Do:
|
||||
find_matching_end_ifdo(i,'do')
|
||||
elif isinstance(line,If):
|
||||
elif type(line) == If:
|
||||
find_matching_end_ifdo(i,'if')
|
||||
elif isinstance(line,Subroutine):
|
||||
elif type(line) == Subroutine:
|
||||
level += 1
|
||||
find_matching_end_subfunpro(i,End)
|
||||
elif isinstance(line,Function):
|
||||
elif type(line) == Function:
|
||||
level += 1
|
||||
find_matching_end_subfunpro(i,End)
|
||||
elif isinstance(line,Begin_provider):
|
||||
elif type(line) == Begin_provider:
|
||||
level += 1
|
||||
find_matching_end_subfunpro(i,End_provider)
|
||||
elif isinstance(line,End):
|
||||
elif type(line) == End:
|
||||
level -= 1
|
||||
elif isinstance(line,End_provider):
|
||||
elif type(line) == End_provider:
|
||||
level -= 1
|
||||
if level < 0:
|
||||
error.fail(line,"Beginning of block not matched")
|
||||
@ -792,16 +792,16 @@ def check_begin_end(text):
|
||||
|
||||
######################################################################
|
||||
def remove_ifdefs(text):
|
||||
assert isinstance(text,list)
|
||||
assert type(text) == list
|
||||
result = []
|
||||
do_print = True
|
||||
for line in text:
|
||||
if isinstance(line,Irp_If):
|
||||
if type(line) == Irp_If:
|
||||
var = line.text.split()[1]
|
||||
do_print = var in command_line.defined
|
||||
elif isinstance(line,Irp_Else):
|
||||
elif type(line) == Irp_Else:
|
||||
do_print = not do_print
|
||||
elif isinstance(line,Irp_Endif):
|
||||
elif type(line) == Irp_Endif:
|
||||
do_print = True
|
||||
else:
|
||||
if do_print:
|
||||
|
@ -33,7 +33,7 @@ class Sub(object):
|
||||
|
||||
############################################################
|
||||
def __init__(self,text):
|
||||
assert isinstance(text,list)
|
||||
assert type(text) == list
|
||||
assert len(text) > 0
|
||||
assert type(text[0]) in [Subroutine, Function]
|
||||
self.text = text
|
||||
@ -57,7 +57,7 @@ class Sub(object):
|
||||
def doc(self):
|
||||
if '_doc' not in self.__dict__:
|
||||
def f(l): return
|
||||
buffer = filter(lambda l:isinstance(l,Doc), self.text)
|
||||
buffer = filter(lambda l:type(l) == Doc, self.text)
|
||||
self._doc = map(lambda l: l.text[1:], buffer)
|
||||
if buffer == []:
|
||||
error.warn(None,"Subroutine %s is not documented"%(self.name))
|
||||
@ -76,7 +76,7 @@ class Sub(object):
|
||||
if '_touches' not in self.__dict__:
|
||||
from subroutines import subroutines
|
||||
self._touches = []
|
||||
for line in filter(lambda x: isinstance(x,Touch),self.text):
|
||||
for line in filter(lambda x: type(x) in [Touch, SoftTouch],self.text):
|
||||
self._touches += line.text.split()[1:]
|
||||
for sub in self.calls:
|
||||
if sub in subroutines:
|
||||
@ -97,7 +97,7 @@ class Sub(object):
|
||||
############################################################
|
||||
def calls(self):
|
||||
if '_calls' not in self.__dict__:
|
||||
buffer = filter(lambda x: isinstance(x,Call),self.text)
|
||||
buffer = filter(lambda x: type(x) == Call,self.text)
|
||||
self._calls = []
|
||||
for line in buffer:
|
||||
sub = line.text.split('(',1)[0].split()[1]
|
||||
|
12
src/util.py
12
src/util.py
@ -35,7 +35,7 @@ def lower(x):
|
||||
|
||||
def same_file(filename,txt):
|
||||
assert isinstance(filename,str)
|
||||
assert isinstance(txt,list)
|
||||
assert type(txt) == list
|
||||
|
||||
try:
|
||||
file = open(filename,"r")
|
||||
@ -85,7 +85,7 @@ def make_single(l):
|
||||
return d.keys()
|
||||
|
||||
def flatten(l):
|
||||
if isinstance(l,list):
|
||||
if type(l) == list:
|
||||
result = []
|
||||
for i in range(len(l)):
|
||||
elem = l[i]
|
||||
@ -116,12 +116,12 @@ def dimsize(x):
|
||||
return size
|
||||
|
||||
def put_info(text,filename):
|
||||
assert isinstance(text,list)
|
||||
assert type(text) == list
|
||||
if len(text) > 0:
|
||||
assert isinstance(text[0],tuple)
|
||||
assert type(text[0]) == tuple
|
||||
from irpf90_t import Line
|
||||
assert isinstance(text[0][0],list)
|
||||
assert isinstance(text[0][1],Line)
|
||||
assert type(text[0][0]) == list
|
||||
assert isinstance(text[0][1], Line)
|
||||
lenmax = 80 - len(filename)
|
||||
format = "%"+str(lenmax)+"s ! %s:%4s"
|
||||
for vars,line in text:
|
||||
|
@ -34,9 +34,9 @@ class Variable(object):
|
||||
|
||||
############################################################
|
||||
def __init__(self,text,name = None):
|
||||
assert isinstance(text,list)
|
||||
assert type(text) == list
|
||||
assert len(text) > 0
|
||||
assert isinstance(text[0],Begin_provider)
|
||||
assert type(text[0]) == Begin_provider
|
||||
self.text = text
|
||||
if name is not None:
|
||||
self._name = name
|
||||
@ -93,7 +93,7 @@ class Variable(object):
|
||||
if '_name' not in self.__dict__:
|
||||
buffer = None
|
||||
for line in self.text:
|
||||
if isinstance(line,Begin_provider):
|
||||
if type(line) == Begin_provider:
|
||||
self._name = line.filename[1]
|
||||
break
|
||||
return self._name
|
||||
@ -103,7 +103,7 @@ class Variable(object):
|
||||
def doc(self):
|
||||
if '_doc' not in self.__dict__:
|
||||
def f(l): return
|
||||
buffer = filter(lambda l:isinstance(l,Doc), self.text)
|
||||
buffer = filter(lambda l:type(l) == Doc, self.text)
|
||||
self._doc = map(lambda l: l.text[1:], buffer)
|
||||
if buffer == []:
|
||||
error.warn(None,"Variable %s is not documented"%(self.name))
|
||||
@ -134,7 +134,7 @@ class Variable(object):
|
||||
############################################################
|
||||
def same_as(self):
|
||||
if '_same_as' not in self.__dict__:
|
||||
if isinstance(self.line,Begin_provider):
|
||||
if type(self.line) == Begin_provider:
|
||||
result = self.name
|
||||
else:
|
||||
result = self.text[0].filename[1]
|
||||
@ -490,14 +490,14 @@ class Variable(object):
|
||||
same_as = self.same_as
|
||||
inside = False
|
||||
for vars,line in buffer:
|
||||
if isinstance(line,Begin_provider):
|
||||
if type(line) == Begin_provider:
|
||||
if line.filename[1] == same_as:
|
||||
inside = True
|
||||
vars = []
|
||||
if inside:
|
||||
text.append( (vars,line) )
|
||||
text += map( lambda x: ([],Simple_line(line.i,x,line.filename)), call_provides(vars) )
|
||||
if isinstance(line,End_provider):
|
||||
if type(line) == End_provider:
|
||||
if inside:
|
||||
break
|
||||
name = self.name
|
||||
|
@ -38,11 +38,11 @@ def create_variables():
|
||||
buffer = []
|
||||
inside = False
|
||||
for line in text:
|
||||
if isinstance(line,Begin_provider):
|
||||
if type(line) == Begin_provider:
|
||||
inside = True
|
||||
if inside:
|
||||
buffer.append(line)
|
||||
if isinstance(line,End_provider):
|
||||
if type(line) == End_provider:
|
||||
inside = False
|
||||
v = Variable(buffer)
|
||||
result[v.name] = v
|
||||
|
@ -1 +1 @@
|
||||
version = "1.1.55"
|
||||
version = "1.1.56"
|
||||
|
Loading…
Reference in New Issue
Block a user