]> gcc.gnu.org Git - gcc.git/log
gcc.git
6 months agogccrs: Fix memory corruption at peek_context
Philip Herron [Mon, 17 Apr 2023 19:48:41 +0000 (20:48 +0100)]
gccrs: Fix memory corruption at peek_context

When working in the resolve_operator_overload it was found that we got
memory corruption as method resolution will use the query system and
therefore resolve new methods and the current function context info will
change and due to the fact the peek_context interface returns a reference
to the element which was now safe from a vector which can change and all
you need is the current function context at that moment in time.

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc: don't take a reference
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
* typecheck/rust-hir-type-check.h: remove reference
* typecheck/rust-typecheck-context.cc (TypeCheckContext::pop_return_type): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: patterns: Add execution testcases to verify proper pattern matching
Arthur Cohen [Fri, 21 Apr 2023 09:22:52 +0000 (11:22 +0200)]
gccrs: patterns: Add execution testcases to verify proper pattern matching

These testcases are similar to the ones added in #2072 but regarding
execution. One more issue was opened from them - #2144

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-1852-1.rs: New test.
* rust/execute/torture/issue-1852.rs: New test.

6 months agogccrs: Resolve identifier-pattern struct pattern fields
Owen Avery [Mon, 24 Apr 2023 19:49:49 +0000 (15:49 -0400)]
gccrs: Resolve identifier-pattern struct pattern fields

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-pattern.cc
(PatternDeclaration::visit): Handle StructPatternFieldIdentPat.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: libproc_macro: Fix literal drop function
Pierre-Emmanuel Patry [Fri, 21 Apr 2023 10:00:08 +0000 (12:00 +0200)]
gccrs: libproc_macro: Fix literal drop function

Fix drop function by changing the delete operator to delete[] in order
to avoid undefined behaviors.

libgrust/ChangeLog:

* libproc_macro/literal.cc (Literal::drop): Change
delete operator to delete[].

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Implement Drop for TokenStream
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 16:07:08 +0000 (18:07 +0200)]
gccrs: libproc_macro: Implement Drop for TokenStream

TokenStream did not have any drop implementation, the memory could not
have been freed correctly.

libgrust/ChangeLog:

* libproc_macro/rust/bridge/token_stream.rs: Implement
drop.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add remaining drop functions
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 15:58:27 +0000 (17:58 +0200)]
gccrs: libproc_macro: Add remaining drop functions

Remaining structures from the rust bridge that missed a drop function
now have one.

libgrust/ChangeLog:

* libproc_macro/group.cc (Group::drop): Add drop
implementation.
* libproc_macro/group.h: Add drop prototype.
* libproc_macro/tokenstream.cc (TokenStream::drop): Add
drop implementation.
(TokenStream__drop): Change to a call to TokenStream::drop.
* libproc_macro/tokenstream.h: Add drop prototype.
* libproc_macro/tokentree.cc (TokenTree::drop): Add
drop implementation.
* libproc_macro/tokentree.h: Add drop prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add drop function to Literal struct
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 15:56:36 +0000 (17:56 +0200)]
gccrs: libproc_macro: Add drop function to Literal struct

Add a drop function to clean internal fields of a Literal struct.

libgrust/ChangeLog:

* libproc_macro/literal.cc (Literal__drop): Replace
implementation by a call to Literal::drop.
(Literal::drop): Add drop implementation.
* libproc_macro/literal.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add drop function on Ident struct
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 15:47:43 +0000 (17:47 +0200)]
gccrs: libproc_macro: Add drop function on Ident struct

Add a drop function that cleans internal fields of a given Ident struct.

libgrust/ChangeLog:

* libproc_macro/ident.cc (Ident__drop): Replace by call
to Ident::drop.
(Ident::drop): Add drop function.
* libproc_macro/ident.h: Add drop prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add remaining tokenstream structs.
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 13:28:45 +0000 (15:28 +0200)]
gccrs: libproc_macro: Add remaining tokenstream structs.

Add remaining missing tokenstream structures. Most are interdependent.

libgrust/ChangeLog:

* libproc_macro/group.cc: New file.
* libproc_macro/group.h: New file.
* libproc_macro/tokenstream.cc: New file.
* libproc_macro/tokenstream.h: New file.
* libproc_macro/tokentree.cc: New file.
* libproc_macro/tokentree.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Fix translation mistakes 2023 in GCC/Rust [PR108890]
TieWay59 [Wed, 19 Apr 2023 06:07:34 +0000 (14:07 +0800)]
gccrs: Fix translation mistakes 2023 in GCC/Rust [PR108890]

In https://gcc.gnu.org/PR108890 "Translation mistakes 2023"
@rillig lists several issues with GCC/Rust diagnostics and
option help texts (but also a few non-GCC/Rust).

This commit fix mistakes only related to GCC/Rust,
specifically to the file `gcc/rust/lang.opt`.

closes https://github.com/Rust-GCC/gccrs/issues/1916

PR translation/108890
gcc/rust/
* lang.opt: Fix translation mistakes 2023 in
GCC/Rust [PR108890]
(line 67): change the inconsistent tab to spaces
(line 75): wrap bare placeholder `integer`
(line 79): remove redundant text of `Choose which`
(line 96): remove redundant text of `Choose which`
(line 112): remove redundant `Flag to`
(line 124): correct the exclusive term `When to stop`
(line 124): correct typo of `copimlation`

Signed-off-by: Tieway59 <tieway59@foxmail.com>
6 months agogccrs: libproc_macro: Add Punct struct
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 12:24:43 +0000 (14:24 +0200)]
gccrs: libproc_macro: Add Punct struct

Add Punct struct for rust interface as well as a basic named
constructor.

libgrust/ChangeLog:

* libproc_macro/punct.cc: New file.
* libproc_macro/punct.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add namespace to Ident
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 10:11:37 +0000 (12:11 +0200)]
gccrs: libproc_macro: Add namespace to Ident

Add a new Ident namespace to group Ident related enumeration and
structures.

libgrust/ChangeLog:

* libproc_macro/ident.cc (Ident::make_ident): Add Ident
namespace.
* libproc_macro/ident.h (Ident__clone): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add named constructor
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 13:07:03 +0000 (15:07 +0200)]
gccrs: libproc_macro: Add named constructor

Add named constructor directly in Ident struct.

libgrust/ChangeLog:

* libproc_macro/ident.cc (Ident__new): Use named
constructor.
(Ident__new_raw): Use named constructor.
(Ident__clone): Use clone member function.
(Ident::clone): Make clone const.
(Ident::make_ident): Add named construcot.
* libproc_macro/ident.h (struct Ident): Add named
constructor prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Change drop rust interface
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 11:53:13 +0000 (13:53 +0200)]
gccrs: libproc_macro: Change drop rust interface

Change rust interface on drop function to take a mut pointer instead.
This will match the drop trait interface more closely.

libgrust/ChangeLog:

* libproc_macro/rust/bridge/ident.rs: Change drop
function interface.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add ident implementation
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 10:18:54 +0000 (12:18 +0200)]
gccrs: libproc_macro: Add ident implementation

