// TODO what to do with outer attr? They are not mentioned in the reference.
+ visit_items_as_lines (lifetime_param.get_outer_attrs ());
auto lifetime = lifetime_param.get_lifetime ();
visit (lifetime);
// Syntax:
// const IDENTIFIER : Type ( = Block | IDENTIFIER | -?LITERAL )?
+ visit_items_as_lines (param.get_outer_attrs ());
push (Rust::Token::make (CONST, param.get_locus ()));
auto id = param.get_name ().as_string ();
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
// TypeParamBounds :
// TypeParamBound ( + TypeParamBound )* +?
+ visit_items_as_lines (param.get_outer_attrs ());
auto id = param.get_type_representation ().as_string ();
push (Rust::Token::make_identifier (param.get_locus (), std::move (id)));
if (param.has_type_param_bounds ())
void
DefaultASTVisitor::visit (AST::LifetimeParam &lifetime_param)
{
- visit (lifetime_param.get_outer_attribute ());
+ visit_outer_attrs (lifetime_param);
visit (lifetime_param.get_lifetime ());
for (auto &lifetime_bound : lifetime_param.get_lifetime_bounds ())
visit (lifetime_bound);
void
DefaultASTVisitor::visit (AST::ConstGenericParam &const_param)
{
- visit (const_param.get_outer_attribute ());
+ visit_outer_attrs (const_param);
if (const_param.has_type ())
visit (const_param.get_type ());
if (const_param.has_default_value ())
void
DefaultASTVisitor::visit (AST::TypeParam ¶m)
{
- visit (param.get_outer_attribute ());
+ visit_outer_attrs (param);
for (auto &bound : param.get_type_param_bounds ())
visit (bound);
if (param.has_type ())
{
std::string str ("LifetimeParam: ");
- str += "\n Outer attribute: ";
+ str += "\n Outer attribute:";
if (!has_outer_attribute ())
str += "none";
- else
- str += outer_attr.as_string ();
+ for (auto &attr : outer_attrs)
+ str += " " + attr.as_string ();
str += "\n Lifetime: " + lifetime.as_string ();
{
std::string str ("TypeParam: ");
- str += "\n Outer attribute: ";
+ str += "\n Outer attribute:";
if (!has_outer_attribute ())
str += "none";
- else
- str += outer_attr.as_string ();
+ for (auto &attr : outer_attrs)
+ str += " " + attr.as_string ();
str += "\n Identifier: " + type_representation.as_string ();
{
Lifetime lifetime;
std::vector<Lifetime> lifetime_bounds;
- Attribute outer_attr;
+ AST::AttrVec outer_attrs;
location_t locus;
public:
Lifetime &get_lifetime () { return lifetime; }
- Attribute &get_outer_attribute () { return outer_attr; }
+ AST::AttrVec &get_outer_attrs () { return outer_attrs; }
// Returns whether the lifetime param has any lifetime bounds.
bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); }
std::vector<Lifetime> &get_lifetime_bounds () { return lifetime_bounds; }
// Returns whether the lifetime param has an outer attribute.
- bool has_outer_attribute () const { return !outer_attr.is_empty (); }
+ bool has_outer_attribute () const { return !outer_attrs.empty (); }
// Creates an error state lifetime param.
static LifetimeParam create_error ()
{
- return LifetimeParam (Lifetime::error (), {}, Attribute::create_empty (),
- UNDEF_LOCATION);
+ return LifetimeParam (Lifetime::error (), {}, {}, UNDEF_LOCATION);
}
// Returns whether the lifetime param is in an error state.
// Constructor
LifetimeParam (Lifetime lifetime, std::vector<Lifetime> lifetime_bounds,
- Attribute outer_attr, location_t locus)
+ AST::AttrVec outer_attrs, location_t locus)
: lifetime (std::move (lifetime)),
lifetime_bounds (std::move (lifetime_bounds)),
- outer_attr (std::move (outer_attr)), locus (locus)
+ outer_attrs (std::move (outer_attrs)), locus (locus)
{}
std::string as_string () const override;
{
// bool has_outer_attribute;
// std::unique_ptr<Attribute> outer_attr;
- Attribute outer_attr;
+ AST::AttrVec outer_attrs;
Identifier type_representation;
bool has_type_param_bounds () const { return !type_param_bounds.empty (); }
// Returns whether the type param has an outer attribute.
- bool has_outer_attribute () const { return !outer_attr.is_empty (); }
+ bool has_outer_attribute () const { return !outer_attrs.empty (); }
- Attribute &get_outer_attribute () { return outer_attr; }
+ AST::AttrVec &get_outer_attrs () { return outer_attrs; }
TypeParam (Identifier type_representation, location_t locus = UNDEF_LOCATION,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds
= std::vector<std::unique_ptr<TypeParamBound>> (),
std::unique_ptr<Type> type = nullptr,
- Attribute outer_attr = Attribute::create_empty ())
+ AST::AttrVec outer_attrs = {})
: GenericParam (Analysis::Mappings::get ().get_next_node_id ()),
- outer_attr (std::move (outer_attr)),
+ outer_attrs (std::move (outer_attrs)),
type_representation (std::move (type_representation)),
type_param_bounds (std::move (type_param_bounds)),
type (std::move (type)), locus (locus)
// Copy constructor uses clone
TypeParam (TypeParam const &other)
- : GenericParam (other.node_id), outer_attr (other.outer_attr),
+ : GenericParam (other.node_id), outer_attrs (other.outer_attrs),
type_representation (other.type_representation), locus (other.locus)
{
// guard to prevent null pointer dereference
TypeParam &operator= (TypeParam const &other)
{
type_representation = other.type_representation;
- outer_attr = other.outer_attr;
+ outer_attrs = other.outer_attrs;
locus = other.locus;
node_id = other.node_id;
*/
GenericArg default_value;
- Attribute outer_attr;
+ AST::AttrVec outer_attrs;
location_t locus;
public:
ConstGenericParam (Identifier name, std::unique_ptr<AST::Type> type,
- GenericArg default_value, Attribute outer_attr,
+ GenericArg default_value, AST::AttrVec outer_attrs,
location_t locus)
: name (name), type (std::move (type)),
- default_value (std::move (default_value)), outer_attr (outer_attr),
+ default_value (std::move (default_value)), outer_attrs (outer_attrs),
locus (locus)
{}
ConstGenericParam (const ConstGenericParam &other)
: GenericParam (), name (other.name), type (other.type->clone_type ()),
- default_value (other.default_value), outer_attr (other.outer_attr),
+ default_value (other.default_value), outer_attrs (other.outer_attrs),
locus (other.locus)
{}
const Identifier &get_name () const { return name; }
- Attribute &get_outer_attribute () { return outer_attr; }
+ AST::AttrVec &get_outer_attrs () { return outer_attrs; }
AST::Type &get_type ()
{
std::unique_ptr<AST::GenericParam>
Parser<ManagedTokenSource>::parse_generic_param (EndTokenPred is_end_token)
{
- auto outer_attrs = parse_outer_attribute ();
+ auto outer_attrs = parse_outer_attributes ();
std::unique_ptr<AST::GenericParam> param;
auto token = lexer.peek_token ();
AST::LifetimeParam
Parser<ManagedTokenSource>::parse_lifetime_param ()
{
- // parse outer attribute, which is optional and may not exist
- AST::Attribute outer_attr = parse_outer_attribute ();
+ // parse outer attributes, which are optional and may not exist
+ auto outer_attrs = parse_outer_attributes ();
// save lifetime token - required
const_TokenPtr lifetime_tok = lexer.peek_token ();
}
return AST::LifetimeParam (std::move (lifetime), std::move (lifetime_bounds),
- std::move (outer_attr),
+ std::move (outer_attrs),
lifetime_tok->get_locus ());
}
std::unique_ptr<AST::TypeParam>
Parser<ManagedTokenSource>::parse_type_param ()
{
- // parse outer attribute, which is optional and may not exist
- AST::Attribute outer_attr = parse_outer_attribute ();
+ // parse outer attributes, which are optional and may not exist
+ auto outer_attrs = parse_outer_attributes ();
const_TokenPtr identifier_tok = lexer.peek_token ();
if (identifier_tok->get_id () != IDENTIFIER)
return std::unique_ptr<AST::TypeParam> (
new AST::TypeParam (std::move (ident), identifier_tok->get_locus (),
std::move (type_param_bounds), std::move (type),
- std::move (outer_attr)));
+ std::move (outer_attrs)));
}
/* Parses regular (i.e. non-generic) parameters in functions or methods. Also