2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
27 * Author: David B. Golub, Carnegie Mellon University
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
37 #include <ddb/db_lex.h>
38 #include <ddb/db_access.h>
39 #include <ddb/db_command.h>
41 static bool db_add_expr(db_expr_t *valuep);
42 static bool db_mult_expr(db_expr_t *valuep);
43 static bool db_shift_expr(db_expr_t *valuep);
44 static bool db_term(db_expr_t *valuep);
45 static bool db_unary(db_expr_t *valuep);
46 static bool db_logical_or_expr(db_expr_t *valuep);
47 static bool db_logical_and_expr(db_expr_t *valuep);
48 static bool db_logical_relation_expr(db_expr_t *valuep);
51 db_term(db_expr_t *valuep)
57 if (!db_value_of_name(db_tok_string, valuep) &&
58 !db_value_of_name_pcpu(db_tok_string, valuep) &&
59 !db_value_of_name_vnet(db_tok_string, valuep)) {
60 db_printf("Symbol '%s' not found\n", db_tok_string);
67 *valuep = (db_expr_t)db_tok_number;
71 *valuep = (db_expr_t)db_dot;
75 *valuep = (db_expr_t)db_prev;
79 *valuep = (db_expr_t) db_next;
83 *valuep = (db_expr_t)db_last_addr;
87 if (!db_get_variable(valuep))
92 if (!db_expression(valuep)) {
93 db_printf("Expression syntax error after '%c'\n", '(');
99 db_printf("Expression syntax error -- expected '%c'\n", ')');
110 db_unary(db_expr_t *valuep)
116 if (!db_unary(valuep)) {
117 db_printf("Expression syntax error after '%c'\n", '-');
125 if(!db_unary(valuep)) {
126 db_printf("Expression syntax error after '%c'\n", '!');
130 *valuep = (!(*valuep));
134 if(!db_unary(valuep)) {
135 db_printf("Expression syntax error after '%c'\n", '~');
139 *valuep = (~(*valuep));
144 if (!db_unary(valuep)) {
145 db_printf("Expression syntax error after '%c'\n", '*');
149 *valuep = db_get_value((db_addr_t)*valuep, sizeof(void *),
154 return (db_term(valuep));
158 db_mult_expr(db_expr_t *valuep)
167 while (t == tSTAR || t == tSLASH || t == tPCT || t == tHASH ||
169 if (!db_term(&rhs)) {
170 db_printf("Expression syntax error after '%c'\n",
171 t == tSTAR ? '*' : t == tSLASH ? '/' : t == tPCT ? '%' :
172 t == tHASH ? '#' : '&');
185 db_error("Division by 0\n");
193 lhs = roundup(lhs, rhs);
203 db_add_expr(db_expr_t *valuep)
208 if (!db_mult_expr(&lhs))
212 while (t == tPLUS || t == tMINUS || t == tBIT_OR) {
213 if (!db_mult_expr(&rhs)) {
214 db_printf("Expression syntax error after '%c'\n",
215 t == tPLUS ? '+' : t == tMINUS ? '-' : '|');
240 db_shift_expr(db_expr_t *valuep)
245 if (!db_add_expr(&lhs))
248 while (t == tSHIFT_L || t == tSHIFT_R) {
249 if (!db_add_expr(&rhs)) {
250 db_printf("Expression syntax error after '%s'\n",
251 t == tSHIFT_L ? "<<" : ">>");
256 db_printf("Negative shift amount %jd\n", (intmax_t)rhs);
263 /* Shift right is unsigned */
264 lhs = (unsigned) lhs >> rhs;
274 db_logical_relation_expr(
280 if (!db_shift_expr(&lhs))
284 while (t == tLOG_EQ || t == tLOG_NOT_EQ || t == tGREATER ||
285 t == tGREATER_EQ || t == tLESS || t == tLESS_EQ) {
286 if (!db_shift_expr(&rhs)) {
287 db_printf("Expression syntax error after '%s'\n",
288 t == tLOG_EQ ? "==" : t == tLOG_NOT_EQ ? "!=" :
289 t == tGREATER ? ">" : t == tGREATER_EQ ? ">=" :
290 t == tLESS ? "<" : "<=");
330 if (!db_logical_relation_expr(&lhs))
334 while (t == tLOG_AND) {
335 if (!db_logical_relation_expr(&rhs)) {
336 db_printf("Expression syntax error after '%s'\n", "&&");
355 if (!db_logical_and_expr(&lhs))
359 while (t == tLOG_OR) {
360 if (!db_logical_and_expr(&rhs)) {
361 db_printf("Expression syntax error after '%s'\n", "||");
374 db_expression(db_expr_t *valuep)
376 return (db_logical_or_expr(valuep));