Skip to content

Commit 28d11fc

Browse files
committed
handle some particular cases
1 parent d8be4cb commit 28d11fc

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

Scripts/developer_scripts/add_checks_for_named_parameters.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,38 @@
99

1010
modified=False
1111

12+
13+
def is_in_comment_section(line):
14+
global in_comment_section
15+
16+
if re.search("^\s*"+re.escape("//"), line):
17+
return True
18+
if re.search("^\s*"+re.escape("/*"), line):
19+
in_comment_section=True
20+
return True
21+
if not in_comment_section:
22+
return False
23+
if re.search(re.escape("*/"), line):
24+
in_comment_section=False;
25+
return True
26+
27+
in_comment_section = False
28+
1229
while True:
1330
line = f.readline()
1431
if not line:
1532
break;
1633
res+=line
1734

35+
if not is_in_comment_section(line):
36+
continue
37+
1838
#possible np name (TODO: does not work if not on the same line)
1939
if re.search("bgl_namedparameters", line):
2040
m = re.search("[@\\\]param\s+([^ ]+)\s", line)
2141
if m:
2242
np_name=m.group(1)
23-
print("found "+np_name)
43+
#print("found "+np_name)
2444

2545
if re.search("cgalNamedParamsBegin", line):
2646
params=[]
@@ -30,6 +50,7 @@
3050
break
3151
res+=line
3252
if re.search("cgalNamedParamsEnd", line):
53+
is_in_comment_section(line)
3354
break
3455
m = re.search(r"cgalParamNBegin{\s*([^ ]+)\s*}", line)
3556
if m:
@@ -42,15 +63,29 @@
4263
break
4364
res+=line
4465
if re.search("cgalNamedParamsBegin", line):
45-
stderr.write("Function with several nps! Not handled yet\n")
66+
stderr.write("Function with several nps! Not handled yet ("+argv[1]+")\n")
4667
exit(1)
68+
if is_in_comment_section(line):
69+
continue
70+
4771
m = re.search("^(\s*).*{", line)
4872
if m:
4973
s=m.group(1)+" CGAL_CHECK_AUTHORIZED_NAMED_PARAMETERS("+np_name
5074
for p in params:
5175
s+=", "+p+"_t"
5276
s+=");"
5377

78+
mb = re.search("(^\s+{)(.*)}$", line)
79+
if mb:
80+
res+=mb.group(1)+"\n";
81+
res+=s+"\n"
82+
if mb.group(2).strip():
83+
res+=m.group(1)+" "+mb.group(2)+"\n"
84+
res+=m.group(1)+"}\n"
85+
modified=True
86+
break
87+
88+
5489
add_macro=True
5590

5691
#do nothing if the macro is already there
@@ -60,6 +95,7 @@
6095
stderr.write("Error parsing the function\n")
6196
exit(1)
6297
if re.search("CGAL_CHECK_AUTHORIZED_NAMED_PARAMETERS", line):
98+
#TODO: in check mode, we should check that there is a match between code and `params`
6399
add_macro=False
64100
res+=line
65101
break

0 commit comments

Comments
 (0)