diff options
-rw-r--r-- | src/hir/path.cpp | 15 | ||||
-rw-r--r-- | src/hir/path.hpp | 5 | ||||
-rw-r--r-- | src/hir/type.cpp | 34 | ||||
-rw-r--r-- | src/hir/type.hpp | 4 | ||||
-rw-r--r-- | src/hir_typeck/expr.cpp | 12 |
5 files changed, 44 insertions, 26 deletions
diff --git a/src/hir/path.cpp b/src/hir/path.cpp index 6a8b2c07..3cc1d817 100644 --- a/src/hir/path.cpp +++ b/src/hir/path.cpp @@ -85,6 +85,15 @@ namespace HIR { rv.m_types.push_back( t.clone() ); return rv; } +bool ::HIR::PathParams::operator==(const ::HIR::PathParams& x) const +{ + if( m_types.size() != x.m_types.size() ) + return false; + for( unsigned int i = 0; i < m_types.size(); i ++ ) + if( !(m_types[i] == x.m_types[i]) ) + return false; + return true; +} ::HIR::GenericPath::GenericPath() { @@ -102,6 +111,12 @@ namespace HIR { { return GenericPath(m_path.clone(), m_params.clone()); } +bool ::HIR::GenericPath::operator==(const GenericPath& x) const +{ + if( m_path != x.m_path ) + return false; + return m_params == x.m_params; +} ::HIR::Path::Path(::HIR::GenericPath gp): diff --git a/src/hir/path.hpp b/src/hir/path.hpp index d56b11a9..50973b85 100644 --- a/src/hir/path.hpp +++ b/src/hir/path.hpp @@ -69,7 +69,7 @@ struct PathParams PathParams(PathParams&&) = default; PathParams& operator=(PathParams&&) = default; - //bool operator==(const PathParams& x) const; + bool operator==(const PathParams& x) const; //bool operator<(const PathParams& x) const; friend ::std::ostream& operator<<(::std::ostream& os, const PathParams& x); @@ -88,7 +88,8 @@ public: GenericPath clone() const; - //bool operator==(const GenericPath& x) const; + bool operator==(const GenericPath& x) const; + bool operator!=(const GenericPath& x) const { return !(*this == x); } //bool operator<(const GenericPath& x) const; friend ::std::ostream& operator<<(::std::ostream& os, const GenericPath& x); diff --git a/src/hir/type.cpp b/src/hir/type.cpp index 8d62de90..c396ad2b 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -138,18 +138,6 @@ void ::HIR::TypeRef::fmt(::std::ostream& os) const ) } -namespace { - bool path_params_equal(const ::HIR::PathParams& t, const ::HIR::PathParams& x) - { - if( t.m_types.size() != x.m_types.size() ) - return false; - for( unsigned int i = 0; i < t.m_types.size(); i ++ ) - if( !(t.m_types[i] == x.m_types[i]) ) - return false; - return true; - } -} - bool ::HIR::TypeRef::operator==(const ::HIR::TypeRef& x) const { if( m_data.tag() != x.m_data.tag() ) @@ -172,34 +160,30 @@ bool ::HIR::TypeRef::operator==(const ::HIR::TypeRef& x) const } TU_MATCH(::HIR::Path::Data, (te.path.m_data, xe.path.m_data), (tpe, xpe), (Generic, - if( tpe.m_path != xpe.m_path ) - return false; - return path_params_equal(tpe.m_params, xpe.m_params); + return tpe == xpe; ), (UfcsInherent, if( *tpe.type != *xpe.type ) return false; if( tpe.item != xpe.item ) return false; - return path_params_equal(tpe.params, xpe.params); + return tpe.params == xpe.params; ), (UfcsKnown, if( *tpe.type != *xpe.type ) return false; - if( tpe.trait.m_path != xpe.trait.m_path ) - return false; - if( !path_params_equal(tpe.trait.m_params, xpe.trait.m_params) ) + if( tpe.trait != xpe.trait ) return false; if( tpe.item != xpe.item ) return false; - return path_params_equal(tpe.params, xpe.params); + return tpe.params == xpe.params; ), (UfcsUnknown, if( *tpe.type != *xpe.type ) return false; if( tpe.item != xpe.item ) return false; - return path_params_equal(tpe.params, xpe.params); + return tpe.params == xpe.params; ) ) ), @@ -207,7 +191,13 @@ bool ::HIR::TypeRef::operator==(const ::HIR::TypeRef& x) const return te.name == xe.name && te.binding == xe.binding; ), (TraitObject, - assert(!"TODO: Compare trait object types"); + if( te.m_traits.size() != xe.m_traits.size() ) + return false; + for(unsigned int i = 0; i < te.m_traits.size(); i ++ ) { + if( te.m_traits[i] != xe.m_traits[i] ) + return false; + } + return te.m_lifetime == xe.m_lifetime; ), (Array, if( *te.inner != *xe.inner ) diff --git a/src/hir/type.hpp b/src/hir/type.hpp index b09d3f40..42d1323e 100644 --- a/src/hir/type.hpp +++ b/src/hir/type.hpp @@ -50,6 +50,10 @@ enum class BorrowType struct LifetimeRef { ::std::string name; + + bool operator==(const LifetimeRef& x) const { + return name == x.name; + } }; struct FunctionType diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp index b9420c70..fac27f03 100644 --- a/src/hir_typeck/expr.cpp +++ b/src/hir_typeck/expr.cpp @@ -56,7 +56,9 @@ namespace typeck { return true; ), (TraitObject, - TODO(Span(), "TraitObject - " << tpl); + for(const auto& trait : e.m_traits) + if( monomorphise_pathparams_needed(trait.m_params) ) return false; + return true; ), (Array, TODO(Span(), "Array - " << tpl); @@ -141,7 +143,13 @@ namespace typeck { return callback(tpl).clone(); ), (TraitObject, - TODO(sp, "TraitObject"); + ::HIR::TypeRef::Data::Data_TraitObject rv; + for(const auto& trait : e.m_traits) + { + rv.m_traits.push_back( monomorphise_genericpath_with(sp, trait, callback, allow_infer) ); + } + rv.m_lifetime = e.m_lifetime; + return ::HIR::TypeRef( mv$(rv) ); ), (Array, if( e.size_val == ~0u ) { |