mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-12-22 04:13:33 +01:00
Move to top OK
Version:1.1.2
This commit is contained in:
parent
210fce7d3e
commit
599cce9d4c
@ -219,7 +219,7 @@ def form(text):
|
|||||||
if re2.match(test) is None and \
|
if re2.match(test) is None and \
|
||||||
re3.match(test) is not None:
|
re3.match(test) is not None:
|
||||||
return Free_form
|
return Free_form
|
||||||
if line.text.strip()[-1] == '&':
|
if line.text.rstrip()[-1] == '&':
|
||||||
return Free_form
|
return Free_form
|
||||||
return Fixed_form
|
return Fixed_form
|
||||||
|
|
||||||
@ -269,16 +269,20 @@ def remove_continuation(text,form):
|
|||||||
result = []
|
result = []
|
||||||
buffer = ""
|
buffer = ""
|
||||||
number = 0
|
number = 0
|
||||||
|
t = None
|
||||||
if form == Free_form:
|
if form == Free_form:
|
||||||
for line in text:
|
for line in text:
|
||||||
if line.text[-1] == '&':
|
if line.text[-1] == '&':
|
||||||
buffer = "%s%s "%(buffer,line.text[:-1].lstrip())
|
buffer = "%s%s "%(buffer,line.text[:-1].lstrip())
|
||||||
if number == 0:
|
if number == 0:
|
||||||
|
t = type(line)
|
||||||
number = line.i
|
number = line.i
|
||||||
else:
|
else:
|
||||||
if number != 0:
|
if number != 0:
|
||||||
line.text = "%s%s"%(buffer,line.text.lstrip())
|
newline = t(number, \
|
||||||
line.i = number
|
"%s%s"%(buffer,line.text.lstrip()), \
|
||||||
|
line.filename)
|
||||||
|
line = newline
|
||||||
number = 0
|
number = 0
|
||||||
buffer = ""
|
buffer = ""
|
||||||
result.append(line)
|
result.append(line)
|
||||||
@ -519,10 +523,48 @@ def change_includes(text):
|
|||||||
######################################################################
|
######################################################################
|
||||||
def process_old_style_do(text):
|
def process_old_style_do(text):
|
||||||
'''Changes old-style do loops to new style'''
|
'''Changes old-style do loops to new style'''
|
||||||
|
assert isinstance(text,list)
|
||||||
|
|
||||||
|
def change_matching_enddo(begin,number):
|
||||||
|
for i in range(begin+1,len(text)):
|
||||||
|
line = text[i]
|
||||||
|
if isinstance(line,Continue) or \
|
||||||
|
isinstance(line,Enddo):
|
||||||
|
buffer = line.text.split()
|
||||||
|
if buffer[0] == number:
|
||||||
|
text[i] = Enddo(line.i," enddo",line.filename)
|
||||||
|
return
|
||||||
|
error.fail(text[begin],"Old-style do loops should end with 'continue' or 'end do'")
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for i in range(len(text)):
|
||||||
|
line = text[i]
|
||||||
|
if isinstance(line,Do):
|
||||||
|
buffer = line.text.split()
|
||||||
|
if buffer[1].isdigit():
|
||||||
|
number = buffer.pop(1)
|
||||||
|
change_matching_enddo(i,number)
|
||||||
|
line.text = " "+" ".join(buffer)
|
||||||
|
result.append(line)
|
||||||
|
return result
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def change_single_line_ifs(text):
|
||||||
|
'''Changes:
|
||||||
|
if (test) result
|
||||||
|
|
||||||
|
to
|
||||||
|
|
||||||
|
if (test) then
|
||||||
|
result
|
||||||
|
endif'''
|
||||||
|
|
||||||
|
assert isinstance(text,list)
|
||||||
|
# TODO
|
||||||
return text
|
return text
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
def check_end(text):
|
def check_begin_end(text):
|
||||||
'''Checks x...endx consistence'''
|
'''Checks x...endx consistence'''
|
||||||
|
|
||||||
def filter_line(line):
|
def filter_line(line):
|
||||||
@ -553,7 +595,6 @@ def check_end(text):
|
|||||||
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)):
|
||||||
line = text[i]
|
line = text[i]
|
||||||
@ -589,6 +630,29 @@ def check_end(text):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def remove_ifdefs(text):
|
||||||
|
# TODO
|
||||||
|
return text
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def move_to_top(text,t):
|
||||||
|
assert isinstance(text,list)
|
||||||
|
assert t in [ Declaration, Implicit, Use ]
|
||||||
|
|
||||||
|
begin = -1
|
||||||
|
for i in range(len(text)):
|
||||||
|
line = text[i]
|
||||||
|
if isinstance(line,Begin_provider) or \
|
||||||
|
isinstance(line,Subroutine) or \
|
||||||
|
isinstance(line,Function):
|
||||||
|
begin = i
|
||||||
|
elif isinstance(line,t):
|
||||||
|
text.pop(i)
|
||||||
|
begin += 1
|
||||||
|
text.insert(begin,line)
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
def preprocessed_text(filename):
|
def preprocessed_text(filename):
|
||||||
@ -598,19 +662,25 @@ def preprocessed_text(filename):
|
|||||||
result = get_text(lines,filename)
|
result = get_text(lines,filename)
|
||||||
result = execute_shell(result)
|
result = execute_shell(result)
|
||||||
fortran_form = form(result)
|
fortran_form = form(result)
|
||||||
|
result = remove_ifdefs(result)
|
||||||
result = remove_comments(result,fortran_form)
|
result = remove_comments(result,fortran_form)
|
||||||
result = remove_continuation(result,fortran_form)
|
result = remove_continuation(result,fortran_form)
|
||||||
result = irp_simple_statements(result)
|
|
||||||
result = change_includes(result)
|
result = change_includes(result)
|
||||||
|
result = change_single_line_ifs(result)
|
||||||
result = process_old_style_do(result)
|
result = process_old_style_do(result)
|
||||||
check_end(result)
|
result = irp_simple_statements(result)
|
||||||
|
result = move_to_top(result,Declaration)
|
||||||
|
result = move_to_top(result,Implicit)
|
||||||
|
result = move_to_top(result,Use)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
txt = preprocessed_text('testfile.irp.f')
|
txt = preprocessed_text('testfile.irp.f')
|
||||||
|
check_begin_end(txt)
|
||||||
for line in txt:
|
for line in txt:
|
||||||
print line
|
print line
|
||||||
txt = preprocessed_text('testfile_fixed.irp.f')
|
txt = preprocessed_text('testfile_fixed.irp.f')
|
||||||
|
check_begin_end(txt)
|
||||||
for line in txt:
|
for line in txt:
|
||||||
print line
|
print line
|
||||||
|
|
||||||
|
@ -5,11 +5,11 @@ import re
|
|||||||
re_comment = re.compile(r"^([^'!]*)('[^']*'[^']*)*!")
|
re_comment = re.compile(r"^([^'!]*)('[^']*'[^']*)*!")
|
||||||
|
|
||||||
re_decl = re.compile( "".join( [ r"^\ *",
|
re_decl = re.compile( "".join( [ r"^\ *",
|
||||||
r"(integer *(::)?",
|
r"(integer[(::)?\* ,]+",
|
||||||
r"|double *precision *(::)?",
|
r"|double *precision[(::)?\* ,]+",
|
||||||
r"|logical *(::)?",
|
r"|logical[(::)?\* ,]+",
|
||||||
r"|character *(::)?",
|
r"|character[(::)?\* ,]+",
|
||||||
r"|real *(::)?",
|
r"|real[(::)?\* ,]+",
|
||||||
r"|dimension *(::)?",
|
r"|dimension *(::)?",
|
||||||
r"|parameter *(::)?",
|
r"|parameter *(::)?",
|
||||||
r"|data */",
|
r"|data */",
|
||||||
@ -17,7 +17,7 @@ re_decl = re.compile( "".join( [ r"^\ *",
|
|||||||
r"|common */",
|
r"|common */",
|
||||||
r"|namelist */",
|
r"|namelist */",
|
||||||
r"|save */",
|
r"|save */",
|
||||||
r"|complex *(::)?",
|
r"|complex[(::)?\* ,]+",
|
||||||
r"|intrinsic *(::)?",
|
r"|intrinsic *(::)?",
|
||||||
r"|external *(::)?",
|
r"|external *(::)?",
|
||||||
r"|equivalence *(::)?",
|
r"|equivalence *(::)?",
|
||||||
|
@ -1 +1 @@
|
|||||||
version = "1.1.1"
|
version = "1.1.2"
|
||||||
|
Loading…
Reference in New Issue
Block a user