diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-26 15:14:54 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-26 15:14:54 +0800 |
commit | 06a1470f8d9e3113bf905088c3d991f4317edf7b (patch) | |
tree | 7886a53e75e985c09c2462ca6ac14b8f5c790648 | |
parent | 09d2408ddaaff051a5ed426a46a18512f4ea3ee9 (diff) | |
download | mrust-06a1470f8d9e3113bf905088c3d991f4317edf7b.tar.gz |
Debug - Clarify logging
-rw-r--r-- | src/macro_rules/eval.cpp | 51 | ||||
-rw-r--r-- | src/main.cpp | 5 | ||||
-rw-r--r-- | src/parse/root.cpp | 1 |
3 files changed, 34 insertions, 23 deletions
diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp index 8b698ac1..66382ed7 100644 --- a/src/macro_rules/eval.cpp +++ b/src/macro_rules/eval.cpp @@ -157,6 +157,7 @@ private: }; // === Prototypes === +unsigned int Macro_InvokeRules_MatchPattern(const MacroRules& rules, TokenTree input, AST::Module& mod, ParameterMappings& bound_tts); void Macro_InvokeRules_CountSubstUses(ParameterMappings& bound_tts, const ::std::vector<MacroExpansionEnt>& contents); // ------------------------------------ @@ -730,9 +731,35 @@ bool Macro_HandlePattern(TokenStream& lex, const MacroPatEnt& pat, ::std::vector /// Parse the input TokenTree according to the `macro_rules!` patterns and return a token stream of the replacement ::std::unique_ptr<TokenStream> Macro_InvokeRules(const char *name, const MacroRules& rules, TokenTree input, AST::Module& mod) { + TRACE_FUNCTION_F(name); + + ParameterMappings bound_tts; + unsigned int rule_index = Macro_InvokeRules_MatchPattern(rules, mv$(input), mod, bound_tts); + + const auto& rule = rules.m_rules.at(rule_index); + + DEBUG( rule.m_contents.size() << " rule contents with " << bound_tts.mappings().size() << " bound values - " << name ); + assert( rule.m_param_names.size() >= bound_tts.mappings().size() ); + for( unsigned int i = 0; i < bound_tts.mappings().size(); i ++ ) + { + DEBUG(" - " << rule.m_param_names.at(i) << " = [" << bound_tts.mappings()[i] << "]"); + } + //bound_tts.dump(); + + // Run through the expansion counting the number of times each fragment is used + Macro_InvokeRules_CountSubstUses(bound_tts, rule.m_contents); + + TokenStream* ret_ptr = new MacroExpander(name, rule.m_contents, mv$(bound_tts), rules.m_source_crate); + + return ::std::unique_ptr<TokenStream>( ret_ptr ); +} + +unsigned int Macro_InvokeRules_MatchPattern(const MacroRules& rules, TokenTree input, AST::Module& mod, ParameterMappings& bound_tts) +{ TRACE_FUNCTION; - Span sp;// = input + Span sp;// = input.span(); + unsigned int rule_index; // - List of active rules (rules that haven't yet failed) ::std::vector< ::std::pair<unsigned, MacroPatternStream> > active_arms; active_arms.reserve( rules.m_rules.size() ); @@ -741,9 +768,6 @@ bool Macro_HandlePattern(TokenStream& lex, const MacroPatEnt& pat, ::std::vector active_arms.push_back( ::std::make_pair(i, MacroPatternStream(rules.m_rules[i].m_pattern)) ); } - ParameterMappings bound_tts; - unsigned int rule_index; - TTStreamO lex( mv$(input) ); SET_MODULE(lex, mod); while(true) @@ -887,24 +911,7 @@ bool Macro_HandlePattern(TokenStream& lex, const MacroPatEnt& pat, ::std::vector // Keep looping - breakout is handled by an if above } - - const auto& rule = rules.m_rules.at(rule_index); - - DEBUG( rule.m_contents.size() << " rule contents with " << bound_tts.mappings().size() << " bound values - " << name ); - assert( rule.m_param_names.size() >= bound_tts.mappings().size() ); - for( unsigned int i = 0; i < bound_tts.mappings().size(); i ++ ) - { - DEBUG(" - " << rule.m_param_names.at(i) << " = [" << bound_tts.mappings()[i] << "]"); - } - //bound_tts.dump(); - - // TODO: Run expander (or something similar) in a dummy mode to figure out how many times each capture is used - // - This will allow the expander to avoid a clone (which could be the only clone) - Macro_InvokeRules_CountSubstUses(bound_tts, rule.m_contents); - - TokenStream* ret_ptr = new MacroExpander(name, rule.m_contents, mv$(bound_tts), rules.m_source_crate); - - return ::std::unique_ptr<TokenStream>( ret_ptr ); + return rule_index; } void Macro_InvokeRules_CountSubstUses(ParameterMappings& bound_tts, const ::std::vector<MacroExpansionEnt>& contents) diff --git a/src/main.cpp b/src/main.cpp index eb4bb478..8ee50aea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -180,6 +180,9 @@ int main(int argc, char *argv[]) CompilePhaseV("LoadCrates", [&]() {
crate.load_externs();
});
+ //CompilePhaseV("Temp output - Parsed", [&]() {
+ // Dump_Rust( FMT(params.outfile << "_0_pp.rs").c_str(), crate );
+ // });
// Iterate all items in the AST, applying syntax extensions
CompilePhaseV("Expand", [&]() {
@@ -188,7 +191,7 @@ int main(int argc, char *argv[]) // XXX: Dump crate before resolve
CompilePhaseV("Temp output - Parsed", [&]() {
- Dump_Rust( FMT(params.outfile << "_0_pp.rs").c_str(), crate );
+ Dump_Rust( FMT(params.outfile << "_0a_exp.rs").c_str(), crate );
});
if( params.last_stage == ProgramParams::STAGE_EXPAND ) {
diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 69860f6e..d5df911f 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -1278,6 +1278,7 @@ void Parse_Use(TokenStream& lex, ::std::function<void(AST::UseStmt, ::std::strin else {
PUTBACK(tok, lex);
}
+ DEBUG("name=" << name << ", ident=" << ident);
TokenTree tt = Parse_TT(lex, true);
return ::AST::MacroInvocation( lex.end_span(span_start), mv$(meta_items), mv$(name), mv$(ident), mv$(tt));
}
|