Stan  2.14.0
probability, sampling & optimization
has_var_vis_def.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_AST_FUN_HAS_VAR_VIS_DEF_HPP
2 #define STAN_LANG_AST_FUN_HAS_VAR_VIS_DEF_HPP
3 
4 #include <stan/lang/ast.hpp>
5 
6 namespace stan {
7  namespace lang {
8 
10  : var_map_(var_map) {
11  }
12 
13  bool has_var_vis::operator()(const nil& e) const {
14  return false;
15  }
16 
17  bool has_var_vis::operator()(const int_literal& e) const {
18  return false;
19  }
20 
21  bool has_var_vis::operator()(const double_literal& e) const {
22  return false;
23  }
24 
25  bool has_var_vis::operator()(const array_expr& e) const {
26  for (size_t i = 0; i < e.args_.size(); ++i)
27  if (boost::apply_visitor(*this, e.args_[i].expr_))
28  return true;
29  return false;
30  }
31 
32  bool has_var_vis::operator()(const variable& e) const {
34  return vo == parameter_origin
36  || (vo == local_origin && e.type_.base_type_ != INT_T);
37  }
38 
39  bool has_var_vis::operator()(const fun& e) const {
40  for (size_t i = 0; i < e.args_.size(); ++i)
41  if (boost::apply_visitor(*this, e.args_[i].expr_))
42  return true;
43  return false;
44  }
45 
46  bool has_var_vis::operator()(const integrate_ode& e) const {
47  // only init state and params may contain vars
48  return boost::apply_visitor(*this, e.y0_.expr_)
49  || boost::apply_visitor(*this, e.theta_.expr_);
50  }
51 
53  // only init state and params may contain vars
54  return boost::apply_visitor(*this, e.y0_.expr_)
55  || boost::apply_visitor(*this, e.theta_.expr_);
56  }
57 
58  bool has_var_vis::operator()(const index_op& e) const {
59  return boost::apply_visitor(*this, e.expr_.expr_);
60  }
61 
63  return boost::apply_visitor(*this, e.expr_.expr_);
64  }
65 
66  bool has_var_vis::operator()(const conditional_op& e) const {
67  return boost::apply_visitor(*this, e.cond_.expr_)
68  || boost::apply_visitor(*this, e.true_val_.expr_)
69  || boost::apply_visitor(*this, e.false_val_.expr_);
70  }
71 
72  bool has_var_vis::operator()(const binary_op& e) const {
73  return boost::apply_visitor(*this, e.left.expr_)
74  || boost::apply_visitor(*this, e.right.expr_);
75  }
76 
77  bool has_var_vis::operator()(const unary_op& e) const {
78  return boost::apply_visitor(*this, e.subject.expr_);
79  }
80 
81  }
82 }
83 #endif
std::string name_
Name of variable.
Definition: variable.hpp:18
std::vector< expression > args_
Sequence of expressions for array values.
Definition: array_expr.hpp:21
Node for holding a double literal.
const int parameter_origin
The origin of the variable is the parameter block.
Definition: var_origin.hpp:32
has_var_vis(const variable_map &var_map)
Construct a non-data variable detection visitor.
Probability, optimization and sampling library.
expression y0_
Initial state (array of real).
Structure to hold an array expression.
Definition: array_expr.hpp:17
Structure for an indexed expression.
Definition: index_op.hpp:14
std::vector< expression > args_
Sequence of argument expressions for function.
Definition: fun.hpp:32
Structure for function application.
Definition: fun.hpp:17
const int transformed_parameter_origin
The origin of the variable is the transformed parameter block.
Definition: var_origin.hpp:37
expression expr_
Expression being indexed.
Definition: index_op.hpp:18
expression y0_
Initial state.
A map from function names to their base declarations and their origin.
Structure for integrate diff eq statement.
expr_type type_
Type of variable.
Definition: variable.hpp:23
expression cond_
Condition (integer).
expression true_val_
Return value if condition is true.
expression left
First argument.
Definition: binary_op.hpp:24
var_origin get_origin(const std::string &name) const
Return the origin of the variable declaration for the variable with the specified name...
expression theta_
Parameters.
int var_origin
The type of a variable indicating where a variable was declared.
Definition: var_origin.hpp:12
base_expr_type base_type_
The base expression type.
Definition: expr_type.hpp:18
const int INT_T
Integer type.
AST structure for holding an expression with a sequence of indexes.
bool operator()(const nil &e) const
Return true if the specified expression contains a non-data variable.
Structure for the conditional operator.
Structure to hold a variable.
Definition: variable.hpp:14
expression right
Second argument.
Definition: binary_op.hpp:29
expression subject
Argument.
Definition: unary_op.hpp:23
const int local_origin
The origin of the variable is as a local variable.
Definition: var_origin.hpp:47
const variable_map & var_map_
Reference to the global variable declaration mapping.
expression theta_
Parameters (array of real).
AST structure for unary operations consisting of an operation and argument.
Definition: unary_op.hpp:14
Node for storing binary operations consisting of an operation and left and right arguments.
Definition: binary_op.hpp:15
The nil structure used as a placeholder for undefined or empty values in several structures.
Definition: nil.hpp:11
expression false_val_
Return value if condition is false.
Structure for a diff eq integration statement with control parameters for the integrator.
expression expr_
Expression being indexed.

     [ Stan Home Page ] © 2011–2016, Stan Development Team.