From fc73e10620500af37ef8d5260dbdebc1647aae30 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 25 Aug 2016 08:50:07 -0700 Subject: [PATCH] ArgList -> format_args --- fmt/format.cc | 26 +++++++++--------- fmt/format.h | 50 +++++++++++++++++------------------ fmt/ostream.cc | 2 +- fmt/ostream.h | 2 +- fmt/posix.h | 2 +- fmt/printf.h | 16 +++++------ test/custom-formatter-test.cc | 4 +-- test/format-test.cc | 4 +-- test/macro-test.cc | 4 +-- test/ostream-test.cc | 2 +- test/util-test.cc | 6 ++--- 11 files changed, 59 insertions(+), 59 deletions(-) diff --git a/fmt/format.cc b/fmt/format.cc index 7fd0308e..8b175bbf 100644 --- a/fmt/format.cc +++ b/fmt/format.cc @@ -223,7 +223,7 @@ FMT_FUNC void format_system_error( } // namespace internal FMT_FUNC void SystemError::init( - int err_code, CStringRef format_str, ArgList args) { + int err_code, CStringRef format_str, format_args args) { error_code_ = err_code; MemoryWriter w; format_system_error(w, err_code, format(format_str, args)); @@ -347,7 +347,7 @@ FMT_FUNC int internal::UTF16ToUTF8::convert(WStringRef s) { } FMT_FUNC void WindowsError::init( - int err_code, CStringRef format_str, ArgList args) { + int err_code, CStringRef format_str, format_args args) { error_code_ = err_code; MemoryWriter w; internal::format_windows_error(w, err_code, format(format_str, args)); @@ -404,13 +404,13 @@ FMT_FUNC void format_system_error( } template -void internal::ArgMap::init(const ArgList &args) { +void internal::ArgMap::init(const format_args &args) { if (!map_.empty()) return; typedef internal::NamedArg NamedArg; const NamedArg *named_arg = 0; bool use_values = - args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE; + args.type(format_args::MAX_PACKED_ARGS - 1) == internal::Arg::NONE; if (use_values) { for (unsigned i = 0;/*nothing*/; ++i) { internal::Arg::Type arg_type = args.type(i); @@ -427,14 +427,14 @@ void internal::ArgMap::init(const ArgList &args) { } return; } - for (unsigned i = 0; i != ArgList::MAX_PACKED_ARGS; ++i) { + for (unsigned i = 0; i != format_args::MAX_PACKED_ARGS; ++i) { internal::Arg::Type arg_type = args.type(i); if (arg_type == internal::Arg::NAMED_ARG) { named_arg = static_cast(args.args_[i].pointer); map_.push_back(Pair(named_arg->name, *named_arg)); } } - for (unsigned i = ArgList::MAX_PACKED_ARGS;/*nothing*/; ++i) { + for (unsigned i = format_args::MAX_PACKED_ARGS;/*nothing*/; ++i) { switch (args.args_[i].type) { case internal::Arg::NONE: return; @@ -483,17 +483,17 @@ FMT_FUNC void report_windows_error( } #endif -FMT_FUNC void print(std::FILE *f, CStringRef format_str, ArgList args) { +FMT_FUNC void print(std::FILE *f, CStringRef format_str, format_args args) { MemoryWriter w; w.write(format_str, args); std::fwrite(w.data(), 1, w.size(), f); } -FMT_FUNC void print(CStringRef format_str, ArgList args) { +FMT_FUNC void print(CStringRef format_str, format_args args) { print(stdout, format_str, args); } -FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) { +FMT_FUNC void print_colored(Color c, CStringRef format, format_args args) { char escape[] = "\x1b[30m"; escape[3] = static_cast('0' + c); std::fputs(escape, stdout); @@ -502,9 +502,9 @@ FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) { } template -void printf(BasicWriter &w, BasicCStringRef format, ArgList args); +void printf(BasicWriter &w, BasicCStringRef format, format_args args); -FMT_FUNC int fprintf(std::FILE *f, CStringRef format, ArgList args) { +FMT_FUNC int fprintf(std::FILE *f, CStringRef format, format_args args) { MemoryWriter w; printf(w, format, args); std::size_t size = w.size(); @@ -519,7 +519,7 @@ template struct internal::BasicData; template void internal::FixedBuffer::grow(std::size_t); -template void internal::ArgMap::init(const ArgList &args); +template void internal::ArgMap::init(const format_args &args); template void PrintfFormatter::format(CStringRef format); @@ -535,7 +535,7 @@ template int internal::CharTraits::format_float( template void internal::FixedBuffer::grow(std::size_t); -template void internal::ArgMap::init(const ArgList &args); +template void internal::ArgMap::init(const format_args &args); template void PrintfFormatter::format(WCStringRef format); diff --git a/fmt/format.h b/fmt/format.h index 6f96e84c..7ca1de9b 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -1351,8 +1351,8 @@ template class ArgMap; } // namespace internal -/** An argument list. */ -class ArgList { +/** Formatting arguments. */ +class format_args { private: // To reduce compiled code size per formatting function call, types of first // MAX_PACKED_ARGS arguments are passed in the types_ field. @@ -1381,11 +1381,11 @@ class ArgList { // Maximum number of arguments with packed types. enum { MAX_PACKED_ARGS = 16 }; - ArgList() : types_(0) {} + format_args() : types_(0) {} - ArgList(ULongLong types, const internal::Value *values) + format_args(ULongLong types, const internal::Value *values) : types_(types), values_(values) {} - ArgList(ULongLong types, const internal::Arg *args) + format_args(ULongLong types, const internal::Arg *args) : types_(types), args_(args) {} /** Returns the argument at specified index. */ @@ -1809,7 +1809,7 @@ class ArgMap { MapType map_; public: - FMT_API void init(const ArgList &args); + FMT_API void init(const format_args &args); const internal::Arg* find(const fmt::BasicStringRef &name) const { // The list is unsorted, so just return the first matching name. @@ -1922,16 +1922,16 @@ class ArgFormatterBase : public ArgVisitor { class FormatterBase { private: - ArgList args_; + format_args args_; int next_arg_index_; // Returns the argument with specified index. FMT_API Arg do_get_arg(unsigned arg_index, const char *&error); protected: - const ArgList &args() const { return args_; } + const format_args &args() const { return args_; } - explicit FormatterBase(const ArgList &args) { + explicit FormatterBase(const format_args &args) { args_ = args; next_arg_index_ = 0; } @@ -2053,7 +2053,7 @@ class BasicFormatter : private internal::FormatterBase { appropriate lifetimes. \endrst */ - BasicFormatter(const ArgList &args, BasicWriter &w) + BasicFormatter(const format_args &args, BasicWriter &w) : internal::FormatterBase(args), writer_(w) {} /** Returns a reference to the writer associated with this formatter. */ @@ -2093,7 +2093,7 @@ inline uint64_t make_type(const T &arg) { return MakeValue< BasicFormatter >::type(arg); } -template +template struct ArgArray; template @@ -2143,7 +2143,7 @@ inline uint64_t make_type(const Arg &first, const Args & ... tail) { typedef fmt::internal::ArgArray ArgArray; \ typename ArgArray::Type array{ \ ArgArray::template make >(args)...}; \ - func(arg0, fmt::ArgList(fmt::internal::make_type(args...), array)); \ + func(arg0, fmt::format_args(fmt::internal::make_type(args...), array)); \ } // Defines a variadic constructor. @@ -2153,7 +2153,7 @@ inline uint64_t make_type(const Arg &first, const Args & ... tail) { typedef fmt::internal::ArgArray ArgArray; \ typename ArgArray::Type array{ \ ArgArray::template make >(args)...}; \ - func(arg0, arg1, fmt::ArgList(fmt::internal::make_type(args...), array)); \ + func(arg0, arg1, fmt::format_args(fmt::internal::make_type(args...), array)); \ } // Generates a comma-separated list with results of applying f to pairs @@ -2184,7 +2184,7 @@ inline uint64_t make_type(const Arg &first, const Args & ... tail) { */ class SystemError : public internal::RuntimeError { private: - void init(int err_code, CStringRef format_str, ArgList args); + void init(int err_code, CStringRef format_str, format_args args); protected: int error_code_; @@ -2213,7 +2213,7 @@ class SystemError : public internal::RuntimeError { \endrst */ SystemError(int error_code, CStringRef message) { - init(error_code, message, ArgList()); + init(error_code, message, format_args()); } FMT_VARIADIC_CTOR(SystemError, init, int, CStringRef) @@ -2433,7 +2433,7 @@ class BasicWriter { See also :ref:`syntax`. \endrst */ - void write(BasicCStringRef format, ArgList args) { + void write(BasicCStringRef format, format_args args) { BasicFormatter(args, *this).format(format); } FMT_VARIADIC_VOID(write, BasicCStringRef) @@ -3030,7 +3030,7 @@ FMT_API void report_system_error(int error_code, /** A Windows error. */ class WindowsError : public SystemError { private: - FMT_API void init(int error_code, CStringRef format_str, ArgList args); + FMT_API void init(int error_code, CStringRef format_str, format_args args); public: /** @@ -3062,7 +3062,7 @@ class WindowsError : public SystemError { \endrst */ WindowsError(int error_code, CStringRef message) { - init(error_code, message, ArgList()); + init(error_code, message, format_args()); } FMT_VARIADIC_CTOR(WindowsError, init, int, CStringRef) }; @@ -3082,7 +3082,7 @@ enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }; Example: print_colored(fmt::RED, "Elapsed time: {0:.2f} seconds", 1.23); */ -FMT_API void print_colored(Color c, CStringRef format, ArgList args); +FMT_API void print_colored(Color c, CStringRef format, format_args args); /** \rst @@ -3093,13 +3093,13 @@ FMT_API void print_colored(Color c, CStringRef format, ArgList args); std::string message = format("The answer is {}", 42); \endrst */ -inline std::string format(CStringRef format_str, ArgList args) { +inline std::string format(CStringRef format_str, format_args args) { MemoryWriter w; w.write(format_str, args); return w.str(); } -inline std::wstring format(WCStringRef format_str, ArgList args) { +inline std::wstring format(WCStringRef format_str, format_args args) { WMemoryWriter w; w.write(format_str, args); return w.str(); @@ -3114,7 +3114,7 @@ inline std::wstring format(WCStringRef format_str, ArgList args) { print(stderr, "Don't {}!", "panic"); \endrst */ -FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args); +FMT_API void print(std::FILE *f, CStringRef format_str, format_args args); /** \rst @@ -3125,7 +3125,7 @@ FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args); print("Elapsed time: {0:.2f} seconds", 1.23); \endrst */ -FMT_API void print(CStringRef format_str, ArgList args); +FMT_API void print(CStringRef format_str, format_args args); /** Fast integer formatter. @@ -3294,7 +3294,7 @@ void arg(WStringRef, const internal::NamedArg&) FMT_DELETED_OR_UNDEFINED; typename ArgArray::Type array{ \ ArgArray::template make >(args)...}; \ call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \ - fmt::ArgList(fmt::internal::make_type(args...), array)); \ + fmt::format_args(fmt::internal::make_type(args...), array)); \ } /** @@ -3305,7 +3305,7 @@ void arg(WStringRef, const internal::NamedArg&) FMT_DELETED_OR_UNDEFINED; **Example**:: void print_error(const char *file, int line, const char *format, - fmt::ArgList args) { + fmt::format_args args) { fmt::print("{}: {}: ", file, line); fmt::print(format, args); } diff --git a/fmt/ostream.cc b/fmt/ostream.cc index 2890b4a8..92b00a09 100644 --- a/fmt/ostream.cc +++ b/fmt/ostream.cc @@ -27,7 +27,7 @@ FMT_FUNC void write(std::ostream &os, Writer &w) { } } -FMT_FUNC void print(std::ostream &os, CStringRef format_str, ArgList args) { +FMT_FUNC void print(std::ostream &os, CStringRef format_str, format_args args) { MemoryWriter w; w.write(format_str, args); internal::write(os, w); diff --git a/fmt/ostream.h b/fmt/ostream.h index e21b2f6d..db433ea0 100644 --- a/fmt/ostream.h +++ b/fmt/ostream.h @@ -95,7 +95,7 @@ void format_arg(BasicFormatter &f, print(cerr, "Don't {}!", "panic"); \endrst */ -FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args); +FMT_API void print(std::ostream &os, CStringRef format_str, format_args args); FMT_VARIADIC(void, print, std::ostream &, CStringRef) } // namespace fmt diff --git a/fmt/posix.h b/fmt/posix.h index 7c2b0b5e..e6b2e900 100644 --- a/fmt/posix.h +++ b/fmt/posix.h @@ -166,7 +166,7 @@ public: // of MinGW that define fileno as a macro. int (fileno)() const; - void print(CStringRef format_str, const ArgList &args) { + void print(CStringRef format_str, const format_args &args) { fmt::print(file_, format_str, args); } FMT_VARIADIC(void, print, CStringRef) diff --git a/fmt/printf.h b/fmt/printf.h index e83a9976..9be2c424 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -262,7 +262,7 @@ class BasicPrintfArgFormatter : public internal::ArgFormatterBase { /** Formats an argument of a custom (user-defined) type. */ void visit_custom(internal::Arg::CustomValue c) { - BasicFormatter formatter(ArgList(), this->writer()); + BasicFormatter formatter(format_args(), this->writer()); const Char format_str[] = {'}', 0}; const Char *format = format_str; c.format(&formatter, c.value, &format); @@ -304,7 +304,7 @@ class PrintfFormatter : private internal::FormatterBase { appropriate lifetimes. \endrst */ - explicit PrintfFormatter(const ArgList &args, BasicWriter &w) + explicit PrintfFormatter(const format_args &args, BasicWriter &w) : FormatterBase(args), writer_(w) {} /** Formats stored arguments and writes the output to the writer. */ @@ -484,7 +484,7 @@ void PrintfFormatter::format(BasicCStringRef format_str) { } template -void printf(BasicWriter &w, BasicCStringRef format, ArgList args) { +void printf(BasicWriter &w, BasicCStringRef format, format_args args) { PrintfFormatter(args, w).format(format); } @@ -497,14 +497,14 @@ void printf(BasicWriter &w, BasicCStringRef format, ArgList args) { std::string message = fmt::sprintf("The answer is %d", 42); \endrst */ -inline std::string sprintf(CStringRef format, ArgList args) { +inline std::string sprintf(CStringRef format, format_args args) { MemoryWriter w; printf(w, format, args); return w.str(); } FMT_VARIADIC(std::string, sprintf, CStringRef) -inline std::wstring sprintf(WCStringRef format, ArgList args) { +inline std::wstring sprintf(WCStringRef format, format_args args) { WMemoryWriter w; printf(w, format, args); return w.str(); @@ -520,7 +520,7 @@ FMT_VARIADIC_W(std::wstring, sprintf, WCStringRef) fmt::fprintf(stderr, "Don't %s!", "panic"); \endrst */ -FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args); +FMT_API int fprintf(std::FILE *f, CStringRef format, format_args args); FMT_VARIADIC(int, fprintf, std::FILE *, CStringRef) /** @@ -532,7 +532,7 @@ FMT_VARIADIC(int, fprintf, std::FILE *, CStringRef) fmt::printf("Elapsed time: %.2f seconds", 1.23); \endrst */ -inline int printf(CStringRef format, ArgList args) { +inline int printf(CStringRef format, format_args args) { return fprintf(stdout, format, args); } FMT_VARIADIC(int, printf, CStringRef) @@ -546,7 +546,7 @@ FMT_VARIADIC(int, printf, CStringRef) fprintf(cerr, "Don't %s!", "panic"); \endrst */ -inline int fprintf(std::ostream &os, CStringRef format_str, ArgList args) { +inline int fprintf(std::ostream &os, CStringRef format_str, format_args args) { MemoryWriter w; printf(w, format_str, args); internal::write(os, w); diff --git a/test/custom-formatter-test.cc b/test/custom-formatter-test.cc index cc9c4485..436986c1 100644 --- a/test/custom-formatter-test.cc +++ b/test/custom-formatter-test.cc @@ -45,7 +45,7 @@ class CustomPrintfArgFormatter : } }; -std::string custom_format(const char *format_str, fmt::ArgList args) { +std::string custom_format(const char *format_str, fmt::format_args args) { fmt::MemoryWriter writer; // Pass custom argument formatter as a template arg to BasicFormatter. fmt::BasicFormatter formatter(args, writer); @@ -54,7 +54,7 @@ std::string custom_format(const char *format_str, fmt::ArgList args) { } FMT_VARIADIC(std::string, custom_format, const char *) -std::string custom_sprintf(const char* format_str, fmt::ArgList args){ +std::string custom_sprintf(const char* format_str, fmt::format_args args){ fmt::MemoryWriter writer; fmt::PrintfFormatter formatter(args, writer); formatter.format(format_str); diff --git a/test/format-test.cc b/test/format-test.cc index a92d875f..e18d136e 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1564,7 +1564,7 @@ TEST(StrTest, Convert) { } std::string format_message(int id, const char *format, - const fmt::ArgList &args) { + const fmt::format_args &args) { MemoryWriter w; w.write("[{}] ", id); w.write(format, args); @@ -1643,7 +1643,7 @@ class MockArgFormatter : MOCK_METHOD1(visit_int, void (int value)); }; -void custom_format(const char *format_str, fmt::ArgList args) { +void custom_format(const char *format_str, fmt::format_args args) { fmt::MemoryWriter writer; fmt::BasicFormatter formatter(args, writer); formatter.format(format_str); diff --git a/test/macro-test.cc b/test/macro-test.cc index ea2fbfd6..ed35151b 100644 --- a/test/macro-test.cc +++ b/test/macro-test.cc @@ -67,7 +67,7 @@ TEST(UtilTest, NArg) { int result; #define MAKE_TEST(func) \ - void func(const char *, const fmt::ArgList &args) { \ + void func(const char *, const fmt::format_args &args) { \ result = 0; \ for (unsigned i = 0; args[i].type; ++i) \ result += args[i].int_value; \ @@ -91,7 +91,7 @@ struct S {}; #define GET_TYPE(n) S -int test_variadic(FMT_GEN(10, GET_TYPE), const fmt::ArgList &args) { \ +int test_variadic(FMT_GEN(10, GET_TYPE), const fmt::format_args &args) { \ int result = 0; \ for (unsigned i = 0; args[i].type; ++i) \ result += args[i].int_value; \ diff --git a/test/ostream-test.cc b/test/ostream-test.cc index fa2c40d6..9542a28c 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -67,7 +67,7 @@ struct TestArgFormatter : fmt::BasicArgFormatter { TEST(OStreamTest, CustomArg) { fmt::MemoryWriter writer; typedef fmt::BasicFormatter Formatter; - Formatter formatter(fmt::ArgList(), writer); + Formatter formatter(fmt::format_args(), writer); fmt::FormatSpec spec; TestArgFormatter af(formatter, spec, "}"); af.visit(fmt::internal::MakeArg(TestEnum())); diff --git a/test/util-test.cc b/test/util-test.cc index d67dd52c..376ea128 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -566,14 +566,14 @@ TEST(ArgTest, MakeArg) { EXPECT_EQ(fmt::internal::Arg::CUSTOM, arg.type); EXPECT_EQ(&t, arg.custom.value); fmt::MemoryWriter w; - fmt::BasicFormatter formatter(fmt::ArgList(), w); + fmt::BasicFormatter formatter(fmt::format_args(), w); const char *s = "}"; arg.custom.format(&formatter, &t, &s); EXPECT_EQ("test", w.str()); } -TEST(UtilTest, ArgList) { - fmt::ArgList args; +TEST(UtilTest, FormatArgs) { + fmt::format_args args; EXPECT_EQ(Arg::NONE, args[1].type); }