From e7dfda0f39c3d89eaa17c5329a62d2faaa053cfa Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 25 Sep 2016 22:04:38 +0800 Subject: Parse - Allow loading modules from macro invocations --- src/macro_rules/eval.cpp | 9 ++++++--- src/macro_rules/macro_rules.hpp | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/macro_rules') diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp index 966c1149..50b92466 100644 --- a/src/macro_rules/eval.cpp +++ b/src/macro_rules/eval.cpp @@ -499,9 +499,12 @@ void Macro_HandlePatternCap(TTStream& lex, unsigned int index, MacroPatEnt::Type case MacroPatEnt::PAT_META: bound_tts.insert( index, iterations, InterpolatedFragment( Parse_MetaItem(lex) ) ); break; - case MacroPatEnt::PAT_ITEM: - bound_tts.insert( index, iterations, InterpolatedFragment( Parse_Mod_Item_S(lex, false, "!", lex.parse_state().module->path(), false, AST::MetaItems{}) ) ); - break; + case MacroPatEnt::PAT_ITEM: { + assert( lex.parse_state().module ); + const auto& cur_mod = *lex.parse_state().module; + // TODO: Pass the filename for `cur_mod` and if it controls its dir + bound_tts.insert( index, iterations, InterpolatedFragment( Parse_Mod_Item_S(lex, cur_mod.m_file_info, cur_mod.path(), false, AST::MetaItems{}) ) ); + } break; case MacroPatEnt::PAT_IDENT: GET_CHECK_TOK(tok, lex, TOK_IDENT); bound_tts.insert( index, iterations, InterpolatedFragment( TokenTree(tok) ) ); diff --git a/src/macro_rules/macro_rules.hpp b/src/macro_rules/macro_rules.hpp index 7f93edf9..265ea73a 100644 --- a/src/macro_rules/macro_rules.hpp +++ b/src/macro_rules/macro_rules.hpp @@ -22,6 +22,7 @@ class MacroExpander; TAGGED_UNION_EX(MacroExpansionEnt, (: public Serialisable), Token, ( // TODO: have a "raw" stream instead of just tokens (Token, Token), + // TODO: Have a flag on `NamedValue` that indicates that it is the only/last usage of this particular value (at this level) // NOTE: This is a 2:30 bitfield - with the high range indicating $crate (NamedValue, unsigned int), (Loop, struct { -- cgit v1.2.3