mirror of
https://github.com/RGBCube/serenity
synced 2025-07-22 22:07:34 +00:00
LibCpp: Add option in Preprocessor to keep #include's in processed text
This commit is contained in:
parent
14e0011825
commit
0522a4360b
2 changed files with 12 additions and 1 deletions
|
@ -22,11 +22,20 @@ const String& Preprocessor::process()
|
||||||
{
|
{
|
||||||
for (; m_line_index < m_lines.size(); ++m_line_index) {
|
for (; m_line_index < m_lines.size(); ++m_line_index) {
|
||||||
auto& line = m_lines[m_line_index];
|
auto& line = m_lines[m_line_index];
|
||||||
|
|
||||||
|
bool include_in_processed_text = false;
|
||||||
if (line.starts_with("#")) {
|
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) {
|
} else if (m_state == State::Normal) {
|
||||||
|
include_in_processed_text = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (include_in_processed_text) {
|
||||||
m_builder.append(line);
|
m_builder.append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_builder.append("\n");
|
m_builder.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
const Definitions& definitions() const { return m_definitions; }
|
const Definitions& definitions() const { return m_definitions; }
|
||||||
|
|
||||||
void set_ignore_unsupported_keywords(bool ignore) { m_options.ignore_unsupported_keywords = ignore; }
|
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:
|
private:
|
||||||
using PreprocessorKeyword = StringView;
|
using PreprocessorKeyword = StringView;
|
||||||
|
@ -61,6 +62,7 @@ private:
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
bool ignore_unsupported_keywords { false };
|
bool ignore_unsupported_keywords { false };
|
||||||
|
bool keep_include_statements { false };
|
||||||
} m_options;
|
} m_options;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue