c201bb0909
`foo ## __LINE__` just emits foo__LINE__ because of how preprocessor expansion works. The typical solution for this is to use a CONCAT macro, but we in fact already have a helper for what this is trying to solve, UNIQUE_IDENTIFIER, so just use that instead. Change-Id: Icea3f01db458c5d557e0affd3b004f4478c6c315 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3293084 Auto-Submit: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Zhi An Ng <zhin@chromium.org> Reviewed-by: Zhi An Ng <zhin@chromium.org> Cr-Commit-Position: refs/heads/main@{#77998}
35 lines
882 B
C++
35 lines
882 B
C++
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef V8_TEST_COMMON_FLAG_UTILS_H
|
|
#define V8_TEST_COMMON_FLAG_UTILS_H
|
|
|
|
#include "src/base/macros.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
template <typename T>
|
|
class V8_NODISCARD FlagScope {
|
|
public:
|
|
FlagScope(T* flag, T new_value) : flag_(flag), previous_value_(*flag) {
|
|
*flag = new_value;
|
|
}
|
|
~FlagScope() { *flag_ = previous_value_; }
|
|
|
|
private:
|
|
T* flag_;
|
|
T previous_value_;
|
|
};
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|
|
|
|
#define FLAG_VALUE_SCOPE(flag, value) \
|
|
v8::internal::FlagScope<bool> UNIQUE_IDENTIFIER(__scope_##flag)( \
|
|
&v8::internal::FLAG_##flag, value)
|
|
#define FLAG_SCOPE(flag) FLAG_VALUE_SCOPE(flag, true)
|
|
|
|
#endif // V8_TEST_COMMON_FLAG_UTILS_H
|