2 * filter-visitor-set-parent.c
4 * LTTng filter set parent visitor
6 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "filter-ast.h"
30 #include "filter-parser.h"
32 #include <common/macros.h>
35 int update_child(struct filter_node
*parent
,
36 struct filter_node
*old_child
,
37 struct filter_node
*new_child
)
39 switch (parent
->type
) {
42 fprintf(stderr
, "[error] %s: unknown node type\n", __func__
);
45 assert(parent
->u
.root
.child
== old_child
);
46 parent
->u
.root
.child
= new_child
;
49 assert(parent
->u
.expression
.type
== AST_EXP_NESTED
);
50 assert(parent
->u
.expression
.u
.child
== old_child
);
51 parent
->u
.expression
.u
.child
= new_child
;
54 assert(parent
->u
.op
.lchild
== old_child
||
55 parent
->u
.op
.rchild
== old_child
);
56 if (parent
->u
.op
.lchild
== old_child
)
57 parent
->u
.op
.lchild
= new_child
;
59 parent
->u
.op
.rchild
= new_child
;
62 assert(parent
->u
.unary_op
.child
== old_child
);
63 parent
->u
.unary_op
.child
= new_child
;
70 int recursive_visit_set_parent(struct filter_node
*node
,
71 struct filter_node
*parent
)
76 fprintf(stderr
, "[error] %s: NULL child\n", __func__
);
79 node
->parent
= parent
;
83 fprintf(stderr
, "[error] %s: unknown node type\n", __func__
);
86 assert(parent
== NULL
);
87 return recursive_visit_set_parent(node
->u
.root
.child
, node
);
89 switch (node
->u
.expression
.type
) {
92 fprintf(stderr
, "[error] %s: unknown expression type\n", __func__
);
95 return recursive_visit_set_parent(node
->u
.expression
.u
.child
, node
);
96 case AST_EXP_IDENTIFIER
:
98 struct filter_node
*orig_node
= node
;
100 while (node
->u
.expression
.prev
) {
101 struct filter_node
*prev
;
103 prev
= node
->u
.expression
.prev
;
104 if (prev
->type
!= NODE_EXPRESSION
||
105 prev
->u
.expression
.type
!= AST_EXP_IDENTIFIER
) {
106 fprintf(stderr
, "[error] %s: expecting identifier before link\n", __func__
);
110 prev
->u
.expression
.next
= node
;
111 prev
->u
.expression
.pre_op
=
112 node
->u
.expression
.post_op
;
113 prev
->parent
= node
->parent
;
116 /* Set first child as forward */
117 ret
= update_child(parent
, orig_node
, node
);
121 case AST_EXP_CONSTANT
:
122 case AST_EXP_FLOAT_CONSTANT
:
128 ret
= recursive_visit_set_parent(node
->u
.op
.lchild
, node
);
131 return recursive_visit_set_parent(node
->u
.op
.rchild
, node
);
133 return recursive_visit_set_parent(node
->u
.unary_op
.child
, node
);
139 int filter_visitor_set_parent(struct filter_parser_ctx
*ctx
)
141 return recursive_visit_set_parent(&ctx
->ast
->root
, NULL
);
This page took 0.040697 seconds and 6 git commands to generate.