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"
33 int update_child(struct filter_node
*parent
,
34 struct filter_node
*old_child
,
35 struct filter_node
*new_child
)
37 switch (parent
->type
) {
40 fprintf(stderr
, "[error] %s: unknown node type\n", __func__
);
43 assert(parent
->u
.root
.child
== old_child
);
44 parent
->u
.root
.child
= new_child
;
47 assert(parent
->u
.expression
.type
== AST_EXP_NESTED
);
48 assert(parent
->u
.expression
.u
.child
== old_child
);
49 parent
->u
.expression
.u
.child
= new_child
;
52 assert(parent
->u
.op
.lchild
== old_child
||
53 parent
->u
.op
.rchild
== old_child
);
54 if (parent
->u
.op
.lchild
== old_child
)
55 parent
->u
.op
.lchild
= new_child
;
57 parent
->u
.op
.rchild
= new_child
;
60 assert(parent
->u
.unary_op
.child
== old_child
);
61 parent
->u
.unary_op
.child
= new_child
;
68 int recursive_visit_set_parent(struct filter_node
*node
,
69 struct filter_node
*parent
)
74 fprintf(stderr
, "[error] %s: NULL child\n", __func__
);
77 node
->parent
= parent
;
81 fprintf(stderr
, "[error] %s: unknown node type\n", __func__
);
84 assert(parent
== NULL
);
85 return recursive_visit_set_parent(node
->u
.root
.child
, node
);
87 switch (node
->u
.expression
.type
) {
90 fprintf(stderr
, "[error] %s: unknown expression type\n", __func__
);
93 return recursive_visit_set_parent(node
->u
.expression
.u
.child
, node
);
94 case AST_EXP_IDENTIFIER
:
96 struct filter_node
*orig_node
= node
;
98 while (node
->u
.expression
.prev
) {
99 struct filter_node
*prev
;
101 prev
= node
->u
.expression
.prev
;
102 if (prev
->type
!= NODE_EXPRESSION
||
103 prev
->u
.expression
.type
!= AST_EXP_IDENTIFIER
) {
104 fprintf(stderr
, "[error] %s: expecting identifier before link\n", __func__
);
108 prev
->u
.expression
.next
= node
;
109 prev
->u
.expression
.pre_op
=
110 node
->u
.expression
.post_op
;
111 prev
->parent
= node
->parent
;
114 /* Set first child as forward */
115 ret
= update_child(parent
, orig_node
, node
);
119 case AST_EXP_CONSTANT
:
120 case AST_EXP_FLOAT_CONSTANT
:
126 ret
= recursive_visit_set_parent(node
->u
.op
.lchild
, node
);
129 return recursive_visit_set_parent(node
->u
.op
.rchild
, node
);
131 return recursive_visit_set_parent(node
->u
.unary_op
.child
, node
);
136 __attribute__((visibility("hidden")))
137 int filter_visitor_set_parent(struct filter_parser_ctx
*ctx
)
139 return recursive_visit_set_parent(&ctx
->ast
->root
, NULL
);
This page took 0.032974 seconds and 5 git commands to generate.