From 6c66615baf391844baec2b04bce71f70e4b34150 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Tue, 10 Feb 2015 01:36:46 +0000 Subject: [PATCH] IR: Add accessors to MDExpression Add some accessors to `MDExpression`. llvm-svn: 228648 --- include/llvm/IR/DebugInfoMetadata.h | 6 ++++++ unittests/IR/MetadataTest.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/include/llvm/IR/DebugInfoMetadata.h b/include/llvm/IR/DebugInfoMetadata.h index fdb6dd8964c..f1af7ef8b8b 100644 --- a/include/llvm/IR/DebugInfoMetadata.h +++ b/include/llvm/IR/DebugInfoMetadata.h @@ -1410,6 +1410,12 @@ public: ArrayRef getElements() const { return Elements; } + unsigned getNumElements() const { return Elements.size(); } + uint64_t getElement(unsigned I) const { + assert(I < Elements.size() && "Index out of range"); + return Elements[I]; + } + typedef ArrayRef::iterator element_iterator; element_iterator elements_begin() const { return getElements().begin(); } element_iterator elements_end() const { return getElements().end(); } diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp index 8a1da4f325d..9e244246c41 100644 --- a/unittests/IR/MetadataTest.cpp +++ b/unittests/IR/MetadataTest.cpp @@ -1389,6 +1389,13 @@ TEST_F(MDExpressionTest, get) { auto *N = MDExpression::get(Context, Elements); EXPECT_EQ(makeArrayRef(Elements), N->getElements()); EXPECT_EQ(N, MDExpression::get(Context, Elements)); + + EXPECT_EQ(5u, N->getNumElements()); + EXPECT_EQ(2u, N->getElement(0)); + EXPECT_EQ(6u, N->getElement(1)); + EXPECT_EQ(9u, N->getElement(2)); + EXPECT_EQ(78u, N->getElement(3)); + EXPECT_EQ(0u, N->getElement(4)); } typedef MetadataTest MDObjCPropertyTest;