10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-22 04:13:33 +01:00

Version:1.1.10

This commit is contained in:
Anthony Scemama 2009-09-09 16:59:43 +02:00
parent 63a49efe15
commit 98e97dbe22
7 changed files with 285 additions and 174 deletions

View File

@ -10,7 +10,7 @@ class Fmodule(object):
def __init__(self,text,filename): def __init__(self,text,filename):
self.text = put_info(text,filename) self.text = put_info(text,filename)
self.name = "%s_mod"%(filename[:-6].lower()) self.name = "%s_mod"%(filename[:-6])
def is_main(self): def is_main(self):
if '_is_main' not in self.__dict__: if '_is_main' not in self.__dict__:
@ -69,8 +69,6 @@ class Fmodule(object):
var = variables[var] var = variables[var]
result += var.provider result += var.provider
result += var.builder result += var.builder
if var.is_freed:
result += var.free
if var.is_touched: if var.is_touched:
result += var.toucher result += var.toucher
if var.is_read: if var.is_read:
@ -84,6 +82,7 @@ class Fmodule(object):
def residual_text(self): def residual_text(self):
if '_residual_text' not in self.__dict__: if '_residual_text' not in self.__dict__:
from variables import build_use from variables import build_use
from parsed_text import move_to_top
def remove_providers(text): def remove_providers(text):
result = [] result = []
inside = False inside = False
@ -128,21 +127,29 @@ class Fmodule(object):
inside = False inside = False
return use, dec, result return use, dec, result
def provide_variables(text):
result = []
for vars,line in text:
result.append( ([],line) )
result += map(lambda x: ([],Simple_line(line.i," call provide_%s"%(x),line.filename)), vars)
return result
result = remove_providers(self.text) result = remove_providers(self.text)
result = modify_functions(result) result = modify_functions(result)
use,dec,result = extract_use_dec_text(result) use,dec,result = extract_use_dec_text(result)
self._use = make_single(map(lambda x: " "+x[1].text, use)) self._use = make_single(map(lambda x: " "+x[1].text, use))
self._dec = make_single(map(lambda x: " "+x[1].text, dec)) self._dec = make_single(map(lambda x: " "+x[1].text, dec))
result = provide_variables(result)
result = move_to_top(result,Declaration)
result = move_to_top(result,Implicit)
result = move_to_top(result,Use)
result = map(lambda x: x[1], result) result = map(lambda x: x[1], result)
result = preprocessed_text.move_to_top(result,Declaration)
result = preprocessed_text.move_to_top(result,Implicit)
result = preprocessed_text.move_to_top(result,Use)
result = map(lambda x: x.text, result) result = map(lambda x: x.text, result)
if self.is_main: if self.is_main:
result = [ \ result = [ \
"program irp_program", "program irp_program",
" call %s"%(self.prog_name), " call %s"%(self.prog_name),
"end irp_program", "end program",
] + result ] + result
self._residual_text = result self._residual_text = result
return self._residual_text return self._residual_text

View File

