#include <string.h>
#include <stdlib.h>
#include <assert.h>
-#include <helpers/list.h>
#include <glib.h>
#include <errno.h>
+#include <inttypes.h>
+#include <babeltrace/list.h>
#include "ctf-scanner.h"
#include "ctf-parser.h"
#include "ctf-ast.h"
+/*
+ * TODO: support enum, variant and struct declarations in scopes.
+ */
+
/* Join two lists, put "add" at the end of "head". */
static inline void
_cds_list_splice_tail (struct cds_list_head *add, struct cds_list_head *head)
char s[];
};
+static const char *node_type_to_str[] = {
+ [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
+ [ NODE_ROOT ] = "NODE_ROOT",
+ [ NODE_EVENT ] = "NODE_EVENT",
+ [ NODE_STREAM ] = "NODE_STREAM",
+ [ NODE_TRACE ] = "NODE_TRACE",
+ [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
+ [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
+ [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
+ [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
+ [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
+ [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
+ [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
+ [ NODE_POINTER ] = "NODE_POINTER",
+ [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
+ [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
+ [ NODE_INTEGER ] = "NODE_INTEGER",
+ [ NODE_STRING ] = "NODE_STRING",
+ [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
+ [ NODE_ENUM ] = "NODE_ENUM",
+ [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
+ [ NODE_VARIANT ] = "NODE_VARIANT",
+ [ NODE_STRUCT ] = "NODE_STRUCT",
+};
+
+const char *node_type(struct ctf_node *node)
+{
+ if (node->type < NR_NODE_TYPES)
+ return node_type_to_str[node->type];
+ else
+ return NULL;
+}
+
static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
size_t len)
{
{
int ret;
- ret = (int) g_hash_table_lookup(s->types, id);
+ ret = (int) (long) g_hash_table_lookup(s->types, id);
printf_dbg("lookup %p %s %d\n", s, id, ret);
return ret;
}
node->type = type;
CDS_INIT_LIST_HEAD(&node->tmp_head);
cds_list_add(&node->gc, &ast->allocated_nodes);
+ cds_list_add(&node->siblings, &node->tmp_head);
switch (type) {
case NODE_ROOT:
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
$$->u.unary_expression.u.string = yylval.gs->s;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| ID_TYPE
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
$$->u.unary_expression.u.string = yylval.gs->s;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| keywords
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
$$->u.unary_expression.u.string = yylval.gs->s;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| DECIMAL_CONSTANT
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
- sscanf(yylval.gs->s, "%llu",
+ sscanf(yylval.gs->s, "%" PRIu64,
&$$->u.unary_expression.u.unsigned_constant);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| OCTAL_CONSTANT
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
- sscanf(yylval.gs->s, "0%llo",
+ sscanf(yylval.gs->s, "0%" PRIo64,
&$$->u.unary_expression.u.unsigned_constant);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| HEXADECIMAL_CONSTANT
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
- sscanf(yylval.gs->s, "0x%llx",
+ sscanf(yylval.gs->s, "0x%" PRIx64,
&$$->u.unary_expression.u.unsigned_constant);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| STRING_LITERAL_START DQUOTE
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
$$->u.unary_expression.u.string = "";
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| STRING_LITERAL_START s_char_sequence DQUOTE
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
$$->u.unary_expression.u.string = $2->s;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| CHARACTER_CONSTANT_START c_char_sequence SQUOTE
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_STRING;
$$->u.unary_expression.u.string = $2->s;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| LPAREN unary_expression RPAREN
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_NESTED;
$$->u.unary_expression.u.nested_exp = $2;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| postfix_expression LSBRAC unary_expression RSBRAC
{
event_declaration_begin event_declaration_end
{
$$ = make_node(scanner, NODE_EVENT);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| event_declaration_begin ctf_assignment_expression_list event_declaration_end
{
$$ = make_node(scanner, NODE_EVENT);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
if (set_parent_node($2, $$))
reparent_error(scanner, "event_declaration");
}
stream_declaration_begin stream_declaration_end
{
$$ = make_node(scanner, NODE_STREAM);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| stream_declaration_begin ctf_assignment_expression_list stream_declaration_end
{
$$ = make_node(scanner, NODE_STREAM);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
if (set_parent_node($2, $$))
reparent_error(scanner, "stream_declaration");
}
trace_declaration_begin trace_declaration_end
{
$$ = make_node(scanner, NODE_TRACE);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| trace_declaration_begin ctf_assignment_expression_list trace_declaration_end
{
$$ = make_node(scanner, NODE_TRACE);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
if (set_parent_node($2, $$))
reparent_error(scanner, "trace_declaration");
}
{
$$ = make_node(scanner, NODE_TYPE_SPECIFIER);
$$->u.type_specifier.type = TYPESPEC_CONST;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| type_specifier
- {
- $$ = $1;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
- }
+ { $$ = $1; }
| declaration_specifiers CONST
{
struct ctf_node *node;
type_declarator_list:
type_declarator
- {
- $$ = $1;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
- }
+ { $$ = $1; }
| type_declarator_list COMMA type_declarator
{
$$ = $1;
abstract_type_declarator_list:
abstract_type_declarator
- {
- $$ = $1;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
- }
+ { $$ = $1; }
| abstract_type_declarator_list COMMA abstract_type_declarator
{
$$ = $1;
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
- sscanf(yylval.gs->s, "%llu",
+ sscanf(yylval.gs->s, "%" PRIu64,
&$$->u.unary_expression.u.unsigned_constant);
}
| OCTAL_CONSTANT
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
- sscanf(yylval.gs->s, "0%llo",
+ sscanf(yylval.gs->s, "0%" PRIo64,
&$$->u.unary_expression.u.unsigned_constant);
}
| HEXADECIMAL_CONSTANT
{
$$ = make_node(scanner, NODE_UNARY_EXPRESSION);
$$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
- sscanf(yylval.gs->s, "0x%llx",
+ sscanf(yylval.gs->s, "0x%" PRIx64,
&$$->u.unary_expression.u.unsigned_constant);
}
;
{
$$ = make_node(scanner, NODE_TYPE_SPECIFIER);
$$->u.type_specifier.type = TYPESPEC_CONST;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| type_specifier
- {
- $$ = $1;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
- }
+ { $$ = $1; }
| specifier_qualifier_list CONST
{
struct ctf_node *node;
struct_or_variant_declarator_list:
struct_or_variant_declarator
- {
- $$ = $1;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
- }
+ { $$ = $1; }
| struct_or_variant_declarator_list COMMA struct_or_variant_declarator
{
$$ = $1;
enumerator_list:
enumerator
- {
- $$ = $1;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
- }
+ { $$ = $1; }
| enumerator_list COMMA enumerator
{
$$ = $1;
abstract_declarator_list:
abstract_declarator
- {
- $$ = $1;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
- }
+ { $$ = $1; }
| abstract_declarator_list COMMA abstract_declarator
{
$$ = $1;
STAR
{
$$ = make_node(scanner, NODE_POINTER);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| STAR pointer
{
$$ = make_node(scanner, NODE_POINTER);
cds_list_splice(&($2)->tmp_head, &($$)->tmp_head);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
| STAR type_qualifier_list pointer
{
$$ = make_node(scanner, NODE_POINTER);
$$->u.pointer.const_qualifier = 1;
cds_list_splice(&($3)->tmp_head, &($$)->tmp_head);
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
}
;
ctf_assignment_expression_list:
ctf_assignment_expression SEMICOLON
- {
- $$ = $1;
- cds_list_add(&($$)->siblings, &($$)->tmp_head);
- }
+ { $$ = $1; }
| ctf_assignment_expression_list ctf_assignment_expression SEMICOLON
{
$$ = $1;