]> gcc.gnu.org Git - gcc.git/log
gcc.git
6 months agogccrs: Respect the concrete type when resolving qualifed path types
Philip Herron [Wed, 31 May 2023 15:06:58 +0000 (16:06 +0100)]
gccrs: Respect the concrete type when resolving qualifed path types

Concrete types can resolve to assoicated impl blocks which will allow us to
resolve the path to the projection type instead of the placeholder trait
associated type which can change. The projection will be fixed and is
safer to use.

Fixes #2165 #2166

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc: when the bound is concrete keep the mapping
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): add missing call
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): make this the same as paths

gcc/testsuite/ChangeLog:

* rust/compile/issue-2165.rs: New test.
* rust/compile/issue-2166.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Prevent initialization related warnings/errors for Optional
Owen Avery [Mon, 5 Jun 2023 19:54:08 +0000 (15:54 -0400)]
gccrs: Prevent initialization related warnings/errors for Optional

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635#c53

gcc/rust/ChangeLog:

* util/rust-optional.h
(class Optional): Add volatile field to union.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Handle crate metavariable
Owen Avery [Sat, 3 Jun 2023 23:57:33 +0000 (19:57 -0400)]
gccrs: Handle crate metavariable

gcc/rust/ChangeLog:

* expand/rust-macro-substitute-ctx.cc
(SubstituteCtx::substitute_metavar): Substitute crate metavar.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Allow parsing a borrow from struct expression
Owen Avery [Mon, 5 Jun 2023 20:48:55 +0000 (16:48 -0400)]
gccrs: Allow parsing a borrow from struct expression

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::null_denotation): Allow struct expression referencing.

gcc/testsuite/ChangeLog:

* rust/compile/struct-expr-parse.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: ast: dump literals correctly
Charalampos Mitrodimas [Sat, 3 Jun 2023 18:09:26 +0000 (18:09 +0000)]
gccrs: ast: dump literals correctly

This commit fixes printing of literals based on their
type.

Previous implementation printed literals the same, regardless
their type. Now we are printing:
  * int, float, bool don't require special printing
  * char        -> '<char>'
  * string      -> "<string>"
  * byte        -> b'<byte>'
  * byte_string -> b"<byte_string>"

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit):
print literals based on their type.

Signed-off-by: Charalampos Mitrodimas <charmitro@gmail.com>
6 months agogccrs: derive: Add dummy builtin transcriber for builtin derive macros.
Arthur Cohen [Thu, 1 Jun 2023 14:23:27 +0000 (16:23 +0200)]
gccrs: derive: Add dummy builtin transcriber for builtin derive macros.

Fixes #2257.

Derive builtins do not need a real transcriber, but still need one. It
will however never be called since builtin derive macros get expanded
differently, and benefit from knowing on what kind of items they are
applied (struct, enums, unions) rather than receiving a list of tokens
like regular builtin macros.

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::dummy): New function.
* expand/rust-macro-builtins.h: Declare it.

gcc/testsuite/ChangeLog:

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

6 months agogccrs: derive: Add proper derive(Clone) for unions
Arthur Cohen [Fri, 12 May 2023 13:14:49 +0000 (15:14 +0200)]
gccrs: derive: Add proper derive(Clone) for unions

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (AstBuilder::struct_expr_struct): New function.
(AstBuilder::let): Likewise.
(AstBuilder::struct_expr): Likewise.
(AstBuilder::struct_expr_field): Likewise.
(AstBuilder::field_access): Likewise.
(AstBuilder::wildcard): Likewise.
* ast/rust-ast-builder.h: Likewise.
* expand/rust-derive-clone.cc (DeriveClone::visit_union): Implement
properly.

gcc/testsuite/ChangeLog:

* rust/compile/derive_macro4.rs: New test.
* rust/compile/derive_macro6.rs: New test.

6 months agogccrs: derive: Add #[derive(Copy)] builtin
Arthur Cohen [Fri, 26 May 2023 11:37:13 +0000 (13:37 +0200)]
gccrs: derive: Add #[derive(Copy)] builtin

gcc/rust/ChangeLog:

* Make-lang.in: Add new files.
* expand/rust-derive.cc (DeriveVisitor::derive): Call into DeriveCopy.
* expand/rust-derive-copy.cc: New file.
* expand/rust-derive-copy.h: New file.

6 months agogccrs: derive: Add #[derive(Clone)] for regular structs
Arthur Cohen [Wed, 17 May 2023 10:17:58 +0000 (12:17 +0200)]
gccrs: derive: Add #[derive(Clone)] for regular structs

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::visit_struct): Implement proper
cloning for structs with fields.
* ast/rust-ast-builder.cc (AstBuilder::struct_expr): New function.
(AstBuilder::struct_expr_field): Likewise.
(AstBuilder::field_access): Likewise.
(AstBuilder::let): Likewise.
* ast/rust-ast-builder.h: Declare new functions.

gcc/testsuite/ChangeLog:

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

6 months agogccrs: converter: Refactor locations
Pierre-Emmanuel Patry [Wed, 31 May 2023 11:08:10 +0000 (13:08 +0200)]
gccrs: converter: Refactor locations

Refactor location to make code smaller and cleaner.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (convert): Use a variable instead
of multiple nested calls.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Convert back Locations from spans
Pierre-Emmanuel Patry [Wed, 31 May 2023 10:52:16 +0000 (12:52 +0200)]
gccrs: converter: Convert back Locations from spans

Use spans to get locations of expanded tokens instead of using unknown
locations.

gcc/rust/ChangeLog:

* lex/rust-lex.h: Make build_token method public.
* lex/rust-token.h: Add a setter for a token location.
* util/rust-token-converter.cc (convert): Add the function to
convert from a Span to a Location.
(from_ident): Convert Ident span to a Location.
(from_literal): Convert Literal span to a Location.
(from_punct): Convert Punct span to a Location.
(from_group): Convert Group span to a Location.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Add conversion from locations to spans
Pierre-Emmanuel Patry [Wed, 31 May 2023 09:17:56 +0000 (11:17 +0200)]
gccrs: converter: Add conversion from locations to spans

Add function implementation to convert either a Location or a
RicheLocation to a libproc_macro span.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (convert): Add implementation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add cpp Span representation
Pierre-Emmanuel Patry [Tue, 30 May 2023 08:57:01 +0000 (10:57 +0200)]
gccrs: libproc_macro: Add cpp Span representation

Add Span representation in libproc_macro cpp part of the library.
Integrate spans to existing types.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (convert): Update call to
constructors with location information.
(handle_suffix): Convert token locus to a Span and use it in the
literal.

libgrust/ChangeLog:

* libproc_macro/Makefile.am: Add span.cc
* libproc_macro/Makefile.in: Regenerate.
* libproc_macro/span.cc: New file.
* libproc_macro/span.h: New file.
* libproc_macro/group.cc (Group::make_group): Add span
argument.
* libproc_macro/group.h (GROUP_H): Add include
directive for spans.
* libproc_macro/ident.cc (Ident__new): Add span
argument.
(Ident__new_raw): Likewise.
(Ident::make_ident): Likewise.
* libproc_macro/ident.h (Ident__new): Likewise.
(Ident__new_raw): Likewise.
* libproc_macro/literal.cc (Literal::clone): Clone the
span.
(Literal::make_literal): Add span argument.
(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.
(Literal::make_char): Likewise.
(Literal::make_usize): Likewise.
(Literal::make_isize): Likewise.
* libproc_macro/literal.h (struct Literal): Add span to
Literal structure.
* libproc_macro/punct.cc (Punct::make_punct): Add span
argument to punct constructor.
* libproc_macro/punct.h (struct Punct): Add span to
Punct structure.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add Span definition
Pierre-Emmanuel Patry [Fri, 26 May 2023 16:03:28 +0000 (18:03 +0200)]
gccrs: libproc_macro: Add Span definition

Add Span type definition in the rust interface.

libgrust/ChangeLog:

* libproc_macro/rust/bridge/group.rs: Add span member
to the Group structure.
* libproc_macro/rust/bridge/ident.rs: Likewise with the
Ident structure.
* libproc_macro/rust/bridge/literal.rs: Likewise with
the Literal structure.
* libproc_macro/rust/bridge/punct.rs: Likewise with the
Punct structure.
* libproc_macro/rust/bridge/span.rs: Add span
internals.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Properly match delimiters
Owen Avery [Tue, 30 May 2023 20:24:08 +0000 (16:24 -0400)]
gccrs: Properly match delimiters

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc
(MacroExpander::try_match_rule): Don't match delimiters for root matcher.
(MacroExpander::match_matcher): Add option to match delimiters.
* expand/rust-macro-expand.h
(MacroExpander::match_matcher): Likewise.
* parse/rust-parse-impl.h
(Parser::skip_token): Add zero argument method.
* parse/rust-parse.h:
(Parser::skip_token): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: get rid of useless helper class and fix header usage
Philip Herron [Thu, 1 Jun 2023 11:51:18 +0000 (12:51 +0100)]
gccrs: get rid of useless helper class and fix header usage

gcc/rust/ChangeLog:

* Make-lang.in: remove files
* backend/rust-compile-block.h: fix headers
* backend/rust-compile-expr.h: likewise
* backend/rust-compile-fnparam.h: likewise
* backend/rust-compile-item.h: likewise
* backend/rust-compile-pattern.h: likewise
* backend/rust-compile-resolve-path.h: likewise
* backend/rust-compile-stmt.h: likewise
* typecheck/rust-autoderef.cc: likewise
* typecheck/rust-hir-path-probe.cc: likewise
* typecheck/rust-hir-path-probe.h: likewise
* typecheck/rust-hir-trait-reference.h: likewise
* typecheck/rust-hir-trait-resolve.cc: use a for loop instead
* typecheck/rust-hir-trait-resolve.h: fix headers
* typecheck/rust-hir-type-check-expr.h: likewise
* typecheck/rust-hir-type-check-implitem.h: likewise
* typecheck/rust-hir-type-check-item.h: likewise
* typecheck/rust-hir-type-check-path.cc: likewise
* typecheck/rust-hir-type-check-pattern.h: likewise
* typecheck/rust-hir-type-check-stmt.h: likewise
* typecheck/rust-hir-type-check-type.h: likewise
* typecheck/rust-hir-type-check-util.cc: Removed.
* typecheck/rust-hir-type-check-util.h: Removed.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: expansion: Add base for deriving builtin macros (Clone, Copy...)
Arthur Cohen [Thu, 25 May 2023 12:18:39 +0000 (14:18 +0200)]
gccrs: expansion: Add base for deriving builtin macros (Clone, Copy...)

gcc/rust/ChangeLog:

* Make-lang.in: Add new object files to Makefile.
* expand/rust-expand-visitor.cc (is_derive): Move function.
(is_builtin): Likewise.
(get_traits_to_derive): New function.
(derive_item): Likewise.
(ExpandVisitor::visit): Visit item/statements containers.
(ExpandVisitor::visit_outer_attrs): Take a reference on the attribute
instead of a copy.
(ExpandVisitor::is_derive): Deleted function.
(ExpandVisitor::is_builtin): Likewise.
* expand/rust-expand-visitor.h (RUST_EXPAND_VISITOR_H): Add missing #ifdef
guards.
(is_derive): Declare function.
(is_builtin): Likewise.
* expand/rust-macro-builtins.cc (builtin_macro_from_string): Use new
MacroBuiltin::builtins map.
(make_macro_path_str): Likewise.
* expand/rust-macro-builtins.h (enum class): Add builtin derive macros.
* expand/rust-derive-clone.cc: New file.
* expand/rust-derive-clone.h: New file.
* expand/rust-derive.cc: New file.
* expand/rust-derive.h: New file.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Fix logic for
setting builtin macro transcribers.

gcc/testsuite/ChangeLog:

* rust/compile/macro43.rs: Fix test with new derive macros.
* rust/compile/derive_macro1.rs: New test.
* rust/compile/derive_macro3.rs: New test.
* rust/execute/torture/derive_macro1.rs: New test.
* rust/execute/torture/derive_macro3.rs: New test.

6 months agogccrs: ast: Add AstBuilder class.
Arthur Cohen [Thu, 25 May 2023 12:18:47 +0000 (14:18 +0200)]
gccrs: ast: Add AstBuilder class.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: New file.
* ast/rust-ast-builder.h: New file.

6 months agogccrs: expand: Add missing copyright headers
Arthur Cohen [Wed, 31 May 2023 13:12:14 +0000 (15:12 +0200)]
gccrs: expand: Add missing copyright headers

Fixes #2250

gcc/rust/ChangeLog:

* expand/rust-macro-invoc-lexer.cc: Add missing copyright header.
* expand/rust-macro-substitute-ctx.cc: Likewise.

6 months agogccrs: Make key and key/value config options seperate
Owen Avery [Fri, 19 May 2023 04:05:19 +0000 (00:05 -0400)]
gccrs: Make key and key/value config options seperate

gcc/rust/ChangeLog:

* rust-session-manager.h:
Include "rust-optional.h".
(struct TargetOptions):
Store values in config key/value pairs as Optional<std::string> rather than std::string.
* rust-session-manager.cc
(TargetOptions::dump_target_options):
Handle Optional<std::string> values.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Fix cast site to not miss type-unifications
Philip Herron [Tue, 30 May 2023 16:16:30 +0000 (17:16 +0100)]
gccrs: Fix cast site to not miss type-unifications

When attempting casts we can try a type coercion first, this is a
TryCoercion which will return a result. In the event this is ok we need to
perform a true coercion so that we don't leave missing infeence variable's
ununified.

Fixes #2195

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::check): do coercion
(TypeCastRules::emit_cast_error): clang-format

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Add missing name resolution to item statements
Philip Herron [Tue, 30 May 2023 12:45:58 +0000 (13:45 +0100)]
gccrs: Add missing name resolution to item statements

This fixes the issue but there are two cleanups to do at some point.

  1. misc namesapce this is a scope AST namespace where we dump resolution
     info when its not defined here. This occurs in the case such as nested
     scopes where the nested scope is popped and we hit an assertion.
     Outside of name resolution this requirement shouldnt really apply
     it should be permissive to allow for this

  2. We reuse our existing name resolution pieces here for Traits and impl
     blocks we should start doing this for the other statements.

Fixes #2238

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): add name resolution
* resolve/rust-ast-resolve-stmt.h: likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): insert resolved node

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: remove unused header
Philip Herron [Tue, 30 May 2023 12:45:36 +0000 (13:45 +0100)]
gccrs: remove unused header

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-pattern.cc: remove unused

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Fix missing pop of name scope at the end of Trait Impl
Philip Herron [Tue, 30 May 2023 12:45:14 +0000 (13:45 +0100)]
gccrs: Fix missing pop of name scope at the end of Trait Impl

This adds the missing label scope and fixes the missing pop of the name
scope at the end of the resolution for a TraitImpl.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): fix missing pop

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: remove useless lookup to NodeId
Philip Herron [Tue, 30 May 2023 11:10:40 +0000 (12:10 +0100)]
gccrs: remove useless lookup to NodeId

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): remove unused

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Add missing HIR lowering to item statements
Philip Herron [Tue, 30 May 2023 08:52:34 +0000 (09:52 +0100)]
gccrs: Add missing HIR lowering to item statements

Addresses #2238

gcc/rust/ChangeLog:

* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::translate): hir lowering
(ASTLoweringStmt::visit): likewise
* hir/rust-ast-lower-stmt.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Avoid invalid metavariable substitutions
Owen Avery [Sun, 28 May 2023 17:33:52 +0000 (13:33 -0400)]
gccrs: Avoid invalid metavariable substitutions

gcc/rust/ChangeLog:

* expand/rust-macro-substitute-ctx.cc
(SubstituteCtx::substitute_metavar): Allow substitution failure.
(SubstituteCtx::substitute_token):
Handle substitution failure, include dollar sign in count of tokens to substitute.
(SubstituteCtx::substitute_tokens):
Include dollar sign in count of tokens to substitute.
* expand/rust-macro-substitute-ctx.h
(SubstituteCtx::substitute_metavar):
Adjust signature and document new substitution failure handling.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Fix handling of single fragments in repetitions
Owen Avery [Mon, 29 May 2023 03:44:57 +0000 (23:44 -0400)]
gccrs: Fix handling of single fragments in repetitions

gcc/rust/ChangeLog:

* expand/rust-macro-substitute-ctx.cc
(SubstituteCtx::check_repetition_amount):
Ignore single fragments while checking repetition amount.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Fix bounds checking to check both sides
Philip Herron [Thu, 25 May 2023 16:43:31 +0000 (17:43 +0100)]
gccrs: Fix bounds checking to check both sides

We were missing bounds checking for both lhs and rhs directions this is
important as we might fail checking for all specified bounds properly.
This is why for #2236 we need the Type parameter T to realise that it
_cannot_ coerce to the i32 max function directly without any adjustments
because T has the specified bound of Deref but i32 does not implement
Deref. This indrectly forces the autoderef cycle to try a deref in order
to get an i32 which _will_ match the i32 max function in the case we
pass an &32 as the type parameter T.

Fixes #2236

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): stop if error
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): fix sized options
* typecheck/rust-tyty.cc (BaseType::satisfies_bound): its ok if its an ?T
(BaseType::bounds_compatible): likewise
* typecheck/rust-tyty.h: update prototype
* typecheck/rust-unify.cc (UnifyRules::go): check both sides bounds

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: support deref cycles to resolve to trait items
Philip Herron [Tue, 23 May 2023 16:55:32 +0000 (17:55 +0100)]
gccrs: support deref cycles to resolve to trait items

Fixes #2190

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (HIRCompileBase::resolve_deref_adjustment):
reuse op overload code
* typecheck/rust-autoderef.cc (Adjuster::try_deref_type): update
(Adjuster::try_raw_deref_type): likewise
* typecheck/rust-autoderef.h: likewise
* typecheck/rust-hir-dot-operator.cc (MethodResolver::select):
improve debug loging

gcc/testsuite/ChangeLog:

* rust/compile/issue-2190-1.rs: New test.
* rust/compile/issue-2190-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: refactor resolve_method_address to be more generic
Philip Herron [Tue, 23 May 2023 13:35:17 +0000 (14:35 +0100)]
gccrs: refactor resolve_method_address to be more generic

We can reuse the DefId to lookup the mappings to Items or Trait Items
instead of the HirId this is more generic and can then be reused for the
deref operator overload during autoderef cycles.

Addresses #2190

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address): refactor
* backend/rust-compile-base.h: likewise
* backend/rust-compile-expr.cc (CompileExpr::visit): likewise
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: hir: remove stray semicolon
David Malcolm [Wed, 24 May 2023 13:19:43 +0000 (09:19 -0400)]
gccrs: hir: remove stray semicolon

Fix for this warning:

../../src/gcc/rust/typecheck/rust-hir-trait-reference.cc:40:2: warning: extra ‘;’ [-Wpedantic]
   40 | };
      |  ^

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.cc (TraitItemReference::is_optional): Remove
stray semicolon.

6 months agogccrs: enr: Cleanup #[macro_use] accumulation
Arthur Cohen [Mon, 22 May 2023 09:22:45 +0000 (11:22 +0200)]
gccrs: enr: Cleanup #[macro_use] accumulation

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver.cc (EarlyNameResolver::go): Cleanup
order of calls when accumulating #[macro_use] macros.
(EarlyNameResolver::visit): Likewise.

6 months agogccrs: Fix macro resolutions in middle of multiple nested macro_use modules
Matthew Jasper [Fri, 19 May 2023 10:21:27 +0000 (11:21 +0100)]
gccrs: Fix macro resolutions in middle of multiple nested macro_use modules

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver.cc (EarlyNameResolver::accumulate_escaped_macros):
Remove unnecessary visit.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
6 months agogccrs: Only check first item of cfg_attr attribute as predicate
Matthew Jasper [Sun, 21 May 2023 19:23:27 +0000 (20:23 +0100)]
gccrs: Only check first item of cfg_attr attribute as predicate

In #[cfg_attr(A, B, C(D))], only A is a predicate.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::check_cfg_predicate):
Only check first item as a predicate.

gcc/testsuite/ChangeLog:

* rust/compile/cfg-attr.rs: New test.

Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
6 months agogccrs: Add operator== for Optional.
Owen Avery [Fri, 19 May 2023 17:15:34 +0000 (13:15 -0400)]
gccrs: Add operator== for Optional.

gcc/rust/ChangeLog:

* util/rust-optional.h
(operator==): New for Optional<T> == Optional<U>.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Parse AttrInputMacro
Owen Avery [Sun, 30 Apr 2023 06:57:15 +0000 (02:57 -0400)]
gccrs: Parse AttrInputMacro

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_attr_input): Parse AttrInputMacro.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: ast: Propagate type suffix
Pierre-Emmanuel Patry [Thu, 11 May 2023 14:13:41 +0000 (16:13 +0200)]
gccrs: ast: Propagate type suffix

Propagate back type suffix to created tokens.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Propagate
coretype hint.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Improve Optional<T> implementation
Owen Avery [Fri, 12 May 2023 07:13:30 +0000 (03:13 -0400)]
gccrs: Improve Optional<T> implementation

gcc/rust/ChangeLog:

* util/rust-optional.h
(class Optional<T>): Improve inner state.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Handle keyword metavariables
Owen Avery [Wed, 17 May 2023 16:32:23 +0000 (12:32 -0400)]
gccrs: Handle keyword metavariables

gcc/rust/ChangeLog:

* expand/rust-macro-substitute-ctx.cc
(SubstituteCtx::check_repetition_amount): Handle keywords.
(SubstituteCtx::substitute_token): Likewise.
* lex/rust-token.cc
(Token::get_str): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_macro_match_fragment): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: ast: Add `outer_attrs` to all `Item`s
Arthur Cohen [Tue, 25 Apr 2023 12:43:15 +0000 (14:43 +0200)]
gccrs: ast: Add `outer_attrs` to all `Item`s

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add `outer_attrs` to Item.
* ast/rust-expr.h: Make use of new inheritance methods.
* ast/rust-item.h: Likewise.
* ast/rust-macro.h: Likewise.

6 months agogccrs: libproc_macro: Change constructor in ffistring
Pierre-Emmanuel Patry [Tue, 16 May 2023 12:01:36 +0000 (14:01 +0200)]
gccrs: libproc_macro: Change constructor in ffistring

The "new" constructor wasn't fitting it's usage well.

libgrust/ChangeLog:

* libproc_macro/rust/bridge/ffistring.rs: Implement
From trait for FFIString.
* libproc_macro/rust/bridge/literal.rs: Change
constructor call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Copy ffistring data from source
Pierre-Emmanuel Patry [Tue, 16 May 2023 11:25:40 +0000 (13:25 +0200)]
gccrs: libproc_macro: Copy ffistring data from source

Data from source pointer were not copied correctly in the ffistring
constructor.

libgrust/ChangeLog:

* libproc_macro/ffistring.cc (FFIString::make_ffistring):
Add copy from source pointer.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Remove has_suffix attribute
Pierre-Emmanuel Patry [Thu, 11 May 2023 10:35:18 +0000 (12:35 +0200)]
gccrs: libproc_macro: Remove has_suffix attribute

This variable was redundant with the empty string representation and
may have lead to desync between both.

libgrust/ChangeLog:

* libproc_macro/literal.h: Remove has_suffix member
attribute from Literal.
* libproc_macro/literal.cc: Update constructors.
* libproc_macro/rust/bridge/literal.rs: Remove
has_suffix attribute from Literal.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Merge dispatch into one function
Pierre-Emmanuel Patry [Thu, 11 May 2023 10:23:38 +0000 (12:23 +0200)]
gccrs: converter: Merge dispatch into one function

Floating point and integer dispatch now have almost the same behavior,
their code could therefore be merged.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (dispatch_float_literals): Remove
function.
(handle_suffix): Rename old dispatch and add one LitKind
argument.
(dispatch_integer_literals): Remove function.
(convert): Change call from dispatch to suffix handler.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Change cpp literal representation
Pierre-Emmanuel Patry [Wed, 10 May 2023 13:17:46 +0000 (15:17 +0200)]
gccrs: libproc_macro: Change cpp literal representation

Change the literal representation on cpp side to match the new one in
rust. This means FFIString had to be implemented on cpp side. A few
helper functions has also been introduced.

libgrust/ChangeLog:

