diff options
Diffstat (limited to 'src/hir')
-rw-r--r-- | src/hir/from_ast.cpp | 23 | ||||
-rw-r--r-- | src/hir/generic_params.hpp | 47 | ||||
-rw-r--r-- | src/hir/hir.cpp | 11 | ||||
-rw-r--r-- | src/hir/visitor.cpp | 4 |
4 files changed, 50 insertions, 35 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index bffafc48..431a75f4 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -18,7 +18,7 @@ { for(const auto& tp : gp.ty_params()) { - rv.m_types.push_back({ tp.name(), LowerHIR_Type(tp.get_default()) }); + rv.m_types.push_back({ tp.name(), LowerHIR_Type(tp.get_default()), true }); } } if( gp.lft_params().size() > 0 ) @@ -50,10 +50,23 @@ })); ), (MaybeTrait, - rv.m_bounds.push_back(::HIR::GenericBound::make_TraitUnbound({ - LowerHIR_Type(e.type), - LowerHIR_GenericPath(bound.span, e.trait) - })); + if( ! e.type.m_data.is_Generic() ) + BUG(bound.span, "MaybeTrait on non-param"); + const auto& param_name = e.type.m_data.as_Generic().name; + unsigned param_idx = ::std::find_if( rv.m_types.begin(), rv.m_types.end(), [&](const auto& x) { return x.m_name == param_name; } ) - rv.m_types.begin(); + if( param_idx >= rv.m_types.size() ) { + BUG(bound.span, "MaybeTrait on parameter not in parameter list"); + } + + // Compare with list of known default traits (just Sized atm) and set a marker + const auto path_Sized = ::HIR::SimplePath("", {"marker", "Sized"}); + auto trait = LowerHIR_GenericPath(bound.span, e.trait); + if( trait.m_path == path_Sized ) { + rv.m_types[param_idx].m_is_sized = false; + } + else { + ERROR(bound.span, E0000, "MaybeTrait on unknown trait " << trait.m_path); + } ), (NotTrait, TODO(bound.span, "Negative trait bounds"); diff --git a/src/hir/generic_params.hpp b/src/hir/generic_params.hpp index 28c9d067..1fe92163 100644 --- a/src/hir/generic_params.hpp +++ b/src/hir/generic_params.hpp @@ -8,34 +8,31 @@ struct TypeParamDef { ::std::string m_name; ::HIR::TypeRef m_default; + bool m_is_sized; }; TAGGED_UNION(GenericBound, Lifetime, -(Lifetime, struct { - ::std::string test; - ::std::string valid_for; - }), -(TypeLifetime, struct { - ::HIR::TypeRef type; - ::std::string valid_for; - }), -(TraitBound, struct { - ::HIR::TypeRef type; - ::HIR::TraitPath trait; - }), -(TraitUnbound, struct { - ::HIR::TypeRef type; - ::HIR::GenericPath trait; - }), -//(NotTrait, struct { -// ::HIR::TypeRef type; -// ::HIR::GenricPath trait; -// }), -(TypeEquality, struct { - ::HIR::TypeRef type; - ::HIR::TypeRef other_type; - }) -); + (Lifetime, struct { + ::std::string test; + ::std::string valid_for; + }), + (TypeLifetime, struct { + ::HIR::TypeRef type; + ::std::string valid_for; + }), + (TraitBound, struct { + ::HIR::TypeRef type; + ::HIR::TraitPath trait; + }), + //(NotTrait, struct { + // ::HIR::TypeRef type; + // ::HIR::GenricPath trait; + // }), + (TypeEquality, struct { + ::HIR::TypeRef type; + ::HIR::TypeRef other_type; + }) + ); struct GenericParams { diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index bc1fecd5..dede6489 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -34,6 +34,7 @@ namespace { { assert(! left.m_data.is_Infer() ); if( right.m_data.is_Infer() ) { + // TODO: Why is this false? A _ type could match anything return false; } @@ -68,7 +69,15 @@ namespace { } if( ple.m_params.m_types.size() > 0 || pre.m_params.m_types.size() > 0 ) { - TODO(Span(), "Match paths " << ple << " and " << pre); + if( ple.m_params.m_types.size() != pre.m_params.m_types.size() ) { + return true; + //TODO(Span(), "Match generic paths " << ple << " and " << pre << " - count mismatch"); + } + for( unsigned int i = 0; i < pre.m_params.m_types.size(); i ++ ) + { + if( ! matches_type_int(params, ple.m_params.m_types[i], pre.m_params.m_types[i]) ) + return false; + } } return true; ) diff --git a/src/hir/visitor.cpp b/src/hir/visitor.cpp index 5734fb77..1bc94bc7 100644 --- a/src/hir/visitor.cpp +++ b/src/hir/visitor.cpp @@ -229,10 +229,6 @@ void ::HIR::Visitor::visit_params(::HIR::GenericParams& params) this->visit_type(e.type); this->visit_generic_path(e.trait.m_path, ::HIR::Visitor::PathContext::TYPE); ), - (TraitUnbound, - this->visit_type(e.type); - // typeof(e.trait) == SimplePath - ), //(NotTrait, struct { // ::HIR::TypeRef type; // ::HIR::GenricPath trait; |