summaryrefslogtreecommitdiff
path: root/src/hir
diff options
context:
space:
mode:
Diffstat (limited to 'src/hir')
-rw-r--r--src/hir/crate_ptr.hpp4
-rw-r--r--src/hir/deserialise.cpp142
-rw-r--r--src/hir/dump.cpp42
-rw-r--r--src/hir/expr.cpp10
-rw-r--r--src/hir/expr.hpp178
-rw-r--r--src/hir/expr_ptr.hpp14
-rw-r--r--src/hir/from_ast.cpp188
-rw-r--r--src/hir/from_ast_expr.cpp82
-rw-r--r--src/hir/generic_params.cpp2
-rw-r--r--src/hir/generic_params.hpp8
-rw-r--r--src/hir/hir.cpp48
-rw-r--r--src/hir/hir.hpp98
-rw-r--r--src/hir/item_path.hpp16
-rw-r--r--src/hir/path.cpp32
-rw-r--r--src/hir/path.hpp34
-rw-r--r--src/hir/pattern.cpp12
-rw-r--r--src/hir/pattern.hpp14
-rw-r--r--src/hir/serialise.cpp78
-rw-r--r--src/hir/serialise_lowlevel.cpp34
-rw-r--r--src/hir/serialise_lowlevel.hpp10
-rw-r--r--src/hir/type.cpp36
-rw-r--r--src/hir/type.hpp28
-rw-r--r--src/hir/visitor.cpp8
-rw-r--r--src/hir/visitor.hpp14
24 files changed, 566 insertions, 566 deletions
diff --git a/src/hir/crate_ptr.hpp b/src/hir/crate_ptr.hpp
index ad6f374e..c870b1ea 100644
--- a/src/hir/crate_ptr.hpp
+++ b/src/hir/crate_ptr.hpp
@@ -10,7 +10,7 @@ class Crate;
class CratePtr
{
Crate* m_ptr;
-
+
public:
CratePtr();
CratePtr(Crate c);
@@ -27,7 +27,7 @@ public:
return *this;
}
~CratePtr();
-
+
Crate& operator*() { return *m_ptr; }
const Crate& operator*() const { return *m_ptr; }
Crate* operator->() { return m_ptr; }
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp
index 7b821630..de0d13da 100644
--- a/src/hir/deserialise.cpp
+++ b/src/hir/deserialise.cpp
@@ -14,12 +14,12 @@
#include "serialise_lowlevel.hpp"
namespace {
-
+
template<typename T>
struct D
{
};
-
+
class HirDeserialiser
{
const ::std::string& m_crate_name;
@@ -29,10 +29,10 @@ namespace {
m_crate_name( crate_name ),
m_in(in)
{}
-
+
::std::string read_string() { return m_in.read_string(); }
size_t deserialise_count() { return m_in.read_count(); }
-
+
template<typename V>
::std::map< ::std::string,V> deserialise_strmap()
{
@@ -74,7 +74,7 @@ namespace {
}
return rv;
}
-
+
template<typename T>
::std::vector<T> deserialise_vec()
{
@@ -100,13 +100,13 @@ namespace {
{
return ::HIR::VisEnt<T> { m_in.read_bool(), D<T>::des(*this) };
}
-
+
template<typename T>
::std::unique_ptr<T> deserialise_ptr() {
return box$( D<T>::des(*this) );
}
-
-
+
+
::HIR::TypeRef deserialise_type();
::HIR::SimplePath deserialise_simplepath();
::HIR::PathParams deserialise_pathparams();
@@ -117,18 +117,18 @@ namespace {
::HIR::GenericParams deserialise_genericparams();
::HIR::TypeParamDef deserialise_typaramdef();
::HIR::GenericBound deserialise_genericbound();
-
+
::HIR::Crate deserialise_crate();
::HIR::Module deserialise_module();
-
+
::HIR::TypeImpl deserialise_typeimpl()
{
::HIR::TypeImpl rv;
TRACE_FUNCTION_FR("", "impl" << rv.m_params.fmt_args() << " " << rv.m_type);
-
+
rv.m_params = deserialise_genericparams();
rv.m_type = deserialise_type();
-
+
size_t method_count = m_in.read_count();
for(size_t i = 0; i < method_count; i ++)
{
@@ -152,12 +152,12 @@ namespace {
{
::HIR::TraitImpl rv;
TRACE_FUNCTION_FR("", "impl" << rv.m_params.fmt_args() << " ?" << rv.m_trait_args << " for " << rv.m_type);
-
+
rv.m_params = deserialise_genericparams();
rv.m_trait_args = deserialise_pathparams();
rv.m_type = deserialise_type();
-
-
+
+
size_t method_count = m_in.read_count();
for(size_t i = 0; i < method_count; i ++)
{
@@ -190,7 +190,7 @@ namespace {
m_in.read_bool(), deserialise_type()
} ) );
}
-
+
// m_src_module doesn't matter after typeck
return rv;
}
@@ -203,7 +203,7 @@ namespace {
deserialise_type()
};
}
-
+
::MacroRulesPtr deserialise_macrorulesptr()
{
return ::MacroRulesPtr( new MacroRules(deserialise_macrorules()) );
@@ -284,7 +284,7 @@ namespace {
throw "";
}
}
-
+
::Token deserialise_token() {
::Token tok;
// HACK: Hand off to old serialiser code
@@ -298,7 +298,7 @@ namespace {
}
::HIR::Literal deserialise_literal();
-
+
::HIR::ExprPtr deserialise_exprptr()
{
::HIR::ExprPtr rv;
@@ -314,7 +314,7 @@ namespace {
::MIR::Statement deserialise_mir_statement();
::MIR::Terminator deserialise_mir_terminator();
::MIR::CallTarget deserialise_mir_calltarget();
-
+
::MIR::LValue deserialise_mir_lvalue() {
::MIR::LValue rv;
TRACE_FUNCTION_FR("", rv);
@@ -352,7 +352,7 @@ namespace {
::MIR::RValue deserialise_mir_rvalue()
{
TRACE_FUNCTION;
-
+
switch( m_in.read_tag() )
{
#define _(x, ...) case ::MIR::RValue::TAG_##x: return ::MIR::RValue::make_##x( __VA_ARGS__ );
@@ -414,7 +414,7 @@ namespace {
::MIR::Constant deserialise_mir_constant()
{
TRACE_FUNCTION;
-
+
switch( m_in.read_tag() )
{
#define _(x, ...) case ::MIR::Constant::TAG_##x: DEBUG("- " #x); return ::MIR::Constant::make_##x( __VA_ARGS__ );
@@ -436,7 +436,7 @@ namespace {
throw "";
}
}
-
+
::HIR::TypeItem deserialise_typeitem()
{
switch( m_in.read_tag() )
@@ -479,7 +479,7 @@ namespace {
throw "";
}
}
-
+
::HIR::Linkage deserialise_linkage()
{
return ::HIR::Linkage {
@@ -487,12 +487,12 @@ namespace {
m_in.read_string(),
};
}
-
+
// - Value items
::HIR::Function deserialise_function()
{
TRACE_FUNCTION;
-
+
::HIR::Function rv {
deserialise_linkage(),
static_cast< ::HIR::Function::Receiver>( m_in.read_tag() ),
@@ -520,7 +520,7 @@ namespace {
::HIR::Constant deserialise_constant()
{
TRACE_FUNCTION;
-
+
return ::HIR::Constant {
deserialise_genericparams(),
deserialise_type(),
@@ -531,7 +531,7 @@ namespace {
::HIR::Static deserialise_static()
{
TRACE_FUNCTION;
-
+
return ::HIR::Static {
deserialise_linkage(),
m_in.read_bool(),
@@ -540,7 +540,7 @@ namespace {
deserialise_literal()
};
}
-
+
// - Type items
::HIR::TypeAlias deserialise_typealias()
{
@@ -565,14 +565,14 @@ namespace {
// TODO: auto_impls
return m;
}
-
+
::HIR::Enum deserialise_enum();
::HIR::Enum::Variant deserialise_enumvariant();
::HIR::Struct deserialise_struct();
::HIR::Union deserialise_union();
::HIR::Trait deserialise_trait();
-
+
::HIR::TraitValueItem deserialise_traitvalueitem()
{
switch( m_in.read_tag() )
@@ -600,50 +600,50 @@ namespace {
#define DEF_D(ty, ...) \
struct D< ty > { static ty des(HirDeserialiser& d) { __VA_ARGS__ } };
-
+
template<>
DEF_D( ::std::string,
return d.read_string(); );
-
+
template<typename T>
DEF_D( ::std::unique_ptr<T>,
return d.deserialise_ptr<T>(); )
-
+
template<typename T, typename U>
struct D< ::std::pair<T,U> > { static ::std::pair<T,U> des(HirDeserialiser& d) {
auto a = D<T>::des(d);
return ::std::make_pair( mv$(a), D<U>::des(d) );
}};
-
+
template<typename T>
DEF_D( ::HIR::VisEnt<T>,
return d.deserialise_visent<T>(); )
-
+
template<> DEF_D( ::HIR::TypeRef, return d.deserialise_type(); )
template<> DEF_D( ::HIR::SimplePath, return d.deserialise_simplepath(); )
template<> DEF_D( ::HIR::GenericPath, return d.deserialise_genericpath(); )
template<> DEF_D( ::HIR::TraitPath, return d.deserialise_traitpath(); )
-
+
template<> DEF_D( ::HIR::TypeParamDef, return d.deserialise_typaramdef(); )
template<> DEF_D( ::HIR::GenericBound, return d.deserialise_genericbound(); )
-
+
template<> DEF_D( ::HIR::ValueItem, return d.deserialise_valueitem(); )
template<> DEF_D( ::HIR::TypeItem, return d.deserialise_typeitem(); )
-
+
template<> DEF_D( ::HIR::Enum::Variant, return d.deserialise_enumvariant(); )
template<> DEF_D( ::HIR::Literal, return d.deserialise_literal(); )
-
+
template<> DEF_D( ::HIR::AssociatedType, return d.deserialise_associatedtype(); )
template<> DEF_D( ::HIR::TraitValueItem, return d.deserialise_traitvalueitem(); )
-
+
template<> DEF_D( ::MIR::LValue, return d.deserialise_mir_lvalue(); )
template<> DEF_D( ::MIR::Statement, return d.deserialise_mir_statement(); )
template<> DEF_D( ::MIR::BasicBlock, return d.deserialise_mir_basicblock(); )
-
+
template<> DEF_D( ::HIR::TypeImpl, return d.deserialise_typeimpl(); )
template<> DEF_D( ::MacroRulesPtr, return d.deserialise_macrorulesptr(); )
template<> DEF_D( unsigned int, return static_cast<unsigned int>(d.deserialise_count()); )
-
+
::HIR::TypeRef HirDeserialiser::deserialise_type()
{
TRACE_FUNCTION;
@@ -704,7 +704,7 @@ namespace {
throw ::std::runtime_error(FMT("Bad TypeRef tag - " << tag));
}
}
-
+
::HIR::SimplePath HirDeserialiser::deserialise_simplepath()
{
TRACE_FUNCTION;
@@ -733,7 +733,7 @@ namespace {
deserialise_pathparams()
};
}
-
+
::HIR::TraitPath HirDeserialiser::deserialise_traitpath()
{
return ::HIR::TraitPath {
@@ -770,7 +770,7 @@ namespace {
throw "";
}
}
-
+
::HIR::GenericParams HirDeserialiser::deserialise_genericparams()
{
::HIR::GenericParams params;
@@ -810,7 +810,7 @@ namespace {
throw "";
}
}
-
+
::HIR::Enum HirDeserialiser::deserialise_enum()
{
TRACE_FUNCTION;
@@ -847,7 +847,7 @@ namespace {
auto repr = static_cast< ::HIR::Union::Repr>( m_in.read_tag() );
auto variants = deserialise_vec< ::std::pair< ::std::string, ::HIR::VisEnt< ::HIR::TypeRef> > >();
auto markings = deserialise_markings();
-
+
return ::HIR::Union {
mv$(params), repr, mv$(variants), mv$(markings)
};
@@ -858,7 +858,7 @@ namespace {
auto params = deserialise_genericparams();
auto repr = static_cast< ::HIR::Struct::Repr>( m_in.read_tag() );
DEBUG("params = " << params.fmt_args() << params.fmt_bounds());
-
+
switch( m_in.read_tag() )
{
case ::HIR::Struct::Data::TAG_Unit:
@@ -889,7 +889,7 @@ namespace {
::HIR::Trait HirDeserialiser::deserialise_trait()
{
TRACE_FUNCTION;
-
+
::HIR::Trait rv {
deserialise_genericparams(),
"", // TODO: Better type for lifetime
@@ -902,7 +902,7 @@ namespace {
rv.m_type_indexes = deserialise_strumap< unsigned int>();
return rv;
}
-
+
::HIR::Literal HirDeserialiser::deserialise_literal()
{
switch( m_in.read_tag() )
@@ -923,25 +923,25 @@ namespace {
throw "";
}
}
-
+
::MIR::FunctionPointer HirDeserialiser::deserialise_mir()
{
TRACE_FUNCTION;
-
+
::MIR::Function rv;
-
+
rv.named_variables = deserialise_vec< ::HIR::TypeRef>( );
DEBUG("named_variables = " << rv.named_variables);
rv.temporaries = deserialise_vec< ::HIR::TypeRef>( );
DEBUG("temporaries = " << rv.temporaries);
rv.blocks = deserialise_vec< ::MIR::BasicBlock>( );
-
+
return ::MIR::FunctionPointer( new ::MIR::Function(mv$(rv)) );
}
::MIR::BasicBlock HirDeserialiser::deserialise_mir_basicblock()
{
TRACE_FUNCTION;
-
+
return ::MIR::BasicBlock {
deserialise_vec< ::MIR::Statement>(),
deserialise_mir_terminator()
@@ -950,7 +950,7 @@ namespace {
::MIR::Statement HirDeserialiser::deserialise_mir_statement()
{
TRACE_FUNCTION;
-
+
switch( m_in.read_tag() )
{
case 0:
@@ -971,7 +971,7 @@ namespace {
::MIR::Terminator HirDeserialiser::deserialise_mir_terminator()
{
TRACE_FUNCTION;
-
+
switch( m_in.read_tag() )
{
#define _(x, ...) case ::MIR::Terminator::TAG_##x: return ::MIR::Terminator::make_##x( __VA_ARGS__ );
@@ -1001,7 +1001,7 @@ namespace {
throw "";
}
}
-
+
::MIR::CallTarget HirDeserialiser::deserialise_mir_calltarget()
{
switch( m_in.read_tag() )
@@ -1018,27 +1018,27 @@ namespace {
throw "";
}
}
-
+
::HIR::Module HirDeserialiser::deserialise_module()
{
TRACE_FUNCTION;
-
+
::HIR::Module rv;
-
+
// m_traits doesn't need to be serialised
rv.m_value_items = deserialise_strumap< ::std::unique_ptr< ::HIR::VisEnt< ::HIR::ValueItem> > >();
rv.m_mod_items = deserialise_strumap< ::std::unique_ptr< ::HIR::VisEnt< ::HIR::TypeItem> > >();
-
+
return rv;
}
::HIR::Crate HirDeserialiser::deserialise_crate()
{
::HIR::Crate rv;
-
+
rv.m_root_module = deserialise_module();
-
+
rv.m_type_impls = deserialise_vec< ::HIR::TypeImpl>();
-
+
{
size_t n = m_in.read_count();
for(size_t i = 0; i < n; i ++)
@@ -1055,10 +1055,10 @@ namespace {
rv.m_marker_impls.insert( ::std::make_pair( mv$(p), deserialise_markerimpl() ) );
}
}
-
+
rv.m_exported_macros = deserialise_strumap< ::MacroRulesPtr>();
rv.m_lang_items = deserialise_strumap< ::HIR::SimplePath>();
-
+
{
size_t n = m_in.read_count();
for(size_t i = 0; i < n; i ++)
@@ -1067,7 +1067,7 @@ namespace {
rv.m_ext_crates.insert( ::std::make_pair(ext_crate_name, ::HIR::CratePtr{}) );
}
}
-
+
return rv;
}
}
@@ -1076,11 +1076,11 @@ namespace {
{
::HIR::serialise::Reader in { filename };
HirDeserialiser s { loaded_name, in };
-
+
try
{
::HIR::Crate rv = s.deserialise_crate();
-
+
return ::HIR::CratePtr( mv$(rv) );
}
catch(int)
diff --git a/src/hir/dump.cpp b/src/hir/dump.cpp
index 6838f40b..ea113a00 100644
--- a/src/hir/dump.cpp
+++ b/src/hir/dump.cpp
@@ -12,21 +12,21 @@
#define NODE_IS(valptr, tysuf) ( dynamic_cast<const ::HIR::ExprNode##tysuf*>(&*valptr) != nullptr )
namespace {
-
+
class TreeVisitor:
public ::HIR::Visitor,
public ::HIR::ExprVisitor
{
::std::ostream& m_os;
unsigned int m_indent_level;
-
+
public:
TreeVisitor(::std::ostream& os):
m_os(os),
m_indent_level(0)
{
}
-
+
void visit_module(::HIR::ItemPath p, ::HIR::Module& mod) override
{
if( p.get_name()[0] )
@@ -34,17 +34,17 @@ namespace {
m_os << indent() << "mod " << p.get_name() << " {\n";
inc_indent();
}
-
+
// TODO: Print publicitiy.
::HIR::Visitor::visit_module(p, mod);
-
+
if( p.get_name()[0] )
{
dec_indent();
m_os << indent() << "}\n";
}
}
-
+
void visit_type_impl(::HIR::TypeImpl& impl) override
{
m_os << indent() << "impl" << impl.m_params.fmt_args() << " " << impl.m_type << "\n";
@@ -80,7 +80,7 @@ namespace {
}
m_os << indent() << "{ }\n";
}
-
+
// - Type Items
void visit_type_alias(::HIR::ItemPath p, ::HIR::TypeAlias& item) override
{
@@ -165,7 +165,7 @@ namespace {
(Unit,
),
(Value,
- m_os << " = ?";// <<
+ m_os << " = ?";// <<
),
(Tuple,
m_os << "(";
@@ -189,7 +189,7 @@ namespace {
dec_indent();
m_os << indent() << "}\n";
}
-
+
// - Value Items
void visit_function(::HIR::ItemPath p, ::HIR::Function& item) override
{
@@ -210,7 +210,7 @@ namespace {
{
m_os << indent() << " " << item.m_params.fmt_bounds() << "\n";
}
-
+
if( item.m_code )
{
m_os << indent();
@@ -221,9 +221,9 @@ namespace {
m_os << "{\n";
inc_indent();
m_os << indent();
-
+
item.m_code->visit( *this );
-
+
m_os << "\n";
dec_indent();
m_os << indent();
@@ -255,18 +255,18 @@ namespace {
{
m_os << indent() << "const " << p.get_name() << ": " << item.m_type << " = " << item.m_value_res << ";\n";
}
-
+
// - Misc
#if 0
virtual void visit_params(::HIR::GenericParams& params);
virtual void visit_pattern(::HIR::Pattern& pat);
virtual void visit_pattern_val(::HIR::Pattern::Value& val);
virtual void visit_type(::HIR::TypeRef& tr);
-
+
enum class PathContext {
TYPE,
TRAIT,
-
+
VALUE,
};
virtual void visit_trait_path(::HIR::TraitPath& p);
@@ -276,7 +276,7 @@ namespace {
virtual void visit_expr(::HIR::ExprPtr& exp);
#endif
-
+
bool node_is_leaf(const ::HIR::ExprNode& node) {
if( NODE_IS(&node, _PathValue) )
return true;
@@ -290,7 +290,7 @@ namespace {
return true;
return false;
}
-
+
void visit(::HIR::ExprNode_Block& node) override
{
if( node.m_nodes.size() == 0 ) {
@@ -321,7 +321,7 @@ namespace {
m_os << indent() << "}";
}
}
-
+
void visit(::HIR::ExprNode_Return& node) override
{
m_os << "return";
@@ -366,7 +366,7 @@ namespace {
for(unsigned int i = 1; i < arm.m_patterns.size(); i ++ ) {
m_os << " | " << arm.m_patterns[i];
}
-
+
if( arm.m_cond ) {
m_os << " if ";
this->visit_node_ptr(arm.m_cond);
@@ -473,7 +473,7 @@ namespace {
void visit(::HIR::ExprNode_Deref& node) override
{
m_os << "*";
-
+
bool skip_parens = this->node_is_leaf(*node.m_value);
if( !skip_parens ) m_os << "(";
this->visit_node_ptr(node.m_value);
@@ -692,7 +692,7 @@ namespace {
void HIR_Dump(::std::ostream& sink, const ::HIR::Crate& crate)
{
TreeVisitor tv { sink };
-
+
tv.visit_crate( const_cast< ::HIR::Crate&>(crate) );
}
diff --git a/src/hir/expr.cpp b/src/hir/expr.cpp
index 7921cf98..46e7d886 100644
--- a/src/hir/expr.cpp
+++ b/src/hir/expr.cpp
@@ -91,10 +91,10 @@ DEF_VISIT(ExprNode_Emplace, node,
DEF_VISIT(ExprNode_TupleVariant, node,
visit_generic_path(::HIR::Visitor::PathContext::VALUE, node.m_path);
-
+
for(auto& ty : node.m_arg_types)
visit_type(ty);
-
+
for(auto& arg : node.m_args)
visit_node_ptr(arg);
)
@@ -102,7 +102,7 @@ DEF_VISIT(ExprNode_CallPath, node,
TRACE_FUNCTION_F("_CallPath: " << node.m_path);
for(auto& ty : node.m_cache.m_arg_types)
visit_type(ty);
-
+
visit_path(::HIR::Visitor::PathContext::VALUE, node.m_path);
for(auto& arg : node.m_args)
visit_node_ptr(arg);
@@ -111,7 +111,7 @@ DEF_VISIT(ExprNode_CallValue, node,
TRACE_FUNCTION_F("_CallValue:");
for(auto& ty : node.m_arg_types)
visit_type(ty);
-
+
visit_node_ptr(node.m_value);
for(auto& arg : node.m_args)
visit_node_ptr(arg);
@@ -122,7 +122,7 @@ DEF_VISIT(ExprNode_CallMethod, node,
visit_type(ty);
visit_path(::HIR::Visitor::PathContext::VALUE, node.m_method_path);
-
+
visit_node_ptr(node.m_value);
for(auto& arg : node.m_args)
visit_node_ptr(arg);
diff --git a/src/hir/expr.hpp b/src/hir/expr.hpp
index 5bb7f248..b8227aa0 100644
--- a/src/hir/expr.hpp
+++ b/src/hir/expr.hpp
@@ -46,7 +46,7 @@ public:
ValueUsage m_usage = ValueUsage::Unknown;
const Span& span() const { return m_span; }
-
+
virtual void visit(ExprVisitor& v) = 0;
ExprNode(Span sp):
m_span( mv$(sp) )
@@ -72,7 +72,7 @@ struct ExprNode_Block:
::HIR::SimplePath m_local_mod;
t_trait_list m_traits;
-
+
ExprNode_Block(Span sp):
ExprNode(mv$(sp)),
m_is_unsafe(false),
@@ -84,20 +84,20 @@ struct ExprNode_Block:
m_nodes( mv$(nodes) ),
m_yields_final(false)
{}
-
+
NODE_METHODS();
};
struct ExprNode_Return:
public ExprNode
{
::HIR::ExprNodeP m_value;
-
+
ExprNode_Return(Span sp, ::HIR::ExprNodeP value):
ExprNode(mv$(sp), ::HIR::TypeRef::new_diverge()),
m_value( mv$(value) )
{
}
-
+
NODE_METHODS();
};
struct ExprNode_Loop:
@@ -106,14 +106,14 @@ struct ExprNode_Loop:
::std::string m_label;
::HIR::ExprNodeP m_code;
bool m_diverges = false;
-
+
ExprNode_Loop(Span sp, ::std::string label, ::HIR::ExprNodeP code):
//ExprNode(mv$(sp), ::HIR::TypeRef::new_unit()),
ExprNode(mv$(sp), ::HIR::TypeRef()),
m_label( mv$(label) ),
m_code( mv$(code) )
{}
-
+
NODE_METHODS();
};
struct ExprNode_LoopControl:
@@ -128,7 +128,7 @@ struct ExprNode_LoopControl:
m_label( mv$(label) ),
m_continue( cont )
{}
-
+
NODE_METHODS();
};
struct ExprNode_Let:
@@ -137,14 +137,14 @@ struct ExprNode_Let:
::HIR::Pattern m_pattern;
::HIR::TypeRef m_type;
::HIR::ExprNodeP m_value;
-
+
ExprNode_Let(Span sp, ::HIR::Pattern pat, ::HIR::TypeRef ty, ::HIR::ExprNodeP val):
ExprNode(mv$(sp), ::HIR::TypeRef::new_unit()),
m_pattern( mv$(pat) ),
m_type( mv$(ty) ),
m_value( mv$(val) )
{}
-
+
NODE_METHODS();
};
@@ -157,7 +157,7 @@ struct ExprNode_Match:
::HIR::ExprNodeP m_cond;
::HIR::ExprNodeP m_code;
};
-
+
::HIR::ExprNodeP m_value;
::std::vector<Arm> m_arms;
@@ -176,14 +176,14 @@ struct ExprNode_If:
::HIR::ExprNodeP m_cond;
::HIR::ExprNodeP m_true;
::HIR::ExprNodeP m_false;
-
+
ExprNode_If(Span sp, ::HIR::ExprNodeP cond, ::HIR::ExprNodeP true_code, ::HIR::ExprNodeP false_code):
ExprNode( mv$(sp) ),
m_cond( mv$(cond) ),
m_true( mv$(true_code) ),
m_false( mv$(false_code) )
{}
-
+
NODE_METHODS();
};
@@ -206,17 +206,17 @@ struct ExprNode_Assign:
case Op::Mul: return "*";
case Op::Div: return "/";
case Op::Mod: return "%";
-
+
case Op::And: return "&";
case Op::Or: return "|";
case Op::Xor: return "^";
-
+
case Op::Shr: return ">>";
case Op::Shl: return "<<";
}
throw "";
}
-
+
Op m_op;
ExprNodeP m_slot;
ExprNodeP m_value;
@@ -227,7 +227,7 @@ struct ExprNode_Assign:
m_slot( mv$(slot) ),
m_value( mv$(value) )
{}
-
+
NODE_METHODS();
};
struct ExprNode_BinOp:
@@ -240,7 +240,7 @@ struct ExprNode_BinOp:
CmpLtE,
CmpGt,
CmpGtE,
-
+
BoolAnd,
BoolOr,
@@ -258,20 +258,20 @@ struct ExprNode_BinOp:
case Op::CmpLtE: return "<=";
case Op::CmpGt: return ">";
case Op::CmpGtE: return ">=";
-
+
case Op::BoolAnd: return "&&";
case Op::BoolOr: return "||";
-
+
case Op::Add: return "+";
case Op::Sub: return "-";
case Op::Mul: return "*";
case Op::Div: return "/";
case Op::Mod: return "%";
-
+
case Op::And: return "&";
case Op::Or: return "|";
case Op::Xor: return "^";
-
+
case Op::Shr: return ">>";
case Op::Shl: return "<<";
}
@@ -300,7 +300,7 @@ struct ExprNode_BinOp:
break;
}
}
-
+
NODE_METHODS();
};
struct ExprNode_UniOp:
@@ -317,7 +317,7 @@ struct ExprNode_UniOp:
}
throw "";
}
-
+
Op m_op;
::HIR::ExprNodeP m_value;
@@ -326,7 +326,7 @@ struct ExprNode_UniOp:
m_op(op),
m_value( mv$(value) )
{}
-
+
NODE_METHODS();
};
struct ExprNode_Borrow:
@@ -340,7 +340,7 @@ struct ExprNode_Borrow:
m_type(bt),
m_value( mv$(value) )
{}
-
+
NODE_METHODS();
};
struct ExprNode_Cast:
@@ -353,7 +353,7 @@ struct ExprNode_Cast:
ExprNode( mv$(sp), mv$(dst_type) ),
m_value( mv$(value) )
{}
-
+
NODE_METHODS();
};
// Magical pointer unsizing operation:
@@ -369,7 +369,7 @@ struct ExprNode_Unsize:
ExprNode( mv$(sp), mv$(dst_type) ),
m_value( mv$(value) )
{}
-
+
NODE_METHODS();
};
struct ExprNode_Index:
@@ -377,13 +377,13 @@ struct ExprNode_Index:
{
::HIR::ExprNodeP m_value;
::HIR::ExprNodeP m_index;
-
+
ExprNode_Index(Span sp, ::HIR::ExprNodeP val, ::HIR::ExprNodeP index):
ExprNode(mv$(sp)),
m_value( mv$(val) ),
m_index( mv$(index) )
{}
-
+
NODE_METHODS();
};
// unary `*`
@@ -391,12 +391,12 @@ struct ExprNode_Deref:
public ExprNode
{
::HIR::ExprNodeP m_value;
-
+
ExprNode_Deref(Span sp, ::HIR::ExprNodeP val):
ExprNode(mv$(sp)),
m_value( mv$(val) )
{}
-
+
NODE_METHODS();
};
/// `box` and `in`/`<-`
@@ -409,11 +409,11 @@ struct ExprNode_Emplace:
Placer,
Boxer,
};
-
+
Type m_type;
ExprNodeP m_place;
ExprNodeP m_value;
-
+
ExprNode_Emplace(Span sp, Type ty, ::HIR::ExprNodeP place, ::HIR::ExprNodeP val):
ExprNode( mv$(sp) ),
m_type(ty),
@@ -421,7 +421,7 @@ struct ExprNode_Emplace:
m_value( mv$(val) )
{
}
-
+
NODE_METHODS();
};
@@ -432,17 +432,17 @@ struct ExprNode_TupleVariant:
::HIR::GenericPath m_path;
bool m_is_struct;
::std::vector<ExprNodeP> m_args;
-
+
// - Cache for typeck
::std::vector< ::HIR::TypeRef> m_arg_types;
-
+
ExprNode_TupleVariant(Span sp, ::HIR::GenericPath path, bool is_struct, ::std::vector< ::HIR::ExprNodeP> args):
ExprNode(mv$(sp)),
m_path( mv$(path) ),
m_is_struct( is_struct ),
m_args( mv$(args) )
{}
-
+
NODE_METHODS();
};
@@ -452,7 +452,7 @@ struct ExprCallCache
const ::HIR::GenericParams* m_fcn_params;
const ::HIR::GenericParams* m_top_params;
const ::HIR::Function* m_fcn;
-
+
::std::function<const ::HIR::TypeRef&(const ::HIR::TypeRef&)> m_monomorph_cb;
};
@@ -461,16 +461,16 @@ struct ExprNode_CallPath:
{
::HIR::Path m_path;
::std::vector<ExprNodeP> m_args;
-
+
// - Cache for typeck
ExprCallCache m_cache;
-
+
ExprNode_CallPath(Span sp, ::HIR::Path path, ::std::vector< ::HIR::ExprNodeP> args):
ExprNode(mv$(sp)),
m_path( mv$(path) ),
m_args( mv$(args) )
{}
-
+
NODE_METHODS();
};
struct ExprNode_CallValue:
@@ -478,13 +478,13 @@ struct ExprNode_CallValue:
{
::HIR::ExprNodeP m_value;
::std::vector<ExprNodeP> m_args;
-
+
// - Argument types used as coercion targets
::std::vector< ::HIR::TypeRef> m_arg_ivars;
-
+
// - Cache for typeck
::std::vector< ::HIR::TypeRef> m_arg_types;
-
+
// Indicates what trait should/is being used for this call
// - Determined by typeck using the present trait bound (also adds borrows etc)
// - If the called value is a closure, this stays a Unknown until closure expansion
@@ -495,13 +495,13 @@ struct ExprNode_CallValue:
FnOnce,
};
TraitUsed m_trait_used = TraitUsed::Unknown;
-
+
ExprNode_CallValue(Span sp, ::HIR::ExprNodeP val, ::std::vector< ::HIR::ExprNodeP> args):
ExprNode(mv$(sp)),
m_value( mv$(val) ),
m_args( mv$(args) )
{}
-
+
NODE_METHODS();
};
struct ExprNode_CallMethod:
@@ -511,12 +511,12 @@ struct ExprNode_CallMethod:
::std::string m_method;
::HIR::PathParams m_params;
::std::vector< ::HIR::ExprNodeP> m_args;
-
+
// - Set during typeck to the real path to the method
::HIR::Path m_method_path;
// - Cache of argument/return types
ExprCallCache m_cache;
-
+
// - List of possible traits (in-scope traits that contain this method)
t_trait_list m_traits;
// - A pool of ivars to use for searching for trait impls
@@ -528,11 +528,11 @@ struct ExprNode_CallMethod:
m_method( mv$(method_name) ),
m_params( mv$(params) ),
m_args( mv$(args) ),
-
+
m_method_path( ::HIR::SimplePath("",{}) )
{
}
-
+
NODE_METHODS();
};
struct ExprNode_Field:
@@ -540,13 +540,13 @@ struct ExprNode_Field:
{
::HIR::ExprNodeP m_value;
::std::string m_field;
-
+
ExprNode_Field(Span sp, ::HIR::ExprNodeP val, ::std::string field):
ExprNode(mv$(sp)),
m_value( mv$(val) ),
m_field( mv$(field) )
{}
-
+
NODE_METHODS();
};
@@ -607,7 +607,7 @@ struct ExprNode_Literal:
)
)
}
-
+
NODE_METHODS();
};
struct ExprNode_UnitVariant:
@@ -616,13 +616,13 @@ struct ExprNode_UnitVariant:
// Path to variant/struct
::HIR::GenericPath m_path;
bool m_is_struct;
-
+
ExprNode_UnitVariant(Span sp, ::HIR::GenericPath path, bool is_struct):
ExprNode(mv$(sp)),
m_path( mv$(path) ),
m_is_struct( is_struct )
{}
-
+
NODE_METHODS();
};
struct ExprNode_PathValue:
@@ -638,13 +638,13 @@ struct ExprNode_PathValue:
};
::HIR::Path m_path;
Target m_target;
-
+
ExprNode_PathValue(Span sp, ::HIR::Path path, Target target):
ExprNode(mv$(sp)),
m_path( mv$(path) ),
m_target( target )
{}
-
+
NODE_METHODS();
};
struct ExprNode_Variable:
@@ -652,13 +652,13 @@ struct ExprNode_Variable:
{
::std::string m_name;
unsigned int m_slot;
-
+
ExprNode_Variable(Span sp, ::std::string name, unsigned int slot):
ExprNode(mv$(sp)),
m_name( mv$(name) ),
m_slot( slot )
{}
-
+
NODE_METHODS();
};
@@ -666,15 +666,15 @@ struct ExprNode_StructLiteral:
public ExprNode
{
typedef ::std::vector< ::std::pair< ::std::string, ExprNodeP > > t_values;
-
+
::HIR::GenericPath m_path;
bool m_is_struct;
::HIR::ExprNodeP m_base_value;
t_values m_values;
-
+
/// Monomorphised types of each field.
::std::vector< ::HIR::TypeRef> m_value_types;
-
+
ExprNode_StructLiteral(Span sp, ::HIR::GenericPath path, bool is_struct, ::HIR::ExprNodeP base_value, t_values values):
ExprNode( mv$(sp) ),
m_path( mv$(path) ),
@@ -685,7 +685,7 @@ struct ExprNode_StructLiteral:
// TODO: set m_res_type based on path?
// - Defer, because it requires binding ivars between m_path and m_res_type
}
-
+
NODE_METHODS();
};
struct ExprNode_UnionLiteral:
@@ -694,9 +694,9 @@ struct ExprNode_UnionLiteral:
::HIR::GenericPath m_path;
::std::string m_variant_name;
::HIR::ExprNodeP m_value;
-
+
unsigned int m_variant_index = ~0;
-
+
ExprNode_UnionLiteral(Span sp, ::HIR::GenericPath path, ::std::string name, ::HIR::ExprNodeP value):
ExprNode( mv$(sp) ),
m_path( mv$(path) ),
@@ -704,31 +704,31 @@ struct ExprNode_UnionLiteral:
m_value( mv$(value) )
{
}
-
+
NODE_METHODS();
};
struct ExprNode_Tuple:
public ExprNode
{
::std::vector< ::HIR::ExprNodeP> m_vals;
-
+
ExprNode_Tuple(Span sp, ::std::vector< ::HIR::ExprNodeP> vals):
ExprNode(mv$(sp)),
m_vals( mv$(vals) )
{}
-
+
NODE_METHODS();
};
struct ExprNode_ArrayList:
public ExprNode
{
::std::vector< ::HIR::ExprNodeP> m_vals;
-
+
ExprNode_ArrayList(Span sp, ::std::vector< ::HIR::ExprNodeP> vals):
ExprNode( mv$(sp), ::HIR::TypeRef::new_array( ::HIR::TypeRef(), vals.size() ) ),
m_vals( mv$(vals) )
{}
-
+
NODE_METHODS();
};
struct ExprNode_ArraySized:
@@ -737,14 +737,14 @@ struct ExprNode_ArraySized:
::HIR::ExprNodeP m_val;
::HIR::ExprNodeP m_size; // TODO: Has to be constant
size_t m_size_val;
-
+
ExprNode_ArraySized(Span sp, ::HIR::ExprNodeP val, ::HIR::ExprNodeP size):
ExprNode(mv$(sp)),
m_val( mv$(val) ),
m_size( mv$(size) ),
m_size_val( ~0u )
{}
-
+
NODE_METHODS();
};
@@ -752,12 +752,12 @@ struct ExprNode_Closure:
public ExprNode
{
typedef ::std::vector< ::std::pair< ::HIR::Pattern, ::HIR::TypeRef> > args_t;
-
+
args_t m_args;
::HIR::TypeRef m_return;
::HIR::ExprNodeP m_code;
bool m_is_move = false;
-
+
enum class Class {
Unknown,
NoCapture,
@@ -765,12 +765,12 @@ struct ExprNode_Closure:
Mut,
Once,
} m_class = Class::Unknown;
-
+
// - Path to the generated closure type
::HIR::GenericPath m_obj_path_base;
::HIR::GenericPath m_obj_path;
::std::vector< ::HIR::ExprNodeP> m_captures;
-
+
ExprNode_Closure(Span sp, args_t args, ::HIR::TypeRef rv, ::HIR::ExprNodeP code, bool is_move):
ExprNode(mv$(sp)),
m_args( ::std::move(args) ),
@@ -778,7 +778,7 @@ struct ExprNode_Closure:
m_code( ::std::move(code) ),
m_is_move(is_move)
{}
-
+
NODE_METHODS();
};
@@ -790,7 +790,7 @@ public:
virtual void visit_node_ptr(::std::unique_ptr<ExprNode>& node_ptr);
virtual void visit_node(ExprNode& node);
#define NV(nt) virtual void visit(nt& n) = 0;
-
+
NV(ExprNode_Block)
NV(ExprNode_Return)
NV(ExprNode_Let)
@@ -798,7 +798,7 @@ public:
NV(ExprNode_LoopControl)
NV(ExprNode_Match)
NV(ExprNode_If)
-
+
NV(ExprNode_Assign)
NV(ExprNode_BinOp)
NV(ExprNode_UniOp)
@@ -808,7 +808,7 @@ public:
NV(ExprNode_Index)
NV(ExprNode_Deref)
NV(ExprNode_Emplace)
-
+
NV(ExprNode_TupleVariant);
NV(ExprNode_CallPath);
NV(ExprNode_CallValue);
@@ -819,13 +819,13 @@ public:
NV(ExprNode_UnitVariant);
NV(ExprNode_PathValue);
NV(ExprNode_Variable);
-
+
NV(ExprNode_StructLiteral);
NV(ExprNode_UnionLiteral);
NV(ExprNode_Tuple);
NV(ExprNode_ArrayList);
NV(ExprNode_ArraySized);
-
+
NV(ExprNode_Closure);
#undef NV
};
@@ -835,7 +835,7 @@ class ExprVisitorDef:
{
public:
#define NV(nt) virtual void visit(nt& n);
-
+
NV(ExprNode_Block)
NV(ExprNode_Return)
NV(ExprNode_Let)
@@ -843,7 +843,7 @@ public:
NV(ExprNode_LoopControl)
NV(ExprNode_Match)
NV(ExprNode_If)
-
+
NV(ExprNode_Assign)
NV(ExprNode_BinOp)
NV(ExprNode_UniOp)
@@ -853,7 +853,7 @@ public:
NV(ExprNode_Index)
NV(ExprNode_Deref)
NV(ExprNode_Emplace)
-
+
NV(ExprNode_TupleVariant);
NV(ExprNode_CallPath);
NV(ExprNode_CallValue);
@@ -864,16 +864,16 @@ public:
NV(ExprNode_UnitVariant);
NV(ExprNode_PathValue);
NV(ExprNode_Variable);
-
+
NV(ExprNode_StructLiteral);
NV(ExprNode_UnionLiteral);
NV(ExprNode_Tuple);
NV(ExprNode_ArrayList);
NV(ExprNode_ArraySized);
-
+
NV(ExprNode_Closure);
#undef NV
-
+
virtual void visit_pattern(const Span& sp, ::HIR::Pattern& pat);
virtual void visit_type(::HIR::TypeRef& ty);
virtual void visit_trait_path(::HIR::TraitPath& p);
diff --git a/src/hir/expr_ptr.hpp b/src/hir/expr_ptr.hpp
index 21bc9e9d..5bedd1da 100644
--- a/src/hir/expr_ptr.hpp
+++ b/src/hir/expr_ptr.hpp
@@ -30,7 +30,7 @@ public:
x.ptr = nullptr;
}
~ExprPtrInner();
-
+
ExprPtrInner& operator=(ExprPtrInner&& x)
{
this->~ExprPtrInner();
@@ -38,7 +38,7 @@ public:
x.ptr = nullptr;
return *this;
}
-
+
::std::unique_ptr< ::HIR::ExprNode> into_unique();
operator bool () const { return ptr != nullptr; }
::HIR::ExprNode* get() const { return ptr; }
@@ -46,7 +46,7 @@ public:
this->~ExprPtrInner();
this->ptr = p;
}
-
+
::HIR::ExprNode& operator*() { return *ptr; }
const ::HIR::ExprNode& operator*() const { return *ptr; }
::HIR::ExprNode* operator->() { return ptr; }
@@ -56,21 +56,21 @@ public:
class ExprPtr
{
::HIR::ExprPtrInner node;
-
+
public:
::std::vector< ::HIR::TypeRef> m_bindings;
::std::vector< ::HIR::TypeRef> m_erased_types;
::MIR::FunctionPointer m_mir;
-
+
public:
ExprPtr() {}
ExprPtr(::std::unique_ptr< ::HIR::ExprNode> _);
-
+
::std::unique_ptr< ::HIR::ExprNode> into_unique();
operator bool () const { return node; }
::HIR::ExprNode* get() const { return node.get(); }
void reset(::HIR::ExprNode* p) { node.reset(p); }
-
+
::HIR::ExprNode& operator*() { return *node; }
const ::HIR::ExprNode& operator*() const { return *node; }
::HIR::ExprNode* operator->() { return &*node; }
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index c4e250a0..e3691f16 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -29,7 +29,7 @@
::HIR::GenericParams LowerHIR_GenericParams(const ::AST::GenericParams& gp, bool* self_is_sized)
{
::HIR::GenericParams rv;
-
+
if( gp.ty_params().size() > 0 )
{
for(const auto& tp : gp.ty_params())
@@ -61,9 +61,9 @@
),
(IsTrait,
auto type = LowerHIR_Type(e.type);
-
+
// TODO: Check for `Sized`
-
+
rv.m_bounds.push_back(::HIR::GenericBound::make_TraitBound({ mv$(type), LowerHIR_TraitPath(bound.span, e.trait) }));
rv.m_bounds.back().as_TraitBound().trait.m_hrls = e.hrls;
),
@@ -85,7 +85,7 @@
BUG(bound.span, "MaybeTrait on parameter not in parameter list (#" << ge.index << " " << param_name << ")");
}
}
-
+
// Compare with list of known default traits (just Sized atm) and set a marker
auto trait = LowerHIR_GenericPath(bound.span, e.trait);
if( trait.m_path == path_Sized ) {
@@ -105,7 +105,7 @@
(NotTrait,
TODO(bound.span, "Negative trait bounds");
),
-
+
(Equality,
rv.m_bounds.push_back(::HIR::GenericBound::make_TypeEquality({
LowerHIR_Type(e.type),
@@ -115,14 +115,14 @@
)
}
}
-
+
return rv;
}
::HIR::Pattern LowerHIR_Pattern(const ::AST::Pattern& pat)
{
TRACE_FUNCTION_F("@" << pat.span().filename << ":" << pat.span().start_line << " pat = " << pat);
-
+
::HIR::PatternBinding binding;
if( pat.binding().is_valid() )
{
@@ -135,7 +135,7 @@
}
binding = ::HIR::PatternBinding(pat.binding().m_mutable, bt, pat.binding().m_name.name, pat.binding().m_slot);
}
-
+
struct H {
static ::std::vector< ::HIR::Pattern> lowerhir_patternvec(const ::std::vector< ::AST::Pattern>& sub_patterns) {
::std::vector< ::HIR::Pattern> rv;
@@ -144,7 +144,7 @@
return rv;
}
};
-
+
TU_MATCH(::AST::Pattern::Data, (pat.data()), (e),
(MaybeBind,
BUG(pat.span(), "Encountered MaybeBind pattern");
@@ -178,7 +178,7 @@
(Tuple,
auto leading = H::lowerhir_patternvec( e.start );
auto trailing = H::lowerhir_patternvec( e.end );
-
+
if( e.has_wildcard )
{
return ::HIR::Pattern {
@@ -199,7 +199,7 @@
};
}
),
-
+
(StructTuple,
unsigned int leading_count = e.tup_pat.start.size();
unsigned int trailing_count = e.tup_pat.end .size();
@@ -219,7 +219,7 @@
field_count = var.as_Tuple().size();
}
::std::vector<HIR::Pattern> sub_patterns;
-
+
if( e.tup_pat.has_wildcard ) {
sub_patterns.reserve( field_count );
if( leading_count + trailing_count > field_count ) {
@@ -238,13 +238,13 @@
}
else {
assert( trailing_count == 0 );
-
+
if( leading_count != field_count ) {
ERROR(pat.span(), E0000, "Enum variant pattern has a mismatched field count - " << field_count << " exp, got " << leading_count);
}
sub_patterns = H::lowerhir_patternvec( e.tup_pat.start );
}
-
+
return ::HIR::Pattern {
mv$(binding),
::HIR::Pattern::Data::make_EnumTuple({
@@ -268,7 +268,7 @@
field_count = pb.hir->m_data.as_Tuple().size();
}
::std::vector<HIR::Pattern> sub_patterns;
-
+
if( e.tup_pat.has_wildcard ) {
sub_patterns.reserve( field_count );
if( leading_count + trailing_count > field_count ) {
@@ -287,13 +287,13 @@
}
else {
assert( trailing_count == 0 );
-
+
if( leading_count != field_count ) {
ERROR(pat.span(), E0000, "Struct pattern has a mismatched field count - " << field_count << " exp, got " << leading_count);
}
sub_patterns = H::lowerhir_patternvec( e.tup_pat.start );
}
-
+
return ::HIR::Pattern {
mv$(binding),
::HIR::Pattern::Data::make_StructTuple({
@@ -309,8 +309,8 @@
::std::vector< ::std::pair< ::std::string, ::HIR::Pattern> > sub_patterns;
for(const auto& sp : e.sub_patterns)
sub_patterns.push_back( ::std::make_pair(sp.first, LowerHIR_Pattern(sp.second)) );
-
-
+
+
TU_MATCH_DEF(::AST::PathBinding, (e.path.binding()), (pb),
(
BUG(pat.span(), "Encountered Struct pattern not pointing to a enum variant or a struct - " << e.path);
@@ -350,7 +350,7 @@
)
)
),
-
+
(Value,
struct H {
static ::HIR::CoreType get_int_type(const Span& sp, const ::eCoreType ct) {
@@ -369,11 +369,11 @@
case CORETYPE_INT: return ::HIR::CoreType::Isize;
case CORETYPE_UINT: return ::HIR::CoreType::Usize;
-
+
case CORETYPE_CHAR: return ::HIR::CoreType::Char;
-
+
case CORETYPE_BOOL: return ::HIR::CoreType::Bool;
-
+
default:
BUG(sp, "Unknown type for integer literal in pattern - " << ct );
}
@@ -451,17 +451,17 @@
::std::vector< ::HIR::Pattern> leading;
for(const auto& sp : e.leading)
leading.push_back( LowerHIR_Pattern(sp) );
-
+
::std::vector< ::HIR::Pattern> trailing;
for(const auto& sp : e.trailing)
trailing.push_back( LowerHIR_Pattern(sp) );
-
+
auto extra_bind = e.extra_bind.is_valid()
// TODO: Share code with the outer binding code
? ::HIR::PatternBinding(false, ::HIR::PatternBinding::Type::Ref, e.extra_bind.m_name.name, e.extra_bind.m_slot)
: ::HIR::PatternBinding()
;
-
+
return ::HIR::Pattern {
mv$(binding),
::HIR::Pattern::Data::make_SplitSlice({
@@ -509,7 +509,7 @@
throw "BUG: Encountered path with parameters when creating ::HIR::GenericPath";
}
}
-
+
rv.m_components.push_back( node.name() );
}
return rv;
@@ -521,7 +521,7 @@
::HIR::PathParams LowerHIR_PathParams(const Span& sp, const ::AST::PathParams& src_params, bool allow_assoc)
{
::HIR::PathParams params;
-
+
// TODO: Lifetime params (not encoded in ::HIR::PathNode as yet)
//for(const auto& param : src_params.m_lifetimes) {
//}
@@ -529,7 +529,7 @@
for(const auto& param : src_params.m_types) {
params.m_types.push_back( LowerHIR_Type(param) );
}
-
+
// Leave 'm_assoc' alone?
if( !allow_assoc && src_params.m_assoc.size() > 0 )
{
@@ -559,12 +559,12 @@
{},
nullptr
};
-
+
for(const auto& assoc : path.nodes().back().args().m_assoc)
{
rv.m_type_bounds.insert(::std::make_pair( assoc.first, LowerHIR_Type(assoc.second) ));
}
-
+
return rv;
}
::HIR::Path LowerHIR_Path(const Span& sp, const ::AST::Path& path)
@@ -654,7 +654,7 @@
case CORETYPE_STR : return ::HIR::TypeRef( ::HIR::CoreType::Str );
case CORETYPE_F32: return ::HIR::TypeRef( ::HIR::CoreType::F32 );
case CORETYPE_F64: return ::HIR::TypeRef( ::HIR::CoreType::F64 );
-
+
case CORETYPE_I8 : return ::HIR::TypeRef( ::HIR::CoreType::I8 );
case CORETYPE_U8 : return ::HIR::TypeRef( ::HIR::CoreType::U8 );
case CORETYPE_I16: return ::HIR::TypeRef( ::HIR::CoreType::I16 );
@@ -700,14 +700,14 @@
return ::HIR::TypeRef::new_array( mv$(inner), size_val );
}
}
-
+
return ::HIR::TypeRef::new_array( mv$(inner), LowerHIR_Expr(e.size) );
}
else {
return ::HIR::TypeRef::new_slice( mv$(inner) );
}
),
-
+
(Path,
TU_IFLET(::AST::Path::Class, e.path.m_class, Local, l,
unsigned int slot;
@@ -754,7 +754,7 @@
//if( e.hrls.size() > 0 )
// TODO(ty.span(), "ErasedType with HRLS - " << ty);
ASSERT_BUG(ty.span(), e.traits.size() > 0, "ErasedType with no traits");
-
+
::std::vector< ::HIR::TraitPath> traits;
for(const auto& t : e.traits)
{
@@ -810,7 +810,7 @@ namespace {
{
TRACE_FUNCTION_F(path);
::HIR::Struct::Data data;
-
+
TU_MATCH(::AST::StructData, (ent.m_data), (e),
(Tuple,
if( e.ents.size() == 0 ) {
@@ -818,10 +818,10 @@ namespace {
}
else {
::HIR::Struct::Data::Data_Tuple fields;
-
+
for(const auto& field : e.ents)
fields.push_back( { field.m_is_public, LowerHIR_Type(field.m_type) } );
-
+
data = ::HIR::Struct::Data::make_Tuple( mv$(fields) );
}
),
@@ -844,7 +844,7 @@ namespace {
::HIR::Enum LowerHIR_Enum(::HIR::ItemPath path, const ::AST::Enum& f)
{
::std::vector< ::std::pair< ::std::string, ::HIR::Enum::Variant> > variants;
-
+
for(const auto& var : f.variants())
{
TU_MATCH(::AST::EnumVariantData, (var.m_data), (e),
@@ -875,7 +875,7 @@ namespace {
)
)
}
-
+
return ::HIR::Enum {
LowerHIR_GenericParams(f.params(), nullptr),
// TODO: Get repr from attributes
@@ -886,7 +886,7 @@ namespace {
::HIR::Union LowerHIR_Union(::HIR::ItemPath path, const ::AST::Union& f, const ::AST::MetaItems& attrs)
{
auto repr = ::HIR::Union::Repr::Rust;
-
+
if( const auto* attr_repr = attrs.get("repr") )
{
const auto& repr_str = attr_repr->string();
@@ -897,11 +897,11 @@ namespace {
// TODO: Error?
}
}
-
+
::HIR::Struct::Data::Data_Named variants;
for(const auto& field : f.m_variants)
variants.push_back( ::std::make_pair( field.m_name, new_visent(field.m_is_public, LowerHIR_Type(field.m_type)) ) );
-
+
return ::HIR::Union {
LowerHIR_GenericParams(f.m_params, nullptr),
repr,
@@ -913,7 +913,7 @@ namespace {
TRACE_FUNCTION_F(trait_path);
bool trait_reqires_sized = false;
auto params = LowerHIR_GenericParams(f.params(), &trait_reqires_sized);
-
+
::std::string lifetime;
::std::vector< ::HIR::TraitPath> supertraits;
for(const auto& st : f.supertraits()) {
@@ -939,12 +939,12 @@ namespace {
}
rv.m_params.m_bounds.push_back( ::HIR::GenericBound::make_TraitBound({ ::HIR::TypeRef("Self",0xFFFF), { mv$(this_trait) } }) );
}
-
+
for(const auto& item : f.items())
{
auto trait_ip = ::HIR::ItemPath(trait_path);
auto item_path = ::HIR::ItemPath( trait_ip, item.name.c_str() );
-
+
TU_MATCH_DEF(::AST::Item, (item.data), (i),
(
BUG(item.data.span, "Encountered unexpected item type in trait");
@@ -1003,23 +1003,23 @@ namespace {
)
)
}
-
+
rv.m_is_marker = f.is_marker();
-
+
return rv;
}
::HIR::Function LowerHIR_Function(::HIR::ItemPath p, const ::AST::MetaItems& attrs, const ::AST::Function& f, const ::HIR::TypeRef& self_type)
{
static Span sp;
-
+
TRACE_FUNCTION_F(p);
-
+
::std::vector< ::std::pair< ::HIR::Pattern, ::HIR::TypeRef > > args;
for(const auto& arg : f.args())
args.push_back( ::std::make_pair( LowerHIR_Pattern(arg.first), LowerHIR_Type(arg.second) ) );
-
+
auto receiver = ::HIR::Function::Receiver::Free;
-
+
if( args.size() > 0 && args.front().first.m_binding.m_name == "self" )
{
const auto& arg_self_ty = args.front().second;
@@ -1051,15 +1051,15 @@ namespace {
)
else {
}
-
+
if( receiver == ::HIR::Function::Receiver::Free )
{
ERROR(sp, E0000, "Unknown receiver type - " << arg_self_ty);
}
}
-
+
::HIR::Linkage linkage;
-
+
// Convert #[link_name/no_mangle] attributes into the name
if( const auto* a = attrs.get("link_name") )
{
@@ -1083,13 +1083,13 @@ namespace {
{
// Leave linkage.name as empty
}
-
+
// If there's no code, demangle the name (TODO: By ABI) and set linkage.
if( linkage.name == "" && ! f.code().is_valid() )
{
linkage.name = p.get_name();
}
-
+
return ::HIR::Function {
mv$(linkage),
receiver,
@@ -1112,19 +1112,19 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H
{
TRACE_FUNCTION_F("path = " << path);
::HIR::Module mod { };
-
+
mod.m_traits = mv$(traits);
-
+
// Populate trait list
for(const auto& item : ast_mod.m_type_items)
{
if( item.second.path.binding().is_Trait() ) {
auto sp = LowerHIR_SimplePath(Span(), item.second.path);
if( ::std::find(mod.m_traits.begin(), mod.m_traits.end(), sp) == mod.m_traits.end() )
- mod.m_traits.push_back( mv$(sp) );
+ mod.m_traits.push_back( mv$(sp) );
}
}
-
+
for( unsigned int i = 0; i < ast_mod.anon_mods().size(); i ++ )
{
const auto& submod_ptr = ast_mod.anon_mods()[i];
@@ -1216,7 +1216,7 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H
)
)
}
-
+
Span mod_span;
for( const auto& ie : ast_mod.m_namespace_items )
{
@@ -1243,7 +1243,7 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H
if( ie.second.is_import ) {
auto hir_path = LowerHIR_SimplePath( sp, ie.second.path );
::HIR::ValueItem vi;
-
+
TU_MATCH_DEF( ::AST::PathBinding, (ie.second.path.binding()), (pb),
(
DEBUG("Import VAL " << ie.first << " = " << hir_path);
@@ -1257,14 +1257,14 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H
_add_mod_val_item(mod, ie.first, ie.second.is_pub, mv$(vi));
}
}
-
+
return mod;
}
void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crate)
{
DEBUG(ast_mod.path());
-
+
// Sub-modules
for( const auto& item : ast_mod.items() )
{
@@ -1278,16 +1278,16 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
LowerHIR_Module_Impls(*submod_ptr, hir_crate);
}
}
-
- //
+
+ //
for( const auto& i : ast_mod.items() )
{
if( !i.data.is_Impl() ) continue;
const auto& impl = i.data.as_Impl();
auto params = LowerHIR_GenericParams(impl.def().params(), nullptr);
-
+
TRACE_FUNCTION_F("IMPL " << impl.def());
-
+
if( impl.def().trait().ent.is_valid() )
{
const auto& pb = impl.def().trait().ent.binding();
@@ -1297,18 +1297,18 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
auto trait_path = LowerHIR_GenericPath(impl.def().trait().sp, impl.def().trait().ent);
auto trait_name = mv$(trait_path.m_path);
auto trait_args = mv$(trait_path.m_params);
-
+
if( !is_marker )
{
auto type = LowerHIR_Type(impl.def().type());
-
+
::HIR::ItemPath path(type, trait_name, trait_args);
DEBUG(path);
-
+
::std::map< ::std::string, ::HIR::TraitImpl::ImplEnt< ::HIR::Function> > methods;
::std::map< ::std::string, ::HIR::TraitImpl::ImplEnt< ::HIR::Constant> > constants;
::std::map< ::std::string, ::HIR::TraitImpl::ImplEnt< ::HIR::TypeRef> > types;
-
+
for(const auto& item : impl.items())
{
::HIR::ItemPath item_path(path, item.name.c_str());
@@ -1343,17 +1343,17 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
)
)
}
-
+
hir_crate.m_trait_impls.insert( ::std::make_pair(mv$(trait_name), ::HIR::TraitImpl {
mv$(params),
mv$(trait_args),
mv$(type),
-
+
mv$(methods),
mv$(constants),
{}, // Statics
mv$(types),
-
+
LowerHIR_SimplePath(Span(), ast_mod.path())
}) );
}
@@ -1369,7 +1369,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
mv$(trait_args),
true,
mv$(type),
-
+
LowerHIR_SimplePath(Span(), ast_mod.path())
} ) );
}
@@ -1379,10 +1379,10 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
// Inherent impls
auto type = LowerHIR_Type(impl.def().type());
::HIR::ItemPath path(type);
-
+
::std::map< ::std::string, ::HIR::TypeImpl::VisImplEnt< ::HIR::Function> > methods;
::std::map< ::std::string, ::HIR::TypeImpl::VisImplEnt< ::HIR::Constant> > constants;
-
+
for(const auto& item : impl.items())
{
::HIR::ItemPath item_path(path, item.name.c_str());
@@ -1413,13 +1413,13 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
)
)
}
-
+
hir_crate.m_type_impls.push_back( ::HIR::TypeImpl {
mv$(params),
mv$(type),
mv$(methods),
mv$(constants),
-
+
LowerHIR_SimplePath(Span(), ast_mod.path())
} );
}
@@ -1428,19 +1428,19 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
{
if( !i.data.is_NegImpl() ) continue;
const auto& impl = i.data.as_NegImpl();
-
+
auto params = LowerHIR_GenericParams(impl.params(), nullptr);
auto type = LowerHIR_Type(impl.type());
auto trait = LowerHIR_GenericPath(impl.trait().sp, impl.trait().ent);
auto trait_name = mv$(trait.m_path);
auto trait_args = mv$(trait.m_params);
-
+
hir_crate.m_marker_impls.insert( ::std::make_pair( mv$(trait_name), ::HIR::MarkerImpl {
mv$(params),
mv$(trait_args),
false,
mv$(type),
-
+
LowerHIR_SimplePath(Span(), ast_mod.path())
} ) );
}
@@ -1456,7 +1456,7 @@ public:
IndexVisitor(const ::HIR::Crate& crate):
crate(crate)
{}
-
+
void visit_params(::HIR::GenericParams& params) override
{
for( auto& bound : params.m_bounds )
@@ -1478,7 +1478,7 @@ public:
g_crate_ptr = &rv;
g_core_crate = (crate.m_load_std == ::AST::Crate::LOAD_NONE ? "" : "core");
auto& macros = rv.m_exported_macros;
-
+
// - Extract exported macros
{
::std::vector< ::AST::Module*> mods;
@@ -1487,7 +1487,7 @@ public:
{
auto& mod = *mods.back();
mods.pop_back();
-
+
for( /*const*/ auto& mac : mod.macros() ) {
if( mac.data->m_exported ) {
auto res = macros.insert( ::std::make_pair( mac.name, mv$(mac.data) ) );
@@ -1498,13 +1498,13 @@ public:
DEBUG("- Non-exported " << mac.name << "!");
}
}
-
+
for(auto& i : mod.items()) {
if( i.data.is_Module() )
mods.push_back( &i.data.as_Module() );
}
} while( mods.size() > 0 );
-
+
for( auto& mac : crate.m_root_module.macro_imports_res() ) {
if( mac.data->m_exported && mac.name != "" ) {
auto v = ::std::make_pair( mac.name, MacroRulesPtr(new MacroRules( mv$(*const_cast<MacroRules*>(mac.data)) )) );
@@ -1521,7 +1521,7 @@ public:
}
}
}
-
+
auto sp = Span();
// - Store the lang item paths so conversion code can use them.
for( const auto& lang_item_path : crate.m_lang_items )
@@ -1544,14 +1544,14 @@ public:
rv.m_ext_crates.insert( ::std::make_pair( ext_crate.first, mv$(ext_crate.second.m_hir) ) );
}
path_Sized = rv.get_lang_item_path(sp, "sized");
-
+
rv.m_root_module = LowerHIR_Module( crate.m_root_module, ::HIR::ItemPath() );
-
+
LowerHIR_Module_Impls(crate.m_root_module, rv);
-
+
// Set all pointers in the HIR to the correct (now fixed) locations
IndexVisitor(rv).visit_crate( rv );
-
+
g_crate_ptr = nullptr;
return ::HIR::CratePtr( mv$(rv) );
}
diff --git a/src/hir/from_ast_expr.cpp b/src/hir/from_ast_expr.cpp
index 273e2b04..39b33e53 100644
--- a/src/hir/from_ast_expr.cpp
+++ b/src/hir/from_ast_expr.cpp
@@ -25,7 +25,7 @@ struct LowerHIR_ExprNode_Visitor:
public ::AST::NodeVisitor
{
::std::unique_ptr< ::HIR::ExprNode> m_rv;
-
+
virtual void visit(::AST::ExprNode_Block& v) override {
auto rv = new ::HIR::ExprNode_Block(v.span());
for(const auto& n : v.m_nodes)
@@ -34,13 +34,13 @@ struct LowerHIR_ExprNode_Visitor:
rv->m_nodes.push_back( LowerHIR_ExprNode_Inner( *n ) );
}
rv->m_yields_final = v.m_yields_final_value;
-
+
if( v.m_local_mod )
{
// TODO: Populate m_traits from the local module's import list
rv->m_local_mod = LowerHIR_SimplePath(v.span(), v.m_local_mod->path());
}
-
+
m_rv.reset( static_cast< ::HIR::ExprNode*>(rv) );
}
virtual void visit(::AST::ExprNode_Macro& v) override {
@@ -78,15 +78,15 @@ struct LowerHIR_ExprNode_Visitor:
case ::AST::ExprNode_Assign::NONE: return ::HIR::ExprNode_Assign::Op::None;
case ::AST::ExprNode_Assign::ADD: return ::HIR::ExprNode_Assign::Op::Add;
case ::AST::ExprNode_Assign::SUB: return ::HIR::ExprNode_Assign::Op::Sub;
-
+
case ::AST::ExprNode_Assign::DIV: return ::HIR::ExprNode_Assign::Op::Mul;
case ::AST::ExprNode_Assign::MUL: return ::HIR::ExprNode_Assign::Op::Div;
case ::AST::ExprNode_Assign::MOD: return ::HIR::ExprNode_Assign::Op::Mod;
-
+
case ::AST::ExprNode_Assign::AND: return ::HIR::ExprNode_Assign::Op::And;
case ::AST::ExprNode_Assign::OR : return ::HIR::ExprNode_Assign::Op::Or ;
case ::AST::ExprNode_Assign::XOR: return ::HIR::ExprNode_Assign::Op::Xor;
-
+
case ::AST::ExprNode_Assign::SHR: return ::HIR::ExprNode_Assign::Op::Shr;
case ::AST::ExprNode_Assign::SHL: return ::HIR::ExprNode_Assign::Op::Shl;
}
@@ -109,13 +109,13 @@ struct LowerHIR_ExprNode_Visitor:
auto path_RangeFrom = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeFrom"}) );
auto path_RangeTo = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeTo"}) );
auto path_RangeFull = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeFull"}) );
-
+
::HIR::ExprNode_StructLiteral::t_values values;
if( v.m_left )
values.push_back( ::std::make_pair( ::std::string("start"), LowerHIR_ExprNode_Inner( *v.m_left ) ) );
if( v.m_right )
values.push_back( ::std::make_pair( ::std::string("end") , LowerHIR_ExprNode_Inner( *v.m_right ) ) );
-
+
if( v.m_left ) {
if( v.m_right ) {
m_rv.reset( new ::HIR::ExprNode_StructLiteral(v.span(), mv$(path_Range), true, nullptr, mv$(values)) );
@@ -137,7 +137,7 @@ struct LowerHIR_ExprNode_Visitor:
// NOTE: Not language items
auto path_RangeInclusive_NonEmpty = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeInclusive", "NonEmpty"}) );
auto path_RangeToInclusive = ::HIR::GenericPath( ::HIR::SimplePath(g_core_crate, {"ops", "RangeToInclusive"}) );
-
+
if( v.m_left )
{
::HIR::ExprNode_StructLiteral::t_values values;
@@ -155,7 +155,7 @@ struct LowerHIR_ExprNode_Visitor:
case ::AST::ExprNode_BinOp::PLACE_IN:
TODO(v.get_pos(), "Desugar placement syntax");
break;
-
+
case ::AST::ExprNode_BinOp::CMPEQU : op = ::HIR::ExprNode_BinOp::Op::CmpEqu ; if(0)
case ::AST::ExprNode_BinOp::CMPNEQU: op = ::HIR::ExprNode_BinOp::Op::CmpNEqu; if(0)
case ::AST::ExprNode_BinOp::CMPLT : op = ::HIR::ExprNode_BinOp::Op::CmpLt ; if(0)
@@ -164,7 +164,7 @@ struct LowerHIR_ExprNode_Visitor:
case ::AST::ExprNode_BinOp::CMPGTE: op = ::HIR::ExprNode_BinOp::Op::CmpGtE; if(0)
case ::AST::ExprNode_BinOp::BOOLAND: op = ::HIR::ExprNode_BinOp::Op::BoolAnd; if(0)
case ::AST::ExprNode_BinOp::BOOLOR : op = ::HIR::ExprNode_BinOp::Op::BoolOr ; if(0)
-
+
case ::AST::ExprNode_BinOp::BITAND: op = ::HIR::ExprNode_BinOp::Op::And; if(0)
case ::AST::ExprNode_BinOp::BITOR : op = ::HIR::ExprNode_BinOp::Op::Or ; if(0)
case ::AST::ExprNode_BinOp::BITXOR: op = ::HIR::ExprNode_BinOp::Op::Xor; if(0)
@@ -175,7 +175,7 @@ struct LowerHIR_ExprNode_Visitor:
case ::AST::ExprNode_BinOp::SUB: op = ::HIR::ExprNode_BinOp::Op::Sub; if(0)
case ::AST::ExprNode_BinOp::SHR: op = ::HIR::ExprNode_BinOp::Op::Shr; if(0)
case ::AST::ExprNode_BinOp::SHL: op = ::HIR::ExprNode_BinOp::Op::Shl;
-
+
m_rv.reset( new ::HIR::ExprNode_BinOp( v.span(),
op,
LowerHIR_ExprNode_Inner( *v.m_left ),
@@ -201,14 +201,14 @@ struct LowerHIR_ExprNode_Visitor:
case ::AST::ExprNode_UniOp::QMARK:
BUG(v.get_pos(), "Encounterd question mark operator (should have been expanded in AST)");
break;
-
+
case ::AST::ExprNode_UniOp::REF:
m_rv.reset(new ::HIR::ExprNode_Borrow(v.span(), ::HIR::BorrowType::Shared, LowerHIR_ExprNode_Inner( *v.m_value ) ));
break;
case ::AST::ExprNode_UniOp::REFMUT:
m_rv.reset(new ::HIR::ExprNode_Borrow(v.span(), ::HIR::BorrowType::Unique, LowerHIR_ExprNode_Inner( *v.m_value ) ));
break;
-
+
case ::AST::ExprNode_UniOp::INVERT: op = ::HIR::ExprNode_UniOp::Op::Invert; if(0)
case ::AST::ExprNode_UniOp::NEGATE: op = ::HIR::ExprNode_UniOp::Op::Negate;
m_rv.reset( new ::HIR::ExprNode_UniOp( v.span(),
@@ -231,12 +231,12 @@ struct LowerHIR_ExprNode_Visitor:
LowerHIR_Type(v.m_type)
) );
}
-
+
virtual void visit(::AST::ExprNode_CallPath& v) override {
::std::vector< ::HIR::ExprNodeP> args;
for(const auto& arg : v.m_args)
args.push_back( LowerHIR_ExprNode_Inner(*arg) );
-
+
TU_IFLET(::AST::Path::Class, v.m_path.m_class, Local, e,
m_rv.reset( new ::HIR::ExprNode_CallValue( v.span(),
::HIR::ExprNodeP(new ::HIR::ExprNode_Variable( v.span(), e.name, v.m_path.binding().as_Variable().slot )),
@@ -274,12 +274,12 @@ struct LowerHIR_ExprNode_Visitor:
::std::vector< ::HIR::ExprNodeP> args;
for(const auto& arg : v.m_args)
args.push_back( LowerHIR_ExprNode_Inner(*arg) );
-
+
// TODO: Should this be abstracted?
::HIR::PathParams params;
for(const auto& param : v.m_method.args().m_types)
params.m_types.push_back( LowerHIR_Type(param) );
-
+
m_rv.reset( new ::HIR::ExprNode_CallMethod( v.span(),
LowerHIR_ExprNode_Inner(*v.m_val),
v.m_method.name(),
@@ -291,7 +291,7 @@ struct LowerHIR_ExprNode_Visitor:
::std::vector< ::HIR::ExprNodeP> args;
for(const auto& arg : v.m_args)
args.push_back( LowerHIR_ExprNode_Inner(*arg) );
-
+
m_rv.reset( new ::HIR::ExprNode_CallValue( v.span(),
LowerHIR_ExprNode_Inner(*v.m_val),
mv$(args)
@@ -315,7 +315,7 @@ struct LowerHIR_ExprNode_Visitor:
::HIR::ExprNodeP( new ::HIR::ExprNode_LoopControl(v.span(), v.m_label, false) )
)) );
code.push_back( LowerHIR_ExprNode_Inner(*v.m_code) );
-
+
m_rv.reset( new ::HIR::ExprNode_Loop( v.span(),
v.m_label,
::HIR::ExprNodeP(new ::HIR::ExprNode_Block( v.span(), false, mv$(code)))
@@ -323,7 +323,7 @@ struct LowerHIR_ExprNode_Visitor:
break; }
case ::AST::ExprNode_Loop::WHILELET: {
::std::vector< ::HIR::ExprNode_Match::Arm> arms;
-
+
// - Matches pattern - Run inner code
arms.push_back(::HIR::ExprNode_Match::Arm {
::make_vec1( LowerHIR_Pattern(v.m_pattern) ),
@@ -336,7 +336,7 @@ struct LowerHIR_ExprNode_Visitor:
::HIR::ExprNodeP(),
::HIR::ExprNodeP( new ::HIR::ExprNode_LoopControl( v.span(), v.m_label, false) )
});
-
+
m_rv.reset( new ::HIR::ExprNode_Loop( v.span(),
v.m_label,
::HIR::ExprNodeP(new ::HIR::ExprNode_Match( v.span(),
@@ -350,7 +350,7 @@ struct LowerHIR_ExprNode_Visitor:
BUG(v.get_pos(), "Encountered still-sugared for loop");
break;
}
-
+
// TODO: Iterate the constructed loop and determine if there are any `break` statements pointing to it
{
struct LoopVisitor:
@@ -359,13 +359,13 @@ struct LowerHIR_ExprNode_Visitor:
const ::std::string& top_label;
bool top_is_broken;
::std::vector< const ::std::string*> name_stack;
-
+
LoopVisitor(const ::std::string& top_label):
top_label(top_label),
top_is_broken(false),
name_stack()
{}
-
+
void visit(::HIR::ExprNode_Loop& node) override {
if( node.m_label != "" ) {
this->name_stack.push_back( &node.m_label );
@@ -377,7 +377,7 @@ struct LowerHIR_ExprNode_Visitor:
}
void visit(::HIR::ExprNode_LoopControl& node) override {
::HIR::ExprVisitorDef::visit(node);
-
+
if( node.m_continue ) {
}
else {
@@ -395,7 +395,7 @@ struct LowerHIR_ExprNode_Visitor:
}
}
};
-
+
auto& loop_node = dynamic_cast< ::HIR::ExprNode_Loop&>(*m_rv);;
LoopVisitor lv { loop_node.m_label };
loop_node.m_code->visit(lv);
@@ -407,7 +407,7 @@ struct LowerHIR_ExprNode_Visitor:
}
virtual void visit(::AST::ExprNode_Match& v) override {
::std::vector< ::HIR::ExprNode_Match::Arm> arms;
-
+
for(const auto& arm : v.m_arms)
{
::HIR::ExprNode_Match::Arm new_arm {
@@ -415,13 +415,13 @@ struct LowerHIR_ExprNode_Visitor:
LowerHIR_ExprNode_Inner_Opt(arm.m_cond.get()),
LowerHIR_ExprNode_Inner(*arm.m_code)
};
-
+
for(const auto& pat : arm.m_patterns)
new_arm.m_patterns.push_back( LowerHIR_Pattern(pat) );
-
+
arms.push_back( mv$(new_arm) );
}
-
+
m_rv.reset( new ::HIR::ExprNode_Match( v.span(),
LowerHIR_ExprNode_Inner(*v.m_val),
mv$(arms)
@@ -436,7 +436,7 @@ struct LowerHIR_ExprNode_Visitor:
}
virtual void visit(::AST::ExprNode_IfLet& v) override {
::std::vector< ::HIR::ExprNode_Match::Arm> arms;
-
+
// - Matches pattern - Take true branch
arms.push_back(::HIR::ExprNode_Match::Arm {
::make_vec1( LowerHIR_Pattern(v.m_pattern) ),
@@ -454,7 +454,7 @@ struct LowerHIR_ExprNode_Visitor:
mv$(arms)
));
}
-
+
virtual void visit(::AST::ExprNode_Integer& v) override {
struct H {
static ::HIR::CoreType get_type(Span sp, ::eCoreType ct) {
@@ -473,9 +473,9 @@ struct LowerHIR_ExprNode_Visitor:
case CORETYPE_INT: return ::HIR::CoreType::Isize;
case CORETYPE_UINT: return ::HIR::CoreType::Usize;
-
+
case CORETYPE_CHAR: return ::HIR::CoreType::Char;
-
+
default:
BUG(sp, "Unknown type for integer literal - " << coretype_name(ct));
}
@@ -544,7 +544,7 @@ struct LowerHIR_ExprNode_Visitor:
ERROR(v.span(), E0000, "Union constructors can only specify a single field");
if( v.m_base_value )
ERROR(v.span(), E0000, "Union constructors can't take a base value");
-
+
m_rv.reset( new ::HIR::ExprNode_UnionLiteral( v.span(),
LowerHIR_GenericPath(v.get_pos(), v.m_path),
v.m_values[0].first,
@@ -645,7 +645,7 @@ struct LowerHIR_ExprNode_Visitor:
const auto& enm = *e.enum_;
auto it = ::std::find_if(enm.variants().begin(), enm.variants().end(), [&](const auto& x){ return x.m_name == var_name; });
assert(it != enm.variants().end());
-
+
var_idx = static_cast<unsigned int>(it - enm.variants().begin());
if( it->m_data.is_Struct() ) {
ERROR(v.span(), E0000, "Named value referring to an enum that isn't tuple-like or unit-like - " << v.m_path);
@@ -657,7 +657,7 @@ struct LowerHIR_ExprNode_Visitor:
const auto& enm = *e.hir;
auto it = ::std::find_if(enm.m_variants.begin(), enm.m_variants.end(), [&](const auto& x){ return x.first == var_name; });
assert(it != enm.m_variants.end());
-
+
var_idx = static_cast<unsigned int>(it - enm.m_variants.begin());
if( it->second.is_Struct() ) {
ERROR(v.span(), E0000, "Named value referring to an enum that isn't tuple-like or unit-like - " << v.m_path);
@@ -698,7 +698,7 @@ struct LowerHIR_ExprNode_Visitor:
)
}
}
-
+
virtual void visit(::AST::ExprNode_Field& v) override {
m_rv.reset( new ::HIR::ExprNode_Field( v.span(),
LowerHIR_ExprNode_Inner(*v.m_obj),
@@ -721,9 +721,9 @@ struct LowerHIR_ExprNode_Visitor:
::std::unique_ptr< ::HIR::ExprNode> LowerHIR_ExprNode_Inner(const ::AST::ExprNode& e)
{
LowerHIR_ExprNode_Visitor v;
-
+
const_cast<::AST::ExprNode*>(&e)->visit( v );
-
+
if( ! v.m_rv ) {
BUG(e.get_pos(), typeid(e).name() << " - Yielded a nullptr HIR node");
}
diff --git a/src/hir/generic_params.cpp b/src/hir/generic_params.cpp
index 54290731..984d8a3a 100644
--- a/src/hir/generic_params.cpp
+++ b/src/hir/generic_params.cpp
@@ -21,7 +21,7 @@ namespace HIR {
)
return os;
}
-
+
::std::ostream& operator<<(::std::ostream& os, const ::HIR::GenericParams::PrintArgs& x)
{
if( x.gp.m_lifetimes.size() > 0 || x.gp.m_types.size() > 0 )
diff --git a/src/hir/generic_params.hpp b/src/hir/generic_params.hpp
index 79ce2cb9..8753ae7e 100644
--- a/src/hir/generic_params.hpp
+++ b/src/hir/generic_params.hpp
@@ -44,13 +44,13 @@ class GenericParams
public:
::std::vector<TypeParamDef> m_types;
::std::vector< ::std::string> m_lifetimes;
-
+
::std::vector<GenericBound> m_bounds;
-
+
//GenericParams() {}
-
+
GenericParams clone() const;
-
+
struct PrintArgs {
const GenericParams& gp;
PrintArgs(const GenericParams& gp): gp(gp) {}
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp
index 0ae4a786..2ec4d40b 100644
--- a/src/hir/hir.cpp
+++ b/src/hir/hir.cpp
@@ -45,7 +45,7 @@ namespace HIR {
)
return os;
}
-
+
bool operator==(const Literal& l, const Literal& r)
{
if( l.tag() != r.tag() )
@@ -96,7 +96,7 @@ const ::HIR::Enum::Variant* ::HIR::Enum::get_variant(const ::std::string& name)
namespace {
bool matches_genericpath(const ::HIR::GenericParams& params, const ::HIR::GenericPath& left, const ::HIR::GenericPath& right, ::HIR::t_cb_resolve_type ty_res, bool expand_generic);
-
+
bool matches_type_int(const ::HIR::GenericParams& params, const ::HIR::TypeRef& left, const ::HIR::TypeRef& right_in, ::HIR::t_cb_resolve_type ty_res, bool expand_generic)
{
assert(! left.m_data.is_Infer() );
@@ -105,9 +105,9 @@ namespace {
expand_generic = false;
//DEBUG("left = " << left << ", right = " << right);
-
+
// TODO: What indicates what out of ty_res?
-
+
if( right.m_data.is_Infer() ) {
//DEBUG("left = " << left << ", right = " << right);
switch(right.m_data.as_Infer().ty_class)
@@ -135,7 +135,7 @@ namespace {
}
throw "";
}
-
+
// A local generic could match anything, leave that up to the caller
if( left.m_data.is_Generic() ) {
return true;
@@ -150,7 +150,7 @@ namespace {
if( right.m_data.is_Generic() ) {
return left.m_data.is_Generic();
}
-
+
if( left.m_data.tag() != right.m_data.tag() ) {
return false;
}
@@ -247,7 +247,7 @@ namespace {
if( left.m_path.m_components[i] != right.m_path.m_components[i] )
return false;
}
-
+
if( left.m_params.m_types.size() > 0 || right.m_params.m_types.size() > 0 ) {
if( left.m_params.m_types.size() != right.m_params.m_types.size() ) {
return true;
@@ -316,11 +316,11 @@ bool ::HIR::MarkerImpl::matches_type(const ::HIR::TypeRef& type, ::HIR::t_cb_res
namespace {
::Ordering typelist_ord_specific(const Span& sp, const ::std::vector<::HIR::TypeRef>& left, const ::std::vector<::HIR::TypeRef>& right);
-
+
::Ordering type_ord_specific(const Span& sp, const ::HIR::TypeRef& left, const ::HIR::TypeRef& right)
{
// TODO: What happens if you get `impl<T> Foo<T> for T` vs `impl<T,U> Foo<U> for T`
-
+
// A generic can't be more specific than any other type we can see
// - It's equally as specific as another Generic, so still false
if( left.m_data.is_Generic() ) {
@@ -330,7 +330,7 @@ namespace {
if( right.m_data.is_Generic() ) {
return ::OrdGreater;
}
-
+
TU_MATCH(::HIR::TypeRef::Data, (left.m_data), (le),
(Generic,
throw "";
@@ -436,7 +436,7 @@ namespace {
)
throw "Fell off end of type_ord_specific";
}
-
+
::Ordering typelist_ord_specific(const Span& sp, const ::std::vector<::HIR::TypeRef>& le, const ::std::vector<::HIR::TypeRef>& re)
{
auto rv = ::OrdEqual;
@@ -459,7 +459,7 @@ namespace {
assert( cur_trait.m_trait_ptr );
const auto& tr = *cur_trait.m_trait_ptr;
auto monomorph_cb = monomorphise_type_get_cb(sp, &type, &cur_trait.m_path.m_params, nullptr);
-
+
for(const auto& trait_path_raw : tr.m_parent_traits)
{
// 1. Monomorph
@@ -469,7 +469,7 @@ namespace {
// 3. Add
rv.push_back( ::HIR::GenericBound::make_TraitBound({ type.clone(), mv$(trait_path_mono) }) );
}
-
+
// TODO: Add traits from `Self: Foo` bounds?
}
::std::vector< ::HIR::GenericBound> flatten_bounds(const ::std::vector<::HIR::GenericBound>& bounds)
@@ -501,7 +501,7 @@ bool ::HIR::TraitImpl::more_specific_than(const ::HIR::TraitImpl& other) const
{
static const Span _sp;
const Span& sp = _sp;
-
+
// >> https://github.com/rust-lang/rfcs/blob/master/text/1210-impl-specialization.md#defining-the-precedence-rules
// 1. If this->m_type is less specific than other.m_type: return false
if( type_ord_specific(sp, this->m_type, other.m_type) == ::OrdLess ) {
@@ -511,9 +511,9 @@ bool ::HIR::TraitImpl::more_specific_than(const ::HIR::TraitImpl& other) const
if( typelist_ord_specific(sp, this->m_trait_args.m_types, other.m_trait_args.m_types) == ::OrdLess ) {
return false;
}
-
+
//assert(m_params.m_types.size() == other.m_params.m_types.size());
-
+
if( other.m_params.m_bounds.size() == 0 ) {
return m_params.m_bounds.size() > 0;
}
@@ -523,13 +523,13 @@ bool ::HIR::TraitImpl::more_specific_than(const ::HIR::TraitImpl& other) const
auto bounds_o = flatten_bounds(other.m_params.m_bounds);
::std::sort(bounds_t.begin(), bounds_t.end(), [](const auto& a, const auto& b){ return ::ord(a,b) == OrdLess; });
::std::sort(bounds_o.begin(), bounds_o.end(), [](const auto& a, const auto& b){ return ::ord(a,b) == OrdLess; });
-
+
DEBUG("bounds_t = " << bounds_t);
DEBUG("bounds_o = " << bounds_o);
-
+
if( bounds_t.size() < bounds_o.size() )
return false;
-
+
auto it_t = bounds_t.begin();
for(auto it_o = bounds_o.begin(); it_o != bounds_o.end(); ++it_o)
{
@@ -569,7 +569,7 @@ const ::HIR::SimplePath& ::HIR::Crate::get_lang_item_path_opt(const char* name)
const ::HIR::TypeItem& ::HIR::Crate::get_typeitem_by_path(const Span& sp, const ::HIR::SimplePath& path, bool ignore_crate_name) const
{
ASSERT_BUG(sp, path.m_components.size() > 0, "get_typeitem_by_path received invalid path - " << path);
-
+
const ::HIR::Module* mod;
if( !ignore_crate_name && path.m_crate_name != "" ) {
ASSERT_BUG(sp, m_ext_crates.count(path.m_crate_name) > 0, "Crate '" << path.m_crate_name << "' not loaded");
@@ -596,14 +596,14 @@ const ::HIR::TypeItem& ::HIR::Crate::get_typeitem_by_path(const Span& sp, const
if( it == mod->m_mod_items.end() ) {
BUG(sp, "Could not find type name in " << path);
}
-
+
return it->second->ent;
}
const ::HIR::Module& ::HIR::Crate::get_mod_by_path(const Span& sp, const ::HIR::SimplePath& path) const
{
if( path.m_components.size() == 0 )
- {
+ {
if( path.m_crate_name != "" )
{
ASSERT_BUG(sp, m_ext_crates.count(path.m_crate_name) > 0, "Crate '" << path.m_crate_name << "' not loaded");
@@ -622,7 +622,7 @@ const ::HIR::Module& ::HIR::Crate::get_mod_by_path(const Span& sp, const ::HIR::
)
else {
BUG(sp, "Module path " << path << " didn't point to a module");
- }
+ }
}
}
const ::HIR::Trait& ::HIR::Crate::get_trait_by_path(const Span& sp, const ::HIR::SimplePath& path) const
@@ -697,7 +697,7 @@ const ::HIR::ValueItem& ::HIR::Crate::get_valitem_by_path(const Span& sp, const
if( it == mod->m_value_items.end() ) {
BUG(sp, "Could not find value name " << path);
}
-
+
return it->second->ent;
}
const ::HIR::Function& ::HIR::Crate::get_function_by_path(const Span& sp, const ::HIR::SimplePath& path) const
diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp
index 5f1f55f0..2f8c39bb 100644
--- a/src/hir/hir.hpp
+++ b/src/hir/hir.hpp
@@ -78,10 +78,10 @@ struct Linkage
Weak, // Weak linkage (multiple definitions are allowed
External, // Force the symbol to be externally visible
};
-
+
// Linkage type
Type type = Type::Auto;
-
+
// External symbol name
::std::string name;
};
@@ -92,16 +92,16 @@ public:
Linkage m_linkage;
bool m_is_mut;
TypeRef m_type;
-
+
ExprPtr m_value;
-
+
Literal m_value_res;
};
struct Constant
{
// NOTE: The generics can't influence the value of this `const`
GenericParams m_params;
-
+
TypeRef m_type;
ExprPtr m_value;
Literal m_value_res;
@@ -119,24 +119,24 @@ public:
//PointerConst,
Box,
};
-
+
typedef ::std::vector< ::std::pair< ::HIR::Pattern, ::HIR::TypeRef> > args_t;
-
+
Linkage m_linkage;
-
+
Receiver m_receiver;
::std::string m_abi;
bool m_unsafe;
bool m_const;
-
+
GenericParams m_params;
-
+
args_t m_args;
bool m_variadic;
TypeRef m_return;
-
+
ExprPtr m_code;
-
+
//::HIR::TypeRef make_ty(const Span& sp, const ::HIR::PathParams& params) const;
};
@@ -157,17 +157,17 @@ struct TraitMarkings
{
/// There is at least one Unsize impl for this type
bool can_unsize = false;
-
+
/// Indicates that there is at least one Deref impl
bool has_a_deref = false;
-
+
/// Indicates that there is a Drop impl
/// - If there is an impl, there must be an applicable impl to every instance.
bool has_drop_impl = false;
-
+
// If populated, indicates the field that is the coercable pointer.
unsigned int coerce_unsized_index = ~0u;
-
+
// TODO: This would have to be changed for custom DSTs
enum class DstType {
None, // Sized
@@ -176,7 +176,7 @@ struct TraitMarkings
TraitObject, // (Trait)
} dst_type;
unsigned int unsized_field = ~0u;
-
+
/// `true` if there is a Copy impl
bool is_copy = false;
@@ -186,7 +186,7 @@ struct TraitMarkings
// Implementation state
bool is_impled;
};
-
+
// General auto trait impls
mutable ::std::map< ::HIR::SimplePath, AutoMarking> auto_impls;
};
@@ -209,13 +209,13 @@ public:
C,
U8, U16, U32,
};
-
+
GenericParams m_params;
Repr m_repr;
::std::vector< ::std::pair< ::std::string, Variant > > m_variants;
-
+
TraitMarkings m_markings;
-
+
const Variant* get_variant(const ::std::string& ) const;
};
class Struct
@@ -233,11 +233,11 @@ public:
(Tuple, t_tuple_fields),
(Named, t_struct_fields)
);
-
+
GenericParams m_params;
Repr m_repr;
Data m_data;
-
+
TraitMarkings m_markings;
};
class Union
@@ -248,11 +248,11 @@ public:
Rust,
C,
};
-
+
GenericParams m_params;
Repr m_repr;
t_struct_fields m_variants;
-
+
TraitMarkings m_markings;
};
@@ -273,17 +273,17 @@ struct Trait
GenericParams m_params;
::std::string m_lifetime;
::std::vector< ::HIR::TraitPath > m_parent_traits;
-
+
bool m_is_marker; // aka OIBIT
-
+
::std::unordered_map< ::std::string, AssociatedType > m_types;
::std::unordered_map< ::std::string, TraitValueItem > m_values;
-
+
// Indexes into the vtable for each present method and value
::std::unordered_multimap< ::std::string, ::std::pair<unsigned int,::HIR::GenericPath> > m_value_indexes;
// Indexes in the vtable parameter list for each associated type
::std::unordered_map< ::std::string, unsigned int > m_type_indexes;
-
+
Trait( GenericParams gps, ::std::string lifetime, ::std::vector< ::HIR::TraitPath> parents):
m_params( mv$(gps) ),
m_lifetime( mv$(lifetime) ),
@@ -297,12 +297,12 @@ class Module
public:
// List of in-scope traits in this module
::std::vector< ::HIR::SimplePath> m_traits;
-
+
// Contains all values and functions (including type constructors)
::std::unordered_map< ::std::string, ::std::unique_ptr<VisEnt<ValueItem>> > m_value_items;
// Contains types, traits, and modules
::std::unordered_map< ::std::string, ::std::unique_ptr<VisEnt<TypeItem>> > m_mod_items;
-
+
Module() {}
Module(const Module&) = delete;
Module(Module&& x) = default;
@@ -344,12 +344,12 @@ public:
::HIR::GenericParams m_params;
::HIR::TypeRef m_type;
-
+
::std::map< ::std::string, VisImplEnt< ::HIR::Function> > m_methods;
::std::map< ::std::string, VisImplEnt< ::HIR::Constant> > m_constants;
::HIR::SimplePath m_src_module;
-
+
bool matches_type(const ::HIR::TypeRef& tr, t_cb_resolve_type ty_res) const;
bool matches_type(const ::HIR::TypeRef& tr) const {
return matches_type(tr, [](const auto& x)->const auto&{ return x; });
@@ -368,20 +368,20 @@ public:
::HIR::GenericParams m_params;
::HIR::PathParams m_trait_args;
::HIR::TypeRef m_type;
-
+
::std::map< ::std::string, ImplEnt< ::HIR::Function> > m_methods;
::std::map< ::std::string, ImplEnt< ::HIR::Constant> > m_constants;
::std::map< ::std::string, ImplEnt< ::HIR::Static> > m_statics;
-
+
::std::map< ::std::string, ImplEnt< ::HIR::TypeRef> > m_types;
-
+
::HIR::SimplePath m_src_module;
-
+
bool matches_type(const ::HIR::TypeRef& tr, t_cb_resolve_type ty_res) const;
bool matches_type(const ::HIR::TypeRef& tr) const {
return matches_type(tr, [](const auto& x)->const auto&{ return x; });
}
-
+
bool more_specific_than(const TraitImpl& x) const;
};
@@ -392,9 +392,9 @@ public:
::HIR::PathParams m_trait_args;
bool is_positive;
::HIR::TypeRef m_type;
-
+
::HIR::SimplePath m_src_module;
-
+
bool matches_type(const ::HIR::TypeRef& tr, t_cb_resolve_type ty_res) const;
bool matches_type(const ::HIR::TypeRef& tr) const {
return matches_type(tr, [](const auto& x)->const auto&{ return x; });
@@ -405,35 +405,35 @@ class Crate
{
public:
Module m_root_module;
-
+
/// Impl blocks on just a type
::std::vector< ::HIR::TypeImpl > m_type_impls;
/// Impl blocks
::std::multimap< ::HIR::SimplePath, ::HIR::TraitImpl > m_trait_impls;
::std::multimap< ::HIR::SimplePath, ::HIR::MarkerImpl > m_marker_impls;
-
+
/// Macros exported by this crate
::std::unordered_map< ::std::string, ::MacroRulesPtr > m_exported_macros;
-
+
/// Language items avaliable through this crate (includes ones from loaded externs)
::std::unordered_map< ::std::string, ::HIR::SimplePath> m_lang_items;
-
+
::std::unordered_map< ::std::string, ::HIR::CratePtr> m_ext_crates;
-
+
/// Method called to populate runtime state after deserialisation
/// See hir/crate_post_load.cpp
void post_load_update(const ::std::string& loaded_name);
-
+
const ::HIR::SimplePath& get_lang_item_path(const Span& sp, const char* name) const;
const ::HIR::SimplePath& get_lang_item_path_opt(const char* name) const;
-
+
const ::HIR::TypeItem& get_typeitem_by_path(const Span& sp, const ::HIR::SimplePath& path, bool ignore_crate_name=false) const;
const ::HIR::Trait& get_trait_by_path(const Span& sp, const ::HIR::SimplePath& path) const;
const ::HIR::Struct& get_struct_by_path(const Span& sp, const ::HIR::SimplePath& path) const;
const ::HIR::Union& get_union_by_path(const Span& sp, const ::HIR::SimplePath& path) const;
const ::HIR::Enum& get_enum_by_path(const Span& sp, const ::HIR::SimplePath& path) const;
const ::HIR::Module& get_mod_by_path(const Span& sp, const ::HIR::SimplePath& path) const;
-
+
const ::HIR::ValueItem& get_valitem_by_path(const Span& sp, const ::HIR::SimplePath& path, bool ignore_crate_name=false) const;
const ::HIR::Function& get_function_by_path(const Span& sp, const ::HIR::SimplePath& path) const;
const ::HIR::Static& get_static_by_path(const Span& sp, const ::HIR::SimplePath& path) const {
@@ -454,7 +454,7 @@ public:
BUG(sp, "`const` path " << path << " didn't point to an enum");
}
}
-
+
bool find_trait_impls(const ::HIR::SimplePath& path, const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::TraitImpl&)> callback) const;
bool find_auto_trait_impls(const ::HIR::SimplePath& path, const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::MarkerImpl&)> callback) const;
bool find_type_impls(const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::TypeImpl&)> callback) const;
diff --git a/src/hir/item_path.hpp b/src/hir/item_path.hpp
index 8ed140af..606c6817 100644
--- a/src/hir/item_path.hpp
+++ b/src/hir/item_path.hpp
@@ -17,7 +17,7 @@ public:
const ::HIR::SimplePath* trait = nullptr;
const ::HIR::PathParams* trait_params = nullptr;
const char* name = nullptr;
-
+
ItemPath() {}
ItemPath(const ItemPath& p, const char* n):
parent(&p),
@@ -34,10 +34,10 @@ public:
ItemPath(const ::HIR::SimplePath& path):
trait(&path)
{}
-
+
const ::HIR::SimplePath* trait_path() const { return trait; }
const ::HIR::PathParams* trait_args() const { return trait_params; }
-
+
::HIR::SimplePath get_simple_path() const {
if( parent ) {
assert(name);
@@ -51,7 +51,7 @@ public:
::HIR::Path get_full_path() const {
assert(parent);
assert(name);
-
+
if( parent->name ) {
return get_simple_path();
}
@@ -65,14 +65,14 @@ public:
const char* get_name() const {
return name ? name : "";
}
-
+
ItemPath operator+(const ::std::string& name) const {
return ItemPath(*this, name.c_str());
}
-
+
bool operator==(const ::HIR::SimplePath& sp) const {
if( sp.m_crate_name != "" ) return false;
-
+
unsigned int i = sp.m_components.size();
const auto* n = this;
while( n && i -- )
@@ -87,7 +87,7 @@ public:
return false;
return true;
}
-
+
friend ::std::ostream& operator<<(::std::ostream& os, const ItemPath& x) {
if( x.parent ) {
os << *x.parent;
diff --git a/src/hir/path.cpp b/src/hir/path.cpp
index 73d1b92f..e6dab41f 100644
--- a/src/hir/path.cpp
+++ b/src/hir/path.cpp
@@ -12,9 +12,9 @@
{
::HIR::SimplePath ret(m_crate_name);
ret.m_components = m_components;
-
+
ret.m_components.push_back( s );
-
+
return ret;
}
namespace HIR {
@@ -38,7 +38,7 @@ namespace HIR {
::std::ostream& operator<<(::std::ostream& os, const PathParams& x)
{
bool has_args = ( x.m_types.size() > 0 );
-
+
if(has_args) {
os << "<";
}
@@ -65,7 +65,7 @@ namespace HIR {
}
os << x.m_path.m_path;
bool has_args = ( x.m_path.m_params.m_types.size() > 0 || x.m_type_bounds.size() > 0 );
-
+
if(has_args) {
os << "<";
}
@@ -160,10 +160,10 @@ bool ::HIR::GenericPath::operator==(const GenericPath& x) const
{},
m_trait_ptr
};
-
+
for( const auto& assoc : m_type_bounds )
rv.m_type_bounds.insert(::std::make_pair( assoc.first, assoc.second.clone() ));
-
+
return rv;
}
bool ::HIR::TraitPath::operator==(const ::HIR::TraitPath& x) const
@@ -172,10 +172,10 @@ bool ::HIR::TraitPath::operator==(const ::HIR::TraitPath& x) const
return false;
if( m_hrls != x.m_hrls )
return false;
-
+
if( m_type_bounds.size() != x.m_type_bounds.size() )
return false;
-
+
for(auto it_l = m_type_bounds.begin(), it_r = x.m_type_bounds.begin(); it_l != m_type_bounds.end(); it_l++, it_r++ ) {
if( it_l->first != it_r->first )
return false;
@@ -237,7 +237,7 @@ bool ::HIR::TraitPath::operator==(const ::HIR::TraitPath& x) const
::HIR::Compare HIR::PathParams::compare_with_placeholders(const Span& sp, const ::HIR::PathParams& x, ::HIR::t_cb_resolve_type resolve_placeholder) const
{
using ::HIR::Compare;
-
+
auto rv = Compare::Equal;
if( this->m_types.size() > 0 || x.m_types.size() > 0 ) {
if( this->m_types.size() != x.m_types.size() ) {
@@ -283,7 +283,7 @@ bool ::HIR::TraitPath::operator==(const ::HIR::TraitPath& x) const
if( this->m_path.m_components[i] != x.m_path.m_components[i] )
return Compare::Unequal;
}
-
+
return this->m_params. compare_with_placeholders(sp, x.m_params, resolve_placeholder);
}
@@ -319,9 +319,9 @@ namespace {
auto rv = m_path .compare_with_placeholders(sp, x.m_path, resolve_placeholder);
if( rv == Compare::Unequal )
return rv;
-
+
// TODO: HRLs
-
+
auto it_l = m_type_bounds.begin();
auto it_r = x.m_type_bounds.begin();
while( it_l != m_type_bounds.end() && it_r != x.m_type_bounds.end() )
@@ -333,12 +333,12 @@ namespace {
++ it_l;
++ it_r;
}
-
+
if( it_l != m_type_bounds.end() || it_r != x.m_type_bounds.end() )
{
return Compare::Unequal;
}
-
+
return rv;
}
@@ -353,7 +353,7 @@ namespace {
(UfcsUnknown,
if( ple.item != pre.item)
return Compare::Unequal;
-
+
TODO(sp, "Path::compare_with_placeholders - UfcsUnknown");
),
(UfcsInherent,
@@ -367,7 +367,7 @@ namespace {
(UfcsKnown,
if( ple.item != pre.item)
return Compare::Unequal;
-
+
::HIR::Compare rv = ::HIR::Compare::Equal;
CMP(rv, ple.type->compare_with_placeholders(sp, *pre.type, resolve_placeholder));
CMP(rv, ::compare_with_placeholders(sp, ple.trait, pre.trait, resolve_placeholder));
diff --git a/src/hir/path.hpp b/src/hir/path.hpp
index e6b4e381..80fb4caa 100644
--- a/src/hir/path.hpp
+++ b/src/hir/path.hpp
@@ -72,7 +72,7 @@ struct SimplePath
}
SimplePath clone() const;
-
+
SimplePath operator+(const ::std::string& s) const;
bool operator==(const SimplePath& x) const {
return m_crate_name == x.m_crate_name && m_components == x.m_components;
@@ -98,7 +98,7 @@ struct SimplePath
struct PathParams
{
::std::vector<TypeRef> m_types;
-
+
PathParams();
PathParams(::HIR::TypeRef );
PathParams clone() const;
@@ -106,10 +106,10 @@ struct PathParams
PathParams& operator=(const PathParams&) = delete;
PathParams(PathParams&&) = default;
PathParams& operator=(PathParams&&) = default;
-
+
Compare compare_with_placeholders(const Span& sp, const PathParams& x, t_cb_resolve_type resolve_placeholder) const;
Compare match_test_generics_fuzz(const Span& sp, const PathParams& x, t_cb_resolve_type resolve_placeholder, t_cb_match_generics) const;
-
+
bool operator==(const PathParams& x) const;
bool operator!=(const PathParams& x) const { return !(*this == x); }
bool operator<(const PathParams& x) const { return ord(x) == OrdLess; }
@@ -130,14 +130,14 @@ public:
GenericPath();
GenericPath(::HIR::SimplePath sp);
GenericPath(::HIR::SimplePath sp, ::HIR::PathParams params);
-
+
GenericPath clone() const;
Compare compare_with_placeholders(const Span& sp, const GenericPath& x, t_cb_resolve_type resolve_placeholder) const;
-
+
bool operator==(const GenericPath& x) const;
bool operator!=(const GenericPath& x) const { return !(*this == x); }
bool operator<(const GenericPath& x) const { return ord(x) == OrdLess; }
-
+
Ordering ord(const GenericPath& x) const {
auto rv = ::ord(m_path, x.m_path);
if(rv != OrdEqual) return rv;
@@ -154,21 +154,21 @@ public:
::std::vector< ::std::string> m_hrls;
// TODO: Each bound should list its origin trait
::std::map< ::std::string, ::HIR::TypeRef> m_type_bounds;
-
+
const ::HIR::Trait* m_trait_ptr;
-
+
TraitPath clone() const;
Compare compare_with_placeholders(const Span& sp, const TraitPath& x, t_cb_resolve_type resolve_placeholder) const;
-
+
bool operator==(const TraitPath& x) const;
bool operator!=(const TraitPath& x) const { return !(*this == x); }
-
+
Ordering ord(const TraitPath& x) const {
ORD(m_path, x.m_path);
ORD(m_hrls, x.m_hrls);
return ::ord(m_type_bounds, x.m_type_bounds);
}
-
+
friend ::std::ostream& operator<<(::std::ostream& os, const TraitPath& x);
};
@@ -207,19 +207,19 @@ public:
{}
Path(GenericPath _);
Path(SimplePath _);
-
+
Path(TypeRef ty, ::std::string item, PathParams item_params=PathParams());
Path(TypeRef ty, GenericPath trait, ::std::string item, PathParams item_params=PathParams());
-
+
Path clone() const;
Compare compare_with_placeholders(const Span& sp, const Path& x, t_cb_resolve_type resolve_placeholder) const;
-
+
Ordering ord(const Path& x) const;
-
+
bool operator==(const Path& x) const;
bool operator!=(const Path& x) const { return !(*this == x); }
bool operator<(const Path& x) const { return ord(x) == OrdLess; }
-
+
friend ::std::ostream& operator<<(::std::ostream& os, const Path& x);
};
diff --git a/src/hir/pattern.cpp b/src/hir/pattern.cpp
index 71b0a9bb..74528aeb 100644
--- a/src/hir/pattern.cpp
+++ b/src/hir/pattern.cpp
@@ -90,14 +90,14 @@ namespace HIR {
os << ns.first << ": " << ns.second << ", ";
os << "}";
),
-
+
(Value,
os << e.val;
),
(Range,
os << e.start << " ... " << e.end;
),
-
+
(EnumValue,
os << e.path;
),
@@ -154,7 +154,7 @@ namespace {
rv.push_back( ::std::make_pair(field.first, field.second.clone()) );
return rv;
}
-
+
::HIR::Pattern::Value clone_patval(const ::HIR::Pattern::Value& val) {
TU_MATCH(::HIR::Pattern::Value, (val), (e),
(Integer,
@@ -225,7 +225,7 @@ namespace {
e.is_exhaustive
}));
),
-
+
(Value,
return Pattern(m_binding, Data::make_Value({
clone_patval(e.val)
@@ -237,7 +237,7 @@ namespace {
clone_patval(e.end)
}));
),
-
+
(EnumValue,
return Pattern(m_binding, Data::make_EnumValue({ e.path.clone(), e.binding_ptr, e.binding_idx }));
),
@@ -271,7 +271,7 @@ namespace {
}));
)
)
-
+
throw "";
}
diff --git a/src/hir/pattern.hpp b/src/hir/pattern.hpp
index f86907fb..51e20c5c 100644
--- a/src/hir/pattern.hpp
+++ b/src/hir/pattern.hpp
@@ -26,14 +26,14 @@ struct PatternBinding
Ref,
MutRef,
};
-
+
bool m_mutable;
Type m_type;
::std::string m_name;
unsigned int m_slot;
-
+
bool is_valid() const { return m_name != ""; }
-
+
PatternBinding():
m_mutable(false),
m_type(Type::Move),
@@ -67,7 +67,7 @@ struct Pattern
})
);
friend ::std::ostream& operator<<(::std::ostream& os, const Pattern::Value& x);
-
+
enum class GlobPos {
None,
Start,
@@ -136,7 +136,7 @@ struct Pattern
PatternBinding m_binding;
Data m_data;
-
+
Pattern() {}
Pattern(PatternBinding pb, Data d):
m_binding( mv$(pb) ),
@@ -146,9 +146,9 @@ struct Pattern
Pattern(Pattern&&) = default;
Pattern& operator=(const Pattern&) = delete;
Pattern& operator=(Pattern&&) = default;
-
+
Pattern clone() const;
-
+
friend ::std::ostream& operator<<(::std::ostream& os, const Pattern& x);
};
diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp
index 0acd95ea..0dfb9b01 100644
--- a/src/hir/serialise.cpp
+++ b/src/hir/serialise.cpp
@@ -20,7 +20,7 @@ namespace {
HirSerialiser(::HIR::serialise::Writer& out):
m_out( out )
{}
-
+
template<typename V>
void serialise_strmap(const ::std::map< ::std::string,V>& map)
{
@@ -77,7 +77,7 @@ namespace {
m_out.write_count(e.first);
serialise(e.second);
}
-
+
void serialise_type(const ::HIR::TypeRef& ty)
{
m_out.write_tag( ty.m_data.tag() );
@@ -107,7 +107,7 @@ namespace {
(ErasedType,
serialise_path(e.m_origin);
m_out.write_count(e.m_index);
-
+
m_out.write_count(e.m_traits.size());
for(const auto& t : e.m_traits)
serialise_traitpath(t);
@@ -233,12 +233,12 @@ namespace {
)
)
}
-
-
+
+
void serialise_crate(const ::HIR::Crate& crate)
{
serialise_module(crate.m_root_module);
-
+
m_out.write_count(crate.m_type_impls.size());
for(const auto& impl : crate.m_type_impls) {
serialise_typeimpl(impl);
@@ -253,10 +253,10 @@ namespace {
serialise_simplepath(tr_impl.first);
serialise_markerimpl(tr_impl.second);
}
-
+
serialise_strmap(crate.m_exported_macros);
serialise_strmap(crate.m_lang_items);
-
+
m_out.write_count(crate.m_ext_crates.size());
for(const auto& ext : crate.m_ext_crates)
m_out.write_string(ext.first);
@@ -264,9 +264,9 @@ namespace {
void serialise_module(const ::HIR::Module& mod)
{
TRACE_FUNCTION;
-
+
// m_traits doesn't need to be serialised
-
+
serialise_strmap(mod.m_value_items);
serialise_strmap(mod.m_mod_items);
}
@@ -275,7 +275,7 @@ namespace {
TRACE_FUNCTION_F("impl" << impl.m_params.fmt_args() << " " << impl.m_type);
serialise_generics(impl.m_params);
serialise_type(impl.m_type);
-
+
m_out.write_count(impl.m_methods.size());
for(const auto& v : impl.m_methods) {
m_out.write_string(v.first);
@@ -298,7 +298,7 @@ namespace {
serialise_generics(impl.m_params);
serialise_pathparams(impl.m_trait_args);
serialise_type(impl.m_type);
-
+
m_out.write_count(impl.m_methods.size());
for(const auto& v : impl.m_methods) {
DEBUG("fn " << v.first);
@@ -336,7 +336,7 @@ namespace {
m_out.write_bool(impl.is_positive);
serialise_type(impl.m_type);
}
-
+
void serialise(const ::HIR::TypeRef& ty) {
serialise_type(ty);
}
@@ -408,10 +408,10 @@ namespace {
Serialiser_TextTree ser(tmp);
tok.serialise( ser );
}
-
+
m_out.write_string(tmp.str());
}
-
+
void serialise(const ::HIR::Literal& lit)
{
m_out.write_tag(lit.tag());
@@ -440,7 +440,7 @@ namespace {
)
)
}
-
+
void serialise(const ::HIR::ExprPtr& exp)
{
m_out.write_bool( (bool)exp.m_mir );
@@ -659,7 +659,7 @@ namespace {
)
)
}
-
+
void serialise(const ::HIR::TypeItem& item)
{
TU_MATCHA( (item), (e),
@@ -726,27 +726,27 @@ namespace {
)
)
}
-
+
void serialise(unsigned int v) { m_out.write_count(v); };
-
+
void serialise(const ::HIR::Linkage& linkage)
{
//m_out.write_tag( static_cast<int>(linkage.type) );
m_out.write_string( linkage.name );
}
-
+
// - Value items
void serialise(const ::HIR::Function& fcn)
{
TRACE_FUNCTION_F("_function:");
-
+
serialise(fcn.m_linkage);
-
+
m_out.write_tag( static_cast<int>(fcn.m_receiver) );
m_out.write_string(fcn.m_abi);
m_out.write_bool(fcn.m_unsafe);
m_out.write_bool(fcn.m_const);
-
+
serialise_generics(fcn.m_params);
m_out.write_count(fcn.m_args.size());
for(const auto& a : fcn.m_args)
@@ -754,13 +754,13 @@ namespace {
m_out.write_bool(fcn.m_variadic);
serialise(fcn.m_return);
DEBUG("m_args = " << fcn.m_args);
-
+
serialise(fcn.m_code);
}
void serialise(const ::HIR::Constant& item)
{
TRACE_FUNCTION_F("_constant:");
-
+
serialise_generics(item.m_params);
serialise(item.m_type);
serialise(item.m_value);
@@ -769,15 +769,15 @@ namespace {
void serialise(const ::HIR::Static& item)
{
TRACE_FUNCTION_F("_static:");
-
+
serialise(item.m_linkage);
-
+
m_out.write_bool(item.m_is_mut);
serialise(item.m_type);
-
+
serialise(item.m_value_res);
}
-
+
// - Type items
void serialise(const ::HIR::TypeAlias& ta)
{
@@ -788,9 +788,9 @@ namespace {
{
serialise_generics(item.m_params);
m_out.write_tag( static_cast<int>(item.m_repr) );
-
+
serialise_vec( item.m_variants );
-
+
serialise(item.m_markings);
}
void serialise(const ::HIR::Enum::Variant& v)
@@ -811,7 +811,7 @@ namespace {
)
)
}
-
+
void serialise(const ::HIR::TraitMarkings& m)
{
uint8_t bitflag_1 = 0;
@@ -822,7 +822,7 @@ namespace {
BIT(3, m.has_drop_impl)
#undef BIT
m_out.write_u8(bitflag_1);
-
+
m_out.write_tag( static_cast<unsigned int>(m.dst_type) );
m_out.write_count( m.coerce_unsized_index );
m_out.write_count( m.unsized_field );
@@ -832,10 +832,10 @@ namespace {
void serialise(const ::HIR::Struct& item)
{
TRACE_FUNCTION_F("Struct");
-
+
serialise_generics(item.m_params);
m_out.write_tag( static_cast<int>(item.m_repr) );
-
+
m_out.write_tag( item.m_data.tag() );
TU_MATCHA( (item.m_data), (e),
(Unit,
@@ -847,18 +847,18 @@ namespace {
serialise_vec(e);
)
)
-
+
serialise(item.m_markings);
}
void serialise(const ::HIR::Union& item)
{
TRACE_FUNCTION_F("Union");
-
+
serialise_generics(item.m_params);
m_out.write_tag( static_cast<int>(item.m_repr) );
-
+
serialise_vec(item.m_variants);
-
+
serialise(item.m_markings);
}
void serialise(const ::HIR::Trait& item)
diff --git a/src/hir/serialise_lowlevel.cpp b/src/hir/serialise_lowlevel.cpp
index 95a547c8..a3bb3870 100644
--- a/src/hir/serialise_lowlevel.cpp
+++ b/src/hir/serialise_lowlevel.cpp
@@ -19,7 +19,7 @@ class WriterInner
::std::ofstream m_backing;
z_stream m_zstream;
::std::vector<unsigned char> m_buffer;
-
+
unsigned int m_byte_out_count = 0;
unsigned int m_byte_in_count = 0;
public:
@@ -51,7 +51,7 @@ WriterInner::WriterInner(const ::std::string& filename):
m_zstream.zalloc = Z_NULL;
m_zstream.zfree = Z_NULL;
m_zstream.opaque = Z_NULL;
-
+
const int COMPRESSION_LEVEL = Z_BEST_COMPRESSION;
int ret = deflateInit(&m_zstream, COMPRESSION_LEVEL);
if(ret != Z_OK)
@@ -63,7 +63,7 @@ WriterInner::WriterInner(const ::std::string& filename):
WriterInner::~WriterInner()
{
assert( m_zstream.avail_in == 0 );
-
+
// Complete the compression
int ret;
do
@@ -78,7 +78,7 @@ WriterInner::~WriterInner()
size_t rem = m_buffer.size() - m_zstream.avail_out;
m_byte_out_count += rem;
m_backing.write( reinterpret_cast<char*>(m_buffer.data()), rem );
-
+
m_zstream.avail_out = m_buffer.size();
m_zstream.next_out = m_buffer.data();
}
@@ -90,23 +90,23 @@ void WriterInner::write(const void* buf, size_t len)
{
m_zstream.avail_in = len;
m_zstream.next_in = reinterpret_cast<unsigned char*>( const_cast<void*>(buf) );
-
+
size_t last_avail_in = m_zstream.avail_in;
// While there's data to compress
while( m_zstream.avail_in > 0 )
{
assert(m_zstream.avail_out != 0);
-
+
// Compress the data
int ret = deflate(&m_zstream, Z_NO_FLUSH);
if(ret == Z_STREAM_ERROR)
throw ::std::runtime_error("zlib deflate stream error");
-
+
size_t used_this_time = last_avail_in - m_zstream.avail_in;
last_avail_in = m_zstream.avail_in;
m_byte_in_count += used_this_time;
-
+
// If the entire input wasn't consumed, then it was likely due to a lack of output space
// - Flush the output buffer to the file
if( m_zstream.avail_in > 0 )
@@ -114,7 +114,7 @@ void WriterInner::write(const void* buf, size_t len)
size_t bytes = m_buffer.size() - m_zstream.avail_out;
m_backing.write( reinterpret_cast<char*>(m_buffer.data()), bytes );
m_byte_out_count += bytes;
-
+
m_zstream.avail_out = m_buffer.size();
m_zstream.next_out = m_buffer.data();
}
@@ -126,10 +126,10 @@ void WriterInner::write(const void* buf, size_t len)
size_t bytes = m_buffer.size() - m_zstream.avail_out;
m_backing.write( reinterpret_cast<char*>(m_buffer.data()), bytes );
m_byte_out_count += bytes;
-
+
m_zstream.avail_out = m_buffer.size();
m_zstream.next_out = m_buffer.data();
-
+
int ret = deflate(&m_zstream, Z_NO_FLUSH);
if(ret == Z_STREAM_ERROR)
throw ::std::runtime_error("zlib deflate stream error");
@@ -201,7 +201,7 @@ void Reader::read(void* buf, size_t len)
}
buf = reinterpret_cast<uint8_t*>(buf) + used;
len -= used;
-
+
if( len >= m_buffer.capacity() )
{
m_inner->read(buf, len);
@@ -224,7 +224,7 @@ ReaderInner::ReaderInner(const ::std::string& filename):
m_zstream.zalloc = Z_NULL;
m_zstream.zfree = Z_NULL;
m_zstream.opaque = Z_NULL;
-
+
int ret = inflateInit(&m_zstream);
if(ret != Z_OK)
throw ::std::runtime_error("zlib init failure");
@@ -251,10 +251,10 @@ size_t ReaderInner::read(void* buf, size_t len)
return len - m_zstream.avail_out;
}
m_zstream.next_in = const_cast<unsigned char*>(m_buffer.data());
-
+
m_byte_in_count += m_zstream.avail_in;
}
-
+
int ret = inflate(&m_zstream, Z_NO_FLUSH);
if(ret == Z_STREAM_ERROR)
throw ::std::runtime_error("zlib inflate stream error");
@@ -268,10 +268,10 @@ size_t ReaderInner::read(void* buf, size_t len)
default:
break;
}
-
+
} while( m_zstream.avail_out > 0 );
m_byte_out_count += len;
-
+
return len;
}
diff --git a/src/hir/serialise_lowlevel.hpp b/src/hir/serialise_lowlevel.hpp
index 5172e8e9..fb4504e7 100644
--- a/src/hir/serialise_lowlevel.hpp
+++ b/src/hir/serialise_lowlevel.hpp
@@ -26,9 +26,9 @@ public:
Writer(const Writer&) = delete;
Writer(Writer&&) = delete;
~Writer();
-
+
void write(const void* data, size_t count);
-
+
void write_u8(uint8_t v) {
write(reinterpret_cast<const char*>(&v), 1);
}
@@ -134,7 +134,7 @@ class ReadBuffer
unsigned int m_ofs;
public:
ReadBuffer(size_t size);
-
+
size_t capacity() const { return m_backing.capacity(); }
size_t read(void* dst, size_t len);
void populate(ReaderInner& is);
@@ -151,7 +151,7 @@ public:
~Reader();
void read(void* dst, size_t count);
-
+
uint8_t read_u8() {
uint8_t v;
read(&v, sizeof v);
@@ -212,7 +212,7 @@ public:
uint64_t va = read_u64c();
bool sign = (va & 0x1) != 0;
va >>= 1;
-
+
if( va == 0 && sign ) {
return INT64_MIN;
}
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index c5e1984a..f2709a90 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -31,10 +31,10 @@ namespace HIR {
case CoreType::I32: return os << "i32";
case CoreType::U64: return os << "u64";
case CoreType::I64: return os << "i64";
-
+
case CoreType::F32: return os << "f32";
case CoreType::F64: return os << "f64";
-
+
case CoreType::Bool: return os << "bool";
case CoreType::Char: return os << "char";
case CoreType::Str: return os << "str";
@@ -185,7 +185,7 @@ bool ::HIR::TypeRef::operator==(const ::HIR::TypeRef& x) const
{
if( m_data.tag() != x.m_data.tag() )
return false;
-
+
TU_MATCH(::HIR::TypeRef::Data, (m_data, x.m_data), (te, xe),
(Infer,
// TODO: Should comparing inferrence vars be an error?
@@ -306,9 +306,9 @@ bool ::HIR::TypeRef::operator==(const ::HIR::TypeRef& x) const
Ordering HIR::TypeRef::ord(const ::HIR::TypeRef& x) const
{
Ordering rv;
-
+
ORD( static_cast<unsigned int>(m_data.tag()), static_cast<unsigned int>(x.m_data.tag()) );
-
+
TU_MATCH(::HIR::TypeRef::Data, (m_data, x.m_data), (te, xe),
(Infer,
// TODO: Should comparing inferrence vars be an error?
@@ -454,7 +454,7 @@ namespace {
if( t.m_types.size() != x.m_types.size() ) {
return ::HIR::Compare::Unequal;
}
-
+
auto rv = ::HIR::Compare::Equal;
for(unsigned int i = 0; i < t.m_types.size(); i ++ )
{
@@ -462,7 +462,7 @@ namespace {
if( rv == ::HIR::Compare::Unequal )
return rv;
}
-
+
return rv;
}
}
@@ -533,11 +533,11 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
break;
}
)
-
+
TU_IFLET(::HIR::TypeRef::Data, v.m_data, Infer, te,
// TODO: Restrict this block with a flag so it panics if an ivar is seen when not expected
ASSERT_BUG(sp, te.index != ~0u, "Encountered ivar for `this` - " << v);
-
+
switch(te.ty_class)
{
case ::HIR::InferClass::None:
@@ -576,7 +576,7 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
break;
}
)
-
+
if( v.m_data.tag() != x.m_data.tag() ) {
// HACK: If the path is Opaque, return a fuzzy match.
// - This works around an impl selection bug.
@@ -644,7 +644,7 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
)
)
}
-
+
if( rv == ::HIR::Compare::Unequal ) {
if( te.binding.is_Unbound() || xe.binding.is_Unbound() ) {
rv = ::HIR::Compare::Fuzzy;
@@ -668,7 +668,7 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
{
cmp &= match_generics_pp(sp, te.m_markers[i].m_params, xe.m_markers[i].m_params, resolve_placeholder, callback);
}
-
+
auto it_l = te.m_trait.m_type_bounds.begin();
auto it_r = xe.m_trait.m_type_bounds.begin();
while( it_l != te.m_trait.m_type_bounds.end() && it_r != xe.m_trait.m_type_bounds.end() )
@@ -680,7 +680,7 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
++ it_l;
++ it_r;
}
-
+
if( it_l != te.m_trait.m_type_bounds.end() || it_r != xe.m_trait.m_type_bounds.end() ) {
return Compare::Unequal;
}
@@ -859,12 +859,12 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
const auto& left = (m_data.is_Infer() || m_data.is_Generic() ? resolve_placeholder(*this) : *this);
//const auto& left = *this;
const auto& right = (x.m_data.is_Infer() ? resolve_placeholder(x) : (x.m_data.is_Generic() ? resolve_placeholder(x) : x));
-
+
// If the two types are the same ivar, return equal
if( left.m_data.is_Infer() && left == right ) {
return Compare::Equal;
}
-
+
// If left is infer
TU_IFLET(::HIR::TypeRef::Data, left.m_data, Infer, e,
switch(e.ty_class)
@@ -934,7 +934,7 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
}
throw "";
)
-
+
// If righthand side is infer, it's a fuzzy match (or not a match)
TU_IFLET(::HIR::TypeRef::Data, right.m_data, Infer, e,
switch( e.ty_class )
@@ -982,10 +982,10 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
}
throw "";
)
-
+
// If righthand is a type parameter, it can only match another type parameter
// - See `(Generic,` below
-
+
if( left.m_data.tag() != right.m_data.tag() ) {
if( left.m_data.is_Path() && left.m_data.as_Path().binding.is_Unbound() ) {
return Compare::Fuzzy;
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index d7436607..adb4e82c 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -38,9 +38,9 @@ enum class CoreType
U16, I16,
U32, I32,
U64, I64,
-
+
F32, F64,
-
+
Bool,
Char, Str,
};
@@ -80,7 +80,7 @@ extern ::std::ostream& operator<<(::std::ostream& os, const BorrowType& bt);
struct LifetimeRef
{
::std::string name;
-
+
bool operator==(const LifetimeRef& x) const {
return name == x.name;
}
@@ -101,7 +101,7 @@ public:
// - Primitive
// - Parameter
// - Path
-
+
// - Array
// - Tuple
// - Borrow
@@ -169,15 +169,15 @@ public:
::std::vector<TypeRef> m_arg_types;
})
);
-
+
Data m_data;
-
+
TypeRef() {}
TypeRef(TypeRef&& ) = default;
TypeRef(const TypeRef& ) = delete;
TypeRef& operator=(TypeRef&& ) = default;
TypeRef& operator=(const TypeRef&) = delete;
-
+
struct TagUnit {};
TypeRef(TagUnit ):
m_data( Data::make_Tuple({}) )
@@ -227,27 +227,27 @@ public:
static TypeRef new_closure(::HIR::ExprNode_Closure* node_ptr, ::std::vector< ::HIR::TypeRef> args, ::HIR::TypeRef rv) {
return TypeRef(Data::make_Closure({ node_ptr, box$(mv$(rv)), mv$(args) }));
}
-
+
TypeRef clone() const;
-
+
void fmt(::std::ostream& os) const;
-
+
bool operator==(const ::HIR::TypeRef& x) const;
bool operator!=(const ::HIR::TypeRef& x) const { return !(*this == x); }
bool operator<(const ::HIR::TypeRef& x) const { return ord(x) == OrdLess; }
Ordering ord(const ::HIR::TypeRef& x) const;
bool contains_generics() const;
-
+
// Match generics in `this` with types from `x`
// Raises a bug against `sp` if there is a form mismatch or `this` has an infer
void match_generics(const Span& sp, const ::HIR::TypeRef& x, t_cb_resolve_type resolve_placeholder, t_cb_match_generics) const;
-
+
bool match_test_generics(const Span& sp, const ::HIR::TypeRef& x, t_cb_resolve_type resolve_placeholder, t_cb_match_generics) const;
-
+
// Compares this type with another, calling the first callback to resolve placeholders in the other type, and the second callback for generics in this type
::HIR::Compare match_test_generics_fuzz(const Span& sp, const ::HIR::TypeRef& x_in, t_cb_resolve_type resolve_placeholder, t_cb_match_generics callback) const;
-
+
// Compares this type with another, using `resolve_placeholder` to get replacements for generics/infers in `x`
Compare compare_with_placeholders(const Span& sp, const ::HIR::TypeRef& x, t_cb_resolve_type resolve_placeholder) const;
};
diff --git a/src/hir/visitor.cpp b/src/hir/visitor.cpp
index 889b3a77..40bc14a4 100644
--- a/src/hir/visitor.cpp
+++ b/src/hir/visitor.cpp
@@ -15,7 +15,7 @@
void ::HIR::Visitor::visit_crate(::HIR::Crate& crate)
{
this->visit_module(::HIR::ItemPath(), crate.m_root_module );
-
+
for( auto& ty_impl : crate.m_type_impls )
{
this->visit_type_impl(ty_impl);
@@ -102,7 +102,7 @@ void ::HIR::Visitor::visit_type_impl(::HIR::TypeImpl& impl)
TRACE_FUNCTION_F("impl.m_type=" << impl.m_type);
this->visit_params(impl.m_params);
this->visit_type(impl.m_type);
-
+
for(auto& method : impl.m_methods) {
DEBUG("method " << method.first);
this->visit_function(p + method.first, method.second.data);
@@ -124,7 +124,7 @@ void ::HIR::Visitor::visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR
impl.m_trait_args = mv$(gp.m_params);
}
this->visit_type(impl.m_type);
-
+
for(auto& ent : impl.m_methods) {
DEBUG("method " << ent.first);
this->visit_function(p + ent.first, ent.second.data);
@@ -159,7 +159,7 @@ void ::HIR::Visitor::visit_trait(::HIR::ItemPath p, ::HIR::Trait& item)
::HIR::SimplePath trait_sp = p.get_simple_path();
ItemPath trait_ip(trait_sp);
TRACE_FUNCTION;
-
+
this->visit_params(item.m_params);
for(auto& par : item.m_parent_traits) {
this->visit_trait_path(par);
diff --git a/src/hir/visitor.hpp b/src/hir/visitor.hpp
index dfae710d..dbf759a4 100644
--- a/src/hir/visitor.hpp
+++ b/src/hir/visitor.hpp
@@ -20,15 +20,15 @@ class Visitor
{
public:
virtual ~Visitor();
-
+
virtual void visit_crate(::HIR::Crate& crate);
-
+
virtual void visit_module(ItemPath p, ::HIR::Module& mod);
-
+
virtual void visit_type_impl(::HIR::TypeImpl& impl);
virtual void visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR::TraitImpl& impl);
virtual void visit_marker_impl(const ::HIR::SimplePath& trait_path, ::HIR::MarkerImpl& impl);
-
+
// - Type Items
virtual void visit_type_alias(ItemPath p, ::HIR::TypeAlias& item);
virtual void visit_trait(ItemPath p, ::HIR::Trait& item);
@@ -39,17 +39,17 @@ public:
virtual void visit_function(ItemPath p, ::HIR::Function& item);
virtual void visit_static(ItemPath p, ::HIR::Static& item);
virtual void visit_constant(ItemPath p, ::HIR::Constant& item);
-
+
// - Misc
virtual void visit_params(::HIR::GenericParams& params);
virtual void visit_pattern(::HIR::Pattern& pat);
virtual void visit_pattern_val(::HIR::Pattern::Value& val);
virtual void visit_type(::HIR::TypeRef& tr);
-
+
enum class PathContext {
TYPE,
TRAIT,
-
+
VALUE,
};
virtual void visit_trait_path(::HIR::TraitPath& p);