aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-03-13 11:45:43 +0000
committerGitHub <noreply@github.com>2022-03-13 11:45:43 +0000
commit41f402f0b19c7e4f19f8d4d65d15223d2752f302 (patch)
treed3cbf6a68ea6a86bf538f46a2d4090656929a9cf /gcc/rust/expand
parent8c88e8e0c9c3ebc627e3f3373cd7303d487c8d63 (diff)
parentd9a5bddb4c64268f2411a2b317872fe0c26284c3 (diff)
downloadgcc-41f402f0b19c7e4f19f8d4d65d15223d2752f302.zip
gcc-41f402f0b19c7e4f19f8d4d65d15223d2752f302.tar.gz
gcc-41f402f0b19c7e4f19f8d4d65d15223d2752f302.tar.bz2
Merge #1004
1004: Added column!() macro r=CohenArthur a=mvvsmk Fixes issue #979 1) Added the column!() macro using the LOCATION_COLUMN() from gcc_linemap 2) To-Do: add relevant test cases. Signed-off-by : M V V S Manoj Kumar <mvvsmanojkumar@gmail.com> The test case I added always fails, I can't figure out whether there is a problem in my test case or there is something wrong with my implementation of the column!() macro. Do let me know where I am going wrong and also if I missed something . :) Co-authored-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.cc14
-rw-r--r--gcc/rust/expand/rust-macro-builtins.h3
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 37923cf..ae9ba37 100644
--- a/gcc/rust/expand/rust-macro-builtins.h
+++ b/gcc/rust/expand/rust-macro-builtins.h
@@ -68,6 +68,9 @@ public:
static AST::ASTFragment file (Location invoc_locus,
AST::MacroInvocData &invoc);
+
+ static AST::ASTFragment column (Location invoc_locus,
+ AST::MacroInvocData &invoc);
};
} // namespace Rust