generate_initializer.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_GENERATOR_GENERATE_INITIALIZER_HPP
2 #define STAN_LANG_GENERATOR_GENERATE_INITIALIZER_HPP
3 
4 #include <stan/lang/ast.hpp>
8 #include <ostream>
9 #include <string>
10 #include <vector>
11 
12 namespace stan {
13  namespace lang {
14 
15  /**
16  * Generate an initializer for a variable of the specified base
17  * type with the specified dimension sizes with an additional size
18  * for vectors and row vectors and two additional sizes for
19  * matrices.
20  *
21  * @param o stream for generating
22  * @param base_type base type of variable
23  * @param dims sizes of dimensions for variable
24  * @param type_arg1 size of vector or row vector or size of rows
25  * for matrix, not used otherwise
26  * @param type_arg2 size of columns for matrix, not used otherwise
27  */
28  void generate_initializer(std::ostream& o,
29  const std::string& base_type,
30  const std::vector<expression>& dims,
31  const expression& type_arg1 = expression(),
32  const expression& type_arg2 = expression()) {
33  for (size_t i = 0; i < dims.size(); ++i) {
34  o << '(';
35  generate_expression(dims[i].expr_, NOT_USER_FACING, o);
36  o << ',';
37  generate_type(base_type, dims, dims.size() - i - 1, o);
38  }
39 
40  o << '(';
41  if (!is_nil(type_arg1)) {
42  generate_eigen_index_expression(type_arg1, o);
43  if (!is_nil(type_arg2)) {
44  o << ',';
45  generate_eigen_index_expression(type_arg2, o);
46  }
47  } else if (!is_nil(type_arg2.expr_)) {
48  generate_eigen_index_expression(type_arg2, o);
49  } else {
50  o << '0';
51  }
52  o << ')';
53 
54  for (size_t i = 0; i < dims.size(); ++i)
55  o << ')';
56  o << ';' << EOL;
57  }
58 
59  }
60 }
61 #endif
bool is_nil(const expression &e)
Definition: is_nil_def.hpp:10
double lang
Definition: runWimpSim.h:113
const bool NOT_USER_FACING(false)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const std::string EOL("\n")
void generate_eigen_index_expression(const expression &e, std::ostream &o)
void generate_initializer(std::ostream &o, const std::string &base_type, const std::vector< expression > &dims, const expression &type_arg1=expression(), const expression &type_arg2=expression())
void generate_type(const std::string &base_type, const std::vector< expression > &, size_t end, std::ostream &o)
void generate_expression(const expression &e, bool user_facing, std::ostream &o)