int parser_t::get_lineno() const { int lineno = -1; if (execution_context) { lineno = execution_context->get_current_line_number(); // If we are executing a function, we have to add in its offset. const wchar_t *function_name = is_function(); if (function_name != NULL) { lineno += function_get_definition_lineno(function_name); } } return lineno; }
static int report_function_metadata(const wchar_t *funcname, bool verbose, io_streams_t &streams, bool metadata_as_comments) { const wchar_t *path = L"n/a"; const wchar_t *autoloaded = L"n/a"; const wchar_t *shadows_scope = L"n/a"; wcstring description = L"n/a"; int line_number = 0; if (function_exists(funcname)) { auto props = function_get_properties(funcname); path = function_get_definition_file(funcname); if (path) { autoloaded = function_is_autoloaded(funcname) ? L"autoloaded" : L"not-autoloaded"; line_number = function_get_definition_lineno(funcname); } else { path = L"stdin"; } shadows_scope = props->shadow_scope ? L"scope-shadowing" : L"no-scope-shadowing"; function_get_desc(funcname, description); description = escape_string(description, ESCAPE_NO_QUOTED); } if (metadata_as_comments) { if (std::wcscmp(path, L"stdin")) { streams.out.append_format(L"# Defined in %ls @ line %d\n", path, line_number); } } else { streams.out.append_format(L"%ls\n", path); if (verbose) { streams.out.append_format(L"%ls\n", autoloaded); streams.out.append_format(L"%d\n", line_number); streams.out.append_format(L"%ls\n", shadows_scope); streams.out.append_format(L"%ls\n", description.c_str()); } } return STATUS_CMD_OK; }