xref: /dflybsd-src/contrib/gdb-7/gdb/m2-lang.c (revision a45ae5f869d9cfcb3e41dbab486e10bfa9e336bf)
15796c8dcSSimon Schubert /* Modula 2 language support routines for GDB, the GNU debugger.
25796c8dcSSimon Schubert 
3*a45ae5f8SJohn Marino    Copyright (C) 1992-1996, 1998, 2000, 2002-2005, 2007-2012 Free
4*a45ae5f8SJohn Marino    Software Foundation, Inc.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    This file is part of GDB.
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
95796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
105796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
115796c8dcSSimon Schubert    (at your option) any later version.
125796c8dcSSimon Schubert 
135796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
145796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
155796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165796c8dcSSimon Schubert    GNU General Public License for more details.
175796c8dcSSimon Schubert 
185796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
195796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
205796c8dcSSimon Schubert 
215796c8dcSSimon Schubert #include "defs.h"
225796c8dcSSimon Schubert #include "symtab.h"
235796c8dcSSimon Schubert #include "gdbtypes.h"
245796c8dcSSimon Schubert #include "expression.h"
255796c8dcSSimon Schubert #include "parser-defs.h"
265796c8dcSSimon Schubert #include "language.h"
275796c8dcSSimon Schubert #include "m2-lang.h"
285796c8dcSSimon Schubert #include "c-lang.h"
295796c8dcSSimon Schubert #include "valprint.h"
305796c8dcSSimon Schubert 
315796c8dcSSimon Schubert extern void _initialize_m2_language (void);
325796c8dcSSimon Schubert static void m2_printchar (int, struct type *, struct ui_file *);
335796c8dcSSimon Schubert static void m2_emit_char (int, struct type *, struct ui_file *, int);
345796c8dcSSimon Schubert 
355796c8dcSSimon Schubert /* Print the character C on STREAM as part of the contents of a literal
365796c8dcSSimon Schubert    string whose delimiter is QUOTER.  Note that that format for printing
375796c8dcSSimon Schubert    characters and strings is language specific.
385796c8dcSSimon Schubert    FIXME:  This is a copy of the same function from c-exp.y.  It should
395796c8dcSSimon Schubert    be replaced with a true Modula version.  */
405796c8dcSSimon Schubert 
415796c8dcSSimon Schubert static void
425796c8dcSSimon Schubert m2_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
435796c8dcSSimon Schubert {
445796c8dcSSimon Schubert 
45c50c785cSJohn Marino   c &= 0xFF;			/* Avoid sign bit follies.  */
465796c8dcSSimon Schubert 
475796c8dcSSimon Schubert   if (PRINT_LITERAL_FORM (c))
485796c8dcSSimon Schubert     {
495796c8dcSSimon Schubert       if (c == '\\' || c == quoter)
505796c8dcSSimon Schubert 	{
515796c8dcSSimon Schubert 	  fputs_filtered ("\\", stream);
525796c8dcSSimon Schubert 	}
535796c8dcSSimon Schubert       fprintf_filtered (stream, "%c", c);
545796c8dcSSimon Schubert     }
555796c8dcSSimon Schubert   else
565796c8dcSSimon Schubert     {
575796c8dcSSimon Schubert       switch (c)
585796c8dcSSimon Schubert 	{
595796c8dcSSimon Schubert 	case '\n':
605796c8dcSSimon Schubert 	  fputs_filtered ("\\n", stream);
615796c8dcSSimon Schubert 	  break;
625796c8dcSSimon Schubert 	case '\b':
635796c8dcSSimon Schubert 	  fputs_filtered ("\\b", stream);
645796c8dcSSimon Schubert 	  break;
655796c8dcSSimon Schubert 	case '\t':
665796c8dcSSimon Schubert 	  fputs_filtered ("\\t", stream);
675796c8dcSSimon Schubert 	  break;
685796c8dcSSimon Schubert 	case '\f':
695796c8dcSSimon Schubert 	  fputs_filtered ("\\f", stream);
705796c8dcSSimon Schubert 	  break;
715796c8dcSSimon Schubert 	case '\r':
725796c8dcSSimon Schubert 	  fputs_filtered ("\\r", stream);
735796c8dcSSimon Schubert 	  break;
745796c8dcSSimon Schubert 	case '\033':
755796c8dcSSimon Schubert 	  fputs_filtered ("\\e", stream);
765796c8dcSSimon Schubert 	  break;
775796c8dcSSimon Schubert 	case '\007':
785796c8dcSSimon Schubert 	  fputs_filtered ("\\a", stream);
795796c8dcSSimon Schubert 	  break;
805796c8dcSSimon Schubert 	default:
815796c8dcSSimon Schubert 	  fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
825796c8dcSSimon Schubert 	  break;
835796c8dcSSimon Schubert 	}
845796c8dcSSimon Schubert     }
855796c8dcSSimon Schubert }
865796c8dcSSimon Schubert 
875796c8dcSSimon Schubert /* FIXME:  This is a copy of the same function from c-exp.y.  It should
885796c8dcSSimon Schubert    be replaced with a true Modula version.  */
895796c8dcSSimon Schubert 
905796c8dcSSimon Schubert static void
915796c8dcSSimon Schubert m2_printchar (int c, struct type *type, struct ui_file *stream)
925796c8dcSSimon Schubert {
935796c8dcSSimon Schubert   fputs_filtered ("'", stream);
945796c8dcSSimon Schubert   LA_EMIT_CHAR (c, type, stream, '\'');
955796c8dcSSimon Schubert   fputs_filtered ("'", stream);
965796c8dcSSimon Schubert }
975796c8dcSSimon Schubert 
985796c8dcSSimon Schubert /* Print the character string STRING, printing at most LENGTH characters.
995796c8dcSSimon Schubert    Printing stops early if the number hits print_max; repeat counts
1005796c8dcSSimon Schubert    are printed as appropriate.  Print ellipses at the end if we
1015796c8dcSSimon Schubert    had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
1025796c8dcSSimon Schubert    FIXME:  This is a copy of the same function from c-exp.y.  It should
1035796c8dcSSimon Schubert    be replaced with a true Modula version.  */
1045796c8dcSSimon Schubert 
1055796c8dcSSimon Schubert static void
1065796c8dcSSimon Schubert m2_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
107cf7f2e2dSJohn Marino 	     unsigned int length, const char *encoding, int force_ellipses,
1085796c8dcSSimon Schubert 	     const struct value_print_options *options)
1095796c8dcSSimon Schubert {
1105796c8dcSSimon Schubert   unsigned int i;
1115796c8dcSSimon Schubert   unsigned int things_printed = 0;
1125796c8dcSSimon Schubert   int in_quotes = 0;
1135796c8dcSSimon Schubert   int need_comma = 0;
1145796c8dcSSimon Schubert 
1155796c8dcSSimon Schubert   if (length == 0)
1165796c8dcSSimon Schubert     {
1175796c8dcSSimon Schubert       fputs_filtered ("\"\"", gdb_stdout);
1185796c8dcSSimon Schubert       return;
1195796c8dcSSimon Schubert     }
1205796c8dcSSimon Schubert 
1215796c8dcSSimon Schubert   for (i = 0; i < length && things_printed < options->print_max; ++i)
1225796c8dcSSimon Schubert     {
1235796c8dcSSimon Schubert       /* Position of the character we are examining
1245796c8dcSSimon Schubert          to see whether it is repeated.  */
1255796c8dcSSimon Schubert       unsigned int rep1;
1265796c8dcSSimon Schubert       /* Number of repetitions we have detected so far.  */
1275796c8dcSSimon Schubert       unsigned int reps;
1285796c8dcSSimon Schubert 
1295796c8dcSSimon Schubert       QUIT;
1305796c8dcSSimon Schubert 
1315796c8dcSSimon Schubert       if (need_comma)
1325796c8dcSSimon Schubert 	{
1335796c8dcSSimon Schubert 	  fputs_filtered (", ", stream);
1345796c8dcSSimon Schubert 	  need_comma = 0;
1355796c8dcSSimon Schubert 	}
1365796c8dcSSimon Schubert 
1375796c8dcSSimon Schubert       rep1 = i + 1;
1385796c8dcSSimon Schubert       reps = 1;
1395796c8dcSSimon Schubert       while (rep1 < length && string[rep1] == string[i])
1405796c8dcSSimon Schubert 	{
1415796c8dcSSimon Schubert 	  ++rep1;
1425796c8dcSSimon Schubert 	  ++reps;
1435796c8dcSSimon Schubert 	}
1445796c8dcSSimon Schubert 
1455796c8dcSSimon Schubert       if (reps > options->repeat_count_threshold)
1465796c8dcSSimon Schubert 	{
1475796c8dcSSimon Schubert 	  if (in_quotes)
1485796c8dcSSimon Schubert 	    {
1495796c8dcSSimon Schubert 	      if (options->inspect_it)
1505796c8dcSSimon Schubert 		fputs_filtered ("\\\", ", stream);
1515796c8dcSSimon Schubert 	      else
1525796c8dcSSimon Schubert 		fputs_filtered ("\", ", stream);
1535796c8dcSSimon Schubert 	      in_quotes = 0;
1545796c8dcSSimon Schubert 	    }
1555796c8dcSSimon Schubert 	  m2_printchar (string[i], type, stream);
1565796c8dcSSimon Schubert 	  fprintf_filtered (stream, " <repeats %u times>", reps);
1575796c8dcSSimon Schubert 	  i = rep1 - 1;
1585796c8dcSSimon Schubert 	  things_printed += options->repeat_count_threshold;
1595796c8dcSSimon Schubert 	  need_comma = 1;
1605796c8dcSSimon Schubert 	}
1615796c8dcSSimon Schubert       else
1625796c8dcSSimon Schubert 	{
1635796c8dcSSimon Schubert 	  if (!in_quotes)
1645796c8dcSSimon Schubert 	    {
1655796c8dcSSimon Schubert 	      if (options->inspect_it)
1665796c8dcSSimon Schubert 		fputs_filtered ("\\\"", stream);
1675796c8dcSSimon Schubert 	      else
1685796c8dcSSimon Schubert 		fputs_filtered ("\"", stream);
1695796c8dcSSimon Schubert 	      in_quotes = 1;
1705796c8dcSSimon Schubert 	    }
1715796c8dcSSimon Schubert 	  LA_EMIT_CHAR (string[i], type, stream, '"');
1725796c8dcSSimon Schubert 	  ++things_printed;
1735796c8dcSSimon Schubert 	}
1745796c8dcSSimon Schubert     }
1755796c8dcSSimon Schubert 
1765796c8dcSSimon Schubert   /* Terminate the quotes if necessary.  */
1775796c8dcSSimon Schubert   if (in_quotes)
1785796c8dcSSimon Schubert     {
1795796c8dcSSimon Schubert       if (options->inspect_it)
1805796c8dcSSimon Schubert 	fputs_filtered ("\\\"", stream);
1815796c8dcSSimon Schubert       else
1825796c8dcSSimon Schubert 	fputs_filtered ("\"", stream);
1835796c8dcSSimon Schubert     }
1845796c8dcSSimon Schubert 
1855796c8dcSSimon Schubert   if (force_ellipses || i < length)
1865796c8dcSSimon Schubert     fputs_filtered ("...", stream);
1875796c8dcSSimon Schubert }
1885796c8dcSSimon Schubert 
1895796c8dcSSimon Schubert static struct value *
1905796c8dcSSimon Schubert evaluate_subexp_modula2 (struct type *expect_type, struct expression *exp,
1915796c8dcSSimon Schubert 			 int *pos, enum noside noside)
1925796c8dcSSimon Schubert {
1935796c8dcSSimon Schubert   enum exp_opcode op = exp->elts[*pos].opcode;
1945796c8dcSSimon Schubert   struct value *arg1;
1955796c8dcSSimon Schubert   struct value *arg2;
1965796c8dcSSimon Schubert   struct type *type;
197cf7f2e2dSJohn Marino 
1985796c8dcSSimon Schubert   switch (op)
1995796c8dcSSimon Schubert     {
2005796c8dcSSimon Schubert     case UNOP_HIGH:
2015796c8dcSSimon Schubert       (*pos)++;
2025796c8dcSSimon Schubert       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
2035796c8dcSSimon Schubert 
2045796c8dcSSimon Schubert       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2055796c8dcSSimon Schubert 	return arg1;
2065796c8dcSSimon Schubert       else
2075796c8dcSSimon Schubert 	{
2085796c8dcSSimon Schubert 	  arg1 = coerce_ref (arg1);
2095796c8dcSSimon Schubert 	  type = check_typedef (value_type (arg1));
2105796c8dcSSimon Schubert 
2115796c8dcSSimon Schubert 	  if (m2_is_unbounded_array (type))
2125796c8dcSSimon Schubert 	    {
2135796c8dcSSimon Schubert 	      struct value *temp = arg1;
214cf7f2e2dSJohn Marino 
2155796c8dcSSimon Schubert 	      type = TYPE_FIELD_TYPE (type, 1);
2165796c8dcSSimon Schubert 	      /* i18n: Do not translate the "_m2_high" part!  */
2175796c8dcSSimon Schubert 	      arg1 = value_struct_elt (&temp, NULL, "_m2_high", NULL,
2185796c8dcSSimon Schubert 				       _("unbounded structure "
2195796c8dcSSimon Schubert 					 "missing _m2_high field"));
2205796c8dcSSimon Schubert 
2215796c8dcSSimon Schubert 	      if (value_type (arg1) != type)
2225796c8dcSSimon Schubert 		arg1 = value_cast (type, arg1);
2235796c8dcSSimon Schubert 	    }
2245796c8dcSSimon Schubert 	}
2255796c8dcSSimon Schubert       return arg1;
2265796c8dcSSimon Schubert 
2275796c8dcSSimon Schubert     case BINOP_SUBSCRIPT:
2285796c8dcSSimon Schubert       (*pos)++;
2295796c8dcSSimon Schubert       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
2305796c8dcSSimon Schubert       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
2315796c8dcSSimon Schubert       if (noside == EVAL_SKIP)
2325796c8dcSSimon Schubert 	goto nosideret;
2335796c8dcSSimon Schubert       /* If the user attempts to subscript something that is not an
2345796c8dcSSimon Schubert          array or pointer type (like a plain int variable for example),
2355796c8dcSSimon Schubert          then report this as an error.  */
2365796c8dcSSimon Schubert 
2375796c8dcSSimon Schubert       arg1 = coerce_ref (arg1);
2385796c8dcSSimon Schubert       type = check_typedef (value_type (arg1));
2395796c8dcSSimon Schubert 
2405796c8dcSSimon Schubert       if (m2_is_unbounded_array (type))
2415796c8dcSSimon Schubert 	{
2425796c8dcSSimon Schubert 	  struct value *temp = arg1;
2435796c8dcSSimon Schubert 	  type = TYPE_FIELD_TYPE (type, 0);
244cf7f2e2dSJohn Marino 	  if (type == NULL || (TYPE_CODE (type) != TYPE_CODE_PTR))
245cf7f2e2dSJohn Marino 	    {
246c50c785cSJohn Marino 	      warning (_("internal error: unbounded "
247c50c785cSJohn Marino 			 "array structure is unknown"));
2485796c8dcSSimon Schubert 	      return evaluate_subexp_standard (expect_type, exp, pos, noside);
2495796c8dcSSimon Schubert 	    }
2505796c8dcSSimon Schubert 	  /* i18n: Do not translate the "_m2_contents" part!  */
2515796c8dcSSimon Schubert 	  arg1 = value_struct_elt (&temp, NULL, "_m2_contents", NULL,
2525796c8dcSSimon Schubert 				   _("unbounded structure "
2535796c8dcSSimon Schubert 				     "missing _m2_contents field"));
2545796c8dcSSimon Schubert 
2555796c8dcSSimon Schubert 	  if (value_type (arg1) != type)
2565796c8dcSSimon Schubert 	    arg1 = value_cast (type, arg1);
2575796c8dcSSimon Schubert 
258c50c785cSJohn Marino 	  check_typedef (value_type (arg1));
2595796c8dcSSimon Schubert 	  return value_ind (value_ptradd (arg1, value_as_long (arg2)));
2605796c8dcSSimon Schubert 	}
2615796c8dcSSimon Schubert       else
2625796c8dcSSimon Schubert 	if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
2635796c8dcSSimon Schubert 	  {
2645796c8dcSSimon Schubert 	    if (TYPE_NAME (type))
2655796c8dcSSimon Schubert 	      error (_("cannot subscript something of type `%s'"),
2665796c8dcSSimon Schubert 		     TYPE_NAME (type));
2675796c8dcSSimon Schubert 	    else
2685796c8dcSSimon Schubert 	      error (_("cannot subscript requested type"));
2695796c8dcSSimon Schubert 	  }
2705796c8dcSSimon Schubert 
2715796c8dcSSimon Schubert       if (noside == EVAL_AVOID_SIDE_EFFECTS)
2725796c8dcSSimon Schubert 	return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
2735796c8dcSSimon Schubert       else
2745796c8dcSSimon Schubert 	return value_subscript (arg1, value_as_long (arg2));
2755796c8dcSSimon Schubert 
2765796c8dcSSimon Schubert     default:
2775796c8dcSSimon Schubert       return evaluate_subexp_standard (expect_type, exp, pos, noside);
2785796c8dcSSimon Schubert     }
2795796c8dcSSimon Schubert 
2805796c8dcSSimon Schubert  nosideret:
2815796c8dcSSimon Schubert   return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
2825796c8dcSSimon Schubert }
2835796c8dcSSimon Schubert 
2845796c8dcSSimon Schubert 
2855796c8dcSSimon Schubert /* Table of operators and their precedences for printing expressions.  */
2865796c8dcSSimon Schubert 
2875796c8dcSSimon Schubert static const struct op_print m2_op_print_tab[] =
2885796c8dcSSimon Schubert {
2895796c8dcSSimon Schubert   {"+", BINOP_ADD, PREC_ADD, 0},
2905796c8dcSSimon Schubert   {"+", UNOP_PLUS, PREC_PREFIX, 0},
2915796c8dcSSimon Schubert   {"-", BINOP_SUB, PREC_ADD, 0},
2925796c8dcSSimon Schubert   {"-", UNOP_NEG, PREC_PREFIX, 0},
2935796c8dcSSimon Schubert   {"*", BINOP_MUL, PREC_MUL, 0},
2945796c8dcSSimon Schubert   {"/", BINOP_DIV, PREC_MUL, 0},
2955796c8dcSSimon Schubert   {"DIV", BINOP_INTDIV, PREC_MUL, 0},
2965796c8dcSSimon Schubert   {"MOD", BINOP_REM, PREC_MUL, 0},
2975796c8dcSSimon Schubert   {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
2985796c8dcSSimon Schubert   {"OR", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
2995796c8dcSSimon Schubert   {"AND", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
3005796c8dcSSimon Schubert   {"NOT", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
3015796c8dcSSimon Schubert   {"=", BINOP_EQUAL, PREC_EQUAL, 0},
3025796c8dcSSimon Schubert   {"<>", BINOP_NOTEQUAL, PREC_EQUAL, 0},
3035796c8dcSSimon Schubert   {"<=", BINOP_LEQ, PREC_ORDER, 0},
3045796c8dcSSimon Schubert   {">=", BINOP_GEQ, PREC_ORDER, 0},
3055796c8dcSSimon Schubert   {">", BINOP_GTR, PREC_ORDER, 0},
3065796c8dcSSimon Schubert   {"<", BINOP_LESS, PREC_ORDER, 0},
3075796c8dcSSimon Schubert   {"^", UNOP_IND, PREC_PREFIX, 0},
3085796c8dcSSimon Schubert   {"@", BINOP_REPEAT, PREC_REPEAT, 0},
3095796c8dcSSimon Schubert   {"CAP", UNOP_CAP, PREC_BUILTIN_FUNCTION, 0},
3105796c8dcSSimon Schubert   {"CHR", UNOP_CHR, PREC_BUILTIN_FUNCTION, 0},
3115796c8dcSSimon Schubert   {"ORD", UNOP_ORD, PREC_BUILTIN_FUNCTION, 0},
3125796c8dcSSimon Schubert   {"FLOAT", UNOP_FLOAT, PREC_BUILTIN_FUNCTION, 0},
3135796c8dcSSimon Schubert   {"HIGH", UNOP_HIGH, PREC_BUILTIN_FUNCTION, 0},
3145796c8dcSSimon Schubert   {"MAX", UNOP_MAX, PREC_BUILTIN_FUNCTION, 0},
3155796c8dcSSimon Schubert   {"MIN", UNOP_MIN, PREC_BUILTIN_FUNCTION, 0},
3165796c8dcSSimon Schubert   {"ODD", UNOP_ODD, PREC_BUILTIN_FUNCTION, 0},
3175796c8dcSSimon Schubert   {"TRUNC", UNOP_TRUNC, PREC_BUILTIN_FUNCTION, 0},
3185796c8dcSSimon Schubert   {NULL, 0, 0, 0}
3195796c8dcSSimon Schubert };
3205796c8dcSSimon Schubert 
3215796c8dcSSimon Schubert /* The built-in types of Modula-2.  */
3225796c8dcSSimon Schubert 
3235796c8dcSSimon Schubert enum m2_primitive_types {
3245796c8dcSSimon Schubert   m2_primitive_type_char,
3255796c8dcSSimon Schubert   m2_primitive_type_int,
3265796c8dcSSimon Schubert   m2_primitive_type_card,
3275796c8dcSSimon Schubert   m2_primitive_type_real,
3285796c8dcSSimon Schubert   m2_primitive_type_bool,
3295796c8dcSSimon Schubert   nr_m2_primitive_types
3305796c8dcSSimon Schubert };
3315796c8dcSSimon Schubert 
3325796c8dcSSimon Schubert static void
3335796c8dcSSimon Schubert m2_language_arch_info (struct gdbarch *gdbarch,
3345796c8dcSSimon Schubert 		       struct language_arch_info *lai)
3355796c8dcSSimon Schubert {
3365796c8dcSSimon Schubert   const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
3375796c8dcSSimon Schubert 
3385796c8dcSSimon Schubert   lai->string_char_type = builtin->builtin_char;
3395796c8dcSSimon Schubert   lai->primitive_type_vector
3405796c8dcSSimon Schubert     = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
3415796c8dcSSimon Schubert                               struct type *);
3425796c8dcSSimon Schubert 
3435796c8dcSSimon Schubert   lai->primitive_type_vector [m2_primitive_type_char]
3445796c8dcSSimon Schubert     = builtin->builtin_char;
3455796c8dcSSimon Schubert   lai->primitive_type_vector [m2_primitive_type_int]
3465796c8dcSSimon Schubert     = builtin->builtin_int;
3475796c8dcSSimon Schubert   lai->primitive_type_vector [m2_primitive_type_card]
3485796c8dcSSimon Schubert     = builtin->builtin_card;
3495796c8dcSSimon Schubert   lai->primitive_type_vector [m2_primitive_type_real]
3505796c8dcSSimon Schubert     = builtin->builtin_real;
3515796c8dcSSimon Schubert   lai->primitive_type_vector [m2_primitive_type_bool]
3525796c8dcSSimon Schubert     = builtin->builtin_bool;
3535796c8dcSSimon Schubert 
3545796c8dcSSimon Schubert   lai->bool_type_symbol = "BOOLEAN";
3555796c8dcSSimon Schubert   lai->bool_type_default = builtin->builtin_bool;
3565796c8dcSSimon Schubert }
3575796c8dcSSimon Schubert 
3585796c8dcSSimon Schubert const struct exp_descriptor exp_descriptor_modula2 =
3595796c8dcSSimon Schubert {
3605796c8dcSSimon Schubert   print_subexp_standard,
3615796c8dcSSimon Schubert   operator_length_standard,
362cf7f2e2dSJohn Marino   operator_check_standard,
3635796c8dcSSimon Schubert   op_name_standard,
3645796c8dcSSimon Schubert   dump_subexp_body_standard,
3655796c8dcSSimon Schubert   evaluate_subexp_modula2
3665796c8dcSSimon Schubert };
3675796c8dcSSimon Schubert 
3685796c8dcSSimon Schubert const struct language_defn m2_language_defn =
3695796c8dcSSimon Schubert {
3705796c8dcSSimon Schubert   "modula-2",
3715796c8dcSSimon Schubert   language_m2,
3725796c8dcSSimon Schubert   range_check_on,
3735796c8dcSSimon Schubert   type_check_on,
3745796c8dcSSimon Schubert   case_sensitive_on,
3755796c8dcSSimon Schubert   array_row_major,
3765796c8dcSSimon Schubert   macro_expansion_no,
3775796c8dcSSimon Schubert   &exp_descriptor_modula2,
3785796c8dcSSimon Schubert   m2_parse,			/* parser */
3795796c8dcSSimon Schubert   m2_error,			/* parser error function */
3805796c8dcSSimon Schubert   null_post_parser,
3815796c8dcSSimon Schubert   m2_printchar,			/* Print character constant */
3825796c8dcSSimon Schubert   m2_printstr,			/* function to print string constant */
3835796c8dcSSimon Schubert   m2_emit_char,			/* Function to print a single character */
3845796c8dcSSimon Schubert   m2_print_type,		/* Print a type using appropriate syntax */
3855796c8dcSSimon Schubert   m2_print_typedef,		/* Print a typedef using appropriate syntax */
3865796c8dcSSimon Schubert   m2_val_print,			/* Print a value using appropriate syntax */
3875796c8dcSSimon Schubert   c_value_print,		/* Print a top-level value */
3885796c8dcSSimon Schubert   NULL,				/* Language specific skip_trampoline */
3895796c8dcSSimon Schubert   NULL,		                /* name_of_this */
3905796c8dcSSimon Schubert   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
3915796c8dcSSimon Schubert   basic_lookup_transparent_type,/* lookup_transparent_type */
3925796c8dcSSimon Schubert   NULL,				/* Language specific symbol demangler */
393c50c785cSJohn Marino   NULL,				/* Language specific
394c50c785cSJohn Marino 				   class_name_from_physname */
3955796c8dcSSimon Schubert   m2_op_print_tab,		/* expression operators for printing */
3965796c8dcSSimon Schubert   0,				/* arrays are first-class (not c-style) */
3975796c8dcSSimon Schubert   0,				/* String lower bound */
3985796c8dcSSimon Schubert   default_word_break_characters,
3995796c8dcSSimon Schubert   default_make_symbol_completion_list,
4005796c8dcSSimon Schubert   m2_language_arch_info,
4015796c8dcSSimon Schubert   default_print_array_index,
4025796c8dcSSimon Schubert   default_pass_by_reference,
4035796c8dcSSimon Schubert   default_get_string,
404*a45ae5f8SJohn Marino   strcmp_iw_ordered,
405*a45ae5f8SJohn Marino   iterate_over_symbols,
4065796c8dcSSimon Schubert   LANG_MAGIC
4075796c8dcSSimon Schubert };
4085796c8dcSSimon Schubert 
4095796c8dcSSimon Schubert static void *
4105796c8dcSSimon Schubert build_m2_types (struct gdbarch *gdbarch)
4115796c8dcSSimon Schubert {
4125796c8dcSSimon Schubert   struct builtin_m2_type *builtin_m2_type
4135796c8dcSSimon Schubert     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_m2_type);
4145796c8dcSSimon Schubert 
4155796c8dcSSimon Schubert   /* Modula-2 "pervasive" types.  NOTE:  these can be redefined!!! */
4165796c8dcSSimon Schubert   builtin_m2_type->builtin_int
4175796c8dcSSimon Schubert     = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "INTEGER");
4185796c8dcSSimon Schubert   builtin_m2_type->builtin_card
4195796c8dcSSimon Schubert     = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "CARDINAL");
4205796c8dcSSimon Schubert   builtin_m2_type->builtin_real
4215796c8dcSSimon Schubert     = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch), "REAL", NULL);
4225796c8dcSSimon Schubert   builtin_m2_type->builtin_char
4235796c8dcSSimon Schubert     = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "CHAR");
4245796c8dcSSimon Schubert   builtin_m2_type->builtin_bool
4255796c8dcSSimon Schubert     = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "BOOLEAN");
4265796c8dcSSimon Schubert 
4275796c8dcSSimon Schubert   return builtin_m2_type;
4285796c8dcSSimon Schubert }
4295796c8dcSSimon Schubert 
4305796c8dcSSimon Schubert static struct gdbarch_data *m2_type_data;
4315796c8dcSSimon Schubert 
4325796c8dcSSimon Schubert const struct builtin_m2_type *
4335796c8dcSSimon Schubert builtin_m2_type (struct gdbarch *gdbarch)
4345796c8dcSSimon Schubert {
4355796c8dcSSimon Schubert   return gdbarch_data (gdbarch, m2_type_data);
4365796c8dcSSimon Schubert }
4375796c8dcSSimon Schubert 
4385796c8dcSSimon Schubert 
4395796c8dcSSimon Schubert /* Initialization for Modula-2 */
4405796c8dcSSimon Schubert 
4415796c8dcSSimon Schubert void
4425796c8dcSSimon Schubert _initialize_m2_language (void)
4435796c8dcSSimon Schubert {
4445796c8dcSSimon Schubert   m2_type_data = gdbarch_data_register_post_init (build_m2_types);
4455796c8dcSSimon Schubert 
4465796c8dcSSimon Schubert   add_language (&m2_language_defn);
4475796c8dcSSimon Schubert }
448