From a16c35340c833ed25035c664ee33551d17309601 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Fri, 2 Sep 2022 16:08:39 -0600 Subject: expand: eager evaluate macros inside builtin macros --- gcc/rust/ast/rust-ast.h | 12 ++++++++++++ gcc/rust/ast/rust-expr.h | 2 ++ 2 files changed, 14 insertions(+) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index e9e16e7..492faea 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -31,6 +31,7 @@ namespace Rust { typedef std::string Identifier; typedef int TupleIndex; struct Session; +struct MacroExpander; namespace AST { // foward decl: ast visitor @@ -951,6 +952,8 @@ public: virtual Location get_locus () const = 0; + virtual bool is_literal () const { return false; } + // HACK: strictly not needed, but faster than full downcast clone virtual bool is_expr_without_block () const = 0; @@ -1471,6 +1474,7 @@ private: // One way of parsing the macro. Probably not applicable for all macros. std::vector > parsed_items; bool parsed_to_meta_item = false; + MacroExpander *expander = nullptr; public: std::string as_string () const; @@ -1495,6 +1499,7 @@ public: path = other.path; token_tree = other.token_tree; parsed_to_meta_item = other.parsed_to_meta_item; + expander = other.expander; parsed_items.reserve (other.parsed_items.size ()); for (const auto &e : other.parsed_items) @@ -1523,6 +1528,13 @@ public: SimplePath &get_path () { return path; } const SimplePath &get_path () const { return path; } + void set_expander (MacroExpander *new_expander) { expander = new_expander; } + MacroExpander *get_expander () + { + rust_assert (expander); + return expander; + } + void set_meta_item_output (std::vector > new_items) { diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 1966a59..c764f9c 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -67,6 +67,8 @@ public: Location get_locus () const override final { return locus; } + bool is_literal () const override final { return true; } + Literal get_literal () const { return literal; } void accept_vis (ASTVisitor &vis) override; -- cgit v1.1