X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=formats%2Fctf%2Fmetadata%2Fctf-visitor-xml.c;h=d1c0751c51e3c8c548144c087cd1834c05d6fa52;hb=427c09b7f5d932748ee0eee050388c9873bcb6c3;hp=54b5feb84d552e0e70cfb4fa11e2884723a64a86;hpb=380d60b1bd3c5d1a709dca3eeb8e718598fed235;p=babeltrace.git
diff --git a/formats/ctf/metadata/ctf-visitor-xml.c b/formats/ctf/metadata/ctf-visitor-xml.c
index 54b5feb8..d1c0751c 100644
--- a/formats/ctf/metadata/ctf-visitor-xml.c
+++ b/formats/ctf/metadata/ctf-visitor-xml.c
@@ -29,9 +29,10 @@
#include "ctf-parser.h"
#include "ctf-ast.h"
-#define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, ## args)
+#define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
-static void print_tabs(FILE *fd, int depth)
+static
+void print_tabs(FILE *fd, int depth)
{
int i;
@@ -39,6 +40,7 @@ static void print_tabs(FILE *fd, int depth)
fprintf(fd, "\t");
}
+static
int ctf_visitor_print_unary_expression(FILE *fd, int depth, struct ctf_node *node)
{
int ret = 0;
@@ -85,23 +87,23 @@ int ctf_visitor_print_unary_expression(FILE *fd, int depth, struct ctf_node *nod
break;
case UNARY_SBRAC:
print_tabs(fd, depth);
- fprintf(fd, "");
+ fprintf(fd, "\n");
ret = ctf_visitor_print_unary_expression(fd, depth + 1,
node->u.unary_expression.u.sbrac_exp);
if (ret)
return ret;
print_tabs(fd, depth);
- fprintf(fd, "");
+ fprintf(fd, "\n");
break;
case UNARY_NESTED:
print_tabs(fd, depth);
- fprintf(fd, "");
+ fprintf(fd, "\n");
ret = ctf_visitor_print_unary_expression(fd, depth + 1,
node->u.unary_expression.u.nested_exp);
if (ret)
return ret;
print_tabs(fd, depth);
- fprintf(fd, "");
+ fprintf(fd, "\n");
break;
case UNARY_UNKNOWN:
@@ -113,10 +115,61 @@ int ctf_visitor_print_unary_expression(FILE *fd, int depth, struct ctf_node *nod
return 0;
}
+static
+int ctf_visitor_print_type_specifier_list(FILE *fd, int depth, struct ctf_node *node)
+{
+ struct ctf_node *iter;
+ int ret;
+
+ print_tabs(fd, depth);
+ fprintf(fd, "\n");
+ cds_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) {
+ ret = ctf_visitor_print_xml(fd, depth + 1, iter);
+ if (ret)
+ return ret;
+ }
+ print_tabs(fd, depth);
+ fprintf(fd, "\n");
+ return 0;
+}
+
+static
int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node)
{
print_tabs(fd, depth);
- fprintf(fd, "u.type_specifier.type) {
+ case TYPESPEC_VOID:
+ case TYPESPEC_CHAR:
+ case TYPESPEC_SHORT:
+ case TYPESPEC_INT:
+ case TYPESPEC_LONG:
+ case TYPESPEC_FLOAT:
+ case TYPESPEC_DOUBLE:
+ case TYPESPEC_SIGNED:
+ case TYPESPEC_UNSIGNED:
+ case TYPESPEC_BOOL:
+ case TYPESPEC_COMPLEX:
+ case TYPESPEC_IMAGINARY:
+ case TYPESPEC_CONST:
+ case TYPESPEC_ID_TYPE:
+ fprintf(fd, "\n");
+ depth++;
+ break;
+ case TYPESPEC_UNKNOWN:
+ default:
+ fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
+ (int) node->u.type_specifier.type);
+ return -EINVAL;
+ }
switch (node->u.type_specifier.type) {
case TYPESPEC_VOID:
@@ -150,7 +203,10 @@ int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node)
fprintf(fd, "bool");
break;
case TYPESPEC_COMPLEX:
- fprintf(fd, "complex");
+ fprintf(fd, "_Complex");
+ break;
+ case TYPESPEC_IMAGINARY:
+ fprintf(fd, "_Imaginary");
break;
case TYPESPEC_CONST:
fprintf(fd, "const");
@@ -158,17 +214,58 @@ int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node)
case TYPESPEC_ID_TYPE:
fprintf(fd, "%s", node->u.type_specifier.id_type);
break;
+ case TYPESPEC_FLOATING_POINT:
+ case TYPESPEC_INTEGER:
+ case TYPESPEC_STRING:
+ case TYPESPEC_STRUCT:
+ case TYPESPEC_VARIANT:
+ case TYPESPEC_ENUM:
+ return ctf_visitor_print_xml(fd, depth, node->u.type_specifier.node);
+ case TYPESPEC_UNKNOWN:
+ default:
+ fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
+ (int) node->u.type_specifier.type);
+ return -EINVAL;
+ }
+ switch (node->u.type_specifier.type) {
+ case TYPESPEC_VOID:
+ case TYPESPEC_CHAR:
+ case TYPESPEC_SHORT:
+ case TYPESPEC_INT:
+ case TYPESPEC_LONG:
+ case TYPESPEC_FLOAT:
+ case TYPESPEC_DOUBLE:
+ case TYPESPEC_SIGNED:
+ case TYPESPEC_UNSIGNED:
+ case TYPESPEC_BOOL:
+ case TYPESPEC_COMPLEX:
+ case TYPESPEC_IMAGINARY:
+ case TYPESPEC_CONST:
+ case TYPESPEC_ID_TYPE:
+ fprintf(fd, "\"/>\n");
+ break;
+ case TYPESPEC_FLOATING_POINT:
+ case TYPESPEC_INTEGER:
+ case TYPESPEC_STRING:
+ case TYPESPEC_STRUCT:
+ case TYPESPEC_VARIANT:
+ case TYPESPEC_ENUM:
+ print_tabs(fd, depth);
+ fprintf(fd, "\n");
+ depth--;
+ break;
case TYPESPEC_UNKNOWN:
default:
fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
(int) node->u.type_specifier.type);
return -EINVAL;
}
- fprintf(fd, "\"/>\n");
+
return 0;
}
+static
int ctf_visitor_print_type_declarator(FILE *fd, int depth, struct ctf_node *node)
{
int ret = 0;
@@ -214,8 +311,7 @@ int ctf_visitor_print_type_declarator(FILE *fd, int depth, struct ctf_node *node
if (node->u.type_declarator.u.nested.length) {
print_tabs(fd, depth);
fprintf(fd, "\n");
- ret = ctf_visitor_print_xml(fd, depth + 1,
- node->u.type_declarator.u.nested.length);
+ ret = ctf_visitor_print_xml(fd, depth + 1, node->u.type_declarator.u.nested.length);
if (ret)
return ret;
print_tabs(fd, depth);
@@ -260,23 +356,12 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
case NODE_ROOT:
print_tabs(fd, depth);
fprintf(fd, "\n");
- cds_list_for_each_entry(iter, &node->u.root._typedef,
- siblings) {
- ret = ctf_visitor_print_xml(fd, depth + 1, iter);
- if (ret)
- return ret;
- }
- cds_list_for_each_entry(iter, &node->u.root.typealias,
+ cds_list_for_each_entry(iter, &node->u.root.declaration_list,
siblings) {
ret = ctf_visitor_print_xml(fd, depth + 1, iter);
if (ret)
return ret;
}
- cds_list_for_each_entry(iter, &node->u.root.declaration_specifier, siblings) {
- ret = ctf_visitor_print_xml(fd, depth + 1, iter);
- if (ret)
- return ret;
- }
cds_list_for_each_entry(iter, &node->u.root.trace, siblings) {
ret = ctf_visitor_print_xml(fd, depth + 1, iter);
if (ret)
@@ -365,25 +450,19 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
print_tabs(fd, depth);
fprintf(fd, "\n");
depth++;
- print_tabs(fd, depth);
- fprintf(fd, "\n");
- cds_list_for_each_entry(iter, &node->u._typedef.declaration_specifier, siblings) {
- ret = ctf_visitor_print_xml(fd, depth + 1, iter);
- if (ret)
- return ret;
- }
- print_tabs(fd, depth);
- fprintf(fd, "\n");
+ ret = ctf_visitor_print_xml(fd, depth + 1, node->u._typedef.type_specifier_list);
+ if (ret)
+ return ret;
print_tabs(fd, depth);
- fprintf(fd, "\n");
+ fprintf(fd, "\n");
cds_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) {
ret = ctf_visitor_print_xml(fd, depth + 1, iter);
if (ret)
return ret;
}
print_tabs(fd, depth);
- fprintf(fd, "\n");
+ fprintf(fd, "\n");
depth--;
print_tabs(fd, depth);
fprintf(fd, "\n");
@@ -393,25 +472,19 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
fprintf(fd, "\n");
depth++;
- print_tabs(fd, depth);
- fprintf(fd, "\n");
- cds_list_for_each_entry(iter, &node->u.typealias_target.declaration_specifier, siblings) {
- ret = ctf_visitor_print_xml(fd, depth + 1, iter);
- if (ret)
- return ret;
- }
- print_tabs(fd, depth);
- fprintf(fd, "\n");
+ ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_target.type_specifier_list);
+ if (ret)
+ return ret;
print_tabs(fd, depth);
- fprintf(fd, "\n");
+ fprintf(fd, "\n");
cds_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
ret = ctf_visitor_print_xml(fd, depth + 1, iter);
if (ret)
return ret;
}
print_tabs(fd, depth);
- fprintf(fd, "\n");
+ fprintf(fd, "\n");
depth--;
print_tabs(fd, depth);
@@ -422,25 +495,19 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
fprintf(fd, "\n");
depth++;
- print_tabs(fd, depth);
- fprintf(fd, "\n");
- cds_list_for_each_entry(iter, &node->u.typealias_alias.declaration_specifier, siblings) {
- ret = ctf_visitor_print_xml(fd, depth + 1, iter);
- if (ret)
- return ret;
- }
- print_tabs(fd, depth);
- fprintf(fd, "\n");
+ ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_alias.type_specifier_list);
+ if (ret)
+ return ret;
print_tabs(fd, depth);
- fprintf(fd, "\n");
+ fprintf(fd, "\n");
cds_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
ret = ctf_visitor_print_xml(fd, depth + 1, iter);
if (ret)
return ret;
}
print_tabs(fd, depth);
- fprintf(fd, "\n");
+ fprintf(fd, "\n");
depth--;
print_tabs(fd, depth);
@@ -459,6 +526,12 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
fprintf(fd, "\n");
break;
+ case NODE_TYPE_SPECIFIER_LIST:
+ ret = ctf_visitor_print_type_specifier_list(fd, depth, node);
+ if (ret)
+ return ret;
+ break;
+
case NODE_TYPE_SPECIFIER:
ret = ctf_visitor_print_type_specifier(fd, depth, node);
if (ret)
@@ -536,9 +609,12 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
if (node->u._enum.container_type) {
print_tabs(fd, depth);
fprintf(fd, "\n");
- ret = ctf_visitor_print_xml(fd, depth + 1, node->u._enum.container_type);
- if (ret)
- return ret;
+ }
+
+ ret = ctf_visitor_print_xml(fd, depth + 1, node->u._enum.container_type);
+ if (ret)
+ return ret;
+ if (node->u._enum.container_type) {
print_tabs(fd, depth);
fprintf(fd, "\n");
}
@@ -558,25 +634,20 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
fprintf(fd, "\n");
break;
case NODE_STRUCT_OR_VARIANT_DECLARATION:
- print_tabs(fd, depth);
- fprintf(fd, "\n");
- cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.declaration_specifier, siblings) {
- ret = ctf_visitor_print_xml(fd, depth + 1, iter);
- if (ret)
- return ret;
- }
- print_tabs(fd, depth);
- fprintf(fd, "\n");
+ ret = ctf_visitor_print_xml(fd, depth,
+ node->u.struct_or_variant_declaration.type_specifier_list);
+ if (ret)
+ return ret;
print_tabs(fd, depth);
- fprintf(fd, "\n");
+ fprintf(fd, "\n");
cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) {
ret = ctf_visitor_print_xml(fd, depth + 1, iter);
if (ret)
return ret;
}
print_tabs(fd, depth);
- fprintf(fd, "\n");
+ fprintf(fd, "\n");
break;
case NODE_VARIANT:
print_tabs(fd, depth);