xref: /openbsd-src/gnu/usr.bin/binutils/gdb/m2-lang.c (revision 63addd46c1e40ca0f49488ddcdc4ab598023b0c1)
1e93f7393Sniklas /* Modula 2 language support routines for GDB, the GNU debugger.
2b725ae77Skettenis    Copyright 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2002, 2003, 2004
3b725ae77Skettenis    Free Software Foundation, Inc.
4e93f7393Sniklas 
5e93f7393Sniklas    This file is part of GDB.
6e93f7393Sniklas 
7e93f7393Sniklas    This program is free software; you can redistribute it and/or modify
8e93f7393Sniklas    it under the terms of the GNU General Public License as published by
9e93f7393Sniklas    the Free Software Foundation; either version 2 of the License, or
10e93f7393Sniklas    (at your option) any later version.
11e93f7393Sniklas 
12e93f7393Sniklas    This program is distributed in the hope that it will be useful,
13e93f7393Sniklas    but WITHOUT ANY WARRANTY; without even the implied warranty of
14e93f7393Sniklas    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15e93f7393Sniklas    GNU General Public License for more details.
16e93f7393Sniklas 
17e93f7393Sniklas    You should have received a copy of the GNU General Public License
18e93f7393Sniklas    along with this program; if not, write to the Free Software
19b725ae77Skettenis    Foundation, Inc., 59 Temple Place - Suite 330,
20b725ae77Skettenis    Boston, MA 02111-1307, USA.  */
21e93f7393Sniklas 
22e93f7393Sniklas #include "defs.h"
23e93f7393Sniklas #include "symtab.h"
24e93f7393Sniklas #include "gdbtypes.h"
25e93f7393Sniklas #include "expression.h"
26e93f7393Sniklas #include "parser-defs.h"
27e93f7393Sniklas #include "language.h"
28e93f7393Sniklas #include "m2-lang.h"
29e93f7393Sniklas #include "c-lang.h"
30b725ae77Skettenis #include "valprint.h"
31e93f7393Sniklas 
32b725ae77Skettenis extern void _initialize_m2_language (void);
33b725ae77Skettenis static struct type *m2_create_fundamental_type (struct objfile *, int);
34b725ae77Skettenis static void m2_printstr (struct ui_file * stream, char *string,
35b725ae77Skettenis 			 unsigned int length, int width,
36b725ae77Skettenis 			 int force_ellipses);
37b725ae77Skettenis static void m2_printchar (int, struct ui_file *);
38b725ae77Skettenis static void m2_emit_char (int, struct ui_file *, int);
39e93f7393Sniklas 
40e93f7393Sniklas /* Print the character C on STREAM as part of the contents of a literal
41e93f7393Sniklas    string whose delimiter is QUOTER.  Note that that format for printing
42e93f7393Sniklas    characters and strings is language specific.
43e93f7393Sniklas    FIXME:  This is a copy of the same function from c-exp.y.  It should
44e93f7393Sniklas    be replaced with a true Modula version.
45e93f7393Sniklas  */
46e93f7393Sniklas 
47e93f7393Sniklas static void
m2_emit_char(int c,struct ui_file * stream,int quoter)48b725ae77Skettenis m2_emit_char (int c, struct ui_file *stream, int quoter)
49e93f7393Sniklas {
50e93f7393Sniklas 
51e93f7393Sniklas   c &= 0xFF;			/* Avoid sign bit follies */
52e93f7393Sniklas 
53e93f7393Sniklas   if (PRINT_LITERAL_FORM (c))
54e93f7393Sniklas     {
55e93f7393Sniklas       if (c == '\\' || c == quoter)
56e93f7393Sniklas 	{
57e93f7393Sniklas 	  fputs_filtered ("\\", stream);
58e93f7393Sniklas 	}
59e93f7393Sniklas       fprintf_filtered (stream, "%c", c);
60e93f7393Sniklas     }
61e93f7393Sniklas   else
62e93f7393Sniklas     {
63e93f7393Sniklas       switch (c)
64e93f7393Sniklas 	{
65e93f7393Sniklas 	case '\n':
66e93f7393Sniklas 	  fputs_filtered ("\\n", stream);
67e93f7393Sniklas 	  break;
68e93f7393Sniklas 	case '\b':
69e93f7393Sniklas 	  fputs_filtered ("\\b", stream);
70e93f7393Sniklas 	  break;
71e93f7393Sniklas 	case '\t':
72e93f7393Sniklas 	  fputs_filtered ("\\t", stream);
73e93f7393Sniklas 	  break;
74e93f7393Sniklas 	case '\f':
75e93f7393Sniklas 	  fputs_filtered ("\\f", stream);
76e93f7393Sniklas 	  break;
77e93f7393Sniklas 	case '\r':
78e93f7393Sniklas 	  fputs_filtered ("\\r", stream);
79e93f7393Sniklas 	  break;
80e93f7393Sniklas 	case '\033':
81e93f7393Sniklas 	  fputs_filtered ("\\e", stream);
82e93f7393Sniklas 	  break;
83e93f7393Sniklas 	case '\007':
84e93f7393Sniklas 	  fputs_filtered ("\\a", stream);
85e93f7393Sniklas 	  break;
86e93f7393Sniklas 	default:
87e93f7393Sniklas 	  fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
88e93f7393Sniklas 	  break;
89e93f7393Sniklas 	}
90e93f7393Sniklas     }
91e93f7393Sniklas }
92e93f7393Sniklas 
93e93f7393Sniklas /* FIXME:  This is a copy of the same function from c-exp.y.  It should
94e93f7393Sniklas    be replaced with a true Modula version. */
95e93f7393Sniklas 
96e93f7393Sniklas static void
m2_printchar(int c,struct ui_file * stream)97b725ae77Skettenis m2_printchar (int c, struct ui_file *stream)
98e93f7393Sniklas {
99e93f7393Sniklas   fputs_filtered ("'", stream);
100b725ae77Skettenis   LA_EMIT_CHAR (c, stream, '\'');
101e93f7393Sniklas   fputs_filtered ("'", stream);
102e93f7393Sniklas }
103e93f7393Sniklas 
104e93f7393Sniklas /* Print the character string STRING, printing at most LENGTH characters.
105e93f7393Sniklas    Printing stops early if the number hits print_max; repeat counts
106e93f7393Sniklas    are printed as appropriate.  Print ellipses at the end if we
107e93f7393Sniklas    had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
108e93f7393Sniklas    FIXME:  This is a copy of the same function from c-exp.y.  It should
109e93f7393Sniklas    be replaced with a true Modula version. */
110e93f7393Sniklas 
111e93f7393Sniklas static void
m2_printstr(struct ui_file * stream,char * string,unsigned int length,int width,int force_ellipses)112b725ae77Skettenis m2_printstr (struct ui_file *stream, char *string, unsigned int length,
113b725ae77Skettenis 	     int width, int force_ellipses)
114e93f7393Sniklas {
115b725ae77Skettenis   unsigned int i;
116e93f7393Sniklas   unsigned int things_printed = 0;
117e93f7393Sniklas   int in_quotes = 0;
118e93f7393Sniklas   int need_comma = 0;
119e93f7393Sniklas 
120e93f7393Sniklas   if (length == 0)
121e93f7393Sniklas     {
122e93f7393Sniklas       fputs_filtered ("\"\"", gdb_stdout);
123e93f7393Sniklas       return;
124e93f7393Sniklas     }
125e93f7393Sniklas 
126e93f7393Sniklas   for (i = 0; i < length && things_printed < print_max; ++i)
127e93f7393Sniklas     {
128e93f7393Sniklas       /* Position of the character we are examining
129e93f7393Sniklas          to see whether it is repeated.  */
130e93f7393Sniklas       unsigned int rep1;
131e93f7393Sniklas       /* Number of repetitions we have detected so far.  */
132e93f7393Sniklas       unsigned int reps;
133e93f7393Sniklas 
134e93f7393Sniklas       QUIT;
135e93f7393Sniklas 
136e93f7393Sniklas       if (need_comma)
137e93f7393Sniklas 	{
138e93f7393Sniklas 	  fputs_filtered (", ", stream);
139e93f7393Sniklas 	  need_comma = 0;
140e93f7393Sniklas 	}
141e93f7393Sniklas 
142e93f7393Sniklas       rep1 = i + 1;
143e93f7393Sniklas       reps = 1;
144e93f7393Sniklas       while (rep1 < length && string[rep1] == string[i])
145e93f7393Sniklas 	{
146e93f7393Sniklas 	  ++rep1;
147e93f7393Sniklas 	  ++reps;
148e93f7393Sniklas 	}
149e93f7393Sniklas 
150e93f7393Sniklas       if (reps > repeat_count_threshold)
151e93f7393Sniklas 	{
152e93f7393Sniklas 	  if (in_quotes)
153e93f7393Sniklas 	    {
154e93f7393Sniklas 	      if (inspect_it)
155e93f7393Sniklas 		fputs_filtered ("\\\", ", stream);
156e93f7393Sniklas 	      else
157e93f7393Sniklas 		fputs_filtered ("\", ", stream);
158e93f7393Sniklas 	      in_quotes = 0;
159e93f7393Sniklas 	    }
160e93f7393Sniklas 	  m2_printchar (string[i], stream);
161e93f7393Sniklas 	  fprintf_filtered (stream, " <repeats %u times>", reps);
162e93f7393Sniklas 	  i = rep1 - 1;
163e93f7393Sniklas 	  things_printed += repeat_count_threshold;
164e93f7393Sniklas 	  need_comma = 1;
165e93f7393Sniklas 	}
166e93f7393Sniklas       else
167e93f7393Sniklas 	{
168e93f7393Sniklas 	  if (!in_quotes)
169e93f7393Sniklas 	    {
170e93f7393Sniklas 	      if (inspect_it)
171e93f7393Sniklas 		fputs_filtered ("\\\"", stream);
172e93f7393Sniklas 	      else
173e93f7393Sniklas 		fputs_filtered ("\"", stream);
174e93f7393Sniklas 	      in_quotes = 1;
175e93f7393Sniklas 	    }
176b725ae77Skettenis 	  LA_EMIT_CHAR (string[i], stream, '"');
177e93f7393Sniklas 	  ++things_printed;
178e93f7393Sniklas 	}
179e93f7393Sniklas     }
180e93f7393Sniklas 
181e93f7393Sniklas   /* Terminate the quotes if necessary.  */
182e93f7393Sniklas   if (in_quotes)
183e93f7393Sniklas     {
184e93f7393Sniklas       if (inspect_it)
185e93f7393Sniklas 	fputs_filtered ("\\\"", stream);
186e93f7393Sniklas       else
187e93f7393Sniklas 	fputs_filtered ("\"", stream);
188e93f7393Sniklas     }
189e93f7393Sniklas 
190e93f7393Sniklas   if (force_ellipses || i < length)
191e93f7393Sniklas     fputs_filtered ("...", stream);
192e93f7393Sniklas }
193e93f7393Sniklas 
194e93f7393Sniklas /* FIXME:  This is a copy of c_create_fundamental_type(), before
195e93f7393Sniklas    all the non-C types were stripped from it.  Needs to be fixed
196e93f7393Sniklas    by an experienced Modula programmer. */
197e93f7393Sniklas 
198e93f7393Sniklas static struct type *
m2_create_fundamental_type(struct objfile * objfile,int typeid)199b725ae77Skettenis m2_create_fundamental_type (struct objfile *objfile, int typeid)
200e93f7393Sniklas {
201b725ae77Skettenis   struct type *type = NULL;
202e93f7393Sniklas 
203e93f7393Sniklas   switch (typeid)
204e93f7393Sniklas     {
205e93f7393Sniklas     default:
206e93f7393Sniklas       /* FIXME:  For now, if we are asked to produce a type not in this
207e93f7393Sniklas          language, create the equivalent of a C integer type with the
208e93f7393Sniklas          name "<?type?>".  When all the dust settles from the type
209e93f7393Sniklas          reconstruction work, this should probably become an error. */
210e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
211e93f7393Sniklas 			TARGET_INT_BIT / TARGET_CHAR_BIT,
212e93f7393Sniklas 			0, "<?type?>", objfile);
213e93f7393Sniklas       warning ("internal error: no Modula fundamental type %d", typeid);
214e93f7393Sniklas       break;
215e93f7393Sniklas     case FT_VOID:
216e93f7393Sniklas       type = init_type (TYPE_CODE_VOID,
217e93f7393Sniklas 			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
218e93f7393Sniklas 			0, "void", objfile);
219e93f7393Sniklas       break;
220e93f7393Sniklas     case FT_BOOLEAN:
221e93f7393Sniklas       type = init_type (TYPE_CODE_BOOL,
222e93f7393Sniklas 			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
223e93f7393Sniklas 			TYPE_FLAG_UNSIGNED, "boolean", objfile);
224e93f7393Sniklas       break;
225e93f7393Sniklas     case FT_STRING:
226e93f7393Sniklas       type = init_type (TYPE_CODE_STRING,
227e93f7393Sniklas 			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
228e93f7393Sniklas 			0, "string", objfile);
229e93f7393Sniklas       break;
230e93f7393Sniklas     case FT_CHAR:
231e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
232e93f7393Sniklas 			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
233e93f7393Sniklas 			0, "char", objfile);
234e93f7393Sniklas       break;
235e93f7393Sniklas     case FT_SIGNED_CHAR:
236e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
237e93f7393Sniklas 			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
238e93f7393Sniklas 			0, "signed char", objfile);
239e93f7393Sniklas       break;
240e93f7393Sniklas     case FT_UNSIGNED_CHAR:
241e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
242e93f7393Sniklas 			TARGET_CHAR_BIT / TARGET_CHAR_BIT,
243e93f7393Sniklas 			TYPE_FLAG_UNSIGNED, "unsigned char", objfile);
244e93f7393Sniklas       break;
245e93f7393Sniklas     case FT_SHORT:
246e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
247e93f7393Sniklas 			TARGET_SHORT_BIT / TARGET_CHAR_BIT,
248e93f7393Sniklas 			0, "short", objfile);
249e93f7393Sniklas       break;
250e93f7393Sniklas     case FT_SIGNED_SHORT:
251e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
252e93f7393Sniklas 			TARGET_SHORT_BIT / TARGET_CHAR_BIT,
253e93f7393Sniklas 			0, "short", objfile);	/* FIXME-fnf */
254e93f7393Sniklas       break;
255e93f7393Sniklas     case FT_UNSIGNED_SHORT:
256e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
257e93f7393Sniklas 			TARGET_SHORT_BIT / TARGET_CHAR_BIT,
258e93f7393Sniklas 			TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
259e93f7393Sniklas       break;
260e93f7393Sniklas     case FT_INTEGER:
261e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
262e93f7393Sniklas 			TARGET_INT_BIT / TARGET_CHAR_BIT,
263e93f7393Sniklas 			0, "int", objfile);
264e93f7393Sniklas       break;
265e93f7393Sniklas     case FT_SIGNED_INTEGER:
266e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
267e93f7393Sniklas 			TARGET_INT_BIT / TARGET_CHAR_BIT,
268e93f7393Sniklas 			0, "int", objfile);	/* FIXME -fnf */
269e93f7393Sniklas       break;
270e93f7393Sniklas     case FT_UNSIGNED_INTEGER:
271e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
272e93f7393Sniklas 			TARGET_INT_BIT / TARGET_CHAR_BIT,
273e93f7393Sniklas 			TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
274e93f7393Sniklas       break;
275e93f7393Sniklas     case FT_FIXED_DECIMAL:
276e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
277e93f7393Sniklas 			TARGET_INT_BIT / TARGET_CHAR_BIT,
278e93f7393Sniklas 			0, "fixed decimal", objfile);
279e93f7393Sniklas       break;
280e93f7393Sniklas     case FT_LONG:
281e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
282e93f7393Sniklas 			TARGET_LONG_BIT / TARGET_CHAR_BIT,
283e93f7393Sniklas 			0, "long", objfile);
284e93f7393Sniklas       break;
285e93f7393Sniklas     case FT_SIGNED_LONG:
286e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
287e93f7393Sniklas 			TARGET_LONG_BIT / TARGET_CHAR_BIT,
288e93f7393Sniklas 			0, "long", objfile);	/* FIXME -fnf */
289e93f7393Sniklas       break;
290e93f7393Sniklas     case FT_UNSIGNED_LONG:
291e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
292e93f7393Sniklas 			TARGET_LONG_BIT / TARGET_CHAR_BIT,
293e93f7393Sniklas 			TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
294e93f7393Sniklas       break;
295e93f7393Sniklas     case FT_LONG_LONG:
296e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
297e93f7393Sniklas 			TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
298e93f7393Sniklas 			0, "long long", objfile);
299e93f7393Sniklas       break;
300e93f7393Sniklas     case FT_SIGNED_LONG_LONG:
301e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
302e93f7393Sniklas 			TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
303e93f7393Sniklas 			0, "signed long long", objfile);
304e93f7393Sniklas       break;
305e93f7393Sniklas     case FT_UNSIGNED_LONG_LONG:
306e93f7393Sniklas       type = init_type (TYPE_CODE_INT,
307e93f7393Sniklas 			TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
308e93f7393Sniklas 			TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
309e93f7393Sniklas       break;
310e93f7393Sniklas     case FT_FLOAT:
311e93f7393Sniklas       type = init_type (TYPE_CODE_FLT,
312e93f7393Sniklas 			TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
313e93f7393Sniklas 			0, "float", objfile);
314e93f7393Sniklas       break;
315e93f7393Sniklas     case FT_DBL_PREC_FLOAT:
316e93f7393Sniklas       type = init_type (TYPE_CODE_FLT,
317e93f7393Sniklas 			TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
318e93f7393Sniklas 			0, "double", objfile);
319e93f7393Sniklas       break;
320e93f7393Sniklas     case FT_FLOAT_DECIMAL:
321e93f7393Sniklas       type = init_type (TYPE_CODE_FLT,
322e93f7393Sniklas 			TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
323e93f7393Sniklas 			0, "floating decimal", objfile);
324e93f7393Sniklas       break;
325e93f7393Sniklas     case FT_EXT_PREC_FLOAT:
326e93f7393Sniklas       type = init_type (TYPE_CODE_FLT,
327e93f7393Sniklas 			TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
328e93f7393Sniklas 			0, "long double", objfile);
329e93f7393Sniklas       break;
330e93f7393Sniklas     case FT_COMPLEX:
331e93f7393Sniklas       type = init_type (TYPE_CODE_COMPLEX,
332e93f7393Sniklas 			2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
333e93f7393Sniklas 			0, "complex", objfile);
334e93f7393Sniklas       TYPE_TARGET_TYPE (type)
335e93f7393Sniklas 	= m2_create_fundamental_type (objfile, FT_FLOAT);
336e93f7393Sniklas       break;
337e93f7393Sniklas     case FT_DBL_PREC_COMPLEX:
338e93f7393Sniklas       type = init_type (TYPE_CODE_COMPLEX,
339e93f7393Sniklas 			2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
340e93f7393Sniklas 			0, "double complex", objfile);
341e93f7393Sniklas       TYPE_TARGET_TYPE (type)
342e93f7393Sniklas 	= m2_create_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
343e93f7393Sniklas       break;
344e93f7393Sniklas     case FT_EXT_PREC_COMPLEX:
345e93f7393Sniklas       type = init_type (TYPE_CODE_COMPLEX,
346e93f7393Sniklas 			2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
347e93f7393Sniklas 			0, "long double complex", objfile);
348e93f7393Sniklas       TYPE_TARGET_TYPE (type)
349e93f7393Sniklas 	= m2_create_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
350e93f7393Sniklas       break;
351e93f7393Sniklas     }
352e93f7393Sniklas   return (type);
353e93f7393Sniklas }
354e93f7393Sniklas 
355b725ae77Skettenis 
356e93f7393Sniklas /* Table of operators and their precedences for printing expressions.  */
357e93f7393Sniklas 
358b725ae77Skettenis static const struct op_print m2_op_print_tab[] =
359b725ae77Skettenis {
360e93f7393Sniklas   {"+", BINOP_ADD, PREC_ADD, 0},
361e93f7393Sniklas   {"+", UNOP_PLUS, PREC_PREFIX, 0},
362e93f7393Sniklas   {"-", BINOP_SUB, PREC_ADD, 0},
363e93f7393Sniklas   {"-", UNOP_NEG, PREC_PREFIX, 0},
364e93f7393Sniklas   {"*", BINOP_MUL, PREC_MUL, 0},
365e93f7393Sniklas   {"/", BINOP_DIV, PREC_MUL, 0},
366e93f7393Sniklas   {"DIV", BINOP_INTDIV, PREC_MUL, 0},
367e93f7393Sniklas   {"MOD", BINOP_REM, PREC_MUL, 0},
368e93f7393Sniklas   {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
369e93f7393Sniklas   {"OR", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
370e93f7393Sniklas   {"AND", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
371e93f7393Sniklas   {"NOT", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
372e93f7393Sniklas   {"=", BINOP_EQUAL, PREC_EQUAL, 0},
373e93f7393Sniklas   {"<>", BINOP_NOTEQUAL, PREC_EQUAL, 0},
374e93f7393Sniklas   {"<=", BINOP_LEQ, PREC_ORDER, 0},
375e93f7393Sniklas   {">=", BINOP_GEQ, PREC_ORDER, 0},
376e93f7393Sniklas   {">", BINOP_GTR, PREC_ORDER, 0},
377e93f7393Sniklas   {"<", BINOP_LESS, PREC_ORDER, 0},
378e93f7393Sniklas   {"^", UNOP_IND, PREC_PREFIX, 0},
379e93f7393Sniklas   {"@", BINOP_REPEAT, PREC_REPEAT, 0},
380e93f7393Sniklas   {"CAP", UNOP_CAP, PREC_BUILTIN_FUNCTION, 0},
381e93f7393Sniklas   {"CHR", UNOP_CHR, PREC_BUILTIN_FUNCTION, 0},
382e93f7393Sniklas   {"ORD", UNOP_ORD, PREC_BUILTIN_FUNCTION, 0},
383e93f7393Sniklas   {"FLOAT", UNOP_FLOAT, PREC_BUILTIN_FUNCTION, 0},
384e93f7393Sniklas   {"HIGH", UNOP_HIGH, PREC_BUILTIN_FUNCTION, 0},
385e93f7393Sniklas   {"MAX", UNOP_MAX, PREC_BUILTIN_FUNCTION, 0},
386e93f7393Sniklas   {"MIN", UNOP_MIN, PREC_BUILTIN_FUNCTION, 0},
387e93f7393Sniklas   {"ODD", UNOP_ODD, PREC_BUILTIN_FUNCTION, 0},
388e93f7393Sniklas   {"TRUNC", UNOP_TRUNC, PREC_BUILTIN_FUNCTION, 0},
389e93f7393Sniklas   {NULL, 0, 0, 0}
390e93f7393Sniklas };
391e93f7393Sniklas 
392e93f7393Sniklas /* The built-in types of Modula-2.  */
393e93f7393Sniklas 
394e93f7393Sniklas struct type *builtin_type_m2_char;
395e93f7393Sniklas struct type *builtin_type_m2_int;
396e93f7393Sniklas struct type *builtin_type_m2_card;
397e93f7393Sniklas struct type *builtin_type_m2_real;
398e93f7393Sniklas struct type *builtin_type_m2_bool;
399e93f7393Sniklas 
400b725ae77Skettenis struct type **const (m2_builtin_types[]) =
401e93f7393Sniklas {
402e93f7393Sniklas   &builtin_type_m2_char,
403e93f7393Sniklas     &builtin_type_m2_int,
404e93f7393Sniklas     &builtin_type_m2_card,
405e93f7393Sniklas     &builtin_type_m2_real,
406e93f7393Sniklas     &builtin_type_m2_bool,
407e93f7393Sniklas     0
408e93f7393Sniklas };
409e93f7393Sniklas 
410b725ae77Skettenis const struct language_defn m2_language_defn =
411b725ae77Skettenis {
412e93f7393Sniklas   "modula-2",
413e93f7393Sniklas   language_m2,
414e93f7393Sniklas   m2_builtin_types,
415e93f7393Sniklas   range_check_on,
416e93f7393Sniklas   type_check_on,
417b725ae77Skettenis   case_sensitive_on,
418*63addd46Skettenis   array_row_major,
419b725ae77Skettenis   &exp_descriptor_standard,
420e93f7393Sniklas   m2_parse,			/* parser */
421e93f7393Sniklas   m2_error,			/* parser error function */
422*63addd46Skettenis   null_post_parser,
423e93f7393Sniklas   m2_printchar,			/* Print character constant */
424e93f7393Sniklas   m2_printstr,			/* function to print string constant */
425b725ae77Skettenis   m2_emit_char,			/* Function to print a single character */
426e93f7393Sniklas   m2_create_fundamental_type,	/* Create fundamental type in this language */
427e93f7393Sniklas   m2_print_type,		/* Print a type using appropriate syntax */
428e93f7393Sniklas   m2_val_print,			/* Print a value using appropriate syntax */
429e93f7393Sniklas   c_value_print,		/* Print a top-level value */
430b725ae77Skettenis   NULL,				/* Language specific skip_trampoline */
431b725ae77Skettenis   value_of_this,		/* value_of_this */
432b725ae77Skettenis   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
433b725ae77Skettenis   basic_lookup_transparent_type,/* lookup_transparent_type */
434b725ae77Skettenis   NULL,				/* Language specific symbol demangler */
435*63addd46Skettenis   NULL,				/* Language specific class_name_from_physname */
436e93f7393Sniklas   m2_op_print_tab,		/* expression operators for printing */
437e93f7393Sniklas   0,				/* arrays are first-class (not c-style) */
438e93f7393Sniklas   0,				/* String lower bound */
439e93f7393Sniklas   &builtin_type_m2_char,	/* Type of string elements */
440b725ae77Skettenis   default_word_break_characters,
441*63addd46Skettenis   NULL, /* FIXME: la_language_arch_info.  */
442e93f7393Sniklas   LANG_MAGIC
443e93f7393Sniklas };
444e93f7393Sniklas 
445e93f7393Sniklas /* Initialization for Modula-2 */
446e93f7393Sniklas 
447e93f7393Sniklas void
_initialize_m2_language(void)448b725ae77Skettenis _initialize_m2_language (void)
449e93f7393Sniklas {
450e93f7393Sniklas   /* Modula-2 "pervasive" types.  NOTE:  these can be redefined!!! */
451e93f7393Sniklas   builtin_type_m2_int =
452e93f7393Sniklas     init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
453e93f7393Sniklas 	       0,
454e93f7393Sniklas 	       "INTEGER", (struct objfile *) NULL);
455e93f7393Sniklas   builtin_type_m2_card =
456e93f7393Sniklas     init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
457e93f7393Sniklas 	       TYPE_FLAG_UNSIGNED,
458e93f7393Sniklas 	       "CARDINAL", (struct objfile *) NULL);
459e93f7393Sniklas   builtin_type_m2_real =
460e93f7393Sniklas     init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
461e93f7393Sniklas 	       0,
462e93f7393Sniklas 	       "REAL", (struct objfile *) NULL);
463e93f7393Sniklas   builtin_type_m2_char =
464e93f7393Sniklas     init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
465e93f7393Sniklas 	       TYPE_FLAG_UNSIGNED,
466e93f7393Sniklas 	       "CHAR", (struct objfile *) NULL);
467e93f7393Sniklas   builtin_type_m2_bool =
468e93f7393Sniklas     init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT,
469e93f7393Sniklas 	       TYPE_FLAG_UNSIGNED,
470e93f7393Sniklas 	       "BOOLEAN", (struct objfile *) NULL);
471e93f7393Sniklas 
472e93f7393Sniklas   add_language (&m2_language_defn);
473e93f7393Sniklas }
474