summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCpp
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-02-26 21:39:47 +0200
committerAndreas Kling <kling@serenityos.org>2021-02-26 21:14:41 +0100
commit85ea60b7f1121a95ffc2429d367ec211692cef16 (patch)
tree54a52f86f1c1ab4ffa375e68ad00036d23aa5dc5 /Userland/Libraries/LibCpp
parente20cd1d8dbfd594774cdf5cba23965e5d884e3f3 (diff)
downloadserenity-85ea60b7f1121a95ffc2429d367ec211692cef16.zip
LibCpp: Don't fail when encountering #elif statements
However, we currently always treat the expression in #elif as true.
Diffstat (limited to 'Userland/Libraries/LibCpp')
-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;