diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-06-11 21:03:45 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-06-11 21:03:45 +0800 |
commit | b3af24cd9e3715097997c8215f82f1184586f542 (patch) | |
tree | 97074debb75d2a80651112f077dd0cc901b6fa66 /src/expand | |
parent | 52d872b36d7fda733273d70100d21b16506f1647 (diff) | |
download | mrust-b3af24cd9e3715097997c8215f82f1184586f542.tar.gz |
Expand - Make file!/line! get the invocation location of a macro
Diffstat (limited to 'src/expand')
-rw-r--r-- | src/expand/file_line.cpp | 17 | ||||
-rw-r--r-- | src/expand/macro_rules.cpp | 5 | ||||
-rw-r--r-- | src/expand/macro_rules.hpp | 2 | ||||
-rw-r--r-- | src/expand/mod.cpp | 5 |
4 files changed, 17 insertions, 12 deletions
diff --git a/src/expand/file_line.cpp b/src/expand/file_line.cpp index 8dfb7e6d..7e117993 100644 --- a/src/expand/file_line.cpp +++ b/src/expand/file_line.cpp @@ -9,12 +9,23 @@ #include "../parse/common.hpp" #include "../parse/ttstream.hpp" +namespace { + const Span& get_top_span(const Span& sp) { + if( sp.outer_span ) { + return get_top_span(*sp.outer_span); + } + else { + return sp; + } + } +} + class CExpanderFile: public ExpandProcMacro { ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override { - return box$( TTStreamO(TokenTree(Token(TOK_STRING, sp.filename.c_str()))) ); + return box$( TTStreamO(TokenTree(Token(TOK_STRING, get_top_span(sp).filename.c_str()))) ); } }; @@ -23,7 +34,7 @@ class CExpanderLine: { ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override { - return box$( TTStreamO(TokenTree(Token((uint64_t)sp.start_line, CORETYPE_U32))) ); + return box$( TTStreamO(TokenTree(Token((uint64_t)get_top_span(sp).start_line, CORETYPE_U32))) ); } }; @@ -32,7 +43,7 @@ class CExpanderColumn: { ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override { - return box$( TTStreamO(TokenTree(Token((uint64_t)sp.start_ofs, CORETYPE_U32))) ); + return box$( TTStreamO(TokenTree(Token((uint64_t)get_top_span(sp).start_ofs, CORETYPE_U32))) ); } }; diff --git a/src/expand/macro_rules.cpp b/src/expand/macro_rules.cpp index 338edd12..0375f430 100644 --- a/src/expand/macro_rules.cpp +++ b/src/expand/macro_rules.cpp @@ -169,11 +169,6 @@ class CMacroReexportHandler: } }; -::std::unique_ptr<TokenStream> Macro_Invoke(const char* name, const MacroRules& rules, TokenTree tt, AST::Module& mod) -{ - return Macro_InvokeRules(name, rules, mv$(tt), mod); -} - STATIC_MACRO("macro_rules", CMacroRulesExpander); STATIC_DECORATOR("macro_use", CMacroUseHandler); diff --git a/src/expand/macro_rules.hpp b/src/expand/macro_rules.hpp index b5f09f1c..00332dd5 100644 --- a/src/expand/macro_rules.hpp +++ b/src/expand/macro_rules.hpp @@ -12,5 +12,3 @@ namespace AST { class TokenTree; class TokenStream; class MacroRules; - -extern ::std::unique_ptr<TokenStream> Macro_Invoke(const char* name, const MacroRules& rules, TokenTree tt, AST::Module& mod); diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index 38e40347..5c3be722 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -11,6 +11,7 @@ #include <synext.hpp> #include <map> #include "macro_rules.hpp" +#include "../macro_rules/macro_rules.hpp" #include "../parse/common.hpp" // For reparse from macros #include <ast/expr.hpp> #include "cfg.hpp" @@ -115,7 +116,7 @@ void Expand_Attrs(::AST::MetaItems& attrs, AttrStage stage, ::AST::Crate& crate if( input_ident != "" ) ERROR(mi_span, E0000, "macro_rules! macros can't take an ident"); - auto e = Macro_Invoke(name.c_str(), *mr.data, mv$(input_tt), mod); + auto e = Macro_InvokeRules(name.c_str(), *mr.data, mi_span, mv$(input_tt), mod); return e; } } @@ -134,7 +135,7 @@ void Expand_Attrs(::AST::MetaItems& attrs, AttrStage stage, ::AST::Crate& crate } if( last_mac ) { - auto e = Macro_Invoke(name.c_str(), *last_mac, mv$(input_tt), mod); + auto e = Macro_InvokeRules(name.c_str(), *last_mac, mi_span, mv$(input_tt), mod); return e; } } |