diff options
author | anastasy888 <anastasy888@yandex-team.ru> | 2022-02-10 16:45:55 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:55 +0300 |
commit | 3a7a498715ef1b66f5054455421b845e45e3a653 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/restricted/abseil-cpp/absl/flags | |
parent | 49f765d71da452ea93138a25559dfa68dd76c7f3 (diff) | |
download | ydb-3a7a498715ef1b66f5054455421b845e45e3a653.tar.gz |
Restoring authorship annotation for <anastasy888@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/restricted/abseil-cpp/absl/flags')
29 files changed, 3223 insertions, 3223 deletions
diff --git a/contrib/restricted/abseil-cpp/absl/flags/config.h b/contrib/restricted/abseil-cpp/absl/flags/config.h index 1bfa9b8ff4..5ab1f311dc 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/config.h +++ b/contrib/restricted/abseil-cpp/absl/flags/config.h @@ -1,50 +1,50 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_FLAGS_CONFIG_H_ -#define ABSL_FLAGS_CONFIG_H_ - -// Determine if we should strip string literals from the Flag objects. -// By default we strip string literals on mobile platforms. -#if !defined(ABSL_FLAGS_STRIP_NAMES) - -#if defined(__ANDROID__) -#define ABSL_FLAGS_STRIP_NAMES 1 - -#elif defined(__APPLE__) -#include <TargetConditionals.h> -#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE -#define ABSL_FLAGS_STRIP_NAMES 1 -#elif defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED -#define ABSL_FLAGS_STRIP_NAMES 1 -#endif // TARGET_OS_* -#endif - -#endif // !defined(ABSL_FLAGS_STRIP_NAMES) - -#if !defined(ABSL_FLAGS_STRIP_NAMES) -// If ABSL_FLAGS_STRIP_NAMES wasn't set on the command line or above, -// the default is not to strip. -#define ABSL_FLAGS_STRIP_NAMES 0 -#endif - -#if !defined(ABSL_FLAGS_STRIP_HELP) -// By default, if we strip names, we also strip help. -#define ABSL_FLAGS_STRIP_HELP ABSL_FLAGS_STRIP_NAMES -#endif - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ABSL_FLAGS_CONFIG_H_ +#define ABSL_FLAGS_CONFIG_H_ + +// Determine if we should strip string literals from the Flag objects. +// By default we strip string literals on mobile platforms. +#if !defined(ABSL_FLAGS_STRIP_NAMES) + +#if defined(__ANDROID__) +#define ABSL_FLAGS_STRIP_NAMES 1 + +#elif defined(__APPLE__) +#include <TargetConditionals.h> +#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE +#define ABSL_FLAGS_STRIP_NAMES 1 +#elif defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED +#define ABSL_FLAGS_STRIP_NAMES 1 +#endif // TARGET_OS_* +#endif + +#endif // !defined(ABSL_FLAGS_STRIP_NAMES) + +#if !defined(ABSL_FLAGS_STRIP_NAMES) +// If ABSL_FLAGS_STRIP_NAMES wasn't set on the command line or above, +// the default is not to strip. +#define ABSL_FLAGS_STRIP_NAMES 0 +#endif + +#if !defined(ABSL_FLAGS_STRIP_HELP) +// By default, if we strip names, we also strip help. +#define ABSL_FLAGS_STRIP_HELP ABSL_FLAGS_STRIP_NAMES +#endif + // ABSL_FLAGS_INTERNAL_HAS_RTTI macro is used for selecting if we can use RTTI // for flag type identification. #ifdef ABSL_FLAGS_INTERNAL_HAS_RTTI @@ -73,4 +73,4 @@ A(std::string, std_string) \ A(std::vector<std::string>, std_vector_of_string) -#endif // ABSL_FLAGS_CONFIG_H_ +#endif // ABSL_FLAGS_CONFIG_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/declare.h b/contrib/restricted/abseil-cpp/absl/flags/declare.h index fa240c84bf..b9794d8b85 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/declare.h +++ b/contrib/restricted/abseil-cpp/absl/flags/declare.h @@ -1,65 +1,65 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ----------------------------------------------------------------------------- -// File: declare.h -// ----------------------------------------------------------------------------- -// -// This file defines the ABSL_DECLARE_FLAG macro, allowing you to declare an -// `absl::Flag` for use within a translation unit. You should place this -// declaration within the header file associated with the .cc file that defines -// and owns the `Flag`. - -#ifndef ABSL_FLAGS_DECLARE_H_ -#define ABSL_FLAGS_DECLARE_H_ - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ----------------------------------------------------------------------------- +// File: declare.h +// ----------------------------------------------------------------------------- +// +// This file defines the ABSL_DECLARE_FLAG macro, allowing you to declare an +// `absl::Flag` for use within a translation unit. You should place this +// declaration within the header file associated with the .cc file that defines +// and owns the `Flag`. + +#ifndef ABSL_FLAGS_DECLARE_H_ +#define ABSL_FLAGS_DECLARE_H_ + #include "absl/base/config.h" - -namespace absl { + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -// absl::Flag<T> represents a flag of type 'T' created by ABSL_FLAG. -template <typename T> -class Flag; - -} // namespace flags_internal - -// Flag -// -// Forward declaration of the `absl::Flag` type for use in defining the macro. -#if defined(_MSC_VER) && !defined(__clang__) -template <typename T> -class Flag; -#else -template <typename T> -using Flag = flags_internal::Flag<T>; -#endif - +namespace flags_internal { + +// absl::Flag<T> represents a flag of type 'T' created by ABSL_FLAG. +template <typename T> +class Flag; + +} // namespace flags_internal + +// Flag +// +// Forward declaration of the `absl::Flag` type for use in defining the macro. +#if defined(_MSC_VER) && !defined(__clang__) +template <typename T> +class Flag; +#else +template <typename T> +using Flag = flags_internal::Flag<T>; +#endif + ABSL_NAMESPACE_END -} // namespace absl - -// ABSL_DECLARE_FLAG() -// -// This macro is a convenience for declaring use of an `absl::Flag` within a -// translation unit. This macro should be used within a header file to -// declare usage of the flag within any .cc file including that header file. -// -// The ABSL_DECLARE_FLAG(type, name) macro expands to: -// -// extern absl::Flag<type> FLAGS_name; -#define ABSL_DECLARE_FLAG(type, name) extern ::absl::Flag<type> FLAGS_##name - -#endif // ABSL_FLAGS_DECLARE_H_ +} // namespace absl + +// ABSL_DECLARE_FLAG() +// +// This macro is a convenience for declaring use of an `absl::Flag` within a +// translation unit. This macro should be used within a header file to +// declare usage of the flag within any .cc file including that header file. +// +// The ABSL_DECLARE_FLAG(type, name) macro expands to: +// +// extern absl::Flag<type> FLAGS_name; +#define ABSL_DECLARE_FLAG(type, name) extern ::absl::Flag<type> FLAGS_##name + +#endif // ABSL_FLAGS_DECLARE_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/flag.cc b/contrib/restricted/abseil-cpp/absl/flags/flag.cc index 73f1d5a55c..531df1287a 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/flag.cc +++ b/contrib/restricted/abseil-cpp/absl/flags/flag.cc @@ -1,38 +1,38 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/flags/flag.h" - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/flags/flag.h" + #include "absl/base/config.h" - -namespace absl { + +namespace absl { ABSL_NAMESPACE_BEGIN - + // This global mutex protects on-demand construction of flag objects in MSVC -// builds. -#if defined(_MSC_VER) && !defined(__clang__) - -namespace flags_internal { - -ABSL_CONST_INIT static absl::Mutex construction_guard(absl::kConstInit); - -absl::Mutex* GetGlobalConstructionGuard() { return &construction_guard; } - -} // namespace flags_internal - -#endif - +// builds. +#if defined(_MSC_VER) && !defined(__clang__) + +namespace flags_internal { + +ABSL_CONST_INIT static absl::Mutex construction_guard(absl::kConstInit); + +absl::Mutex* GetGlobalConstructionGuard() { return &construction_guard; } + +} // namespace flags_internal + +#endif + ABSL_NAMESPACE_END -} // namespace absl +} // namespace absl diff --git a/contrib/restricted/abseil-cpp/absl/flags/flag.h b/contrib/restricted/abseil-cpp/absl/flags/flag.h index 98a50faa29..a724ccc97d 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/flag.h +++ b/contrib/restricted/abseil-cpp/absl/flags/flag.h @@ -1,121 +1,121 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ----------------------------------------------------------------------------- -// File: flag.h -// ----------------------------------------------------------------------------- -// -// This header file defines the `absl::Flag<T>` type for holding command-line -// flag data, and abstractions to create, get and set such flag data. -// -// It is important to note that this type is **unspecified** (an implementation -// detail) and you do not construct or manipulate actual `absl::Flag<T>` -// instances. Instead, you define and declare flags using the -// `ABSL_FLAG()` and `ABSL_DECLARE_FLAG()` macros, and get and set flag values -// using the `absl::GetFlag()` and `absl::SetFlag()` functions. - -#ifndef ABSL_FLAGS_FLAG_H_ -#define ABSL_FLAGS_FLAG_H_ - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ----------------------------------------------------------------------------- +// File: flag.h +// ----------------------------------------------------------------------------- +// +// This header file defines the `absl::Flag<T>` type for holding command-line +// flag data, and abstractions to create, get and set such flag data. +// +// It is important to note that this type is **unspecified** (an implementation +// detail) and you do not construct or manipulate actual `absl::Flag<T>` +// instances. Instead, you define and declare flags using the +// `ABSL_FLAG()` and `ABSL_DECLARE_FLAG()` macros, and get and set flag values +// using the `absl::GetFlag()` and `absl::SetFlag()` functions. + +#ifndef ABSL_FLAGS_FLAG_H_ +#define ABSL_FLAGS_FLAG_H_ + #include <string> #include <type_traits> -#include "absl/base/attributes.h" +#include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/optimization.h" -#include "absl/flags/config.h" -#include "absl/flags/internal/flag.h" +#include "absl/flags/config.h" +#include "absl/flags/internal/flag.h" #include "absl/flags/internal/registry.h" #include "absl/strings/string_view.h" - -namespace absl { + +namespace absl { ABSL_NAMESPACE_BEGIN - -// Flag -// -// An `absl::Flag` holds a command-line flag value, providing a runtime -// parameter to a binary. Such flags should be defined in the global namespace -// and (preferably) in the module containing the binary's `main()` function. -// -// You should not construct and cannot use the `absl::Flag` type directly; -// instead, you should declare flags using the `ABSL_DECLARE_FLAG()` macro -// within a header file, and define your flag using `ABSL_FLAG()` within your -// header's associated `.cc` file. Such flags will be named `FLAGS_name`. -// -// Example: -// -// .h file -// -// // Declares usage of a flag named "FLAGS_count" -// ABSL_DECLARE_FLAG(int, count); -// -// .cc file -// -// // Defines a flag named "FLAGS_count" with a default `int` value of 0. -// ABSL_FLAG(int, count, 0, "Count of items to process"); -// -// No public methods of `absl::Flag<T>` are part of the Abseil Flags API. -#if !defined(_MSC_VER) || defined(__clang__) -template <typename T> -using Flag = flags_internal::Flag<T>; -#else + +// Flag +// +// An `absl::Flag` holds a command-line flag value, providing a runtime +// parameter to a binary. Such flags should be defined in the global namespace +// and (preferably) in the module containing the binary's `main()` function. +// +// You should not construct and cannot use the `absl::Flag` type directly; +// instead, you should declare flags using the `ABSL_DECLARE_FLAG()` macro +// within a header file, and define your flag using `ABSL_FLAG()` within your +// header's associated `.cc` file. Such flags will be named `FLAGS_name`. +// +// Example: +// +// .h file +// +// // Declares usage of a flag named "FLAGS_count" +// ABSL_DECLARE_FLAG(int, count); +// +// .cc file +// +// // Defines a flag named "FLAGS_count" with a default `int` value of 0. +// ABSL_FLAG(int, count, 0, "Count of items to process"); +// +// No public methods of `absl::Flag<T>` are part of the Abseil Flags API. +#if !defined(_MSC_VER) || defined(__clang__) +template <typename T> +using Flag = flags_internal::Flag<T>; +#else #include "absl/flags/internal/flag_msvc.inc" -#endif - -// GetFlag() -// -// Returns the value (of type `T`) of an `absl::Flag<T>` instance, by value. Do -// not construct an `absl::Flag<T>` directly and call `absl::GetFlag()`; -// instead, refer to flag's constructed variable name (e.g. `FLAGS_name`). -// Because this function returns by value and not by reference, it is -// thread-safe, but note that the operation may be expensive; as a result, avoid -// `absl::GetFlag()` within any tight loops. -// -// Example: -// -// // FLAGS_count is a Flag of type `int` -// int my_count = absl::GetFlag(FLAGS_count); -// -// // FLAGS_firstname is a Flag of type `std::string` -// std::string first_name = absl::GetFlag(FLAGS_firstname); -template <typename T> -ABSL_MUST_USE_RESULT T GetFlag(const absl::Flag<T>& flag) { +#endif + +// GetFlag() +// +// Returns the value (of type `T`) of an `absl::Flag<T>` instance, by value. Do +// not construct an `absl::Flag<T>` directly and call `absl::GetFlag()`; +// instead, refer to flag's constructed variable name (e.g. `FLAGS_name`). +// Because this function returns by value and not by reference, it is +// thread-safe, but note that the operation may be expensive; as a result, avoid +// `absl::GetFlag()` within any tight loops. +// +// Example: +// +// // FLAGS_count is a Flag of type `int` +// int my_count = absl::GetFlag(FLAGS_count); +// +// // FLAGS_firstname is a Flag of type `std::string` +// std::string first_name = absl::GetFlag(FLAGS_firstname); +template <typename T> +ABSL_MUST_USE_RESULT T GetFlag(const absl::Flag<T>& flag) { return flags_internal::FlagImplPeer::InvokeGet<T>(flag); -} - -// SetFlag() -// -// Sets the value of an `absl::Flag` to the value `v`. Do not construct an -// `absl::Flag<T>` directly and call `absl::SetFlag()`; instead, use the -// flag's variable name (e.g. `FLAGS_name`). This function is -// thread-safe, but is potentially expensive. Avoid setting flags in general, -// but especially within performance-critical code. -template <typename T> -void SetFlag(absl::Flag<T>* flag, const T& v) { +} + +// SetFlag() +// +// Sets the value of an `absl::Flag` to the value `v`. Do not construct an +// `absl::Flag<T>` directly and call `absl::SetFlag()`; instead, use the +// flag's variable name (e.g. `FLAGS_name`). This function is +// thread-safe, but is potentially expensive. Avoid setting flags in general, +// but especially within performance-critical code. +template <typename T> +void SetFlag(absl::Flag<T>* flag, const T& v) { flags_internal::FlagImplPeer::InvokeSet(*flag, v); -} - -// Overload of `SetFlag()` to allow callers to pass in a value that is -// convertible to `T`. E.g., use this overload to pass a "const char*" when `T` -// is `std::string`. -template <typename T, typename V> -void SetFlag(absl::Flag<T>* flag, const V& v) { - T value(v); +} + +// Overload of `SetFlag()` to allow callers to pass in a value that is +// convertible to `T`. E.g., use this overload to pass a "const char*" when `T` +// is `std::string`. +template <typename T, typename V> +void SetFlag(absl::Flag<T>* flag, const V& v) { + T value(v); flags_internal::FlagImplPeer::InvokeSet(*flag, value); -} - +} + // GetFlagReflectionHandle() // // Returns the reflection handle corresponding to specified Abseil Flag @@ -132,66 +132,66 @@ const CommandLineFlag& GetFlagReflectionHandle(const absl::Flag<T>& f) { } ABSL_NAMESPACE_END -} // namespace absl - - -// ABSL_FLAG() -// -// This macro defines an `absl::Flag<T>` instance of a specified type `T`: -// -// ABSL_FLAG(T, name, default_value, help); -// -// where: -// -// * `T` is a supported flag type (see the list of types in `marshalling.h`), -// * `name` designates the name of the flag (as a global variable -// `FLAGS_name`), -// * `default_value` is an expression holding the default value for this flag -// (which must be implicitly convertible to `T`), -// * `help` is the help text, which can also be an expression. -// -// This macro expands to a flag named 'FLAGS_name' of type 'T': -// -// absl::Flag<T> FLAGS_name = ...; -// -// Note that all such instances are created as global variables. -// -// For `ABSL_FLAG()` values that you wish to expose to other translation units, -// it is recommended to define those flags within the `.cc` file associated with -// the header where the flag is declared. -// -// Note: do not construct objects of type `absl::Flag<T>` directly. Only use the -// `ABSL_FLAG()` macro for such construction. -#define ABSL_FLAG(Type, name, default_value, help) \ - ABSL_FLAG_IMPL(Type, name, default_value, help) - -// ABSL_FLAG().OnUpdate() -// -// Defines a flag of type `T` with a callback attached: -// -// ABSL_FLAG(T, name, default_value, help).OnUpdate(callback); -// +} // namespace absl + + +// ABSL_FLAG() +// +// This macro defines an `absl::Flag<T>` instance of a specified type `T`: +// +// ABSL_FLAG(T, name, default_value, help); +// +// where: +// +// * `T` is a supported flag type (see the list of types in `marshalling.h`), +// * `name` designates the name of the flag (as a global variable +// `FLAGS_name`), +// * `default_value` is an expression holding the default value for this flag +// (which must be implicitly convertible to `T`), +// * `help` is the help text, which can also be an expression. +// +// This macro expands to a flag named 'FLAGS_name' of type 'T': +// +// absl::Flag<T> FLAGS_name = ...; +// +// Note that all such instances are created as global variables. +// +// For `ABSL_FLAG()` values that you wish to expose to other translation units, +// it is recommended to define those flags within the `.cc` file associated with +// the header where the flag is declared. +// +// Note: do not construct objects of type `absl::Flag<T>` directly. Only use the +// `ABSL_FLAG()` macro for such construction. +#define ABSL_FLAG(Type, name, default_value, help) \ + ABSL_FLAG_IMPL(Type, name, default_value, help) + +// ABSL_FLAG().OnUpdate() +// +// Defines a flag of type `T` with a callback attached: +// +// ABSL_FLAG(T, name, default_value, help).OnUpdate(callback); +// // `callback` should be convertible to `void (*)()`. // -// After any setting of the flag value, the callback will be called at least -// once. A rapid sequence of changes may be merged together into the same -// callback. No concurrent calls to the callback will be made for the same -// flag. Callbacks are allowed to read the current value of the flag but must -// not mutate that flag. -// -// The update mechanism guarantees "eventual consistency"; if the callback -// derives an auxiliary data structure from the flag value, it is guaranteed -// that eventually the flag value and the derived data structure will be -// consistent. -// -// Note: ABSL_FLAG.OnUpdate() does not have a public definition. Hence, this -// comment serves as its API documentation. - -// ----------------------------------------------------------------------------- -// Implementation details below this section -// ----------------------------------------------------------------------------- - -// ABSL_FLAG_IMPL macro definition conditional on ABSL_FLAGS_STRIP_NAMES +// After any setting of the flag value, the callback will be called at least +// once. A rapid sequence of changes may be merged together into the same +// callback. No concurrent calls to the callback will be made for the same +// flag. Callbacks are allowed to read the current value of the flag but must +// not mutate that flag. +// +// The update mechanism guarantees "eventual consistency"; if the callback +// derives an auxiliary data structure from the flag value, it is guaranteed +// that eventually the flag value and the derived data structure will be +// consistent. +// +// Note: ABSL_FLAG.OnUpdate() does not have a public definition. Hence, this +// comment serves as its API documentation. + +// ----------------------------------------------------------------------------- +// Implementation details below this section +// ----------------------------------------------------------------------------- + +// ABSL_FLAG_IMPL macro definition conditional on ABSL_FLAGS_STRIP_NAMES #if !defined(_MSC_VER) || defined(__clang__) #define ABSL_FLAG_IMPL_FLAG_PTR(flag) flag #define ABSL_FLAG_IMPL_HELP_ARG(name) \ @@ -204,34 +204,34 @@ ABSL_NAMESPACE_END #define ABSL_FLAG_IMPL_HELP_ARG(name) &AbslFlagHelpGenFor##name::NonConst #define ABSL_FLAG_IMPL_DEFAULT_ARG(Type, name) &AbslFlagDefaultGenFor##name::Gen #endif - -#if ABSL_FLAGS_STRIP_NAMES -#define ABSL_FLAG_IMPL_FLAGNAME(txt) "" -#define ABSL_FLAG_IMPL_FILENAME() "" + +#if ABSL_FLAGS_STRIP_NAMES +#define ABSL_FLAG_IMPL_FLAGNAME(txt) "" +#define ABSL_FLAG_IMPL_FILENAME() "" #define ABSL_FLAG_IMPL_REGISTRAR(T, flag) \ absl::flags_internal::FlagRegistrar<T, false>(ABSL_FLAG_IMPL_FLAG_PTR(flag), \ nullptr) -#else -#define ABSL_FLAG_IMPL_FLAGNAME(txt) txt -#define ABSL_FLAG_IMPL_FILENAME() __FILE__ +#else +#define ABSL_FLAG_IMPL_FLAGNAME(txt) txt +#define ABSL_FLAG_IMPL_FILENAME() __FILE__ #define ABSL_FLAG_IMPL_REGISTRAR(T, flag) \ absl::flags_internal::FlagRegistrar<T, true>(ABSL_FLAG_IMPL_FLAG_PTR(flag), \ __FILE__) -#endif - -// ABSL_FLAG_IMPL macro definition conditional on ABSL_FLAGS_STRIP_HELP - -#if ABSL_FLAGS_STRIP_HELP -#define ABSL_FLAG_IMPL_FLAGHELP(txt) absl::flags_internal::kStrippedFlagHelp -#else -#define ABSL_FLAG_IMPL_FLAGHELP(txt) txt -#endif - -// AbslFlagHelpGenFor##name is used to encapsulate both immediate (method Const) -// and lazy (method NonConst) evaluation of help message expression. We choose -// between the two via the call to HelpArg in absl::Flag instantiation below. -// If help message expression is constexpr evaluable compiler will optimize -// away this whole struct. +#endif + +// ABSL_FLAG_IMPL macro definition conditional on ABSL_FLAGS_STRIP_HELP + +#if ABSL_FLAGS_STRIP_HELP +#define ABSL_FLAG_IMPL_FLAGHELP(txt) absl::flags_internal::kStrippedFlagHelp +#else +#define ABSL_FLAG_IMPL_FLAGHELP(txt) txt +#endif + +// AbslFlagHelpGenFor##name is used to encapsulate both immediate (method Const) +// and lazy (method NonConst) evaluation of help message expression. We choose +// between the two via the call to HelpArg in absl::Flag instantiation below. +// If help message expression is constexpr evaluable compiler will optimize +// away this whole struct. // TODO(rogeeff): place these generated structs into local namespace and apply // ABSL_INTERNAL_UNIQUE_SHORT_NAME. // TODO(rogeeff): Apply __attribute__((nodebug)) to FLAGS_help_storage_##name @@ -250,7 +250,7 @@ ABSL_NAMESPACE_END ABSL_ATTRIBUTE_SECTION_VARIABLE(flags_help_cold) = \ absl::flags_internal::HelpStringAsArray<AbslFlagHelpGenFor##name>( \ 0); - + #define ABSL_FLAG_IMPL_DECLARE_DEF_VAL_WRAPPER(name, Type, default_value) \ struct AbslFlagDefaultGenFor##name { \ Type value = absl::flags_internal::InitDefaultValue<Type>(default_value); \ @@ -258,12 +258,12 @@ ABSL_NAMESPACE_END new (absl_flag_default_loc) Type(AbslFlagDefaultGenFor##name{}.value); \ } \ }; - -// ABSL_FLAG_IMPL -// -// Note: Name of registrar object is not arbitrary. It is used to "grab" -// global name for FLAGS_no<flag_name> symbol, thus preventing the possibility -// of defining two flags with names foo and nofoo. + +// ABSL_FLAG_IMPL +// +// Note: Name of registrar object is not arbitrary. It is used to "grab" +// global name for FLAGS_no<flag_name> symbol, thus preventing the possibility +// of defining two flags with names foo and nofoo. #define ABSL_FLAG_IMPL(Type, name, default_value, help) \ namespace absl /* block flags in namespaces */ {} \ ABSL_FLAG_IMPL_DECLARE_DEF_VAL_WRAPPER(name, Type, default_value) \ @@ -274,26 +274,26 @@ ABSL_NAMESPACE_END extern absl::flags_internal::FlagRegistrarEmpty FLAGS_no##name; \ absl::flags_internal::FlagRegistrarEmpty FLAGS_no##name = \ ABSL_FLAG_IMPL_REGISTRAR(Type, FLAGS_##name) - -// ABSL_RETIRED_FLAG -// -// Designates the flag (which is usually pre-existing) as "retired." A retired -// flag is a flag that is now unused by the program, but may still be passed on -// the command line, usually by production scripts. A retired flag is ignored -// and code can't access it at runtime. -// -// This macro registers a retired flag with given name and type, with a name -// identical to the name of the original flag you are retiring. The retired -// flag's type can change over time, so that you can retire code to support a -// custom flag type. -// -// This macro has the same signature as `ABSL_FLAG`. To retire a flag, simply -// replace an `ABSL_FLAG` definition with `ABSL_RETIRED_FLAG`, leaving the -// arguments unchanged (unless of course you actually want to retire the flag -// type at this time as well). -// -// `default_value` is only used as a double check on the type. `explanation` is -// unused. + +// ABSL_RETIRED_FLAG +// +// Designates the flag (which is usually pre-existing) as "retired." A retired +// flag is a flag that is now unused by the program, but may still be passed on +// the command line, usually by production scripts. A retired flag is ignored +// and code can't access it at runtime. +// +// This macro registers a retired flag with given name and type, with a name +// identical to the name of the original flag you are retiring. The retired +// flag's type can change over time, so that you can retire code to support a +// custom flag type. +// +// This macro has the same signature as `ABSL_FLAG`. To retire a flag, simply +// replace an `ABSL_FLAG` definition with `ABSL_RETIRED_FLAG`, leaving the +// arguments unchanged (unless of course you actually want to retire the flag +// type at this time as well). +// +// `default_value` is only used as a double check on the type. `explanation` is +// unused. // TODO(rogeeff): replace RETIRED_FLAGS with FLAGS once forward declarations of // retired flags are cleaned up. #define ABSL_RETIRED_FLAG(type, name, default_value, explanation) \ @@ -301,5 +301,5 @@ ABSL_NAMESPACE_END ABSL_ATTRIBUTE_UNUSED static const auto RETIRED_FLAGS_REG_##name = \ (RETIRED_FLAGS_##name.Retire(#name), \ ::absl::flags_internal::FlagRegistrarEmpty{}) - -#endif // ABSL_FLAGS_FLAG_H_ + +#endif // ABSL_FLAGS_FLAG_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag.cc b/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag.cc index 57596fc6d9..4482955c4c 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag.cc +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag.cc @@ -1,26 +1,26 @@ -// +// // Copyright 2020 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/flags/internal/commandlineflag.h" - -namespace absl { +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/flags/internal/commandlineflag.h" + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - +namespace flags_internal { + FlagStateInterface::~FlagStateInterface() {} - -} // namespace flags_internal + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl +} // namespace absl diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag.h b/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag.h index 8a96d714bd..ebfe81ba1e 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag.h +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag.h @@ -1,68 +1,68 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_ -#define ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_ - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_ +#define ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_ + #include "absl/base/config.h" #include "absl/base/internal/fast_type_id.h" - -namespace absl { + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - +namespace flags_internal { + // An alias for flag fast type id. This value identifies the flag value type // similarly to typeid(T), without relying on RTTI being available. In most // cases this id is enough to uniquely identify the flag's value type. In a few // cases we'll have to resort to using actual RTTI implementation if it is // available. using FlagFastTypeId = absl::base_internal::FastTypeIdType; - -// Options that control SetCommandLineOptionWithMode. -enum FlagSettingMode { - // update the flag's value unconditionally (can call this multiple times). - SET_FLAGS_VALUE, - // update the flag's value, but *only if* it has not yet been updated - // with SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef". - SET_FLAG_IF_DEFAULT, - // set the flag's default value to this. If the flag has not been updated - // yet (via SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef") - // change the flag's current value to the new default value as well. - SET_FLAGS_DEFAULT -}; - + +// Options that control SetCommandLineOptionWithMode. +enum FlagSettingMode { + // update the flag's value unconditionally (can call this multiple times). + SET_FLAGS_VALUE, + // update the flag's value, but *only if* it has not yet been updated + // with SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef". + SET_FLAG_IF_DEFAULT, + // set the flag's default value to this. If the flag has not been updated + // yet (via SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef") + // change the flag's current value to the new default value as well. + SET_FLAGS_DEFAULT +}; + // Options that control ParseFrom: Source of a value. -enum ValueSource { - // Flag is being set by value specified on a command line. - kCommandLine, - // Flag is being set by value specified in the code. - kProgrammaticChange, -}; - -// Handle to FlagState objects. Specific flag state objects will restore state -// of a flag produced this flag state from method CommandLineFlag::SaveState(). -class FlagStateInterface { - public: +enum ValueSource { + // Flag is being set by value specified on a command line. + kCommandLine, + // Flag is being set by value specified in the code. + kProgrammaticChange, +}; + +// Handle to FlagState objects. Specific flag state objects will restore state +// of a flag produced this flag state from method CommandLineFlag::SaveState(). +class FlagStateInterface { + public: virtual ~FlagStateInterface(); - - // Restores the flag originated this object to the saved state. - virtual void Restore() const = 0; -}; - -} // namespace flags_internal + + // Restores the flag originated this object to the saved state. + virtual void Restore() const = 0; +}; + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_ +} // namespace absl + +#endif // ABSL_FLAGS_INTERNAL_COMMANDLINEFLAG_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag/ya.make b/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag/ya.make index e03e2878db..e5a0389d4d 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag/ya.make +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag/ya.make @@ -1,29 +1,29 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() -OWNER(g:cpp-contrib) - -LICENSE(Apache-2.0) - -ADDINCL( - GLOBAL contrib/restricted/abseil-cpp -) - -NO_COMPILER_WARNINGS() - -NO_UTIL() - +OWNER(g:cpp-contrib) + +LICENSE(Apache-2.0) + +ADDINCL( + GLOBAL contrib/restricted/abseil-cpp +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + CFLAGS( -DNOMINMAX ) -SRCDIR(contrib/restricted/abseil-cpp/absl/flags/internal) - -SRCS( - commandlineflag.cc -) - -END() +SRCDIR(contrib/restricted/abseil-cpp/absl/flags/internal) + +SRCS( + commandlineflag.cc +) + +END() diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/flag.cc b/contrib/restricted/abseil-cpp/absl/flags/internal/flag.cc index abaea99043..1515022d11 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/flag.cc +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/flag.cc @@ -1,20 +1,20 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/flags/internal/flag.h" - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/flags/internal/flag.h" + #include <assert.h> #include <stddef.h> #include <stdint.h> @@ -30,18 +30,18 @@ #include "absl/base/call_once.h" #include "absl/base/casts.h" #include "absl/base/config.h" -#include "absl/base/optimization.h" +#include "absl/base/optimization.h" #include "absl/flags/config.h" #include "absl/flags/internal/commandlineflag.h" #include "absl/flags/usage_config.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" - -namespace absl { +#include "absl/synchronization/mutex.h" + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { +namespace flags_internal { // The help message indicating that the commandline flag has been // 'stripped'. It will not show up when doing "-help" and its @@ -49,18 +49,18 @@ namespace flags_internal { // before including absl/flags/flag.h const char kStrippedFlagHelp[] = "\001\002\003\004 (unknown) \004\003\002\001"; -namespace { - -// Currently we only validate flag values for user-defined flag types. +namespace { + +// Currently we only validate flag values for user-defined flag types. bool ShouldValidateFlagValue(FlagFastTypeId flag_type_id) { #define DONT_VALIDATE(T, _) \ if (flag_type_id == base_internal::FastTypeId<T>()) return false; ABSL_FLAGS_INTERNAL_SUPPORTED_TYPES(DONT_VALIDATE) -#undef DONT_VALIDATE - - return true; -} - +#undef DONT_VALIDATE + + return true; +} + // RAII helper used to temporarily unlock and relock `absl::Mutex`. // This is used when we need to ensure that locks are released while // invoking user supplied callbacks and then reacquired, since callbacks may @@ -77,13 +77,13 @@ class MutexRelock { absl::Mutex& mu_; }; -} // namespace - +} // namespace + /////////////////////////////////////////////////////////////////////////////// // Persistent state of the flag data. - + class FlagImpl; - + class FlagState : public flags_internal::FlagStateInterface { public: template <typename V> @@ -100,11 +100,11 @@ class FlagState : public flags_internal::FlagStateInterface { flag_impl_.ValueStorageKind() != FlagValueStorageKind::kSequenceLocked) return; flags_internal::Delete(flag_impl_.op_, value_.heap_allocated); - } - + } + private: friend class FlagImpl; - + // Restores the flag to the saved state. void Restore() const override { if (!flag_impl_.RestoreState(*this)) return; @@ -112,7 +112,7 @@ class FlagState : public flags_internal::FlagStateInterface { ABSL_INTERNAL_LOG(INFO, absl::StrCat("Restore saved value of ", flag_impl_.Name(), " to: ", flag_impl_.CurrentValue())); - } + } // Flag and saved flag data. FlagImpl& flag_impl_; @@ -137,8 +137,8 @@ void DynValueDeleter::operator()(void* ptr) const { if (op == nullptr) return; Delete(op, ptr); -} - +} + void FlagImpl::Init() { new (&data_guard_) absl::Mutex; @@ -177,22 +177,22 @@ void FlagImpl::Init() { assert(def_kind == FlagDefaultKind::kGenFunc); (*default_value_.gen_func)(AlignedBufferValue()); break; - } + } seq_lock_.MarkInitialized(); } - + absl::Mutex* FlagImpl::DataGuard() const { absl::call_once(const_cast<FlagImpl*>(this)->init_control_, &FlagImpl::Init, const_cast<FlagImpl*>(this)); // data_guard_ is initialized inside Init. return reinterpret_cast<absl::Mutex*>(&data_guard_); -} - +} + void FlagImpl::AssertValidType(FlagFastTypeId rhs_type_id, const std::type_info* (*gen_rtti)()) const { FlagFastTypeId lhs_type_id = flags_internal::FastTypeId(op_); - + // `rhs_type_id` is the fast type id corresponding to the declaration // visibile at the call site. `lhs_type_id` is the fast type id // corresponding to the type specified in flag definition. They must match @@ -227,10 +227,10 @@ std::unique_ptr<void, DynValueDeleter> FlagImpl::MakeInitValue() const { default: res = flags_internal::Clone(op_, &default_value_); break; - } + } return {res, DynValueDeleter{op_}}; } - + void FlagImpl::StoreValue(const void* src) { switch (ValueStorageKind()) { case FlagValueStorageKind::kValueAndInitBit: @@ -253,40 +253,40 @@ void FlagImpl::StoreValue(const void* src) { } modified_ = true; InvokeCallback(); -} - +} + absl::string_view FlagImpl::Name() const { return name_; } std::string FlagImpl::Filename() const { return flags_internal::GetUsageConfig().normalize_filename(filename_); } -std::string FlagImpl::Help() const { +std::string FlagImpl::Help() const { return HelpSourceKind() == FlagHelpKind::kLiteral ? help_.literal : help_.gen_func(); -} - +} + FlagFastTypeId FlagImpl::TypeId() const { return flags_internal::FastTypeId(op_); -} - +} + int64_t FlagImpl::ModificationCount() const { return seq_lock_.ModificationCount(); } -bool FlagImpl::IsSpecifiedOnCommandLine() const { - absl::MutexLock l(DataGuard()); - return on_command_line_; -} - -std::string FlagImpl::DefaultValue() const { - absl::MutexLock l(DataGuard()); - +bool FlagImpl::IsSpecifiedOnCommandLine() const { + absl::MutexLock l(DataGuard()); + return on_command_line_; +} + +std::string FlagImpl::DefaultValue() const { + absl::MutexLock l(DataGuard()); + auto obj = MakeInitValue(); return flags_internal::Unparse(op_, obj.get()); -} - -std::string FlagImpl::CurrentValue() const { +} + +std::string FlagImpl::CurrentValue() const { auto* guard = DataGuard(); // Make sure flag initialized switch (ValueStorageKind()) { case FlagValueStorageKind::kValueAndInitBit: @@ -307,44 +307,44 @@ std::string FlagImpl::CurrentValue() const { return flags_internal::Unparse(op_, AlignedBufferValue()); } } - + return ""; -} - +} + void FlagImpl::SetCallback(const FlagCallbackFunc mutation_callback) { - absl::MutexLock l(DataGuard()); - + absl::MutexLock l(DataGuard()); + if (callback_ == nullptr) { callback_ = new FlagCallback; } callback_->func = mutation_callback; - - InvokeCallback(); -} - + + InvokeCallback(); +} + void FlagImpl::InvokeCallback() const { - if (!callback_) return; - + if (!callback_) return; + // Make a copy of the C-style function pointer that we are about to invoke // before we release the lock guarding it. FlagCallbackFunc cb = callback_->func; - // If the flag has a mutation callback this function invokes it. While the - // callback is being invoked the primary flag's mutex is unlocked and it is - // re-locked back after call to callback is completed. Callback invocation is - // guarded by flag's secondary mutex instead which prevents concurrent - // callback invocation. Note that it is possible for other thread to grab the - // primary lock and update flag's value at any time during the callback - // invocation. This is by design. Callback can get a value of the flag if - // necessary, but it might be different from the value initiated the callback - // and it also can be different by the time the callback invocation is - // completed. Requires that *primary_lock be held in exclusive mode; it may be - // released and reacquired by the implementation. + // If the flag has a mutation callback this function invokes it. While the + // callback is being invoked the primary flag's mutex is unlocked and it is + // re-locked back after call to callback is completed. Callback invocation is + // guarded by flag's secondary mutex instead which prevents concurrent + // callback invocation. Note that it is possible for other thread to grab the + // primary lock and update flag's value at any time during the callback + // invocation. This is by design. Callback can get a value of the flag if + // necessary, but it might be different from the value initiated the callback + // and it also can be different by the time the callback invocation is + // completed. Requires that *primary_lock be held in exclusive mode; it may be + // released and reacquired by the implementation. MutexRelock relock(*DataGuard()); absl::MutexLock lock(&callback_->guard); cb(); } - + std::unique_ptr<FlagStateInterface> FlagImpl::SaveState() { absl::MutexLock l(DataGuard()); @@ -372,16 +372,16 @@ std::unique_ptr<FlagStateInterface> FlagImpl::SaveState() { *this, flags_internal::Clone(op_, AlignedBufferValue()), modified, on_command_line, ModificationCount()); } - } + } return nullptr; -} - +} + bool FlagImpl::RestoreState(const FlagState& flag_state) { absl::MutexLock l(DataGuard()); if (flag_state.counter_ == ModificationCount()) { return false; - } - + } + switch (ValueStorageKind()) { case FlagValueStorageKind::kValueAndInitBit: case FlagValueStorageKind::kOneWordAtomic: @@ -392,13 +392,13 @@ bool FlagImpl::RestoreState(const FlagState& flag_state) { StoreValue(flag_state.value_.heap_allocated); break; } - + modified_ = flag_state.modified_; on_command_line_ = flag_state.on_command_line_; - - return true; -} - + + return true; +} + template <typename StorageT> StorageT* FlagImpl::OffsetValue() const { char* p = reinterpret_cast<char*>(const_cast<FlagImpl*>(this)); @@ -424,7 +424,7 @@ std::atomic<int64_t>& FlagImpl::OneWordValue() const { return OffsetValue<FlagOneWordValue>()->value; } -// Attempts to parse supplied `value` string using parsing routine in the `flag` +// Attempts to parse supplied `value` string using parsing routine in the `flag` // argument. If parsing successful, this function replaces the dst with newly // parsed value. In case if any error is encountered in either step, the error // message is stored in 'err' @@ -432,17 +432,17 @@ std::unique_ptr<void, DynValueDeleter> FlagImpl::TryParse( absl::string_view value, std::string& err) const { std::unique_ptr<void, DynValueDeleter> tentative_value = MakeInitValue(); - std::string parse_err; + std::string parse_err; if (!flags_internal::Parse(op_, value, tentative_value.get(), &parse_err)) { - absl::string_view err_sep = parse_err.empty() ? "" : "; "; + absl::string_view err_sep = parse_err.empty() ? "" : "; "; err = absl::StrCat("Illegal value '", value, "' specified for flag '", Name(), "'", err_sep, parse_err); return nullptr; - } - + } + return tentative_value; -} - +} + void FlagImpl::Read(void* dst) const { auto* guard = DataGuard(); // Make sure flag initialized switch (ValueStorageKind()) { @@ -462,9 +462,9 @@ void FlagImpl::Read(void* dst) const { flags_internal::CopyConstruct(op_, AlignedBufferValue(), dst); break; } - } -} - + } +} + int64_t FlagImpl::ReadOneWord() const { assert(ValueStorageKind() == FlagValueStorageKind::kOneWordAtomic || ValueStorageKind() == FlagValueStorageKind::kValueAndInitBit); @@ -497,68 +497,68 @@ void FlagImpl::ReadSequenceLockedData(void* dst) const { } void FlagImpl::Write(const void* src) { - absl::MutexLock l(DataGuard()); - + absl::MutexLock l(DataGuard()); + if (ShouldValidateFlagValue(flags_internal::FastTypeId(op_))) { std::unique_ptr<void, DynValueDeleter> obj{flags_internal::Clone(op_, src), DynValueDeleter{op_}}; - std::string ignored_error; + std::string ignored_error; std::string src_as_str = flags_internal::Unparse(op_, src); if (!flags_internal::Parse(op_, src_as_str, obj.get(), &ignored_error)) { ABSL_INTERNAL_LOG(ERROR, absl::StrCat("Attempt to set flag '", Name(), "' to invalid value ", src_as_str)); - } - } - + } + } + StoreValue(src); -} - -// Sets the value of the flag based on specified string `value`. If the flag -// was successfully set to new value, it returns true. Otherwise, sets `err` -// to indicate the error, leaves the flag unchanged, and returns false. There -// are three ways to set the flag's value: -// * Update the current flag value -// * Update the flag's default value -// * Update the current flag value if it was never set before -// The mode is selected based on 'set_mode' parameter. +} + +// Sets the value of the flag based on specified string `value`. If the flag +// was successfully set to new value, it returns true. Otherwise, sets `err` +// to indicate the error, leaves the flag unchanged, and returns false. There +// are three ways to set the flag's value: +// * Update the current flag value +// * Update the flag's default value +// * Update the current flag value if it was never set before +// The mode is selected based on 'set_mode' parameter. bool FlagImpl::ParseFrom(absl::string_view value, FlagSettingMode set_mode, ValueSource source, std::string& err) { - absl::MutexLock l(DataGuard()); - - switch (set_mode) { - case SET_FLAGS_VALUE: { - // set or modify the flag's value + absl::MutexLock l(DataGuard()); + + switch (set_mode) { + case SET_FLAGS_VALUE: { + // set or modify the flag's value auto tentative_value = TryParse(value, err); if (!tentative_value) return false; - + StoreValue(tentative_value.get()); - if (source == kCommandLine) { - on_command_line_ = true; - } - break; - } - case SET_FLAG_IF_DEFAULT: { - // set the flag's value, but only if it hasn't been set by someone else + if (source == kCommandLine) { + on_command_line_ = true; + } + break; + } + case SET_FLAG_IF_DEFAULT: { + // set the flag's value, but only if it hasn't been set by someone else if (modified_) { - // TODO(rogeeff): review and fix this semantic. Currently we do not fail - // in this case if flag is modified. This is misleading since the flag's - // value is not updated even though we return true. - // *err = absl::StrCat(Name(), " is already set to ", - // CurrentValue(), "\n"); - // return false; - return true; - } + // TODO(rogeeff): review and fix this semantic. Currently we do not fail + // in this case if flag is modified. This is misleading since the flag's + // value is not updated even though we return true. + // *err = absl::StrCat(Name(), " is already set to ", + // CurrentValue(), "\n"); + // return false; + return true; + } auto tentative_value = TryParse(value, err); if (!tentative_value) return false; StoreValue(tentative_value.get()); - break; - } - case SET_FLAGS_DEFAULT: { + break; + } + case SET_FLAGS_DEFAULT: { auto tentative_value = TryParse(value, err); if (!tentative_value) return false; - + if (DefaultKind() == FlagDefaultKind::kDynamicValue) { void* old_value = default_value_.dynamic_value; default_value_.dynamic_value = tentative_value.release(); @@ -568,45 +568,45 @@ bool FlagImpl::ParseFrom(absl::string_view value, FlagSettingMode set_mode, def_kind_ = static_cast<uint8_t>(FlagDefaultKind::kDynamicValue); } - if (!modified_) { + if (!modified_) { // Need to set both default value *and* current, in this case. StoreValue(default_value_.dynamic_value); modified_ = false; - } - break; - } - } - - return true; -} - + } + break; + } + } + + return true; +} + void FlagImpl::CheckDefaultValueParsingRoundtrip() const { - std::string v = DefaultValue(); - - absl::MutexLock lock(DataGuard()); - + std::string v = DefaultValue(); + + absl::MutexLock lock(DataGuard()); + auto dst = MakeInitValue(); - std::string error; + std::string error; if (!flags_internal::Parse(op_, v, dst.get(), &error)) { - ABSL_INTERNAL_LOG( - FATAL, + ABSL_INTERNAL_LOG( + FATAL, absl::StrCat("Flag ", Name(), " (from ", Filename(), "): string form of default value '", v, - "' could not be parsed; error=", error)); - } - - // We do not compare dst to def since parsing/unparsing may make - // small changes, e.g., precision loss for floating point types. -} - -bool FlagImpl::ValidateInputValue(absl::string_view value) const { - absl::MutexLock l(DataGuard()); - + "' could not be parsed; error=", error)); + } + + // We do not compare dst to def since parsing/unparsing may make + // small changes, e.g., precision loss for floating point types. +} + +bool FlagImpl::ValidateInputValue(absl::string_view value) const { + absl::MutexLock l(DataGuard()); + auto obj = MakeInitValue(); - std::string ignored_error; + std::string ignored_error; return flags_internal::Parse(op_, value, obj.get(), &ignored_error); -} - -} // namespace flags_internal +} + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl +} // namespace absl diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/flag.h b/contrib/restricted/abseil-cpp/absl/flags/internal/flag.h index 4324cfdf70..124a2f1c03 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/flag.h +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/flag.h @@ -1,79 +1,79 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_FLAGS_INTERNAL_FLAG_H_ -#define ABSL_FLAGS_INTERNAL_FLAG_H_ - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ABSL_FLAGS_INTERNAL_FLAG_H_ +#define ABSL_FLAGS_INTERNAL_FLAG_H_ + #include <stddef.h> #include <stdint.h> -#include <atomic> -#include <cstring> +#include <atomic> +#include <cstring> #include <memory> #include <new> #include <string> #include <type_traits> #include <typeinfo> - + #include "absl/base/attributes.h" #include "absl/base/call_once.h" #include "absl/base/casts.h" #include "absl/base/config.h" #include "absl/base/optimization.h" -#include "absl/base/thread_annotations.h" +#include "absl/base/thread_annotations.h" #include "absl/flags/commandlineflag.h" #include "absl/flags/config.h" -#include "absl/flags/internal/commandlineflag.h" -#include "absl/flags/internal/registry.h" +#include "absl/flags/internal/commandlineflag.h" +#include "absl/flags/internal/registry.h" #include "absl/flags/internal/sequence_lock.h" #include "absl/flags/marshalling.h" #include "absl/meta/type_traits.h" #include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" +#include "absl/synchronization/mutex.h" #include "absl/utility/utility.h" - -namespace absl { + +namespace absl { ABSL_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // Forward declaration of absl::Flag<T> public API. -namespace flags_internal { +namespace flags_internal { template <typename T> class Flag; } // namespace flags_internal - + #if defined(_MSC_VER) && !defined(__clang__) -template <typename T> -class Flag; +template <typename T> +class Flag; #else template <typename T> using Flag = flags_internal::Flag<T>; #endif - -template <typename T> + +template <typename T> ABSL_MUST_USE_RESULT T GetFlag(const absl::Flag<T>& flag); - + template <typename T> void SetFlag(absl::Flag<T>* flag, const T& v); - + template <typename T, typename V> void SetFlag(absl::Flag<T>* flag, const V& v); - + template <typename U> const CommandLineFlag& GetFlagReflectionHandle(const absl::Flag<U>& f); - + /////////////////////////////////////////////////////////////////////////////// // Flag value type operations, eg., parsing, copying, etc. are provided // by function specific to that type with a signature matching FlagOpFn. @@ -91,9 +91,9 @@ enum class FlagOp { kParse, kUnparse, kValueOffset, -}; +}; using FlagOpFn = void* (*)(FlagOp, const void*, void*, void*); - + // Forward declaration for Flag value specific operations. template <typename T> void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3); @@ -173,15 +173,15 @@ inline const std::type_info* GenRuntimeTypeId() { /////////////////////////////////////////////////////////////////////////////// // Flag help auxiliary structs. -// This is help argument for absl::Flag encapsulating the string literal pointer -// or pointer to function generating it as well as enum descriminating two -// cases. -using HelpGenFunc = std::string (*)(); - +// This is help argument for absl::Flag encapsulating the string literal pointer +// or pointer to function generating it as well as enum descriminating two +// cases. +using HelpGenFunc = std::string (*)(); + template <size_t N> struct FixedCharArray { char value[N]; - + template <size_t... I> static constexpr FixedCharArray<N> FromLiteralString( absl::string_view str, absl::index_sequence<I...>) { @@ -204,50 +204,50 @@ union FlagHelpMsg { constexpr explicit FlagHelpMsg(const char* help_msg) : literal(help_msg) {} constexpr explicit FlagHelpMsg(HelpGenFunc help_gen) : gen_func(help_gen) {} - const char* literal; - HelpGenFunc gen_func; -}; - + const char* literal; + HelpGenFunc gen_func; +}; + enum class FlagHelpKind : uint8_t { kLiteral = 0, kGenFunc = 1 }; - + struct FlagHelpArg { FlagHelpMsg source; FlagHelpKind kind; -}; - +}; + extern const char kStrippedFlagHelp[]; - -// These two HelpArg overloads allows us to select at compile time one of two -// way to pass Help argument to absl::Flag. We'll be passing + +// These two HelpArg overloads allows us to select at compile time one of two +// way to pass Help argument to absl::Flag. We'll be passing // AbslFlagHelpGenFor##name as Gen and integer 0 as a single argument to prefer // first overload if possible. If help message is evaluatable on constexpr // context We'll be able to make FixedCharArray out of it and we'll choose first // overload. In this case the help message expression is immediately evaluated // and is used to construct the absl::Flag. No additionl code is generated by // ABSL_FLAG Otherwise SFINAE kicks in and first overload is dropped from the -// consideration, in which case the second overload will be used. The second -// overload does not attempt to evaluate the help message expression -// immediately and instead delays the evaluation by returing the function -// pointer (&T::NonConst) genering the help message when necessary. This is -// evaluatable in constexpr context, but the cost is an extra function being -// generated in the ABSL_FLAG code. +// consideration, in which case the second overload will be used. The second +// overload does not attempt to evaluate the help message expression +// immediately and instead delays the evaluation by returing the function +// pointer (&T::NonConst) genering the help message when necessary. This is +// evaluatable in constexpr context, but the cost is an extra function being +// generated in the ABSL_FLAG code. template <typename Gen, size_t N> constexpr FlagHelpArg HelpArg(const FixedCharArray<N>& value) { return {FlagHelpMsg(value.value), FlagHelpKind::kLiteral}; -} - +} + template <typename Gen> constexpr FlagHelpArg HelpArg(std::false_type) { return {FlagHelpMsg(&Gen::NonConst), FlagHelpKind::kGenFunc}; -} - +} + /////////////////////////////////////////////////////////////////////////////// // Flag default value auxiliary structs. // Signature for the function generating the initial flag value (usually -// based on default value supplied in flag's definition) +// based on default value supplied in flag's definition) using FlagDfltGenFunc = void (*)(void*); - + union FlagDefaultSrc { constexpr explicit FlagDefaultSrc(FlagDfltGenFunc gen_func_arg) : gen_func(gen_func_arg) {} @@ -404,16 +404,16 @@ struct FlagValue<T, FlagValueStorageKind::kAlignedBuffer> { /////////////////////////////////////////////////////////////////////////////// // Flag callback auxiliary structs. -// Signature for the mutation callback used by watched Flags -// The callback is noexcept. -// TODO(rogeeff): add noexcept after C++17 support is added. +// Signature for the mutation callback used by watched Flags +// The callback is noexcept. +// TODO(rogeeff): add noexcept after C++17 support is added. using FlagCallbackFunc = void (*)(); - + struct FlagCallback { FlagCallbackFunc func; absl::Mutex guard; // Guard for concurrent callback invocations. }; - + /////////////////////////////////////////////////////////////////////////////// // Flag implementation, which does not depend on flag value type. // The class encapsulates the Flag's data and access to it. @@ -428,14 +428,14 @@ struct DynValueDeleter { class FlagState; class FlagImpl final : public CommandLineFlag { - public: + public: constexpr FlagImpl(const char* name, const char* filename, FlagOpFn op, FlagHelpArg help, FlagValueStorageKind value_kind, FlagDefaultArg default_arg) : name_(name), filename_(filename), op_(op), - help_(help.source), + help_(help.source), help_source_kind_(static_cast<uint8_t>(help.kind)), value_storage_kind_(static_cast<uint8_t>(value_kind)), def_kind_(static_cast<uint8_t>(default_arg.kind)), @@ -444,8 +444,8 @@ class FlagImpl final : public CommandLineFlag { callback_(nullptr), default_value_(default_arg.source), data_guard_{} {} - - // Constant access methods + + // Constant access methods int64_t ReadOneWord() const ABSL_LOCKS_EXCLUDED(*DataGuard()); bool ReadOneBool() const ABSL_LOCKS_EXCLUDED(*DataGuard()); void Read(void* dst) const override ABSL_LOCKS_EXCLUDED(*DataGuard()); @@ -467,15 +467,15 @@ class FlagImpl final : public CommandLineFlag { void Read(T* value) const ABSL_LOCKS_EXCLUDED(*DataGuard()) { *value = absl::bit_cast<FlagValueAndInitBit<T>>(ReadOneWord()).value; } - - // Mutating access methods + + // Mutating access methods void Write(const void* src) ABSL_LOCKS_EXCLUDED(*DataGuard()); - - // Interfaces to operate on callbacks. + + // Interfaces to operate on callbacks. void SetCallback(const FlagCallbackFunc mutation_callback) ABSL_LOCKS_EXCLUDED(*DataGuard()); void InvokeCallback() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard()); - + // Used in read/write operations to validate source/target has correct type. // For example if flag is declared as absl::Flag<int> FLAGS_foo, a call to // absl::GetFlag(FLAGS_foo) validates that the type of FLAGS_foo is indeed @@ -486,10 +486,10 @@ class FlagImpl final : public CommandLineFlag { const std::type_info* (*gen_rtti)()) const; private: - template <typename T> + template <typename T> friend class Flag; friend class FlagState; - + // Ensures that `data_guard_` is initialized and returns it. absl::Mutex* DataGuard() const ABSL_LOCK_RETURNED(reinterpret_cast<absl::Mutex*>(data_guard_)); @@ -535,7 +535,7 @@ class FlagImpl final : public CommandLineFlag { FlagHelpKind HelpSourceKind() const { return static_cast<FlagHelpKind>(help_source_kind_); - } + } FlagValueStorageKind ValueStorageKind() const { return static_cast<FlagValueStorageKind>(value_storage_kind_); } @@ -543,7 +543,7 @@ class FlagImpl final : public CommandLineFlag { ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard()) { return static_cast<FlagDefaultKind>(def_kind_); } - + // CommandLineFlag interface implementation absl::string_view Name() const override; std::string Filename() const override; @@ -557,7 +557,7 @@ class FlagImpl final : public CommandLineFlag { ABSL_LOCKS_EXCLUDED(*DataGuard()); void CheckDefaultValueParsingRoundtrip() const override ABSL_LOCKS_EXCLUDED(*DataGuard()); - + int64_t ModificationCount() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard()); // Interfaces to save and restore flags to/from persistent state. @@ -565,7 +565,7 @@ class FlagImpl final : public CommandLineFlag { // saving and restoring a state. std::unique_ptr<FlagStateInterface> SaveState() override ABSL_LOCKS_EXCLUDED(*DataGuard()); - + // Restores the flag state to the supplied state object. If there is // nothing to restore returns false. Otherwise returns true. bool RestoreState(const FlagState& flag_state) @@ -585,11 +585,11 @@ class FlagImpl final : public CommandLineFlag { const FlagOpFn op_; // Help message literal or function to generate it. const FlagHelpMsg help_; - // Indicates if help message was supplied as literal or generator func. + // Indicates if help message was supplied as literal or generator func. const uint8_t help_source_kind_ : 1; // Kind of storage this flag is using for the flag's value. const uint8_t value_storage_kind_ : 2; - + uint8_t : 0; // The bytes containing the const bitfields must not be // shared with bytes containing the mutable bitfields. @@ -616,7 +616,7 @@ class FlagImpl final : public CommandLineFlag { // value via SetCommandLineOptionWithMode. def_kind_ is used to distinguish // these two cases. FlagDefaultSrc default_value_; - + // This is reserved space for an absl::Mutex to guard flag data. It will be // initialized in FlagImpl::Init via placement new. // We can't use "absl::Mutex data_guard_", since this class is not literal. @@ -625,21 +625,21 @@ class FlagImpl final : public CommandLineFlag { // and can fail. Using reserved space + placement new allows us to avoid both // problems. alignas(absl::Mutex) mutable char data_guard_[sizeof(absl::Mutex)]; -}; - +}; + /////////////////////////////////////////////////////////////////////////////// // The Flag object parameterized by the flag's value type. This class implements // flag reflection handle interface. -template <typename T> +template <typename T> class Flag { - public: + public: constexpr Flag(const char* name, const char* filename, FlagHelpArg help, const FlagDefaultArg default_arg) : impl_(name, filename, &FlagOps<T>, help, flags_internal::StorageKind<T>(), default_arg), value_() {} - + // CommandLineFlag interface absl::string_view Name() const { return impl_.Name(); } std::string Filename() const { return impl_.Filename(); } @@ -656,15 +656,15 @@ class Flag { friend class FlagRegistrar; friend class FlagImplPeer; - T Get() const { - // See implementation notes in CommandLineFlag::Get(). - union U { - T value; - U() {} - ~U() { value.~T(); } - }; - U u; - + T Get() const { + // See implementation notes in CommandLineFlag::Get(). + union U { + T value; + U() {} + ~U() { value.~T(); } + }; + U u; + #if !defined(NDEBUG) impl_.AssertValidType(base_internal::FastTypeId<T>(), &GenRuntimeTypeId<T>); #endif @@ -672,16 +672,16 @@ class Flag { if (ABSL_PREDICT_FALSE(!value_.Get(impl_.seq_lock_, u.value))) { impl_.Read(&u.value); } - return std::move(u.value); - } + return std::move(u.value); + } void Set(const T& v) { impl_.AssertValidType(base_internal::FastTypeId<T>(), &GenRuntimeTypeId<T>); impl_.Write(&v); - } - + } + // Access to the reflection. const CommandLineFlag& Reflect() const { return impl_; } - + // Flag's data // The implementation depends on value_ field to be placed exactly after the // impl_ field, so that impl_ can figure out the offset to the value and @@ -689,29 +689,29 @@ class Flag { FlagImpl impl_; FlagValue<T> value_; }; - + /////////////////////////////////////////////////////////////////////////////// // Trampoline for friend access - + class FlagImplPeer { public: template <typename T, typename FlagType> static T InvokeGet(const FlagType& flag) { return flag.Get(); - } + } template <typename FlagType, typename T> static void InvokeSet(FlagType& flag, const T& v) { flag.Set(v); - } + } template <typename FlagType> static const CommandLineFlag& InvokeReflect(const FlagType& f) { return f.Reflect(); - } -}; - + } +}; + /////////////////////////////////////////////////////////////////////////////// // Implementation of Flag value specific operations routine. -template <typename T> +template <typename T> void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) { switch (op) { case FlagOp::kAlloc: { @@ -760,39 +760,39 @@ void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) { (sizeof(FlagImpl) + round_to - 1) / round_to * round_to; return reinterpret_cast<void*>(offset); } - } + } return nullptr; -} - +} + /////////////////////////////////////////////////////////////////////////////// -// This class facilitates Flag object registration and tail expression-based -// flag definition, for example: -// ABSL_FLAG(int, foo, 42, "Foo help").OnUpdate(NotifyFooWatcher); +// This class facilitates Flag object registration and tail expression-based +// flag definition, for example: +// ABSL_FLAG(int, foo, 42, "Foo help").OnUpdate(NotifyFooWatcher); struct FlagRegistrarEmpty {}; -template <typename T, bool do_register> -class FlagRegistrar { - public: +template <typename T, bool do_register> +class FlagRegistrar { + public: explicit FlagRegistrar(Flag<T>& flag, const char* filename) : flag_(flag) { if (do_register) flags_internal::RegisterCommandLineFlag(flag_.impl_, filename); - } - + } + FlagRegistrar OnUpdate(FlagCallbackFunc cb) && { flag_.impl_.SetCallback(cb); - return *this; - } - + return *this; + } + // Make the registrar "die" gracefully as an empty struct on a line where // registration happens. Registrar objects are intended to live only as // temporary. operator FlagRegistrarEmpty() const { return {}; } // NOLINT - - private: + + private: Flag<T>& flag_; // Flag being registered (not owned). -}; - -} // namespace flags_internal +}; + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_INTERNAL_FLAG_H_ +} // namespace absl + +#endif // ABSL_FLAGS_INTERNAL_FLAG_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/parse.h b/contrib/restricted/abseil-cpp/absl/flags/internal/parse.h index 893ff7176d..de706c8984 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/parse.h +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/parse.h @@ -1,50 +1,50 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_FLAGS_INTERNAL_PARSE_H_ -#define ABSL_FLAGS_INTERNAL_PARSE_H_ - -#include <string> -#include <vector> - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ABSL_FLAGS_INTERNAL_PARSE_H_ +#define ABSL_FLAGS_INTERNAL_PARSE_H_ + +#include <string> +#include <vector> + #include "absl/base/config.h" -#include "absl/flags/declare.h" +#include "absl/flags/declare.h" #include "absl/strings/string_view.h" - -ABSL_DECLARE_FLAG(std::vector<std::string>, flagfile); -ABSL_DECLARE_FLAG(std::vector<std::string>, fromenv); -ABSL_DECLARE_FLAG(std::vector<std::string>, tryfromenv); -ABSL_DECLARE_FLAG(std::vector<std::string>, undefok); - -namespace absl { + +ABSL_DECLARE_FLAG(std::vector<std::string>, flagfile); +ABSL_DECLARE_FLAG(std::vector<std::string>, fromenv); +ABSL_DECLARE_FLAG(std::vector<std::string>, tryfromenv); +ABSL_DECLARE_FLAG(std::vector<std::string>, undefok); + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -enum class ArgvListAction { kRemoveParsedArgs, kKeepParsedArgs }; -enum class UsageFlagsAction { kHandleUsage, kIgnoreUsage }; -enum class OnUndefinedFlag { - kIgnoreUndefined, - kReportUndefined, - kAbortIfUndefined -}; - -std::vector<char*> ParseCommandLineImpl(int argc, char* argv[], - ArgvListAction arg_list_act, - UsageFlagsAction usage_flag_act, - OnUndefinedFlag on_undef_flag); - +namespace flags_internal { + +enum class ArgvListAction { kRemoveParsedArgs, kKeepParsedArgs }; +enum class UsageFlagsAction { kHandleUsage, kIgnoreUsage }; +enum class OnUndefinedFlag { + kIgnoreUndefined, + kReportUndefined, + kAbortIfUndefined +}; + +std::vector<char*> ParseCommandLineImpl(int argc, char* argv[], + ArgvListAction arg_list_act, + UsageFlagsAction usage_flag_act, + OnUndefinedFlag on_undef_flag); + // -------------------------------------------------------------------- // Inspect original command line @@ -52,8 +52,8 @@ std::vector<char*> ParseCommandLineImpl(int argc, char* argv[], // command line or specified in flag file present on the original command line. bool WasPresentOnCommandLine(absl::string_view flag_name); -} // namespace flags_internal +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_INTERNAL_PARSE_H_ +} // namespace absl + +#endif // ABSL_FLAGS_INTERNAL_PARSE_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/path_util.h b/contrib/restricted/abseil-cpp/absl/flags/internal/path_util.h index ab261b91fc..a6594d3347 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/path_util.h +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/path_util.h @@ -1,62 +1,62 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_FLAGS_INTERNAL_PATH_UTIL_H_ -#define ABSL_FLAGS_INTERNAL_PATH_UTIL_H_ - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ABSL_FLAGS_INTERNAL_PATH_UTIL_H_ +#define ABSL_FLAGS_INTERNAL_PATH_UTIL_H_ + #include "absl/base/config.h" -#include "absl/strings/string_view.h" - -namespace absl { +#include "absl/strings/string_view.h" + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -// A portable interface that returns the basename of the filename passed as an -// argument. It is similar to basename(3) -// <https://linux.die.net/man/3/basename>. -// For example: -// flags_internal::Basename("a/b/prog/file.cc") -// returns "file.cc" -// flags_internal::Basename("file.cc") -// returns "file.cc" -inline absl::string_view Basename(absl::string_view filename) { - auto last_slash_pos = filename.find_last_of("/\\"); - - return last_slash_pos == absl::string_view::npos - ? filename - : filename.substr(last_slash_pos + 1); -} - -// A portable interface that returns the directory name of the filename -// passed as an argument, including the trailing slash. -// Returns the empty string if a slash is not found in the input file name. -// For example: -// flags_internal::Package("a/b/prog/file.cc") -// returns "a/b/prog/" -// flags_internal::Package("file.cc") -// returns "" -inline absl::string_view Package(absl::string_view filename) { - auto last_slash_pos = filename.find_last_of("/\\"); - - return last_slash_pos == absl::string_view::npos - ? absl::string_view() - : filename.substr(0, last_slash_pos + 1); -} - -} // namespace flags_internal +namespace flags_internal { + +// A portable interface that returns the basename of the filename passed as an +// argument. It is similar to basename(3) +// <https://linux.die.net/man/3/basename>. +// For example: +// flags_internal::Basename("a/b/prog/file.cc") +// returns "file.cc" +// flags_internal::Basename("file.cc") +// returns "file.cc" +inline absl::string_view Basename(absl::string_view filename) { + auto last_slash_pos = filename.find_last_of("/\\"); + + return last_slash_pos == absl::string_view::npos + ? filename + : filename.substr(last_slash_pos + 1); +} + +// A portable interface that returns the directory name of the filename +// passed as an argument, including the trailing slash. +// Returns the empty string if a slash is not found in the input file name. +// For example: +// flags_internal::Package("a/b/prog/file.cc") +// returns "a/b/prog/" +// flags_internal::Package("file.cc") +// returns "" +inline absl::string_view Package(absl::string_view filename) { + auto last_slash_pos = filename.find_last_of("/\\"); + + return last_slash_pos == absl::string_view::npos + ? absl::string_view() + : filename.substr(0, last_slash_pos + 1); +} + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_INTERNAL_PATH_UTIL_H_ +} // namespace absl + +#endif // ABSL_FLAGS_INTERNAL_PATH_UTIL_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/private_handle_accessor/ya.make b/contrib/restricted/abseil-cpp/absl/flags/internal/private_handle_accessor/ya.make index 9ebf72a825..80a55d0f76 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/private_handle_accessor/ya.make +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/private_handle_accessor/ya.make @@ -1,43 +1,43 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() -OWNER(g:cpp-contrib) - -LICENSE(Apache-2.0) - -PEERDIR( - contrib/restricted/abseil-cpp/absl/base - contrib/restricted/abseil-cpp/absl/base/internal/raw_logging - contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait - contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate - contrib/restricted/abseil-cpp/absl/base/log_severity +OWNER(g:cpp-contrib) + +LICENSE(Apache-2.0) + +PEERDIR( + contrib/restricted/abseil-cpp/absl/base + contrib/restricted/abseil-cpp/absl/base/internal/raw_logging + contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait + contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate + contrib/restricted/abseil-cpp/absl/base/log_severity contrib/restricted/abseil-cpp/absl/flags/commandlineflag contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag - contrib/restricted/abseil-cpp/absl/numeric + contrib/restricted/abseil-cpp/absl/numeric contrib/restricted/abseil-cpp/absl/strings contrib/restricted/abseil-cpp/absl/strings/internal/absl_strings_internal contrib/restricted/abseil-cpp/absl/types/bad_optional_access -) - -ADDINCL( - GLOBAL contrib/restricted/abseil-cpp -) - -NO_COMPILER_WARNINGS() - -NO_UTIL() - +) + +ADDINCL( + GLOBAL contrib/restricted/abseil-cpp +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + CFLAGS( -DNOMINMAX ) SRCDIR(contrib/restricted/abseil-cpp/absl/flags/internal) -SRCS( +SRCS( private_handle_accessor.cc -) - -END() +) + +END() diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/program_name.cc b/contrib/restricted/abseil-cpp/absl/flags/internal/program_name.cc index 2f0799cfda..51d698da8b 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/program_name.cc +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/program_name.cc @@ -1,60 +1,60 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/flags/internal/program_name.h" - -#include <string> - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/flags/internal/program_name.h" + +#include <string> + #include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/const_init.h" #include "absl/base/thread_annotations.h" -#include "absl/flags/internal/path_util.h" +#include "absl/flags/internal/path_util.h" #include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" - -namespace absl { +#include "absl/synchronization/mutex.h" + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -ABSL_CONST_INIT static absl::Mutex program_name_guard(absl::kConstInit); -ABSL_CONST_INIT static std::string* program_name - ABSL_GUARDED_BY(program_name_guard) = nullptr; - -std::string ProgramInvocationName() { - absl::MutexLock l(&program_name_guard); - - return program_name ? *program_name : "UNKNOWN"; -} - -std::string ShortProgramInvocationName() { - absl::MutexLock l(&program_name_guard); - - return program_name ? std::string(flags_internal::Basename(*program_name)) - : "UNKNOWN"; -} - -void SetProgramInvocationName(absl::string_view prog_name_str) { - absl::MutexLock l(&program_name_guard); - - if (!program_name) - program_name = new std::string(prog_name_str); - else - program_name->assign(prog_name_str.data(), prog_name_str.size()); -} - -} // namespace flags_internal +namespace flags_internal { + +ABSL_CONST_INIT static absl::Mutex program_name_guard(absl::kConstInit); +ABSL_CONST_INIT static std::string* program_name + ABSL_GUARDED_BY(program_name_guard) = nullptr; + +std::string ProgramInvocationName() { + absl::MutexLock l(&program_name_guard); + + return program_name ? *program_name : "UNKNOWN"; +} + +std::string ShortProgramInvocationName() { + absl::MutexLock l(&program_name_guard); + + return program_name ? std::string(flags_internal::Basename(*program_name)) + : "UNKNOWN"; +} + +void SetProgramInvocationName(absl::string_view prog_name_str) { + absl::MutexLock l(&program_name_guard); + + if (!program_name) + program_name = new std::string(prog_name_str); + else + program_name->assign(prog_name_str.data(), prog_name_str.size()); +} + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl +} // namespace absl diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/program_name.h b/contrib/restricted/abseil-cpp/absl/flags/internal/program_name.h index 2ded360ccc..b99b94fe18 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/program_name.h +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/program_name.h @@ -1,50 +1,50 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_FLAGS_INTERNAL_PROGRAM_NAME_H_ -#define ABSL_FLAGS_INTERNAL_PROGRAM_NAME_H_ - -#include <string> - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ABSL_FLAGS_INTERNAL_PROGRAM_NAME_H_ +#define ABSL_FLAGS_INTERNAL_PROGRAM_NAME_H_ + +#include <string> + #include "absl/base/config.h" -#include "absl/strings/string_view.h" - -// -------------------------------------------------------------------- -// Program name - -namespace absl { +#include "absl/strings/string_view.h" + +// -------------------------------------------------------------------- +// Program name + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -// Returns program invocation name or "UNKNOWN" if `SetProgramInvocationName()` -// is never called. At the moment this is always set to argv[0] as part of -// library initialization. -std::string ProgramInvocationName(); - -// Returns base name for program invocation name. For example, if -// ProgramInvocationName() == "a/b/mybinary" -// then -// ShortProgramInvocationName() == "mybinary" -std::string ShortProgramInvocationName(); - -// Sets program invocation name to a new value. Should only be called once -// during program initialization, before any threads are spawned. -void SetProgramInvocationName(absl::string_view prog_name_str); - -} // namespace flags_internal +namespace flags_internal { + +// Returns program invocation name or "UNKNOWN" if `SetProgramInvocationName()` +// is never called. At the moment this is always set to argv[0] as part of +// library initialization. +std::string ProgramInvocationName(); + +// Returns base name for program invocation name. For example, if +// ProgramInvocationName() == "a/b/mybinary" +// then +// ShortProgramInvocationName() == "mybinary" +std::string ShortProgramInvocationName(); + +// Sets program invocation name to a new value. Should only be called once +// during program initialization, before any threads are spawned. +void SetProgramInvocationName(absl::string_view prog_name_str); + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_INTERNAL_PROGRAM_NAME_H_ +} // namespace absl + +#endif // ABSL_FLAGS_INTERNAL_PROGRAM_NAME_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/program_name/ya.make b/contrib/restricted/abseil-cpp/absl/flags/internal/program_name/ya.make index a614dc6590..701fef73c0 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/program_name/ya.make +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/program_name/ya.make @@ -1,50 +1,50 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() -OWNER(g:cpp-contrib) - -LICENSE(Apache-2.0) - -PEERDIR( - contrib/restricted/abseil-cpp/absl/base - contrib/restricted/abseil-cpp/absl/base/internal/low_level_alloc - contrib/restricted/abseil-cpp/absl/base/internal/raw_logging - contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait - contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate - contrib/restricted/abseil-cpp/absl/base/log_severity - contrib/restricted/abseil-cpp/absl/debugging - contrib/restricted/abseil-cpp/absl/debugging/stacktrace - contrib/restricted/abseil-cpp/absl/debugging/symbolize - contrib/restricted/abseil-cpp/absl/demangle - contrib/restricted/abseil-cpp/absl/numeric - contrib/restricted/abseil-cpp/absl/strings +OWNER(g:cpp-contrib) + +LICENSE(Apache-2.0) + +PEERDIR( + contrib/restricted/abseil-cpp/absl/base + contrib/restricted/abseil-cpp/absl/base/internal/low_level_alloc + contrib/restricted/abseil-cpp/absl/base/internal/raw_logging + contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait + contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate + contrib/restricted/abseil-cpp/absl/base/log_severity + contrib/restricted/abseil-cpp/absl/debugging + contrib/restricted/abseil-cpp/absl/debugging/stacktrace + contrib/restricted/abseil-cpp/absl/debugging/symbolize + contrib/restricted/abseil-cpp/absl/demangle + contrib/restricted/abseil-cpp/absl/numeric + contrib/restricted/abseil-cpp/absl/strings contrib/restricted/abseil-cpp/absl/strings/internal/absl_strings_internal - contrib/restricted/abseil-cpp/absl/synchronization - contrib/restricted/abseil-cpp/absl/synchronization/internal - contrib/restricted/abseil-cpp/absl/time - contrib/restricted/abseil-cpp/absl/time/civil_time - contrib/restricted/abseil-cpp/absl/time/time_zone -) - -ADDINCL( - GLOBAL contrib/restricted/abseil-cpp -) - -NO_COMPILER_WARNINGS() - -NO_UTIL() - + contrib/restricted/abseil-cpp/absl/synchronization + contrib/restricted/abseil-cpp/absl/synchronization/internal + contrib/restricted/abseil-cpp/absl/time + contrib/restricted/abseil-cpp/absl/time/civil_time + contrib/restricted/abseil-cpp/absl/time/time_zone +) + +ADDINCL( + GLOBAL contrib/restricted/abseil-cpp +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + CFLAGS( -DNOMINMAX ) SRCDIR(contrib/restricted/abseil-cpp/absl/flags/internal) - -SRCS( + +SRCS( program_name.cc -) - -END() +) + +END() diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/registry.h b/contrib/restricted/abseil-cpp/absl/flags/internal/registry.h index 6376a24e70..4b68c85f5c 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/registry.h +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/registry.h @@ -1,97 +1,97 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_FLAGS_INTERNAL_REGISTRY_H_ -#define ABSL_FLAGS_INTERNAL_REGISTRY_H_ - -#include <functional> - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ABSL_FLAGS_INTERNAL_REGISTRY_H_ +#define ABSL_FLAGS_INTERNAL_REGISTRY_H_ + +#include <functional> + #include "absl/base/config.h" #include "absl/flags/commandlineflag.h" -#include "absl/flags/internal/commandlineflag.h" +#include "absl/flags/internal/commandlineflag.h" #include "absl/strings/string_view.h" - -// -------------------------------------------------------------------- -// Global flags registry API. - -namespace absl { + +// -------------------------------------------------------------------- +// Global flags registry API. + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -// Executes specified visitor for each non-retired flag in the registry. While -// callback are executed, the registry is locked and can't be changed. +namespace flags_internal { + +// Executes specified visitor for each non-retired flag in the registry. While +// callback are executed, the registry is locked and can't be changed. void ForEachFlag(std::function<void(CommandLineFlag&)> visitor); - -//----------------------------------------------------------------------------- - + +//----------------------------------------------------------------------------- + bool RegisterCommandLineFlag(CommandLineFlag&, const char* filename); - + void FinalizeRegistry(); -//----------------------------------------------------------------------------- -// Retired registrations: -// -// Retired flag registrations are treated specially. A 'retired' flag is -// provided only for compatibility with automated invocations that still -// name it. A 'retired' flag: -// - is not bound to a C++ FLAGS_ reference. -// - has a type and a value, but that value is intentionally inaccessible. -// - does not appear in --help messages. -// - is fully supported by _all_ flag parsing routines. -// - consumes args normally, and complains about type mismatches in its -// argument. -// - emits a complaint but does not die (e.g. LOG(ERROR)) if it is -// accessed by name through the flags API for parsing or otherwise. -// -// The registrations for a flag happen in an unspecified order as the -// initializers for the namespace-scope objects of a program are run. -// Any number of weak registrations for a flag can weakly define the flag. -// One non-weak registration will upgrade the flag from weak to non-weak. -// Further weak registrations of a non-weak flag are ignored. -// -// This mechanism is designed to support moving dead flags into a -// 'graveyard' library. An example migration: -// -// 0: Remove references to this FLAGS_flagname in the C++ codebase. -// 1: Register as 'retired' in old_lib. -// 2: Make old_lib depend on graveyard. -// 3: Add a redundant 'retired' registration to graveyard. -// 4: Remove the old_lib 'retired' registration. -// 5: Eventually delete the graveyard registration entirely. -// - -// Retire flag with name "name" and type indicated by ops. +//----------------------------------------------------------------------------- +// Retired registrations: +// +// Retired flag registrations are treated specially. A 'retired' flag is +// provided only for compatibility with automated invocations that still +// name it. A 'retired' flag: +// - is not bound to a C++ FLAGS_ reference. +// - has a type and a value, but that value is intentionally inaccessible. +// - does not appear in --help messages. +// - is fully supported by _all_ flag parsing routines. +// - consumes args normally, and complains about type mismatches in its +// argument. +// - emits a complaint but does not die (e.g. LOG(ERROR)) if it is +// accessed by name through the flags API for parsing or otherwise. +// +// The registrations for a flag happen in an unspecified order as the +// initializers for the namespace-scope objects of a program are run. +// Any number of weak registrations for a flag can weakly define the flag. +// One non-weak registration will upgrade the flag from weak to non-weak. +// Further weak registrations of a non-weak flag are ignored. +// +// This mechanism is designed to support moving dead flags into a +// 'graveyard' library. An example migration: +// +// 0: Remove references to this FLAGS_flagname in the C++ codebase. +// 1: Register as 'retired' in old_lib. +// 2: Make old_lib depend on graveyard. +// 3: Add a redundant 'retired' registration to graveyard. +// 4: Remove the old_lib 'retired' registration. +// 5: Eventually delete the graveyard registration entirely. +// + +// Retire flag with name "name" and type indicated by ops. void Retire(const char* name, FlagFastTypeId type_id, char* buf); - + constexpr size_t kRetiredFlagObjSize = 3 * sizeof(void*); constexpr size_t kRetiredFlagObjAlignment = alignof(void*); -// Registered a retired flag with name 'flag_name' and type 'T'. -template <typename T> +// Registered a retired flag with name 'flag_name' and type 'T'. +template <typename T> class RetiredFlag { - public: + public: void Retire(const char* flag_name) { flags_internal::Retire(flag_name, base_internal::FastTypeId<T>(), buf_); } - - private: + + private: alignas(kRetiredFlagObjAlignment) char buf_[kRetiredFlagObjSize]; -}; - -} // namespace flags_internal +}; + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_INTERNAL_REGISTRY_H_ +} // namespace absl + +#endif // ABSL_FLAGS_INTERNAL_REGISTRY_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/usage.cc b/contrib/restricted/abseil-cpp/absl/flags/internal/usage.cc index d7835aca06..949709e883 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/usage.cc +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/usage.cc @@ -1,42 +1,42 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/flags/internal/usage.h" - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/flags/internal/usage.h" + #include <stdint.h> #include <functional> -#include <map> +#include <map> #include <ostream> -#include <string> +#include <string> #include <utility> #include <vector> - + #include "absl/base/config.h" #include "absl/flags/commandlineflag.h" -#include "absl/flags/flag.h" +#include "absl/flags/flag.h" #include "absl/flags/internal/flag.h" -#include "absl/flags/internal/path_util.h" +#include "absl/flags/internal/path_util.h" #include "absl/flags/internal/private_handle_accessor.h" -#include "absl/flags/internal/program_name.h" +#include "absl/flags/internal/program_name.h" #include "absl/flags/internal/registry.h" -#include "absl/flags/usage_config.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" - +#include "absl/flags/usage_config.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/str_split.h" +#include "absl/strings/string_view.h" + // Dummy global variables to prevent anyone else defining these. bool FLAGS_help = false; bool FLAGS_helpfull = false; @@ -46,277 +46,277 @@ bool FLAGS_version = false; bool FLAGS_only_check_args = false; bool FLAGS_helpon = false; bool FLAGS_helpmatch = false; - -namespace absl { + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { -namespace { - +namespace flags_internal { +namespace { + using PerFlagFilter = std::function<bool(const absl::CommandLineFlag&)>; // Maximum length size in a human readable format. constexpr size_t kHrfMaxLineLength = 80; -// This class is used to emit an XML element with `tag` and `text`. -// It adds opening and closing tags and escapes special characters in the text. -// For example: -// std::cout << XMLElement("title", "Milk & Cookies"); -// prints "<title>Milk & Cookies</title>" -class XMLElement { - public: - XMLElement(absl::string_view tag, absl::string_view txt) - : tag_(tag), txt_(txt) {} - - friend std::ostream& operator<<(std::ostream& out, - const XMLElement& xml_elem) { - out << "<" << xml_elem.tag_ << ">"; - - for (auto c : xml_elem.txt_) { - switch (c) { - case '"': - out << """; - break; - case '\'': - out << "'"; - break; - case '&': - out << "&"; - break; - case '<': - out << "<"; - break; - case '>': - out << ">"; - break; - default: - out << c; - break; - } - } - - return out << "</" << xml_elem.tag_ << ">"; - } - - private: - absl::string_view tag_; - absl::string_view txt_; -}; - -// -------------------------------------------------------------------- -// Helper class to pretty-print info about a flag. - -class FlagHelpPrettyPrinter { - public: - // Pretty printer holds on to the std::ostream& reference to direct an output - // to that stream. +// This class is used to emit an XML element with `tag` and `text`. +// It adds opening and closing tags and escapes special characters in the text. +// For example: +// std::cout << XMLElement("title", "Milk & Cookies"); +// prints "<title>Milk & Cookies</title>" +class XMLElement { + public: + XMLElement(absl::string_view tag, absl::string_view txt) + : tag_(tag), txt_(txt) {} + + friend std::ostream& operator<<(std::ostream& out, + const XMLElement& xml_elem) { + out << "<" << xml_elem.tag_ << ">"; + + for (auto c : xml_elem.txt_) { + switch (c) { + case '"': + out << """; + break; + case '\'': + out << "'"; + break; + case '&': + out << "&"; + break; + case '<': + out << "<"; + break; + case '>': + out << ">"; + break; + default: + out << c; + break; + } + } + + return out << "</" << xml_elem.tag_ << ">"; + } + + private: + absl::string_view tag_; + absl::string_view txt_; +}; + +// -------------------------------------------------------------------- +// Helper class to pretty-print info about a flag. + +class FlagHelpPrettyPrinter { + public: + // Pretty printer holds on to the std::ostream& reference to direct an output + // to that stream. FlagHelpPrettyPrinter(size_t max_line_len, size_t min_line_len, size_t wrapped_line_indent, std::ostream& out) : out_(out), - max_line_len_(max_line_len), + max_line_len_(max_line_len), min_line_len_(min_line_len), wrapped_line_indent_(wrapped_line_indent), - line_len_(0), - first_line_(true) {} - - void Write(absl::string_view str, bool wrap_line = false) { + line_len_(0), + first_line_(true) {} + + void Write(absl::string_view str, bool wrap_line = false) { // Empty string - do nothing. - if (str.empty()) return; - - std::vector<absl::string_view> tokens; - if (wrap_line) { - for (auto line : absl::StrSplit(str, absl::ByAnyChar("\n\r"))) { - if (!tokens.empty()) { + if (str.empty()) return; + + std::vector<absl::string_view> tokens; + if (wrap_line) { + for (auto line : absl::StrSplit(str, absl::ByAnyChar("\n\r"))) { + if (!tokens.empty()) { // Keep line separators in the input string. - tokens.push_back("\n"); - } - for (auto token : - absl::StrSplit(line, absl::ByAnyChar(" \t"), absl::SkipEmpty())) { - tokens.push_back(token); - } - } - } else { - tokens.push_back(str); - } - - for (auto token : tokens) { - bool new_line = (line_len_ == 0); - + tokens.push_back("\n"); + } + for (auto token : + absl::StrSplit(line, absl::ByAnyChar(" \t"), absl::SkipEmpty())) { + tokens.push_back(token); + } + } + } else { + tokens.push_back(str); + } + + for (auto token : tokens) { + bool new_line = (line_len_ == 0); + // Respect line separators in the input string. - if (token == "\n") { - EndLine(); - continue; - } - + if (token == "\n") { + EndLine(); + continue; + } + // Write the token, ending the string first if necessary/possible. if (!new_line && (line_len_ + static_cast<int>(token.size()) >= max_line_len_)) { - EndLine(); - new_line = true; - } - - if (new_line) { - StartLine(); - } else { - out_ << ' '; - ++line_len_; - } - - out_ << token; - line_len_ += token.size(); - } - } - - void StartLine() { - if (first_line_) { + EndLine(); + new_line = true; + } + + if (new_line) { + StartLine(); + } else { + out_ << ' '; + ++line_len_; + } + + out_ << token; + line_len_ += token.size(); + } + } + + void StartLine() { + if (first_line_) { line_len_ = min_line_len_; - first_line_ = false; - } else { + first_line_ = false; + } else { line_len_ = min_line_len_ + wrapped_line_indent_; - } + } out_ << std::string(line_len_, ' '); - } - void EndLine() { - out_ << '\n'; - line_len_ = 0; - } - - private: - std::ostream& out_; + } + void EndLine() { + out_ << '\n'; + line_len_ = 0; + } + + private: + std::ostream& out_; const size_t max_line_len_; const size_t min_line_len_; const size_t wrapped_line_indent_; size_t line_len_; - bool first_line_; -}; - + bool first_line_; +}; + void FlagHelpHumanReadable(const CommandLineFlag& flag, std::ostream& out) { FlagHelpPrettyPrinter printer(kHrfMaxLineLength, 4, 2, out); - - // Flag name. + + // Flag name. printer.Write(absl::StrCat("--", flag.Name())); - - // Flag help. - printer.Write(absl::StrCat("(", flag.Help(), ");"), /*wrap_line=*/true); - - // The listed default value will be the actual default from the flag - // definition in the originating source file, unless the value has - // subsequently been modified using SetCommandLineOption() with mode - // SET_FLAGS_DEFAULT. - std::string dflt_val = flag.DefaultValue(); + + // Flag help. + printer.Write(absl::StrCat("(", flag.Help(), ");"), /*wrap_line=*/true); + + // The listed default value will be the actual default from the flag + // definition in the originating source file, unless the value has + // subsequently been modified using SetCommandLineOption() with mode + // SET_FLAGS_DEFAULT. + std::string dflt_val = flag.DefaultValue(); std::string curr_val = flag.CurrentValue(); bool is_modified = curr_val != dflt_val; - if (flag.IsOfType<std::string>()) { - dflt_val = absl::StrCat("\"", dflt_val, "\""); - } - printer.Write(absl::StrCat("default: ", dflt_val, ";")); - + if (flag.IsOfType<std::string>()) { + dflt_val = absl::StrCat("\"", dflt_val, "\""); + } + printer.Write(absl::StrCat("default: ", dflt_val, ";")); + if (is_modified) { - if (flag.IsOfType<std::string>()) { - curr_val = absl::StrCat("\"", curr_val, "\""); - } - printer.Write(absl::StrCat("currently: ", curr_val, ";")); - } - - printer.EndLine(); -} - -// Shows help for every filename which matches any of the filters -// If filters are empty, shows help for every file. -// If a flag's help message has been stripped (e.g. by adding '#define -// STRIP_FLAG_HELP 1' then this flag will not be displayed by '--help' -// and its variants. + if (flag.IsOfType<std::string>()) { + curr_val = absl::StrCat("\"", curr_val, "\""); + } + printer.Write(absl::StrCat("currently: ", curr_val, ";")); + } + + printer.EndLine(); +} + +// Shows help for every filename which matches any of the filters +// If filters are empty, shows help for every file. +// If a flag's help message has been stripped (e.g. by adding '#define +// STRIP_FLAG_HELP 1' then this flag will not be displayed by '--help' +// and its variants. void FlagsHelpImpl(std::ostream& out, PerFlagFilter filter_cb, - HelpFormat format, absl::string_view program_usage_message) { - if (format == HelpFormat::kHumanReadable) { - out << flags_internal::ShortProgramInvocationName() << ": " - << program_usage_message << "\n\n"; - } else { - // XML schema is not a part of our public API for now. - out << "<?xml version=\"1.0\"?>\n" - << "<!-- This output should be used with care. We do not report type " - "names for flags with user defined types -->\n" - << "<!-- Prefer flag only_check_args for validating flag inputs -->\n" - // The document. - << "<AllFlags>\n" - // The program name and usage. - << XMLElement("program", flags_internal::ShortProgramInvocationName()) - << '\n' - << XMLElement("usage", program_usage_message) << '\n'; - } - + HelpFormat format, absl::string_view program_usage_message) { + if (format == HelpFormat::kHumanReadable) { + out << flags_internal::ShortProgramInvocationName() << ": " + << program_usage_message << "\n\n"; + } else { + // XML schema is not a part of our public API for now. + out << "<?xml version=\"1.0\"?>\n" + << "<!-- This output should be used with care. We do not report type " + "names for flags with user defined types -->\n" + << "<!-- Prefer flag only_check_args for validating flag inputs -->\n" + // The document. + << "<AllFlags>\n" + // The program name and usage. + << XMLElement("program", flags_internal::ShortProgramInvocationName()) + << '\n' + << XMLElement("usage", program_usage_message) << '\n'; + } + // Ordered map of package name to - // map of file name to - // vector of flags in the file. - // This map is used to output matching flags grouped by package and file - // name. - std::map<std::string, + // map of file name to + // vector of flags in the file. + // This map is used to output matching flags grouped by package and file + // name. + std::map<std::string, std::map<std::string, std::vector<const absl::CommandLineFlag*>>> - matching_flags; - + matching_flags; + flags_internal::ForEachFlag([&](absl::CommandLineFlag& flag) { - // Ignore retired flags. + // Ignore retired flags. if (flag.IsRetired()) return; - - // If the flag has been stripped, pretend that it doesn't exist. + + // If the flag has been stripped, pretend that it doesn't exist. if (flag.Help() == flags_internal::kStrippedFlagHelp) return; - + // Make sure flag satisfies the filter if (!filter_cb(flag)) return; std::string flag_filename = flag.Filename(); - matching_flags[std::string(flags_internal::Package(flag_filename))] - [flag_filename] + matching_flags[std::string(flags_internal::Package(flag_filename))] + [flag_filename] .push_back(&flag); - }); - + }); + absl::string_view package_separator; // controls blank lines between packages absl::string_view file_separator; // controls blank lines between files for (auto& package : matching_flags) { - if (format == HelpFormat::kHumanReadable) { - out << package_separator; - package_separator = "\n\n"; - } - - file_separator = ""; + if (format == HelpFormat::kHumanReadable) { + out << package_separator; + package_separator = "\n\n"; + } + + file_separator = ""; for (auto& flags_in_file : package.second) { - if (format == HelpFormat::kHumanReadable) { - out << file_separator << " Flags from " << flags_in_file.first - << ":\n"; - file_separator = "\n"; - } - + if (format == HelpFormat::kHumanReadable) { + out << file_separator << " Flags from " << flags_in_file.first + << ":\n"; + file_separator = "\n"; + } + std::sort(std::begin(flags_in_file.second), std::end(flags_in_file.second), [](const CommandLineFlag* lhs, const CommandLineFlag* rhs) { return lhs->Name() < rhs->Name(); }); - for (const auto* flag : flags_in_file.second) { - flags_internal::FlagHelp(out, *flag, format); - } - } - } - - if (format == HelpFormat::kHumanReadable) { + for (const auto* flag : flags_in_file.second) { + flags_internal::FlagHelp(out, *flag, format); + } + } + } + + if (format == HelpFormat::kHumanReadable) { FlagHelpPrettyPrinter printer(kHrfMaxLineLength, 0, 0, out); - if (filter_cb && matching_flags.empty()) { + if (filter_cb && matching_flags.empty()) { printer.Write("No flags matched.\n", true); - } + } printer.EndLine(); printer.Write( "Try --helpfull to get a list of all flags or --help=substring " "shows help for flags which include specified substring in either " "in the name, or description or path.\n", true); - } else { - // The end of the document. - out << "</AllFlags>\n"; - } -} - + } else { + // The end of the document. + out << "</AllFlags>\n"; + } +} + void FlagsHelpImpl(std::ostream& out, flags_internal::FlagKindFilter filename_filter_cb, HelpFormat format, absl::string_view program_usage_message) { @@ -328,32 +328,32 @@ void FlagsHelpImpl(std::ostream& out, format, program_usage_message); } -} // namespace - -// -------------------------------------------------------------------- -// Produces the help message describing specific flag. +} // namespace + +// -------------------------------------------------------------------- +// Produces the help message describing specific flag. void FlagHelp(std::ostream& out, const CommandLineFlag& flag, - HelpFormat format) { - if (format == HelpFormat::kHumanReadable) + HelpFormat format) { + if (format == HelpFormat::kHumanReadable) flags_internal::FlagHelpHumanReadable(flag, out); -} - -// -------------------------------------------------------------------- +} + +// -------------------------------------------------------------------- // Produces the help messages for all flags matching the filename filter. -// If filter is empty produces help messages for all flags. -void FlagsHelp(std::ostream& out, absl::string_view filter, HelpFormat format, - absl::string_view program_usage_message) { - flags_internal::FlagKindFilter filter_cb = [&](absl::string_view filename) { - return filter.empty() || filename.find(filter) != absl::string_view::npos; - }; - flags_internal::FlagsHelpImpl(out, filter_cb, format, program_usage_message); -} - -// -------------------------------------------------------------------- -// Checks all the 'usage' command line flags to see if any have been set. -// If so, handles them appropriately. -int HandleUsageFlags(std::ostream& out, - absl::string_view program_usage_message) { +// If filter is empty produces help messages for all flags. +void FlagsHelp(std::ostream& out, absl::string_view filter, HelpFormat format, + absl::string_view program_usage_message) { + flags_internal::FlagKindFilter filter_cb = [&](absl::string_view filename) { + return filter.empty() || filename.find(filter) != absl::string_view::npos; + }; + flags_internal::FlagsHelpImpl(out, filter_cb, format, program_usage_message); +} + +// -------------------------------------------------------------------- +// Checks all the 'usage' command line flags to see if any have been set. +// If so, handles them appropriately. +int HandleUsageFlags(std::ostream& out, + absl::string_view program_usage_message) { switch (GetFlagsHelpMode()) { case HelpMode::kNone: break; @@ -362,25 +362,25 @@ int HandleUsageFlags(std::ostream& out, out, flags_internal::GetUsageConfig().contains_help_flags, GetFlagsHelpFormat(), program_usage_message); return 1; - + case HelpMode::kShort: flags_internal::FlagsHelpImpl( out, flags_internal::GetUsageConfig().contains_helpshort_flags, GetFlagsHelpFormat(), program_usage_message); return 1; - + case HelpMode::kFull: flags_internal::FlagsHelp(out, "", GetFlagsHelpFormat(), program_usage_message); return 1; - + case HelpMode::kPackage: flags_internal::FlagsHelpImpl( out, flags_internal::GetUsageConfig().contains_helppackage_flags, GetFlagsHelpFormat(), program_usage_message); - + return 1; - + case HelpMode::kMatch: { std::string substr = GetFlagsHelpMatchSubstr(); if (substr.empty()) { @@ -392,7 +392,7 @@ int HandleUsageFlags(std::ostream& out, if (absl::StrContains(flag.Name(), substr)) return true; if (absl::StrContains(flag.Filename(), substr)) return true; if (absl::StrContains(flag.Help(), substr)) return true; - + return false; }; flags_internal::FlagsHelpImpl( @@ -409,14 +409,14 @@ int HandleUsageFlags(std::ostream& out, case HelpMode::kOnlyCheckArgs: return 0; - } - + } + return -1; } - + // -------------------------------------------------------------------- // Globals representing usage reporting flags - + namespace { ABSL_CONST_INIT absl::Mutex help_attributes_guard(absl::kConstInit); @@ -504,21 +504,21 @@ bool DeduceUsageFlags(absl::string_view name, absl::string_view value) { } return false; - } - + } + if (name == "version") { SetFlagsHelpMode(HelpMode::kVersion); return true; - } - + } + if (name == "only_check_args") { SetFlagsHelpMode(HelpMode::kOnlyCheckArgs); return true; - } - + } + return false; -} - -} // namespace flags_internal +} + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl +} // namespace absl diff --git a/contrib/restricted/abseil-cpp/absl/flags/internal/usage.h b/contrib/restricted/abseil-cpp/absl/flags/internal/usage.h index f780af74b2..c0bcac5762 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/internal/usage.h +++ b/contrib/restricted/abseil-cpp/absl/flags/internal/usage.h @@ -1,71 +1,71 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_FLAGS_INTERNAL_USAGE_H_ -#define ABSL_FLAGS_INTERNAL_USAGE_H_ - -#include <iosfwd> -#include <string> - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ABSL_FLAGS_INTERNAL_USAGE_H_ +#define ABSL_FLAGS_INTERNAL_USAGE_H_ + +#include <iosfwd> +#include <string> + #include "absl/base/config.h" #include "absl/flags/commandlineflag.h" -#include "absl/flags/declare.h" -#include "absl/strings/string_view.h" - -// -------------------------------------------------------------------- -// Usage reporting interfaces - -namespace absl { +#include "absl/flags/declare.h" +#include "absl/strings/string_view.h" + +// -------------------------------------------------------------------- +// Usage reporting interfaces + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -// The format to report the help messages in. -enum class HelpFormat { - kHumanReadable, -}; - +namespace flags_internal { + +// The format to report the help messages in. +enum class HelpFormat { + kHumanReadable, +}; + // Streams the help message describing `flag` to `out`. // The default value for `flag` is included in the output. void FlagHelp(std::ostream& out, const CommandLineFlag& flag, - HelpFormat format = HelpFormat::kHumanReadable); - -// Produces the help messages for all flags matching the filter. A flag matches -// the filter if it is defined in a file with a filename which includes -// filter string as a substring. You can use '/' and '.' to restrict the -// matching to a specific file names. For example: -// FlagsHelp(out, "/path/to/file."); -// restricts help to only flags which resides in files named like: -// .../path/to/file.<ext> -// for any extension 'ext'. If the filter is empty this function produces help -// messages for all flags. -void FlagsHelp(std::ostream& out, absl::string_view filter, - HelpFormat format, absl::string_view program_usage_message); - -// -------------------------------------------------------------------- - -// If any of the 'usage' related command line flags (listed on the bottom of -// this file) has been set this routine produces corresponding help message in -// the specified output stream and returns: -// 0 - if "version" or "only_check_flags" flags were set and handled. -// 1 - if some other 'usage' related flag was set and handled. -// -1 - if no usage flags were set on a commmand line. -// Non negative return values are expected to be used as an exit code for a -// binary. -int HandleUsageFlags(std::ostream& out, - absl::string_view program_usage_message); - + HelpFormat format = HelpFormat::kHumanReadable); + +// Produces the help messages for all flags matching the filter. A flag matches +// the filter if it is defined in a file with a filename which includes +// filter string as a substring. You can use '/' and '.' to restrict the +// matching to a specific file names. For example: +// FlagsHelp(out, "/path/to/file."); +// restricts help to only flags which resides in files named like: +// .../path/to/file.<ext> +// for any extension 'ext'. If the filter is empty this function produces help +// messages for all flags. +void FlagsHelp(std::ostream& out, absl::string_view filter, + HelpFormat format, absl::string_view program_usage_message); + +// -------------------------------------------------------------------- + +// If any of the 'usage' related command line flags (listed on the bottom of +// this file) has been set this routine produces corresponding help message in +// the specified output stream and returns: +// 0 - if "version" or "only_check_flags" flags were set and handled. +// 1 - if some other 'usage' related flag was set and handled. +// -1 - if no usage flags were set on a commmand line. +// Non negative return values are expected to be used as an exit code for a +// binary. +int HandleUsageFlags(std::ostream& out, + absl::string_view program_usage_message); + // -------------------------------------------------------------------- // Globals representing usage reporting flags @@ -97,8 +97,8 @@ void SetFlagsHelpFormat(HelpFormat); // function. bool DeduceUsageFlags(absl::string_view name, absl::string_view value); -} // namespace flags_internal +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_INTERNAL_USAGE_H_ +} // namespace absl + +#endif // ABSL_FLAGS_INTERNAL_USAGE_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/marshalling.cc b/contrib/restricted/abseil-cpp/absl/flags/marshalling.cc index ce07bf7ff1..81f9cebd6f 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/marshalling.cc +++ b/contrib/restricted/abseil-cpp/absl/flags/marshalling.cc @@ -1,241 +1,241 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/flags/marshalling.h" - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/flags/marshalling.h" + #include <stddef.h> #include <cmath> -#include <limits> +#include <limits> #include <string> -#include <type_traits> +#include <type_traits> #include <vector> - + #include "absl/base/config.h" #include "absl/base/log_severity.h" -#include "absl/base/macros.h" +#include "absl/base/macros.h" #include "absl/strings/ascii.h" -#include "absl/strings/match.h" -#include "absl/strings/numbers.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_join.h" -#include "absl/strings/str_split.h" +#include "absl/strings/match.h" +#include "absl/strings/numbers.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/str_format.h" +#include "absl/strings/str_join.h" +#include "absl/strings/str_split.h" #include "absl/strings/string_view.h" - -namespace absl { + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -// -------------------------------------------------------------------- -// AbslParseFlag specializations for boolean type. - -bool AbslParseFlag(absl::string_view text, bool* dst, std::string*) { - const char* kTrue[] = {"1", "t", "true", "y", "yes"}; - const char* kFalse[] = {"0", "f", "false", "n", "no"}; - static_assert(sizeof(kTrue) == sizeof(kFalse), "true_false_equal"); - - text = absl::StripAsciiWhitespace(text); - - for (size_t i = 0; i < ABSL_ARRAYSIZE(kTrue); ++i) { - if (absl::EqualsIgnoreCase(text, kTrue[i])) { - *dst = true; - return true; - } else if (absl::EqualsIgnoreCase(text, kFalse[i])) { - *dst = false; - return true; - } - } - return false; // didn't match a legal input -} - -// -------------------------------------------------------------------- -// AbslParseFlag for integral types. - -// Return the base to use for parsing text as an integer. Leading 0x -// puts us in base 16. But leading 0 does not put us in base 8. It -// caused too many bugs when we had that behavior. -static int NumericBase(absl::string_view text) { - const bool hex = (text.size() >= 2 && text[0] == '0' && - (text[1] == 'x' || text[1] == 'X')); - return hex ? 16 : 10; -} - -template <typename IntType> +namespace flags_internal { + +// -------------------------------------------------------------------- +// AbslParseFlag specializations for boolean type. + +bool AbslParseFlag(absl::string_view text, bool* dst, std::string*) { + const char* kTrue[] = {"1", "t", "true", "y", "yes"}; + const char* kFalse[] = {"0", "f", "false", "n", "no"}; + static_assert(sizeof(kTrue) == sizeof(kFalse), "true_false_equal"); + + text = absl::StripAsciiWhitespace(text); + + for (size_t i = 0; i < ABSL_ARRAYSIZE(kTrue); ++i) { + if (absl::EqualsIgnoreCase(text, kTrue[i])) { + *dst = true; + return true; + } else if (absl::EqualsIgnoreCase(text, kFalse[i])) { + *dst = false; + return true; + } + } + return false; // didn't match a legal input +} + +// -------------------------------------------------------------------- +// AbslParseFlag for integral types. + +// Return the base to use for parsing text as an integer. Leading 0x +// puts us in base 16. But leading 0 does not put us in base 8. It +// caused too many bugs when we had that behavior. +static int NumericBase(absl::string_view text) { + const bool hex = (text.size() >= 2 && text[0] == '0' && + (text[1] == 'x' || text[1] == 'X')); + return hex ? 16 : 10; +} + +template <typename IntType> inline bool ParseFlagImpl(absl::string_view text, IntType& dst) { - text = absl::StripAsciiWhitespace(text); - + text = absl::StripAsciiWhitespace(text); + return absl::numbers_internal::safe_strtoi_base(text, &dst, NumericBase(text)); -} - -bool AbslParseFlag(absl::string_view text, short* dst, std::string*) { - int val; +} + +bool AbslParseFlag(absl::string_view text, short* dst, std::string*) { + int val; if (!ParseFlagImpl(text, val)) return false; - if (static_cast<short>(val) != val) // worked, but number out of range - return false; - *dst = static_cast<short>(val); - return true; -} - -bool AbslParseFlag(absl::string_view text, unsigned short* dst, std::string*) { - unsigned int val; + if (static_cast<short>(val) != val) // worked, but number out of range + return false; + *dst = static_cast<short>(val); + return true; +} + +bool AbslParseFlag(absl::string_view text, unsigned short* dst, std::string*) { + unsigned int val; if (!ParseFlagImpl(text, val)) return false; - if (static_cast<unsigned short>(val) != - val) // worked, but number out of range - return false; - *dst = static_cast<unsigned short>(val); - return true; -} - -bool AbslParseFlag(absl::string_view text, int* dst, std::string*) { + if (static_cast<unsigned short>(val) != + val) // worked, but number out of range + return false; + *dst = static_cast<unsigned short>(val); + return true; +} + +bool AbslParseFlag(absl::string_view text, int* dst, std::string*) { return ParseFlagImpl(text, *dst); -} - -bool AbslParseFlag(absl::string_view text, unsigned int* dst, std::string*) { +} + +bool AbslParseFlag(absl::string_view text, unsigned int* dst, std::string*) { return ParseFlagImpl(text, *dst); -} - -bool AbslParseFlag(absl::string_view text, long* dst, std::string*) { +} + +bool AbslParseFlag(absl::string_view text, long* dst, std::string*) { return ParseFlagImpl(text, *dst); -} - -bool AbslParseFlag(absl::string_view text, unsigned long* dst, std::string*) { +} + +bool AbslParseFlag(absl::string_view text, unsigned long* dst, std::string*) { return ParseFlagImpl(text, *dst); -} - -bool AbslParseFlag(absl::string_view text, long long* dst, std::string*) { +} + +bool AbslParseFlag(absl::string_view text, long long* dst, std::string*) { return ParseFlagImpl(text, *dst); -} - -bool AbslParseFlag(absl::string_view text, unsigned long long* dst, - std::string*) { +} + +bool AbslParseFlag(absl::string_view text, unsigned long long* dst, + std::string*) { return ParseFlagImpl(text, *dst); -} - -// -------------------------------------------------------------------- -// AbslParseFlag for floating point types. - -bool AbslParseFlag(absl::string_view text, float* dst, std::string*) { - return absl::SimpleAtof(text, dst); -} - -bool AbslParseFlag(absl::string_view text, double* dst, std::string*) { - return absl::SimpleAtod(text, dst); -} - -// -------------------------------------------------------------------- -// AbslParseFlag for strings. - -bool AbslParseFlag(absl::string_view text, std::string* dst, std::string*) { - dst->assign(text.data(), text.size()); - return true; -} - -// -------------------------------------------------------------------- -// AbslParseFlag for vector of strings. - -bool AbslParseFlag(absl::string_view text, std::vector<std::string>* dst, - std::string*) { - // An empty flag value corresponds to an empty vector, not a vector - // with a single, empty std::string. - if (text.empty()) { - dst->clear(); - return true; - } - *dst = absl::StrSplit(text, ',', absl::AllowEmpty()); - return true; -} - -// -------------------------------------------------------------------- -// AbslUnparseFlag specializations for various builtin flag types. - -std::string Unparse(bool v) { return v ? "true" : "false"; } -std::string Unparse(short v) { return absl::StrCat(v); } -std::string Unparse(unsigned short v) { return absl::StrCat(v); } -std::string Unparse(int v) { return absl::StrCat(v); } -std::string Unparse(unsigned int v) { return absl::StrCat(v); } -std::string Unparse(long v) { return absl::StrCat(v); } -std::string Unparse(unsigned long v) { return absl::StrCat(v); } -std::string Unparse(long long v) { return absl::StrCat(v); } -std::string Unparse(unsigned long long v) { return absl::StrCat(v); } -template <typename T> -std::string UnparseFloatingPointVal(T v) { +} + +// -------------------------------------------------------------------- +// AbslParseFlag for floating point types. + +bool AbslParseFlag(absl::string_view text, float* dst, std::string*) { + return absl::SimpleAtof(text, dst); +} + +bool AbslParseFlag(absl::string_view text, double* dst, std::string*) { + return absl::SimpleAtod(text, dst); +} + +// -------------------------------------------------------------------- +// AbslParseFlag for strings. + +bool AbslParseFlag(absl::string_view text, std::string* dst, std::string*) { + dst->assign(text.data(), text.size()); + return true; +} + +// -------------------------------------------------------------------- +// AbslParseFlag for vector of strings. + +bool AbslParseFlag(absl::string_view text, std::vector<std::string>* dst, + std::string*) { + // An empty flag value corresponds to an empty vector, not a vector + // with a single, empty std::string. + if (text.empty()) { + dst->clear(); + return true; + } + *dst = absl::StrSplit(text, ',', absl::AllowEmpty()); + return true; +} + +// -------------------------------------------------------------------- +// AbslUnparseFlag specializations for various builtin flag types. + +std::string Unparse(bool v) { return v ? "true" : "false"; } +std::string Unparse(short v) { return absl::StrCat(v); } +std::string Unparse(unsigned short v) { return absl::StrCat(v); } +std::string Unparse(int v) { return absl::StrCat(v); } +std::string Unparse(unsigned int v) { return absl::StrCat(v); } +std::string Unparse(long v) { return absl::StrCat(v); } +std::string Unparse(unsigned long v) { return absl::StrCat(v); } +std::string Unparse(long long v) { return absl::StrCat(v); } +std::string Unparse(unsigned long long v) { return absl::StrCat(v); } +template <typename T> +std::string UnparseFloatingPointVal(T v) { // digits10 is guaranteed to roundtrip correctly in string -> value -> string - // conversions, but may not be enough to represent all the values correctly. - std::string digit10_str = - absl::StrFormat("%.*g", std::numeric_limits<T>::digits10, v); - if (std::isnan(v) || std::isinf(v)) return digit10_str; - - T roundtrip_val = 0; - std::string err; - if (absl::ParseFlag(digit10_str, &roundtrip_val, &err) && - roundtrip_val == v) { - return digit10_str; - } - - // max_digits10 is the number of base-10 digits that are necessary to uniquely - // represent all distinct values. - return absl::StrFormat("%.*g", std::numeric_limits<T>::max_digits10, v); -} -std::string Unparse(float v) { return UnparseFloatingPointVal(v); } -std::string Unparse(double v) { return UnparseFloatingPointVal(v); } -std::string AbslUnparseFlag(absl::string_view v) { return std::string(v); } -std::string AbslUnparseFlag(const std::vector<std::string>& v) { - return absl::StrJoin(v, ","); -} - -} // namespace flags_internal - -bool AbslParseFlag(absl::string_view text, absl::LogSeverity* dst, - std::string* err) { - text = absl::StripAsciiWhitespace(text); - if (text.empty()) { - *err = "no value provided"; - return false; - } - if (text.front() == 'k' || text.front() == 'K') text.remove_prefix(1); - if (absl::EqualsIgnoreCase(text, "info")) { - *dst = absl::LogSeverity::kInfo; - return true; - } - if (absl::EqualsIgnoreCase(text, "warning")) { - *dst = absl::LogSeverity::kWarning; - return true; - } - if (absl::EqualsIgnoreCase(text, "error")) { - *dst = absl::LogSeverity::kError; - return true; - } - if (absl::EqualsIgnoreCase(text, "fatal")) { - *dst = absl::LogSeverity::kFatal; - return true; - } - std::underlying_type<absl::LogSeverity>::type numeric_value; - if (absl::ParseFlag(text, &numeric_value, err)) { - *dst = static_cast<absl::LogSeverity>(numeric_value); - return true; - } - *err = "only integers and absl::LogSeverity enumerators are accepted"; - return false; -} - -std::string AbslUnparseFlag(absl::LogSeverity v) { - if (v == absl::NormalizeLogSeverity(v)) return absl::LogSeverityName(v); - return absl::UnparseFlag(static_cast<int>(v)); -} - + // conversions, but may not be enough to represent all the values correctly. + std::string digit10_str = + absl::StrFormat("%.*g", std::numeric_limits<T>::digits10, v); + if (std::isnan(v) || std::isinf(v)) return digit10_str; + + T roundtrip_val = 0; + std::string err; + if (absl::ParseFlag(digit10_str, &roundtrip_val, &err) && + roundtrip_val == v) { + return digit10_str; + } + + // max_digits10 is the number of base-10 digits that are necessary to uniquely + // represent all distinct values. + return absl::StrFormat("%.*g", std::numeric_limits<T>::max_digits10, v); +} +std::string Unparse(float v) { return UnparseFloatingPointVal(v); } +std::string Unparse(double v) { return UnparseFloatingPointVal(v); } +std::string AbslUnparseFlag(absl::string_view v) { return std::string(v); } +std::string AbslUnparseFlag(const std::vector<std::string>& v) { + return absl::StrJoin(v, ","); +} + +} // namespace flags_internal + +bool AbslParseFlag(absl::string_view text, absl::LogSeverity* dst, + std::string* err) { + text = absl::StripAsciiWhitespace(text); + if (text.empty()) { + *err = "no value provided"; + return false; + } + if (text.front() == 'k' || text.front() == 'K') text.remove_prefix(1); + if (absl::EqualsIgnoreCase(text, "info")) { + *dst = absl::LogSeverity::kInfo; + return true; + } + if (absl::EqualsIgnoreCase(text, "warning")) { + *dst = absl::LogSeverity::kWarning; + return true; + } + if (absl::EqualsIgnoreCase(text, "error")) { + *dst = absl::LogSeverity::kError; + return true; + } + if (absl::EqualsIgnoreCase(text, "fatal")) { + *dst = absl::LogSeverity::kFatal; + return true; + } + std::underlying_type<absl::LogSeverity>::type numeric_value; + if (absl::ParseFlag(text, &numeric_value, err)) { + *dst = static_cast<absl::LogSeverity>(numeric_value); + return true; + } + *err = "only integers and absl::LogSeverity enumerators are accepted"; + return false; +} + +std::string AbslUnparseFlag(absl::LogSeverity v) { + if (v == absl::NormalizeLogSeverity(v)) return absl::LogSeverityName(v); + return absl::UnparseFlag(static_cast<int>(v)); +} + ABSL_NAMESPACE_END -} // namespace absl +} // namespace absl diff --git a/contrib/restricted/abseil-cpp/absl/flags/marshalling.h b/contrib/restricted/abseil-cpp/absl/flags/marshalling.h index 74ff4c0e8d..7cbc136d57 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/marshalling.h +++ b/contrib/restricted/abseil-cpp/absl/flags/marshalling.h @@ -1,264 +1,264 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ----------------------------------------------------------------------------- -// File: marshalling.h -// ----------------------------------------------------------------------------- -// -// This header file defines the API for extending Abseil flag support to -// custom types, and defines the set of overloads for fundamental types. -// -// Out of the box, the Abseil flags library supports the following types: -// -// * `bool` -// * `int16_t` -// * `uint16_t` -// * `int32_t` -// * `uint32_t` -// * `int64_t` -// * `uint64_t` -// * `float` -// * `double` -// * `std::string` -// * `std::vector<std::string>` +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ----------------------------------------------------------------------------- +// File: marshalling.h +// ----------------------------------------------------------------------------- +// +// This header file defines the API for extending Abseil flag support to +// custom types, and defines the set of overloads for fundamental types. +// +// Out of the box, the Abseil flags library supports the following types: +// +// * `bool` +// * `int16_t` +// * `uint16_t` +// * `int32_t` +// * `uint32_t` +// * `int64_t` +// * `uint64_t` +// * `float` +// * `double` +// * `std::string` +// * `std::vector<std::string>` // * `absl::LogSeverity` (provided natively for layering reasons) -// -// Note that support for integral types is implemented using overloads for -// variable-width fundamental types (`short`, `int`, `long`, etc.). However, -// you should prefer the fixed-width integral types (`int32_t`, `uint64_t`, -// etc.) we've noted above within flag definitions. -// -// In addition, several Abseil libraries provide their own custom support for +// +// Note that support for integral types is implemented using overloads for +// variable-width fundamental types (`short`, `int`, `long`, etc.). However, +// you should prefer the fixed-width integral types (`int32_t`, `uint64_t`, +// etc.) we've noted above within flag definitions. +// +// In addition, several Abseil libraries provide their own custom support for // Abseil flags. Documentation for these formats is provided in the type's // `AbslParseFlag()` definition. -// -// The Abseil time library provides the following support for civil time values: -// -// * `absl::CivilSecond` -// * `absl::CivilMinute` -// * `absl::CivilHour` -// * `absl::CivilDay` -// * `absl::CivilMonth` -// * `absl::CivilYear` -// -// and also provides support for the following absolute time values: -// -// * `absl::Duration` -// * `absl::Time` -// -// Additional support for Abseil types will be noted here as it is added. -// -// You can also provide your own custom flags by adding overloads for -// `AbslParseFlag()` and `AbslUnparseFlag()` to your type definitions. (See -// below.) -// -// ----------------------------------------------------------------------------- -// Adding Type Support for Abseil Flags -// ----------------------------------------------------------------------------- -// -// To add support for your user-defined type, add overloads of `AbslParseFlag()` -// and `AbslUnparseFlag()` as free (non-member) functions to your type. If `T` -// is a class type, these functions can be friend function definitions. These -// overloads must be added to the same namespace where the type is defined, so -// that they can be discovered by Argument-Dependent Lookup (ADL). -// -// Example: -// -// namespace foo { -// -// enum OutputMode { kPlainText, kHtml }; -// -// // AbslParseFlag converts from a string to OutputMode. -// // Must be in same namespace as OutputMode. -// +// +// The Abseil time library provides the following support for civil time values: +// +// * `absl::CivilSecond` +// * `absl::CivilMinute` +// * `absl::CivilHour` +// * `absl::CivilDay` +// * `absl::CivilMonth` +// * `absl::CivilYear` +// +// and also provides support for the following absolute time values: +// +// * `absl::Duration` +// * `absl::Time` +// +// Additional support for Abseil types will be noted here as it is added. +// +// You can also provide your own custom flags by adding overloads for +// `AbslParseFlag()` and `AbslUnparseFlag()` to your type definitions. (See +// below.) +// +// ----------------------------------------------------------------------------- +// Adding Type Support for Abseil Flags +// ----------------------------------------------------------------------------- +// +// To add support for your user-defined type, add overloads of `AbslParseFlag()` +// and `AbslUnparseFlag()` as free (non-member) functions to your type. If `T` +// is a class type, these functions can be friend function definitions. These +// overloads must be added to the same namespace where the type is defined, so +// that they can be discovered by Argument-Dependent Lookup (ADL). +// +// Example: +// +// namespace foo { +// +// enum OutputMode { kPlainText, kHtml }; +// +// // AbslParseFlag converts from a string to OutputMode. +// // Must be in same namespace as OutputMode. +// // // Parses an OutputMode from the command line flag value `text`. Returns -// // `true` and sets `*mode` on success; returns `false` and sets `*error` -// // on failure. -// bool AbslParseFlag(absl::string_view text, -// OutputMode* mode, -// std::string* error) { -// if (text == "plaintext") { -// *mode = kPlainText; -// return true; -// } -// if (text == "html") { -// *mode = kHtml; -// return true; -// } -// *error = "unknown value for enumeration"; -// return false; -// } -// -// // AbslUnparseFlag converts from an OutputMode to a string. -// // Must be in same namespace as OutputMode. -// -// // Returns a textual flag value corresponding to the OutputMode `mode`. -// std::string AbslUnparseFlag(OutputMode mode) { -// switch (mode) { -// case kPlainText: return "plaintext"; -// case kHtml: return "html"; -// } -// return absl::StrCat(mode); -// } -// -// Notice that neither `AbslParseFlag()` nor `AbslUnparseFlag()` are class -// members, but free functions. `AbslParseFlag/AbslUnparseFlag()` overloads -// for a type should only be declared in the same file and namespace as said -// type. The proper `AbslParseFlag/AbslUnparseFlag()` implementations for a -// given type will be discovered via Argument-Dependent Lookup (ADL). -// -// `AbslParseFlag()` may need, in turn, to parse simpler constituent types -// using `absl::ParseFlag()`. For example, a custom struct `MyFlagType` -// consisting of a `std::pair<int, std::string>` would add an `AbslParseFlag()` -// overload for its `MyFlagType` like so: -// -// Example: -// -// namespace my_flag_type { -// -// struct MyFlagType { -// std::pair<int, std::string> my_flag_data; -// }; -// -// bool AbslParseFlag(absl::string_view text, MyFlagType* flag, -// std::string* err); -// -// std::string AbslUnparseFlag(const MyFlagType&); -// -// // Within the implementation, `AbslParseFlag()` will, in turn invoke -// // `absl::ParseFlag()` on its constituent `int` and `std::string` types +// // `true` and sets `*mode` on success; returns `false` and sets `*error` +// // on failure. +// bool AbslParseFlag(absl::string_view text, +// OutputMode* mode, +// std::string* error) { +// if (text == "plaintext") { +// *mode = kPlainText; +// return true; +// } +// if (text == "html") { +// *mode = kHtml; +// return true; +// } +// *error = "unknown value for enumeration"; +// return false; +// } +// +// // AbslUnparseFlag converts from an OutputMode to a string. +// // Must be in same namespace as OutputMode. +// +// // Returns a textual flag value corresponding to the OutputMode `mode`. +// std::string AbslUnparseFlag(OutputMode mode) { +// switch (mode) { +// case kPlainText: return "plaintext"; +// case kHtml: return "html"; +// } +// return absl::StrCat(mode); +// } +// +// Notice that neither `AbslParseFlag()` nor `AbslUnparseFlag()` are class +// members, but free functions. `AbslParseFlag/AbslUnparseFlag()` overloads +// for a type should only be declared in the same file and namespace as said +// type. The proper `AbslParseFlag/AbslUnparseFlag()` implementations for a +// given type will be discovered via Argument-Dependent Lookup (ADL). +// +// `AbslParseFlag()` may need, in turn, to parse simpler constituent types +// using `absl::ParseFlag()`. For example, a custom struct `MyFlagType` +// consisting of a `std::pair<int, std::string>` would add an `AbslParseFlag()` +// overload for its `MyFlagType` like so: +// +// Example: +// +// namespace my_flag_type { +// +// struct MyFlagType { +// std::pair<int, std::string> my_flag_data; +// }; +// +// bool AbslParseFlag(absl::string_view text, MyFlagType* flag, +// std::string* err); +// +// std::string AbslUnparseFlag(const MyFlagType&); +// +// // Within the implementation, `AbslParseFlag()` will, in turn invoke +// // `absl::ParseFlag()` on its constituent `int` and `std::string` types // // (which have built-in Abseil flag support). -// -// bool AbslParseFlag(absl::string_view text, MyFlagType* flag, -// std::string* err) { -// std::pair<absl::string_view, absl::string_view> tokens = -// absl::StrSplit(text, ','); -// if (!absl::ParseFlag(tokens.first, &flag->my_flag_data.first, err)) -// return false; -// if (!absl::ParseFlag(tokens.second, &flag->my_flag_data.second, err)) -// return false; -// return true; -// } -// -// // Similarly, for unparsing, we can simply invoke `absl::UnparseFlag()` on -// // the constituent types. -// std::string AbslUnparseFlag(const MyFlagType& flag) { -// return absl::StrCat(absl::UnparseFlag(flag.my_flag_data.first), -// ",", -// absl::UnparseFlag(flag.my_flag_data.second)); -// } -#ifndef ABSL_FLAGS_MARSHALLING_H_ -#define ABSL_FLAGS_MARSHALLING_H_ - -#include <string> -#include <vector> - +// +// bool AbslParseFlag(absl::string_view text, MyFlagType* flag, +// std::string* err) { +// std::pair<absl::string_view, absl::string_view> tokens = +// absl::StrSplit(text, ','); +// if (!absl::ParseFlag(tokens.first, &flag->my_flag_data.first, err)) +// return false; +// if (!absl::ParseFlag(tokens.second, &flag->my_flag_data.second, err)) +// return false; +// return true; +// } +// +// // Similarly, for unparsing, we can simply invoke `absl::UnparseFlag()` on +// // the constituent types. +// std::string AbslUnparseFlag(const MyFlagType& flag) { +// return absl::StrCat(absl::UnparseFlag(flag.my_flag_data.first), +// ",", +// absl::UnparseFlag(flag.my_flag_data.second)); +// } +#ifndef ABSL_FLAGS_MARSHALLING_H_ +#define ABSL_FLAGS_MARSHALLING_H_ + +#include <string> +#include <vector> + #include "absl/base/config.h" -#include "absl/strings/string_view.h" - -namespace absl { +#include "absl/strings/string_view.h" + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -// Overloads of `AbslParseFlag()` and `AbslUnparseFlag()` for fundamental types. -bool AbslParseFlag(absl::string_view, bool*, std::string*); -bool AbslParseFlag(absl::string_view, short*, std::string*); // NOLINT -bool AbslParseFlag(absl::string_view, unsigned short*, std::string*); // NOLINT -bool AbslParseFlag(absl::string_view, int*, std::string*); // NOLINT -bool AbslParseFlag(absl::string_view, unsigned int*, std::string*); // NOLINT -bool AbslParseFlag(absl::string_view, long*, std::string*); // NOLINT -bool AbslParseFlag(absl::string_view, unsigned long*, std::string*); // NOLINT -bool AbslParseFlag(absl::string_view, long long*, std::string*); // NOLINT -bool AbslParseFlag(absl::string_view, unsigned long long*, // NOLINT - std::string*); -bool AbslParseFlag(absl::string_view, float*, std::string*); -bool AbslParseFlag(absl::string_view, double*, std::string*); -bool AbslParseFlag(absl::string_view, std::string*, std::string*); -bool AbslParseFlag(absl::string_view, std::vector<std::string>*, std::string*); - -template <typename T> -bool InvokeParseFlag(absl::string_view input, T* dst, std::string* err) { - // Comment on next line provides a good compiler error message if T - // does not have AbslParseFlag(absl::string_view, T*, std::string*). - return AbslParseFlag(input, dst, err); // Is T missing AbslParseFlag? -} - -// Strings and std:: containers do not have the same overload resolution -// considerations as fundamental types. Naming these 'AbslUnparseFlag' means we -// can avoid the need for additional specializations of Unparse (below). -std::string AbslUnparseFlag(absl::string_view v); -std::string AbslUnparseFlag(const std::vector<std::string>&); - -template <typename T> -std::string Unparse(const T& v) { - // Comment on next line provides a good compiler error message if T does not - // have UnparseFlag. - return AbslUnparseFlag(v); // Is T missing AbslUnparseFlag? -} - -// Overloads for builtin types. -std::string Unparse(bool v); -std::string Unparse(short v); // NOLINT -std::string Unparse(unsigned short v); // NOLINT -std::string Unparse(int v); // NOLINT -std::string Unparse(unsigned int v); // NOLINT -std::string Unparse(long v); // NOLINT -std::string Unparse(unsigned long v); // NOLINT -std::string Unparse(long long v); // NOLINT -std::string Unparse(unsigned long long v); // NOLINT -std::string Unparse(float v); -std::string Unparse(double v); - -} // namespace flags_internal - -// ParseFlag() -// -// Parses a string value into a flag value of type `T`. Do not add overloads of -// this function for your type directly; instead, add an `AbslParseFlag()` -// free function as documented above. -// -// Some implementations of `AbslParseFlag()` for types which consist of other, -// constituent types which already have Abseil flag support, may need to call -// `absl::ParseFlag()` on those consituent string values. (See above.) -template <typename T> -inline bool ParseFlag(absl::string_view input, T* dst, std::string* error) { - return flags_internal::InvokeParseFlag(input, dst, error); -} - -// UnparseFlag() -// -// Unparses a flag value of type `T` into a string value. Do not add overloads -// of this function for your type directly; instead, add an `AbslUnparseFlag()` -// free function as documented above. -// -// Some implementations of `AbslUnparseFlag()` for types which consist of other, -// constituent types which already have Abseil flag support, may want to call -// `absl::UnparseFlag()` on those constituent types. (See above.) -template <typename T> -inline std::string UnparseFlag(const T& v) { - return flags_internal::Unparse(v); -} - -// Overloads for `absl::LogSeverity` can't (easily) appear alongside that type's -// definition because it is layered below flags. See proper documentation in -// base/log_severity.h. -enum class LogSeverity : int; -bool AbslParseFlag(absl::string_view, absl::LogSeverity*, std::string*); -std::string AbslUnparseFlag(absl::LogSeverity); - +namespace flags_internal { + +// Overloads of `AbslParseFlag()` and `AbslUnparseFlag()` for fundamental types. +bool AbslParseFlag(absl::string_view, bool*, std::string*); +bool AbslParseFlag(absl::string_view, short*, std::string*); // NOLINT +bool AbslParseFlag(absl::string_view, unsigned short*, std::string*); // NOLINT +bool AbslParseFlag(absl::string_view, int*, std::string*); // NOLINT +bool AbslParseFlag(absl::string_view, unsigned int*, std::string*); // NOLINT +bool AbslParseFlag(absl::string_view, long*, std::string*); // NOLINT +bool AbslParseFlag(absl::string_view, unsigned long*, std::string*); // NOLINT +bool AbslParseFlag(absl::string_view, long long*, std::string*); // NOLINT +bool AbslParseFlag(absl::string_view, unsigned long long*, // NOLINT + std::string*); +bool AbslParseFlag(absl::string_view, float*, std::string*); +bool AbslParseFlag(absl::string_view, double*, std::string*); +bool AbslParseFlag(absl::string_view, std::string*, std::string*); +bool AbslParseFlag(absl::string_view, std::vector<std::string>*, std::string*); + +template <typename T> +bool InvokeParseFlag(absl::string_view input, T* dst, std::string* err) { + // Comment on next line provides a good compiler error message if T + // does not have AbslParseFlag(absl::string_view, T*, std::string*). + return AbslParseFlag(input, dst, err); // Is T missing AbslParseFlag? +} + +// Strings and std:: containers do not have the same overload resolution +// considerations as fundamental types. Naming these 'AbslUnparseFlag' means we +// can avoid the need for additional specializations of Unparse (below). +std::string AbslUnparseFlag(absl::string_view v); +std::string AbslUnparseFlag(const std::vector<std::string>&); + +template <typename T> +std::string Unparse(const T& v) { + // Comment on next line provides a good compiler error message if T does not + // have UnparseFlag. + return AbslUnparseFlag(v); // Is T missing AbslUnparseFlag? +} + +// Overloads for builtin types. +std::string Unparse(bool v); +std::string Unparse(short v); // NOLINT +std::string Unparse(unsigned short v); // NOLINT +std::string Unparse(int v); // NOLINT +std::string Unparse(unsigned int v); // NOLINT +std::string Unparse(long v); // NOLINT +std::string Unparse(unsigned long v); // NOLINT +std::string Unparse(long long v); // NOLINT +std::string Unparse(unsigned long long v); // NOLINT +std::string Unparse(float v); +std::string Unparse(double v); + +} // namespace flags_internal + +// ParseFlag() +// +// Parses a string value into a flag value of type `T`. Do not add overloads of +// this function for your type directly; instead, add an `AbslParseFlag()` +// free function as documented above. +// +// Some implementations of `AbslParseFlag()` for types which consist of other, +// constituent types which already have Abseil flag support, may need to call +// `absl::ParseFlag()` on those consituent string values. (See above.) +template <typename T> +inline bool ParseFlag(absl::string_view input, T* dst, std::string* error) { + return flags_internal::InvokeParseFlag(input, dst, error); +} + +// UnparseFlag() +// +// Unparses a flag value of type `T` into a string value. Do not add overloads +// of this function for your type directly; instead, add an `AbslUnparseFlag()` +// free function as documented above. +// +// Some implementations of `AbslUnparseFlag()` for types which consist of other, +// constituent types which already have Abseil flag support, may want to call +// `absl::UnparseFlag()` on those constituent types. (See above.) +template <typename T> +inline std::string UnparseFlag(const T& v) { + return flags_internal::Unparse(v); +} + +// Overloads for `absl::LogSeverity` can't (easily) appear alongside that type's +// definition because it is layered below flags. See proper documentation in +// base/log_severity.h. +enum class LogSeverity : int; +bool AbslParseFlag(absl::string_view, absl::LogSeverity*, std::string*); +std::string AbslUnparseFlag(absl::LogSeverity); + ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_MARSHALLING_H_ +} // namespace absl + +#endif // ABSL_FLAGS_MARSHALLING_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/parse.cc b/contrib/restricted/abseil-cpp/absl/flags/parse.cc index e99640a745..dd1a6796ca 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/parse.cc +++ b/contrib/restricted/abseil-cpp/absl/flags/parse.cc @@ -1,73 +1,73 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/flags/parse.h" - -#include <stdlib.h> - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/flags/parse.h" + +#include <stdlib.h> + #include <algorithm> -#include <fstream> -#include <iostream> +#include <fstream> +#include <iostream> #include <iterator> #include <string> -#include <tuple> +#include <tuple> #include <utility> #include <vector> - -#ifdef _WIN32 -#include <windows.h> -#endif - + +#ifdef _WIN32 +#include <windows.h> +#endif + #include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/const_init.h" #include "absl/base/thread_annotations.h" #include "absl/flags/commandlineflag.h" #include "absl/flags/config.h" -#include "absl/flags/flag.h" +#include "absl/flags/flag.h" #include "absl/flags/internal/commandlineflag.h" #include "absl/flags/internal/flag.h" #include "absl/flags/internal/parse.h" #include "absl/flags/internal/private_handle_accessor.h" -#include "absl/flags/internal/program_name.h" -#include "absl/flags/internal/usage.h" +#include "absl/flags/internal/program_name.h" +#include "absl/flags/internal/usage.h" #include "absl/flags/reflection.h" -#include "absl/flags/usage.h" -#include "absl/flags/usage_config.h" +#include "absl/flags/usage.h" +#include "absl/flags/usage_config.h" #include "absl/strings/ascii.h" -#include "absl/strings/str_cat.h" +#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "absl/strings/strip.h" -#include "absl/synchronization/mutex.h" - -// -------------------------------------------------------------------- - -namespace absl { +#include "absl/strings/strip.h" +#include "absl/synchronization/mutex.h" + +// -------------------------------------------------------------------- + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { -namespace { - -ABSL_CONST_INIT absl::Mutex processing_checks_guard(absl::kConstInit); - -ABSL_CONST_INIT bool flagfile_needs_processing - ABSL_GUARDED_BY(processing_checks_guard) = false; -ABSL_CONST_INIT bool fromenv_needs_processing - ABSL_GUARDED_BY(processing_checks_guard) = false; -ABSL_CONST_INIT bool tryfromenv_needs_processing - ABSL_GUARDED_BY(processing_checks_guard) = false; - +namespace flags_internal { +namespace { + +ABSL_CONST_INIT absl::Mutex processing_checks_guard(absl::kConstInit); + +ABSL_CONST_INIT bool flagfile_needs_processing + ABSL_GUARDED_BY(processing_checks_guard) = false; +ABSL_CONST_INIT bool fromenv_needs_processing + ABSL_GUARDED_BY(processing_checks_guard) = false; +ABSL_CONST_INIT bool tryfromenv_needs_processing + ABSL_GUARDED_BY(processing_checks_guard) = false; + ABSL_CONST_INIT absl::Mutex specified_flags_guard(absl::kConstInit); ABSL_CONST_INIT std::vector<const CommandLineFlag*>* specified_flags ABSL_GUARDED_BY(specified_flags_guard) = nullptr; @@ -84,516 +84,516 @@ struct SpecifiedFlagsCompare { } }; -} // namespace -} // namespace flags_internal +} // namespace +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl - -ABSL_FLAG(std::vector<std::string>, flagfile, {}, - "comma-separated list of files to load flags from") - .OnUpdate([]() { - if (absl::GetFlag(FLAGS_flagfile).empty()) return; - - absl::MutexLock l(&absl::flags_internal::processing_checks_guard); - - // Setting this flag twice before it is handled most likely an internal - // error and should be reviewed by developers. - if (absl::flags_internal::flagfile_needs_processing) { - ABSL_INTERNAL_LOG(WARNING, "flagfile set twice before it is handled"); - } - - absl::flags_internal::flagfile_needs_processing = true; - }); -ABSL_FLAG(std::vector<std::string>, fromenv, {}, - "comma-separated list of flags to set from the environment" - " [use 'export FLAGS_flag1=value']") - .OnUpdate([]() { - if (absl::GetFlag(FLAGS_fromenv).empty()) return; - - absl::MutexLock l(&absl::flags_internal::processing_checks_guard); - - // Setting this flag twice before it is handled most likely an internal - // error and should be reviewed by developers. - if (absl::flags_internal::fromenv_needs_processing) { - ABSL_INTERNAL_LOG(WARNING, "fromenv set twice before it is handled."); - } - - absl::flags_internal::fromenv_needs_processing = true; - }); -ABSL_FLAG(std::vector<std::string>, tryfromenv, {}, - "comma-separated list of flags to try to set from the environment if " - "present") - .OnUpdate([]() { - if (absl::GetFlag(FLAGS_tryfromenv).empty()) return; - - absl::MutexLock l(&absl::flags_internal::processing_checks_guard); - - // Setting this flag twice before it is handled most likely an internal - // error and should be reviewed by developers. - if (absl::flags_internal::tryfromenv_needs_processing) { - ABSL_INTERNAL_LOG(WARNING, - "tryfromenv set twice before it is handled."); - } - - absl::flags_internal::tryfromenv_needs_processing = true; - }); - -ABSL_FLAG(std::vector<std::string>, undefok, {}, - "comma-separated list of flag names that it is okay to specify " - "on the command line even if the program does not define a flag " - "with that name"); - -namespace absl { +} // namespace absl + +ABSL_FLAG(std::vector<std::string>, flagfile, {}, + "comma-separated list of files to load flags from") + .OnUpdate([]() { + if (absl::GetFlag(FLAGS_flagfile).empty()) return; + + absl::MutexLock l(&absl::flags_internal::processing_checks_guard); + + // Setting this flag twice before it is handled most likely an internal + // error and should be reviewed by developers. + if (absl::flags_internal::flagfile_needs_processing) { + ABSL_INTERNAL_LOG(WARNING, "flagfile set twice before it is handled"); + } + + absl::flags_internal::flagfile_needs_processing = true; + }); +ABSL_FLAG(std::vector<std::string>, fromenv, {}, + "comma-separated list of flags to set from the environment" + " [use 'export FLAGS_flag1=value']") + .OnUpdate([]() { + if (absl::GetFlag(FLAGS_fromenv).empty()) return; + + absl::MutexLock l(&absl::flags_internal::processing_checks_guard); + + // Setting this flag twice before it is handled most likely an internal + // error and should be reviewed by developers. + if (absl::flags_internal::fromenv_needs_processing) { + ABSL_INTERNAL_LOG(WARNING, "fromenv set twice before it is handled."); + } + + absl::flags_internal::fromenv_needs_processing = true; + }); +ABSL_FLAG(std::vector<std::string>, tryfromenv, {}, + "comma-separated list of flags to try to set from the environment if " + "present") + .OnUpdate([]() { + if (absl::GetFlag(FLAGS_tryfromenv).empty()) return; + + absl::MutexLock l(&absl::flags_internal::processing_checks_guard); + + // Setting this flag twice before it is handled most likely an internal + // error and should be reviewed by developers. + if (absl::flags_internal::tryfromenv_needs_processing) { + ABSL_INTERNAL_LOG(WARNING, + "tryfromenv set twice before it is handled."); + } + + absl::flags_internal::tryfromenv_needs_processing = true; + }); + +ABSL_FLAG(std::vector<std::string>, undefok, {}, + "comma-separated list of flag names that it is okay to specify " + "on the command line even if the program does not define a flag " + "with that name"); + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -namespace { - -class ArgsList { - public: - ArgsList() : next_arg_(0) {} - ArgsList(int argc, char* argv[]) : args_(argv, argv + argc), next_arg_(0) {} - explicit ArgsList(const std::vector<std::string>& args) - : args_(args), next_arg_(0) {} - - // Returns success status: true if parsing successful, false otherwise. - bool ReadFromFlagfile(const std::string& flag_file_name); - - int Size() const { return args_.size() - next_arg_; } - int FrontIndex() const { return next_arg_; } - absl::string_view Front() const { return args_[next_arg_]; } - void PopFront() { next_arg_++; } - - private: - std::vector<std::string> args_; - int next_arg_; -}; - -bool ArgsList::ReadFromFlagfile(const std::string& flag_file_name) { - std::ifstream flag_file(flag_file_name); - - if (!flag_file) { - flags_internal::ReportUsageError( - absl::StrCat("Can't open flagfile ", flag_file_name), true); - - return false; - } - - // This argument represents fake argv[0], which should be present in all arg - // lists. - args_.push_back(""); - - std::string line; - bool success = true; - - while (std::getline(flag_file, line)) { - absl::string_view stripped = absl::StripLeadingAsciiWhitespace(line); - - if (stripped.empty() || stripped[0] == '#') { - // Comment or empty line; just ignore. - continue; - } - - if (stripped[0] == '-') { - if (stripped == "--") { - flags_internal::ReportUsageError( - "Flagfile can't contain position arguments or --", true); - - success = false; - break; - } - - args_.push_back(std::string(stripped)); - continue; - } - - flags_internal::ReportUsageError( - absl::StrCat("Unexpected line in the flagfile ", flag_file_name, ": ", - line), - true); - - success = false; - } - - return success; -} - -// -------------------------------------------------------------------- - -// Reads the environment variable with name `name` and stores results in -// `value`. If variable is not present in environment returns false, otherwise -// returns true. +namespace flags_internal { + +namespace { + +class ArgsList { + public: + ArgsList() : next_arg_(0) {} + ArgsList(int argc, char* argv[]) : args_(argv, argv + argc), next_arg_(0) {} + explicit ArgsList(const std::vector<std::string>& args) + : args_(args), next_arg_(0) {} + + // Returns success status: true if parsing successful, false otherwise. + bool ReadFromFlagfile(const std::string& flag_file_name); + + int Size() const { return args_.size() - next_arg_; } + int FrontIndex() const { return next_arg_; } + absl::string_view Front() const { return args_[next_arg_]; } + void PopFront() { next_arg_++; } + + private: + std::vector<std::string> args_; + int next_arg_; +}; + +bool ArgsList::ReadFromFlagfile(const std::string& flag_file_name) { + std::ifstream flag_file(flag_file_name); + + if (!flag_file) { + flags_internal::ReportUsageError( + absl::StrCat("Can't open flagfile ", flag_file_name), true); + + return false; + } + + // This argument represents fake argv[0], which should be present in all arg + // lists. + args_.push_back(""); + + std::string line; + bool success = true; + + while (std::getline(flag_file, line)) { + absl::string_view stripped = absl::StripLeadingAsciiWhitespace(line); + + if (stripped.empty() || stripped[0] == '#') { + // Comment or empty line; just ignore. + continue; + } + + if (stripped[0] == '-') { + if (stripped == "--") { + flags_internal::ReportUsageError( + "Flagfile can't contain position arguments or --", true); + + success = false; + break; + } + + args_.push_back(std::string(stripped)); + continue; + } + + flags_internal::ReportUsageError( + absl::StrCat("Unexpected line in the flagfile ", flag_file_name, ": ", + line), + true); + + success = false; + } + + return success; +} + +// -------------------------------------------------------------------- + +// Reads the environment variable with name `name` and stores results in +// `value`. If variable is not present in environment returns false, otherwise +// returns true. bool GetEnvVar(const char* var_name, std::string& var_value) { -#ifdef _WIN32 - char buf[1024]; - auto get_res = GetEnvironmentVariableA(var_name, buf, sizeof(buf)); - if (get_res >= sizeof(buf)) { - return false; - } - - if (get_res == 0) { - return false; - } - +#ifdef _WIN32 + char buf[1024]; + auto get_res = GetEnvironmentVariableA(var_name, buf, sizeof(buf)); + if (get_res >= sizeof(buf)) { + return false; + } + + if (get_res == 0) { + return false; + } + var_value = std::string(buf, get_res); -#else - const char* val = ::getenv(var_name); - if (val == nullptr) { - return false; - } - +#else + const char* val = ::getenv(var_name); + if (val == nullptr) { + return false; + } + var_value = val; -#endif - - return true; -} - -// -------------------------------------------------------------------- - -// Returns: -// Flag name or empty if arg= -- -// Flag value after = in --flag=value (empty if --foo) -// "Is empty value" status. True if arg= --foo=, false otherwise. This is -// required to separate --foo from --foo=. -// For example: -// arg return values -// "--foo=bar" -> {"foo", "bar", false}. -// "--foo" -> {"foo", "", false}. -// "--foo=" -> {"foo", "", true}. -std::tuple<absl::string_view, absl::string_view, bool> SplitNameAndValue( - absl::string_view arg) { - // Allow -foo and --foo - absl::ConsumePrefix(&arg, "-"); - - if (arg.empty()) { - return std::make_tuple("", "", false); - } - - auto equal_sign_pos = arg.find("="); - - absl::string_view flag_name = arg.substr(0, equal_sign_pos); - - absl::string_view value; - bool is_empty_value = false; - - if (equal_sign_pos != absl::string_view::npos) { - value = arg.substr(equal_sign_pos + 1); - is_empty_value = value.empty(); - } - - return std::make_tuple(flag_name, value, is_empty_value); -} - -// -------------------------------------------------------------------- - -// Returns: -// found flag or nullptr -// is negative in case of --nofoo -std::tuple<CommandLineFlag*, bool> LocateFlag(absl::string_view flag_name) { +#endif + + return true; +} + +// -------------------------------------------------------------------- + +// Returns: +// Flag name or empty if arg= -- +// Flag value after = in --flag=value (empty if --foo) +// "Is empty value" status. True if arg= --foo=, false otherwise. This is +// required to separate --foo from --foo=. +// For example: +// arg return values +// "--foo=bar" -> {"foo", "bar", false}. +// "--foo" -> {"foo", "", false}. +// "--foo=" -> {"foo", "", true}. +std::tuple<absl::string_view, absl::string_view, bool> SplitNameAndValue( + absl::string_view arg) { + // Allow -foo and --foo + absl::ConsumePrefix(&arg, "-"); + + if (arg.empty()) { + return std::make_tuple("", "", false); + } + + auto equal_sign_pos = arg.find("="); + + absl::string_view flag_name = arg.substr(0, equal_sign_pos); + + absl::string_view value; + bool is_empty_value = false; + + if (equal_sign_pos != absl::string_view::npos) { + value = arg.substr(equal_sign_pos + 1); + is_empty_value = value.empty(); + } + + return std::make_tuple(flag_name, value, is_empty_value); +} + +// -------------------------------------------------------------------- + +// Returns: +// found flag or nullptr +// is negative in case of --nofoo +std::tuple<CommandLineFlag*, bool> LocateFlag(absl::string_view flag_name) { CommandLineFlag* flag = absl::FindCommandLineFlag(flag_name); - bool is_negative = false; - - if (!flag && absl::ConsumePrefix(&flag_name, "no")) { + bool is_negative = false; + + if (!flag && absl::ConsumePrefix(&flag_name, "no")) { flag = absl::FindCommandLineFlag(flag_name); - is_negative = true; - } - - return std::make_tuple(flag, is_negative); -} - -// -------------------------------------------------------------------- - -// Verify that default values of typed flags must be convertible to string and -// back. -void CheckDefaultValuesParsingRoundtrip() { -#ifndef NDEBUG + is_negative = true; + } + + return std::make_tuple(flag, is_negative); +} + +// -------------------------------------------------------------------- + +// Verify that default values of typed flags must be convertible to string and +// back. +void CheckDefaultValuesParsingRoundtrip() { +#ifndef NDEBUG flags_internal::ForEachFlag([&](CommandLineFlag& flag) { if (flag.IsRetired()) return; - + #define ABSL_FLAGS_INTERNAL_IGNORE_TYPE(T, _) \ if (flag.IsOfType<T>()) return; - + ABSL_FLAGS_INTERNAL_SUPPORTED_TYPES(ABSL_FLAGS_INTERNAL_IGNORE_TYPE) #undef ABSL_FLAGS_INTERNAL_IGNORE_TYPE - + flags_internal::PrivateHandleAccessor::CheckDefaultValueParsingRoundtrip( flag); - }); -#endif -} - -// -------------------------------------------------------------------- - -// Returns success status, which is true if we successfully read all flag files, -// in which case new ArgLists are appended to the input_args in a reverse order -// of file names in the input flagfiles list. This order ensures that flags from -// the first flagfile in the input list are processed before the second flagfile -// etc. -bool ReadFlagfiles(const std::vector<std::string>& flagfiles, + }); +#endif +} + +// -------------------------------------------------------------------- + +// Returns success status, which is true if we successfully read all flag files, +// in which case new ArgLists are appended to the input_args in a reverse order +// of file names in the input flagfiles list. This order ensures that flags from +// the first flagfile in the input list are processed before the second flagfile +// etc. +bool ReadFlagfiles(const std::vector<std::string>& flagfiles, std::vector<ArgsList>& input_args) { - bool success = true; - for (auto it = flagfiles.rbegin(); it != flagfiles.rend(); ++it) { - ArgsList al; - - if (al.ReadFromFlagfile(*it)) { + bool success = true; + for (auto it = flagfiles.rbegin(); it != flagfiles.rend(); ++it) { + ArgsList al; + + if (al.ReadFromFlagfile(*it)) { input_args.push_back(al); - } else { - success = false; - } - } - - return success; -} - -// Returns success status, which is true if were able to locate all environment -// variables correctly or if fail_on_absent_in_env is false. The environment -// variable names are expected to be of the form `FLAGS_<flag_name>`, where -// `flag_name` is a string from the input flag_names list. If successful we -// append a single ArgList at the end of the input_args. -bool ReadFlagsFromEnv(const std::vector<std::string>& flag_names, + } else { + success = false; + } + } + + return success; +} + +// Returns success status, which is true if were able to locate all environment +// variables correctly or if fail_on_absent_in_env is false. The environment +// variable names are expected to be of the form `FLAGS_<flag_name>`, where +// `flag_name` is a string from the input flag_names list. If successful we +// append a single ArgList at the end of the input_args. +bool ReadFlagsFromEnv(const std::vector<std::string>& flag_names, std::vector<ArgsList>& input_args, - bool fail_on_absent_in_env) { - bool success = true; - std::vector<std::string> args; - - // This argument represents fake argv[0], which should be present in all arg - // lists. - args.push_back(""); - - for (const auto& flag_name : flag_names) { - // Avoid infinite recursion. - if (flag_name == "fromenv" || flag_name == "tryfromenv") { - flags_internal::ReportUsageError( - absl::StrCat("Infinite recursion on flag ", flag_name), true); - - success = false; - continue; - } - - const std::string envname = absl::StrCat("FLAGS_", flag_name); - std::string envval; + bool fail_on_absent_in_env) { + bool success = true; + std::vector<std::string> args; + + // This argument represents fake argv[0], which should be present in all arg + // lists. + args.push_back(""); + + for (const auto& flag_name : flag_names) { + // Avoid infinite recursion. + if (flag_name == "fromenv" || flag_name == "tryfromenv") { + flags_internal::ReportUsageError( + absl::StrCat("Infinite recursion on flag ", flag_name), true); + + success = false; + continue; + } + + const std::string envname = absl::StrCat("FLAGS_", flag_name); + std::string envval; if (!GetEnvVar(envname.c_str(), envval)) { - if (fail_on_absent_in_env) { - flags_internal::ReportUsageError( - absl::StrCat(envname, " not found in environment"), true); - - success = false; - } - - continue; - } - - args.push_back(absl::StrCat("--", flag_name, "=", envval)); - } - - if (success) { + if (fail_on_absent_in_env) { + flags_internal::ReportUsageError( + absl::StrCat(envname, " not found in environment"), true); + + success = false; + } + + continue; + } + + args.push_back(absl::StrCat("--", flag_name, "=", envval)); + } + + if (success) { input_args.emplace_back(args); - } - - return success; -} - -// -------------------------------------------------------------------- - -// Returns success status, which is true if were able to handle all generator -// flags (flagfile, fromenv, tryfromemv) successfully. + } + + return success; +} + +// -------------------------------------------------------------------- + +// Returns success status, which is true if were able to handle all generator +// flags (flagfile, fromenv, tryfromemv) successfully. bool HandleGeneratorFlags(std::vector<ArgsList>& input_args, std::vector<std::string>& flagfile_value) { - bool success = true; - - absl::MutexLock l(&flags_internal::processing_checks_guard); - - // flagfile could have been set either on a command line or - // programmatically before invoking ParseCommandLine. Note that we do not - // actually process arguments specified in the flagfile, but instead - // create a secondary arguments list to be processed along with the rest - // of the comamnd line arguments. Since we always the process most recently - // created list of arguments first, this will result in flagfile argument - // being processed before any other argument in the command line. If - // FLAGS_flagfile contains more than one file name we create multiple new - // levels of arguments in a reverse order of file names. Thus we always - // process arguments from first file before arguments containing in a - // second file, etc. If flagfile contains another - // --flagfile inside of it, it will produce new level of arguments and - // processed before the rest of the flagfile. We are also collecting all - // flagfiles set on original command line. Unlike the rest of the flags, - // this flag can be set multiple times and is expected to be handled - // multiple times. We are collecting them all into a single list and set - // the value of FLAGS_flagfile to that value at the end of the parsing. - if (flags_internal::flagfile_needs_processing) { - auto flagfiles = absl::GetFlag(FLAGS_flagfile); - + bool success = true; + + absl::MutexLock l(&flags_internal::processing_checks_guard); + + // flagfile could have been set either on a command line or + // programmatically before invoking ParseCommandLine. Note that we do not + // actually process arguments specified in the flagfile, but instead + // create a secondary arguments list to be processed along with the rest + // of the comamnd line arguments. Since we always the process most recently + // created list of arguments first, this will result in flagfile argument + // being processed before any other argument in the command line. If + // FLAGS_flagfile contains more than one file name we create multiple new + // levels of arguments in a reverse order of file names. Thus we always + // process arguments from first file before arguments containing in a + // second file, etc. If flagfile contains another + // --flagfile inside of it, it will produce new level of arguments and + // processed before the rest of the flagfile. We are also collecting all + // flagfiles set on original command line. Unlike the rest of the flags, + // this flag can be set multiple times and is expected to be handled + // multiple times. We are collecting them all into a single list and set + // the value of FLAGS_flagfile to that value at the end of the parsing. + if (flags_internal::flagfile_needs_processing) { + auto flagfiles = absl::GetFlag(FLAGS_flagfile); + if (input_args.size() == 1) { flagfile_value.insert(flagfile_value.end(), flagfiles.begin(), flagfiles.end()); - } - - success &= ReadFlagfiles(flagfiles, input_args); - - flags_internal::flagfile_needs_processing = false; - } - - // Similar to flagfile fromenv/tryfromemv can be set both - // programmatically and at runtime on a command line. Unlike flagfile these - // can't be recursive. - if (flags_internal::fromenv_needs_processing) { - auto flags_list = absl::GetFlag(FLAGS_fromenv); - - success &= ReadFlagsFromEnv(flags_list, input_args, true); - - flags_internal::fromenv_needs_processing = false; - } - - if (flags_internal::tryfromenv_needs_processing) { - auto flags_list = absl::GetFlag(FLAGS_tryfromenv); - - success &= ReadFlagsFromEnv(flags_list, input_args, false); - - flags_internal::tryfromenv_needs_processing = false; - } - - return success; -} - -// -------------------------------------------------------------------- - -void ResetGeneratorFlags(const std::vector<std::string>& flagfile_value) { - // Setting flagfile to the value which collates all the values set on a - // command line and programmatically. So if command line looked like - // --flagfile=f1 --flagfile=f2 the final value of the FLAGS_flagfile flag is - // going to be {"f1", "f2"} - if (!flagfile_value.empty()) { - absl::SetFlag(&FLAGS_flagfile, flagfile_value); - absl::MutexLock l(&flags_internal::processing_checks_guard); - flags_internal::flagfile_needs_processing = false; - } - - // fromenv/tryfromenv are set to <undefined> value. - if (!absl::GetFlag(FLAGS_fromenv).empty()) { - absl::SetFlag(&FLAGS_fromenv, {}); - } - if (!absl::GetFlag(FLAGS_tryfromenv).empty()) { - absl::SetFlag(&FLAGS_tryfromenv, {}); - } - - absl::MutexLock l(&flags_internal::processing_checks_guard); - flags_internal::fromenv_needs_processing = false; - flags_internal::tryfromenv_needs_processing = false; -} - -// -------------------------------------------------------------------- - -// Returns: -// success status -// deduced value -// We are also mutating curr_list in case if we need to get a hold of next -// argument in the input. -std::tuple<bool, absl::string_view> DeduceFlagValue(const CommandLineFlag& flag, - absl::string_view value, - bool is_negative, - bool is_empty_value, - ArgsList* curr_list) { - // Value is either an argument suffix after `=` in "--foo=<value>" - // or separate argument in case of "--foo" "<value>". - - // boolean flags have these forms: - // --foo - // --nofoo - // --foo=true - // --foo=false - // --nofoo=<value> is not supported - // --foo <value> is not supported - - // non boolean flags have these forms: - // --foo=<value> - // --foo <value> - // --nofoo is not supported - - if (flag.IsOfType<bool>()) { - if (value.empty()) { - if (is_empty_value) { - // "--bool_flag=" case - flags_internal::ReportUsageError( - absl::StrCat( - "Missing the value after assignment for the boolean flag '", - flag.Name(), "'"), - true); - return std::make_tuple(false, ""); - } - - // "--bool_flag" case - value = is_negative ? "0" : "1"; - } else if (is_negative) { - // "--nobool_flag=Y" case - flags_internal::ReportUsageError( - absl::StrCat("Negative form with assignment is not valid for the " - "boolean flag '", - flag.Name(), "'"), - true); - return std::make_tuple(false, ""); - } - } else if (is_negative) { - // "--noint_flag=1" case - flags_internal::ReportUsageError( - absl::StrCat("Negative form is not valid for the flag '", flag.Name(), - "'"), - true); - return std::make_tuple(false, ""); - } else if (value.empty() && (!is_empty_value)) { - if (curr_list->Size() == 1) { - // "--int_flag" case - flags_internal::ReportUsageError( - absl::StrCat("Missing the value for the flag '", flag.Name(), "'"), - true); - return std::make_tuple(false, ""); - } - - // "--int_flag" "10" case - curr_list->PopFront(); - value = curr_list->Front(); - + } + + success &= ReadFlagfiles(flagfiles, input_args); + + flags_internal::flagfile_needs_processing = false; + } + + // Similar to flagfile fromenv/tryfromemv can be set both + // programmatically and at runtime on a command line. Unlike flagfile these + // can't be recursive. + if (flags_internal::fromenv_needs_processing) { + auto flags_list = absl::GetFlag(FLAGS_fromenv); + + success &= ReadFlagsFromEnv(flags_list, input_args, true); + + flags_internal::fromenv_needs_processing = false; + } + + if (flags_internal::tryfromenv_needs_processing) { + auto flags_list = absl::GetFlag(FLAGS_tryfromenv); + + success &= ReadFlagsFromEnv(flags_list, input_args, false); + + flags_internal::tryfromenv_needs_processing = false; + } + + return success; +} + +// -------------------------------------------------------------------- + +void ResetGeneratorFlags(const std::vector<std::string>& flagfile_value) { + // Setting flagfile to the value which collates all the values set on a + // command line and programmatically. So if command line looked like + // --flagfile=f1 --flagfile=f2 the final value of the FLAGS_flagfile flag is + // going to be {"f1", "f2"} + if (!flagfile_value.empty()) { + absl::SetFlag(&FLAGS_flagfile, flagfile_value); + absl::MutexLock l(&flags_internal::processing_checks_guard); + flags_internal::flagfile_needs_processing = false; + } + + // fromenv/tryfromenv are set to <undefined> value. + if (!absl::GetFlag(FLAGS_fromenv).empty()) { + absl::SetFlag(&FLAGS_fromenv, {}); + } + if (!absl::GetFlag(FLAGS_tryfromenv).empty()) { + absl::SetFlag(&FLAGS_tryfromenv, {}); + } + + absl::MutexLock l(&flags_internal::processing_checks_guard); + flags_internal::fromenv_needs_processing = false; + flags_internal::tryfromenv_needs_processing = false; +} + +// -------------------------------------------------------------------- + +// Returns: +// success status +// deduced value +// We are also mutating curr_list in case if we need to get a hold of next +// argument in the input. +std::tuple<bool, absl::string_view> DeduceFlagValue(const CommandLineFlag& flag, + absl::string_view value, + bool is_negative, + bool is_empty_value, + ArgsList* curr_list) { + // Value is either an argument suffix after `=` in "--foo=<value>" + // or separate argument in case of "--foo" "<value>". + + // boolean flags have these forms: + // --foo + // --nofoo + // --foo=true + // --foo=false + // --nofoo=<value> is not supported + // --foo <value> is not supported + + // non boolean flags have these forms: + // --foo=<value> + // --foo <value> + // --nofoo is not supported + + if (flag.IsOfType<bool>()) { + if (value.empty()) { + if (is_empty_value) { + // "--bool_flag=" case + flags_internal::ReportUsageError( + absl::StrCat( + "Missing the value after assignment for the boolean flag '", + flag.Name(), "'"), + true); + return std::make_tuple(false, ""); + } + + // "--bool_flag" case + value = is_negative ? "0" : "1"; + } else if (is_negative) { + // "--nobool_flag=Y" case + flags_internal::ReportUsageError( + absl::StrCat("Negative form with assignment is not valid for the " + "boolean flag '", + flag.Name(), "'"), + true); + return std::make_tuple(false, ""); + } + } else if (is_negative) { + // "--noint_flag=1" case + flags_internal::ReportUsageError( + absl::StrCat("Negative form is not valid for the flag '", flag.Name(), + "'"), + true); + return std::make_tuple(false, ""); + } else if (value.empty() && (!is_empty_value)) { + if (curr_list->Size() == 1) { + // "--int_flag" case + flags_internal::ReportUsageError( + absl::StrCat("Missing the value for the flag '", flag.Name(), "'"), + true); + return std::make_tuple(false, ""); + } + + // "--int_flag" "10" case + curr_list->PopFront(); + value = curr_list->Front(); + // Heuristic to detect the case where someone treats a string arg - // like a bool or just forgets to pass a value: - // --my_string_var --foo=bar + // like a bool or just forgets to pass a value: + // --my_string_var --foo=bar // We look for a flag of string type, whose value begins with a - // dash and corresponds to known flag or standalone --. + // dash and corresponds to known flag or standalone --. if (!value.empty() && value[0] == '-' && flag.IsOfType<std::string>()) { - auto maybe_flag_name = std::get<0>(SplitNameAndValue(value.substr(1))); - - if (maybe_flag_name.empty() || - std::get<0>(LocateFlag(maybe_flag_name)) != nullptr) { - // "--string_flag" "--known_flag" case - ABSL_INTERNAL_LOG( - WARNING, - absl::StrCat("Did you really mean to set flag '", flag.Name(), - "' to the value '", value, "'?")); - } - } - } - - return std::make_tuple(true, value); -} - -// -------------------------------------------------------------------- - -bool CanIgnoreUndefinedFlag(absl::string_view flag_name) { - auto undefok = absl::GetFlag(FLAGS_undefok); - if (std::find(undefok.begin(), undefok.end(), flag_name) != undefok.end()) { - return true; - } - - if (absl::ConsumePrefix(&flag_name, "no") && - std::find(undefok.begin(), undefok.end(), flag_name) != undefok.end()) { - return true; - } - - return false; -} - -} // namespace - -// -------------------------------------------------------------------- - + auto maybe_flag_name = std::get<0>(SplitNameAndValue(value.substr(1))); + + if (maybe_flag_name.empty() || + std::get<0>(LocateFlag(maybe_flag_name)) != nullptr) { + // "--string_flag" "--known_flag" case + ABSL_INTERNAL_LOG( + WARNING, + absl::StrCat("Did you really mean to set flag '", flag.Name(), + "' to the value '", value, "'?")); + } + } + } + + return std::make_tuple(true, value); +} + +// -------------------------------------------------------------------- + +bool CanIgnoreUndefinedFlag(absl::string_view flag_name) { + auto undefok = absl::GetFlag(FLAGS_undefok); + if (std::find(undefok.begin(), undefok.end(), flag_name) != undefok.end()) { + return true; + } + + if (absl::ConsumePrefix(&flag_name, "no") && + std::find(undefok.begin(), undefok.end(), flag_name) != undefok.end()) { + return true; + } + + return false; +} + +} // namespace + +// -------------------------------------------------------------------- + bool WasPresentOnCommandLine(absl::string_view flag_name) { absl::MutexLock l(&specified_flags_guard); ABSL_INTERNAL_CHECK(specified_flags != nullptr, @@ -605,41 +605,41 @@ bool WasPresentOnCommandLine(absl::string_view flag_name) { // -------------------------------------------------------------------- -std::vector<char*> ParseCommandLineImpl(int argc, char* argv[], - ArgvListAction arg_list_act, - UsageFlagsAction usage_flag_act, - OnUndefinedFlag on_undef_flag) { - ABSL_INTERNAL_CHECK(argc > 0, "Missing argv[0]"); - +std::vector<char*> ParseCommandLineImpl(int argc, char* argv[], + ArgvListAction arg_list_act, + UsageFlagsAction usage_flag_act, + OnUndefinedFlag on_undef_flag) { + ABSL_INTERNAL_CHECK(argc > 0, "Missing argv[0]"); + // Once parsing has started we will not have more flag registrations. // If we did, they would be missing during parsing, which is a problem on // itself. flags_internal::FinalizeRegistry(); - // This routine does not return anything since we abort on failure. - CheckDefaultValuesParsingRoundtrip(); - - std::vector<std::string> flagfile_value; - - std::vector<ArgsList> input_args; - input_args.push_back(ArgsList(argc, argv)); - - std::vector<char*> output_args; - std::vector<char*> positional_args; - output_args.reserve(argc); - - // This is the list of undefined flags. The element of the list is the pair - // consisting of boolean indicating if flag came from command line (vs from - // some flag file we've read) and flag name. - // TODO(rogeeff): Eliminate the first element in the pair after cleanup. - std::vector<std::pair<bool, std::string>> undefined_flag_names; - - // Set program invocation name if it is not set before. - if (ProgramInvocationName() == "UNKNOWN") { - flags_internal::SetProgramInvocationName(argv[0]); - } - output_args.push_back(argv[0]); - + // This routine does not return anything since we abort on failure. + CheckDefaultValuesParsingRoundtrip(); + + std::vector<std::string> flagfile_value; + + std::vector<ArgsList> input_args; + input_args.push_back(ArgsList(argc, argv)); + + std::vector<char*> output_args; + std::vector<char*> positional_args; + output_args.reserve(argc); + + // This is the list of undefined flags. The element of the list is the pair + // consisting of boolean indicating if flag came from command line (vs from + // some flag file we've read) and flag name. + // TODO(rogeeff): Eliminate the first element in the pair after cleanup. + std::vector<std::pair<bool, std::string>> undefined_flag_names; + + // Set program invocation name if it is not set before. + if (ProgramInvocationName() == "UNKNOWN") { + flags_internal::SetProgramInvocationName(argv[0]); + } + output_args.push_back(argv[0]); + absl::MutexLock l(&specified_flags_guard); if (specified_flags == nullptr) { specified_flags = new std::vector<const CommandLineFlag*>; @@ -647,177 +647,177 @@ std::vector<char*> ParseCommandLineImpl(int argc, char* argv[], specified_flags->clear(); } - // Iterate through the list of the input arguments. First level are arguments - // originated from argc/argv. Following levels are arguments originated from - // recursive parsing of flagfile(s). - bool success = true; - while (!input_args.empty()) { - // 10. First we process the built-in generator flags. + // Iterate through the list of the input arguments. First level are arguments + // originated from argc/argv. Following levels are arguments originated from + // recursive parsing of flagfile(s). + bool success = true; + while (!input_args.empty()) { + // 10. First we process the built-in generator flags. success &= HandleGeneratorFlags(input_args, flagfile_value); - - // 30. Select top-most (most recent) arguments list. If it is empty drop it - // and re-try. - ArgsList& curr_list = input_args.back(); - - curr_list.PopFront(); - - if (curr_list.Size() == 0) { - input_args.pop_back(); - continue; - } - - // 40. Pick up the front remaining argument in the current list. If current - // stack of argument lists contains only one element - we are processing an - // argument from the original argv. - absl::string_view arg(curr_list.Front()); - bool arg_from_argv = input_args.size() == 1; - - // 50. If argument does not start with - or is just "-" - this is - // positional argument. - if (!absl::ConsumePrefix(&arg, "-") || arg.empty()) { - ABSL_INTERNAL_CHECK(arg_from_argv, - "Flagfile cannot contain positional argument"); - - positional_args.push_back(argv[curr_list.FrontIndex()]); - continue; - } - - if (arg_from_argv && (arg_list_act == ArgvListAction::kKeepParsedArgs)) { - output_args.push_back(argv[curr_list.FrontIndex()]); - } - - // 60. Split the current argument on '=' to figure out the argument - // name and value. If flag name is empty it means we've got "--". value + + // 30. Select top-most (most recent) arguments list. If it is empty drop it + // and re-try. + ArgsList& curr_list = input_args.back(); + + curr_list.PopFront(); + + if (curr_list.Size() == 0) { + input_args.pop_back(); + continue; + } + + // 40. Pick up the front remaining argument in the current list. If current + // stack of argument lists contains only one element - we are processing an + // argument from the original argv. + absl::string_view arg(curr_list.Front()); + bool arg_from_argv = input_args.size() == 1; + + // 50. If argument does not start with - or is just "-" - this is + // positional argument. + if (!absl::ConsumePrefix(&arg, "-") || arg.empty()) { + ABSL_INTERNAL_CHECK(arg_from_argv, + "Flagfile cannot contain positional argument"); + + positional_args.push_back(argv[curr_list.FrontIndex()]); + continue; + } + + if (arg_from_argv && (arg_list_act == ArgvListAction::kKeepParsedArgs)) { + output_args.push_back(argv[curr_list.FrontIndex()]); + } + + // 60. Split the current argument on '=' to figure out the argument + // name and value. If flag name is empty it means we've got "--". value // can be empty either if there were no '=' in argument string at all or - // an argument looked like "--foo=". In a latter case is_empty_value is - // true. - absl::string_view flag_name; - absl::string_view value; - bool is_empty_value = false; - - std::tie(flag_name, value, is_empty_value) = SplitNameAndValue(arg); - - // 70. "--" alone means what it does for GNU: stop flags parsing. We do - // not support positional arguments in flagfiles, so we just drop them. - if (flag_name.empty()) { - ABSL_INTERNAL_CHECK(arg_from_argv, - "Flagfile cannot contain positional argument"); - - curr_list.PopFront(); - break; - } - - // 80. Locate the flag based on flag name. Handle both --foo and --nofoo - CommandLineFlag* flag = nullptr; - bool is_negative = false; - std::tie(flag, is_negative) = LocateFlag(flag_name); - - if (flag == nullptr) { + // an argument looked like "--foo=". In a latter case is_empty_value is + // true. + absl::string_view flag_name; + absl::string_view value; + bool is_empty_value = false; + + std::tie(flag_name, value, is_empty_value) = SplitNameAndValue(arg); + + // 70. "--" alone means what it does for GNU: stop flags parsing. We do + // not support positional arguments in flagfiles, so we just drop them. + if (flag_name.empty()) { + ABSL_INTERNAL_CHECK(arg_from_argv, + "Flagfile cannot contain positional argument"); + + curr_list.PopFront(); + break; + } + + // 80. Locate the flag based on flag name. Handle both --foo and --nofoo + CommandLineFlag* flag = nullptr; + bool is_negative = false; + std::tie(flag, is_negative) = LocateFlag(flag_name); + + if (flag == nullptr) { // Usage flags are not modeled as Abseil flags. Locate them separately. if (flags_internal::DeduceUsageFlags(flag_name, value)) { continue; } - if (on_undef_flag != OnUndefinedFlag::kIgnoreUndefined) { - undefined_flag_names.emplace_back(arg_from_argv, - std::string(flag_name)); - } - continue; - } - - // 90. Deduce flag's value (from this or next argument) - auto curr_index = curr_list.FrontIndex(); - bool value_success = true; - std::tie(value_success, value) = - DeduceFlagValue(*flag, value, is_negative, is_empty_value, &curr_list); - success &= value_success; - - // If above call consumed an argument, it was a standalone value - if (arg_from_argv && (arg_list_act == ArgvListAction::kKeepParsedArgs) && - (curr_index != curr_list.FrontIndex())) { - output_args.push_back(argv[curr_list.FrontIndex()]); - } - - // 100. Set the located flag to a new new value, unless it is retired. + if (on_undef_flag != OnUndefinedFlag::kIgnoreUndefined) { + undefined_flag_names.emplace_back(arg_from_argv, + std::string(flag_name)); + } + continue; + } + + // 90. Deduce flag's value (from this or next argument) + auto curr_index = curr_list.FrontIndex(); + bool value_success = true; + std::tie(value_success, value) = + DeduceFlagValue(*flag, value, is_negative, is_empty_value, &curr_list); + success &= value_success; + + // If above call consumed an argument, it was a standalone value + if (arg_from_argv && (arg_list_act == ArgvListAction::kKeepParsedArgs) && + (curr_index != curr_list.FrontIndex())) { + output_args.push_back(argv[curr_list.FrontIndex()]); + } + + // 100. Set the located flag to a new new value, unless it is retired. // Setting retired flag fails, but we ignoring it here while also reporting // access to retired flag. std::string error; if (!flags_internal::PrivateHandleAccessor::ParseFrom( *flag, value, SET_FLAGS_VALUE, kCommandLine, error)) { if (flag->IsRetired()) continue; - - flags_internal::ReportUsageError(error, true); - success = false; + + flags_internal::ReportUsageError(error, true); + success = false; } else { specified_flags->push_back(flag); - } - } - - for (const auto& flag_name : undefined_flag_names) { - if (CanIgnoreUndefinedFlag(flag_name.second)) continue; - - flags_internal::ReportUsageError( - absl::StrCat("Unknown command line flag '", flag_name.second, "'"), - true); - - success = false; - } - -#if ABSL_FLAGS_STRIP_NAMES - if (!success) { - flags_internal::ReportUsageError( - "NOTE: command line flags are disabled in this build", true); - } -#endif - - if (!success) { - flags_internal::HandleUsageFlags(std::cout, - ProgramUsageMessage()); - std::exit(1); - } - - if (usage_flag_act == UsageFlagsAction::kHandleUsage) { - int exit_code = flags_internal::HandleUsageFlags( - std::cout, ProgramUsageMessage()); - - if (exit_code != -1) { - std::exit(exit_code); - } - } - - ResetGeneratorFlags(flagfile_value); - - // Reinstate positional args which were intermixed with flags in the arguments - // list. - for (auto arg : positional_args) { - output_args.push_back(arg); - } - - // All the remaining arguments are positional. - if (!input_args.empty()) { - for (int arg_index = input_args.back().FrontIndex(); arg_index < argc; - ++arg_index) { - output_args.push_back(argv[arg_index]); - } - } - + } + } + + for (const auto& flag_name : undefined_flag_names) { + if (CanIgnoreUndefinedFlag(flag_name.second)) continue; + + flags_internal::ReportUsageError( + absl::StrCat("Unknown command line flag '", flag_name.second, "'"), + true); + + success = false; + } + +#if ABSL_FLAGS_STRIP_NAMES + if (!success) { + flags_internal::ReportUsageError( + "NOTE: command line flags are disabled in this build", true); + } +#endif + + if (!success) { + flags_internal::HandleUsageFlags(std::cout, + ProgramUsageMessage()); + std::exit(1); + } + + if (usage_flag_act == UsageFlagsAction::kHandleUsage) { + int exit_code = flags_internal::HandleUsageFlags( + std::cout, ProgramUsageMessage()); + + if (exit_code != -1) { + std::exit(exit_code); + } + } + + ResetGeneratorFlags(flagfile_value); + + // Reinstate positional args which were intermixed with flags in the arguments + // list. + for (auto arg : positional_args) { + output_args.push_back(arg); + } + + // All the remaining arguments are positional. + if (!input_args.empty()) { + for (int arg_index = input_args.back().FrontIndex(); arg_index < argc; + ++arg_index) { + output_args.push_back(argv[arg_index]); + } + } + // Trim and sort the vector. specified_flags->shrink_to_fit(); std::sort(specified_flags->begin(), specified_flags->end(), SpecifiedFlagsCompare{}); - return output_args; -} - -} // namespace flags_internal - -// -------------------------------------------------------------------- - -std::vector<char*> ParseCommandLine(int argc, char* argv[]) { - return flags_internal::ParseCommandLineImpl( - argc, argv, flags_internal::ArgvListAction::kRemoveParsedArgs, - flags_internal::UsageFlagsAction::kHandleUsage, - flags_internal::OnUndefinedFlag::kAbortIfUndefined); -} - + return output_args; +} + +} // namespace flags_internal + +// -------------------------------------------------------------------- + +std::vector<char*> ParseCommandLine(int argc, char* argv[]) { + return flags_internal::ParseCommandLineImpl( + argc, argv, flags_internal::ArgvListAction::kRemoveParsedArgs, + flags_internal::UsageFlagsAction::kHandleUsage, + flags_internal::OnUndefinedFlag::kAbortIfUndefined); +} + ABSL_NAMESPACE_END -} // namespace absl +} // namespace absl diff --git a/contrib/restricted/abseil-cpp/absl/flags/parse.h b/contrib/restricted/abseil-cpp/absl/flags/parse.h index e45b192d83..929de2cb40 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/parse.h +++ b/contrib/restricted/abseil-cpp/absl/flags/parse.h @@ -1,60 +1,60 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ----------------------------------------------------------------------------- -// File: parse.h -// ----------------------------------------------------------------------------- -// -// This file defines the main parsing function for Abseil flags: -// `absl::ParseCommandLine()`. - -#ifndef ABSL_FLAGS_PARSE_H_ -#define ABSL_FLAGS_PARSE_H_ - -#include <vector> - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ----------------------------------------------------------------------------- +// File: parse.h +// ----------------------------------------------------------------------------- +// +// This file defines the main parsing function for Abseil flags: +// `absl::ParseCommandLine()`. + +#ifndef ABSL_FLAGS_PARSE_H_ +#define ABSL_FLAGS_PARSE_H_ + +#include <vector> + #include "absl/base/config.h" -#include "absl/flags/internal/parse.h" - -namespace absl { +#include "absl/flags/internal/parse.h" + +namespace absl { ABSL_NAMESPACE_BEGIN - -// ParseCommandLine() -// -// Parses the set of command-line arguments passed in the `argc` (argument -// count) and `argv[]` (argument vector) parameters from `main()`, assigning -// values to any defined Abseil flags. (Any arguments passed after the -// flag-terminating delimiter (`--`) are treated as positional arguments and -// ignored.) -// -// Any command-line flags (and arguments to those flags) are parsed into Abseil -// Flag values, if those flags are defined. Any undefined flags will either -// return an error, or be ignored if that flag is designated using `undefok` to -// indicate "undefined is OK." -// -// Any command-line positional arguments not part of any command-line flag (or -// arguments to a flag) are returned in a vector, with the program invocation -// name at position 0 of that vector. (Note that this includes positional -// arguments after the flag-terminating delimiter `--`.) -// -// After all flags and flag arguments are parsed, this function looks for any -// built-in usage flags (e.g. `--help`), and if any were specified, it reports -// help messages and then exits the program. -std::vector<char*> ParseCommandLine(int argc, char* argv[]); - + +// ParseCommandLine() +// +// Parses the set of command-line arguments passed in the `argc` (argument +// count) and `argv[]` (argument vector) parameters from `main()`, assigning +// values to any defined Abseil flags. (Any arguments passed after the +// flag-terminating delimiter (`--`) are treated as positional arguments and +// ignored.) +// +// Any command-line flags (and arguments to those flags) are parsed into Abseil +// Flag values, if those flags are defined. Any undefined flags will either +// return an error, or be ignored if that flag is designated using `undefok` to +// indicate "undefined is OK." +// +// Any command-line positional arguments not part of any command-line flag (or +// arguments to a flag) are returned in a vector, with the program invocation +// name at position 0 of that vector. (Note that this includes positional +// arguments after the flag-terminating delimiter `--`.) +// +// After all flags and flag arguments are parsed, this function looks for any +// built-in usage flags (e.g. `--help`), and if any were specified, it reports +// help messages and then exits the program. +std::vector<char*> ParseCommandLine(int argc, char* argv[]); + ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_PARSE_H_ +} // namespace absl + +#endif // ABSL_FLAGS_PARSE_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/parse/ya.make b/contrib/restricted/abseil-cpp/absl/flags/parse/ya.make index 8300972cc3..267b3e4a97 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/parse/ya.make +++ b/contrib/restricted/abseil-cpp/absl/flags/parse/ya.make @@ -1,33 +1,33 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() -OWNER(g:cpp-contrib) - -LICENSE(Apache-2.0) - -PEERDIR( - contrib/restricted/abseil-cpp/absl/base - contrib/restricted/abseil-cpp/absl/base/internal/low_level_alloc - contrib/restricted/abseil-cpp/absl/base/internal/raw_logging - contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait - contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate - contrib/restricted/abseil-cpp/absl/base/log_severity +OWNER(g:cpp-contrib) + +LICENSE(Apache-2.0) + +PEERDIR( + contrib/restricted/abseil-cpp/absl/base + contrib/restricted/abseil-cpp/absl/base/internal/low_level_alloc + contrib/restricted/abseil-cpp/absl/base/internal/raw_logging + contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait + contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate + contrib/restricted/abseil-cpp/absl/base/log_severity contrib/restricted/abseil-cpp/absl/city contrib/restricted/abseil-cpp/absl/container/internal/absl_hashtablez_sampler contrib/restricted/abseil-cpp/absl/container/internal/raw_hash_set - contrib/restricted/abseil-cpp/absl/debugging - contrib/restricted/abseil-cpp/absl/debugging/stacktrace - contrib/restricted/abseil-cpp/absl/debugging/symbolize - contrib/restricted/abseil-cpp/absl/demangle + contrib/restricted/abseil-cpp/absl/debugging + contrib/restricted/abseil-cpp/absl/debugging/stacktrace + contrib/restricted/abseil-cpp/absl/debugging/symbolize + contrib/restricted/abseil-cpp/absl/demangle contrib/restricted/abseil-cpp/absl/flags contrib/restricted/abseil-cpp/absl/flags/commandlineflag contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag contrib/restricted/abseil-cpp/absl/flags/internal/flag contrib/restricted/abseil-cpp/absl/flags/internal/private_handle_accessor - contrib/restricted/abseil-cpp/absl/flags/internal/program_name + contrib/restricted/abseil-cpp/absl/flags/internal/program_name contrib/restricted/abseil-cpp/absl/flags/internal/usage contrib/restricted/abseil-cpp/absl/flags/marshalling contrib/restricted/abseil-cpp/absl/flags/reflection @@ -35,9 +35,9 @@ PEERDIR( contrib/restricted/abseil-cpp/absl/flags/usage_config contrib/restricted/abseil-cpp/absl/hash contrib/restricted/abseil-cpp/absl/hash/internal - contrib/restricted/abseil-cpp/absl/numeric + contrib/restricted/abseil-cpp/absl/numeric contrib/restricted/abseil-cpp/absl/profiling/internal/exponential_biased - contrib/restricted/abseil-cpp/absl/strings + contrib/restricted/abseil-cpp/absl/strings contrib/restricted/abseil-cpp/absl/strings/cord contrib/restricted/abseil-cpp/absl/strings/internal/absl_cord_internal contrib/restricted/abseil-cpp/absl/strings/internal/absl_strings_internal @@ -45,31 +45,31 @@ PEERDIR( contrib/restricted/abseil-cpp/absl/strings/internal/cordz_handle contrib/restricted/abseil-cpp/absl/strings/internal/cordz_info contrib/restricted/abseil-cpp/absl/strings/internal/str_format - contrib/restricted/abseil-cpp/absl/synchronization - contrib/restricted/abseil-cpp/absl/synchronization/internal - contrib/restricted/abseil-cpp/absl/time - contrib/restricted/abseil-cpp/absl/time/civil_time - contrib/restricted/abseil-cpp/absl/time/time_zone + contrib/restricted/abseil-cpp/absl/synchronization + contrib/restricted/abseil-cpp/absl/synchronization/internal + contrib/restricted/abseil-cpp/absl/time + contrib/restricted/abseil-cpp/absl/time/civil_time + contrib/restricted/abseil-cpp/absl/time/time_zone contrib/restricted/abseil-cpp/absl/types/bad_optional_access contrib/restricted/abseil-cpp/absl/types/bad_variant_access -) - -ADDINCL( - GLOBAL contrib/restricted/abseil-cpp -) - -NO_COMPILER_WARNINGS() - -NO_UTIL() - +) + +ADDINCL( + GLOBAL contrib/restricted/abseil-cpp +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + CFLAGS( -DNOMINMAX ) -SRCDIR(contrib/restricted/abseil-cpp/absl/flags) - -SRCS( +SRCDIR(contrib/restricted/abseil-cpp/absl/flags) + +SRCS( parse.cc -) - -END() +) + +END() diff --git a/contrib/restricted/abseil-cpp/absl/flags/usage.cc b/contrib/restricted/abseil-cpp/absl/flags/usage.cc index e47c26f1aa..452f667512 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/usage.cc +++ b/contrib/restricted/abseil-cpp/absl/flags/usage.cc @@ -1,65 +1,65 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#include "absl/flags/usage.h" - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "absl/flags/usage.h" + #include <stdlib.h> -#include <string> - +#include <string> + #include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/const_init.h" #include "absl/base/thread_annotations.h" -#include "absl/flags/internal/usage.h" +#include "absl/flags/internal/usage.h" #include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" - -namespace absl { +#include "absl/synchronization/mutex.h" + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { -namespace { -ABSL_CONST_INIT absl::Mutex usage_message_guard(absl::kConstInit); -ABSL_CONST_INIT std::string* program_usage_message - ABSL_GUARDED_BY(usage_message_guard) = nullptr; -} // namespace -} // namespace flags_internal - -// -------------------------------------------------------------------- -// Sets the "usage" message to be used by help reporting routines. -void SetProgramUsageMessage(absl::string_view new_usage_message) { - absl::MutexLock l(&flags_internal::usage_message_guard); - - if (flags_internal::program_usage_message != nullptr) { - ABSL_INTERNAL_LOG(FATAL, "SetProgramUsageMessage() called twice."); - std::exit(1); - } - - flags_internal::program_usage_message = new std::string(new_usage_message); -} - -// -------------------------------------------------------------------- -// Returns the usage message set by SetProgramUsageMessage(). -// Note: We able to return string_view here only because calling -// SetProgramUsageMessage twice is prohibited. -absl::string_view ProgramUsageMessage() { - absl::MutexLock l(&flags_internal::usage_message_guard); - - return flags_internal::program_usage_message != nullptr - ? absl::string_view(*flags_internal::program_usage_message) - : "Warning: SetProgramUsageMessage() never called"; -} - +namespace flags_internal { +namespace { +ABSL_CONST_INIT absl::Mutex usage_message_guard(absl::kConstInit); +ABSL_CONST_INIT std::string* program_usage_message + ABSL_GUARDED_BY(usage_message_guard) = nullptr; +} // namespace +} // namespace flags_internal + +// -------------------------------------------------------------------- +// Sets the "usage" message to be used by help reporting routines. +void SetProgramUsageMessage(absl::string_view new_usage_message) { + absl::MutexLock l(&flags_internal::usage_message_guard); + + if (flags_internal::program_usage_message != nullptr) { + ABSL_INTERNAL_LOG(FATAL, "SetProgramUsageMessage() called twice."); + std::exit(1); + } + + flags_internal::program_usage_message = new std::string(new_usage_message); +} + +// -------------------------------------------------------------------- +// Returns the usage message set by SetProgramUsageMessage(). +// Note: We able to return string_view here only because calling +// SetProgramUsageMessage twice is prohibited. +absl::string_view ProgramUsageMessage() { + absl::MutexLock l(&flags_internal::usage_message_guard); + + return flags_internal::program_usage_message != nullptr + ? absl::string_view(*flags_internal::program_usage_message) + : "Warning: SetProgramUsageMessage() never called"; +} + ABSL_NAMESPACE_END -} // namespace absl +} // namespace absl diff --git a/contrib/restricted/abseil-cpp/absl/flags/usage.h b/contrib/restricted/abseil-cpp/absl/flags/usage.h index 70678b7de2..ad12ab7ad9 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/usage.h +++ b/contrib/restricted/abseil-cpp/absl/flags/usage.h @@ -1,43 +1,43 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_FLAGS_USAGE_H_ -#define ABSL_FLAGS_USAGE_H_ - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ABSL_FLAGS_USAGE_H_ +#define ABSL_FLAGS_USAGE_H_ + #include "absl/base/config.h" -#include "absl/strings/string_view.h" - -// -------------------------------------------------------------------- -// Usage reporting interfaces - -namespace absl { +#include "absl/strings/string_view.h" + +// -------------------------------------------------------------------- +// Usage reporting interfaces + +namespace absl { ABSL_NAMESPACE_BEGIN - -// Sets the "usage" message to be used by help reporting routines. -// For example: -// absl::SetProgramUsageMessage( -// absl::StrCat("This program does nothing. Sample usage:\n", argv[0], -// " <uselessarg1> <uselessarg2>")); -// Do not include commandline flags in the usage: we do that for you! -// Note: Calling SetProgramUsageMessage twice will trigger a call to std::exit. -void SetProgramUsageMessage(absl::string_view new_usage_message); - -// Returns the usage message set by SetProgramUsageMessage(). -absl::string_view ProgramUsageMessage(); - + +// Sets the "usage" message to be used by help reporting routines. +// For example: +// absl::SetProgramUsageMessage( +// absl::StrCat("This program does nothing. Sample usage:\n", argv[0], +// " <uselessarg1> <uselessarg2>")); +// Do not include commandline flags in the usage: we do that for you! +// Note: Calling SetProgramUsageMessage twice will trigger a call to std::exit. +void SetProgramUsageMessage(absl::string_view new_usage_message); + +// Returns the usage message set by SetProgramUsageMessage(). +absl::string_view ProgramUsageMessage(); + ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_FLAGS_USAGE_H_ +} // namespace absl + +#endif // ABSL_FLAGS_USAGE_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/usage/ya.make b/contrib/restricted/abseil-cpp/absl/flags/usage/ya.make index 9f802b7458..f6b243c84c 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/usage/ya.make +++ b/contrib/restricted/abseil-cpp/absl/flags/usage/ya.make @@ -1,74 +1,74 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() -OWNER(g:cpp-contrib) - -LICENSE(Apache-2.0) - -PEERDIR( - contrib/restricted/abseil-cpp/absl/base - contrib/restricted/abseil-cpp/absl/base/internal/low_level_alloc - contrib/restricted/abseil-cpp/absl/base/internal/raw_logging - contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait - contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate - contrib/restricted/abseil-cpp/absl/base/log_severity +OWNER(g:cpp-contrib) + +LICENSE(Apache-2.0) + +PEERDIR( + contrib/restricted/abseil-cpp/absl/base + contrib/restricted/abseil-cpp/absl/base/internal/low_level_alloc + contrib/restricted/abseil-cpp/absl/base/internal/raw_logging + contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait + contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate + contrib/restricted/abseil-cpp/absl/base/log_severity contrib/restricted/abseil-cpp/absl/city contrib/restricted/abseil-cpp/absl/container/internal/absl_hashtablez_sampler contrib/restricted/abseil-cpp/absl/container/internal/raw_hash_set - contrib/restricted/abseil-cpp/absl/debugging - contrib/restricted/abseil-cpp/absl/debugging/stacktrace - contrib/restricted/abseil-cpp/absl/debugging/symbolize - contrib/restricted/abseil-cpp/absl/demangle - contrib/restricted/abseil-cpp/absl/flags + contrib/restricted/abseil-cpp/absl/debugging + contrib/restricted/abseil-cpp/absl/debugging/stacktrace + contrib/restricted/abseil-cpp/absl/debugging/symbolize + contrib/restricted/abseil-cpp/absl/demangle + contrib/restricted/abseil-cpp/absl/flags contrib/restricted/abseil-cpp/absl/flags/commandlineflag - contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag - contrib/restricted/abseil-cpp/absl/flags/internal/flag + contrib/restricted/abseil-cpp/absl/flags/internal/commandlineflag + contrib/restricted/abseil-cpp/absl/flags/internal/flag contrib/restricted/abseil-cpp/absl/flags/internal/private_handle_accessor - contrib/restricted/abseil-cpp/absl/flags/internal/program_name - contrib/restricted/abseil-cpp/absl/flags/internal/usage - contrib/restricted/abseil-cpp/absl/flags/marshalling + contrib/restricted/abseil-cpp/absl/flags/internal/program_name + contrib/restricted/abseil-cpp/absl/flags/internal/usage + contrib/restricted/abseil-cpp/absl/flags/marshalling contrib/restricted/abseil-cpp/absl/flags/reflection - contrib/restricted/abseil-cpp/absl/flags/usage_config + contrib/restricted/abseil-cpp/absl/flags/usage_config contrib/restricted/abseil-cpp/absl/hash contrib/restricted/abseil-cpp/absl/hash/internal - contrib/restricted/abseil-cpp/absl/numeric + contrib/restricted/abseil-cpp/absl/numeric contrib/restricted/abseil-cpp/absl/profiling/internal/exponential_biased - contrib/restricted/abseil-cpp/absl/strings + contrib/restricted/abseil-cpp/absl/strings contrib/restricted/abseil-cpp/absl/strings/cord contrib/restricted/abseil-cpp/absl/strings/internal/absl_cord_internal contrib/restricted/abseil-cpp/absl/strings/internal/absl_strings_internal contrib/restricted/abseil-cpp/absl/strings/internal/cordz_functions contrib/restricted/abseil-cpp/absl/strings/internal/cordz_handle contrib/restricted/abseil-cpp/absl/strings/internal/cordz_info - contrib/restricted/abseil-cpp/absl/strings/internal/str_format - contrib/restricted/abseil-cpp/absl/synchronization - contrib/restricted/abseil-cpp/absl/synchronization/internal - contrib/restricted/abseil-cpp/absl/time - contrib/restricted/abseil-cpp/absl/time/civil_time - contrib/restricted/abseil-cpp/absl/time/time_zone - contrib/restricted/abseil-cpp/absl/types/bad_optional_access + contrib/restricted/abseil-cpp/absl/strings/internal/str_format + contrib/restricted/abseil-cpp/absl/synchronization + contrib/restricted/abseil-cpp/absl/synchronization/internal + contrib/restricted/abseil-cpp/absl/time + contrib/restricted/abseil-cpp/absl/time/civil_time + contrib/restricted/abseil-cpp/absl/time/time_zone + contrib/restricted/abseil-cpp/absl/types/bad_optional_access contrib/restricted/abseil-cpp/absl/types/bad_variant_access -) - -ADDINCL( - GLOBAL contrib/restricted/abseil-cpp -) - -NO_COMPILER_WARNINGS() - -NO_UTIL() - +) + +ADDINCL( + GLOBAL contrib/restricted/abseil-cpp +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + CFLAGS( -DNOMINMAX ) -SRCDIR(contrib/restricted/abseil-cpp/absl/flags) - -SRCS( - usage.cc -) - -END() +SRCDIR(contrib/restricted/abseil-cpp/absl/flags) + +SRCS( + usage.cc +) + +END() diff --git a/contrib/restricted/abseil-cpp/absl/flags/usage_config.cc b/contrib/restricted/abseil-cpp/absl/flags/usage_config.cc index 4260277c25..5d7426db31 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/usage_config.cc +++ b/contrib/restricted/abseil-cpp/absl/flags/usage_config.cc @@ -1,165 +1,165 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/flags/usage_config.h" - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/flags/usage_config.h" + #include <functional> -#include <iostream> +#include <iostream> #include <string> - -#include "absl/base/attributes.h" + +#include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/const_init.h" #include "absl/base/thread_annotations.h" -#include "absl/flags/internal/path_util.h" -#include "absl/flags/internal/program_name.h" +#include "absl/flags/internal/path_util.h" +#include "absl/flags/internal/program_name.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" -#include "absl/strings/strip.h" -#include "absl/synchronization/mutex.h" - -extern "C" { - -// Additional report of fatal usage error message before we std::exit. Error is -// fatal if is_fatal argument to ReportUsageError is true. +#include "absl/strings/strip.h" +#include "absl/synchronization/mutex.h" + +extern "C" { + +// Additional report of fatal usage error message before we std::exit. Error is +// fatal if is_fatal argument to ReportUsageError is true. ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL( AbslInternalReportFatalUsageError)(absl::string_view) {} - -} // extern "C" - -namespace absl { + +} // extern "C" + +namespace absl { ABSL_NAMESPACE_BEGIN -namespace flags_internal { - -namespace { - -// -------------------------------------------------------------------- -// Returns true if flags defined in the filename should be reported with -// -helpshort flag. - -bool ContainsHelpshortFlags(absl::string_view filename) { - // By default we only want flags in binary's main. We expect the main - // routine to reside in <program>.cc or <program>-main.cc or +namespace flags_internal { + +namespace { + +// -------------------------------------------------------------------- +// Returns true if flags defined in the filename should be reported with +// -helpshort flag. + +bool ContainsHelpshortFlags(absl::string_view filename) { + // By default we only want flags in binary's main. We expect the main + // routine to reside in <program>.cc or <program>-main.cc or // <program>_main.cc, where the <program> is the name of the binary // (without .exe on Windows). - auto suffix = flags_internal::Basename(filename); + auto suffix = flags_internal::Basename(filename); auto program_name = flags_internal::ShortProgramInvocationName(); absl::string_view program_name_ref = program_name; #if defined(_WIN32) absl::ConsumeSuffix(&program_name_ref, ".exe"); #endif if (!absl::ConsumePrefix(&suffix, program_name_ref)) - return false; - return absl::StartsWith(suffix, ".") || absl::StartsWith(suffix, "-main.") || - absl::StartsWith(suffix, "_main."); -} - -// -------------------------------------------------------------------- -// Returns true if flags defined in the filename should be reported with -// -helppackage flag. - -bool ContainsHelppackageFlags(absl::string_view filename) { - // TODO(rogeeff): implement properly when registry is available. - return ContainsHelpshortFlags(filename); -} - -// -------------------------------------------------------------------- -// Generates program version information into supplied output. - -std::string VersionString() { - std::string version_str(flags_internal::ShortProgramInvocationName()); - - version_str += "\n"; - -#if !defined(NDEBUG) - version_str += "Debug build (NDEBUG not #defined)\n"; -#endif - - return version_str; -} - -// -------------------------------------------------------------------- -// Normalizes the filename specific to the build system/filesystem used. - -std::string NormalizeFilename(absl::string_view filename) { - // Skip any leading slashes - auto pos = filename.find_first_not_of("\\/"); - if (pos == absl::string_view::npos) return ""; - - filename.remove_prefix(pos); - return std::string(filename); -} - -// -------------------------------------------------------------------- - -ABSL_CONST_INIT absl::Mutex custom_usage_config_guard(absl::kConstInit); -ABSL_CONST_INIT FlagsUsageConfig* custom_usage_config - ABSL_GUARDED_BY(custom_usage_config_guard) = nullptr; - -} // namespace - -FlagsUsageConfig GetUsageConfig() { - absl::MutexLock l(&custom_usage_config_guard); - - if (custom_usage_config) return *custom_usage_config; - - FlagsUsageConfig default_config; - default_config.contains_helpshort_flags = &ContainsHelpshortFlags; - default_config.contains_help_flags = &ContainsHelppackageFlags; - default_config.contains_helppackage_flags = &ContainsHelppackageFlags; - default_config.version_string = &VersionString; - default_config.normalize_filename = &NormalizeFilename; - - return default_config; -} - -void ReportUsageError(absl::string_view msg, bool is_fatal) { - std::cerr << "ERROR: " << msg << std::endl; - - if (is_fatal) { + return false; + return absl::StartsWith(suffix, ".") || absl::StartsWith(suffix, "-main.") || + absl::StartsWith(suffix, "_main."); +} + +// -------------------------------------------------------------------- +// Returns true if flags defined in the filename should be reported with +// -helppackage flag. + +bool ContainsHelppackageFlags(absl::string_view filename) { + // TODO(rogeeff): implement properly when registry is available. + return ContainsHelpshortFlags(filename); +} + +// -------------------------------------------------------------------- +// Generates program version information into supplied output. + +std::string VersionString() { + std::string version_str(flags_internal::ShortProgramInvocationName()); + + version_str += "\n"; + +#if !defined(NDEBUG) + version_str += "Debug build (NDEBUG not #defined)\n"; +#endif + + return version_str; +} + +// -------------------------------------------------------------------- +// Normalizes the filename specific to the build system/filesystem used. + +std::string NormalizeFilename(absl::string_view filename) { + // Skip any leading slashes + auto pos = filename.find_first_not_of("\\/"); + if (pos == absl::string_view::npos) return ""; + + filename.remove_prefix(pos); + return std::string(filename); +} + +// -------------------------------------------------------------------- + +ABSL_CONST_INIT absl::Mutex custom_usage_config_guard(absl::kConstInit); +ABSL_CONST_INIT FlagsUsageConfig* custom_usage_config + ABSL_GUARDED_BY(custom_usage_config_guard) = nullptr; + +} // namespace + +FlagsUsageConfig GetUsageConfig() { + absl::MutexLock l(&custom_usage_config_guard); + + if (custom_usage_config) return *custom_usage_config; + + FlagsUsageConfig default_config; + default_config.contains_helpshort_flags = &ContainsHelpshortFlags; + default_config.contains_help_flags = &ContainsHelppackageFlags; + default_config.contains_helppackage_flags = &ContainsHelppackageFlags; + default_config.version_string = &VersionString; + default_config.normalize_filename = &NormalizeFilename; + + return default_config; +} + +void ReportUsageError(absl::string_view msg, bool is_fatal) { + std::cerr << "ERROR: " << msg << std::endl; + + if (is_fatal) { ABSL_INTERNAL_C_SYMBOL(AbslInternalReportFatalUsageError)(msg); - } -} - -} // namespace flags_internal - -void SetFlagsUsageConfig(FlagsUsageConfig usage_config) { - absl::MutexLock l(&flags_internal::custom_usage_config_guard); - - if (!usage_config.contains_helpshort_flags) - usage_config.contains_helpshort_flags = - flags_internal::ContainsHelpshortFlags; - - if (!usage_config.contains_help_flags) - usage_config.contains_help_flags = flags_internal::ContainsHelppackageFlags; - - if (!usage_config.contains_helppackage_flags) - usage_config.contains_helppackage_flags = - flags_internal::ContainsHelppackageFlags; - - if (!usage_config.version_string) - usage_config.version_string = flags_internal::VersionString; - - if (!usage_config.normalize_filename) - usage_config.normalize_filename = flags_internal::NormalizeFilename; - - if (flags_internal::custom_usage_config) - *flags_internal::custom_usage_config = usage_config; - else - flags_internal::custom_usage_config = new FlagsUsageConfig(usage_config); -} - + } +} + +} // namespace flags_internal + +void SetFlagsUsageConfig(FlagsUsageConfig usage_config) { + absl::MutexLock l(&flags_internal::custom_usage_config_guard); + + if (!usage_config.contains_helpshort_flags) + usage_config.contains_helpshort_flags = + flags_internal::ContainsHelpshortFlags; + + if (!usage_config.contains_help_flags) + usage_config.contains_help_flags = flags_internal::ContainsHelppackageFlags; + + if (!usage_config.contains_helppackage_flags) + usage_config.contains_helppackage_flags = + flags_internal::ContainsHelppackageFlags; + + if (!usage_config.version_string) + usage_config.version_string = flags_internal::VersionString; + + if (!usage_config.normalize_filename) + usage_config.normalize_filename = flags_internal::NormalizeFilename; + + if (flags_internal::custom_usage_config) + *flags_internal::custom_usage_config = usage_config; + else + flags_internal::custom_usage_config = new FlagsUsageConfig(usage_config); +} + ABSL_NAMESPACE_END -} // namespace absl +} // namespace absl diff --git a/contrib/restricted/abseil-cpp/absl/flags/usage_config.h b/contrib/restricted/abseil-cpp/absl/flags/usage_config.h index fec59be224..ded70300f0 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/usage_config.h +++ b/contrib/restricted/abseil-cpp/absl/flags/usage_config.h @@ -1,135 +1,135 @@ -// -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ----------------------------------------------------------------------------- -// File: usage_config.h -// ----------------------------------------------------------------------------- -// -// This file defines the main usage reporting configuration interfaces and -// documents Abseil's supported built-in usage flags. If these flags are found -// when parsing a command-line, Abseil will exit the program and display -// appropriate help messages. -#ifndef ABSL_FLAGS_USAGE_CONFIG_H_ -#define ABSL_FLAGS_USAGE_CONFIG_H_ - -#include <functional> -#include <string> - +// +// Copyright 2019 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ----------------------------------------------------------------------------- +// File: usage_config.h +// ----------------------------------------------------------------------------- +// +// This file defines the main usage reporting configuration interfaces and +// documents Abseil's supported built-in usage flags. If these flags are found +// when parsing a command-line, Abseil will exit the program and display +// appropriate help messages. +#ifndef ABSL_FLAGS_USAGE_CONFIG_H_ +#define ABSL_FLAGS_USAGE_CONFIG_H_ + +#include <functional> +#include <string> + #include "absl/base/config.h" -#include "absl/strings/string_view.h" - -// ----------------------------------------------------------------------------- -// Built-in Usage Flags -// ----------------------------------------------------------------------------- -// -// Abseil supports the following built-in usage flags. When passed, these flags -// exit the program and : -// -// * --help -// Shows help on important flags for this binary -// * --helpfull -// Shows help on all flags -// * --helpshort -// Shows help on only the main module for this program -// * --helppackage -// Shows help on all modules in the main package -// * --version -// Shows the version and build info for this binary and exits -// * --only_check_args -// Exits after checking all flags -// * --helpon -// Shows help on the modules named by this flag value -// * --helpmatch -// Shows help on modules whose name contains the specified substring - -namespace absl { +#include "absl/strings/string_view.h" + +// ----------------------------------------------------------------------------- +// Built-in Usage Flags +// ----------------------------------------------------------------------------- +// +// Abseil supports the following built-in usage flags. When passed, these flags +// exit the program and : +// +// * --help +// Shows help on important flags for this binary +// * --helpfull +// Shows help on all flags +// * --helpshort +// Shows help on only the main module for this program +// * --helppackage +// Shows help on all modules in the main package +// * --version +// Shows the version and build info for this binary and exits +// * --only_check_args +// Exits after checking all flags +// * --helpon +// Shows help on the modules named by this flag value +// * --helpmatch +// Shows help on modules whose name contains the specified substring + +namespace absl { ABSL_NAMESPACE_BEGIN - -namespace flags_internal { -using FlagKindFilter = std::function<bool (absl::string_view)>; -} // namespace flags_internal - -// FlagsUsageConfig -// -// This structure contains the collection of callbacks for changing the behavior -// of the usage reporting routines in Abseil Flags. -struct FlagsUsageConfig { - // Returns true if flags defined in the given source code file should be - // reported with --helpshort flag. For example, if the file - // "path/to/my/code.cc" defines the flag "--my_flag", and - // contains_helpshort_flags("path/to/my/code.cc") returns true, invoking the - // program with --helpshort will include information about --my_flag in the - // program output. - flags_internal::FlagKindFilter contains_helpshort_flags; - - // Returns true if flags defined in the filename should be reported with - // --help flag. For example, if the file - // "path/to/my/code.cc" defines the flag "--my_flag", and - // contains_help_flags("path/to/my/code.cc") returns true, invoking the - // program with --help will include information about --my_flag in the - // program output. - flags_internal::FlagKindFilter contains_help_flags; - - // Returns true if flags defined in the filename should be reported with - // --helppackage flag. For example, if the file - // "path/to/my/code.cc" defines the flag "--my_flag", and - // contains_helppackage_flags("path/to/my/code.cc") returns true, invoking the - // program with --helppackage will include information about --my_flag in the - // program output. - flags_internal::FlagKindFilter contains_helppackage_flags; - + +namespace flags_internal { +using FlagKindFilter = std::function<bool (absl::string_view)>; +} // namespace flags_internal + +// FlagsUsageConfig +// +// This structure contains the collection of callbacks for changing the behavior +// of the usage reporting routines in Abseil Flags. +struct FlagsUsageConfig { + // Returns true if flags defined in the given source code file should be + // reported with --helpshort flag. For example, if the file + // "path/to/my/code.cc" defines the flag "--my_flag", and + // contains_helpshort_flags("path/to/my/code.cc") returns true, invoking the + // program with --helpshort will include information about --my_flag in the + // program output. + flags_internal::FlagKindFilter contains_helpshort_flags; + + // Returns true if flags defined in the filename should be reported with + // --help flag. For example, if the file + // "path/to/my/code.cc" defines the flag "--my_flag", and + // contains_help_flags("path/to/my/code.cc") returns true, invoking the + // program with --help will include information about --my_flag in the + // program output. + flags_internal::FlagKindFilter contains_help_flags; + + // Returns true if flags defined in the filename should be reported with + // --helppackage flag. For example, if the file + // "path/to/my/code.cc" defines the flag "--my_flag", and + // contains_helppackage_flags("path/to/my/code.cc") returns true, invoking the + // program with --helppackage will include information about --my_flag in the + // program output. + flags_internal::FlagKindFilter contains_helppackage_flags; + // Generates string containing program version. This is the string reported - // when user specifies --version in a command line. - std::function<std::string()> version_string; - - // Normalizes the filename specific to the build system/filesystem used. This - // routine is used when we report the information about the flag definition - // location. For instance, if your build resides at some location you do not - // want to expose in the usage output, you can trim it to show only relevant - // part. - // For example: - // normalize_filename("/my_company/some_long_path/src/project/file.cc") - // might produce - // "project/file.cc". - std::function<std::string(absl::string_view)> normalize_filename; -}; - -// SetFlagsUsageConfig() -// -// Sets the usage reporting configuration callbacks. If any of the callbacks are -// not set in usage_config instance, then the default value of the callback is -// used. -void SetFlagsUsageConfig(FlagsUsageConfig usage_config); - -namespace flags_internal { - -FlagsUsageConfig GetUsageConfig(); - -void ReportUsageError(absl::string_view msg, bool is_fatal); - -} // namespace flags_internal + // when user specifies --version in a command line. + std::function<std::string()> version_string; + + // Normalizes the filename specific to the build system/filesystem used. This + // routine is used when we report the information about the flag definition + // location. For instance, if your build resides at some location you do not + // want to expose in the usage output, you can trim it to show only relevant + // part. + // For example: + // normalize_filename("/my_company/some_long_path/src/project/file.cc") + // might produce + // "project/file.cc". + std::function<std::string(absl::string_view)> normalize_filename; +}; + +// SetFlagsUsageConfig() +// +// Sets the usage reporting configuration callbacks. If any of the callbacks are +// not set in usage_config instance, then the default value of the callback is +// used. +void SetFlagsUsageConfig(FlagsUsageConfig usage_config); + +namespace flags_internal { + +FlagsUsageConfig GetUsageConfig(); + +void ReportUsageError(absl::string_view msg, bool is_fatal); + +} // namespace flags_internal ABSL_NAMESPACE_END -} // namespace absl - -extern "C" { - -// Additional report of fatal usage error message before we std::exit. Error is -// fatal if is_fatal argument to ReportUsageError is true. +} // namespace absl + +extern "C" { + +// Additional report of fatal usage error message before we std::exit. Error is +// fatal if is_fatal argument to ReportUsageError is true. void ABSL_INTERNAL_C_SYMBOL(AbslInternalReportFatalUsageError)( absl::string_view); - -} // extern "C" - -#endif // ABSL_FLAGS_USAGE_CONFIG_H_ + +} // extern "C" + +#endif // ABSL_FLAGS_USAGE_CONFIG_H_ diff --git a/contrib/restricted/abseil-cpp/absl/flags/usage_config/ya.make b/contrib/restricted/abseil-cpp/absl/flags/usage_config/ya.make index 280ffdd8e7..adeb527aee 100644 --- a/contrib/restricted/abseil-cpp/absl/flags/usage_config/ya.make +++ b/contrib/restricted/abseil-cpp/absl/flags/usage_config/ya.make @@ -1,26 +1,26 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() -OWNER(g:cpp-contrib) - -LICENSE(Apache-2.0) - -PEERDIR( - contrib/restricted/abseil-cpp/absl/base +OWNER(g:cpp-contrib) + +LICENSE(Apache-2.0) + +PEERDIR( + contrib/restricted/abseil-cpp/absl/base contrib/restricted/abseil-cpp/absl/base/internal/low_level_alloc - contrib/restricted/abseil-cpp/absl/base/internal/raw_logging - contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait - contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate - contrib/restricted/abseil-cpp/absl/base/log_severity + contrib/restricted/abseil-cpp/absl/base/internal/raw_logging + contrib/restricted/abseil-cpp/absl/base/internal/spinlock_wait + contrib/restricted/abseil-cpp/absl/base/internal/throw_delegate + contrib/restricted/abseil-cpp/absl/base/log_severity contrib/restricted/abseil-cpp/absl/debugging contrib/restricted/abseil-cpp/absl/debugging/stacktrace contrib/restricted/abseil-cpp/absl/debugging/symbolize contrib/restricted/abseil-cpp/absl/demangle contrib/restricted/abseil-cpp/absl/flags/internal/program_name - contrib/restricted/abseil-cpp/absl/numeric + contrib/restricted/abseil-cpp/absl/numeric contrib/restricted/abseil-cpp/absl/strings contrib/restricted/abseil-cpp/absl/strings/internal/absl_strings_internal contrib/restricted/abseil-cpp/absl/synchronization @@ -28,24 +28,24 @@ PEERDIR( contrib/restricted/abseil-cpp/absl/time contrib/restricted/abseil-cpp/absl/time/civil_time contrib/restricted/abseil-cpp/absl/time/time_zone -) - -ADDINCL( - GLOBAL contrib/restricted/abseil-cpp -) - -NO_COMPILER_WARNINGS() - -NO_UTIL() - +) + +ADDINCL( + GLOBAL contrib/restricted/abseil-cpp +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + CFLAGS( -DNOMINMAX ) SRCDIR(contrib/restricted/abseil-cpp/absl/flags) -SRCS( +SRCS( usage_config.cc -) - -END() +) + +END() |