X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Ffilter%2Ffilter-parser.y;h=ba2d3007b932754ea080d3f88ed4ff030aeda8d6;hp=2fa41ab405259d9eec1533ff47793a5d54cc3a26;hb=52dc69b2dc349a43f108a9926b0794ee6b6ec4c3;hpb=116d3c01872d62ee86bdbd0aea575b12fbc9c272 diff --git a/src/lib/lttng-ctl/filter/filter-parser.y b/src/lib/lttng-ctl/filter/filter-parser.y index 2fa41ab40..ba2d3007b 100644 --- a/src/lib/lttng-ctl/filter/filter-parser.y +++ b/src/lib/lttng-ctl/filter/filter-parser.y @@ -4,20 +4,9 @@ * * LTTng filter expression parser * - * Copyright 2012 - Mathieu Desnoyers + * Copyright 2012 Mathieu Desnoyers * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License, version 2.1 only, - * as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * SPDX-License-Identifier: LGPL-2.1-only * * Grammar inspired from http://www.quut.com/c/ANSI-C-grammar-y.html */ @@ -104,7 +93,7 @@ end: * gsrc will be garbage collected immediately, and gstr might be. * Should only be used to append characters to a string literal or constant. */ -LTTNG_HIDDEN +static struct gc_string *gc_string_append(struct filter_parser_ctx *parser_ctx, struct gc_string *gstr, struct gc_string *gsrc) @@ -196,17 +185,11 @@ static struct filter_node *make_op_node(struct filter_parser_ctx *scanner, return node; } -LTTNG_HIDDEN +static void yyerror(struct filter_parser_ctx *parser_ctx, yyscan_t scanner, const char *str) { fprintf(stderr, "error %s\n", str); } - -LTTNG_HIDDEN -int yywrap(void) -{ - return 1; -} #define parse_error(parser_ctx, str) \ do { \ @@ -307,6 +290,14 @@ void filter_parser_ctx_free(struct filter_parser_ctx *parser_ctx) %} +%code provides +{ +#include "common/macros.h" + +LTTNG_HIDDEN +void setstring(struct filter_parser_ctx *parser_ctx, YYSTYPE *lvalp, const char *src); +} + %define api.pure /* %locations */ %parse-param {struct filter_parser_ctx *parser_ctx} @@ -596,22 +587,49 @@ shift_expression } ; -relational_expression +and_expression : shift_expression { $$ = $1; } - | relational_expression LT_OP shift_expression + | and_expression AND_BIN shift_expression + { + $$ = make_op_node(parser_ctx, AST_OP_BIT_AND, $1, $3); + } + ; + +exclusive_or_expression + : and_expression + { $$ = $1; } + | exclusive_or_expression XOR_BIN and_expression + { + $$ = make_op_node(parser_ctx, AST_OP_BIT_XOR, $1, $3); + } + ; + +inclusive_or_expression + : exclusive_or_expression + { $$ = $1; } + | inclusive_or_expression OR_BIN exclusive_or_expression + { + $$ = make_op_node(parser_ctx, AST_OP_BIT_OR, $1, $3); + } + ; + +relational_expression + : inclusive_or_expression + { $$ = $1; } + | relational_expression LT_OP inclusive_or_expression { $$ = make_op_node(parser_ctx, AST_OP_LT, $1, $3); } - | relational_expression GT_OP shift_expression + | relational_expression GT_OP inclusive_or_expression { $$ = make_op_node(parser_ctx, AST_OP_GT, $1, $3); } - | relational_expression LE_OP shift_expression + | relational_expression LE_OP inclusive_or_expression { $$ = make_op_node(parser_ctx, AST_OP_LE, $1, $3); } - | relational_expression GE_OP shift_expression + | relational_expression GE_OP inclusive_or_expression { $$ = make_op_node(parser_ctx, AST_OP_GE, $1, $3); } @@ -630,37 +648,10 @@ equality_expression } ; -and_expression - : equality_expression - { $$ = $1; } - | and_expression AND_BIN equality_expression - { - $$ = make_op_node(parser_ctx, AST_OP_BIT_AND, $1, $3); - } - ; - -exclusive_or_expression - : and_expression - { $$ = $1; } - | exclusive_or_expression XOR_BIN and_expression - { - $$ = make_op_node(parser_ctx, AST_OP_BIT_XOR, $1, $3); - } - ; - -inclusive_or_expression - : exclusive_or_expression - { $$ = $1; } - | inclusive_or_expression OR_BIN exclusive_or_expression - { - $$ = make_op_node(parser_ctx, AST_OP_BIT_OR, $1, $3); - } - ; - logical_and_expression - : inclusive_or_expression + : equality_expression { $$ = $1; } - | logical_and_expression AND_OP inclusive_or_expression + | logical_and_expression AND_OP equality_expression { $$ = make_op_node(parser_ctx, AST_OP_AND, $1, $3); }