diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-06 08:09:45 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-06 08:09:45 +0800 |
commit | 8c4c592c977833ac41defcf78463b811ae14e1ca (patch) | |
tree | 698ebf9a1a25d949cd376aa54af1b8d1a899999b | |
parent | ed32a6680af7731b647962ee8cbb94cbcc3b9fa1 (diff) | |
download | mrust-8c4c592c977833ac41defcf78463b811ae14e1ca.tar.gz |
Parse - Save unsafety for function pointer types
-rw-r--r-- | src/ast/types.hpp | 10 | ||||
-rw-r--r-- | src/hir/from_ast.cpp | 2 | ||||
-rw-r--r-- | src/hir/type.cpp | 10 | ||||
-rw-r--r-- | src/parse/types.cpp | 8 |
4 files changed, 18 insertions, 12 deletions
diff --git a/src/ast/types.hpp b/src/ast/types.hpp index e35c178f..e0cede23 100644 --- a/src/ast/types.hpp +++ b/src/ast/types.hpp @@ -41,13 +41,15 @@ struct Type_Function ::std::string m_abi;
::std::unique_ptr<TypeRef> m_rettype;
::std::vector<TypeRef> m_arg_types;
+ bool is_variadic;
Type_Function() {}
- Type_Function(bool is_unsafe, ::std::string abi, ::std::unique_ptr<TypeRef> ret, ::std::vector<TypeRef> args):
+ Type_Function(bool is_unsafe, ::std::string abi, ::std::unique_ptr<TypeRef> ret, ::std::vector<TypeRef> args, bool is_variadic):
is_unsafe(is_unsafe),
m_abi(mv$(abi)),
m_rettype(mv$(ret)),
- m_arg_types(mv$(args))
+ m_arg_types(mv$(args)),
+ is_variadic(is_variadic)
{}
Type_Function(Type_Function&& other) = default;
Type_Function(const Type_Function& other);
@@ -166,9 +168,9 @@ public: m_data(TypeData::make_Tuple({::std::move(inner_types)}))
{}
struct TagFunction {};
- TypeRef(TagFunction, Span sp, ::std::string abi, ::std::vector<TypeRef> args, TypeRef ret):
+ TypeRef(TagFunction, Span sp, 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( false, abi, box$(ret), mv$(args) ) }))
+ m_data(TypeData::make_Function({ Type_Function( is_unsafe, abi, box$(ret), mv$(args), is_variadic ) }))
{}
struct TagReference {};
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index 06102fe5..275e5845 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -735,7 +735,7 @@ e.info.is_unsafe, e.info.m_abi, box$( LowerHIR_Type(*e.info.m_rettype) ), - mv$(args) + mv$(args) // TODO: e.info.is_variadic }; if( f.m_abi == "" ) f.m_abi = "rust"; diff --git a/src/hir/type.cpp b/src/hir/type.cpp index c9f3fe85..abad9757 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -776,10 +776,12 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x return ::HIR::TypeRef( Data::make_Pointer({e.type, box$(e.inner->clone())}) ); ), (Function, - FunctionType ft; - ft.is_unsafe = e.is_unsafe; - ft.m_abi = e.m_abi; - ft.m_rettype = box$( e.m_rettype->clone() ); + FunctionType ft { + e.is_unsafe, + e.m_abi, + box$( e.m_rettype->clone() ), + {} + }; for(const auto& a : e.m_arg_types) ft.m_arg_types.push_back( a.clone() ); return ::HIR::TypeRef(Data::make_Function( mv$(ft) )); diff --git a/src/parse/types.cpp b/src/parse/types.cpp index d960d1d3..39bd5b5d 100644 --- a/src/parse/types.cpp +++ b/src/parse/types.cpp @@ -200,12 +200,13 @@ TypeRef Parse_Type_Fn(TokenStream& lex, ::std::vector<::std::string> hrls) Token tok; ::std::string abi = ""; + bool is_unsafe = false; GET_TOK(tok, lex); if( tok.type() == TOK_RWORD_UNSAFE ) { - // TODO: Unsafe functions in types + is_unsafe = true; GET_TOK(tok, lex); } if( tok.type() == TOK_RWORD_EXTERN ) @@ -223,12 +224,13 @@ TypeRef Parse_Type_Fn(TokenStream& lex, ::std::vector<::std::string> hrls) CHECK_TOK(tok, TOK_RWORD_FN); ::std::vector<TypeRef> args; + bool is_variadic = false; GET_CHECK_TOK(tok, lex, TOK_PAREN_OPEN); while( LOOK_AHEAD(lex) != TOK_PAREN_CLOSE ) { if( LOOK_AHEAD(lex) == TOK_TRIPLE_DOT ) { GET_TOK(tok, lex); - // TODO: Mark function as vardic + is_variadic = true; break; } // Handle `ident: ` @@ -253,7 +255,7 @@ TypeRef Parse_Type_Fn(TokenStream& lex, ::std::vector<::std::string> hrls) PUTBACK(tok, lex); } - return TypeRef(TypeRef::TagFunction(), lex.end_span(ps), ::std::move(abi), ::std::move(args), ::std::move(ret_type)); + return TypeRef(TypeRef::TagFunction(), lex.end_span(ps), is_unsafe, mv$(abi), mv$(args), is_variadic, mv$(ret_type)); } TypeRef Parse_Type_Path(TokenStream& lex, ::std::vector<::std::string> hrls, bool allow_trait_list) |