Skip to content

Commit aeda502

Browse files
committed
Summary: hide -Wswitch-enum in yydestruct
1 parent d4fdeb0 commit aeda502

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

scripts/fix-bison.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def fix(file):
2828
with open(backup, "r") as infile, open(file, "w") as outfile:
2929
seen_yyerrlab1 = False
3030
syntax_error_has_default = False
31+
in_yydestruct_function = False
32+
in_yydestruct_switch = False
3133
line_offset = 1
3234

3335
# Read entire source lines
@@ -110,6 +112,36 @@ def fix(file):
110112

111113
# Remove all mention of unused var yynerrs
112114
line = re.sub(r"^(\s*)(.*yynerrs.*)", r"\1/* \2 */", line)
115+
116+
# Track when we enter yydestruct function
117+
if "yydestruct (const char *yymsg," in line:
118+
in_yydestruct_function = True
119+
120+
# Track when we exit yydestruct function (closing brace after YY_IGNORE_MAYBE_UNINITIALIZED_END)
121+
if (
122+
in_yydestruct_function
123+
and line.strip() == "}"
124+
and not in_yydestruct_switch
125+
):
126+
in_yydestruct_function = False
127+
128+
# Add pragma to disable -Wswitch-enum warning around switch in yydestruct function
129+
if in_yydestruct_function and "switch (yykind)" in line:
130+
in_yydestruct_switch = True
131+
outfile.write("#pragma GCC diagnostic push\n")
132+
outfile.write('#pragma GCC diagnostic ignored "-Wswitch-enum"\n')
133+
line_offset += 2 # added 2 lines
134+
outfile.write(line)
135+
continue
136+
137+
# Close pragma after switch statement in yydestruct
138+
if in_yydestruct_switch and "YY_IGNORE_MAYBE_UNINITIALIZED_END" in line:
139+
in_yydestruct_switch = False
140+
outfile.write(line)
141+
outfile.write("#pragma GCC diagnostic pop\n")
142+
line_offset += 1 # added 1 line
143+
continue
144+
113145
outfile.write(line)
114146

115147

0 commit comments

Comments
 (0)