summaryrefslogtreecommitdiff
path: root/src/hir
diff options
context:
space:
mode:
Diffstat (limited to 'src/hir')
-rw-r--r--src/hir/dump.cpp33
-rw-r--r--src/hir/from_ast.cpp15
-rw-r--r--src/hir/hir.hpp2
-rw-r--r--src/hir/visitor.cpp11
-rw-r--r--src/hir/visitor.hpp3
5 files changed, 60 insertions, 4 deletions
diff --git a/src/hir/dump.cpp b/src/hir/dump.cpp
index 874a80a7..e607925e 100644
--- a/src/hir/dump.cpp
+++ b/src/hir/dump.cpp
@@ -89,13 +89,46 @@ namespace {
void visit_trait(::HIR::ItemPath p, ::HIR::Trait& item) override
{
m_os << indent() << "trait " << p.get_name() << item.m_params.fmt_args() << "\n";
+ if( ! item.m_parent_traits.empty() )
+ {
+ m_os << indent() << " " << ": ";
+ bool is_first = true;
+ for(auto& bound : item.m_parent_traits)
+ {
+ if( !is_first )
+ m_os << indent() << " " << "+ ";
+ m_os << bound << "\n";
+ is_first = false;
+ }
+ }
if( ! item.m_params.m_bounds.empty() )
{
m_os << indent() << " " << item.m_params.fmt_bounds() << "\n";
}
m_os << indent() << "{\n";
inc_indent();
+
+ for(auto& i : item.m_types)
+ {
+ m_os << indent() << "type " << i.first;
+ if( ! i.second.m_trait_bounds.empty() )
+ {
+ m_os << ": ";
+ bool is_first = true;
+ for(auto& bound : i.second.m_trait_bounds)
+ {
+ if( !is_first )
+ m_os << " + ";
+ m_os << bound;
+ is_first = false;
+ }
+ }
+ //this->visit_type(i.second.m_default);
+ m_os << ";\n";
+ }
+
::HIR::Visitor::visit_trait(p, item);
+
dec_indent();
m_os << indent() << "}\n";
}
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 5dbf9c03..9c8f34f6 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -1258,6 +1258,21 @@ namespace {
receiver = ::HIR::Function::Receiver::Box;
}
}
+ // TODO: for other types, support arbitary structs/paths.
+ // - The path must include Self as a (the only?) type param.
+ if( receiver == ::HIR::Function::Receiver::Free )
+ {
+ if( pe.m_params.m_types.size() == 0 ) {
+ ERROR(sp, E0000, "Unsupported receiver type - " << arg_self_ty);
+ }
+ if( pe.m_params.m_types.size() != 1 ) {
+ TODO(sp, "Receiver types with more than one param - " << arg_self_ty);
+ }
+ if( pe.m_params.m_types[0] != self_type ) {
+ ERROR(sp, E0000, "Unsupported receiver type - " << arg_self_ty);
+ }
+ receiver = ::HIR::Function::Receiver::Custom;
+ }
)
)
else {
diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp
index 20b9ad58..daa27d10 100644
--- a/src/hir/hir.hpp
+++ b/src/hir/hir.hpp
@@ -8,6 +8,7 @@
* Contains the expanded and desugared AST
*/
#pragma once
+#include <target_version.hpp>
#include <cassert>
#include <unordered_map>
@@ -122,6 +123,7 @@ public:
//PointerMut,
//PointerConst,
Box,
+ Custom,
};
typedef ::std::vector< ::std::pair< ::HIR::Pattern, ::HIR::TypeRef> > args_t;
diff --git a/src/hir/visitor.cpp b/src/hir/visitor.cpp
index 2e03990a..87b790ae 100644
--- a/src/hir/visitor.cpp
+++ b/src/hir/visitor.cpp
@@ -168,10 +168,9 @@ void ::HIR::Visitor::visit_trait(::HIR::ItemPath p, ::HIR::Trait& item)
this->visit_trait_path(par);
}
for(auto& i : item.m_types) {
+ auto item_path = ::HIR::ItemPath(trait_ip, i.first.c_str());
DEBUG("type " << i.first);
- for(auto& bound : i.second.m_trait_bounds)
- this->visit_trait_path(bound);
- this->visit_type(i.second.m_default);
+ this->visit_associatedtype(item_path, i.second);
}
for(auto& i : item.m_values) {
auto item_path = ::HIR::ItemPath(trait_ip, i.first.c_str());
@@ -234,6 +233,12 @@ void ::HIR::Visitor::visit_union(::HIR::ItemPath p, ::HIR::Union& item)
for(auto& var : item.m_variants)
this->visit_type(var.second.ent);
}
+void ::HIR::Visitor::visit_associatedtype(ItemPath p, ::HIR::AssociatedType& item)
+{
+ for(auto& bound : item.m_trait_bounds)
+ this->visit_trait_path(bound);
+ this->visit_type(item.m_default);
+}
void ::HIR::Visitor::visit_function(::HIR::ItemPath p, ::HIR::Function& item)
{
this->visit_params(item.m_params);
diff --git a/src/hir/visitor.hpp b/src/hir/visitor.hpp
index dbf759a4..d432b29d 100644
--- a/src/hir/visitor.hpp
+++ b/src/hir/visitor.hpp
@@ -33,8 +33,9 @@ public:
virtual void visit_type_alias(ItemPath p, ::HIR::TypeAlias& item);
virtual void visit_trait(ItemPath p, ::HIR::Trait& item);
virtual void visit_struct(ItemPath p, ::HIR::Struct& item);
- virtual void visit_union(ItemPath p, ::HIR::Union& item);
virtual void visit_enum(ItemPath p, ::HIR::Enum& item);
+ virtual void visit_union(ItemPath p, ::HIR::Union& item);
+ virtual void visit_associatedtype(ItemPath p, ::HIR::AssociatedType& item);
// - Value Items
virtual void visit_function(ItemPath p, ::HIR::Function& item);
virtual void visit_static(ItemPath p, ::HIR::Static& item);