/* Parse expressions for GDB.
- Copyright (C) 1986, 1989, 1990, 1991 Free Software Foundation, Inc.
+ Copyright (C) 1986, 1989, 1990, 1991, 1994 Free Software Foundation, Inc.
Modified from expread.y by the Department of Computer Science at the
State University of New York at Buffalo, 1991.
expout_ptr += lenelt - 2;
write_exp_elt_longcst ((LONGEST) bits);
}
+
+/* Type that corresponds to the address given in a minimal symbol. */
+
+static struct type *msymbol_addr_type;
+
+/* 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 (msymbol_addr_type);
+ 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. */
/* 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;
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)
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 ()
{
type_stack_depth = 0;
type_stack = (union type_stack_elt *)
xmalloc (type_stack_size * sizeof (*type_stack));
+
+ /* We don't worry too much about what the name of this type is
+ because the name should rarely appear in output to the user. */
+
+ msymbol_addr_type =
+ init_type (TYPE_CODE_PTR, TARGET_PTR_BIT / HOST_CHAR_BIT, 0,
+ "void *", NULL);
}