1 #ifndef __STAN__GM__AST_DEF_HPP__
2 #define __STAN__GM__AST_DEF_HPP__
4 #include <boost/variant/apply_visitor.hpp>
5 #include <boost/variant/recursive_variant.hpp>
55 : base_type_(base_type),
60 : base_type_(base_type),
68 return !(*
this == et);
120 const std::vector<expr_type>& arg_types) {
126 std::vector<expr_type> arg_types;
127 add(name,result_type,arg_types);
132 std::vector<expr_type> arg_types;
133 arg_types.push_back(arg_type);
134 add(name,result_type,arg_types);
140 std::vector<expr_type> arg_types;
141 arg_types.push_back(arg_type1);
142 arg_types.push_back(arg_type2);
143 add(name,result_type,arg_types);
150 std::vector<expr_type> arg_types;
151 arg_types.push_back(arg_type1);
152 arg_types.push_back(arg_type2);
153 arg_types.push_back(arg_type3);
154 add(name,result_type,arg_types);
162 std::vector<expr_type> arg_types;
163 arg_types.push_back(arg_type1);
164 arg_types.push_back(arg_type2);
165 arg_types.push_back(arg_type3);
166 arg_types.push_back(arg_type4);
167 add(name,result_type,arg_types);
176 std::vector<expr_type> arg_types;
177 arg_types.push_back(arg_type1);
178 arg_types.push_back(arg_type2);
179 arg_types.push_back(arg_type3);
180 arg_types.push_back(arg_type4);
181 arg_types.push_back(arg_type5);
182 add(name,result_type,arg_types);
200 const std::vector<expr_type>& call_args,
201 const std::vector<expr_type>& sig_args) {
202 if (call_args.size() != sig_args.size()) {
206 for (
size_t i = 0; i < call_args.size(); ++i) {
207 if (call_args[i] == sig_args[i]) {
209 }
else if (call_args[i].is_primitive_int()
210 && sig_args[i].is_primitive_double()) {
219 const std::string& name,
220 const std::vector<expr_type>& args,
221 std::ostream& error_msgs) {
222 std::vector<function_signature_t> signatures = sigs_map_[name];
223 size_t match_index = 0;
225 size_t num_matches = 0;
227 for (
size_t i = 0; i < signatures.size(); ++i) {
229 if (promotions < 0)
continue;
230 size_t promotions_ui =
static_cast<size_t>(promotions);
231 if (promotions_ui < min_promotions) {
232 min_promotions = promotions_ui;
235 }
else if (promotions_ui == min_promotions) {
240 if (num_matches == 1) {
241 return signatures[match_index].first;
242 }
else if (num_matches == 0) {
243 error_msgs <<
"no matches for function name=\"" << name <<
"\""
246 error_msgs << num_matches <<
" matches with "
247 << min_promotions <<
" integer promotions "
248 <<
"for function name=\"" << name <<
"\"" << std::endl;
250 for (
size_t i = 0; i < args.size(); ++i)
251 error_msgs <<
" arg " << i <<
" type=" << args[i] << std::endl;
254 function_signatures::function_signatures() {
257 function_signatures* function_signatures::sigs_ = 0;
263 const std::vector<statement>& stmts)
264 : local_decl_(local_decl),
305 return boost::apply_visitor(vis,
expr_);
324 : printable_(printable) { }
326 : printable_(printable.printable_) { }
342 return boost::apply_visitor(ino,e.
expr_);
347 std::vector<expression>
const& dims)
395 std::vector<expression>
const& args)
405 size_t total_dims(
const std::vector<std::vector<expression> >& dimss) {
407 for (
size_t i = 0; i < dimss.size(); ++i)
408 total += dimss[i].size();
414 size_t num_expr_dims,
415 size_t num_index_dims) {
416 if (num_index_dims <= num_expr_dims)
417 return expr_type(expr_base_type,num_expr_dims - num_index_dims);
418 if (num_index_dims == (num_expr_dims + 1)) {
424 if (num_index_dims == (num_expr_dims + 2))
433 size_t num_index_dims) {
442 const std::vector<std::vector<expression> >& dimss)
459 right.expression_type())) {
488 o <<
"transformed data";
492 o <<
"transformed parameter";
498 o <<
"UNKNOWN ORIGIN";
504 : base_type_(base_type) {
507 const std::vector<expression>& dims,
511 base_type_(base_type) {
515 return map_.find(name) !=
map_.end();
519 throw std::invalid_argument(
"variable does not exist");
520 return map_.find(name)->second.first;
523 return get(name).base_type_;
526 return get(name).dims_.size();
530 throw std::invalid_argument(
"variable does not exist");
531 return map_.find(name)->second.second;
547 std::string
const& name,
548 std::vector<expression>
const& dims)
560 std::string
const& name,
561 std::vector<expression>
const& dims)
571 std::string
const& name,
572 std::vector<expression>
const& dims)
582 std::string
const& name,
583 std::vector<expression>
const& dims)
593 std::string
const& name,
594 std::vector<expression>
const& dims)
603 std::string
const& name,
604 std::vector<expression>
const& dims)
613 std::string
const& name,
614 std::vector<expression>
const& dims)
624 std::string
const& name,
625 std::vector<expression>
const& dims)
636 std::string
const& name,
637 std::vector<expression>
const& dims)
644 std::string
const& name,
645 std::vector<expression>
const& dims)
740 : variable_(variable),
748 : printables_(printables) {
753 const std::pair<std::vector<var_decl>,
754 std::vector<statement> >& derived_data_decl,
755 const std::vector<var_decl>& parameter_decl,
756 const std::pair<std::vector<var_decl>,
757 std::vector<statement> >& derived_decl,
759 const std::pair<std::vector<var_decl>,
760 std::vector<statement> >& generated_decl)
761 : data_decl_(data_decl),
762 derived_data_decl_(derived_data_decl),
763 parameter_decl_(parameter_decl),
764 derived_decl_(derived_decl),
766 generated_decl_(generated_decl) {
790 : var_dims_(var_dims),