]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
18 months agogccrs: Create base class AssociatedItem
Owen Avery [Wed, 11 Oct 2023 16:58:27 +0000 (12:58 -0400)] 
gccrs: Create base class AssociatedItem

gcc/rust/ChangeLog:

* ast/rust-ast.h
(class AssociatedItem):
New, based on TraitItem, InherentImplItem, and TraitImplItem classes.
(class TraitItem): Inherit from AssociatedItem.
(class InherentImplItem): Likewise.
(class TraitImplItem): Likewise.
* ast/rust-item.h
(class Method): Update cloning functions.
(class Function): Likewise.
(class TypeAlias): Likewise.
(class ConstantItem): Likewise.
(class TraitItemFunc): Likewise.
(class TraitItemMethod): Likewise.
(class TraitItemConst): Likewise.
(class TraitItemType): Likewise.
* ast/rust-macro.h
(class MacroInvocation): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add tests for v0 mangling
Raiki Tamura [Fri, 22 Sep 2023 10:39:21 +0000 (19:39 +0900)] 
gccrs: Add tests for v0 mangling

gcc/rust/ChangeLog:

* backend/rust-mangle.cc (v0_identifier): Fix broken encoding.
(v0_scope_path): Modify paramter.
(v0_path): Fix namespace for modules.

gcc/testsuite/ChangeLog:

* rust/compile/v0-mangle1.rs: New test.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: Add new test for closure in closure parsing
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 12:16:52 +0000 (14:16 +0200)] 
gccrs: Add new test for closure in closure parsing

This new test highlight the fix of #2656.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Break OR tokens in closure parameter list context
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 12:06:30 +0000 (14:06 +0200)] 
gccrs: Break OR tokens in closure parameter list context

The parser was unable to process as closure inside a closure because the
lexer could not differentiate an OR from two PIPE tokens.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_closure_expr_pratt): Fix
closure parsing function to handle consecutive parameter lists.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add new regression test for macro matcher behavior
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 08:41:06 +0000 (10:41 +0200)] 
gccrs: Add new regression test for macro matcher behavior

Add a new test to highlight the fix introduced for #2653.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add path to macro fragment follow restrictions
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 08:29:35 +0000 (10:29 +0200)] 
gccrs: Add path to macro fragment follow restrictions

The previous follow set rules did not allow PATH fragment, changing this
allow gccrs to accept more valid rust macros.

gcc/rust/ChangeLog:

* ast/rust-macro.h: Add PATH fragment to follow set restrictions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add a new test for mbe named macro_rules
Pierre-Emmanuel Patry [Tue, 17 Oct 2023 12:56:09 +0000 (14:56 +0200)] 
gccrs: Add a new test for mbe named macro_rules

Macro rules named macro_rules may cause some problems if not handled
correctly. This new test ensure we always compile those macros named
macro_rules correctly as well as other macro definitions.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add new regression test
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 14:03:45 +0000 (16:03 +0200)] 
gccrs: Add new regression test

This new test highlight the fix for #2651.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Allow macro named macro_rules
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 13:46:48 +0000 (15:46 +0200)] 
gccrs: Allow macro named macro_rules

Change the constraints around macro rules declaration in order to allow
macro_rules named macro as well as tighter constraint around macro rules
definitions.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::is_macro_rules_def): Add a function
that checks tokens given by the lexer represents an accurate macro
definition. This will reduce code duplication.
(Parser::parse_item): Replace condition with call to new checking
function.
(Parser::parse_stmt): Likewise.
* parse/rust-parse.h: Add function prototype for is_macro_rules_def.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add new regression test
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 12:21:42 +0000 (14:21 +0200)] 
gccrs: Add new regression test

Add a new test to highlight fix of #2658.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add a new regression test
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 11:20:33 +0000 (13:20 +0200)] 
gccrs: Add a new regression test

Add a new test to highlight the fix made for #2660.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Fix RangeFromExpr parsing in for loops
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 11:11:55 +0000 (13:11 +0200)] 
gccrs: Fix RangeFromExpr parsing in for loops

Those ranges were looking for a curly brace after the brace, leading
to an error when using range from expr in for loops.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_expr): Fix range from expr.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add a new regression test for macro call "default"
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 12:53:39 +0000 (14:53 +0200)] 
gccrs: Add a new regression test for macro call "default"

This test highlight the fix required for #2655.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Allow call to macro named "default" at item level
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 12:36:35 +0000 (14:36 +0200)] 
gccrs: Allow call to macro named "default" at item level

The parser was too agressive and did reject any line beginning with
default even if this was a macro call.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_item): Relax constraints
around default identifier at item scope to accept "default" macros.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add a new regression test
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 08:21:16 +0000 (10:21 +0200)] 
gccrs: Add a new regression test

New regression test to highlight behavior of #2652.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Fix path expr segment parsing with generic path
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 08:04:57 +0000 (10:04 +0200)] 
gccrs: Fix path expr segment parsing with generic path

When a token was identified as bit left shift it slipped through the
parser and resulted in an error.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_path_expr_segment): Accept
left shift tokens in order to let generic parsing function split the
token.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Replace get_pattern_node_id with get_node_id
Owen Avery [Wed, 11 Oct 2023 02:50:55 +0000 (22:50 -0400)] 
gccrs: Replace get_pattern_node_id with get_node_id

gcc/rust/ChangeLog:

* ast/rust-ast.h
(Pattern::get_pattern_node_id): Rename to...
(Pattern::get_node_id): ...here.
* ast/rust-macro.h
(MacroInvocation::get_pattern_node_id): Rename to...
(MacroInvocation::get_node_id): ...here.
* ast/rust-path.h
(PathInExpression::get_pattern_node_id): Remove.
(QualifiedPathInExpression::get_pattern_node_id): Remove.
* ast/rust-pattern.h
(LiteralPattern::get_pattern_node_id): Remove.
(IdentifierPattern::get_pattern_node_id): Remove.
(WildcardPattern::get_pattern_node_id): Remove.
(RestPattern::get_pattern_node_id): Rename to...
(RestPattern::get_node_id): ...here.
(RangePattern::get_pattern_node_id): Remove.
(ReferencePattern::get_pattern_node_id): Remove.
(StructPattern::get_pattern_node_id): Remove.
(TupleStructPattern::get_pattern_node_id): Remove.
(TuplePattern::get_pattern_node_id): Remove.
(GroupedPattern::get_pattern_node_id): Remove.
(SlicePattern::get_pattern_node_id): Remove.
(AltPattern::get_pattern_node_id): Remove.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit):
Use get_node_id instead of get_pattern_node_id.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add regression test
Pierre-Emmanuel Patry [Wed, 11 Oct 2023 12:40:18 +0000 (14:40 +0200)] 
gccrs: Add regression test

This new test highlight the fix for issue #2657.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add comma for expr delimiter to fix match arms
Pierre-Emmanuel Patry [Wed, 11 Oct 2023 12:31:25 +0000 (14:31 +0200)] 
gccrs: Add comma for expr delimiter to fix match arms

Add a comma as an expr delimiter, this will allow correct parsing of
match arm expressions.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_expr): Add comma delimiter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add regression test
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 09:41:27 +0000 (11:41 +0200)] 
gccrs: Add regression test

Add a new test to highlight fix for #2648.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Fix pub unit type parsing
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 09:28:34 +0000 (11:28 +0200)] 
gccrs: Fix pub unit type parsing

Public unit types where not parsed correctly due to visibility specifiers
within parenthesis. Fixes #2648.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_visibility): Relax constraints
over public visibility return condition in order to accept pub unit
types.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: TyTy: use new subclass API
Jakub Dupak [Thu, 5 Oct 2023 10:36:08 +0000 (12:36 +0200)] 
gccrs: TyTy: use new subclass API

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::is_unit): Refactor.
(BaseType::satisfies_bound): Refactor.
(BaseType::get_root): Refactor.
(BaseType::destructure): Refactor.
(BaseType::monomorphized_clone): Refactor.
(BaseType::is_concrete): Refactor.
(InferType::InferType): Refactor.
(InferType::clone): Refactor.
(InferType::apply_primitive_type_hint): Refactor.
(StructFieldType::is_equal): Refactor.
(ADTType::is_equal): Refactor.
(handle_substitions): Refactor.
(ADTType::handle_substitions): Refactor.
(TupleType::TupleType): Refactor.
(TupleType::is_equal): Refactor.
(TupleType::handle_substitions): Refactor.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
18 months agogccrs: TyTy: TyTy improved subclass casting and checking
Jakub Dupak [Tue, 3 Oct 2023 14:14:39 +0000 (16:14 +0200)] 
gccrs: TyTy: TyTy improved subclass casting and checking

