Print this page
7085 add support for "if" and "else" statements in dtrace

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libdtrace/common/dt_grammar.y
          +++ new/usr/src/lib/libdtrace/common/dt_grammar.y
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  17   17   * If applicable, add the following below this CDDL HEADER, with the
  18   18   * fields enclosed by brackets "[]" replaced with your own identifying
  19   19   * information: Portions Copyright [yyyy] [name of copyright owner]
  20   20   *
  21   21   * CDDL HEADER END
  22   22   *
  23   23   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
       26 +
  26   27  /*
  27      - * Copyright (c) 2013 by Delphix. All rights reserved.
       28 + * Copyright (c) 2014 by Delphix. All rights reserved.
  28   29   * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  29   30   */
  30   31  
  31   32  #include <dt_impl.h>
  32   33  
  33   34  #define OP1(op, c)      dt_node_op1(op, c)
  34   35  #define OP2(op, l, r)   dt_node_op2(op, l, r)
  35   36  #define OP3(x, y, z)    dt_node_op3(x, y, z)
  36   37  #define LINK(l, r)      dt_node_link(l, r)
  37   38  #define DUP(s)          strdup(s)
↓ open down ↓ 110 lines elided ↑ open up ↑
 148  149  %type   <l_node>        translator_member_list
 149  150  %type   <l_node>        translator_member
 150  151  %type   <l_node>        provider_definition
 151  152  %type   <l_node>        provider_probe_list
 152  153  %type   <l_node>        provider_probe
 153  154  %type   <l_node>        probe_definition
 154  155  %type   <l_node>        probe_specifiers
 155  156  %type   <l_node>        probe_specifier_list
 156  157  %type   <l_node>        probe_specifier
 157  158  %type   <l_node>        statement_list
      159 +%type   <l_node>        statement_list_impl
      160 +%type   <l_node>        statement_or_block
 158  161  %type   <l_node>        statement
 159  162  %type   <l_node>        declaration
 160  163  %type   <l_node>        init_declarator_list
 161  164  %type   <l_node>        init_declarator
 162  165  
 163  166  %type   <l_decl>        type_specifier
 164  167  %type   <l_decl>        type_qualifier
 165  168  %type   <l_decl>        struct_or_union_specifier
 166  169  %type   <l_decl>        specifier_qualifier_list
 167  170  %type   <l_decl>        enum_specifier
↓ open down ↓ 142 lines elided ↑ open up ↑
 310  313                           * an ambiguous predicate was slurped up as a comment.
 311  314                           * We cannot perform this check if input() is a string
 312  315                           * because dtrace(1M) [-fmnP] also use the compiler and
 313  316                           * things like dtrace -n BEGIN have to be accepted.
 314  317                           */
 315  318                          if (yypcb->pcb_fileptr != NULL) {
 316  319                                  dnerror($1, D_SYNTAX, "expected predicate and/"
 317  320                                      "or actions following probe description\n");
 318  321                          }
 319  322                          $$ = dt_node_clause($1, NULL, NULL);
      323 +                        yybegin(YYS_CLAUSE);
 320  324                  }
 321  325          |       probe_specifiers '{' statement_list '}' {
 322  326                          $$ = dt_node_clause($1, NULL, $3);
      327 +                        yybegin(YYS_CLAUSE);
 323  328                  }
 324  329          |       probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED {
 325  330                          dnerror($3, D_SYNTAX, "expected actions { } following "
 326  331                              "probe description and predicate\n");
 327  332                  }
 328  333          |       probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED
 329  334                      '{' statement_list '}' {
 330  335                          $$ = dt_node_clause($1, $3, $6);
      336 +                        yybegin(YYS_CLAUSE);
 331  337                  }
 332  338          ;
 333  339  
 334  340  probe_specifiers:
 335  341                  probe_specifier_list { yybegin(YYS_EXPR); $$ = $1; }
 336  342          ;
 337  343  
 338  344  probe_specifier_list:
 339  345                  probe_specifier
 340  346          |       probe_specifier_list DT_TOK_COMMA probe_specifier {
 341  347                          $$ = LINK($1, $3);
 342  348                  }
 343  349          ;
 344  350  
 345  351  probe_specifier:
 346  352                  DT_TOK_PSPEC { $$ = dt_node_pdesc_by_name($1); }
 347  353          |       DT_TOK_INT   { $$ = dt_node_pdesc_by_id($1); }
 348  354          ;
 349  355  
 350      -statement_list: statement { $$ = $1; }
 351      -        |       statement_list ';' statement { $$ = LINK($1, $3); }
      356 +statement_list_impl: /* empty */ { $$ = NULL; }
      357 +        |       statement_list_impl statement { $$ = LINK($1, $2); }
 352  358          ;
 353  359  
 354      -statement:      /* empty */ { $$ = NULL; }
 355      -        |       expression { $$ = dt_node_statement($1); }
      360 +statement_list:
      361 +                statement_list_impl { $$ = $1; }
      362 +        |       statement_list_impl expression {
      363 +                        $$ = LINK($1, dt_node_statement($2));
      364 +                }
 356  365          ;
 357  366  
      367 +statement_or_block:
      368 +                statement
      369 +        |       '{' statement_list '}' { $$ = $2; }
      370 +
      371 +statement:      ';' { $$ = NULL; }
      372 +        |       expression ';' { $$ = dt_node_statement($1); }
      373 +        |       DT_KEY_IF DT_TOK_LPAR expression DT_TOK_RPAR statement_or_block {
      374 +                        $$ = dt_node_if($3, $5, NULL);
      375 +                }
      376 +        |       DT_KEY_IF DT_TOK_LPAR expression DT_TOK_RPAR
      377 +                statement_or_block DT_KEY_ELSE statement_or_block {
      378 +                        $$ = dt_node_if($3, $5, $7);
      379 +                }
      380 +        ;
      381 +
 358  382  argument_expression_list:
 359  383                  assignment_expression
 360  384          |       argument_expression_list DT_TOK_COMMA assignment_expression {
 361  385                          $$ = LINK($1, $3);
 362  386                  }
 363  387          ;
 364  388  
 365  389  primary_expression:
 366  390                  DT_TOK_IDENT { $$ = dt_node_ident($1); }
 367  391          |       DT_TOK_AGG { $$ = dt_node_ident($1); }
↓ open down ↓ 471 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX