aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-ast.cc
AgeCommit message (Collapse)AuthorFilesLines
2025-03-17gccrs: Add RAW_STRING_LITERALansh1-0/+5
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Handle case for RAW_STRING_LITERAL. * ast/rust-ast.cc (AttributeParser::parse_meta_item_inner): Likewise. (AttributeParser::parse_literal): Likewise. * ast/rust-ast.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_literal): Likewise. * lex/rust-lex.cc (Lexer::parse_raw_string): Likewise. * lex/rust-token.cc (Token::as_string): Likewise. * lex/rust-token.h (enum PrimitiveCoreType): Likewise. * parse/rust-parse-impl.h (Parser::parse_attr_input): Likewise. (Parser::parse_literal_expr): Likewise. (Parser::parse_pattern_no_alt): Likewise. Signed-off-by: ansh <anshmalik2002@gmail.com>
2025-03-17gccrs: expand: Keep track of semicoloned builtin macrosArthur Cohen1-1/+0
This is quite a rough fix (like a lot of the macro expansion code...) but it allows built-in macros to be treated as statements. I *think* asm!() might be the only one where it really matters, but also doing something like { line!(); } will now work, whereas before the macro invocation would not get expanded properly and would be ignored. gcc/rust/ChangeLog: * ast/rust-ast-fragment.h: Pass `is_semicolon` information to builtin macro transcribers. * ast/rust-macro.h: Pass semicolon information to transcriber.. * expand/rust-macro-builtins-asm.cc (MacroBuiltin::asm_handler): Likewise. (parse_asm): Likewise. * expand/rust-macro-builtins-asm.h (parse_asm): Likewise. * expand/rust-macro-builtins-format-args.cc (MacroBuiltin::format_args_handler): Likewise. * expand/rust-macro-builtins-include.cc (MacroBuiltin::include_bytes_handler): Likewise. (MacroBuiltin::include_str_handler): Likewise. (MacroBuiltin::include_handler): Likewise. * expand/rust-macro-builtins-location.cc (MacroBuiltin::file_handler): Likewise. (MacroBuiltin::column_handler): Likewise. (MacroBuiltin::line_handler): Likewise. * expand/rust-macro-builtins-log-debug.cc (MacroBuiltin::assert_handler): Likewise. * expand/rust-macro-builtins-utility.cc (MacroBuiltin::compile_error_handler): Likewise. (MacroBuiltin::concat_handler): Likewise. (MacroBuiltin::env_handler): Likewise. (MacroBuiltin::cfg_handler): Likewise. (MacroBuiltin::stringify_handler): Likewise. * expand/rust-macro-builtins.cc (format_args_maker): Likewise. (inline_asm_maker): Likewise. (MacroBuiltin::sorry): Likewise. (MacroBuiltin::proc_macro_builtin): Likewise. * expand/rust-macro-builtins.h: Likewise. * expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Likewise. (MacroExpander::expand_invoc): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove rust_unreachable. * ast/rust-ast.cc (InlineAsm::accept_vis): Likewise. * hir/tree/rust-hir.cc (InlineAsm::accept_vis): Likewise.
2025-03-17gccrs: Scaffolding HIRFullVisitor for inline asmjjasmine1-0/+1
gcc/rust/ChangeLog: * ast/rust-ast-visitor.h: Scaffolding HIRFullVisitor for inline asm * ast/rust-ast.cc (InlineAsm::accept_vis): Likewise. * hir/tree/rust-hir-visitor.h (RUST_HIR_VISITOR_H): Likewise. * hir/tree/rust-hir.cc (InlineAsm::accept_vis): Likewise.
2025-03-17gccrs: Scaffolding ast visitor for InlineAsmjjasmine1-0/+7
gcc/rust/ChangeLog: * ast/rust-ast-visitor.h: Scaffolding ast visitor for InlineAsm * ast/rust-ast.cc (InlineAsm::accept_vis): Likewise. * ast/rust-expr.h: Likewise.
2025-03-17gccrs: Parse raw ref operatorPierre-Emmanuel Patry1-5/+13
The raw ref operator is an unstable feature required to obtain a pointer to unaligned adresses (mainly unaligned struct fields) without UB. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::ref): Adapt constructor to the new API. * ast/rust-ast-collector.cc (TokenCollector::visit): Emit a raw weak keyword when required. * ast/rust-ast.cc (BorrowExpr::as_string): Change as_string representation to handle raw ref operator. * ast/rust-expr.h (class BorrowExpr): Add raw discriminant. * expand/rust-macro-builtins-include.cc: Adapt constructor to the new API. * parse/rust-parse-impl.h: Handle the raw weak keyword. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17gccrs: Allow multiple outer attributes on generic paramsPierre-Emmanuel Patry1-6/+6
Previously generic params only allowed one outer attribute in front of them. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Visit outer attributes. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change outer attribute visit, we need to visit all of them. * ast/rust-ast.cc (LifetimeParam::as_string): Change as_string implementation to allow multiple outer attributes. (TypeParam::as_string): Likewise. * ast/rust-ast.h (class LifetimeParam): Allow multiple outer attributes. * ast/rust-item.h (class TypeParam): Likewise. * ast/rust-path.h: Likewise. * parse/rust-parse-impl.h (Parser::parse_generic_param): Change call to outer attribute parsing to collect several attributes. (Parser::parse_lifetime_param): Likewise. (Parser::parse_type_param): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17gccrs: Parse box expressionsPierre-Emmanuel Patry1-0/+12
Add support for old box expression syntax. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add visit member function for BoxExpr nodes. * ast/rust-ast-collector.h: Add visit function prototype. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add visit member function to default ast visitor. * ast/rust-ast-visitor.h: Add visit function's prototype. * ast/rust-ast.cc (BoxExpr::as_string): Add as_string function implementation for BoxExpr. (BoxExpr::accept_vis): Add accept_vis implementation to BoxExpr. * ast/rust-expr.h (class BoxExpr): Add BoxExpr class to represent boxed expressions. * expand/rust-derive.h: Add BoxExpr visit function prototype. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add BoxExpr visitor implementation. * hir/rust-ast-lower-base.h: Add visit function's prototype. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add BoxExpr visitor implementation. * hir/rust-ast-lower-expr.h: Add visit function's prototype. * parse/rust-parse-impl.h (Parser::parse_box_expr): Add parse_box_expr function's implementation. * parse/rust-parse.h: Add parse_box_expr function's prototype. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add resolver visit implementation. * resolve/rust-ast-resolve-base.h: Add resolver's visit function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-01-02Update copyright years.Jakub Jelinek1-1/+1
2024-08-01gccrs: Replace unique_ptr references with referencesPierre-Emmanuel Patry1-2/+2
This kind of double indirection is pointless and prone to error. This commit change the api of all getters from the AST to use references directly instead of references to unique pointers. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove reference to unique pointer and replace it with a direct reference to the wrapped data. * ast/rust-ast.cc (VariadicParam::as_string): Likewise. (BlockExpr::normalize_tail_expr): Likewise. * ast/rust-expr.h: Likewise and add pointer getter in order to allow pointer reseat. * ast/rust-item.h: Likewise and add pointer getter for reseat. * ast/rust-path.h: Likewise. * ast/rust-pattern.h: Likewise. * ast/rust-stmt.h: Likewise. * ast/rust-type.h: Likewise. * expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_struct_fields): Remove references to unique pointers and replace it with direct references to the wrapped object. (CfgStrip::maybe_strip_tuple_fields): Likewise. (CfgStrip::maybe_strip_generic_args): Likewise. (CfgStrip::maybe_strip_qualified_path_type): Likewise. (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::maybe_expand_expr): Likewise. (ExpandVisitor::maybe_expand_type): Likewise. (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_binding): Likewise. (ASTLoweringBase::lower_generic_args): Likewise. (ASTLoweringBase::lower_self): Likewise. (ASTLoweringBase::lower_type_no_bounds): Likewise. (ASTLoweringBase::lower_bound): Likewise. (ASTLoweringBase::lower_range_pattern_bound): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-block.h: Likewise. * hir/rust-ast-lower-enumitem.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::translate): Likewise. (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-expr.h: Likewise. * hir/rust-ast-lower-extern.h: Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::translate): Likewise. (ASTLowerImplItem::visit): Likewise. (ASTLowerTraitItem::translate): Likewise. (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-implitem.h: Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::translate): Likewise. (ASTLoweringItem::visit): Likewise. * hir/rust-ast-lower-item.h: Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::translate): Likewise. (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower-pattern.h: Likewise. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise. * hir/rust-ast-lower-struct-field-expr.h: Likewise. * hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Likewise. (ASTLowerQualifiedPathInType::visit): Likewise. (ASTLoweringType::translate): Likewise. (ASTLoweringType::visit): Likewise. (ASTLowerGenericParam::translate): Likewise. (ASTLowerGenericParam::visit): Likewise. (ASTLoweringTypeBounds::translate): Likewise. (ASTLoweringTypeBounds::visit): Likewise. (ASTLowerWhereClauseItem::visit): Likewise. * hir/rust-ast-lower-type.h: Likewise. * hir/rust-ast-lower.cc (ASTLowering::go): Likewise. (ASTLoweringBlock::visit): Likewise. (ASTLoweringIfBlock::visit): Likewise. (ASTLoweringIfLetBlock::visit): Likewise. (ASTLowerStructExprField::visit): Likewise. (ASTLoweringExprWithBlock::visit): Likewise. (ASTLoweringBase::lower_qual_path_type): Likewise. (ASTLoweringBase::lower_closure_param): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::resolve_visibility): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::go): Likewise. (ResolveExpr::visit): Likewise. (ResolveExpr::resolve_closure_param): Likewise. * resolve/rust-ast-resolve-expr.h: Likewise. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. (ResolveItem::go): Likewise. (ResolveItem::visit): Likewise. (ResolveItem::resolve_impl_item): Likewise. (ResolveItem::resolve_extern_item): Likewise. (ResolveImplItems::go): Likewise. (ResolveExternItem::go): Likewise. (ResolveExternItem::visit): Likewise. * resolve/rust-ast-resolve-item.h: Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::go): Likewise. (ResolvePath::resolve_path): Likewise. * resolve/rust-ast-resolve-path.h: Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go): Likewise. (PatternDeclaration::visit): Likewise. (resolve_range_pattern_bound): Likewise. * resolve/rust-ast-resolve-pattern.h: Likewise. * resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-ast-resolve-struct-expr-field.cc (ResolveStructExprField::go): Likewise. (ResolveStructExprField::visit): Likewise. * resolve/rust-ast-resolve-struct-expr-field.h: Likewise. * resolve/rust-ast-resolve-toplevel.h: Likewise. * resolve/rust-ast-resolve-type.cc (ResolveType::visit): Likewise. (ResolveRelativeTypePath::go): Likewise. (ResolveRelativeQualTypePath::resolve_qual_seg): Likewise. (ResolveTypeToCanonicalPath::go): Likewise. (ResolveTypeToCanonicalPath::visit): Likewise. (ResolveGenericArgs::resolve_disambiguated_generic): Likewise. (ResolveGenericArgs::go): Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-ast-resolve.cc (NameResolution::go): Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::resolve_qualified_path_type): Likewise. (EarlyNameResolver::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. * checks/errors/rust-ast-validation.cc: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-08-01gccrs: Remove dead code associated with `AST::ExternalFunctionItem`0xn4utilus1-69/+0
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove dead code. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-full-decls.h (class ExternalFunctionItem): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h: Likewise. * ast/rust-ast.cc (ExternalFunctionItem::as_string): Likewise. (ExternalFunctionItem::accept_vis): Likewise. * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Likewise. * checks/errors/rust-ast-validation.h: Likewise. * checks/errors/rust-feature-gate.h: Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-cfg-strip.h: Likewise. * expand/rust-derive.h: Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * metadata/rust-export-metadata.cc (ExportContext::emit_function): Likewise. * parse/rust-parse-impl.h: Likewise. * parse/rust-parse.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-default-resolver.h: Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h: Likewise. gcc/testsuite/ChangeLog: * rust/compile/extern_func_with_body.rs: New test. Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
2024-08-01gccrs: Add support for external functions0xn4utilus1-3/+6
gcc/rust/ChangeLog: * ast/rust-ast.cc (Function::Function): Add `is_external_function` field. (Function::operator=): Likewise. * ast/rust-ast.h: New constructor for ExternalItem. * ast/rust-item.h (class Function): Add `is_external_function` field. Update `get_node_id`. * ast/rust-macro.h: Update copy constructor. Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
2024-08-01gccrs: lower: Add base for lowering FormatArgs nodesArthur Cohen1-1/+1
gcc/rust/ChangeLog: * Make-lang.in: Compile the new source file. * ast/rust-ast-collector.cc (TokenCollector::visit): Error out when visiting FormatArgs nodes. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * ast/rust-ast.cc (FormatArgs::get_locus): New. * ast/rust-builtin-ast-nodes.h: Improve FormatArgs API. * ast/rust-fmt.cc (Pieces::~Pieces): Cleanup. (Pieces::Pieces): Likewise. * ast/rust-fmt.h (struct Pieces): Add pieces_vector member. * hir/rust-ast-lower-format-args.cc: New file. * hir/rust-ast-lower-format-args.h: New file.
2024-08-01gccrs: format-args: Fix Rust interface and add input parsing.Arthur Cohen1-0/+51
gcc/rust/ChangeLog: * ast/rust-ast.cc: Make FormatArgs inherit from AST::Expr * ast/rust-builtin-ast-nodes.h: Improve FormatArg* nodes and helpers. * ast/rust-fmt.cc (Pieces::collect): Fix interface to match FFI function. * ast/rust-fmt.h (collect_pieces): Likewise. (struct Pieces): Add append_newline parameter. * expand/rust-macro-builtins.cc: Add proper parsing of format_args input. * hir/rust-ast-lower-base.cc: Include diagnostics header. libgrust/ChangeLog: * libformat_parser/src/lib.rs: Switch interface to use more parser parameters. * libformat_parser/src/bin.rs: Use new interface.
2024-08-01gccrs: ast: Add base nodes for FormatArgsArthur Cohen1-0/+6
This commit adds a base for creating AST FormatArgs nodes after expanding invocations of `format_args!()`. These nodes will then be expanded to the proper runtime function calls (to core::fmt::rt) during the AST lowering. gcc/rust/ChangeLog: * ast/rust-builtin-ast-nodes.h: New file. * ast/rust-ast-full-decls.h (class FormatArgs): Declare new class. * ast/rust-ast-collector.cc: Handle FormatArgs nodes properly. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-full.h: Likewise. * ast/rust-ast-visitor.cc: Likewise. * ast/rust-ast-visitor.h: Likewise. * ast/rust-ast.cc: Likewise. * ast/rust-ast.h: Likewise. * expand/rust-derive.h: Likewise. * hir/rust-ast-lower-base.cc: Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-expr.cc: Likewise. * hir/rust-ast-lower-expr.h: Likewise. * resolve/rust-ast-resolve-base.cc: Likewise. * resolve/rust-ast-resolve-base.h: Likewise.
2024-02-07gccrs: Remove obsolete classes and functions.Kushal Pal1-209/+0
Trait functions now use AST::Function class, so classes AST::TraitItemFunc, AST::TraitItemMethod, AST::TraitFunctionDecl, AST::TraitMethodDecl and their related functions can be removed. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove obsolete classes and functions. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-full-decls.h (class TraitFunctionDecl): Likewise. (class TraitItemFunc): Likewise. (class TraitMethodDecl): Likewise. (class TraitItemMethod): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h: Likewise. * ast/rust-ast.cc (TraitItemFunc::TraitItemFunc): Likewise. (TraitItemFunc::operator=): Likewise. (TraitItemFunc::as_string): Likewise. (TraitFunctionDecl::as_string): Likewise. (TraitItemMethod::TraitItemMethod): Likewise. (TraitItemMethod::operator=): Likewise. (TraitItemMethod::as_string): Likewise. (TraitMethodDecl::as_string): Likewise. (TraitItemFunc::accept_vis): Likewise. (TraitItemMethod::accept_vis): Likewise. * ast/rust-item.h (class TraitFunctionDecl): Likewise. (class TraitItemFunc): Likewise. (class TraitMethodDecl): Likewise. (class TraitItemMethod): Likewise. * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Likewise. * checks/errors/rust-ast-validation.h: Likewise. * checks/errors/rust-feature-gate.h: Likewise. * expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_trait_function_decl): Likewise. (CfgStrip::maybe_strip_trait_method_decl): Likewise. (CfgStrip::visit): Likewise. * expand/rust-cfg-strip.h: Likewise. * expand/rust-derive.h: Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::expand_trait_function_decl): Likewise. (ExpandVisitor::expand_trait_method_decl): Likewise. (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-implitem.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-ast-resolve-implitem.h (visit): Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. * resolve/rust-ast-resolve-item.h: Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-default-resolver.h: Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.h: Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h: Likewise. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30gccrs: Unify storage of associated items in SingleASTNodeOwen Avery1-42/+10
gcc/rust/ChangeLog: * ast/rust-ast-fragment.cc (Fragment::assert_single_fragment): Update. * ast/rust-ast.h (class TraitImplItem): Move definition before that of TraitItem. (class TraitItem): Inherit from TraitImplItem instead of AssociatedItem. (class SingleASTNode): Unify handling of associated items. (SingleASTNode::take_assoc_item): Move from... (SingleASTNode::take_impl_item): ...here, but leave stub calling take_assoc_item behind. (SingleASTNode::take_trait_item): Cast associated item to TraitItem. (SingleASTNode::take_trait_impl_item): Cast associated item to TraitImplItem. * ast/rust-ast.cc (SingleASTNode::SingleASTNode): Unify handling of associated items. (SingleASTNode::operator=): Likewise. (SingleASTNode::accept_vis): Likewise. (SingleASTNode::is_error): Likewise. (SingleASTNode::as_string): Likewise. * ast/rust-item.h (class Function): Remove direct inheritence from AssociatedItem. (class ConstantItem): Likewise. * ast/rust-macro.h (class MacroInvocation): Remove direct inheritence from AssociatedItem and TraitImplItem.
2024-01-30gccrs: Make function bodies truly optionalPierre-Emmanuel Patry1-14/+10
Missing body on a function should be rejected at a later stage in the compiler, not during parsing. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Adapt defintion getter. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower-implitem.h: Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * parse/rust-parse-impl.h: Allow empty function body during parsing. * ast/rust-ast.cc (Function::Function): Constructor now take an optional for the body. (Function::operator=): Adapt to new optional member. (Function::as_string): Likewise. * ast/rust-item.h (class Function): Make body optional and do not rely on nullptr anymore. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-30gccrs: Split async and const function qualifiersPierre-Emmanuel Patry1-16/+5
A function cannot be both async and const, however this should not be handled in the parser but rather at a later stage in the compiler. This commit change the AsyncConstStatus in the AST and the HIR to allows a function to be both async and const. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (AstBuilder::fn_qualifiers): Change constructor to match the new arguments. * ast/rust-ast-collector.cc (TokenCollector::visit): Change behavior to handle both const and async specifiers at the same time. * ast/rust-ast.cc (FunctionQualifiers::as_string): Likewise. * ast/rust-item.h (class FunctionQualifiers): Remove AsyncConstStatus and replace it with both Async and Const status. Also change the safety arguments to use an enum instead of a boolean. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers): Update constructor call. * hir/tree/rust-hir-item.h: Add Const and Async status, remove AsyncConstStatus, update the constructor. * hir/tree/rust-hir.cc (FunctionQualifiers::as_string): Update with the new status. * parse/rust-parse-impl.h (Parser::parse_function_qualifiers): Update constructor call. * util/rust-common.h (enum Mutability): Make an enum class. (enum class): Add Async and Const enum class to avoid booleans. (enum Unsafety): Change to an enum class. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-30gccrs: Remove class AST::InherentImplItemOwen Avery1-2/+2
gcc/rust/ChangeLog: * ast/rust-ast-full-decls.h (class InherentImplItem): Remove. * ast/rust-ast.h (class InherentImplItem): Remove. (class SingleASTNode): Store pointer to AssociatedItem instead of InherentImplItem. * ast/rust-ast.cc (SingleASTNode::SingleASTNode): Use clone_associated_item instead of clone_inherent_impl_item. (SingleASTNode::operator=): Likewise. * ast/rust-item.h (class InherentImpl): Use AssociatedItem rather than InherentImplItem. (class Function): Likewise. (class ConstantItem): Likewise. * ast/rust-macro.h (class MacroInvocation): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_impl): Likewise. (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_inherent_impl_function_or_method): Likewise. * parse/rust-parse.h (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_inherent_impl_function_or_method): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Rework function special parametersPierre-Emmanuel Patry1-5/+141
Make self param and variadic param Param, introduce Param class and make function parameters param too. Self can now be represented as a standard parameter and is thus no longer required as a separate function attribute. Prevent self pointers and allow self in standard functions during parsing so they could be rejected at a later stage. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor for VariadicParam and remove Self parameter visitor from Function visit. * expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_self_param): Remove function. (CfgStrip::maybe_strip_trait_method_decl): Remove self parameter visit. (CfgStrip::maybe_strip_function_params): Handle new function parameters. (CfgStrip::visit): Handle VariadicParam, SelfParam and FunctionParam. * expand/rust-expand-visitor.cc (ExpandVisitor::expand_self_param): Remove function. (ExpandVisitor::expand_trait_method_decl): Do not visit self parameter. (ExpandVisitor::visit): Add visit for VariadicParam, FunctionParam and SelfParam. (ExpandVisitor::expand_function_params): Visit parameters instead. * expand/rust-expand-visitor.h: Update function prototypes. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Update visit with new parameters. (ResolveTraitItems::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Update visit functions with the new visitor functions for VariadicParam SelfParam and FunctionParam. * resolve/rust-early-name-resolver.h: Update function prototypes. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Update visitor according to the new function parameter structures. * ast/rust-ast-visitor.h: Update prototypes and add visitor virtual functions for SelfParam, FunctionParam and VariadicParam. * ast/rust-ast.cc (Function::Function): Move constructor in implementation instead of header. (Function::operator=): Likewise. (Function::as_string): Update function with pointer dereference. (VariadicParam::as_string): Likewise. (TraitFunctionDecl::as_string): Likewise. (TraitMethodDecl::as_string): Likewise. (FunctionParam::accept_vis): Add function for visitor. (SelfParam::accept_vis): Likewise. (VariadicParam::accept_vis): Likewise. (TraitItemFunc::TraitItemFunc): Move constructor to implementation file. (TraitItemFunc::operator=): Likewise. (TraitItemMethod::TraitItemMethod): Likewise. (TraitItemMethod::operator=): Likewise. * ast/rust-item.h (class Function): Remove self optional member. (class TraitMethodDecl): Likewise. (class TraitFunctionDecl): Likewise. (class Param): Add abstract parameter class. (class SelfParam): Inherit from Param and remove parameter common members. (class FunctionParam): Likewise. (class VariadicParam): Likewise. (struct Visibility): Move structure declaration. (class VisItem): Likewise. * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add a self parameter check during AST validation. * checks/errors/rust-ast-validation.h: Add function prototype. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Update function constructor. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Rework function for the new parameters. (ASTLoweringBase::visit): Add visit functions for VariadicParam, FunctionParam and SelfParam. * hir/rust-ast-lower-base.h: Update function prototypes. * parse/rust-parse-impl.h (Parser::parse_function): Update function according to new function representation. (Parser::parse_function_param): Return vector of abstract param instead of FunctionParam. (Parser::parse_method): Update according to new representation. (Parser::parse_trait_item): Likewise. (Parser::parse_self_param): Error out with self pointers and prevent the lexer from eating regular function parameters. Update return type. * parse/rust-parse.h: Update function return types. * ast/rust-ast-collector.h: Add VariadicParam visit prototype. * ast/rust-ast.h (struct Visibility): Move struct declaration. (class VisItem): Likewise. * ast/rust-expr.h: Update included files. * checks/errors/rust-feature-gate.h: Add visitor functions for SelfParam, FunctionParam and VariadicParam. * expand/rust-cfg-strip.h: Update function prototypes. * expand/rust-derive.h: Likewise. * hir/rust-ast-lower-implitem.h: Handle special arguments. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * metadata/rust-export-metadata.cc (ExportContext::emit_function): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visitor functions. * resolve/rust-ast-resolve-base.h: Update prototypes. * resolve/rust-ast-resolve-stmt.h: Handle new parameter kind. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-default-resolver.h: Update prototype. * util/rust-attributes.cc (AttributeChecker::visit): Add visitor functions for SelfParam and VariadicParam. * util/rust-attributes.h: Add visit prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Replace AST::Method with existing AST::FunctionOwen Avery1-69/+0
gcc/rust/ChangeLog: * ast/rust-item.h (class Method): Remove. (Function::self_param): New. (Function::has_self_param): New. (Function::Function): Initialize self_param. (Function::operator=): Likewise. (Function::get_self_param): New. * ast/rust-ast.cc (Method::as_string): Remove. (Method::accept_vis): Remove. * ast/rust-ast-collector.cc (TokenCollector::visit): Remove AST::Method visitor, handle self_param in AST::Function visitor. * ast/rust-ast-collector.h (TokenCollector::visit): Remove AST::Method visitor. * ast/rust-ast-full-decls.h (class Method): Remove. * ast/rust-ast-visitor.h (ASTVisitor::visit): Remove AST::Method visitor. (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove AST::Method visitor, handle self_param in AST::Function visitor. * checks/errors/rust-feature-gate.cc (FeatureGate::visit): Remove AST::Method visitor. * checks/errors/rust-feature-gate.h (FeatureGate::visit): Likewise.. * expand/rust-cfg-strip.cc (CfgStrip::visit): Remove AST::Method visitor, handle self_param in AST::Function visitor. * expand/rust-cfg-strip.h (CfgStrip::visit): Remove AST::Method visitor. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Return AST::Function instead of AST::Method. * expand/rust-derive.h (DeriveVisitor::visit): Remove AST::Method visitor. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Remove AST::Method visitor, handle self_param in AST::Function visitor. * expand/rust-expand-visitor.h: (ExpandVisitor::visit): Remove AST::Method visitor. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-implitem.h (ASTLowerImplItem::visit): Remove AST::Method visitor, handle self_param in AST::Function visitor. * parse/rust-parse-impl.h: Include optional.h. (Parser::parse_function): Adjust AST::Function construction. (Parser::parse_inherent_impl_function_or_method): Construct AST::Function instead of AST::Method, adjust AST::Function construction. (Parser::parse_trait_impl_function_or_method): Likewise. (Parser::parse_method): Return std::unique_ptr<AST::Function> instead of AST::Method. * parse/rust-parse.h (Parser::parse_method): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Remove AST::Method visitor. * resolve/rust-ast-resolve-base.h (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-implitem.h (ResolveToplevelImplItem::visit): Likewise. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Remove AST::Method visitor, handle self_param in AST::Function visitor. * resolve/rust-ast-resolve-item.h (ResolveItem::visit): Remove AST::Method visitor. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove AST::Method visitor. * resolve/rust-default-resolver.h (DefaultResolver::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Remove AST::Method visitor, handle self_param in AST::Function visitor. * resolve/rust-early-name-resolver.h (EarlyNameResolver::visit): Remove AST::Method visitor. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.h (TopLevel::visit): Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h (AttributeChecker::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Fix multiple issues with variadic representationPierre-Emmanuel Patry1-18/+7
The new variadic representation has introduced multiple issues and ICE into the codebase. Some early passes in the compiler depend on the parameters all having a type and being an actual parameter. gcc/rust/ChangeLog: * ast/rust-ast.cc (ExternalFunctionItem::as_string): Adapt as_string function to the new ast representation. (NamedFunctionParam::as_string): Likewise. * ast/rust-item.h: Add a function to test whether a FunctionParam has a name pattern. * expand/rust-cfg-strip.cc (CfgStrip::visit): Adapt cfg strip visitor for the new variadic arguments. * hir/rust-ast-lower-extern.h: Adapt lowering to the new variadic function representation. * metadata/rust-export-metadata.cc (ExportContext::emit_function): Change call to constructor. * parse/rust-parse-impl.h (Parser::parse_named_function_param): Change NamedFunctionParam parsing to accomodate new variadic representation. (Parser::parse_external_item): Change external item parsing to use the new NamedFunctionParam variadics. * parse/rust-parse.h: Add new parsing function prototypes. * ast/rust-ast-collector.cc (TokenCollector::visit): Rework token collection to take into account variadic parameters. * ast/rust-ast-visitor.cc: Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Change function bound to avoid getting the type of a variadic parameter. * resolve/rust-ast-resolve-item.cc (ResolveExternItem::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Move SingleASTNode implementation out of headerPierre-Emmanuel Patry1-0/+174
Those functions implementation put additional constraints on the headers which makes the codebase harder to work with. gcc/rust/ChangeLog: * ast/rust-ast.h: Move implementation from here... * ast/rust-ast.cc (SingleASTNode::SingleASTNode): ...to here. (SingleASTNode::operator=): ...and here... (SingleASTNode::accept_vis): ...and here... (SingleASTNode::is_error): ...and here... (SingleASTNode::as_string): ...also here. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Unify raw attribute valuesPierre-Emmanuel Patry1-2/+4
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>
2024-01-16gccrs: Parse unparsed derive tokenstreamsPierre-Emmanuel Patry1-0/+3
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>
2024-01-16gccrs: Ease some constraints on derive definitionPierre-Emmanuel Patry1-4/+1
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>
2024-01-16gccrs: Change trait getter to return referencesPierre-Emmanuel Patry1-3/+3
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>
2024-01-16gccrs: Set traits getter as member functionPierre-Emmanuel Patry1-0/+72
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>
2024-01-16gccrs: Make is_builtin a member functionPierre-Emmanuel Patry1-0/+9
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>
2024-01-16gccrs: resolve: Add mappings for proc macros and resolvingPierre-Emmanuel Patry1-1/+1
Add multiple mappings for procedural macro name resolution. Procedural macros were not resolved using name resolution and mapping but rather with some hacky path comparison. gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (MacroExpander::import_proc_macros): Remove function. * expand/rust-macro-expand.h (struct MacroExpander): Remove import_proc_macro function. * util/rust-hir-map.cc (Mappings::insert_derive_proc_macro_def): Add a function to insert a derive proc macro definition. (Mappings::insert_bang_proc_macro): Remove function. (Mappings::insert_bang_proc_macro_def): Add function to insert a bang proc macro definition. (Mappings::insert_attribute_proc_macro_def): Likewise with attribute proc macros. (Mappings::lookup_derive_proc_macro_def): Add a function to lookup a defined derive proc macro definition. (Mappings::lookup_bang_proc_macro): Remove function. (Mappings::lookup_bang_proc_macro_def): Add a function to lookup a bang proc macro definition. (Mappings::lookup_attribute_proc_macro_def): Add a function to lookup an attribute prod macro definition. (Mappings::insert_derive_proc_macro_invocation): Add a function to insert a derive proc macro invocation. (Mappings::lookup_derive_proc_macro_invocation): Add a function to lookup a derive proc macro invocation. (Mappings::insert_bang_proc_macro_invocation): Add a function to insert a bang proc macro invocation. (Mappings::lookup_bang_proc_macro_invocation): Add a function to lookup a bang proc macro invocation. (Mappings::insert_attribute_proc_macro_invocation): Add a function to insert an attribute proc macro invocation. (Mappings::lookup_attribute_proc_macro_invocation): Add a function to lookup an attribute proc macro invocation. * util/rust-hir-map.h: Add different proc macro mappings and change function prototypes. * expand/rust-expand-visitor.cc (get_traits_to_derive): Return a vector of SimplePath instead. (derive_item): Accept SimplePath instead of a string. * ast/rust-ast.h: Add common ProcMacroInvocable interface to Identifiers and SimplePath nodes. * ast/rust-ast.cc: Add const modifier. * ast/rust-macro.h: Change path and identifier getters. * ast/rust-path.h: Change return type to reference. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Replace some usages of Location with location_tOwen Avery1-2/+2
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc: Replace Location with location_t. * ast/rust-ast.cc: Likewise. * ast/rust-ast.h: Likewise. * ast/rust-expr.h: Likewise. * ast/rust-item.h: Likewise. * ast/rust-macro.h: Likewise. * ast/rust-path.cc: Likewise. * ast/rust-path.h: Likewise. * ast/rust-pattern.h: Likewise. * ast/rust-stmt.h: Likewise. * ast/rust-type.h: Likewise. * backend/rust-compile-base.cc: Likewise. * backend/rust-compile-base.h: Likewise. * backend/rust-compile-block.cc: Likewise. * backend/rust-compile-expr.cc: Likewise. * backend/rust-compile-expr.h: Likewise. * backend/rust-compile-fnparam.cc: Likewise. * backend/rust-compile-fnparam.h: Likewise. * backend/rust-compile-intrinsic.cc: Likewise. * backend/rust-compile-pattern.cc: Likewise. * backend/rust-compile-resolve-path.h: Likewise. * backend/rust-compile.cc: Likewise. * checks/errors/rust-const-checker.cc: Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc: Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * expand/rust-macro-builtins.cc: Likewise. * expand/rust-macro-expand.h: Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-implitem.h: Likewise. * hir/rust-ast-lower-item.cc: Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-item.h: Likewise. * hir/tree/rust-hir-path.h: Likewise. * hir/tree/rust-hir-pattern.h: Likewise. * hir/tree/rust-hir-stmt.h: Likewise. * hir/tree/rust-hir-type.h: Likewise. * hir/tree/rust-hir.cc: Likewise. * hir/tree/rust-hir.h: Likewise. * lex/rust-token.h: Likewise. * metadata/rust-extern-crate.cc: Likewise. * metadata/rust-extern-crate.h: Likewise. * parse/rust-parse-impl.h: Likewise. * parse/rust-parse.h: Likewise. * resolve/rust-ast-resolve-expr.cc: Likewise. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-pattern.h: Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-ast-resolve-toplevel.h: Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-name-resolver.cc: Likewise. * resolve/rust-name-resolver.h: Likewise. * rust-diagnostics.cc: Likewise. * rust-diagnostics.h: Likewise. * rust-gcc.cc: Likewise. * rust-session-manager.cc: Likewise. * rust-session-manager.h: Likewise. * typecheck/rust-casts.cc: Likewise. * typecheck/rust-casts.h: Likewise. * typecheck/rust-coercion.cc: Likewise. * typecheck/rust-coercion.h: Likewise. * typecheck/rust-hir-path-probe.cc: Likewise. * typecheck/rust-hir-path-probe.h: Likewise. * typecheck/rust-hir-trait-reference.cc: Likewise. * typecheck/rust-hir-trait-reference.h: Likewise. * typecheck/rust-hir-trait-resolve.cc: Likewise. * typecheck/rust-hir-type-check-base.cc: Likewise. * typecheck/rust-hir-type-check-base.h: Likewise. * typecheck/rust-hir-type-check-item.cc: Likewise. * typecheck/rust-hir-type-check-item.h: Likewise. * typecheck/rust-hir-type-check-path.cc: Likewise. * typecheck/rust-hir-type-check-pattern.cc: Likewise. * typecheck/rust-hir-type-check-pattern.h: Likewise. * typecheck/rust-hir-type-check-type.cc: Likewise. * typecheck/rust-hir-type-check-type.h: Likewise. * typecheck/rust-hir-type-check.cc: Likewise. * typecheck/rust-hir-type-check.h: Likewise. * typecheck/rust-substitution-mapper.cc: Likewise. * typecheck/rust-substitution-mapper.h: Likewise. * typecheck/rust-type-util.cc: Likewise. * typecheck/rust-typecheck-context.cc: Likewise. * typecheck/rust-tyty-bounds.cc: Likewise. * typecheck/rust-tyty-call.h: Likewise. * typecheck/rust-tyty-subst.cc: Likewise. * typecheck/rust-tyty-subst.h: Likewise. * typecheck/rust-tyty-util.cc: Likewise. * typecheck/rust-tyty-util.h: Likewise. * typecheck/rust-tyty.cc: Likewise. * typecheck/rust-tyty.h: Likewise. * typecheck/rust-unify.cc: Likewise. * typecheck/rust-unify.h: Likewise. * util/rust-hir-map.cc: Likewise. * util/rust-hir-map.h: Likewise. * util/rust-identifier.h: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: rust-unreachable: Add specific behavior for rust_unreachableArthur Cohen1-2/+2
As discussed during the community call, rust_unreachable() should always trigger an internal compiler error and should not offer the behavior of __builtin_unreachable when asserts are disabled, unlike gcc_unreachable(). gcc/rust/ChangeLog: * rust-system.h (rust_unreachable): Change definition to fancy_abort * ast/rust-ast-collector.cc (TokenCollector::visit): Use rust_unreachable instead of gcc_unreachable. (get_delimiters): Likewise. * ast/rust-ast-dump.h: Likewise. * ast/rust-ast-formatting.cc (get_string_in_delims): Likewise. (get_mode_dump_desc): Likewise. * ast/rust-ast.cc (Visibility::as_string): Likewise. (UseTreeGlob::as_string): Likewise. * ast/rust-ast.h: Likewise. * ast/rust-macro.h: Likewise. * ast/rust-path.h: Likewise. * backend/rust-compile-expr.cc (sort_tuple_patterns): Likewise. (CompileExpr::visit): Likewise. (CompileExpr::generate_closure_fntype): Likewise. * backend/rust-compile-intrinsic.cc (op_with_overflow_inner): Likewise. * backend/rust-compile-pattern.cc (CompilePatternBindings::visit): Likewise. (CompilePatternLet::visit): Likewise. * backend/rust-constexpr.cc (base_field_constructor_elt): Likewise. (eval_array_reference): Likewise. (label_matches): Likewise. (eval_store_expression): Likewise. (eval_call_expression): Likewise. (build_data_member_initialization): Likewise. (array_index_cmp): Likewise. (get_array_or_vector_nelts): Likewise. (eval_bit_field_ref): Likewise. (eval_loop_expr): Likewise. (potential_constant_expression_1): Likewise. * backend/rust-mangle.cc (v0_simple_type_prefix): Likewise. (v0_type_prefix): Likewise. (v0_mangle_item): Likewise. (Mangler::mangle_item): Likewise. * backend/rust-tree.cc (convert_to_void): Likewise. (type_memfn_quals): Likewise. (rs_tree_equal): Likewise. (fold_offsetof): Likewise. (fold_builtin_source_location): Likewise. (lvalue_error): Likewise. * backend/rust-tree.h (struct named_decl_hash): Likewise. (struct named_label_hash): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_visibility): Likewise. (VisibilityResolver::visit): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::ctx_to_str): Likewise. * checks/errors/rust-feature.cc (Feature::create): Likewise. * expand/rust-expand-visitor.cc (get_traits_to_derive): Likewise. (derive_item): Likewise. (expand_item_attribute): Likewise. (expand_stmt_attribute): Likewise. * expand/rust-macro-expand.cc (MacroExpander::match_matcher): Likewise. (MacroExpander::match_repetition): Likewise. (transcribe_context): Likewise. (MacroExpander::import_proc_macros): Likewise. (MacroExpander::parse_proc_macro_output): Likewise. * expand/rust-macro-expand.h: Likewise. * expand/rust-macro-invoc-lexer.h: Likewise. * expand/rust-macro-substitute-ctx.cc (SubstituteCtx::substitute_token): Likewise. * expand/rust-proc-macro-invoc-lexer.h: Likewise. * expand/rust-proc-macro.cc (load_macros): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args): Likewise. (ASTLoweringBase::lower_literal): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower-type.cc (ASTLoweringType::visit): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/tree/rust-hir.cc (get_string_in_delims): Likewise. (Visibility::as_string): Likewise. (UseTreeGlob::as_string): Likewise. (CompoundAssignmentExpr::as_string): Likewise. (ArithmeticOrLogicalExpr::as_string): Likewise. * lex/rust-lex.cc (Lexer::parse_byte_string): Likewise. (Lexer::parse_string): Likewise. * lex/rust-token.cc (RS_TOKEN): Likewise. * parse/rust-parse-impl.h (Parser::parse_simple_path_segment): Likewise. (Parser::parse_path_ident_segment): Likewise. (Parser::parse_attr_input): Likewise. (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_trait_impl_item): Likewise. (Parser::parse_type_path_segment): Likewise. (Parser::parse_reference_type): Likewise. (get_lbp_for_comparison_expr): Likewise. * parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. (ResolveTypeToCanonicalPath::visit): Likewise. (ResolveGenericArgs::resolve_disambiguated_generic): Likewise. * rust-gcc.cc (operator_to_tree_code): Likewise. (fetch_overflow_builtins): Likewise. (Gcc_backend::non_zero_size_type): Likewise. (Gcc_backend::convert_tree): Likewise. * rust-lang.cc (grs_langhook_type_for_mode): Likewise. (grs_langhook_global_bindings_p): Likewise. (grs_langhook_pushdecl): Likewise. (grs_langhook_getdecls): Likewise. (convert): Likewise. * typecheck/rust-autoderef.h: Likewise. * typecheck/rust-hir-path-probe.cc: Likewise. * typecheck/rust-hir-trait-reference.cc (TraitItemReference::get_tyty): Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise. * typecheck/rust-hir-type-check-expr.cc: Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise. * typecheck/rust-hir-type-check-stmt.h: Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-substitution-mapper.h: Likewise. * typecheck/rust-typecheck-context.cc (TypeCheckContextItem::get_context_type): Likewise. * typecheck/rust-tyty-call.h: Likewise. * typecheck/rust-tyty.cc (TypeKindFormat::to_string): Likewise. (BaseType::monomorphized_clone): Likewise. (VariantDef::variant_type_string): Likewise. (ClosureType::handle_substitions): Likewise. (IntType::as_string): Likewise. (UintType::as_string): Likewise. (FloatType::as_string): Likewise. * typecheck/rust-unify.cc (UnifyRules::expect_projection): Likewise. * util/rust-token-converter.cc (convert): Likewise. (from_literal): Likewise. (from_group): Likewise. (from_tokentree): Likewise.
2024-01-16gccrs: Replace Linemap::unknown_location with UNKNOWN_LOCATIONOwen Avery1-8/+7
gcc/rust/ChangeLog: * rust-linemap.h (Linemap::unknown_location): Remove. * ast/rust-ast.cc: Replace Linemap::unknown_location with UNKNOWN_LOCATION. * ast/rust-path.cc: Likewise. * hir/tree/rust-hir.cc: Likewise. * metadata/rust-imports.cc: Likewise. * parse/rust-parse-impl.h: Likewise. * parse/rust-parse.h: Likewise. * rust-backend.h: Likewise. * rust-diagnostics.cc: Likewise. * rust-session-manager.cc: Likewise. * typecheck/rust-tyty.cc: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: ast: Change Identifier definitionPierre-Emmanuel Patry1-50/+64
Change Identifier type definition from a simple typedef to a whole class with it's own node id. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Change with call to getter. * ast/rust-ast.cc (Module::as_string): Likewise. (StaticItem::as_string): Likewise. (TupleStruct::as_string): Likewise. (Method::as_string): Likewise. (StructStruct::as_string): Likewise. (UseTreeRebind::as_string): Likewise. (Enum::as_string): Likewise. (Trait::as_string): Likewise. (Union::as_string): Likewise. (Function::as_string): Likewise. (TypeAlias::as_string): Likewise. (MacroRulesDefinition::as_string): Likewise. (FieldAccessExpr::as_string): Likewise. (MacroMatchFragment::as_string): Likewise. (TypeParam::as_string): Likewise. (StructExprFieldIdentifierValue::as_string): Likewise. (EnumItem::as_string): Likewise. (StructField::as_string): Likewise. (ExternalTypeItem::as_string): Likewise. (ExternalStaticItem::as_string): Likewise. (ExternalFunctionItem::as_string): Likewise. (TraitFunctionDecl::as_string): Likewise. (TraitMethodDecl::as_string): Likewise. (TraitItemConst::as_string): Likewise. (TraitItemType::as_string): Likewise. (MaybeNamedParam::as_string): Likewise. (MetaListPaths::as_string): Likewise. (MetaListNameValueStr::as_string): Likewise. (Module::process_file_path): Likewise. (MetaListNameValueStr::check_cfg_predicate): Likewise. (MetaListPaths::check_cfg_predicate): Likewise. (MetaWord::check_cfg_predicate): Likewise. (MetaNameValueStr::check_cfg_predicate): Likewise. (MetaNameValueStr::to_attribute): Likewise. (MetaWord::to_attribute): Likewise. (MetaListPaths::to_attribute): Likewise. (MetaListNameValueStr::to_attribute): Likewise. (operator<<): Change Identifier class << operator overload for standard output stream. * ast/rust-ast.h (class Identifier): Change typedef to proper class definition. (operator<<): Add prototype for operator overload. (class Token): Change getter identifier. (class MetaListNameValueStr): Likewise. (class PathExpr): Likewise. * ast/rust-expr.h: Likewise. * ast/rust-item.h: Likewise. * ast/rust-macro.h: Likewise. * ast/rust-path.cc (GenericArg::disambiguate_to_type): Likewise. (GenericArgsBinding::as_string): Likewise. (ConstGenericParam::as_string): Likewise. * ast/rust-path.h: Likewise. * ast/rust-pattern.cc (IdentifierPattern::as_string): Likewise. (StructPatternFieldIdentPat::as_string): Likewise. (StructPatternFieldIdent::as_string): Likewise. * ast/rust-type.h: Likewise. * backend/rust-compile-base.cc: Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. * backend/rust-compile-extern.h: Likewise. * backend/rust-compile-fnparam.cc (CompileFnParam::visit): Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-pattern.cc (CompilePatternBindings::visit): Likewise. * backend/rust-compile-struct-field-expr.cc (CompileStructExprField::visit): Likewise. * backend/rust-compile-var-decl.h: Likewise. * backend/rust-compile.cc: Likewise. * checks/errors/rust-unsafe-checker.cc (check_extern_call): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::visit): Likewise. * checks/lints/rust-lint-scan-deadcode.h: Likewise. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Likewise. (DeriveClone::visit_tuple): Likewise. (DeriveClone::visit_struct): Likewise. (DeriveClone::visit_union): Likewise. * expand/rust-derive-copy.cc (DeriveCopy::visit_struct): Likewise. (DeriveCopy::visit_tuple): Likewise. (DeriveCopy::visit_enum): Likewise. (DeriveCopy::visit_union): Likewise. * expand/rust-macro-expand.cc (MacroExpander::match_matcher): Likewise. (MacroExpander::match_n_matches): Likewise. (MacroExpander::match_repetition): Likewise. (MacroExpander::match_repetition_skipped_metavars): Likewise. * hir/rust-ast-lower-base.cc (struct_field_name_exists): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-item.h: Likewise. * hir/tree/rust-hir-path.h: Likewise. * hir/tree/rust-hir-type.h: Likewise. * hir/tree/rust-hir.cc (Module::as_string): Likewise. (StaticItem::as_string): Likewise. (TupleStruct::as_string): Likewise. (ConstantItem::as_string): Likewise. (StructStruct::as_string): Likewise. (UseTreeRebind::as_string): Likewise. (Enum::as_string): Likewise. (Trait::as_string): Likewise. (Union::as_string): Likewise. (Function::as_string): Likewise. (TypeAlias::as_string): Likewise. (FieldAccessExpr::as_string): Likewise. (TypeParam::as_string): Likewise. (GenericArgsBinding::as_string): Likewise. (StructPatternFieldIdent::as_string): Likewise. (StructPatternFieldIdentPat::as_string): Likewise. (IdentifierPattern::as_string): Likewise. (StructExprFieldIdentifierValue::as_string): Likewise. (EnumItem::as_string): Likewise. (StructField::as_string): Likewise. (ExternalStaticItem::as_string): Likewise. (ExternalFunctionItem::as_string): Likewise. (NamedFunctionParam::as_string): Likewise. (TraitFunctionDecl::as_string): Likewise. (TraitItemConst::as_string): Likewise. (TraitItemType::as_string): Likewise. (MaybeNamedParam::as_string): Likewise. * hir/tree/rust-hir.h: Likewise. * parse/rust-parse-impl.h (Parser::parse_macro_match_fragment): Likewise. (Parser::parse_module): Likewise. (Parser::parse_use_tree): Likewise. (Parser::parse_maybe_named_param): Likewise. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. (ResolveItem::visit): Likewise. (flatten_rebind): Likewise. (ResolveExternItem::visit): Likewise. (rust_flatten_rebind): Likewise. (rust_flatten_rebind_nested): Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go): Likewise. (PatternDeclaration::visit): Likewise. (PatternDeclaration::add_new_binding): Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-ast-resolve-toplevel.h: Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * typecheck/rust-autoderef.cc: Likewise. * typecheck/rust-hir-dot-operator.cc (MethodResolver::select): Likewise. * typecheck/rust-hir-path-probe.cc (PathProbeType::visit): Likewise. * typecheck/rust-hir-trait-reference.cc (TraitReference::get_name): Likewise. * typecheck/rust-hir-trait-resolve.cc (ResolveTraitItemToRef::visit): Likewise. (TraitResolver::resolve_trait): Likewise. (TraitItemReference::resolve_item): Likewise. (AssociatedImplTrait::setup_raw_associated_types): Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise. (TypeCheckImplItem::visit): Likewise. (TypeCheckImplItemWithTrait::visit): Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::visit): Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): Likewise. * util/rust-attributes.cc (check_doc_attribute): Likewise. * util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: expand: Change names and document behaviorPierre-Emmanuel Patry1-1/+3
Change some argument name, as well as some documentation. gcc/rust/ChangeLog: * ast/rust-ast.cc (BlockExpr::normalize_tail_expr): Refactor code and warn about dangling reference. * expand/rust-expand-visitor.cc (expand_stmt_attribute): Document function and change argument names to make those clearer. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Handle tail expression normalization right before lowering to HIR.Matthew Jasper1-4/+2
This allows braced macros at the end of blocks to correctly expand to zero or more statements followed by a tail expression. Parsing still creates a tail expression for now. gcc/rust/ChangeLog: * ast/rust-ast.cc (BlockExpr::strip_tail_expr): Don't normalize tail expression in this method. (BlockExpr::normalize_tail_expr): New method that only does the normalization. * ast/rust-expr.h: Declare new method. * hir/rust-ast-lower-block.h: Normalize tail expressions on blocks before lowering. Signed-off-by: Matthew Jasper <mjjasper1@gmail.com>
2024-01-16gccrs: Fix non-mod-rs files' external module loading pathsOwen Avery1-8/+24
gcc/rust/ChangeLog: * Make-lang.in: Add "rust-dir-owner.o". * ast/rust-ast.cc: Include "rust-dir-owner.h". (Module::process_file_path): Handle non-mod-rs external file modules properly. * parse/rust-parse-impl.h: Include "rust-dir-owner.h". (Parser::parse_module): Handle non-mod-rs external file modules properly. * util/rust-dir-owner.cc: New file. * util/rust-dir-owner.h: New file. gcc/testsuite/ChangeLog: * rust/compile/test_mod.rs: Moved to... * rust/compile/issue-1089/test_mod.rs: ...here. * rust/compile/mod_missing_middle.rs: Fix paths. * rust/compile/missing_middle/both_path.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/both_path.rs: ...here. * rust/compile/missing_middle/explicit.not.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/explicit.not.rs: ...here. * rust/compile/missing_middle/other.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/explicit.not/other.rs: ...here. * rust/compile/missing_middle/inner_path.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/inner_path.rs: ...here. * rust/compile/missing_middle/outer_path.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/outer_path.rs: ...here. * rust/compile/missing_middle/sub/mod.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/sub/mod.rs: ...here. * rust/compile/torture/modules/mod.rs: Moved to... * rust/compile/torture/extern_mod1/modules/mod.rs: ...here. * rust/execute/torture/modules/mod.rs: Moved to... * rust/execute/torture/extern_mod4/modules/mod.rs: ...here. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Only check first item of cfg_attr attribute as predicateMatthew Jasper1-1/+2
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>
2024-01-16gccrs: Add AST::AttrInputMacroOwen Avery1-0/+24
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>
2024-01-16gccrs: ast: Remove ExprStmtWithBlock / ExprStmtWithoutBlock distinctionMatthew Jasper1-32/+8
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>
2024-01-16gccrs: Handle replacing stripped tail expressionsOwen Avery1-0/+25
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>
2024-01-16gccrs: Unify AST::IfLetExprConseqIf{,Let} into AST::IfLetExprConseqElseOwen Avery1-33/+1
This simplifies the AST's representation of if-let-statements to match the HIR. gcc/rust/ChangeLog: * ast/rust-expr.h (class IfLetExprConseqElse): Make else_block ExprWithBlock. (class IfLetExprConseqIf): Remove. (class IfLetExprConseqIfLet): Remove. * ast/rust-ast-full-decls.h (class IfLetExprConseqIf): Remove. (class IfLetExprConseqIfLet): Remove. * ast/rust-ast.cc (IfLetExprConseqElse::as_string): Adjust output. (IfLetExprConseqIf::as_string): Remove. (IfLetExprConseqIfLet::as_string): Remove. (IfLetExprConseqIf::accept_vis): Remove. (IfLetExprConseqIfLet::accept_vis): Remove. * ast/rust-ast-visitor.h (ASTVisitor::visit): Remove IfLetExprConseqIf{,Let} visitors. * ast/rust-ast-dump.cc (Dump::visit): Likewise. * ast/rust-ast-dump.h: (Dump::visit): Likewise. * ast/rust-ast-tokenstream.cc (TokenStream::visit): Likewise. * ast/rust-ast-tokenstream.h (TokenStream::visit): Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h: (AttributeChecker::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * resolve/rust-early-name-resolver.h (EarlyNameResolver::visit): Likewise. * resolve/rust-ast-resolve-base.h (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * checks/errors/rust-feature-gate.h (FeatureGate::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-cfg-strip.h: (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: (ASTLoweringBase::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_if_let_expr): Replace IfLetExprConseqIf{,Let} with IfLetExprConseqElse. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Unify AST::IfExprConseqIf{,Let} into AST::IfExprConseqElseOwen Avery1-33/+1
This simplifies the AST's representation of if-statements to match the HIR. gcc/rust/ChangeLog: * ast/rust-expr.h (class IfExprConseqElse): Make else_block ExprWithBlock. (class IfExprConseqIf): Remove. (class IfExprConseqIfLet): Remove. * ast/rust-ast-full-decls.h (class IfExprConseqIf): Remove. (class IfExprConseqIfLet): Remove. * ast/rust-ast.cc (IfExprConseqElse::as_string): Adjust output. (IfExprConseqIf::as_string): Remove. (IfExprConseqIfLet::as_string): Remove. (IfExprConseqIf::accept_vis): Remove. (IfExprConseqIfLet::accept_vis): Remove. * ast/rust-ast-visitor.h (ASTVisitor::visit): Remove IfExprConseqIf{,Let} visitors. * ast/rust-ast-tokenstream.cc (TokenStream::visit): Likewise. * ast/rust-ast-tokenstream.h (TokenStream::visit): Likewise. * ast/rust-ast-dump.cc (Dump::visit): Likewise. * ast/rust-ast-dump.h (Dump::visit): Likewise. * checks/errors/rust-feature-gate.h (FeatureGate::visit): Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h (AttributeChecker::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * resolve/rust-early-name-resolver.h (EarlyNameResolver::visit): Likewise. * resolve/rust-ast-resolve-base.h (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-expr.h (ResolveExpr::visit): Remove IfExprConseqIf visitor. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Remove IfExprConseqIf{,Let} visitors. * expand/rust-cfg-strip.h (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfBlock::visit): Remove IfExprConseqIf visitor. (ASTLoweringExprWithBlock::visit): Likewise. * hir/rust-ast-lower.cc (ASTLoweringIfBlock::visit): Remove IfExprConseqIf visitor, adjust IfExprConseqElse lowering. * hir/rust-ast-lower-expr.h (ASTLoweringExpr::visit): Remove IfExprConseqIf visitor. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_if_expr): Replace IfExprConseqIf{,Let} with IfExprConseqElse. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: ast: Move pattern implementation out of rust-astPierre-Emmanuel Patry1-530/+0
Move rust-pattern implementation out of rust-ast.cc in their own file. gcc/rust/ChangeLog: * Make-lang.in: Add two new files to the list of sources. * ast/rust-ast-full.h: Add new ast formatting header. * ast/rust-ast.cc (enum indent_mode): Move formatting function to it's own file. (indent_spaces): Likewise. (get_string_in_delims): Likewise. (enum AttrMode): Likewise. (get_mode_dump_desc): Likewise. (append_attributes): Likewise. (unquote_string): Likewise. (GroupedExpr::as_string): Move pattern implementation to it's own file. (RangePattern::as_string): Likewise. (RangePatternBoundLiteral::as_string): Likewise. (SlicePattern::as_string): Likewise. (AltPattern::as_string): Likewise. (TuplePatternItemsMultiple::as_string): Likewise. (TuplePatternItemsRanged::as_string): Likewise. (TuplePattern::as_string): Likewise. (StructPatternField::as_string): Likewise. (StructPatternFieldIdent::as_string): Likewise. (StructPatternFieldTuplePat::as_string): Likewise. (StructPatternFieldIdentPat::as_string): Likewise. (StructPatternElements::as_string): Likewise. (StructPattern::as_string): Likewise. (LiteralPattern::as_string): Likewise. (ReferencePattern::as_string): Likewise. (IdentifierPattern::as_string): Likewise. (TupleStructItemsNoRange::as_string): Likewise. (TupleStructItemsRange::as_string): Likewise. (TupleStructPattern::as_string): Likewise. (GroupedExpr::accept_vis): Likewise. (LiteralPattern::accept_vis): Likewise. (IdentifierPattern::accept_vis): Likewise. (WildcardPattern::accept_vis): Likewise. (RestPattern::accept_vis): Likewise. (RangePatternBoundLiteral::accept_vis): Likewise. (RangePatternBoundPath::accept_vis): Likewise. (RangePatternBoundQualPath::accept_vis): Likewise. (RangePattern::accept_vis): Likewise. (ReferencePattern::accept_vis): Likewise. (StructPatternFieldTuplePat::accept_vis): Likewise. (StructPatternFieldIdentPat::accept_vis): Likewise. (StructPatternFieldIdent::accept_vis): Likewise. (StructPattern::accept_vis): Likewise. (TupleStructItemsNoRange::accept_vis): Likewise. (TupleStructItemsRange::accept_vis): Likewise. (TupleStructPattern::accept_vis): Likewise. (TuplePatternItemsMultiple::accept_vis): Likewise. (TuplePatternItemsRanged::accept_vis): Likewise. (TuplePattern::accept_vis): Likewise. (GroupedPattern::accept_vis): Likewise. (SlicePattern::accept_vis): Likewise. (AltPattern::accept_vis): Likewise. * ast/rust-ast-formatting.cc: New file. * ast/rust-ast-formatting.h: New file. * ast/rust-pattern.cc: New file. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Move rust-path implementation out of rust-astPierre-Emmanuel Patry1-326/+0
Move rust-path implementation details out of rust-ast.cc file. This will hopefully decrease compile time and make things clearer. gcc/rust/ChangeLog: * Make-lang.in: Add new file for rust-path implementation. * ast/rust-ast.cc (PathInExpression::as_string): Move function to the new file. (PathPattern::as_string): Likewise. (QualifiedPathInExpression::as_string): Likewise. (ConstGenericParam::as_string): Likewise. (QualifiedPathInType::as_string): Likewise. (TypePath::as_string): Likewise. (PathPattern::convert_to_simple_path): Likewise. (TypePath::as_simple_path): Likewise. (PathExprSegment::as_string): Likewise. (GenericArgs::as_string): Likewise. (GenericArgsBinding::as_string): Likewise. (TypePath::to_trait_bound): Likewise. (TypePathSegmentGeneric::as_string): Likewise. (TypePathFunction::as_string): Likewise. (TypePathSegmentFunction::as_string): Likewise. (ConstGenericParam::accept_vis): Likewise. (PathInExpression::accept_vis): Likewise. (TypePathSegment::accept_vis): Likewise. (TypePathSegmentGeneric::accept_vis): Likewise. (TypePathSegmentFunction::accept_vis): Likewise. (TypePath::accept_vis): Likewise. (QualifiedPathInExpression::accept_vis): Likewise. (QualifiedPathInType::accept_vis): Likewise. (GenericArg::disambiguate_to_const): Likewise. (GenericArg::disambiguate_to_type): Likewise. * ast/rust-path.cc: New file. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Refactor SimplePath attribute namePierre-Emmanuel Patry1-1/+1
The getter name was overly complicated and long, this could be refactored to a shorter name. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Change getter name. * ast/rust-ast.cc (SimplePath::as_string): Change attribute name. * ast/rust-ast.h (class SimplePath): Refactor attribute name and change getter name. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Fix missing move and copy constructors missing the associated-pathPhilip Herron1-0/+1
Addresses #1524 Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * ast/rust-ast.cc (QualifiedPathInType::as_string): add missing to string * ast/rust-path.h: add missing copy+move constructors and assignment overloads * hir/tree/rust-hir-path.h: likewise * hir/tree/rust-hir.cc (QualifiedPathInType::as_string): add missing to string gcc/testsuite/ChangeLog: * rust/compile/parse_associated_type_as_generic_arg.rs: it now works without -fsyntax-only * rust/compile/parse_associated_type_as_generic_arg2.rs: likewise
2024-01-16gccrs: ast: Add RestPattern AST nodePierre-Emmanuel Patry1-0/+6
Add the RestPattern AST node representing ".." code in some rust context. This commit also provides the different visitors for this node. gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add visitor. * ast/rust-ast-dump.h: Add visitor prototype. * ast/rust-ast-full-decls.h (class RestPattern): Add forward declaration for class RestPattern. * ast/rust-ast-visitor.h: Add visitor prototype. * ast/rust-ast.cc (RestPattern::accept_vis): Add function to accept a foreign visitor. * ast/rust-pattern.h (class RestPattern): Add class RestPattern. * checks/errors/rust-feature-gate.h: Add visitor prototype. * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Add visitor implementation. * expand/rust-attribute-visitor.h: Add visitor prototype. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add visitor implementation. * hir/rust-ast-lower-base.h: Add visitor prototype. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visitor implementation. * resolve/rust-ast-resolve-base.h: Add visitor prototype. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Add visitor implementation. * resolve/rust-early-name-resolver.h: Add visitor prototype. * util/rust-attributes.cc (AttributeChecker::visit): Add visitor implementation. * util/rust-attributes.h: Add visitor prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add ExternalTypeItem nodeArthur Cohen1-0/+16
gcc/rust/ChangeLog: * ast/rust-item.h (class ExternalTypeItem): New class. * ast/rust-ast.cc (ExternalTypeItem::as_string): New function. (ExternalTypeItem::accept_vis): Likewise. * ast/rust-ast-full-decls.h (class ExternalTypeItem): Declare class. * ast/rust-ast-dump.cc (Dump::visit): Add base visitor for ExternalTypeItem. * ast/rust-ast-dump.h: Likewise. * ast/rust-ast-visitor.h: Likewise. * checks/errors/rust-feature-gate.h: Likewise. * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Likewise. * expand/rust-attribute-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * resolve/rust-early-name-resolver.h: Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h: Likewise.
2024-01-03Update copyright years.Jakub Jelinek1-1/+1