diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-09-03 15:44:07 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-09-03 15:44:07 +0800 |
commit | 775e33423d98bf76c5658af59de65fac5cf93e87 (patch) | |
tree | 8be299ca47dad8a40fe2bb73c9eaf03149ad1104 /src/parse | |
parent | 3504b0dbf00a367bba77dbb9707ffec9e75a6dcb (diff) | |
download | mrust-775e33423d98bf76c5658af59de65fac5cf93e87.tar.gz |
Parse - Tweaked hygine for an edge case in libproc_macro
Diffstat (limited to 'src/parse')
-rw-r--r-- | src/parse/lex.hpp | 7 | ||||
-rw-r--r-- | src/parse/root.cpp | 7 | ||||
-rw-r--r-- | src/parse/tokenstream.hpp | 2 |
3 files changed, 16 insertions, 0 deletions
diff --git a/src/parse/lex.hpp b/src/parse/lex.hpp index 871ab29a..67aa155d 100644 --- a/src/parse/lex.hpp +++ b/src/parse/lex.hpp @@ -58,6 +58,13 @@ private: double parseFloat(uint64_t whole); uint32_t parseEscape(char enclosing); + void push_hygine() override { + m_hygiene = Ident::Hygiene::new_scope_chained(m_hygiene); + } + void pop_hygine() override { + m_hygiene = m_hygiene.get_parent(); + } + void ungetc(); Codepoint getc_num(); Codepoint getc(); diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 85d51ddb..eb009622 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -481,8 +481,11 @@ AST::Function Parse_FunctionDefWithCode(TokenStream& lex, ::std::string abi, boo Token tok; auto ret = Parse_FunctionDef(lex, abi, allow_self, false, is_unsafe, is_const); GET_CHECK_TOK(tok, lex, TOK_BRACE_OPEN); + // Enter a new hygine scope (TODO: Should this be in Parse_ExprBlock?) + lex.push_hygine(); PUTBACK(tok, lex); ret.set_code( Parse_ExprBlock(lex) ); + lex.pop_hygine(); return ret; } @@ -775,7 +778,11 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::MetaItems& meta_items) if( GET_TOK(tok, lex) == TOK_BRACE_OPEN ) { PUTBACK(tok, lex); + // Enter a new hygine scope for the function body. + // - TODO: Should this just happen in Parse_ExprBlock? + lex.push_hygine(); fcn.set_code( Parse_ExprBlock(lex) ); + lex.pop_hygine(); } else if( tok.type() == TOK_SEMICOLON ) { diff --git a/src/parse/tokenstream.hpp b/src/parse/tokenstream.hpp index 5f2e0733..766e52bc 100644 --- a/src/parse/tokenstream.hpp +++ b/src/parse/tokenstream.hpp @@ -61,6 +61,8 @@ public: eTokenType lookahead(unsigned int count); Ident::Hygiene getHygiene() const; + virtual void push_hygine() {} + virtual void pop_hygine() {} ParseState& parse_state() { return m_parse_state; } |