@ -14,8 +14,9 @@ def find_variables_in_line(line):
buffer = regexps.re_string.sub('',line.text) buffer = regexps.re_string.sub('',line.text)
for v in variables.keys(): for v in variables.keys():
var = variables[v] var = variables[v]
if var.regexp.search(buffer) is not None: if var.name in buffer.lower():
result.append(var.name) if var.regexp.search(buffer) is not None:
result.append(var.same_as)
return result return result
def find_subroutine_in_line(line): def find_subroutine_in_line(line):
@ -72,6 +73,9 @@ def get_parsed_text():
elif isinstance(line,Provide): elif isinstance(line,Provide):
l = line.text.lower().split()[1:] l = line.text.lower().split()[1:]
l = filter(lambda x: x not in varlist, l) 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))
result.append( (l,Simple_line(line.i,"!%s"%(line.text),line.filename)) ) result.append( (l,Simple_line(line.i,"!%s"%(line.text),line.filename)) )
elif isinstance(line,Call): elif isinstance(line,Call):
sub = find_subroutine_in_line(line) sub = find_subroutine_in_line(line)
@ -82,7 +86,9 @@ def get_parsed_text():
t = Simple_line t = Simple_line
else: else:
t = Provide_all t = Provide_all
result.append( ([],t(line.i,line.text,line.filename)) ) l = find_variables_in_line(line)
l = filter(lambda x: x not in varlist, l)
result.append( (l,t(line.i,line.text,line.filename)) )
elif isinstance(line,Free): elif isinstance(line,Free):
vars = line.text.split() vars = line.text.split()
if len(vars) < 2: if len(vars) < 2:
@ -91,9 +97,12 @@ def get_parsed_text():
for v in vars: for v in vars:
variables[v].is_freed = True variables[v].is_freed = True
result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) ) result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
use = map(lambda x: " use %s"%(variables[x].fmodule),vars)
for var in vars: for var in vars:
result.append( ([],Simple_line(line.i," call free_%s"%var, result += map(lambda x: ([],Use(line.i,x,line.filename)),
line.filename)) ) make_single(use))
result += map(lambda x: ([],Simple_line(line.i,x,line.filename)),
variables[var].free)
elif isinstance(line,Irp_read): elif isinstance(line,Irp_read):
variables[line.filename].is_read = True variables[line.filename].is_read = True
result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) ) result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
@ -106,7 +115,7 @@ def get_parsed_text():
error.fail(line,"Syntax error") error.fail(line,"Syntax error")
vars = map(lower,vars[1:]) vars = map(lower,vars[1:])
for v in vars: for v in vars:
variables[v].is_touched = True variables[v]._is_touched = True
def fun(x): def fun(x):
if x not in variables: if x not in variables:
error.fail(line,"Variable %s unknown"%(x,)) error.fail(line,"Variable %s unknown"%(x,))
@ -121,7 +130,8 @@ def get_parsed_text():
if x not in variables: if x not in variables:
error.fail(line,"Variable %s unknown"%(x,)) error.fail(line,"Variable %s unknown"%(x,))
return [ ([],Simple_line(line.i," call touch_%s"%(x,),line.filename)), return [ ([],Simple_line(line.i," call touch_%s"%(x,),line.filename)),
([],Simple_line(line.i," %s_is_built = .True."%(x,),line.filename)) ] ([],Simple_line(line.i," %s_is_built = .True."%(x,),line.filename)),
([],Use(line.i," use %s"%(variables[x].fmodule), line.filename)) ]
result += flatten(map( fun, main_vars )) result += flatten(map( fun, main_vars ))
def fun(x): def fun(x):
if x not in variables: if x not in variables:
@ -137,7 +147,7 @@ def get_parsed_text():
v = buffer[1].lower() v = buffer[1].lower()
varlist.append(v) varlist.append(v)
variable_list = find_variables_in_line(line) variable_list = find_variables_in_line(line)
variable_list.remove(v) variable_list.remove(variables[v].same_as)
result.append( (variable_list,line) ) result.append( (variable_list,line) )
else: else:
l = find_variables_in_line(line) l = find_variables_in_line(line)
@ -242,10 +252,33 @@ def move_variables():
parsed_text = move_variables() parsed_text = move_variables()
######################################################################
def move_to_top(text,t):
assert isinstance(text,list)
assert t in [ Declaration, Implicit, Use, Cont_provider ]
inside = False
for i in range(len(text)):
vars, line = text[i]
if type(line) in [ Begin_provider, Subroutine, Function ]:
begin = i
inside = True
elif type(line) in [ End_provider, End ]:
inside = False
elif isinstance(line,t):
if inside:
text.pop(i)
begin += 1
text.insert(begin,(vars,line))
return text
###################################################################### ######################################################################
def build_needs(): def build_needs():
# Needs # Needs
for filename, text in parsed_text: for filename, text in parsed_text:
var = None
for vars,line in text: for vars,line in text:
if isinstance(line,Begin_provider): if isinstance(line,Begin_provider):
buffer = map(strip,line.text.replace(']',',').split(',')) buffer = map(strip,line.text.replace(']',',').split(','))
@ -273,8 +306,9 @@ def build_needs():
variables[v].needed_by = variables[main].needed_by variables[v].needed_by = variables[main].needed_by
for v in variables.keys(): for v in variables.keys():
var = variables[v] var = variables[v]
for x in var.needs: if var.is_main:
variables[x].needed_by.append(var.same_as) for x in var.needs:
variables[x].needed_by.append(var.same_as)
for v in variables.keys(): for v in variables.keys():
var = variables[v] var = variables[v]
var.needed_by = make_single(var.needed_by) var.needed_by = make_single(var.needed_by)
@ -282,11 +316,21 @@ def build_needs():
build_needs() build_needs()
result = []
for filename,text in parsed_text:
text = move_to_top(text,Declaration)
text = move_to_top(text,Implicit)
text = move_to_top(text,Use)
text = move_to_top(text,Cont_provider)
result.append ( (filename,text) )
parsed_text = result
###################################################################### ######################################################################
if __name__ == '__main__': if __name__ == '__main__':
for i in range(len(parsed_text)): for i in range(len(parsed_text)):
if parsed_text[i][0] == 'mpi.irp.f':
print '!-------- %s -----------'%(parsed_text[i][0]) print '!-------- %s -----------'%(parsed_text[i][0])
for line in parsed_text[i][1]: for line in parsed_text[i][1]:
print line[1] print line[1]
print line[0] print line[0], line[1].filename

