X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fmetadata%2Fctf-visitor-semantic-validator.c;h=5a5de793b7417abd00bef0b1fec8590875f5bb51;hb=6070d2f1612a27050f14362a910b565b8e70662c;hp=be5ed8f440e1b51c5672962f0684bc46ebf875d1;hpb=b7e35badc2eac52e27b802a9078bfb7c8f3b04a7;p=babeltrace.git diff --git a/formats/ctf/metadata/ctf-visitor-semantic-validator.c b/formats/ctf/metadata/ctf-visitor-semantic-validator.c index be5ed8f4..5a5de793 100644 --- a/formats/ctf/metadata/ctf-visitor-semantic-validator.c +++ b/formats/ctf/metadata/ctf-visitor-semantic-validator.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include "ctf-scanner.h" #include "ctf-parser.h" @@ -71,9 +71,10 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node) */ switch (node->u.unary_expression.type) { case UNARY_UNSIGNED_CONSTANT: + case UNARY_STRING: break; default: - fprintf(fd, "[error]: semantic error (children of type declarator and enum can only be unsigned numeric constants)\n"); + fprintf(fd, "[error]: semantic error (children of type declarator and enum can only be unsigned numeric constants or references to fields (a.b.c))\n"); goto errperm; } break; /* OK */ @@ -106,7 +107,9 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node) case NODE_ROOT: case NODE_EVENT: case NODE_STREAM: + case NODE_ENV: case NODE_TRACE: + case NODE_CLOCK: case NODE_TYPEDEF: case NODE_TYPEALIAS_TARGET: case NODE_TYPEALIAS_ALIAS: @@ -208,7 +211,9 @@ int ctf_visitor_type_specifier_list(FILE *fd, int depth, struct ctf_node *node) case NODE_EVENT: case NODE_STREAM: + case NODE_ENV: case NODE_TRACE: + case NODE_CLOCK: case NODE_UNARY_EXPRESSION: case NODE_TYPEALIAS: case NODE_TYPE_SPECIFIER: @@ -247,7 +252,9 @@ int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node) case NODE_ROOT: case NODE_EVENT: case NODE_STREAM: + case NODE_ENV: case NODE_TRACE: + case NODE_CLOCK: case NODE_UNARY_EXPRESSION: case NODE_TYPEALIAS: case NODE_TYPE_SPECIFIER: @@ -300,18 +307,21 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node) */ if (node->u.type_declarator.type == TYPEDEC_NESTED) goto errperm; - switch (node->u.type_declarator.type) { - case TYPESPEC_FLOATING_POINT: - case TYPESPEC_INTEGER: - case TYPESPEC_STRING: - case TYPESPEC_STRUCT: - case TYPESPEC_VARIANT: - case TYPESPEC_ENUM: - if (cds_list_empty(&node->u.type_declarator.pointers)) - goto errperm; - break; - default: - break; + cds_list_for_each_entry(iter, &node->parent->u.typealias_alias.type_specifier_list->u.type_specifier_list.head, + siblings) { + switch (iter->u.type_specifier.type) { + case TYPESPEC_FLOATING_POINT: + case TYPESPEC_INTEGER: + case TYPESPEC_STRING: + case TYPESPEC_STRUCT: + case TYPESPEC_VARIANT: + case TYPESPEC_ENUM: + if (cds_list_empty(&node->u.type_declarator.pointers)) + goto errperm; + break; + default: + break; + } } if (node->u.type_declarator.type == TYPEDEC_ID && node->u.type_declarator.u.id != NULL) @@ -324,7 +334,9 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node) case NODE_ROOT: case NODE_EVENT: case NODE_STREAM: + case NODE_ENV: case NODE_TRACE: + case NODE_CLOCK: case NODE_CTF_EXPRESSION: case NODE_UNARY_EXPRESSION: case NODE_TYPEALIAS: @@ -341,13 +353,11 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node) goto errinval; } - if (!cds_list_empty(&node->u.type_declarator.pointers)) { - cds_list_for_each_entry(iter, &node->u.type_declarator.pointers, - siblings) { - ret = _ctf_visitor_semantic_check(fd, depth + 1, iter); - if (ret) - return ret; - } + cds_list_for_each_entry(iter, &node->u.type_declarator.pointers, + siblings) { + ret = _ctf_visitor_semantic_check(fd, depth + 1, iter); + if (ret) + return ret; } switch (node->u.type_declarator.type) { @@ -361,10 +371,23 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node) if (ret) return ret; } - ret = _ctf_visitor_semantic_check(fd, depth + 1, - node->u.type_declarator.u.nested.length); - if (ret) - return ret; + if (!node->u.type_declarator.u.nested.abstract_array) { + cds_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length, + siblings) { + if (iter->type != NODE_UNARY_EXPRESSION) { + fprintf(fd, "[error] %s: expecting unary expression as length\n", __func__); + return -EINVAL; + } + ret = _ctf_visitor_semantic_check(fd, depth + 1, iter); + if (ret) + return ret; + } + } else { + if (node->parent->type == NODE_TYPEALIAS_TARGET) { + fprintf(fd, "[error] %s: abstract array declarator not permitted as target of typealias\n", __func__); + return -EINVAL; + } + } if (node->u.type_declarator.bitfield_len) { ret = _ctf_visitor_semantic_check(fd, depth + 1, node->u.type_declarator.bitfield_len); @@ -451,6 +474,20 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node) return ret; } break; + case NODE_ENV: + switch (node->parent->type) { + case NODE_ROOT: + break; /* OK */ + default: + goto errinval; + } + + cds_list_for_each_entry(iter, &node->u.env.declaration_list, siblings) { + ret = _ctf_visitor_semantic_check(fd, depth + 1, iter); + if (ret) + return ret; + } + break; case NODE_TRACE: switch (node->parent->type) { case NODE_ROOT: @@ -465,13 +502,30 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node) return ret; } break; + case NODE_CLOCK: + switch (node->parent->type) { + case NODE_ROOT: + break; /* OK */ + default: + goto errinval; + } + + cds_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) { + ret = _ctf_visitor_semantic_check(fd, depth + 1, iter); + if (ret) + return ret; + } + break; + case NODE_CTF_EXPRESSION: switch (node->parent->type) { case NODE_ROOT: case NODE_EVENT: case NODE_STREAM: + case NODE_ENV: case NODE_TRACE: + case NODE_CLOCK: case NODE_FLOATING_POINT: case NODE_INTEGER: case NODE_STRING: @@ -538,6 +592,8 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node) case NODE_STRING: case NODE_ENUMERATOR: case NODE_ENUM: + case NODE_CLOCK: + case NODE_ENV: default: goto errinval; } @@ -642,6 +698,8 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node) case NODE_STRING: case NODE_ENUMERATOR: case NODE_ENUM: + case NODE_CLOCK: + case NODE_ENV: default: goto errinval; }