<commit_before>#ifndef RDB_PROTOCOL_TERMS_SINDEX_HPP_
#define RDB_PROTOCOL_TERMS_SINDEX_HPP_

#include <string>

#include "rdb_protocol/error.hpp"
#include "rdb_protocol/op.hpp"
#include "rdb_protocol/pb_utils.hpp"

namespace ql {

class sindex_create_term_t : public env_t::special_var_shadower_t, public op_term_t {
public:
    sindex_create_term_t(env_t *env, const Term *term)
        : env_t::special_var_shadower_t(env, env_t::SINDEX_ERROR_VAR),
          op_term_t(env, term, argspec_t(2, 3)) { }

    virtual val_t *eval_impl() {
        table_t *table = arg(0)->as_table();
        const datum_t *name_datum = arg(1)->as_datum();
        std::string name = name_datum->as_str();
        rcheck(name != table->get_pkey(),
               strprintf("Index name conflict: `%s` is the name of the primary key.",
                         name.c_str()));
        func_t *index_func = NULL;
        if (num_args() == 3) {
            index_func = arg(2)->as_func();
        } else {
            env_wrapper_t<Term> *twrap = env->add_ptr(new env_wrapper_t<Term>());
            Term *func_term = &twrap->t;
            int x = env->gensym();
            Term *arg = pb::set_func(func_term, x);
            N2(GETATTR, NVAR(x), NDATUM(name_datum));
            prop_bt(func_term);<commit_msg>added comment and changed to private inheritance for special_var_shadower_t<commit_after>#ifndef RDB_PROTOCOL_TERMS_SINDEX_HPP_
#define RDB_PROTOCOL_TERMS_SINDEX_HPP_

#include <string>

#include "rdb_protocol/error.hpp"
#include "rdb_protocol/op.hpp"
#include "rdb_protocol/pb_utils.hpp"

namespace ql {

// We need to use inheritance rather than composition for
// `env_t::special_var_shadower_t` because it needs to be initialized before
// `op_term_t`.
class sindex_create_term_t : private env_t::special_var_shadower_t, public op_term_t {
public:
    sindex_create_term_t(env_t *env, const Term *term)
        : env_t::special_var_shadower_t(env, env_t::SINDEX_ERROR_VAR),
          op_term_t(env, term, argspec_t(2, 3)) { }

    virtual val_t *eval_impl() {
        table_t *table = arg(0)->as_table();
        const datum_t *name_datum = arg(1)->as_datum();
        std::string name = name_datum->as_str();
        rcheck(name != table->get_pkey(),
               strprintf("Index name conflict: `%s` is the name of the primary key.",
                         name.c_str()));
        func_t *index_func = NULL;
        if (num_args() == 3) {
            index_func = arg(2)->as_func();
        } else {
            env_wrapper_t<Term> *twrap = env->add_ptr(new env_wrapper_t<Term>());
            Term *func_term = &twrap->t;
            int x = env->gensym();
            Term *arg = pb::set_func(func_term, x);
            N2(GETATTR, NVAR(x), NDATUM(name_datum));
            prop_bt(func_term);
{'fraction_non_alphanumeric': 0.12696709585121602, 'fraction_numerical': 0.005007153075822604, 'mean_word_length': 2.9786628733997156, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7038392', 'n_tokens_mistral': 1003, 'n_tokens_neox': 994, 'n_words': 197}