Refuse 0 integer size
[babeltrace.git] / formats / ctf / metadata / ctf-parser.y
index 84d4702ebb30afa0cb78b8e9008c3475487a1a23..61292c91f29c380ff77e52dc91352bf811d6e5d1 100644 (file)
@@ -58,15 +58,15 @@ _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
 }
 
 BT_HIDDEN
-int yyparse(struct ctf_scanner *scanner);
+int yyparse(struct ctf_scanner *scanner, yyscan_t yyscanner);
 BT_HIDDEN
-int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
+int yylex(union YYSTYPE *yyval, yyscan_t yyscanner);
 BT_HIDDEN
 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
 BT_HIDDEN
 int yylex_destroy(yyscan_t yyscanner);
 BT_HIDDEN
-void yyrestart(FILE * in_str, yyscan_t scanner);
+void yyrestart(FILE * in_str, yyscan_t yyscanner);
 BT_HIDDEN
 int yyget_lineno(yyscan_t yyscanner);
 BT_HIDDEN
@@ -362,19 +362,16 @@ static void add_type(struct ctf_scanner *scanner, char *id)
 static struct ctf_node *make_node(struct ctf_scanner *scanner,
                                  enum node_type type)
 {
-       struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
        struct ctf_node *node;
 
-       node = malloc(sizeof(*node));
+       node = objstack_alloc(scanner->objstack, sizeof(*node));
        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);
        BT_INIT_LIST_HEAD(&node->tmp_head);
-       bt_list_add(&node->gc, &ast->allocated_nodes);
        bt_list_add(&node->siblings, &node->tmp_head);
 
        switch (type) {
@@ -937,7 +934,7 @@ static int set_parent_node(struct ctf_node *node,
 }
 
 BT_HIDDEN
-void yyerror(struct ctf_scanner *scanner, const char *str)
+void yyerror(struct ctf_scanner *scanner, yyscan_t yyscanner, const char *str)
 {
        printfl_error(yyget_lineno(scanner->scanner),
                "token \"%s\": %s\n",
@@ -952,19 +949,17 @@ int yywrap(void)
 
 #define reparent_error(scanner, str)                           \
 do {                                                           \
-       yyerror(scanner, YY_("reparent_error: " str));  \
+       yyerror(scanner, scanner->scanner, YY_("reparent_error: " str)); \
        YYERROR;                                                \
 } while (0)
 
-static struct ctf_ast *ctf_ast_alloc(void)
+static struct ctf_ast *ctf_ast_alloc(struct ctf_scanner *scanner)
 {
        struct ctf_ast *ast;
 
-       ast = malloc(sizeof(*ast));
+       ast = objstack_alloc(scanner->objstack, sizeof(*ast));
        if (!ast)
                return NULL;
-       memset(ast, 0, sizeof(*ast));
-       BT_INIT_LIST_HEAD(&ast->allocated_nodes);
        ast->root.type = NODE_ROOT;
        BT_INIT_LIST_HEAD(&ast->root.tmp_head);
        BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
@@ -977,18 +972,9 @@ static struct ctf_ast *ctf_ast_alloc(void)
        return ast;
 }
 
-static void ctf_ast_free(struct ctf_ast *ast)
-{
-       struct ctf_node *node, *tmp;
-
-       bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
-               free(node);
-       free(ast);
-}
-
 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
 {
-       return yyparse(scanner);
+       return yyparse(scanner, scanner->scanner);
 }
 
 struct ctf_scanner *ctf_scanner_alloc(FILE *input)
@@ -1011,12 +997,12 @@ struct ctf_scanner *ctf_scanner_alloc(FILE *input)
        /* Start processing new stream */
        yyrestart(input, scanner->scanner);
 
-       scanner->ast = ctf_ast_alloc();
-       if (!scanner->ast)
-               goto cleanup_lexer;
        scanner->objstack = objstack_create();
        if (!scanner->objstack)
-               goto cleanup_ast;
+               goto cleanup_lexer;
+       scanner->ast = ctf_ast_alloc(scanner);
+       if (!scanner->ast)
+               goto cleanup_objstack;
        init_scope(&scanner->root_scope, NULL);
        scanner->cs = &scanner->root_scope;
 
@@ -1027,8 +1013,8 @@ struct ctf_scanner *ctf_scanner_alloc(FILE *input)
 
        return scanner;
 
-cleanup_ast:
-       ctf_ast_free(scanner->ast);
+cleanup_objstack:
+       objstack_destroy(scanner->objstack);
 cleanup_lexer:
        ret = yylex_destroy(scanner->scanner);
        if (!ret)
@@ -1044,7 +1030,6 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
 
        finalize_scope(&scanner->root_scope);
        objstack_destroy(scanner->objstack);
-       ctf_ast_free(scanner->ast);
        ret = yylex_destroy(scanner->scanner);
        if (ret)
                printf_error("yylex_destroy error");
@@ -1057,7 +1042,8 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
        /* %locations */
 %error-verbose
 %parse-param {struct ctf_scanner *scanner}
-%lex-param {struct ctf_scanner *scanner}
+%parse-param {yyscan_t yyscanner}
+%lex-param {yyscan_t yyscanner}
 /*
  * Expect two shift-reduce conflicts. Caused by enum name-opt : type {}
  * vs struct { int :value; } (unnamed bit-field). The default is to
This page took 0.025929 seconds and 4 git commands to generate.