diff options
author | Itamar <itamar8910@gmail.com> | 2021-05-21 15:41:38 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-22 15:52:11 +0200 |
commit | 0522a4360bc7abd5a8c814db9b02d00a24a98ae6 (patch) | |
tree | 605a947f01fe159bfed6817483c311fc7d548e83 /Userland | |
parent | 14e00118251f84b469952d2b885fae9655897ccb (diff) | |
download | serenity-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.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/Preprocessor.h | 2 |
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; }; } |