<commit_before>/*
Copyright 2013-present Barefoot Networks, Inc. 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "ir.h"

namespace {
class IRDumper : public Inspector {
    std::ostream                &out;
    std::set<const IR::Node *>  dumped;
    unsigned                    maxdepth;
    cstring                     ignore;
    bool preorder(const IR::Node *n) override {
        if (auto ctxt = getContext()) {
            if (unsigned(ctxt->depth) > maxdepth)
                return false;
            if (ctxt->child_name && ignore == ctxt->child_name)
                return false;
            out << indent_t(ctxt->depth);
            if (ctxt->child_name)
                out << ctxt->child_name << ": "; }
        out << "[" << n->id << "] " << n->node_type_name();
        n->dump_fields(out);
        if (dumped.count(n)) {
            out << "..." << std::endl;
            return false; }
        dumped.insert(n);
        out << std::endl;
        return true; }
    void postorder(const IR::Node *n) override {
        if (getChildrenVisited() == 0)
            dumped.erase(n); }<commit_msg>fix dumping to print IR::Expression types<commit_after>/*
Copyright 2013-present Barefoot Networks, Inc. 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "ir.h"

namespace {
class IRDumper : public Inspector {
    std::ostream                &out;
    std::set<const IR::Node *>  dumped;
    unsigned                    maxdepth;
    cstring                     ignore;
    bool preorder(const IR::Node *n) override {
        if (auto ctxt = getContext()) {
            if (unsigned(ctxt->depth) > maxdepth)
                return false;
            if (ctxt->child_name && ignore == ctxt->child_name)
                return false;
            out << indent_t(ctxt->depth);
            if (ctxt->child_name)
                out << ctxt->child_name << ": "; }
        out << "[" << n->id << "] " << n->node_type_name();
        n->dump_fields(out);
        if (dumped.count(n)) {
            out << "..." << std::endl;
            return false; }
        dumped.insert(n);
        out << std::endl;
        return true; }
    bool preorder(const IR::Expression *e) override {
        if (!preorder(static_cast<const IR::Node *>(e))) return false;
        visit(e->type, "type");
        return true; }
    bool preorder(const IR::Constant *c) override {
        return preorder(static_cast<const IR::Node *>(c)); }
    void postorder(const IR::Node *n) override {
        if (getChildrenVisited() == 0)
            dumped.erase(n); }
{'fraction_non_alphanumeric': 0.1169457848424638, 'fraction_numerical': 0.00510928186204939, 'mean_word_length': 2.278139534883721, 'pattern_counts': {'":': 2, '<': 47, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7074689', 'n_tokens_mistral': 1003, 'n_tokens_neox': 971, 'n_words': 329}