1 /* Scheme/Guile language support routines for GDB, the GNU debugger.
3 Copyright (C) 1995, 1996, 2000, 2003, 2005, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
25 #include "parser-defs.h"
32 #define USE_EXPRSTRING 0
34 static void scm_lreadparen (int);
35 static int scm_skip_ws (void);
36 static void scm_read_token (int, int);
37 static LONGEST scm_istring2number (char *, int, int);
38 static LONGEST scm_istr2int (char *, int, int);
39 static void scm_lreadr (int);
42 scm_istr2int (char *str, int len, int radix)
50 return SCM_BOOL_F; /* zero scm_length */
57 return SCM_BOOL_F; /* bad if lone `+' or `-' */
92 return SCM_BOOL_F; /* bad digit for radix */
97 return SCM_BOOL_F; /* not a digit */
103 return SCM_MAKINUM (inum);
107 scm_istring2number (char *str, int len, int radix)
111 char ex_p = 0, rx_p = 0; /* Only allow 1 exactness and 1 radix prefix */
117 if (*str == '+' || *str == '-') /* Catches lone `+' and `-' for speed */
120 while ((len - i) >= 2 && str[i] == '#' && ++i)
166 return scm_istr2int (&str[i], len - i, radix);
168 return scm_istr2int (&str[i], len - i, radix);
174 return scm_istr2flo (&str[i], len - i, radix);
182 scm_read_token (int c, int weird)
202 case '\0': /* End of line */
244 switch ((c = *lexptr++))
251 switch ((c = *lexptr++))
272 scm_lreadparen (int skipping)
276 int c = scm_skip_ws ();
278 if (')' == c || ']' == c)
282 error ("missing close paren");
283 scm_lreadr (skipping);
288 scm_lreadr (int skipping)
303 scm_lreadparen (skipping);
307 error ("unexpected #\\%c", c);
311 str.ptr = lexptr - 1;
312 scm_lreadr (skipping);
315 struct value *val = scm_evaluate_string (str.ptr, lexptr - str.ptr);
317 if (!is_scmvalue_type (value_type (val)))
318 error ("quoted scm form yields non-SCM value");
319 svalue = extract_signed_integer (value_contents (val),
320 TYPE_LENGTH (value_type (val)),
321 gdbarch_byte_order (parse_gdbarch));
322 goto handle_immediate;
329 scm_lreadr (skipping);
337 scm_lreadparen (skipping);
342 goto handle_immediate;
346 goto handle_immediate;
362 case '*': /* bitvector */
363 scm_read_token (c, 0);
366 scm_read_token (c, 1);
368 case '\\': /* character */
370 scm_read_token (c, 0);
373 j = 1; /* here j is the comment nesting depth */
380 error ("unbalanced comment");
384 if ('#' != (c = *lexptr++))
390 if ('|' != (c = *lexptr++))
401 scm_lreadr (skipping);
405 while ('\"' != (c = *lexptr++))
408 switch (c = *lexptr++)
411 error ("non-terminated string literal");
440 str.ptr = lexptr - 1;
441 scm_read_token (c, 0);
444 svalue = scm_istring2number (str.ptr, lexptr - str.ptr, 10);
445 if (svalue != SCM_BOOL_F)
446 goto handle_immediate;
452 scm_read_token ('-', 0);
458 str.ptr = lexptr - 1;
459 scm_read_token (c, 0);
463 str.length = lexptr - str.ptr;
464 if (str.ptr[0] == '$')
466 write_dollar_variable (str);
469 write_exp_elt_opcode (OP_NAME);
470 write_exp_string (str);
471 write_exp_elt_opcode (OP_NAME);
478 write_exp_elt_opcode (OP_LONG);
479 write_exp_elt_type (builtin_scm_type (parse_gdbarch)->builtin_scm);
480 write_exp_elt_longcst (svalue);
481 write_exp_elt_opcode (OP_LONG);
490 while (*lexptr == ' ')
493 scm_lreadr (USE_EXPRSTRING);
495 str.length = lexptr - start;
497 write_exp_elt_opcode (OP_EXPRSTRING);
498 write_exp_string (str);
499 write_exp_elt_opcode (OP_EXPRSTRING);