1 /* -*- mode: C; c-basic-offset: 2 -*-
3 C# language support for Mono.
4 Copyright 2002 Ximian, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
24 #include "expression.h"
25 #include "parser-defs.h"
31 #include "gdb_string.h"
33 #include "csharp-lang.h"
38 /* Print the character C on STREAM as part of the contents of a literal
39 string whose delimiter is QUOTER. Note that that format for printing
40 characters and strings is language specific. */
43 csharp_emit_char (int c, struct ui_file *stream, int quoter)
49 fprintf_filtered (stream, "\\%c", c);
52 fputs_filtered ("\\b", stream);
55 fputs_filtered ("\\t", stream);
58 fputs_filtered ("\\n", stream);
61 fputs_filtered ("\\f", stream);
64 fputs_filtered ("\\r", stream);
68 fputc_filtered (c, stream);
70 fprintf_filtered (stream, "\\u%.4x", (unsigned int) c);
76 csharp_value_print (struct value *val, struct ui_file *stream, int format,
77 enum val_prettyprint pretty)
84 type = VALUE_TYPE (val);
85 address = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
87 /* If it's type String, print it */
89 if (TYPE_CODE (type) == TYPE_CODE_PTR
90 && TYPE_TARGET_TYPE (type)
91 && TYPE_TAG_NAME (TYPE_TARGET_TYPE (type))
92 && strcmp (TYPE_TAG_NAME (TYPE_TARGET_TYPE (type)), "MonoString") == 0
93 && (format == 0 || format == 's')
95 && value_as_address (val) != 0)
97 struct value *data_val;
99 struct value *count_val;
103 mark = value_mark (); /* Remember start of new values */
105 data_val = value_struct_elt (&val, NULL, "Chars", NULL, NULL);
106 data = VALUE_ADDRESS (data_val) + VALUE_OFFSET (data_val);
108 count_val = value_struct_elt (&val, NULL, "Length", NULL, NULL);
109 count = value_as_address (count_val);
111 value_free_to_mark (mark); /* Release unnecessary values */
113 val_print_string (data, count, 2, stream);
118 return (val_print (type, VALUE_CONTENTS (val), 0, address,
119 stream, format, 1, 0, pretty));
123 /* Print data of type TYPE located at VALADDR (within GDB), which came from
124 the inferior at address ADDRESS, onto stdio stream STREAM according to
125 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
128 If the data are a string pointer, returns the number of string characters
131 If DEREF_REF is nonzero, then dereference references, otherwise just print
134 The PRETTY parameter controls prettyprinting. */
137 csharp_val_print (struct type *type, char *valaddr, int embedded_offset,
138 CORE_ADDR address, struct ui_file *stream, int format,
139 int deref_ref, int recurse, enum val_prettyprint pretty)
141 register unsigned int i = 0; /* Number of characters printed */
142 struct type *target_type;
146 CHECK_TYPEDEF (type);
147 switch (TYPE_CODE (type))
150 case TYPE_CODE_CSHARP_STRING:
151 addr = address + TYPE_CSHARP_STRING_LENGTH_OFFSET (type);
152 length = read_memory_integer (addr, TYPE_CSHARP_STRING_LENGTH_BYTESIZE (type));
154 addr = address + TYPE_CSHARP_STRING_DATA_OFFSET (type);
156 return val_print_string (addr, length, 2, stream);
159 addr = unpack_pointer (type, valaddr);
160 target_type = check_typedef (TYPE_TARGET_TYPE (type));
162 if (deref_ref && addr != 0)
164 if (TYPE_CODE (target_type) == TYPE_CODE_CSHARP_STRING)
165 return csharp_val_print (target_type, NULL, 0, addr, stream,
166 format, deref_ref, recurse, pretty);
171 return c_val_print (type, valaddr, embedded_offset, address, stream,
172 format, deref_ref, recurse, pretty);
176 return c_val_print (type, valaddr, embedded_offset, address, stream,
177 format, deref_ref, recurse, pretty);
183 /* Table mapping opcodes into strings for printing operators
184 and precedences of the operators. */
186 const struct op_print csharp_op_print_tab[] =