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