* libproc_macro/Makefile.am: Add ffistring unit to
compiled objects list.
* libproc_macro/Makefile.in: Regenerate.
* libproc_macro/literal.cc (Literal::drop): Change with
a call to ffistring drop function.
(Literal::make_literal): Add new helper constructor
(Literal__drop): Remove this function.
(Literal__string): Likewise.
(Literal__byte_string): Likewise.
(Literal__from_string): Moved this function.
(Literal::make_unsigned): Changed the constructor to match the
new layout.
(Literal::make_signed): Likewise.
(Literal::clone): Reimplement th eclone function.
(Literal::make_u8): Changed the constructor, make suffixed by
default.
(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.
(Literal::make_char): Likewise.
(Literal::make_usize): Likewise.
(Literal::make_isize): Likewise.
(LitKind::make_byte): Add new helper constructor to avoid having
to set the payload value.
(LitKind::make_char): Likewise.
(LitKind::make_integer): Likewise.
(LitKind::make_float): Likewise.
(LitKind::make_str): Likewise.
(LitKind::make_str_raw): Add a new helper constructor which
takes the payload value as an argument.
(LitKind::make_byte_str): Add new helper constructor to avoid
mistakes with payload value.
(LitKind::make_byte_str_raw): Add a new helper constructor which
takes the payload value as an argument.
* libproc_macro/literal.h: Add new functions prototype.
(enum UnsignedTag): Removed because it is now unused.
(struct Payload128): Likewise.
(union UnsignedPayload): Likewise.
(struct Unsigned): Likewise.
(enum SignedTag): Likewise.
(union SignedPayload): Likewise.
(struct Signed): Likewise.
(enum LiteralTag): Likewise.
(enum LitKindTag): Likewise.
(struct StringPayload): Likewise.
(struct ByteStringPayload): Likewise.
(union LitKindPayload): Likewise.
(struct UnsignedSuffixPayload): Likewise.
(struct LitKind): Add new literal kind struct representation to
match the enum on rust side.
(struct SignedSuffixPayload): Removed because now unused.
(struct UsizePayload): Likewise.
(struct IsizePayload): Likewise.
(struct Float32Payload): Likewise.
(struct Float64Payload): Likewise.
(union LiteralPayload): Likewise.
(struct Literal): Changed the internals of the structure.
(Literal__drop): Removed the drop function fom the c interface.
(Literal__string): Removed unused function.
(Literal__byte_string): Removed unused function.
* libproc_macro/ffistring.cc: New file.
* libproc_macro/ffistring.h: New file.

gcc/rust/ChangeLog:

* lex/rust-token.h: Implement hash for token id enumeration.
* util/rust-token-converter.cc (dispatch_float_literals): Update
to new internals.
(dispatch_integer_literals): Likewise.
(convert): Likewise.
(string_literal): Remove function.
(byte_string_literal): Likewise.
(unsigned_literal): Likewise.
(signed_literal): Likewise.
(from_literal): Update with new internals.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Change rust literal internals
Pierre-Emmanuel Patry [Wed, 10 May 2023 09:34:45 +0000 (11:34 +0200)]
gccrs: libproc_macro: Change rust literal internals

Rust interface literal internals were taking a type and storing that
type. This lead to multiple problems such as various conversion from
string to int/float/other type as well as dead end on undetermined types
(type checker runs at a later stage).

libgrust/ChangeLog:

* libproc_macro/rust/bridge.rs: Add ffistring module.
* libproc_macro/rust/bridge/literal.rs: Rework type
internals.
* libproc_macro/rust/bridge/ffistring.rs: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Add AST::AttrInputMacro
Owen Avery [Sun, 30 Apr 2023 06:54:22 +0000 (02:54 -0400)]
gccrs: Add AST::AttrInputMacro

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc
(Dump::visit): Add AttrInputMacro visitor.
* ast/rust-ast-dump.h:
(Dump::visit): Likewise.
* ast/rust-ast-full-decls.h
(class AttrInputMacro): New.
* ast/rust-ast-collector.cc
(TokenCollector::visit):
Add and call out to AttrInputMacro visitor.
* ast/rust-ast-collector.h:
(TokenCollector::visit): Add AttrInputMacro visitor.
* ast/rust-ast-visitor.h:
(ASTVisitor::visit): Likewise.
* ast/rust-ast.cc
(AttrInputMacro::accept_vis): New.
(AttrInputMacro::as_string): New.
(AttrInputMacro::AttrInputMacro): New.
(AttrInputMacro::operator=): New.
* ast/rust-ast.h:
(AttrInput::AttrInputType::MACRO): New.
* ast/rust-expr.h
(class AttrInputMacro): New.
* checks/errors/rust-feature-gate.h:
(FeatureGate::visit): Add AttrInputMacro visitor.
* 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.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h:
(ResolverBase::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h:
(EarlyNameResolver::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
(check_doc_attribute): Handle AttrInputType::MACRO.
* util/rust-attributes.h:
(AttributeChecker::visit): Add AttrInputMacro visitor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Make MacroInvocation cloning public
Owen Avery [Thu, 11 May 2023 04:29:04 +0000 (00:29 -0400)]
gccrs: Make MacroInvocation cloning public

gcc/rust/ChangeLog:

* ast/rust-macro.h
(MacroInvocation::clone_macro_invocation_impl): Make public.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Allow hashing Optional<T>
Owen Avery [Fri, 12 May 2023 07:14:29 +0000 (03:14 -0400)]
gccrs: Allow hashing Optional<T>

gcc/rust/ChangeLog:

* util/rust-optional.h
(struct std::hash<Optional<T>>): New.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Improve Optional<T&> implementation
Owen Avery [Fri, 12 May 2023 07:05:03 +0000 (03:05 -0400)]
gccrs: Improve Optional<T&> implementation

gcc/rust/ChangeLog:

* util/rust-optional.h
(class Optional<T&>): Use pointers internally.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: dump: Dump `TupleIndexExpr`s
Arthur Cohen [Fri, 12 May 2023 12:44:54 +0000 (14:44 +0200)]
gccrs: dump: Dump `TupleIndexExpr`s

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Implement dump for
`TupleIndexExpr`.

6 months agogccrs: Change return type of token_id_keyword_string
Owen Avery [Tue, 16 May 2023 04:31:38 +0000 (00:31 -0400)]
gccrs: Change return type of token_id_keyword_string

gcc/rust/ChangeLog:

* lex/rust-token.cc
(token_id_keyword_string): Return std::string reference.
* lex/rust-token.h
(token_id_keyword_string): Return std::string reference.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Fix parsing of block expressions followed by `.`
Matthew Jasper [Wed, 10 May 2023 01:08:37 +0000 (02:08 +0100)]
gccrs: Fix parsing of block expressions followed by `.`

`{ ... }.f;` is parsed as a single statement in rust. This means that we can't
determine whether an expression statement will need a semicolon terminator
until we finish parsing it. To handle this we change expression parsing to
check for this case by inspecting the expression returned from null_denotation
and looking ahead for a `.` or `?` token.

gcc/rust/ChangeLog:

* ast/rust-ast.h (Expr::as_expr_without_block): Remove.
(Expr::set_outer_attrs): Make public in base class.
* expand/rust-macro-expand.cc:
Add fixme comment for pre-existing bug.
* hir/tree/rust-hir.h: Remove Expr::as_expr_without_block.
* parse/rust-parse-impl.h (Parser::parse_lifetime): Use lifetime_from_token.
(Parser::lifetime_from_token): New method.
(Parser::null_denotation): Handle labelled loop expressions and for loop expressions.
(Parser::parse_loop_label): Make initial token a parameter.
(Parser::parse_labelled_loop_expr): Likewise.
(Parser::parse_for_loop_expr): Allow FOR token to already be skipped.
(Parser::parse_expr): Handle expr_can_be_stmt.
(Parser::parse_expr_with_block): Remove.
(Parser::parse_expr_stmt_with_block): Remove.
(Parser::parse_expr_stmt_without_block): Remove.
(Parser::parse_expr_without_block): Remove.
(Parser::parse_stmt_or_expr_with_block): Remove.
(Parser::parse_expr_stmt): Use parse_expr directly.
(Parser::parse_match_expr): Likewise.
(Parser::parse_stmt): Use parse_expr_stmt in more cases.
(Parser::parse_stmt_or_expr):
Rename from parse_stmt_or_expr_without_block, use parse_expr directly.
(Parser::parse_block_expr): Update error message.
* parse/rust-parse.h: Update declarations.

gcc/testsuite/ChangeLog:

* rust/compile/for_expr.rs: New test.
* rust/compile/issue-407-2.rs: Update compiler output.
* rust/compile/issue-407.rs: Update compiler output.
* rust/compile/issue-867.rs: Update compiler output.
* rust/compile/issue-2189.rs: New test.
* rust/compile/macro_call_statement.rs: New test.
* rust/compile/stmt_with_block_dot.rs: New test.
* rust/compile/torture/loop8.rs: New test.

Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
6 months agogccrs: ast: Remove ExprStmtWithBlock / ExprStmtWithoutBlock distinction
Matthew Jasper [Tue, 9 May 2023 11:53:33 +0000 (12:53 +0100)]
gccrs: ast: Remove ExprStmtWithBlock / ExprStmtWithoutBlock distinction

This distinction isn't very helpful and makes correct parsing harder.

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* ast/rust-stmt.h (class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
(class ExprStmt):
Make non-abstract, add common functionality from removed base classes.
* ast/rust-ast.h: Move to_stmt to base class.
* ast/rust-ast.cc (ExprStmtWithBlock::as_string): Remove.
* ast/rust-macro.h: Use new signature for to_stmt.
(ExprStmt::as_string): New method.
(ExprStmtWithoutBlock::as_string): Remove.
(BlockExpr::strip_tail_expr): Update for removed classes.
(ExprStmtWithoutBlock::accept_vis): Remove.
(ExprStmtWithBlock::accept_vis): Remove.
(ExprStmt::accept_vis): New method.
* ast/rust-ast-dump.cc (Dump::visit): Update for removed classes.
* ast/rust-ast-dump.h: Likewise.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-collector.cc (TokenStream::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h: Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
* expand/rust-cfg-strip.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise.
* hir/rust-ast-lower-stmt.h: Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
* util/rust-attributes.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.
* resolve/rust-early-name-resolver.h: Likewise.
* parse/rust-parse-impl.h (Parser::parse_match_expr): Likewise.
(Parser::parse_stmt_or_expr_without_block): Likewise.
* parse/rust-parse.h: Likewise.

Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
6 months agogccrs: Handle keywords in macro fragments
Owen Avery [Tue, 9 May 2023 00:58:59 +0000 (20:58 -0400)]
gccrs: Handle keywords in macro fragments

gcc/rust/ChangeLog:

* lex/rust-token.cc
(token_id_is_keyword): New.
(token_id_keyword_string): New.
* lex/rust-token.h
(token_id_is_keyword): New.
(token_id_keyword_string): New.
* expand/rust-macro-expand.cc
(MacroExpander::match_fragment): Match keywords for ident fragment.
* parse/rust-parse-impl.h
(Parser::parse_identifier_or_keyword_token): Add.
* parse/rust-parse.h
(Parser::parse_identifier_or_keyword_token): Add.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Address invalid little-endian-only testcases
Arthur Cohen [Thu, 11 May 2023 08:19:56 +0000 (10:19 +0200)]
gccrs: Address invalid little-endian-only testcases

gcc/testsuite/ChangeLog:

* rust/compile/const-issue1440.rs: Remove LE conditional compilation.
* rust/compile/torture/issue-1432.rs: Likewise.

6 months agogccrs: converter: Fix suffix condition
Pierre-Emmanuel Patry [Fri, 5 May 2023 12:40:20 +0000 (14:40 +0200)]
gccrs: converter: Fix suffix condition

The suffix condition was wrong, the code was assigning a suffix to
unsuffixed literals. The literals length equals the end of digit
parsing position  means there is no suffix.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (dispatch_float_literals): Invert
suffix condition.
(dispatch_integer_literals): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Fix some styling issues
Pierre-Emmanuel Patry [Fri, 5 May 2023 12:34:09 +0000 (14:34 +0200)]
gccrs: converter: Fix some styling issues

Fix multiple issues regarding style around loops and conditions with one
single element.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (convert): Fix style.
(from_ident): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Make converter input immutable
Pierre-Emmanuel Patry [Wed, 3 May 2023 13:33:43 +0000 (15:33 +0200)]
gccrs: converter: Make converter input immutable

Inputs of the converter are never changed and may thus be qualified as
const.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (dispatch_float_literals): Make
input immutable.
(dispatch_integer_literals): Likewise.
(convert): Likewise.
* util/rust-token-converter.h (convert): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Add Ident conversions
Pierre-Emmanuel Patry [Wed, 3 May 2023 13:18:51 +0000 (15:18 +0200)]
gccrs: converter: Add Ident conversions

Add the implementation to convert an Ident structure back to a token.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (from_tokenstream): Add
conversion of Ident structures.
(from_ident): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Convert literals back to tokens
Pierre-Emmanuel Patry [Wed, 3 May 2023 12:38:51 +0000 (14:38 +0200)]
gccrs: converter: Convert literals back to tokens

Add the implementation of the function to convert Literal back to
tokens. Also change the function signature to accept const.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (from_literal): Add function
implementation.
(string_literal): String literal specific handler.
(byte_string_literal): Byte string specific handler.
(unsigned_literal): Unsigned literal specific handler.
(signed_literal): Signed literal specific handler.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Add punct conversion function
Pierre-Emmanuel Patry [Wed, 3 May 2023 10:38:06 +0000 (12:38 +0200)]
gccrs: converter: Add punct conversion function

Add the implementation of the Punct conversion function to tokens.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (from_punct): Add conversion
implementation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Const conversion to tokenstream
Pierre-Emmanuel Patry [Wed, 3 May 2023 10:09:59 +0000 (12:09 +0200)]
gccrs: converter: Const conversion to tokenstream

Make the conversion to tokenstream accept a const pointer vector instead
of a simple pointer vector because no changes are made to the original
tokens.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (dispatch_float_literals): Accept
const_TokenPtr instead of TokenPtr.
(dispatch_integer_literals): Likewise.
(convert): Accept vector of const_TokenPtr instead of a vector
of TokenPtr.
* util/rust-token-converter.h (convert): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Return a vector to const pointers
Pierre-Emmanuel Patry [Wed, 3 May 2023 10:04:20 +0000 (12:04 +0200)]
gccrs: converter: Return a vector to const pointers

We do not need mutability on the output vector. Also add an accumulator
for punct tokens.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (from_tokenstream): Add vector
for joined punct accumulation.
(from_ident): Accept const pointer vector.
(from_literal): Likewise.
(from_punct): Likewise.
(from_group): Likewise.
(from_tokentree): Likewise.
(convert): Likewise.
* util/rust-token-converter.h (convert): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Add from_tokentree function
Pierre-Emmanuel Patry [Wed, 3 May 2023 08:42:36 +0000 (10:42 +0200)]
gccrs: converter: Add from_tokentree function

Add the from_tokentree function which converts a tokentree to it's
token representation. This function was previously inlined in the
from_tokenstream function but I wanted to keep things clear and
coherent.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (from_tokenstream): Add call to
from_tokentree.
(from_tokentree): Add implementation, from the from_tokenstream
function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Add group conversion implementation
Pierre-Emmanuel Patry [Wed, 3 May 2023 08:32:17 +0000 (10:32 +0200)]
gccrs: converter: Add group conversion implementation

Add conversion of a given Group reference.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (from_punct): Add group
conversion.
(from_group): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Add TokenStream conversion function
Pierre-Emmanuel Patry [Wed, 3 May 2023 08:17:16 +0000 (10:17 +0200)]
gccrs: converter: Add TokenStream conversion function

Add a tokenstream conversion function dispatching to inner elements

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (to_tokenstream): Change function
name from to_tokenstream to convert.
(convert): Likewise.
(from_tokenstream): Add tokenstream handler.
(from_ident): Add empty function.
(from_literal): Likewise.
(from_punct): Likewise.
(from_group): Likewise.
* util/rust-token-converter.h (to_tokenstream): Change function
name from to_tokenstream to convert.
(convert): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: converter: Remove redundant variable
Pierre-Emmanuel Patry [Tue, 2 May 2023 14:53:17 +0000 (16:53 +0200)]
gccrs: converter: Remove redundant variable

Since the introduction of this variable the code has changed and no
value order preservation is required anymore, the comparison can be done
inline.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (dispatch_float_literals): Remove
suffixed temporary variable.
(dispatch_integer_literals): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Move token converter out of ast module
Pierre-Emmanuel Patry [Tue, 2 May 2023 14:34:46 +0000 (16:34 +0200)]
gccrs: ast: Move token converter out of ast module

Move the token vector to tokenstream converter out of the TokenCollector
class. This code is not exactly related to the token collection and the
code would be clearer with this rather lengthy conversion split on it's
own.

gcc/rust/ChangeLog:

* Make-lang.in: Add new rust-token-converter file.
* ast/rust-ast-collector.cc (pop_group): Function moved from
TokenCollector.
(dispatch_float_literals): Likewise.
(dispatch_integer_literals): Likewise.
(TokenCollector::collect): Removed function.
* ast/rust-ast-collector.h: Removed function prototype.
* util/rust-token-converter.cc: New file.
* util/rust-token-converter.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Rename header guard
Pierre-Emmanuel Patry [Tue, 2 May 2023 14:14:38 +0000 (16:14 +0200)]
gccrs: ast: Rename header guard

The header guard did not match the file name anymore.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.h (RUST_AST_TOKENSTREAM_H): Rename
headerguard from RUST_AST_TOKENSTREAM_H ...
(RUST_AST_COLLECTOR_H): ... to RUST_AST_COLLECTOR_H.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Rename rust-ast-tokenstream file
Pierre-Emmanuel Patry [Tue, 2 May 2023 14:02:55 +0000 (16:02 +0200)]
gccrs: ast: Rename rust-ast-tokenstream file

The file does not contain any TokenStream declaration anymore and thus
should be named more appropriately.

gcc/rust/ChangeLog:

* Make-lang.in: Change file name.
* ast/rust-ast-tokenstream.cc: Moved to...
* ast/rust-ast-collector.cc: ...here.
* ast/rust-ast-tokenstream.h: Moved to...
* ast/rust-ast-collector.h: ...here.
* rust-session-manager.cc: Change header name.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: ast: Rename TokenStream in the AST module
Pierre-Emmanuel Patry [Tue, 2 May 2023 13:49:10 +0000 (15:49 +0200)]
gccrs: ast: Rename TokenStream in the AST module

Rename the TokenStream class to TokenCollector as it may induce errors
in the future as it is not a tokenstream as defined by the rust
interface. Furthermore this change match more closely the actual behavior
of the class.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::TokenStream): Rename
TokenStream to TokenCollector.
(TokenCollector::TokenCollector): Likewise.
(TokenStream::collect_tokens): Likewise.
(TokenCollector::collect_tokens): Likewise.
(TokenStream::collect): Likewise.
(TokenCollector::collect): Likewise.
(TokenStream::visit): Likewise.
(TokenCollector::visit): Likewise.
(TokenStream::visit_items_joined_by_separator): Likewise.
(TokenCollector::visit_items_joined_by_separator): Likewise.
(TokenStream::visit_as_line): Likewise.
(TokenCollector::visit_as_line): Likewise.
(TokenStream::visit_items_as_lines): Likewise.
(TokenCollector::visit_items_as_lines): Likewise.
(TokenStream::visit_items_as_block): Likewise.
(TokenCollector::visit_items_as_block): Likewise.
(TokenStream::trailing_comma): Likewise.
(TokenCollector::trailing_comma): Likewise.
(TokenStream::newline): Likewise.
(TokenCollector::newline): Likewise.
(TokenStream::indentation): Likewise.
(TokenCollector::indentation): Likewise.
(TokenStream::increment_indentation): Likewise.
(TokenCollector::increment_indentation): Likewise.
(TokenStream::decrement_indentation): Likewise.
(TokenCollector::decrement_indentation): Likewise.
(TokenStream::visit_closure_common): Likewise.
(TokenCollector::visit_closure_common): Likewise.
(TokenStream::visit_loop_common): Likewise.
(TokenCollector::visit_loop_common): Likewise.
(TokenStream::visit_function_common): Likewise.
(TokenCollector::visit_function_common): Likewise.
* ast/rust-ast-tokenstream.h (class TokenStream): Likewise.
(class TokenCollector): Likewise.
* rust-session-manager.cc (Session::dump_tokenstream): Rename
token vector for clearer intent.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: tokenstream: Add conversion for float literals
Pierre-Emmanuel Patry [Fri, 28 Apr 2023 13:07:33 +0000 (15:07 +0200)]
gccrs: tokenstream: Add conversion for float literals

Add the conversion handler for float/double literal tokens to
tokenstream Literals.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (dispatch_float_literals): Add
dispatch function for floating point literals.
(TokenStream::collect): Add call to dispatcher.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: tokenstream: Add literal int draft conversion
Pierre-Emmanuel Patry [Fri, 28 Apr 2023 11:01:05 +0000 (13:01 +0200)]
gccrs: tokenstream: Add literal int draft conversion

Add a first draft for the literal integer conversion to tokenstream
Literal types.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (dispatch_integer_literals):
Add a static function to dispatch depending on the core type.
(TokenStream::collect): Add call to dispatch function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: tokenstream: Add string and byte string literals
Pierre-Emmanuel Patry [Thu, 27 Apr 2023 16:16:44 +0000 (18:16 +0200)]
gccrs: tokenstream: Add string and byte string literals

Add conversion to tokenstream Literals for string and byte strings.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::collect): Add
conversion for byte string and string.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: tokenstream: Add tokens to Ident conversion
Pierre-Emmanuel Patry [Thu, 27 Apr 2023 15:33:35 +0000 (17:33 +0200)]
gccrs: tokenstream: Add tokens to Ident conversion

Add conversion from a rust token to tokenstream Idents.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::collect): Add Ident
conversion.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: tokenstream: Add joint punct token conversion
Pierre-Emmanuel Patry [Thu, 27 Apr 2023 13:17:35 +0000 (15:17 +0200)]
gccrs: tokenstream: Add joint punct token conversion

Add the conversion from tokens to punct structures in tokenstream
conversion function.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::collect): Add joint
punct token conversion.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: tokenstream: Convert single punctuation tokens
Pierre-Emmanuel Patry [Thu, 27 Apr 2023 11:24:40 +0000 (13:24 +0200)]
gccrs: tokenstream: Convert single punctuation tokens

Add the code to convert single punctuation tokens to a tokenstream
element.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::collect): Add
conversion for single punctuation tokens.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: tokenstream: Convert group markers
Pierre-Emmanuel Patry [Thu, 27 Apr 2023 09:01:32 +0000 (11:01 +0200)]
gccrs: tokenstream: Convert group markers

