Skip to content

Use MacroInvocLexer in AttributeParser#3890

Merged
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
powerboat9:better-attr-2
Jul 19, 2025
Merged

Use MacroInvocLexer in AttributeParser#3890
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
powerboat9:better-attr-2

Conversation

@powerboat9

Copy link
Copy Markdown
Collaborator

This should make it easier for us to handle attribute meta items of the form <SimplePath> '=' <Expression> where the expression isn't a literal. Some low hanging fruit remains here, but I think I should keep this patch small as I had some trouble debugging it as-is (see: Rust::Token::as_string vs Rust::Token::get_str vs Rust::AST::Token::as_string).

This should make it easier for us to handle attribute meta items of the
form <SimplePath> '=' <Expression> where the expression isn't a literal.
Some low hanging fruit remains here, but I think I should keep this
patch small as I had some trouble debugging it as-is (see:
Rust::Token::as_string vs Rust::Token::get_str vs
Rust::AST::Token::as_string).

gcc/rust/ChangeLog:

	* ast/rust-ast.cc: Include "rust-macro-invoc-lexer.h".
	(AttributeParser::~AttributeParser): Move function definition
	here.
	(AttributeParser::AttributeParser): Likewise and adjust member
	initialization.
	(AttributeParser::parse_meta_item_inner): Handle changes to
	peek_token.
	(AttributeParser::parse_literal): Likewise.
	(AttributeParser::parse_simple_path_segment): Likewise.
	(AttributeParser::parse_meta_item_seq): Handle changes to
	AttributeParser fields.
	(AttributeParser::peek_token): Move function definition here and
	wrap MacroInvocLexer.
	(AttributeParser::skip_token): Likewise.
	* ast/rust-macro.h (class MacroInvocLexer): Forward declare.
	(class Parser): Likewise.
	(AttributeParser::token_stream): Remove field.
	(AttributeParser::stream_pos): Likewise.
	(AttributeParser::lexer): New field.
	(AttributeParser::parser): Likewise.
	(AttributeParser::AttributeParser): Move definition to
	"rust-ast.cc".
	(AttributeParser::~AttributeParser): Likewise.
	(AttributeParser::peek_token): Likewise.
	(AttributeParser::skip_token): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>

@philberty philberty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CohenArthur

Copy link
Copy Markdown
Member

aaaah that's amazing, thank you

@CohenArthur CohenArthur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@CohenArthur CohenArthur added this pull request to the merge queue Jul 19, 2025
Merged via the queue into Rust-GCC:master with commit a671c41 Jul 19, 2025
13 checks passed
@powerboat9 powerboat9 deleted the better-attr-2 branch July 21, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants