Add missing permission notice in each source file
[babeltrace.git] / formats / ctf / metadata / ctf-visitor-parent-links.c
index 44e2031535839ff3d9fac0e707dfa737e22b8715..953727e84c3eccc809328f7f7ca6f82e8c7e0cc7 100644 (file)
  *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
  */
 
 #include <stdio.h>
 #include <glib.h>
 #include <inttypes.h>
 #include <errno.h>
+#include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/list.h>
 #include "ctf-scanner.h"
 #include "ctf-parser.h"
 #include "ctf-ast.h"
 
-#define printf_dbg(fmt, args...)       fprintf(fd, "%s: " fmt, __func__, ## args)
+#define fprintf_dbg(fd, fmt, args...)  fprintf(fd, "%s: " fmt, __func__, ## args)
 
 static
 int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
@@ -80,6 +89,8 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
 static
 int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
 {
+       int ret;
+
        switch (node->u.type_specifier.type) {
        case TYPESPEC_VOID:
        case TYPESPEC_CHAR:
@@ -92,9 +103,21 @@ int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
        case TYPESPEC_UNSIGNED:
        case TYPESPEC_BOOL:
        case TYPESPEC_COMPLEX:
+       case TYPESPEC_IMAGINARY:
        case TYPESPEC_CONST:
        case TYPESPEC_ID_TYPE:
                break;
+       case TYPESPEC_FLOATING_POINT:
+       case TYPESPEC_INTEGER:
+       case TYPESPEC_STRING:
+       case TYPESPEC_STRUCT:
+       case TYPESPEC_VARIANT:
+       case TYPESPEC_ENUM:
+               node->u.type_specifier.node->parent = node;
+               ret = ctf_visitor_parent_links(fd, depth + 1, node->u.type_specifier.node);
+               if (ret)
+                       return ret;
+               break;
 
        case TYPESPEC_UNKNOWN:
        default:
@@ -113,14 +136,12 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
 
        depth++;
 
-       if (!cds_list_empty(&node->u.type_declarator.pointers)) {
-               cds_list_for_each_entry(iter, &node->u.type_declarator.pointers,
-                                       siblings) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+       bt_list_for_each_entry(iter, &node->u.type_declarator.pointers,
+                               siblings) {
+               iter->parent = node;
+               ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+               if (ret)
+                       return ret;
        }
 
        switch (node->u.type_declarator.type) {
@@ -134,12 +155,14 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
                        if (ret)
                                return ret;
                }
-               if (node->u.type_declarator.u.nested.length) {
-                       node->u.type_declarator.u.nested.length->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1,
-                               node->u.type_declarator.u.nested.length);
-                       if (ret)
-                               return ret;
+               if (!node->u.type_declarator.u.nested.abstract_array) {
+                       bt_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
+                                               siblings) {
+                               iter->parent = node;
+                               ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+                               if (ret)
+                                       return ret;
+                       }
                }
                if (node->u.type_declarator.bitfield_len) {
                        node->u.type_declarator.bitfield_len = node;
@@ -166,39 +189,37 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
 
        switch (node->type) {
        case NODE_ROOT:
-               cds_list_for_each_entry(iter, &node->u.root._typedef,
-                                       siblings) {
+               bt_list_for_each_entry(iter, &node->u.root.declaration_list, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.root.typealias,
-                                       siblings) {
+               bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.root.declaration_specifier, siblings) {
+               bt_list_for_each_entry(iter, &node->u.root.stream, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.root.trace, siblings) {
+               bt_list_for_each_entry(iter, &node->u.root.event, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.root.stream, siblings) {
+               bt_list_for_each_entry(iter, &node->u.root.clock, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.root.event, siblings) {
+               bt_list_for_each_entry(iter, &node->u.root.callsite, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -207,7 +228,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                break;
 
        case NODE_EVENT:
-               cds_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
+               bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -215,7 +236,15 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                break;
        case NODE_STREAM:
-               cds_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) {
+               bt_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) {
+                       iter->parent = node;
+                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+                       if (ret)
+                               return ret;
+               }
+               break;
+       case NODE_ENV:
+               bt_list_for_each_entry(iter, &node->u.env.declaration_list, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -223,42 +252,39 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                break;
        case NODE_TRACE:
-               cds_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
+               bt_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
                break;
-
-       case NODE_CTF_EXPRESSION:
-               depth++;
-               cds_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) {
+       case NODE_CLOCK:
+               bt_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) {
+               break;
+       case NODE_CALLSITE:
+               bt_list_for_each_entry(iter, &node->u.callsite.declaration_list, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               depth--;
                break;
-       case NODE_UNARY_EXPRESSION:
-               return ctf_visitor_unary_expression(fd, depth, node);
 
-       case NODE_TYPEDEF:
+       case NODE_CTF_EXPRESSION:
                depth++;
-               cds_list_for_each_entry(iter, &node->u._typedef.declaration_specifier, siblings) {
+               bt_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) {
+               bt_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -266,15 +292,30 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                depth--;
                break;
-       case NODE_TYPEALIAS_TARGET:
+       case NODE_UNARY_EXPRESSION:
+               return ctf_visitor_unary_expression(fd, depth, node);
+
+       case NODE_TYPEDEF:
                depth++;
-               cds_list_for_each_entry(iter, &node->u.typealias_target.declaration_specifier, siblings) {
+               node->u._typedef.type_specifier_list->parent = node;
+               ret = ctf_visitor_parent_links(fd, depth + 1, node->u._typedef.type_specifier_list);
+               if (ret)
+                       return ret;
+               bt_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
+               depth--;
+               break;
+       case NODE_TYPEALIAS_TARGET:
+               depth++;
+               node->u.typealias_target.type_specifier_list->parent = node;
+               ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias_target.type_specifier_list);
+               if (ret)
+                       return ret;
+               bt_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -284,13 +325,11 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                break;
        case NODE_TYPEALIAS_ALIAS:
                depth++;
-               cds_list_for_each_entry(iter, &node->u.typealias_alias.declaration_specifier, siblings) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               cds_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
+               node->u.typealias_alias.type_specifier_list->parent = node;
+               ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias_alias.type_specifier_list);
+               if (ret)
+                       return ret;
+               bt_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -309,6 +348,15 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                        return ret;
                break;
 
+       case NODE_TYPE_SPECIFIER_LIST:
+               bt_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) {
+                       iter->parent = node;
+                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+                       if (ret)
+                               return ret;
+               }
+               break;
+
        case NODE_TYPE_SPECIFIER:
                ret = ctf_visitor_type_specifier(fd, depth, node);
                if (ret)
@@ -323,7 +371,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                break;
 
        case NODE_FLOATING_POINT:
-               cds_list_for_each_entry(iter, &node->u.floating_point.expressions, siblings) {
+               bt_list_for_each_entry(iter, &node->u.floating_point.expressions, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -331,7 +379,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                break;
        case NODE_INTEGER:
-               cds_list_for_each_entry(iter, &node->u.integer.expressions, siblings) {
+               bt_list_for_each_entry(iter, &node->u.integer.expressions, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -339,7 +387,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                break;
        case NODE_STRING:
-               cds_list_for_each_entry(iter, &node->u.string.expressions, siblings) {
+               bt_list_for_each_entry(iter, &node->u.string.expressions, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -347,10 +395,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                break;
        case NODE_ENUMERATOR:
-               if (node->u.enumerator.id)
-                       fprintf(fd, " id=\"%s\"", node->u.enumerator.id);
-               fprintf(fd, ">\n");
-               cds_list_for_each_entry(iter, &node->u.enumerator.values, siblings) {
+               bt_list_for_each_entry(iter, &node->u.enumerator.values, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -358,21 +403,14 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                break;
        case NODE_ENUM:
-               if (node->u._struct.name)
-                       fprintf(fd, "<enum name=\"%s\">\n",
-                               node->u._enum.enum_id);
-               else
-                       fprintf(fd, "<enum >\n");
                depth++;
-
                if (node->u._enum.container_type) {
-                       node->u._enum.container_type->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, node->u._enum.container_type);
                        if (ret)
                                return ret;
                }
 
-               cds_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) {
+               bt_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -381,31 +419,35 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                depth--;
                break;
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
-               cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.declaration_specifier, siblings) {
+               node->u.struct_or_variant_declaration.type_specifier_list->parent = node;
+               ret = ctf_visitor_parent_links(fd, depth + 1,
+                       node->u.struct_or_variant_declaration.type_specifier_list);
+               if (ret)
+                       return ret;
+               bt_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) {
+               break;
+       case NODE_VARIANT:
+               bt_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
                break;
-       case NODE_VARIANT:
-               if (node->u.variant.choice)
-                       fprintf(fd, " choice=\"%s\"", node->u.variant.choice);
-               cds_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) {
+       case NODE_STRUCT:
+               bt_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               break;
-       case NODE_STRUCT:
-               cds_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) {
+               bt_list_for_each_entry(iter, &node->u._struct.min_align,
+                                       siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
This page took 0.035699 seconds and 4 git commands to generate.