From 51a04ad6e7b451eb3543fe97a1dfe9430f3a4436 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 10 Oct 2016 14:33:01 +0800 Subject: Parse - Remove old inefficient TT parse code --- src/expand/format_args.cpp | 9 ++-- src/parse/expr.cpp | 117 --------------------------------------------- src/parse/tokentree.hpp | 7 --- 3 files changed, 5 insertions(+), 128 deletions(-) (limited to 'src') diff --git a/src/expand/format_args.cpp b/src/expand/format_args.cpp index 39440dc9..e09e2fdb 100644 --- a/src/expand/format_args.cpp +++ b/src/expand/format_args.cpp @@ -11,6 +11,7 @@ #include "../parse/parseerror.hpp" #include "../parse/tokentree.hpp" #include "../parse/lex.hpp" +#include "../parse/interpolated_fragment.hpp" #include // for m_load_std #include // for ExprNode_* @@ -339,7 +340,7 @@ class CFormatArgsExpander: GET_CHECK_TOK(tok, lex, TOK_EQUAL); - auto expr_tt = Parse_TT_Expr(lex); + auto expr_tt = TokenTree(Token( InterpolatedFragment(InterpolatedFragment::EXPR, Parse_Expr0(lex).release()) )); auto ins_rv = named_args_index.insert( ::std::make_pair(mv$(name), named_args.size()) ); if( ins_rv.second == false ) { @@ -350,7 +351,7 @@ class CFormatArgsExpander: // - Free parameters else { - auto expr_tt = Parse_TT_Expr(lex); + auto expr_tt = TokenTree(Token( InterpolatedFragment(InterpolatedFragment::EXPR, Parse_Expr0(lex).release()) )); free_args.push_back( mv$(expr_tt) ); } } @@ -399,10 +400,10 @@ class CFormatArgsExpander: push_path(toks, crate, {"fmt", "ArgumentV1", "new"}); toks.push_back( Token(TOK_PAREN_OPEN) ); toks.push_back( Token(TOK_AMP) ); - toks.push_back( Token(TOK_PAREN_OPEN) ); toks.push_back( mv$(free_args[frag.arg_index]) ); - toks.push_back( Token(TOK_PAREN_CLOSE) ); + toks.push_back( TokenTree(TOK_COMMA) ); + push_path(toks, crate, {"fmt", frag.trait_name, "fmt"}); toks.push_back( TokenTree(TOK_PAREN_CLOSE) ); toks.push_back( TokenTree(TOK_COMMA) ); diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index 6b33b3e7..5463f50f 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -1295,120 +1295,3 @@ TokenTree Parse_TT(TokenStream& lex, bool unwrapped) items.push_back( mv$(tok) ); return TokenTree(mv$(items)); } - -/// A wrapping lexer that -class TTLexer: - public TokenStream -{ - TokenStream& m_input; - Token m_last_token; - ::std::vector m_output; -public: - TTLexer(TokenStream& input): - m_input(input) - { - } - - virtual Position getPosition() const override { return m_input.getPosition(); } - virtual Token realGetToken() override { - Token tok = m_input.getToken(); - m_output.push_back( TokenTree(tok.clone()) ); - return tok; - } - - TokenTree get_output() { - unsigned int eat = (TokenStream::m_cache_valid ? 1 : 0) + TokenStream::m_lookahead.size(); - DEBUG(eat << " tokens were not consumed"); - assert( m_output.size() >= eat ); - assert( m_input.m_lookahead.size() == 0 ); - assert( m_input.m_cache_valid == false ); - for( unsigned int i = 0; i < eat; i ++ ) - { - Token tok = m_output[ m_output.size() - eat + i ].tok(); - DEBUG("Unconsume " << tok); - m_input.m_lookahead.push_back( tok ); - } - DEBUG("- output was [" << m_output << "]"); - m_output.erase( m_output.end() - eat, m_output.end() ); - DEBUG("Returning [" << m_output << "]"); - return ::std::move(m_output); - } -}; - -TokenTree Parse_TT_Type(TokenStream& lex) -{ - TRACE_FUNCTION; - TTLexer wlex(lex); - SET_PARSE_FLAG(wlex, no_expand_macros); - - // discard result - Parse_Type(wlex); - - return wlex.get_output(); -} - -/// Parse a token tree path -TokenTree Parse_TT_Path(TokenStream& lex, bool mode_expr) -{ - TRACE_FUNCTION; - TTLexer wlex(lex); - SET_PARSE_FLAG(wlex, no_expand_macros); - - Token tok; - - if( GET_TOK(tok, wlex) == TOK_DOUBLE_COLON ) { - Parse_Path(wlex, true, (mode_expr ? PATH_GENERIC_EXPR : PATH_GENERIC_TYPE)); - } - else { - PUTBACK(tok, lex); - Parse_Path(wlex, false, (mode_expr ? PATH_GENERIC_EXPR : PATH_GENERIC_TYPE)); - } - - return wlex.get_output(); -} -/// Parse a token tree expression -TokenTree Parse_TT_Expr(TokenStream& lex) -{ - TRACE_FUNCTION; - TTLexer wlex(lex); - SET_PARSE_FLAG(wlex, no_expand_macros); - - Parse_Expr1(wlex); - - return wlex.get_output(); -} -TokenTree Parse_TT_Pattern(TokenStream& lex) -{ - TRACE_FUNCTION; - TTLexer wlex(lex); - SET_PARSE_FLAG(wlex, no_expand_macros); - - // Allow a refutable pattern here - Parse_Pattern(wlex, true); - - return wlex.get_output(); -} -TokenTree Parse_TT_Stmt(TokenStream& lex) -{ - TRACE_FUNCTION; - TTLexer wlex(lex); - SET_PARSE_FLAG(wlex, no_expand_macros); - - throw ParseError::Todo("Parse_TT_Stmt"); -} -TokenTree Parse_TT_Block(TokenStream& lex) -{ - TRACE_FUNCTION; - TTLexer wlex(lex); - SET_PARSE_FLAG(wlex, no_expand_macros); - - throw ParseError::Todo("Parse_TT_Block"); -} -TokenTree Parse_TT_Meta(TokenStream& lex) -{ - TRACE_FUNCTION; - TTLexer wlex(lex); - SET_PARSE_FLAG(wlex, no_expand_macros); - Parse_MetaItem(wlex); - return wlex.get_output(); -} diff --git a/src/parse/tokentree.hpp b/src/parse/tokentree.hpp index 0856c326..82c4f97d 100644 --- a/src/parse/tokentree.hpp +++ b/src/parse/tokentree.hpp @@ -90,12 +90,5 @@ protected: // unwrapped = Exclude the enclosing brackets (used by macro parse code) extern TokenTree Parse_TT(TokenStream& lex, bool unwrapped); -extern TokenTree Parse_TT_Pattern(TokenStream& lex); -extern TokenTree Parse_TT_Expr(TokenStream& lex); -extern TokenTree Parse_TT_Type(TokenStream& lex); -extern TokenTree Parse_TT_Stmt(TokenStream& lex); -extern TokenTree Parse_TT_Block(TokenStream& lex); -extern TokenTree Parse_TT_Path(TokenStream& lex, bool mode_expr); -extern TokenTree Parse_TT_Meta(TokenStream& lex); #endif // TOKENTREE_HPP_INCLUDED -- cgit v1.2.3