From e60aa50103d9b24819f3dc26c783c2237f873664 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 29 Mar 2015 22:28:21 +0800 Subject: Minor tweaks to handle libcore update --- src/macros.cpp | 3 ++- src/parse/expr.cpp | 19 +++++++++++++++++++ src/parse/parseerror.cpp | 8 ++++++++ src/parse/parseerror.hpp | 1 + src/parse/root.cpp | 14 ++++++++++++-- 5 files changed, 42 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/macros.cpp b/src/macros.cpp index d8d74d5a..296f6d40 100644 --- a/src/macros.cpp +++ b/src/macros.cpp @@ -523,8 +523,9 @@ bool Macro_HandlePattern(TTStream& lex, const MacroPatEnt& pat, unsigned int lay for( auto ent = g_macro_module; ent; ent = ent->m_prev ) { const AST::Module& mm = *ent->m_item; - for( const auto &m : mm.macros() ) + for( unsigned int i = mm.macros().size(); i --; ) { + const auto& m = mm.macros()[i]; DEBUG("" << m.name); if( m.name == name ) { diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index 32fd171e..7f4e73a1 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -60,6 +60,7 @@ ExprNodeP Parse_ExprBlockNode(TokenStream& lex) GET_CHECK_TOK(tok, lex, TOK_BRACE_OPEN); + while( GET_TOK(tok, lex) != TOK_BRACE_CLOSE ) { AST::MetaItems item_attrs; @@ -72,6 +73,10 @@ ExprNodeP Parse_ExprBlockNode(TokenStream& lex) switch(tok.type()) { + case TOK_CATTR_OPEN: + /*node_attrs.push_back(*/ Parse_MetaItem(lex) /*)*/; + GET_CHECK_TOK(tok, lex, TOK_SQUARE_CLOSE); + break; // Items: // - 'use' case TOK_RWORD_USE: @@ -146,6 +151,19 @@ ExprNodeP Parse_ExprBlockNode(TokenStream& lex) false, tok.str(), Parse_FunctionDefWithCode(lex, "rust", ::std::move(item_attrs), false) ); break; + case TOK_RWORD_UNSAFE: + if( LOOK_AHEAD(lex) == TOK_RWORD_FN ) + { + GET_TOK(tok, lex); + keep_mod = true; + GET_CHECK_TOK(tok, lex, TOK_IDENT); + // - self not allowed, not prototype + local_mod->add_function( + false, tok.str(), Parse_FunctionDefWithCode(lex, "rust", ::std::move(item_attrs), false) + ); + break; + } + if(0) // Macros - If not macro_rules, fall though to expression case TOK_MACRO: if( tok.str() == "macro_rules" ) @@ -162,6 +180,7 @@ ExprNodeP Parse_ExprBlockNode(TokenStream& lex) // Set to TRUE if there was no semicolon after a statement if( expect_end ) { + DEBUG("expect_end == true"); if( GET_TOK(tok, lex) != TOK_BRACE_CLOSE ) { throw ParseError::Unexpected(lex, tok, Token(TOK_BRACE_CLOSE)); diff --git a/src/parse/parseerror.cpp b/src/parse/parseerror.cpp index eebad982..0d58bd52 100644 --- a/src/parse/parseerror.cpp +++ b/src/parse/parseerror.cpp @@ -72,6 +72,14 @@ ParseError::Unexpected::Unexpected(const TokenStream& lex, Token tok, Token exp) pos = lex.getPosition(); ::std::cout << pos << ": Unexpected(" << tok << ", " << exp << ")" << ::std::endl; } +ParseError::Unexpected::Unexpected(const TokenStream& lex, Token tok, ::std::vector exp) +{ + auto pos = tok.get_pos(); + if(pos.filename == "") + pos = lex.getPosition(); + ::std::cout << pos << ": Unexpected " << tok << ", expected "; + ::std::cout << exp << ")" << ::std::endl; +} ParseError::Unexpected::~Unexpected() throw() { } diff --git a/src/parse/parseerror.hpp b/src/parse/parseerror.hpp index 50ec19ff..bae5de6a 100644 --- a/src/parse/parseerror.hpp +++ b/src/parse/parseerror.hpp @@ -27,6 +27,7 @@ class Unexpected: public: Unexpected(const TokenStream& lex, Token tok); Unexpected(const TokenStream& lex, Token tok, Token exp); + Unexpected(const TokenStream& lex, Token tok, ::std::vector exp); virtual ~Unexpected() throw (); }; diff --git a/src/parse/root.cpp b/src/parse/root.cpp index cbc0ef3b..eefe0d52 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -684,9 +684,18 @@ AST::Impl Parse_Impl(TokenStream& lex, bool is_unsafe/*=false*/) if( GET_TOK(tok, lex) == TOK_RWORD_FOR ) { - // Implementing a trait for another type, get the target type trait_type = impl_type; - impl_type = Parse_Type(lex); + // Implementing a trait for another type, get the target type + if( GET_TOK(tok, lex) == TOK_DOUBLE_DOT ) + { + // Default impl + impl_type = TypeRef(); + } + else + { + lex.putback(tok); + impl_type = Parse_Type(lex); + } } else { lex.putback(tok); @@ -717,6 +726,7 @@ AST::Impl Parse_Impl(TokenStream& lex, bool is_unsafe/*=false*/) void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl) { + TRACE_FUNCTION; Token tok; GET_TOK(tok, lex); -- cgit v1.2.3