View File

@ -111,7 +111,7 @@ def get_type (i, filename, line, is_doc):
if firstword[0] == '#': if firstword[0] == '#':
result = [ Simple_line(i,line,filename) ] result = [ Simple_line(i,line,filename) ]
error.warn ( result , error.warn ( result[0] ,
"""irpf90 may not work with preprocessor directives. You can use """irpf90 may not work with preprocessor directives. You can use
Irp_if ... Irp_else ... Irp_endif Irp_if ... Irp_else ... Irp_endif
instead of instead of
@ -361,7 +361,7 @@ def irp_simple_statements(text):
def process_assert(line): def process_assert(line):
assert isinstance(line,Assert) assert isinstance(line,Assert)
if command_line.do_assert: if command_line.do_assert:
condition = line.text.split(None,1)[1] condition = "(%s"%(line.text.split('(',1)[1])
if condition == "": if condition == "":
error.fail(line,"Error in Assert statement") error.fail(line,"Error in Assert statement")
condition_str = condition.replace("'","''") condition_str = condition.replace("'","''")
@ -411,14 +411,26 @@ def irp_simple_statements(text):
length = len(varname) length = len(varname)
i = line.i i = line.i
f = line.filename f = line.filename
result = [ line, result = [ Begin_provider(i,line.text, (f,varname)),
Declaration(i," character*(%d), parameter :: irp_here = '%s'"%(length,varname), f) ] Declaration(i," character*(%d), parameter :: irp_here = '%s'"%(length,varname), filename) ]
if command_line.do_assert or command_line.do_debug: if command_line.do_assert or command_line.do_debug:
result += [ result += [
Simple_line(i," call irp_enter(irp_here)", f), Simple_line(i," call irp_enter(irp_here)", f),
] ]
return result return result
def process_cont_provider(line):
assert isinstance(line,Cont_provider)
buffer = line.text.replace('['," ")
buffer = buffer.replace(']',"")
buffer = buffer.split(',')
if len(buffer) < 2:
error.fail(line,"Error in Cont_provider statement")
varname = buffer[1].strip().lower()
i = line.i
f = line.filename
return [ Cont_provider(i,line.text,(f,varname)) ]
def process_subroutine(line): def process_subroutine(line):
assert isinstance(line,Subroutine) assert isinstance(line,Subroutine)
subname = find_subname(line) subname = find_subname(line)
@ -462,11 +474,11 @@ def irp_simple_statements(text):
Assert : process_assert, Assert : process_assert,
End : process_end, End : process_end,
Begin_provider : process_begin_provider, Begin_provider : process_begin_provider,
Cont_provider : process_cont_provider,
End_provider : process_end, End_provider : process_end,
Subroutine : process_subroutine, Subroutine : process_subroutine,
Function : process_function, Function : process_function,
Program : process_program, Program : process_program,
Provide : process_provide,
} }
result = [] result = []
@ -661,27 +673,6 @@ def remove_ifdefs(text):
result.append(line) result.append(line)
return result return result
######################################################################
def move_to_top(text,t):
assert isinstance(text,list)
assert t in [ Declaration, Implicit, Use, Cont_provider ]
inside = False
for i in range(len(text)):
line = text[i]
if type(line) in [ Begin_provider, Subroutine, Function ]:
begin = i
inside = True
elif type(line) in [ End_provider, End ]:
inside = False
elif isinstance(line,t):
if inside:
text.pop(i)
begin += 1
text.insert(begin,line)
return text
###################################################################### ######################################################################
def create_preprocessed_text(filename): def create_preprocessed_text(filename):
file = open(filename,"r") file = open(filename,"r")
@ -697,10 +688,6 @@ def create_preprocessed_text(filename):
result = change_single_line_ifs(result) result = change_single_line_ifs(result)
result = process_old_style_do(result) result = process_old_style_do(result)
result = irp_simple_statements(result) result = irp_simple_statements(result)
result = move_to_top(result,Declaration)
result = move_to_top(result,Implicit)
result = move_to_top(result,Use)
result = move_to_top(result,Cont_provider)
return result return result
###################################################################### ######################################################################

