aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-06-05 16:40:06 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-06-05 16:40:06 +0100
commit1b3d621f215c8dfe39f43b0c25f72a29aea89908 (patch)
tree0d17f286e5bd74e3cfd4f9433b057c8de9b61c23
parent1c0d6ea02a74761a1756b65aaa3028054e9be680 (diff)
downloadgcc-1b3d621f215c8dfe39f43b0c25f72a29aea89908.zip
gcc-1b3d621f215c8dfe39f43b0c25f72a29aea89908.tar.gz
gcc-1b3d621f215c8dfe39f43b0c25f72a29aea89908.tar.bz2
Add NodeMappings to HIR::Trait Items
NodeMappings are used to map HIR items into the type system and back to NodeIds as part of name Resolution. LocalDefId signify local crate defintions and DefId are cratenum + localdefids for cross crate definitions. Addresses: #395
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h53
-rw-r--r--gcc/rust/hir/tree/rust-hir.h19
2 files changed, 38 insertions, 34 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 6ac936c..fa097e4 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -2485,15 +2485,18 @@ public:
// Returns whether function has a definition or is just a declaration.
bool has_definition () const { return block_expr != nullptr; }
- TraitItemFunc (TraitFunctionDecl decl, std::unique_ptr<BlockExpr> block_expr,
+ TraitItemFunc (Analysis::NodeMapping mappings, TraitFunctionDecl decl,
+ std::unique_ptr<BlockExpr> block_expr,
AST::AttrVec outer_attrs, Location locus)
- : outer_attrs (std::move (outer_attrs)), decl (std::move (decl)),
- block_expr (std::move (block_expr)), locus (locus)
+ : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
+ decl (std::move (decl)), block_expr (std::move (block_expr)),
+ locus (locus)
{}
// Copy constructor with clone
TraitItemFunc (TraitItemFunc const &other)
- : outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus)
+ : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
+ decl (other.decl), locus (other.locus)
{
if (other.block_expr != nullptr)
block_expr = other.block_expr->clone_block_expr ();
@@ -2506,6 +2509,7 @@ public:
outer_attrs = other.outer_attrs;
decl = other.decl;
locus = other.locus;
+ mappings = other.mappings;
if (other.block_expr != nullptr)
block_expr = other.block_expr->clone_block_expr ();
@@ -2636,16 +2640,19 @@ public:
// Returns whether method has a definition or is just a declaration.
bool has_definition () const { return block_expr != nullptr; }
- TraitItemMethod (TraitMethodDecl decl, std::unique_ptr<BlockExpr> block_expr,
+ TraitItemMethod (Analysis::NodeMapping mappings, TraitMethodDecl decl,
+ std::unique_ptr<BlockExpr> block_expr,
AST::AttrVec outer_attrs, Location locus)
- : outer_attrs (std::move (outer_attrs)), decl (std::move (decl)),
- block_expr (std::move (block_expr)), locus (locus)
+ : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
+ decl (std::move (decl)), block_expr (std::move (block_expr)),
+ locus (locus)
{}
// Copy constructor with clone
TraitItemMethod (TraitItemMethod const &other)
- : outer_attrs (other.outer_attrs), decl (other.decl),
- block_expr (other.block_expr->clone_block_expr ()), locus (other.locus)
+ : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
+ decl (other.decl), block_expr (other.block_expr->clone_block_expr ()),
+ locus (other.locus)
{}
// Overloaded assignment operator to clone
@@ -2656,6 +2663,7 @@ public:
decl = other.decl;
block_expr = other.block_expr->clone_block_expr ();
locus = other.locus;
+ mappings = other.mappings;
return *this;
}
@@ -2696,18 +2704,19 @@ public:
// Whether the constant item has an associated expression.
bool has_expression () const { return expr != nullptr; }
- TraitItemConst (Identifier name, std::unique_ptr<Type> type,
- std::unique_ptr<Expr> expr, AST::AttrVec outer_attrs,
- Location locus)
- : outer_attrs (std::move (outer_attrs)), name (std::move (name)),
- type (std::move (type)), expr (std::move (expr)), locus (locus)
+ TraitItemConst (Analysis::NodeMapping mappings, Identifier name,
+ std::unique_ptr<Type> type, std::unique_ptr<Expr> expr,
+ AST::AttrVec outer_attrs, Location locus)
+ : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
+ name (std::move (name)), type (std::move (type)), expr (std::move (expr)),
+ locus (locus)
{}
// Copy constructor with clones
TraitItemConst (TraitItemConst const &other)
- : outer_attrs (other.outer_attrs), name (other.name),
- type (other.type->clone_type ()), expr (other.expr->clone_expr ()),
- locus (other.locus)
+ : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
+ name (other.name), type (other.type->clone_type ()),
+ expr (other.expr->clone_expr ()), locus (other.locus)
{}
// Overloaded assignment operator to clone
@@ -2719,6 +2728,7 @@ public:
type = other.type->clone_type ();
expr = other.expr->clone_expr ();
locus = other.locus;
+ mappings = other.mappings;
return *this;
}
@@ -2760,16 +2770,18 @@ public:
bool has_type_param_bounds () const { return !type_param_bounds.empty (); }
TraitItemType (
- Identifier name,
+ Analysis::NodeMapping mappings, Identifier name,
std::vector<std::unique_ptr<TypeParamBound> > type_param_bounds,
AST::AttrVec outer_attrs, Location locus)
- : outer_attrs (std::move (outer_attrs)), name (std::move (name)),
+ : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
+ name (std::move (name)),
type_param_bounds (std::move (type_param_bounds)), locus (locus)
{}
// Copy constructor with vector clone
TraitItemType (TraitItemType const &other)
- : outer_attrs (other.outer_attrs), name (other.name), locus (other.locus)
+ : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
+ name (other.name), locus (other.locus)
{
type_param_bounds.reserve (other.type_param_bounds.size ());
for (const auto &e : other.type_param_bounds)
@@ -2783,6 +2795,7 @@ public:
outer_attrs = other.outer_attrs;
name = other.name;
locus = other.locus;
+ mappings = other.mappings;
type_param_bounds.reserve (other.type_param_bounds.size ());
for (const auto &e : other.type_param_bounds)
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 896c2f5..1ac418c 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -770,29 +770,18 @@ protected:
// Item used in trait declarations - abstract base class
class TraitItem
{
- // bool has_outer_attrs;
- // TODO: remove and rely on virtual functions and VisItem-derived attributes?
- // std::vector<Attribute> outer_attrs;
-
- // NOTE: all children should have outer attributes
-
protected:
// Constructor
- /*TraitItem(std::vector<Attribute> outer_attrs = std::vector<Attribute>())
- : outer_attrs(std::move(outer_attrs)) {}*/
+ TraitItem (Analysis::NodeMapping mappings) : mappings (mappings) {}
// Clone function implementation as pure virtual method
virtual TraitItem *clone_trait_item_impl () const = 0;
+ Analysis::NodeMapping mappings;
+
public:
virtual ~TraitItem () {}
- // Returns whether TraitItem has outer attributes.
- /*bool has_outer_attrs() const {
- return !outer_attrs.empty();
- }*/
-
- // Unique pointer custom clone function
std::unique_ptr<TraitItem> clone_trait_item () const
{
return std::unique_ptr<TraitItem> (clone_trait_item_impl ());
@@ -801,6 +790,8 @@ public:
virtual std::string as_string () const = 0;
virtual void accept_vis (HIRVisitor &vis) = 0;
+
+ const Analysis::NodeMapping &get_mappings () const { return mappings; }
};
/* Abstract base class for items used within an inherent impl block (the impl