summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/ident.hpp7
-rw-r--r--src/parse/lex.hpp7
-rw-r--r--src/parse/root.cpp7
-rw-r--r--src/parse/tokenstream.hpp2
4 files changed, 23 insertions, 0 deletions
diff --git a/src/include/ident.hpp b/src/include/ident.hpp
index d702385c..b9a6dec5 100644
--- a/src/include/ident.hpp
+++ b/src/include/ident.hpp
@@ -37,6 +37,13 @@ struct Ident
rv.contexts.push_back( ++g_next_scope );
return rv;
}
+ Hygiene get_parent() const
+ {
+ //assert(this->contexts.size() > 1);
+ Hygiene rv;
+ rv.contexts.insert(rv.contexts.begin(), this->contexts.begin(), this->contexts.end()-1);
+ return rv;
+ }
Hygiene(Hygiene&& x) = default;
Hygiene(const Hygiene& x) = default;
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; }