mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Migrated function_data_t out of base block class
Removed an auto_ptr (yay)
This commit is contained in:
parent
d788c84440
commit
95de6cf5a7
3 changed files with 38 additions and 55 deletions
85
builtin.cpp
85
builtin.cpp
|
@ -1526,11 +1526,12 @@ static int builtin_function( parser_t &parser, wchar_t **argv )
|
||||||
std::auto_ptr<wcstring_list_t> named_arguments(NULL);
|
std::auto_ptr<wcstring_list_t> named_arguments(NULL);
|
||||||
|
|
||||||
wchar_t *name = 0;
|
wchar_t *name = 0;
|
||||||
int shadows = 1;
|
bool shadows = true;
|
||||||
|
|
||||||
woptind=0;
|
woptind=0;
|
||||||
|
|
||||||
parser.push_block( new function_def_block_t() );
|
function_def_block_t * const fdb = new function_def_block_t();
|
||||||
|
parser.push_block( fdb );
|
||||||
|
|
||||||
static const struct woption
|
static const struct woption
|
||||||
long_options[] =
|
long_options[] =
|
||||||
|
@ -1838,24 +1839,21 @@ static int builtin_function( parser_t &parser, wchar_t **argv )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
function_data_t *d = new function_data_t();
|
function_data_t &d = fdb->function_data;
|
||||||
|
|
||||||
d->name = name;
|
d.name = name;
|
||||||
if (desc)
|
if (desc)
|
||||||
d->description = desc;
|
d.description = desc;
|
||||||
d->events.swap(events);
|
d.events.swap(events);
|
||||||
d->shadows = shadows;
|
d.shadows = shadows;
|
||||||
if (named_arguments.get())
|
if (named_arguments.get())
|
||||||
d->named_arguments.swap(*named_arguments);
|
d.named_arguments.swap(*named_arguments);
|
||||||
|
|
||||||
for( size_t i=0; i<d->events.size(); i++ )
|
for( size_t i=0; i<d.events.size(); i++ )
|
||||||
{
|
{
|
||||||
event_t &e = d->events.at(i);
|
event_t &e = d.events.at(i);
|
||||||
e.function_name = d->name;
|
e.function_name = d.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.current_block->function_data.reset(d);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.current_block->tok_pos = parser.get_pos();
|
parser.current_block->tok_pos = parser.get_pos();
|
||||||
|
@ -3325,43 +3323,32 @@ static int builtin_end( parser_t &parser, wchar_t **argv )
|
||||||
|
|
||||||
case FUNCTION_DEF:
|
case FUNCTION_DEF:
|
||||||
{
|
{
|
||||||
|
function_def_block_t *fdb = static_cast<function_def_block_t *>(parser.current_block);
|
||||||
|
function_data_t &d = fdb->function_data;
|
||||||
|
|
||||||
function_data_t *d = parser.current_block->function_data.get();
|
if (d.name.empty())
|
||||||
|
{
|
||||||
if( d )
|
/* Disallow empty function names */
|
||||||
{
|
append_format(stderr_buffer, _( L"%ls: No function name given\n" ), argv[0] );
|
||||||
if (d->name.empty())
|
|
||||||
{
|
/* Return an error via a crummy way. Don't just return here, since we need to pop the block. */
|
||||||
/* Disallow empty function names */
|
proc_set_last_status(STATUS_BUILTIN_ERROR);
|
||||||
append_format(stderr_buffer, _( L"%ls: No function name given\n" ), argv[0] );
|
}
|
||||||
|
else
|
||||||
/* Return an error via a crummy way. Don't just return here, since we need to pop the block. */
|
{
|
||||||
proc_set_last_status(STATUS_BUILTIN_ERROR);
|
/**
|
||||||
}
|
Copy the text from the beginning of the function
|
||||||
else
|
until the end command and use as the new definition
|
||||||
{
|
for the specified function
|
||||||
/**
|
*/
|
||||||
Copy the text from the beginning of the function
|
|
||||||
until the end command and use as the new definition
|
|
||||||
for the specified function
|
|
||||||
*/
|
|
||||||
|
|
||||||
wchar_t *def = wcsndup( parser.get_buffer()+parser.current_block->tok_pos,
|
|
||||||
parser.get_job_pos()-parser.current_block->tok_pos );
|
|
||||||
d->definition = def;
|
|
||||||
|
|
||||||
function_add( *d, parser );
|
|
||||||
free( def );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
debug(0,
|
|
||||||
_(L"%ls: Missing function definition information."),
|
|
||||||
argv[0] );
|
|
||||||
bugreport();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
wchar_t *def = wcsndup( parser.get_buffer()+parser.current_block->tok_pos,
|
||||||
|
parser.get_job_pos()-parser.current_block->tok_pos );
|
||||||
|
d.definition = def;
|
||||||
|
|
||||||
|
function_add( d, parser );
|
||||||
|
free( def );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -3628,7 +3628,6 @@ block_t::block_t(block_type_t t) :
|
||||||
tok_pos(),
|
tok_pos(),
|
||||||
loop_status(),
|
loop_status(),
|
||||||
job(),
|
job(),
|
||||||
function_data(),
|
|
||||||
src_filename(),
|
src_filename(),
|
||||||
src_lineno(),
|
src_lineno(),
|
||||||
wants_pop_env(false),
|
wants_pop_env(false),
|
||||||
|
@ -3696,6 +3695,7 @@ fake_block_t::fake_block_t() :
|
||||||
}
|
}
|
||||||
|
|
||||||
function_def_block_t::function_def_block_t() :
|
function_def_block_t::function_def_block_t() :
|
||||||
|
function_data(),
|
||||||
block_t(FUNCTION_DEF)
|
block_t(FUNCTION_DEF)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
6
parser.h
6
parser.h
|
@ -100,11 +100,6 @@ struct block_t
|
||||||
The job that is currently evaluated in the specified block.
|
The job that is currently evaluated in the specified block.
|
||||||
*/
|
*/
|
||||||
job_t *job;
|
job_t *job;
|
||||||
|
|
||||||
/**
|
|
||||||
Block type-specific data
|
|
||||||
*/
|
|
||||||
std::auto_ptr<function_data_t> function_data;
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
union
|
union
|
||||||
|
@ -189,6 +184,7 @@ struct fake_block_t : public block_t {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct function_def_block_t : public block_t {
|
struct function_def_block_t : public block_t {
|
||||||
|
function_data_t function_data;
|
||||||
function_def_block_t();
|
function_def_block_t();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue