119370Spst/* C language support routines for GDB, the GNU debugger.
2130803Smarcel   Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003, 2004
398944Sobrien   Free Software Foundation, Inc.
419370Spst
598944Sobrien   This file is part of GDB.
619370Spst
798944Sobrien   This program is free software; you can redistribute it and/or modify
898944Sobrien   it under the terms of the GNU General Public License as published by
998944Sobrien   the Free Software Foundation; either version 2 of the License, or
1098944Sobrien   (at your option) any later version.
1119370Spst
1298944Sobrien   This program is distributed in the hope that it will be useful,
1398944Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1498944Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1598944Sobrien   GNU General Public License for more details.
1619370Spst
1798944Sobrien   You should have received a copy of the GNU General Public License
1898944Sobrien   along with this program; if not, write to the Free Software
1998944Sobrien   Foundation, Inc., 59 Temple Place - Suite 330,
2098944Sobrien   Boston, MA 02111-1307, USA.  */
2119370Spst
2219370Spst#include "defs.h"
2319370Spst#include "symtab.h"
2419370Spst#include "gdbtypes.h"
2519370Spst#include "expression.h"
2619370Spst#include "parser-defs.h"
2719370Spst#include "language.h"
2819370Spst#include "c-lang.h"
2998944Sobrien#include "valprint.h"
30130803Smarcel#include "macroscope.h"
31130803Smarcel#include "gdb_assert.h"
32130803Smarcel#include "charset.h"
33130803Smarcel#include "gdb_string.h"
34130803Smarcel#include "demangle.h"
35130803Smarcel#include "cp-support.h"
3619370Spst
3798944Sobrienextern void _initialize_c_language (void);
3898944Sobrienstatic void c_emit_char (int c, struct ui_file * stream, int quoter);
3946283Sdfr
4019370Spst/* Print the character C on STREAM as part of the contents of a literal
4119370Spst   string whose delimiter is QUOTER.  Note that that format for printing
4219370Spst   characters and strings is language specific. */
4319370Spst
4419370Spststatic void
45130803Smarcelc_emit_char (int c, struct ui_file *stream, int quoter)
4619370Spst{
47130803Smarcel  const char *escape;
48130803Smarcel  int host_char;
49130803Smarcel
5019370Spst  c &= 0xFF;			/* Avoid sign bit follies */
5119370Spst
52130803Smarcel  escape = c_target_char_has_backslash_escape (c);
53130803Smarcel  if (escape)
5419370Spst    {
55130803Smarcel      if (quoter == '"' && strcmp (escape, "0") == 0)
56130803Smarcel	/* Print nulls embedded in double quoted strings as \000 to
57130803Smarcel	   prevent ambiguity.  */
58130803Smarcel	fprintf_filtered (stream, "\\000");
59130803Smarcel      else
60130803Smarcel	fprintf_filtered (stream, "\\%s", escape);
6119370Spst    }
62130803Smarcel  else if (target_char_to_host (c, &host_char)
63130803Smarcel           && host_char_print_literally (host_char))
6419370Spst    {
65130803Smarcel      if (host_char == '\\' || host_char == quoter)
66130803Smarcel        fputs_filtered ("\\", stream);
67130803Smarcel      fprintf_filtered (stream, "%c", host_char);
6819370Spst    }
69130803Smarcel  else
70130803Smarcel    fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
7119370Spst}
7219370Spst
7319370Spstvoid
7498944Sobrienc_printchar (int c, struct ui_file *stream)
7519370Spst{
7646283Sdfr  fputc_filtered ('\'', stream);
7746283Sdfr  LA_EMIT_CHAR (c, stream, '\'');
7846283Sdfr  fputc_filtered ('\'', stream);
7919370Spst}
8019370Spst
8119370Spst/* Print the character string STRING, printing at most LENGTH characters.
8246283Sdfr   LENGTH is -1 if the string is nul terminated.  Each character is WIDTH bytes
8346283Sdfr   long.  Printing stops early if the number hits print_max; repeat counts are
8446283Sdfr   printed as appropriate.  Print ellipses at the end if we had to stop before
8546283Sdfr   printing LENGTH characters, or if FORCE_ELLIPSES.  */
8619370Spst
8719370Spstvoid
8898944Sobrienc_printstr (struct ui_file *stream, char *string, unsigned int length,
8998944Sobrien	    int width, int force_ellipses)
9019370Spst{
91130803Smarcel  unsigned int i;
9219370Spst  unsigned int things_printed = 0;
9319370Spst  int in_quotes = 0;
9419370Spst  int need_comma = 0;
9519370Spst
9619370Spst  /* If the string was not truncated due to `set print elements', and
9719370Spst     the last byte of it is a null, we don't print that, in traditional C
9819370Spst     style.  */
9946283Sdfr  if (!force_ellipses
10046283Sdfr      && length > 0
10198944Sobrien      && (extract_unsigned_integer (string + (length - 1) * width, width)
10298944Sobrien          == '\0'))
10319370Spst    length--;
10419370Spst
10519370Spst  if (length == 0)
10619370Spst    {
10719370Spst      fputs_filtered ("\"\"", stream);
10819370Spst      return;
10919370Spst    }
11019370Spst
11119370Spst  for (i = 0; i < length && things_printed < print_max; ++i)
11219370Spst    {
11319370Spst      /* Position of the character we are examining
11498944Sobrien         to see whether it is repeated.  */
11519370Spst      unsigned int rep1;
11619370Spst      /* Number of repetitions we have detected so far.  */
11719370Spst      unsigned int reps;
11846283Sdfr      unsigned long current_char;
11919370Spst
12019370Spst      QUIT;
12119370Spst
12219370Spst      if (need_comma)
12319370Spst	{
12419370Spst	  fputs_filtered (", ", stream);
12519370Spst	  need_comma = 0;
12619370Spst	}
12719370Spst
12846283Sdfr      current_char = extract_unsigned_integer (string + i * width, width);
12946283Sdfr
13019370Spst      rep1 = i + 1;
13119370Spst      reps = 1;
13246283Sdfr      while (rep1 < length
13346283Sdfr	     && extract_unsigned_integer (string + rep1 * width, width)
13498944Sobrien	     == current_char)
13519370Spst	{
13619370Spst	  ++rep1;
13719370Spst	  ++reps;
13819370Spst	}
13919370Spst
14019370Spst      if (reps > repeat_count_threshold)
14119370Spst	{
14219370Spst	  if (in_quotes)
14319370Spst	    {
14419370Spst	      if (inspect_it)
14519370Spst		fputs_filtered ("\\\", ", stream);
14619370Spst	      else
14719370Spst		fputs_filtered ("\", ", stream);
14819370Spst	      in_quotes = 0;
14919370Spst	    }
15046283Sdfr	  LA_PRINT_CHAR (current_char, stream);
15119370Spst	  fprintf_filtered (stream, " <repeats %u times>", reps);
15219370Spst	  i = rep1 - 1;
15319370Spst	  things_printed += repeat_count_threshold;
15419370Spst	  need_comma = 1;
15519370Spst	}
15619370Spst      else
15719370Spst	{
15819370Spst	  if (!in_quotes)
15919370Spst	    {
16019370Spst	      if (inspect_it)
16119370Spst		fputs_filtered ("\\\"", stream);
16219370Spst	      else
16319370Spst		fputs_filtered ("\"", stream);
16419370Spst	      in_quotes = 1;
16519370Spst	    }
16646283Sdfr	  LA_EMIT_CHAR (current_char, stream, '"');
16719370Spst	  ++things_printed;
16819370Spst	}
16919370Spst    }
17019370Spst
17119370Spst  /* Terminate the quotes if necessary.  */
17219370Spst  if (in_quotes)
17319370Spst    {
17419370Spst      if (inspect_it)
17519370Spst	fputs_filtered ("\\\"", stream);
17619370Spst      else
17719370Spst	fputs_filtered ("\"", stream);
17819370Spst    }
17919370Spst
18019370Spst  if (force_ellipses || i < length)
18119370Spst    fputs_filtered ("...", stream);
18219370Spst}
18319370Spst
18419370Spst/* Create a fundamental C type using default reasonable for the current
18519370Spst   target machine.
18619370Spst
18719370Spst   Some object/debugging file formats (DWARF version 1, COFF, etc) do not
18819370Spst   define fundamental types such as "int" or "double".  Others (stabs or
18919370Spst   DWARF version 2, etc) do define fundamental types.  For the formats which
19019370Spst   don't provide fundamental types, gdb can create such types using this
19119370Spst   function.
19219370Spst
19319370Spst   FIXME:  Some compilers distinguish explicitly signed integral types
19419370Spst   (signed short, signed int, signed long) from "regular" integral types
19519370Spst   (short, int, long) in the debugging information.  There is some dis-
19619370Spst   agreement as to how useful this feature is.  In particular, gcc does
19719370Spst   not support this.  Also, only some debugging formats allow the
19819370Spst   distinction to be passed on to a debugger.  For now, we always just
19919370Spst   use "short", "int", or "long" as the type name, for both the implicit
20019370Spst   and explicitly signed types.  This also makes life easier for the
20119370Spst   gdb test suite since we don't have to account for the differences
20219370Spst   in output depending upon what the compiler and debugging format
20319370Spst   support.  We will probably have to re-examine the issue when gdb
20419370Spst   starts taking it's fundamental type information directly from the
20519370Spst   debugging information supplied by the compiler.  fnf@cygnus.com */
20619370Spst
20719370Spststruct type *
20898944Sobrienc_create_fundamental_type (struct objfile *objfile, int typeid)
20919370Spst{
210130803Smarcel  struct type *type = NULL;
21119370Spst
21219370Spst  switch (typeid)
21319370Spst    {
21498944Sobrien    default:
21598944Sobrien      /* FIXME:  For now, if we are asked to produce a type not in this
21698944Sobrien         language, create the equivalent of a C integer type with the
21798944Sobrien         name "<?type?>".  When all the dust settles from the type
21898944Sobrien         reconstruction work, this should probably become an error. */
21998944Sobrien      type = init_type (TYPE_CODE_INT,
22098944Sobrien			TARGET_INT_BIT / TARGET_CHAR_BIT,
22198944Sobrien			0, "<?type?>", objfile);
22298944Sobrien      warning ("internal error: no C/C++ fundamental type %d", typeid);
22398944Sobrien      break;
22498944Sobrien    case FT_VOID:
22598944Sobrien      type = init_type (TYPE_CODE_VOID,
22698944Sobrien			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
22798944Sobrien			0, "void", objfile);
22898944Sobrien      break;
22998944Sobrien    case FT_BOOLEAN:
23098944Sobrien      type = init_type (TYPE_CODE_BOOL,
23198944Sobrien			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
23298944Sobrien			0, "bool", objfile);
23398944Sobrien      break;
23498944Sobrien    case FT_CHAR:
23598944Sobrien      type = init_type (TYPE_CODE_INT,
23698944Sobrien			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
23798944Sobrien			TYPE_FLAG_NOSIGN, "char", objfile);
23898944Sobrien      break;
23998944Sobrien    case FT_SIGNED_CHAR:
24098944Sobrien      type = init_type (TYPE_CODE_INT,
24198944Sobrien			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
24298944Sobrien			0, "signed char", objfile);
24398944Sobrien      break;
24498944Sobrien    case FT_UNSIGNED_CHAR:
24598944Sobrien      type = init_type (TYPE_CODE_INT,
24698944Sobrien			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
24798944Sobrien			TYPE_FLAG_UNSIGNED, "unsigned char", objfile);
24898944Sobrien      break;
24998944Sobrien    case FT_SHORT:
25098944Sobrien      type = init_type (TYPE_CODE_INT,
25198944Sobrien			TARGET_SHORT_BIT / TARGET_CHAR_BIT,
25298944Sobrien			0, "short", objfile);
25398944Sobrien      break;
25498944Sobrien    case FT_SIGNED_SHORT:
25598944Sobrien      type = init_type (TYPE_CODE_INT,
25698944Sobrien			TARGET_SHORT_BIT / TARGET_CHAR_BIT,
25798944Sobrien			0, "short", objfile);	/* FIXME-fnf */
25898944Sobrien      break;
25998944Sobrien    case FT_UNSIGNED_SHORT:
26098944Sobrien      type = init_type (TYPE_CODE_INT,
26198944Sobrien			TARGET_SHORT_BIT / TARGET_CHAR_BIT,
26298944Sobrien			TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
26398944Sobrien      break;
26498944Sobrien    case FT_INTEGER:
26598944Sobrien      type = init_type (TYPE_CODE_INT,
26698944Sobrien			TARGET_INT_BIT / TARGET_CHAR_BIT,
26798944Sobrien			0, "int", objfile);
26898944Sobrien      break;
26998944Sobrien    case FT_SIGNED_INTEGER:
27098944Sobrien      type = init_type (TYPE_CODE_INT,
27198944Sobrien			TARGET_INT_BIT / TARGET_CHAR_BIT,
27298944Sobrien			0, "int", objfile);	/* FIXME -fnf */
27398944Sobrien      break;
27498944Sobrien    case FT_UNSIGNED_INTEGER:
27598944Sobrien      type = init_type (TYPE_CODE_INT,
27698944Sobrien			TARGET_INT_BIT / TARGET_CHAR_BIT,
27798944Sobrien			TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
27898944Sobrien      break;
27998944Sobrien    case FT_LONG:
28098944Sobrien      type = init_type (TYPE_CODE_INT,
28198944Sobrien			TARGET_LONG_BIT / TARGET_CHAR_BIT,
28298944Sobrien			0, "long", objfile);
28398944Sobrien      break;
28498944Sobrien    case FT_SIGNED_LONG:
28598944Sobrien      type = init_type (TYPE_CODE_INT,
28698944Sobrien			TARGET_LONG_BIT / TARGET_CHAR_BIT,
28798944Sobrien			0, "long", objfile);	/* FIXME -fnf */
28898944Sobrien      break;
28998944Sobrien    case FT_UNSIGNED_LONG:
29098944Sobrien      type = init_type (TYPE_CODE_INT,
29198944Sobrien			TARGET_LONG_BIT / TARGET_CHAR_BIT,
29298944Sobrien			TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
29398944Sobrien      break;
29498944Sobrien    case FT_LONG_LONG:
29598944Sobrien      type = init_type (TYPE_CODE_INT,
29698944Sobrien			TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
29798944Sobrien			0, "long long", objfile);
29898944Sobrien      break;
29998944Sobrien    case FT_SIGNED_LONG_LONG:
30098944Sobrien      type = init_type (TYPE_CODE_INT,
30198944Sobrien			TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
30298944Sobrien			0, "signed long long", objfile);
30398944Sobrien      break;
30498944Sobrien    case FT_UNSIGNED_LONG_LONG:
30598944Sobrien      type = init_type (TYPE_CODE_INT,
30698944Sobrien			TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
30798944Sobrien			TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
30898944Sobrien      break;
30998944Sobrien    case FT_FLOAT:
31098944Sobrien      type = init_type (TYPE_CODE_FLT,
31198944Sobrien			TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
31298944Sobrien			0, "float", objfile);
31398944Sobrien      break;
31498944Sobrien    case FT_DBL_PREC_FLOAT:
31598944Sobrien      type = init_type (TYPE_CODE_FLT,
31698944Sobrien			TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
31798944Sobrien			0, "double", objfile);
31898944Sobrien      break;
31998944Sobrien    case FT_EXT_PREC_FLOAT:
32098944Sobrien      type = init_type (TYPE_CODE_FLT,
32198944Sobrien			TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
32298944Sobrien			0, "long double", objfile);
32398944Sobrien      break;
324130803Smarcel    case FT_COMPLEX:
325130803Smarcel      type = init_type (TYPE_CODE_FLT,
326130803Smarcel			2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
327130803Smarcel			0, "complex float", objfile);
328130803Smarcel      TYPE_TARGET_TYPE (type)
329130803Smarcel	= init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
330130803Smarcel		     0, "float", objfile);
331130803Smarcel      break;
332130803Smarcel    case FT_DBL_PREC_COMPLEX:
333130803Smarcel      type = init_type (TYPE_CODE_FLT,
334130803Smarcel			2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
335130803Smarcel			0, "complex double", objfile);
336130803Smarcel      TYPE_TARGET_TYPE (type)
337130803Smarcel	= init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
338130803Smarcel		     0, "double", objfile);
339130803Smarcel      break;
340130803Smarcel    case FT_EXT_PREC_COMPLEX:
341130803Smarcel      type = init_type (TYPE_CODE_FLT,
342130803Smarcel			2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
343130803Smarcel			0, "complex long double", objfile);
344130803Smarcel      TYPE_TARGET_TYPE (type)
345130803Smarcel	= init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
346130803Smarcel		     0, "long double", objfile);
347130803Smarcel      break;
34898944Sobrien    case FT_TEMPLATE_ARG:
34998944Sobrien      type = init_type (TYPE_CODE_TEMPLATE_ARG,
35098944Sobrien			0,
35198944Sobrien			0, "<template arg>", objfile);
35298944Sobrien      break;
35398944Sobrien    }
35419370Spst  return (type);
35519370Spst}
35698944Sobrien
357130803Smarcel/* Preprocessing and parsing C and C++ expressions.  */
35819370Spst
359130803Smarcel
360130803Smarcel/* When we find that lexptr (the global var defined in parse.c) is
361130803Smarcel   pointing at a macro invocation, we expand the invocation, and call
362130803Smarcel   scan_macro_expansion to save the old lexptr here and point lexptr
363130803Smarcel   into the expanded text.  When we reach the end of that, we call
364130803Smarcel   end_macro_expansion to pop back to the value we saved here.  The
365130803Smarcel   macro expansion code promises to return only fully-expanded text,
366130803Smarcel   so we don't need to "push" more than one level.
367130803Smarcel
368130803Smarcel   This is disgusting, of course.  It would be cleaner to do all macro
369130803Smarcel   expansion beforehand, and then hand that to lexptr.  But we don't
370130803Smarcel   really know where the expression ends.  Remember, in a command like
371130803Smarcel
372130803Smarcel     (gdb) break *ADDRESS if CONDITION
373130803Smarcel
374130803Smarcel   we evaluate ADDRESS in the scope of the current frame, but we
375130803Smarcel   evaluate CONDITION in the scope of the breakpoint's location.  So
376130803Smarcel   it's simply wrong to try to macro-expand the whole thing at once.  */
377130803Smarcelstatic char *macro_original_text;
378130803Smarcelstatic char *macro_expanded_text;
379130803Smarcel
380130803Smarcel
381130803Smarcelvoid
382130803Smarcelscan_macro_expansion (char *expansion)
383130803Smarcel{
384130803Smarcel  /* We'd better not be trying to push the stack twice.  */
385130803Smarcel  gdb_assert (! macro_original_text);
386130803Smarcel  gdb_assert (! macro_expanded_text);
387130803Smarcel
388130803Smarcel  /* Save the old lexptr value, so we can return to it when we're done
389130803Smarcel     parsing the expanded text.  */
390130803Smarcel  macro_original_text = lexptr;
391130803Smarcel  lexptr = expansion;
392130803Smarcel
393130803Smarcel  /* Save the expanded text, so we can free it when we're finished.  */
394130803Smarcel  macro_expanded_text = expansion;
395130803Smarcel}
396130803Smarcel
397130803Smarcel
398130803Smarcelint
399130803Smarcelscanning_macro_expansion (void)
400130803Smarcel{
401130803Smarcel  return macro_original_text != 0;
402130803Smarcel}
403130803Smarcel
404130803Smarcel
405130803Smarcelvoid
406130803Smarcelfinished_macro_expansion (void)
407130803Smarcel{
408130803Smarcel  /* There'd better be something to pop back to, and we better have
409130803Smarcel     saved a pointer to the start of the expanded text.  */
410130803Smarcel  gdb_assert (macro_original_text);
411130803Smarcel  gdb_assert (macro_expanded_text);
412130803Smarcel
413130803Smarcel  /* Pop back to the original text.  */
414130803Smarcel  lexptr = macro_original_text;
415130803Smarcel  macro_original_text = 0;
416130803Smarcel
417130803Smarcel  /* Free the expanded text.  */
418130803Smarcel  xfree (macro_expanded_text);
419130803Smarcel  macro_expanded_text = 0;
420130803Smarcel}
421130803Smarcel
422130803Smarcel
423130803Smarcelstatic void
424130803Smarcelscan_macro_cleanup (void *dummy)
425130803Smarcel{
426130803Smarcel  if (macro_original_text)
427130803Smarcel    finished_macro_expansion ();
428130803Smarcel}
429130803Smarcel
430130803Smarcel
431130803Smarcel/* We set these global variables before calling c_parse, to tell it
432130803Smarcel   how it to find macro definitions for the expression at hand.  */
433130803Smarcelmacro_lookup_ftype *expression_macro_lookup_func;
434130803Smarcelvoid *expression_macro_lookup_baton;
435130803Smarcel
436130803Smarcel
437130803Smarcelstatic struct macro_definition *
438130803Smarcelnull_macro_lookup (const char *name, void *baton)
439130803Smarcel{
440130803Smarcel  return 0;
441130803Smarcel}
442130803Smarcel
443130803Smarcel
444130803Smarcelstatic int
445130803Smarcelc_preprocess_and_parse (void)
446130803Smarcel{
447130803Smarcel  /* Set up a lookup function for the macro expander.  */
448130803Smarcel  struct macro_scope *scope = 0;
449130803Smarcel  struct cleanup *back_to = make_cleanup (free_current_contents, &scope);
450130803Smarcel
451130803Smarcel  if (expression_context_block)
452130803Smarcel    scope = sal_macro_scope (find_pc_line (expression_context_pc, 0));
453130803Smarcel  else
454130803Smarcel    scope = default_macro_scope ();
455130803Smarcel
456130803Smarcel  if (scope)
457130803Smarcel    {
458130803Smarcel      expression_macro_lookup_func = standard_macro_lookup;
459130803Smarcel      expression_macro_lookup_baton = (void *) scope;
460130803Smarcel    }
461130803Smarcel  else
462130803Smarcel    {
463130803Smarcel      expression_macro_lookup_func = null_macro_lookup;
464130803Smarcel      expression_macro_lookup_baton = 0;
465130803Smarcel    }
466130803Smarcel
467130803Smarcel  gdb_assert (! macro_original_text);
468130803Smarcel  make_cleanup (scan_macro_cleanup, 0);
469130803Smarcel
470130803Smarcel  {
471130803Smarcel    int result = c_parse ();
472130803Smarcel    do_cleanups (back_to);
473130803Smarcel    return result;
474130803Smarcel  }
475130803Smarcel}
476130803Smarcel
477130803Smarcel
478130803Smarcel
47919370Spst/* Table mapping opcodes into strings for printing operators
48019370Spst   and precedences of the operators.  */
48119370Spst
48219370Spstconst struct op_print c_op_print_tab[] =
48398944Sobrien{
48498944Sobrien  {",", BINOP_COMMA, PREC_COMMA, 0},
48598944Sobrien  {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
48698944Sobrien  {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
48798944Sobrien  {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
48898944Sobrien  {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
48998944Sobrien  {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
49098944Sobrien  {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
49198944Sobrien  {"==", BINOP_EQUAL, PREC_EQUAL, 0},
49298944Sobrien  {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
49398944Sobrien  {"<=", BINOP_LEQ, PREC_ORDER, 0},
49498944Sobrien  {">=", BINOP_GEQ, PREC_ORDER, 0},
49598944Sobrien  {">", BINOP_GTR, PREC_ORDER, 0},
49698944Sobrien  {"<", BINOP_LESS, PREC_ORDER, 0},
49798944Sobrien  {">>", BINOP_RSH, PREC_SHIFT, 0},
49898944Sobrien  {"<<", BINOP_LSH, PREC_SHIFT, 0},
49998944Sobrien  {"+", BINOP_ADD, PREC_ADD, 0},
50098944Sobrien  {"-", BINOP_SUB, PREC_ADD, 0},
50198944Sobrien  {"*", BINOP_MUL, PREC_MUL, 0},
50298944Sobrien  {"/", BINOP_DIV, PREC_MUL, 0},
50398944Sobrien  {"%", BINOP_REM, PREC_MUL, 0},
50498944Sobrien  {"@", BINOP_REPEAT, PREC_REPEAT, 0},
50598944Sobrien  {"-", UNOP_NEG, PREC_PREFIX, 0},
50698944Sobrien  {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
50798944Sobrien  {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
50898944Sobrien  {"*", UNOP_IND, PREC_PREFIX, 0},
50998944Sobrien  {"&", UNOP_ADDR, PREC_PREFIX, 0},
51098944Sobrien  {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
51198944Sobrien  {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
51298944Sobrien  {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
51398944Sobrien  {NULL, 0, 0, 0}
51419370Spst};
51519370Spst
51698944Sobrienstruct type **const (c_builtin_types[]) =
51719370Spst{
51819370Spst  &builtin_type_int,
51919370Spst  &builtin_type_long,
52019370Spst  &builtin_type_short,
52119370Spst  &builtin_type_char,
52219370Spst  &builtin_type_float,
52319370Spst  &builtin_type_double,
52419370Spst  &builtin_type_void,
52519370Spst  &builtin_type_long_long,
52619370Spst  &builtin_type_signed_char,
52719370Spst  &builtin_type_unsigned_char,
52819370Spst  &builtin_type_unsigned_short,
52919370Spst  &builtin_type_unsigned_int,
53019370Spst  &builtin_type_unsigned_long,
53119370Spst  &builtin_type_unsigned_long_long,
53219370Spst  &builtin_type_long_double,
53319370Spst  &builtin_type_complex,
53419370Spst  &builtin_type_double_complex,
53519370Spst  0
53619370Spst};
53719370Spst
53898944Sobrienconst struct language_defn c_language_defn =
53998944Sobrien{
54019370Spst  "c",				/* Language name */
54119370Spst  language_c,
54219370Spst  c_builtin_types,
54319370Spst  range_check_off,
54419370Spst  type_check_off,
54598944Sobrien  case_sensitive_on,
546130803Smarcel  &exp_descriptor_standard,
547130803Smarcel  c_preprocess_and_parse,
54819370Spst  c_error,
54919370Spst  c_printchar,			/* Print a character constant */
55019370Spst  c_printstr,			/* Function to print string constant */
55146283Sdfr  c_emit_char,			/* Print a single char */
55219370Spst  c_create_fundamental_type,	/* Create fundamental type in this language */
55319370Spst  c_print_type,			/* Print a type using appropriate syntax */
55419370Spst  c_val_print,			/* Print a value using appropriate syntax */
55519370Spst  c_value_print,		/* Print a top-level value */
556130803Smarcel  NULL,				/* Language specific skip_trampoline */
557130803Smarcel  NULL,				/* value_of_this */
558130803Smarcel  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
559130803Smarcel  basic_lookup_transparent_type,/* lookup_transparent_type */
560130803Smarcel  NULL,				/* Language specific symbol demangler */
56198944Sobrien  {"", "", "", ""},		/* Binary format info */
56298944Sobrien  {"0%lo", "0", "o", ""},	/* Octal format info */
56398944Sobrien  {"%ld", "", "d", ""},		/* Decimal format info */
56498944Sobrien  {"0x%lx", "0x", "x", ""},	/* Hex format info */
56519370Spst  c_op_print_tab,		/* expression operators for printing */
56619370Spst  1,				/* c-style arrays */
56719370Spst  0,				/* String lower bound */
56898944Sobrien  &builtin_type_char,		/* Type of string elements */
569130803Smarcel  default_word_break_characters,
57019370Spst  LANG_MAGIC
57119370Spst};
57219370Spst
57398944Sobrienstruct type **const (cplus_builtin_types[]) =
57446283Sdfr{
57546283Sdfr  &builtin_type_int,
57646283Sdfr  &builtin_type_long,
57746283Sdfr  &builtin_type_short,
57846283Sdfr  &builtin_type_char,
57946283Sdfr  &builtin_type_float,
58046283Sdfr  &builtin_type_double,
58146283Sdfr  &builtin_type_void,
58246283Sdfr  &builtin_type_long_long,
58346283Sdfr  &builtin_type_signed_char,
58446283Sdfr  &builtin_type_unsigned_char,
58546283Sdfr  &builtin_type_unsigned_short,
58646283Sdfr  &builtin_type_unsigned_int,
58746283Sdfr  &builtin_type_unsigned_long,
58846283Sdfr  &builtin_type_unsigned_long_long,
58946283Sdfr  &builtin_type_long_double,
59046283Sdfr  &builtin_type_complex,
59146283Sdfr  &builtin_type_double_complex,
59246283Sdfr  &builtin_type_bool,
59346283Sdfr  0
59446283Sdfr};
59546283Sdfr
59698944Sobrienconst struct language_defn cplus_language_defn =
59798944Sobrien{
59898944Sobrien  "c++",			/* Language name */
59919370Spst  language_cplus,
60046283Sdfr  cplus_builtin_types,
60119370Spst  range_check_off,
60219370Spst  type_check_off,
60398944Sobrien  case_sensitive_on,
604130803Smarcel  &exp_descriptor_standard,
605130803Smarcel  c_preprocess_and_parse,
60619370Spst  c_error,
60719370Spst  c_printchar,			/* Print a character constant */
60819370Spst  c_printstr,			/* Function to print string constant */
60946283Sdfr  c_emit_char,			/* Print a single char */
61019370Spst  c_create_fundamental_type,	/* Create fundamental type in this language */
61119370Spst  c_print_type,			/* Print a type using appropriate syntax */
61219370Spst  c_val_print,			/* Print a value using appropriate syntax */
61319370Spst  c_value_print,		/* Print a top-level value */
614130803Smarcel  NULL,				/* Language specific skip_trampoline */
615130803Smarcel  value_of_this,		/* value_of_this */
616130803Smarcel  cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
617130803Smarcel  cp_lookup_transparent_type,   /* lookup_transparent_type */
618130803Smarcel  cplus_demangle,		/* Language specific symbol demangler */
61998944Sobrien  {"", "", "", ""},		/* Binary format info */
62098944Sobrien  {"0%lo", "0", "o", ""},	/* Octal format info */
62198944Sobrien  {"%ld", "", "d", ""},		/* Decimal format info */
62298944Sobrien  {"0x%lx", "0x", "x", ""},	/* Hex format info */
62319370Spst  c_op_print_tab,		/* expression operators for printing */
62419370Spst  1,				/* c-style arrays */
62519370Spst  0,				/* String lower bound */
62698944Sobrien  &builtin_type_char,		/* Type of string elements */
627130803Smarcel  default_word_break_characters,
62819370Spst  LANG_MAGIC
62919370Spst};
63019370Spst
63198944Sobrienconst struct language_defn asm_language_defn =
63298944Sobrien{
63319370Spst  "asm",			/* Language name */
63419370Spst  language_asm,
63519370Spst  c_builtin_types,
63619370Spst  range_check_off,
63719370Spst  type_check_off,
63898944Sobrien  case_sensitive_on,
639130803Smarcel  &exp_descriptor_standard,
640130803Smarcel  c_preprocess_and_parse,
64119370Spst  c_error,
64219370Spst  c_printchar,			/* Print a character constant */
64319370Spst  c_printstr,			/* Function to print string constant */
64446283Sdfr  c_emit_char,			/* Print a single char */
64519370Spst  c_create_fundamental_type,	/* Create fundamental type in this language */
64619370Spst  c_print_type,			/* Print a type using appropriate syntax */
64719370Spst  c_val_print,			/* Print a value using appropriate syntax */
64819370Spst  c_value_print,		/* Print a top-level value */
649130803Smarcel  NULL,				/* Language specific skip_trampoline */
650130803Smarcel  NULL,				/* value_of_this */
651130803Smarcel  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
652130803Smarcel  basic_lookup_transparent_type,/* lookup_transparent_type */
653130803Smarcel  NULL,				/* Language specific symbol demangler */
65498944Sobrien  {"", "", "", ""},		/* Binary format info */
65598944Sobrien  {"0%lo", "0", "o", ""},	/* Octal format info */
65698944Sobrien  {"%ld", "", "d", ""},		/* Decimal format info */
65798944Sobrien  {"0x%lx", "0x", "x", ""},	/* Hex format info */
65819370Spst  c_op_print_tab,		/* expression operators for printing */
65919370Spst  1,				/* c-style arrays */
66019370Spst  0,				/* String lower bound */
66198944Sobrien  &builtin_type_char,		/* Type of string elements */
662130803Smarcel  default_word_break_characters,
66319370Spst  LANG_MAGIC
66419370Spst};
66519370Spst
666130803Smarcel/* The following language_defn does not represent a real language.
667130803Smarcel   It just provides a minimal support a-la-C that should allow users
668130803Smarcel   to do some simple operations when debugging applications that use
669130803Smarcel   a language currently not supported by GDB.  */
670130803Smarcel
671130803Smarcelconst struct language_defn minimal_language_defn =
672130803Smarcel{
673130803Smarcel  "minimal",			/* Language name */
674130803Smarcel  language_minimal,
675130803Smarcel  c_builtin_types,
676130803Smarcel  range_check_off,
677130803Smarcel  type_check_off,
678130803Smarcel  case_sensitive_on,
679130803Smarcel  &exp_descriptor_standard,
680130803Smarcel  c_preprocess_and_parse,
681130803Smarcel  c_error,
682130803Smarcel  c_printchar,			/* Print a character constant */
683130803Smarcel  c_printstr,			/* Function to print string constant */
684130803Smarcel  c_emit_char,			/* Print a single char */
685130803Smarcel  c_create_fundamental_type,	/* Create fundamental type in this language */
686130803Smarcel  c_print_type,			/* Print a type using appropriate syntax */
687130803Smarcel  c_val_print,			/* Print a value using appropriate syntax */
688130803Smarcel  c_value_print,		/* Print a top-level value */
689130803Smarcel  NULL,				/* Language specific skip_trampoline */
690130803Smarcel  NULL,				/* value_of_this */
691130803Smarcel  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
692130803Smarcel  basic_lookup_transparent_type,/* lookup_transparent_type */
693130803Smarcel  NULL,				/* Language specific symbol demangler */
694130803Smarcel  {"", "", "", ""},		/* Binary format info */
695130803Smarcel  {"0%lo", "0", "o", ""},	/* Octal format info */
696130803Smarcel  {"%ld", "", "d", ""},		/* Decimal format info */
697130803Smarcel  {"0x%lx", "0x", "x", ""},	/* Hex format info */
698130803Smarcel  c_op_print_tab,		/* expression operators for printing */
699130803Smarcel  1,				/* c-style arrays */
700130803Smarcel  0,				/* String lower bound */
701130803Smarcel  &builtin_type_char,		/* Type of string elements */
702130803Smarcel  default_word_break_characters,
703130803Smarcel  LANG_MAGIC
704130803Smarcel};
705130803Smarcel
70619370Spstvoid
70798944Sobrien_initialize_c_language (void)
70819370Spst{
70919370Spst  add_language (&c_language_defn);
71019370Spst  add_language (&cplus_language_defn);
71119370Spst  add_language (&asm_language_defn);
712130803Smarcel  add_language (&minimal_language_defn);
71319370Spst}
714