From 8c583c4767e4b2f4713c5d4b22cd25cf08b2e33d Mon Sep 17 00:00:00 2001 From: asoffer Date: Mon, 11 Sep 2023 01:05:10 -0400 Subject: [PATCH] Adding a begin iterator to the ValueStack. --- .bazelversion | 2 +- WORKSPACE | 6 +++--- jasmin/value_stack.h | 1 + jasmin/value_stack_test.cc | 10 ++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.bazelversion b/.bazelversion index ac14c3d..024b066 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.1.1 +6.2.1 diff --git a/WORKSPACE b/WORKSPACE index a119dcb..9331a4e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,9 +3,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "com_google_googletest", - urls = ["https://github.com/google/googletest/archive/d166e09483845b9b6a658dccc3d3dbb293676b62.zip"], - strip_prefix = "googletest-d166e09483845b9b6a658dccc3d3dbb293676b62", - sha256 = "d27641a853c49d3e8d7b9bbced1ceb861336134cd148bf6db720a40ccde66516", + urls = ["https://github.com/google/googletest/archive/8a6feabf04bec8fb125e0df0ad1195c42350725f.zip"], + strip_prefix = "googletest-8a6feabf04bec8fb125e0df0ad1195c42350725f", + sha256 = "c83f69fa8cb7a503d3ae9f736cf679b0846772b1ae955c63133520b749491a7c", ) http_archive( diff --git a/jasmin/value_stack.h b/jasmin/value_stack.h index fec152d..a76736a 100644 --- a/jasmin/value_stack.h +++ b/jasmin/value_stack.h @@ -50,6 +50,7 @@ struct ValueStack { using const_iterator = Value const *; // Returns an iterator referrencing one passed the end. of the `ValueStack`. + const_iterator begin() const { return values_.get(); } const_iterator end() const { return head_; } // Pop the top `Value` off the stack and return it. Behavior is undefined if diff --git a/jasmin/value_stack_test.cc b/jasmin/value_stack_test.cc index a8da549..9b23c2b 100644 --- a/jasmin/value_stack_test.cc +++ b/jasmin/value_stack_test.cc @@ -173,6 +173,16 @@ TEST(ValueStack, Erase) { #endif // defined(JASMIN_DEBUG) } +TEST(ValueStack, Begin) { + ValueStack value_stack{1, true, 3.14}; + EXPECT_EQ((value_stack.begin() + 2)->as(), 3.14); + EXPECT_EQ((value_stack.begin() + 1)->as(), true); + EXPECT_EQ((value_stack.begin())->as(), 1); + value_stack.pop_value(); + EXPECT_EQ((value_stack.begin() + 2)->as(), true); + EXPECT_EQ((value_stack.begin() + 1)->as(), 1); +} + TEST(ValueStack, End) { ValueStack value_stack{1, true, 3.14}; EXPECT_EQ((value_stack.end() - 1)->as(), 3.14);