void
TokenCollector::visit (StructExprFieldIdentifier &expr)
{
- // TODO: Add attributes
- // visit_items_as_lines (expr.get_attrs ());
+ visit_items_as_lines (expr.get_outer_attrs ());
auto id = expr.get_field_name ().as_string ();
push (Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
}
void
TokenCollector::visit (StructExprFieldIdentifierValue &expr)
{
- // TODO: Add attributes
- // visit_items_as_lines (expr.get_attrs ());
+ visit_items_as_lines (expr.get_outer_attrs ());
auto id = expr.get_field_name ();
push (Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
push (Rust::Token::make (COLON, UNDEF_LOCATION));
void
TokenCollector::visit (StructExprFieldIndexValue &expr)
{
- // TODO: Add attributes
- // visit_items_as_lines (expr.get_attrs ());
+ visit_items_as_lines (expr.get_outer_attrs ());
push (Rust::Token::make_int (expr.get_locus (),
std::to_string (expr.get_index ())));
push (Rust::Token::make (COLON, UNDEF_LOCATION));
NodeId get_node_id () const { return node_id; }
+ const std::vector<AST::Attribute> &get_outer_attrs () const
+ {
+ return outer_attrs;
+ }
+
+ std::vector<AST::Attribute> &get_outer_attrs () { return outer_attrs; }
+
protected:
// pure virtual clone implementation
virtual StructExprField *clone_struct_expr_field_impl () const = 0;
StructExprField () : node_id (Analysis::Mappings::get ().get_next_node_id ())
{}
+ StructExprField (AST::AttrVec outer_attrs)
+ : outer_attrs (std::move (outer_attrs)),
+ node_id (Analysis::Mappings::get ().get_next_node_id ())
+ {}
+
+ AST::AttrVec outer_attrs;
NodeId node_id;
};
location_t locus;
public:
- StructExprFieldIdentifier (Identifier field_identifier, location_t locus)
- : StructExprField (), field_name (std::move (field_identifier)),
- locus (locus)
+ StructExprFieldIdentifier (Identifier field_identifier,
+ AST::AttrVec outer_attrs, location_t locus)
+ : StructExprField (std::move (outer_attrs)),
+ field_name (std::move (field_identifier)), locus (locus)
{}
std::string as_string () const override { return field_name.as_string (); }
std::unique_ptr<Expr> value;
protected:
- StructExprFieldWithVal (std::unique_ptr<Expr> field_value)
- : StructExprField (), value (std::move (field_value))
+ StructExprFieldWithVal (std::unique_ptr<Expr> field_value,
+ AST::AttrVec outer_attrs)
+ : StructExprField (std::move (outer_attrs)), value (std::move (field_value))
{}
// Copy constructor requires clone
StructExprFieldWithVal (StructExprFieldWithVal const &other)
- : value (other.value->clone_expr ())
+ : StructExprField (other.get_outer_attrs ()),
+ value (other.value->clone_expr ())
{}
// Overload assignment operator to clone unique_ptr
StructExprFieldWithVal &operator= (StructExprFieldWithVal const &other)
{
value = other.value->clone_expr ();
+ outer_attrs = other.get_outer_attrs ();
return *this;
}
location_t locus;
public:
+ StructExprFieldIdentifierValue (Identifier field_identifier,
+ std::unique_ptr<Expr> field_value,
+ AST::AttrVec outer_attrs, location_t locus)
+ : StructExprFieldWithVal (std::move (field_value), std::move (outer_attrs)),
+ field_name (std::move (field_identifier)), locus (locus)
+ {}
+
StructExprFieldIdentifierValue (Identifier field_identifier,
std::unique_ptr<Expr> field_value,
location_t locus)
- : StructExprFieldWithVal (std::move (field_value)),
+ : StructExprFieldWithVal (std::move (field_value), {}),
field_name (std::move (field_identifier)), locus (locus)
{}
public:
StructExprFieldIndexValue (TupleIndex tuple_index,
std::unique_ptr<Expr> field_value,
- location_t locus)
- : StructExprFieldWithVal (std::move (field_value)), index (tuple_index),
- locus (locus)
+ AST::AttrVec outer_attrs, location_t locus)
+ : StructExprFieldWithVal (std::move (field_value), std::move (outer_attrs)),
+ index (tuple_index), locus (locus)
{}
std::string as_string () const override;
std::unique_ptr<AST::StructExprField>
Parser<ManagedTokenSource>::parse_struct_expr_field ()
{
+ AST::AttrVec outer_attrs = parse_outer_attributes ();
const_TokenPtr t = lexer.peek_token ();
switch (t->get_id ())
{
return std::unique_ptr<AST::StructExprFieldIdentifierValue> (
new AST::StructExprFieldIdentifierValue (std::move (ident),
std::move (expr),
+ std::move (outer_attrs),
t->get_locus ()));
}
else
return std::unique_ptr<AST::StructExprFieldIdentifier> (
new AST::StructExprFieldIdentifier (std::move (ident),
+ std::move (outer_attrs),
t->get_locus ()));
}
case INT_LITERAL: {
return std::unique_ptr<AST::StructExprFieldIndexValue> (
new AST::StructExprFieldIndexValue (index, std::move (expr),
+ std::move (outer_attrs),
t->get_locus ()));
}
case DOT_DOT:
/* technically this would give a struct base-only struct, but this
* algorithm should work too. As such, AST type not happening. */
case IDENTIFIER:
+ case HASH:
case INT_LITERAL: {
// struct with struct expr fields