From 859720937474816d4d386664d56d80a9e840f06f Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Fri, 25 Dec 2020 17:16:25 +0800 Subject: Rewrote SingleASTNode representation --- gcc/rust/ast/rust-macro.h | 49 +++++++++++++++++++++++++++---------- gcc/rust/expand/rust-macro-expand.h | 1 + 2 files changed, 37 insertions(+), 13 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index eeb8ecf..5f05985 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -591,22 +591,11 @@ protected: }; /* A "tagged union" describing a single AST node. Due to technical difficulties - * with unions, had to use raw pointers. */ + * with unions, this is actually a struct and so wastes space. FIXME */ +/* struct SingleASTNode { public: - union { - std::unique_ptr expr; - std::unique_ptr stmt; - std::unique_ptr item; - std::unique_ptr type; - std::unique_ptr pattern; - std::unique_ptr trait_item; - std::unique_ptr inherent_impl_item; - std::unique_ptr trait_impl_item; - std::unique_ptr external_item; - }; - enum tag_types { EXPR, STMT, @@ -656,6 +645,7 @@ struct SingleASTNode } + // destructor definition is required ~SingleASTNode () { switch (tag) { case EXPR: @@ -695,6 +685,39 @@ struct SingleASTNode private: tag_types tag; + union { + std::unique_ptr expr; + std::unique_ptr stmt; + std::unique_ptr item; + std::unique_ptr type; + std::unique_ptr pattern; + std::unique_ptr trait_item; + std::unique_ptr inherent_impl_item; + std::unique_ptr trait_impl_item; + std::unique_ptr external_item; + }; +}; +*/ +struct SingleASTNode { + std::unique_ptr expr; + std::unique_ptr stmt; + std::unique_ptr item; + std::unique_ptr type; + std::unique_ptr pattern; + std::unique_ptr trait_item; + std::unique_ptr inherent_impl_item; + std::unique_ptr trait_impl_item; + std::unique_ptr external_item; + + SingleASTNode (std::unique_ptr expr) : expr (std::move (expr)) {} + SingleASTNode (std::unique_ptr stmt) : stmt (std::move (stmt)) {} + SingleASTNode (std::unique_ptr item) : item (std::move (item)) {} + SingleASTNode (std::unique_ptr type) : type (std::move (type)) {} + SingleASTNode (std::unique_ptr pattern) : pattern (std::move (pattern)) {} + SingleASTNode (std::unique_ptr trait_item) : trait_item (std::move (trait_item)) {} + SingleASTNode (std::unique_ptr inherent_impl_item) : inherent_impl_item (std::move (inherent_impl_item)) {} + SingleASTNode (std::unique_ptr trait_impl_item) : trait_impl_item (std::move (trait_impl_item)) {} + SingleASTNode (std::unique_ptr external_item) : external_item (std::move (external_item)) {} }; /* Basically, a "fragment" that can be incorporated into the AST, created as diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index 66e506d..17adf0e 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -2,6 +2,7 @@ #define RUST_MACRO_EXPAND_H #include "rust-ast.h" +#include "rust-macro.h" // Provides objects and method prototypes for macro expansion -- cgit v1.1