Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Source-language-related definitions for GDB. |
1bac305b | 2 | |
b811d2c2 | 3 | Copyright (C) 1991-2020 Free Software Foundation, Inc. |
1bac305b | 4 | |
c906108c SS |
5 | Contributed by the Department of Computer Science at the State University |
6 | of New York at Buffalo. | |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 13 | (at your option) any later version. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b | 20 | You should have received a copy of the GNU General Public License |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
22 | |
23 | #if !defined (LANGUAGE_H) | |
24 | #define LANGUAGE_H 1 | |
25 | ||
671afef6 | 26 | #include "symtab.h" |
268a13a5 | 27 | #include "gdbsupport/function-view.h" |
e9d9f57e | 28 | #include "expression.h" |
671afef6 | 29 | |
1777feb0 | 30 | /* Forward decls for prototypes. */ |
c906108c SS |
31 | struct value; |
32 | struct objfile; | |
52f729a7 | 33 | struct frame_info; |
da3331ec | 34 | struct ui_file; |
79a45b7d | 35 | struct value_print_options; |
79d43c61 | 36 | struct type_print_options; |
a53b64ea | 37 | struct lang_varobj_ops; |
410a0ff2 | 38 | struct parser_state; |
9cdfd9a2 | 39 | class compile_instance; |
a207cff2 | 40 | struct completion_match_for_lcd; |
699bd4cf | 41 | class innermost_block_tracker; |
62dfaa9c | 42 | |
1777feb0 | 43 | #define MAX_FORTRAN_DIMS 7 /* Maximum number of F77 array dims. */ |
c906108c | 44 | |
c906108c SS |
45 | /* range_check == |
46 | range_check_on: Ranges are checked in GDB expressions, producing errors. | |
47 | range_check_warn: Ranges are checked, producing warnings. | |
48 | range_check_off: Ranges are not checked in GDB expressions. */ | |
49 | ||
50 | extern enum range_check | |
c5aa993b JM |
51 | { |
52 | range_check_off, range_check_warn, range_check_on | |
53 | } | |
54 | range_check; | |
c906108c | 55 | |
7ca2d3a3 | 56 | /* array_ordering == |
1777feb0 MS |
57 | array_row_major: Arrays are in row major order. |
58 | array_column_major: Arrays are in column major order. */ | |
7ca2d3a3 DL |
59 | |
60 | extern enum array_ordering | |
61 | { | |
62 | array_row_major, array_column_major | |
63 | } | |
64 | array_ordering; | |
65 | ||
66 | ||
63872f9d | 67 | /* case_sensitivity == |
1777feb0 MS |
68 | case_sensitive_on: Case sensitivity in name matching is used. |
69 | case_sensitive_off: Case sensitivity in name matching is not used. */ | |
63872f9d JG |
70 | |
71 | extern enum case_sensitivity | |
72 | { | |
73 | case_sensitive_on, case_sensitive_off | |
74 | } | |
75 | case_sensitivity; | |
9a044a89 TT |
76 | |
77 | ||
78 | /* macro_expansion == | |
1777feb0 MS |
79 | macro_expansion_no: No macro expansion is available. |
80 | macro_expansion_c: C-like macro expansion is available. */ | |
9a044a89 TT |
81 | |
82 | enum macro_expansion | |
83 | { | |
84 | macro_expansion_no, macro_expansion_c | |
85 | }; | |
86 | ||
c906108c | 87 | \f |
f290d38e AC |
88 | /* Per architecture (OS/ABI) language information. */ |
89 | ||
90 | struct language_arch_info | |
91 | { | |
5a44ea29 | 92 | /* Its primitive types. This is a vector ended by a NULL pointer. |
f290d38e AC |
93 | These types can be specified by name in parsing types in |
94 | expressions, regardless of whether the program being debugged | |
95 | actually defines such a type. */ | |
5a44ea29 | 96 | struct type **primitive_type_vector; |
1994afbf DE |
97 | |
98 | /* Symbol wrappers around primitive_type_vector, so that the symbol lookup | |
99 | machinery can return them. */ | |
100 | struct symbol **primitive_type_symbols; | |
101 | ||
1777feb0 | 102 | /* Type of elements of strings. */ |
f290d38e | 103 | struct type *string_char_type; |
fbb06eb1 UW |
104 | |
105 | /* Symbol name of type to use as boolean type, if defined. */ | |
106 | const char *bool_type_symbol; | |
107 | /* Otherwise, this is the default boolean builtin type. */ | |
108 | struct type *bool_type_default; | |
f290d38e AC |
109 | }; |
110 | ||
9d084466 TBA |
111 | /* In a language (particularly C++) a function argument of an aggregate |
112 | type (i.e. class/struct/union) may be implicitly passed by reference | |
113 | even though it is declared a call-by-value argument in the source. | |
114 | The struct below puts together necessary information for GDB to be | |
115 | able to detect and carry out pass-by-reference semantics for a | |
116 | particular type. This type is referred as T in the inlined comments | |
117 | below. | |
118 | ||
119 | The default values of the fields are chosen to give correct semantics | |
120 | for primitive types and for simple aggregate types, such as | |
121 | ||
122 | class T { | |
123 | int x; | |
124 | }; */ | |
125 | ||
126 | struct language_pass_by_ref_info | |
127 | { | |
128 | /* True if an argument of type T can be passed to a function by value | |
129 | (i.e. not through an implicit reference). False, otherwise. */ | |
130 | bool trivially_copyable = true; | |
131 | ||
132 | /* True if a copy of a value of type T can be initialized by | |
133 | memcpy'ing the value bit-by-bit. False, otherwise. | |
134 | E.g. If T has a user-defined copy ctor, this should be false. */ | |
135 | bool trivially_copy_constructible = true; | |
136 | ||
137 | /* True if a value of type T can be destructed simply by reclaiming | |
138 | the memory area occupied by the value. False, otherwise. | |
139 | E.g. If T has a user-defined destructor, this should be false. */ | |
140 | bool trivially_destructible = true; | |
141 | ||
142 | /* True if it is allowed to create a copy of a value of type T. | |
143 | False, otherwise. | |
144 | E.g. If T has a deleted copy ctor, this should be false. */ | |
145 | bool copy_constructible = true; | |
146 | ||
147 | /* True if a value of type T can be destructed. False, otherwise. | |
148 | E.g. If T has a deleted destructor, this should be false. */ | |
149 | bool destructible = true; | |
150 | }; | |
151 | ||
53fc67f8 AB |
152 | /* Splitting strings into words. */ |
153 | extern const char *default_word_break_characters (void); | |
154 | ||
0874fd07 AB |
155 | /* Base class from which all other language classes derive. */ |
156 | ||
0e25e767 | 157 | struct language_defn |
0874fd07 | 158 | { |
0e25e767 AB |
159 | language_defn (enum language lang) |
160 | : la_language (lang) | |
0874fd07 AB |
161 | { |
162 | /* We should only ever create one instance of each language. */ | |
163 | gdb_assert (languages[lang] == nullptr); | |
164 | languages[lang] = this; | |
165 | } | |
166 | ||
85967615 AB |
167 | /* Which language this is. */ |
168 | ||
169 | const enum language la_language; | |
170 | ||
6f7664a9 AB |
171 | /* Name of the language. */ |
172 | ||
173 | virtual const char *name () const = 0; | |
174 | ||
175 | /* Natural or official name of the language. */ | |
176 | ||
177 | virtual const char *natural_name () const = 0; | |
178 | ||
e171d6f1 AB |
179 | /* Return a vector of file extensions for this language. The extension |
180 | must include the ".", like ".c". If this language doesn't need to | |
181 | provide any filename extensions, this may be an empty vector (which is | |
182 | the default). */ | |
183 | ||
184 | virtual const std::vector<const char *> &filename_extensions () const | |
185 | { | |
186 | static const std::vector<const char *> no_extensions; | |
187 | return no_extensions; | |
188 | } | |
189 | ||
5bd40f2a AB |
190 | /* Print the index of an element of an array. This default |
191 | implementation prints using C99 syntax. */ | |
192 | ||
193 | virtual void print_array_index (struct type *index_type, | |
194 | LONGEST index_value, | |
195 | struct ui_file *stream, | |
196 | const value_print_options *options) const; | |
197 | ||
15e5fd35 AB |
198 | /* Given a symbol VAR, the corresponding block VAR_BLOCK (if any) and a |
199 | stack frame id FRAME, read the value of the variable and return (pointer | |
200 | to a) struct value containing the value. | |
201 | ||
202 | VAR_BLOCK is needed if there's a possibility for VAR to be outside | |
203 | FRAME. This is what happens if FRAME correspond to a nested function | |
204 | and VAR is defined in the outer function. If callers know that VAR is | |
205 | located in FRAME or is global/static, NULL can be passed as VAR_BLOCK. | |
206 | ||
207 | Throw an error if the variable cannot be found. */ | |
208 | ||
209 | virtual struct value *read_var_value (struct symbol *var, | |
210 | const struct block *var_block, | |
211 | struct frame_info *frame) const; | |
212 | ||
48448202 AB |
213 | /* Return information about whether TYPE should be passed |
214 | (and returned) by reference at the language level. The default | |
215 | implementation returns a LANGUAGE_PASS_BY_REF_INFO initialised in its | |
216 | default state. */ | |
217 | ||
218 | virtual struct language_pass_by_ref_info pass_by_reference_info | |
219 | (struct type *type) const | |
220 | { | |
221 | return {}; | |
222 | } | |
223 | ||
1fb314aa AB |
224 | /* The per-architecture (OS/ABI) language information. */ |
225 | ||
226 | virtual void language_arch_info (struct gdbarch *, | |
227 | struct language_arch_info *) const = 0; | |
228 | ||
54f4ca46 AB |
229 | /* Find the definition of the type with the given name. */ |
230 | ||
231 | virtual struct type *lookup_transparent_type (const char *name) const | |
232 | { | |
233 | return basic_lookup_transparent_type (name); | |
234 | } | |
235 | ||
4009ee92 AB |
236 | /* Find all symbols in the current program space matching NAME in |
237 | DOMAIN, according to this language's rules. | |
238 | ||
239 | The search is done in BLOCK only. | |
240 | The caller is responsible for iterating up through superblocks | |
241 | if desired. | |
242 | ||
243 | For each one, call CALLBACK with the symbol. If CALLBACK | |
244 | returns false, the iteration ends at that point. | |
245 | ||
246 | This field may not be NULL. If the language does not need any | |
247 | special processing here, 'iterate_over_symbols' should be | |
248 | used as the definition. */ | |
249 | virtual bool iterate_over_symbols | |
250 | (const struct block *block, const lookup_name_info &name, | |
251 | domain_enum domain, | |
252 | gdb::function_view<symbol_found_callback_ftype> callback) const | |
253 | { | |
254 | return ::iterate_over_symbols (block, name, domain, callback); | |
255 | } | |
256 | ||
c9debfb9 AB |
257 | /* Return a pointer to the function that should be used to match a |
258 | symbol name against LOOKUP_NAME, according to this language's | |
259 | rules. The matching algorithm depends on LOOKUP_NAME. For | |
260 | example, on Ada, the matching algorithm depends on the symbol | |
261 | name (wild/full/verbatim matching), and on whether we're doing | |
262 | a normal lookup or a completion match lookup. | |
263 | ||
264 | As Ada wants to capture symbol matching for all languages in some | |
265 | cases, then this method is a non-overridable interface. Languages | |
266 | should override GET_SYMBOL_NAME_MATCHER_INNER if they need to. */ | |
267 | ||
268 | symbol_name_matcher_ftype *get_symbol_name_matcher | |
269 | (const lookup_name_info &lookup_name) const; | |
270 | ||
8e25bafe AB |
271 | /* If this language allows compilation from the gdb command line, then |
272 | this method will return an instance of struct gcc_context appropriate | |
273 | to the language. If compilation for this language is generally | |
274 | supported, but something goes wrong then an exception is thrown. The | |
275 | returned compiler instance is owned by its caller and must be | |
276 | deallocated by the caller. If compilation is not supported for this | |
277 | language then this method returns NULL. */ | |
278 | ||
279 | virtual compile_instance *get_compile_instance () const | |
280 | { | |
281 | return nullptr; | |
282 | } | |
283 | ||
9a49ad8c AB |
284 | /* This method must be overridden if 'get_compile_instance' is |
285 | overridden. | |
286 | ||
287 | This takes the user-supplied text and returns a new bit of code | |
288 | to compile. | |
289 | ||
290 | INST is the compiler instance being used. | |
291 | INPUT is the user's input text. | |
292 | GDBARCH is the architecture to use. | |
293 | EXPR_BLOCK is the block in which the expression is being | |
294 | parsed. | |
295 | EXPR_PC is the PC at which the expression is being parsed. */ | |
296 | ||
297 | virtual std::string compute_program (compile_instance *inst, | |
298 | const char *input, | |
299 | struct gdbarch *gdbarch, | |
300 | const struct block *expr_block, | |
301 | CORE_ADDR expr_pc) const | |
302 | { | |
303 | gdb_assert_not_reached ("language_defn::compute_program"); | |
304 | } | |
305 | ||
fb8006fd AB |
306 | /* Hash the given symbol search name. */ |
307 | virtual unsigned int search_name_hash (const char *name) const; | |
308 | ||
6f827019 AB |
309 | /* Demangle a symbol according to this language's rules. Unlike |
310 | la_demangle, this does not take any options. | |
311 | ||
312 | *DEMANGLED will be set by this function. | |
313 | ||
314 | If this function returns false, then *DEMANGLED must always be set | |
315 | to NULL. | |
316 | ||
317 | If this function returns true, the implementation may set this to | |
318 | a xmalloc'd string holding the demangled form. However, it is | |
319 | not required to. The string, if any, is owned by the caller. | |
320 | ||
321 | The resulting string should be of the form that will be | |
322 | installed into a symbol. */ | |
323 | virtual bool sniff_from_mangled_name (const char *mangled, | |
324 | char **demangled) const | |
325 | { | |
326 | *demangled = nullptr; | |
327 | return false; | |
328 | } | |
329 | ||
0a50df5d AB |
330 | /* Return demangled language symbol version of MANGLED, or NULL. */ |
331 | virtual char *demangle (const char *mangled, int options) const | |
332 | { | |
333 | return nullptr; | |
334 | } | |
335 | ||
fbfb0a46 AB |
336 | /* Print a type using syntax appropriate for this language. */ |
337 | ||
338 | virtual void print_type (struct type *, const char *, struct ui_file *, int, | |
339 | int, const struct type_print_options *) const = 0; | |
340 | ||
f6eee2d0 AB |
341 | /* PC is possibly an unknown languages trampoline. |
342 | If that PC falls in a trampoline belonging to this language, return | |
343 | the address of the first pc in the real function, or 0 if it isn't a | |
344 | language tramp for this language. */ | |
345 | virtual CORE_ADDR skip_trampoline (struct frame_info *fi, CORE_ADDR pc) const | |
346 | { | |
347 | return (CORE_ADDR) 0; | |
348 | } | |
349 | ||
eff93b4d AB |
350 | /* Return class name of a mangled method name or NULL. */ |
351 | virtual char *class_name_from_physname (const char *physname) const | |
352 | { | |
353 | return nullptr; | |
354 | } | |
355 | ||
53fc67f8 AB |
356 | /* The list of characters forming word boundaries. */ |
357 | virtual const char *word_break_characters (void) const | |
358 | { | |
359 | return default_word_break_characters (); | |
360 | } | |
361 | ||
7e56227d AB |
362 | /* Add to the completion tracker all symbols which are possible |
363 | completions for TEXT. WORD is the entire command on which the | |
364 | completion is being made. If CODE is TYPE_CODE_UNDEF, then all | |
365 | symbols should be examined; otherwise, only STRUCT_DOMAIN symbols | |
366 | whose type has a code of CODE should be matched. */ | |
367 | ||
368 | virtual void collect_symbol_completion_matches | |
369 | (completion_tracker &tracker, | |
370 | complete_symbol_mode mode, | |
371 | symbol_name_match_type name_match_type, | |
372 | const char *text, | |
373 | const char *word, | |
374 | enum type_code code) const | |
375 | { | |
376 | return default_collect_symbol_completion_matches_break_on | |
377 | (tracker, mode, name_match_type, text, word, "", code); | |
378 | } | |
379 | ||
a78a19b1 AB |
380 | /* This is a function that lookup_symbol will call when it gets to |
381 | the part of symbol lookup where C looks up static and global | |
382 | variables. This default implements the basic C lookup rules. */ | |
383 | ||
384 | virtual struct block_symbol lookup_symbol_nonlocal | |
385 | (const char *name, | |
386 | const struct block *block, | |
387 | const domain_enum domain) const; | |
388 | ||
f16a9f57 AB |
389 | /* Return an expression that can be used for a location |
390 | watchpoint. TYPE is a pointer type that points to the memory | |
391 | to watch, and ADDR is the address of the watched memory. */ | |
392 | virtual gdb::unique_xmalloc_ptr<char> watch_location_expression | |
393 | (struct type *type, CORE_ADDR addr) const; | |
394 | ||
0874fd07 AB |
395 | /* List of all known languages. */ |
396 | static const struct language_defn *languages[nr_languages]; | |
c9debfb9 | 397 | |
a1d1fa3e AB |
398 | /* Print a top-level value using syntax appropriate for this language. */ |
399 | virtual void value_print (struct value *val, struct ui_file *stream, | |
400 | const struct value_print_options *options) const; | |
401 | ||
ebe2334e AB |
402 | /* Print a value using syntax appropriate for this language. RECURSE is |
403 | the recursion depth. It is zero-based. */ | |
404 | virtual void value_print_inner | |
405 | (struct value *val, struct ui_file *stream, int recurse, | |
406 | const struct value_print_options *options) const; | |
407 | ||
87afa652 AB |
408 | /* Parser function. */ |
409 | ||
410 | virtual int parser (struct parser_state *ps) const; | |
411 | ||
1bf9c363 AB |
412 | /* Given an expression *EXPP created by prefixifying the result of |
413 | la_parser, perform any remaining processing necessary to complete its | |
414 | translation. *EXPP may change; la_post_parser is responsible for | |
415 | releasing its previous contents, if necessary. If VOID_CONTEXT_P, | |
416 | then no value is expected from the expression. If COMPLETING is | |
417 | non-zero, then the expression has been parsed for completion, not | |
418 | evaluation. */ | |
419 | ||
420 | virtual void post_parser (expression_up *expp, int void_context_p, | |
421 | int completing, | |
422 | innermost_block_tracker *tracker) const | |
423 | { | |
424 | /* By default the post-parser does nothing. */ | |
425 | } | |
426 | ||
ec8cec5b AB |
427 | /* Print the character CH (of type CHTYPE) on STREAM as part of the |
428 | contents of a literal string whose delimiter is QUOTER. */ | |
429 | ||
430 | virtual void emitchar (int ch, struct type *chtype, | |
431 | struct ui_file *stream, int quoter) const; | |
432 | ||
52b50f2c AB |
433 | virtual void printchar (int ch, struct type *chtype, |
434 | struct ui_file * stream) const; | |
435 | ||
d711ee67 AB |
436 | /* Print the character string STRING, printing at most LENGTH characters. |
437 | Printing stops early if the number hits print_max; repeat counts | |
438 | are printed as appropriate. Print ellipses at the end if we | |
439 | had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */ | |
440 | ||
441 | virtual void printstr (struct ui_file *stream, struct type *elttype, | |
442 | const gdb_byte *string, unsigned int length, | |
443 | const char *encoding, int force_ellipses, | |
444 | const struct value_print_options *options) const; | |
445 | ||
4ffc13fb AB |
446 | |
447 | /* Print a typedef using syntax appropriate for this language. | |
448 | TYPE is the underlying type. NEW_SYMBOL is the symbol naming | |
449 | the type. STREAM is the output stream on which to print. */ | |
450 | ||
451 | virtual void print_typedef (struct type *type, struct symbol *new_symbol, | |
452 | struct ui_file *stream) const; | |
453 | ||
39e7ecca AB |
454 | /* Return true if TYPE is a string type. */ |
455 | virtual bool is_string_type_p (struct type *type) const; | |
456 | ||
22e3f3ed AB |
457 | /* Return a string that is used by the 'set print max-depth' setting. |
458 | When GDB replaces a struct or union (during value printing) that is | |
459 | "too deep" this string is displayed instead. The default value here | |
460 | suits most languages. If overriding then the string here should | |
461 | ideally be similar in style to the default; an opener, three '.', and | |
462 | a closer. */ | |
463 | ||
464 | virtual const char *struct_too_deep_ellipsis () const | |
465 | { return "{...}"; } | |
466 | ||
5bae7c4e AB |
467 | /* If this returns non-NULL then the string returned specifies the name |
468 | of the implicit local variable that refers to the current object | |
469 | instance. Return NULL (the default) for languages that have no name | |
470 | for the current object instance. */ | |
471 | ||
472 | virtual const char *name_of_this () const | |
473 | { return nullptr; } | |
474 | ||
67bd3fd5 AB |
475 | /* Return false if the language has first-class arrays. Return true if |
476 | there are no array values, and array objects decay to pointers, as in | |
477 | C. The default is true as currently most supported languages behave | |
478 | in this manor. */ | |
479 | ||
480 | virtual bool c_style_arrays_p () const | |
481 | { return true; } | |
482 | ||
22c12a6c AB |
483 | /* Return the index to use for extracting the first element of a string, |
484 | or as the lower bound when creating a new string. The default of | |
485 | choosing 0 or 1 based on C_STYLE_ARRAYS_P works for all currently | |
486 | supported languages except Modula-2. */ | |
487 | ||
488 | virtual char string_lower_bound () const | |
489 | { return c_style_arrays_p () ? 0 : 1; } | |
490 | ||
d3355e4d AB |
491 | /* Returns true if the symbols names should be stored in GDB's data |
492 | structures for minimal/partial/full symbols using their linkage (aka | |
493 | mangled) form; false if the symbol names should be demangled first. | |
494 | ||
495 | Most languages implement symbol lookup by comparing the demangled | |
496 | names, in which case it is advantageous to store that information | |
497 | already demangled, and so would return false, which is the default. | |
498 | ||
499 | On the other hand, some languages have opted for doing symbol lookups | |
500 | by comparing mangled names instead, for reasons usually specific to | |
501 | the language. Those languages should override this function and | |
502 | return true. | |
503 | ||
504 | And finally, other languages such as C or Asm do not have the concept | |
505 | of mangled vs demangled name, so those languages should also override | |
506 | this function and return true, to prevent any accidental demangling | |
507 | through an unrelated language's demangler. */ | |
508 | ||
509 | virtual bool store_sym_names_in_linkage_form_p () const | |
510 | { return false; } | |
511 | ||
efdf6a73 AB |
512 | /* Default range checking preference. The return value from this |
513 | function provides the automatic setting for 'set check range'. As a | |
514 | consequence a user is free to override this setting if they want. */ | |
515 | ||
516 | virtual bool range_checking_on_by_default () const | |
517 | { return false; } | |
518 | ||
0d201fa4 AB |
519 | /* Is this language case sensitive? The return value from this function |
520 | provides the automativ setting for 'set case-sensitive', as a | |
521 | consequence, a user is free to override this setting if they want. */ | |
522 | ||
523 | virtual enum case_sensitivity case_sensitivity () const | |
524 | { return case_sensitive_on; } | |
525 | ||
3a3440fb AB |
526 | |
527 | /* Multi-dimensional array ordering. */ | |
528 | ||
529 | virtual enum array_ordering array_ordering () const | |
530 | { return array_row_major; } | |
531 | ||
1ac14a04 AB |
532 | /* Style of macro expansion, if any, supported by this language. The |
533 | default is no macro expansion. */ | |
534 | ||
535 | virtual enum macro_expansion macro_expansion () const | |
536 | { return macro_expansion_no; } | |
537 | ||
b63a3f3f AB |
538 | /* Return a structure containing various operations on varobj specific |
539 | for this language. */ | |
540 | ||
541 | virtual const struct lang_varobj_ops *varobj_ops () const; | |
542 | ||
5aba6ebe AB |
543 | /* Definitions related to expression printing, prefixifying, and |
544 | dumping. */ | |
545 | ||
546 | virtual const struct exp_descriptor *expression_ops () const; | |
547 | ||
b7c6e27d AB |
548 | /* Table for printing expressions. */ |
549 | ||
550 | virtual const struct op_print *opcode_print_table () const = 0; | |
551 | ||
c9debfb9 AB |
552 | protected: |
553 | ||
554 | /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method. | |
555 | See that method for a description of the arguments. */ | |
556 | ||
557 | virtual symbol_name_matcher_ftype *get_symbol_name_matcher_inner | |
558 | (const lookup_name_info &lookup_name) const; | |
0874fd07 AB |
559 | }; |
560 | ||
c906108c SS |
561 | /* Pointer to the language_defn for our current language. This pointer |
562 | always points to *some* valid struct; it can be used without checking | |
563 | it for validity. | |
564 | ||
565 | The current language affects expression parsing and evaluation | |
566 | (FIXME: it might be cleaner to make the evaluation-related stuff | |
567 | separate exp_opcodes for each different set of semantics. We | |
568 | should at least think this through more clearly with respect to | |
569 | what happens if the language is changed between parsing and | |
570 | evaluation) and printing of things like types and arrays. It does | |
571 | *not* affect symbol-reading-- each source file in a symbol-file has | |
572 | its own language and we should keep track of that regardless of the | |
573 | language when symbols are read. If we want some manual setting for | |
574 | the language of symbol files (e.g. detecting when ".c" files are | |
7e73cedf | 575 | C++), it should be a separate setting from the current_language. */ |
c906108c SS |
576 | |
577 | extern const struct language_defn *current_language; | |
578 | ||
579 | /* Pointer to the language_defn expected by the user, e.g. the language | |
580 | of main(), or the language we last mentioned in a message, or C. */ | |
581 | ||
582 | extern const struct language_defn *expected_language; | |
583 | ||
34916edc CB |
584 | /* Warning issued when current_language and the language of the current |
585 | frame do not match. */ | |
586 | ||
587 | extern const char lang_frame_mismatch_warn[]; | |
588 | ||
c906108c SS |
589 | /* language_mode == |
590 | language_mode_auto: current_language automatically set upon selection | |
c5aa993b | 591 | of scope (e.g. stack frame) |
c906108c SS |
592 | language_mode_manual: current_language set only by user. */ |
593 | ||
594 | extern enum language_mode | |
c5aa993b JM |
595 | { |
596 | language_mode_auto, language_mode_manual | |
597 | } | |
598 | language_mode; | |
b62f3443 | 599 | |
fbb06eb1 UW |
600 | struct type *language_bool_type (const struct language_defn *l, |
601 | struct gdbarch *gdbarch); | |
602 | ||
b62f3443 JB |
603 | struct type *language_string_char_type (const struct language_defn *l, |
604 | struct gdbarch *gdbarch); | |
605 | ||
1994afbf DE |
606 | /* Look up type NAME in language L, and return its definition for architecture |
607 | GDBARCH. Returns NULL if not found. */ | |
608 | ||
46b0da17 DE |
609 | struct type *language_lookup_primitive_type (const struct language_defn *l, |
610 | struct gdbarch *gdbarch, | |
611 | const char *name); | |
b62f3443 | 612 | |
1994afbf DE |
613 | /* Wrapper around language_lookup_primitive_type to return the |
614 | corresponding symbol. */ | |
615 | ||
616 | struct symbol * | |
617 | language_lookup_primitive_type_as_symbol (const struct language_defn *l, | |
618 | struct gdbarch *gdbarch, | |
619 | const char *name); | |
620 | ||
c906108c SS |
621 | \f |
622 | /* These macros define the behaviour of the expression | |
623 | evaluator. */ | |
624 | ||
1777feb0 | 625 | /* Should we range check values against the domain of their type? */ |
c906108c SS |
626 | #define RANGE_CHECK (range_check != range_check_off) |
627 | ||
1777feb0 MS |
628 | /* "cast" really means conversion. */ |
629 | /* FIXME -- should be a setting in language_defn. */ | |
cc73bb8c TT |
630 | #define CAST_IS_CONVERSION(LANG) ((LANG)->la_language == language_c || \ |
631 | (LANG)->la_language == language_cplus || \ | |
632 | (LANG)->la_language == language_objc) | |
c906108c | 633 | |
a14ed312 | 634 | extern void language_info (int); |
c906108c | 635 | |
a14ed312 | 636 | extern enum language set_language (enum language); |
c906108c | 637 | \f |
c5aa993b | 638 | |
c906108c SS |
639 | /* This page contains functions that return things that are |
640 | specific to languages. Each of these functions is based on | |
641 | the current setting of working_lang, which the user sets | |
1777feb0 | 642 | with the "set language" command. */ |
c906108c | 643 | |
79d43c61 | 644 | #define LA_PRINT_TYPE(type,varstring,stream,show,level,flags) \ |
fbfb0a46 | 645 | (current_language->print_type(type,varstring,stream,show,level,flags)) |
c906108c | 646 | |
5c6ce71d | 647 | #define LA_PRINT_TYPEDEF(type,new_symbol,stream) \ |
4ffc13fb | 648 | (current_language->print_typedef (type,new_symbol,stream)) |
5c6ce71d | 649 | |
79a45b7d | 650 | #define LA_VALUE_PRINT(val,stream,options) \ |
a1d1fa3e | 651 | (current_language->value_print (val,stream,options)) |
c906108c | 652 | |
6c7a06a3 | 653 | #define LA_PRINT_CHAR(ch, type, stream) \ |
52b50f2c | 654 | (current_language->printchar (ch, type, stream)) |
3e43a32a | 655 | #define LA_PRINT_STRING(stream, elttype, string, length, encoding, force_ellipses, options) \ |
d711ee67 AB |
656 | (current_language->printstr (stream, elttype, string, length, \ |
657 | encoding, force_ellipses,options)) | |
6c7a06a3 | 658 | #define LA_EMIT_CHAR(ch, type, stream, quoter) \ |
ec8cec5b | 659 | (current_language->emitchar (ch, type, stream, quoter)) |
c906108c | 660 | |
53a47a3e | 661 | #define LA_PRINT_ARRAY_INDEX(index_type, index_value, stream, options) \ |
5bd40f2a AB |
662 | (current_language->print_array_index(index_type, index_value, stream, \ |
663 | options)) | |
e79af960 | 664 | |
14bc53a8 | 665 | #define LA_ITERATE_OVER_SYMBOLS(BLOCK, NAME, DOMAIN, CALLBACK) \ |
4009ee92 | 666 | (current_language->iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK)) |
f8eba3c6 | 667 | |
c906108c SS |
668 | /* Test a character to decide whether it can be printed in literal form |
669 | or needs to be printed in another representation. For example, | |
670 | in C the literal form of the character with octal value 141 is 'a' | |
671 | and the "other representation" is '\141'. The "other representation" | |
1777feb0 | 672 | is program language dependent. */ |
c906108c SS |
673 | |
674 | #define PRINT_LITERAL_FORM(c) \ | |
675 | ((c) >= 0x20 \ | |
676 | && ((c) < 0x7F || (c) >= 0xA0) \ | |
677 | && (!sevenbit_strings || (c) < 0x80)) | |
678 | ||
c906108c SS |
679 | /* Type predicates */ |
680 | ||
a14ed312 | 681 | extern int pointer_type (struct type *); |
c906108c | 682 | |
c906108c SS |
683 | /* Error messages */ |
684 | ||
a0b31db1 | 685 | extern void range_error (const char *, ...) ATTRIBUTE_PRINTF (1, 2); |
c906108c SS |
686 | |
687 | /* Data: Does this value represent "truth" to the current language? */ | |
688 | ||
a14ed312 | 689 | extern int value_true (struct value *); |
c906108c | 690 | |
c906108c SS |
691 | /* Misc: The string representing a particular enum language. */ |
692 | ||
2039bd9f | 693 | extern enum language language_enum (const char *str); |
c906108c | 694 | |
a14ed312 | 695 | extern const struct language_defn *language_def (enum language); |
7a292a7a | 696 | |
27cd387b | 697 | extern const char *language_str (enum language); |
c906108c | 698 | |
1777feb0 | 699 | /* Check for a language-specific trampoline. */ |
f636b87d | 700 | |
52f729a7 | 701 | extern CORE_ADDR skip_language_trampoline (struct frame_info *, CORE_ADDR pc); |
f636b87d | 702 | |
9a3d7dfd AF |
703 | /* Return demangled language symbol, or NULL. */ |
704 | extern char *language_demangle (const struct language_defn *current_language, | |
705 | const char *mangled, int options); | |
706 | ||
9d084466 TBA |
707 | /* Return information about whether TYPE should be passed |
708 | (and returned) by reference at the language level. */ | |
709 | struct language_pass_by_ref_info language_pass_by_reference (struct type *type); | |
5c6ce71d | 710 | |
b4be9fad TT |
711 | void c_get_string (struct value *value, |
712 | gdb::unique_xmalloc_ptr<gdb_byte> *buffer, | |
713 | int *length, struct type **char_type, | |
714 | const char **charset); | |
ae6a3a4c | 715 | |
b5ec771e | 716 | /* Get LANG's symbol_name_matcher method for LOOKUP_NAME. Returns |
c63d3e8d PA |
717 | default_symbol_name_matcher if not set. LANG is used as a hint; |
718 | the function may ignore it depending on the current language and | |
719 | LOOKUP_NAME. Specifically, if the current language is Ada, this | |
720 | may return an Ada matcher regardless of LANG. */ | |
618daa93 | 721 | symbol_name_matcher_ftype *get_symbol_name_matcher |
b5ec771e PA |
722 | (const language_defn *lang, const lookup_name_info &lookup_name); |
723 | ||
e3ad2841 TT |
724 | /* Save the current language and restore it upon destruction. */ |
725 | ||
726 | class scoped_restore_current_language | |
727 | { | |
728 | public: | |
729 | ||
730 | explicit scoped_restore_current_language () | |
731 | : m_lang (current_language->la_language) | |
732 | { | |
733 | } | |
734 | ||
735 | ~scoped_restore_current_language () | |
736 | { | |
737 | set_language (m_lang); | |
738 | } | |
739 | ||
740 | scoped_restore_current_language (const scoped_restore_current_language &) | |
741 | = delete; | |
742 | scoped_restore_current_language &operator= | |
743 | (const scoped_restore_current_language &) = delete; | |
744 | ||
745 | private: | |
746 | ||
747 | enum language m_lang; | |
748 | }; | |
749 | ||
9e6a1ab6 PW |
750 | /* If language_mode is language_mode_auto, |
751 | then switch current language to the language of SYM | |
752 | and restore current language upon destruction. | |
753 | ||
754 | Else do nothing. */ | |
755 | ||
756 | class scoped_switch_to_sym_language_if_auto | |
757 | { | |
758 | public: | |
759 | ||
760 | explicit scoped_switch_to_sym_language_if_auto (const struct symbol *sym) | |
761 | { | |
762 | if (language_mode == language_mode_auto) | |
763 | { | |
764 | m_lang = current_language->la_language; | |
765 | m_switched = true; | |
c1b5c1eb | 766 | set_language (sym->language ()); |
9e6a1ab6 PW |
767 | } |
768 | else | |
ae73e2e2 TT |
769 | { |
770 | m_switched = false; | |
771 | /* Assign to m_lang to silence a GCC warning. See | |
772 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635. */ | |
773 | m_lang = language_unknown; | |
774 | } | |
9e6a1ab6 PW |
775 | } |
776 | ||
777 | ~scoped_switch_to_sym_language_if_auto () | |
778 | { | |
779 | if (m_switched) | |
780 | set_language (m_lang); | |
781 | } | |
782 | ||
783 | DISABLE_COPY_AND_ASSIGN (scoped_switch_to_sym_language_if_auto); | |
784 | ||
785 | private: | |
786 | bool m_switched; | |
787 | enum language m_lang; | |
788 | }; | |
789 | ||
c5aa993b | 790 | #endif /* defined (LANGUAGE_H) */ |