4 * LTTng filter XML pretty printer 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-parser.h"
30 #include "filter-ast.h"
32 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
35 int recursive_visit_print(struct filter_node
*node
, FILE *stream
, int indent
);
38 void print_tabs(FILE *fd
, int depth
)
42 for (i
= 0; i
< depth
; i
++)
47 int recursive_visit_print_expression(struct filter_node
*node
,
48 FILE *stream
, int indent
)
51 fprintf(stderr
, "[error] %s: NULL child\n", __func__
);
54 switch (node
->u
.expression
.type
) {
57 fprintf(stderr
, "[error] %s: unknown expression\n", __func__
);
60 print_tabs(stream
, indent
);
61 fprintf(stream
, "<string value=\"%s\"/>\n",
62 node
->u
.expression
.u
.string
);
64 case AST_EXP_CONSTANT
:
65 print_tabs(stream
, indent
);
66 fprintf(stream
, "<constant value=\"%" PRIu64
"\"/>\n",
67 node
->u
.expression
.u
.constant
);
69 case AST_EXP_IDENTIFIER
:
70 print_tabs(stream
, indent
);
71 fprintf(stream
, "<identifier value=\"%s\"/>\n",
72 node
->u
.expression
.u
.identifier
);
73 while (node
->u
.expression
.next
) {
74 print_tabs(stream
, indent
);
75 fprintf(stream
, "<link type=\"");
76 switch (node
->u
.expression
.pre_op
) {
77 case AST_LINK_UNKNOWN
:
79 fprintf(stderr
, "[error] %s: unknown link\n", __func__
);
85 fprintf(stream
, "->");
88 fprintf(stream
, "\"/>\n");
90 node
= node
->u
.expression
.next
;
91 if (node
->type
!= NODE_EXPRESSION
||
92 node
->u
.expression
.type
!= AST_EXP_IDENTIFIER
) {
93 fprintf(stderr
, "[error] %s: expecting identifier before link\n", __func__
);
97 print_tabs(stream
, indent
);
98 fprintf(stream
, "<identifier value=\"%s\"/>\n",
99 node
->u
.expression
.u
.identifier
);
103 return recursive_visit_print(node
->u
.expression
.u
.child
,
111 int recursive_visit_print(struct filter_node
*node
, FILE *stream
, int indent
)
116 fprintf(stderr
, "[error] %s: NULL child\n", __func__
);
119 switch (node
->type
) {
122 fprintf(stderr
, "[error] %s: unknown node type\n", __func__
);
125 print_tabs(stream
, indent
);
126 fprintf(stream
, "<root>\n");
127 ret
= recursive_visit_print(node
->u
.root
.child
, stream
,
129 print_tabs(stream
, indent
);
130 fprintf(stream
, "</root>\n");
132 case NODE_EXPRESSION
:
133 print_tabs(stream
, indent
);
134 fprintf(stream
, "<expression>\n");
135 ret
= recursive_visit_print_expression(node
, stream
,
137 print_tabs(stream
, indent
);
138 fprintf(stream
, "</expression>\n");
141 print_tabs(stream
, indent
);
142 fprintf(stream
, "<op type=");
143 switch (node
->u
.op
.type
) {
146 fprintf(stderr
, "[error] %s: unknown op\n", __func__
);
149 fprintf(stream
, "\"*\"");
152 fprintf(stream
, "\"/\"");
155 fprintf(stream
, "\"%%\"");
158 fprintf(stream
, "\"+\"");
161 fprintf(stream
, "\"-\"");
164 fprintf(stream
, "\">>\"");
167 fprintf(stream
, "\"<<\"");
170 fprintf(stream
, "\"&&\"");
173 fprintf(stream
, "\"||\"");
176 fprintf(stream
, "\"&\"");
179 fprintf(stream
, "\"|\"");
182 fprintf(stream
, "\"^\"");
186 fprintf(stream
, "\"==\"");
189 fprintf(stream
, "\"!=\"");
192 fprintf(stream
, "\">\"");
195 fprintf(stream
, "\"<\"");
198 fprintf(stream
, "\">=\"");
201 fprintf(stream
, "\"<=\"");
204 fprintf(stream
, ">\n");
205 ret
= recursive_visit_print(node
->u
.op
.lchild
,
209 ret
= recursive_visit_print(node
->u
.op
.rchild
,
213 print_tabs(stream
, indent
);
214 fprintf(stream
, "</op>\n");
217 print_tabs(stream
, indent
);
218 fprintf(stream
, "<unary_op type=");
219 switch (node
->u
.unary_op
.type
) {
220 case AST_UNARY_UNKNOWN
:
222 fprintf(stderr
, "[error] %s: unknown unary_op\n", __func__
);
225 fprintf(stream
, "\"+\"");
227 case AST_UNARY_MINUS
:
228 fprintf(stream
, "\"-\"");
231 fprintf(stream
, "\"!\"");
234 fprintf(stream
, ">\n");
235 ret
= recursive_visit_print(node
->u
.unary_op
.child
,
237 print_tabs(stream
, indent
);
238 fprintf(stream
, "</unary_op>\n");
244 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
247 return recursive_visit_print(&ctx
->ast
->root
, stream
, indent
);
This page took 0.040564 seconds and 4 git commands to generate.