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