aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2023-11-21Add await keywordPierre-Emmanuel Patry1-0/+1
The 2018 edition await keyword was missing from the keyword list. gcc/rust/ChangeLog: * lex/rust-token.h (enum PrimitiveCoreType): Add await keyword definition. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Treat underscore as a keywordPierre-Emmanuel Patry1-2/+1
Make the underscore token a 2015 keyword. gcc/rust/ChangeLog: * lex/rust-token.h (enum PrimitiveCoreType): Change macro for underscore in token list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Add edition separation for keywordsPierre-Emmanuel Patry4-68/+82
It might be required in the future to get only the keywords from a specific edition. To do so we need a mean to differentiate keywords based on their edition. This commit changes the existing keyword macro to allow such behavior. gcc/rust/ChangeLog: * lex/rust-token.h (enum PrimitiveCoreType): Change enum macro calls. (RS_TOKEN_KEYWORD): Remove generic token keyword macro. (RS_TOKEN_KEYWORD_2015): Introduce keywords for edition 2015. (RS_TOKEN_KEYWORD_2018): Likewise with edition 2018. * lex/rust-token.cc (RS_TOKEN_KEYWORD): Remove old macro definition. (RS_TOKEN_KEYWORD_2015): Replace with 2015 definition... (RS_TOKEN_KEYWORD_2018): ... and 2018 definition. * util/rust-keyword-values.cc (RS_TOKEN_KEYWORD): Likewise. (RS_TOKEN_KEYWORD_2015): Likewise. (RS_TOKEN_KEYWORD_2018): Likewise. * util/rust-keyword-values.h (RS_TOKEN_KEYWORD): Likewise. (RS_TOKEN_KEYWORD_2015): Likewise. (RS_TOKEN_KEYWORD_2018): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Replace TOK suffix with KWPierre-Emmanuel Patry6-111/+111
TOK suffix was chosen to disambiguate some identifiers with c++ reserved keyword. Even though this list lies within the rust-token header, this macro is used in many context sometimes unrelated with the lexer and tokens. This TOK suffix may appear surprising in such context. gcc/rust/ChangeLog: * lex/rust-token.h (enum PrimitiveCoreType): Change keyword suffix from tok to kw. * ast/rust-ast-collector.cc (TokenCollector::visit): Update suffix to match the new declaration. * lex/rust-lex.cc (Lexer::parse_raw_identifier): Likewise. * parse/rust-parse-impl.h (can_tok_start_type): Likewise. (Parser::parse_item): Likewise. (Parser::parse_vis_item): Likewise. (Parser::parse_extern_crate): Likewise. (Parser::parse_function): Likewise. (Parser::parse_function_qualifiers): Likewise. (Parser::parse_struct): Likewise. (Parser::parse_enum): Likewise. (Parser::parse_static_item): Likewise. (Parser::parse_trait_item): Likewise. (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_trait_impl_item): Likewise. (Parser::parse_extern_block): Likewise. (Parser::parse_external_item): Likewise. (Parser::parse_stmt): Likewise. (Parser::parse_return_expr): Likewise. (Parser::parse_match_expr): Likewise. (Parser::parse_type): Likewise. (Parser::parse_for_prefixed_type): Likewise. (Parser::parse_type_no_bounds): Likewise. (Parser::parse_stmt_or_expr): Likewise. * parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewie. * util/rust-token-converter.cc (convert): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Add ast validation check on union variant numberPierre-Emmanuel Patry4-1/+20
Unions with zero fields are forbidden. Add regression test for empty unions. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add zero field check during ast validation pass. * checks/errors/rust-ast-validation.h: Add union visit function prototype. gcc/testsuite/ChangeLog: * rust/compile/const_generics_8.rs: Fill the union with dummy values. * rust/compile/empty_union.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Add a test regular variadic functions errorsPierre-Emmanuel Patry1-0/+4
Add a new regression test for the error message in regular function variadic errors during ast validation pass. gcc/testsuite/ChangeLog: * rust/compile/non_foreign_variadic_function.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Emit an error on variadic non extern functionsPierre-Emmanuel Patry1-0/+5
Variadic regular functions were recently added in the parser as they should be rejected in the ast validation pass. This commit add the ast validation pass rejecting this kind of variadic arguments. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add ast validation pass to reject variadic arguments on regular functions. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Add check for associated items on auto traitsPierre-Emmanuel Patry3-14/+10
Reject rust code with associated items on auto traits. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add auto trait associated item check in AST validation pass. * parse/rust-parse-impl.h: Remove old error emission done during parsing pass. gcc/testsuite/ChangeLog: * rust/compile/auto_trait_invalid.rs: Update old test with updated error message. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Add a regression test for super trait on auto traitPierre-Emmanuel Patry1-0/+4
Add a new regression test to highlight the error behavior with a super trait on an auto trait. gcc/testsuite/ChangeLog: * rust/compile/auto_trait_super_trait.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Reject auto traits with super traitPierre-Emmanuel Patry1-0/+4
Reject auto traits containing a super trait bound during AST validation pass. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Reject auto traits with super traits. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Add regression test for generic auto traitsPierre-Emmanuel Patry1-0/+2
Generics are forbidden on auto traits and an error should be emitted. This commit highlight this behavior. gcc/testsuite/ChangeLog: * rust/compile/generic_auto_trait.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Reject auto traits with generic parametersPierre-Emmanuel Patry2-0/+15
Generic parameters are not allowed on auto traits, the compiler should emit an error. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add check for generics on auto traits. * checks/errors/rust-ast-validation.h: Add visit function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21fixup: Ensure buffer allocation for bootstrapPierre-Emmanuel Patry1-1/+2
Bootstrap was failing because the vector did not allocate the internal buffer and was holding a null pointer. Commit to fixup is b71fd2afa831 gcc/rust/ChangeLog: * expand/rust-proc-macro.cc (generate_proc_macro_decls_symbol): Resize the vector and initialize it with dummy data before changing it. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21forever stack: Remove development debug infoArthur Cohen1-2/+0
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Remove debug log.
2023-11-21resolve: Format if properlyArthur Cohen1-3/+1
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Format.
2023-11-21foreverstack: Add `to_rib` methodArthur Cohen2-1/+21
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: New method. * resolve/rust-forever-stack.hxx: Likewise.
2023-11-21foreverstack: Add `to_canonical_path` methodArthur Cohen2-5/+110
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: New method. * resolve/rust-forever-stack.hxx: Likewise.
2023-11-21forever stack: Improve resolve_path implementationArthur Cohen1-1/+1
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Do not copy segment when dereferencing iterator in `find_starting_point`.
2023-11-21forever stack: Fix resolve_path signatureArthur Cohen3-12/+18
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Fix `ForeverStack::resolve_path` signature. * resolve/rust-forever-stack.hxx: Likewise. * resolve/rust-early-name-resolver-2.0.cc (Early::visit): Use new API. (Early::visit_attributes): Likewise.
2023-11-21foreverstack: Specialize `get` for Namespace::LabelsArthur Cohen1-1/+28
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Add specific behavior for `ForeverStack::get` when dealing with labels.
2023-11-21forever-stack: Fix basic get logicArthur Cohen2-28/+29
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Improve resolve_path API. * resolve/rust-forever-stack.hxx: Likewise and fix implementation.
2023-11-21rib: Add Namespace enumArthur Cohen1-0/+25
gcc/rust/ChangeLog: * resolve/rust-rib.h: Add Namespace enum.
2023-11-21ast: Change *Path nodes APIArthur Cohen6-7/+17
gcc/rust/ChangeLog: * ast/rust-ast.h: Change Path API to be more consistent. * ast/rust-path.h: Likewise. * ast/rust-ast-collector.cc (TokenCollector::visit): Use new API. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise. * resolve/rust-forever-stack.hxx: Likewise.
2023-11-21Add new test for parsing errors on self pointersPierre-Emmanuel Patry3-0/+24
Add new tests to highlight the behavior of errors thrown when meeting a self pointer. gcc/testsuite/ChangeLog: * rust/compile/self_const_ptr.rs: New test. * rust/compile/self_mut_ptr.rs: New test. * rust/compile/self_ptr.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Report self parameter parsing error kindPierre-Emmanuel Patry2-28/+56
Self parameter parsing errors may come from different situations, which should not be handled in the same way. It is now possible to differentiate a missing self parameter from a self pointer or a parsing error. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_function): Early return on unrecoverable errors. (Parser::parse_trait_item): Likewise. (Parser::parse_self_param): Update return type. * parse/rust-parse.h (enum ParseSelfError): Add enumeration to describe different self parameter parsing errors. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Fix error emission for self pointersPierre-Emmanuel Patry1-1/+1
Self pointer checking loop condition was inverted, the latter was therefore never executed. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_self_param): Fix the loop exit condition. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Add a test to highlight public trait type parsingPierre-Emmanuel Patry1-0/+6
This new test highlight the parser's behavior around public trait types. gcc/testsuite/ChangeLog: * rust/compile/trait_pub_type.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-21Add visibility to trait itemPierre-Emmanuel Patry4-126/+140
The compiler shall parse visibility modifiers on trait items and reject those at a later stage (ast validation). gcc/rust/ChangeLog: * ast/rust-item.h (struct Visibility): Move Visibility from here... * ast/rust-ast.h (struct Visibility): ...to here. * parse/rust-parse-impl.h (Parser::parse_trait_item): Parse visibility before giving it back to the item parsing function. (Parser::parse_trait_type): Add visibility modifier. * parse/rust-parse.h (RUST_PARSE_H): Change function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-15Adjust item kind enums for TupleStructItems and TuplePatternItemsOwen Avery4-26/+20
gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (TupleStructItems::ItemType::RANGE): Rename to... (TupleStructItems::ItemType::RANGED): ...here. (TupleStructItems::ItemType::NO_RANGE): Rename to... (TupleStructItems::ItemType::MULTIPLE): ...here. (TuplePatternItems::TuplePatternItemType): Rename to... (TuplePatternItems::ItemType): ...here. : Handle renames. * backend/rust-compile-pattern.cc: Likewise. * typecheck/rust-hir-type-check-pattern.cc: Likewise. * checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-11-15Add a new test for float disambiguationPierre-Emmanuel Patry1-0/+6
This new regression test highlight the behavior fixed for float disambiguation with empty floating point. gcc/testsuite/ChangeLog: * rust/compile/tuple_float_index.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-15Fix float lexing and tuple index disambiguationPierre-Emmanuel Patry2-9/+12
When a float has a floating point but no value after it, a zero was added this lead to errors when trying to disambiguate a float into a tuple index. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_decimal_int_or_float): Remove additional zero after empty floating point. * parse/rust-parse-impl.h (Parser::left_denotation): Handle float with empty floating point. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-15gccrs: v0-mangle closuresRaiki Tamura4-10/+50
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): Fix reference to node. * backend/rust-mangle.cc (struct V0Path): Modified to accept closures. (v0_crate_path): Modified to accept closures. (v0_closure): New function to mangle closures. (v0_path): Modified to accept closures * util/rust-mapping-common.h (UNKNOWN_NODEID): Change to UINT32_MAX. (UNKNOWN_HIRID): Change to UINT32_MAX. gcc/testsuite/ChangeLog: * rust/compile/v0-mangle2.rs: New test. Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
2023-11-15Move default visitor templates to headerPierre-Emmanuel Patry2-16/+5
Move default ast visitor template implementation to headers in order to match the codebase and avoid link errors. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Move from here... * ast/rust-ast-visitor.h: ... to here. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-15Move templated functions to header filePierre-Emmanuel Patry2-76/+46
Templated functions shall remain in header files to stay in line with the rest of the codebase. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Move to header file. (TokenCollector::visit_items_joined_by_separator): Likewise. (TokenCollector::visit_as_line): Likewise. (TokenCollector::visit_items_as_lines): Likewise. (TokenCollector::visit_items_as_block): Likewise. * ast/rust-ast-collector.h: Add implementation. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-15Bump actions/upload-artifact from v2 to v3Owen Avery1-4/+4
ChangeLog: * .github/workflows/ccpp.yml: Bump actions/upload-artifact from v2 to v3. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-11-14Rework function special parametersPierre-Emmanuel Patry34-739/+1089
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>
2023-11-14Add new test for invalid variadicsPierre-Emmanuel Patry1-0/+6
Highlight invalid variadic filtering through the ast validation checker. gcc/testsuite/ChangeLog: * rust/compile/invalid_variadics.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Add multiple check on variadics positionPierre-Emmanuel Patry2-0/+20
Variadics are forbidden alone as well as non final position, this should be checked during ast validation. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add check for additional named argument as well as variadic argument's position. * checks/errors/rust-ast-validation.h: Add visit function prototype for external functions. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Add trait context to ContextualASTVisitorPierre-Emmanuel Patry2-0/+11
Some construct are forbidden in trait context (eg. pub, async...) and we'll need to reject those. To do so we need to identify a trait context. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Push the new trait context when visiting a trait. * ast/rust-ast-visitor.h: Add visit function prototype and TRAIT context. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Add regression test for invalid label namePierre-Emmanuel Patry1-0/+23
An error message should be emitted when the rust code contains invalid label name. Add a new test for this behavior. gcc/testsuite/ChangeLog: * rust/compile/invalid_label_name.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Change error location for LoopLabelPierre-Emmanuel Patry1-1/+1
Loop label error reporting during ast validation was done at loop label level. It lead to some innacurate error reporting in break loop labels due to the way the label is built. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Change reported error location to the lifetime location. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Add validation pass for label namePierre-Emmanuel Patry3-1/+19
Prevent from using reserved keyword in label name. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check if there is a label before visit. * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Emit an error when a label has a forbidden name. * checks/errors/rust-ast-validation.h: Add function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Use a loop label in break expressionPierre-Emmanuel Patry3-6/+7
Break expression were using a raw lifetime value instead of a loop label this behavior would have lead to some errors in ast validation. gcc/rust/ChangeLog: * ast/rust-expr.h (class BreakExpr): Change Lifetime to LoopLabel. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower lifetime inside the label instead. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve the inner lifetime. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Use keyword const values instead of raw valuesPierre-Emmanuel Patry2-5/+12
Change the keyword values from a raw string value to their matching const value in utils. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_raw_identifier): Use const value. * parse/rust-parse-impl.h (Parser::parse_simple_path_segment): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Change keyword set to a mapPierre-Emmanuel Patry3-19/+16
Some part of the code requires the token id behind a given keyword, a map keep the "set" aspect whilst providing this additional feature. gcc/rust/ChangeLog: * lex/rust-lex.cc (RS_TOKEN): Remove local map. (RS_TOKEN_KEYWORD): Likewise. (Lexer::classify_keyword): Change call to utils. * util/rust-keyword-values.cc (get_keywords): Add init function. (RS_TOKEN_KEYWORD): Call to X macro. * util/rust-keyword-values.h: Change from set to a map. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Replace local keyword set with the utilsPierre-Emmanuel Patry1-11/+3
We don't require that local set anymore. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (RS_TOKEN): Remove locale set. (RS_TOKEN_KEYWORD): Likewise. (ASTValidation::visit): Change keyword set call to the one from utils. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Add new keyword utility classPierre-Emmanuel Patry3-0/+79
Much like attributes values, keywords are known beforehand and never change. Instead of relying on handcrafted string we could centralize everything in one place. We may require to check whether a word is a keyword, which can now be done easily thanks to the keyword set. gcc/rust/ChangeLog: * Make-lang.in: Add rust-keyword-values.cc to the list. * util/rust-keyword-values.cc: New file. * util/rust-keyword-values.h: New file. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Add licence text and change header guard namePierre-Emmanuel Patry1-3/+21
This file was missing a licence text and it's header guard was not matching the file name. gcc/rust/ChangeLog: * util/rust-attribute-values.h (RUST_ATTRIBUTES_VALUE_H): Remove old header guard. (RUST_ATTRIBUTE_VALUES_H): Add new one. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Add regression test for lifetime name validationPierre-Emmanuel Patry1-0/+6
Lifetime name are restricted and cannot be keyword, this commit add a test failing the ast validation pass due to some keyword name. gcc/testsuite/ChangeLog: * rust/compile/lifetime_name_validation.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-11-14Add lifetime name validation passPierre-Emmanuel Patry2-0/+24
Add lifetime name check in ast validation visitor. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (RS_TOKEN): Add keyword set. (RS_TOKEN_KEYWORD): Likewise. (ASTValidation::visit): Add validation on lifetime visit. * checks/errors/rust-ast-validation.h: Add function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>