Add implementation and representation for ident cpp structure as well as
a high level wrapper interface.

libgrust/ChangeLog:

* libproc_macro/ident.cc: New file.
* libproc_macro/ident.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Deleted the as_string ASR and HIR dumps
M V V S Manoj Kumar [Fri, 14 Apr 2023 12:59:48 +0000 (18:29 +0530)]
gccrs: Deleted the as_string ASR and HIR dumps

Fixes #2021, #2022
Deleted Parser::debug_dump_ast_output, removed any functions that called
it i.e Session::dump_ast and Session::dump_ast_expanded, and any
associated items.

Made it so that when you use the dump option "expanded" it dumps the
pretty ast only.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::debug_dump_ast_output): Removed this funtion.
* rust-session-manager.cc (Session::enable_dump): Removed else if (arg == "parse").
(Session::compile_crate): Removed calls of dump_ast and dump_ast_expanded.
(Session::dump_ast): Removed this function.
(Session::dump_ast_expanded): Removed this function.
* rust-session-manager.h (struct CompileOptions): Removed the PARSER_AST_DUMP option.

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
6 months agogccrs: parser: Parse reference patterns correctly
Arthur Cohen [Wed, 19 Apr 2023 15:40:15 +0000 (17:40 +0200)]
gccrs: parser: Parse reference patterns correctly

Reference patterns cannot contain AltPatterns per the Rust reference,
so we should not call into `parse_pattern` to parse the referenced pattern,
but rather the more restrictive `parse_pattern_no_alt`.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_reference_pattern): Do not
call into `parse_pattern` anymore.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1807.rs: New test.

6 months agogccrs: Add error message for AltPattern in let statements
Owen Avery [Fri, 21 Apr 2023 05:43:25 +0000 (01:43 -0400)]
gccrs: Add error message for AltPattern in let statements

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::translate): Add is_let_top_level parameter.
(ASTLoweringPattern::visit): Handle is_let_top_level.
* hir/rust-ast-lower-pattern.h
(class ASTLoweringPattern): Add is_let_top_level.
* hir/rust-ast-lower-stmt.cc
(ASTLoweringStmt::visit): Set is_let_top_level.

gcc/testsuite/ChangeLog:

* rust/compile/let_alt.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Implement Dump:visit() function for QualifiedPathInType argument.
Zheyuan Chen [Thu, 13 Apr 2023 12:57:31 +0000 (05:57 -0700)]
gccrs: Implement Dump:visit() function for QualifiedPathInType argument.

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc: fix bad formatting for associated type.

Signed-off-by: Zheyuan Chen <sephirotheca17@gmail.com>
6 months agogccrs: Add testcase to show matching of enum variants
Philip Herron [Wed, 29 Mar 2023 21:27:38 +0000 (22:27 +0100)]
gccrs: Add testcase to show matching of enum variants

Fixes #852

gcc/testsuite/ChangeLog:

* rust/compile/issue-852.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Lower ErrorPropagationExpr from AST to HIR
Sergey Bugaev [Fri, 14 Apr 2023 16:47:46 +0000 (19:47 +0300)]
gccrs: Lower ErrorPropagationExpr from AST to HIR

gcc/rust/ChangeLog:
* hir/rust-ast-lower-expr.h, hir/rust-ast-lower-expr.cc:
Lower AST::ErrorPropagationExpr to HIR::ErrorPropagationExpr

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
6 months agogccrs: libproc_macro: Add member functions to Literal
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 14:24:09 +0000 (16:24 +0200)]
gccrs: libproc_macro: Add member functions to Literal

Add some member functions to the Literal structure as well as named
constructors.

libgrust/ChangeLog:

* libproc_macro/literal.cc (Literal__string): Add call
to named constructor.
(Literal__byte_string): Likewise.
(Literal::make_unsigned): Add function.
(Literal::make_signed): Add function.
(Literal::clone): Likewise.
(Literal::make_u8): Likewise.
(Literal::make_u16): Likewise.
(Literal::make_u32): Likewise.
(Literal::make_u64): Likewise.
(Literal::make_i8): Likewise.
(Literal::make_i16): Likewise.
(Literal::make_i32): Likewise.
(Literal::make_i64): Likewise.
(Literal::make_string): Likewise.
(Literal::make_byte_string): Likewise.
(Literal::make_f32): Likewise.
(Literal::make_f64): Likewise.
(make_char): Likewise.
(Literal::make_char): Likewise.
(make_usize): Likewise.
(Literal::make_usize): Likewise.
(make_isize): Likewise.
(Literal::make_isize): Likewise.
* libproc_macro/literal.h: Add prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Put literal members in namespace
Pierre-Emmanuel Patry [Fri, 7 Apr 2023 13:02:55 +0000 (15:02 +0200)]
gccrs: libproc_macro: Put literal members in namespace

Add a Literal namespace to gather all every literal related code.

libgrust/ChangeLog:

* libproc_macro/literal.cc (Literal__from_string):
Add abort because unimplemented.
* libproc_macro/literal.h (Literal__from_string): Add
namespace.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Drop function shall take a mutable
Pierre-Emmanuel Patry [Fri, 7 Apr 2023 11:52:04 +0000 (13:52 +0200)]
gccrs: libproc_macro: Drop function shall take a mutable

The rust API requires a mut reference, hence having a mutable pointer
seems to match better. Furthermore the implementation is now modifying
the struct in order to set the size to 0 instead of simply freeing the
data, this will allow us to easily identify mistaken manual call to this
function.

libgrust/ChangeLog:

* libproc_macro/rust/bridge/literal.rs: Make the
pointer mutable.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add literal ffi implementations
Pierre-Emmanuel Patry [Thu, 6 Apr 2023 12:29:53 +0000 (14:29 +0200)]
gccrs: libproc_macro: Add literal ffi implementations

Add literal type related ffi functions implementation.

libgrust/ChangeLog:

* libproc_macro/literal.h (Literal__drop): Implement
drop.
(Literal__string): Constructor from a string function prototype.
(Literal__byte_string): Constructor from a byte string function
prototype.
(Literal__from_string): Add function body, no implementation
yet.
* libproc_macro/literal.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add Literal type
Pierre-Emmanuel Patry [Thu, 6 Apr 2023 10:13:13 +0000 (12:13 +0200)]
gccrs: libproc_macro: Add Literal type

Add the Literal type matching rust ffi definitions.

libgrust/ChangeLog:

* libproc_macro/proc_macro.h (PROC_MACRO_H): Add
literal header include directive.
* libproc_macro/literal.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add license headers
Pierre-Emmanuel Patry [Thu, 6 Apr 2023 10:10:39 +0000 (12:10 +0200)]
gccrs: libproc_macro: Add license headers

Add license headers to existing files.

libgrust/ChangeLog:

* libproc_macro/proc_macro.cc (test): Remove dummy
function.
* libproc_macro/proc_macro.h (test): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Fix scope separator in tokenstreams
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 16:27:24 +0000 (18:27 +0200)]
gccrs: ast: Fix scope separator in tokenstreams

