Skip to content

Commit b018f12

Browse files
committed
align labelled continue statements: run
1 parent fb757ab commit b018f12

11 files changed

+9498
-9419
lines changed

scripts/align_labelled_continue.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Revert the ugly labelled continue statements created by fprettify
2+
3+
def revert_fprettify_labels(source_folder,file_name):
4+
5+
import re
6+
import os
7+
8+
# Load whole file; split by lines
9+
with open(os.path.join(source_folder,file_name), 'r') as file:
10+
# Create an empty list to store the lines
11+
file_body = []
12+
13+
# Iterate over the lines of the file
14+
for line in file:
15+
file_body.append(line.rstrip())
16+
17+
18+
file.close()
19+
20+
for i in range(len(file_body)):
21+
if 'continue' in file_body[i]:
22+
old = file_body[i]
23+
nspaces = len(file_body[i-1])-len(file_body[i-1].lstrip())
24+
file_body[i] = re.sub(r'(\s*)([0-9]+)(\s*)(continue)(\s*)'," "*nspaces+r'\2 \4',old)
25+
26+
# Write out
27+
fid = open(os.path.join(source_folder,file_name), 'w')
28+
for i in range(len(file_body)):
29+
fid.write("{}\n".format(file_body[i]))
30+
fid.close()
31+
32+
33+
# Launch script
34+
revert_fprettify_labels("../src","stdlib_linalg_lapack_s.f90")
35+
revert_fprettify_labels("../src","stdlib_linalg_lapack_d.f90")
36+
revert_fprettify_labels("../src","stdlib_linalg_lapack_q.f90")
37+
revert_fprettify_labels("../src","stdlib_linalg_lapack_c.f90")
38+
revert_fprettify_labels("../src","stdlib_linalg_lapack_z.f90")
39+
revert_fprettify_labels("../src","stdlib_linalg_lapack_w.f90")
40+
41+
42+
43+

scripts/modularize_blas.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,12 @@ def double_to_quad(lines,initial,newinit,prefix,procedure_name=None):
436436
initial = sing_prefixes[i]
437437
newinit = dble_prefixes[i]
438438
whole = re.sub(prefix[:-1]+r'\_'+initial,prefix+newinit,whole)
439-
# whole = re.sub(r'\_'+initial,r'_'+newinit,whole)
440-
441-
if initial=='s':
442-
whole = re.sub(prefix[:-1]+r'\_delctg',prefix+r'selctg',whole)
443-
whole = re.sub(prefix[:-1]+r'\_delect',prefix+r'select',whole)
444439

440+
whole = re.sub(prefix[:-1]+r'\_delctg',prefix+r'selctg',whole)
441+
whole = re.sub(prefix[:-1]+r'\_delect',prefix+r'select',whole)
442+
whole = re.sub(prefix[:-1]+r'\_dlag2d',prefix+r'dlag2q',whole)
443+
whole = re.sub(prefix[:-1]+r'\_zlag2z',prefix+r'zlag2w',whole)
444+
whole = re.sub(prefix[:-1]+r'\_zlag2w',prefix+r'clag2z',whole)
445445

446446
whole = re.sub(r'32\-bit',r'64-bit',whole)
447447
whole = re.sub(r'single precision',r'double precision',whole)
@@ -1147,6 +1147,7 @@ def write_function_body(fid,body,INDENT,MAX_LINE_LENGTH,adjust_comments):
11471147
fid.write("\n")
11481148

11491149
header = True
1150+
previous = []
11501151

11511152
for i in range(len(body)):
11521153
line = body[i]
@@ -1192,6 +1193,8 @@ def write_function_body(fid,body,INDENT,MAX_LINE_LENGTH,adjust_comments):
11921193
if not is_comment_line:
11931194
line = re.sub(r"([\"'])((?=(\\?))\3.)*?\1", upper_repl, line)
11941195

1196+
line = align_labelled_continue(line,previous)
1197+
11951198
if is_directive:
11961199
fid.write(line+"\n")
11971200
elif bool(re.match(r'^\s*!\s*$',line)):
@@ -1200,6 +1203,9 @@ def write_function_body(fid,body,INDENT,MAX_LINE_LENGTH,adjust_comments):
12001203
else:
12011204
write_with_continuation(line,fid,INDENT,MAX_LINE_LENGTH)
12021205

1206+
# Save for the next one
1207+
previous = line
1208+
12031209

12041210

12051211
# Write with continuation
@@ -1472,20 +1478,35 @@ def to_quad_precision(self):
14721478
print("function "+self.old_name+" cannot be converted to quadruple precision: it must be double")
14731479
exit(1)
14741480

