diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-03 14:11:40 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-03 14:11:40 +0800 |
commit | c9442608f88bb841660aa9358b42f3fc9729c72f (patch) | |
tree | faecc8464db161fed70882cad90d8bc867d5178a /src/hir/from_ast_expr.cpp | |
parent | 5b8ec18a7c2e85d4e0f8ebbbe24d816d0caa4a76 (diff) | |
download | mrust-c9442608f88bb841660aa9358b42f3fc9729c72f.tar.gz |
Resolve - More populated bindings
Diffstat (limited to 'src/hir/from_ast_expr.cpp')
-rw-r--r-- | src/hir/from_ast_expr.cpp | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/hir/from_ast_expr.cpp b/src/hir/from_ast_expr.cpp index 415ff978..5e3908aa 100644 --- a/src/hir/from_ast_expr.cpp +++ b/src/hir/from_ast_expr.cpp @@ -563,16 +563,32 @@ struct LowerHIR_ExprNode_Visitor: m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), mv$(p), ::HIR::ExprNode_PathValue::UNKNOWN ) ); ), (Struct, - assert( e.struct_ ); + ASSERT_BUG(v.span(), e.struct_ || e.hir, "PathValue bound to a struct but pointer not set - " << v.m_path); // Check the form and emit a PathValue if not a unit - if( e.struct_->m_data.is_Struct() ) { - ERROR(v.span(), E0000, "Named value referring to a struct that isn't tuple-like or unit-like - " << v.m_path); - } - else if( e.struct_->m_data.as_Tuple().ents.size() > 0 ) { - m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STRUCT_CONSTR ) ); + if( e.struct_ ) + { + if( e.struct_->m_data.is_Struct() ) { + ERROR(v.span(), E0000, "Named value referring to a struct that isn't tuple-like or unit-like - " << v.m_path); + } + else if( e.struct_->m_data.as_Tuple().ents.size() > 0 ) { + m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STRUCT_CONSTR ) ); + } + else { + m_rv.reset( new ::HIR::ExprNode_UnitVariant( v.span(), LowerHIR_GenericPath(Span(v.get_pos()), v.m_path), true ) ); + } } - else { - m_rv.reset( new ::HIR::ExprNode_UnitVariant( v.span(), LowerHIR_GenericPath(Span(v.get_pos()), v.m_path), true ) ); + else + { + const auto& str = *e.hir; + if( str.m_data.is_Unit() ) { + m_rv.reset( new ::HIR::ExprNode_UnitVariant( v.span(), LowerHIR_GenericPath(Span(v.get_pos()), v.m_path), true ) ); + } + else if( str.m_data.is_Tuple() ) { + m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STRUCT_CONSTR ) ); + } + else { + ERROR(v.span(), E0000, "Named value referring to a struct that isn't tuple-like or unit-like - " << v.m_path); + } } ), (EnumVar, @@ -582,11 +598,22 @@ struct LowerHIR_ExprNode_Visitor: m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::FUNCTION ) ); ), (Static, - assert( e.static_ ); - if( e.static_->s_class() != ::AST::Static::CONST ) { + if( e.static_ ) + { + if( e.static_->s_class() != ::AST::Static::CONST ) { + m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STATIC ) ); + } + else { + m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::CONSTANT ) ); + } + } + else if( e.hir ) + { m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STATIC ) ); } - else { + // HACK: If the HIR pointer is nullptr, then it refers to a `const + else + { m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::CONSTANT ) ); } ) |