]>
Commit | Line | Data |
---|---|---|
62f29fda | 1 | /* Cache of styled source file text |
42a4f53d | 2 | Copyright (C) 2018-2019 Free Software Foundation, Inc. |
62f29fda TT |
3 | |
4 | This file is part of GDB. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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/>. */ | |
18 | ||
19 | #ifndef SOURCE_CACHE_H | |
20 | #define SOURCE_CACHE_H | |
21 | ||
22 | /* This caches highlighted source text, keyed by the source file's | |
23 | full name. A size-limited LRU cache is used. | |
24 | ||
25 | Highlighting depends on the GNU Source Highlight library. When not | |
26 | available, this cache will fall back on reading plain text from the | |
27 | appropriate file. */ | |
28 | class source_cache | |
29 | { | |
30 | public: | |
31 | ||
32 | source_cache () | |
33 | { | |
34 | } | |
35 | ||
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 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); | |
43 | ||
44 | /* Remove all the items from the source cache. */ | |
45 | void clear () | |
46 | { | |
47 | m_source_map.clear (); | |
48 | } | |
49 | ||
50 | private: | |
51 | ||
52 | /* One element in the cache. */ | |
53 | struct source_text | |
54 | { | |
55 | /* The full name of the file. */ | |
56 | std::string fullname; | |
57 | /* The contents of the file. */ | |
58 | std::string contents; | |
59 | }; | |
60 | ||
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); | |
66 | /* A helper function for get_plain_source_lines that extracts the | |
67 | desired source lines from TEXT, putting them into LINES. The | |
68 | arguments and return value are as for get_source_lines. */ | |
69 | bool extract_lines (const struct source_text &text, int first_line, | |
70 | int last_line, std::string *lines); | |
71 | ||
72 | /* The contents of the cache. */ | |
73 | std::vector<source_text> m_source_map; | |
74 | }; | |
75 | ||
76 | /* The global source cache. */ | |
77 | extern source_cache g_source_cache; | |
78 | ||
79 | #endif /* SOURCE_CACHE_H */ |