View File

@ -24,14 +24,7 @@ re_decl = re.compile( "".join( [ r"^\ *",
r")[^=(]" r")[^=(]"
] ) ) ] ) )
re_left = re.compile(r"\[")
re_right = re.compile(r"\]")
re_test = re.compile(r"\( *(.*)(\.[a-zA-Z]*\.|[<>]=?|[=/]=)([^=]*)\)") re_test = re.compile(r"\( *(.*)(\.[a-zA-Z]*\.|[<>]=?|[=/]=)([^=]*)\)")
re_space = re.compile("\s")
re_string = re.compile(r"'.*'") re_string = re.compile(r"'.*'")
re_assert = re.compile(r"assert *",re.I)
re_check = re.compile(r".*[() ].*")

View File

@ -58,7 +58,7 @@ class Sub(object):
if '_regexp' not in self.__dict__: if '_regexp' not in self.__dict__:
import re import re
self._regexp = re.compile( \ self._regexp = re.compile( \
r"^.*[^a-z0-9'\"_]+%s([^a-z0-9_]|$)"%(self.name),re.I) r"([^a-z0-9'\"_]|^)%s([^a-z0-9_]|$)"%(self.name),re.I)
return self._regexp return self._regexp
regexp = property(regexp) regexp = property(regexp)

View File

