Simplify function_info_t and function_data_t

Work towards cleaning up function definition. Migrate inherit_vars into
props and capture their values at the point of definition.
This commit is contained in:
ridiculousfish
2019-11-12 09:53:10 -08:00
parent b0cf94e3ba
commit b51edcfcac
5 changed files with 40 additions and 67 deletions

View File

@@ -253,17 +253,26 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
}
// We have what we need to actually define the function.
auto props = std::make_shared<function_properties_t>();
props->shadow_scope = opts.shadow_scope;
props->named_arguments = std::move(opts.named_arguments);
// Populate inherit_vars.
for (const wcstring &name : opts.inherit_vars) {
if (auto var = parser.vars().get(name)) {
props->inherit_vars[name] = var->as_list();
}
}
props->parsed_source = source;
props->body_node = body;
function_data_t d;
d.name = function_name;
if (!opts.description.empty()) d.description = opts.description;
// d.description = opts.description;
d.description = opts.description;
d.props = props;
d.events = std::move(opts.events);
d.props.shadow_scope = opts.shadow_scope;
d.props.named_arguments = std::move(opts.named_arguments);
d.inherit_vars = std::move(opts.inherit_vars);
d.props.parsed_source = source;
d.props.body_node = body;
function_add(std::move(d), parser);
// Handle wrap targets by creating the appropriate completions.