diff options
author | John Hodge <tpg@mutabah.net> | 2018-05-27 11:33:04 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-05-27 11:33:04 +0800 |
commit | af1ec8a893d33aa974186d06498d0fc81d22ae7b (patch) | |
tree | 294ad6c81512df1901af85df5e563db2a98c33c7 /src | |
parent | 84392bea7f6f0754f61d5b424129eb5fa809674d (diff) | |
download | mrust-af1ec8a893d33aa974186d06498d0fc81d22ae7b.tar.gz |
AST - Include HRBs on fn() types, fix minor parsing bug
Diffstat (limited to 'src')
-rw-r--r-- | src/ast/types.hpp | 8 | ||||
-rw-r--r-- | src/parse/root.cpp | 4 | ||||
-rw-r--r-- | src/parse/types.cpp | 8 | ||||
-rw-r--r-- | src/resolve/absolute.cpp | 2 |
4 files changed, 15 insertions, 7 deletions
diff --git a/src/ast/types.hpp b/src/ast/types.hpp index 1c06593c..22465593 100644 --- a/src/ast/types.hpp +++ b/src/ast/types.hpp @@ -96,6 +96,7 @@ struct TypeArgRef struct Type_Function { + AST::HigherRankedBounds hrbs; bool is_unsafe; ::std::string m_abi; ::std::unique_ptr<TypeRef> m_rettype; @@ -103,7 +104,8 @@ struct Type_Function bool is_variadic; Type_Function() {} - Type_Function(bool is_unsafe, ::std::string abi, ::std::unique_ptr<TypeRef> ret, ::std::vector<TypeRef> args, bool is_variadic): + Type_Function(AST::HigherRankedBounds hrbs, bool is_unsafe, ::std::string abi, ::std::unique_ptr<TypeRef> ret, ::std::vector<TypeRef> args, bool is_variadic): + hrbs(mv$(hrbs)), is_unsafe(is_unsafe), m_abi(mv$(abi)), m_rettype(mv$(ret)), @@ -239,9 +241,9 @@ public: m_data(TypeData::make_Tuple({::std::move(inner_types)})) {} struct TagFunction {}; - TypeRef(TagFunction, Span sp, bool is_unsafe, ::std::string abi, ::std::vector<TypeRef> args, bool is_variadic, TypeRef ret): + TypeRef(TagFunction, Span sp, AST::HigherRankedBounds hrbs, bool is_unsafe, ::std::string abi, ::std::vector<TypeRef> args, bool is_variadic, TypeRef ret): m_span(mv$(sp)), - m_data(TypeData::make_Function({ Type_Function( is_unsafe, abi, box$(ret), mv$(args), is_variadic ) })) + m_data(TypeData::make_Function({ Type_Function( mv$(hrbs), is_unsafe, abi, box$(ret), mv$(args), is_variadic ) })) {} struct TagReference {}; diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 0fcbe63a..0a8d2909 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -183,9 +183,11 @@ void Parse_TypeBound(TokenStream& lex, AST::GenericParams& ret, TypeRef checked_ else { PUTBACK(tok, lex); } + auto trait_path = Parse_Path(lex, PATH_GENERIC_TYPE); + auto this_outer_hrbs = (lex.lookahead(0) == TOK_PLUS ? AST::HigherRankedBounds(outer_hrbs) : mv$(outer_hrbs)); ret.add_bound( AST::GenericBound::make_IsTrait({ - mv$(outer_hrbs), checked_type.clone(), mv$(inner_hrls), Parse_Path(lex, PATH_GENERIC_TYPE) + mv$(this_outer_hrbs), checked_type.clone(), mv$(inner_hrls), mv$(trait_path) }) ); } } while( GET_TOK(tok, lex) == TOK_PLUS ); diff --git a/src/parse/types.cpp b/src/parse/types.cpp index 53c79d3b..a07e66f8 100644 --- a/src/parse/types.cpp +++ b/src/parse/types.cpp @@ -71,7 +71,6 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) case TOK_RWORD_UNSAFE: case TOK_RWORD_EXTERN: case TOK_RWORD_FN: - // TODO: Handle HRLS in fn types return Parse_Type_Fn(lex, hrls); default: return Parse_Type_Path(lex, hrls, true); @@ -197,7 +196,6 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) TypeRef Parse_Type_Fn(TokenStream& lex, ::AST::HigherRankedBounds hrbs) { auto ps = lex.start_span(); - // TODO: HRLs TRACE_FUNCTION; Token tok; @@ -206,11 +204,13 @@ TypeRef Parse_Type_Fn(TokenStream& lex, ::AST::HigherRankedBounds hrbs) GET_TOK(tok, lex); + // `unsafe` if( tok.type() == TOK_RWORD_UNSAFE ) { is_unsafe = true; GET_TOK(tok, lex); } + // `exern` if( tok.type() == TOK_RWORD_EXTERN ) { if( GET_TOK(tok, lex) == TOK_STRING ) { @@ -223,6 +223,7 @@ TypeRef Parse_Type_Fn(TokenStream& lex, ::AST::HigherRankedBounds hrbs) abi = "C"; } } + // `fn` CHECK_TOK(tok, TOK_RWORD_FN); ::std::vector<TypeRef> args; @@ -248,6 +249,7 @@ TypeRef Parse_Type_Fn(TokenStream& lex, ::AST::HigherRankedBounds hrbs) } GET_CHECK_TOK(tok, lex, TOK_PAREN_CLOSE); + // `-> RetType` TypeRef ret_type = TypeRef(TypeRef::TagUnit(), Span(tok.get_pos())); if( GET_TOK(tok, lex) == TOK_THINARROW ) { @@ -257,7 +259,7 @@ TypeRef Parse_Type_Fn(TokenStream& lex, ::AST::HigherRankedBounds hrbs) PUTBACK(tok, lex); } - return TypeRef(TypeRef::TagFunction(), lex.end_span(ps), is_unsafe, mv$(abi), mv$(args), is_variadic, mv$(ret_type)); + return TypeRef(TypeRef::TagFunction(), lex.end_span(ps), mv$(hrbs), is_unsafe, mv$(abi), mv$(args), is_variadic, mv$(ret_type)); } TypeRef Parse_Type_Path(TokenStream& lex, ::AST::HigherRankedBounds hrbs, bool allow_trait_list) diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index ceb0e40a..f114fd78 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -1512,10 +1512,12 @@ void Resolve_Absolute_Type(Context& context, TypeRef& type) (Primitive, ), (Function, + context.push( e.info.hrbs ); Resolve_Absolute_Type(context, *e.info.m_rettype); for(auto& t : e.info.m_arg_types) { Resolve_Absolute_Type(context, t); } + context.pop( e.info.hrbs ); ), (Tuple, for(auto& t : e.inner_types) |