Commit | Line | Data |
---|---|---|
bd5635a1 RP |
1 | /* Definitions for expressions stored in reversed prefix form, for GDB. |
2 | Copyright (C) 1986, 1989 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | GDB 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 1, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GDB 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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GDB; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | /* Definitions for saved C expressions. */ | |
21 | ||
22 | /* An expression is represented as a vector of union exp_element's. | |
23 | Each exp_element is an opcode, except that some opcodes cause | |
24 | the following exp_element to be treated as a long or double constant | |
25 | or as a variable. The opcodes are obeyed, using a stack for temporaries. | |
26 | The value is left on the temporary stack at the end. */ | |
27 | ||
28 | /* When it is necessary to include a string, | |
29 | it can occupy as many exp_elements as it needs. | |
30 | We find the length of the string using strlen, | |
31 | divide to find out how many exp_elements are used up, | |
32 | and skip that many. Strings, like numbers, are indicated | |
33 | by the preceding opcode. */ | |
34 | ||
35 | enum exp_opcode | |
36 | { | |
37 | /* BINOP_... operate on two values computed by following subexpressions, | |
38 | replacing them by one result value. They take no immediate arguments. */ | |
39 | BINOP_ADD, /* + */ | |
40 | BINOP_SUB, /* - */ | |
41 | BINOP_MUL, /* * */ | |
42 | BINOP_DIV, /* / */ | |
43 | BINOP_REM, /* % */ | |
44 | BINOP_LSH, /* << */ | |
45 | BINOP_RSH, /* >> */ | |
46 | BINOP_AND, /* && */ | |
47 | BINOP_OR, /* || */ | |
48 | BINOP_LOGAND, /* & */ | |
49 | BINOP_LOGIOR, /* | */ | |
50 | BINOP_LOGXOR, /* ^ */ | |
51 | BINOP_EQUAL, /* == */ | |
52 | BINOP_NOTEQUAL, /* != */ | |
53 | BINOP_LESS, /* < */ | |
54 | BINOP_GTR, /* > */ | |
55 | BINOP_LEQ, /* <= */ | |
56 | BINOP_GEQ, /* >= */ | |
57 | BINOP_REPEAT, /* @ */ | |
58 | BINOP_ASSIGN, /* = */ | |
59 | BINOP_COMMA, /* , */ | |
60 | BINOP_SUBSCRIPT, /* x[y] */ | |
61 | BINOP_EXP, /* Exponentiation */ | |
62 | ||
63 | /* C++. */ | |
64 | BINOP_MIN, /* <? */ | |
65 | BINOP_MAX, /* >? */ | |
66 | BINOP_SCOPE, /* :: */ | |
67 | ||
68 | /* STRUCTOP_MEMBER is used for pointer-to-member constructs. | |
69 | X . * Y translates into X STRUCTOP_MEMBER Y. */ | |
70 | STRUCTOP_MEMBER, | |
71 | /* STRUCTOP_MPTR is used for pointer-to-member constructs | |
72 | when X is a pointer instead of an aggregate. */ | |
73 | STRUCTOP_MPTR, | |
74 | /* end of C++. */ | |
75 | ||
76 | BINOP_END, | |
77 | ||
78 | BINOP_ASSIGN_MODIFY, /* +=, -=, *=, and so on. | |
79 | The following exp_element is another opcode, | |
80 | a BINOP_, saying how to modify. | |
81 | Then comes another BINOP_ASSIGN_MODIFY, | |
82 | making three exp_elements in total. */ | |
83 | ||
84 | /* Operates on three values computed by following subexpressions. */ | |
85 | TERNOP_COND, /* ?: */ | |
86 | ||
87 | /* The OP_... series take immediate following arguments. | |
88 | After the arguments come another OP_... (the same one) | |
89 | so that the grouping can be recognized from the end. */ | |
90 | ||
91 | /* OP_LONG is followed by a type pointer in the next exp_element | |
92 | and the long constant value in the following exp_element. | |
93 | Then comes another OP_LONG. | |
94 | Thus, the operation occupies four exp_elements. */ | |
95 | ||
96 | OP_LONG, | |
97 | /* OP_DOUBLE is similar but takes a double constant instead of a long one. */ | |
98 | OP_DOUBLE, | |
99 | /* OP_VAR_VALUE takes one struct symbol * in the following exp_element, | |
100 | followed by another OP_VAR_VALUE, making three exp_elements. */ | |
101 | OP_VAR_VALUE, | |
102 | /* OP_LAST is followed by an integer in the next exp_element. | |
103 | The integer is zero for the last value printed, | |
104 | or it is the absolute number of a history element. | |
105 | With another OP_LAST at the end, this makes three exp_elements. */ | |
106 | OP_LAST, | |
107 | /* OP_REGISTER is followed by an integer in the next exp_element. | |
108 | This is the number of a register to fetch (as an int). | |
109 | With another OP_REGISTER at the end, this makes three exp_elements. */ | |
110 | OP_REGISTER, | |
111 | /* OP_INTERNALVAR is followed by an internalvar ptr in the next exp_element. | |
112 | With another OP_INTERNALVAR at the end, this makes three exp_elements. */ | |
113 | OP_INTERNALVAR, | |
114 | /* OP_FUNCALL is followed by an integer in the next exp_element. | |
115 | The integer is the number of args to the function call. | |
116 | That many plus one values from following subexpressions | |
117 | are used, the first one being the function. | |
118 | The integer is followed by a repeat of OP_FUNCALL, | |
119 | making three exp_elements. */ | |
120 | OP_FUNCALL, | |
121 | /* OP_STRING represents a string constant. | |
122 | Its format is the same as that of a STRUCTOP, but the string | |
123 | data is just made into a string constant when the operation | |
124 | is executed. */ | |
125 | OP_STRING, | |
126 | ||
127 | /* UNOP_CAST is followed by a type pointer in the next exp_element. | |
128 | With another UNOP_CAST at the end, this makes three exp_elements. | |
129 | It casts the value of the following subexpression. */ | |
130 | UNOP_CAST, | |
131 | /* UNOP_MEMVAL is followed by a type pointer in the next exp_element | |
132 | With another UNOP_MEMVAL at the end, this makes three exp_elements. | |
133 | It casts the contents of the word addressed by the value of the | |
134 | following subexpression. */ | |
135 | UNOP_MEMVAL, | |
136 | /* UNOP_... operate on one value from a following subexpression | |
137 | and replace it with a result. They take no immediate arguments. */ | |
138 | UNOP_NEG, /* Unary - */ | |
139 | UNOP_ZEROP, /* Unary ! */ | |
140 | UNOP_LOGNOT, /* Unary ~ */ | |
141 | UNOP_IND, /* Unary * */ | |
142 | UNOP_ADDR, /* Unary & */ | |
143 | UNOP_PREINCREMENT, /* ++ before an expression */ | |
144 | UNOP_POSTINCREMENT, /* ++ after an expression */ | |
145 | UNOP_PREDECREMENT, /* -- before an expression */ | |
146 | UNOP_POSTDECREMENT, /* -- after an expression */ | |
147 | UNOP_SIZEOF, /* Unary sizeof (followed by expression) */ | |
148 | ||
149 | /* STRUCTOP_... operate on a value from a following subexpression | |
150 | by extracting a structure component specified by a string | |
151 | that appears in the following exp_elements (as many as needed). | |
152 | STRUCTOP_STRUCT is used for "." and STRUCTOP_PTR for "->". | |
153 | They differ only in the error message given in case the value is | |
154 | not suitable or the structure component specified is not found. | |
155 | ||
156 | The length of the string follows in the next exp_element, | |
157 | (after the string), followed by another STRUCTOP_... code. */ | |
158 | STRUCTOP_STRUCT, | |
159 | STRUCTOP_PTR, | |
160 | ||
161 | /* C++ */ | |
162 | /* OP_THIS is just a placeholder for the class instance variable. | |
163 | It just comes in a tight (OP_THIS, OP_THIS) pair. */ | |
164 | OP_THIS, | |
165 | ||
166 | /* OP_SCOPE surrounds a type name and a field name. The type | |
167 | name is encoded as one element, but the field name stays as | |
168 | a string, which, of course, is variable length. */ | |
169 | OP_SCOPE, | |
170 | ||
171 | }; | |
172 | ||
173 | union exp_element | |
174 | { | |
175 | enum exp_opcode opcode; | |
176 | struct symbol *symbol; | |
177 | LONGEST longconst; | |
178 | double doubleconst; | |
179 | char string; | |
180 | struct type *type; | |
181 | struct internalvar *internalvar; | |
182 | }; | |
183 | ||
184 | struct expression | |
185 | { | |
186 | int nelts; | |
187 | union exp_element elts[1]; | |
188 | }; | |
189 | ||
190 | /* From expread.y. */ | |
191 | struct expression *parse_c_expression (); | |
192 | struct expression *parse_c_1 (); | |
193 | ||
194 | /* The innermost context required by the stack and register variables | |
195 | we've encountered so far. To use this, set it to NULL, then call | |
196 | parse_c_<whatever>, then look at it. */ | |
197 | extern struct block *innermost_block; | |
198 | ||
199 | /* From expprint.c. */ | |
200 | void print_expression (); |