1 #ifndef STAN_LANG_GRAMMARS_SEMANTIC_ACTIONS_HPP 2 #define STAN_LANG_GRAMMARS_SEMANTIC_ACTIONS_HPP 3 4 #include <boost/spirit/include/qi.hpp> 5 #include <boost/variant/recursive_variant.hpp> 6 #include <stan/io/program_reader.hpp> 7 #include <stan/lang/ast.hpp> 8 #include <stan/lang/grammars/iterator_typedefs.hpp> 9 #include <map> 10 #include <set> 11 #include <string> 12 #include <utility> 13 #include <vector> 14 15 namespace stan { 16 17 namespace lang { 18 19 bool has_prob_suffix(const std::string &s); 20 21 void replace_suffix(const std::string &old_suffix, 22 const std::string &new_suffix, fun &f); 23 24 void set_fun_type(fun &fun, std::ostream &error_msgs); 25 26 int num_dimss(std::vector<std::vector<stan::lang::expression>> &dimss); 27 28 /** 29 * This is the base class for unnary functors that are adapted to 30 * lazy semantic actions by boost::phoenix. The base class deals 31 * with the type dispatch required by Phoenix. 32 */ 33 struct phoenix_functor_unary { 34 /** 35 * Declare result to be a template struct. 36 */ 37 template <class> struct result; 38 39 /** 40 * Specialize as required by Phoenix to functional form 41 * with typedef of return type. 42 */ 43 template <typename F, typename T1> struct result<F(T1)> { 44 typedef void type; 45 }; 46 }; 47 48 /** 49 * This is the base class for binary functors that are adapted to 50 * lazy semantic actions by boost::phoenix. The base class deals 51 * with the type dispatch required by Phoenix. 52 */ 53 struct phoenix_functor_binary { 54 /** 55 * Declare result to be a template struct. 56 */ 57 template <class> struct result; 58 59 /** 60 * Specialize as required by Phoenix to functional form 61 * with typedef of return type. 62 */ 63 template <typename F, typename T1, typename T2> struct result<F(T1, T2)> { 64 typedef void type; 65 }; 66 }; 67 68 /** 69 * This is the base class for ternary functors that are adapted to 70 * lazy semantic actions by boost::phoenix. The base class deals 71 * with the type dispatch required by Phoenix. 72 */ 73 struct phoenix_functor_ternary { 74 /** 75 * Declare result to be a template struct. 76 */ 77 template <class> struct result; 78 79 /** 80 * Specialize as required by Phoenix to functional form 81 * with typedef of return type. 82 */ 83 template <typename F, typename T1, typename T2, typename T3> 84 struct result<F(T1, T2, T3)> { 85 typedef void type; 86 }; 87 }; 88 89 /** 90 * This is the base class for quatenary functors that are adapted 91 * to lazy semantic actions by boost::phoenix. The base class 92 * deals with the type dispatch required by Phoenix. 93 */ 94 struct phoenix_functor_quaternary { 95 /** 96 * Declare result to be a template struct. 97 */ 98 template <class> struct result; 99 100 /** 101 * Specialize as required by Phoenix to functional form 102 * with typedef of return type. 103 */ 104 template <typename F, typename T1, typename T2, typename T3, typename T4> 105 struct result<F(T1, T2, T3, T4)> { 106 typedef void type; 107 }; 108 }; 109 110 /** 111 * This is the base class for quinary functors that are adapted to 112 * lazy semantic actions by boost::phoenix. The base class deals 113 * with the type dispatch required by Phoenix. 114 */ 115 struct phoenix_functor_quinary { 116 /** 117 * Declare result to be a template struct. 118 */ 119 template <class> struct result; 120 121 /** 122 * Specialize as required by Phoenix to functional form 123 * with typedef of return type. 124 */ 125 template <typename F, typename T1, typename T2, typename T3, typename T4, 126 typename T5> 127 struct result<F(T1, T2, T3, T4, T5)> { 128 typedef void type; 129 }; 130 }; 131 132 /** 133 * This is the base class for senary functors that are adapted to 134 * lazy semantic actions by boost::phoenix. The base class deals 135 * with the type dispatch required by Phoenix. 136 */ 137 struct phoenix_functor_senary { 138 /** 139 * Declare result to be a template struct. 140 */ 141 template <class> struct result; 142 143 /** 144 * Specialize as required by Phoenix to functional form 145 * with typedef of return type. 146 */ 147 template <typename F, typename T1, typename T2, typename T3, typename T4, 148 typename T5, typename T6> 149 struct result<F(T1, T2, T3, T4, T5, T6)> { 150 typedef void type; 151 }; 152 }; 153 154 /** 155 * This is the base class for septenary functors that are adapted to 156 * lazy semantic actions by boost::phoenix. The base class deals 157 * with the type dispatch required by Phoenix. 158 */ 159 struct phoenix_functor_septenary { 160 /** 161 * Declare result to be a template struct. 162 */ 163 template <class> struct result; 164 165 /** 166 * Specialize as required by Phoenix to functional form 167 * with typedef of return type. 168 */ 169 template <typename F, typename T1, typename T2, typename T3, typename T4, 170 typename T5, typename T6, typename T7> 171 struct result<F(T1, T2, T3, T4, T5, T6, T7)> { 172 typedef void type; 173 }; 174 }; 175 176 struct assign_lhs : public phoenix_functor_binary { 177 template <typename L, typename R> void operator()(L &lhs, const R &rhs) const; 178 }; 179 extern boost::phoenix::function<assign_lhs> assign_lhs_f; 180 181 // called from: expression07_grammar 182 struct validate_expr_type3 : public phoenix_functor_ternary { 183 void operator()(const expression &expr, bool &pass, 184 std::ostream &error_msgs) const; 185 }; 186 extern boost::phoenix::function<validate_expr_type3> validate_expr_type3_f; 187 188 // called from: term_grammar 189 struct is_prob_fun : public phoenix_functor_binary { 190 void operator()(const std::string &s, bool &pass) const; 191 }; 192 extern boost::phoenix::function<is_prob_fun> is_prob_fun_f; 193 194 // called from: expression07_grammar 195 struct addition_expr3 : public phoenix_functor_ternary { 196 void operator()(expression &expr1, const expression &expr2, 197 std::ostream &error_msgs) const; 198 }; 199 extern boost::phoenix::function<addition_expr3> addition3_f; 200 201 // called from: expression07_grammar 202 struct subtraction_expr3 : public phoenix_functor_ternary { 203 void operator()(expression &expr1, const expression &expr2, 204 std::ostream &error_msgs) const; 205 }; 206 extern boost::phoenix::function<subtraction_expr3> subtraction3_f; 207 208 // called from bare_type_grammar 209 struct increment_size_t : public phoenix_functor_unary { 210 void operator()(size_t &lhs) const; 211 }; 212 extern boost::phoenix::function<increment_size_t> increment_size_t_f; 213 214 // called from: expression_grammar 215 struct validate_conditional_op : public phoenix_functor_quinary { 216 void operator()(conditional_op &cond_expr, const scope &var_scope, bool &pass, 217 const variable_map &var_map, std::ostream &error_msgs) const; 218 }; 219 extern boost::phoenix::function<validate_conditional_op> 220 validate_conditional_op_f; 221 222 // called from: expression_grammar 223 struct binary_op_expr : public phoenix_functor_quinary { 224 void operator()(expression &expr1, const expression &expr2, 225 const std::string &op, const std::string &fun_name, 226 std::ostream &error_msgs) const; 227 }; 228 extern boost::phoenix::function<binary_op_expr> binary_op_f; 229 230 // called from: functions_grammar 231 struct validate_non_void_arg_function : public phoenix_functor_quaternary { 232 void operator()(bare_expr_type &arg_type, const scope &var_scope, bool &pass, 233 std::ostream &error_msgs) const; 234 }; 235 extern boost::phoenix::function<validate_non_void_arg_function> 236 validate_non_void_arg_f; 237 238 // called from: functions_grammar 239 struct set_void_function : public phoenix_functor_quaternary { 240 void operator()(const bare_expr_type &return_type, scope &var_scope, 241 bool &pass, std::ostream &error_msgs) const; 242 }; 243 extern boost::phoenix::function<set_void_function> set_void_function_f; 244 245 // called from: functions_grammar 246 struct set_allows_sampling_origin : public phoenix_functor_binary { 247 void operator()(const std::string &identifier, scope &var_scope) const; 248 }; 249 extern boost::phoenix::function<set_allows_sampling_origin> 250 set_allows_sampling_origin_f; 251 252 // called from: functions_grammar 253 struct validate_declarations : public phoenix_functor_quinary { 254 void 255 operator()(bool &pass, 256 std::set<std::pair<std::string, function_signature_t>> &declared, 257 std::set<std::pair<std::string, function_signature_t>> &defined, 258 std::ostream &error_msgs, bool allow_undefined) const; 259 }; 260 extern boost::phoenix::function<validate_declarations> validate_declarations_f; 261 262 // called from: functions_grammar 263 struct add_function_signature : public phoenix_functor_quinary { 264 void operator()( 265 const function_decl_def &decl, bool &pass, 266 std::set<std::pair<std::string, function_signature_t>> 267 &functions_declared, 268 std::set<std::pair<std::string, function_signature_t>> &functions_defined, 269 std::ostream &error_msgs) const; 270 }; 271 extern boost::phoenix::function<add_function_signature> 272 add_function_signature_f; 273 274 // called from: functions_grammar 275 struct validate_return_type : public phoenix_functor_ternary { 276 void operator()(function_decl_def &decl, bool &pass, 277 std::ostream &error_msgs) const; 278 }; 279 extern boost::phoenix::function<validate_return_type> validate_return_type_f; 280 281 // called from: functions_grammar 282 struct validate_pmf_pdf_variate : public phoenix_functor_ternary { 283 void operator()(function_decl_def &decl, bool &pass, 284 std::ostream &error_msgs) const; 285 }; 286 extern boost::phoenix::function<validate_pmf_pdf_variate> 287 validate_pmf_pdf_variate_f; 288 289 // called from: functions_grammar 290 struct validate_prob_fun : public phoenix_functor_ternary { 291 void operator()(std::string &fname, bool &pass, 292 std::ostream &error_msgs) const; 293 }; 294 extern boost::phoenix::function<validate_prob_fun> validate_prob_fun_f; 295 296 // called from: functions_grammar 297 struct set_fun_params_scope : public phoenix_functor_binary { 298 void operator()(scope &var_scope, variable_map &vm) const; 299 }; 300 extern boost::phoenix::function<set_fun_params_scope> set_fun_params_scope_f; 301 302 // called from: functions_grammar 303 struct unscope_variables : public phoenix_functor_binary { 304 void operator()(function_decl_def &decl, variable_map &vm) const; 305 }; 306 extern boost::phoenix::function<unscope_variables> unscope_variables_f; 307 308 // called from: functions_grammar 309 struct add_fun_arg_var : public phoenix_functor_quinary { 310 void operator()(const var_decl &decl, const scope &scope, bool &pass, 311 variable_map &vm, std::ostream &error_msgs) const; 312 }; 313 extern boost::phoenix::function<add_fun_arg_var> add_fun_arg_var_f; 314 315 struct validate_fun_arg_var : public phoenix_functor_quinary { 316 void operator()(var_decl &var_decl_result, const bare_expr_type &bare_type, 317 const std::string &name, bool &pass, 318 std::ostream &error_msgs) const; 319 }; 320 extern boost::phoenix::function<validate_fun_arg_var> validate_fun_arg_var_f; 321 322 // called from: indexes_grammar 323 struct set_omni_idx : public phoenix_functor_unary { 324 void operator()(omni_idx &val) const; 325 }; 326 extern boost::phoenix::function<set_omni_idx> set_omni_idx_f; 327 328 // called from: indexes_grammar, statement_grammar 329 struct validate_int_expr_silent : public phoenix_functor_binary { 330 void operator()(const expression &e, bool &pass) const; 331 }; 332 extern boost::phoenix::function<validate_int_expr_silent> 333 validate_int_expr_silent_f; 334 335 // called from: indexes_grammar 336 struct validate_ints_expression : public phoenix_functor_ternary { 337 void operator()(const expression &e, bool &pass, 338 std::ostream &error_msgs) const; 339 }; 340 extern boost::phoenix::function<validate_ints_expression> 341 validate_ints_expression_f; 342 343 // called from: program_grammar 344 struct add_params_var : public phoenix_functor_unary { 345 void operator()(variable_map &vm) const; 346 }; 347 extern boost::phoenix::function<add_params_var> add_params_var_f; 348 349 // called from: program_grammar 350 struct remove_params_var : public phoenix_functor_unary { 351 void operator()(variable_map &vm) const; 352 }; 353 extern boost::phoenix::function<remove_params_var> remove_params_var_f; 354 355 // called from: program_grammar 356 struct program_error : public phoenix_functor_senary { 357 void operator()(pos_iterator_t _begin, pos_iterator_t _end, 358 pos_iterator_t _where, variable_map &vm, 359 std::stringstream &error_msgs, 360 const io::program_reader &reader) const; 361 }; 362 extern boost::phoenix::function<program_error> program_error_f; 363 364 // called from: statement_2_grammar 365 struct add_conditional_condition : public phoenix_functor_quaternary { 366 void operator()(conditional_statement &cs, const expression &e, bool &pass, 367 std::stringstream &error_msgs) const; 368 }; 369 extern boost::phoenix::function<add_conditional_condition> 370 add_conditional_condition_f; 371 372 // called from: statement_2_grammar 373 struct add_conditional_body : public phoenix_functor_binary { 374 void operator()(conditional_statement &cs, const statement &s) const; 375 }; 376 extern boost::phoenix::function<add_conditional_body> add_conditional_body_f; 377 378 // called from: statement_grammar 379 struct deprecate_old_assignment_op : public phoenix_functor_binary { 380 void operator()(std::string &op, std::ostream &error_msgs) const; 381 }; 382 extern boost::phoenix::function<deprecate_old_assignment_op> 383 deprecate_old_assignment_op_f; 384 385 // called from: statement_grammar 386 struct non_void_return_msg : public phoenix_functor_ternary { 387 void operator()(scope var_scope, bool &pass, std::ostream &error_msgs) const; 388 }; 389 extern boost::phoenix::function<non_void_return_msg> non_void_return_msg_f; 390 391 // called from: statement_grammar 392 struct validate_return_allowed : public phoenix_functor_ternary { 393 void operator()(scope var_scope, bool &pass, std::ostream &error_msgs) const; 394 }; 395 extern boost::phoenix::function<validate_return_allowed> 396 validate_return_allowed_f; 397 398 // called from: statement_grammar 399 struct validate_void_return_allowed : public phoenix_functor_ternary { 400 void operator()(scope var_scope, bool &pass, std::ostream &error_msgs) const; 401 }; 402 extern boost::phoenix::function<validate_void_return_allowed> 403 validate_void_return_allowed_f; 404 405 // called from: statement_grammar 406 struct set_lhs_var_assgn : public phoenix_functor_quaternary { 407 void operator()(assgn &a, const std::string &name, bool &pass, 408 const variable_map &vm) const; 409 }; 410 extern boost::phoenix::function<set_lhs_var_assgn> set_lhs_var_assgn_f; 411 412 // called from: statement_grammar 413 struct validate_lhs_var_assgn : public phoenix_functor_quinary { 414 void operator()(assgn &a, const scope &var_scope, bool &pass, 415 const variable_map &vm, std::ostream &error_msgs) const; 416 }; 417 extern boost::phoenix::function<validate_lhs_var_assgn> 418 validate_lhs_var_assgn_f; 419 420 // called from: statement_grammar 421 struct validate_assgn : public phoenix_functor_quaternary { 422 void operator()(assgn &a, bool &pass, const variable_map &vm, 423 std::ostream &error_msgs) const; 424 }; 425 extern boost::phoenix::function<validate_assgn> validate_assgn_f; 426 427 // called from: statement_grammar 428 struct validate_sample : public phoenix_functor_quaternary { 429 void operator()(sample &s, const variable_map &var_map, bool &pass, 430 std::ostream &error_msgs) const; 431 }; 432 extern boost::phoenix::function<validate_sample> validate_sample_f; 433 434 // called from: statement_grammar 435 struct expression_as_statement : public phoenix_functor_ternary { 436 void operator()(bool &pass, const stan::lang::expression &expr, 437 std::stringstream &error_msgs) const; 438 }; 439 extern boost::phoenix::function<expression_as_statement> 440 expression_as_statement_f; 441 442 // called from: statement_grammar 443 struct unscope_locals : public phoenix_functor_binary { 444 void operator()(const std::vector<local_var_decl> &var_decls, 445 variable_map &vm) const; 446 }; 447 extern boost::phoenix::function<unscope_locals> unscope_locals_f; 448 449 // called from: statement_grammar 450 struct add_while_condition : public phoenix_functor_quaternary { 451 void operator()(while_statement &ws, const expression &e, bool &pass, 452 std::stringstream &error_msgs) const; 453 }; 454 extern boost::phoenix::function<add_while_condition> add_while_condition_f; 455 456 // called from: statement_grammar 457 struct add_while_body : public phoenix_functor_binary { 458 void operator()(while_statement &ws, const statement &s) const; 459 }; 460 extern boost::phoenix::function<add_while_body> add_while_body_f; 461 462 // called from: statement_grammar 463 struct add_loop_identifier : public phoenix_functor_ternary { 464 void operator()(const std::string &name, const scope &var_scope, 465 variable_map &vm) const; 466 }; 467 extern boost::phoenix::function<add_loop_identifier> add_loop_identifier_f; 468 469 // called from: statement_grammar 470 struct add_array_loop_identifier : public phoenix_functor_quinary { 471 void operator()(const stan::lang::expression &expr, std::string &name, 472 const scope &var_scope, bool &pass, variable_map &vm) const; 473 }; 474 extern boost::phoenix::function<add_array_loop_identifier> 475 add_array_loop_identifier_f; 476 477 // called from: statement_grammar 478 struct add_matrix_loop_identifier : public phoenix_functor_senary { 479 void operator()(const stan::lang::expression &expr, std::string &name, 480 const scope &var_scope, bool &pass, variable_map &vm, 481 std::stringstream &error_msgs) const; 482 }; 483 extern boost::phoenix::function<add_matrix_loop_identifier> 484 add_matrix_loop_identifier_f; 485 486 // called from: statement_grammar 487 struct store_loop_identifier : public phoenix_functor_quinary { 488 void operator()(const std::string &name, std::string &name_local, bool &pass, 489 variable_map &vm, std::stringstream &error_msgs) const; 490 }; 491 extern boost::phoenix::function<store_loop_identifier> store_loop_identifier_f; 492 493 // called from: statement_grammar 494 struct remove_loop_identifier : public phoenix_functor_binary { 495 void operator()(const std::string &name, variable_map &vm) const; 496 }; 497 extern boost::phoenix::function<remove_loop_identifier> 498 remove_loop_identifier_f; 499 500 // called from: statement_grammar 501 struct deprecate_increment_log_prob : public phoenix_functor_unary { 502 void operator()(std::stringstream &error_msgs) const; 503 }; 504 extern boost::phoenix::function<deprecate_increment_log_prob> 505 deprecate_increment_log_prob_f; 506 507 // called from: statement_grammar 508 struct validate_allow_sample : public phoenix_functor_ternary { 509 void operator()(const scope &var_scope, bool &pass, 510 std::stringstream &error_msgs) const; 511 }; 512 extern boost::phoenix::function<validate_allow_sample> validate_allow_sample_f; 513 514 // called from: statement_grammar 515 struct validate_non_void_expression : public phoenix_functor_ternary { 516 void operator()(const expression &e, bool &pass, 517 std::ostream &error_msgs) const; 518 }; 519 extern boost::phoenix::function<validate_non_void_expression> 520 validate_non_void_expression_f; 521 522 // called from: statement_grammar 523 struct set_void_return : public phoenix_functor_unary { 524 void operator()(return_statement &s) const; 525 }; 526 extern boost::phoenix::function<set_void_return> set_void_return_f; 527 528 // called from: statement_grammar 529 struct set_no_op : public phoenix_functor_unary { 530 void operator()(no_op_statement &s) const; 531 }; 532 extern boost::phoenix::function<set_no_op> set_no_op_f; 533 534 // called from: term_grammar 535 struct deprecated_integrate_ode : phoenix_functor_unary { 536 void operator()(std::ostream &error_msgs) const; 537 }; 538 extern boost::phoenix::function<deprecated_integrate_ode> 539 deprecated_integrate_ode_f; 540 541 // test first arguments for both ode calling patterns 542 // (with/without control) 543 template <class T> 544 void validate_integrate_ode_non_control_args(const T &ode_fun, 545 const variable_map &var_map, 546 bool &pass, 547 std::ostream &error_msgs); 548 549 // called from: term_grammar 550 struct validate_integrate_ode : public phoenix_functor_quaternary { 551 void operator()(const integrate_ode &ode_fun, const variable_map &var_map, 552 bool &pass, std::ostream &error_msgs) const; 553 }; 554 extern boost::phoenix::function<validate_integrate_ode> 555 validate_integrate_ode_f; 556 557 // called from: term_grammar 558 struct validate_integrate_ode_control : public phoenix_functor_quaternary { 559 void operator()(const integrate_ode_control &ode_fun, 560 const variable_map &var_map, bool &pass, 561 std::ostream &error_msgs) const; 562 }; 563 extern boost::phoenix::function<validate_integrate_ode_control> 564 validate_integrate_ode_control_f; 565 566 // test first arguments for both algebra_solver calling patterns 567 // (with/without control) 568 template <class T> 569 void validate_algebra_solver_non_control_args(const T &alg_fun, 570 const variable_map &var_map, 571 bool &pass, 572 std::ostream &error_msgs); 573 574 // called from: term_grammar 575 struct validate_algebra_solver : public phoenix_functor_quaternary { 576 void operator()(const algebra_solver &alg_fun, const variable_map &var_map, 577 bool &pass, std::ostream &error_msgs) const; 578 }; 579 extern boost::phoenix::function<validate_algebra_solver> 580 validate_algebra_solver_f; 581 582 // called from: term_grammar 583 struct validate_algebra_solver_control : public phoenix_functor_quaternary { 584 void operator()(const algebra_solver_control &alg_fun, 585 const variable_map &var_map, bool &pass, 586 std::ostream &error_msgs) const; 587 }; 588 extern boost::phoenix::function<validate_algebra_solver_control> 589 validate_algebra_solver_control_f; 590 591 // called from: term_grammar 592 /** 593 * Functor for validating the arguments to map_rect. 594 */ 595 struct validate_map_rect : public phoenix_functor_quaternary { 596 /** 597 * Validate that the specified rectangular map object has 598 * appropriately typed arguments and assign it a unique 599 * identifier, setting the pass flag to false and writing an 600 * error message to the output stream if they don't. 601 * 602 * @param[in,out] mr structure to validate 603 * @param[in] var_map mapping for variables 604 * @param[in,out] pass reference to set to false upon failure 605 * @param[in,out] error_msgs reference to error message stream 606 * @throws std::illegal_argument_exception if the arguments are 607 * not of the appropriate shapes. 608 */ 609 void operator()(map_rect &mr, const variable_map &var_map, bool &pass, 610 std::ostream &error_msgs) const; 611 }; 612 /** 613 * Phoenix wrapper for the rectangular map structure validator. 614 */ 615 extern boost::phoenix::function<validate_map_rect> validate_map_rect_f; 616 617 // called from: term_grammar 618 /** 619 * Functor for validating the arguments to map_rect. 620 */ 621 struct validate_integrate_1d : public phoenix_functor_quaternary { 622 /** 623 * Validate that the specified 1d integration object has 624 * appropriately typed arguments with appropriate data-only 625 * requirements, setting the pass flag to false and writing an 626 * error message to the output stream if they don't. 627 * 628 * @param[in,out] fx structure to validate 629 * @param[in] var_map mapping for variables 630 * @param[in,out] pass reference to set to false upon failure 631 * @param[in,out] error_msgs reference to error message stream 632 * @throws std::illegal_argument_exception if the arguments are 633 * not of the appropriate shapes. 634 */ 635 void operator()(integrate_1d &fx, const variable_map &var_map, bool &pass, 636 std::ostream &error_msgs) const; 637 }; 638 /** 639 * Phoenix wrapper for the rectangular map structure validator. 640 */ 641 extern boost::phoenix::function<validate_integrate_1d> validate_integrate_1d_f; 642 643 // called from: term_grammar 644 struct set_fun_type_named : public phoenix_functor_senary { 645 void operator()(expression &fun_result, fun &fun, const scope &var_scope, 646 bool &pass, const variable_map &var_map, 647 std::ostream &error_msgs) const; 648 }; 649 extern boost::phoenix::function<set_fun_type_named> set_fun_type_named_f; 650 651 // called from: term_grammar 652 struct infer_array_expr_type : public phoenix_functor_senary { 653 void operator()(expression &e, array_expr &array_expr, const scope &var_scope, 654 bool &pass, const variable_map &var_map, 655 std::ostream &error_msgs) const; 656 }; 657 extern boost::phoenix::function<infer_array_expr_type> infer_array_expr_type_f; 658 659 // called from: term_grammar 660 struct infer_vec_or_matrix_expr_type : public phoenix_functor_senary { 661 void operator()(expression &e, row_vector_expr &vec_expr, 662 const scope &var_scope, bool &pass, 663 const variable_map &var_map, std::ostream &error_msgs) const; 664 }; 665 extern boost::phoenix::function<infer_vec_or_matrix_expr_type> 666 infer_vec_or_matrix_expr_type_f; 667 668 // called from: term_grammar 669 struct exponentiation_expr : public phoenix_functor_quinary { 670 void operator()(expression &expr1, const expression &expr2, 671 const scope &var_scope, bool &pass, 672 std::ostream &error_msgs) const; 673 }; 674 extern boost::phoenix::function<exponentiation_expr> exponentiation_f; 675 676 // called from: term_grammar 677 struct multiplication_expr : public phoenix_functor_ternary { 678 void operator()(expression &expr1, const expression &expr2, 679 std::ostream &error_msgs) const; 680 }; 681 extern boost::phoenix::function<multiplication_expr> multiplication_f; 682 683 // called from: term_grammar 684 struct division_expr : public phoenix_functor_ternary { 685 void operator()(expression &expr1, const expression &expr2, 686 std::ostream &error_msgs) const; 687 }; 688 extern boost::phoenix::function<division_expr> division_f; 689 690 // called from: term_grammar 691 struct modulus_expr : public phoenix_functor_quaternary { 692 void operator()(expression &expr1, const expression &expr2, bool &pass, 693 std::ostream &error_msgs) const; 694 }; 695 extern boost::phoenix::function<modulus_expr> modulus_f; 696 697 // called from: term_grammar 698 struct left_division_expr : public phoenix_functor_quaternary { 699 void operator()(expression &expr1, bool &pass, const expression &expr2, 700 std::ostream &error_msgs) const; 701 }; 702 extern boost::phoenix::function<left_division_expr> left_division_f; 703 704 // called from: term_grammar 705 struct elt_multiplication_expr : public phoenix_functor_ternary { 706 void operator()(expression &expr1, const expression &expr2, 707 std::ostream &error_msgs) const; 708 }; 709 extern boost::phoenix::function<elt_multiplication_expr> elt_multiplication_f; 710 711 // called from: term_grammar 712 struct elt_division_expr : public phoenix_functor_ternary { 713 void operator()(expression &expr1, const expression &expr2, 714 std::ostream &error_msgs) const; 715 }; 716 extern boost::phoenix::function<elt_division_expr> elt_division_f; 717 718 // called from: term_grammar 719 struct negate_expr : public phoenix_functor_quaternary { 720 void operator()(expression &expr_result, const expression &expr, bool &pass, 721 std::ostream &error_msgs) const; 722 }; 723 extern boost::phoenix::function<negate_expr> negate_expr_f; 724 725 // called from: term_grammar 726 struct logical_negate_expr : public phoenix_functor_ternary { 727 void operator()(expression &expr_result, const expression &expr, 728 std::ostream &error_msgs) const; 729 }; 730 extern boost::phoenix::function<logical_negate_expr> logical_negate_expr_f; 731 732 // called from: term_grammar 733 struct transpose_expr : public phoenix_functor_ternary { 734 void operator()(expression &expr, bool &pass, std::ostream &error_msgs) const; 735 }; 736 extern boost::phoenix::function<transpose_expr> transpose_f; 737 738 // called from: term_grammar 739 struct add_idxs : public phoenix_functor_quaternary { 740 void operator()(expression &e, std::vector<idx> &idxs, bool &pass, 741 std::ostream &error_msgs) const; 742 }; 743 extern boost::phoenix::function<add_idxs> add_idxs_f; 744 745 // called from: term_grammar 746 struct add_expression_dimss : public phoenix_functor_quaternary { 747 void operator()(expression &expression, 748 std::vector<std::vector<stan::lang::expression>> &dimss, 749 bool &pass, std::ostream &error_msgs) const; 750 }; 751 extern boost::phoenix::function<add_expression_dimss> add_expression_dimss_f; 752 753 // called from: term_grammar 754 struct set_var_type : public phoenix_functor_quinary { 755 void operator()(variable &var_expr, expression &val, variable_map &vm, 756 std::ostream &error_msgs, bool &pass) const; 757 }; 758 extern boost::phoenix::function<set_var_type> set_var_type_f; 759 760 struct require_vbar : public phoenix_functor_binary { 761 void operator()(bool &pass, std::ostream &error_msgs) const; 762 }; 763 extern boost::phoenix::function<require_vbar> require_vbar_f; 764 765 struct data_only_expression : public boost::static_visitor<bool> { 766 std::stringstream &error_msgs_; 767 variable_map &var_map_; 768 data_only_expression(std::stringstream &error_msgs, variable_map &var_map); 769 bool operator()(const nil & /*e*/) const; 770 bool operator()(const int_literal & /*x*/) const; 771 bool operator()(const double_literal & /*x*/) const; 772 bool operator()(const array_expr &x) const; 773 bool operator()(const matrix_expr &x) const; 774 bool operator()(const row_vector_expr &x) const; 775 bool operator()(const variable &x) const; 776 bool operator()(const integrate_1d &x) const; 777 bool operator()(const integrate_ode &x) const; 778 bool operator()(const integrate_ode_control &x) const; 779 bool operator()(const algebra_solver &x) const; 780 bool operator()(const algebra_solver_control &x) const; 781 bool operator()(const map_rect &x) const; 782 bool operator()(const fun &x) const; 783 bool operator()(const index_op &x) const; 784 bool operator()(const index_op_sliced &x) const; 785 bool operator()(const conditional_op &x) const; 786 bool operator()(const binary_op &x) const; 787 bool operator()(const unary_op &x) const; 788 }; 789 790 struct add_line_number : public phoenix_functor_ternary { 791 template <typename T, typename I> 792 void operator()(T &line, const I &begin, const I &end) const; 793 }; 794 extern boost::phoenix::function<add_line_number> add_line_number_f; 795 796 struct add_literal_string : public phoenix_functor_ternary { 797 void operator()(double_literal &lit, const pos_iterator_t &begin, 798 const pos_iterator_t &end) const; 799 }; 800 extern boost::phoenix::function<add_literal_string> add_literal_string_f; 801 802 struct validate_definition : public phoenix_functor_quaternary { 803 template <typename T> 804 void operator()(const scope &var_scope, const T &var_decl, bool &pass, 805 std::stringstream &error_msgs) const; 806 }; 807 extern boost::phoenix::function<validate_definition> validate_definition_f; 808 809 struct validate_identifier : public phoenix_functor_ternary { 810 std::set<std::string> reserved_word_set_; 811 std::set<std::string> const_fun_name_set_; 812 validate_identifier(); 813 void operator()(const std::string &identifier, bool &pass, 814 std::stringstream &error_msgs) const; 815 bool contains(const std::set<std::string> &s, const std::string &x) const; 816 bool identifier_exists(const std::string &identifier) const; 817 void reserve(const std::string &w); 818 }; 819 extern boost::phoenix::function<validate_identifier> validate_identifier_f; 820 821 // copies single dimension from M to N if only M declared 822 struct copy_square_cholesky_dimension_if_necessary 823 : public phoenix_functor_unary { 824 void operator()(cholesky_factor_cov_block_type &block_type) const; 825 }; 826 extern boost::phoenix::function<copy_square_cholesky_dimension_if_necessary> 827 copy_square_cholesky_dimension_if_necessary_f; 828 829 struct empty_range : public phoenix_functor_binary { 830 void operator()(range &r, std::stringstream & /*error_msgs*/) const; 831 }; 832 extern boost::phoenix::function<empty_range> empty_range_f; 833 834 struct empty_offset_multiplier : public phoenix_functor_binary { 835 void operator()(offset_multiplier &r, 836 std::stringstream & /*error_msgs*/) const; 837 }; 838 extern boost::phoenix::function<empty_offset_multiplier> 839 empty_offset_multiplier_f; 840 841 struct validate_int_expr : public phoenix_functor_ternary { 842 void operator()(const expression &expr, bool &pass, 843 std::stringstream &error_msgs) const; 844 }; 845 extern boost::phoenix::function<validate_int_expr> validate_int_expr_f; 846 847 struct set_int_range_lower : public phoenix_functor_quaternary { 848 void operator()(range &range, const expression &expr, bool &pass, 849 std::stringstream &error_msgs) const; 850 }; 851 extern boost::phoenix::function<set_int_range_lower> set_int_range_lower_f; 852 853 struct set_int_range_upper : public phoenix_functor_quaternary { 854 void operator()(range &range, const expression &expr, bool &pass, 855 std::stringstream &error_msgs) const; 856 }; 857 extern boost::phoenix::function<set_int_range_upper> set_int_range_upper_f; 858 859 struct validate_int_data_only_expr : public phoenix_functor_quaternary { 860 void operator()(const expression &expr, bool &pass, variable_map &var_map, 861 std::stringstream &error_msgs) const; 862 }; 863 extern boost::phoenix::function<validate_int_data_only_expr> 864 validate_int_data_only_expr_f; 865 866 struct validate_double_expr : public phoenix_functor_ternary { 867 void operator()(const expression &expr, bool &pass, 868 std::stringstream &error_msgs) const; 869 }; 870 extern boost::phoenix::function<validate_double_expr> validate_double_expr_f; 871 872 struct set_double_range_lower : public phoenix_functor_quaternary { 873 void operator()(range &range, const expression &expr, bool &pass, 874 std::stringstream &error_msgs) const; 875 }; 876 extern boost::phoenix::function<set_double_range_lower> 877 set_double_range_lower_f; 878 879 struct set_double_range_upper : public phoenix_functor_quaternary { 880 void operator()(range &range, const expression &expr, bool &pass, 881 std::stringstream &error_msgs) const; 882 }; 883 extern boost::phoenix::function<set_double_range_upper> 884 set_double_range_upper_f; 885 886 struct set_double_offset_multiplier_loc : public phoenix_functor_quaternary { 887 void operator()(offset_multiplier &offset_multiplier, const expression &expr, 888 bool &pass, std::stringstream &error_msgs) const; 889 }; 890 extern boost::phoenix::function<set_double_offset_multiplier_loc> 891 set_double_offset_multiplier_offset_f; 892 893 struct set_double_offset_multiplier_multiplier 894 : public phoenix_functor_quaternary { 895 void operator()(offset_multiplier &offset_multiplier, const expression &expr, 896 bool &pass, std::stringstream &error_msgs) const; 897 }; 898 extern boost::phoenix::function<set_double_offset_multiplier_multiplier> 899 set_double_offset_multiplier_multiplier_f; 900 901 struct validate_bare_type : public phoenix_functor_quinary { 902 void operator()(bare_expr_type &bare_type_result, 903 const bare_expr_type &el_type, const size_t &num_dims, 904 bool &pass, std::ostream &error_msgs) const; 905 }; 906 extern boost::phoenix::function<validate_bare_type> validate_bare_type_f; 907 908 struct validate_array_block_var_decl : public phoenix_functor_septenary { 909 void operator()(block_var_decl &var_decl_result, 910 const block_var_type &el_type, const std::string &name, 911 const std::vector<expression> &dims, const expression &def, 912 bool &pass, std::ostream &error_msgs) const; 913 }; 914 extern boost::phoenix::function<validate_array_block_var_decl> 915 validate_array_block_var_decl_f; 916 917 struct validate_array_local_var_decl : public phoenix_functor_septenary { 918 void operator()(local_var_decl &var_decl_result, 919 const local_var_type &el_type, const std::string &name, 920 const std::vector<expression> &dims, const expression &def, 921 bool &pass, std::ostream &error_msgs) const; 922 }; 923 extern boost::phoenix::function<validate_array_local_var_decl> 924 validate_array_local_var_decl_f; 925 926 struct validate_single_block_var_decl : public phoenix_functor_ternary { 927 void operator()(const block_var_decl &var_decl_result, bool &pass, 928 std::ostream &error_msgs) const; 929 }; 930 extern boost::phoenix::function<validate_single_block_var_decl> 931 validate_single_block_var_decl_f; 932 933 struct validate_single_local_var_decl : public phoenix_functor_ternary { 934 void operator()(const local_var_decl &var_decl_result, bool &pass, 935 std::ostream &error_msgs) const; 936 }; 937 extern boost::phoenix::function<validate_single_local_var_decl> 938 validate_single_local_var_decl_f; 939 940 struct add_to_var_map : public phoenix_functor_quinary { 941 template <typename T> 942 void operator()(const T &decl, variable_map &vm, bool &pass, 943 const scope &var_scope, std::ostream &error_msgs) const; 944 }; 945 extern boost::phoenix::function<add_to_var_map> add_to_var_map_f; 946 947 struct validate_in_loop : public phoenix_functor_ternary { 948 void operator()(bool in_loop, bool &pass, std::ostream &error_msgs) const; 949 }; 950 extern boost::phoenix::function<validate_in_loop> validate_in_loop_f; 951 952 struct non_void_expression : public phoenix_functor_ternary { 953 void operator()(const expression &e, bool &pass, 954 std::ostream &error_msgs) const; 955 }; 956 extern boost::phoenix::function<non_void_expression> non_void_expression_f; 957 958 struct set_var_scope : public phoenix_functor_binary { 959 void operator()(scope &var_scope, const origin_block &program_block) const; 960 }; 961 extern boost::phoenix::function<set_var_scope> set_var_scope_f; 962 963 struct set_data_origin : public phoenix_functor_unary { 964 void operator()(scope &var_scope) const; 965 }; 966 extern boost::phoenix::function<set_data_origin> set_data_origin_f; 967 968 struct set_var_scope_local : public phoenix_functor_binary { 969 void operator()(scope &var_scope, const origin_block &program_block) const; 970 }; 971 extern boost::phoenix::function<set_var_scope_local> set_var_scope_local_f; 972 973 struct reset_var_scope : public phoenix_functor_binary { 974 void operator()(scope &var_scope, const scope &scope_enclosing) const; 975 }; 976 extern boost::phoenix::function<reset_var_scope> reset_var_scope_f; 977 978 // handle trace messages as needed for debugging 979 struct trace : public phoenix_functor_unary { 980 void operator()(const std::string &msg) const; 981 }; 982 extern boost::phoenix::function<trace> trace_f; 983 984 // handle trace messages as needed for debugging 985 struct trace_pass : public phoenix_functor_binary { 986 void operator()(const std::string &msg, const bool &pass) const; 987 }; 988 extern boost::phoenix::function<trace_pass> trace_pass_f; 989 990 // called from: whitespace_grammar 991 struct deprecate_pound_comment : public phoenix_functor_unary { 992 void operator()(std::ostream &error_msgs) const; 993 }; 994 extern boost::phoenix::function<deprecate_pound_comment> 995 deprecate_pound_comment_f; 996 997 } // namespace lang 998 } // namespace stan 999 #endif 1000