aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/autoload.h
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-04-18 21:35:53 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-04-18 22:06:31 -0700
commitc93e38380a1f1bed6c73846c4e3e6cf0b83b8471 (patch)
tree07315f0846629ab99217a831c7347766abf62837 /src/autoload.h
parenta10a79c6d09c468d78d31bb7b444c8acefe44f5f (diff)
restyle autoload module to match project style
Reduces lint errors from 38 to 19 (-50%). Line count from 506 to 426 (-16%). Another step in resolving issue #2902.
Diffstat (limited to 'src/autoload.h')
-rw-r--r--src/autoload.h154
1 files changed, 68 insertions, 86 deletions
diff --git a/src/autoload.h b/src/autoload.h
index f0ad9d03..5f8b4d31 100644
--- a/src/autoload.h
+++ b/src/autoload.h
@@ -1,8 +1,4 @@
-/** \file autoload.h
-
- The classes responsible for autoloading functions and completions.
-*/
-
+// The classes responsible for autoloading functions and completions.
#ifndef FISH_AUTOLOAD_H
#define FISH_AUTOLOAD_H
@@ -13,118 +9,104 @@
#include "common.h"
#include "lru.h"
-/** A struct responsible for recording an attempt to access a file. */
-struct file_access_attempt_t
-{
- time_t mod_time; /** The modification time of the file */
- time_t last_checked; /** When we last checked the file */
- bool accessible; /** Whether we believe we could access this file */
- bool stale; /** Whether the access attempt is stale */
- int error; /** If we could not access the file, the error code */
+// A struct responsible for recording an attempt to access a file.
+struct file_access_attempt_t {
+ time_t mod_time; // modification time of the file
+ time_t last_checked; // when we last checked the file
+ bool accessible; // whether we believe we could access this file
+ bool stale; // whether the access attempt is stale
+ int error; // if we could not access the file, the error code
};
file_access_attempt_t access_file(const wcstring &path, int mode);
-struct autoload_function_t : public lru_node_t
-{
- explicit autoload_function_t(const wcstring &key) : lru_node_t(key), access(), is_loaded(false), is_placeholder(false), is_internalized(false) { }
- file_access_attempt_t access; /** The last access attempt */
- bool is_loaded; /** Whether we have actually loaded this function */
- bool is_placeholder; /** Whether we are a placeholder that stands in for "no such function". If this is true, then is_loaded must be false. */
- bool is_internalized; /** Whether this function came from a builtin "internalized" script */
+struct autoload_function_t : public lru_node_t {
+ explicit autoload_function_t(const wcstring &key)
+ : lru_node_t(key),
+ access(),
+ is_loaded(false),
+ is_placeholder(false),
+ is_internalized(false) {}
+ file_access_attempt_t access; // the last access attempt
+ bool is_loaded; // whether we have actually loaded this function
+ // Whether we are a placeholder that stands in for "no such function". If this is true, then
+ // is_loaded must be false.
+ bool is_placeholder;
+ // Whether this function came from a builtin "internalized" script.
+ bool is_internalized;
};
-struct builtin_script_t
-{
+struct builtin_script_t {
const wchar_t *name;
const char *def;
};
class env_vars_snapshot_t;
-/**
- A class that represents a path from which we can autoload, and the autoloaded contents.
- */
-class autoload_t : private lru_cache_t<autoload_function_t>
-{
-private:
-
- /** Lock for thread safety */
+// A class that represents a path from which we can autoload, and the autoloaded contents.
+class autoload_t : private lru_cache_t<autoload_function_t> {
+ private:
+ // Lock for thread safety.
pthread_mutex_t lock;
-
- /** The environment variable name */
+ // The environment variable name.
const wcstring env_var_name;
-
- /** Builtin script array */
+ // Builtin script array.
const struct builtin_script_t *const builtin_scripts;
-
- /** Builtin script count */
+ // Builtin script count.
const size_t builtin_script_count;
-
- /** The path from which we most recently autoloaded */
+ // The path from which we most recently autoloaded.
wcstring last_path;
-
- /** That path, tokenized (split on separators) */
+ // That path, tokenized (split on separators).
wcstring_list_t last_path_tokenized;
- /**
- A table containing all the files that are currently being
- loaded. This is here to help prevent recursion.
- */
+ // A table containing all the files that are currently being loaded. This is here to help
+ // prevent recursion.
std::set<wcstring> is_loading_set;
- void remove_all_functions(void)
- {
- this->evict_all_nodes();
- }
+ void remove_all_functions(void) { this->evict_all_nodes(); }
- bool locate_file_and_maybe_load_it(const wcstring &cmd, bool really_load, bool reload, const wcstring_list_t &path_list);
+ bool locate_file_and_maybe_load_it(const wcstring &cmd, bool really_load, bool reload,
+ const wcstring_list_t &path_list);
virtual void node_was_evicted(autoload_function_t *node);
- autoload_function_t *get_autoloaded_function_with_creation(const wcstring &cmd, bool allow_eviction);
-
-protected:
- /** Overridable callback for when a command is removed */
- virtual void command_removed(const wcstring &cmd) { }
-
-public:
-
- /** Create an autoload_t for the given environment variable name */
- autoload_t(const wcstring &env_var_name_var, const builtin_script_t *scripts, size_t script_count);
-
- /** Destructor */
- virtual ~autoload_t();
-
- /**
- Autoload the specified file, if it exists in the specified path. Do
- not load it multiple times unless its timestamp changes or
- parse_util_unload is called.
-
- Autoloading one file may unload another.
-
- \param cmd the filename to search for. The suffix '.fish' is always added to this name
- \param on_unload a callback function to run if a suitable file is found, which has not already been run. unload will also be called for old files which are unloaded.
- \param reload wheter to recheck file timestamps on already loaded files
- */
+ autoload_function_t *get_autoloaded_function_with_creation(const wcstring &cmd,
+ bool allow_eviction);
+
+ protected:
+ // Overridable callback for when a command is removed.
+ virtual void command_removed(const wcstring &cmd) {}
+
+ public:
+ // Create an autoload_t for the given environment variable name.
+ autoload_t(const wcstring &env_var_name_var, const builtin_script_t *scripts,
+ size_t script_count);
+
+ virtual ~autoload_t(); // destructor
+
+ // Autoload the specified file, if it exists in the specified path. Do not load it multiple
+ // times unless its timestamp changes or parse_util_unload is called.
+ //
+ // Autoloading one file may unload another.
+ //
+ // \param cmd the filename to search for. The suffix '.fish' is always added to this name
+ // \param on_unload a callback function to run if a suitable file is found, which has not
+ // already been run. unload will also be called for old files which are unloaded.
+ // \param reload wheter to recheck file timestamps on already loaded files
int load(const wcstring &cmd, bool reload);
- /** Check whether we have tried loading the given command. Does not do any I/O. */
+ // Check whether we have tried loading the given command. Does not do any I/O.
bool has_tried_loading(const wcstring &cmd);
- /**
- Tell the autoloader that the specified file, in the specified path,
- is no longer loaded.
-
- \param cmd the filename to search for. The suffix '.fish' is always added to this name
- \param on_unload a callback function which will be called before (re)loading a file, may be used to unload the previous file.
- \return non-zero if the file was removed, zero if the file had not yet been loaded
- */
+ // Tell the autoloader that the specified file, in the specified path, is no longer loaded.
+ //
+ // \param cmd the filename to search for. The suffix '.fish' is always added to this name
+ // \param on_unload a callback function which will be called before (re)loading a file, may be
+ // used to unload the previous file.
+ // \return non-zero if the file was removed, zero if the file had not yet been loaded
int unload(const wcstring &cmd);
- /** Check whether the given command could be loaded, but do not load it. */
+ // Check whether the given command could be loaded, but do not load it.
bool can_load(const wcstring &cmd, const env_vars_snapshot_t &vars);
-
};
-
#endif