diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-05-02 12:31:33 -0700 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-05-02 13:00:03 -0700 |
commit | ea945cc4377d91ceeeb0954ae8ad862f82f91918 (patch) | |
tree | f8801902fda879e447cd9df3e4ae2089b0e8e8fa /src/parse_execution.h | |
parent | 13d7432368dbb4272997b3b4cb7d50cc5e9f786b (diff) |
restyle parse_execution module to match project style
Reduces lint errors from 184 to 84 (-54%). Line count from 2139 to 1943 (-9%).
Another step in resolving issue #2902.
Diffstat (limited to 'src/parse_execution.h')
-rw-r--r-- | src/parse_execution.h | 169 |
1 files changed, 86 insertions, 83 deletions
diff --git a/src/parse_execution.h b/src/parse_execution.h index 088729cb..5c1ee101 100644 --- a/src/parse_execution.h +++ b/src/parse_execution.h @@ -1,65 +1,55 @@ -/**\file parse_execution.h - - Provides the "linkage" between a parse_node_tree_t and actual execution structures (job_t, etc.). -*/ +// Provides the "linkage" between a parse_node_tree_t and actual execution structures (job_t, etc.). #ifndef FISH_PARSE_EXECUTION_H #define FISH_PARSE_EXECUTION_H #include <stddef.h> +#include <stdbool.h> #include "common.h" #include "io.h" #include "parse_constants.h" #include "parse_tree.h" #include "proc.h" -#include <stdbool.h> class parser_t; struct block_t; -enum parse_execution_result_t -{ - /* The job was successfully executed (though it have failed on its own). */ +enum parse_execution_result_t { + /// The job was successfully executed (though it have failed on its own). parse_execution_success, - - /* The job did not execute due to some error (e.g. failed to wildcard expand). An error will have been printed and proc_last_status will have been set. */ + /// The job did not execute due to some error (e.g. failed to wildcard expand). An error will + /// have been printed and proc_last_status will have been set. parse_execution_errored, - - /* The job was cancelled (e.g. Ctrl-C) */ + /// The job was cancelled (e.g. Ctrl-C). parse_execution_cancelled, - - /* The job was skipped (e.g. due to a not-taken 'and' command). This is a special return allowed only from the populate functions, not the run functions. */ + /// The job was skipped (e.g. due to a not-taken 'and' command). This is a special return + /// allowed only from the populate functions, not the run functions. parse_execution_skipped }; -class parse_execution_context_t -{ -private: +class parse_execution_context_t { + private: const parse_node_tree_t tree; const wcstring src; io_chain_t block_io; - parser_t * const parser; - //parse_error_list_t errors; - + parser_t *const parser; + // parse_error_list_t errors; int eval_level; - - /* The currently executing node index, used to indicate the line number */ + // The currently executing node index, used to indicate the line number. node_offset_t executing_node_idx; - - /* Cached line number information */ + // Cached line number information. size_t cached_lineno_offset; int cached_lineno_count; + // No copying allowed. + parse_execution_context_t(const parse_execution_context_t &); + parse_execution_context_t &operator=(const parse_execution_context_t &); - /* No copying allowed */ - parse_execution_context_t(const parse_execution_context_t&); - parse_execution_context_t& operator=(const parse_execution_context_t&); - - /* Should I cancel? */ + // Should I cancel? bool should_cancel_execution(const block_t *block) const; - /* Ways that we can stop executing a block. These are in a sort of ascending order of importance, e.g. `exit` should trump `break` */ - enum execution_cancellation_reason_t - { + // Ways that we can stop executing a block. These are in a sort of ascending order of + // importance, e.g. `exit` should trump `break`. + enum execution_cancellation_reason_t { execution_cancellation_none, execution_cancellation_loop_control, execution_cancellation_skip, @@ -67,85 +57,98 @@ private: }; execution_cancellation_reason_t cancellation_reason(const block_t *block) const; - /* Report an error. Always returns true. */ + // Report an error. Always returns true. parse_execution_result_t report_error(const parse_node_t &node, const wchar_t *fmt, ...) const; parse_execution_result_t report_errors(const parse_error_list_t &errors) const; - /* Wildcard error helper */ - parse_execution_result_t report_unmatched_wildcard_error(const parse_node_t &unmatched_wildcard); + // Wildcard error helper. + parse_execution_result_t report_unmatched_wildcard_error( + const parse_node_t &unmatched_wildcard); - /* Command not found support */ - parse_execution_result_t handle_command_not_found(const wcstring &cmd, const parse_node_t &statement_node, int err_code); + /// Command not found support. + parse_execution_result_t handle_command_not_found(const wcstring &cmd, + const parse_node_t &statement_node, + int err_code); - /* Utilities */ + // Utilities wcstring get_source(const parse_node_t &node) const; - const parse_node_t *get_child(const parse_node_t &parent, node_offset_t which, parse_token_type_t expected_type = token_type_invalid) const; + const parse_node_t *get_child(const parse_node_t &parent, node_offset_t which, + parse_token_type_t expected_type = token_type_invalid) const; node_offset_t get_offset(const parse_node_t &node) const; - const parse_node_t *infinite_recursive_statement_in_job_list(const parse_node_t &job_list, wcstring *out_func_name) const; + const parse_node_t *infinite_recursive_statement_in_job_list(const parse_node_t &job_list, + wcstring *out_func_name) const; - /* Indicates whether a job is a simple block (one block, no redirections) */ + /// Indicates whether a job is a simple block (one block, no redirections). bool job_is_simple_block(const parse_node_t &node) const; - enum process_type_t process_type_for_command(const parse_node_t &plain_statement, const wcstring &cmd) const; + enum process_type_t process_type_for_command(const parse_node_t &plain_statement, + const wcstring &cmd) const; - /* These create process_t structures from statements */ - parse_execution_result_t populate_job_process(job_t *job, process_t *proc, const parse_node_t &statement_node); - parse_execution_result_t populate_boolean_process(job_t *job, process_t *proc, const parse_node_t &bool_statement); - parse_execution_result_t populate_plain_process(job_t *job, process_t *proc, const parse_node_t &statement); - parse_execution_result_t populate_block_process(job_t *job, process_t *proc, const parse_node_t &statement_node); + // These create process_t structures from statements. + parse_execution_result_t populate_job_process(job_t *job, process_t *proc, + const parse_node_t &statement_node); + parse_execution_result_t populate_boolean_process(job_t *job, process_t *proc, + const parse_node_t &bool_statement); + parse_execution_result_t populate_plain_process(job_t *job, process_t *proc, + const parse_node_t &statement); + parse_execution_result_t populate_block_process(job_t *job, process_t *proc, + const parse_node_t &statement_node); - /* These encapsulate the actual logic of various (block) statements. */ + // These encapsulate the actual logic of various (block) statements. parse_execution_result_t run_block_statement(const parse_node_t &statement); - parse_execution_result_t run_for_statement(const parse_node_t &header, const parse_node_t &contents); + parse_execution_result_t run_for_statement(const parse_node_t &header, + const parse_node_t &contents); parse_execution_result_t run_if_statement(const parse_node_t &statement); parse_execution_result_t run_switch_statement(const parse_node_t &statement); - parse_execution_result_t run_while_statement(const parse_node_t &header, const parse_node_t &contents); - parse_execution_result_t run_function_statement(const parse_node_t &header, const parse_node_t &block_end_command); - parse_execution_result_t run_begin_statement(const parse_node_t &header, const parse_node_t &contents); - - enum globspec_t - { - failglob, - nullglob - }; - parse_execution_result_t determine_arguments(const parse_node_t &parent, wcstring_list_t *out_arguments, globspec_t glob_behavior); - - /* Determines the IO chain. Returns true on success, false on error */ + parse_execution_result_t run_while_statement(const parse_node_t &header, + const parse_node_t &contents); + parse_execution_result_t run_function_statement(const parse_node_t &header, + const parse_node_t &block_end_command); + parse_execution_result_t run_begin_statement(const parse_node_t &header, + const parse_node_t &contents); + + enum globspec_t { failglob, nullglob }; + parse_execution_result_t determine_arguments(const parse_node_t &parent, + wcstring_list_t *out_arguments, + globspec_t glob_behavior); + + // Determines the IO chain. Returns true on success, false on error. bool determine_io_chain(const parse_node_t &statement, io_chain_t *out_chain); - parse_execution_result_t run_1_job(const parse_node_t &job_node, const block_t *associated_block); - parse_execution_result_t run_job_list(const parse_node_t &job_list_node, const block_t *associated_block); - parse_execution_result_t populate_job_from_job_node(job_t *j, const parse_node_t &job_node, const block_t *associated_block); + parse_execution_result_t run_1_job(const parse_node_t &job_node, + const block_t *associated_block); + parse_execution_result_t run_job_list(const parse_node_t &job_list_node, + const block_t *associated_block); + parse_execution_result_t populate_job_from_job_node(job_t *j, const parse_node_t &job_node, + const block_t *associated_block); - /* Returns the line number of the node at the given index, indexed from 0. Not const since it touches cached_lineno_offset */ + // Returns the line number of the node at the given index, indexed from 0. Not const since it + // touches cached_lineno_offset. int line_offset_of_node_at_offset(node_offset_t idx); int line_offset_of_character_at_offset(size_t char_idx); -public: - parse_execution_context_t(moved_ref<parse_node_tree_t> t, const wcstring &s, parser_t *p, int initial_eval_level); + public: + parse_execution_context_t(moved_ref<parse_node_tree_t> t, const wcstring &s, parser_t *p, + int initial_eval_level); - /* Returns the current eval level */ - int current_eval_level() const - { - return eval_level; - } + /// Returns the current eval level. + int current_eval_level() const { return eval_level; } - /* Returns the current line number, indexed from 1. Not const since it touches cached_lineno_offset */ + /// Returns the current line number, indexed from 1. Not const since it touches + /// cached_lineno_offset. int get_current_line_number(); - /* Returns the source offset, or -1 */ + /// Returns the source offset, or -1. int get_current_source_offset() const; - /* Returns the source string */ - const wcstring &get_source() const - { - return src; - } - - /* Start executing at the given node offset. Returns 0 if there was no error, 1 if there was an error */ - parse_execution_result_t eval_node_at_offset(node_offset_t offset, const block_t *associated_block, const io_chain_t &io); + /// Returns the source string. + const wcstring &get_source() const { return src; } + /// Start executing at the given node offset. Returns 0 if there was no error, 1 if there was an + /// error. + parse_execution_result_t eval_node_at_offset(node_offset_t offset, + const block_t *associated_block, + const io_chain_t &io); }; - #endif |