<commit_before>#include "rdb_protocol/term_walker.hpp"

#include "rdb_protocol/error.hpp"
#include "rdb_protocol/minidriver.hpp"
#include "rdb_protocol/pseudo_time.hpp"
#include "rdb_protocol/ql2.pb.h"
#include "rdb_protocol/ql2_extensions.pb.h"

namespace ql {

// We use this class to walk a term and do something to every node.
class term_walker_t {
public:
    // This constructor fills in the backtraces of a term (`walk`) and checks
    // that it's well-formed with regard to write placement.
    explicit term_walker_t(Term *root)
        : depth(0), writes_legal(true), bt(0), curtime(pseudo::time_now()) {
        walk(root, 0, head_frame);
    }

    // This constructor propagates a backtrace down a tree until it hits a node
    // that already has a backtrace (this is used for e.g. rewrite terms so that
    // they return reasonable backtraces in the macroexpanded nodes).
    term_walker_t(Term *root, const Backtrace *_bt)
        : depth(0), writes_legal(true), bt(_bt) {
        propwalk(root, 0, head_frame);
    }
    ~term_walker_t() {
        r_sanity_check(depth == 0);
        r_sanity_check(writes_legal == true);
    }

    void walk(Term *t, Term *parent, backtrace_t::frame_t frame) {
        r_sanity_check(!bt);

        val_pusher_t<int> depth_pusher(&depth, depth+1);
        add_bt(t, parent, frame);

        if (t->type() == Term::NOW && t->args_size() == 0) {
            *t = r::expr(*curtime.get()).get();
        }

        if (t->type() == Term::ASC || t->type() == Term::DESC) {
            rcheck_src(&t->GetExtension(ql2::extension::backtrace),<commit_msg>Construct timestamp only when used in term_walker_t<commit_after>#include "rdb_protocol/term_walker.hpp"

#include "rdb_protocol/error.hpp"
#include "rdb_protocol/minidriver.hpp"
#include "rdb_protocol/pseudo_time.hpp"
#include "rdb_protocol/ql2.pb.h"
#include "rdb_protocol/ql2_extensions.pb.h"

namespace ql {

// We use this class to walk a term and do something to every node.
class term_walker_t {
public:
    // This constructor fills in the backtraces of a term (`walk`) and checks
    // that it's well-formed with regard to write placement.
    explicit term_walker_t(Term *root)
        : depth(0), writes_legal(true), bt(0) {
        walk(root, 0, head_frame);
    }

    // This constructor propagates a backtrace down a tree until it hits a node
    // that already has a backtrace (this is used for e.g. rewrite terms so that
    // they return reasonable backtraces in the macroexpanded nodes).
    term_walker_t(Term *root, const Backtrace *_bt)
        : depth(0), writes_legal(true), bt(_bt) {
        propwalk(root, 0, head_frame);
    }
    ~term_walker_t() {
        r_sanity_check(depth == 0);
        r_sanity_check(writes_legal == true);
    }

    void walk(Term *t, Term *parent, backtrace_t::frame_t frame) {
        r_sanity_check(!bt);

        val_pusher_t<int> depth_pusher(&depth, depth+1);
        add_bt(t, parent, frame);

        if (t->type() == Term::NOW && t->args_size() == 0) {
            // Construct curtime the first time we access it
            if (!curtime.has()) {
                curtime = pseudo::time_now();
            }
            *t = r::expr(*curtime.get()).get();
        }

        if (t->type() == Term::ASC || t->type() == Term::DESC) {
            rcheck_src(&t->GetExtension(ql2::extension::backtrace),
{'fraction_non_alphanumeric': 0.13161021984551396, 'fraction_numerical': 0.006535947712418301, 'mean_word_length': 3.0035671819262784, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '3605553', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1102, 'n_words': 294}