1 /* Scheme/Guile language support routines for GDB, the GNU debugger.
3 Copyright (C) 1995, 1996, 2000, 2003, 2005, 2008, 2009
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 */
116 if (*str == '+' || *str == '-') /* Catches lone `+' and `-' for speed */
119 while ((len - i) >= 2 && str[i] == '#' && ++i)
165 return scm_istr2int (&str[i], len - i, radix);
167 return scm_istr2int (&str[i], len - i, radix);
173 return scm_istr2flo (&str[i], len - i, radix);
181 scm_read_token (int c, int weird)
201 case '\0': /* End of line */
242 switch ((c = *lexptr++))
249 switch ((c = *lexptr++))
270 scm_lreadparen (int skipping)
274 int c = scm_skip_ws ();
275 if (')' == c || ']' == c)
279 error ("missing close paren");
280 scm_lreadr (skipping);
285 scm_lreadr (int skipping)
299 scm_lreadparen (skipping);
303 error ("unexpected #\\%c", c);
307 str.ptr = lexptr - 1;
308 scm_lreadr (skipping);
311 struct value *val = scm_evaluate_string (str.ptr, lexptr - str.ptr);
312 if (!is_scmvalue_type (value_type (val)))
313 error ("quoted scm form yields non-SCM value");
314 svalue = extract_signed_integer (value_contents (val),
315 TYPE_LENGTH (value_type (val)),
316 gdbarch_byte_order (parse_gdbarch));
317 goto handle_immediate;
324 scm_lreadr (skipping);
332 scm_lreadparen (skipping);
337 goto handle_immediate;
341 goto handle_immediate;
357 case '*': /* bitvector */
358 scm_read_token (c, 0);
361 scm_read_token (c, 1);
363 case '\\': /* character */
365 scm_read_token (c, 0);
368 j = 1; /* here j is the comment nesting depth */
375 error ("unbalanced comment");
379 if ('#' != (c = *lexptr++))
385 if ('|' != (c = *lexptr++))
396 scm_lreadr (skipping);
400 while ('\"' != (c = *lexptr++))
403 switch (c = *lexptr++)
406 error ("non-terminated string literal");
435 str.ptr = lexptr - 1;
436 scm_read_token (c, 0);
439 svalue = scm_istring2number (str.ptr, lexptr - str.ptr, 10);
440 if (svalue != SCM_BOOL_F)
441 goto handle_immediate;
447 scm_read_token ('-', 0);
453 str.ptr = lexptr - 1;
454 scm_read_token (c, 0);
458 str.length = lexptr - str.ptr;
459 if (str.ptr[0] == '$')
461 write_dollar_variable (str);
464 write_exp_elt_opcode (OP_NAME);
465 write_exp_string (str);
466 write_exp_elt_opcode (OP_NAME);
473 write_exp_elt_opcode (OP_LONG);
474 write_exp_elt_type (builtin_scm_type (parse_gdbarch)->builtin_scm);
475 write_exp_elt_longcst (svalue);
476 write_exp_elt_opcode (OP_LONG);
484 while (*lexptr == ' ')
487 scm_lreadr (USE_EXPRSTRING);
489 str.length = lexptr - start;
491 write_exp_elt_opcode (OP_EXPRSTRING);
492 write_exp_string (str);
493 write_exp_elt_opcode (OP_EXPRSTRING);