aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
AgeCommit message (Collapse)AuthorFilesLines
2024-01-16gccrs: ast: Fix macros in tokenstreamsPierre-Emmanuel Patry1-1/+4
A default token was used as a separator, wich resulted in a wrong token stream. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Remove default separator. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Visit crate inner attributes for tokenstreamsPierre-Emmanuel Patry1-0/+1
Crate level inner attributes were not visited. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Visit inner attributes.
2024-01-16gccrs: ast: Change visibility in token typePierre-Emmanuel Patry1-1/+1
Change the token type from a custom identifier to the reserved token keyword "in". gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Change token type. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Fix attribute tokenstreamsPierre-Emmanuel Patry1-12/+4
Attributes were not converted to a correct tokenstream, furthermore meta items containers and token trees attribute arguments were not even implemented. This commit fix the literal attribute type and implement both unimplemented types. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix existing and implement remaining attribute visitors. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Output union's outer attributesPierre-Emmanuel Patry1-0/+1
Output a union's outer attributes in a tokenstream. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor to the union's outer attributes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Output inner attributes in tokenstreamsPierre-Emmanuel Patry1-0/+1
Inner attributes were not correctly visited. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Add call to inner attribute visitor. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Fix char literal ICEPierre-Emmanuel Patry1-2/+4
The code was attempting to convert a char to an integer by parsing it instead of taking it's raw value. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix ICE. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Fix match case comma outputPierre-Emmanuel Patry1-1/+1
Even though the comma may be optional with blocks of expressions, it is mandatory for a single expression alone. By changing this behavior we ensure a working behavior with any kind of expressions. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Make comma mandatory. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Fix tokenstream extern block statementsPierre-Emmanuel Patry2-3/+2
The visitor created some additional semicolon between statements in extern blocks, this lead to empty statement. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Remove additional semicolon output. * ast/rust-ast-tokenstream.h: Change block visitor prototype with a default value for trailing tokens. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Move pattern implementation out of rust-astPierre-Emmanuel Patry5-530/+634
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 Patry2-326/+360
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: Fix various TokenStream visitorsPierre-Emmanuel Patry1-24/+74
TokenStream visitors still have many issues, this commit fixes some of them. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit_items_as_lines): Handle trailing chars. (TokenStream::visit_items_as_block): Likewise. (TokenStream::visit): Fix visitor. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add missing constructor implementationPierre-Emmanuel Patry1-0/+3
Add a missing constructor implementation for TokenStream objects. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::TokenStream): Add constructor. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add TokenStream collect functionPierre-Emmanuel Patry2-4/+13
Add a function to TokenStream to collect in a single vector all tokens. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::collect_tokens): Add getter. (TokenStream::go): Rename function. (TokenStream::visit): Likewise. * ast/rust-ast-tokenstream.h: Add collect prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Refactor SimplePath attribute namePierre-Emmanuel Patry3-7/+7
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: ast: Add multiple formatting stub functionsPierre-Emmanuel Patry2-6/+95
Add multiple stub functions depending on the context. This will allow an easier unification of ast dump. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit_as_line): Add formatting calls. (TokenStream::visit_items_as_block): Likewise. (TokenStream::newline): Add stub. (TokenStream::indentation): Add stub. (TokenStream::increment_indentation): Add stub. (TokenStream::decrement_indentation): Add stub. (TokenStream::visit): Add formatting calls. (TokenStream::visit_function_common): Likewise. * ast/rust-ast-tokenstream.h: Add stub prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add AltPattern TokenStream visitorPierre-Emmanuel Patry1-2/+4
Add TokenStream visitor implementation for AltPattern. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add Meta items TokenStream visitorPierre-Emmanuel Patry4-16/+92
Add visitor implementation for all remaining meta items. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor implementation. * ast/rust-ast-tokenstream.h: Add additional function prototype. * ast/rust-item.h: Add some getters. * ast/rust-macro.h: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add use declarations TokenStream visitorsPierre-Emmanuel Patry2-8/+80
Add UseDeclaration (and it's childrens) visitor implementation. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor. * ast/rust-item.h: Add missing getters. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add ExternCrate TokenStream visitorPierre-Emmanuel Patry1-2/+16
Add a visitor implementation for ExternCrate declarations. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Implement remaining expr TokenStream visitorPierre-Emmanuel Patry3-34/+162
Implement the missing expression functions visitors for TokenStream. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitors. (TokenStream::visit_closure_common): Merge common code for closure visitors. * ast/rust-ast-tokenstream.h: Add function prototype. * ast/rust-expr.h: Add missing move attribute getter. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add Tokenstream visitors for loop expressionsPierre-Emmanuel Patry2-12/+64
Add the implementation of tokenstream dump for multiple loop expressions. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitors. (TokenStream::visit_loop_common): Merge common loop code. * ast/rust-ast-tokenstream.h: Add function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add some expr TokenStream visitorsPierre-Emmanuel Patry2-15/+73
Implement some TokenStream expression visitor functions. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Implement visitor. * ast/rust-ast-tokenstream.h: Add function prototype for missing component. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add trailing comma formatting optionPierre-Emmanuel Patry2-0/+11
Add an option to output trailing commas depending on the configuration of the TokenStream. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::trailing_comma): Output a trailing comma to the token stream according to the configuration. * ast/rust-ast-tokenstream.h: Add function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Implement TokenStream visitor for meta nodesPierre-Emmanuel Patry1-7/+24
Implement TokenStream visitor on some Meta container nodes. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Implement visitors. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Refactor and add some Path node visitorsPierre-Emmanuel Patry4-124/+131
Implement some functions for Path nodes and refactor existing ones by merging some common code. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Implement visitors. * ast/rust-ast-tokenstream.h: Add function prototypes. * ast/rust-ast.h: Add missing getters. * ast/rust-expr.h: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: ast: Add conversion to token streamPierre-Emmanuel Patry4-0/+2709
Add several functions to convert an ast back to a token stream. This may be used later either to unify the ast dumping and modifications on ast nodes in procedural macros. gcc/rust/ChangeLog: * Make-lang.in: Add rust-as-tokenstream to compile list. * ast/rust-item.h: Add missing getter for location. * ast/rust-ast-tokenstream.cc: Add ast visitor implementation. * ast/rust-ast-tokenstream.h: New file. * ast/rust-pattern.h: Add getter. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: privacy: Check for pub(crate) when resolving visibility path.Arthur Cohen1-1/+1
This causes the function to return true and the checks to pass, but it requires more thinking - how do we deal with pub(crate) in the current system? Should we simply treat it as a pub item in the current crate, but export it as a private item in the metadata? gcc/rust/ChangeLog: * ast/rust-item.h: Fix `Visibility::has_path()` implementation. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_module_path): Check if we are dealing with pub(crate) properly. gcc/testsuite/ChangeLog: * rust/compile/privacy8.rs: New test.
2024-01-16gccrs: ast: Fix location for pub(crate)Arthur Cohen1-1/+1
When creating a SimplePath from a string, we end up creating a path which contains only one segment but no location. Take the location of the one segment instead and use it as the simple path's location. gcc/rust/ChangeLog: * ast/rust-ast.h: Call SimplePath constructor differently in SimplePath::from_str
2024-01-16gccrs: Remove commented out TuplePatternItemsSingleOwen Avery1-35/+0
gcc/rust/ChangeLog: * ast/rust-pattern.h: Remove commented out code. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: ast: Dump each MacroRule properly without the extra semicolonArthur Cohen1-1/+0
Having the extra semicolon causes parsing errors when importing macros exported using the AST dump, as no rule expects multiple tokens after a single macro rule definition. gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Remove extraneous semicolon when dumping macro rules.
2024-01-16gccrs: support use declaration to write the type into the correct namespacePhilip Herron1-0/+5
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: Convert structs to classesOwen Avery2-27/+18
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: Unify indentation approach with astJakub Dupak2-36/+1
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: fix some clang warningsMarc Poulhiès3-7/+7
This fixes some extra warnings reported by clang. gcc/rust/ChangeLog: PR rust/108111 * ast/rust-ast-full-decls.h (StructPatternElements): Declare as a class. * ast/rust-item.h (EnumItem): Mark several method as being overrides. * ast/rust-pattern.h (StructPattern::get_locus): Add override. * lex/rust-lex.h (BufferInputSource): Use reference_wrapper instead of bare reference. (TokenSource::get): Add method to implement the reference_wrapper interface. * typecheck/rust-tyty.h (TypeBoundPredicate): Add empty dtor. * util/rust-buffered-queue.h (peek): Source token stream is now using a reference_wrapper, use .get() Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2024-01-16gccrs: expand: Add stringify macroPierre-Emmanuel Patry2-0/+4
Add the stringify macro expansion as well as some tests. gcc/rust/ChangeLog: * ast/rust-macro.cc (builtin_macro_from_string): Add identifier identification. * ast/rust-macro.h (enum class): Add Stringify builtin macro type. * expand/rust-macro-builtins.cc (make_macro_path_str): Add path for builtin stringify macro. (MacroBuiltin::stringify_handler): Add handler for builtin stringify macro. * expand/rust-macro-builtins.h: Add stringify handler's prototype. * util/rust-hir-map.cc (Mappings::insert_macro_def): Add stringify handler to builtin hir map. gcc/testsuite/ChangeLog: * rust/compile/stringify.rs: Add a basic test with some text. * rust/execute/torture/builtin_macro_stringify.rs: Verify the text is left as is without any other macro expansion. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Add missing node_id copys in the copy constructorsPhilip Herron1-0/+2
Signed-off-by: Philip Herron <herron.philip@googlemail.com> gcc/rust/ChangeLog: * ast/rust-path.h: add missing copy for node_id
2024-01-16gccrs: Fix missing move and copy constructors missing the associated-pathPhilip Herron2-9/+64
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 NodeId and clone to RestPatternPierre-Emmanuel Patry1-1/+12
The RestPattern AST node did not have any NodeId to identify it and could therefore not be instanciated. gcc/rust/ChangeLog: * ast/rust-pattern.h (class RestPattern): Add NodeId as well as the clone_impl function. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Fix assignment operator overloads for AST and HIR patternsOwen Avery1-0/+9
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: ast: Add RestPattern AST nodePierre-Emmanuel Patry6-0/+27
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: parser: Parse `default` impl Functions and MethodsArthur Cohen1-6/+16
gcc/rust/ChangeLog: * ast/rust-item.h (class Method): Add `is_default` field. (class Function): Likewise. * parse/rust-parse-impl.h (Parser::parse_item): Add nice error when parsing `default` outside of an `impl` block (Parser::parse_trait_impl_item): Allow parsing functions or methods when seeing `default`. gcc/testsuite/ChangeLog: * rust/compile/parse_invalid_specialization.rs: New test. * rust/compile/parse_specialization.rs: New test. * rust/compile/default_not_a_kw.rs: New test.
2024-01-16gccrs: ast: Add proper visitors for ExternalTypeItemArthur Cohen2-1/+6
gcc/rust/ChangeLog: * ast/rust-item.h: Add non-const `get_visibility` to ExternalTypeItem. * ast/rust-ast-dump.cc (Dump::visit): Add implementation for ExternalTypeItem. * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Likewise.
2024-01-16gccrs: ast: Add ExternalTypeItem nodeArthur Cohen6-0/+98
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-16gccrs: parser: Add parsing of auto traitsArthur Cohen1-5/+8
This adds enough handling to start parsing `auto` traits but not handle them in the AST, lowering phase or HIR yet. The feature is named `optin_builtin_traits` in Rust 1.49 but changes to `auto_traits` later down the line. So we'll need to take care of this later on. Finally, this also changes the way the lexer detects if a string is a keyword or not. We relied on a call to `std::lower_bound` to figure out if a string was contained in an array or not, and this ended up causing issues when adding new keywords. We can instead switch to a simple hashmap and search for the key. The code *might* be less optimized (unsure) but it is definitely simpler and easier to read. Fixes #1814 gcc/rust/ChangeLog: * ast/rust-item.h (class Trait): Add `has_auto` field. * checks/errors/rust-feature.cc: Add handling for `feature(optin_builtin_traits)` * checks/errors/rust-feature.h: Likewise. * lex/rust-lex.cc: Fix keyword classification using hashmap. * lex/rust-token.h: Add `auto` keyword token. * parse/rust-parse-impl.h (Parser::parse_vis_item): Parse auto traits on `auto` keyword. gcc/testsuite/ChangeLog: * rust/compile/auto_trait_invalid.rs: New test. * rust/compile/auto_trait_valid.rs: New test.
2024-01-03Update copyright years.Jakub Jelinek17-17/+17
2023-04-06gccrs: Added AST Node AST::InlineAsmM V V S Manoj Kumar2-0/+139
Addresses #1567 Created a AST node InlineAsm similar to the one found in rustc. As there is no Symbol struct/class in gccrs I have made every instance of Symbol a string. gcc/rust/ChangeLog: * ast/rust-ast-full-decls.h (class InlineAsm):Added class declaration. * ast/rust-expr.h (class InlineAsm):Added class definition. Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
2023-04-06gccrs: diagnostic: Refactor Error classArthur Cohen1-1/+1
The class now allows for more variants including a `Hint` one which then gets emitted by calling `rust_inform`. This allows us to display hints/tips/notes in backtracking contexts such as the parser. gcc/rust/ChangeLog: * rust-diagnostics.h (struct Error): Add new Kind enum and various new static constructors to allow for hints as well. * rust-diagnostics.cc (Error::Error): Use new `kind` field properly. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_module_path): Use new Error API. * expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Likewise. * expand/rust-macro-expand.cc (parse_many): Likewise. (transcribe_type): Likewise. * parse/rust-parse-impl.h (Parser::parse_crate): Likewise. * rust-session-manager.cc (Session::handle_crate_name): Likewise. * ast/rust-ast.cc (Module::load_items): Likewise.
2023-04-06gccrs: ast: Refactor TraitItem to keep Location infoArthur Cohen3-34/+26
gcc/rust/ChangeLog: * ast/rust-ast.h: Keep location in TraitItem base class * ast/rust-item.h (class TraitItemFunc): Use base class location instead. (class TraitItemMethod): Likewise. (class TraitItemConst): Likewise. (class TraitItemType): Likewise. * ast/rust-macro.h: Likewise.