diff options
Diffstat (limited to 'gcc/rust/ast/rust-ast.h')
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 4916e36..58bc372 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1,18 +1,31 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + #ifndef RUST_AST_BASE_H #define RUST_AST_BASE_H // Base for AST used in gccrs, basically required by all specific ast things #include "rust-system.h" - -// STL imports -#include <memory> -#include <string> -#include <vector> +#include "rust-hir-map.h" // gccrs imports // required for AST::Token #include "rust-token.h" - #include "rust-location.h" namespace Rust { @@ -253,6 +266,10 @@ public: bool is_error () const { return value_as_string == ""; } }; +/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to + * be defined */ +class AttrInputLiteral; + /* TODO: move applicable stuff into here or just don't include it because * nothing uses it A segment of a path (maybe) */ class PathSegment @@ -473,7 +490,7 @@ public: std::string as_string () const; // TODO: does this require visitor pattern as not polymorphic? - + const SimplePath &get_path () const { return path; } SimplePath &get_path () { return path; } @@ -768,10 +785,15 @@ public: virtual void mark_for_strip () = 0; virtual bool is_marked_for_strip () const = 0; + NodeId get_node_id () const { return node_id; } protected: + Stmt () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} + // Clone function implementation as pure virtual method virtual Stmt *clone_stmt_impl () const = 0; + + NodeId node_id; }; // Rust "item" AST node (declaration of top-level/module-level allowed stuff) @@ -848,10 +870,13 @@ public: virtual void mark_for_strip () = 0; virtual bool is_marked_for_strip () const = 0; + virtual NodeId get_node_id () const { return node_id; } + protected: // Constructor Expr (std::vector<Attribute> outer_attribs = std::vector<Attribute> ()) - : outer_attrs (std::move (outer_attribs)) + : outer_attrs (std::move (outer_attribs)), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // Clone function implementation as pure virtual method @@ -863,6 +888,8 @@ protected: { outer_attrs = std::move (outer_attrs_to_set); } + + NodeId node_id; }; // AST node for an expression without an accompanying block - abstract @@ -978,9 +1005,15 @@ public: * methods. */ virtual Location get_locus_slow () const = 0; + virtual NodeId get_node_id () const { return node_id; } + protected: // Clone pattern implementation as pure virtual method virtual Pattern *clone_pattern_impl () const = 0; + + Pattern () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} + + NodeId node_id; }; // forward decl for Type @@ -1015,9 +1048,15 @@ public: virtual Location get_locus_slow () const = 0; + NodeId get_node_id () const { return node_id; } + protected: + Type () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} + // Clone function implementation as pure virtual method virtual Type *clone_type_impl () const = 0; + + NodeId node_id; }; // A type without parentheses? - abstract @@ -1041,6 +1080,8 @@ protected: { return clone_type_no_bounds_impl (); } + + TypeNoBounds () : Type () {} }; /* Abstract base class representing a type param bound - Lifetime and TraitBound @@ -1494,19 +1535,22 @@ struct Crate * top-level one)? */ std::vector<std::unique_ptr<Item> > items; + NodeId node_id; + public: // Constructor Crate (std::vector<std::unique_ptr<Item> > items, std::vector<Attribute> inner_attrs, bool has_utf8bom = false, bool has_shebang = false) : has_utf8bom (has_utf8bom), has_shebang (has_shebang), - inner_attrs (std::move (inner_attrs)), items (std::move (items)) + inner_attrs (std::move (inner_attrs)), items (std::move (items)), + node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // Copy constructor with vector clone Crate (Crate const &other) : has_utf8bom (other.has_utf8bom), has_shebang (other.has_shebang), - inner_attrs (other.inner_attrs) + inner_attrs (other.inner_attrs), node_id (other.node_id) { items.reserve (other.items.size ()); for (const auto &e : other.items) @@ -1521,6 +1565,7 @@ public: inner_attrs = other.inner_attrs; has_shebang = other.has_shebang; has_utf8bom = other.has_utf8bom; + node_id = other.node_id; items.reserve (other.items.size ()); for (const auto &e : other.items) @@ -1546,6 +1591,8 @@ public: items.shrink_to_fit (); // TODO: is this the best way to do this? } + + NodeId get_node_id () const { return node_id; } }; // Base path expression AST node - abstract |