Skip to content

gccrs: Introduce AST::Visitable class for AST#2107

Merged
CohenArthur merged 1 commit into
masterfrom
dkm/debug_ast
Apr 11, 2023
Merged

gccrs: Introduce AST::Visitable class for AST#2107
CohenArthur merged 1 commit into
masterfrom
dkm/debug_ast

Conversation

@dkm

@dkm dkm commented Apr 6, 2023

Copy link
Copy Markdown
Member

AST::Visitable is an abstract class with a unique accept_vis() method.
Make all abstract AST node class inherit from this class.

Allows for easy definition of operations on nodes that must accept a
visitor.

The static Dump::dump() is an example of such use: the static method
accepts any AST node, creates a Dump visitor and have it visit the AST
starting at the node.

This change also inserts a debug(Visitable&) function in the global
namespace to make it easy to call from the debugger (similar to
debug_tree or debug(rtx*) functions).

gcc/rust/ChangeLog:
            * ast/rust-ast-dump.cc (Dump::debug): New.
            * ast/rust-ast-dump.h (Dump::debug): Untemplate it.
            (debug): New.
            * ast/rust-ast.h (class Visitable): New.
            (class TokenTree): Inherit from Visitable.
            (class MacroMatch): Likewise.
            (class AttrInput): Likewise.
            (class MetaItemInner): Likewise.
            (class Pattern): Likewise.
            (classTypeParamBound): Likewise.
            (class GenericParam): Likewise.
            (class TraitItem): Likewise.
            (classInherentImplItem): Likewise.
            (class TraitImplItem): Likewise.
            (class ExternalItem): Likewise.
            (class SingleASTNode): Likewise.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>

@dkm dkm force-pushed the dkm/debug_ast branch from 7ac09c0 to 1b0b50b Compare April 6, 2023 19:33
@CohenArthur CohenArthur requested a review from philberty April 7, 2023 08:36
@CohenArthur CohenArthur added this to the Final upstream patches milestone Apr 7, 2023
@CohenArthur CohenArthur requested a review from P-E-P April 7, 2023 08:37

@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.

Great idea and great execution :) thank you!

Comment thread gcc/rust/ast/rust-ast.h Outdated
AST::Visitable is an abstract class with a unique accept_vis() method.
Make all abstract AST node class inherit from this class.

Allows for easy definition of operations on nodes that must accept a
visitor.

The static Dump::dump() is an example of such use: the static method
accepts any AST node, creates a Dump visitor and have it visit the AST
starting at the node.

This change also inserts a debug(Visitable&) function in the global
namespace to make it easy to call from the debugger (similar to
debug_tree or debug(rtx*) functions).

gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::debug): New.
	* ast/rust-ast-dump.h (Dump::debug): Untemplate it.
	(debug): New.
	* ast/rust-ast.h (class Visitable): New.
	(class TokenTree): Inherit from Visitable.
	(class MacroMatch): Likewise.
	(class AttrInput): Likewise.
	(class MetaItemInner): Likewise.
	(class Pattern): Likewise.
	(classTypeParamBound): Likewise.
	(class GenericParam): Likewise.
	(class TraitItem): Likewise.
	(classInherentImplItem): Likewise.
	(class TraitImplItem): Likewise.
	(class ExternalItem): Likewise.
	(class SingleASTNode): Likewise.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
@dkm dkm force-pushed the dkm/debug_ast branch from 1b0b50b to 05dd8e1 Compare April 7, 2023 18:36
@dkm

dkm commented Apr 7, 2023

Copy link
Copy Markdown
Member Author

Implemented your suggestion @CohenArthur

@CohenArthur CohenArthur added this pull request to the merge queue Apr 11, 2023
Merged via the queue into master with commit 62d48d5 Apr 11, 2023
@dkm dkm deleted the dkm/debug_ast branch April 11, 2023 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants