diff options
author | M V V S Manoj Kumar <mvvsmanojkumar@gmail.com> | 2022-03-10 12:38:29 +0530 |
---|---|---|
committer | M V V S Manoj Kumar <mvvsmanojkumar@gmail.com> | 2022-03-13 11:42:22 +0530 |
commit | d9a5bddb4c64268f2411a2b317872fe0c26284c3 (patch) | |
tree | 4469187e2c1aaff90f199acaa8de89a52a183643 /gcc/rust/expand | |
parent | b82408fd6a17762fcb6fc7b5efe9307a3e59f8b7 (diff) | |
download | gcc-d9a5bddb4c64268f2411a2b317872fe0c26284c3.zip gcc-d9a5bddb4c64268f2411a2b317872fe0c26284c3.tar.gz gcc-d9a5bddb4c64268f2411a2b317872fe0c26284c3.tar.bz2 |
Added column!() macro
Addresses issue #979
1) Added the column!() macro using the LOCATION_COLUMN() from gcc_linemap
2) Added relevent test cases
Signed-off-by : M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
Diffstat (limited to 'gcc/rust/expand')
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins.cc | 14 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index ce0be92..c33a2e8 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -49,4 +49,18 @@ MacroBuiltin::file (Location invoc_locus, AST::MacroInvocData &invoc) return AST::ASTFragment ({file_str}); } +AST::ASTFragment +MacroBuiltin::column (Location invoc_locus, AST::MacroInvocData &invoc) +{ + auto current_column + = Session::get_instance ().linemap->location_to_column (invoc_locus); + // auto column_no + // = AST::SingleASTNode (make_string (invoc_locus, current_column)); + + auto column_no = AST::SingleASTNode (std::unique_ptr<AST::Expr> ( + new AST::LiteralExpr (std::to_string (current_column), AST::Literal::INT, + PrimitiveCoreType::CORETYPE_U32, {}, invoc_locus))); + + return AST::ASTFragment ({column_no}); +} } // namespace Rust diff --git a/gcc/rust/expand/rust-macro-builtins.h b/gcc/rust/expand/rust-macro-builtins.h index ee42fe1..d946129 100644 --- a/gcc/rust/expand/rust-macro-builtins.h +++ b/gcc/rust/expand/rust-macro-builtins.h @@ -31,6 +31,9 @@ public: static AST::ASTFragment file (Location invoc_locus, AST::MacroInvocData &invoc); + + static AST::ASTFragment column (Location invoc_locus, + AST::MacroInvocData &invoc); }; } // namespace Rust |