Print this page
7085 add support for "if" and "else" statements in dtrace
*** 21,32 ****
* CDDL HEADER END
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
! * Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
*/
#include <dt_impl.h>
--- 21,33 ----
* CDDL HEADER END
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+
/*
! * Copyright (c) 2014 by Delphix. All rights reserved.
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
*/
#include <dt_impl.h>
*** 153,162 ****
--- 154,165 ----
%type <l_node> probe_definition
%type <l_node> probe_specifiers
%type <l_node> probe_specifier_list
%type <l_node> probe_specifier
%type <l_node> statement_list
+ %type <l_node> statement_list_impl
+ %type <l_node> statement_or_block
%type <l_node> statement
%type <l_node> declaration
%type <l_node> init_declarator_list
%type <l_node> init_declarator
*** 315,335 ****
--- 318,341 ----
if (yypcb->pcb_fileptr != NULL) {
dnerror($1, D_SYNTAX, "expected predicate and/"
"or actions following probe description\n");
}
$$ = dt_node_clause($1, NULL, NULL);
+ yybegin(YYS_CLAUSE);
}
| probe_specifiers '{' statement_list '}' {
$$ = dt_node_clause($1, NULL, $3);
+ yybegin(YYS_CLAUSE);
}
| probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED {
dnerror($3, D_SYNTAX, "expected actions { } following "
"probe description and predicate\n");
}
| probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED
'{' statement_list '}' {
$$ = dt_node_clause($1, $3, $6);
+ yybegin(YYS_CLAUSE);
}
;
probe_specifiers:
probe_specifier_list { yybegin(YYS_EXPR); $$ = $1; }
*** 345,362 ****
probe_specifier:
DT_TOK_PSPEC { $$ = dt_node_pdesc_by_name($1); }
| DT_TOK_INT { $$ = dt_node_pdesc_by_id($1); }
;
! statement_list: statement { $$ = $1; }
! | statement_list ';' statement { $$ = LINK($1, $3); }
;
! statement: /* empty */ { $$ = NULL; }
! | expression { $$ = dt_node_statement($1); }
;
argument_expression_list:
assignment_expression
| argument_expression_list DT_TOK_COMMA assignment_expression {
$$ = LINK($1, $3);
}
--- 351,386 ----
probe_specifier:
DT_TOK_PSPEC { $$ = dt_node_pdesc_by_name($1); }
| DT_TOK_INT { $$ = dt_node_pdesc_by_id($1); }
;
! statement_list_impl: /* empty */ { $$ = NULL; }
! | statement_list_impl statement { $$ = LINK($1, $2); }
;
! statement_list:
! statement_list_impl { $$ = $1; }
! | statement_list_impl expression {
! $$ = LINK($1, dt_node_statement($2));
! }
;
+ statement_or_block:
+ statement
+ | '{' statement_list '}' { $$ = $2; }
+
+ statement: ';' { $$ = NULL; }
+ | expression ';' { $$ = dt_node_statement($1); }
+ | DT_KEY_IF DT_TOK_LPAR expression DT_TOK_RPAR statement_or_block {
+ $$ = dt_node_if($3, $5, NULL);
+ }
+ | DT_KEY_IF DT_TOK_LPAR expression DT_TOK_RPAR
+ statement_or_block DT_KEY_ELSE statement_or_block {
+ $$ = dt_node_if($3, $5, $7);
+ }
+ ;
+
argument_expression_list:
assignment_expression
| argument_expression_list DT_TOK_COMMA assignment_expression {
$$ = LINK($1, $3);
}