1 /* Cache of styled source file text
2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #ifndef SOURCE_CACHE_H
20 #define SOURCE_CACHE_H
22 /* This caches highlighted source text, keyed by the source file's
23 full name. A size-limited LRU cache is used.
25 Highlighting depends on the GNU Source Highlight library. When not
26 available, this cache will fall back on reading plain text from the
36 /* Get the source text for the source file in symtab S. FIRST_LINE
37 and LAST_LINE are the first and last lines to return; line
38 numbers are 1-based. If the file cannot be read, false is
39 returned. Otherwise, LINES_OUT is set to the desired text. The
40 returned text may include ANSI terminal escapes. */
41 bool get_source_lines (struct symtab *s, int first_line,
42 int last_line, std::string *lines_out);
44 /* Remove all the items from the source cache. */
47 m_source_map.clear ();
52 /* One element in the cache. */
55 /* The full name of the file. */
57 /* The contents of the file. */
61 /* A helper function for get_source_lines that is used when the
62 source lines are not highlighted. The arguments and return value
63 are as for get_source_lines. */
64 bool get_plain_source_lines (struct symtab *s, int first_line,
65 int last_line, std::string *lines_out);
66 /* A helper function for get_plain_source_lines that extracts the
67 desired source lines from TEXT, putting them into LINES_OUT. The
68 arguments are as for get_source_lines. The return value is the
70 std::string extract_lines (const struct source_text &text, int first_line,
73 /* The contents of the cache. */
74 std::vector<source_text> m_source_map;
77 /* The global source cache. */
78 extern source_cache g_source_cache;
80 #endif /* SOURCE_CACHE_H */