Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
struct {
/* typedec has no pointer list */
struct ctf_node *type_declarator;
struct {
/* typedec has no pointer list */
struct ctf_node *type_declarator;
- /* value or first node of declaration specifier list */
- struct ctf_node *length;
+ /*
+ * unary expression (value) or
+ * declaration specifiers.
+ */
+ struct cds_list_head length;
/* for abstract type declarator */
unsigned int abstract_array;
} nested;
/* for abstract type declarator */
unsigned int abstract_array;
} nested;
} enumerator;
struct {
char *enum_id;
} enumerator;
struct {
char *enum_id;
- /* NULL, value or declaration specifier */
- struct ctf_node *container_type;
+ /*
+ * Either empty, contains unary expression or
+ * declaration specifiers.
+ */
+ struct cds_list_head container_type;
struct cds_list_head enumerator_list;
int has_body;
} _enum;
struct cds_list_head enumerator_list;
int has_body;
} _enum;
CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
break;
case NODE_ENUM:
CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
break;
case NODE_ENUM:
+ CDS_INIT_LIST_HEAD(&node->u._enum.container_type);
CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
break;
case NODE_STRUCT_OR_VARIANT_DECLARATION:
CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
break;
case NODE_STRUCT_OR_VARIANT_DECLARATION:
break;
case NODE_TYPE_DECLARATOR:
parent->u.type_declarator.type = TYPEDEC_NESTED;
break;
case NODE_TYPE_DECLARATOR:
parent->u.type_declarator.type = TYPEDEC_NESTED;
- parent->u.type_declarator.u.nested.length = node;
+ CDS_INIT_LIST_HEAD(&parent->u.type_declarator.u.nested.length);
+ _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.u.nested.length);
- parent->u._enum.container_type = node;
+ _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.container_type);
break;
case NODE_STRUCT_OR_VARIANT_DECLARATION:
_cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.declaration_specifier);
break;
case NODE_STRUCT_OR_VARIANT_DECLARATION:
_cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.declaration_specifier);
%type <n> type_specifier
%type <n> struct_type_specifier
%type <n> variant_type_specifier
%type <n> type_specifier
%type <n> struct_type_specifier
%type <n> variant_type_specifier
-%type <n> type_specifier_or_integer_constant
+%type <n> declaration_specifiers_or_integer_constant
%type <n> enum_type_specifier
%type <n> struct_or_variant_declaration_list
%type <n> struct_or_variant_declaration
%type <n> enum_type_specifier
%type <n> struct_or_variant_declaration_list
%type <n> struct_or_variant_declaration
{ pop_scope(scanner); }
;
{ pop_scope(scanner); }
;
-type_specifier_or_integer_constant:
+declaration_specifiers_or_integer_constant:
declaration_specifiers
{ $$ = $1; }
| DECIMAL_CONSTANT
declaration_specifiers
{ $$ = $1; }
| DECIMAL_CONSTANT
$$->u._enum.has_body = 1;
_cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
}
$$->u._enum.has_body = 1;
_cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
}
- | LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
+ | LT declaration_specifiers_or_integer_constant GT LBRAC enumerator_list RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.container_type = $2;
+ _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.container_type);
_cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
}
| IDENTIFIER LBRAC enumerator_list RBRAC
_cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
}
| IDENTIFIER LBRAC enumerator_list RBRAC
$$->u._enum.enum_id = $1->s;
_cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
$$->u._enum.enum_id = $1->s;
_cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
- | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
+ | IDENTIFIER LT declaration_specifiers_or_integer_constant GT LBRAC enumerator_list RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
$$->u._enum.enum_id = $1->s;
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
$$->u._enum.enum_id = $1->s;
- $$->u._enum.container_type = $3;
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
_cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
}
| ID_TYPE LBRAC enumerator_list RBRAC
_cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
}
| ID_TYPE LBRAC enumerator_list RBRAC
$$->u._enum.enum_id = $1->s;
_cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
$$->u._enum.enum_id = $1->s;
_cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
- | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC
+ | ID_TYPE LT declaration_specifiers_or_integer_constant GT LBRAC enumerator_list RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
$$->u._enum.enum_id = $1->s;
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
$$->u._enum.enum_id = $1->s;
- $$->u._enum.container_type = $3;
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
_cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
}
| LBRAC enumerator_list COMMA RBRAC
_cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
}
| LBRAC enumerator_list COMMA RBRAC
$$->u._enum.has_body = 1;
_cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
}
$$->u._enum.has_body = 1;
_cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list);
}
- | LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
+ | LT declaration_specifiers_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
- $$->u._enum.container_type = $2;
+ _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.container_type);
_cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
}
| IDENTIFIER LBRAC enumerator_list COMMA RBRAC
_cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
}
| IDENTIFIER LBRAC enumerator_list COMMA RBRAC
$$->u._enum.enum_id = $1->s;
_cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
$$->u._enum.enum_id = $1->s;
_cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
- | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
+ | IDENTIFIER LT declaration_specifiers_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
$$->u._enum.enum_id = $1->s;
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
$$->u._enum.enum_id = $1->s;
- $$->u._enum.container_type = $3;
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
_cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
}
| IDENTIFIER
_cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
}
| IDENTIFIER
$$->u._enum.has_body = 0;
$$->u._enum.enum_id = $1->s;
}
$$->u._enum.has_body = 0;
$$->u._enum.enum_id = $1->s;
}
- | IDENTIFIER LT type_specifier_or_integer_constant GT
+ | IDENTIFIER LT declaration_specifiers_or_integer_constant GT
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 0;
$$->u._enum.enum_id = $1->s;
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 0;
$$->u._enum.enum_id = $1->s;
- $$->u._enum.container_type = $3;
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
}
| ID_TYPE LBRAC enumerator_list COMMA RBRAC
{
}
| ID_TYPE LBRAC enumerator_list COMMA RBRAC
{
$$->u._enum.enum_id = $1->s;
_cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
$$->u._enum.enum_id = $1->s;
_cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
}
- | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
+ | ID_TYPE LT declaration_specifiers_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
$$->u._enum.enum_id = $1->s;
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 1;
$$->u._enum.enum_id = $1->s;
- $$->u._enum.container_type = $3;
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
_cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
}
| ID_TYPE
_cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
}
| ID_TYPE
$$->u._enum.has_body = 0;
$$->u._enum.enum_id = $1->s;
}
$$->u._enum.has_body = 0;
$$->u._enum.enum_id = $1->s;
}
- | ID_TYPE LT type_specifier_or_integer_constant GT
+ | ID_TYPE LT declaration_specifiers_or_integer_constant GT
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 0;
$$->u._enum.enum_id = $1->s;
{
$$ = make_node(scanner, NODE_ENUM);
$$->u._enum.has_body = 0;
$$->u._enum.enum_id = $1->s;
- $$->u._enum.container_type = $3;
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $2;
}
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $2;
}
- | direct_abstract_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
+ | direct_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $1;
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $1;
- $$->u.type_declarator.u.nested.length = $3;
+ CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
}
| direct_abstract_declarator LSBRAC RSBRAC
{
}
| direct_abstract_declarator LSBRAC RSBRAC
{
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $2;
}
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $2;
}
- | direct_alias_abstract_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
+ | direct_alias_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $1;
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $1;
- $$->u.type_declarator.u.nested.length = $3;
+ CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
}
| direct_alias_abstract_declarator LSBRAC RSBRAC
{
}
| direct_alias_abstract_declarator LSBRAC RSBRAC
{
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $2;
}
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $2;
}
- | direct_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
+ | direct_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $1;
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $1;
- $$->u.type_declarator.u.nested.length = $3;
+ CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $2;
}
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $2;
}
- | direct_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC
+ | direct_type_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $1;
{
$$ = make_node(scanner, NODE_TYPE_DECLARATOR);
$$->u.type_declarator.type = TYPEDEC_NESTED;
$$->u.type_declarator.u.nested.type_declarator = $1;
- $$->u.type_declarator.u.nested.length = $3;
+ CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
+ _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
- 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);
+ cds_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 (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);
+ cds_list_for_each_entry(iter, &node->u._enum.container_type,
+ siblings) {
+ iter->parent = node;
+ ret = ctf_visitor_parent_links(fd, depth + 1, iter);
case TYPEDEC_ID:
break;
case TYPEDEC_NESTED:
case TYPEDEC_ID:
break;
case TYPEDEC_NESTED:
if (node->u.type_declarator.u.nested.type_declarator) {
ret = _ctf_visitor_semantic_check(fd, depth + 1,
node->u.type_declarator.u.nested.type_declarator);
if (ret)
return ret;
}
if (node->u.type_declarator.u.nested.type_declarator) {
ret = _ctf_visitor_semantic_check(fd, depth + 1,
node->u.type_declarator.u.nested.type_declarator);
if (ret)
return ret;
}
- if (node->u.type_declarator.u.nested.length) {
+ cds_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
+ siblings) {
ret = _ctf_visitor_semantic_check(fd, depth + 1,
ret = _ctf_visitor_semantic_check(fd, depth + 1,
- node->u.type_declarator.u.nested.length);
+ nr_nest_len++;
+ if (iter->type == NODE_UNARY_EXPRESSION && nr_nest_len > 1) {
+ goto errperm;
+ }
}
if (node->u.type_declarator.bitfield_len) {
ret = _ctf_visitor_semantic_check(fd, depth + 1,
}
if (node->u.type_declarator.bitfield_len) {
ret = _ctf_visitor_semantic_check(fd, depth + 1,
case TYPEDEC_UNKNOWN:
default:
fprintf(fd, "[error] %s: unknown type declarator %d\n", __func__,
case TYPEDEC_UNKNOWN:
default:
fprintf(fd, "[error] %s: unknown type declarator %d\n", __func__,
- if (node->u._enum.container_type) {
- ret = _ctf_visitor_semantic_check(fd, depth + 1, node->u._enum.container_type);
+ cds_list_for_each_entry(iter, &node->u._enum.container_type,
+ siblings) {
+ ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
print_tabs(fd, depth);
fprintf(fd, "</type_declarator>\n");
}
print_tabs(fd, depth);
fprintf(fd, "</type_declarator>\n");
}
- if (node->u.type_declarator.u.nested.length) {
+ if (!cds_list_empty(&node->u.type_declarator.u.nested.length)) {
print_tabs(fd, depth);
fprintf(fd, "<length>\n");
print_tabs(fd, depth);
fprintf(fd, "<length>\n");
- ret = ctf_visitor_print_xml(fd, depth + 1,
- node->u.type_declarator.u.nested.length);
+ }
+ cds_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
+ siblings) {
+ ret = ctf_visitor_print_xml(fd, depth + 1, iter);
+ }
+ if (!cds_list_empty(&node->u.type_declarator.u.nested.length)) {
print_tabs(fd, depth);
fprintf(fd, "</length>\n");
}
print_tabs(fd, depth);
fprintf(fd, "</length>\n");
}
fprintf(fd, "<enum >\n");
depth++;
fprintf(fd, "<enum >\n");
depth++;
- if (node->u._enum.container_type) {
+ if (!cds_list_empty(&node->u._enum.container_type)) {
print_tabs(fd, depth);
fprintf(fd, "<container_type>\n");
print_tabs(fd, depth);
fprintf(fd, "<container_type>\n");
- ret = ctf_visitor_print_xml(fd, depth + 1, node->u._enum.container_type);
+ }
+
+ cds_list_for_each_entry(iter, &node->u._enum.container_type,
+ siblings) {
+ ret = ctf_visitor_print_xml(fd, depth + 1, iter);
+ }
+ if (!cds_list_empty(&node->u._enum.container_type)) {
print_tabs(fd, depth);
fprintf(fd, "</container_type>\n");
}
print_tabs(fd, depth);
fprintf(fd, "</container_type>\n");
}