1 #ifndef STAN_LANG_AST_FUN_VAR_OCCURS_VIS_HPP
2 #define STAN_LANG_AST_FUN_VAR_OCCURS_VIS_HPP
3 
4 #include <boost/variant/static_visitor.hpp>
5 #include <string>
6 
7 namespace stan {
8   namespace lang {
9 
10     struct nil;
11     struct int_literal;
12     struct double_literal;
13     struct array_expr;
14     struct matrix_expr;
15     struct row_vector_expr;
16     struct variable;
17     struct fun;
18     struct integrate_1d;
19     struct integrate_ode;
20     struct integrate_ode_control;
21     struct algebra_solver;
22     struct algebra_solver_control;
23     struct map_rect;
24     struct index_op;
25     struct index_op_sliced;
26     struct conditional_op;
27     struct binary_op;
28     struct unary_op;
29 
30     struct var_occurs_vis : public boost::static_visitor<bool> {
31       /**
32        * Construct a visitor to detect whether the specified variable
33        * occurs in a statement.
34        *
35        * @param e variable to detect
36        */
37       explicit var_occurs_vis(const variable& e);
38 
39       /**
40        * Return true if the variable occurs in the specified
41        * expression.
42        *
43        * @param[in] e expression
44        * @return false
45        */
46       bool operator()(const nil& e) const;
47 
48       /**
49        * Return true if the variable occurs in the specified
50        * expression.
51        *
52        * @param[in] e expression
53        * @return false
54        */
55       bool operator()(const int_literal& e) const;
56 
57       /**
58        * Return true if the variable occurs in the specified
59        * expression.
60        *
61        * @param[in] e expression
62        * @return false
63        */
64       bool operator()(const double_literal& e) const;
65 
66       /**
67        * Return true if the variable occurs in the specified
68        * expression.
69        *
70        * @param[in] e expression
71        * @return true if the variable occurs in any of the array
72        * expression elements
73        */
74       bool operator()(const array_expr& e) const;
75 
76       /**
77        * Return true if the variable occurs in the specified
78        * expression.
79        *
80        * @param[in] e expression
81        * @return true if the variable occurs in any of the matrix
82        * expression elements
83        */
84       bool operator()(const matrix_expr& e) const;
85 
86       /**
87        * Return true if the variable occurs in the specified
88        * expression.
89        *
90        * @param[in] e expression
91        * @return true if the variable occurs in any of the row_vector
92        * expression elements
93        */
94       bool operator()(const row_vector_expr& e) const;
95 
96       /**
97        * Return true if the variable occurs in the specified
98        * expression.
99        *
100        * @param[in] e expression
101        * @return true if variable is equal to the specifed variable
102        */
103       bool operator()(const variable& e) const;
104 
105       /**
106        * Return true if the variable occurs in the specified
107        * expression.
108        *
109        * @param[in] e expression
110        * @return true if the variable occurs in the arguments
111        */
112       bool operator()(const fun& e) const;
113 
114       /**
115        * Return true if the variable occurs in the specified
116        * expression.
117        *
118        * @param[in] e expression
119        * @return true if the variable occurs in the arguments
120        */
121       bool operator()(const integrate_1d& e) const;
122 
123       /**
124        * Return true if the variable occurs in the specified
125        * expression.
126        *
127        * @param[in] e expression
128        * @return true if the variable occurs in the arguments
129        */
130       bool operator()(const integrate_ode& e) const;
131 
132       /**
133        * Return true if the variable occurs in the specified
134        * expression.
135        *
136        * @param[in] e expression
137        * @return true if the variable occurs in the arguments
138        */
139       bool operator()(const integrate_ode_control& e) const;
140 
141       /**
142        * Return true if the variable occurs in the specified
143        * expression.
144        *
145        * @param[in] e expression
146        * @return true if the variable occurs in the arguments
147        */
148       bool operator()(const algebra_solver& e) const;
149 
150       /**
151        * Return true if the variable occurs in the specified
152        * expression.
153        *
154        * @param[in] e expression
155        * @return true if the variable occurs in the arguments
156        */
157       bool operator()(const algebra_solver_control& e) const;
158 
159       /**
160        * Return true if the variable occurs in the specified
161        * expression.
162        *
163        * @param[in] e expression
164        * @return true if the variable occurs in the arguments
165        */
166       bool operator()(const map_rect& e) const;
167 
168       /**
169        * Return true if the variable occurs in the specified
170        * expression.
171        *
172        * @param[in] e expression
173        * @return true if the variable occurs in the variable being
174        * indexed or in any of the indexes
175        */
176       bool operator()(const index_op& e) const;
177 
178       /**
179        * Return true if the variable occurs in the specified
180        * expression.
181        *
182        * @param[in] e expression
183        * @return true if the variable occurs in the variable being
184        * indexed or in any of the indexes
185        */
186       bool operator()(const index_op_sliced& e) const;
187 
188       /**
189        * Return true if the variable occurs in the specified
190        * expression.
191        *
192        * @param[in] e expression
193        * @return true if the variable occurs in the conditional or
194        * result expressions
195        */
196       bool operator()(const conditional_op& e) const;
197 
198       /**
199        * Return true if the variable occurs in the specified
200        * expression.
201        *
202        * @param[in] e expression
203        * @return true if the variable occurs in either of the operands
204        */
205       bool operator()(const binary_op& e) const;
206 
207       /**
208        * Return true if the variable occurs in the specified
209        * expression.
210        *
211        * @param[in] e expression
212        * @return true if the variable occurs in the operand
213        */
214       bool operator()(const unary_op& e) const;
215 
216       /**
217        * The name of the variable for which to search.
218        */
219       const std::string var_name_;
220     };
221 
222   }
223 }
224 #endif
225