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-ast.h"
30 #include "filter-parser.h"
32 #include <common/macros.h>
34 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
37 int recursive_visit_print(struct filter_node
*node
, FILE *stream
, int indent
);
40 void print_tabs(FILE *fd
, int depth
)
44 for (i
= 0; i
< depth
; i
++)
49 int recursive_visit_print_expression(struct filter_node
*node
,
50 FILE *stream
, int indent
)
53 fprintf(stderr
, "[error] %s: NULL child\n", __func__
);
56 switch (node
->u
.expression
.type
) {
59 fprintf(stderr
, "[error] %s: unknown expression\n", __func__
);
62 print_tabs(stream
, indent
);
63 fprintf(stream
, "<string value=\"%s\"/>\n",
64 node
->u
.expression
.u
.string
);
66 case AST_EXP_CONSTANT
:
67 print_tabs(stream
, indent
);
68 fprintf(stream
, "<constant value=\"%" PRIu64
"\"/>\n",
69 node
->u
.expression
.u
.constant
);
71 case AST_EXP_FLOAT_CONSTANT
:
72 print_tabs(stream
, indent
);
73 fprintf(stream
, "<float_constant value=\"%lg\"/>\n",
74 node
->u
.expression
.u
.float_constant
);
76 case AST_EXP_IDENTIFIER
:
77 print_tabs(stream
, indent
);
78 fprintf(stream
, "<identifier value=\"%s\"/>\n",
79 node
->u
.expression
.u
.identifier
);
80 while (node
->u
.expression
.next
) {
81 print_tabs(stream
, indent
);
82 fprintf(stream
, "<link type=\"");
83 switch (node
->u
.expression
.pre_op
) {
84 case AST_LINK_UNKNOWN
:
86 fprintf(stderr
, "[error] %s: unknown link\n", __func__
);
92 fprintf(stream
, "->");
95 fprintf(stream
, "\"/>\n");
97 node
= node
->u
.expression
.next
;
98 if (node
->type
!= NODE_EXPRESSION
||
99 node
->u
.expression
.type
!= AST_EXP_IDENTIFIER
) {
100 fprintf(stderr
, "[error] %s: expecting identifier before link\n", __func__
);
104 print_tabs(stream
, indent
);
105 fprintf(stream
, "<identifier value=\"%s\"/>\n",
106 node
->u
.expression
.u
.identifier
);
110 return recursive_visit_print(node
->u
.expression
.u
.child
,
118 int recursive_visit_print(struct filter_node
*node
, FILE *stream
, int indent
)
123 fprintf(stderr
, "[error] %s: NULL child\n", __func__
);
126 switch (node
->type
) {
129 fprintf(stderr
, "[error] %s: unknown node type\n", __func__
);
132 print_tabs(stream
, indent
);
133 fprintf(stream
, "<root>\n");
134 ret
= recursive_visit_print(node
->u
.root
.child
, stream
,
136 print_tabs(stream
, indent
);
137 fprintf(stream
, "</root>\n");
139 case NODE_EXPRESSION
:
140 print_tabs(stream
, indent
);
141 fprintf(stream
, "<expression>\n");
142 ret
= recursive_visit_print_expression(node
, stream
,
144 print_tabs(stream
, indent
);
145 fprintf(stream
, "</expression>\n");
148 print_tabs(stream
, indent
);
149 fprintf(stream
, "<op type=");
150 switch (node
->u
.op
.type
) {
153 fprintf(stderr
, "[error] %s: unknown op\n", __func__
);
156 fprintf(stream
, "\"*\"");
159 fprintf(stream
, "\"/\"");
162 fprintf(stream
, "\"%%\"");
165 fprintf(stream
, "\"+\"");
168 fprintf(stream
, "\"-\"");
171 fprintf(stream
, "\">>\"");
174 fprintf(stream
, "\"<<\"");
177 fprintf(stream
, "\"&&\"");
180 fprintf(stream
, "\"||\"");
183 fprintf(stream
, "\"&\"");
186 fprintf(stream
, "\"|\"");
189 fprintf(stream
, "\"^\"");
193 fprintf(stream
, "\"==\"");
196 fprintf(stream
, "\"!=\"");
199 fprintf(stream
, "\">\"");
202 fprintf(stream
, "\"<\"");
205 fprintf(stream
, "\">=\"");
208 fprintf(stream
, "\"<=\"");
211 fprintf(stream
, ">\n");
212 ret
= recursive_visit_print(node
->u
.op
.lchild
,
216 ret
= recursive_visit_print(node
->u
.op
.rchild
,
220 print_tabs(stream
, indent
);
221 fprintf(stream
, "</op>\n");
224 print_tabs(stream
, indent
);
225 fprintf(stream
, "<unary_op type=");
226 switch (node
->u
.unary_op
.type
) {
227 case AST_UNARY_UNKNOWN
:
229 fprintf(stderr
, "[error] %s: unknown unary_op\n", __func__
);
232 fprintf(stream
, "\"+\"");
234 case AST_UNARY_MINUS
:
235 fprintf(stream
, "\"-\"");
238 fprintf(stream
, "\"!\"");
240 case AST_UNARY_BIN_NOT
:
241 fprintf(stream
, "\"~\"");
244 fprintf(stream
, ">\n");
245 ret
= recursive_visit_print(node
->u
.unary_op
.child
,
247 print_tabs(stream
, indent
);
248 fprintf(stream
, "</unary_op>\n");
255 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
258 return recursive_visit_print(&ctx
->ast
->root
, stream
, indent
);
This page took 0.034183 seconds and 4 git commands to generate.