Mercurial > illumos > git > illumos-omnios
changeset 21423:bf3d3f4f3fdb
10941 mdb deserves a modulus operator
Reviewed by: John Levon <john.levon@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Toomas Soome <toomas@me.com>
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Approved by: Dan McDonald <danmcd@joyent.com>
author | Robert Mustacchi <rm@joyent.com> |
---|---|
date | Thu, 31 Jan 2019 05:09:40 +0000 |
parents | ea9e01f73587 |
children | 915509b0c716 |
files | usr/src/cmd/mdb/common/mdb/mdb_grammar.y usr/src/cmd/mdb/common/mdb/mdb_lex.l |
diffstat | 2 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/mdb/common/mdb/mdb_grammar.y Mon Jan 21 19:18:28 2019 +0200 +++ b/usr/src/cmd/mdb/common/mdb/mdb_grammar.y Thu Jan 31 05:09:40 2019 +0000 @@ -26,7 +26,7 @@ */ /* - * Copyright (c) 2015, Joyent, Inc. All rights reserved. + * Copyright (c) 2019, Joyent, Inc. All rights reserved. */ #include <mdb/mdb_types.h> @@ -112,6 +112,7 @@ %left MDB_TOK_LSHIFT MDB_TOK_RSHIFT %left '-' '+' %left '*' '%' '#' +%left MDB_TOK_MODULUS %right MDB_COR_VALUE %right MDB_OBJ_VALUE @@ -309,6 +310,16 @@ $$ = (intmax_t)$1 / (intmax_t)$3; } + | expression MDB_TOK_MODULUS expression { + + if ($3 == 0UL) + yyerror("attempted to divide by zero"); + + $$ = $1 % $3; + } + + + | expression '&' expression { $$ = $1 & $3; } | expression '|' expression { $$ = $1 | $3; } | expression '^' expression { $$ = $1 ^ $3; }
--- a/usr/src/cmd/mdb/common/mdb/mdb_lex.l Mon Jan 21 19:18:28 2019 +0200 +++ b/usr/src/cmd/mdb/common/mdb/mdb_lex.l Thu Jan 31 05:09:40 2019 +0000 @@ -28,6 +28,7 @@ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2017 by Delphix. All rights reserved. + * Copyright 2019, Joyent, Inc. */ #include <sys/types.h> @@ -131,6 +132,9 @@ <S_INITIAL>"!=" | <S_EXPR>"!=" return (MDB_TOK_NOTEQUAL); /* Inequality operator */ +<S_INITIAL>"%%" | +<S_EXPR>"%%" return (MDB_TOK_MODULUS); /* Modulus operator */ + <S_INITIAL>"!" | <S_FMTLIST>"!" | <S_ARGLIST>"!" {