diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ast/pattern.cpp | 9 | ||||
-rw-r--r-- | src/ast/pattern.hpp | 6 | ||||
-rw-r--r-- | src/convert/ast_iterate.cpp | 9 | ||||
-rw-r--r-- | src/dump_as_rust.cpp | 10 | ||||
-rw-r--r-- | src/parse/lex.cpp | 2 | ||||
-rw-r--r-- | src/parse/pattern.cpp | 6 | ||||
-rw-r--r-- | src/parse/root.cpp | 1 |
7 files changed, 40 insertions, 3 deletions
diff --git a/src/ast/pattern.cpp b/src/ast/pattern.cpp index 1b189fa9..f2279a55 100644 --- a/src/ast/pattern.cpp +++ b/src/ast/pattern.cpp @@ -21,6 +21,9 @@ namespace AST { (MaybeBind, os << "?"; ), + (Box, + os << "box " << *ent.sub; + ), (Ref, os << "&" << (ent.mut ? "mut " : "") << *ent.sub; ), @@ -59,6 +62,9 @@ SERIALISE_TYPE(Pattern::, "Pattern", { ), (MaybeBind, ), + (Box, + s << e.sub; + ), (Ref, s << e.mut; s << e.sub; @@ -88,6 +94,9 @@ SERIALISE_TYPE(Pattern::, "Pattern", { _D(Any, ) _D(MaybeBind, ) + _D(Box, + s.item( ent.sub ); + ) _D(Ref, s.item( ent.mut ); s.item( ent.sub ); diff --git a/src/ast/pattern.hpp b/src/ast/pattern.hpp index 6b89aa35..f28fe8e3 100644 --- a/src/ast/pattern.hpp +++ b/src/ast/pattern.hpp @@ -21,6 +21,7 @@ public: TAGGED_UNION(Data, Any, (Any, () ), (MaybeBind, () ), + (Box, (unique_ptr<Pattern> sub;) ), (Ref, (bool mut; unique_ptr<Pattern> sub;) ), (Value, (unique_ptr<ExprNode> start; unique_ptr<ExprNode> end;) ), (Tuple, (::std::vector<Pattern> sub_patterns;) ), @@ -52,6 +53,11 @@ public: m_data( Data::make_MaybeBind({}) ) {} + struct TagBox {}; + Pattern(TagBox, Pattern sub): + m_data( Data::make_Box({ unique_ptr<Pattern>(new Pattern(mv$(sub))) }) ) + {} + struct TagValue {}; Pattern(TagValue, unique_ptr<ExprNode> node, unique_ptr<ExprNode> node2 = 0): m_data( Data::make_Value({ ::std::move(node), ::std::move(node2) }) ) diff --git a/src/convert/ast_iterate.cpp b/src/convert/ast_iterate.cpp index 79d4caf8..3674d947 100644 --- a/src/convert/ast_iterate.cpp +++ b/src/convert/ast_iterate.cpp @@ -123,6 +123,15 @@ void CASTIterator::handle_pattern(AST::Pattern& pat, const TypeRef& type_hint) (Any, // Wildcard, nothing to do ), + (Box, { + auto& v = pat.data().as_Box(); + if( type_hint.is_wildcard() ) + handle_pattern(*v.sub, (const TypeRef&)TypeRef()); + else { + throw ::std::runtime_error("TODO: Handle box patterns in CASTIterator::handle_pattern"); + handle_pattern(*v.sub, type_hint.inner_type()); + } + }), (Ref, { auto& v = pat.data().as_Ref(); if( type_hint.is_wildcard() ) diff --git a/src/dump_as_rust.cpp b/src/dump_as_rust.cpp index 11ace14b..a498e626 100644 --- a/src/dump_as_rust.cpp +++ b/src/dump_as_rust.cpp @@ -746,9 +746,17 @@ void RustPrinter::print_pattern(const AST::Pattern& p, bool is_refutable) (MaybeBind, m_os << "_ /*?*/"; ), + (Box, { + const auto& v = p.data().as_Box(); + m_os << "& "; + print_pattern(*v.sub, is_refutable); + }), (Ref, { const auto& v = p.data().as_Ref(); - m_os << "& "; + if(v.mut) + m_os << "&mut "; + else + m_os << "& "; print_pattern(*v.sub, is_refutable); }), (Value, { diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index cb97022d..2338adcd 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -989,7 +989,7 @@ void TokenStream::putback(Token tok) { if( m_cache_valid ) { - DEBUG("" << getPosition()); + DEBUG("" << getPosition() << " - Double putback: " << tok << " but " << m_cache); throw ParseError::BugCheck("Double putback"); } else diff --git a/src/parse/pattern.cpp b/src/parse/pattern.cpp index 02286ceb..32d1b017 100644 --- a/src/parse/pattern.cpp +++ b/src/parse/pattern.cpp @@ -108,6 +108,10 @@ AST::Pattern Parse_Pattern(TokenStream& lex, bool is_refutable) return Parse_PatternReal_Path(lex, path, is_refutable); } } + else + { + // Otherwise, fall through + } lex.putback(tok); AST::Pattern pat = Parse_PatternReal(lex, is_refutable); @@ -153,6 +157,8 @@ AST::Pattern Parse_PatternReal1(TokenStream& lex, bool is_refutable) return AST::Pattern( ); case TOK_DOUBLE_DOT: return AST::Pattern( AST::Pattern::TagWildcard() ); + case TOK_RWORD_BOX: + return AST::Pattern( AST::Pattern::TagBox(), Parse_Pattern(lex, is_refutable) ); case TOK_DOUBLE_AMP: lex.putback(TOK_AMP); case TOK_AMP: diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 93b360f1..fb7249e4 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -265,7 +265,6 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, AST::MetaIt else
{
// Unbound method
- lex.putback(tok); // un-eat the '&'
}
}
else if( tok.type() == TOK_RWORD_MUT )
|