@@ -2090,6 +2090,7 @@ def replace_vars(line: str):
2090
2090
pp_skips = []
2091
2091
pp_defines = []
2092
2092
pp_stack = []
2093
+ pp_stack_group = []
2093
2094
defs_tmp = pp_defs .copy ()
2094
2095
def_regexes = {}
2095
2096
output_file = []
@@ -2135,28 +2136,49 @@ def replace_vars(line: str):
2135
2136
# Closing/middle conditional statements
2136
2137
inc_start = False
2137
2138
exc_start = False
2139
+ exc_continue = False
2138
2140
if match .group (1 ) == "elif" :
2139
- if pp_stack [- 1 ][0 ] < 0 :
2140
- pp_stack [- 1 ][0 ] = i + 1
2141
- exc_start = True
2141
+ if (not pp_stack_group ) or (pp_stack_group [- 1 ][0 ] != len (pp_stack )):
2142
+ # First elif statement for this elif group
2143
+ if pp_stack [- 1 ][0 ] < 0 :
2144
+ pp_stack_group .append ([len (pp_stack ), True ])
2145
+ else :
2146
+ pp_stack_group .append ([len (pp_stack ), False ])
2147
+ if pp_stack_group [- 1 ][1 ]:
2148
+ # An earlier if or elif in this group has been true
2149
+ exc_continue = True
2150
+ if pp_stack [- 1 ][0 ] < 0 :
2151
+ pp_stack [- 1 ][0 ] = i + 1
2152
+ elif eval_pp_if (line [match .end (1 ) :], defs_tmp ):
2153
+ pp_stack [- 1 ][1 ] = i + 1
2154
+ pp_skips .append (pp_stack .pop ())
2155
+ pp_stack_group [- 1 ][1 ] = True
2156
+ pp_stack .append ([- 1 , - 1 ])
2157
+ inc_start = True
2142
2158
else :
2143
- if eval_pp_if (line [match .end (1 ) :], defs_tmp ):
2144
- pp_stack [- 1 ][1 ] = i + 1
2145
- pp_skips .append (pp_stack .pop ())
2146
- pp_stack .append ([- 1 , - 1 ])
2147
- inc_start = True
2159
+ exc_start = True
2148
2160
elif match .group (1 ) == "else" :
2149
2161
if pp_stack [- 1 ][0 ] < 0 :
2150
2162
pp_stack [- 1 ][0 ] = i + 1
2151
2163
exc_start = True
2164
+ elif (
2165
+ pp_stack_group
2166
+ and (pp_stack_group [- 1 ][0 ] == len (pp_stack ))
2167
+ and (pp_stack_group [- 1 ][1 ])
2168
+ ):
2169
+ # An earlier if or elif in this group has been true
2170
+ exc_continue = True
2152
2171
else :
2153
2172
pp_stack [- 1 ][1 ] = i + 1
2154
2173
pp_skips .append (pp_stack .pop ())
2155
2174
pp_stack .append ([- 1 , - 1 ])
2156
2175
inc_start = True
2157
2176
elif match .group (1 ) == "endif" :
2177
+ if pp_stack_group and (pp_stack_group [- 1 ][0 ] == len (pp_stack )):
2178
+ pp_stack_group .pop ()
2158
2179
if pp_stack [- 1 ][0 ] < 0 :
2159
2180
pp_stack .pop ()
2181
+ log .debug (f"{ line .strip ()} !!! Conditional TRUE/END({ i + 1 } )" )
2160
2182
continue
2161
2183
if pp_stack [- 1 ][1 ] < 0 :
2162
2184
pp_stack [- 1 ][1 ] = i + 1
@@ -2167,6 +2189,8 @@ def replace_vars(line: str):
2167
2189
log .debug (f"{ line .strip ()} !!! Conditional TRUE({ i + 1 } )" )
2168
2190
elif exc_start :
2169
2191
log .debug (f"{ line .strip ()} !!! Conditional FALSE({ i + 1 } )" )
2192
+ elif exc_continue :
2193
+ log .debug (f"{ line .strip ()} !!! Conditional EXCLUDED({ i + 1 } )" )
2170
2194
continue
2171
2195
# Handle variable/macro definitions files
2172
2196
match = FRegex .PP_DEF .match (line )
0 commit comments