summaryrefslogtreecommitdiff
path: root/src/hir/path.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/hir/path.cpp')
-rw-r--r--src/hir/path.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/hir/path.cpp b/src/hir/path.cpp
index 4fcd46e5..6a8b2c07 100644
--- a/src/hir/path.cpp
+++ b/src/hir/path.cpp
@@ -144,4 +144,94 @@ namespace HIR {
throw "";
}
+namespace {
+ ::HIR::Compare compare_with_paceholders(
+ const Span& sp,
+ const ::HIR::PathParams& l, const ::HIR::PathParams& r,
+ ::HIR::t_cb_resolve_type resolve_placeholder
+ )
+ {
+ using ::HIR::Compare;
+
+ auto rv = Compare::Equal;
+ if( l.m_types.size() > 0 || r.m_types.size() > 0 ) {
+ if( l.m_types.size() != r.m_types.size() ) {
+ return Compare::Unequal;
+ }
+ for( unsigned int i = 0; i < r.m_types.size(); i ++ )
+ {
+ auto rv2 = l.m_types[i].compare_with_paceholders( sp, r.m_types[i], resolve_placeholder );
+ if( rv2 == Compare::Unequal )
+ return Compare::Unequal;
+ if( rv2 == Compare::Fuzzy )
+ rv = Compare::Fuzzy;
+ }
+ }
+ return rv;
+ }
+ ::HIR::Compare compare_with_paceholders(
+ const Span& sp,
+ const ::HIR::GenericPath& l, const ::HIR::GenericPath& r,
+ ::HIR::t_cb_resolve_type resolve_placeholder
+ )
+ {
+ using ::HIR::Compare;
+
+ if( l.m_path.m_crate_name != r.m_path.m_crate_name )
+ return Compare::Unequal;
+ if( l.m_path.m_components.size() != r.m_path.m_components.size() )
+ return Compare::Unequal;
+ for(unsigned int i = 0; i < l.m_path.m_components.size(); i ++ )
+ {
+ if( l.m_path.m_components[i] != r.m_path.m_components[i] )
+ return Compare::Unequal;
+ }
+
+ return compare_with_paceholders(sp, l.m_params, r.m_params, resolve_placeholder);
+ }
+}
+
+#define CMP(rv, cmp) do { \
+ switch(cmp) {\
+ case ::HIR::Compare::Unequal: return ::HIR::Compare::Unequal; \
+ case ::HIR::Compare::Fuzzy: rv = ::HIR::Compare::Fuzzy; break; \
+ case ::HIR::Compare::Equal: break; \
+ }\
+} while(0)
+
+::HIR::Compare HIR::Path::compare_with_paceholders(const Span& sp, const Path& x, t_cb_resolve_type resolve_placeholder) const
+{
+ if( this->m_data.tag() != x.m_data.tag() )
+ return Compare::Unequal;
+ TU_MATCH(::HIR::Path::Data, (this->m_data, x.m_data), (ple, pre),
+ (Generic,
+ return ::compare_with_paceholders(sp, ple, pre, resolve_placeholder);
+ ),
+ (UfcsUnknown,
+ if( ple.item != pre.item)
+ return Compare::Unequal;
+
+ TODO(sp, "Path::compare_with_paceholders - UfcsUnknown");
+ ),
+ (UfcsInherent,
+ if( ple.item != pre.item)
+ return Compare::Unequal;
+ ::HIR::Compare rv = ::HIR::Compare::Equal;
+ CMP(rv, ple.type->compare_with_paceholders(sp, *pre.type, resolve_placeholder));
+ CMP(rv, ::compare_with_paceholders(sp, ple.params, pre.params, resolve_placeholder));
+ return rv;
+ ),
+ (UfcsKnown,
+ if( ple.item != pre.item)
+ return Compare::Unequal;
+
+ ::HIR::Compare rv = ::HIR::Compare::Equal;
+ CMP(rv, ple.type->compare_with_paceholders(sp, *pre.type, resolve_placeholder));
+ CMP(rv, ::compare_with_paceholders(sp, ple.trait, pre.trait, resolve_placeholder));
+ CMP(rv, ::compare_with_paceholders(sp, ple.params, pre.params, resolve_placeholder));
+ return rv;
+ )
+ )
+ throw "";
+}