Convert typedef to using.
Remove unused char_traits.h
There should be no behavior change.
Change-Id: I6085c03f5140e46c6f1f2d1c2974cdacfa532133
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/6080
Reviewed-by: Scott Graham <scottmg@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/base/strings/char_traits.h b/base/strings/char_traits.h
deleted file mode 100644
index c432849..0000000
--- a/base/strings/char_traits.h
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_STRINGS_CHAR_TRAITS_H_
-#define BASE_STRINGS_CHAR_TRAITS_H_
-
-#include <stddef.h>
-
-#include "base/compiler_specific.h"
-
-namespace base {
-
-// constexpr version of http://en.cppreference.com/w/cpp/string/char_traits.
-// This currently just implements the bits needed to support a (mostly)
-// constexpr std::string_view.
-//
-// TODO(dcheng): Once we switch to C++17, most methods will become constexpr and
-// we can switch over to using the one in the standard library.
-template <typename T>
-struct CharTraits {
- // Performs a lexographical comparison of the first N characters of |s1| and
- // |s2|. Returns 0 if equal, -1 if |s1| is less than |s2|, and 1 if |s1| is
- // greater than |s2|.
- static constexpr int compare(const T* s1, const T* s2, size_t n) noexcept;
-
- // Returns the length of |s|, assuming null termination (and not including the
- // terminating null).
- static constexpr size_t length(const T* s) noexcept;
-};
-
-template <typename T>
-constexpr int CharTraits<T>::compare(const T* s1,
- const T* s2,
- size_t n) noexcept {
- for (; n; --n, ++s1, ++s2) {
- if (*s1 < *s2)
- return -1;
- if (*s1 > *s2)
- return 1;
- }
- return 0;
-}
-
-template <typename T>
-constexpr size_t CharTraits<T>::length(const T* s) noexcept {
- size_t i = 0;
- for (; *s; ++s)
- ++i;
- return i;
-}
-
-// char specialization of CharTraits that can use clang's constexpr instrinsics,
-// where available.
-template <>
-struct CharTraits<char> {
- static constexpr int compare(const char* s1,
- const char* s2,
- size_t n) noexcept;
- static constexpr size_t length(const char* s) noexcept;
-};
-
-constexpr int CharTraits<char>::compare(const char* s1,
- const char* s2,
- size_t n) noexcept {
-#if HAS_FEATURE(cxx_constexpr_string_builtins)
- return __builtin_memcmp(s1, s2, n);
-#else
- for (; n; --n, ++s1, ++s2) {
- if (*s1 < *s2)
- return -1;
- if (*s1 > *s2)
- return 1;
- }
- return 0;
-#endif
-}
-
-constexpr size_t CharTraits<char>::length(const char* s) noexcept {
-#if defined(__clang__)
- return __builtin_strlen(s);
-#else
- size_t i = 0;
- for (; *s; ++s)
- ++i;
- return i;
-#endif
-}
-
-} // namespace base
-
-#endif // BASE_STRINGS_CHAR_TRAITS_H_
diff --git a/tools/gn/build_settings.h b/tools/gn/build_settings.h
index 646472f..40049d9 100644
--- a/tools/gn/build_settings.h
+++ b/tools/gn/build_settings.h
@@ -25,8 +25,8 @@
// may be multiple Settings objects that refer to this, one for each toolchain.
class BuildSettings {
public:
- typedef base::Callback<void(std::unique_ptr<Item>)> ItemDefinedCallback;
- typedef base::Callback<void(const std::string&)> PrintCallback;
+ using ItemDefinedCallback = base::Callback<void(std::unique_ptr<Item>)>;
+ using PrintCallback = base::Callback<void(const std::string&)>;
BuildSettings();
BuildSettings(const BuildSettings& other);
diff --git a/tools/gn/builder.cc b/tools/gn/builder.cc
index fc271c4..bbdb182 100644
--- a/tools/gn/builder.cc
+++ b/tools/gn/builder.cc
@@ -20,7 +20,7 @@
namespace {
-typedef BuilderRecord::BuilderRecordSet BuilderRecordSet;
+using BuilderRecordSet = BuilderRecord::BuilderRecordSet;
// Recursively looks in the tree for a given node, returning true if it
// was found in the dependecy graph. This is used to see if a given node
diff --git a/tools/gn/builder.h b/tools/gn/builder.h
index 973ee6a..62f4f96 100644
--- a/tools/gn/builder.h
+++ b/tools/gn/builder.h
@@ -24,7 +24,7 @@
// the main thread only. See also BuilderRecord.
class Builder {
public:
- typedef base::Callback<void(const BuilderRecord*)> ResolvedGeneratedCallback;
+ using ResolvedGeneratedCallback = base::Callback<void(const BuilderRecord*)>;
explicit Builder(Loader* loader);
~Builder();
diff --git a/tools/gn/builder_record.h b/tools/gn/builder_record.h
index 9dcc366..adf07be 100644
--- a/tools/gn/builder_record.h
+++ b/tools/gn/builder_record.h
@@ -29,7 +29,7 @@
// the current build (should_generate is false).
class BuilderRecord {
public:
- typedef std::set<BuilderRecord*> BuilderRecordSet;
+ using BuilderRecordSet = std::set<BuilderRecord*>;
enum ItemType {
ITEM_UNKNOWN,
diff --git a/tools/gn/command_path.cc b/tools/gn/command_path.cc
index 503ba6d..14b1796 100644
--- a/tools/gn/command_path.cc
+++ b/tools/gn/command_path.cc
@@ -41,7 +41,7 @@
bool with_data;
};
-typedef std::list<PathVector> WorkQueue;
+using WorkQueue = std::list<PathVector>;
struct Stats {
Stats() : public_paths(0), other_paths(0) {}
diff --git a/tools/gn/command_refs.cc b/tools/gn/command_refs.cc
index 6364d81..8854652 100644
--- a/tools/gn/command_refs.cc
+++ b/tools/gn/command_refs.cc
@@ -26,11 +26,11 @@
namespace {
-typedef std::set<const Target*> TargetSet;
-typedef std::vector<const Target*> TargetVector;
+using TargetSet = std::set<const Target*>;
+using TargetVector = std::vector<const Target*>;
// Maps targets to the list of targets that depend on them.
-typedef std::multimap<const Target*, const Target*> DepMap;
+using DepMap = std::multimap<const Target*, const Target*>;
// Populates the reverse dependency map for the targets in the Setup.
void FillDepMap(Setup* setup, DepMap* dep_map) {
diff --git a/tools/gn/commands.h b/tools/gn/commands.h
index f57f740..db38a2c 100644
--- a/tools/gn/commands.h
+++ b/tools/gn/commands.h
@@ -27,7 +27,7 @@
namespace commands {
-typedef int (*CommandRunner)(const std::vector<std::string>&);
+using CommandRunner = int (*)(const std::vector<std::string>&);
extern const char kAnalyze[];
extern const char kAnalyze_HelpShort[];
@@ -102,7 +102,7 @@
CommandRunner runner;
};
-typedef std::map<std::string_view, CommandInfo> CommandInfoMap;
+using CommandInfoMap = std::map<std::string_view, CommandInfo>;
const CommandInfoMap& GetCommands();
diff --git a/tools/gn/desc_builder.cc b/tools/gn/desc_builder.cc
index 6ede896..2c079a0 100644
--- a/tools/gn/desc_builder.cc
+++ b/tools/gn/desc_builder.cc
@@ -106,7 +106,7 @@
// Common functionality for target and config description builder
class BaseDescBuilder {
public:
- typedef std::unique_ptr<base::Value> ValuePtr;
+ using ValuePtr = std::unique_ptr<base::Value>;
BaseDescBuilder(const std::set<std::string>& what,
bool all,
diff --git a/tools/gn/functions.h b/tools/gn/functions.h
index 4119571..8149db7 100644
--- a/tools/gn/functions.h
+++ b/tools/gn/functions.h
@@ -26,31 +26,31 @@
// This type of function invocation has no block and evaluates its arguments
// itself rather than taking a pre-executed list. This allows us to implement
// certain built-in functions.
-typedef Value (*SelfEvaluatingArgsFunction)(Scope* scope,
- const FunctionCallNode* function,
- const ListNode* args_list,
- Err* err);
+using SelfEvaluatingArgsFunction = Value (*)(Scope* scope,
+ const FunctionCallNode* function,
+ const ListNode* args_list,
+ Err* err);
// This type of function invocation takes a block node that it will execute.
-typedef Value (*GenericBlockFunction)(Scope* scope,
- const FunctionCallNode* function,
- const std::vector<Value>& args,
- BlockNode* block,
- Err* err);
+using GenericBlockFunction = Value (*)(Scope* scope,
+ const FunctionCallNode* function,
+ const std::vector<Value>& args,
+ BlockNode* block,
+ Err* err);
// This type of function takes a block, but does not need to control execution
// of it. The dispatch function will pre-execute the block and pass the
// resulting block_scope to the function.
-typedef Value (*ExecutedBlockFunction)(const FunctionCallNode* function,
- const std::vector<Value>& args,
- Scope* block_scope,
- Err* err);
+using ExecutedBlockFunction = Value (*)(const FunctionCallNode* function,
+ const std::vector<Value>& args,
+ Scope* block_scope,
+ Err* err);
// This type of function does not take a block. It just has arguments.
-typedef Value (*NoBlockFunction)(Scope* scope,
- const FunctionCallNode* function,
- const std::vector<Value>& args,
- Err* err);
+using NoBlockFunction = Value (*)(Scope* scope,
+ const FunctionCallNode* function,
+ const std::vector<Value>& args,
+ Err* err);
extern const char kAction[];
extern const char kAction_HelpShort[];
@@ -432,7 +432,7 @@
bool is_target;
};
-typedef std::map<std::string_view, FunctionInfo> FunctionInfoMap;
+using FunctionInfoMap = std::map<std::string_view, FunctionInfo>;
// Returns the mapping of all built-in functions.
const FunctionInfoMap& GetFunctions();
diff --git a/tools/gn/header_checker.h b/tools/gn/header_checker.h
index 8e73c19..786edcb 100644
--- a/tools/gn/header_checker.h
+++ b/tools/gn/header_checker.h
@@ -46,7 +46,7 @@
return target == other.target && is_public == other.is_public;
}
};
- typedef std::vector<ChainLink> Chain;
+ using Chain = std::vector<ChainLink>;
// check_generated, if true, will also check generated
// files. Something that can only be done after running a build that
@@ -94,10 +94,10 @@
bool is_generated;
};
- typedef std::vector<TargetInfo> TargetVector;
- typedef std::map<SourceFile, TargetVector> FileMap;
- typedef base::RepeatingCallback<bool(const base::FilePath& path)>
- PathExistsCallback;
+ using TargetVector = std::vector<TargetInfo>;
+ using FileMap = std::map<SourceFile, TargetVector>;
+ using PathExistsCallback =
+ base::RepeatingCallback<bool(const base::FilePath& path)>;
// Backend for Run() that takes the list of files to check. The errors_ list
// will be populate on failure.
diff --git a/tools/gn/import_manager.h b/tools/gn/import_manager.h
index d72d5a7..e033183 100644
--- a/tools/gn/import_manager.h
+++ b/tools/gn/import_manager.h
@@ -43,7 +43,7 @@
std::mutex imports_lock_;
// Owning pointers to the scopes.
- typedef std::map<SourceFile, std::unique_ptr<ImportInfo>> ImportMap;
+ using ImportMap = std::map<SourceFile, std::unique_ptr<ImportInfo>>;
ImportMap imports_;
std::unordered_set<std::string> imports_in_progress_;
diff --git a/tools/gn/inherited_libraries.h b/tools/gn/inherited_libraries.h
index e8568b2..71d02f4 100644
--- a/tools/gn/inherited_libraries.h
+++ b/tools/gn/inherited_libraries.h
@@ -62,7 +62,7 @@
bool is_public;
};
- typedef std::map<const Target*, Node> LibraryMap;
+ using LibraryMap = std::map<const Target*, Node>;
LibraryMap map_;
DISALLOW_COPY_AND_ASSIGN(InheritedLibraries);
diff --git a/tools/gn/label_ptr.h b/tools/gn/label_ptr.h
index ac994f5..d51ef16 100644
--- a/tools/gn/label_ptr.h
+++ b/tools/gn/label_ptr.h
@@ -22,7 +22,7 @@
// location of the thing that added this dependency.
template <typename T>
struct LabelPtrPair {
- typedef T DestType;
+ using DestType = T;
LabelPtrPair() = default;
@@ -43,11 +43,11 @@
const ParseNode* origin = nullptr;
};
-typedef LabelPtrPair<Config> LabelConfigPair;
-typedef LabelPtrPair<Target> LabelTargetPair;
+using LabelConfigPair = LabelPtrPair<Config>;
+using LabelTargetPair = LabelPtrPair<Target>;
-typedef std::vector<LabelConfigPair> LabelConfigVector;
-typedef std::vector<LabelTargetPair> LabelTargetVector;
+using LabelConfigVector = std::vector<LabelConfigPair>;
+using LabelTargetVector = std::vector<LabelTargetPair>;
// Default comparison operators -----------------------------------------------
//
diff --git a/tools/gn/loader.h b/tools/gn/loader.h
index 71b22b8..06737c3 100644
--- a/tools/gn/loader.h
+++ b/tools/gn/loader.h
@@ -71,12 +71,12 @@
class LoaderImpl : public Loader {
public:
// Callback to emulate InputFileManager::AsyncLoadFile.
- typedef base::Callback<bool(const LocationRange&,
- const BuildSettings*,
- const SourceFile&,
- const base::Callback<void(const ParseNode*)>&,
- Err*)>
- AsyncLoadFileCallback;
+ using AsyncLoadFileCallback =
+ base::Callback<bool(const LocationRange&,
+ const BuildSettings*,
+ const SourceFile&,
+ const base::Callback<void(const ParseNode*)>&,
+ Err*)>;
explicit LoaderImpl(const BuildSettings* build_settings);
@@ -164,14 +164,14 @@
// mocking purposes.
AsyncLoadFileCallback async_load_file_;
- typedef std::set<LoadID> LoadIDSet;
+ using LoadIDSet = std::set<LoadID>;
LoadIDSet invocations_;
const BuildSettings* build_settings_;
Label default_toolchain_label_;
// Records for the build config file loads.
- typedef std::map<Label, std::unique_ptr<ToolchainRecord>> ToolchainRecordMap;
+ using ToolchainRecordMap = std::map<Label, std::unique_ptr<ToolchainRecord>>;
ToolchainRecordMap toolchain_records_;
};
diff --git a/tools/gn/loader_unittest.cc b/tools/gn/loader_unittest.cc
index dc8b0df..83a2389 100644
--- a/tools/gn/loader_unittest.cc
+++ b/tools/gn/loader_unittest.cc
@@ -52,7 +52,7 @@
class MockInputFileManager {
public:
- typedef base::Callback<void(const ParseNode*)> Callback;
+ using Callback = base::Callback<void(const ParseNode*)>;
MockInputFileManager() = default;
@@ -84,7 +84,7 @@
return true;
}
- typedef std::map<SourceFile, std::unique_ptr<CannedResult>> CannedResponseMap;
+ using CannedResponseMap = std::map<SourceFile, std::unique_ptr<CannedResult>>;
CannedResponseMap canned_responses_;
std::vector<std::pair<SourceFile, Callback>> pending_;
diff --git a/tools/gn/ninja_c_binary_target_writer.h b/tools/gn/ninja_c_binary_target_writer.h
index 8dacf8e..445198f 100644
--- a/tools/gn/ninja_c_binary_target_writer.h
+++ b/tools/gn/ninja_c_binary_target_writer.h
@@ -28,7 +28,7 @@
UniqueVector<OutputFile>* obj_files) const override;
private:
- typedef std::set<OutputFile> OutputFileSet;
+ using OutputFileSet = std::set<OutputFile>;
// Writes all flags for the compiler: includes, defines, cflags, etc.
void WriteCompilerVars();
diff --git a/tools/gn/parser.h b/tools/gn/parser.h
index a537170..de1a082 100644
--- a/tools/gn/parser.h
+++ b/tools/gn/parser.h
@@ -137,9 +137,9 @@
DISALLOW_COPY_AND_ASSIGN(Parser);
};
-typedef std::unique_ptr<ParseNode> (Parser::*PrefixFunc)(const Token& token);
-typedef std::unique_ptr<ParseNode> (
- Parser::*InfixFunc)(std::unique_ptr<ParseNode> left, const Token& token);
+using PrefixFunc = std::unique_ptr<ParseNode> (Parser::*)(const Token& token);
+using InfixFunc = std::unique_ptr<ParseNode> (
+ Parser::*)(std::unique_ptr<ParseNode> left, const Token& token);
struct ParserHelper {
PrefixFunc prefix;
@@ -151,7 +151,8 @@
// Renders parse subtree as a formatted text, indenting by the given number of
// spaces.
-void RenderToText(const base::Value& node, int indent_level,
- std::ostringstream& os);
+void RenderToText(const base::Value& node,
+ int indent_level,
+ std::ostringstream& os);
#endif // TOOLS_GN_PARSER_H_
diff --git a/tools/gn/scope.h b/tools/gn/scope.h
index 962f5c3..397669b 100644
--- a/tools/gn/scope.h
+++ b/tools/gn/scope.h
@@ -366,7 +366,7 @@
// Note that this can't use string pieces since the names are constructed from
// Values which might be deallocated before this goes out of scope.
- typedef std::unordered_map<std::string, std::unique_ptr<Scope>> NamedScopeMap;
+ using NamedScopeMap = std::unordered_map<std::string, std::unique_ptr<Scope>>;
NamedScopeMap target_defaults_;
// Null indicates not set and that we should fallback to the containing
@@ -374,16 +374,16 @@
std::unique_ptr<PatternList> sources_assignment_filter_;
// Owning pointers, must be deleted.
- typedef std::map<std::string, scoped_refptr<const Template>> TemplateMap;
+ using TemplateMap = std::map<std::string, scoped_refptr<const Template>>;
TemplateMap templates_;
ItemVector* item_collector_;
// Opaque pointers. See SetProperty() above.
- typedef std::map<const void*, void*> PropertyMap;
+ using PropertyMap = std::map<const void*, void*>;
PropertyMap properties_;
- typedef std::set<ProgrammaticProvider*> ProviderSet;
+ using ProviderSet = std::set<ProgrammaticProvider*>;
ProviderSet programmatic_providers_;
SourceDir source_dir_;
diff --git a/tools/gn/switches.h b/tools/gn/switches.h
index 9f0ddf0..900104a 100644
--- a/tools/gn/switches.h
+++ b/tools/gn/switches.h
@@ -18,7 +18,7 @@
const char* long_help;
};
-typedef std::map<std::string_view, SwitchInfo> SwitchInfoMap;
+using SwitchInfoMap = std::map<std::string_view, SwitchInfo>;
// Returns the mapping of all global switches.
const SwitchInfoMap& GetSwitches();
diff --git a/tools/gn/target.cc b/tools/gn/target.cc
index 27dce25..8a5b989 100644
--- a/tools/gn/target.cc
+++ b/tools/gn/target.cc
@@ -23,7 +23,7 @@
namespace {
-typedef std::set<const Config*> ConfigSet;
+using ConfigSet = std::set<const Config*>;
// Merges the public configs from the given target to the given config list.
void MergePublicConfigsFrom(const Target* from_target,
diff --git a/tools/gn/target.h b/tools/gn/target.h
index 549b354..abd1b44 100644
--- a/tools/gn/target.h
+++ b/tools/gn/target.h
@@ -56,8 +56,8 @@
DEPS_LINKED, // Iterates through all non-data dependencies.
};
- typedef std::vector<SourceFile> FileList;
- typedef std::vector<std::string> StringVector;
+ using FileList = std::vector<SourceFile>;
+ using StringVector = std::vector<std::string>;
// We track the set of build files that may affect this target, please refer
// to Scope for how this is determined.
diff --git a/tools/gn/unique_vector.h b/tools/gn/unique_vector.h
index ec8bb27..3ebf182 100644
--- a/tools/gn/unique_vector.h
+++ b/tools/gn/unique_vector.h
@@ -91,9 +91,9 @@
template <typename T>
class UniqueVector {
public:
- typedef std::vector<T> Vector;
- typedef typename Vector::iterator iterator;
- typedef typename Vector::const_iterator const_iterator;
+ using Vector = std::vector<T>;
+ using iterator = typename Vector::iterator;
+ using const_iterator = typename Vector::const_iterator;
const Vector& vector() const { return vector_; }
size_t size() const { return vector_.size(); }
@@ -153,8 +153,8 @@
}
private:
- typedef internal::UniquifyRef<T> Ref;
- typedef std::unordered_set<Ref> HashSet;
+ using Ref = internal::UniquifyRef<T>;
+ using HashSet = std::unordered_set<Ref>;
HashSet set_;
Vector vector_;
diff --git a/tools/gn/variables.h b/tools/gn/variables.h
index 60769d4..0de220d 100644
--- a/tools/gn/variables.h
+++ b/tools/gn/variables.h
@@ -336,7 +336,7 @@
const char* help;
};
-typedef std::map<std::string_view, VariableInfo> VariableInfoMap;
+using VariableInfoMap = std::map<std::string_view, VariableInfo>;
// Returns the built-in readonly variables.
// Note: this is used only for help so this getter is not threadsafe.