1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00

LibCpp: Don't fail when encountering #elif statements

However, we currently always treat the expression in #elif as true.
This commit is contained in:
Itamar 2021-02-26 21:39:47 +02:00 committed by Andreas Kling
parent e20cd1d8db
commit 85ea60b7f1

View file

@ -81,7 +81,6 @@ void Preprocessor::handle_preprocessor_line(const StringView& line)
m_state = State::Normal;
}
if (m_depths_of_taken_branches.contains_slow(m_current_depth - 1)) {
m_depths_of_taken_branches.contains_slow(m_current_depth - 1);
m_state = State::SkipElseBranch;
}
return;
@ -94,7 +93,7 @@ void Preprocessor::handle_preprocessor_line(const StringView& line)
m_depths_of_not_taken_branches.remove_all_matching([this](auto x) { return x == m_current_depth; });
}
if (m_depths_of_taken_branches.contains_slow(m_current_depth)) {
m_depths_of_taken_branches.contains_slow(m_current_depth);
m_depths_of_taken_branches.remove_all_matching([this](auto x) { return x == m_current_depth; });
}
m_state = State::Normal;
return;
@ -159,6 +158,20 @@ void Preprocessor::handle_preprocessor_line(const StringView& line)
}
return;
}
if (keyword == "elif") {
VERIFY(m_current_depth > 0);
// FIXME: Evaluate the elif expression
// We currently always treat the expression in #elif as true.
if (m_depths_of_not_taken_branches.contains_slow(m_current_depth - 1) /* && should_take*/) {
m_depths_of_not_taken_branches.remove_all_matching([this](auto x) { return x == m_current_depth - 1; });
m_state = State::Normal;
}
if (m_depths_of_taken_branches.contains_slow(m_current_depth - 1)) {
m_state = State::SkipElseBranch;
}
return;
}
if (keyword == "pragma") {
lexer.consume_all();
return;