Qualified types had a simple colon output instead of full scope
resolution tokens in QualifiedPathInTypes.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix scope
resolution token output.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Fix tokenstream QualifiedPathInExpression
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 16:26:03 +0000 (18:26 +0200)]
gccrs: ast: Fix tokenstream QualifiedPathInExpression

The associated type was not kept in the tokenstream.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Keep
associated type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Fix tokenstream function body
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 16:04:41 +0000 (18:04 +0200)]
gccrs: ast: Fix tokenstream function body

Function body were skipped in tokenstream when no return type was
provided.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit_function_common):
Fix function body output.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: parser: Fix attribute differentation
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 14:20:32 +0000 (16:20 +0200)]
gccrs: parser: Fix attribute differentation

In some cases, while parsing an outer attribute, the parser would return
an inner attribute.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_outer_attribute): Fix
attribute status.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: lex: Fix lifetime string representation
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 13:59:03 +0000 (15:59 +0200)]
gccrs: lex: Fix lifetime string representation

Lifetime string representation used two single quotes instead of one.

gcc/rust/ChangeLog:

* lex/rust-token.cc (Token::as_string): Fix lifetime string
representation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: resolve: Add "break rust" Easter egg
Sergey Bugaev [Mon, 3 Apr 2023 15:58:43 +0000 (18:58 +0300)]
gccrs: resolve: Add "break rust" Easter egg

When we encounter a "break rust" statement, emit a funny error message
and intentionally cause an ICE. This matches the corresponding Easter
egg in rustc. As a GNU extension, "break gcc" is also supported.

The conditions for this to happen are:
* The break expression must be literally "rust" or "gcc". For instance,
  "break (rust)" will not trigger the Easter egg.
* The name ("rust" or "gcc") must not be in scope; if it is, no error
  is emitted, and the compilation proceeds as usual. In other words,
  this only affects how GCC diagnoses programs that would fail to
  compile anyway.

Note that this is different from the conditions under which rustc emits
its ICE. For rustc, it matters whether or not the "break" is inside a
loop, and for us it matters whether or not the name resolves. The end
result should be the same anyway: valid programs continue to compile,
and typing in

fn main() {
    break rust;
}

triggers a funny ICE.

Closes https://github.com/Rust-GCC/gccrs/issues/1996

gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc: Add "break rust" Easter egg

gcc/testsuite/ChangeLog:
* lib/prune.exp (prune_ices):
Also prune "You have broken GCC Rust. This is a feature."
* rust/compile/break-rust1.rs: New test
* rust/compile/break-rust2.rs: New test
* rust/compile/break-rust3.rs: New test

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
6 months agogccrs: resolve: Add ResolveExpr::funny_error
Sergey Bugaev [Mon, 3 Apr 2023 15:51:58 +0000 (18:51 +0300)]
gccrs: resolve: Add ResolveExpr::funny_error

...and thread it through the constructors and the ResolveExpr::go ()
method.

This will be used for implementing the "break rust" Easter egg.

gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.h,
resolve/rust-ast-resolve-expr.cc: Add ResolveExpr::funny_error

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
6 months agogccrs: ast: Add AST::Kind::IDENTIFIER
Sergey Bugaev [Mon, 3 Apr 2023 15:48:45 +0000 (18:48 +0300)]
gccrs: ast: Add AST::Kind::IDENTIFIER

...and return it from IdentifierExpr::get_ast_kind (). This enables
other code to dynamically test whether an expression is in fact an
IdentifierExpr.

gcc/rust/ChangeLog:
* ast/rust-ast.h: Add AST::Kind::IDENTIFIER

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
6 months agogccrs: ast: Make AST::Kind an enum class
Sergey Bugaev [Mon, 3 Apr 2023 15:43:08 +0000 (18:43 +0300)]
gccrs: ast: Make AST::Kind an enum class

We're going to introduce AST::Kind::IDENTIFIER next, and with the
default C-style enum member scoping, this would cause name clashes.
Instead, convert AST::Kind into an enum class, so that its members
are properly namespaced.

