0fac7be1d12ded3a30a3fa56606c26921fbb0391
[deliverable/binutils-gdb.git] / gdb / expression.h
1 /* Definitions for expressions stored in reversed prefix form, for GDB.
2 Copyright (C) 1986 Free Software Foundation, Inc.
3
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
9
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
16
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
19 */
20
21 /* Definitions for saved C expressions. */
22
23 /* An expression is represented as a vector of union exp_element's.
24 Each exp_element is an opcode, except that some opcodes cause
25 the following exp_element to be treated as a long or double constant
26 or as a variable. The opcodes are obeyed, using a stack for temporaries.
27 The value is left on the temporary stack at the end. */
28
29 /* When it is necessary to include a string,
30 it can occupy as many exp_elements as it needs.
31 We find the length of the string using strlen,
32 divide to find out how many exp_elements are used up,
33 and skip that many. Strings, like numbers, are indicated
34 by the preceding opcode. */
35
36 enum exp_opcode
37 {
38 /* BINOP_... operate on two values computed by following subexpressions,
39 replacing them by one result value. They take no immediate arguments. */
40 BINOP_ADD, /* + */
41 BINOP_SUB, /* - */
42 BINOP_MUL, /* * */
43 BINOP_DIV, /* / */
44 BINOP_REM, /* % */
45 BINOP_LSH, /* << */
46 BINOP_RSH, /* >> */
47 BINOP_AND, /* && */
48 BINOP_OR, /* || */
49 BINOP_LOGAND, /* & */
50 BINOP_LOGIOR, /* | */
51 BINOP_LOGXOR, /* ^ */
52 BINOP_EQUAL, /* == */
53 BINOP_NOTEQUAL, /* != */
54 BINOP_LESS, /* < */
55 BINOP_GTR, /* > */
56 BINOP_LEQ, /* <= */
57 BINOP_GEQ, /* >= */
58 BINOP_REPEAT, /* @ */
59 BINOP_ASSIGN, /* = */
60 BINOP_COMMA, /* , */
61 BINOP_SUBSCRIPT, /* x[y] */
62 BINOP_EXP, /* Exponentiation */
63
64 /* C++. */
65 BINOP_MIN, /* <? */
66 BINOP_MAX, /* >? */
67 BINOP_SCOPE, /* :: */
68
69 /* STRUCTOP_MEMBER is used for pointer-to-member constructs.
70 X . * Y translates into X STRUCTOP_MEMBER Y. */
71 STRUCTOP_MEMBER,
72 /* STRUCTOP_MPTR is used for pointer-to-member constructs
73 when X is a pointer instead of an aggregate. */
74 STRUCTOP_MPTR,
75 /* end of C++. */
76
77 BINOP_END,
78
79 BINOP_ASSIGN_MODIFY, /* +=, -=, *=, and so on.
80 The following exp_element is another opcode,
81 a BINOP_, saying how to modify.
82 Then comes another BINOP_ASSIGN_MODIFY,
83 making three exp_elements in total. */
84
85 /* Operates on three values computed by following subexpressions. */
86 TERNOP_COND, /* ?: */
87
88 /* The OP_... series take immediate following arguments.
89 After the arguments come another OP_... (the same one)
90 so that the grouping can be recognized from the end. */
91
92 /* OP_LONG is followed by a type pointer in the next exp_element
93 and the long constant value in the following exp_element.
94 Then comes another OP_LONG.
95 Thus, the operation occupies four exp_elements. */
96
97 OP_LONG,
98 /* OP_DOUBLE is similar but takes a double constant instead of a long one. */
99 OP_DOUBLE,
100 /* OP_VAR_VALUE takes one struct symbol * in the following exp_element,
101 followed by another OP_VAR_VALUE, making three exp_elements. */
102 OP_VAR_VALUE,
103 /* OP_LAST is followed by an integer in the next exp_element.
104 The integer is zero for the last value printed,
105 or it is the absolute number of a history element.
106 With another OP_LAST at the end, this makes three exp_elements. */
107 OP_LAST,
108 /* OP_REGISTER is followed by an integer in the next exp_element.
109 This is the number of a register to fetch (as an int).
110 With another OP_REGISTER at the end, this makes three exp_elements. */
111 OP_REGISTER,
112 /* OP_INTERNALVAR is followed by an internalvar ptr in the next exp_element.
113 With another OP_INTERNALVAR at the end, this makes three exp_elements. */
114 OP_INTERNALVAR,
115 /* OP_FUNCALL is followed by an integer in the next exp_element.
116 The integer is the number of args to the function call.
117 That many plus one values from following subexpressions
118 are used, the first one being the function.
119 The integer is followed by a repeat of OP_FUNCALL,
120 making three exp_elements. */
121 OP_FUNCALL,
122 /* OP_STRING represents a string constant.
123 Its format is the same as that of a STRUCTOP, but the string
124 data is just made into a string constant when the operation
125 is executed. */
126 OP_STRING,
127
128 /* UNOP_CAST is followed by a type pointer in the next exp_element.
129 With another UNOP_CAST at the end, this makes three exp_elements.
130 It casts the value of the following subexpression. */
131 UNOP_CAST,
132 /* UNOP_MEMVAL is followed by a type pointer in the next exp_element
133 With another UNOP_MEMVAL at the end, this makes three exp_elements.
134 It casts the contents of the word addressed by the value of the
135 following subexpression. */
136 UNOP_MEMVAL,
137 /* UNOP_... operate on one value from a following subexpression
138 and replace it with a result. They take no immediate arguments. */
139 UNOP_NEG, /* Unary - */
140 UNOP_ZEROP, /* Unary ! */
141 UNOP_LOGNOT, /* Unary ~ */
142 UNOP_IND, /* Unary * */
143 UNOP_ADDR, /* Unary & */
144 UNOP_PREINCREMENT, /* ++ before an expression */
145 UNOP_POSTINCREMENT, /* ++ after an expression */
146 UNOP_PREDECREMENT, /* -- before an expression */
147 UNOP_POSTDECREMENT, /* -- after an expression */
148 UNOP_SIZEOF, /* Unary sizeof (followed by expression) */
149
150 /* STRUCTOP_... operate on a value from a following subexpression
151 by extracting a structure component specified by a string
152 that appears in the following exp_elements (as many as needed).
153 STRUCTOP_STRUCT is used for "." and STRUCTOP_PTR for "->".
154 They differ only in the error message given in case the value is
155 not suitable or the structure component specified is not found.
156
157 The length of the string follows in the next exp_element,
158 (after the string), followed by another STRUCTOP_... code. */
159 STRUCTOP_STRUCT,
160 STRUCTOP_PTR,
161
162 /* C++ */
163 /* OP_THIS is just a placeholder for the class instance variable.
164 It just comes in a tight (OP_THIS, OP_THIS) pair. */
165 OP_THIS,
166
167 /* OP_SCOPE surrounds a type name and a field name. The type
168 name is encoded as one element, but the field name stays as
169 a string, which, of course, is variable length. */
170 OP_SCOPE,
171
172 };
173
174 union exp_element
175 {
176 enum exp_opcode opcode;
177 struct symbol *symbol;
178 long longconst;
179 double doubleconst;
180 char string;
181 struct type *type;
182 struct internalvar *internalvar;
183 };
184
185 struct expression
186 {
187 int nelts;
188 union exp_element elts[1];
189 };
190
191 struct expression *parse_c_expression ();
192 struct expression *parse_c_1 ();
This page took 0.033482 seconds and 4 git commands to generate.