Set default LANGUAGE to english/us.
[deliverable/binutils-gdb.git] / gdb / parse.c
CommitLineData
c906108c 1/* Parse expressions for GDB.
b6ba6518
KB
2 Copyright 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
c906108c
SS
4 Modified from expread.y by the Department of Computer Science at the
5 State University of New York at Buffalo, 1991.
6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b
JM
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
c906108c
SS
23
24/* Parse an expression from text in a string,
25 and return the result as a struct expression pointer.
26 That structure contains arithmetic operations in reverse polish,
27 with constants represented by operations that are followed by special data.
28 See expression.h for the details of the format.
29 What is important here is that it can be built up sequentially
30 during the process of parsing; the lower levels of the tree always
31 come first in the result. */
c5aa993b 32
cce74817
JM
33#include <ctype.h>
34
c906108c
SS
35#include "defs.h"
36#include "gdb_string.h"
c906108c
SS
37#include "symtab.h"
38#include "gdbtypes.h"
39#include "frame.h"
40#include "expression.h"
41#include "value.h"
42#include "command.h"
43#include "language.h"
44#include "parser-defs.h"
45#include "gdbcmd.h"
c5aa993b 46#include "symfile.h" /* for overlay functions */
e2305d34
MS
47#include "inferior.h" /* for NUM_PSEUDO_REGS. NOTE: replace
48 with "gdbarch.h" when appropriate. */
d16aafd8 49#include "doublest.h"
0406ec40
AC
50#include "builtin-regs.h"
51#include "gdb_assert.h"
e2305d34 52
2df3850c
JM
53\f
54/* Symbols which architectures can redefine. */
55
56/* Some systems have routines whose names start with `$'. Giving this
57 macro a non-zero value tells GDB's expression parser to check for
58 such routines when parsing tokens that begin with `$'.
59
60 On HP-UX, certain system routines (millicode) have names beginning
61 with `$' or `$$'. For example, `$$dyncall' is a millicode routine
62 that handles inter-space procedure calls on PA-RISC. */
63#ifndef SYMBOLS_CAN_START_WITH_DOLLAR
64#define SYMBOLS_CAN_START_WITH_DOLLAR (0)
65#endif
66
67
c906108c
SS
68\f
69/* Global variables declared in parser-defs.h (and commented there). */
70struct expression *expout;
71int expout_size;
72int expout_ptr;
73struct block *expression_context_block;
74struct block *innermost_block;
75int arglist_len;
76union type_stack_elt *type_stack;
77int type_stack_depth, type_stack_size;
78char *lexptr;
79char *namecopy;
80int paren_depth;
81int comma_terminates;
82\f
c906108c 83static int expressiondebug = 0;
c906108c
SS
84
85extern int hp_som_som_object_present;
86
74b7792f 87static void free_funcalls (void *ignore);
c906108c 88
a14ed312 89static void prefixify_expression (struct expression *);
c906108c
SS
90
91static void
a14ed312 92prefixify_subexp (struct expression *, struct expression *, int, int);
c906108c 93
a14ed312 94void _initialize_parse (void);
392a587b 95
c906108c
SS
96/* Data structure for saving values of arglist_len for function calls whose
97 arguments contain other function calls. */
98
99struct funcall
100 {
101 struct funcall *next;
102 int arglist_len;
103 };
104
105static struct funcall *funcall_chain;
106
107/* Assign machine-independent names to certain registers
108 (unless overridden by the REGISTER_NAMES table) */
109
c906108c 110unsigned num_std_regs = 0;
cce74817 111struct std_regs *std_regs;
c906108c
SS
112
113/* The generic method for targets to specify how their registers are
114 named. The mapping can be derived from three sources:
115 REGISTER_NAME; std_regs; or a target specific alias hook. */
116
117int
fba45db2 118target_map_name_to_register (char *str, int len)
c906108c
SS
119{
120 int i;
121
d1c7e53b
AC
122 /* Search register name space. */
123 for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
1a1404f1
MS
124 if (REGISTER_NAME (i) && len == strlen (REGISTER_NAME (i))
125 && STREQN (str, REGISTER_NAME (i), len))
126 {
127 return i;
128 }
129
130 /* Try standard aliases. */
c906108c
SS
131 for (i = 0; i < num_std_regs; i++)
132 if (std_regs[i].name && len == strlen (std_regs[i].name)
133 && STREQN (str, std_regs[i].name, len))
134 {
135 return std_regs[i].regnum;
136 }
137
0406ec40
AC
138 /* Try builtin registers. */
139 i = builtin_reg_map_name_to_regnum (str, len);
140 if (i >= 0)
141 {
142 gdb_assert (i >= NUM_REGS + NUM_PSEUDO_REGS);
143 return i;
144 }
145
c906108c
SS
146 return -1;
147}
148
149/* Begin counting arguments for a function call,
150 saving the data about any containing call. */
151
152void
fba45db2 153start_arglist (void)
c906108c
SS
154{
155 register struct funcall *new;
156
157 new = (struct funcall *) xmalloc (sizeof (struct funcall));
158 new->next = funcall_chain;
159 new->arglist_len = arglist_len;
160 arglist_len = 0;
161 funcall_chain = new;
162}
163
164/* Return the number of arguments in a function call just terminated,
165 and restore the data for the containing function call. */
166
167int
fba45db2 168end_arglist (void)
c906108c
SS
169{
170 register int val = arglist_len;
171 register struct funcall *call = funcall_chain;
172 funcall_chain = call->next;
173 arglist_len = call->arglist_len;
b8c9b27d 174 xfree (call);
c906108c
SS
175 return val;
176}
177
178/* Free everything in the funcall chain.
179 Used when there is an error inside parsing. */
180
181static void
74b7792f 182free_funcalls (void *ignore)
c906108c
SS
183{
184 register struct funcall *call, *next;
185
186 for (call = funcall_chain; call; call = next)
187 {
188 next = call->next;
b8c9b27d 189 xfree (call);
c906108c
SS
190 }
191}
192\f
193/* This page contains the functions for adding data to the struct expression
194 being constructed. */
195
196/* Add one element to the end of the expression. */
197
198/* To avoid a bug in the Sun 4 compiler, we pass things that can fit into
199 a register through here */
200
201void
fba45db2 202write_exp_elt (union exp_element expelt)
c906108c
SS
203{
204 if (expout_ptr >= expout_size)
205 {
206 expout_size *= 2;
207 expout = (struct expression *)
208 xrealloc ((char *) expout, sizeof (struct expression)
209 + EXP_ELEM_TO_BYTES (expout_size));
210 }
211 expout->elts[expout_ptr++] = expelt;
212}
213
214void
fba45db2 215write_exp_elt_opcode (enum exp_opcode expelt)
c906108c
SS
216{
217 union exp_element tmp;
218
219 tmp.opcode = expelt;
220
221 write_exp_elt (tmp);
222}
223
224void
fba45db2 225write_exp_elt_sym (struct symbol *expelt)
c906108c
SS
226{
227 union exp_element tmp;
228
229 tmp.symbol = expelt;
230
231 write_exp_elt (tmp);
232}
233
234void
fba45db2 235write_exp_elt_block (struct block *b)
c906108c
SS
236{
237 union exp_element tmp;
238 tmp.block = b;
239 write_exp_elt (tmp);
240}
241
242void
fba45db2 243write_exp_elt_longcst (LONGEST expelt)
c906108c
SS
244{
245 union exp_element tmp;
246
247 tmp.longconst = expelt;
248
249 write_exp_elt (tmp);
250}
251
252void
fba45db2 253write_exp_elt_dblcst (DOUBLEST expelt)
c906108c
SS
254{
255 union exp_element tmp;
256
257 tmp.doubleconst = expelt;
258
259 write_exp_elt (tmp);
260}
261
262void
fba45db2 263write_exp_elt_type (struct type *expelt)
c906108c
SS
264{
265 union exp_element tmp;
266
267 tmp.type = expelt;
268
269 write_exp_elt (tmp);
270}
271
272void
fba45db2 273write_exp_elt_intern (struct internalvar *expelt)
c906108c
SS
274{
275 union exp_element tmp;
276
277 tmp.internalvar = expelt;
278
279 write_exp_elt (tmp);
280}
281
282/* Add a string constant to the end of the expression.
283
284 String constants are stored by first writing an expression element
285 that contains the length of the string, then stuffing the string
286 constant itself into however many expression elements are needed
287 to hold it, and then writing another expression element that contains
288 the length of the string. I.E. an expression element at each end of
289 the string records the string length, so you can skip over the
290 expression elements containing the actual string bytes from either
291 end of the string. Note that this also allows gdb to handle
292 strings with embedded null bytes, as is required for some languages.
293
294 Don't be fooled by the fact that the string is null byte terminated,
295 this is strictly for the convenience of debugging gdb itself. Gdb
296 Gdb does not depend up the string being null terminated, since the
297 actual length is recorded in expression elements at each end of the
298 string. The null byte is taken into consideration when computing how
299 many expression elements are required to hold the string constant, of
300 course. */
301
302
303void
fba45db2 304write_exp_string (struct stoken str)
c906108c
SS
305{
306 register int len = str.length;
307 register int lenelt;
308 register char *strdata;
309
310 /* Compute the number of expression elements required to hold the string
311 (including a null byte terminator), along with one expression element
312 at each end to record the actual string length (not including the
313 null byte terminator). */
314
315 lenelt = 2 + BYTES_TO_EXP_ELEM (len + 1);
316
317 /* Ensure that we have enough available expression elements to store
318 everything. */
319
320 if ((expout_ptr + lenelt) >= expout_size)
321 {
322 expout_size = max (expout_size * 2, expout_ptr + lenelt + 10);
323 expout = (struct expression *)
324 xrealloc ((char *) expout, (sizeof (struct expression)
325 + EXP_ELEM_TO_BYTES (expout_size)));
326 }
327
328 /* Write the leading length expression element (which advances the current
329 expression element index), then write the string constant followed by a
330 terminating null byte, and then write the trailing length expression
331 element. */
332
333 write_exp_elt_longcst ((LONGEST) len);
334 strdata = (char *) &expout->elts[expout_ptr];
335 memcpy (strdata, str.ptr, len);
336 *(strdata + len) = '\0';
337 expout_ptr += lenelt - 2;
338 write_exp_elt_longcst ((LONGEST) len);
339}
340
341/* Add a bitstring constant to the end of the expression.
342
343 Bitstring constants are stored by first writing an expression element
344 that contains the length of the bitstring (in bits), then stuffing the
345 bitstring constant itself into however many expression elements are
346 needed to hold it, and then writing another expression element that
347 contains the length of the bitstring. I.E. an expression element at
348 each end of the bitstring records the bitstring length, so you can skip
349 over the expression elements containing the actual bitstring bytes from
350 either end of the bitstring. */
351
352void
fba45db2 353write_exp_bitstring (struct stoken str)
c906108c
SS
354{
355 register int bits = str.length; /* length in bits */
356 register int len = (bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
357 register int lenelt;
358 register char *strdata;
359
360 /* Compute the number of expression elements required to hold the bitstring,
361 along with one expression element at each end to record the actual
362 bitstring length in bits. */
363
364 lenelt = 2 + BYTES_TO_EXP_ELEM (len);
365
366 /* Ensure that we have enough available expression elements to store
367 everything. */
368
369 if ((expout_ptr + lenelt) >= expout_size)
370 {
371 expout_size = max (expout_size * 2, expout_ptr + lenelt + 10);
372 expout = (struct expression *)
373 xrealloc ((char *) expout, (sizeof (struct expression)
374 + EXP_ELEM_TO_BYTES (expout_size)));
375 }
376
377 /* Write the leading length expression element (which advances the current
378 expression element index), then write the bitstring constant, and then
379 write the trailing length expression element. */
380
381 write_exp_elt_longcst ((LONGEST) bits);
382 strdata = (char *) &expout->elts[expout_ptr];
383 memcpy (strdata, str.ptr, len);
384 expout_ptr += lenelt - 2;
385 write_exp_elt_longcst ((LONGEST) bits);
386}
387
388/* Add the appropriate elements for a minimal symbol to the end of
389 the expression. The rationale behind passing in text_symbol_type and
390 data_symbol_type was so that Modula-2 could pass in WORD for
391 data_symbol_type. Perhaps it still is useful to have those types vary
392 based on the language, but they no longer have names like "int", so
393 the initial rationale is gone. */
394
395static struct type *msym_text_symbol_type;
396static struct type *msym_data_symbol_type;
397static struct type *msym_unknown_symbol_type;
398
399void
a858089e
MS
400write_exp_msymbol (struct minimal_symbol *msymbol,
401 struct type *text_symbol_type,
402 struct type *data_symbol_type)
c906108c
SS
403{
404 CORE_ADDR addr;
405
406 write_exp_elt_opcode (OP_LONG);
a858089e
MS
407 /* Let's make the type big enough to hold a 64-bit address. */
408 write_exp_elt_type (builtin_type_CORE_ADDR);
c906108c
SS
409
410 addr = SYMBOL_VALUE_ADDRESS (msymbol);
411 if (overlay_debugging)
412 addr = symbol_overlayed_address (addr, SYMBOL_BFD_SECTION (msymbol));
413 write_exp_elt_longcst ((LONGEST) addr);
c5aa993b 414
c906108c
SS
415 write_exp_elt_opcode (OP_LONG);
416
417 write_exp_elt_opcode (UNOP_MEMVAL);
c5aa993b 418 switch (msymbol->type)
c906108c
SS
419 {
420 case mst_text:
421 case mst_file_text:
422 case mst_solib_trampoline:
423 write_exp_elt_type (msym_text_symbol_type);
424 break;
425
426 case mst_data:
427 case mst_file_data:
428 case mst_bss:
429 case mst_file_bss:
430 write_exp_elt_type (msym_data_symbol_type);
431 break;
432
433 default:
434 write_exp_elt_type (msym_unknown_symbol_type);
435 break;
436 }
437 write_exp_elt_opcode (UNOP_MEMVAL);
438}
439\f
440/* Recognize tokens that start with '$'. These include:
441
c5aa993b
JM
442 $regname A native register name or a "standard
443 register name".
c906108c 444
c5aa993b
JM
445 $variable A convenience variable with a name chosen
446 by the user.
c906108c 447
c5aa993b
JM
448 $digits Value history with index <digits>, starting
449 from the first value which has index 1.
c906108c 450
c5aa993b
JM
451 $$digits Value history with index <digits> relative
452 to the last value. I.E. $$0 is the last
453 value, $$1 is the one previous to that, $$2
454 is the one previous to $$1, etc.
c906108c 455
c5aa993b 456 $ | $0 | $$0 The last value in the value history.
c906108c 457
c5aa993b
JM
458 $$ An abbreviation for the second to the last
459 value in the value history, I.E. $$1
c906108c 460
c5aa993b 461 */
c906108c
SS
462
463void
fba45db2 464write_dollar_variable (struct stoken str)
c906108c
SS
465{
466 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
467 and $$digits (equivalent to $<-digits> if you could type that). */
468
c906108c
SS
469 int negate = 0;
470 int i = 1;
471 /* Double dollar means negate the number and add -1 as well.
472 Thus $$ alone means -1. */
473 if (str.length >= 2 && str.ptr[1] == '$')
474 {
475 negate = 1;
476 i = 2;
477 }
478 if (i == str.length)
479 {
480 /* Just dollars (one or two) */
c5aa993b 481 i = -negate;
c906108c
SS
482 goto handle_last;
483 }
484 /* Is the rest of the token digits? */
485 for (; i < str.length; i++)
486 if (!(str.ptr[i] >= '0' && str.ptr[i] <= '9'))
487 break;
488 if (i == str.length)
489 {
490 i = atoi (str.ptr + 1 + negate);
491 if (negate)
c5aa993b 492 i = -i;
c906108c
SS
493 goto handle_last;
494 }
c5aa993b 495
c906108c
SS
496 /* Handle tokens that refer to machine registers:
497 $ followed by a register name. */
c5aa993b
JM
498 i = target_map_name_to_register (str.ptr + 1, str.length - 1);
499 if (i >= 0)
c906108c
SS
500 goto handle_register;
501
2df3850c 502 if (SYMBOLS_CAN_START_WITH_DOLLAR)
c906108c 503 {
2df3850c
JM
504 struct symbol *sym = NULL;
505 struct minimal_symbol *msym = NULL;
506
507 /* On HP-UX, certain system routines (millicode) have names beginning
508 with $ or $$, e.g. $$dyncall, which handles inter-space procedure
509 calls on PA-RISC. Check for those, first. */
510
511 /* This code is not enabled on non HP-UX systems, since worst case
512 symbol table lookup performance is awful, to put it mildly. */
513
514 sym = lookup_symbol (copy_name (str), (struct block *) NULL,
515 VAR_NAMESPACE, (int *) NULL, (struct symtab **) NULL);
516 if (sym)
517 {
518 write_exp_elt_opcode (OP_VAR_VALUE);
519 write_exp_elt_block (block_found); /* set by lookup_symbol */
520 write_exp_elt_sym (sym);
521 write_exp_elt_opcode (OP_VAR_VALUE);
522 return;
523 }
524 msym = lookup_minimal_symbol (copy_name (str), NULL, NULL);
525 if (msym)
526 {
527 write_exp_msymbol (msym,
528 lookup_function_type (builtin_type_int),
529 builtin_type_int);
530 return;
531 }
c906108c 532 }
c5aa993b 533
c906108c
SS
534 /* Any other names starting in $ are debugger internal variables. */
535
536 write_exp_elt_opcode (OP_INTERNALVAR);
537 write_exp_elt_intern (lookup_internalvar (copy_name (str) + 1));
c5aa993b 538 write_exp_elt_opcode (OP_INTERNALVAR);
c906108c 539 return;
c5aa993b 540handle_last:
c906108c
SS
541 write_exp_elt_opcode (OP_LAST);
542 write_exp_elt_longcst ((LONGEST) i);
543 write_exp_elt_opcode (OP_LAST);
544 return;
c5aa993b 545handle_register:
c906108c
SS
546 write_exp_elt_opcode (OP_REGISTER);
547 write_exp_elt_longcst (i);
c5aa993b 548 write_exp_elt_opcode (OP_REGISTER);
c906108c
SS
549 return;
550}
551
552
553/* Parse a string that is possibly a namespace / nested class
554 specification, i.e., something of the form A::B::C::x. Input
555 (NAME) is the entire string; LEN is the current valid length; the
556 output is a string, TOKEN, which points to the largest recognized
557 prefix which is a series of namespaces or classes. CLASS_PREFIX is
558 another output, which records whether a nested class spec was
559 recognized (= 1) or a fully qualified variable name was found (=
560 0). ARGPTR is side-effected (if non-NULL) to point to beyond the
561 string recognized and consumed by this routine.
562
563 The return value is a pointer to the symbol for the base class or
564 variable if found, or NULL if not found. Callers must check this
565 first -- if NULL, the outputs may not be correct.
566
567 This function is used c-exp.y. This is used specifically to get
568 around HP aCC (and possibly other compilers), which insists on
569 generating names with embedded colons for namespace or nested class
570 members.
571
572 (Argument LEN is currently unused. 1997-08-27)
573
574 Callers must free memory allocated for the output string TOKEN. */
575
c5aa993b
JM
576static const char coloncolon[2] =
577{':', ':'};
c906108c
SS
578
579struct symbol *
fba45db2
KB
580parse_nested_classes_for_hpacc (char *name, int len, char **token,
581 int *class_prefix, char **argptr)
c906108c 582{
c5aa993b
JM
583 /* Comment below comes from decode_line_1 which has very similar
584 code, which is called for "break" command parsing. */
585
586 /* We have what looks like a class or namespace
c906108c
SS
587 scope specification (A::B), possibly with many
588 levels of namespaces or classes (A::B::C::D).
589
590 Some versions of the HP ANSI C++ compiler (as also possibly
591 other compilers) generate class/function/member names with
592 embedded double-colons if they are inside namespaces. To
593 handle this, we loop a few times, considering larger and
594 larger prefixes of the string as though they were single
595 symbols. So, if the initially supplied string is
596 A::B::C::D::foo, we have to look up "A", then "A::B",
597 then "A::B::C", then "A::B::C::D", and finally
598 "A::B::C::D::foo" as single, monolithic symbols, because
599 A, B, C or D may be namespaces.
600
601 Note that namespaces can nest only inside other
602 namespaces, and not inside classes. So we need only
603 consider *prefixes* of the string; there is no need to look up
604 "B::C" separately as a symbol in the previous example. */
605
c5aa993b
JM
606 register char *p;
607 char *start, *end;
608 char *prefix = NULL;
609 char *tmp;
610 struct symbol *sym_class = NULL;
611 struct symbol *sym_var = NULL;
612 struct type *t;
c906108c
SS
613 int prefix_len = 0;
614 int done = 0;
c5aa993b 615 char *q;
c906108c
SS
616
617 /* Check for HP-compiled executable -- in other cases
618 return NULL, and caller must default to standard GDB
619 behaviour. */
620
621 if (!hp_som_som_object_present)
622 return (struct symbol *) NULL;
623
624 p = name;
625
c5aa993b
JM
626 /* Skip over whitespace and possible global "::" */
627 while (*p && (*p == ' ' || *p == '\t'))
628 p++;
c906108c
SS
629 if (p[0] == ':' && p[1] == ':')
630 p += 2;
c5aa993b
JM
631 while (*p && (*p == ' ' || *p == '\t'))
632 p++;
633
c906108c
SS
634 while (1)
635 {
636 /* Get to the end of the next namespace or class spec. */
637 /* If we're looking at some non-token, fail immediately */
638 start = p;
639 if (!(isalpha (*p) || *p == '$' || *p == '_'))
c5aa993b 640 return (struct symbol *) NULL;
c906108c 641 p++;
c5aa993b
JM
642 while (*p && (isalnum (*p) || *p == '$' || *p == '_'))
643 p++;
644
645 if (*p == '<')
646 {
647 /* If we have the start of a template specification,
648 scan right ahead to its end */
649 q = find_template_name_end (p);
650 if (q)
651 p = q;
652 }
653
c906108c
SS
654 end = p;
655
c5aa993b
JM
656 /* Skip over "::" and whitespace for next time around */
657 while (*p && (*p == ' ' || *p == '\t'))
658 p++;
c906108c 659 if (p[0] == ':' && p[1] == ':')
c5aa993b
JM
660 p += 2;
661 while (*p && (*p == ' ' || *p == '\t'))
662 p++;
c906108c 663
c5aa993b 664 /* Done with tokens? */
c906108c 665 if (!*p || !(isalpha (*p) || *p == '$' || *p == '_'))
c5aa993b 666 done = 1;
c906108c
SS
667
668 tmp = (char *) alloca (prefix_len + end - start + 3);
669 if (prefix)
c5aa993b
JM
670 {
671 memcpy (tmp, prefix, prefix_len);
672 memcpy (tmp + prefix_len, coloncolon, 2);
673 memcpy (tmp + prefix_len + 2, start, end - start);
674 tmp[prefix_len + 2 + end - start] = '\000';
675 }
c906108c 676 else
c5aa993b
JM
677 {
678 memcpy (tmp, start, end - start);
679 tmp[end - start] = '\000';
680 }
681
c906108c
SS
682 prefix = tmp;
683 prefix_len = strlen (prefix);
c5aa993b 684
c906108c
SS
685 /* See if the prefix we have now is something we know about */
686
c5aa993b
JM
687 if (!done)
688 {
689 /* More tokens to process, so this must be a class/namespace */
690 sym_class = lookup_symbol (prefix, 0, STRUCT_NAMESPACE,
691 0, (struct symtab **) NULL);
692 }
c906108c 693 else
c5aa993b
JM
694 {
695 /* No more tokens, so try as a variable first */
696 sym_var = lookup_symbol (prefix, 0, VAR_NAMESPACE,
697 0, (struct symtab **) NULL);
698 /* If failed, try as class/namespace */
699 if (!sym_var)
700 sym_class = lookup_symbol (prefix, 0, STRUCT_NAMESPACE,
701 0, (struct symtab **) NULL);
702 }
c906108c
SS
703
704 if (sym_var ||
c5aa993b
JM
705 (sym_class &&
706 (t = check_typedef (SYMBOL_TYPE (sym_class)),
707 (TYPE_CODE (t) == TYPE_CODE_STRUCT
708 || TYPE_CODE (t) == TYPE_CODE_UNION))))
709 {
710 /* We found a valid token */
711 *token = (char *) xmalloc (prefix_len + 1);
712 memcpy (*token, prefix, prefix_len);
713 (*token)[prefix_len] = '\000';
714 break;
715 }
716
717 /* No variable or class/namespace found, no more tokens */
c906108c 718 if (done)
c5aa993b 719 return (struct symbol *) NULL;
c906108c
SS
720 }
721
722 /* Out of loop, so we must have found a valid token */
723 if (sym_var)
724 *class_prefix = 0;
725 else
726 *class_prefix = 1;
727
728 if (argptr)
729 *argptr = done ? p : end;
730
c5aa993b 731 return sym_var ? sym_var : sym_class; /* found */
c906108c
SS
732}
733
734char *
fba45db2 735find_template_name_end (char *p)
c906108c
SS
736{
737 int depth = 1;
738 int just_seen_right = 0;
739 int just_seen_colon = 0;
740 int just_seen_space = 0;
c5aa993b 741
c906108c
SS
742 if (!p || (*p != '<'))
743 return 0;
744
745 while (*++p)
746 {
747 switch (*p)
c5aa993b
JM
748 {
749 case '\'':
750 case '\"':
751 case '{':
752 case '}':
753 /* In future, may want to allow these?? */
754 return 0;
755 case '<':
756 depth++; /* start nested template */
757 if (just_seen_colon || just_seen_right || just_seen_space)
758 return 0; /* but not after : or :: or > or space */
759 break;
760 case '>':
761 if (just_seen_colon || just_seen_right)
762 return 0; /* end a (nested?) template */
763 just_seen_right = 1; /* but not after : or :: */
764 if (--depth == 0) /* also disallow >>, insist on > > */
765 return ++p; /* if outermost ended, return */
766 break;
767 case ':':
768 if (just_seen_space || (just_seen_colon > 1))
769 return 0; /* nested class spec coming up */
770 just_seen_colon++; /* we allow :: but not :::: */
771 break;
772 case ' ':
773 break;
774 default:
775 if (!((*p >= 'a' && *p <= 'z') || /* allow token chars */
776 (*p >= 'A' && *p <= 'Z') ||
777 (*p >= '0' && *p <= '9') ||
778 (*p == '_') || (*p == ',') || /* commas for template args */
779 (*p == '&') || (*p == '*') || /* pointer and ref types */
780 (*p == '(') || (*p == ')') || /* function types */
781 (*p == '[') || (*p == ']'))) /* array types */
782 return 0;
783 }
c906108c 784 if (*p != ' ')
c5aa993b 785 just_seen_space = 0;
c906108c 786 if (*p != ':')
c5aa993b 787 just_seen_colon = 0;
c906108c 788 if (*p != '>')
c5aa993b 789 just_seen_right = 0;
c906108c
SS
790 }
791 return 0;
792}
c5aa993b 793\f
c906108c
SS
794
795
c906108c
SS
796/* Return a null-terminated temporary copy of the name
797 of a string token. */
798
799char *
fba45db2 800copy_name (struct stoken token)
c906108c
SS
801{
802 memcpy (namecopy, token.ptr, token.length);
803 namecopy[token.length] = 0;
804 return namecopy;
805}
806\f
807/* Reverse an expression from suffix form (in which it is constructed)
808 to prefix form (in which we can conveniently print or execute it). */
809
810static void
fba45db2 811prefixify_expression (register struct expression *expr)
c906108c
SS
812{
813 register int len =
c5aa993b 814 sizeof (struct expression) + EXP_ELEM_TO_BYTES (expr->nelts);
c906108c
SS
815 register struct expression *temp;
816 register int inpos = expr->nelts, outpos = 0;
817
818 temp = (struct expression *) alloca (len);
819
820 /* Copy the original expression into temp. */
821 memcpy (temp, expr, len);
822
823 prefixify_subexp (temp, expr, inpos, outpos);
824}
825
826/* Return the number of exp_elements in the subexpression of EXPR
827 whose last exp_element is at index ENDPOS - 1 in EXPR. */
828
829int
fba45db2 830length_of_subexp (register struct expression *expr, register int endpos)
c906108c
SS
831{
832 register int oplen = 1;
833 register int args = 0;
834 register int i;
835
836 if (endpos < 1)
837 error ("?error in length_of_subexp");
838
839 i = (int) expr->elts[endpos - 1].opcode;
840
841 switch (i)
842 {
843 /* C++ */
844 case OP_SCOPE:
845 oplen = longest_to_int (expr->elts[endpos - 2].longconst);
846 oplen = 5 + BYTES_TO_EXP_ELEM (oplen + 1);
847 break;
848
849 case OP_LONG:
850 case OP_DOUBLE:
851 case OP_VAR_VALUE:
852 oplen = 4;
853 break;
854
855 case OP_TYPE:
856 case OP_BOOL:
857 case OP_LAST:
858 case OP_REGISTER:
859 case OP_INTERNALVAR:
860 oplen = 3;
861 break;
862
863 case OP_COMPLEX:
c5aa993b 864 oplen = 1;
c906108c 865 args = 2;
c5aa993b 866 break;
c906108c
SS
867
868 case OP_FUNCALL:
869 case OP_F77_UNDETERMINED_ARGLIST:
870 oplen = 3;
871 args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
872 break;
873
874 case UNOP_MAX:
875 case UNOP_MIN:
876 oplen = 3;
877 break;
878
c5aa993b
JM
879 case BINOP_VAL:
880 case UNOP_CAST:
881 case UNOP_MEMVAL:
c906108c
SS
882 oplen = 3;
883 args = 1;
884 break;
885
886 case UNOP_ABS:
887 case UNOP_CAP:
888 case UNOP_CHR:
889 case UNOP_FLOAT:
890 case UNOP_HIGH:
891 case UNOP_ODD:
892 case UNOP_ORD:
893 case UNOP_TRUNC:
894 oplen = 1;
895 args = 1;
896 break;
897
898 case OP_LABELED:
899 case STRUCTOP_STRUCT:
900 case STRUCTOP_PTR:
901 args = 1;
902 /* fall through */
903 case OP_M2_STRING:
904 case OP_STRING:
905 case OP_NAME:
906 case OP_EXPRSTRING:
907 oplen = longest_to_int (expr->elts[endpos - 2].longconst);
908 oplen = 4 + BYTES_TO_EXP_ELEM (oplen + 1);
909 break;
910
911 case OP_BITSTRING:
912 oplen = longest_to_int (expr->elts[endpos - 2].longconst);
913 oplen = (oplen + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
914 oplen = 4 + BYTES_TO_EXP_ELEM (oplen);
915 break;
916
917 case OP_ARRAY:
918 oplen = 4;
919 args = longest_to_int (expr->elts[endpos - 2].longconst);
920 args -= longest_to_int (expr->elts[endpos - 3].longconst);
921 args += 1;
922 break;
923
924 case TERNOP_COND:
925 case TERNOP_SLICE:
926 case TERNOP_SLICE_COUNT:
927 args = 3;
928 break;
929
930 /* Modula-2 */
c5aa993b 931 case MULTI_SUBSCRIPT:
c906108c 932 oplen = 3;
c5aa993b 933 args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
c906108c
SS
934 break;
935
936 case BINOP_ASSIGN_MODIFY:
937 oplen = 3;
938 args = 2;
939 break;
940
941 /* C++ */
942 case OP_THIS:
943 oplen = 2;
944 break;
945
946 default:
947 args = 1 + (i < (int) BINOP_END);
948 }
949
950 while (args > 0)
951 {
952 oplen += length_of_subexp (expr, endpos - oplen);
953 args--;
954 }
955
956 return oplen;
957}
958
959/* Copy the subexpression ending just before index INEND in INEXPR
960 into OUTEXPR, starting at index OUTBEG.
961 In the process, convert it from suffix to prefix form. */
962
963static void
fba45db2
KB
964prefixify_subexp (register struct expression *inexpr,
965 struct expression *outexpr, register int inend, int outbeg)
c906108c
SS
966{
967 register int oplen = 1;
968 register int args = 0;
969 register int i;
970 int *arglens;
971 enum exp_opcode opcode;
972
973 /* Compute how long the last operation is (in OPLEN),
974 and also how many preceding subexpressions serve as
975 arguments for it (in ARGS). */
976
977 opcode = inexpr->elts[inend - 1].opcode;
978 switch (opcode)
979 {
980 /* C++ */
981 case OP_SCOPE:
982 oplen = longest_to_int (inexpr->elts[inend - 2].longconst);
983 oplen = 5 + BYTES_TO_EXP_ELEM (oplen + 1);
984 break;
985
986 case OP_LONG:
987 case OP_DOUBLE:
988 case OP_VAR_VALUE:
989 oplen = 4;
990 break;
991
992 case OP_TYPE:
993 case OP_BOOL:
994 case OP_LAST:
995 case OP_REGISTER:
996 case OP_INTERNALVAR:
997 oplen = 3;
998 break;
999
1000 case OP_COMPLEX:
c5aa993b
JM
1001 oplen = 1;
1002 args = 2;
1003 break;
c906108c
SS
1004
1005 case OP_FUNCALL:
1006 case OP_F77_UNDETERMINED_ARGLIST:
1007 oplen = 3;
1008 args = 1 + longest_to_int (inexpr->elts[inend - 2].longconst);
1009 break;
1010
1011 case UNOP_MIN:
1012 case UNOP_MAX:
1013 oplen = 3;
1014 break;
1015
1016 case UNOP_CAST:
1017 case UNOP_MEMVAL:
1018 oplen = 3;
1019 args = 1;
1020 break;
1021
1022 case UNOP_ABS:
1023 case UNOP_CAP:
1024 case UNOP_CHR:
1025 case UNOP_FLOAT:
1026 case UNOP_HIGH:
1027 case UNOP_ODD:
1028 case UNOP_ORD:
1029 case UNOP_TRUNC:
c5aa993b
JM
1030 oplen = 1;
1031 args = 1;
c906108c
SS
1032 break;
1033
1034 case STRUCTOP_STRUCT:
1035 case STRUCTOP_PTR:
1036 case OP_LABELED:
1037 args = 1;
1038 /* fall through */
1039 case OP_M2_STRING:
1040 case OP_STRING:
1041 case OP_NAME:
1042 case OP_EXPRSTRING:
1043 oplen = longest_to_int (inexpr->elts[inend - 2].longconst);
1044 oplen = 4 + BYTES_TO_EXP_ELEM (oplen + 1);
1045 break;
1046
1047 case OP_BITSTRING:
1048 oplen = longest_to_int (inexpr->elts[inend - 2].longconst);
1049 oplen = (oplen + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
1050 oplen = 4 + BYTES_TO_EXP_ELEM (oplen);
1051 break;
1052
1053 case OP_ARRAY:
1054 oplen = 4;
1055 args = longest_to_int (inexpr->elts[inend - 2].longconst);
1056 args -= longest_to_int (inexpr->elts[inend - 3].longconst);
1057 args += 1;
1058 break;
1059
1060 case TERNOP_COND:
1061 case TERNOP_SLICE:
1062 case TERNOP_SLICE_COUNT:
1063 args = 3;
1064 break;
1065
1066 case BINOP_ASSIGN_MODIFY:
1067 oplen = 3;
1068 args = 2;
1069 break;
1070
1071 /* Modula-2 */
c5aa993b 1072 case MULTI_SUBSCRIPT:
c906108c
SS
1073 oplen = 3;
1074 args = 1 + longest_to_int (inexpr->elts[inend - 2].longconst);
1075 break;
1076
1077 /* C++ */
1078 case OP_THIS:
1079 oplen = 2;
1080 break;
1081
1082 default:
1083 args = 1 + ((int) opcode < (int) BINOP_END);
1084 }
1085
1086 /* Copy the final operator itself, from the end of the input
1087 to the beginning of the output. */
1088 inend -= oplen;
1089 memcpy (&outexpr->elts[outbeg], &inexpr->elts[inend],
1090 EXP_ELEM_TO_BYTES (oplen));
1091 outbeg += oplen;
1092
1093 /* Find the lengths of the arg subexpressions. */
1094 arglens = (int *) alloca (args * sizeof (int));
1095 for (i = args - 1; i >= 0; i--)
1096 {
1097 oplen = length_of_subexp (inexpr, inend);
1098 arglens[i] = oplen;
1099 inend -= oplen;
1100 }
1101
1102 /* Now copy each subexpression, preserving the order of
1103 the subexpressions, but prefixifying each one.
1104 In this loop, inend starts at the beginning of
1105 the expression this level is working on
1106 and marches forward over the arguments.
1107 outbeg does similarly in the output. */
1108 for (i = 0; i < args; i++)
1109 {
1110 oplen = arglens[i];
1111 inend += oplen;
1112 prefixify_subexp (inexpr, outexpr, inend, outbeg);
1113 outbeg += oplen;
1114 }
1115}
1116\f
1117/* This page contains the two entry points to this file. */
1118
1119/* Read an expression from the string *STRINGPTR points to,
1120 parse it, and return a pointer to a struct expression that we malloc.
1121 Use block BLOCK as the lexical context for variable names;
1122 if BLOCK is zero, use the block of the selected stack frame.
1123 Meanwhile, advance *STRINGPTR to point after the expression,
1124 at the first nonwhite character that is not part of the expression
1125 (possibly a null character).
1126
1127 If COMMA is nonzero, stop if a comma is reached. */
1128
1129struct expression *
fba45db2 1130parse_exp_1 (char **stringptr, struct block *block, int comma)
c906108c
SS
1131{
1132 struct cleanup *old_chain;
1133
1134 lexptr = *stringptr;
1135
1136 paren_depth = 0;
1137 type_stack_depth = 0;
1138
1139 comma_terminates = comma;
1140
1141 if (lexptr == 0 || *lexptr == 0)
1142 error_no_arg ("expression to compute");
1143
74b7792f 1144 old_chain = make_cleanup (free_funcalls, 0 /*ignore*/);
c906108c
SS
1145 funcall_chain = 0;
1146
ae767bfb 1147 expression_context_block = block ? block : get_selected_block (0);
c906108c
SS
1148
1149 namecopy = (char *) alloca (strlen (lexptr) + 1);
1150 expout_size = 10;
1151 expout_ptr = 0;
1152 expout = (struct expression *)
1153 xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size));
1154 expout->language_defn = current_language;
c13c43fd 1155 make_cleanup (free_current_contents, &expout);
c906108c
SS
1156
1157 if (current_language->la_parser ())
1158 current_language->la_error (NULL);
1159
1160 discard_cleanups (old_chain);
1161
1162 /* Record the actual number of expression elements, and then
1163 reallocate the expression memory so that we free up any
1164 excess elements. */
1165
1166 expout->nelts = expout_ptr;
1167 expout = (struct expression *)
1168 xrealloc ((char *) expout,
1169 sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_ptr));;
1170
1171 /* Convert expression from postfix form as generated by yacc
1172 parser, to a prefix form. */
1173
c906108c 1174 if (expressiondebug)
9846de1b 1175 dump_prefix_expression (expout, gdb_stdlog,
c906108c 1176 "before conversion to prefix form");
c906108c
SS
1177
1178 prefixify_expression (expout);
1179
c906108c 1180 if (expressiondebug)
9846de1b 1181 dump_postfix_expression (expout, gdb_stdlog,
c906108c 1182 "after conversion to prefix form");
c906108c
SS
1183
1184 *stringptr = lexptr;
1185 return expout;
1186}
1187
1188/* Parse STRING as an expression, and complain if this fails
1189 to use up all of the contents of STRING. */
1190
1191struct expression *
fba45db2 1192parse_expression (char *string)
c906108c
SS
1193{
1194 register struct expression *exp;
1195 exp = parse_exp_1 (&string, 0, 0);
1196 if (*string)
1197 error ("Junk after end of expression.");
1198 return exp;
1199}
1200\f
1201/* Stuff for maintaining a stack of types. Currently just used by C, but
1202 probably useful for any language which declares its types "backwards". */
1203
47663de5
MS
1204static void
1205check_type_stack_depth (void)
c906108c
SS
1206{
1207 if (type_stack_depth == type_stack_size)
1208 {
1209 type_stack_size *= 2;
1210 type_stack = (union type_stack_elt *)
1211 xrealloc ((char *) type_stack, type_stack_size * sizeof (*type_stack));
1212 }
47663de5
MS
1213}
1214
1215void
1216push_type (enum type_pieces tp)
1217{
1218 check_type_stack_depth ();
c906108c
SS
1219 type_stack[type_stack_depth++].piece = tp;
1220}
1221
1222void
fba45db2 1223push_type_int (int n)
c906108c 1224{
47663de5 1225 check_type_stack_depth ();
c906108c
SS
1226 type_stack[type_stack_depth++].int_val = n;
1227}
1228
47663de5
MS
1229void
1230push_type_address_space (char *string)
1231{
1232 push_type_int (address_space_name_to_int (string));
1233}
1234
c5aa993b 1235enum type_pieces
fba45db2 1236pop_type (void)
c906108c
SS
1237{
1238 if (type_stack_depth)
1239 return type_stack[--type_stack_depth].piece;
1240 return tp_end;
1241}
1242
1243int
fba45db2 1244pop_type_int (void)
c906108c
SS
1245{
1246 if (type_stack_depth)
1247 return type_stack[--type_stack_depth].int_val;
1248 /* "Can't happen". */
1249 return 0;
1250}
1251
1252/* Pop the type stack and return the type which corresponds to FOLLOW_TYPE
1253 as modified by all the stuff on the stack. */
1254struct type *
fba45db2 1255follow_types (struct type *follow_type)
c906108c
SS
1256{
1257 int done = 0;
2e2394a0
MS
1258 int make_const = 0;
1259 int make_volatile = 0;
47663de5 1260 int make_addr_space = 0;
c906108c
SS
1261 int array_size;
1262 struct type *range_type;
1263
1264 while (!done)
1265 switch (pop_type ())
1266 {
1267 case tp_end:
1268 done = 1;
2e2394a0
MS
1269 if (make_const)
1270 follow_type = make_cv_type (make_const,
1271 TYPE_VOLATILE (follow_type),
1272 follow_type, 0);
1273 if (make_volatile)
1274 follow_type = make_cv_type (TYPE_CONST (follow_type),
1275 make_volatile,
1276 follow_type, 0);
47663de5
MS
1277 if (make_addr_space)
1278 follow_type = make_type_with_address_space (follow_type,
1279 make_addr_space);
1280 make_const = make_volatile = 0;
1281 make_addr_space = 0;
2e2394a0
MS
1282 break;
1283 case tp_const:
1284 make_const = 1;
1285 break;
1286 case tp_volatile:
1287 make_volatile = 1;
c906108c 1288 break;
47663de5
MS
1289 case tp_space_identifier:
1290 make_addr_space = pop_type_int ();
1291 break;
c906108c
SS
1292 case tp_pointer:
1293 follow_type = lookup_pointer_type (follow_type);
2e2394a0
MS
1294 if (make_const)
1295 follow_type = make_cv_type (make_const,
1296 TYPE_VOLATILE (follow_type),
1297 follow_type, 0);
1298 if (make_volatile)
1299 follow_type = make_cv_type (TYPE_CONST (follow_type),
1300 make_volatile,
1301 follow_type, 0);
47663de5
MS
1302 if (make_addr_space)
1303 follow_type = make_type_with_address_space (follow_type,
1304 make_addr_space);
2e2394a0 1305 make_const = make_volatile = 0;
47663de5 1306 make_addr_space = 0;
c906108c
SS
1307 break;
1308 case tp_reference:
1309 follow_type = lookup_reference_type (follow_type);
2e2394a0 1310 if (make_const)
47663de5
MS
1311 follow_type = make_cv_type (make_const,
1312 TYPE_VOLATILE (follow_type),
1313 follow_type, 0);
2e2394a0 1314 if (make_volatile)
47663de5
MS
1315 follow_type = make_cv_type (TYPE_CONST (follow_type),
1316 make_volatile,
1317 follow_type, 0);
1318 if (make_addr_space)
1319 follow_type = make_type_with_address_space (follow_type,
1320 make_addr_space);
2e2394a0 1321 make_const = make_volatile = 0;
47663de5 1322 make_addr_space = 0;
c906108c
SS
1323 break;
1324 case tp_array:
1325 array_size = pop_type_int ();
1326 /* FIXME-type-allocation: need a way to free this type when we are
1327 done with it. */
1328 range_type =
1329 create_range_type ((struct type *) NULL,
1330 builtin_type_int, 0,
1331 array_size >= 0 ? array_size - 1 : 0);
1332 follow_type =
1333 create_array_type ((struct type *) NULL,
1334 follow_type, range_type);
1335 if (array_size < 0)
c5aa993b 1336 TYPE_ARRAY_UPPER_BOUND_TYPE (follow_type)
c906108c
SS
1337 = BOUND_CANNOT_BE_DETERMINED;
1338 break;
1339 case tp_function:
1340 /* FIXME-type-allocation: need a way to free this type when we are
1341 done with it. */
1342 follow_type = lookup_function_type (follow_type);
1343 break;
1344 }
1345 return follow_type;
1346}
1347\f
a14ed312 1348static void build_parse (void);
ac9a91a7 1349static void
fba45db2 1350build_parse (void)
c906108c 1351{
cce74817
JM
1352 int i;
1353
c906108c
SS
1354 msym_text_symbol_type =
1355 init_type (TYPE_CODE_FUNC, 1, 0, "<text variable, no debug info>", NULL);
1356 TYPE_TARGET_TYPE (msym_text_symbol_type) = builtin_type_int;
1357 msym_data_symbol_type =
1358 init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
1359 "<data variable, no debug info>", NULL);
1360 msym_unknown_symbol_type =
1361 init_type (TYPE_CODE_INT, 1, 0,
1362 "<variable (not text or data), no debug info>",
1363 NULL);
cce74817
JM
1364
1365 /* create the std_regs table */
1366
1367 num_std_regs = 0;
1368#ifdef PC_REGNUM
1369 if (PC_REGNUM >= 0)
1370 num_std_regs++;
1371#endif
1372#ifdef FP_REGNUM
1373 if (FP_REGNUM >= 0)
1374 num_std_regs++;
1375#endif
adf40b2e 1376#ifdef SP_REGNUM
cce74817
JM
1377 if (SP_REGNUM >= 0)
1378 num_std_regs++;
1379#endif
1380#ifdef PS_REGNUM
1381 if (PS_REGNUM >= 0)
1382 num_std_regs++;
1383#endif
1384 /* create an empty table */
1385 std_regs = xmalloc ((num_std_regs + 1) * sizeof *std_regs);
1386 i = 0;
1387 /* fill it in */
1388#ifdef PC_REGNUM
538155bd
DT
1389 if (PC_REGNUM >= 0)
1390 {
1391 std_regs[i].name = "pc";
1392 std_regs[i].regnum = PC_REGNUM;
1393 i++;
1394 }
cce74817
JM
1395#endif
1396#ifdef FP_REGNUM
538155bd
DT
1397 if (FP_REGNUM >= 0)
1398 {
1399 std_regs[i].name = "fp";
1400 std_regs[i].regnum = FP_REGNUM;
1401 i++;
1402 }
cce74817
JM
1403#endif
1404#ifdef SP_REGNUM
538155bd
DT
1405 if (SP_REGNUM >= 0)
1406 {
1407 std_regs[i].name = "sp";
1408 std_regs[i].regnum = SP_REGNUM;
1409 i++;
1410 }
cce74817
JM
1411#endif
1412#ifdef PS_REGNUM
538155bd
DT
1413 if (PS_REGNUM >= 0)
1414 {
1415 std_regs[i].name = "ps";
1416 std_regs[i].regnum = PS_REGNUM;
1417 i++;
1418 }
cce74817
JM
1419#endif
1420 memset (&std_regs[i], 0, sizeof (std_regs[i]));
ac9a91a7
JM
1421}
1422
1423void
fba45db2 1424_initialize_parse (void)
ac9a91a7
JM
1425{
1426 type_stack_size = 80;
1427 type_stack_depth = 0;
1428 type_stack = (union type_stack_elt *)
1429 xmalloc (type_stack_size * sizeof (*type_stack));
1430
1431 build_parse ();
c906108c 1432
0f71a2f6
JM
1433 /* FIXME - For the moment, handle types by swapping them in and out.
1434 Should be using the per-architecture data-pointer and a large
1435 struct. */
1436 register_gdbarch_swap (&msym_text_symbol_type, sizeof (msym_text_symbol_type), NULL);
1437 register_gdbarch_swap (&msym_data_symbol_type, sizeof (msym_data_symbol_type), NULL);
1438 register_gdbarch_swap (&msym_unknown_symbol_type, sizeof (msym_unknown_symbol_type), NULL);
1439
1440 register_gdbarch_swap (&num_std_regs, sizeof (std_regs), NULL);
1441 register_gdbarch_swap (&std_regs, sizeof (std_regs), NULL);
1442 register_gdbarch_swap (NULL, 0, build_parse);
1443
c906108c 1444 add_show_from_set (
5d161b24 1445 add_set_cmd ("expression", class_maintenance, var_zinteger,
c5aa993b
JM
1446 (char *) &expressiondebug,
1447 "Set expression debugging.\n\
c906108c 1448When non-zero, the internal representation of expressions will be printed.",
5d161b24
DB
1449 &setdebuglist),
1450 &showdebuglist);
c906108c 1451}
This page took 0.237626 seconds and 4 git commands to generate.