Associate each subclass with its kind and create cast/match+cast
methods.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (InferType::InferType): Use static constant for kind information.
(ErrorType::ErrorType): Use static constant for kind information.
(TupleType::TupleType): Use static constant for kind information.
(BoolType::BoolType): Use static constant for kind information.
(IntType::IntType): Use static constant for kind information.
(UintType::UintType): Use static constant for kind information.
(FloatType::FloatType): Use static constant for kind information.
(USizeType::USizeType): Use static constant for kind information.
(ISizeType::ISizeType): Use static constant for kind information.
(CharType::CharType): Use static constant for kind information.
(ReferenceType::ReferenceType): Use static constant for kind information.
(PointerType::PointerType): Use static constant for kind information.
(ParamType::ParamType): Use static constant for kind information.
(StrType::StrType): Use static constant for kind information.
(NeverType::NeverType): Use static constant for kind information.
(PlaceholderType::PlaceholderType): Use static constant for kind information.
* typecheck/rust-tyty.h: Add static kind information to all TyTy classes.
Create safe cast and check methods.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
18 months agogccrs: Add a regression test for global path parsing
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 08:37:18 +0000 (10:37 +0200)] 
gccrs: Add a regression test for global path parsing

Add a new test to highlight fix for #2649.

gcc/testsuite/ChangeLog:

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

18 months agogccrs: Fix type param bound parsing with opening scope
Pierre-Emmanuel Patry [Mon, 9 Oct 2023 12:46:55 +0000 (14:46 +0200)] 
gccrs: Fix type param bound parsing with opening scope

The function parsing type param bounds had a problem with scope
resolution opening token.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_type_param_bound): Add missing
case for lifetime switch.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Change debug log call to as_string function
Pierre-Emmanuel Patry [Mon, 9 Oct 2023 11:06:22 +0000 (13:06 +0200)] 
gccrs: Change debug log call to as_string function

This will ensure an accurate representation of the token. Also update the
as_string function to represent accurately scope resolution tokens.

gcc/rust/ChangeLog:

* lex/rust-token.cc (Token::as_string): Update function to output scope
resolution tokens correctly.
* parse/rust-parse-impl.h (Parser::parse_generic_param): Change call to
as_string.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Initial implementation of v0 mangling
Raiki Tamura [Tue, 8 Aug 2023 08:13:29 +0000 (17:13 +0900)] 
gccrs: Initial implementation of v0 mangling

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: Modify declaration.
* backend/rust-mangle.cc (struct V0Path): New struct.
(v0_path): New function.
(legacy_mangle_name): Take Context as argument.
(v0_numeric_prefix): Fix type strings.
(v0_complex_type_prefix): New function.
(v0_add_integer_62): Deleted
(v0_integer_62): New function.
(v0_add_opt_integer_62): Deleted.
(v0_opt_integer_62): New function.
(v0_add_disambiguator): Deleted.
(v0_disambiguator): New function.
(v0_type_prefix): Support more types.
(v0_generic_args): New function.
(v0_add_identifier): Deleted.
(v0_identifier): New function.
(v0_type_path): New function.
(v0_function_path): New function.
(v0_scope_path): New function.
(v0_crate_path): New function.
(v0_inherent_or_trait_impl_path): New function.
(v0_mangle_item): Use v0_path.
(Mangler::mangle_item): Take Context as argument.
* backend/rust-mangle.h (class Context): Add forward declaration.
* hir/tree/rust-hir-item.h: Fix include.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: Rename cloning methods in TupleStructItems and TuplePatternItems
Owen Avery [Sat, 7 Oct 2023 03:16:41 +0000 (23:16 -0400)] 
gccrs: Rename cloning methods in TupleStructItems and TuplePatternItems

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(TupleStructItems::clone_tuple_struct_items_impl): Rename to...
(TupleStructItems::clone_tuple_items_impl): ...here.
(TupleStructItemsNoRange::clone_tuple_struct_items_impl): Rename to...
(TupleStructItemsNoRange::clone_tuple_items_impl): ...here.
(TupleStructItemsRange::clone_tuple_struct_items_impl): Rename to...
(TupleStructItemsRange::clone_tuple_items_impl): ...here.

(TuplePatternItems::clone_tuple_pattern_items_impl): Rename to...
(TuplePatternItems::clone_tuple_items_impl): ...here.
(TuplePatternItemsMultiple::clone_tuple_pattern_items_impl): Rename to...
(TuplePatternItemsMultiple::clone_tuple_items_impl): ...here.
(TuplePatternItemsRanged::clone_tuple_pattern_items_impl): Rename to...
(TuplePatternItemsRanged::clone_tuple_items_impl): ...here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Adjust methods for TuplePatternItems to match TupleStructItems
Owen Avery [Tue, 3 Oct 2023 21:56:33 +0000 (17:56 -0400)] 
gccrs: Adjust methods for TuplePatternItems to match TupleStructItems

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(TuplePatternItems::get_pattern_type): Rename to...
(TuplePatternItems::get_item_type): ...here.
(TuplePatternItemsMultiple::get_pattern_type): Rename to...
(TuplePatternItemsMultiple::get_item_type): ...here.
(TuplePatternItemsRanged::get_pattern_type): Rename to...
(TuplePatternItemsRanged::get_item_type): ...here.

* backend/rust-compile-expr.cc: Adjust calls to renamed methods.
* backend/rust-compile-pattern.cc: Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: minor changes (typo and minor refactor)
Marc Poulhiès [Fri, 13 Oct 2023 22:02:47 +0000 (00:02 +0200)] 
gccrs: minor changes (typo and minor refactor)

Fix a typo and merge 2 if clauses using the same condition.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Merge 2 if clauses.
* backend/rust-compile-extern.h: Fix typo in comment.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: Add test for parser bug
Jakub Dupak [Thu, 5 Oct 2023 12:52:24 +0000 (14:52 +0200)] 
gccrs: Add test for parser bug

gcc/testsuite/ChangeLog:

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

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
18 months agogccrs: Fix parser bug on tupplestruct pattern
Jakub Dupak [Thu, 5 Oct 2023 10:10:37 +0000 (12:10 +0200)] 
gccrs: Fix parser bug on tupplestruct pattern

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h: Add missing token consumption

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
18 months agogccrs: Removed unnecessary comments
Mohammed Rizan Farooqui [Wed, 4 Oct 2023 08:19:24 +0000 (13:49 +0530)] 
gccrs: Removed unnecessary comments

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::include_str_handler): Comment removed
(MacroBuiltin::env_handler): Comment removed
(MacroBuiltin::cfg_handler): Comment removed
(MacroBuiltin::line_handler): Comment removed

Signed-off-by: Mohammed Rizan Farooqui <rizanfarooqui@gmail.com>
18 months agogccrs: Fix type confusion in coercion
Jakub Dupak [Mon, 2 Oct 2023 19:54:16 +0000 (21:54 +0200)] 
gccrs: Fix type confusion in coercion

There was a mismatch between a manual discriminant test and the static cast.

gcc/rust/ChangeLog:

* backend/rust-compile.cc (HIRCompileBase::coercion_site1): Fix wrong cast

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
18 months agogccrs: Fix ICE when emitting an error during cfg strip
Pierre-Emmanuel Patry [Tue, 26 Sep 2023 12:49:10 +0000 (14:49 +0200)] 
gccrs: Fix ICE when emitting an error during cfg strip

When an error was emitted during the cfg strip pass by the crate loader,
it was ignored and the error state propagated until another pass
(name resolver).

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::expansion): Add early break on
error.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Fix CanonicalPath for inherent impl
Raiki Tamura [Wed, 20 Sep 2023 04:42:02 +0000 (13:42 +0900)] 
gccrs: Fix CanonicalPath for inherent impl

gcc/rust/ChangeLog:

* util/rust-canonical-path.h: Add new segment kind for inherent impl.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Use it.
* resolve/rust-ast-resolve-toplevel.h: Use it.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: Fix spelling
Owen Avery [Tue, 19 Sep 2023 15:48:02 +0000 (11:48 -0400)] 
gccrs: Fix spelling

