bf52724ef4df253bcdfa715cbd4589b7772b152d
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_FLOAT_CONSTANT
:
70 print_tabs(stream
, indent
);
71 fprintf(stream
, "<float_constant value=\"%lg\"/>\n",
72 node
->u
.expression
.u
.float_constant
);
74 case AST_EXP_IDENTIFIER
:
75 print_tabs(stream
, indent
);
76 fprintf(stream
, "<identifier value=\"%s\"/>\n",
77 node
->u
.expression
.u
.identifier
);
78 while (node
->u
.expression
.next
) {
79 print_tabs(stream
, indent
);
80 fprintf(stream
, "<link type=\"");
81 switch (node
->u
.expression
.pre_op
) {
82 case AST_LINK_UNKNOWN
:
84 fprintf(stderr
, "[error] %s: unknown link\n", __func__
);
90 fprintf(stream
, "->");
93 fprintf(stream
, "\"/>\n");
95 node
= node
->u
.expression
.next
;
96 if (node
->type
!= NODE_EXPRESSION
||
97 node
->u
.expression
.type
!= AST_EXP_IDENTIFIER
) {
98 fprintf(stderr
, "[error] %s: expecting identifier before link\n", __func__
);
102 print_tabs(stream
, indent
);
103 fprintf(stream
, "<identifier value=\"%s\"/>\n",
104 node
->u
.expression
.u
.identifier
);
108 return recursive_visit_print(node
->u
.expression
.u
.child
,
116 int recursive_visit_print(struct filter_node
*node
, FILE *stream
, int indent
)
121 fprintf(stderr
, "[error] %s: NULL child\n", __func__
);
124 switch (node
->type
) {
127 fprintf(stderr
, "[error] %s: unknown node type\n", __func__
);
130 print_tabs(stream
, indent
);
131 fprintf(stream
, "<root>\n");
132 ret
= recursive_visit_print(node
->u
.root
.child
, stream
,
134 print_tabs(stream
, indent
);
135 fprintf(stream
, "</root>\n");
137 case NODE_EXPRESSION
:
138 print_tabs(stream
, indent
);
139 fprintf(stream
, "<expression>\n");
140 ret
= recursive_visit_print_expression(node
, stream
,
142 print_tabs(stream
, indent
);
143 fprintf(stream
, "</expression>\n");
146 print_tabs(stream
, indent
);
147 fprintf(stream
, "<op type=");
148 switch (node
->u
.op
.type
) {
151 fprintf(stderr
, "[error] %s: unknown op\n", __func__
);
154 fprintf(stream
, "\"*\"");
157 fprintf(stream
, "\"/\"");
160 fprintf(stream
, "\"%%\"");
163 fprintf(stream
, "\"+\"");
166 fprintf(stream
, "\"-\"");
169 fprintf(stream
, "\">>\"");
172 fprintf(stream
, "\"<<\"");
175 fprintf(stream
, "\"&&\"");
178 fprintf(stream
, "\"||\"");
181 fprintf(stream
, "\"&\"");
184 fprintf(stream
, "\"|\"");
187 fprintf(stream
, "\"^\"");
191 fprintf(stream
, "\"==\"");
194 fprintf(stream
, "\"!=\"");
197 fprintf(stream
, "\">\"");
200 fprintf(stream
, "\"<\"");
203 fprintf(stream
, "\">=\"");
206 fprintf(stream
, "\"<=\"");
209 fprintf(stream
, ">\n");
210 ret
= recursive_visit_print(node
->u
.op
.lchild
,
214 ret
= recursive_visit_print(node
->u
.op
.rchild
,
218 print_tabs(stream
, indent
);
219 fprintf(stream
, "</op>\n");
222 print_tabs(stream
, indent
);
223 fprintf(stream
, "<unary_op type=");
224 switch (node
->u
.unary_op
.type
) {
225 case AST_UNARY_UNKNOWN
:
227 fprintf(stderr
, "[error] %s: unknown unary_op\n", __func__
);
230 fprintf(stream
, "\"+\"");
232 case AST_UNARY_MINUS
:
233 fprintf(stream
, "\"-\"");
236 fprintf(stream
, "\"!\"");
239 fprintf(stream
, ">\n");
240 ret
= recursive_visit_print(node
->u
.unary_op
.child
,
242 print_tabs(stream
, indent
);
243 fprintf(stream
, "</unary_op>\n");
249 int filter_visitor_print_xml(struct filter_parser_ctx
*ctx
, FILE *stream
,
252 return recursive_visit_print(&ctx
->ast
->root
, stream
, indent
);
This page took 0.03392 seconds and 4 git commands to generate.