summaryrefslogtreecommitdiff
path: root/src/macro_rules
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-09-25 22:04:38 +0800
committerJohn Hodge <tpg@mutabah.net>2016-09-25 22:04:38 +0800
commite7dfda0f39c3d89eaa17c5329a62d2faaa053cfa (patch)
tree85de7d5dbeb0ace41ee974dc4ccaabbb2381762c /src/macro_rules
parent36e197f903ba19229b35cdd7c5bea045ca34dcdc (diff)
downloadmrust-e7dfda0f39c3d89eaa17c5329a62d2faaa053cfa.tar.gz
Parse - Allow loading modules from macro invocations
Diffstat (limited to 'src/macro_rules')
-rw-r--r--src/macro_rules/eval.cpp9
-rw-r--r--src/macro_rules/macro_rules.hpp1
2 files changed, 7 insertions, 3 deletions
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 {