1 #ifndef STAN_LANG_AST_BARE_EXPR_TYPE_HPP 2 #define STAN_LANG_AST_BARE_EXPR_TYPE_HPP 3 4 #include <stan/lang/ast/node/expression.hpp> 5 #include <boost/variant/recursive_variant.hpp> 6 #include <string> 7 #include <ostream> 8 #include <cstddef> 9 10 namespace stan { 11 namespace lang { 12 13 /** 14 * Bare type for Stan variables and expressions. 15 */ 16 struct bare_array_type; 17 struct double_type; 18 struct ill_formed_type; 19 struct int_type; 20 struct matrix_type; 21 struct row_vector_type; 22 struct vector_type; 23 struct void_type; 24 25 struct bare_expr_type { 26 /** 27 * Recursive wrapper for bare types. 28 */ 29 typedef boost::variant<boost::recursive_wrapper<ill_formed_type>, 30 boost::recursive_wrapper<double_type>, 31 boost::recursive_wrapper<int_type>, 32 boost::recursive_wrapper<matrix_type>, 33 boost::recursive_wrapper<row_vector_type>, 34 boost::recursive_wrapper<vector_type>, 35 boost::recursive_wrapper<void_type>, 36 boost::recursive_wrapper<bare_array_type> > 37 bare_t; 38 39 /** 40 * The bare type held by this wrapper. 41 */ 42 bare_t bare_type_; 43 44 /** 45 * Construct a bare var type with default values. 46 */ 47 bare_expr_type(); 48 49 /** 50 * Construct a bare var type with the specified variant type. 51 * 52 * @param type bare type raw variant type. 53 */ 54 bare_expr_type(const bare_expr_type& type); // NOLINT(runtime/explicit) 55 56 /** 57 * Construct a bare type with the specified type. 58 * 59 * @param type bare type 60 */ 61 bare_expr_type(const ill_formed_type& type); // NOLINT(runtime/explicit) 62 63 /** 64 * Construct a bare type with the specified type. 65 * 66 * @param type bare type 67 */ 68 bare_expr_type(const double_type& type); // NOLINT(runtime/explicit) 69 70 /** 71 * Construct a bare type with the specified type. 72 * 73 * @param type bare type 74 */ 75 bare_expr_type(const int_type& type); // NOLINT(runtime/explicit) 76 77 /** 78 * Construct a bare type with the specified type. 79 * 80 * @param type bare type 81 */ 82 bare_expr_type(const matrix_type& type); // NOLINT(runtime/explicit) 83 84 /** 85 * Construct a bare type with the specified type. 86 * 87 * @param type bare type 88 */ 89 bare_expr_type(const row_vector_type& type); // NOLINT(runtime/explicit) 90 91 /** 92 * Construct a bare type with the specified type. 93 * 94 * @param type bare type 95 */ 96 bare_expr_type(const vector_type& type); // NOLINT(runtime/explicit) 97 98 /** 99 * Construct a bare type with the specified type. 100 * 101 * @param type bare type 102 */ 103 bare_expr_type(const void_type& type); // NOLINT(runtime/explicit) 104 105 /** 106 * Construct a bare type with the specified type. 107 * 108 * @param type bare type 109 */ 110 bare_expr_type(const bare_array_type& type); // NOLINT(runtime/explicit) 111 112 /** 113 * Construct a bare type with the specified type. 114 * 115 * @param type bare type 116 */ 117 bare_expr_type(const bare_t& type); // NOLINT(runtime/explicit) 118 119 /** 120 * Return true if the specified bare type is the same as 121 * this bare type. 122 * 123 * @param bare_type Other bare type. 124 * @return result of equality test. 125 */ 126 bool operator==(const bare_expr_type& bare_type) const; 127 128 /** 129 * Return true if the specified bare type is not the same as 130 * this bare type. 131 * 132 * @param bare_type Other bare type. 133 * @return result of inequality test. 134 */ 135 bool operator!=(const bare_expr_type& bare_type) const; 136 137 /** 138 * Return true if this bare type `order_id_` 139 * is less than that of the specified bare type. 140 * 141 * @param bare_type Other bare type. 142 * @return result of comparison. 143 */ 144 bool operator<(const bare_expr_type& bare_type) const; 145 146 /** 147 * Return true if this bare type `order_id_` 148 * is less than or equal to that of the specified bare type. 149 * 150 * @param bare_type Other bare type. 151 * @return result of comparison. 152 */ 153 bool operator<=(const bare_expr_type& bare_type) const; 154 155 /** 156 * Return true if this bare type `order_id_` 157 * is greater than that of the specified bare type. 158 * 159 * @param bare_type Other bare type. 160 * @return result of comparison. 161 */ 162 bool operator>(const bare_expr_type& bare_type) const; 163 164 /** 165 * Return true if this bare type `order_id_` 166 * is greater than or equal to that of the specified bare type. 167 * 168 * @param bare_type Other bare type. 169 * @return result of comparison. 170 */ 171 bool operator>=(const bare_expr_type& bare_type) const; 172 173 /** 174 * Returns the element type for `bare_array_type`, otherwise 175 * will return `ill_formed_type`. 176 */ 177 bare_expr_type array_element_type() const; 178 179 /** 180 * If `bare_type` is `bare_array_type`, returns the innermost type 181 * contained in the array, otherwise will return `ill_formed_type`. 182 */ 183 bare_expr_type array_contains() const; 184 185 /** 186 * Returns number of array dimensions for this type. 187 * Returns 0 for non-array types. 188 */ 189 int array_dims() const; 190 191 /** 192 * If array type, returns bare_expr_type of innermost type, 193 * otherwise returns this type. 194 */ 195 bare_expr_type innermost_type() const; 196 197 /** 198 * Returns true if `bare_type_` is `bare_array_type`, false otherwise. 199 */ 200 bool is_array_type() const; 201 202 /** 203 * Returns value of `bare_type_` member var `is_data_`. 204 */ 205 bool is_data() const; 206 207 /** 208 * Returns true if `bare_type_` is `double_type`, false otherwise. 209 */ 210 bool is_double_type() const; 211 212 /** 213 * Returns true if `bare_type_` is `ill_formed_type`, false otherwise. 214 */ 215 bool is_ill_formed_type() const; 216 217 /** 218 * Returns true if `bare_type_` is `int_type`, false otherwise. 219 */ 220 bool is_int_type() const; 221 222 /** 223 * Returns true if `bare_type_` is `matrix_type`, false otherwise. 224 */ 225 bool is_matrix_type() const; 226 227 /** 228 * Returns true if `bare_type_` is `int_type` or `double_type`, false 229 * otherwise. 230 */ 231 bool is_primitive() const; 232 233 /** 234 * Returns true if `bare_type_` is `row_vector_type`, false otherwise. 235 */ 236 bool is_row_vector_type() const; 237 238 /** 239 * Returns true if `bare_type_` is `vector_type`, false otherwise. 240 */ 241 bool is_vector_type() const; 242 243 /** 244 * Returns true if `bare_type_` is `void_type`, false otherwise. 245 */ 246 bool is_void_type() const; 247 248 /** 249 * Returns total number of dimensions for container type. 250 * Returns 0 for scalar types. 251 */ 252 int num_dims() const; 253 254 /** 255 * Returns order id for this bare type. 256 */ 257 std::string order_id() const; 258 259 /** 260 * Set flag `is_data` to true 261 */ 262 void set_is_data(); 263 }; 264 265 /** 266 * Stream a user-readable version of the bare_expr_type to the 267 * specified output stream, returning the specified argument 268 * output stream to allow chaining. 269 * 270 * @param o output stream 271 * @param x expression type 272 * @return argument output stream 273 */ 274 std::ostream& operator<<(std::ostream& o, const bare_expr_type& x); 275 } // namespace lang 276 } // namespace stan 277 #endif 278