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;
253 error_msgs <<
"available function signatures for "
254 << name <<
":" << std::endl;
255 for (
size_t i = 0; i < signatures.size(); ++i) {
256 error_msgs << i <<
". " << name <<
"(";
257 for (
size_t j = 0; j < signatures[i].second.size(); ++j) {
258 if (j > 0) error_msgs <<
", ";
259 error_msgs << signatures[i].second[j];
261 error_msgs <<
") : " << signatures[i].first << std::endl;
265 function_signatures::function_signatures() {
268 function_signatures* function_signatures::sigs_ = 0;
274 const std::vector<statement>& stmts)
275 : local_decl_(local_decl),
319 return boost::apply_visitor(vis,
expr_);
339 : printable_(printable) { }
341 : printable_(printable.printable_) { }
405 return boost::apply_visitor(ino,e.
expr_);
410 std::vector<expression>
const&
dims)
472 std::vector<expression>
const& args)
482 size_t total_dims(
const std::vector<std::vector<expression> >& dimss) {
484 for (
size_t i = 0; i < dimss.size(); ++i)
485 total += dimss[i].
size();
491 size_t num_expr_dims,
492 size_t num_index_dims) {
493 if (num_index_dims <= num_expr_dims)
494 return expr_type(expr_base_type,num_expr_dims - num_index_dims);
495 if (num_index_dims == (num_expr_dims + 1)) {
501 if (num_index_dims == (num_expr_dims + 2))
510 size_t num_index_dims) {
519 const std::vector<std::vector<expression> >& dimss)
530 const std::string& op,
536 right.expression_type())) {
565 o <<
"transformed data";
569 o <<
"transformed parameter";
571 o <<
"generated quantities";
575 o <<
"UNKNOWN ORIGIN";
581 : base_type_(base_type) {
584 const std::vector<expression>&
dims,
588 base_type_(base_type) {
592 return map_.find(name) !=
map_.end();
596 throw std::invalid_argument(
"variable does not exist");
597 return map_.find(name)->second.first;
600 return get(name).base_type_;
603 return get(name).dims_.size();
607 throw std::invalid_argument(
"variable does not exist");
608 return map_.find(name)->second.second;
624 std::string
const& name,
625 std::vector<expression>
const&
dims)
637 std::string
const& name,
638 std::vector<expression>
const&
dims)
648 std::string
const& name,
649 std::vector<expression>
const&
dims)
659 std::string
const& name,
660 std::vector<expression>
const&
dims)
670 std::string
const& name,
671 std::vector<expression>
const&
dims)
681 std::string
const& name,
682 std::vector<expression>
const&
dims)
691 std::string
const& name,
692 std::vector<expression>
const&
dims)
701 std::string
const& name,
702 std::vector<expression>
const&
dims)
712 std::string
const& name,
713 std::vector<expression>
const&
dims)
724 std::string
const& name,
725 std::vector<expression>
const&
dims)
732 std::string
const& name,
733 std::vector<expression>
const&
dims)
835 : variable_(variable),
844 : condition_(condition),
852 const std::vector<statement>& bodies)
853 : conditions_(conditions),
860 : printables_(printables) {
865 const std::pair<std::vector<var_decl>,
866 std::vector<statement> >& derived_data_decl,
867 const std::vector<var_decl>& parameter_decl,
868 const std::pair<std::vector<var_decl>,
869 std::vector<statement> >& derived_decl,
871 const std::pair<std::vector<var_decl>,
872 std::vector<statement> >& generated_decl)
873 : data_decl_(data_decl),
874 derived_data_decl_(derived_data_decl),
875 parameter_decl_(parameter_decl),
876 derived_decl_(derived_decl),
878 generated_decl_(generated_decl) {
902 : var_dims_(var_dims),