summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-07-03 12:26:02 +0800
committerJohn Hodge <tpg@mutabah.net>2016-07-03 12:26:02 +0800
commitba32d2d8db970ebe112ad8aaa6eb5ab0dd09a672 (patch)
tree1dbe310fa2164cc24609f2b3d1afa6021b7f2b49
parent5cb11676166042251d46102f2ac5a85801e36abc (diff)
downloadmrust-ba32d2d8db970ebe112ad8aaa6eb5ab0dd09a672.tar.gz
HIR Typecheck - Allow easy selection of CS
-rw-r--r--Makefile1
-rw-r--r--src/hir_typeck/expr_cs.cpp191
-rw-r--r--src/hir_typeck/expr_simple.cpp192
-rw-r--r--src/hir_typeck/expr_visit.cpp139
-rw-r--r--src/hir_typeck/expr_visit.hpp62
5 files changed, 212 insertions, 373 deletions
diff --git a/Makefile b/Makefile
index 5b202351..2fc1ce77 100644
--- a/Makefile
+++ b/Makefile
@@ -51,6 +51,7 @@ OBJ += hir/type.o hir/path.o hir/expr.o hir/pattern.o
OBJ += hir/visitor.o
OBJ += hir_conv/expand_type.o hir_conv/constant_evaluation.o hir_conv/resolve_ufcs.o hir_conv/bind.o
OBJ += hir_typeck/outer.o hir_typeck/expr_context.o hir_typeck/helpers.o
+OBJ += hir_typeck/expr_visit.o
OBJ += hir_typeck/expr_simple.o hir_typeck/expr_cs.o
PCHS := ast/ast.hpp
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index 5e5ef9f8..b8afd2ab 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -12,7 +12,7 @@
#include <algorithm> // std::find_if
#include "helpers.hpp"
-//#include "expr.hpp"
+#include "expr_visit.hpp"
// PLAN: Build up a set of conditions that are easier to solve
struct Context
@@ -1548,66 +1548,8 @@ void fix_param_count(const Span& sp, Context& context, const ::HIR::GenericPath&
fix_param_count_(sp, context, path, param_defs, params);
}
-namespace {
- struct ModuleState
- {
- ::HIR::Crate& m_crate;
-
- ::HIR::GenericParams* m_impl_generics;
- ::HIR::GenericParams* m_item_generics;
-
- ::std::vector< ::std::pair< const ::HIR::SimplePath*, const ::HIR::Trait* > > m_traits;
-
- ModuleState(::HIR::Crate& crate):
- m_crate(crate),
- m_impl_generics(nullptr),
- m_item_generics(nullptr)
- {}
-
- template<typename T>
- class NullOnDrop {
- T*& ptr;
- public:
- NullOnDrop(T*& ptr):
- ptr(ptr)
- {}
- ~NullOnDrop() {
- ptr = nullptr;
- }
- };
- NullOnDrop< ::HIR::GenericParams> set_impl_generics(::HIR::GenericParams& gps) {
- assert( !m_impl_generics );
- m_impl_generics = &gps;
- return NullOnDrop< ::HIR::GenericParams>(m_impl_generics);
- }
- NullOnDrop< ::HIR::GenericParams> set_item_generics(::HIR::GenericParams& gps) {
- assert( !m_item_generics );
- m_item_generics = &gps;
- return NullOnDrop< ::HIR::GenericParams>(m_item_generics);
- }
-
- void push_traits(const ::HIR::Module& mod) {
- auto sp = Span();
- DEBUG("Module has " << mod.m_traits.size() << " in-scope traits");
- // - Push a NULL entry to prevent parent module import lists being searched
- m_traits.push_back( ::std::make_pair(nullptr, nullptr) );
- for( const auto& trait_path : mod.m_traits ) {
- DEBUG("Push " << trait_path);
- m_traits.push_back( ::std::make_pair( &trait_path, &this->m_crate.get_trait_by_path(sp, trait_path) ) );
- }
- }
- void pop_traits(const ::HIR::Module& mod) {
- DEBUG("Module has " << mod.m_traits.size() << " in-scope traits");
- for(unsigned int i = 0; i < mod.m_traits.size(); i ++ )
- m_traits.pop_back();
- m_traits.pop_back();
- }
- };
-}
-
-typedef ::std::vector< ::std::pair<::HIR::Pattern, ::HIR::TypeRef> > t_args;
-void Typecheck_Code_CS(const ModuleState& ms, t_args& args, const ::HIR::TypeRef& result_type, ::HIR::ExprPtr& expr)
+void Typecheck_Code_CS(const typeck::ModuleState& ms, t_args& args, const ::HIR::TypeRef& result_type, ::HIR::ExprPtr& expr)
{
Context context { ms.m_crate, ms.m_impl_generics, ms.m_item_generics };
@@ -1623,132 +1565,3 @@ void Typecheck_Code_CS(const ModuleState& ms, t_args& args, const ::HIR::TypeRef
// TODO: Run
}
-
-namespace {
-
- class OuterVisitor:
- public ::HIR::Visitor
- {
- ModuleState m_ms;
- public:
- OuterVisitor(::HIR::Crate& crate):
- m_ms(crate)
- {
- }
-
-
- public:
- void visit_module(::HIR::PathChain p, ::HIR::Module& mod) override
- {
- m_ms.push_traits(mod);
- ::HIR::Visitor::visit_module(p, mod);
- m_ms.pop_traits(mod);
- }
-
- // NOTE: This is left here to ensure that any expressions that aren't handled by higher code cause a failure
- void visit_expr(::HIR::ExprPtr& exp) {
- TODO(Span(), "visit_expr");
- }
-
- void visit_trait(::HIR::PathChain p, ::HIR::Trait& item) override
- {
- auto _ = this->m_ms.set_impl_generics(item.m_params);
- ::HIR::Visitor::visit_trait(p, item);
- }
-
- void visit_type_impl(::HIR::TypeImpl& impl) override
- {
- TRACE_FUNCTION_F("impl " << impl.m_type);
- auto _ = this->m_ms.set_impl_generics(impl.m_params);
-
- const auto& mod = this->m_ms.m_crate.get_mod_by_path(Span(), impl.m_src_module);
- m_ms.push_traits(mod);
- ::HIR::Visitor::visit_type_impl(impl);
- m_ms.pop_traits(mod);
- }
- void visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR::TraitImpl& impl) override
- {
- TRACE_FUNCTION_F("impl " << trait_path << " for " << impl.m_type);
- auto _ = this->m_ms.set_impl_generics(impl.m_params);
-
- const auto& mod = this->m_ms.m_crate.get_mod_by_path(Span(), impl.m_src_module);
- m_ms.push_traits(mod);
- ::HIR::Visitor::visit_trait_impl(trait_path, impl);
- m_ms.pop_traits(mod);
- }
- void visit_marker_impl(const ::HIR::SimplePath& trait_path, ::HIR::MarkerImpl& impl) override
- {
- TRACE_FUNCTION_F("impl " << trait_path << " for " << impl.m_type << " { }");
- auto _ = this->m_ms.set_impl_generics(impl.m_params);
-
- const auto& mod = this->m_ms.m_crate.get_mod_by_path(Span(), impl.m_src_module);
- m_ms.push_traits(mod);
- ::HIR::Visitor::visit_marker_impl(trait_path, impl);
- m_ms.pop_traits(mod);
- }
-
- void visit_type(::HIR::TypeRef& ty) override
- {
- TU_IFLET(::HIR::TypeRef::Data, ty.m_data, Array, e,
- this->visit_type( *e.inner );
- DEBUG("Array size " << ty);
- t_args tmp;
- Typecheck_Code_CS( m_ms, tmp, ::HIR::TypeRef(::HIR::CoreType::Usize), e.size );
- )
- else {
- ::HIR::Visitor::visit_type(ty);
- }
- }
- // ------
- // Code-containing items
- // ------
- void visit_function(::HIR::PathChain p, ::HIR::Function& item) override {
- auto _ = this->m_ms.set_item_generics(item.m_params);
- if( item.m_code )
- {
- DEBUG("Function code " << p);
- Typecheck_Code_CS( m_ms, item.m_args, item.m_return, item.m_code );
- }
- }
- void visit_static(::HIR::PathChain p, ::HIR::Static& item) override {
- //auto _ = this->m_ms.set_item_generics(item.m_params);
- if( item.m_value )
- {
- DEBUG("Static value " << p);
- t_args tmp;
- Typecheck_Code_CS(m_ms, tmp, item.m_type, item.m_value);
- }
- }
- void visit_constant(::HIR::PathChain p, ::HIR::Constant& item) override {
- auto _ = this->m_ms.set_item_generics(item.m_params);
- if( item.m_value )
- {
- DEBUG("Const value " << p);
- t_args tmp;
- Typecheck_Code_CS(m_ms, tmp, item.m_type, item.m_value);
- }
- }
- void visit_enum(::HIR::PathChain p, ::HIR::Enum& item) override {
- auto _ = this->m_ms.set_item_generics(item.m_params);
-
- // TODO: Use a different type depding on repr()
- auto enum_type = ::HIR::TypeRef(::HIR::CoreType::Usize);
-
- // TODO: Check types too?
- for(auto& var : item.m_variants)
- {
- TU_IFLET(::HIR::Enum::Variant, var.second, Value, e,
- DEBUG("Enum value " << p << " - " << var.first);
- t_args tmp;
- Typecheck_Code_CS(m_ms, tmp, enum_type, e);
- )
- }
- }
- };
-}
-
-//void Typecheck_Expressions(::HIR::Crate& crate)
-//{
-// OuterVisitor visitor { crate };
-// visitor.visit_crate( crate );
-//}
diff --git a/src/hir_typeck/expr_simple.cpp b/src/hir_typeck/expr_simple.cpp
index 7379ed2c..1185d6b9 100644
--- a/src/hir_typeck/expr_simple.cpp
+++ b/src/hir_typeck/expr_simple.cpp
@@ -7,6 +7,7 @@
#include <algorithm> // std::find_if
#include "helpers.hpp"
+#include "expr_visit.hpp"
#include "expr_simple.hpp"
namespace typeck {
@@ -1994,189 +1995,12 @@ void Typecheck_Code(typeck::TypecheckContext context, const ::HIR::TypeRef& resu
expr->visit( visitor );
}
}
-
-
-
-namespace {
- using typeck::TypecheckContext;
-
- class OuterVisitor:
- public ::HIR::Visitor
- {
- ::HIR::Crate& m_crate;
-
- ::HIR::GenericParams* m_impl_generics;
- ::HIR::GenericParams* m_item_generics;
- ::std::vector< ::std::pair< const ::HIR::SimplePath*, const ::HIR::Trait* > > m_traits;
- public:
- OuterVisitor(::HIR::Crate& crate):
- m_crate(crate),
- m_impl_generics(nullptr),
- m_item_generics(nullptr)
- {
- }
-
- private:
- template<typename T>
- class NullOnDrop {
- T*& ptr;
- public:
- NullOnDrop(T*& ptr):
- ptr(ptr)
- {}
- ~NullOnDrop() {
- ptr = nullptr;
- }
- };
- NullOnDrop< ::HIR::GenericParams> set_impl_generics(::HIR::GenericParams& gps) {
- assert( !m_impl_generics );
- m_impl_generics = &gps;
- return NullOnDrop< ::HIR::GenericParams>(m_impl_generics);
- }
- NullOnDrop< ::HIR::GenericParams> set_item_generics(::HIR::GenericParams& gps) {
- assert( !m_item_generics );
- m_item_generics = &gps;
- return NullOnDrop< ::HIR::GenericParams>(m_item_generics);
- }
-
- void push_traits(const ::HIR::Module& mod) {
- auto sp = Span();
- DEBUG("Module has " << mod.m_traits.size() << " in-scope traits");
- // - Push a NULL entry to prevent parent module import lists being searched
- m_traits.push_back( ::std::make_pair(nullptr, nullptr) );
- for( const auto& trait_path : mod.m_traits ) {
- DEBUG("Push " << trait_path);
- m_traits.push_back( ::std::make_pair( &trait_path, &this->m_crate.get_trait_by_path(sp, trait_path) ) );
- }
- }
- void pop_traits(const ::HIR::Module& mod) {
- DEBUG("Module has " << mod.m_traits.size() << " in-scope traits");
- for(unsigned int i = 0; i < mod.m_traits.size(); i ++ )
- m_traits.pop_back();
- m_traits.pop_back();
- }
-
- public:
- void visit_module(::HIR::PathChain p, ::HIR::Module& mod) override
- {
- push_traits(mod);
- ::HIR::Visitor::visit_module(p, mod);
- pop_traits(mod);
- }
-
- // NOTE: This is left here to ensure that any expressions that aren't handled by higher code cause a failure
- void visit_expr(::HIR::ExprPtr& exp) {
- TODO(Span(), "visit_expr");
- }
-
- void visit_trait(::HIR::PathChain p, ::HIR::Trait& item) override
- {
- auto _ = this->set_impl_generics(item.m_params);
- ::HIR::Visitor::visit_trait(p, item);
- }
-
- void visit_type_impl(::HIR::TypeImpl& impl) override
- {
- TRACE_FUNCTION_F("impl " << impl.m_type);
- auto _ = this->set_impl_generics(impl.m_params);
-
- const auto& mod = this->m_crate.get_mod_by_path(Span(), impl.m_src_module);
- push_traits(mod);
- ::HIR::Visitor::visit_type_impl(impl);
- pop_traits(mod);
- }
- void visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR::TraitImpl& impl) override
- {
- TRACE_FUNCTION_F("impl " << trait_path << " for " << impl.m_type);
- auto _ = this->set_impl_generics(impl.m_params);
-
- const auto& mod = this->m_crate.get_mod_by_path(Span(), impl.m_src_module);
- push_traits(mod);
- ::HIR::Visitor::visit_trait_impl(trait_path, impl);
- pop_traits(mod);
- }
- void visit_marker_impl(const ::HIR::SimplePath& trait_path, ::HIR::MarkerImpl& impl) override
- {
- TRACE_FUNCTION_F("impl " << trait_path << " for " << impl.m_type << " { }");
- auto _ = this->set_impl_generics(impl.m_params);
-
- const auto& mod = this->m_crate.get_mod_by_path(Span(), impl.m_src_module);
- push_traits(mod);
- ::HIR::Visitor::visit_marker_impl(trait_path, impl);
- pop_traits(mod);
- }
-
- void visit_type(::HIR::TypeRef& ty) override
- {
- TU_IFLET(::HIR::TypeRef::Data, ty.m_data, Array, e,
- this->visit_type( *e.inner );
- TypecheckContext typeck_context { m_crate, m_impl_generics, m_item_generics };
- typeck_context.m_traits = this->m_traits;
- DEBUG("Array size " << ty);
- Typecheck_Code( mv$(typeck_context), ::HIR::TypeRef(::HIR::CoreType::Usize), e.size );
- )
- else {
- ::HIR::Visitor::visit_type(ty);
- }
- }
- // ------
- // Code-containing items
- // ------
- void visit_function(::HIR::PathChain p, ::HIR::Function& item) override {
- auto _ = this->set_item_generics(item.m_params);
- if( item.m_code )
- {
- TypecheckContext typeck_context { m_crate, m_impl_generics, m_item_generics };
- typeck_context.m_traits = this->m_traits;
- for( auto& arg : item.m_args ) {
- typeck_context.add_binding( Span(), arg.first, arg.second );
- }
- DEBUG("Function code " << p);
- Typecheck_Code( mv$(typeck_context), item.m_return, item.m_code );
- }
- }
- void visit_static(::HIR::PathChain p, ::HIR::Static& item) override {
- //auto _ = this->set_item_generics(item.m_params);
- if( item.m_value )
- {
- TypecheckContext typeck_context { m_crate, m_impl_generics, m_item_generics };
- typeck_context.m_traits = this->m_traits;
- DEBUG("Static value " << p);
- Typecheck_Code( mv$(typeck_context), item.m_type, item.m_value );
- }
- }
- void visit_constant(::HIR::PathChain p, ::HIR::Constant& item) override {
- auto _ = this->set_item_generics(item.m_params);
- if( item.m_value )
- {
- TypecheckContext typeck_context { m_crate, m_impl_generics, m_item_generics };
- typeck_context.m_traits = this->m_traits;
- DEBUG("Const value " << p);
- Typecheck_Code( mv$(typeck_context), item.m_type, item.m_value );
- }
- }
- void visit_enum(::HIR::PathChain p, ::HIR::Enum& item) override {
- auto _ = this->set_item_generics(item.m_params);
-
- // TODO: Use a different type depding on repr()
- auto enum_type = ::HIR::TypeRef(::HIR::CoreType::Usize);
-
- // TODO: Check types too?
- for(auto& var : item.m_variants)
- {
- TU_IFLET(::HIR::Enum::Variant, var.second, Value, e,
- TypecheckContext typeck_context { m_crate, m_impl_generics, m_item_generics };
- typeck_context.m_traits = this->m_traits;
- DEBUG("Enum value " << p << " - " << var.first);
- Typecheck_Code( mv$(typeck_context), enum_type, e );
- )
- }
- }
- };
-}
-
-void Typecheck_Expressions(::HIR::Crate& crate)
+void Typecheck_Code_Simple(const typeck::ModuleState& ms, t_args& args, const ::HIR::TypeRef& result_type, ::HIR::ExprPtr& expr)
{
- OuterVisitor visitor { crate };
- visitor.visit_crate( crate );
+ typeck::TypecheckContext typeck_context { ms.m_crate, ms.m_impl_generics, ms.m_item_generics };
+ typeck_context.m_traits = ms.m_traits;
+ for( auto& arg : args ) {
+ typeck_context.add_binding( Span(), arg.first, arg.second );
+ }
+ Typecheck_Code( mv$(typeck_context), result_type, expr );
}
diff --git a/src/hir_typeck/expr_visit.cpp b/src/hir_typeck/expr_visit.cpp
new file mode 100644
index 00000000..1953f9ef
--- /dev/null
+++ b/src/hir_typeck/expr_visit.cpp
@@ -0,0 +1,139 @@
+/*
+ */
+#include <hir/hir.hpp>
+#include <hir/expr.hpp>
+#include <hir/visitor.hpp>
+#include "expr_visit.hpp"
+
+namespace {
+ void Typecheck_Code(const typeck::ModuleState& ms, t_args& args, const ::HIR::TypeRef& result_type, ::HIR::ExprPtr& expr) {
+ Typecheck_Code_Simple(ms, args, result_type, expr);
+ //Typecheck_Code_CS(ms, args, result_type, expr);
+ }
+
+ class OuterVisitor:
+ public ::HIR::Visitor
+ {
+ ::typeck::ModuleState m_ms;
+ public:
+ OuterVisitor(::HIR::Crate& crate):
+ m_ms(crate)
+ {
+ }
+
+
+ public:
+ void visit_module(::HIR::PathChain p, ::HIR::Module& mod) override
+ {
+ m_ms.push_traits(mod);
+ ::HIR::Visitor::visit_module(p, mod);
+ m_ms.pop_traits(mod);
+ }
+
+ // NOTE: This is left here to ensure that any expressions that aren't handled by higher code cause a failure
+ void visit_expr(::HIR::ExprPtr& exp) {
+ TODO(Span(), "visit_expr");
+ }
+
+ void visit_trait(::HIR::PathChain p, ::HIR::Trait& item) override
+ {
+ auto _ = this->m_ms.set_impl_generics(item.m_params);
+ ::HIR::Visitor::visit_trait(p, item);
+ }
+
+ void visit_type_impl(::HIR::TypeImpl& impl) override
+ {
+ TRACE_FUNCTION_F("impl " << impl.m_type);
+ auto _ = this->m_ms.set_impl_generics(impl.m_params);
+
+ const auto& mod = this->m_ms.m_crate.get_mod_by_path(Span(), impl.m_src_module);
+ m_ms.push_traits(mod);
+ ::HIR::Visitor::visit_type_impl(impl);
+ m_ms.pop_traits(mod);
+ }
+ void visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR::TraitImpl& impl) override
+ {
+ TRACE_FUNCTION_F("impl " << trait_path << " for " << impl.m_type);
+ auto _ = this->m_ms.set_impl_generics(impl.m_params);
+
+ const auto& mod = this->m_ms.m_crate.get_mod_by_path(Span(), impl.m_src_module);
+ m_ms.push_traits(mod);
+ ::HIR::Visitor::visit_trait_impl(trait_path, impl);
+ m_ms.pop_traits(mod);
+ }
+ void visit_marker_impl(const ::HIR::SimplePath& trait_path, ::HIR::MarkerImpl& impl) override
+ {
+ TRACE_FUNCTION_F("impl " << trait_path << " for " << impl.m_type << " { }");
+ auto _ = this->m_ms.set_impl_generics(impl.m_params);
+
+ const auto& mod = this->m_ms.m_crate.get_mod_by_path(Span(), impl.m_src_module);
+ m_ms.push_traits(mod);
+ ::HIR::Visitor::visit_marker_impl(trait_path, impl);
+ m_ms.pop_traits(mod);
+ }
+
+ void visit_type(::HIR::TypeRef& ty) override
+ {
+ TU_IFLET(::HIR::TypeRef::Data, ty.m_data, Array, e,
+ this->visit_type( *e.inner );
+ DEBUG("Array size " << ty);
+ t_args tmp;
+ Typecheck_Code( m_ms, tmp, ::HIR::TypeRef(::HIR::CoreType::Usize), e.size );
+ )
+ else {
+ ::HIR::Visitor::visit_type(ty);
+ }
+ }
+ // ------
+ // Code-containing items
+ // ------
+ void visit_function(::HIR::PathChain p, ::HIR::Function& item) override {
+ auto _ = this->m_ms.set_item_generics(item.m_params);
+ if( item.m_code )
+ {
+ DEBUG("Function code " << p);
+ Typecheck_Code( m_ms, item.m_args, item.m_return, item.m_code );
+ }
+ }
+ void visit_static(::HIR::PathChain p, ::HIR::Static& item) override {
+ //auto _ = this->m_ms.set_item_generics(item.m_params);
+ if( item.m_value )
+ {
+ DEBUG("Static value " << p);
+ t_args tmp;
+ Typecheck_Code(m_ms, tmp, item.m_type, item.m_value);
+ }
+ }
+ void visit_constant(::HIR::PathChain p, ::HIR::Constant& item) override {
+ auto _ = this->m_ms.set_item_generics(item.m_params);
+ if( item.m_value )
+ {
+ DEBUG("Const value " << p);
+ t_args tmp;
+ Typecheck_Code(m_ms, tmp, item.m_type, item.m_value);
+ }
+ }
+ void visit_enum(::HIR::PathChain p, ::HIR::Enum& item) override {
+ auto _ = this->m_ms.set_item_generics(item.m_params);
+
+ // TODO: Use a different type depding on repr()
+ auto enum_type = ::HIR::TypeRef(::HIR::CoreType::Usize);
+
+ // TODO: Check types too?
+ for(auto& var : item.m_variants)
+ {
+ TU_IFLET(::HIR::Enum::Variant, var.second, Value, e,
+ DEBUG("Enum value " << p << " - " << var.first);
+ t_args tmp;
+ Typecheck_Code(m_ms, tmp, enum_type, e);
+ )
+ }
+ }
+ };
+}
+
+void Typecheck_Expressions(::HIR::Crate& crate)
+{
+ OuterVisitor visitor { crate };
+ visitor.visit_crate( crate );
+}
diff --git a/src/hir_typeck/expr_visit.hpp b/src/hir_typeck/expr_visit.hpp
new file mode 100644
index 00000000..5ef2a838
--- /dev/null
+++ b/src/hir_typeck/expr_visit.hpp
@@ -0,0 +1,62 @@
+
+namespace typeck {
+ struct ModuleState
+ {
+ ::HIR::Crate& m_crate;
+
+ ::HIR::GenericParams* m_impl_generics;
+ ::HIR::GenericParams* m_item_generics;
+
+ ::std::vector< ::std::pair< const ::HIR::SimplePath*, const ::HIR::Trait* > > m_traits;
+
+ ModuleState(::HIR::Crate& crate):
+ m_crate(crate),
+ m_impl_generics(nullptr),
+ m_item_generics(nullptr)
+ {}
+
+ template<typename T>
+ class NullOnDrop {
+ T*& ptr;
+ public:
+ NullOnDrop(T*& ptr):
+ ptr(ptr)
+ {}
+ ~NullOnDrop() {
+ ptr = nullptr;
+ }
+ };
+ NullOnDrop< ::HIR::GenericParams> set_impl_generics(::HIR::GenericParams& gps) {
+ assert( !m_impl_generics );
+ m_impl_generics = &gps;
+ return NullOnDrop< ::HIR::GenericParams>(m_impl_generics);
+ }
+ NullOnDrop< ::HIR::GenericParams> set_item_generics(::HIR::GenericParams& gps) {
+ assert( !m_item_generics );
+ m_item_generics = &gps;
+ return NullOnDrop< ::HIR::GenericParams>(m_item_generics);
+ }
+
+ void push_traits(const ::HIR::Module& mod) {
+ auto sp = Span();
+ DEBUG("Module has " << mod.m_traits.size() << " in-scope traits");
+ // - Push a NULL entry to prevent parent module import lists being searched
+ m_traits.push_back( ::std::make_pair(nullptr, nullptr) );
+ for( const auto& trait_path : mod.m_traits ) {
+ DEBUG("Push " << trait_path);
+ m_traits.push_back( ::std::make_pair( &trait_path, &this->m_crate.get_trait_by_path(sp, trait_path) ) );
+ }
+ }
+ void pop_traits(const ::HIR::Module& mod) {
+ DEBUG("Module has " << mod.m_traits.size() << " in-scope traits");
+ for(unsigned int i = 0; i < mod.m_traits.size(); i ++ )
+ m_traits.pop_back();
+ m_traits.pop_back();
+ }
+ };
+}
+
+
+typedef ::std::vector< ::std::pair<::HIR::Pattern, ::HIR::TypeRef> > t_args;
+extern void Typecheck_Code_CS(const typeck::ModuleState& ms, t_args& args, const ::HIR::TypeRef& result_type, ::HIR::ExprPtr& expr);
+extern void Typecheck_Code_Simple(const typeck::ModuleState& ms, t_args& args, const ::HIR::TypeRef& result_type, ::HIR::ExprPtr& expr);