gcc/rust/ChangeLog:
* ast/rust-ast.h (Kind): Convert into a C++ enum class
* expand/rust-macro-builtins.cc: Adapt to the change

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
6 months agogccrs: Add lowering for if-let expressions
Owen Avery [Sat, 18 Mar 2023 05:41:01 +0000 (01:41 -0400)]
gccrs: Add lowering for if-let expressions

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::visit): Add implementation for IfLetExprConseqElse.
* typecheck/rust-hir-type-check-expr.h:
(TypeCheckExpr::visit): Remove stub implementation for IfLetExprConseqElse.
* hir/rust-ast-lower-expr.cc
(ASTLoweringExpr::visit): Lower IfLetExpr{,ConseqElse}.
* hir/rust-ast-lower-expr.h:
(ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-block.h
(ASTLoweringIfLetBlock::visit): Lower IfLetExprConseqElse.
(ASTLoweringExprWithBlock::visit): Likewise.
* hir/rust-ast-lower.cc
(ASTLoweringIfLetBlock::visit): Lower IfLetExprConseqElse.
* hir/tree/rust-hir-expr.h
(IfLetExprConseqElse::IfLetExprConseqElse): Make constructor more general.
(IfLetExprConseqElse::vis_else_block): Add.
(IfLetExprConseqElse::get_else_block): Add.
* resolve/rust-ast-resolve-expr.cc
(ResolveExpr::visit): Add IfLetExprConseqElse visitor.
* resolve/rust-ast-resolve-expr.h
(ResolveExpr::visit): Add IfLetExprConseqElse visitor.

gcc/testsuite/ChangeLog:

* rust/compile/if_let_expr.rs: Increase test coverage.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: parser: macro: reject separator in `?` repetition
Sebastian Kirmayer [Wed, 5 Apr 2023 04:09:11 +0000 (06:09 +0200)]
gccrs: parser: macro: reject separator in `?` repetition

A matcher like $(a),? is no longer accepted.

Fixes #2092.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser<ManagedTokenSource>::parse_macro_match_repetition):
reject separator in `?` repetition

gcc/testsuite/ChangeLog:

* rust/compile/macro-issue2092.rs: New test.

Signed-off-by: Sebastian Kirmayer <gnu@kirmayer.eu>
6 months agogccrs: Unify AST::IfLetExprConseqIf{,Let} into AST::IfLetExprConseqElse
Owen Avery [Thu, 16 Mar 2023 03:30:19 +0000 (23:30 -0400)]
gccrs: Unify AST::IfLetExprConseqIf{,Let} into AST::IfLetExprConseqElse

This simplifies the AST's representation of if-let-statements
to match the HIR.

gcc/rust/ChangeLog:

* ast/rust-expr.h
(class IfLetExprConseqElse): Make else_block ExprWithBlock.
(class IfLetExprConseqIf): Remove.
(class IfLetExprConseqIfLet): Remove.
* ast/rust-ast-full-decls.h
(class IfLetExprConseqIf): Remove.
(class IfLetExprConseqIfLet): Remove.
* ast/rust-ast.cc
(IfLetExprConseqElse::as_string): Adjust output.
(IfLetExprConseqIf::as_string): Remove.
(IfLetExprConseqIfLet::as_string): Remove.
(IfLetExprConseqIf::accept_vis): Remove.
(IfLetExprConseqIfLet::accept_vis): Remove.
* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove IfLetExprConseqIf{,Let} visitors.
* ast/rust-ast-dump.cc
(Dump::visit): Likewise.
* ast/rust-ast-dump.h:
(Dump::visit): Likewise.
* ast/rust-ast-tokenstream.cc
(TokenStream::visit): Likewise.
* ast/rust-ast-tokenstream.h
(TokenStream::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h:
(AttributeChecker::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Likewise.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise.
* expand/rust-cfg-strip.cc
(CfgStrip::visit): Likewise.
* expand/rust-cfg-strip.h:
(CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h:
(ASTLoweringBase::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_if_let_expr): Replace IfLetExprConseqIf{,Let} with IfLetExprConseqElse.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: ast: Fix StructExprStruct tokenstream
Pierre-Emmanuel Patry [Wed, 5 Apr 2023 11:45:36 +0000 (13:45 +0200)]
gccrs: ast: Fix StructExprStruct tokenstream

StructExprStructFields inherit from StructExprStruct and shall output
the struct name and curly braces.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add struct
name and curly braces to output tokenstream.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Handle underscore in MacroMatch.
Owen Avery [Fri, 7 Apr 2023 20:47:54 +0000 (16:47 -0400)]
gccrs: Handle underscore in MacroMatch.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_macro_match): Handle underscore.

gcc/testsuite/ChangeLog:

* rust/compile/macro51.rs: New test.

6 months agogccrs: Fully unify deriving classes into HIR::ExprStmt
Owen Avery [Sat, 8 Apr 2023 06:24:03 +0000 (02:24 -0400)]
gccrs: Fully unify deriving classes into HIR::ExprStmt

gcc/rust/ChangeLog:

* hir/tree/rust-hir-full-decls.h
(class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* hir/tree/rust-hir-stmt.h
(class ExprStmt):
Add remaining ExprStmtWith{,out}Block functionality.
(class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* hir/rust-ast-lower-stmt.cc
(ASTLoweringStmt::visit):
Lower to HIR::ExprStmt instead of deriving class.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Unify HIR::ExprStmt derived class visiting
Owen Avery [Sat, 8 Apr 2023 05:37:56 +0000 (01:37 -0400)]
gccrs: Unify HIR::ExprStmt derived class visiting

gcc/rust/ChangeLog:

* backend/rust-compile-stmt.cc
(CompileStmt::visit): Unify ExprStmtWith{,out}Block visitors.
* backend/rust-compile-stmt.h
(CompileStmt::visit): Likewise.
* backend/rust-compile-item.h
(CompileItem::visit): Likewise.
* hir/rust-hir-dump.cc
(Dump::visit): Likewise.
* hir/rust-hir-dump.h
(Dump::visit): Likewise.
* hir/tree/rust-hir-stmt.h
(ExprStmt::accept_vis): Add.
(ExprStmtWithoutBlock::accept_vis): Remove.
(ExprStmtWithBlock::accept_vis): Remove.
* hir/tree/rust-hir.cc
(ExprStmt::accept_vis): Add.
(ExprStmtWithoutBlock::accept_vis): Remove.
(ExprStmtWithBlock::accept_vis): Remove.
* hir/tree/rust-hir-visitor.h
(HIRFullVisitor::visit): Likewise.
(HIRFullVisitorBase::visit): Likewise.
(HIRStmtVisitor::visit): Likewise.
* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Likewise.
* checks/errors/rust-const-checker.h
(ConstChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc
(UnsafeChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.h
(UnsafeChecker::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h
(PrivacyReporter::visit): Likewise.
* checks/lints/rust-lint-marklive.h
(MarkLive::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.cc
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.h
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-tycheck-dump.h
(TypeResolverDump::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Move functionality into HIR::ExprStmt from deriving classes
Owen Avery [Sun, 5 Feb 2023 01:15:52 +0000 (20:15 -0500)]
gccrs: Move functionality into HIR::ExprStmt from deriving classes

And move method as_string into HIR::ExprStmt from deriving classes

gcc/rust/ChangeLog:

* hir/tree/rust-hir-stmt.h
(ExprStmt::expr): Add field.
(ExprStmt::get_expr): Add method.
(ExprStmt::ExprStmt): Add copy/move constructors, modify existing constructor.
(ExprStmt::operator=): Add assignment operator.
(ExprStmtWithoutBlock::expr): Remove field.
(ExprStmtWithoutBlock::get_expr): Remove method.
(ExprStmtWithoutBlock::ExprStmt):
Remove copy/move constructors, modify existing constructor.
(ExprStmtWithoutBlock::operator=): Remove assignment operator.
(ExprStmtWithBlock::expr): Remove field.
(ExprStmtWithBlock::get_expr): Remove method.
(ExprStmtWithBlock::ExprStmt): Remove copy/move constructors, modify existing constructor.
(ExprStmtWithBlock::operator=): Remove assignment operator.
(ExprStmt::as_string): Add method.
(ExprStmtWithBlock::as_string): Remove method.
(ExprStmtWithoutBlock::as_string): Remove method.
* hir/tree/rust-hir.cc
(ExprStmt::as_string): Add method.
(ExprStmtWithBlock::as_string): Remove method.
(ExprStmtWithoutBlock::as_string): Remove method.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Unify AST::IfExprConseqIf{,Let} into AST::IfExprConseqElse
Owen Avery [Thu, 16 Mar 2023 03:05:07 +0000 (23:05 -0400)]
gccrs: Unify AST::IfExprConseqIf{,Let} into AST::IfExprConseqElse

This simplifies the AST's representation of if-statements
to match the HIR.

gcc/rust/ChangeLog:

* ast/rust-expr.h
(class IfExprConseqElse): Make else_block ExprWithBlock.
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* ast/rust-ast-full-decls.h
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* ast/rust-ast.cc
(IfExprConseqElse::as_string): Adjust output.
(IfExprConseqIf::as_string): Remove.
(IfExprConseqIfLet::as_string): Remove.
(IfExprConseqIf::accept_vis): Remove.
(IfExprConseqIfLet::accept_vis): Remove.
* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove IfExprConseqIf{,Let} visitors.
* ast/rust-ast-tokenstream.cc
(TokenStream::visit): Likewise.
* ast/rust-ast-tokenstream.h
(TokenStream::visit): Likewise.
* ast/rust-ast-dump.cc
(Dump::visit): Likewise.
* ast/rust-ast-dump.h
(Dump::visit): Likewise.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h
(AttributeChecker::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Likewise.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-expr.h
(ResolveExpr::visit): Remove IfExprConseqIf visitor.
* resolve/rust-ast-resolve-expr.cc
(ResolveExpr::visit): Likewise.
* expand/rust-cfg-strip.cc
(CfgStrip::visit): Remove IfExprConseqIf{,Let} visitors.
* expand/rust-cfg-strip.h
(CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-block.h
(ASTLoweringIfBlock::visit): Remove IfExprConseqIf visitor.
(ASTLoweringExprWithBlock::visit): Likewise.
* hir/rust-ast-lower.cc
(ASTLoweringIfBlock::visit):
Remove IfExprConseqIf visitor, adjust IfExprConseqElse lowering.
* hir/rust-ast-lower-expr.h
(ASTLoweringExpr::visit): Remove IfExprConseqIf visitor.
* hir/rust-ast-lower-expr.cc
(ASTLoweringExpr::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_if_expr): Replace IfExprConseqIf{,Let} with IfExprConseqElse.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: ast: Fix inner attribute tokenstream
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 16:11:09 +0000 (18:11 +0200)]
gccrs: ast: Fix inner attribute tokenstream

Inner attribute did not output exclamation tokens as there was no way to
differentiate inner from outer attributes previously.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix inner
attribute tokenstream output.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Introduce AST::Visitable class for AST
Marc Poulhiès [Thu, 6 Apr 2023 17:20:55 +0000 (19:20 +0200)]
gccrs: Introduce AST::Visitable class for AST

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>
6 months agogccrs: Placate clang-format, 'gcc/rust/rust-lang.cc:grs_langhook_type_for_mode'
Thomas Schwinge [Tue, 11 Apr 2023 06:47:24 +0000 (08:47 +0200)]
gccrs: Placate clang-format, 'gcc/rust/rust-lang.cc:grs_langhook_type_for_mode'

Yesterday's commit 3757e8d71794cece4a5c9d08245b7ad111044853
"Merge commit '6baa95c9c5b3fea96fd22d03d961db4e4cf48d88' into HEAD [#2112]"
brought in the #1713 change from GCC upstream master branch that broke the
rules (via code copied verbatim from elsehwhere in GCC).

gcc/rust/
* rust-lang.cc (grs_langhook_type_for_mode): Placate clang-format.

6 months agogccrs: ast: Add difference between attributes
Pierre-Emmanuel Patry [Wed, 5 Apr 2023 10:36:41 +0000 (12:36 +0200)]
gccrs: ast: Add difference between attributes

Add a boolean to tell inner and outer attributes ast nodes appart. This
meant refactoring a bit their parsing function.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add boolean for differenciation.
* parse/rust-parse-impl.h (Parser::parse_doc_comment): Change
function interface to make code cleaner. It should return a body
instead of the whole attribute.
(Parser::parse_inner_attribute): Specify the inner status of the
node.
(Parser::parse_attribute_body): Change function interface to
make the code cleaner much like parse_doc_comment.
(Parser::parse_outer_attribute): Specify outer status of the
node.
* parse/rust-parse.h: Update functions prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Support fully qualified calls to trait items from CallExpr's
Philip Herron [Tue, 4 Apr 2023 14:40:26 +0000 (15:40 +0100)]
gccrs: Support fully qualified calls to trait items from CallExpr's

Fixes #2070

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile):
reuse resolve_method_address to monomorphize the call if required
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments):
allow matching against unimplemented trait item bounds

gcc/testsuite/ChangeLog:

* rust/compile/issue-2070.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: never re-setup trait item bound with a dyn object
Philip Herron [Tue, 4 Apr 2023 15:13:18 +0000 (16:13 +0100)]
gccrs: never re-setup trait item bound with a dyn object

It results in a recursive generic Param cycle.

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc: dont subst with a dynamic object

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: refactor resolve_method_address to be inside base class
Philip Herron [Tue, 4 Apr 2023 14:49:20 +0000 (15:49 +0100)]
gccrs: refactor resolve_method_address to be inside base class

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address): moved here
* backend/rust-compile-base.h: refactored prototype
* backend/rust-compile-expr.cc (CompileExpr::resolve_method_address): refactor
* backend/rust-compile-expr.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: remove unused code in query_compile
Philip Herron [Tue, 4 Apr 2023 14:37:33 +0000 (15:37 +0100)]
gccrs: remove unused code in query_compile

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): remove unused

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: cleanup query_compile to reuse destructure call
Philip Herron [Tue, 4 Apr 2023 14:34:03 +0000 (15:34 +0100)]
gccrs: cleanup query_compile to reuse destructure call

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): call destructure

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: cleanup resolve method address
Philip Herron [Tue, 4 Apr 2023 14:24:01 +0000 (15:24 +0100)]
gccrs: cleanup resolve method address

Calling PathProbeImplTrait resolves directly to the trait bound in question
to stop resolving to potentially multiple implementations of that bound

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::resolve_method_address):
call path probe impl trait

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: expand: Add outer attribute expansion on expr
Pierre-Emmanuel Patry [Mon, 3 Apr 2023 10:38:50 +0000 (12:38 +0200)]
gccrs: expand: Add outer attribute expansion on expr

Add additional outer attribute expansion on some expressions.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
to attribute expansion function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: expand: Add builtin attribute identification
Pierre-Emmanuel Patry [Mon, 3 Apr 2023 09:03:37 +0000 (11:03 +0200)]
gccrs: expand: Add builtin attribute identification

Add a function to identify builtin attributes and skip those on proc
macro expansion phase.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit_outer_attrs):
Change condition order.
(ExpandVisitor::visit_inner_using_attrs): Likewise.
(ExpandVisitor::visit_attrs_with_derive): Likewise.
(ExpandVisitor::is_builtin): Add builtin identification
function.
* expand/rust-expand-visitor.h: Add function prototype.
* util/rust-attributes.cc: Add missing rustc_builtin_macro
attribute.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: expand: Add call to outer attributes stubs
Pierre-Emmanuel Patry [Fri, 31 Mar 2023 10:17:04 +0000 (12:17 +0200)]
gccrs: expand: Add call to outer attributes stubs

Add call to outer attribute expansion stub on required types.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::expand_struct_fields):
Add call to expand structu fields.
(ExpandVisitor::expand_function_params): Add call to expand
function parameters.
(ExpandVisitor::expand_closure_params): Add call to expand
closure parameters.
(ExpandVisitor::visit): Add calls for item outer attribute
expansions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: expand: Add stub function for attribute expansion
Pierre-Emmanuel Patry [Thu, 30 Mar 2023 18:40:07 +0000 (20:40 +0200)]
gccrs: expand: Add stub function for attribute expansion

Add a stub function and utility functions that should be called on some
nodes to expand attribute procedural macros.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::expand_outer_attribute):
Stub for a single attribute expansion.
(ExpandVisitor::visit_outer_attrs): Visit the attributes to
expand on a given item.
* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add outer attribute getter to Expr class
Pierre-Emmanuel Patry [Thu, 30 Mar 2023 18:05:14 +0000 (20:05 +0200)]
gccrs: ast: Add outer attribute getter to Expr class

We need to retrieve outer attributes from some Expressions depending on
their context. This means this should be retrieved from their parent
node. But expr did not have a getter for outer attributes since some
expr can't have any outer attribute.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add getter to Expr class.
* ast/rust-expr.h: Add override attribute to existing getters.
Also implement it for RangeExpr, attempting to retrieve outer
attributes on those types will crash the compiler.
* ast/rust-macro.h: Add override attribute to existing getters.
* ast/rust-path.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: expand: Add inner attribute expansion stubs
Pierre-Emmanuel Patry [Thu, 30 Mar 2023 14:35:53 +0000 (16:35 +0200)]
gccrs: expand: Add inner attribute expansion stubs

Add function stubs for inner attribute proc macros expansion.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
to inner attribute stub.
(ExpandVisitor::expand_inner_attribute): Expand one single
attribute.
(ExpandVisitor::visit_inner_using_attrs): Expand a given item
using a vector of attributes.
(ExpandVisitor::visit_inner_attrs): Visit inner attributes of a
given item.
* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: expand: Add derive expansion stubs
Pierre-Emmanuel Patry [Thu, 30 Mar 2023 14:28:12 +0000 (16:28 +0200)]
gccrs: expand: Add derive expansion stubs

Add derive macros expansion stub functions.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
to derive expander.
(ExpandVisitor::expand_derive): Expand a single derive.
(ExpandVisitor::visit_attrs_with_derive): Visit an item with
derive attributes.
(ExpandVisitor::is_derive): Identify a derive attribute.
* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Fix ICE on generic args path
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 17:52:38 +0000 (19:52 +0200)]
gccrs: ast: Fix ICE on generic args path

The path should be retrieved only when a generic arg has either type.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix ICE.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Fix macros in tokenstreams
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 16:22:56 +0000 (18:22 +0200)]
gccrs: ast: Fix macros in tokenstreams

