summaryrefslogtreecommitdiff
path: root/src/expand/file_line.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/expand/file_line.cpp')
-rw-r--r--src/expand/file_line.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/expand/file_line.cpp b/src/expand/file_line.cpp
new file mode 100644
index 00000000..a4117d70
--- /dev/null
+++ b/src/expand/file_line.cpp
@@ -0,0 +1,30 @@
+/*
+ */
+#include <synext.hpp>
+#include "../parse/common.hpp"
+
+class CExpanderFile:
+ public ExpandProcMacro
+{
+ bool expand_early() const override { return true; }
+
+ ::std::unique_ptr<TokenStream> expand(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))) );
+ }
+};
+
+class CExpanderLine:
+ public ExpandProcMacro
+{
+ bool expand_early() const override { return true; }
+
+ ::std::unique_ptr<TokenStream> expand(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_I32))) );
+ }
+};
+
+STATIC_MACRO("file", CExpanderFile);
+STATIC_MACRO("line", CExpanderLine);
+