From 033af47aa634d727d0e2102c1f5dea5c513916a9 Mon Sep 17 00:00:00 2001 From: Hsin-Yi Chen Date: Mon, 13 Feb 2023 16:46:00 +0800 Subject: [PATCH] Replace TypeQueueCheckAndPushBack with TypeStackGuard A followup commit will rename type_queue to type_stack. Test: ./test.py Bug: 255702405 Change-Id: Ie5c21b0883f08386d30b80ca955708aa7f4bdb16 --- .../src/diff/abi_diff_wrappers.cpp | 5 +++-- .../src/repr/abi_diff_helpers.cpp | 20 ++----------------- .../src/repr/abi_diff_helpers.h | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/vndk/tools/header-checker/src/diff/abi_diff_wrappers.cpp b/vndk/tools/header-checker/src/diff/abi_diff_wrappers.cpp index eeaa8819f..4e51ef697 100644 --- a/vndk/tools/header-checker/src/diff/abi_diff_wrappers.cpp +++ b/vndk/tools/header-checker/src/diff/abi_diff_wrappers.cpp @@ -25,6 +25,7 @@ namespace diff { using repr::AbiElementMap; using repr::DiffStatus; +using repr::TypeStackGuard; using repr::Unwind; @@ -56,7 +57,7 @@ template <> bool DiffWrapper::DumpDiff( repr::DiffMessageIR::DiffKind diff_kind) { std::deque type_queue; - type_queue.push_back(oldp_->GetName()); + TypeStackGuard guard(&type_queue, oldp_->GetName()); DiffStatus type_diff = CompareAndDumpTypeDiff(oldp_->GetReferencedType(), newp_->GetReferencedType(), &type_queue, diff_kind); @@ -78,7 +79,7 @@ template <> bool DiffWrapper::DumpDiff( repr::DiffMessageIR::DiffKind diff_kind) { std::deque type_queue; - type_queue.push_back(oldp_->GetName()); + TypeStackGuard guard(&type_queue, oldp_->GetName()); DiffStatus function_type_diff = CompareFunctionTypes(oldp_, newp_, &type_queue, diff_kind); diff --git a/vndk/tools/header-checker/src/repr/abi_diff_helpers.cpp b/vndk/tools/header-checker/src/repr/abi_diff_helpers.cpp index 03cff4313..1184b770b 100644 --- a/vndk/tools/header-checker/src/repr/abi_diff_helpers.cpp +++ b/vndk/tools/header-checker/src/repr/abi_diff_helpers.cpp @@ -38,19 +38,6 @@ std::string Unwind(const std::deque *type_queue) { return stack_str; } -static void TypeQueueCheckAndPushBack(std::deque *type_queue, - const std::string &str) { - if (type_queue) { - type_queue->push_back(str); - } -} - -static void TypeQueueCheckAndPop(std::deque *type_queue) { - if (type_queue && !type_queue->empty()) { - type_queue->pop_back(); - } -} - static std::string ConvertTypeIdToString( const AbiElementMap &type_graph, const std::string &type_id) { @@ -1067,8 +1054,8 @@ DiffStatus AbiDiffHelper::CompareAndDumpTypeDiff( return DiffStatus::kNoDiff; } - TypeQueueCheckAndPushBack( - type_queue, ConvertTypeIdToString(old_types_,old_type_id)); + TypeStackGuard guard(type_queue, + ConvertTypeIdToString(old_types_, old_type_id)); AbiElementMap::const_iterator old_it = old_types_.find(old_type_id); @@ -1076,7 +1063,6 @@ DiffStatus AbiDiffHelper::CompareAndDumpTypeDiff( new_types_.find(new_type_id); if (old_it == old_types_.end() || new_it == new_types_.end()) { - TypeQueueCheckAndPop(type_queue); // One of the types were hidden, we cannot compare further. return AreOpaqueTypesEqual(old_type_id, new_type_id) ? DiffStatus::kNoDiff @@ -1092,8 +1078,6 @@ DiffStatus AbiDiffHelper::CompareAndDumpTypeDiff( diff_status = CompareAndDumpTypeDiff(old_it->second , new_it->second , old_kind, type_queue, diff_kind); } - - TypeQueueCheckAndPop(type_queue); return diff_status; } diff --git a/vndk/tools/header-checker/src/repr/abi_diff_helpers.h b/vndk/tools/header-checker/src/repr/abi_diff_helpers.h index 6a63fbc38..8f1fdbd67 100644 --- a/vndk/tools/header-checker/src/repr/abi_diff_helpers.h +++ b/vndk/tools/header-checker/src/repr/abi_diff_helpers.h @@ -70,6 +70,26 @@ struct RecordFieldDiffResult { std::vector added_fields; }; +class TypeStackGuard { + public: + TypeStackGuard(std::deque *type_stack, + const std::string &type_name) { + type_stack_ = type_stack; + if (type_stack_) { + type_stack_->push_back(type_name); + } + } + + ~TypeStackGuard() { + if (type_stack_ && !type_stack_->empty()) { + type_stack_->pop_back(); + } + } + + private: + std::deque *type_stack_; +}; + std::string Unwind(const std::deque *type_queue); struct DiffPolicyOptions {