aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse.h
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-06-15 12:25:33 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2022-06-15 18:16:39 +0200
commit0dbfdb5cfc5cf64de086a85aadc1e58b115fb7f6 (patch)
tree7e6233b81959b0908909c956b047bbf0c748fc89 /gcc/rust/parse/rust-parse.h
parent08e407e977e78bfebb2faa71be377c58369b8b0d (diff)
downloadgcc-0dbfdb5cfc5cf64de086a85aadc1e58b115fb7f6.zip
gcc-0dbfdb5cfc5cf64de086a85aadc1e58b115fb7f6.tar.gz
gcc-0dbfdb5cfc5cf64de086a85aadc1e58b115fb7f6.tar.bz2
parser: Add base for parsing const generic application
1. Refactor const generic declaration The default value for const generics now benefits from using the same function as parsing a regular const generic expression 2. `Parser::parse_type` should not always add errors In the case that we are parsing a const generic and not a type, we should not emit bogus errors from `parse_type` such as "unexpected token in type: LITERAL". Thus, we add a flag to the function to not always add errors to the error table 3. Figure out how to deal with ambiguities In the following cases, parsing is ambiguous: ```rust let a: Foo<N>; ``` What is N? Is it a type to be used as a generic argument? Is it a const value to be used for a const generic argument? We need to keep both possibilities and differentiate later during typechecking. We need to figure out if it would be better to keep the ambiguity in our future `ConstGenericArg` type (something like Kind::ConstVarOrType) or modify our current `AST::Type` to maybe get differentiated later as a const variable, which seems more annoying. Finally, since the const evaluation is not implemented yet, we are getting some bogus errors in the testcase. This commit simply serves as a necessary base: parsing const generics before we can apply them.
Diffstat (limited to 'gcc/rust/parse/rust-parse.h')
-rw-r--r--gcc/rust/parse/rust-parse.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index d19bc71..f0aedfe 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -138,7 +138,7 @@ public:
*/
std::unique_ptr<AST::Stmt> parse_stmt (ParseRestrictions restrictions
= ParseRestrictions ());
- std::unique_ptr<AST::Type> parse_type ();
+ std::unique_ptr<AST::Type> parse_type (bool save_errors = true);
std::unique_ptr<AST::ExternalItem> parse_external_item ();
std::unique_ptr<AST::TraitItem> parse_trait_item ();
std::unique_ptr<AST::InherentImplItem> parse_inherent_impl_item ();
@@ -177,6 +177,7 @@ private:
AST::TypePath parse_type_path ();
std::unique_ptr<AST::TypePathSegment> parse_type_path_segment ();
AST::PathIdentSegment parse_path_ident_segment ();
+ std::unique_ptr<AST::Expr> parse_const_generic_expression ();
AST::GenericArgs parse_path_generic_args ();
AST::GenericArgsBinding parse_generic_args_binding ();
AST::TypePathFunction parse_type_path_function (Location locus);