Add environment (env {}) parser-level support
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 1 Feb 2012 22:24:54 +0000 (17:24 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 1 Feb 2012 22:24:54 +0000 (17:24 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/metadata/ctf-ast.h
formats/ctf/metadata/ctf-lexer.l
formats/ctf/metadata/ctf-parser.y
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
formats/ctf/metadata/ctf-visitor-parent-links.c
formats/ctf/metadata/ctf-visitor-semantic-validator.c
formats/ctf/metadata/ctf-visitor-xml.c

index 40298b8e506821cb520f444d06115bf752e647ac..eba14cdadf54e76e23d835a6dca3d65e4e963d6c 100644 (file)
@@ -22,6 +22,7 @@ enum node_type {
 
        NODE_EVENT,
        NODE_STREAM,
+       NODE_ENV,
        NODE_TRACE,
        NODE_CLOCK,
 
@@ -70,6 +71,7 @@ struct ctf_node {
                         */
                        struct cds_list_head declaration_list;
                        struct cds_list_head trace;
+                       struct cds_list_head env;
                        struct cds_list_head stream;
                        struct cds_list_head event;
                        struct cds_list_head clock;
@@ -88,6 +90,13 @@ struct ctf_node {
                         */
                        struct cds_list_head declaration_list;
                } stream;
+               struct {
+                       /*
+                        * Children nodes are ctf_expression, typedef,
+                        * typealias and type_specifier_list.
+                        */
+                       struct cds_list_head declaration_list;
+               } env;
                struct {
                        /*
                         * Children nodes are ctf_expression, typedef,
index f5ff02f1aa17084b9b1c1e920d6317e7194b3252..a0232aa422324a41f58424db6e2c31d3286ade52 100644 (file)
@@ -99,6 +99,7 @@ char                          setstring(yyextra, yylval, yytext); return CHAR;
 clock                          setstring(yyextra, yylval, yytext); return CLOCK;
 double                         setstring(yyextra, yylval, yytext); return DOUBLE;
 enum                           setstring(yyextra, yylval, yytext); return ENUM;
+env                            setstring(yyextra, yylval, yytext); return ENV;
 event                          setstring(yyextra, yylval, yytext); return EVENT;
 floating_point                 setstring(yyextra, yylval, yytext); return FLOATING_POINT;
 float                          setstring(yyextra, yylval, yytext); return FLOAT;
index 78b63cc36d6adfbd4c465072418e2ed0b602f012..2c90ab483f165a4b33ff7193b356d87aed10efa0 100644 (file)
@@ -64,6 +64,7 @@ static const char *node_type_to_str[] = {
        [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
        [ NODE_ROOT ] = "NODE_ROOT",
        [ NODE_EVENT ] = "NODE_EVENT",
+       [ NODE_ENV ] = "NODE_ENV",
        [ NODE_STREAM ] = "NODE_STREAM",
        [ NODE_TRACE ] = "NODE_TRACE",
        [ NODE_CLOCK ] = "NODE_CLOCK",
@@ -244,6 +245,9 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
        case NODE_STREAM:
                CDS_INIT_LIST_HEAD(&node->u.stream.declaration_list);
                break;
+       case NODE_ENV:
+               CDS_INIT_LIST_HEAD(&node->u.env.declaration_list);
+               break;
        case NODE_TRACE:
                CDS_INIT_LIST_HEAD(&node->u.trace.declaration_list);
                break;
@@ -327,6 +331,9 @@ static int reparent_ctf_expression(struct ctf_node *node,
        case NODE_STREAM:
                _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
                break;
+       case NODE_ENV:
+               _cds_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
+               break;
        case NODE_TRACE:
                _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
                break;
@@ -382,6 +389,9 @@ static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
        case NODE_STREAM:
                _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
                break;
+       case NODE_ENV:
+               _cds_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
+               break;
        case NODE_TRACE:
                _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
                break;
@@ -434,6 +444,9 @@ static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
        case NODE_STREAM:
                _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
                break;
+       case NODE_ENV:
+               _cds_list_splice_tail(&node->tmp_head, &parent->u.env.declaration_list);
+               break;
        case NODE_TRACE:
                _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
                break;
@@ -485,6 +498,7 @@ static int reparent_type_specifier(struct ctf_node *node,
        case NODE_TYPE_SPECIFIER:
        case NODE_EVENT:
        case NODE_STREAM:
+       case NODE_ENV:
        case NODE_TRACE:
        case NODE_CLOCK:
        case NODE_VARIANT:
@@ -527,6 +541,9 @@ static int reparent_type_specifier_list(struct ctf_node *node,
        case NODE_STREAM:
                cds_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
                break;
+       case NODE_ENV:
+               cds_list_add_tail(&node->siblings, &parent->u.env.declaration_list);
+               break;
        case NODE_TRACE:
                cds_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
                break;
@@ -599,6 +616,7 @@ static int reparent_type_declarator(struct ctf_node *node,
        case NODE_ROOT:
        case NODE_EVENT:
        case NODE_STREAM:
+       case NODE_ENV:
        case NODE_TRACE:
        case NODE_CLOCK:
        case NODE_VARIANT:
@@ -659,6 +677,13 @@ static int set_parent_node(struct ctf_node *node,
                        return -EPERM;
                }
                break;
+       case NODE_ENV:
+               if (parent->type == NODE_ROOT) {
+                       _cds_list_splice_tail(&node->tmp_head, &parent->u.root.env);
+               } else {
+                       return -EPERM;
+               }
+               break;
        case NODE_TRACE:
                if (parent->type == NODE_ROOT) {
                        _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
@@ -787,6 +812,7 @@ static struct ctf_ast *ctf_ast_alloc(void)
        CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
        CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
        CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
+       CDS_INIT_LIST_HEAD(&ast->root.u.root.env);
        CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
        CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
        CDS_INIT_LIST_HEAD(&ast->root.u.root.clock);
@@ -878,7 +904,7 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
  */
 %expect 2
 %start file
-%token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
+%token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
 %token <gs> IDENTIFIER ID_TYPE
 %token ERROR
 %union
@@ -897,6 +923,7 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
 %type <n> declaration
 %type <n> event_declaration
 %type <n> stream_declaration
+%type <n> env_declaration
 %type <n> trace_declaration
 %type <n> clock_declaration
 %type <n> integer_declaration_specifiers
@@ -1188,6 +1215,8 @@ declaration:
                {       $$ = $1;        }
        |       stream_declaration
                {       $$ = $1;        }
+       |       env_declaration
+               {       $$ = $1;        }
        |       trace_declaration
                {       $$ = $1;        }
        |       clock_declaration
@@ -1290,6 +1319,29 @@ stream_declaration_end:
                {       pop_scope(scanner);     }
        ;
 
+env_declaration:
+               env_declaration_begin env_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_ENV);
+               }
+       |       env_declaration_begin ctf_assignment_expression_list env_declaration_end
+               {
+                       $$ = make_node(scanner, NODE_ENV);
+                       if (set_parent_node($2, $$))
+                               reparent_error(scanner, "env declaration");
+               }
+       ;
+
+env_declaration_begin:
+               ENV LBRAC
+               {       push_scope(scanner);    }
+       ;
+
+env_declaration_end:
+               RBRAC SEMICOLON
+               {       pop_scope(scanner);     }
+       ;
+
 trace_declaration:
                trace_declaration_begin trace_declaration_end
                {
index dee8384d703b07778fd5fa46b1045a6b0e1ce7d0..31e55f42cb78653cf65fd820de107de4cc0907e5 100644 (file)
@@ -2304,6 +2304,13 @@ void clock_free(gpointer data)
        g_free(clock);
 }
 
+static
+int ctf_env_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace *trace)
+{
+       fprintf(fd, "[warning] %s: environment declaration support not implement yet.\n", __func__);
+       return 0;       /* continue */
+}
+
 static
 int ctf_root_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace *trace)
 {
@@ -2355,7 +2362,7 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node,
 {
        int ret = 0;
        struct ctf_node *iter;
-       int clock_done = 0;
+       int env_clock_done = 0;
 
        printf_verbose("CTF visitor: metadata construction... ");
        trace->byte_order = byte_order;
@@ -2367,7 +2374,16 @@ retry:
 
        switch (node->type) {
        case NODE_ROOT:
-               if (!clock_done) {
+               if (!env_clock_done) {
+                       cds_list_for_each_entry(iter, &node->u.root.env, siblings) {
+                               ret = ctf_env_visit(fd, depth + 1, iter,
+                                                   trace);
+                               if (ret) {
+                                       fprintf(fd, "[error] %s: env declaration error\n", __func__);
+                                       goto error;
+                               }
+                       }
+
                        /*
                         * declarations need to query clock hash table,
                         * so clock need to be treated first.
@@ -2380,7 +2396,7 @@ retry:
                                        goto error;
                                }
                        }
-                       clock_done = 1;
+                       env_clock_done = 1;
                }
                cds_list_for_each_entry(iter, &node->u.root.declaration_list,
                                        siblings) {
index 4f987211cd276595f4013da17dd1647634768b8e..821083ebd1e77bff1a607f7f7cf1d21dc1ac926c 100644 (file)
@@ -229,6 +229,14 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                                return ret;
                }
                break;
+       case NODE_ENV:
+               cds_list_for_each_entry(iter, &node->u.env.declaration_list, siblings) {
+                       iter->parent = node;
+                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+                       if (ret)
+                               return ret;
+               }
+               break;
        case NODE_TRACE:
                cds_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
                        iter->parent = node;
index da813e0a50acf6ce1b9eacde0e6caaaf81b15fde..5a5de793b7417abd00bef0b1fec8590875f5bb51 100644 (file)
@@ -107,6 +107,7 @@ 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:
@@ -210,6 +211,7 @@ 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:
@@ -250,6 +252,7 @@ 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:
@@ -331,6 +334,7 @@ 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:
@@ -470,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:
@@ -505,6 +523,7 @@ int _ctf_visitor_semantic_check(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_FLOATING_POINT:
@@ -574,6 +593,7 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                case NODE_ENUMERATOR:
                case NODE_ENUM:
                case NODE_CLOCK:
+               case NODE_ENV:
                default:
                        goto errinval;
                }
@@ -679,6 +699,7 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                case NODE_ENUMERATOR:
                case NODE_ENUM:
                case NODE_CLOCK:
+               case NODE_ENV:
                default:
                        goto errinval;
                }
index 56974c382f70e07a4a1781467856decd14fd7d54..66b375615f925915fcaf25e74f58bead0fe4ac74 100644 (file)
@@ -410,6 +410,17 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
                print_tabs(fd, depth);
                fprintf(fd, "</stream>\n");
                break;
+       case NODE_ENV:
+               print_tabs(fd, depth);
+               fprintf(fd, "<env>\n");
+               cds_list_for_each_entry(iter, &node->u.env.declaration_list, siblings) {
+                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
+                       if (ret)
+                               return ret;
+               }
+               print_tabs(fd, depth);
+               fprintf(fd, "</env>\n");
+               break;
        case NODE_TRACE:
                print_tabs(fd, depth);
                fprintf(fd, "<trace>\n");
@@ -421,6 +432,18 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
                print_tabs(fd, depth);
                fprintf(fd, "</trace>\n");
                break;
+       case NODE_CLOCK:
+               print_tabs(fd, depth);
+               fprintf(fd, "<clock>\n");
+               cds_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) {
+                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
+                       if (ret)
+                               return ret;
+               }
+               print_tabs(fd, depth);
+               fprintf(fd, "</clock>\n");
+               break;
+
 
        case NODE_CTF_EXPRESSION:
                print_tabs(fd, depth);
This page took 0.046078 seconds and 4 git commands to generate.