[llvm] baa18ee - Add a new API seek for the Cursor class in the DataExtractor.cpp
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 16 06:40:04 PDT 2021
Author: zhijian
Date: 2021-09-16T09:39:49-04:00
New Revision: baa18ee63e83ee534a5844e6219665ce42b57707
URL: https://github.com/llvm/llvm-project/commit/baa18ee63e83ee534a5844e6219665ce42b57707
DIFF: https://github.com/llvm/llvm-project/commit/baa18ee63e83ee534a5844e6219665ce42b57707.diff
LOG: Add a new API seek for the Cursor class in the DataExtractor.cpp
Summary:
add a new API seek for the Cursor class in the DataExtractor.cpp
Reviewers: James Henderson, Fangrui Song
Differential Revision: https://reviews.llvm.org/D109603
Added:
Modified:
llvm/include/llvm/Support/DataExtractor.h
llvm/unittests/Support/DataExtractorTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/DataExtractor.h b/llvm/include/llvm/Support/DataExtractor.h
index f9335c161563..f4f5905d4bcc 100644
--- a/llvm/include/llvm/Support/DataExtractor.h
+++ b/llvm/include/llvm/Support/DataExtractor.h
@@ -70,6 +70,9 @@ class DataExtractor {
/// the position of the Cursor before the first error was encountered.
uint64_t tell() const { return Offset; }
+ /// Set the cursor to the new offset. This does not impact the error state.
+ void seek(uint64_t NewOffSet) { Offset = NewOffSet; }
+
/// Return error contained inside this Cursor, if any. Clears the internal
/// Cursor state.
Error takeError() { return std::move(Err); }
diff --git a/llvm/unittests/Support/DataExtractorTest.cpp b/llvm/unittests/Support/DataExtractorTest.cpp
index 41c40648b85e..358751cbb129 100644
--- a/llvm/unittests/Support/DataExtractorTest.cpp
+++ b/llvm/unittests/Support/DataExtractorTest.cpp
@@ -177,6 +177,18 @@ TEST(DataExtractorTest, Cursor_tell) {
consumeError(C.takeError());
}
+TEST(DataExtractorTest, Cursor_seek) {
+ DataExtractor::Cursor C(5);
+
+ C.seek(3);
+ EXPECT_EQ(3u, C.tell());
+
+ C.seek(8);
+ EXPECT_EQ(8u, C.tell());
+
+ EXPECT_THAT_ERROR(C.takeError(), Succeeded());
+}
+
TEST(DataExtractorTest, Cursor_takeError) {
DataExtractor DE(StringRef("AB"), false, 8);
DataExtractor::Cursor C(0);
More information about the llvm-commits
mailing list