diff options
Diffstat (limited to 'Userland/Libraries/LibCpp')
-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; }; } |