1475-
q.old_name = newi + self.old_name[len(initial):]
14761481

14771482
# Extract prefix
14781483
i = self.new_name.index(self.old_name)
1479-
prefix = self.new_name[:i]
1484+
prefix = self.new_name[:i]
1485+
1486+
1487+
# Patch for names that change more than just the initial
1488+
if self.old_name=='slag2d':
1489+
q.old_name = 'dlag2q'
1490+
else:
1491+
q.old_name = newi + self.old_name[len(initial):]
14801492
q.new_name = prefix + q.old_name
14811493

1482-
#print("double->quad "+q.old_name+" "+q.new_name)
1494+
print("double->quad "+q.old_name+" "+q.new_name)
14831495

14841496
# Body, header
14851497
q.header = double_to_quad(q.header,initial,newi,prefix,[self.old_name,q.old_name])
14861498
q.body = double_to_quad(q.body,initial,newi,prefix)
14871499
q.decl = double_to_quad(q.decl,initial,newi,prefix)
14881500

1501+
if (self.old_name=='slag2d'):
1502+
print("self old "+self.old_name)
1503+
print("q old"+q.old_name)
1504+
print("self new "+self.new_name)
1505+
print("q new"+q.new_name)
1506+
print("self line 1 "+self.body[0])
1507+
print("q line 1 "+q.body[0])
1508+
#exit(1)
1509+
14891510
# Parameters: we only rename type and value
14901511
q.ptype = double_to_quad(q.ptype,initial,newi,prefix)
14911512
q.pvalue = double_to_quad(q.pvalue,initial,newi,prefix)
@@ -1540,6 +1561,10 @@ def is_pure(self):
15401561

15411562
DEBUG = False # self.old_name=='sisnan'
15421563

1564+
# Patch
1565+
if self.old_name=='dnrm2' or self.old_name=='znrm2' or self.old_name=='qznrm2' \
1566+
or self.old_name=='qnrm2': return True
1567+
15431568
io = 'stop' in self.body or \
15441569
'write' in self.body or \
15451570
self.save_stmt;
@@ -2174,6 +2199,10 @@ def align_labelled_continue(line,previous=None):
21742199

21752200
nspaces = len(previous)-len(previous.lstrip())
21762201

2202+
print("CONTINUE: # spaces = "+str(nspaces))
2203+
print("CONTINUE: prev line = "+previous)
2204+
print("CONTINUE: = "+" "*nspaces + label + " continue")
2205+
21772206
return " "*nspaces + label + " continue"
21782207

21792208
# Given the list of all variables, extract those that are module constants

scripts/run_fprettify.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ python3 modularize_blas.py
55

66
# prettify
77
fprettify -i 4 -l 132 -w 2 --disable-indent --strip-comments --c-relations --enable-replacements --enable-decl --whitespace-comma 0 --recursive ../src/
8+
9+
# Revert ugly changes at labelled continue statements
10+
python3 align_labelled_continue.py

src/stdlib_linalg_blas_d.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,8 @@ end subroutine stdlib_dger
840840
!> name, so that
841841
!> DNRM2 := sqrt( x'*x )
842842

843-
pure real(dp) function stdlib_dnrm2(n,x,incx)
843+
pure function stdlib_dnrm2(n,x,incx)
844+
real(dp) :: stdlib_dnrm2
844845
! -- reference blas level1 routine (version 3.9.1_dp) --
845846
! -- reference blas is a software package provided by univ. of tennessee, --
846847
! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--

src/stdlib_linalg_blas_q.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ end subroutine stdlib_qger
842842
!> name, so that
843843
!> DNRM2 := sqrt( x'*x )
844844

845-
pure real(qp) function stdlib_qnrm2(n,x,incx)
845+
pure function stdlib_qnrm2(n,x,incx)
846+
real(qp) :: stdlib_qnrm2
846847
! -- reference blas level1 routine (version 3.9.1_qp) --
847848
! -- reference blas is a software package provided by univ. of tennessee, --
848849
! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
@@ -4414,6 +4415,8 @@ pure real(qp) function stdlib_qzasum(n,zx,incx)
44144415
return
44154416
end function stdlib_qzasum
44164417

4418+
!> !
4419+
!>
44174420
!> DZNRM2: returns the euclidean norm of a vector via the function
44184421
!> name, so that
44194422
!> DZNRM2 := sqrt( x**H*x )

0 commit comments

Comments
 (0)