This attribute kind is being replaced with AttrInputExpr attributes.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Remove
AttrInputMacro handling.
* ast/rust-ast-collector.h: Remove function prototype.
* ast/rust-ast-full-decls.h (class AttrInputMacro): Remove forward
declaration.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove function.
* ast/rust-ast-visitor.h: Remove function prototypes.
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Remove handling of
macros.
(AttrInputMacro::as_string): Remove function.
(AttrInputMacro::AttrInputMacro): Likewise.
(AttrInputMacro::operator=): Likewise.
(AttrInputMacro::accept_vis): Likewise.
* ast/rust-ast.h: Remove MACRO kind.
* ast/rust-expr.h (class AttrInputMacro): Add getter for expr pointer.
Remove AttrInputMacro class.
* expand/rust-derive.h: Remove function prototype.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Change function
to AttrInputExpr.
* expand/rust-expand-visitor.h: Update prototype.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Remove function.
* hir/rust-ast-lower-base.h: Remove function prototype.
* parse/rust-parse-impl-attribute.hxx: Parse the attribute content as
AttrInputExpr instead.
* util/rust-attributes.cc (check_doc_attribute): Remove MACRO kind
handling.
(check_export_name_attribute): Remove switch and only handle literals.
(AttributeChecker::visit): Remove function.
* util/rust-attributes.h: Remove function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
static_cast<AttrInputLiteral &> (attrib.get_attr_input ()));
break;
}
- case AST::AttrInput::AttrInputType::MACRO:
- {
- visit (static_cast<AttrInputMacro &> (attrib.get_attr_input ()));
- break;
- }
case AST::AttrInput::AttrInputType::EXPR:
{
visit (static_cast<AttrInputExpr &> (attrib.get_attr_input ()));
});
}
-void
-TokenCollector::visit (AttrInputMacro ¯o)
-{
- describe_node (std::string ("AttrInputMacro"), [this, ¯o] () {
- push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
- visit (macro.get_macro ());
- });
-}
-
void
TokenCollector::visit (AttrInputExpr &attr)
{
// rust-expr.h
void visit (LiteralExpr &expr);
void visit (AttrInputLiteral &attr_input);
- void visit (AttrInputMacro &attr_input);
void visit (AttrInputExpr &attr_input);
void visit (MetaItemLitExpr &meta_item);
void visit (MetaItemPathExpr &meta_item);
class ExprWithBlock;
class LiteralExpr;
class AttrInputLiteral;
-class AttrInputMacro;
class MetaItemLitExpr;
class MetaItemPathExpr;
class OperatorExpr;
visit (attr_input.get_literal ());
}
-void
-DefaultASTVisitor::visit (AST::AttrInputMacro &attr_input)
-{
- visit (attr_input.get_macro ());
-}
-
void
DefaultASTVisitor::visit (AST::AttrInputExpr &attr_input)
{
// rust-expr.h
virtual void visit (LiteralExpr &expr) = 0;
virtual void visit (AttrInputLiteral &attr_input) = 0;
- virtual void visit (AttrInputMacro &attr_input) = 0;
virtual void visit (AttrInputExpr &attr_input) = 0;
virtual void visit (MetaItemLitExpr &meta_item) = 0;
virtual void visit (MetaItemPathExpr &meta_item) = 0;
virtual void visit (AST::LiteralExpr &expr) override;
virtual void visit (AST::AttrInputLiteral &attr_input) override;
virtual void visit (AST::AttrInputExpr &attr_input) override;
- virtual void visit (AST::AttrInputMacro &attr_input) override;
virtual void visit (AST::MetaItemLitExpr &meta_item) override;
virtual void visit (AST::MetaItemPathExpr &meta_item) override;
virtual void visit (AST::BorrowExpr &expr) override;
break;
case AST::AttrInput::TOKEN_TREE:
case AST::AttrInput::LITERAL:
- case AST::AttrInput::MACRO:
case AST::AttrInput::EXPR:
rust_unreachable ();
break;
vis.visit (*this);
}
-std::string
-AttrInputMacro::as_string () const
-{
- return " = " + macro->as_string ();
-}
-
/* Override that calls the function recursively on all items contained within
* the module. */
void
}
}
-// needed here because "rust-expr.h" doesn't include "rust-macro.h"
-AttrInputMacro::AttrInputMacro (const AttrInputMacro &oth)
- : macro (oth.macro->clone_macro_invocation_impl ())
-{}
-
-AttrInputMacro &
-AttrInputMacro::operator= (const AttrInputMacro &oth)
-{
- macro = std::unique_ptr<MacroInvocation> (
- oth.macro->clone_macro_invocation_impl ());
- return *this;
-}
-
/* Visitor implementations - these are short but inlining can't happen anyway
* due to virtual functions and I didn't want to make the ast header includes
* any longer than they already are. */
vis.visit (*this);
}
-void
-AttrInputMacro::accept_vis (ASTVisitor &vis)
-{
- vis.visit (*this);
-}
-
void
MetaItemLitExpr::accept_vis (ASTVisitor &vis)
{
{
EXPR,
LITERAL,
- MACRO,
META_ITEM,
TOKEN_TREE,
};
Expr &get_expr () { return *expr; }
+ std::unique_ptr<Expr> &get_expr_ptr () { return expr; }
+
AttrInputExpr *clone_attr_input_impl () const override
{
return new AttrInputExpr (*this);
}
};
-// Like an AttrInputLiteral, but stores a MacroInvocation
-class AttrInputMacro : public AttrInput
-{
- std::unique_ptr<MacroInvocation> macro;
-
-public:
- AttrInputMacro (std::unique_ptr<MacroInvocation> macro)
- : macro (std::move (macro))
- {}
-
- AttrInputMacro (const AttrInputMacro &oth);
-
- AttrInputMacro (AttrInputMacro &&oth) : macro (std::move (oth.macro)) {}
-
- AttrInputMacro &operator= (const AttrInputMacro &oth);
-
- AttrInputMacro &operator= (AttrInputMacro &&oth)
- {
- macro = std::move (oth.macro);
- return *this;
- }
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
- // assuming this can't be a cfg predicate
- bool check_cfg_predicate (const Session &) const override { return false; }
-
- // assuming this is like AttrInputLiteral
- bool is_meta_item () const override { return false; }
-
- std::unique_ptr<MacroInvocation> &get_macro () { return macro; }
-
- AttrInputType get_attr_input_type () const final override
- {
- return AttrInput::AttrInputType::MACRO;
- }
-
-protected:
- AttrInputMacro *clone_attr_input_impl () const override
- {
- return new AttrInputMacro (*this);
- }
-};
-
/* literal expr only meta item inner - TODO possibly replace with inheritance of
* LiteralExpr itself? */
class MetaItemLitExpr : public MetaItemInner
virtual void visit (Token &tok) override final{};
virtual void visit (DelimTokenTree &delim_tok_tree) override final{};
virtual void visit (AttrInputMetaItemContainer &input) override final{};
- virtual void visit (AttrInputMacro &expr) override final{};
virtual void visit (AttrInputExpr &expr) override final{};
virtual void visit (IdentifierExpr &ident_expr) override final{};
virtual void visit (Lifetime &lifetime) override final{};
{}
void
-ExpandVisitor::visit (AST::AttrInputMacro ¯o)
+ExpandVisitor::visit (AST::AttrInputExpr &attr_input)
{
- rust_sorry_at (UNDEF_LOCATION, "macros in attributes not supported");
+ reseat (attr_input.get_expr_ptr ());
}
void
void visit (AST::LiteralExpr &expr) override;
void visit (AST::AttrInputLiteral &) override;
- void visit (AST::AttrInputMacro &) override;
+ void visit (AST::AttrInputExpr &) override;
void visit (AST::MetaItemLitExpr &) override;
void visit (AST::MetaItemPathExpr &) override;
void visit (AST::StructExprStruct &expr) override;
void
ASTLoweringBase::visit (AST::AttrInputLiteral &)
{}
-void
-ASTLoweringBase::visit (AST::AttrInputMacro &)
-{}
void
ASTLoweringBase::visit (AST::AttrInputExpr &)
virtual void visit (AST::LiteralExpr &expr) override;
virtual void visit (AST::AttrInputLiteral &attr_input) override;
virtual void visit (AST::AttrInputExpr &attr_input) override;
- virtual void visit (AST::AttrInputMacro &attr_input) override;
virtual void visit (AST::MetaItemLitExpr &meta_item) override;
virtual void visit (AST::MetaItemPathExpr &meta_item) override;
virtual void visit (AST::BorrowExpr &expr) override;
if (!invoke)
return Parse::Error::AttrInput::make_bad_macro_invocation ();
- return std::unique_ptr<AST::AttrInput> (
- new AST::AttrInputMacro (std::move (invoke)));
+ return std::make_unique<AST::AttrInputExpr> (std::move (invoke));
}
AST::Literal::LitType lit_type = AST::Literal::STRING;
switch (attribute.get_attr_input ().get_attr_input_type ())
{
case AST::AttrInput::LITERAL:
- case AST::AttrInput::MACRO:
case AST::AttrInput::META_ITEM:
case AST::AttrInput::EXPR:
break;
return;
}
- // We don't support the whole extended_key_value_attributes feature, we only
- // support a subset for macros. We need to emit an error message when the
- // attribute does not contain a macro or a string literal.
if (attribute.has_attr_input ())
{
auto &attr_input = attribute.get_attr_input ();
- switch (attr_input.get_attr_input_type ())
+ if (attr_input.get_attr_input_type ()
+ == AST::AttrInput::AttrInputType::LITERAL)
{
- case AST::AttrInput::AttrInputType::LITERAL:
- {
- auto &literal_expr
- = static_cast<AST::AttrInputLiteral &> (attr_input)
- .get_literal ();
- auto lit_type = literal_expr.get_lit_type ();
- switch (lit_type)
- {
- case AST::Literal::LitType::STRING:
- case AST::Literal::LitType::RAW_STRING:
- case AST::Literal::LitType::BYTE_STRING:
- return;
- default:
- break;
- }
- break;
- }
- case AST::AttrInput::AttrInputType::MACRO:
- return;
- default:
- break;
+ auto &literal_expr
+ = static_cast<AST::AttrInputLiteral &> (attr_input).get_literal ();
+ auto lit_type = literal_expr.get_lit_type ();
+ switch (lit_type)
+ {
+ case AST::Literal::LitType::STRING:
+ case AST::Literal::LitType::RAW_STRING:
+ case AST::Literal::LitType::BYTE_STRING:
+ return;
+ default:
+ break;
+ }
}
}
- rust_error_at (attribute.get_locus (), "attribute must be a string literal");
}
static void
AttributeChecker::visit (AST::AttrInputLiteral &)
{}
-void
-AttributeChecker::visit (AST::AttrInputMacro &)
-{}
-
void
AttributeChecker::visit (AST::MetaItemLitExpr &)
{}
// rust-expr.h
void visit (AST::LiteralExpr &expr) override;
void visit (AST::AttrInputLiteral &attr_input) override;
- void visit (AST::AttrInputMacro &attr_input) override;
void visit (AST::MetaItemLitExpr &meta_item) override;
void visit (AST::MetaItemPathExpr &meta_item) override;
void visit (AST::BorrowExpr &expr) override;