aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
authorliushuyu <liushuyu011@gmail.com>2022-09-02 16:08:39 -0600
committerliushuyu <liushuyu011@gmail.com>2022-09-26 22:12:08 -0600
commita16c35340c833ed25035c664ee33551d17309601 (patch)
treedcf1829b39977c431bfd8ebd72c4e3b8b4a3697e /gcc/rust/ast
parent8ed1bbaa40527c561b25b5dadb963ca404f2da37 (diff)
downloadgcc-a16c35340c833ed25035c664ee33551d17309601.zip
gcc-a16c35340c833ed25035c664ee33551d17309601.tar.gz
gcc-a16c35340c833ed25035c664ee33551d17309601.tar.bz2
expand: eager evaluate macros inside builtin macros
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-ast.h12
-rw-r--r--gcc/rust/ast/rust-expr.h2
2 files changed, 14 insertions, 0 deletions
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<std::unique_ptr<MetaItemInner> > 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<std::unique_ptr<MetaItemInner> > 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;