gcc/rust/ChangeLog:

* ast/rust-expr.h: Fix spelling of "doesn't".
* backend/rust-compile-expr.cc: Fix spelling of "accessors".
* backend/rust-compile-implitem.h: Fix spelling of "normal".
* backend/rust-constexpr.cc: Fix spelling of "actual".

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add debug helper to dump HIR
Marc Poulhiès [Mon, 18 Sep 2023 20:16:06 +0000 (22:16 +0200)] 
gccrs: Add debug helper to dump HIR

Add simple debug wrapper to dump HIR nodes on stderr.
Similar to what we already have for AST.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::debug): New.
(debug): New.
* hir/rust-hir-dump.h (debug): New.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: port over readonly_error from c-family for lvalue assignment checks
Philip Herron [Sun, 17 Sep 2023 19:11:23 +0000 (20:11 +0100)] 
gccrs: port over readonly_error from c-family for lvalue assignment checks

Fixes #2391

gcc/rust/ChangeLog:

* Make-lang.in: fixup formatting
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): remove old check
* rust-session-manager.cc (Session::compile_crate): call new lint
* resolve/rust-ast-verify-assignee.h: Removed.
* checks/errors/rust-readonly-check.cc: New file.
* checks/errors/rust-readonly-check.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/wrong_lhs_assignment.rs: update error message
* rust/compile/issue-2391.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: [E0617] attempt for invalid type variable in variadic function
Muhammad Mahad [Sun, 17 Sep 2023 11:58:51 +0000 (16:58 +0500)] 
gccrs: [E0617] attempt for invalid type variable in variadic function

There are some certain rust types must be cast before
passing them to a variadic function, because of arcane
ABI rules dictated by the C standard. To fix the error,
cast the value to the type specified by the error message.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
Added ErrorCode & more fixit hints.

gcc/testsuite/ChangeLog:

* rust/compile/variadic.rs: Added new checks.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Remove HIR::ForLoopExpr
Philip Herron [Sun, 17 Sep 2023 14:08:42 +0000 (15:08 +0100)] 
gccrs: Remove HIR::ForLoopExpr

This will end up getting desugared into a LoopExpr with a MatchExpr body.

gcc/rust/ChangeLog:

* backend/rust-compile-block.h: remove HIR::ForLoopExpr
* backend/rust-compile-expr.h: likewise
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): likewise
* checks/errors/privacy/rust-privacy-reporter.h: likewise
* checks/errors/rust-const-checker.cc (ConstChecker::visit): likewise
* checks/errors/rust-const-checker.h: likewise
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): likewise
* checks/errors/rust-unsafe-checker.h: likewise
* checks/lints/rust-lint-marklive.h: likewise
* hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): likewise
* hir/rust-hir-dump.cc (Dump::visit): likewise
* hir/rust-hir-dump.h: likewise
* hir/tree/rust-hir-expr.h (class ForLoopExpr): likewise
* hir/tree/rust-hir-full-decls.h (class ForLoopExpr): likewise
* hir/tree/rust-hir-visitor.h: likewise
* hir/tree/rust-hir.cc (ForLoopExpr::as_string): likewise
(ForLoopExpr::accept_vis): likewise
* typecheck/rust-hir-type-check-expr.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Minor typo fix
Marc Poulhiès [Sat, 16 Sep 2023 21:31:34 +0000 (23:31 +0200)] 
gccrs: Minor typo fix

Fix varadic -> variadic

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Fix typo in varIadic.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise.
* rust-backend.h (function_type_varadic): Rename into ...
(function_type_variadic): ... this.
* rust-gcc.cc (function_type_varadic): Rename into ...
(function_type_variadic): ... this.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise.
* typecheck/rust-tyty.h (is_varadic): Renamed into ...
(is_variadic): ... this.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: Add license text to libproc_macro rust interface
Pierre-Emmanuel Patry [Mon, 11 Sep 2023 10:13:01 +0000 (12:13 +0200)] 
gccrs: Add license text to libproc_macro rust interface

The license text was missing in rust files producing the libproc_macro
interface to the libproc_macro_internal library.

libgrust/ChangeLog:

* libproc_macro/bridge.rs: Add license text.
* libproc_macro/bridge/ffistring.rs: Likewise.
* libproc_macro/bridge/group.rs: Likewise.
* libproc_macro/bridge/ident.rs: Likewise.
* libproc_macro/bridge/literal.rs: Likewise.
* libproc_macro/bridge/punct.rs: Likewise.
* libproc_macro/bridge/span.rs: Likewise.
* libproc_macro/bridge/token_stream.rs: Likewise.
* libproc_macro/group.rs: Likewise.
* libproc_macro/ident.rs: Likewise.
* libproc_macro/lib.rs: Likewise.
* libproc_macro/literal.rs: Likewise.
* libproc_macro/punct.rs: Likewise.
* libproc_macro/span.rs: Likewise.
* libproc_macro/token_stream.rs: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: trivial typo fix.
Marc Poulhiès [Thu, 14 Sep 2023 21:24:26 +0000 (23:24 +0200)] 
gccrs: trivial typo fix.

Fix subsititions -> substitutions

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::compile_function):
Fix typo in substitutions.
(HIRCompileBase::resolve_method_address): Likewise.
* backend/rust-compile-extern.h (CompileExternItem::visit):
Likewise.
* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Likewise.
* backend/rust-compile-intrinsic.cc (maybe_override_ctx):
Likewise.
* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
* backend/rust-compile-resolve-path.cc
(HIRCompileBase::query_compile): Likewise.
* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion):
Likewise.
* typecheck/rust-hir-type-check-item.cc
(TypeCheckItem::ResolveImplBlockSelfWithInference): Likewise.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit):
Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit):
Likewise.
* typecheck/rust-tyty.cc (BaseType::has_subsititions_defined):
Renamed into ...
(BaseType::has_substitutions_defined): ... this.
(ADTType::is_equal): Fix typo in substitutions.
(handle_substitions): Likewise.
(FnType::is_equal): Likewise.
(FnType::handle_substitions): Likewise.
* typecheck/rust-tyty.h (has_subsititions_defined): Renamed into
...
(has_substitutions_defined): ... this.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: Add intrinsics::assume
Owen Avery [Wed, 13 Sep 2023 16:32:33 +0000 (12:32 -0400)] 
gccrs: Add intrinsics::assume

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc
(get_identifier): Add declaration.
(assume_handler): New.
(generic_intrinsics): Add assume_handler entry.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Memoize Backend::wchar_type
Owen Avery [Tue, 12 Sep 2023 16:52:25 +0000 (12:52 -0400)] 
gccrs: Memoize Backend::wchar_type

gcc/rust/ChangeLog:

* rust-gcc.cc
(Backend::wchar_type): Store static wchar tree.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Remove unused complex number support
Owen Avery [Wed, 13 Sep 2023 01:42:01 +0000 (21:42 -0400)] 
gccrs: Remove unused complex number support

gcc/rust/ChangeLog:

* rust-backend.h
(complex_type): Remove.
(complex_constant_expression): Remove.
(real_part_expression): Remove.
(imag_part_expression): Remove.
(complex_expression): Remove.
* rust-gcc.cc
(complex_type): Remove.
(complex_constant_expression): Remove.
(real_part_expression): Remove.
(imag_part_expression): Remove.
(complex_expression): Remove.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Use namespace definition to simplify function declarations
Owen Avery [Thu, 7 Sep 2023 23:07:52 +0000 (19:07 -0400)] 
gccrs: Use namespace definition to simplify function declarations

gcc/rust/ChangeLog:

* rust-gcc.cc
(namespace Backend):
Use namespace definition instead of qualified names.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: rust-compile-intrinsic: add `copy` intrinsics ...
liushuyu [Thu, 1 Jun 2023 04:22:35 +0000 (22:22 -0600)] 
gccrs: rust-compile-intrinsic: add `copy` intrinsics ...

... also made `copy_nonoverlapping` handler more generic

gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc: add `copy`
intrinsics and make `copy_nonoverlapping` handler more generic

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
18 months agogccrs: rust-builtins: add likely and unlikey intrinsics
liushuyu [Thu, 1 Jun 2023 04:08:02 +0000 (22:08 -0600)] 
gccrs: rust-builtins: add likely and unlikey intrinsics

