Merge "Replace TypeQueueCheckAndPushBack with TypeStackGuard"
This commit is contained in:
@@ -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<repr::GlobalVarIR>::DumpDiff(
|
||||
repr::DiffMessageIR::DiffKind diff_kind) {
|
||||
std::deque<std::string> 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<repr::FunctionIR>::DumpDiff(
|
||||
repr::DiffMessageIR::DiffKind diff_kind) {
|
||||
std::deque<std::string> 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);
|
||||
|
||||
@@ -38,19 +38,6 @@ std::string Unwind(const std::deque<std::string> *type_queue) {
|
||||
return stack_str;
|
||||
}
|
||||
|
||||
static void TypeQueueCheckAndPushBack(std::deque<std::string> *type_queue,
|
||||
const std::string &str) {
|
||||
if (type_queue) {
|
||||
type_queue->push_back(str);
|
||||
}
|
||||
}
|
||||
|
||||
static void TypeQueueCheckAndPop(std::deque<std::string> *type_queue) {
|
||||
if (type_queue && !type_queue->empty()) {
|
||||
type_queue->pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
static std::string ConvertTypeIdToString(
|
||||
const AbiElementMap<const TypeIR *> &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 TypeIR *>::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;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,26 @@ struct RecordFieldDiffResult {
|
||||
std::vector<const RecordFieldIR *> added_fields;
|
||||
};
|
||||
|
||||
class TypeStackGuard {
|
||||
public:
|
||||
TypeStackGuard(std::deque<std::string> *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<std::string> *type_stack_;
|
||||
};
|
||||
|
||||
std::string Unwind(const std::deque<std::string> *type_queue);
|
||||
|
||||
struct DiffPolicyOptions {
|
||||
|
||||
Reference in New Issue
Block a user