From 9f7972a08b8f6e933e7dbb53c60e0436ad1ade98 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 29 Dec 2019 14:25:42 -0800 Subject: [PATCH] clang-format C++ files --- src/builtin_read.cpp | 11 +++-- src/builtin_set.cpp | 3 +- src/complete.cpp | 8 ++-- src/io.h | 1 - src/parse_execution.cpp | 3 +- src/parser_keywords.cpp | 5 +-- src/timer.cpp | 97 ++++++++++++++++++++++------------------- src/timer.h | 11 ++--- src/tnode.h | 3 +- src/topic_monitor.cpp | 3 +- 10 files changed, 76 insertions(+), 69 deletions(-) diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 052678143..c3880cac7 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -2,6 +2,7 @@ #include "config.h" // IWYU pragma: keep #include "builtin_read.h" + #include #include @@ -403,16 +404,14 @@ static int validate_read_args(const wchar_t *cmd, read_cmd_opts_t &opts, int arg } if (opts.tokenize && opts.have_delimiter) { - streams.err.append_format( - BUILTIN_ERR_COMBO2, cmd, - L"--delimiter and --tokenize can not be used together"); + streams.err.append_format(BUILTIN_ERR_COMBO2, cmd, + L"--delimiter and --tokenize can not be used together"); return STATUS_INVALID_ARGS; } if (opts.tokenize && opts.one_line) { - streams.err.append_format( - BUILTIN_ERR_COMBO2, cmd, - L"--line and --tokenize can not be used together"); + streams.err.append_format(BUILTIN_ERR_COMBO2, cmd, + L"--line and --tokenize can not be used together"); return STATUS_INVALID_ARGS; } diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index c21c886d8..1c2631038 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -483,7 +483,8 @@ static int builtin_set_list(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, if (!names_only) { wcstring val; if (opts.shorten_ok && key == L"history") { - history_t *history = &history_t::history_with_name(history_session_id(env_stack_t::principal())); + history_t *history = + &history_t::history_with_name(history_session_id(env_stack_t::principal())); for (size_t i = 1; i < history->size() && val.size() < 64; i++) { if (i > 1) val += L' '; val += expand_escape_string(history->item_at_index(i).str()); diff --git a/src/complete.cpp b/src/complete.cpp index 7a7c3dbc1..2b0056905 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -39,9 +39,9 @@ #include "history.h" #include "iothread.h" #include "parse_constants.h" -#include "parser_keywords.h" #include "parse_util.h" #include "parser.h" +#include "parser_keywords.h" #include "path.h" #include "proc.h" #include "reader.h" @@ -1193,9 +1193,11 @@ bool completer_t::complete_variable(const wcstring &str, size_t start_offset) { wcstring desc; if (this->wants_descriptions()) { if (this->type() != COMPLETE_AUTOSUGGEST) { - // $history can be huge, don't put all of it in the completion description; see #6288. + // $history can be huge, don't put all of it in the completion description; see + // #6288. if (env_name == L"history") { - history_t *history = &history_t::history_with_name(history_session_id(env_stack_t::principal())); + history_t *history = + &history_t::history_with_name(history_session_id(env_stack_t::principal())); for (size_t i = 1; i < history->size() && desc.size() < 64; i++) { if (i > 1) desc += L' '; desc += expand_escape_string(history->item_at_index(i).str()); diff --git a/src/io.h b/src/io.h index c43b70896..b5dd366cb 100644 --- a/src/io.h +++ b/src/io.h @@ -457,5 +457,4 @@ struct io_streams_t { explicit io_streams_t(size_t read_limit) : out(read_limit), err(read_limit), stdin_fd(-1) {} }; - #endif diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index c292e7208..8654b6bd1 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -1356,7 +1356,8 @@ eval_result_t parse_execution_context_t::run_job_conjunction( if (continuation) { // Check the conjunction type. parse_job_decoration_t conj = bool_statement_type(continuation); - assert((conj == parse_job_decoration_and || conj == parse_job_decoration_or) && "Unexpected conjunction"); + assert((conj == parse_job_decoration_and || conj == parse_job_decoration_or) && + "Unexpected conjunction"); skip = should_skip(conj); } if (!skip) { diff --git a/src/parser_keywords.cpp b/src/parser_keywords.cpp index aae7b91b2..6f4fe1eff 100644 --- a/src/parser_keywords.cpp +++ b/src/parser_keywords.cpp @@ -16,9 +16,8 @@ static const wcstring skip_keywords[]{ L"begin", }; -static const wcstring subcommand_keywords[]{L"command", L"builtin", L"while", L"exec", - L"if", L"and", L"or", L"not", - L"time", L"begin"}; +static const wcstring subcommand_keywords[]{L"command", L"builtin", L"while", L"exec", L"if", + L"and", L"or", L"not", L"time", L"begin"}; static const string_set_t block_keywords = {L"for", L"while", L"if", L"function", L"switch", L"begin"}; diff --git a/src/timer.cpp b/src/timer.cpp index 08b7deb02..d4289a766 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -1,25 +1,26 @@ // Functions for executing the time builtin. #include "config.h" // IWYU pragma: keep +#include "timer.h" + +#include + +#include #include -#include #include #include +#include -#include "common.h" #include "builtin.h" +#include "common.h" #include "exec.h" #include "fallback.h" // IWYU pragma: keep #include "io.h" #include "parser.h" #include "proc.h" -#include "timer.h" #include "wgetopt.h" #include "wutil.h" // IWYU pragma: keep -#include -#include - // Measuring time is always complicated with many caveats. Quite apart from the typical // gotchas faced by developers attempting to choose between monotonic vs non-monotonic and system vs // cpu clocks, the fact that we are executing as a shell further complicates matters: we can't just @@ -60,7 +61,6 @@ static int64_t micros(const std::chrono::duration &d) { return std::chrono::duration_cast(d).count(); }; - timer_snapshot_t timer_snapshot_t::take() { timer_snapshot_t snapshot; @@ -71,8 +71,8 @@ timer_snapshot_t timer_snapshot_t::take() { return snapshot; } -wcstring -timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool verbose /* = true */) { +wcstring timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, + bool verbose /* = true */) { int64_t fish_sys_micros = micros(t2.cpu_fish.ru_stime) - micros(t1.cpu_fish.ru_stime); int64_t fish_usr_micros = micros(t2.cpu_fish.ru_utime) - micros(t1.cpu_fish.ru_utime); int64_t child_sys_micros = micros(t2.cpu_children.ru_stime) - micros(t1.cpu_children.ru_stime); @@ -112,10 +112,14 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver auto unit_name = [](tunit unit) { switch (unit) { - case tunit::minutes: return "minutes"; - case tunit::seconds: return "seconds"; - case tunit::milliseconds: return "milliseconds"; - case tunit::microseconds: return "microseconds"; + case tunit::minutes: + return "minutes"; + case tunit::seconds: + return "seconds"; + case tunit::milliseconds: + return "milliseconds"; + case tunit::microseconds: + return "microseconds"; } // GCC does not recognize the exhaustive switch above return ""; @@ -123,10 +127,14 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver auto unit_short_name = [](tunit unit) { switch (unit) { - case tunit::minutes: return "mins"; - case tunit::seconds: return "secs"; - case tunit::milliseconds: return "millis"; - case tunit::microseconds: return "micros"; + case tunit::minutes: + return "mins"; + case tunit::seconds: + return "secs"; + case tunit::milliseconds: + return "millis"; + case tunit::microseconds: + return "micros"; } // GCC does not recognize the exhaustive switch above return ""; @@ -134,10 +142,14 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver auto convert = [](int64_t micros, tunit unit) { switch (unit) { - case tunit::minutes: return micros / 1.0E6 / 60.0; - case tunit::seconds: return micros / 1.0E6; - case tunit::milliseconds: return micros / 1.0E3; - case tunit::microseconds: return micros / 1.0; + case tunit::minutes: + return micros / 1.0E6 / 60.0; + case tunit::seconds: + return micros / 1.0E6; + case tunit::milliseconds: + return micros / 1.0E3; + case tunit::microseconds: + return micros / 1.0; } // GCC does not recognize the exhaustive switch above return 0.0; @@ -152,15 +164,13 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver wcstring output; if (!verbose) { append_format(output, - L"\n_______________________________" \ - L"\nExecuted in %6.2F %s" \ - L"\n usr time %6.2F %s" \ - L"\n sys time %6.2F %s" \ - L"\n", - wall_time, unit_name(wall_unit), - usr_time, unit_name(cpu_unit), - sys_time, unit_name(cpu_unit) - ); + L"\n_______________________________" + L"\nExecuted in %6.2F %s" + L"\n usr time %6.2F %s" + L"\n sys time %6.2F %s" + L"\n", + wall_time, unit_name(wall_unit), usr_time, unit_name(cpu_unit), sys_time, + unit_name(cpu_unit)); } else { auto fish_unit = get_unit((fish_sys_micros + fish_usr_micros) / 2); auto child_unit = get_unit((child_sys_micros + child_usr_micros) / 2); @@ -170,22 +180,17 @@ timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool ver auto child_sys_time = convert(child_sys_micros, child_unit); append_format(output, - L"\n________________________________________________________" \ - L"\nExecuted in %6.2F %s %*s %*s " \ - L"\n usr time %6.2F %s %6.2F %s %6.2F %s " \ - L"\n sys time %6.2F %s %6.2F %s %6.2F %s " \ - L"\n", - wall_time, unit_short_name(wall_unit), - strlen(unit_short_name(wall_unit)) - 1, "fish", - strlen(unit_short_name(fish_unit)) - 1, "external", - usr_time, unit_short_name(cpu_unit), - fish_usr_time, unit_short_name(fish_unit), - child_usr_time, unit_short_name(child_unit), - sys_time, unit_short_name(cpu_unit), - fish_sys_time, unit_short_name(fish_unit), - child_sys_time, unit_short_name(child_unit) - ); - + L"\n________________________________________________________" + L"\nExecuted in %6.2F %s %*s %*s " + L"\n usr time %6.2F %s %6.2F %s %6.2F %s " + L"\n sys time %6.2F %s %6.2F %s %6.2F %s " + L"\n", + wall_time, unit_short_name(wall_unit), strlen(unit_short_name(wall_unit)) - 1, + "fish", strlen(unit_short_name(fish_unit)) - 1, "external", usr_time, + unit_short_name(cpu_unit), fish_usr_time, unit_short_name(fish_unit), + child_usr_time, unit_short_name(child_unit), sys_time, + unit_short_name(cpu_unit), fish_sys_time, unit_short_name(fish_unit), + child_sys_time, unit_short_name(child_unit)); } return output; diff --git a/src/timer.h b/src/timer.h index 8ed1a2d7d..bdc34bc2e 100644 --- a/src/timer.h +++ b/src/timer.h @@ -2,10 +2,11 @@ #ifndef FISH_TIMER_H #define FISH_TIMER_H -#include -#include -#include #include +#include +#include + +#include #include "common.h" @@ -13,7 +14,7 @@ class parser_t; struct io_streams_t; struct timer_snapshot_t { -public: + public: struct rusage cpu_fish; struct rusage cpu_children; std::chrono::time_point wall; @@ -21,7 +22,7 @@ public: static timer_snapshot_t take(); static wcstring print_delta(timer_snapshot_t t1, timer_snapshot_t t2, bool verbose = false); -private: + private: timer_snapshot_t() {} }; diff --git a/src/tnode.h b/src/tnode.h index 0ec725f41..cfe3fd17b 100644 --- a/src/tnode.h +++ b/src/tnode.h @@ -235,8 +235,7 @@ parse_statement_decoration_t get_decoration(tnode_t st /// Return the type for a boolean statement. parse_job_decoration_t bool_statement_type(tnode_t stmt); -parse_job_decoration_t bool_statement_type( - tnode_t cont); +parse_job_decoration_t bool_statement_type(tnode_t cont); /// Given a redirection node, get the parsed redirection and target of the redirection (file path, /// or fd). diff --git a/src/topic_monitor.cpp b/src/topic_monitor.cpp index 57763ae7a..779c5bffb 100644 --- a/src/topic_monitor.cpp +++ b/src/topic_monitor.cpp @@ -155,7 +155,8 @@ generation_list_t topic_monitor_t::await_gens(const generation_list_t &input_gen #endif uint8_t ignored[PIPE_BUF]; auto unused = read(fd, ignored, sizeof ignored); - if (unused) {} + if (unused) { + } // We are finished reading. We must stop being the reader, and post on the condition // variable to wake up any other threads waiting for us to finish reading.