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_error("Symbol not found\n");
66 *valuep = (db_expr_t)db_tok_number;
70 *valuep = (db_expr_t)db_dot;
74 *valuep = (db_expr_t)db_prev;
78 *valuep = (db_expr_t) db_next;
82 *valuep = (db_expr_t)db_last_addr;
86 if (!db_get_variable(valuep))
91 if (!db_expression(valuep)) {
92 db_error("Syntax error\n");
97 db_error("Syntax error\n");
107 db_unary(db_expr_t *valuep)
113 if (!db_unary(valuep)) {
114 db_printf("Expression syntax error after '%c'\n", '-');
122 if(!db_unary(valuep)) {
123 db_printf("Expression syntax error after '%c'\n", '!');
127 *valuep = (!(*valuep));
131 if(!db_unary(valuep)) {
132 db_printf("Expression syntax error after '%c'\n", '~');
136 *valuep = (~(*valuep));
141 if (!db_unary(valuep)) {
142 db_printf("Expression syntax error after '%c'\n", '*');
146 *valuep = db_get_value((db_addr_t)*valuep, sizeof(void *),
151 return (db_term(valuep));
155 db_mult_expr(db_expr_t *valuep)
164 while (t == tSTAR || t == tSLASH || t == tPCT || t == tHASH ||
166 if (!db_term(&rhs)) {
167 db_printf("Expression syntax error after '%c'\n", '!');
180 db_error("Divide by 0\n");
188 lhs = roundup(lhs, rhs);
198 db_add_expr(db_expr_t *valuep)
204 if (!db_mult_expr(&lhs))
208 while (t == tPLUS || t == tMINUS || t == tBIT_OR) {
209 if (!db_mult_expr(&rhs)) {
210 c = db_tok_string[0];
211 db_printf("Expression syntax error after '%c'\n", c);
236 db_shift_expr(db_expr_t *valuep)
241 if (!db_add_expr(&lhs))
244 while (t == tSHIFT_L || t == tSHIFT_R) {
245 if (!db_add_expr(&rhs)) {
246 db_error("Syntax error\n");
250 db_error("Negative shift amount\n");
256 /* Shift right is unsigned */
257 lhs = (unsigned) lhs >> rhs;
267 db_logical_relation_expr(
274 if (!db_shift_expr(&lhs))
278 while (t == tLOG_EQ || t == tLOG_NOT_EQ || t == tGREATER ||
279 t == tGREATER_EQ || t == tLESS || t == tLESS_EQ) {
280 op[0] = db_tok_string[0];
281 op[1] = db_tok_string[1];
283 if (!db_shift_expr(&rhs)) {
284 db_printf("Expression syntax error after \"%s\"\n", op);
324 if (!db_logical_relation_expr(&lhs))
328 while (t == tLOG_AND) {
329 if (!db_logical_relation_expr(&rhs)) {
330 db_printf("Expression syntax error after '%s'\n", "&&");
349 if (!db_logical_and_expr(&lhs))
353 while (t == tLOG_OR) {
354 if (!db_logical_and_expr(&rhs)) {
355 db_printf("Expression syntax error after '%s'\n", "||");
368 db_expression(db_expr_t *valuep)
370 return (db_logical_or_expr(valuep));