<commit_before>#ifndef STAN_LANG_GENERATOR_EXPRESSION_VISGEN_HPP
#define STAN_LANG_GENERATOR_EXPRESSION_VISGEN_HPP

#include <stan/lang/ast.hpp>
#include <stan/lang/generator/generate_array_var_type.hpp>
#include <stan/lang/generator/generate_indexed_expr.hpp>
#include <stan/lang/generator/generate_real_var_type.hpp>
#include <stan/lang/generator/generate_type.hpp>
#include <stan/lang/generator/visgen.hpp>
#include <boost/lexical_cast.hpp>
#include <ostream>
#include <string>
#include <vector>

namespace stan {
  namespace lang {

    void generate_expression(const expression& e, bool user_facing,
                             bool is_var_context, std::ostream& o);

    void generate_idxs(const std::vector<idx>& idxs, std::ostream& o);

    void generate_idxs_user(const std::vector<idx>& idxs, std::ostream& o);

    struct expression_visgen : public visgen {
      explicit expression_visgen(std::ostream& o, bool user_facing,
                                 bool is_var_context)
        : visgen(o),
          user_facing_(user_facing),
          is_var_context_(is_var_context) {
      }

      void operator()(const nil& /*x*/) const {
        o_ << "nil";
      }

      void operator()(const int_literal& n) const { o_ << n.val_; }

      void operator()(const double_literal& x) const {
        std::string num_str = boost::lexical_cast<std::string>(x.val_);
        o_ << num_str;
        if (num_str.find_first_of("eE.") == std::string::npos)
          o_ << ".0";  // trailing 0 to ensure C++ makes it a double
      }

      void operator()(const array_expr& x) const {
        std::stringstream ssRealType;
        generate_real_var_type(x.array_expr_scope_, x.has_var_,
                               is_var_context_, ssRealType);
        std::stringstream ssArrayType;
        generate_array_var_type(x.type_.base_type_, ssRealType.str(),
                                is_var_context_, ssArrayType);
        o_ << "static_cast<";
        generate_type(ssArrayType.str(), x.args_, x.type_.num_dims_, o_);
        o_ << " >(";
        o_ << "stan::math::array_builder<";
        generate_type(ssArrayType.str(),
                      x.args_,
                      x.type_.num_dims_ - 1,
                      o_);
        o_ << " >()";
        for (size_t i = 0; i < x.args_.size(); ++i) {
          o_ << ".add(";
          generate_expression(x.args_[i], user_facing_, is_var_context_, o_);
          o_ << ")";
        }
        o_ << ".array()";
        o_ << ")";
      }

      void operator()(const matrix_expr& x) const {
        std::stringstream ssRealType;
        generate_real_var_type(x.matrix_expr_scope_, x.has_var_,
                               is_var_context_, ssRealType);
        o_ << "stan::math::to_vector(stan::math::array_builder<std::vector<";
        generate_type(ssRealType.str(), x.args_, 0, o_);
        o_ << " > >()";
        for (size_t i = 0; i < x.args_.size(); ++i) {
          o_ << ".add(";
          generate_expression(x.args_[i], user_facing_, is_var_context_, o_);
          o_ << ")";
        }
        o_ << ".array()";<commit_msg>checkpointing<commit_after>#ifndef STAN_LANG_GENERATOR_EXPRESSION_VISGEN_HPP
#define STAN_LANG_GENERATOR_EXPRESSION_VISGEN_HPP

#include <stan/lang/ast.hpp>
#include <stan/lang/generator/generate_array_var_type.hpp>
#include <stan/lang/generator/generate_indexed_expr.hpp>
#include <stan/lang/generator/generate_real_var_type.hpp>
#include <stan/lang/generator/generate_type.hpp>
#include <stan/lang/generator/visgen.hpp>
#include <boost/lexical_cast.hpp>
#include <ostream>
#include <string>
#include <vector>

namespace stan {
  namespace lang {

    void generate_expression(const expression& e, bool user_facing,
                             bool is_var_context, std::ostream& o);

    void generate_idxs(const std::vector<idx>& idxs, std::ostream& o);

    void generate_idxs_user(const std::vector<idx>& idxs, std::ostream& o);

    struct expression_visgen : public visgen {
      explicit expression_visgen(std::ostream& o, bool user_facing,
                                 bool is_var_context)
        : visgen(o),
          user_facing_(user_facing),
          is_var_context_(is_var_context) {
      }

      void operator()(const nil& /*x*/) const {
        o_ << "nil";
      }

      void operator()(const int_literal& n) const { o_ << n.val_; }

      void operator()(const double_literal& x) const {
        std::string num_str = boost::lexical_cast<std::string>(x.val_);
        o_ << num_str;
        if (num_str.find_first_of("eE.") == std::string::npos)
          o_ << ".0";  // trailing 0 to ensure C++ makes it a double
      }

      void operator()(const array_expr& x) const {
        std::stringstream ssRealType;
        generate_real_var_type(x.array_expr_scope_, x.has_var_,
                               is_var_context_, ssRealType);
        std::stringstream ssArrayType;
        generate_array_var_type(x.type_.base_type_, ssRealType.str(),
                                is_var_context_, ssArrayType);
        o_ << "static_cast<";
        generate_type(ssArrayType.str(), x.args_, x.type_.num_dims_, o_);
        o_ << " >(";
        o_ << "stan::math::array_builder<";
        generate_type(ssArrayType.str(),
                      x.args_,
                      x.type_.num_dims_ - 1,
                      o_);
        o_ << " >()";
        for (size_t i = 0; i < x.args_.size(); ++i) {
          o_ << ".add(";
          generate_expression(x.args_[i], user_facing_, is_var_context_, o_);
          o_ << ")";
        }
        o_ << ".array()";
        o_ << ")";
      }

      void operator()(const matrix_expr& x) const {
        std::stringstream ssRealType;
        generate_real_var_type(x.matrix_expr_scope_, x.has_var_,
                               is_var_context_, ssRealType);
        o_ << "stan::math::to_matrix(stan::math::array_builder<std::vector<";
        generate_type(ssRealType.str(), x.args_, 0, o_);
        o_ << "> >()";
        for (size_t i = 0; i < x.args_.size(); ++i) {
          o_ << ".add(";
          generate_expression(x.args_[i], user_facing_, is_var_context_, o_);
          o_ << ")";
        }
        o_ << ".array()";
{'fraction_non_alphanumeric': 0.13726437892701787, 'fraction_numerical': 0.0019333011116481392, 'mean_word_length': 2.377584330794342, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6978106', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1983, 'n_words': 369}