A default token was used as a separator, wich resulted in a wrong token
stream.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Remove
default separator.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Visit crate inner attributes for tokenstreams
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 14:56:00 +0000 (16:56 +0200)]
gccrs: ast: Visit crate inner attributes for tokenstreams

Crate level inner attributes were not visited.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Visit inner
attributes.

6 months agogccrs: ast: Change visibility in token type
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 14:19:51 +0000 (16:19 +0200)]
gccrs: ast: Change visibility in token type

Change the token type from a custom identifier to the reserved token
keyword "in".

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Change token
type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Fix attribute tokenstreams
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 13:56:02 +0000 (15:56 +0200)]
gccrs: ast: Fix attribute tokenstreams

Attributes were not converted to a correct tokenstream, furthermore meta
items containers and token trees attribute arguments were not even
implemented. This commit fix the literal attribute type and implement
both unimplemented types.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix existing
and implement remaining attribute visitors.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Output union's outer attributes
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 11:53:34 +0000 (13:53 +0200)]
gccrs: ast: Output union's outer attributes

Output a union's outer attributes in a tokenstream.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor
to the union's outer attributes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Output inner attributes in tokenstreams
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 10:50:25 +0000 (12:50 +0200)]
gccrs: ast: Output inner attributes in tokenstreams

