2011-12-27 11:18:46 +08:00
|
|
|
/** \file function.h
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
Prototypes for functions for storing and retrieving function
|
2006-11-15 22:16:49 +08:00
|
|
|
information. These functions also take care of autoloading
|
|
|
|
functions in the $fish_function_path. Actual function evaluation
|
|
|
|
is taken care of by the parser and to some degree the builtin
|
|
|
|
handling library.
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#ifndef FISH_FUNCTION_H
|
|
|
|
#define FISH_FUNCTION_H
|
|
|
|
|
|
|
|
#include <wchar.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
2012-01-14 15:44:18 +08:00
|
|
|
#include "common.h"
|
2012-02-08 18:34:31 +08:00
|
|
|
#include "event.h"
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2012-01-24 12:32:36 +08:00
|
|
|
#include <tr1/memory>
|
|
|
|
using std::tr1::shared_ptr;
|
|
|
|
|
2012-01-17 04:10:08 +08:00
|
|
|
class parser_t;
|
2012-01-29 06:56:13 +08:00
|
|
|
class env_vars;
|
2012-01-17 04:10:08 +08:00
|
|
|
|
2007-04-23 06:10:33 +08:00
|
|
|
/**
|
2008-01-16 09:06:01 +08:00
|
|
|
Structure describing a function. This is used by the parser to
|
|
|
|
store data on a function while parsing it. It is not used
|
|
|
|
internally to store functions, the function_internal_data_t
|
|
|
|
structure is used for that purpose. Parhaps these two should be
|
|
|
|
merged.
|
|
|
|
*/
|
2012-02-08 18:34:31 +08:00
|
|
|
struct function_data_t
|
2007-04-23 06:10:33 +08:00
|
|
|
{
|
2008-01-14 00:47:47 +08:00
|
|
|
/**
|
|
|
|
Name of function
|
|
|
|
*/
|
2007-04-23 06:10:33 +08:00
|
|
|
wchar_t *name;
|
2008-01-14 00:47:47 +08:00
|
|
|
/**
|
|
|
|
Description of function
|
|
|
|
*/
|
2007-04-23 06:10:33 +08:00
|
|
|
wchar_t *description;
|
2008-01-14 00:47:47 +08:00
|
|
|
/**
|
|
|
|
Function definition
|
|
|
|
*/
|
2007-04-23 06:10:33 +08:00
|
|
|
wchar_t *definition;
|
2008-01-14 00:47:47 +08:00
|
|
|
/**
|
|
|
|
List of all event handlers for this function
|
|
|
|
*/
|
2012-02-08 18:34:31 +08:00
|
|
|
std::vector<event_t *> events;
|
2008-01-14 00:47:47 +08:00
|
|
|
/**
|
|
|
|
List of all named arguments for this function
|
|
|
|
*/
|
2007-04-23 06:10:33 +08:00
|
|
|
array_list_t *named_arguments;
|
2008-01-14 00:47:47 +08:00
|
|
|
/**
|
|
|
|
Set to non-zero if invoking this function shadows the variables
|
|
|
|
of the underlying function.
|
|
|
|
*/
|
2007-04-23 06:10:33 +08:00
|
|
|
int shadows;
|
2012-02-08 18:34:31 +08:00
|
|
|
};
|
2012-01-24 12:32:36 +08:00
|
|
|
|
|
|
|
class function_info_t {
|
|
|
|
public:
|
|
|
|
/** Function definition */
|
|
|
|
wcstring definition;
|
|
|
|
|
|
|
|
/** Function description */
|
|
|
|
wcstring description;
|
|
|
|
|
|
|
|
/**
|
|
|
|
File where this function was defined (intern'd string)
|
|
|
|
*/
|
|
|
|
const wchar_t *definition_file;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Line where definition started
|
|
|
|
*/
|
|
|
|
int definition_offset;
|
|
|
|
|
|
|
|
/**
|
|
|
|
List of all named arguments for this function
|
|
|
|
*/
|
|
|
|
wcstring_list_t named_arguments;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Flag for specifying that this function was automatically loaded
|
|
|
|
*/
|
|
|
|
bool is_autoload;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set to non-zero if invoking this function shadows the variables
|
|
|
|
of the underlying function.
|
|
|
|
*/
|
|
|
|
bool shadows;
|
|
|
|
};
|
2007-04-23 06:10:33 +08:00
|
|
|
|
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
2011-12-27 11:18:46 +08:00
|
|
|
Initialize function data
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
|
|
|
void function_init();
|
2006-11-15 22:16:49 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
2012-01-24 12:32:36 +08:00
|
|
|
Add a function. The parameters values are copied and should be
|
2006-11-15 22:16:49 +08:00
|
|
|
freed by the caller.
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
2012-01-17 03:16:12 +08:00
|
|
|
void function_add( function_data_t *data, const parser_t &parser );
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Remove the function with the specified name.
|
|
|
|
*/
|
2012-01-26 10:40:08 +08:00
|
|
|
void function_remove( const wcstring &name );
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-24 12:32:36 +08:00
|
|
|
/**
|
|
|
|
Gets a function by name.
|
|
|
|
*/
|
|
|
|
shared_ptr<function_info_t> function_get(const wcstring &name);
|
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
|
|
|
Returns the definition of the function with the name \c name.
|
|
|
|
*/
|
|
|
|
const wchar_t *function_get_definition( const wchar_t *name );
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the description of the function with the name \c name.
|
|
|
|
*/
|
|
|
|
const wchar_t *function_get_desc( const wchar_t *name );
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the description of the function with the name \c name.
|
|
|
|
*/
|
|
|
|
void function_set_desc( const wchar_t *name, const wchar_t *desc );
|
|
|
|
|
|
|
|
/**
|
2006-11-15 22:16:49 +08:00
|
|
|
Returns true if the function with the name name exists.
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
2005-11-30 03:50:30 +08:00
|
|
|
int function_exists( const wchar_t *name );
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2011-12-27 11:18:46 +08:00
|
|
|
/**
|
|
|
|
Returns true if the function with the name name exists, without triggering autoload.
|
|
|
|
*/
|
2012-01-29 06:56:13 +08:00
|
|
|
int function_exists_no_autoload( const wchar_t *name, const env_vars &vars );
|
2011-12-27 11:18:46 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
2012-01-14 15:44:18 +08:00
|
|
|
Returns all function names.
|
2011-12-27 11:18:46 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
\param get_hidden whether to include hidden functions, i.e. ones starting with an underscore
|
|
|
|
*/
|
2012-01-14 15:44:18 +08:00
|
|
|
wcstring_list_t function_get_names( int get_hidden );
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2006-02-09 01:37:18 +08:00
|
|
|
/**
|
|
|
|
Returns tha absolute path of the file where the specified function
|
|
|
|
was defined. Returns 0 if the file was defined on the commandline.
|
2006-11-15 22:16:49 +08:00
|
|
|
|
|
|
|
This function does not autoload functions, it will only work on
|
|
|
|
functions that have already been defined.
|
2006-02-09 01:37:18 +08:00
|
|
|
*/
|
2006-01-26 22:48:10 +08:00
|
|
|
const wchar_t *function_get_definition_file( const wchar_t *name );
|
|
|
|
|
2006-02-09 01:37:18 +08:00
|
|
|
/**
|
2006-11-15 22:16:49 +08:00
|
|
|
Returns the linenumber where the definition of the specified
|
|
|
|
function started.
|
|
|
|
|
|
|
|
This function does not autoload functions, it will only work on
|
|
|
|
functions that have already been defined.
|
2006-02-09 01:37:18 +08:00
|
|
|
*/
|
2006-01-26 22:48:10 +08:00
|
|
|
int function_get_definition_offset( const wchar_t *name );
|
|
|
|
|
2007-04-17 04:06:11 +08:00
|
|
|
/**
|
|
|
|
Returns a list of all named arguments of the specified function.
|
|
|
|
*/
|
2012-01-14 15:44:18 +08:00
|
|
|
wcstring_list_t function_get_named_arguments( const wchar_t *name );
|
2007-04-17 04:06:11 +08:00
|
|
|
|
2010-09-08 01:31:05 +08:00
|
|
|
/**
|
|
|
|
Creates a new function using the same definition as the specified function.
|
|
|
|
Returns non-zero if copy is successful.
|
|
|
|
*/
|
|
|
|
int function_copy( const wchar_t *name, const wchar_t *new_name );
|
|
|
|
|
2011-12-27 11:18:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns whether this function shadows variables of the underlying function
|
|
|
|
*/
|
|
|
|
int function_get_shadows( const wchar_t *name );
|
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#endif
|