summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-05-21 15:41:38 +0300
committerAndreas Kling <kling@serenityos.org>2021-05-22 15:52:11 +0200
commit0522a4360bc7abd5a8c814db9b02d00a24a98ae6 (patch)
tree605a947f01fe159bfed6817483c311fc7d548e83 /Userland
parent14e00118251f84b469952d2b885fae9655897ccb (diff)
downloadserenity-0522a4360bc7abd5a8c814db9b02d00a24a98ae6.zip
LibCpp: Add option in Preprocessor to keep #include's in processed text
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibCpp/Preprocessor.cpp11
-rw-r--r--Userland/Libraries/LibCpp/Preprocessor.h2
2 files changed, 12 insertions, 1 deletions
diff --git a/Userland/Libraries/LibCpp/Preprocessor.cpp b/Userland/Libraries/LibCpp/Preprocessor.cpp
index c1dac5cae2..6dbb601201 100644
--- a/Userland/Libraries/LibCpp/Preprocessor.cpp
+++ b/Userland/Libraries/LibCpp/Preprocessor.cpp
@@ -22,11 +22,20 @@ const String& Preprocessor::process()
{
for (; m_line_index < m_lines.size(); ++m_line_index) {
auto& line = m_lines[m_line_index];
+
+ bool include_in_processed_text = false;
if (line.starts_with("#")) {
- handle_preprocessor_line(line);
+ auto keyword = handle_preprocessor_line(line);
+ if (m_options.keep_include_statements && keyword == "include")
+ include_in_processed_text = true;
} else if (m_state == State::Normal) {
+ include_in_processed_text = true;
+ }
+
+ if (include_in_processed_text) {
m_builder.append(line);
}
+
m_builder.append("\n");
}
diff --git a/Userland/Libraries/LibCpp/Preprocessor.h b/Userland/Libraries/LibCpp/Preprocessor.h
index 774f19730b..e62cb95027 100644
--- a/Userland/Libraries/LibCpp/Preprocessor.h
+++ b/Userland/Libraries/LibCpp/Preprocessor.h
@@ -33,6 +33,7 @@ public:
const Definitions& definitions() const { return m_definitions; }
void set_ignore_unsupported_keywords(bool ignore) { m_options.ignore_unsupported_keywords = ignore; }
+ void set_keep_include_statements(bool keep) { m_options.keep_include_statements = keep; }
private:
using PreprocessorKeyword = StringView;
@@ -61,6 +62,7 @@ private:
struct Options {
bool ignore_unsupported_keywords { false };
+ bool keep_include_statements { false };
} m_options;
};
}