Add conversion for group delimiters.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (pop_group): Add a function to
easily collect a group from a given stack at the end of it.
(TokenStream::collect): Collect tokens as a rust compatible
Tokenstream type.
* ast/rust-ast-tokenstream.h (RUST_AST_TOKENSTREAM_H): Move
includes to stay constrained by guards.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Added HIR::InlineAsm node
M V V S Manoj Kumar [Thu, 16 Mar 2023 05:33:57 +0000 (11:03 +0530)]
gccrs: Added HIR::InlineAsm node

Fixes Issue #1568
Added HIR node HIR::InlineAsm similar to the one found in rustc. In this
I also changed the defination of the AST::InlineAsm node, so that we can
reuse many of it's data members in the HIR::InlineAsm node.

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (enum class): Added declaration.
(struct AnonConst): Added declaration.
(struct InlineAsmRegOrRegClass): Added declaration.
(struct InlineAsmOperand): Added declaration.
(struct InlineAsmPlaceHolder): Added declaration.
(struct InlineAsmTemplatePiece): Added declaration.
(struct TupleClobber): Added declaration.
(struct TupleTemplateStr): Added declaration.
* ast/rust-expr.h (class InlineAsm): Defined all it's data members outside.
(enum class InlineAsmOptions): Converted this to a enum class so we could use it in the HIR.
(struct AnonConst): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmRegOrRegClass): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmOperand): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmPlaceHolder): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmTemplatePiece): Defined it independent of the AST::InlineAsm node.
(struct TupleClobber): Defined it independent of the AST::InlineAsm node.
(struct TupleTemplateStr): Defined it independent of the AST::InlineAsm node.
* hir/tree/rust-hir-expr.h (class InlineAsmReg): Added defination.
(class InlineAsmRegClass): Added defination.
(struct InlineAsmRegOrRegClass): Added defination.
(class InlineAsm): Added defination.
* hir/tree/rust-hir-full-decls.h (class InlineAsmReg): Added declaration.
(class InlineAsmRegClass): Added declaration.
(struct InlineAsmRegOrRegClass): Added declaration.
(class InlineAsm): Added declaration.

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
6 months agogccrs: Add missing coercion site logic to return expressions
Philip Herron [Tue, 9 May 2023 14:59:46 +0000 (15:59 +0100)]
gccrs: Add missing coercion site logic to return expressions

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: track return type in fncontext
* backend/rust-compile-context.h (struct fncontext): likewise
* backend/rust-compile-expr.cc (CompileExpr::visit): apply coercion site
(CompileExpr::generate_closure_function): update push_context
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: add missing coercion site code generation for block tail
Philip Herron [Tue, 9 May 2023 13:47:37 +0000 (14:47 +0100)]
gccrs: add missing coercion site code generation for block tail

