summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-06-08 10:02:13 +0800
committerJohn Hodge <tpg@mutabah.net>2016-06-08 10:02:13 +0800
commit368c42ce7e5355341d547e5af6b71808dfd01acb (patch)
tree81a46fe3b660c9c3057ada289a30e39f49b4b2d4 /src
parent1ad65688d231ddee98ebf8425f45eba305f324f7 (diff)
downloadmrust-368c42ce7e5355341d547e5af6b71808dfd01acb.tar.gz
Resolve - Fix generic binding indexes
Diffstat (limited to 'src')
-rw-r--r--src/include/debug.hpp26
-rw-r--r--src/resolve/absolute.cpp15
2 files changed, 36 insertions, 5 deletions
diff --git a/src/include/debug.hpp b/src/include/debug.hpp
index 9dafdb42..2b3b1bee 100644
--- a/src/include/debug.hpp
+++ b/src/include/debug.hpp
@@ -3,6 +3,7 @@
#pragma once
#include <sstream>
#include <cassert>
+#include <functional>
extern int g_debug_indent_level;
@@ -41,21 +42,42 @@ public:
class TraceLog
{
const char* m_tag;
+ ::std::function<void(::std::ostream&)> m_ret;
public:
- TraceLog(const char* tag, ::std::string info): m_tag(tag) {
+ TraceLog(const char* tag, ::std::string info, ::std::function<void(::std::ostream&)> ret):
+ m_tag(tag),
+ m_ret(ret)
+ {
DEBUG(" >> " << m_tag << "(" << info << ")");
INDENT();
}
- TraceLog(const char* tag): m_tag(tag) {
+ TraceLog(const char* tag, ::std::string info):
+ m_tag(tag),
+ m_ret([](const auto&){})
+ {
+ DEBUG(" >> " << m_tag << "(" << info << ")");
+ INDENT();
+ }
+ TraceLog(const char* tag):
+ m_tag(tag),
+ m_ret([](const auto&){})
+ {
DEBUG(" >> " << m_tag);
INDENT();
}
~TraceLog() {
UNINDENT();
DEBUG("<< " << m_tag);
+ if(debug_enabled()) {
+ auto& os = debug_output(g_debug_indent_level, __FUNCTION__);
+ os << "<<" << m_tag;
+ m_ret(os);
+ os << ::std::endl;
+ }
}
};
#define TRACE_FUNCTION TraceLog _tf_(__func__)
#define TRACE_FUNCTION_F(ss) TraceLog _tf_(__func__, FMT(ss))
+#define TRACE_FUNCTION_FR(ss,ss2) TraceLog _tf_(__func__, FMT(ss), [&](::std::ostream&__os){ __os<<"(" << ss2 <<"}";})
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index b3934d1b..4b749e33 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -18,6 +18,15 @@ struct GenericSlot
Method,
} level;
unsigned short index;
+
+ unsigned int to_binding() const {
+ if(level == Level::Method) {
+ return (unsigned int)index + 256;
+ }
+ else {
+ return (unsigned int)index;
+ }
+ }
};
template<typename Val>
struct Named
@@ -360,7 +369,7 @@ struct Context
{
if( it2->name == name ) {
::AST::Path rv(name);
- rv.bind_variable( it2->value.index * (it2->value.level == GenericSlot::Level::Method ? 256 : 1) );
+ rv.bind_variable( it2->value.to_binding() );
return rv;
}
}
@@ -412,7 +421,7 @@ struct Context
for( auto it2 = e.types.rbegin(); it2 != e.types.rend(); ++ it2 )
{
if( it2->name == name ) {
- return it2->value.index * (it2->value.level == GenericSlot::Level::Method ? 256 : 1);
+ return it2->value.to_binding();
}
}
}
@@ -823,7 +832,7 @@ void Resolve_Absolute_Path(/*const*/ Context& context, const Span& sp, Context::
void Resolve_Absolute_Type(Context& context, TypeRef& type)
{
- TRACE_FUNCTION_F("type = " << type);
+ TRACE_FUNCTION_FR("type = " << type, "type = " << type);
const auto& sp = type.span();
TU_MATCH(TypeData, (type.m_data), (e),
(None,