Inner attributes were not correctly visited.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add call to
inner attribute visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Fix char literal ICE
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 09:54:59 +0000 (11:54 +0200)]
gccrs: ast: Fix char literal ICE

The code was attempting to convert a char to an integer by parsing it
instead of taking it's raw value.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix ICE.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Fix match case comma output
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 09:26:51 +0000 (11:26 +0200)]
gccrs: ast: Fix match case comma output

Even though the comma may be optional with blocks of expressions, it is
mandatory for a single expression alone. By changing this behavior we
ensure a working behavior with any kind of expressions.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Make comma
mandatory.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Fix tokenstream extern block statements
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 09:24:44 +0000 (11:24 +0200)]
gccrs: ast: Fix tokenstream extern block statements

The visitor created some additional semicolon between statements in
extern blocks, this lead to empty statement.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Remove
additional semicolon output.
* ast/rust-ast-tokenstream.h: Change block visitor prototype
with a default value for trailing tokens.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Move pattern implementation out of rust-ast
Pierre-Emmanuel Patry [Mon, 3 Apr 2023 18:44:45 +0000 (20:44 +0200)]
gccrs: ast: Move pattern implementation out of rust-ast

Move rust-pattern implementation out of rust-ast.cc in their own file.

gcc/rust/ChangeLog:

* Make-lang.in: Add two new files to the list of sources.
* ast/rust-ast-full.h: Add new ast formatting header.
* ast/rust-ast.cc (enum indent_mode): Move formatting function
to it's own file.
(indent_spaces): Likewise.
(get_string_in_delims): Likewise.
(enum AttrMode): Likewise.
(get_mode_dump_desc): Likewise.
(append_attributes): Likewise.
(unquote_string): Likewise.
(GroupedExpr::as_string): Move pattern implementation to it's
own file.
(RangePattern::as_string): Likewise.
(RangePatternBoundLiteral::as_string): Likewise.
(SlicePattern::as_string): Likewise.
(AltPattern::as_string): Likewise.
(TuplePatternItemsMultiple::as_string): Likewise.
(TuplePatternItemsRanged::as_string): Likewise.
(TuplePattern::as_string): Likewise.
(StructPatternField::as_string): Likewise.
(StructPatternFieldIdent::as_string): Likewise.
(StructPatternFieldTuplePat::as_string): Likewise.
(StructPatternFieldIdentPat::as_string): Likewise.
(StructPatternElements::as_string): Likewise.
(StructPattern::as_string): Likewise.
(LiteralPattern::as_string): Likewise.
(ReferencePattern::as_string): Likewise.
(IdentifierPattern::as_string): Likewise.
(TupleStructItemsNoRange::as_string): Likewise.
(TupleStructItemsRange::as_string): Likewise.
(TupleStructPattern::as_string): Likewise.
(GroupedExpr::accept_vis): Likewise.
(LiteralPattern::accept_vis): Likewise.
(IdentifierPattern::accept_vis): Likewise.
(WildcardPattern::accept_vis): Likewise.
(RestPattern::accept_vis): Likewise.
(RangePatternBoundLiteral::accept_vis): Likewise.
(RangePatternBoundPath::accept_vis): Likewise.
(RangePatternBoundQualPath::accept_vis): Likewise.
(RangePattern::accept_vis): Likewise.
(ReferencePattern::accept_vis): Likewise.
(StructPatternFieldTuplePat::accept_vis): Likewise.
(StructPatternFieldIdentPat::accept_vis): Likewise.
(StructPatternFieldIdent::accept_vis): Likewise.
(StructPattern::accept_vis): Likewise.
(TupleStructItemsNoRange::accept_vis): Likewise.
(TupleStructItemsRange::accept_vis): Likewise.
(TupleStructPattern::accept_vis): Likewise.
(TuplePatternItemsMultiple::accept_vis): Likewise.
(TuplePatternItemsRanged::accept_vis): Likewise.
(TuplePattern::accept_vis): Likewise.
(GroupedPattern::accept_vis): Likewise.
(SlicePattern::accept_vis): Likewise.
(AltPattern::accept_vis): Likewise.
* ast/rust-ast-formatting.cc: New file.
* ast/rust-ast-formatting.h: New file.
* ast/rust-pattern.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Move rust-path implementation out of rust-ast
Pierre-Emmanuel Patry [Mon, 3 Apr 2023 15:22:57 +0000 (17:22 +0200)]
gccrs: ast: Move rust-path implementation out of rust-ast

