Skip to content

Commit fb757ab

Browse files
authored
Adjust style (#51)
2 parents 1648f2d + 508eea2 commit fb757ab

18 files changed

+45229
-45146
lines changed

scripts/modularize_blas.py

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,6 @@ def find_parameter_declaration(line,datatype):
10561056
# Remove header and spaces
10571057
if old_style:
10581058
nospace = re.sub('\s','',ll)
1059-
print(nospace)
10601059
nospace = nospace[10:len(nospace)-1]
10611060
datatype = " "
10621061

@@ -1664,6 +1663,49 @@ def declaration(self,strip_prefix,keep_classifiers):
16641663

16651664
return head,var_decl
16661665

1666+
# Cleanup a function's header and comment section
1667+
def cleanup_comments(self):
1668+
1669+
# Header description
1670+
new_header = []
1671+
started = False
1672+
colonized = False
1673+
for h in range(len(self.header)):
1674+
l = self.header[h].rstrip()
1675+
ls = l.lstrip()
1676+
nspaces = len(l) - len(ls)
1677+
1678+
# Skip empty comment lines before start
1679+
if (not started) and (ls=='!' or ls==""):
1680+
continue
1681+
else:
1682+
started = True
1683+
1684+
# If the function name is contained, follow a colon
1685+
if self.old_name.upper() in ls and not colonized:
1686+
ls = re.sub(r'\b'+self.old_name.upper()+r'\b',self.old_name.upper()+":",ls)
1687+
colonized = True
1688+
1689+
# FORD-style comment
1690+
new_header.append(nspaces*" "+"!>"+ls[1:])
1691+
1692+
self.header = new_header
1693+
1694+
# Cleanup a function's LAPACK-style .. comments ..
1695+
def cleanup_double_dots(body):
1696+
1697+
# Comments: remove double-dot style
1698+
new_body = []
1699+
for b in range(len(body)):
1700+
new = re.sub(r'^(\s*\!\s*)\.{2}\s*([ \w]*)\s*\.{0,2}\s*$',r'\1\2',body[b])
1701+
if len(new)<len(body[b]) and len(new)>0:
1702+
new_body.append(new.title())
1703+
else:
1704+
new_body.append(new)
1705+
1706+
return new_body
1707+
1708+
16671709
class Fortran_Line:
16681710
def __init__(self):
16691711
self.string = ""
@@ -2312,6 +2354,10 @@ def rename_source_body(Source,Sources,external_funs,prefix):
23122354
for j in range(len(body)):
23132355
body[j] = re.sub(r' lsame\(',r' stdlib_lsame(',body[j])
23142356

2357+
# Finally, adjust comment style
2358+
body = cleanup_double_dots(body)
2359+
2360+
23152361
return body,dependency_list
23162362

23172363
# Replace data statements with variable assignments.
@@ -2404,8 +2450,6 @@ def replace_data_statements(Source,prefix,body):
24042450
m = re.match(r'data\(mm\((\d+),j\),j=(\d+),(\d+)\)/(.+)/',nosp)
24052451

24062452
if (not m is None):
2407-
print(m.group(1))
2408-
print(m.group(4))
24092453
line = nspaces*" "+"mm("+m.group(1)+","+m.group(2)+":"+m.group(3)+")=["+m.group(4)+"]"
24102454
new_body.append(line)
24112455

@@ -2639,7 +2683,7 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
26392683
initial = 'a'
26402684

26412685
INDENT = " "
2642-
DEBUG = False # file_name.startswith("sisnan")
2686+
DEBUG = False #file_name.startswith("caxpy")
26432687

26442688
Procedures = []
26452689

@@ -2657,6 +2701,7 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
26572701
loop_lines = [] # Starting line where the loop is opened
26582702
loop_spaces = [] # Heading spaces of an open loop label
26592703
loop_statements = [] # Other statements for this loop were found
2704+
header_spaces = 0
26602705

26612706
# FiLoad whole file; split by lines; join concatenation lines
26622707
with open(os.path.join(source_folder,file_name), 'r') as file:
@@ -2762,7 +2807,15 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
27622807
line = re.sub(r'\!\>',"",line)
27632808
line = re.sub(r'\\verbatim',"",line)
27642809
line = re.sub(r'=============',"",line)
2765-
if len(line)>0: Source.header.append("! " + line.strip())
2810+
2811+
# Ensure (constant) number of line spaces
2812+
if len(line)>0:
2813+
2814+
ls = line.lstrip()
2815+
if header_spaces==0: header_spaces = len(line)-len(ls)
2816+
Source.header.append("! " + ls.rstrip())
2817+
2818+
27662819
if DEBUG: print(Source.header[-1])
27672820

27682821

@@ -2999,12 +3052,14 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
29993052
else:
30003053
if DEBUG: print("NOT printed: " + line + " " + str(whereAt))
30013054

3002-
# On function end
3055+
# On function end, do some cleanup
30033056
if whereAt==Section.END:
30043057

30053058
# Data statements
30063059
Source.body = replace_data_statements(Source,prefix,Source.body)
30073060

3061+
# Header
3062+
Source.cleanup_comments()
30083063
if DEBUG: print("function "+Source.old_name+" is pure: "+str(Source.is_pure()))
30093064

30103065
# Save source
@@ -3018,6 +3073,7 @@ def parse_fortran_source(source_folder,file_name,prefix,remove_headers):
30183073
loop_lines = []
30193074
loop_spaces = []
30203075
loop_statements = []
3076+
header_spaces = 0
30213077

30223078

30233079

scripts/run_fprettify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
python3 modularize_blas.py
55

66
# prettify
7-
#fprettify -i 4 -l 132 -w 2 --disable-indent --strip-comments --c-relations --enable-replacements --enable-decl --whitespace-comma 0 --recursive ../src/
7+
fprettify -i 4 -l 132 -w 2 --disable-indent --strip-comments --c-relations --enable-replacements --enable-decl --whitespace-comma 0 --recursive ../src/

0 commit comments

Comments
 (0)