|
9 | 9 |
|
10 | 10 | modified=False |
11 | 11 |
|
| 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 | + |
12 | 29 | while True: |
13 | 30 | line = f.readline() |
14 | 31 | if not line: |
15 | 32 | break; |
16 | 33 | res+=line |
17 | 34 |
|
| 35 | + if not is_in_comment_section(line): |
| 36 | + continue |
| 37 | + |
18 | 38 | #possible np name (TODO: does not work if not on the same line) |
19 | 39 | if re.search("bgl_namedparameters", line): |
20 | 40 | m = re.search("[@\\\]param\s+([^ ]+)\s", line) |
21 | 41 | if m: |
22 | 42 | np_name=m.group(1) |
23 | | - print("found "+np_name) |
| 43 | + #print("found "+np_name) |
24 | 44 |
|
25 | 45 | if re.search("cgalNamedParamsBegin", line): |
26 | 46 | params=[] |
|
30 | 50 | break |
31 | 51 | res+=line |
32 | 52 | if re.search("cgalNamedParamsEnd", line): |
| 53 | + is_in_comment_section(line) |
33 | 54 | break |
34 | 55 | m = re.search(r"cgalParamNBegin{\s*([^ ]+)\s*}", line) |
35 | 56 | if m: |
|
42 | 63 | break |
43 | 64 | res+=line |
44 | 65 | 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") |
46 | 67 | exit(1) |
| 68 | + if is_in_comment_section(line): |
| 69 | + continue |
| 70 | + |
47 | 71 | m = re.search("^(\s*).*{", line) |
48 | 72 | if m: |
49 | 73 | s=m.group(1)+" CGAL_CHECK_AUTHORIZED_NAMED_PARAMETERS("+np_name |
50 | 74 | for p in params: |
51 | 75 | s+=", "+p+"_t" |
52 | 76 | s+=");" |
53 | 77 |
|
| 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 | + |
54 | 89 | add_macro=True |
55 | 90 |
|
56 | 91 | #do nothing if the macro is already there |
|
60 | 95 | stderr.write("Error parsing the function\n") |
61 | 96 | exit(1) |
62 | 97 | 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` |
63 | 99 | add_macro=False |
64 | 100 | res+=line |
65 | 101 | break |
|
0 commit comments