Move rust-path implementation details out of rust-ast.cc file. This will
hopefully decrease compile time and make things clearer.

gcc/rust/ChangeLog:

* Make-lang.in: Add new file for rust-path implementation.
* ast/rust-ast.cc (PathInExpression::as_string): Move function
to the new file.
(PathPattern::as_string): Likewise.
(QualifiedPathInExpression::as_string): Likewise.
(ConstGenericParam::as_string): Likewise.
(QualifiedPathInType::as_string): Likewise.
(TypePath::as_string): Likewise.
(PathPattern::convert_to_simple_path): Likewise.
(TypePath::as_simple_path): Likewise.
(PathExprSegment::as_string): Likewise.
(GenericArgs::as_string): Likewise.
(GenericArgsBinding::as_string): Likewise.
(TypePath::to_trait_bound): Likewise.
(TypePathSegmentGeneric::as_string): Likewise.
(TypePathFunction::as_string): Likewise.
(TypePathSegmentFunction::as_string): Likewise.
(ConstGenericParam::accept_vis): Likewise.
(PathInExpression::accept_vis): Likewise.
(TypePathSegment::accept_vis): Likewise.
(TypePathSegmentGeneric::accept_vis): Likewise.
(TypePathSegmentFunction::accept_vis): Likewise.
(TypePath::accept_vis): Likewise.
(QualifiedPathInExpression::accept_vis): Likewise.
(QualifiedPathInType::accept_vis): Likewise.
(GenericArg::disambiguate_to_const): Likewise.
(GenericArg::disambiguate_to_type): Likewise.
* ast/rust-path.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Fix ICE using constructors for intilizers in statics
Philip Herron [Sun, 2 Apr 2023 20:59:50 +0000 (21:59 +0100)]
gccrs: Fix ICE using constructors for intilizers in statics

We are getting constant expressions for the initilizers for static items
this hits an assertion in the GCC middle-end which is looking for a
constructor so we need to unwrap the constant expression using DECL_INITIAL
as the initilizer to the global static.

Fixes #2080

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): unwrap the constant expression

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-2080.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Handle "fn" and "fn_mut" lang items
Owen Avery [Mon, 3 Apr 2023 22:52:23 +0000 (18:52 -0400)]
gccrs: Handle "fn" and "fn_mut" lang items

gcc/rust/ChangeLog:

* util/rust-lang-item.h
(RustLangItem::ItemType::FN): Add.
(RustLangItem::ItemType::FN_MUT): Add.
(RustLangItem::Parse): Handle FN and FN_MUT.
(RustLangItem::ToString): Handle FN and FN_MUT.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Fix bad cast as a char
Emanuele Micheletti [Fri, 31 Mar 2023 10:50:36 +0000 (12:50 +0200)]
gccrs: Fix bad cast as a char

In rust cast to char is allowed only from u8 type.
This patch handles fix the case when the type is infered from an integer value,
allowing only the u8 case'

Fixes #2027

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::cast_rules):
case INTEGRAL handles TypeKind::CHAR

gcc/testsuite/ChangeLog:

* rust/compile/cast5.rs: New test.

Signed-off-by: Emanuele Micheletti <micheletti.emanuele@hotmail.com>
6 months agogccrs: Fix handling of generic arguments for lifetimes only
Philip Herron [Wed, 29 Mar 2023 12:35:53 +0000 (13:35 +0100)]
gccrs: Fix handling of generic arguments for lifetimes only

We might have generics that are only for lifetimes this is a bad error
check. We can simply rely on the function to marshall the HIR generics
arguements for the type system to do the error handling for us which will
be more acurate anyway.

Fixes #2043 #2039

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
add check for reference marker and type's in self params
(ResolveItem::visit): likewise
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path):
remove bad generics check
(TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): likewise

gcc/testsuite/ChangeLog:

* rust/compile/const_generics_5.rs: update test case
* rust/compile/issue-2043.rs: New test.
* rust/compile/issue-2039.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: add missing name resolution to self params with specified types
Philip Herron [Wed, 29 Mar 2023 13:24:12 +0000 (14:24 +0100)]
gccrs: add missing name resolution to self params with specified types

In rust it is possible to write method where you explicitly specify the
type of a self param. It does not however allow for you to use reference
destructuring in this senario.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc
(ResolveTraitItems::visit): add name resolution self param
(ResolveItem::visit): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: make distinction between error and empty for substution args
Philip Herron [Wed, 29 Mar 2023 14:00:39 +0000 (15:00 +0100)]
gccrs: make distinction between error and empty for substution args

When handling generics of only lifetimes we have an empty
SubstitutionArgumentMappings which was being detected as an error but this
is not the case as we don't currently handle const generics or generic
lifetimes so this makes the distinction between an error occurred or its
simply empty because it was all only lifetime arguments and we don't care
about it.

Addresses #2043 #2039

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): this is an empty
(TypeBoundPredicate::operator=): likewise
* typecheck/rust-tyty-subst.cc (SubstitutionArgumentMappings::empty): new interface
(SubstitutionArgumentMappings::is_error): this marks it as an error
* typecheck/rust-tyty-subst.h: update prototypes

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: privacy reporter should be permissive of error types
Philip Herron [Wed, 29 Mar 2023 13:01:34 +0000 (14:01 +0100)]
gccrs: privacy reporter should be permissive of error types

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::check_base_type_privacy): allow error types to be permissive

Signed-off-by: Philip Herron <herron.philip@googlemail.com>a
6 months agogccrs: ast: Fix various TokenStream visitors
Pierre-Emmanuel Patry [Tue, 28 Mar 2023 07:56:52 +0000 (09:56 +0200)]
gccrs: ast: Fix various TokenStream visitors

TokenStream visitors still have many issues, this commit fixes some of
them.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit_items_as_lines):
Handle trailing chars.
(TokenStream::visit_items_as_block): Likewise.
(TokenStream::visit): Fix visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: token: Add type hints to string dump
Pierre-Emmanuel Patry [Mon, 27 Mar 2023 13:41:47 +0000 (15:41 +0200)]
gccrs: token: Add type hints to string dump

The conversion to string of any known type literal was not giving back
any type hint, not even quotes for string. This commit fix this.

gcc/rust/ChangeLog:

* lex/rust-token.cc (Token::as_string): Add type hint output.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: session: Add tokenstream dump option
Pierre-Emmanuel Patry [Mon, 27 Mar 2023 11:09:34 +0000 (13:09 +0200)]
gccrs: session: Add tokenstream dump option