Fixes #2179

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::compile_function_body):
add missing coercion_site codegen

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: unify how we handle DST's
Philip Herron [Mon, 8 May 2023 13:10:57 +0000 (14:10 +0100)]
gccrs: unify how we handle DST's

DST's are not truely reference types they are "unsized types" so
the exact size of them is not known at compile time. We actually
achieve this by pretending they are a reference but really its
struct we pass around.

Fixes #2180

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): refactr
(CompileExpr::get_fn_addr_from_dyn): likewise
(CompileExpr::get_receiver_from_dyn): likewise
(CompileExpr::type_cast_expression): likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): likewise
(TyTyResolveCompile::create_dyn_obj_record): likewise
(TyTyResolveCompile::create_slice_type_record): likewise
(TyTyResolveCompile::create_str_type_record): likewise
* backend/rust-compile-type.h: likewise
* backend/rust-compile.cc (HIRCompileBase::coercion_site1): likewise
(HIRCompileBase::coerce_to_dyn_object): refactor
* backend/rust-tree.h (SLICE_FLAG): removed
(SLICE_TYPE_P): removed
(RS_DST_FLAG): new flag
(RS_DST_FLAG_P): new predicate
* typecheck/rust-tyty.cc (ReferenceType::is_dyn_object): new helper
(ReferenceType::is_dyn_obj_type): likewise
(PointerType::is_dyn_object): likewise
(PointerType::is_dyn_obj_type): likewise
* typecheck/rust-tyty.h (class DynamicObjectType): moved up

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: we can only return unit-type when the ABI is non C
Philip Herron [Mon, 8 May 2023 13:52:05 +0000 (14:52 +0100)]
gccrs: we can only return unit-type when the ABI is non C

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): add filter

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Redo how we handle unit types for the final time
Philip Herron [Fri, 5 May 2023 18:06:37 +0000 (19:06 +0100)]
gccrs: Redo how we handle unit types for the final time

We had a very inconsistant way for dealing with unit-types in gccrs we
tried to optimize the case for a function returning unit type to be clever
and not emit any return value for unit types. Then for other cases we would
use an empty constructor for an empty tuple and in others use a zero
percsion integer. This was all just confusing and made the IR less
conformant to Rust. In this patch I change all of this to use an empty
tuple type for all cases so we pass around {} which maps over to Rust and
gets optimized away in the middle end anyway.

In the patch we also remove old gccgo code which optimizes away zero
size types to void_type_node which is why my original attempt at doing this
two years ago failed.

Fixes #2188

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::compile_function_body): use unit_expression
(HIRCompileBase::unit_expression): new helper
* backend/rust-compile-base.h: update prototype
* backend/rust-compile-block.cc (CompileBlock::visit): use unit_expression
* backend/rust-compile-expr.cc (CompileExpr::visit): likewise
(CompileExpr::generate_closure_function): likewise
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): cleanup
* backend/rust-compile-item.cc (CompileItem::visit): likewise
* backend/rust-compile-pattern.cc (CompilePatternLet::visit): likewise
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::get_unit_type): new helper
(TyTyResolveCompile::visit): use new unit_type helper
* backend/rust-compile-type.h: likewise
* rust-backend.h: simplify the return_expression
* rust-gcc.cc (Gcc_backend::function_type): likewise
(Gcc_backend::return_statement): likewise
* backend/rust-constexpr.cc (eval_constant_expression): remove bad assertion

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Fix ICE in check for unused global variables
Philip Herron [Fri, 5 May 2023 16:16:08 +0000 (17:16 +0100)]
gccrs: Fix ICE in check for unused global variables

Calling get variable expression will return an expression but we are
checking for unused decls so lets actually pass the decl.

Addresses #2188

gcc/rust/ChangeLog:

* checks/lints/rust-lint-unused-var.cc (UnusedVariables::Lint): use the decl not the expr

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: Fix "default unsafe fn ..." parsing
Owen Avery [Mon, 8 May 2023 00:29:15 +0000 (20:29 -0400)]
gccrs: Fix "default unsafe fn ..." parsing

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_trait_impl_function_or_method):
Parse function/method qualifiers after "default".

gcc/testsuite/ChangeLog:

* rust/compile/parse_specialization.rs:
Add "default unsafe" coverage.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Add missing compile locals for constants and statics
Philip Herron [Fri, 5 May 2023 15:54:28 +0000 (16:54 +0100)]
gccrs: Add missing compile locals for constants and statics

When we have a block expression for cosntants or statics we need to ensure
we compile the locals for the implicit function we generate in GIMPLE
before feeding it directly into the constant folder to evaluate the data.

Fixes #2178

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: add missing compile_locals call

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 months agogccrs: ast: Format AST code properly.
Arthur Cohen [Fri, 5 May 2023 10:59:16 +0000 (12:59 +0200)]
gccrs: ast: Format AST code properly.

gcc/rust/ChangeLog:

* ast/rust-ast.h (class AttrInputMetaItemContainer): Run clang-format.
(class DelimTokenTree): Likewise.

6 months agogccrs: enr: Accumulate nested escaped macros properly.
Arthur Cohen [Tue, 18 Apr 2023 14:22:22 +0000 (16:22 +0200)]
gccrs: enr: Accumulate nested escaped macros properly.

gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver.cc (is_macro_use_module): New function.
(EarlyNameResolver::accumulate_escaped_macros): New function.
(EarlyNameResolver::go): Use `accumulate_escaped_macros`.
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h: Declare `accumulate_escaped_macros`.

gcc/testsuite/ChangeLog:
* rust/compile/macro_use1.rs: New test.
* rust/execute/torture/macro_use1.rs: New test.
* rust/compile/nested_macro_use1.rs: New test.
* rust/compile/nested_macro_use2.rs: New test.

6 months agogccrs: ast: Add take_items() and set_items() methods for Item containers
Arthur Cohen [Tue, 18 Apr 2023 12:38:22 +0000 (14:38 +0200)]
gccrs: ast: Add take_items() and set_items() methods for Item containers

Both the AST::Crate and AST::Module class are std::unique_ptr<AST::Item>
containers, and may require spurious insertions in these containers,
for example when expanding a procedural macro, or in our case, escaping
macros through the #[macro_use] attribute. These functions allow you
to replace *all* of the items contained in such a container.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add take_items() and set_items() method to Crate.
* ast/rust-item.h: Add take_items() and set_items() method to Module.

6 months agogccrs: ast: Add Kind::MODULE
Arthur Cohen [Wed, 29 Mar 2023 14:56:12 +0000 (16:56 +0200)]
gccrs: ast: Add Kind::MODULE

gcc/rust/ChangeLog:

* ast/rust-ast.h (enum Kind): Add MODULE variant.
* ast/rust-item.h: Return Kind::MODULE in AST::Module::get_kind().

6 months agogccrs: builtin: Cleanup handling of builtin macros
Arthur Cohen [Wed, 3 May 2023 09:19:30 +0000 (11:19 +0200)]
gccrs: builtin: Cleanup handling of builtin macros

This commit regroups information related to builtin macros in one place instead
of spreading it over multiple files. It also adds a simple bi-directional
hashmap in order to perform lookups from a key as well as a value.

gcc/rust/ChangeLog:

* ast/rust-macro.cc (builtin_macro_from_string): Move function.
* ast/rust-macro.h (enum class): Move enum.
(builtin_macro_from_string): Move function.
* expand/rust-macro-builtins.cc (builtin_macro_from_string): New function.
(make_macro_path_str): Use new bi-map.
(parse_single_string_literal): Use new `BuiltinMacro` enum.
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::compile_error_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
(MacroBuiltin::sorry): New function.
* expand/rust-macro-builtins.h (enum class): Move enum here.
(builtin_macro_from_string): New function declaration.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Use
new function.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Remove old
builtin macro map.

6 months agogccrs: utils: Add bidirectional hashmap class
Arthur Cohen [Wed, 3 May 2023 09:17:01 +0000 (11:17 +0200)]
gccrs: utils: Add bidirectional hashmap class

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc: Include bidirectional map.
* util/bi-map.h: New file.

6 months agogccrs: libproc_macro: Add helpers to construct Procmacro
Pierre-Emmanuel Patry [Mon, 24 Apr 2023 15:14:35 +0000 (17:14 +0200)]
gccrs: libproc_macro: Add helpers to construct Procmacro

Add some helper functions to create Procmacro tagged unions.

libgrust/ChangeLog:

* libproc_macro/proc_macro.cc (Procmacro::make_derive):
Add custom derive macro constructor.
(Procmacro::make_attribute): Add attribute macro constructor.
(Procmacro::make_bang): Add bang macro constructor.
* libproc_macro/proc_macro.h (struct Procmacro):
Add helper function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: libproc_macro: Add proc_macro interface structures
Pierre-Emmanuel Patry [Mon, 24 Apr 2023 14:46:23 +0000 (16:46 +0200)]
gccrs: libproc_macro: Add proc_macro interface structures

Add the structures that should be used by a compiler opening a
procedural macro to either identify or execute it.

libgrust/ChangeLog:

* libproc_macro/proc_macro.h (struct CustomDerivePayload):
Add C compatible payload structure.
(struct AttrPayload): Likewise.
(struct BangPayload): Likewise.
(enum ProcmacroTag): Add tag for tagged union.
(union ProcmacroPayload): Proc macro payload union.
(struct Procmacro): Tagged union.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 months agogccrs: Add test from issue 1446
Owen Avery [Wed, 3 May 2023 00:21:42 +0000 (20:21 -0400)]
gccrs: Add test from issue 1446

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Handle replacing stripped tail expressions
Owen Avery [Wed, 26 Apr 2023 13:29:04 +0000 (09:29 -0400)]
gccrs: Handle replacing stripped tail expressions

gcc/rust/ChangeLog:

* ast/rust-ast.cc
(BlockExpr::strip_tail_expr):
Try to take new tail expression from statements list.
* ast/rust-expr.h
(BlockExpr::strip_tail_expr):
Replace definition with only declaration.

gcc/testsuite/ChangeLog:

* rust/execute/torture/cfg-tail.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 months agogccrs: Add is_expr method to AST::Stmt
Owen Avery [Wed, 26 Apr 2023 13:25:35 +0000 (09:25 -0400)]
gccrs: Add is_expr method to AST::Stmt

gcc/rust/ChangeLog:

* ast/rust-ast.h
(Stmt::is_expr): New.
* ast/rust-stmt.h
(ExprStmt::is_expr): New.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
This page took 0.111793 seconds and 5 git commands to generate.