D language support.
[external/binutils.git] / gdb / c-lang.c
1 /* C language support routines for GDB, the GNU debugger.
2
3    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003,
4    2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 #include "defs.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "expression.h"
25 #include "parser-defs.h"
26 #include "language.h"
27 #include "c-lang.h"
28 #include "valprint.h"
29 #include "macroscope.h"
30 #include "gdb_assert.h"
31 #include "charset.h"
32 #include "gdb_string.h"
33 #include "demangle.h"
34 #include "cp-abi.h"
35 #include "cp-support.h"
36 #include "gdb_obstack.h"
37 #include <ctype.h>
38
39 extern void _initialize_c_language (void);
40
41 /* Given a C string type, STR_TYPE, return the corresponding target
42    character set name.  */
43
44 static const char *
45 charset_for_string_type (enum c_string_type str_type,
46                          struct gdbarch *gdbarch)
47 {
48   switch (str_type & ~C_CHAR)
49     {
50     case C_STRING:
51       return target_charset (gdbarch);
52     case C_WIDE_STRING:
53       return target_wide_charset (gdbarch);
54     case C_STRING_16:
55       /* FIXME: UTF-16 is not always correct.  */
56       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
57         return "UTF-16BE";
58       else
59         return "UTF-16LE";
60     case C_STRING_32:
61       /* FIXME: UTF-32 is not always correct.  */
62       if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
63         return "UTF-32BE";
64       else
65         return "UTF-32LE";
66     }
67   internal_error (__FILE__, __LINE__, "unhandled c_string_type");
68 }
69
70 /* Classify ELTTYPE according to what kind of character it is.  Return
71    the enum constant representing the character type.  Also set
72    *ENCODING to the name of the character set to use when converting
73    characters of this type in target BYTE_ORDER to the host character set.  */
74
75 static enum c_string_type
76 classify_type (struct type *elttype, struct gdbarch *gdbarch,
77                const char **encoding)
78 {
79   struct type *saved_type;
80   enum c_string_type result;
81
82   /* We loop because ELTTYPE may be a typedef, and we want to
83      successively peel each typedef until we reach a type we
84      understand.  We don't use CHECK_TYPEDEF because that will strip
85      all typedefs at once -- but in C, wchar_t is itself a typedef, so
86      that would do the wrong thing.  */
87   while (elttype)
88     {
89       char *name = TYPE_NAME (elttype);
90
91       if (TYPE_CODE (elttype) == TYPE_CODE_CHAR || !name)
92         {
93           result = C_CHAR;
94           goto done;
95         }
96
97       if (!strcmp (name, "wchar_t"))
98         {
99           result = C_WIDE_CHAR;
100           goto done;
101         }
102
103       if (!strcmp (name, "char16_t"))
104         {
105           result = C_CHAR_16;
106           goto done;
107         }
108
109       if (!strcmp (name, "char32_t"))
110         {
111           result = C_CHAR_32;
112           goto done;
113         }
114
115       if (TYPE_CODE (elttype) != TYPE_CODE_TYPEDEF)
116         break;
117
118       /* Call for side effects.  */
119       check_typedef (elttype);
120
121       if (TYPE_TARGET_TYPE (elttype))
122         elttype = TYPE_TARGET_TYPE (elttype);
123       else
124         {
125           /* Perhaps check_typedef did not update the target type.  In
126              this case, force the lookup again and hope it works out.
127              It never will for C, but it might for C++.  */
128           CHECK_TYPEDEF (elttype);
129         }
130     }
131
132   /* Punt.  */
133   result = C_CHAR;
134
135  done:
136   if (encoding)
137     *encoding = charset_for_string_type (result, gdbarch);
138
139   return result;
140 }
141
142 /* Return true if print_wchar can display W without resorting to a
143    numeric escape, false otherwise.  */
144
145 static int
146 wchar_printable (gdb_wchar_t w)
147 {
148   return (gdb_iswprint (w)
149           || w == LCST ('\a') || w == LCST ('\b')
150           || w == LCST ('\f') || w == LCST ('\n')
151           || w == LCST ('\r') || w == LCST ('\t')
152           || w == LCST ('\v'));
153 }
154
155 /* A helper function that converts the contents of STRING to wide
156    characters and then appends them to OUTPUT.  */
157
158 static void
159 append_string_as_wide (const char *string, struct obstack *output)
160 {
161   for (; *string; ++string)
162     {
163       gdb_wchar_t w = gdb_btowc (*string);
164       obstack_grow (output, &w, sizeof (gdb_wchar_t));
165     }
166 }
167
168 /* Print a wide character W to OUTPUT.  ORIG is a pointer to the
169    original (target) bytes representing the character, ORIG_LEN is the
170    number of valid bytes.  WIDTH is the number of bytes in a base
171    characters of the type.  OUTPUT is an obstack to which wide
172    characters are emitted.  QUOTER is a (narrow) character indicating
173    the style of quotes surrounding the character to be printed.
174    NEED_ESCAPE is an in/out flag which is used to track numeric
175    escapes across calls.  */
176
177 static void
178 print_wchar (gdb_wint_t w, const gdb_byte *orig, int orig_len,
179              int width, enum bfd_endian byte_order, struct obstack *output,
180              int quoter, int *need_escapep)
181 {
182   int need_escape = *need_escapep;
183   *need_escapep = 0;
184   if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
185                                             && w != LCST ('8')
186                                             && w != LCST ('9'))))
187     {
188       gdb_wchar_t wchar = w;
189
190       if (w == gdb_btowc (quoter) || w == LCST ('\\'))
191         obstack_grow_wstr (output, LCST ("\\"));
192       obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
193     }
194   else
195     {
196       switch (w)
197         {
198         case LCST ('\a'):
199           obstack_grow_wstr (output, LCST ("\\a"));
200           break;
201         case LCST ('\b'):
202           obstack_grow_wstr (output, LCST ("\\b"));
203           break;
204         case LCST ('\f'):
205           obstack_grow_wstr (output, LCST ("\\f"));
206           break;
207         case LCST ('\n'):
208           obstack_grow_wstr (output, LCST ("\\n"));
209           break;
210         case LCST ('\r'):
211           obstack_grow_wstr (output, LCST ("\\r"));
212           break;
213         case LCST ('\t'):
214           obstack_grow_wstr (output, LCST ("\\t"));
215           break;
216         case LCST ('\v'):
217           obstack_grow_wstr (output, LCST ("\\v"));
218           break;
219         default:
220           {
221             int i;
222
223             for (i = 0; i + width <= orig_len; i += width)
224               {
225                 char octal[30];
226                 ULONGEST value;
227                 value = extract_unsigned_integer (&orig[i], width, byte_order);
228                 /* If the value fits in 3 octal digits, print it that
229                    way.  Otherwise, print it as a hex escape.  */
230                 if (value <= 0777)
231                   sprintf (octal, "\\%.3o", (int) (value & 0777));
232                 else
233                   sprintf (octal, "\\x%lx", (long) value);
234                 append_string_as_wide (octal, output);
235               }
236             /* If we somehow have extra bytes, print them now.  */
237             while (i < orig_len)
238               {
239                 char octal[5];
240                 sprintf (octal, "\\%.3o", orig[i] & 0xff);
241                 append_string_as_wide (octal, output);
242                 ++i;
243               }
244
245             *need_escapep = 1;
246           }
247           break;
248         }
249     }
250 }
251
252 /* Print the character C on STREAM as part of the contents of a literal
253    string whose delimiter is QUOTER.  Note that that format for printing
254    characters and strings is language specific. */
255
256 void
257 c_emit_char (int c, struct type *type,
258              struct ui_file *stream, int quoter)
259 {
260   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
261   struct obstack wchar_buf, output;
262   struct cleanup *cleanups;
263   const char *encoding;
264   gdb_byte *buf;
265   struct wchar_iterator *iter;
266   int need_escape = 0;
267
268   classify_type (type, get_type_arch (type), &encoding);
269
270   buf = alloca (TYPE_LENGTH (type));
271   pack_long (buf, type, c);
272
273   iter = make_wchar_iterator (buf, TYPE_LENGTH (type), encoding,
274                               TYPE_LENGTH (type));
275   cleanups = make_cleanup_wchar_iterator (iter);
276
277   /* This holds the printable form of the wchar_t data.  */
278   obstack_init (&wchar_buf);
279   make_cleanup_obstack_free (&wchar_buf);
280
281   while (1)
282     {
283       int num_chars;
284       gdb_wchar_t *chars;
285       const gdb_byte *buf;
286       size_t buflen;
287       int print_escape = 1;
288       enum wchar_iterate_result result;
289
290       num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
291       if (num_chars < 0)
292         break;
293       if (num_chars > 0)
294         {
295           /* If all characters are printable, print them.  Otherwise,
296              we're going to have to print an escape sequence.  We
297              check all characters because we want to print the target
298              bytes in the escape sequence, and we don't know character
299              boundaries there.  */
300           int i;
301
302           print_escape = 0;
303           for (i = 0; i < num_chars; ++i)
304             if (!wchar_printable (chars[i]))
305               {
306                 print_escape = 1;
307                 break;
308               }
309
310           if (!print_escape)
311             {
312               for (i = 0; i < num_chars; ++i)
313                 print_wchar (chars[i], buf, buflen, TYPE_LENGTH (type),
314                              byte_order, &wchar_buf, quoter, &need_escape);
315             }
316         }
317
318       /* This handles the NUM_CHARS == 0 case as well.  */
319       if (print_escape)
320         print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type), byte_order,
321                      &wchar_buf, quoter, &need_escape);
322     }
323
324   /* The output in the host encoding.  */
325   obstack_init (&output);
326   make_cleanup_obstack_free (&output);
327
328   convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
329                              obstack_base (&wchar_buf),
330                              obstack_object_size (&wchar_buf),
331                              1, &output, translit_char);
332   obstack_1grow (&output, '\0');
333
334   fputs_filtered (obstack_base (&output), stream);
335
336   do_cleanups (cleanups);
337 }
338
339 void
340 c_printchar (int c, struct type *type, struct ui_file *stream)
341 {
342   enum c_string_type str_type;
343
344   str_type = classify_type (type, get_type_arch (type), NULL);
345   switch (str_type)
346     {
347     case C_CHAR:
348       break;
349     case C_WIDE_CHAR:
350       fputc_filtered ('L', stream);
351       break;
352     case C_CHAR_16:
353       fputc_filtered ('u', stream);
354       break;
355     case C_CHAR_32:
356       fputc_filtered ('U', stream);
357       break;
358     }
359
360   fputc_filtered ('\'', stream);
361   LA_EMIT_CHAR (c, type, stream, '\'');
362   fputc_filtered ('\'', stream);
363 }
364
365 /* Print the character string STRING, printing at most LENGTH characters.
366    LENGTH is -1 if the string is nul terminated.  Each character is WIDTH bytes
367    long.  Printing stops early if the number hits print_max; repeat counts are
368    printed as appropriate.  Print ellipses at the end if we had to stop before
369    printing LENGTH characters, or if FORCE_ELLIPSES.  */
370
371 void
372 c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
373             unsigned int length, const char *user_encoding, int force_ellipses,
374             const struct value_print_options *options)
375 {
376   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
377   unsigned int i;
378   unsigned int things_printed = 0;
379   int in_quotes = 0;
380   int need_comma = 0;
381   int width = TYPE_LENGTH (type);
382   struct obstack wchar_buf, output;
383   struct cleanup *cleanup;
384   enum c_string_type str_type;
385   const char *type_encoding;
386   const char *encoding;
387   struct wchar_iterator *iter;
388   int finished = 0;
389   int need_escape = 0;
390
391   /* If the string was not truncated due to `set print elements', and
392      the last byte of it is a null, we don't print that, in traditional C
393      style.  */
394   if (!force_ellipses
395       && length > 0
396       && (extract_unsigned_integer (string + (length - 1) * width,
397                                     width, byte_order) == 0))
398     length--;
399
400   str_type = (classify_type (type, get_type_arch (type), &type_encoding)
401               & ~C_CHAR);
402   switch (str_type)
403     {
404     case C_STRING:
405       break;
406     case C_WIDE_STRING:
407       fputs_filtered ("L", stream);
408       break;
409     case C_STRING_16:
410       fputs_filtered ("u", stream);
411       break;
412     case C_STRING_32:
413       fputs_filtered ("U", stream);
414       break;
415     }
416
417   encoding = (user_encoding && *user_encoding) ? user_encoding : type_encoding;
418
419   if (length == 0)
420     {
421       fputs_filtered ("\"\"", stream);
422       return;
423     }
424
425   if (length == -1)
426     {
427       unsigned long current_char = 1;
428       for (i = 0; current_char; ++i)
429         {
430           QUIT;
431           current_char = extract_unsigned_integer (string + i * width,
432                                                    width, byte_order);
433         }
434       length = i;
435     }
436
437   /* Arrange to iterate over the characters, in wchar_t form.  */
438   iter = make_wchar_iterator (string, length * width, encoding, width);
439   cleanup = make_cleanup_wchar_iterator (iter);
440
441   /* WCHAR_BUF is the obstack we use to represent the string in
442      wchar_t form.  */
443   obstack_init (&wchar_buf);
444   make_cleanup_obstack_free (&wchar_buf);
445
446   while (!finished && things_printed < options->print_max)
447     {
448       int num_chars;
449       enum wchar_iterate_result result;
450       gdb_wchar_t *chars;
451       const gdb_byte *buf;
452       size_t buflen;
453
454       QUIT;
455
456       if (need_comma)
457         {
458           obstack_grow_wstr (&wchar_buf, LCST (", "));
459           need_comma = 0;
460         }
461
462       num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
463       /* We only look at repetitions when we were able to convert a
464          single character in isolation.  This makes the code simpler
465          and probably does the sensible thing in the majority of
466          cases.  */
467       while (num_chars == 1 && things_printed < options->print_max)
468         {
469           /* Count the number of repetitions.  */
470           unsigned int reps = 0;
471           gdb_wchar_t current_char = chars[0];
472           const gdb_byte *orig_buf = buf;
473           int orig_len = buflen;
474
475           if (need_comma)
476             {
477               obstack_grow_wstr (&wchar_buf, LCST (", "));
478               need_comma = 0;
479             }
480
481           while (num_chars == 1 && current_char == chars[0])
482             {
483               num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
484               ++reps;
485             }
486
487           /* Emit CURRENT_CHAR according to the repetition count and
488              options.  */
489           if (reps > options->repeat_count_threshold)
490             {
491               if (in_quotes)
492                 {
493                   if (options->inspect_it)
494                     obstack_grow_wstr (&wchar_buf, LCST ("\\\", "));
495                   else
496                     obstack_grow_wstr (&wchar_buf, LCST ("\", "));
497                   in_quotes = 0;
498                 }
499               obstack_grow_wstr (&wchar_buf, LCST ("'"));
500               need_escape = 0;
501               print_wchar (current_char, orig_buf, orig_len, width,
502                            byte_order, &wchar_buf, '\'', &need_escape);
503               obstack_grow_wstr (&wchar_buf, LCST ("'"));
504               {
505                 /* Painful gyrations.  */
506                 int j;
507                 char *s = xstrprintf (_(" <repeats %u times>"), reps);
508                 for (j = 0; s[j]; ++j)
509                   {
510                     gdb_wchar_t w = gdb_btowc (s[j]);
511                     obstack_grow (&wchar_buf, &w, sizeof (gdb_wchar_t));
512                   }
513                 xfree (s);
514               }
515               things_printed += options->repeat_count_threshold;
516               need_comma = 1;
517             }
518           else
519             {
520               /* Saw the character one or more times, but fewer than
521                  the repetition threshold.  */
522               if (!in_quotes)
523                 {
524                   if (options->inspect_it)
525                     obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
526                   else
527                     obstack_grow_wstr (&wchar_buf, LCST ("\""));
528                   in_quotes = 1;
529                   need_escape = 0;
530                 }
531
532               while (reps-- > 0)
533                 {
534                   print_wchar (current_char, orig_buf, orig_len, width,
535                                byte_order, &wchar_buf, '"', &need_escape);
536                   ++things_printed;
537                 }
538             }
539         }
540
541       /* NUM_CHARS and the other outputs from wchar_iterate are valid
542          here regardless of which branch was taken above.  */
543       if (num_chars < 0)
544         {
545           /* Hit EOF.  */
546           finished = 1;
547           break;
548         }
549
550       switch (result)
551         {
552         case wchar_iterate_invalid:
553           if (!in_quotes)
554             {
555               if (options->inspect_it)
556                 obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
557               else
558                 obstack_grow_wstr (&wchar_buf, LCST ("\""));
559               in_quotes = 1;
560             }
561           need_escape = 0;
562           print_wchar (gdb_WEOF, buf, buflen, width, byte_order, &wchar_buf,
563                        '"', &need_escape);
564           break;
565
566         case wchar_iterate_incomplete:
567           if (in_quotes)
568             {
569               if (options->inspect_it)
570                 obstack_grow_wstr (&wchar_buf, LCST ("\\\","));
571               else
572                 obstack_grow_wstr (&wchar_buf, LCST ("\","));
573               in_quotes = 0;
574             }
575           obstack_grow_wstr (&wchar_buf, LCST (" <incomplete sequence "));
576           print_wchar (gdb_WEOF, buf, buflen, width, byte_order, &wchar_buf,
577                        0, &need_escape);
578           obstack_grow_wstr (&wchar_buf, LCST (">"));
579           finished = 1;
580           break;
581         }
582     }
583
584   /* Terminate the quotes if necessary.  */
585   if (in_quotes)
586     {
587       if (options->inspect_it)
588         obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
589       else
590         obstack_grow_wstr (&wchar_buf, LCST ("\""));
591     }
592
593   if (force_ellipses || !finished)
594     obstack_grow_wstr (&wchar_buf, LCST ("..."));
595
596   /* OUTPUT is where we collect `char's for printing.  */
597   obstack_init (&output);
598   make_cleanup_obstack_free (&output);
599
600   convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
601                              obstack_base (&wchar_buf),
602                              obstack_object_size (&wchar_buf),
603                              1, &output, translit_char);
604   obstack_1grow (&output, '\0');
605
606   fputs_filtered (obstack_base (&output), stream);
607
608   do_cleanups (cleanup);
609 }
610
611 /* Obtain a C string from the inferior storing it in a newly allocated
612    buffer in BUFFER, which should be freed by the caller.   If the
613    in- and out-parameter *LENGTH is specified at -1, the string is read
614    until a null character of the appropriate width is found, otherwise
615    the string is read to the length of characters specified.
616    The size of a character is determined by the length of the target
617    type of the pointer or  array.  If VALUE is an array with a known
618    length, the function will  not read past the end of the array.
619    On completion, *LENGTH will be set to the size of the string read in
620    characters.  (If a length of -1 is specified, the length returned
621    will not include the null character).  CHARSET is always set to the
622    target charset.  */
623
624 void
625 c_get_string (struct value *value, gdb_byte **buffer, int *length,
626               struct type **char_type, const char **charset)
627 {
628   int err, width;
629   unsigned int fetchlimit;
630   struct type *type = check_typedef (value_type (value));
631   struct type *element_type = TYPE_TARGET_TYPE (type);
632   int req_length = *length;
633   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
634   enum c_string_type kind;
635
636   if (element_type == NULL)
637     goto error;
638
639   if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
640     {
641       /* If we know the size of the array, we can use it as a limit on the
642          number of characters to be fetched.  */
643       if (TYPE_NFIELDS (type) == 1
644           && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE)
645         {
646           LONGEST low_bound, high_bound;
647
648           get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
649                                &low_bound, &high_bound);
650           fetchlimit = high_bound - low_bound + 1;
651         }
652       else
653         fetchlimit = UINT_MAX;
654     }
655   else if (TYPE_CODE (type) == TYPE_CODE_PTR)
656     fetchlimit = UINT_MAX;
657   else
658     /* We work only with arrays and pointers.  */
659     goto error;
660
661   if (! c_textual_element_type (element_type, 0))
662     goto error;
663   kind = classify_type (element_type,
664                         get_type_arch (element_type),
665                         charset);
666   width = TYPE_LENGTH (element_type);
667
668   /* If the string lives in GDB's memory instead of the inferior's, then we
669      just need to copy it to BUFFER.  Also, since such strings are arrays
670      with known size, FETCHLIMIT will hold the size of the array.  */
671   if ((VALUE_LVAL (value) == not_lval
672        || VALUE_LVAL (value) == lval_internalvar)
673       && fetchlimit != UINT_MAX)
674     {
675       int i;
676       const gdb_byte *contents = value_contents (value);
677
678       /* If a length is specified, use that.  */
679       if (*length >= 0)
680         i  = *length;
681       else
682         /* Otherwise, look for a null character.  */
683         for (i = 0; i < fetchlimit; i++)
684           if (extract_unsigned_integer (contents + i * width, width,
685                                         byte_order) == 0)
686             break;
687   
688       /* I is now either a user-defined length, the number of non-null
689          characters, or FETCHLIMIT.  */
690       *length = i * width;
691       *buffer = xmalloc (*length);
692       memcpy (*buffer, contents, *length);
693       err = 0;
694     }
695   else
696     {
697       err = read_string (value_as_address (value), *length, width, fetchlimit,
698                          byte_order, buffer, length);
699       if (err)
700         {
701           xfree (*buffer);
702           error (_("Error reading string from inferior: %s"),
703                  safe_strerror (err));
704         }
705     }
706
707   /* If the LENGTH is specified at -1, we want to return the string
708      length up to the terminating null character.  If an actual length
709      was specified, we want to return the length of exactly what was
710      read.  */
711   if (req_length == -1)
712     /* If the last character is null, subtract it from LENGTH.  */
713     if (*length > 0
714         && extract_unsigned_integer (*buffer + *length - width, width,
715                                      byte_order) == 0)
716       *length -= width;
717   
718   /* The read_string function will return the number of bytes read.
719      If length returned from read_string was > 0, return the number of
720      characters read by dividing the number of bytes by width.  */
721   if (*length != 0)
722      *length = *length / width;
723
724   *char_type = element_type;
725
726   return;
727
728  error:
729   {
730     char *type_str;
731
732     type_str = type_to_string (type);
733     if (type_str)
734       {
735         make_cleanup (xfree, type_str);
736         error (_("Trying to read string with inappropriate type `%s'."),
737                type_str);
738       }
739     else
740       error (_("Trying to read string with inappropriate type."));
741   }
742 }
743
744 \f
745 /* Evaluating C and C++ expressions.  */
746
747 /* Convert a UCN.  The digits of the UCN start at P and extend no
748    farther than LIMIT.  DEST_CHARSET is the name of the character set
749    into which the UCN should be converted.  The results are written to
750    OUTPUT.  LENGTH is the maximum length of the UCN, either 4 or 8.
751    Returns a pointer to just after the final digit of the UCN.  */
752
753 static char *
754 convert_ucn (char *p, char *limit, const char *dest_charset,
755              struct obstack *output, int length)
756 {
757   unsigned long result = 0;
758   gdb_byte data[4];
759   int i;
760
761   for (i = 0; i < length && p < limit && isxdigit (*p); ++i, ++p)
762     result = (result << 4) + host_hex_value (*p);
763
764   for (i = 3; i >= 0; --i)
765     {
766       data[i] = result & 0xff;
767       result >>= 8;
768     }
769
770   convert_between_encodings ("UTF-32BE", dest_charset, data, 4, 4, output,
771                              translit_none);
772
773   return p;
774 }
775
776 /* Emit a character, VALUE, which was specified numerically, to
777    OUTPUT.  TYPE is the target character type.  */
778
779 static void
780 emit_numeric_character (struct type *type, unsigned long value,
781                         struct obstack *output)
782 {
783   gdb_byte *buffer;
784
785   buffer = alloca (TYPE_LENGTH (type));
786   pack_long (buffer, type, value);
787   obstack_grow (output, buffer, TYPE_LENGTH (type));
788 }
789
790 /* Convert an octal escape sequence.  TYPE is the target character
791    type.  The digits of the escape sequence begin at P and extend no
792    farther than LIMIT.  The result is written to OUTPUT.  Returns a
793    pointer to just after the final digit of the escape sequence.  */
794
795 static char *
796 convert_octal (struct type *type, char *p, char *limit, struct obstack *output)
797 {
798   int i;
799   unsigned long value = 0;
800
801   for (i = 0;
802        i < 3 && p < limit && isdigit (*p) && *p != '8' && *p != '9';
803        ++i)
804     {
805       value = 8 * value + host_hex_value (*p);
806       ++p;
807     }
808
809   emit_numeric_character (type, value, output);
810
811   return p;
812 }
813
814 /* Convert a hex escape sequence.  TYPE is the target character type.
815    The digits of the escape sequence begin at P and extend no farther
816    than LIMIT.  The result is written to OUTPUT.  Returns a pointer to
817    just after the final digit of the escape sequence.  */
818
819 static char *
820 convert_hex (struct type *type, char *p, char *limit, struct obstack *output)
821 {
822   unsigned long value = 0;
823
824   while (p < limit && isxdigit (*p))
825     {
826       value = 16 * value + host_hex_value (*p);
827       ++p;
828     }
829
830   emit_numeric_character (type, value, output);
831
832   return p;
833 }
834
835 #define ADVANCE                                 \
836   do {                                          \
837     ++p;                                        \
838     if (p == limit)                             \
839       error (_("Malformed escape sequence"));   \
840   } while (0)
841
842 /* Convert an escape sequence to a target format.  TYPE is the target
843    character type to use, and DEST_CHARSET is the name of the target
844    character set.  The backslash of the escape sequence is at *P, and
845    the escape sequence will not extend past LIMIT.  The results are
846    written to OUTPUT.  Returns a pointer to just past the final
847    character of the escape sequence.  */
848
849 static char *
850 convert_escape (struct type *type, const char *dest_charset,
851                 char *p, char *limit, struct obstack *output)
852 {
853   /* Skip the backslash.  */
854   ADVANCE;
855
856   switch (*p)
857     {
858     case '\\':
859       obstack_1grow (output, '\\');
860       ++p;
861       break;
862
863     case 'x':
864       ADVANCE;
865       if (!isxdigit (*p))
866         error (_("\\x used with no following hex digits."));
867       p = convert_hex (type, p, limit, output);
868       break;
869
870     case '0':
871     case '1':
872     case '2':
873     case '3':
874     case '4':
875     case '5':
876     case '6':
877     case '7':
878       p = convert_octal (type, p, limit, output);
879       break;
880
881     case 'u':
882     case 'U':
883       {
884         int length = *p == 'u' ? 4 : 8;
885         ADVANCE;
886         if (!isxdigit (*p))
887           error (_("\\u used with no following hex digits"));
888         p = convert_ucn (p, limit, dest_charset, output, length);
889       }
890     }
891
892   return p;
893 }
894
895 /* Given a single string from a (C-specific) OP_STRING list, convert
896    it to a target string, handling escape sequences specially.  The
897    output is written to OUTPUT.  DATA is the input string, which has
898    length LEN.  DEST_CHARSET is the name of the target character set,
899    and TYPE is the type of target character to use.  */
900
901 static void
902 parse_one_string (struct obstack *output, char *data, int len,
903                   const char *dest_charset, struct type *type)
904 {
905   char *limit;
906
907   limit = data + len;
908
909   while (data < limit)
910     {
911       char *p = data;
912       /* Look for next escape, or the end of the input.  */
913       while (p < limit && *p != '\\')
914         ++p;
915       /* If we saw a run of characters, convert them all.  */
916       if (p > data)
917         convert_between_encodings (host_charset (), dest_charset,
918                                    data, p - data, 1, output, translit_none);
919       /* If we saw an escape, convert it.  */
920       if (p < limit)
921         p = convert_escape (type, dest_charset, p, limit, output);
922       data = p;
923     }
924 }
925
926 /* Expression evaluator for the C language family.  Most operations
927    are delegated to evaluate_subexp_standard; see that function for a
928    description of the arguments.  */
929
930 static struct value *
931 evaluate_subexp_c (struct type *expect_type, struct expression *exp,
932                    int *pos, enum noside noside)
933 {
934   enum exp_opcode op = exp->elts[*pos].opcode;
935
936   switch (op)
937     {
938     case OP_STRING:
939       {
940         int oplen, limit;
941         struct type *type;
942         struct obstack output;
943         struct cleanup *cleanup;
944         struct value *result;
945         enum c_string_type dest_type;
946         const char *dest_charset;
947
948         obstack_init (&output);
949         cleanup = make_cleanup_obstack_free (&output);
950
951         ++*pos;
952         oplen = longest_to_int (exp->elts[*pos].longconst);
953
954         ++*pos;
955         limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1);
956         dest_type
957           = (enum c_string_type) longest_to_int (exp->elts[*pos].longconst);
958         switch (dest_type & ~C_CHAR)
959           {
960           case C_STRING:
961             type = language_string_char_type (exp->language_defn,
962                                               exp->gdbarch);
963             break;
964           case C_WIDE_STRING:
965             type = lookup_typename (exp->language_defn, exp->gdbarch,
966                                     "wchar_t", NULL, 0);
967             break;
968           case C_STRING_16:
969             type = lookup_typename (exp->language_defn, exp->gdbarch,
970                                     "char16_t", NULL, 0);
971             break;
972           case C_STRING_32:
973             type = lookup_typename (exp->language_defn, exp->gdbarch,
974                                     "char32_t", NULL, 0);
975             break;
976           default:
977             internal_error (__FILE__, __LINE__, "unhandled c_string_type");
978           }
979
980         /* Ensure TYPE_LENGTH is valid for TYPE.  */
981         check_typedef (type);
982
983         dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
984
985         ++*pos;
986         while (*pos < limit)
987           {
988             int len;
989
990             len = longest_to_int (exp->elts[*pos].longconst);
991
992             ++*pos;
993             if (noside != EVAL_SKIP)
994               parse_one_string (&output, &exp->elts[*pos].string, len,
995                                 dest_charset, type);
996             *pos += BYTES_TO_EXP_ELEM (len);
997           }
998
999         /* Skip the trailing length and opcode.  */
1000         *pos += 2;
1001
1002         if (noside == EVAL_SKIP)
1003           {
1004             /* Return a dummy value of the appropriate type.  */
1005             if ((dest_type & C_CHAR) != 0)
1006               result = allocate_value (type);
1007             else
1008               result = value_cstring ("", 0, type);
1009             do_cleanups (cleanup);
1010             return result;
1011           }
1012
1013         if ((dest_type & C_CHAR) != 0)
1014           {
1015             LONGEST value;
1016
1017             if (obstack_object_size (&output) != TYPE_LENGTH (type))
1018               error (_("Could not convert character constant to target character set"));
1019             value = unpack_long (type, obstack_base (&output));
1020             result = value_from_longest (type, value);
1021           }
1022         else
1023           {
1024             int i;
1025             /* Write the terminating character.  */
1026             for (i = 0; i < TYPE_LENGTH (type); ++i)
1027               obstack_1grow (&output, 0);
1028             result = value_cstring (obstack_base (&output),
1029                                     obstack_object_size (&output),
1030                                     type);
1031           }
1032         do_cleanups (cleanup);
1033         return result;
1034       }
1035       break;
1036
1037     default:
1038       break;
1039     }
1040   return evaluate_subexp_standard (expect_type, exp, pos, noside);
1041 }
1042
1043
1044 \f
1045 /* Table mapping opcodes into strings for printing operators
1046    and precedences of the operators.  */
1047
1048 const struct op_print c_op_print_tab[] =
1049 {
1050   {",", BINOP_COMMA, PREC_COMMA, 0},
1051   {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1052   {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
1053   {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
1054   {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
1055   {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
1056   {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
1057   {"==", BINOP_EQUAL, PREC_EQUAL, 0},
1058   {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1059   {"<=", BINOP_LEQ, PREC_ORDER, 0},
1060   {">=", BINOP_GEQ, PREC_ORDER, 0},
1061   {">", BINOP_GTR, PREC_ORDER, 0},
1062   {"<", BINOP_LESS, PREC_ORDER, 0},
1063   {">>", BINOP_RSH, PREC_SHIFT, 0},
1064   {"<<", BINOP_LSH, PREC_SHIFT, 0},
1065   {"+", BINOP_ADD, PREC_ADD, 0},
1066   {"-", BINOP_SUB, PREC_ADD, 0},
1067   {"*", BINOP_MUL, PREC_MUL, 0},
1068   {"/", BINOP_DIV, PREC_MUL, 0},
1069   {"%", BINOP_REM, PREC_MUL, 0},
1070   {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1071   {"-", UNOP_NEG, PREC_PREFIX, 0},
1072   {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
1073   {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
1074   {"*", UNOP_IND, PREC_PREFIX, 0},
1075   {"&", UNOP_ADDR, PREC_PREFIX, 0},
1076   {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
1077   {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
1078   {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
1079   {NULL, 0, 0, 0}
1080 };
1081 \f
1082 enum c_primitive_types {
1083   c_primitive_type_int,
1084   c_primitive_type_long,
1085   c_primitive_type_short,
1086   c_primitive_type_char,
1087   c_primitive_type_float,
1088   c_primitive_type_double,
1089   c_primitive_type_void,
1090   c_primitive_type_long_long,
1091   c_primitive_type_signed_char,
1092   c_primitive_type_unsigned_char,
1093   c_primitive_type_unsigned_short,
1094   c_primitive_type_unsigned_int,
1095   c_primitive_type_unsigned_long,
1096   c_primitive_type_unsigned_long_long,
1097   c_primitive_type_long_double,
1098   c_primitive_type_complex,
1099   c_primitive_type_double_complex,
1100   c_primitive_type_decfloat,
1101   c_primitive_type_decdouble,
1102   c_primitive_type_declong,
1103   nr_c_primitive_types
1104 };
1105
1106 void
1107 c_language_arch_info (struct gdbarch *gdbarch,
1108                       struct language_arch_info *lai)
1109 {
1110   const struct builtin_type *builtin = builtin_type (gdbarch);
1111   lai->string_char_type = builtin->builtin_char;
1112   lai->primitive_type_vector
1113     = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
1114                               struct type *);
1115   lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int;
1116   lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long;
1117   lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short;
1118   lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char;
1119   lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float;
1120   lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double;
1121   lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void;
1122   lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long;
1123   lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char;
1124   lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char;
1125   lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short;
1126   lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int;
1127   lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long;
1128   lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long;
1129   lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double;
1130   lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex;
1131   lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex;
1132   lai->primitive_type_vector [c_primitive_type_decfloat] = builtin->builtin_decfloat;
1133   lai->primitive_type_vector [c_primitive_type_decdouble] = builtin->builtin_decdouble;
1134   lai->primitive_type_vector [c_primitive_type_declong] = builtin->builtin_declong;
1135
1136   lai->bool_type_default = builtin->builtin_int;
1137 }
1138
1139 const struct exp_descriptor exp_descriptor_c = 
1140 {
1141   print_subexp_standard,
1142   operator_length_standard,
1143   operator_check_standard,
1144   op_name_standard,
1145   dump_subexp_body_standard,
1146   evaluate_subexp_c
1147 };
1148
1149 const struct language_defn c_language_defn =
1150 {
1151   "c",                          /* Language name */
1152   language_c,
1153   range_check_off,
1154   type_check_off,
1155   case_sensitive_on,
1156   array_row_major,
1157   macro_expansion_c,
1158   &exp_descriptor_c,
1159   c_parse,
1160   c_error,
1161   null_post_parser,
1162   c_printchar,                  /* Print a character constant */
1163   c_printstr,                   /* Function to print string constant */
1164   c_emit_char,                  /* Print a single char */
1165   c_print_type,                 /* Print a type using appropriate syntax */
1166   c_print_typedef,              /* Print a typedef using appropriate syntax */
1167   c_val_print,                  /* Print a value using appropriate syntax */
1168   c_value_print,                /* Print a top-level value */
1169   NULL,                         /* Language specific skip_trampoline */
1170   NULL,                         /* name_of_this */
1171   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1172   basic_lookup_transparent_type,/* lookup_transparent_type */
1173   NULL,                         /* Language specific symbol demangler */
1174   NULL,                         /* Language specific class_name_from_physname */
1175   c_op_print_tab,               /* expression operators for printing */
1176   1,                            /* c-style arrays */
1177   0,                            /* String lower bound */
1178   default_word_break_characters,
1179   default_make_symbol_completion_list,
1180   c_language_arch_info,
1181   default_print_array_index,
1182   default_pass_by_reference,
1183   c_get_string,
1184   LANG_MAGIC
1185 };
1186
1187 enum cplus_primitive_types {
1188   cplus_primitive_type_int,
1189   cplus_primitive_type_long,
1190   cplus_primitive_type_short,
1191   cplus_primitive_type_char,
1192   cplus_primitive_type_float,
1193   cplus_primitive_type_double,
1194   cplus_primitive_type_void,
1195   cplus_primitive_type_long_long,
1196   cplus_primitive_type_signed_char,
1197   cplus_primitive_type_unsigned_char,
1198   cplus_primitive_type_unsigned_short,
1199   cplus_primitive_type_unsigned_int,
1200   cplus_primitive_type_unsigned_long,
1201   cplus_primitive_type_unsigned_long_long,
1202   cplus_primitive_type_long_double,
1203   cplus_primitive_type_complex,
1204   cplus_primitive_type_double_complex,
1205   cplus_primitive_type_bool,
1206   cplus_primitive_type_decfloat,
1207   cplus_primitive_type_decdouble,
1208   cplus_primitive_type_declong,
1209   nr_cplus_primitive_types
1210 };
1211
1212 static void
1213 cplus_language_arch_info (struct gdbarch *gdbarch,
1214                           struct language_arch_info *lai)
1215 {
1216   const struct builtin_type *builtin = builtin_type (gdbarch);
1217   lai->string_char_type = builtin->builtin_char;
1218   lai->primitive_type_vector
1219     = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
1220                               struct type *);
1221   lai->primitive_type_vector [cplus_primitive_type_int]
1222     = builtin->builtin_int;
1223   lai->primitive_type_vector [cplus_primitive_type_long]
1224     = builtin->builtin_long;
1225   lai->primitive_type_vector [cplus_primitive_type_short]
1226     = builtin->builtin_short;
1227   lai->primitive_type_vector [cplus_primitive_type_char]
1228     = builtin->builtin_char;
1229   lai->primitive_type_vector [cplus_primitive_type_float]
1230     = builtin->builtin_float;
1231   lai->primitive_type_vector [cplus_primitive_type_double]
1232     = builtin->builtin_double;
1233   lai->primitive_type_vector [cplus_primitive_type_void]
1234     = builtin->builtin_void;
1235   lai->primitive_type_vector [cplus_primitive_type_long_long]
1236     = builtin->builtin_long_long;
1237   lai->primitive_type_vector [cplus_primitive_type_signed_char]
1238     = builtin->builtin_signed_char;
1239   lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
1240     = builtin->builtin_unsigned_char;
1241   lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
1242     = builtin->builtin_unsigned_short;
1243   lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
1244     = builtin->builtin_unsigned_int;
1245   lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
1246     = builtin->builtin_unsigned_long;
1247   lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
1248     = builtin->builtin_unsigned_long_long;
1249   lai->primitive_type_vector [cplus_primitive_type_long_double]
1250     = builtin->builtin_long_double;
1251   lai->primitive_type_vector [cplus_primitive_type_complex]
1252     = builtin->builtin_complex;
1253   lai->primitive_type_vector [cplus_primitive_type_double_complex]
1254     = builtin->builtin_double_complex;
1255   lai->primitive_type_vector [cplus_primitive_type_bool]
1256     = builtin->builtin_bool;
1257   lai->primitive_type_vector [cplus_primitive_type_decfloat]
1258     = builtin->builtin_decfloat;
1259   lai->primitive_type_vector [cplus_primitive_type_decdouble]
1260     = builtin->builtin_decdouble;
1261   lai->primitive_type_vector [cplus_primitive_type_declong]
1262     = builtin->builtin_declong;
1263
1264   lai->bool_type_symbol = "bool";
1265   lai->bool_type_default = builtin->builtin_bool;
1266 }
1267
1268 const struct language_defn cplus_language_defn =
1269 {
1270   "c++",                        /* Language name */
1271   language_cplus,
1272   range_check_off,
1273   type_check_off,
1274   case_sensitive_on,
1275   array_row_major,
1276   macro_expansion_c,
1277   &exp_descriptor_c,
1278   c_parse,
1279   c_error,
1280   null_post_parser,
1281   c_printchar,                  /* Print a character constant */
1282   c_printstr,                   /* Function to print string constant */
1283   c_emit_char,                  /* Print a single char */
1284   c_print_type,                 /* Print a type using appropriate syntax */
1285   c_print_typedef,              /* Print a typedef using appropriate syntax */
1286   c_val_print,                  /* Print a value using appropriate syntax */
1287   c_value_print,                /* Print a top-level value */
1288   cplus_skip_trampoline,        /* Language specific skip_trampoline */
1289   "this",                       /* name_of_this */
1290   cp_lookup_symbol_nonlocal,    /* lookup_symbol_nonlocal */
1291   cp_lookup_transparent_type,   /* lookup_transparent_type */
1292   cplus_demangle,               /* Language specific symbol demangler */
1293   cp_class_name_from_physname,  /* Language specific class_name_from_physname */
1294   c_op_print_tab,               /* expression operators for printing */
1295   1,                            /* c-style arrays */
1296   0,                            /* String lower bound */
1297   default_word_break_characters,
1298   default_make_symbol_completion_list,
1299   cplus_language_arch_info,
1300   default_print_array_index,
1301   cp_pass_by_reference,
1302   c_get_string,
1303   LANG_MAGIC
1304 };
1305
1306 const struct language_defn asm_language_defn =
1307 {
1308   "asm",                        /* Language name */
1309   language_asm,
1310   range_check_off,
1311   type_check_off,
1312   case_sensitive_on,
1313   array_row_major,
1314   macro_expansion_c,
1315   &exp_descriptor_c,
1316   c_parse,
1317   c_error,
1318   null_post_parser,
1319   c_printchar,                  /* Print a character constant */
1320   c_printstr,                   /* Function to print string constant */
1321   c_emit_char,                  /* Print a single char */
1322   c_print_type,                 /* Print a type using appropriate syntax */
1323   c_print_typedef,              /* Print a typedef using appropriate syntax */
1324   c_val_print,                  /* Print a value using appropriate syntax */
1325   c_value_print,                /* Print a top-level value */
1326   NULL,                         /* Language specific skip_trampoline */
1327   NULL,                         /* name_of_this */
1328   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1329   basic_lookup_transparent_type,/* lookup_transparent_type */
1330   NULL,                         /* Language specific symbol demangler */
1331   NULL,                         /* Language specific class_name_from_physname */
1332   c_op_print_tab,               /* expression operators for printing */
1333   1,                            /* c-style arrays */
1334   0,                            /* String lower bound */
1335   default_word_break_characters,
1336   default_make_symbol_completion_list,
1337   c_language_arch_info, /* FIXME: la_language_arch_info.  */
1338   default_print_array_index,
1339   default_pass_by_reference,
1340   c_get_string,
1341   LANG_MAGIC
1342 };
1343
1344 /* The following language_defn does not represent a real language.
1345    It just provides a minimal support a-la-C that should allow users
1346    to do some simple operations when debugging applications that use
1347    a language currently not supported by GDB.  */
1348
1349 const struct language_defn minimal_language_defn =
1350 {
1351   "minimal",                    /* Language name */
1352   language_minimal,
1353   range_check_off,
1354   type_check_off,
1355   case_sensitive_on,
1356   array_row_major,
1357   macro_expansion_c,
1358   &exp_descriptor_c,
1359   c_parse,
1360   c_error,
1361   null_post_parser,
1362   c_printchar,                  /* Print a character constant */
1363   c_printstr,                   /* Function to print string constant */
1364   c_emit_char,                  /* Print a single char */
1365   c_print_type,                 /* Print a type using appropriate syntax */
1366   c_print_typedef,              /* Print a typedef using appropriate syntax */
1367   c_val_print,                  /* Print a value using appropriate syntax */
1368   c_value_print,                /* Print a top-level value */
1369   NULL,                         /* Language specific skip_trampoline */
1370   NULL,                         /* name_of_this */
1371   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
1372   basic_lookup_transparent_type,/* lookup_transparent_type */
1373   NULL,                         /* Language specific symbol demangler */
1374   NULL,                         /* Language specific class_name_from_physname */
1375   c_op_print_tab,               /* expression operators for printing */
1376   1,                            /* c-style arrays */
1377   0,                            /* String lower bound */
1378   default_word_break_characters,
1379   default_make_symbol_completion_list,
1380   c_language_arch_info,
1381   default_print_array_index,
1382   default_pass_by_reference,
1383   c_get_string,
1384   LANG_MAGIC
1385 };
1386
1387 void
1388 _initialize_c_language (void)
1389 {
1390   add_language (&c_language_defn);
1391   add_language (&cplus_language_defn);
1392   add_language (&asm_language_defn);
1393   add_language (&minimal_language_defn);
1394 }