summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibCpp/Preprocessor.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/Userland/Libraries/LibCpp/Preprocessor.cpp b/Userland/Libraries/LibCpp/Preprocessor.cpp
index 3094d2b97c..99bef96ea3 100644
--- a/Userland/Libraries/LibCpp/Preprocessor.cpp
+++ b/Userland/Libraries/LibCpp/Preprocessor.cpp
@@ -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;