Stan  2.14.0
probability, sampling & optimization
var_occurs_vis_def.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_AST_FUN_VAR_OCCURS_VIS_DEF_HPP
2 #define STAN_LANG_AST_FUN_VAR_OCCURS_VIS_DEF_HPP
3 
4 #include <stan/lang/ast.hpp>
5 
6 namespace stan {
7  namespace lang {
8 
10  : var_name_(e.name_) {
11  }
12 
13  bool var_occurs_vis::operator()(const nil& st) const {
14  return false;
15  }
16 
17  bool var_occurs_vis::operator()(const int_literal& e) const {
18  return false;
19  }
20 
22  return false;
23  }
24 
25  bool var_occurs_vis::operator()(const array_expr& e) const {
26  return false; // TODO(carpenter): update for array_expr
27  }
28 
29  bool var_occurs_vis::operator()(const variable& e) const {
30  return var_name_ == e.name_;
31  }
32 
33  bool var_occurs_vis::operator()(const fun& e) const {
34  for (size_t i = 0; i < e.args_.size(); ++i)
35  if (boost::apply_visitor(*this, e.args_[i].expr_))
36  return true;
37  return false;
38  }
39 
41  return false; // no refs persist out of integrate_ode() call
42  }
43 
45  return false; // no refs persist out of integrate_ode_control() call
46  }
47 
48  bool var_occurs_vis::operator()(const index_op& e) const {
49  // refs only persist out of expression, not indexes
50  return boost::apply_visitor(*this, e.expr_.expr_);
51  }
52 
54  return boost::apply_visitor(*this, e.expr_.expr_);
55  }
56 
58  return boost::apply_visitor(*this, e.cond_.expr_)
59  || boost::apply_visitor(*this, e.true_val_.expr_)
60  || boost::apply_visitor(*this, e.false_val_.expr_);
61  }
62 
63  bool var_occurs_vis::operator()(const binary_op& e) const {
64  return boost::apply_visitor(*this, e.left.expr_)
65  || boost::apply_visitor(*this, e.right.expr_);
66  }
67 
68  bool var_occurs_vis::operator()(const unary_op& e) const {
69  return boost::apply_visitor(*this, e.subject.expr_);
70  }
71 
72  }
73 }
74 #endif
var_occurs_vis(const variable &e)
Construct a visitor to detect whether the specified variable occurs in a statement.
std::string name_
Name of variable.
Definition: variable.hpp:18
Node for holding a double literal.
Probability, optimization and sampling library.
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
expression expr_
Expression being indexed.
Definition: index_op.hpp:18
Structure for integrate diff eq statement.
bool operator()(const nil &e) const
Return true if the variable occurs in the specified expression.
expression cond_
Condition (integer).
expression true_val_
Return value if condition is true.
expression left
First argument.
Definition: binary_op.hpp:24
const std::string var_name_
The name of the variable for which to search.
AST structure for holding an expression with a sequence of indexes.
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
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.