* target.h: Add enum target_waitkind, enum target_signal, and
[deliverable/binutils-gdb.git] / gdb / parse.c
index 1327d601c1fe1c42c7c667137bd5f3a5c5ebdc53..ca9bcc8c9b011fd36689b640eedad801c5095ff9 100644 (file)
@@ -38,6 +38,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "language.h"
 #include "parser-defs.h"
 
+static void
+free_funcalls PARAMS ((void));
+
 static void
 prefixify_expression PARAMS ((struct expression *));
 
@@ -47,10 +50,26 @@ length_of_subexp PARAMS ((struct expression *, int));
 static void
 prefixify_subexp PARAMS ((struct expression *, struct expression *, int, int));
 
+/* Data structure for saving values of arglist_len for function calls whose
+   arguments contain other function calls.  */
+
+struct funcall
+  {
+    struct funcall *next;
+    int arglist_len;
+  };
+
+static struct funcall *funcall_chain;
+
 /* Assign machine-independent names to certain registers 
    (unless overridden by the REGISTER_NAMES table) */
 
+#ifdef NO_STD_REGS
+unsigned num_std_regs = 0;
+struct std_regs std_regs[1];
+#else
 struct std_regs std_regs[] = {
+
 #ifdef PC_REGNUM
        { "pc", PC_REGNUM },
 #endif
@@ -63,10 +82,13 @@ struct std_regs std_regs[] = {
 #ifdef PS_REGNUM
        { "ps", PS_REGNUM },
 #endif
+
 };
 
 unsigned num_std_regs = (sizeof std_regs / sizeof std_regs[0]);
 
+#endif
+
 
 /* Begin counting arguments for a function call,
    saving the data about any containing call.  */
@@ -74,8 +96,9 @@ unsigned num_std_regs = (sizeof std_regs / sizeof std_regs[0]);
 void
 start_arglist ()
 {
-  register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall));
+  register struct funcall *new;
 
+  new = (struct funcall *) xmalloc (sizeof (struct funcall));
   new->next = funcall_chain;
   new->arglist_len = arglist_len;
   arglist_len = 0;
@@ -99,7 +122,7 @@ end_arglist ()
 /* Free everything in the funcall chain.
    Used when there is an error inside parsing.  */
 
-void
+static void
 free_funcalls ()
 {
   register struct funcall *call, *next;
@@ -155,6 +178,15 @@ write_exp_elt_sym (expelt)
   write_exp_elt (tmp);
 }
 
+void
+write_exp_elt_block (b)
+     struct block *b;
+{
+  union exp_element tmp;
+  tmp.block = b;
+  write_exp_elt (tmp);
+}
+
 void
 write_exp_elt_longcst (expelt)
      LONGEST expelt;
@@ -306,6 +338,42 @@ write_exp_bitstring (str)
   expout_ptr += lenelt - 2;
   write_exp_elt_longcst ((LONGEST) bits);
 }
+
+/* Add the appropriate elements for a minimal symbol to the end of
+   the expression.  */
+
+void
+write_exp_msymbol (msymbol, text_symbol_type, data_symbol_type)
+     struct minimal_symbol *msymbol;
+     struct type *text_symbol_type;
+     struct type *data_symbol_type;
+{
+  write_exp_elt_opcode (OP_LONG);
+  write_exp_elt_type (builtin_type_long);
+  write_exp_elt_longcst ((LONGEST) SYMBOL_VALUE_ADDRESS (msymbol));
+  write_exp_elt_opcode (OP_LONG);
+
+  write_exp_elt_opcode (UNOP_MEMVAL);
+  switch (msymbol -> type)
+    {
+    case mst_text:
+    case mst_file_text:
+      write_exp_elt_type (text_symbol_type);
+      break;
+
+    case mst_data:
+    case mst_file_data:
+    case mst_bss:
+    case mst_file_bss:
+      write_exp_elt_type (data_symbol_type);
+      break;
+
+    default:
+      write_exp_elt_type (builtin_type_char);
+      break;
+    }
+  write_exp_elt_opcode (UNOP_MEMVAL);
+}
 \f
 /* Return a null-terminated temporary copy of the name
    of a string token.  */
@@ -366,12 +434,12 @@ length_of_subexp (expr, endpos)
 
     case OP_LONG:
     case OP_DOUBLE:
+    case OP_VAR_VALUE:
       oplen = 4;
       break;
 
     case OP_TYPE:
     case OP_BOOL:
-    case OP_VAR_VALUE:
     case OP_LAST:
     case OP_REGISTER:
     case OP_INTERNALVAR:
@@ -495,12 +563,12 @@ prefixify_subexp (inexpr, outexpr, inend, outbeg)
 
     case OP_LONG:
     case OP_DOUBLE:
+    case OP_VAR_VALUE:
       oplen = 4;
       break;
 
     case OP_TYPE:
     case OP_BOOL:
-    case OP_VAR_VALUE:
     case OP_LAST:
     case OP_REGISTER:
     case OP_INTERNALVAR:
@@ -673,9 +741,9 @@ parse_exp_1 (stringptr, block, comma)
   /* Convert expression from postfix form as generated by yacc
      parser, to a prefix form. */
 
-  DUMP_EXPRESSION (expout, stdout, "before conversion to prefix form");
+  DUMP_EXPRESSION (expout, gdb_stdout, "before conversion to prefix form");
   prefixify_expression (expout);
-  DUMP_EXPRESSION (expout, stdout, "after conversion to prefix form");
+  DUMP_EXPRESSION (expout, gdb_stdout, "after conversion to prefix form");
 
   *stringptr = lexptr;
   return expout;
@@ -694,6 +762,9 @@ parse_expression (string)
     error ("Junk after end of expression.");
   return exp;
 }
+\f
+/* Stuff for maintaining a stack of types.  Currently just used by C, but
+   probably useful for any language which declares its types "backwards".  */
 
 void 
 push_type (tp)
@@ -738,6 +809,50 @@ pop_type_int ()
   return 0;
 }
 
+/* Pop the type stack and return the type which corresponds to FOLLOW_TYPE
+   as modified by all the stuff on the stack.  */
+struct type *
+follow_types (follow_type)
+     struct type *follow_type;
+{
+  int done = 0;
+  int array_size;
+  struct type *range_type;
+
+  while (!done)
+    switch (pop_type ())
+      {
+      case tp_end:
+       done = 1;
+       break;
+      case tp_pointer:
+       follow_type = lookup_pointer_type (follow_type);
+       break;
+      case tp_reference:
+       follow_type = lookup_reference_type (follow_type);
+       break;
+      case tp_array:
+       array_size = pop_type_int ();
+       if (array_size != -1)
+         {
+           range_type =
+             create_range_type ((struct type *) NULL,
+                                builtin_type_int, 0,
+                                array_size - 1);
+           follow_type =
+             create_array_type ((struct type *) NULL,
+                                follow_type, range_type);
+         }
+       else
+         follow_type = lookup_pointer_type (follow_type);
+       break;
+      case tp_function:
+       follow_type = lookup_function_type (follow_type);
+       break;
+      }
+  return follow_type;
+}
+\f
 void
 _initialize_parse ()
 {
This page took 0.025286 seconds and 4 git commands to generate.