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

preprocessed text finished

This commit is contained in:
Anthony Scemama 2009-09-03 23:12:32 +02:00
parent f4461836ea
commit 5f6950fd7c
5 changed files with 45 additions and 12 deletions

View File

@ -12,13 +12,26 @@ options['h'] = [ 'help' , 'Print this help', 0 ]
options['o'] = [ 'openmp' , 'Activate openMP', 0 ] options['o'] = [ 'openmp' , 'Activate openMP', 0 ]
options['c'] = [ 'check_cycles' , 'Check cycles in dependencies', 0 ] options['c'] = [ 'check_cycles' , 'Check cycles in dependencies', 0 ]
options['i'] = [ 'init' , 'Initialize current directory', 0 ] options['i'] = [ 'init' , 'Initialize current directory', 0 ]
options['D'] = [ 'define' , 'Define variable', 1 ]
class CommandLine(object): class CommandLine(object):
def __init__(self): def __init__(self):
global options
self._opts = None self._opts = None
self.argv = list(sys.argv)
self.executable_name = self.argv[0]
executable_name = sys.argv[0] def defined(self):
try:
d = self._defined
except AttributeError:
self._defined = []
for o,a in self.opts:
if o in [ "-D", options['D'][0] ]:
self._defined.append(a)
return self._defined
defined = property(fget=defined)
def usage(self): def usage(self):
t = """ t = """
@ -54,7 +67,7 @@ Options:
optlist[1] += [b[1]] optlist[1] += [b[1]]
try: try:
self._opts, args = getopt.getopt(sys.argv[1:], optlist[0], optlist[1]) self._opts, args = getopt.getopt(self.argv[1:], optlist[0], optlist[1])
except getopt.GetoptError, err: except getopt.GetoptError, err:
# print help information and exit: # print help information and exit:
self.usage() self.usage()

View File

@ -103,9 +103,10 @@ subroutine irp_trace
end subroutine end subroutine
""" """
txt = txt.splitlines()
if not util.same_file(FILENAME, txt): if not util.same_file(FILENAME, txt):
file = open(FILENAME,'w') file = open(FILENAME,'w')
file.write(txt) file.writelines(txt)
file.close() file.close()

View File

@ -3,6 +3,9 @@
def main(): def main():
from command_line import command_line from command_line import command_line
if command_line.do_help:
command_line.usage()
if command_line.do_version: if command_line.do_version:
from version import version from version import version
print version print version
@ -18,4 +21,4 @@ def main():
import irp_stack import irp_stack
irp_stack.create() irp_stack.create()
main()

View File

@ -11,7 +11,7 @@ def create():
has_makefile = True has_makefile = True
try: try:
file = open(FILENAME,"r") file = open(FILENAME,"r")
except OSError: except IOError:
has_makefile = False has_makefile = False
if has_makefile: if has_makefile:
return return

View File

@ -143,7 +143,6 @@ def get_text(lines,filename):
for i,line in enumerate(lines): for i,line in enumerate(lines):
line, is_doc = get_type(i+1,filename,line,is_doc) line, is_doc = get_type(i+1,filename,line,is_doc)
result += line result += line
assert not is_doc
return result return result
###################################################################### ######################################################################
@ -603,15 +602,16 @@ def check_begin_end(text):
def filter_line(line): def filter_line(line):
for type in [ Do, Enddo, If, Endif, Begin_provider, End_provider, \ for type in [ Do, Enddo, If, Endif, Begin_provider, End_provider, \
Subroutine, Function, End ]: Subroutine, Function, End, Begin_doc, End_doc ]:
if isinstance(line,type): if isinstance(line,type):
return True return True
return False return False
text = filter(filter_line, text) text = filter(filter_line, text)
d = { 'do': Do, 'enddo': Enddo, d = { 'do' : Do, 'enddo': Enddo,
'if': If, 'endif': Endif} 'if' : If, 'endif': Endif,
'_doc': Begin_doc, 'end_doc': End_doc}
assert isinstance(text,list) assert isinstance(text,list)
def find_matching_end_ifdo(begin,x): def find_matching_end_ifdo(begin,x):
@ -627,7 +627,7 @@ def check_begin_end(text):
elif isinstance(line,End) or \ elif isinstance(line,End) or \
isinstance(line,End_provider): isinstance(line,End_provider):
break break
error.fail(text[begin],"Missing 'end %s'"%(x,)) error.fail(text[begin],"Missing 'end%s'"%(x,))
def find_matching_end_subfunpro(begin,x): def find_matching_end_subfunpro(begin,x):
for i in range(begin+1,len(text)): for i in range(begin+1,len(text)):
@ -641,6 +641,9 @@ def check_begin_end(text):
level = 0 level = 0
for i,line in enumerate(text):
if isinstance(line,Begin_doc):
find_matching_end_ifdo(i,'_doc')
for i,line in enumerate(text): for i,line in enumerate(text):
if isinstance(line,Do): if isinstance(line,Do):
find_matching_end_ifdo(i,'do') find_matching_end_ifdo(i,'do')
@ -666,8 +669,21 @@ def check_begin_end(text):
###################################################################### ######################################################################
def remove_ifdefs(text): def remove_ifdefs(text):
# TODO assert isinstance(text,list)
return text result = []
do_print = True
for line in text:
if isinstance(line,Irp_If):
var = line.text.split()[1]
do_print = var in command_line.defined
elif isinstance(line,Irp_Else):
do_print = not do_print
elif isinstance(line,Irp_Endif):
do_print = True
else:
if do_print:
result.append(line)
return result
###################################################################### ######################################################################
def move_to_top(text,t): def move_to_top(text,t):