Remove nested expressions
[babeltrace.git] / formats / ctf / metadata / ctf-visitor-parent-links.c
index 9337dd49b832e9a053f568d6f3b96887ba04bd23..104afb717ddad5e78fb2dcbe87c9dabc0c0fb3eb 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>
@@ -24,6 +32,7 @@
 #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"
@@ -60,13 +69,6 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
                if (ret)
                        return ret;
                break;
-       case UNARY_NESTED:
-               node->u.unary_expression.u.nested_exp->parent = node;
-               ret = ctf_visitor_unary_expression(fd, depth + 1,
-                       node->u.unary_expression.u.nested_exp);
-               if (ret)
-                       return ret;
-               break;
 
        case UNARY_UNKNOWN:
        default:
@@ -127,14 +129,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) {
@@ -148,11 +148,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;
@@ -179,25 +182,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.declaration_list, 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.trace, 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.stream, 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.event, 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;
+               }
+               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;
+               }
+               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)
@@ -206,7 +221,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)
@@ -214,7 +229,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)
@@ -222,7 +245,23 @@ 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_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;
+               }
+               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)
@@ -232,13 +271,13 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
 
        case NODE_CTF_EXPRESSION:
                depth++;
-               cds_list_for_each_entry(iter, &node->u.ctf_expression.left, 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.ctf_expression.right, 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)
@@ -255,7 +294,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                ret = ctf_visitor_parent_links(fd, depth + 1, node->u._typedef.type_specifier_list);
                if (ret)
                        return ret;
-               cds_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) {
+               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)
@@ -269,7 +308,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias_target.type_specifier_list);
                if (ret)
                        return ret;
-               cds_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
+               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)
@@ -283,7 +322,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias_alias.type_specifier_list);
                if (ret)
                        return ret;
-               cds_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
+               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)
@@ -303,7 +342,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                break;
 
        case NODE_TYPE_SPECIFIER_LIST:
-               cds_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) {
+               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)
@@ -325,7 +364,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)
@@ -333,7 +372,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)
@@ -341,7 +380,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)
@@ -349,7 +388,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                break;
        case NODE_ENUMERATOR:
-               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,11 +397,13 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                break;
        case NODE_ENUM:
                depth++;
-               ret = ctf_visitor_parent_links(fd, depth + 1, node->u._enum.container_type);
-               if (ret)
-                       return ret;
+               if (node->u._enum.container_type) {
+                       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)
@@ -376,7 +417,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                        node->u.struct_or_variant_declaration.type_specifier_list);
                if (ret)
                        return ret;
-               cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) {
+               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)
@@ -384,7 +425,7 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                break;
        case NODE_VARIANT:
-               cds_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) {
+               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)
@@ -392,7 +433,14 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                }
                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.declaration_list, 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._struct.min_align,
+                                       siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
This page took 0.02891 seconds and 4 git commands to generate.