@ -15,10 +15,30 @@ class Variable(object):
self.text = text self.text = text
if name is not None: if name is not None:
self._name = name.lower() self._name = name.lower()
self.is_freed = False
self.is_read = False self.is_read = False
self.is_written = False self.is_written = False
self.is_touched = False
############################################################
def is_touched(self):
'''Name is lowercase'''
if '_is_touched' not in self.__dict__:
from variables import variables
result = True # False
#for i in self.children:
# if variables[i].is_touched:
# result = True
# break
self._is_touched = result
return self._is_touched
is_touched = property(is_touched)
############################################################
def is_main(self):
'''Name is lowercase'''
if '_is_main' not in self.__dict__:
self._is_main = (self.name == self.same_as)
return self._is_main
is_main = property(is_main)
############################################################ ############################################################
def name(self): def name(self):
@ -27,12 +47,8 @@ class Variable(object):
buffer = None buffer = None
for line in self.text: for line in self.text:
if isinstance(line,Begin_provider): if isinstance(line,Begin_provider):
buffer = line.text.replace(']',',').split(',') self._name = line.filename[1]
break break
assert buffer is not None
if len(buffer) < 3:
error.fail(line, "Error in Begin_provider line")
self._name = buffer[1].strip().lower()
return self._name return self._name
name = property(name) name = property(name)
@ -61,11 +77,7 @@ class Variable(object):
f = lambda l: type(l) in [Begin_provider, Cont_provider] f = lambda l: type(l) in [Begin_provider, Cont_provider]
lines = filter(f, self.text) lines = filter(f, self.text)
for line in lines: for line in lines:
buffer = line.text.replace(']',',').split(',') result.append(line.filename[1])
if len(buffer) < 3:
error.fail(line,"Syntax Error")
buffer = buffer[1].strip().lower()
result.append(buffer)
result.remove(self.name) result.remove(self.name)
self._others = result self._others = result
return self._others return self._others
@ -77,10 +89,7 @@ class Variable(object):
if isinstance(self.line,Begin_provider): if isinstance(self.line,Begin_provider):
result = self.name result = self.name
else: else:
buffer = self.text[0].text.replace(']',',').split(',') result = self.text[0].filename[1]
if len(buffer) < 3:
error.fail(line,"Syntax Error")
result = buffer[1].strip().lower()
self._same_as = result self._same_as = result
return self._same_as return self._same_as
same_as = property(same_as) same_as = property(same_as)
@ -88,10 +97,13 @@ class Variable(object):
############################################################ ############################################################
def allocate(self): def allocate(self):
if '_allocate' not in self.__dict__: if '_allocate' not in self.__dict__:
from variables import variables if not self.is_main:
def f(var): self._allocate = []
return variables[var].dim != [] else:
self._allocate = filter ( f, self.others + [self.name] ) from variables import variables
def f(var):
return variables[var].dim != []
self._allocate = filter ( f, self.others + [self.name] )
return self._allocate return self._allocate
allocate = property(allocate) allocate = property(allocate)
@ -114,7 +126,7 @@ class Variable(object):
line = self.line.text line = self.line.text
buffer = line.split(',')[0] buffer = line.split(',')[0]
buffer = buffer.split('[')[1].strip() buffer = buffer.split('[')[1].strip()
if self.dim != '': if self.dim != []:
buffer = "%s, allocatable"%(buffer) buffer = "%s, allocatable"%(buffer)
self._type = buffer self._type = buffer
return self._type return self._type
@ -123,7 +135,7 @@ class Variable(object):
############################################################ ############################################################
def fmodule(self): def fmodule(self):
if '_fmodule' not in self.__dict__: if '_fmodule' not in self.__dict__:
self._fmodule = self.line.filename.split('.irp.f')[0]+'_mod' self._fmodule = self.line.filename[0].split('.irp.f')[0]+'_mod'
return self._fmodule return self._fmodule
fmodule = property(fmodule) fmodule = property(fmodule)
@ -132,7 +144,8 @@ class Variable(object):
if '_regexp' not in self.__dict__: if '_regexp' not in self.__dict__:
import re import re
self._regexp = re.compile( \ self._regexp = re.compile( \
r"^.*[^a-z0-9'\"_]+%s([^a-z0-9_]|$)"%(self.name),re.I) #r"^.*[^a-z0-9'\"_]+%s([^a-z0-9_]|$)"%(self.name),re.I)
r"([^a-z0-9'\"_]|^)%s([^a-z0-9_]|$)"%(self.name),re.I)
return self._regexp return self._regexp
regexp = property(regexp) regexp = property(regexp)
@ -142,11 +155,8 @@ class Variable(object):
f = lambda l: type(l) in [Begin_provider, Cont_provider] f = lambda l: type(l) in [Begin_provider, Cont_provider]
lines = filter(f, self.text) lines = filter(f, self.text)
for line in lines: for line in lines:
buffer = line.text.replace(']',',').split(',') buffer = line.filename[1]
if len(buffer) < 3: if self._name == buffer:
error.fail(line,"Syntax Error")
buffer = buffer[1].strip().lower()
if self.name == buffer:
self._line = line self._line = line
break break
assert '_line' in self.__dict__ assert '_line' in self.__dict__
@ -157,18 +167,23 @@ class Variable(object):
def header(self): def header(self):
if '_header' not in self.__dict__: if '_header' not in self.__dict__:
name = self.name name = self.name
self._header = [ def build_dim(d):
" %s :: %s %s"%(self.type, name, build_dim(self.dim) ), if d == []:
" logical :: %s_is_built = .False."%(name), return ""
] else:
x = map(lambda x: ":", self.dim)
return "(%s)"%(','.join(x))
self._header = [ " %s :: %s %s"%(self.type, name, build_dim(self.dim) ) ]
if self.is_main:
self._header += [ " logical :: %s_is_built = .False."%(name) ]
return self._header return self._header
header = property(header) header = property(header)
############################################################ ############################################################
def toucher(self): def toucher(self):
if '_toucher' not in self.__dict__: if '_toucher' not in self.__dict__:
if self.same_as != self.name: if not self.is_main:
self._toucher = "" self._toucher = []
else: else:
if '_needed_by' not in self.__dict__: if '_needed_by' not in self.__dict__:
import parsed_text import parsed_text
@ -194,81 +209,93 @@ class Variable(object):
########################################################## ##########################################################
def reader(self): def reader(self):
if '_reader' not in self.__dict__: if '_reader' not in self.__dict__:
if '_needs' not in self.__dict__: if not self.is_main:
import parsed_text self._reader = []
name = self.name else:
result = [ \ if '_needs' not in self.__dict__:
"subroutine reader_%s(irp_num)"%(name), import parsed_text
" use %s"%(self.fmodule), from variables import variables
" implicit none", name = self.name
" character*(*), intent(in) :: irp_num", result = [ \
" logical :: irp_is_open", "subroutine reader_%s(irp_num)"%(name),
" integer :: irp_iunit" ] " use %s"%(self.fmodule),
if command_line.do_debug: " implicit none",
length = len("reader_%s"%(self.name)) " character*(*), intent(in) :: irp_num",
result += [\ " logical :: irp_is_open",
" character*(%d), parameter :: irp_here = 'reader_%s'"%(length,name), " integer :: irp_iunit" ]
" call irp_enter(irp_here)" ] if command_line.do_debug:
result += map(lambda x: " call reader_%s(irp_num)"%(x),self.needs) length = len("reader_%s"%(self.name))
result += [ \ result += [\
" irp_is_open = .True.", " character*(%d), parameter :: irp_here = 'reader_%s'"%(length,name),
" irp_iunit = 9", " call irp_enter(irp_here)" ]
" do while (irp_is_open)", result += map(lambda x: " call reader_%s(irp_num)"%(x),self.needs)
" irp_iunit = irp_iunit+1", result += [ \
" inquire(unit=irp_iunit,opened=irp_is_open)", " irp_is_open = .True.",
" enddo", " irp_iunit = 9",
" open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='OLD',action='READ')"%(name), " do while (irp_is_open)",
" read(irp_iunit,*) %s%s"%(name,build_dim(self.dim)), " irp_iunit = irp_iunit+1",
" close(irp_iunit)", " inquire(unit=irp_iunit,opened=irp_is_open)",
" call touch_%s"%(self.same_as), " enddo"]
" %s_is_built = .True."%(self.same_as) ] for n in [ name ]+self.others:
if command_line.do_debug: result += [\
result.append(" call irp_leave(irp_here)") " open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='OLD',action='READ')"%(n),
result.append("end subroutine reader_%s"%(name)) " read(irp_iunit,*) %s%s"%(n,build_dim(variables[n].dim)),
result.append("") " close(irp_iunit)" ]
self._reader = result rsult += [ \
" call touch_%s"%(name),
" %s_is_built = .True."%(name) ]
if command_line.do_debug:
result.append(" call irp_leave(irp_here)")
result.append("end subroutine reader_%s"%(name))
result.append("")
self._reader = result
return self._reader return self._reader
reader = property(reader) reader = property(reader)
########################################################## ##########################################################
def writer(self): def writer(self):
if '_writer' not in self.__dict__: if '_writer' not in self.__dict__:
if '_needs' not in self.__dict__: if not self.is_main:
import parsed_text self._writer = []
name = self.name else:
result = [ \ from variables import variables
"subroutine writer_%s(irp_num)"%(name), if '_needs' not in self.__dict__:
" use %s"%(self.fmodule), import parsed_text
" implicit none", name = self.name
" character*(*), intent(in) :: irp_num", result = [ \
" logical :: irp_is_open", "subroutine writer_%s(irp_num)"%(name),
" integer :: irp_iunit" ] " use %s"%(self.fmodule),
if command_line.do_debug: " implicit none",
length = len("writer_%s"%(self.name)) " character*(*), intent(in) :: irp_num",
result += [\ " logical :: irp_is_open",
" character*(%d), parameter :: irp_here = 'writer_%s'"%(length,name), " integer :: irp_iunit" ]
" call irp_enter(irp_here)" ] if command_line.do_debug:
result += [ \ length = len("writer_%s"%(self.name))
" if (.not.%s_is_built) then"%(self.same_as), result += [\
" call provide_%s"%(self.same_as), " character*(%d), parameter :: irp_here = 'writer_%s'"%(length,name),
" endif" ] " call irp_enter(irp_here)" ]
result += map(lambda x: " call writer_%s(irp_num)"%(x),self.needs) result += [ \
result += [ \ " if (.not.%s_is_built) then"%(self.same_as),
" irp_is_open = .True.", " call provide_%s"%(self.same_as),
" irp_iunit = 9", " endif" ]
" do while (irp_is_open)", result += map(lambda x: " call writer_%s(irp_num)"%(x),self.needs)
" irp_iunit = irp_iunit+1", result += [ \
" inquire(unit=irp_iunit,opened=irp_is_open)", " irp_is_open = .True.",
" enddo", " irp_iunit = 9",
" open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='UNKNOWN',action='WRITE')"%(name), " do while (irp_is_open)",
" write(irp_iunit,*) %s%s"%(name,build_dim(self.dim)), " irp_iunit = irp_iunit+1",
" close(irp_iunit)" ] " inquire(unit=irp_iunit,opened=irp_is_open)",
result += map(lambda x: " call writer_%s(irp_num)"%(x),self.others) " enddo" ]
if command_line.do_debug: for n in [ name ] + self.others:
result.append(" call irp_leave(irp_here)") result += [\
result.append("end subroutine writer_%s"%(name)) " open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='UNKNOWN',action='WRITE')"%(n),
result.append("") " write(irp_iunit,*) %s%s"%(n,build_dim(variables[n].dim)),
self._writer = result " close(irp_iunit)" ]
if command_line.do_debug:
result.append(" call irp_leave(irp_here)")
result.append("end subroutine writer_%s"%(name))
result.append("")
self._writer = result
return self._writer return self._writer
writer = property(writer) writer = property(writer)
@ -276,24 +303,14 @@ class Variable(object):
def free(self): def free(self):
if '_free' not in self.__dict__: if '_free' not in self.__dict__:
name = self.name name = self.name
result = [ \ result = [ "!","! >>> FREE %s"%(self.name),
"subroutine free_%s"%(name),
" use %s"%(self.fmodule),
" implicit none" ]
if command_line.do_debug:
length = len("free_%s"%(self.name))
result += [\
" character*(%d), parameter :: irp_here = 'free_%s'"%(length,name),
" %s_is_built = .False."%(self.same_as) ] " %s_is_built = .False."%(self.same_as) ]
if self.dim != []: if self.dim != []:
result += [ \ result += [ \
" if (allocated(%s)) then"%(name), " if (allocated(%s)) then"%(name),
" deallocate (%s)"%(name), " deallocate (%s)"%(name),
" endif" ] " endif" ]
if command_line.do_debug: result.append("! <<< END FREE")
result.append(" call irp_leave(irp_here)")
result.append("end subroutine free_%s"%(name))
result.append("")
self._free = result self._free = result
return self._free return self._free
free = property(free) free = property(free)
@ -301,6 +318,9 @@ class Variable(object):
########################################################## ##########################################################
def provider(self): def provider(self):
if '_provider' not in self.__dict__: if '_provider' not in self.__dict__:
if not self.is_main:
self._provider = []
else:
if '_to_provide' not in self.__dict__: if '_to_provide' not in self.__dict__:
import parsed_text import parsed_text
from variables import variables, build_use, call_provides from variables import variables, build_use, call_provides
@ -387,11 +407,28 @@ class Variable(object):
########################################################## ##########################################################
def builder(self): def builder(self):
if '_builder' not in self.__dict__: if '_builder' not in self.__dict__:
if not self.is_main:
self._builder = []
if '_needs' not in self.__dict__: if '_needs' not in self.__dict__:
import parsed_text import parsed_text
from variables import build_use from variables import build_use
for filename,buffer in parsed_text.parsed_text:
if self.line.filename[0].startswith(filename):
break
text = []
same_as = self.same_as
inside = False
for vars,line in buffer:
if isinstance(line,Begin_provider):
if line.filename[1] == same_as:
inside = True
if inside:
text.append(line)
if isinstance(line,End_provider):
if inside:
break
name = self.name name = self.name
for line in filter(lambda x: type(x) not in [ Begin_doc, End_doc, Doc], self.text): for line in filter(lambda x: type(x) not in [ Begin_doc, End_doc, Doc], text):
if type(line) == Begin_provider: if type(line) == Begin_provider:
result = [ "subroutine bld_%s"%(name) ] result = [ "subroutine bld_%s"%(name) ]
result += build_use([name]+self.needs) result += build_use([name]+self.needs)
@ -406,11 +443,54 @@ class Variable(object):
return self._builder return self._builder
builder = property(builder) builder = property(builder)
##########################################################
def children(self):
if '_children' not in self.__dict__:
if not self.is_main:
self._children = []
from variables import variables
if '_needs' not in self.__dict__:
import parsed_text
result = []
for x in self.needs:
result.append(x)
try:
result += variables[x].children
except RuntimeError:
pass # Exception will be checked after
self._children = make_single(result)
if self.name in result:
error.fail(self.line,"Cyclic dependencies:\n%s"%(str(self._children)))
return self._children
children = property(children)
##########################################################
def parents(self):
if '_parents' not in self.__dict__:
if not self._is_main:
self._parents = []
else:
from variables import variables
if '_needed_by' not in self.__dict__:
import parsed_text
result = []
for x in self.needed_by:
result.append(x)
try:
result += variables[x].parents
except RuntimeError:
pass # Exception will be checked after
self._parents = make_single(result)
if self.name in result:
error.fail(self.line,"Cyclic dependencies:\n%s"%(str(self._parents)))
return self._parents
parents = property(parents)
###################################################################### ######################################################################
if __name__ == '__main__': if __name__ == '__main__':
from preprocessed_text import preprocessed_text from preprocessed_text import preprocessed_text
from variables import variables from variables import variables
#for v in variables.keys(): #for v in variables.keys():
# print v # print v
for line in variables['grid_eplf_aa'].builder: for line in variables['e_loc'].parents:
print line print line

View File

@ -1 +1 @@
version = "1.1.9" version = "1.1.10"