mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibCpp: Do macro substitution in the preprocessor instead of the parser
After this change, the parser is completely separated from preprocessor concepts.
This commit is contained in:
parent
0c4dc00f01
commit
9da9398bf0
5 changed files with 55 additions and 65 deletions
|
@ -25,14 +25,20 @@ public:
|
|||
Vector<StringView> included_paths() const { return m_included_paths; }
|
||||
|
||||
struct DefinedValue {
|
||||
Optional<StringView> value;
|
||||
String value;
|
||||
FlyString filename;
|
||||
size_t line { 0 };
|
||||
size_t column { 0 };
|
||||
};
|
||||
using Definitions = HashMap<StringView, DefinedValue>;
|
||||
|
||||
const Definitions& definitions() const { return m_definitions; }
|
||||
struct Substitution {
|
||||
Token original_token;
|
||||
DefinedValue defined_value;
|
||||
};
|
||||
|
||||
Definitions const& definitions() const { return m_definitions; }
|
||||
Vector<Substitution> const& substitutions() const { return m_substitutions; }
|
||||
|
||||
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; }
|
||||
|
@ -43,12 +49,17 @@ private:
|
|||
using PreprocessorKeyword = StringView;
|
||||
PreprocessorKeyword handle_preprocessor_line(StringView const&);
|
||||
void handle_preprocessor_keyword(StringView const& keyword, GenericLexer& line_lexer);
|
||||
Vector<Token> process_line(StringView const& line);
|
||||
void process_line(StringView const& line);
|
||||
void do_substitution(Token const& replaced_token, DefinedValue const&);
|
||||
|
||||
String m_filename;
|
||||
String m_program;
|
||||
Definitions m_definitions;
|
||||
Vector<StringView> m_lines;
|
||||
|
||||
Vector<Token> m_tokens;
|
||||
Definitions m_definitions;
|
||||
Vector<Substitution> m_substitutions;
|
||||
|
||||
size_t m_line_index { 0 };
|
||||
size_t m_current_depth { 0 };
|
||||
Vector<size_t> m_depths_of_taken_branches;
|
||||
|
@ -62,7 +73,6 @@ private:
|
|||
State m_state { State::Normal };
|
||||
|
||||
Vector<StringView> m_included_paths;
|
||||
String m_processed_text;
|
||||
|
||||
struct Options {
|
||||
bool ignore_unsupported_keywords { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue