diff options
author | SimplyTheOther <simplytheother@gmail.com> | 2020-12-25 17:16:25 +0800 |
---|---|---|
committer | SimplyTheOther <simplytheother@gmail.com> | 2020-12-25 17:16:25 +0800 |
commit | 859720937474816d4d386664d56d80a9e840f06f (patch) | |
tree | c24398609b8fe7777b15ab83d0775013dfb5b322 /gcc/rust/ast/rust-macro.h | |
parent | 7299d6d84ac4a1e8118915b00d361e7251e32b65 (diff) | |
download | gcc-859720937474816d4d386664d56d80a9e840f06f.zip gcc-859720937474816d4d386664d56d80a9e840f06f.tar.gz gcc-859720937474816d4d386664d56d80a9e840f06f.tar.bz2 |
Rewrote SingleASTNode representation
Diffstat (limited to 'gcc/rust/ast/rust-macro.h')
-rw-r--r-- | gcc/rust/ast/rust-macro.h | 49 |
1 files changed, 36 insertions, 13 deletions
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> expr; - std::unique_ptr<Stmt> stmt; - std::unique_ptr<Item> item; - std::unique_ptr<Type> type; - std::unique_ptr<Pattern> pattern; - std::unique_ptr<TraitItem> trait_item; - std::unique_ptr<InherentImplItem> inherent_impl_item; - std::unique_ptr<TraitImplItem> trait_impl_item; - std::unique_ptr<ExternalItem> 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> expr; + std::unique_ptr<Stmt> stmt; + std::unique_ptr<Item> item; + std::unique_ptr<Type> type; + std::unique_ptr<Pattern> pattern; + std::unique_ptr<TraitItem> trait_item; + std::unique_ptr<InherentImplItem> inherent_impl_item; + std::unique_ptr<TraitImplItem> trait_impl_item; + std::unique_ptr<ExternalItem> external_item; + }; +}; +*/ +struct SingleASTNode { + std::unique_ptr<Expr> expr; + std::unique_ptr<Stmt> stmt; + std::unique_ptr<Item> item; + std::unique_ptr<Type> type; + std::unique_ptr<Pattern> pattern; + std::unique_ptr<TraitItem> trait_item; + std::unique_ptr<InherentImplItem> inherent_impl_item; + std::unique_ptr<TraitImplItem> trait_impl_item; + std::unique_ptr<ExternalItem> external_item; + + SingleASTNode (std::unique_ptr<Expr> expr) : expr (std::move (expr)) {} + SingleASTNode (std::unique_ptr<Stmt> stmt) : stmt (std::move (stmt)) {} + SingleASTNode (std::unique_ptr<Item> item) : item (std::move (item)) {} + SingleASTNode (std::unique_ptr<Type> type) : type (std::move (type)) {} + SingleASTNode (std::unique_ptr<Pattern> pattern) : pattern (std::move (pattern)) {} + SingleASTNode (std::unique_ptr<TraitItem> trait_item) : trait_item (std::move (trait_item)) {} + SingleASTNode (std::unique_ptr<InherentImplItem> inherent_impl_item) : inherent_impl_item (std::move (inherent_impl_item)) {} + SingleASTNode (std::unique_ptr<TraitImplItem> trait_impl_item) : trait_impl_item (std::move (trait_impl_item)) {} + SingleASTNode (std::unique_ptr<ExternalItem> external_item) : external_item (std::move (external_item)) {} }; /* Basically, a "fragment" that can be incorporated into the AST, created as |