From: Pierre-Emmanuel Patry Date: Wed, 25 Mar 2026 15:51:42 +0000 (+0100) Subject: gccrs: Remove AttrInputMacro attribute input kind X-Git-Tag: basepoints/gcc-17~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03d64d23a66248cace050181f606d13645b2ce06;p=thirdparty%2Fgcc.git gccrs: Remove AttrInputMacro attribute input kind 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 --- diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index ba4b8aa0b3d..e6072a80bca 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -176,11 +176,6 @@ TokenCollector::visit (Attribute &attrib) static_cast (attrib.get_attr_input ())); break; } - case AST::AttrInput::AttrInputType::MACRO: - { - visit (static_cast (attrib.get_attr_input ())); - break; - } case AST::AttrInput::AttrInputType::EXPR: { visit (static_cast (attrib.get_attr_input ())); @@ -903,15 +898,6 @@ TokenCollector::visit (AttrInputLiteral &literal) }); } -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) { diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h index af60e9d1f41..6f03f575862 100644 --- a/gcc/rust/ast/rust-ast-collector.h +++ b/gcc/rust/ast/rust-ast-collector.h @@ -291,7 +291,6 @@ public: // 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); diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index f90b93145e8..21bb686d4e7 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -77,7 +77,6 @@ class QualifiedPathInType; class ExprWithBlock; class LiteralExpr; class AttrInputLiteral; -class AttrInputMacro; class MetaItemLitExpr; class MetaItemPathExpr; class OperatorExpr; diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc index 66054c7afbd..f7d33ffc44e 100644 --- a/gcc/rust/ast/rust-ast-visitor.cc +++ b/gcc/rust/ast/rust-ast-visitor.cc @@ -208,12 +208,6 @@ DefaultASTVisitor::visit (AST::AttrInputLiteral &attr_input) visit (attr_input.get_literal ()); } -void -DefaultASTVisitor::visit (AST::AttrInputMacro &attr_input) -{ - visit (attr_input.get_macro ()); -} - void DefaultASTVisitor::visit (AST::AttrInputExpr &attr_input) { diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index 0ad69a453ee..c3ec4362b50 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -72,7 +72,6 @@ public: // 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; @@ -270,7 +269,6 @@ public: 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; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 004e2760372..e8897696a47 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -344,7 +344,6 @@ Attribute::get_traits_to_derive () break; case AST::AttrInput::TOKEN_TREE: case AST::AttrInput::LITERAL: - case AST::AttrInput::MACRO: case AST::AttrInput::EXPR: rust_unreachable (); break; @@ -3377,12 +3376,6 @@ AttrInputExpr::accept_vis (ASTVisitor &vis) 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 @@ -4314,19 +4307,6 @@ BlockExpr::normalize_tail_expr () } } -// 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 ( - 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. */ @@ -4373,12 +4353,6 @@ AttrInputLiteral::accept_vis (ASTVisitor &vis) vis.visit (*this); } -void -AttrInputMacro::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - void MetaItemLitExpr::accept_vis (ASTVisitor &vis) { diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index b82a8cbd7a7..4a1974d4d9d 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -726,7 +726,6 @@ public: { EXPR, LITERAL, - MACRO, META_ITEM, TOKEN_TREE, }; diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 1ea5c3a3004..90e4daec413 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -204,58 +204,14 @@ public: Expr &get_expr () { return *expr; } + std::unique_ptr &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 macro; - -public: - AttrInputMacro (std::unique_ptr 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 &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 diff --git a/gcc/rust/expand/rust-derive.h b/gcc/rust/expand/rust-derive.h index 1f0662ab2cb..7774c6bac83 100644 --- a/gcc/rust/expand/rust-derive.h +++ b/gcc/rust/expand/rust-derive.h @@ -104,7 +104,6 @@ private: 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{}; diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index 690c74bee28..c124f9ab937 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -584,9 +584,9 @@ ExpandVisitor::visit (AST::AttrInputLiteral &) {} 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 diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h index 2a3938afe73..d6e48e0757f 100644 --- a/gcc/rust/expand/rust-expand-visitor.h +++ b/gcc/rust/expand/rust-expand-visitor.h @@ -231,7 +231,7 @@ public: 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; diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 1fc73152a00..8b2fa5a2f50 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -140,9 +140,6 @@ ASTLoweringBase::visit (AST::LiteralExpr &) void ASTLoweringBase::visit (AST::AttrInputLiteral &) {} -void -ASTLoweringBase::visit (AST::AttrInputMacro &) -{} void ASTLoweringBase::visit (AST::AttrInputExpr &) diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index 42675c281cf..ff1e51eb21b 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -106,7 +106,6 @@ public: 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; diff --git a/gcc/rust/parse/rust-parse-impl-attribute.hxx b/gcc/rust/parse/rust-parse-impl-attribute.hxx index 5c7bd99bf3e..3db1cd5c69e 100644 --- a/gcc/rust/parse/rust-parse-impl-attribute.hxx +++ b/gcc/rust/parse/rust-parse-impl-attribute.hxx @@ -314,8 +314,7 @@ Parser::parse_attr_input () if (!invoke) return Parse::Error::AttrInput::make_bad_macro_invocation (); - return std::unique_ptr ( - new AST::AttrInputMacro (std::move (invoke))); + return std::make_unique (std::move (invoke)); } AST::Literal::LitType lit_type = AST::Literal::STRING; diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 7c137d06b98..3b6587ffdaa 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -271,7 +271,6 @@ check_doc_attribute (const AST::Attribute &attribute) 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; @@ -507,38 +506,26 @@ check_export_name_attribute (const AST::Attribute &attribute) 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 (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 (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 @@ -642,10 +629,6 @@ void AttributeChecker::visit (AST::AttrInputLiteral &) {} -void -AttributeChecker::visit (AST::AttrInputMacro &) -{} - void AttributeChecker::visit (AST::MetaItemLitExpr &) {} diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index f63f902363c..4bac820120c 100644 --- a/gcc/rust/util/rust-attributes.h +++ b/gcc/rust/util/rust-attributes.h @@ -129,7 +129,6 @@ private: // 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;