diff options
author | John Hodge (bugs) <tpg@mutabah.net> | 2017-07-06 17:41:10 +0800 |
---|---|---|
committer | John Hodge (bugs) <tpg@mutabah.net> | 2017-07-06 17:41:10 +0800 |
commit | 48e2c4973d5401c9f7d0ee2bac22ac6015744961 (patch) | |
tree | b93fb21b85343633e2d0c00c42ea7a388bb6f883 /src/expand/file_line.cpp | |
parent | ce3d36a90b9efd11c94f9084b5e727d65b6509a7 (diff) | |
parent | c4e88b3c49736e71534c918a83956885c052beb8 (diff) | |
download | mrust-48e2c4973d5401c9f7d0ee2bac22ac6015744961.tar.gz |
Merge branch 'master' of https://github.com/thepowersgang/mrustc
# Conflicts:
# src/trans/codegen_c.cpp
Diffstat (limited to 'src/expand/file_line.cpp')
-rw-r--r-- | src/expand/file_line.cpp | 17 |
1 files changed, 14 insertions, 3 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))) ); } }; |