Add an option to the command line interface to dump the ast back to a
tokenstream.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::enable_dump): Enable new
dump.
(Session::compile_crate): CLI argument parsing.
(Session::dump_tokenstream): Dump the tokenstream as a string in
the specified file.
* rust-session-manager.h (struct CompileOptions): Add
tokenstream dump option.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: lex: Add source code token string representation
Pierre-Emmanuel Patry [Mon, 27 Mar 2023 10:54:53 +0000 (12:54 +0200)]
gccrs: lex: Add source code token string representation

Add a new representation for tokens which should reflect the string
token as it could be found in the original source.

gcc/rust/ChangeLog:

* lex/rust-token.cc (Token::as_string): Add as_string
implementation.
* lex/rust-token.h: Add as_string prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add missing constructor implementation
Pierre-Emmanuel Patry [Mon, 27 Mar 2023 10:53:29 +0000 (12:53 +0200)]
gccrs: ast: Add missing constructor implementation

Add a missing constructor implementation for TokenStream objects.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::TokenStream): Add
constructor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add TokenStream collect function
Pierre-Emmanuel Patry [Fri, 24 Mar 2023 11:39:48 +0000 (12:39 +0100)]
gccrs: ast: Add TokenStream collect function

Add a function to TokenStream to collect in a single vector all tokens.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::collect_tokens): Add
getter.
(TokenStream::go): Rename function.
(TokenStream::visit): Likewise.
* ast/rust-ast-tokenstream.h: Add collect prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Refactor SimplePath attribute name
Pierre-Emmanuel Patry [Fri, 24 Mar 2023 10:42:19 +0000 (11:42 +0100)]
gccrs: ast: Refactor SimplePath attribute name

The getter name was overly complicated and long, this could be
refactored to a shorter name.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Change
getter name.
* ast/rust-ast.cc (SimplePath::as_string): Change attribute
name.
* ast/rust-ast.h (class SimplePath): Refactor attribute name and
change getter name.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add multiple formatting stub functions
Pierre-Emmanuel Patry [Thu, 23 Mar 2023 19:30:53 +0000 (20:30 +0100)]
gccrs: ast: Add multiple formatting stub functions

Add multiple stub functions depending on the context. This will allow an
easier unification of ast dump.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit_as_line): Add
formatting calls.
(TokenStream::visit_items_as_block): Likewise.
(TokenStream::newline): Add stub.
(TokenStream::indentation): Add stub.
(TokenStream::increment_indentation): Add stub.
(TokenStream::decrement_indentation): Add stub.
(TokenStream::visit): Add formatting calls.
(TokenStream::visit_function_common): Likewise.
* ast/rust-ast-tokenstream.h: Add stub prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add AltPattern TokenStream visitor
Pierre-Emmanuel Patry [Thu, 23 Mar 2023 18:30:51 +0000 (19:30 +0100)]
gccrs: ast: Add AltPattern TokenStream visitor

Add TokenStream visitor implementation for AltPattern.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add Meta items TokenStream visitor
Pierre-Emmanuel Patry [Thu, 23 Mar 2023 18:24:59 +0000 (19:24 +0100)]
gccrs: ast: Add Meta items TokenStream visitor

Add visitor implementation for all remaining meta items.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor
implementation.
* ast/rust-ast-tokenstream.h: Add additional function prototype.
* ast/rust-item.h: Add some getters.
* ast/rust-macro.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add use declarations TokenStream visitors
Pierre-Emmanuel Patry [Thu, 23 Mar 2023 15:46:51 +0000 (16:46 +0100)]
gccrs: ast: Add use declarations TokenStream visitors

Add UseDeclaration (and it's childrens) visitor implementation.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor.
* ast/rust-item.h: Add missing getters.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add ExternCrate TokenStream visitor
Pierre-Emmanuel Patry [Thu, 23 Mar 2023 15:45:35 +0000 (16:45 +0100)]
gccrs: ast: Add ExternCrate TokenStream visitor

Add a visitor implementation for ExternCrate declarations.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Implement remaining expr TokenStream visitor
Pierre-Emmanuel Patry [Thu, 23 Mar 2023 10:02:47 +0000 (11:02 +0100)]
gccrs: ast: Implement remaining expr TokenStream visitor

Implement the missing expression functions visitors for TokenStream.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add
visitors.
(TokenStream::visit_closure_common): Merge common code for
closure visitors.
* ast/rust-ast-tokenstream.h: Add function prototype.
* ast/rust-expr.h: Add missing move attribute getter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add Tokenstream visitors for loop expressions
Pierre-Emmanuel Patry [Wed, 22 Mar 2023 15:17:42 +0000 (16:17 +0100)]
gccrs: ast: Add Tokenstream visitors for loop expressions

Add the implementation of tokenstream dump for multiple loop
expressions.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add
visitors.
(TokenStream::visit_loop_common): Merge common loop code.
* ast/rust-ast-tokenstream.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add some expr TokenStream visitors
Pierre-Emmanuel Patry [Wed, 22 Mar 2023 13:44:05 +0000 (14:44 +0100)]
gccrs: ast: Add some expr TokenStream visitors

Implement some TokenStream expression visitor functions.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Implement
visitor.
* ast/rust-ast-tokenstream.h: Add function prototype for missing
component.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add trailing comma formatting option
Pierre-Emmanuel Patry [Wed, 22 Mar 2023 13:39:34 +0000 (14:39 +0100)]
gccrs: ast: Add trailing comma formatting option

Add an option to output trailing commas depending on the configuration
of the TokenStream.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::trailing_comma):
Output a trailing comma to the token stream according to the
configuration.
* ast/rust-ast-tokenstream.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Implement TokenStream visitor for meta nodes
Pierre-Emmanuel Patry [Wed, 22 Mar 2023 12:27:50 +0000 (13:27 +0100)]
gccrs: ast: Implement TokenStream visitor for meta nodes

Implement TokenStream visitor on some Meta container nodes.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Implement
visitors.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Refactor and add some Path node visitors
Pierre-Emmanuel Patry [Wed, 22 Mar 2023 12:20:31 +0000 (13:20 +0100)]
gccrs: ast: Refactor and add some Path node visitors

Implement some functions for Path nodes and refactor existing ones by
merging some common code.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Implement
visitors.
* ast/rust-ast-tokenstream.h: Add function prototypes.
* ast/rust-ast.h: Add missing getters.
* ast/rust-expr.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Add conversion to token stream
Pierre-Emmanuel Patry [Tue, 21 Mar 2023 09:39:51 +0000 (10:39 +0100)]
gccrs: ast: Add conversion to token stream

Add several functions to convert an ast back to a token stream. This may
be used later either to unify the ast dumping and modifications on ast
nodes in procedural macros.

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-as-tokenstream to compile list.
* ast/rust-item.h: Add missing getter for location.
* ast/rust-ast-tokenstream.cc: Add ast visitor implementation.
* ast/rust-ast-tokenstream.h: New file.
* ast/rust-pattern.h: Add getter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This page took 0.198219 seconds and 5 git commands to generate.