10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-21 11:53:32 +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['c'] = [ 'check_cycles' , 'Check cycles in dependencies', 0 ]
options['i'] = [ 'init' , 'Initialize current directory', 0 ]
options['D'] = [ 'define' , 'Define variable', 1 ]
class CommandLine(object):
def __init__(self):
global options
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):
t = """
@ -54,7 +67,7 @@ Options:
optlist[1] += [b[1]]
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:
# print help information and exit:
self.usage()

View File

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

View File

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

View File

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

View File

@ -143,7 +143,6 @@ def get_text(lines,filename):
for i,line in enumerate(lines):
line, is_doc = get_type(i+1,filename,line,is_doc)
result += line
assert not is_doc
return result
######################################################################
@ -603,15 +602,16 @@ def check_begin_end(text):
def filter_line(line):
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):
return True
return False
text = filter(filter_line, text)
d = { 'do': Do, 'enddo': Enddo,
'if': If, 'endif': Endif}
d = { 'do' : Do, 'enddo': Enddo,
'if' : If, 'endif': Endif,
'_doc': Begin_doc, 'end_doc': End_doc}
assert isinstance(text,list)
def find_matching_end_ifdo(begin,x):
@ -627,7 +627,7 @@ def check_begin_end(text):
elif isinstance(line,End) or \
isinstance(line,End_provider):
break
error.fail(text[begin],"Missing 'end %s'"%(x,))
error.fail(text[begin],"Missing 'end%s'"%(x,))
def find_matching_end_subfunpro(begin,x):
for i in range(begin+1,len(text)):
@ -641,6 +641,9 @@ def check_begin_end(text):
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):
if isinstance(line,Do):
find_matching_end_ifdo(i,'do')
@ -666,8 +669,21 @@ def check_begin_end(text):
######################################################################
def remove_ifdefs(text):
# TODO
return text
assert isinstance(text,list)
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):