@@ -218,13 +218,20 @@ public void ParseFileData(string fileData, string fileName)
218
218
}
219
219
}
220
220
221
+ enum IfState
222
+ {
223
+ True ,
224
+ False ,
225
+ Skip
226
+ }
227
+
221
228
private string PreprocessBody ( string body )
222
229
{
223
230
using var reader = new StringReader ( body ) ;
224
231
using var writer = new StringWriter ( ) ;
225
232
226
233
string line ;
227
- ImmutableStack < bool > ifStack = ImmutableStack < bool > . Empty ;
234
+ var ifStack = ImmutableStack < IfState > . Empty ;
228
235
bool currentState = true ;
229
236
while ( ( line = reader . ReadLine ( ) ) != null )
230
237
{
@@ -233,19 +240,24 @@ private string PreprocessBody(string body)
233
240
if ( line . StartsWith ( "#" ) )
234
241
{
235
242
if ( line . StartsWith ( "#if CEF_API_ADDED(" ) )
236
- ifStack = ifStack . Push ( true ) ;
243
+ ifStack = ifStack . Push ( IfState . True ) ;
237
244
else if ( line . StartsWith ( "#if CEF_API_REMOVED(" ) )
238
- ifStack = ifStack . Push ( false ) ;
245
+ ifStack = ifStack . Push ( IfState . False ) ;
239
246
else if ( line . StartsWith ( "#endif" ) )
240
247
ifStack = ifStack . Pop ( ) ;
248
+ else if ( line . StartsWith ( "#elif CEF_API_ADDED(" ) )
249
+ {
250
+ var lastValue = ifStack . Peek ( ) ;
251
+ ifStack = ifStack . Pop ( ) . Push ( lastValue == IfState . False ? IfState . True : IfState . Skip ) ;
252
+ }
241
253
else if ( line . StartsWith ( "#else" ) )
242
254
{
243
- bool lastValue = ifStack . Peek ( ) ;
244
- ifStack = ifStack . Pop ( ) . Push ( ! lastValue ) ;
255
+ var lastValue = ifStack . Peek ( ) ;
256
+ ifStack = ifStack . Pop ( ) . Push ( lastValue != IfState . False ? IfState . Skip : IfState . True ) ;
245
257
}
246
258
else
247
259
throw new FormatException ( $ "Unsupported preprocessor macro ({ line } )") ;
248
- currentState = ifStack . IsEmpty || ifStack . All ( a => a ) ;
260
+ currentState = ifStack . IsEmpty || ifStack . All ( a => a == IfState . True ) ;
249
261
continue ;
250
262
}
251
263
0 commit comments