gcc/rust/ChangeLog:
* backend/rust-builtins.cc: add `expect` builtin definition.
* backend/rust-compile-intrinsic.cc: add `likely` and `unlikely`
intrinsics handler.

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
18 months agogccrs: Rename "rust_error_codes.def" to "rust-error-codes.def"
Owen Avery [Wed, 13 Sep 2023 04:36:06 +0000 (00:36 -0400)] 
gccrs: Rename "rust_error_codes.def" to "rust-error-codes.def"

gcc/rust/ChangeLog:

* rust_error_codes.def: Moved to...
* rust-error-codes.def: ...here...
* rust-diagnostics.h: ...and update references.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Shorten `make_unsigned_long_tree` code and remove `Backend::integer_constant_e...
Guillaume Gomez [Fri, 8 Sep 2023 13:40:28 +0000 (15:40 +0200)] 
gccrs: Shorten `make_unsigned_long_tree` code and remove `Backend::integer_constant_expression`

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc: Simplify `make_unsigned_long_tree`
* rust-backend.h: Remove `integer_constant_expression`
* rust-gcc.cc: Remove `integer_constant_expression`

18 months agogccrs: Fix typechecking (and compilation) error for alt patterns in match expressions.
Dave Evans [Thu, 24 Aug 2023 19:10:42 +0000 (14:10 -0500)] 
gccrs: Fix typechecking (and compilation) error for alt patterns in match expressions.

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternCaseLabelExpr::visit):
Add AltPattern visitor function
* backend/rust-compile-pattern.h:
Update CompilePatternCaseLabelExpr::visit(AltPattern&).
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Update AltPattern visitor

gcc/testsuite/ChangeLog:

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

Signed-off-by: Dave Evans <dave@dmetwo.org>
18 months agogccrs: Remove unused `ctx` argument in `make_unsigned_long_tree` function
Guillaume Gomez [Mon, 11 Sep 2023 14:38:40 +0000 (16:38 +0200)] 
gccrs: Remove unused `ctx` argument in `make_unsigned_long_tree` function

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc: Remove unused argument

18 months agogccrs: privacy: Uncomment test relying on #1257
Arthur Cohen [Mon, 21 Aug 2023 14:28:03 +0000 (16:28 +0200)] 
gccrs: privacy: Uncomment test relying on #1257

gcc/testsuite/ChangeLog:

* rust/compile/privacy6.rs: Uncomment commented out functions.
* rust/compile/privacy9.rs: Fix unused variables.

18 months agogccrs: privacy: Add testcase for #1260
Arthur Cohen [Mon, 21 Aug 2023 14:26:51 +0000 (16:26 +0200)] 
gccrs: privacy: Add testcase for #1260

gcc/testsuite/ChangeLog:

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

18 months agogccrs: [E0599] Failed to resovle method implementation
Muhammad Mahad [Tue, 29 Aug 2023 15:00:18 +0000 (20:00 +0500)] 
gccrs: [E0599] Failed to resovle method implementation

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Added new error message, rich location and error code.

gcc/testsuite/ChangeLog:

* rust/compile/cfg2.rs: Updated according to new message.
* rust/compile/issue-2139.rs: likewise.
* rust/compile/issue-2190-1.rs: likewise.
* rust/compile/method1.rs: likewise.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Convert class Backend into namespace
Owen Avery [Mon, 4 Sep 2023 20:13:31 +0000 (16:13 -0400)] 
gccrs: Convert class Backend into namespace

gcc/rust/ChangeLog:

* rust-backend.h
(class Backend): Convert to ...
(namespace Backend): ... namespace.
* rust-gcc.cc
(Backend::Backend): Rename to ...
(Backend::init): ... here.
(rust_get_backend): Remove.

* rust-session-manager.cc
(rust_get_backend): Remove.
(Session::init): Use Backend::init instead of rust_get_backend.
(Session::compile_crate):
Initialize Context without pointer to Backend.
* rust-session-manager.h
(Session::backend): Remove.
* backend/rust-compile-context.cc
(Context::Context): Remove pointer to Backend.
* backend/rust-compile-context.h
(class Context): Remove pointer to Backend, update function calls.

* backend/rust-compile-base.cc: Update function calls.
* backend/rust-compile-block.cc: Likewise.
* backend/rust-compile-expr.cc: Likewise.
* backend/rust-compile-extern.h: Likewise.
* backend/rust-compile-fnparam.cc: Likewise.
* backend/rust-compile-intrinsic.cc: Likewise.
* backend/rust-compile-item.cc: Likewise.
* backend/rust-compile-pattern.cc: Likewise.
* backend/rust-compile-resolve-path.cc: Likewise.
* backend/rust-compile-type.cc: Likewise.
* backend/rust-compile-var-decl.h: Likewise.
* backend/rust-compile.cc: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Unify raw attribute values
Pierre-Emmanuel Patry [Fri, 1 Sep 2023 11:14:09 +0000 (13:14 +0200)] 
gccrs: Unify raw attribute values

Attribute values were used as raw string, this is error prone and
makes renaming harder. Using a constexpr instead will leverage the power
of the compiler and emit an error when an incorrect builtin attribute
value is used.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::check_cfg_predicate): Change raw
string to constexpr call.
(Attribute::separate_cfg_attrs): Likewise.
* backend/rust-compile-base.cc (should_mangle_item): Likewise.
(HIRCompileBase::setup_fndecl): Likewise.
(HIRCompileBase::handle_cold_attribute_on_fndecl): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute):
Likewise.
* checks/errors/rust-unsafe-checker.cc (check_target_attr):
Likewise.
* expand/rust-cfg-strip.cc (fails_cfg): Likewise.
(fails_cfg_with_expand): Likewise.
(expand_cfg_attrs): Likewise.
* expand/rust-macro-builtins.cc: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Likewise.
(ASTLoweringBase::lower_macro_definition): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* parse/rust-parse-impl.h (Parser::parse_doc_comment): Likewise.
* parse/rust-parse.cc (extract_module_path): Likewise.
* resolve/rust-early-name-resolver.cc (is_macro_use_module):
Likewise.
(EarlyNameResolver::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (is_macro_export):
Likwise.
* rust-session-manager.cc (Session::injection): Likewise.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): Likewise.
* util/rust-attributes.cc (is_proc_macro_type): Likewise.
(AttributeChecker::check_attribute): Likewise.
(AttributeChecker::visit): Likewise.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise.
* util/rust-attribute-values.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Remove Gcc_backend
Owen Avery [Mon, 4 Sep 2023 18:09:10 +0000 (14:09 -0400)] 
gccrs: Remove Gcc_backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::Backend): New.
(Backend::~Backend): Remove.
(class Gcc_backend): Remove.
* rust-gcc.cc
(Gcc_backend::Gcc_backend): Rename to ...
(Backend::Backend): ... here.
(rust_get_backend): Construct Backend instead of Gcc_backend.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add missing linemap to lexer
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 15:24:03 +0000 (17:24 +0200)] 
gccrs: Add missing linemap to lexer

When some proc macro create tokens and later have some code referring to
those created tokens the code was missing a linemap since the pointer
was null, throwing an ICE.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (tokenstream_from_string): Change
linemap null pointer to the current linemap.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add proc macro definition insertion
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 14:49:31 +0000 (16:49 +0200)] 
gccrs: Add proc macro definition insertion

Insert proc macro definition from extern crates.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Add proc macro definition insertion.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Change proc macro mapping definition insertion
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 14:41:55 +0000 (16:41 +0200)] 
gccrs: Change proc macro mapping definition insertion

Since the node id already is contained into the proc macro we may omit
it from the function arguments.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_derive_proc_macro_def):
Change the function body to fetch the node id from the macro
parameter.
(Mappings::insert_bang_proc_macro_def): Likewise.
(Mappings::insert_attribute_proc_macro_def): Likewise.
* util/rust-hir-map.h: Update the function's prototype by
removing the node id from the list of arguments.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Retrieve def for derive & attribute proc macros
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 13:59:58 +0000 (15:59 +0200)] 
gccrs: Retrieve def for derive & attribute proc macros

Add definition retrieval for derive and attribute proc macro types.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Add proc macro handle retrieval for attribute and derive proc macros.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Change proc macro definition lookup to optionals
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 13:02:21 +0000 (15:02 +0200)] 
gccrs: Change proc macro definition lookup to optionals

Continue changing the api to use optionals instead of bools and double
pointers.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::lookup_derive_proc_macro_def):
Update function to accomodate new signature.
(Mappings::lookup_bang_proc_macro_def): Likewise.
(Mappings::lookup_attribute_proc_macro_def): Likewise.
* util/rust-hir-map.h: Update function signatures.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Use optional for proc macro invocation lookup
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 12:42:02 +0000 (14:42 +0200)] 
gccrs: Use optional for proc macro invocation lookup

The old interface for those mappings was clunky at best. Now we can use
the optional structure to return a reference to the instance.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.h (struct MacroExpander): Update
lookup function prototypes.
* util/rust-hir-map.cc (Mappings::lookup_derive_proc_macro_invocation):
Update lookup function according to new signature.
(Mappings::lookup_bang_proc_macro_invocation): Likewise.
(Mappings::lookup_attribute_proc_macro_invocation): Likewise.
* util/rust-hir-map.h: Update function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Remove Backend::write_export_data
Owen Avery [Mon, 4 Sep 2023 18:23:10 +0000 (14:23 -0400)] 
gccrs: Remove Backend::write_export_data

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::write_export_data): Remove.
* rust-gcc.cc
(Backend::write_export_data): Remove.

18 months agogccrs: Move remaining expression-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 21:25:55 +0000 (17:25 -0400)] 
gccrs: Move remaining expression-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::real_part_expression): Make non-virtual.
(Backend::imag_part_expression): Likewise.
(Backend::complex_expression): Likewise.
(Backend::convert_expression): Likewise.
(Backend::struct_field_expression): Likewise.
(Backend::compound_expression): Likewise.
(Backend::conditional_expression): Likewise.
(Backend::negation_expression): Likewise.
(Backend::arithmetic_or_logical_expression): Likewise.
(Backend::arithmetic_or_logical_expression_checked): Likewise.
(Backend::comparison_expression): Likewise.
(Backend::lazy_boolean_expression): Likewise.
(Backend::constructor_expression): Likewise.
(Backend::array_constructor_expression): Likewise.
(Backend::array_initializer): Likewise.
(Backend::array_index_expression): Likewise.
(Backend::call_expression): Likewise.

(Gcc_backend::real_part_expression): Remove.
(Gcc_backend::imag_part_expression): Remove.
(Gcc_backend::complex_expression): Remove.
(Gcc_backend::convert_expression): Remove.
(Gcc_backend::struct_field_expression): Remove.
(Gcc_backend::compound_expression): Remove.
(Gcc_backend::conditional_expression): Remove.
(Gcc_backend::negation_expression): Remove.
(Gcc_backend::arithmetic_or_logical_expression): Remove.
(Gcc_backend::arithmetic_or_logical_expression_checked): Remove.
(Gcc_backend::comparison_expression): Remove.
(Gcc_backend::lazy_boolean_expression): Remove.
(Gcc_backend::constructor_expression): Remove.
(Gcc_backend::array_constructor_expression): Remove.
(Gcc_backend::array_initializer): Remove.
(Gcc_backend::array_index_expression): Remove.
(Gcc_backend::call_expression): Remove.
* rust-gcc.cc
(Gcc_backend::real_part_expression): Rename to ...
(Backend::real_part_expression): ... here.
(Gcc_backend::imag_part_expression): Rename to ...
(Backend::imag_part_expression): ... here.
(Gcc_backend::complex_expression): Rename to ...
(Backend::complex_expression): ... here.
(Gcc_backend::convert_expression): Rename to ...
(Backend::convert_expression): ... here.
(Gcc_backend::struct_field_expression): Rename to ...
(Backend::struct_field_expression): ... here.
(Gcc_backend::compound_expression): Rename to ...
(Backend::compound_expression): ... here.
(Gcc_backend::conditional_expression): Rename to ...
(Backend::conditional_expression): ... here.
(Gcc_backend::negation_expression): Rename to ...
(Backend::negation_expression): ... here.
(Gcc_backend::arithmetic_or_logical_expression): Rename to ...
(Backend::arithmetic_or_logical_expression): ... here.
(Gcc_backend::arithmetic_or_logical_expression_checked): Rename to ...
(Backend::arithmetic_or_logical_expression_checked): ... here.
(Gcc_backend::comparison_expression): Rename to ...
(Backend::comparison_expression): ... here.
(Gcc_backend::lazy_boolean_expression): Rename to ...
(Backend::lazy_boolean_expression): ... here.
(Gcc_backend::constructor_expression): Rename to ...
(Backend::constructor_expression): ... here.
(Gcc_backend::array_constructor_expression): Rename to ...
(Backend::array_constructor_expression): ... here.
(Gcc_backend::array_initializer): Rename to ...
(Backend::array_initializer): ... here.
(Gcc_backend::array_index_expression): Rename to ...
(Backend::array_index_expression): ... here.
(Gcc_backend::call_expression): Rename to ...
(Backend::call_expression): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Clarify package import procedure
Pierre-Emmanuel Patry [Mon, 4 Sep 2023 10:19:13 +0000 (12:19 +0200)] 
gccrs: Clarify package import procedure

This part of the code is a bit tricky as it calls multiple functions
with almost the same name and slightly different behaviors. It was even
more with a meaningless variable name.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::load_extern_crate): Change
variable name, add temporaries and comments.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: resolver: Refactor macro insertion
Pierre-Emmanuel Patry [Mon, 28 Aug 2023 09:39:44 +0000 (11:39 +0200)] 
gccrs: resolver: Refactor macro insertion

Add a templated function to insert any of the three kind of proc macro
into the resolver context.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.h: Change get_trait_name to get_name in
order to be coherent with the others proc macro type name
convention.
* resolve/rust-toplevel-name-resolver-2.0.cc (insert_macros):
Add a templated funtion that inserts a proc macro into the
context and emit an error on failure.
(TopLevel::visit): Change from manual insertion to a function
call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: resolver: Refactor assertion
Pierre-Emmanuel Patry [Mon, 28 Aug 2023 08:54:12 +0000 (10:54 +0200)] 
gccrs: resolver: Refactor assertion

Change the condition with rust_unreachable to an assertion. This will
keep the code clean and concise.
Some styling issues appeared during review, this commit make the code
more readable.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Change to assertion.
* util/rust-hir-map.cc (Mappings::lookup_derive_proc_macros):
Add empty line.
(Mappings::lookup_bang_proc_macros): Likewise.
(Mappings::lookup_attribute_proc_macros): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Move extern crate resolving
Pierre-Emmanuel Patry [Wed, 2 Aug 2023 14:57:09 +0000 (16:57 +0200)] 
gccrs: Move extern crate resolving

Move extern crate resolving under the extern crate declaration instead
of doing it under the crate's root as extern crates are not resolved by
the top level resolver.

gcc/rust/ChangeLog:

* metadata/rust-extern-crate.cc (ExternCrate::ExternCrate):
Update definition to allow Extern crate with no content (pure
proc macros).
(ExternCrate::ok): Panic on no content.
(ExternCrate::load): Likewise.
* metadata/rust-extern-crate.h: Update prototypes.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Remove macro resolution.
(TopLevel::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Add visit prototype
for extern crate.
* rust-session-manager.cc (Session::load_extern_crate): Adapt
content depending on the loaded crate's content.
* util/rust-hir-map.cc (Mappings::lookup_derive_proc_macros):
Change return type to optional because it is way more
convenient.
(Mappings::lookup_bang_proc_macros): Likewise.
(Mappings::lookup_attribute_proc_macros): Likewise.
* util/rust-hir-map.h: Update function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Supress error with proc macro crates
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 16:32:46 +0000 (18:32 +0200)] 
gccrs: Supress error with proc macro crates

This error was emitted when a valid proc macro crate was loaded. Proc
macros do not contain any import data for now.

gcc/rust/ChangeLog:

* metadata/rust-imports.cc (Import::try_package_in_directory):
Remove error when some macro are found even if no import data is
available.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Move proc macro definition to mappings
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 15:42:45 +0000 (17:42 +0200)] 
gccrs: Move proc macro definition to mappings

This commit moves the procedural macros loaded definition from outside
the AST to the mappings. This means most getters/setters around the
mappings had to be changed. This commit also introduces the top level
visit of those mappings instead of visiting the Crate ast members.

gcc/rust/ChangeLog:

* ast/rust-ast.h (class BangProcMacro): Move class from here to
rust-proc-macro.h. Also remove related functions.
(class AttributeProcMacro): Likewise.
(class CustomDeriveProcMacro): Likewise.
(struct Crate): Remove proc macro vector members.
* expand/rust-macro-expand.h (struct MacroExpander): Change the
type to the newly created classes.
* expand/rust-proc-macro.cc (BangProcMacro::BangProcMacro): Add
constructor implementation.
(AttributeProcMacro::AttributeProcMacro): Likewise.
(CustomDeriveProcMacro::CustomDeriveProcMacro): Likewise.
* expand/rust-proc-macro.h (class BangProcMacro): Move class to
here.
(class AttributeProcMacro): Likewise.
(class CustomDeriveProcMacro): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Change top level visitor to check mappings instead
* rust-session-manager.cc (Session::load_extern_crate):
Add back macro collection to mappings.
* util/rust-hir-map.cc (Mappings::insert_derive_proc_macros):
Update getter signature with new types.
(Mappings::insert_bang_proc_macros): Likewise.
(Mappings::insert_attribute_proc_macros): Likewise.
(Mappings::lookup_derive_proc_macros): Likewise.
(Mappings::lookup_bang_proc_macros): Likewise.
(Mappings::lookup_attribute_proc_macros): Likewise.
(Mappings::insert_derive_proc_macro_def): Likewise.
(Mappings::insert_bang_proc_macro_def): Likewise.
(Mappings::insert_attribute_proc_macro_def): Likewise.
(Mappings::lookup_derive_proc_macro_def): Likewise.
(Mappings::lookup_bang_proc_macro_def): Likewise.
(Mappings::lookup_attribute_proc_macro_def): Likewise.
(Mappings::insert_derive_proc_macro_invocation): Likewise.
(Mappings::lookup_derive_proc_macro_invocation): Likewise.
(Mappings::insert_bang_proc_macro_invocation): Likewise.
(Mappings::lookup_bang_proc_macro_invocation): Likewise.
(Mappings::insert_attribute_proc_macro_invocation): Likewise.
(Mappings::lookup_attribute_proc_macro_invocation): Likewise.
* util/rust-hir-map.h: Update function prototypes as well as map
types.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add proc macro top level discovery
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 10:45:11 +0000 (12:45 +0200)] 
gccrs: Add proc macro top level discovery

Add mechanism to discover proc macros in loaded extern crates. In the
top level resolver.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Visit crate's newly stored proc macros.
* rust-session-manager.cc (Session::load_extern_crate):
Store proc macros in the parsed crate instead of a local
variable to achieve mappings.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Change early resolver visit_attributes arguments
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 10:43:27 +0000 (12:43 +0200)] 
gccrs: Change early resolver visit_attributes arguments

We do not need to copy the whole vector we can simply take a reference
instead.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Change argument to reference.
* resolve/rust-early-name-resolver-2.0.h: Update function
prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add getters for different types of proc macros
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 09:20:00 +0000 (11:20 +0200)] 
gccrs: Add getters for different types of proc macros

Add some getters on the ast crate in order to be able to retrieve a
reference to a crate's proc macros.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add getters.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add proc macros abstractions to crate structure
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 16:31:51 +0000 (18:31 +0200)] 
gccrs: Add proc macros abstractions to crate structure

Add multiple setters for a crate object in order to add macro
abstractions previously introduced.

gcc/rust/ChangeLog:

* ast/rust-ast.h (struct Crate): Add proc macro members.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add proc macro ast representation
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 16:26:40 +0000 (18:26 +0200)] 
gccrs: Add proc macro ast representation

When resolving proc macros it is convenient to store every macro
directly in the extern crate. These class in the ast module provide a
better abstraction over the raw ProcMacro::{CustomDerive, Bang,
Attribute} structures provided by the proc_macro library.

gcc/rust/ChangeLog:

* ast/rust-ast.h (class BangProcMacro): Add new proc macro
abstraction.
(class AttributeProcMacro): Likewise.
(class CustomDeriveProcMacro): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Visit function and structure attributes
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 13:29:36 +0000 (15:29 +0200)] 
gccrs: Visit function and structure attributes

Add a simple attribute visit function and override StructStruct &
Function visit functions.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Add function to handle attributes.
(Early::visit): Override visitor functions.
* resolve/rust-early-name-resolver-2.0.h: Add prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Parse unparsed derive tokenstreams
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 13:10:41 +0000 (15:10 +0200)] 
gccrs: Parse unparsed derive tokenstreams

Derive attributes should be parsed before attempting to retrieve any
traits. This will convert the tokenstream to a list of path if this
hasn't been done previously.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::get_traits_to_derive): Convert
tokenstream to path list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Ease some constraints on derive definition
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 11:08:06 +0000 (13:08 +0200)] 
gccrs: Ease some constraints on derive definition

Member function is_derive was overly constrained, the attribute changes
when we parse it's meta items and it no longer contains a tokenstream
while staying a derive.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::is_derive): Remove tokenstream
condition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Change trait getter to return references
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 10:31:58 +0000 (12:31 +0200)] 
gccrs: Change trait getter to return references

Having copy and any other constructor stuff might lead to a breakage in
the future where the node id differs due to a newly constructed
SimplePath node. This change will allow us to assert the NodeId is from
the ast and not any copy made in between.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::get_traits_to_derive): Change
return type to a vector of references.
* ast/rust-ast.h: Update constructor.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_stmts):
Update function call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Set traits getter as member function
Pierre-Emmanuel Patry [Fri, 28 Jul 2023 15:55:55 +0000 (17:55 +0200)] 
gccrs: Set traits getter as member function

This function will be used outside of the expand visitor, making it
easily accessible is therefore mandatory.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::get_traits_to_derive): Add
function as member function.
* ast/rust-ast.h: Add prototype.
* expand/rust-expand-visitor.cc (get_traits_to_derive): Remove
function.
(ExpandVisitor::expand_inner_stmts): Update function call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Make is_builtin a member function
Pierre-Emmanuel Patry [Fri, 28 Jul 2023 15:26:50 +0000 (17:26 +0200)] 
gccrs: Make is_builtin a member function

This function will be used in the multiple other places, therefore we
should make it easily usable from there.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::is_derive): Add member function.
* ast/rust-ast.h: Likewise.
* expand/rust-expand-visitor.cc (is_derive): Remove old
function.
(ExpandVisitor::expand_inner_stmts): Update function call.
(ExpandVisitor::visit_inner_using_attrs): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Fix match-expression code-gen
Philip Herron [Mon, 4 Sep 2023 14:28:46 +0000 (15:28 +0100)] 
gccrs: Fix match-expression code-gen

We were massing the match scruitinee expression as a way to access the
result of the expression. This is wrong and needs to be stored in a
temporary otherwise it will cause the code to be regnerated for each time
it is used. This is not an issue in the case where the expression is only
used once.

Fixes #1895

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): use a temp for the value

gcc/testsuite/ChangeLog:

* rust/execute/torture/iter1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Move block-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 19:58:22 +0000 (15:58 -0400)] 
gccrs: Move block-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::block): Make non-virtual.
(Backend::block_add_statements): Likewise.

(Gcc_backend::block): Remove.
(Gcc_backend::block_add_statements): Remove.
* rust-gcc.cc
(Gcc_backend::block): Rename to ...
(Backend::block): ... here.
(Gcc_backend::block_add_statements): Rename to ...
(Backend::block_add_statements): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: libproc_macro: Split c++ and rust
Pierre-Emmanuel Patry [Mon, 28 Aug 2023 15:20:28 +0000 (17:20 +0200)] 
gccrs: libproc_macro: Split c++ and rust

Move the rust interface to the libproc_macro directory.

libgrust/ChangeLog:

* libproc_macro_internal/rust/bridge.rs: Moved to...
* libproc_macro/bridge.rs: ...here.
* libproc_macro_internal/rust/bridge/ffistring.rs: Moved to...
* libproc_macro/bridge/ffistring.rs: ...here.
* libproc_macro_internal/rust/bridge/group.rs: Moved to...
* libproc_macro/bridge/group.rs: ...here.
* libproc_macro_internal/rust/bridge/ident.rs: Moved to...
* libproc_macro/bridge/ident.rs: ...here.
* libproc_macro_internal/rust/bridge/literal.rs: Moved to...
* libproc_macro/bridge/literal.rs: ...here.
* libproc_macro_internal/rust/bridge/punct.rs: Moved to...
* libproc_macro/bridge/punct.rs: ...here.
* libproc_macro_internal/rust/bridge/span.rs: Moved to...
* libproc_macro/bridge/span.rs: ...here.
* libproc_macro_internal/rust/bridge/token_stream.rs: Moved to...
* libproc_macro/bridge/token_stream.rs: ...here.
* libproc_macro_internal/rust/group.rs: Moved to...
* libproc_macro/group.rs: ...here.
* libproc_macro_internal/rust/ident.rs: Moved to...
* libproc_macro/ident.rs: ...here.
* libproc_macro_internal/rust/lib.rs: Moved to...
* libproc_macro/lib.rs: ...here.
* libproc_macro_internal/rust/literal.rs: Moved to...
* libproc_macro/literal.rs: ...here.
* libproc_macro_internal/rust/punct.rs: Moved to...
* libproc_macro/punct.rs: ...here.
* libproc_macro_internal/rust/span.rs: Moved to...
* libproc_macro/span.rs: ...here.
* libproc_macro_internal/rust/token_stream.rs: Moved to...
* libproc_macro/token_stream.rs: ...here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Rename libproc_macro to libproc_macro_internal
Pierre-Emmanuel Patry [Mon, 28 Aug 2023 15:08:40 +0000 (17:08 +0200)] 
gccrs: Rename libproc_macro to libproc_macro_internal

The name was a bit misleading since libproc_macro is a rust library that
should we should be able to link against some rust code. This cpp
library was the layer below the libproc_macro library, the "real" gcc
libproc_macro act as a translation layer for the internal library.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.h: Change include directive with the
new name.
* expand/rust-proc-macro.h (RUST_PROC_MACRO_H): Likewise.
* util/rust-hir-map.h: Likewise.
* util/rust-token-converter.h: Likewise.
* util/rust-token-converter.cc: Remove useless include
directive.
* Make-lang.in: Rename library.

libgrust/ChangeLog:

* Makefile.am: Change library name.
* Makefile.in: Likewise.
* configure.ac: Likewise.
* configure: Regenerate.
* libproc_macro/Makefile.am: Moved to...
* libproc_macro_internal/Makefile.am: ...here.
* libproc_macro/Makefile.in: Moved to...
* libproc_macro_internal/Makefile.in: ...here.
* libproc_macro/bridge.h: Moved to...
* libproc_macro_internal/bridge.h: ...here.
* libproc_macro/ffistring.cc: Moved to...
* libproc_macro_internal/ffistring.cc: ...here.
* libproc_macro/ffistring.h: Moved to...
* libproc_macro_internal/ffistring.h: ...here.
* libproc_macro/group.cc: Moved to...
* libproc_macro_internal/group.cc: ...here.
* libproc_macro/group.h: Moved to...
* libproc_macro_internal/group.h: ...here.
* libproc_macro/ident.cc: Moved to...
* libproc_macro_internal/ident.cc: ...here.
* libproc_macro/ident.h: Moved to...
* libproc_macro_internal/ident.h: ...here.
* libproc_macro/literal.cc: Moved to...
* libproc_macro_internal/literal.cc: ...here.
* libproc_macro/literal.h: Moved to...
* libproc_macro_internal/literal.h: ...here.
* libproc_macro/proc_macro.cc: Moved to...
* libproc_macro_internal/proc_macro.cc: ...here.
* libproc_macro/proc_macro.h: Moved to...
* libproc_macro_internal/proc_macro.h: ...here.
* libproc_macro/punct.cc: Moved to...
* libproc_macro_internal/punct.cc: ...here.
* libproc_macro/punct.h: Moved to...
* libproc_macro_internal/punct.h: ...here.
* libproc_macro/registration.h: Moved to...
* libproc_macro_internal/registration.h: ...here.
* libproc_macro/rust/bridge.rs: Moved to...
* libproc_macro_internal/rust/bridge.rs: ...here.
* libproc_macro/rust/bridge/ffistring.rs: Moved to...
* libproc_macro_internal/rust/bridge/ffistring.rs: ...here.
* libproc_macro/rust/bridge/group.rs: Moved to...
* libproc_macro_internal/rust/bridge/group.rs: ...here.
* libproc_macro/rust/bridge/ident.rs: Moved to...
* libproc_macro_internal/rust/bridge/ident.rs: ...here.
* libproc_macro/rust/bridge/literal.rs: Moved to...
* libproc_macro_internal/rust/bridge/literal.rs: ...here.
* libproc_macro/rust/bridge/punct.rs: Moved to...
* libproc_macro_internal/rust/bridge/punct.rs: ...here.
* libproc_macro/rust/bridge/span.rs: Moved to...
* libproc_macro_internal/rust/bridge/span.rs: ...here.
* libproc_macro/rust/bridge/token_stream.rs: Moved to...
* libproc_macro_internal/rust/bridge/token_stream.rs: ...here.
* libproc_macro/rust/group.rs: Moved to...
* libproc_macro_internal/rust/group.rs: ...here.
* libproc_macro/rust/ident.rs: Moved to...
* libproc_macro_internal/rust/ident.rs: ...here.
* libproc_macro/rust/lib.rs: Moved to...
* libproc_macro_internal/rust/lib.rs: ...here.
* libproc_macro/rust/literal.rs: Moved to...
* libproc_macro_internal/rust/literal.rs: ...here.
* libproc_macro/rust/punct.rs: Moved to...
* libproc_macro_internal/rust/punct.rs: ...here.
* libproc_macro/rust/span.rs: Moved to...
* libproc_macro_internal/rust/span.rs: ...here.
* libproc_macro/rust/token_stream.rs: Moved to...
* libproc_macro_internal/rust/token_stream.rs: ...here.
* libproc_macro/span.cc: Moved to...
* libproc_macro_internal/span.cc: ...here.
* libproc_macro/span.h: Moved to...
* libproc_macro_internal/span.h: ...here.
* libproc_macro/tokenstream.cc: Moved to...
* libproc_macro_internal/tokenstream.cc: ...here.
* libproc_macro/tokenstream.h: Moved to...
* libproc_macro_internal/tokenstream.h: ...here.
* libproc_macro/tokentree.cc: Moved to...
* libproc_macro_internal/tokentree.cc: ...here.
* libproc_macro/tokentree.h: Moved to...
* libproc_macro_internal/tokentree.h: ...here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Move statement-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 18:53:50 +0000 (14:53 -0400)] 
gccrs: Move statement-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::init_statement): Make non-virtual.
(Backend::assignment_statement): Likewise.
(Backend::return_statement): Likewise.
(Backend::if_statement): Likewise.
(Backend::loop_expression): Likewise.
(Backend::exit_expression): Likewise.
(Backend::compound_statement): Likewise.
(Backend::statement_list): Likewise.
(Backend::exception_handler_statement): Likewise.

(Gcc_backend::init_statement): Remove.
(Gcc_backend::assignment_statement): Remove.
(Gcc_backend::return_statement): Remove.
(Gcc_backend::if_statement): Remove.
(Gcc_backend::compound_statement): Remove.
(Gcc_backend::statement_list): Remove.
(Gcc_backend::exception_handler_statement): Remove.
(Gcc_backend::loop_expression): Remove.
(Gcc_backend::exit_expression): Remove.
* rust-gcc.cc
(Gcc_backend::init_statement): Rename to ...
(Backend::init_statement): ... here.
(Gcc_backend::assignment_statement): Rename to ...
(Backend::assignment_statement): ... here.
(Gcc_backend::return_statement): Rename to ...
(Backend::return_statement): ... here.
(Gcc_backend::exception_handler_statement): Rename to ...
(Backend::exception_handler_statement): ... here.
(Gcc_backend::if_statement): Rename to ...
(Backend::if_statement): ... here.
(Gcc_backend::loop_expression): Rename to ...
(Backend::loop_expression): ... here.
(Gcc_backend::exit_expression): Rename to ...
(Backend::exit_expression): ... here.
(Gcc_backend::compound_statement): Rename to ...
(Backend::compound_statement): ... here.
(Gcc_backend::statement_list): Rename to ...
(Backend::statement_list): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Move function-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 18:39:27 +0000 (14:39 -0400)] 
gccrs: Move function-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::function): Make non-virtual.
(Backend::function_defer_statement): Likewise.
(Backend::function_set_parameters): Likewise.
(Backend::write_global_definitions): Likewise.
(Backend::write_export_data): Likewise.

(Gcc_backend::function): Remove.
(Gcc_backend::function_defer_statement): Remove.
(Gcc_backend::function_set_parameters): Remove.
(Gcc_backend::write_global_definitions): Remove.
(Gcc_backend::write_export_data): Remove.
* rust-gcc.cc
(Gcc_backend::function): Rename to ...
(Backend::function): ... here.
(Gcc_backend::function_defer_statement):
Fix a qualified lookup of Backend::label and rename to ...
(Backend::function_defer_statement): ... here.
(Gcc_backend::function_set_parameters) Rename to ...
(Backend::function_set_parameters): ... here.
(Gcc_backend::write_global_definitions): Rename to ...
(Backend::write_global_definitions): ... here.
(Gcc_backend::write_export_data): Rename to ...
(Backend::write_export_data): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: gccrs:[E0592] methods or associated functions with same name already defined
Muhammad Mahad [Thu, 17 Aug 2023 05:42:52 +0000 (10:42 +0500)] 
gccrs: gccrs:[E0592] methods or associated functions with same name already defined

gcc/rust/ChangeLog:

* typecheck/rust-hir-inherent-impl-overlap.h:
Added rich location and errorcode.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
likewise.

gcc/testsuite/ChangeLog:

* rust/compile/generics7.rs: Added Errorcode hint.
* rust/compile/generics8.rs: Updated dejagnu comment.
* rust/compile/issue-925.rs: Added Errorcode hint.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0532] Pattern arm did not match expected kind
Muhammad Mahad [Sat, 2 Sep 2023 10:18:20 +0000 (15:18 +0500)] 
gccrs: [E0532] Pattern arm did not match expected kind

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Added error code.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2029.rs:
Updated for dejagnu testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Move some simple expression-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 20:23:53 +0000 (16:23 -0400)] 
gccrs: Move some simple expression-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::zero_expression): Make non-virtual.
(Backend::var_expression): Likewise.
(Backend::integer_constant_expression): Likewise.
(Backend::float_constant_expression): Likewise.
(Backend::complex_constant_expression): Likewise.
(Backend::string_constant_expression): Likewise.
(Backend::char_constant_literal): Likewise.
(Backend::wchar_constant_literal): Likewise.
(Backend::boolean_constant_expression): Likewise.

(Gcc_backend::zero_expression): Remove.
(Gcc_backend::var_expression): Remove.
(Gcc_backend::integer_constant_expression): Remove.
(Gcc_backend::float_constant_expression): Remove.
(Gcc_backend::complex_constant_expression): Remove.
(Gcc_backend::string_constant_expression): Remove.
(Gcc_backend::wchar_constant_expression): Remove.
(Gcc_backend::char_constant_expression): Remove.
(Gcc_backend::boolean_constant_expression): Remove.
* rust-gcc.cc
(Gcc_backend::zero_expression): Rename to ...
(Backend::zero_expression): ... here.
(Gcc_backend::var_expression): Rename to ...
(Backend::var_expression): ... here.
(Gcc_backend::integer_constant_expression): Rename to ...
(Backend::integer_constant_expression): ... here.
(Gcc_backend::float_constant_expression): Rename to ...
(Backend::float_constant_expression): ... here.
(Gcc_backend::complex_constant_expression): Rename to ...
(Backend::complex_constant_expression): ... here.
(Gcc_backend::string_constant_expression): Rename to ...
(Backend::string_constant_expression): ... here.
(Gcc_backend::wchar_constant_expression): Rename to ...
(Backend::wchar_constant_expression): ... here.
(Gcc_backend::char_constant_expression): Rename to ...
(Backend::char_constant_expression): ... here.
(Gcc_backend::boolean_constant_expression): Rename to ...
(Backend::boolean_constant_expression): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Move variable-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 15:39:51 +0000 (11:39 -0400)] 
gccrs: Move variable-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::global_variable): Make non-virtual.
(Backend::global_variable_set_init): Likewise.
(Backend::local_variable): Likewise.
(Backend::parameter_variable): Likewise.
(Backend::static_chain_variable): Likewise.
(Backend::temporary_variable): Likewise.

(Gcc_backend::global_variable): Remove.
(Gcc_backend::global_variable_set_init): Remove.
(Gcc_backend::local_variable): Remove.
(Gcc_backend::parameter_variable): Remove.
(Gcc_backend::static_chain_variable): Remove.
(Gcc_backend::temporary_variable): Remove.

(Gcc_backend::non_zero_size_type): Move to ...
(Backend::non_zero_size_type): ... here.
(Gcc_backend::convert_tree): Move to ...
(Backend::convert_tree): ... here.

* rust-gcc.cc
(Gcc_backend::non_zero_size_type): Rename to ...
(Backend::non_zero_size_type): ... here.
(Gcc_backend::convert_tree): Rename to ...
(Backend::convert_tree): ... here.
(Gcc_backend::global_variable): Rename to ...
(Backend::global_variable): ... here.
(Gcc_backend::global_variable_set_init): Rename to ...
(Backend::global_variable_set_init): ... here.
(Gcc_backend::local_variable): Rename to ...
(Backend::local_variable): ... here.
(Gcc_backend::parameter_variable): Rename to ...
(Backend::parameter_variable): ... here.
(Gcc_backend::static_chain_variable): Rename to ...
(Backend::static_chain_variable): ... here.
(Gcc_backend::temporary_variable): Rename to ...
(Backend::temporary_variable): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: [E0603] Use of private item outside scope
Muhammad Mahad [Sun, 3 Sep 2023 06:13:53 +0000 (11:13 +0500)] 
gccrs: [E0603] Use of private item outside scope

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::check_for_privacy_violation):
Added errorcode & richlocation.

gcc/testsuite/ChangeLog:

* rust/compile/privacy1.rs: Added errorcode.
* rust/compile/privacy3.rs: likewise.
* rust/compile/privacy4.rs: likewise.
* rust/compile/privacy5.rs: likewise.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Move debug-related functions into base class Backend
Owen Avery [Thu, 31 Aug 2023 15:25:47 +0000 (11:25 -0400)] 
gccrs: Move debug-related functions into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::debug): Make non-virtual.
(Backend::get_identifier_node): Likewise.

(Gcc_backend::debug): Remove.
(Gcc_backend::get_identifier_node): Remove.
* rust-gcc.cc
(Gcc_backend::debug): Rename to ...
(Backend::debug): ... here.
(Gcc_backend::get_identifier_node): Rename to ...
(Backend::get_identifier_node): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Improve type checking for if expressions
Owen Avery [Sat, 2 Sep 2023 02:07:30 +0000 (22:07 -0400)] 
gccrs: Improve type checking for if expressions

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::visit): Expect if conditions to have type bool.

gcc/testsuite/ChangeLog:

* rust/compile/type-if.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Move label-related functions into base class Backend
Owen Avery [Thu, 31 Aug 2023 15:32:11 +0000 (11:32 -0400)] 
gccrs: Move label-related functions into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::label): Make non-virtual.
(Backend::label_definition_statement): Likewise.
(Backend::goto_statement): Likewise.
(Backend::label_address): Likewise.

(Gcc_backend::label): Remove.
(Gcc_backend::label_definition_statement): Remove.
(Gcc_backend::goto_statement): Remove.
(Gcc_backend::label_address): Remove.
* rust-gcc.cc
(Gcc_backend::label): Rename to ...
(Backend::label): ... here.
(Gcc_backend::label_definition_statement): Rename to ...
(Backend::label_definition_statement): ... here.
(Gcc_backend::goto_statement): Rename to ...
(Backend::goto_statement): ... here.
(Gcc_backend::label_address): Rename to ...
(Backend::label_address): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Fix ODR violations
Owen Avery [Sat, 2 Sep 2023 00:46:20 +0000 (20:46 -0400)] 
gccrs: Fix ODR violations

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc
(struct constexpr_fundef): Rename to ...
(struct rust_constexpr_fundef): ... here.
(struct constexpr_call): Rename to ...
(struct rust_constexpr_call): ... here.

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