PR binutils/1437
[deliverable/binutils-gdb.git] / gdb / parse.c
index 4720f016e47e4c3db65ea9b677fc8e4471c4e585..f6b0c4f8eddf52ed3867d4692c2d8c171e255436 100644 (file)
@@ -1,7 +1,7 @@
 /* Parse expressions for GDB.
 
    Copyright 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
+   1997, 1998, 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
 
    Modified from expread.y by the Department of Computer Science at the
    State University of New York at Buffalo, 1991.
@@ -43,6 +43,7 @@
 #include "value.h"
 #include "command.h"
 #include "language.h"
+#include "f-lang.h"
 #include "parser-defs.h"
 #include "gdbcmd.h"
 #include "symfile.h"           /* for overlay functions */
@@ -76,11 +77,26 @@ union type_stack_elt *type_stack;
 int type_stack_depth, type_stack_size;
 char *lexptr;
 char *prev_lexptr;
-char *namecopy;
 int paren_depth;
 int comma_terminates;
+
+/* A temporary buffer for identifiers, so we can null-terminate them.
+
+   We allocate this with xrealloc.  parse_exp_1 used to allocate with
+   alloca, using the size of the whole expression as a conservative
+   estimate of the space needed.  However, macro expansion can
+   introduce names longer than the original expression; there's no
+   practical way to know beforehand how large that might be.  */
+char *namecopy;
+size_t namecopy_size;
 \f
 static int expressiondebug = 0;
+static void
+show_expressiondebug (struct ui_file *file, int from_tty,
+                     struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Expression debugging is %s.\n"), value);
+}
 
 static void free_funcalls (void *ignore);
 
@@ -752,8 +768,16 @@ find_template_name_end (char *p)
 char *
 copy_name (struct stoken token)
 {
+  /* Make sure there's enough space for the token.  */
+  if (namecopy_size < token.length + 1)
+    {
+      namecopy_size = token.length + 1;
+      namecopy = xrealloc (namecopy, token.length + 1);
+    }
+      
   memcpy (namecopy, token.ptr, token.length);
   namecopy[token.length] = 0;
+
   return namecopy;
 }
 \f
@@ -814,6 +838,7 @@ operator_length_standard (struct expression *expr, int endpos,
 {
   int oplen = 1;
   int args = 0;
+  enum f90_range_type range_type;
   int i;
 
   if (endpos < 1)
@@ -934,6 +959,26 @@ operator_length_standard (struct expression *expr, int endpos,
       oplen = 2;
       break;
 
+    case OP_F90_RANGE:
+      oplen = 3;
+
+      range_type = longest_to_int (expr->elts[endpos - 2].longconst);
+      switch (range_type)
+       {
+       case LOW_BOUND_DEFAULT:
+       case HIGH_BOUND_DEFAULT:
+         args = 1;
+         break;
+       case BOTH_BOUND_DEFAULT:
+         args = 0;
+         break;
+       case NONE_BOUND_DEFAULT:
+         args = 2;
+         break;
+       }
+
+      break;
+
     default:
       args = 1 + (i < (int) BINOP_END);
     }
@@ -1038,7 +1083,6 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
   else
     expression_context_block = get_selected_block (&expression_context_pc);
 
-  namecopy = (char *) alloca (strlen (lexptr) + 1);
   expout_size = 10;
   expout_ptr = 0;
   expout = (struct expression *)
@@ -1318,6 +1362,6 @@ Set expression debugging."), _("\
 Show expression debugging."), _("\
 When non-zero, the internal representation of expressions will be printed."),
                            NULL,
-                           NULL, /* FIXME: i18n: */
+                           show_expressiondebug,
                            &setdebuglist, &showdebuglist);
 }
This page took 0.024772 seconds and 4 git commands to generate.