summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-06-11 22:30:53 +0800
committerJohn Hodge <tpg@mutabah.net>2016-06-11 22:31:16 +0800
commitf9e2d4130f6936c302069cab2681bca3c0bb0f55 (patch)
tree667a0b0f278584974446fa9324416e8c248addb8 /src
parent353109b07cfaeee463b71ab47de8471e3d0280e1 (diff)
downloadmrust-f9e2d4130f6936c302069cab2681bca3c0bb0f55.tar.gz
HIR Typecheck - Insert i32/f64 defaults
Diffstat (limited to 'src')
-rw-r--r--src/hir_typeck/expr.cpp2
-rw-r--r--src/hir_typeck/expr.hpp2
-rw-r--r--src/hir_typeck/expr_context.cpp25
3 files changed, 28 insertions, 1 deletions
diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp
index a11b5e7e..e6480a18 100644
--- a/src/hir_typeck/expr.cpp
+++ b/src/hir_typeck/expr.cpp
@@ -1798,7 +1798,7 @@ void Typecheck_Code(typeck::TypecheckContext context, const ::HIR::TypeRef& resu
DEBUG("==== PASS " << count << " ====");
visitor.visit_node_ptr(root_ptr);
context.compact_ivars();
- } while( context.take_changed() );
+ } while( context.take_changed() || context.apply_defaults() );
DEBUG("==== STOPPED: " << count << " passes ====");
}
diff --git a/src/hir_typeck/expr.hpp b/src/hir_typeck/expr.hpp
index 18523823..c4e8cdc4 100644
--- a/src/hir_typeck/expr.hpp
+++ b/src/hir_typeck/expr.hpp
@@ -82,6 +82,8 @@ public:
}
void compact_ivars();
+ /// Apply defaults (i32 or f64), returns true if a default was applied
+ bool apply_defaults();
/// Adds a local variable binding (type is mutable so it can be inferred if required)
void add_local(unsigned int index, const ::std::string& name, ::HIR::TypeRef type);
diff --git a/src/hir_typeck/expr_context.cpp b/src/hir_typeck/expr_context.cpp
index 5edf8b80..0cb67974 100644
--- a/src/hir_typeck/expr_context.cpp
+++ b/src/hir_typeck/expr_context.cpp
@@ -57,6 +57,31 @@ void typeck::TypecheckContext::compact_ivars()
v.type = this->get_type(v.type).clone();
}
}
+bool typeck::TypecheckContext::apply_defaults()
+{
+ bool rv = false;
+ for(auto& v : m_ivars)
+ {
+ if( !v.is_alias() ) {
+ TU_IFLET(::HIR::TypeRef::Data, v.type->m_data, Infer, e,
+ switch(e.ty_class)
+ {
+ case ::HIR::InferClass::None:
+ break;
+ case ::HIR::InferClass::Integer:
+ rv = true;
+ *v.type = ::HIR::TypeRef( ::HIR::CoreType::I32 );
+ break;
+ case ::HIR::InferClass::Float:
+ rv = true;
+ *v.type = ::HIR::TypeRef( ::HIR::CoreType::F64 );
+ break;
+ }
+ )
+ }
+ }
+ return rv;
+}
void typeck::TypecheckContext::add_local(unsigned int index, const ::std::string& name, ::HIR::TypeRef type)
{