const wchar_t *parser_t::current_filename() const { ASSERT_IS_MAIN_THREAD(); for (size_t i=0; i < this->block_count(); i++) { const block_t *b = this->block_at_index(i); if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW) { const function_block_t *fb = static_cast<const function_block_t *>(b); return function_get_definition_file(fb->name); } else if (b->type() == SOURCE) { const source_block_t *sb = static_cast<const source_block_t *>(b); return sb->source_file; } } /* We query a global array for the current file name, but only do that if we are the principal parser */ if (this == &principal_parser()) { return reader_current_filename(); } return NULL; }
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; }