aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir
AgeCommit message (Collapse)AuthorFilesLines
2024-01-16gccrs: ast: Change Identifier definitionPierre-Emmanuel Patry10-46/+57
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: Handle tail expression normalization right before lowering to HIR.Matthew Jasper1-0/+1
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: Add missing HIR lowering to item statementsPhilip Herron2-262/+28
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>
2024-01-16gccrs: Add AST::AttrInputMacroOwen Avery2-0/+4
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: Fix parsing of block expressions followed by `.`Matthew Jasper1-11/+0
`{ ... }.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>
2024-01-16gccrs: ast: Remove ExprStmtWithBlock / ExprStmtWithoutBlock distinctionMatthew Jasper4-27/+7
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: Added HIR::InlineAsm nodeM V V S Manoj Kumar2-0/+92
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>
2024-01-16gccrs: Lower StructPatternFieldIdentPatOwen Avery1-2/+17
gcc/rust/ChangeLog: * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Lower StructPatternFieldIdentPat. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Add missing where clause lowering for Impl functionsPhilip Herron1-0/+16
Fixes #2106 gcc/rust/ChangeLog: * hir/rust-ast-lower-implitem.h: add missing where clause lowering gcc/testsuite/ChangeLog: * rust/compile/issue-2106.rs: New test. * rust/compile/issue-1524.rs: regression (placeholder generic) Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16gccrs: Add missing TypeBoundWhereClauseItem::get_locusPhilip Herron1-0/+2
gcc/rust/ChangeLog: * hir/tree/rust-hir-item.h: add get_locus() const Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16gccrs: Add accessors to HIR::StructPatternFieldIdentPatOwen Avery1-0/+4
gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (StructPatternFieldIdentPat::get_identifier): New. (StructPatternFieldIdentPat::get_pattern): New. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Add mechanism use pattern information to improve type infoPhilip Herron1-0/+2
When we have an untyped closure we assumed all parameters were inference variables but we can use the pattern type to try and improve the type info so if we have a reference pattern it must be a reference to an inference variables '&_'. This patch adds a new visitor to figure this out for untyped closure parameters. Note this test case does fully type resolve into the gimple: bool test::main::{{closure}} (struct test::main::{{closure}} $closure, struct (& u8) args) { ... } Though the Rustc version does fail type-resolution but we make some assumptions during comparison expressions here that they resolve to a bool this will change when we implement the comparison lang items. Fixes #2142 gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h: add missing get_mutability * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): use new ClosureParamInfer on untyped parameters * typecheck/rust-hir-type-check-pattern.cc (ClosureParamInfer::Resolve): interface (ClosureParamInfer::ClosureParamInfer): constructor (ClosureParamInfer::visit): visitors for each pattern * typecheck/rust-hir-type-check-pattern.h (class ClosureParamInfer): new visitor gcc/testsuite/ChangeLog: * rust/compile/issue-2142.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16gccrs: Add error message for AltPattern in let statementsOwen Avery3-3/+11
gcc/rust/ChangeLog: * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::translate): Add is_let_top_level parameter. (ASTLoweringPattern::visit): Handle is_let_top_level. * hir/rust-ast-lower-pattern.h (class ASTLoweringPattern): Add is_let_top_level. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Set is_let_top_level. gcc/testsuite/ChangeLog: * rust/compile/let_alt.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Lower ErrorPropagationExpr from AST to HIRSergey Bugaev2-0/+16
gcc/rust/ChangeLog: * hir/rust-ast-lower-expr.h, hir/rust-ast-lower-expr.cc: Lower AST::ErrorPropagationExpr to HIR::ErrorPropagationExpr Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2024-01-16gccrs: Add lowering for if-let expressionsOwen Avery5-1/+60
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add implementation for IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.h: (TypeCheckExpr::visit): Remove stub implementation for IfLetExprConseqElse. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower IfLetExpr{,ConseqElse}. * hir/rust-ast-lower-expr.h: (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::visit): Lower IfLetExprConseqElse. (ASTLoweringExprWithBlock::visit): Likewise. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::visit): Lower IfLetExprConseqElse. * hir/tree/rust-hir-expr.h (IfLetExprConseqElse::IfLetExprConseqElse): Make constructor more general. (IfLetExprConseqElse::vis_else_block): Add. (IfLetExprConseqElse::get_else_block): Add. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Add IfLetExprConseqElse visitor. * resolve/rust-ast-resolve-expr.h (ResolveExpr::visit): Add IfLetExprConseqElse visitor. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Increase test coverage. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Unify AST::IfLetExprConseqIf{,Let} into AST::IfLetExprConseqElseOwen Avery2-8/+0
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: Fully unify deriving classes into HIR::ExprStmtOwen Avery3-56/+18
gcc/rust/ChangeLog: * hir/tree/rust-hir-full-decls.h (class ExprStmtWithoutBlock): Remove. (class ExprStmtWithBlock): Remove. * hir/tree/rust-hir-stmt.h (class ExprStmt): Add remaining ExprStmtWith{,out}Block functionality. (class ExprStmtWithoutBlock): Remove. (class ExprStmtWithBlock): Remove. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Lower to HIR::ExprStmt instead of deriving class. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Unify HIR::ExprStmt derived class visitingOwen Avery5-32/+10
gcc/rust/ChangeLog: * backend/rust-compile-stmt.cc (CompileStmt::visit): Unify ExprStmtWith{,out}Block visitors. * backend/rust-compile-stmt.h (CompileStmt::visit): Likewise. * backend/rust-compile-item.h (CompileItem::visit): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h (Dump::visit): Likewise. * hir/tree/rust-hir-stmt.h (ExprStmt::accept_vis): Add. (ExprStmtWithoutBlock::accept_vis): Remove. (ExprStmtWithBlock::accept_vis): Remove. * hir/tree/rust-hir.cc (ExprStmt::accept_vis): Add. (ExprStmtWithoutBlock::accept_vis): Remove. (ExprStmtWithBlock::accept_vis): Remove. * hir/tree/rust-hir-visitor.h (HIRFullVisitor::visit): Likewise. (HIRFullVisitorBase::visit): Likewise. (HIRStmtVisitor::visit): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h (ConstChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h (UnsafeChecker::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h (PrivacyReporter::visit): Likewise. * checks/lints/rust-lint-marklive.h (MarkLive::visit): Likewise. * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Likewise. * typecheck/rust-hir-type-check-stmt.h (TypeCheckStmt::visit): Likewise. * typecheck/rust-tycheck-dump.h (TypeResolverDump::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Move functionality into HIR::ExprStmt from deriving classesOwen Avery2-72/+30
And move method as_string into HIR::ExprStmt from deriving classes gcc/rust/ChangeLog: * hir/tree/rust-hir-stmt.h (ExprStmt::expr): Add field. (ExprStmt::get_expr): Add method. (ExprStmt::ExprStmt): Add copy/move constructors, modify existing constructor. (ExprStmt::operator=): Add assignment operator. (ExprStmtWithoutBlock::expr): Remove field. (ExprStmtWithoutBlock::get_expr): Remove method. (ExprStmtWithoutBlock::ExprStmt): Remove copy/move constructors, modify existing constructor. (ExprStmtWithoutBlock::operator=): Remove assignment operator. (ExprStmtWithBlock::expr): Remove field. (ExprStmtWithBlock::get_expr): Remove method. (ExprStmtWithBlock::ExprStmt): Remove copy/move constructors, modify existing constructor. (ExprStmtWithBlock::operator=): Remove assignment operator. (ExprStmt::as_string): Add method. (ExprStmtWithBlock::as_string): Remove method. (ExprStmtWithoutBlock::as_string): Remove method. * hir/tree/rust-hir.cc (ExprStmt::as_string): Add method. (ExprStmtWithBlock::as_string): Remove method. (ExprStmtWithoutBlock::as_string): Remove method. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Unify AST::IfExprConseqIf{,Let} into AST::IfExprConseqElseOwen Avery6-54/+5
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: Refactor rust-ast-lower-type.h to source fileArthur Cohen2-363/+407
gcc/rust/ChangeLog: * hir/rust-ast-lower-type.h: Move all remaining definitions to source file. * hir/rust-ast-lower-type.cc (ASTLoweringType::translate): Moved to source file. (ASTLoweringType::visit): Likewise. (ASTLowerGenericParam::translate): Likewise. (ASTLowerGenericParam::visit): Likewise. (ASTLoweringTypeBounds::translate): Likewise. (ASTLoweringTypeBounds::visit): Likewise. (ASTLowerWhereClauseItem::translate): Likewise. (ASTLowerWhereClauseItem::visit): Likewise.
2024-01-16gccrs: lowering: Add lowering of exported macrosArthur Cohen6-12/+37
Macros marked with #[macro_export] need to be lowered to HIR in order to get exported to the relevant metadata files. gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_macro_definition): New function. * hir/rust-ast-lower-base.h: Declare `lower_macro_definition`. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Lower public macro definitions. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise. * hir/rust-ast-lower-stmt.h: Add visitor for `AST::MacroRulesDefinition`. * hir/rust-ast-lower.cc (ASTLowering::go): Formatting. (ASTLoweringBlock::visit): Visit `AST::MacroRulesDefinition` (ASTLoweringIfLetBlock::visit): Formatting. (ASTLoweringExprWithBlock::visit): Formatting.
2024-01-16gccrs: mappings: Keep exported macro IDsArthur Cohen2-0/+9
gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Add new visitor for AST::MacroRulesDefinition. * hir/rust-ast-lower-item.h: Declare above mentioned visitor. * metadata/rust-export-metadata.cc (ExportContext::emit_macro): New function. * metadata/rust-export-metadata.h: Declare it. (PublicInterface::gather_export_data): Go through each exported macro. * util/rust-hir-map.cc (Mappings::insert_exported_macro): New function. (Mappings::get_exported_macros): New function. * util/rust-hir-map.h: Add new mappings for exported macros.
2024-01-16gccrs: Revert "hir: Add ExportedMacro node and handling."Arthur Cohen9-92/+0
This reverts commit a1f940d193c6cdb13483690a4f4a7d501ad7040e. It is easier and cleaner to store exported macros' NodeIds into our mappings rather than create a new HIR kind of node. gcc/rust/ChangeLog: * backend/rust-compile-item.h: Revert 1c946687239b86a92839d57dfbc928ad7ce35eae. * backend/rust-compile-stmt.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/privacy/rust-pub-restricted-visitor.cc (PubRestrictedVisitor::visit): Likewise. * checks/errors/privacy/rust-pub-restricted-visitor.h: Likewise. * checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise. * checks/errors/privacy/rust-reachability.h: Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::visit): Likewise. * checks/errors/privacy/rust-visibility-resolver.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * hir/rust-ast-lower-item.h: Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h: Likewise. * hir/tree/rust-hir-full-decls.h (class ExportedMacro): Likewise. * hir/tree/rust-hir-item.h (class ExportedMacro): Likewise. * hir/tree/rust-hir-visitor.h: Likewise. * hir/tree/rust-hir.cc (ExportedMacro::accept_vis): Likewise. (ExportedMacro::get_locus): Likewise. (ExportedMacro::get_item_kind): Likewise. (ExportedMacro::clone_item_impl): Likewise. * hir/tree/rust-hir.h: Likewise. * metadata/rust-export-metadata.cc: Likewise. * typecheck/rust-hir-type-check-item.h: Likewise. * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Likewise. * typecheck/rust-hir-type-check-stmt.h: Likewise. * typecheck/rust-tycheck-dump.h: Likewise. * util/rust-attributes.cc: Likewise.
2024-01-16gccrs: Lower AltPatternOwen Avery2-0/+21
gcc/rust/ChangeLog: * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Lower AltPattern. * hir/rust-ast-lower-pattern.h: (ASTLoweringPattern::visit): Add AltPattern visitor. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: support use declaration to write the type into the correct namespacePhilip Herron4-11/+22
This builds upon the previous path resolution fixes so that it returns the resolved_node_id or UNKNOWN_NODEID on failure to resolve the use-path. It then exports the name to the current module namespace so it can be used. Fixes #850 #855 gcc/rust/ChangeLog: * ast/rust-ast.h: add const get_final_segment helper * hir/rust-ast-lower-enumitem.h: dont add an item mapping for enumitems * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): add enum to enum-items mappings * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): likewise * hir/tree/rust-hir-item.h: add non const helper to get variants * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): resolve the use declaration * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): handle self * resolve/rust-ast-resolve-toplevel.h: add enum item mappings to module mappings * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): ensure variant (TypeCheckExpr::resolve_segments): likewise * typecheck/rust-type-util.cc (query_type): lookup enum's * util/rust-hir-map.cc (Mappings::insert_hir_enumitem): enum item mappings (Mappings::lookup_hir_enumitem): likewise * util/rust-hir-map.h: likewise gcc/testsuite/ChangeLog: * rust/compile/issue-850.rs: New test. * rust/compile/issue-855.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16gccrs: Add name resolution and ast lowering for slice patternMahmoud Mohamed2-2/+22
gcc/rust/ChangeLog: * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Add lowering for SlicePattern. * hir/rust-ast-lower-pattern.h: Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Add name resolution visit for SlicePattern. * resolve/rust-ast-resolve-pattern.h: Likewise. Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
2024-01-16gccrs: Cleanup unused headersPhilip Herron8-26/+17
gcc/rust/ChangeLog: * hir/rust-ast-lower-implitem.h (RUST_AST_LOWER_IMPLITEM_H): cleanup header usage * hir/rust-ast-lower-item.cc: likewise * hir/rust-ast-lower-item.h (RUST_AST_LOWER_ITEM): likewise * hir/rust-ast-lower-stmt.cc: likewise * hir/rust-ast-lower-stmt.h (RUST_AST_LOWER_STMT): likewise * hir/rust-ast-lower-type.h: likewise * hir/rust-ast-lower.cc: likewise * hir/rust-ast-lower.h: likewise * resolve/rust-ast-resolve-expr.h: likewise * resolve/rust-ast-resolve-item.cc: likewise * resolve/rust-ast-resolve-item.h: likewise * resolve/rust-ast-resolve-stmt.cc: likewise * resolve/rust-ast-resolve-stmt.h: likewise * resolve/rust-ast-resolve-struct-expr-field.h: likewise * resolve/rust-ast-resolve-toplevel.h: likewise * resolve/rust-ast-resolve-type.h: likewise * resolve/rust-ast-resolve.h: likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16gccrs: Dump inner attrs for Dump::visit(BlockExpr &)Jiakun Fan2-7/+60
Refer to `BlockExpr::as_string ()`, dump inner attrs for `Dump::visit`. Add visit (AST::Attribute &). gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::go): fix format (Dump::visit): impl `visit (AST::Attribute &)`, dump inner attrs and `visit (Lifetime &)` * hir/rust-hir-dump.h:add `visit (AST::Attribute &)` Signed-off-by: Jiakun Fan <120090316@link.cuhk.edu.cn>
2024-01-16gccrs: Unify HIR::IfLetExprConseqIf{,Let} into HIR::IfLetExprConseqElseOwen Avery6-198/+4
This should allow for 'if let' expressions to be lowered more easily. gcc/rust/ChangeLog: * backend/rust-compile-block.h (CompileConditionalBlocks::visit): Remove IfLetExprConseqIf{,Let} visitors. (CompileExprWithBlock::visit): Remove IfLetExprConseqIf{,Let} visitors. * backend/rust-compile-expr.h (CompileExpr::visit): Remove IfLetExprConseqIf{,Let} visitors. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Remove IfLetExprConseqIf{,Let} visitors. * checks/errors/rust-unsafe-checker.h (UnsafeChecker::visit): Remove IfLetExprConseqIf{,Let} visitors. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Remove IfLetExprConseqIf{,Let} visitors. * checks/errors/rust-const-checker.h (ConstChecker::visit): Remove IfLetExprConseqIf{,Let} visitors. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Remove IfLetExprConseqIf{,Let} visitors. * checks/errors/privacy/rust-privacy-reporter.h (PrivacyReporter::visit): Remove IfLetExprConseqIf{,Let} visitors. * hir/tree/rust-hir-expr.h (class IfLetExprConseqElse): Make else_block ExprWithBlock. (class IfLetExprConseqIf): Remove. (class IfLetExprConseqIfLet): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExprConseqIf): Remove. (class IfLetExprConseqIfLet): Remove. * hir/tree/rust-hir.cc (IfLetExprConseqElse::as_string): Adjust output. (IfLetExprConseqIf::as_string): Remove. (IfLetExprConseqIfLet::as_string): Remove. (IfLetExprConseqIf::accept_vis): Remove. (IfLetExprConseqIfLet::accept_vis): Remove. * hir/tree/rust-hir-visitor.h (HIRFullVisitor::visit): Remove IfLetExprConseqIf{,Let} visitors. (HIRFullVisitorBase::visit): Remove IfLetExprConseqIf{,Let} visitors. (HIRExpressionVisitor::visit): Remove IfLetExprConseqIf{,Let} visitors. * hir/rust-hir-dump.cc (Dump::visit): Remove IfLetExprConseqIf{,Let} visitors. * hir/rust-hir-dump.h (Dump::visit): Remove IfLetExprConseqIf{,Let} visitors. * typecheck/rust-hir-type-check-expr.h (TypeCheckExpr::visit): Remove IfLetExprConseqIf{,Let} visitors. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Unify HIR::IfExprConseqIf{,Let} into HIR::IfExprConseqElseOwen Avery7-207/+10
This should simplify 'if' expression handling to match future simplifications to 'if let' expression handling. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Remove IfExprConseqIf visitor. * typecheck/rust-hir-type-check-expr.h (TypeCheckExpr::visit): Remove IfExprConseqIf{,Let} visitor. * backend/rust-compile-block.cc (CompileConditionalBlocks::visit): Remove IfExprConseqIf visitor. * backend/rust-compile-block.h (CompileConditionalBlocks::visit): Remove IfExprConseqIf{,Let} visitors. (CompileExprWithBlock::visit): Remove IfExprConseqIf{,Let} visitors, implement BlockExpr visitor. * backend/rust-compile-expr.cc (CompileExpr::visit): Remove IfExprConseqIf visitor. * backend/rust-compile-expr.h (CompileExpr::visit): Remove IfExprConseqIf{,Let} visitors. * checks/lints/rust-lint-marklive.h (MarkLive::visit): Remove IfExprConseqIf visitor. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/rust-const-checker.h (ConstChecker::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/rust-unsafe-checker.h (UnsafeChecker::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/privacy/rust-privacy-reporter.h (PrivacyReporter::visit): Remove IfExprConseqIf{,Let} visitors. * hir/tree/rust-hir-expr.h (class IfExprConseqElse): Make else_block ExprWithBlock. (class IfExprConseqIf): Remove. (class IfExprConseqIfLet): Remove. * hir/tree/rust-hir-full-decls.h (class IfExprConseqIf): Remove. (class IfExprConseqIfLet): Remove. * hir/tree/rust-hir.cc (IfExprConseqElse::as_string): Adjust output. (IfExprConseqIf::as_string): Remove. (IfExprConseqIfLet::as_string): Remove. (IfExprConseqIf::accept_vis): Remove. (IfExprConseqIfLet::accept_vis): Remove. * hir/tree/rust-hir-visitor.h (HIRFullVisitor::visit): Remove IfExprConseqIf{,Let} visitors. (HIRFullVisitorBase::visit): Remove IfExprConseqIf{,Let} visitors. (HIRExpressionVisitor::visit): Remove IfExprConseqIf{,Let} visitors. * hir/rust-hir-dump.cc (Dump::visit): Remove IfExprConseqIf{,Let} visitors. * hir/rust-hir-dump.h (Dump::visit): Remove IfExprConseqIf{,Let} visitors. * hir/rust-ast-lower.cc (ASTLoweringIfBlock::visit): Replace HIR::IfExprConseqIf with HIR::IfExprConseqElse. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Add method to access SlicePattern itemsOwen Avery1-0/+6
gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (SlicePattern::get_items): Add. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Convert structs to classesOwen Avery2-9/+6
gcc/rust/ChangeLog: * hir/tree/rust-hir-full-decls.h (struct GenericArgsBinding): Convert to class. (class GenericArgsBinding): Convert from struct. (struct TypePathFunction): See above. (class TypePathFunction): See above. (struct QualifiedPathType): See above. (class QualifiedPathType): See above. * ast/rust-ast-full-decls.h (struct WhereClause): See above. (class WhereClause): See above. (struct SelfParam): See above. (class SelfParam): See above. (struct FunctionQualifiers): See above. (class FunctionQualifiers): See above. (struct FunctionParam): See above. (class FunctionParam): See above. (struct StructField): See above. (class StructField): See above. (struct TupleField): See above. (class TupleField): See above. (struct TraitFunctionDecl): See above. (class TraitFunctionDecl): See above. (struct TraitMethodDecl): See above. (class TraitMethodDecl): See above. (struct NamedFunctionParam): See above. (class NamedFunctionParam): See above. * hir/tree/rust-hir-path.h (struct GenericArgsBinding): See above. (class GenericArgsBinding): See above. (struct TypePathFunction): See above. (class TypePathFunction): See above. (struct QualifiedPathType): See above. (class QualifiedPathType): See above. * ast/rust-item.h (struct WhereClause): See above. (class WhereClause): See above. (struct SelfParam): See above. (class SelfParam): See above. (struct FunctionQualifiers): See above. (class FunctionQualifiers): See above. (struct FunctionParam): See above. (class FunctionParam): See above. (struct StructField): See above. (class StructField): See above. (struct TupleField): See above. (class TupleField): See above. (struct TraitFunctionDecl): See above. (class TraitFunctionDecl): See above. (struct TraitMethodDecl): See above. (class TraitMethodDecl): See above. (struct NamedFunctionParam): See above. (class NamedFunctionParam): See above. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: HIR::AltPattern fixesOwen Avery2-1/+31
gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (class AltPattern): Remove duplicate access specifier. (AltPattern::get_alts): Add. * hir/tree/rust-hir.cc (AltPattern::as_string): Add. (AltPattern::accept_vis): Add. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: hir: Add ExportedMacro node and handling.Arthur Cohen9-0/+92
This HIR node represents macros which should be exported into the final Rust metadata files. Because our metadata exporter operates on the HIR, while macros are inherently tied to the AST, we need a way to propagate exported macros up until the metadata export pass on the HIR. Hence the existence of this class, whose sole purpose is to keep enough information for the metadata exporter to retrieve the original AST::MacroRulesDefinition. Handling for actually exporting these macros will come later. gcc/rust/ChangeLog: * hir/tree/rust-hir-item.h (class ExportedMacro): Add new ExportedMacro class. * hir/tree/rust-hir.cc (ExportedMacro::accept_vis): New function. (ExportedMacro::get_locus): Likewise. (ExportedMacro::get_item_kind): Likewise. (ExportedMacro::clone_item_impl): Likewise. * hir/tree/rust-hir-full-decls.h (class ExportedMacro): Forward declare class. * backend/rust-compile-item.h: Add visitor for ExportedMacro. * backend/rust-compile-stmt.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/privacy/rust-pub-restricted-visitor.cc (PubRestrictedVisitor::visit): Likewise. * checks/errors/privacy/rust-pub-restricted-visitor.h: Likewise. * checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise. * checks/errors/privacy/rust-reachability.h: Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::visit): Likewise. * checks/errors/privacy/rust-visibility-resolver.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * hir/rust-ast-lower-item.h: Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h: Likewise. * hir/tree/rust-hir-visitor.h: Likewise. * metadata/rust-export-metadata.cc: Likewise. * typecheck/rust-hir-type-check-item.h: Likewise. * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Likewise. * typecheck/rust-hir-type-check-stmt.h: Likewise. * typecheck/rust-tycheck-dump.h: Likewise. * hir/tree/rust-hir.h: Add new ItemKind::MacroExport variant. * util/rust-attributes.cc: Add #[macro_export] attribute.
2024-01-16gccrs: hir: Simplify indentation to single lineJakub Dupak1-55/+38
Improves readability by better corresponding to resulting output. gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::visit): Simplify indentation dump to single line. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-16gccrs: hir: Unify indentation approach with astJakub Dupak2-53/+53
gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Indent::Indent): Move to separate file. (operator<<): Move to separate file. (Indent::increment): Move to separate file. (Indent::decrement): Move to separate file. * ast/rust-ast-dump.h (class Indent): Move to separate file. * hir/rust-hir-dump.cc (Dump::Dump): Use new indentation object. (Dump::go): Use new indentation object. (Dump::visit): Use new indention object. * hir/rust-hir-dump.h: Use new indentation object. * util/rust-dump.h: New file. Moved Indentation from rust-ast-dump.cc Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-16gccrs: typecheck: Add basic typechecking for ReferenceTypegoar56701-0/+6
gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (HIR::ReferencePattern): added get_referenced_pattern function. * resolve/rust-ast-resolve-pattern.h (Resolve::PatternDeclaration): add visit function for AST::ReferencePattern * typecheck/rust-hir-type-check-pattern.cc (Resolver::TypeCheckPattern): add visit function for HIR::ReferencePattern gcc/testsuite/ChangeLog: * rust/compile/ref_pattern_fn_param.rs: New test. Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
2024-01-16gccrs: Add AltPattern HIR nodeOwen Avery6-0/+76
Example: match x { 0 | 1 => true, _ => false } gcc/rust/ChangeLog: * backend/rust-compile-fnparam.h: (CompileFnParam::visit): Add AltPattern visitor. * backend/rust-compile-pattern.h: (CompilePatternCaseLabelExpr::visit): Add AltPattern visitor. (CompilePatternBindings::visit): Add AltPattern visitor. (CompilePatternLet::visit): Add AltPattern visitor. * backend/rust-compile-resolve-path.h: (ResolvePathRef::visit): Add AltPattern visitor. * backend/rust-compile-var-decl.h: (CompileVarDecl::visit): Add AltPattern visitor. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Add AltPattern visitor. * checks/errors/rust-const-checker.h: (ConstChecker::visit): Add AltPattern visitor. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Add AltPattern visitor. * checks/errors/rust-unsafe-checker.h: (UnsafeChecker::visit): Add AltPattern visitor. * hir/rust-hir-dump.cc (Dump::visit): Add AltPattern visitor. * hir/rust-hir-dump.h: (Dump::visit): Add AltPattern visitor. * hir/tree/rust-hir-full-decls.h (class AltPattern): Add forward declaration. * hir/tree/rust-hir-pattern.h (class AltPattern): New class. * hir/tree/rust-hir-visitor.h: (HIRFullVisitor::visit): Add AltPattern visitor. (HIRFullVisitorBase::visit): Add AltPattern visitor. (HIRPatternVisitor::visit): Add AltPattern visitor. * hir/tree/rust-hir.h: (Pattern::PatternType::ALT): New enumerator. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Add AltPattern visitor. * typecheck/rust-hir-type-check-pattern.h: (TypeCheckPattern::visit): Add AltPattern visitor. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Cleanup and AssertionParthib1-16/+6
gcc/rust/ChangLog: * rust-object-export.cc: Modified * hir/rust-ast-lower-type.cc (rust_fatal_error): Removed (rust_assert): Added Signed-off-by: Parthib <parthibdutta02@gmail.com>
2024-01-16gccrs: Fix missing move and copy constructors missing the associated-pathPhilip Herron2-8/+8
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: added support for printing HIR dump of functions, statements, ↵Abdul Rafey1-56/+215
arithematic/logical expressions and literals. gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::go): support inner attrs, crate items and node mappings (Dump::visit): support functions, arith/logical exprs, let stmts and literals Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
2024-01-16gccrs: hir: Refactor ASTLoweringStmt to source file.Arthur Cohen2-368/+413
gcc/rust/ChangeLog: * Make-lang.in: Add rust-ast-lower-stmt.o * hir/rust-ast-lower-stmt.h: Move definitions to... * hir/rust-ast-lower-stmt.cc: ...here.
2024-01-16gccrs: Fix assignment operator overloads for AST and HIR patternsOwen Avery1-0/+8
gcc/rust/ChangeLog: * ast/rust-pattern.h (StructPatternElements::operator=): Clear vector before inserting. (TupleStructItemsNoRange::operator=): Clear vector before inserting. (TupleStructItemsRange::operator=): Clear vectors before inserting. (TuplePatternItemsMultiple::operator=): Clear vector before inserting. (TuplePatternItemsRanged::operator=): Clear vectors before inserting. (SlicePattern::operator=): Clear vector before inserting. (AltPattern::operator=): Clear vector before inserting. * hir/tree/rust-hir-pattern.h (StructPatternElements::operator=): Clear vector before inserting. (TupleStructItemsNoRange::operator=): Clear vector before inserting. (TupleStructItemsRange::operator=): Clear vectors before inserting. (TuplePatternItemsMultiple::operator=): Clear vector before inserting. (TuplePatternItemsRanged::operator=): Clear vectors before inserting. (SlicePattern::operator=): Clear vector before inserting. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Change struct StructPatternElements into classOwen Avery1-2/+1
gcc/rust/ChangeLog: * ast/rust-pattern.h (struct StructPatternElements): Change to class. (class StructPatternElements): Change from struct. * hir/tree/rust-hir-pattern.h (struct StructPatternElements): Change to class. (class StructPatternElements): Change from struct. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: Fix formattingOwen Avery1-32/+30
gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (class TupleStructItemsNoRange): Fix formatting. (class TupleStructItemsRange): Fix formatting. (class TuplePatternItemsMultiple): Fix formatting. (class TuplePatternItemsRanged): Fix formatting. (class SlicePattern): Fix formatting. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: ast: Add RestPattern AST nodePierre-Emmanuel Patry2-0/+4
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 Cohen2-0/+4
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 Jelinek31-31/+31
2023-04-06gccrs: rename rust-hir-full-tests.ccSainiAditya11-0/+0
gcc/rust/Changelog: * hir/tree/rust-hir-full-test.cc: Moved to... * hir/tree/rust-hir.cc: ...here. * Make-lang.in: Rename rust-hir-full-test. Signed-off-by: SainiAditya1 <Adityasaini10012001@outlook.com>