diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-17 09:17:49 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-17 09:17:49 +0800 |
commit | 9faf10162f9f52201cdf1fa60248139037d615c4 (patch) | |
tree | 1fb61c58d8263d3dd28cf8192cd8e25967235b24 /src | |
parent | 62d063f49c15b837c3c16855d4c93905345eceb1 (diff) | |
download | mrust-9faf10162f9f52201cdf1fa60248139037d615c4.tar.gz |
HIR Visitor - Include type/paths visit functions in Expr
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/expr.cpp | 92 | ||||
-rw-r--r-- | src/hir/expr.hpp | 7 | ||||
-rw-r--r-- | src/hir/visitor.hpp | 1 |
3 files changed, 100 insertions, 0 deletions
diff --git a/src/hir/expr.cpp b/src/hir/expr.cpp index 891aae0f..fdeff6b5 100644 --- a/src/hir/expr.cpp +++ b/src/hir/expr.cpp @@ -129,3 +129,95 @@ DEF_VISIT(ExprNode_Closure, node, #undef DEF_VISIT +// TODO: Merge this with the stuff in ::HIR::Visitor +void ::HIR::ExprVisitorDef::visit_type(::HIR::TypeRef& ty) +{ + TU_MATCH(::HIR::TypeRef::Data, (ty.m_data), (e), + (Infer, + ), + (Diverge, + ), + (Primitive, + ), + (Path, + this->visit_path(::HIR::Visitor::PathContext::TYPE, e.path); + ), + (Generic, + ), + (TraitObject, + this->visit_trait_path(e.m_trait); + for(auto& trait : e.m_markers) { + this->visit_generic_path(::HIR::Visitor::PathContext::TYPE, trait); + } + ), + (Array, + this->visit_type( *e.inner ); + //this->visit_expr( e.size ); + ), + (Slice, + this->visit_type( *e.inner ); + ), + (Tuple, + for(auto& t : e) { + this->visit_type(t); + } + ), + (Borrow, + this->visit_type( *e.inner ); + ), + (Pointer, + this->visit_type( *e.inner ); + ), + (Function, + for(auto& t : e.m_arg_types) { + this->visit_type(t); + } + this->visit_type(*e.m_rettype); + ), + (Closure, + for(auto& t : e.m_arg_types) { + this->visit_type(t); + } + this->visit_type(*e.m_rettype); + ) + ) +} +void ::HIR::ExprVisitorDef::visit_path_params(::HIR::PathParams& pp) +{ + for(auto& ty : pp.m_types) + { + visit_type(ty); + } +} +void ::HIR::ExprVisitorDef::visit_trait_path(::HIR::TraitPath& p) +{ + this->visit_generic_path(::HIR::Visitor::PathContext::TYPE, p.m_path); + for(auto& assoc : p.m_type_bounds) + this->visit_type(assoc.second); +} +void ::HIR::ExprVisitorDef::visit_path(::HIR::Visitor::PathContext pc, ::HIR::Path& path) +{ + TU_MATCHA( (path.m_data), (e), + (Generic, + visit_generic_path(pc, e); + ), + (UfcsKnown, + visit_type(*e.type); + visit_generic_path(pc, e.trait); + visit_path_params(e.params); + ), + (UfcsUnknown, + visit_type(*e.type); + visit_path_params(e.params); + ), + (UfcsInherent, + visit_type(*e.type); + visit_path_params(e.params); + ) + ) +} +void ::HIR::ExprVisitorDef::visit_generic_path(::HIR::Visitor::PathContext pc, ::HIR::GenericPath& path) +{ + visit_path_params(path.m_params); +} + diff --git a/src/hir/expr.hpp b/src/hir/expr.hpp index 8da873c1..ae9ce7ed 100644 --- a/src/hir/expr.hpp +++ b/src/hir/expr.hpp @@ -6,6 +6,7 @@ #include <hir/pattern.hpp> #include <hir/type.hpp> #include <span.hpp> +#include <hir/visitor.hpp> namespace HIR { @@ -808,6 +809,12 @@ public: NV(ExprNode_Closure); #undef NV + + virtual void visit_type(::HIR::TypeRef& ty); + virtual void visit_trait_path(::HIR::TraitPath& p); + virtual void visit_path_params(::HIR::PathParams& ty); + virtual void visit_path(::HIR::Visitor::PathContext pc, ::HIR::Path& ty); + virtual void visit_generic_path(::HIR::Visitor::PathContext pc, ::HIR::GenericPath& ty); }; } diff --git a/src/hir/visitor.hpp b/src/hir/visitor.hpp index baf0c4a5..c250bd4a 100644 --- a/src/hir/visitor.hpp +++ b/src/hir/visitor.hpp @@ -6,6 +6,7 @@ namespace HIR { +// TODO: Split into Visitor and ItemVisitor class Visitor { public: |