diff options
author | John Hodge <tpg@mutabah.net> | 2016-06-08 15:59:40 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-06-08 15:59:40 +0800 |
commit | 0c50c6f50831bc79c12aed4e3a83ab8919661d34 (patch) | |
tree | af813b9d2ad926cba7bd0958f5eed6e3a5d9230f /src | |
parent | f2e025e7e7cc1e00407c2ad9a28afe6e318bdbdc (diff) | |
download | mrust-0c50c6f50831bc79c12aed4e3a83ab8919661d34.tar.gz |
HIR Typecheck - Starting work on Fn* traits
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/hir.cpp | 4 | ||||
-rw-r--r-- | src/hir_typeck/expr.cpp | 28 | ||||
-rw-r--r-- | src/include/debug.hpp | 3 | ||||
-rw-r--r-- | src/include/tagged_union.hpp | 1 |
4 files changed, 33 insertions, 3 deletions
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index 81a4d488..dc0aca0a 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -169,6 +169,10 @@ const ::HIR::SimplePath& ::HIR::Crate::get_lang_item_path(const Span& sp, const static ::HIR::SimplePath lang_path { "", {"cmp", "PartialEq"} }; return lang_path; } + else if( ::std::strcmp(name, "fn_once") == 0 ) { + static ::HIR::SimplePath lang_path { "", {"ops", "FnOnce"} }; + return lang_path; + } else { ERROR(sp, E0000, "Unknown language item '" << name << "' encountered"); } diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp index 0439cb57..cdc1741c 100644 --- a/src/hir_typeck/expr.cpp +++ b/src/hir_typeck/expr.cpp @@ -1281,11 +1281,18 @@ namespace { for(const auto& b : p->m_bounds) { TU_IFLET(::HIR::GenericBound, b, TraitBound, e, - if( e.type == type && e.trait.m_path.m_path == trait ) { + if( e.type != type ) + continue ; + if( e.trait.m_path.m_path == trait ) { if( callback(e.trait.m_path.m_params) ) { return true; } } + for( const auto& pt : e.trait.m_trait_ptr->m_parent_traits ) { + if( pt.m_path == trait ) { + TODO(Span(), "Fix arguments for a parent trait and call callback - " << pt << " with paramset " << e.trait.m_trait_ptr->m_params.fmt_args()); + } + } ) } } @@ -2498,6 +2505,25 @@ namespace { // - Call Value: If type is known, locate impl of Fn/FnMut/FnOnce void visit(::HIR::ExprNode_CallValue& node) override { + const auto& ty = this->context.get_type(node.m_value->m_res_type); + DEBUG("(CallValue) ty = " << ty); + + TU_MATCH_DEF(decltype(ty.m_data), (ty.m_data), (e), + ( + // Locate impl of FnOnce + this->context.find_trait_impls(this->context.m_crate.get_lang_item_path(node.span(), "fn_once"), ty, [&](const auto& args) { + DEBUG("TODO: Handle FnOnce for type, FnOnce" << args); + return false; + }); + TODO(node.span(), "CallValue with other type - " << ty); + ), + (Function, + TODO(node.span(), "CallValue with Function - " << ty); + ), + (Infer, + ) + ) + ::HIR::ExprVisitorDef::visit(node); } // - Call Method: Locate method on type diff --git a/src/include/debug.hpp b/src/include/debug.hpp index 2b3b1bee..8aace983 100644 --- a/src/include/debug.hpp +++ b/src/include/debug.hpp @@ -67,10 +67,9 @@ public: } ~TraceLog() { UNINDENT(); - DEBUG("<< " << m_tag); if(debug_enabled()) { auto& os = debug_output(g_debug_indent_level, __FUNCTION__); - os << "<<" << m_tag; + os << " << " << m_tag; m_ret(os); os << ::std::endl; } diff --git a/src/include/tagged_union.hpp b/src/include/tagged_union.hpp index fcf924c8..9762937e 100644 --- a/src/include/tagged_union.hpp +++ b/src/include/tagged_union.hpp @@ -96,6 +96,7 @@ #define MAXS13(a1,a2,a3,a4,a5,a6,a7, b1,b2,b3,b4,b5,b6) MAX2(MAXS7(a1,a2,a3,a4,a5,a6,a7), MAXS6(b1,b2,b3,b4,b5,b6)) #define MAXS14(a1,a2,a3,a4,a5,a6,a7, b1,b2,b3,b4,b5,b6,b7) MAX2(MAXS7(a1,a2,a3,a4,a5,a6,a7), MAXS7(b1,b2,b3,b4,b5,b6,b7)) +// TODO: use `decltype` in place of the `class` argument to TU_MATCH/TU_IFLET // "match"-like statement // TU_MATCH(Class, m_data, ent, (Variant, CODE), (Variant2, CODE)) #define TU_MATCH(CLASS, VAR, NAME, ...) switch( (TU_FIRST VAR).tag()) {/* |