Simplify error node
[babeltrace.git] / formats / ctf / metadata / ctf-parser.y
index 4d1017391cb0e30d20c755ad59f2215a6a89de04..40cf65e9a03605922d631a83bcb7b0bc49dccdd1 100644 (file)
@@ -83,6 +83,15 @@ static const char *node_type_to_str[] = {
 #undef ENTRY
 };
 
+/*
+ * Static node for out of memory errors. Only "type" is used. lineno is
+ * always left at 0. The rest of the node content can be overwritten,
+ * but is never used.
+ */
+static struct ctf_node error_node = {
+       .type = NODE_ERROR,
+};
+
 BT_HIDDEN
 const char *node_type(struct ctf_node *node)
 {
@@ -327,8 +336,10 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
        struct ctf_node *node;
 
        node = malloc(sizeof(*node));
-       if (!node)
-               return NULL;
+       if (!node) {
+               printfl_fatal(yyget_lineno(scanner->scanner), "out of memory");
+               return &error_node;
+       }
        memset(node, 0, sizeof(*node));
        node->type = type;
        node->lineno = yyget_lineno(scanner->scanner);
@@ -338,6 +349,7 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
 
        switch (type) {
        case NODE_ROOT:
+               node->type = NODE_ERROR;
                printfn_fatal(node, "trying to create root node");
                break;
 
@@ -418,6 +430,7 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
 
        case NODE_UNKNOWN:
        default:
+               node->type = NODE_ERROR;
                printfn_fatal(node, "unknown node type '%d'", (int) type);
                break;
        }
@@ -1199,9 +1212,7 @@ postfix_expression:
                }
        |       LPAREN unary_expression RPAREN
                {
-                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
-                       $$->u.unary_expression.type = UNARY_NESTED;
-                       $$->u.unary_expression.u.nested_exp = $2;
+                       $$ = $2;
                }
        |       postfix_expression LSBRAC unary_expression RSBRAC
                {
This page took 0.024185 seconds and 4 git commands to generate.