Skip to content

Commit 326b6d7

Browse files
committed
Handle #elif preprocessor instruction
1 parent 12e5d51 commit 326b6d7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

CefGlue.Interop.Gen/CefParser.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,20 @@ public void ParseFileData(string fileData, string fileName)
218218
}
219219
}
220220

221+
enum IfState
222+
{
223+
True,
224+
False,
225+
Skip
226+
}
227+
221228
private string PreprocessBody(string body)
222229
{
223230
using var reader = new StringReader(body);
224231
using var writer = new StringWriter();
225232

226233
string line;
227-
ImmutableStack<bool> ifStack = ImmutableStack<bool>.Empty;
234+
var ifStack = ImmutableStack<IfState>.Empty;
228235
bool currentState = true;
229236
while ((line = reader.ReadLine()) != null)
230237
{
@@ -233,19 +240,24 @@ private string PreprocessBody(string body)
233240
if (line.StartsWith("#"))
234241
{
235242
if (line.StartsWith("#if CEF_API_ADDED("))
236-
ifStack = ifStack.Push(true);
243+
ifStack = ifStack.Push(IfState.True);
237244
else if (line.StartsWith("#if CEF_API_REMOVED("))
238-
ifStack = ifStack.Push(false);
245+
ifStack = ifStack.Push(IfState.False);
239246
else if (line.StartsWith("#endif"))
240247
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+
}
241253
else if (line.StartsWith("#else"))
242254
{
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);
245257
}
246258
else
247259
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);
249261
continue;
250262
}
251263

0 commit comments

Comments
 (0)