<commit_before>/*
  Copyright Kitware, 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 "Output.h"
#include "Options.h"
#include "Utils.h"

#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclOpenMP.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/Support/raw_ostream.h"

#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

//----------------------------------------------------------------------------
class ASTVisitorBase
{
protected:
  clang::CompilerInstance& CI;
  clang::ASTContext const& CTX;
  llvm::raw_ostream& OS;

  ASTVisitorBase(clang::CompilerInstance& ci,
                 clang::ASTContext const& ctx,
                 llvm::raw_ostream& os): CI(ci), CTX(ctx), OS(os) {}

  // Represent cv qualifier state of one dump node.
  struct DumpQual {
    bool IsConst = false;
    bool IsVolatile = false;
    bool IsRestrict = false;
    explicit operator bool() const {
      return this->IsConst || this->IsVolatile || this->IsRestrict;
    }
    friend bool operator < (DumpQual const& l, DumpQual const& r) {
      if (!l.IsConst && r.IsConst) {
        return true;
      } else if (l.IsConst && !r.IsConst) {
        return false;
      } else if (!l.IsVolatile && r.IsVolatile) {
        return true;
      } else if (l.IsVolatile && !r.IsVolatile) {
        return false;
      } else if (!l.IsRestrict && r.IsRestrict) {
        return true;
      } else if (l.IsRestrict && !r.IsRestrict) {
        return false;
      } else {
        return false;
      }
    }
    friend llvm::raw_ostream& operator << (llvm::raw_ostream& os,
                                           DumpQual const& dq) {
      return os << (dq.IsConst? "c":"")
                << (dq.IsVolatile? "v":"")
                << (dq.IsRestrict? "r":"");
    }
  };

  // Represent id of one dump node.
  struct DumpId {
    unsigned int Id = 0;
    DumpQual Qual;
    DumpId() {}
    DumpId(unsigned int id, DumpQual dq): Id(id), Qual(dq) {}
    explicit operator bool() const {
      return this->Id != 0;
    }
    friend bool operator < (DumpId const& l, DumpId const& r) {
      if (l.Id < r.Id) {
        return true;
      } else if (l.Id > r.Id) {
        return false;
      } else {
        return l.Qual < r.Qual;
      }
    }
    friend llvm::raw_ostream& operator << (llvm::raw_ostream& os,
                                           DumpId const& id) {
      return os << id.Id << id.Qual;
    }
  };

  // Record status of one AST node to be dumped.
  struct DumpNode {
    DumpNode(): Index(), Complete(false) {}

    // Index in nodes ordered by first encounter.
    DumpId Index;

    // Whether the node is to be traversed completely.
    bool Complete;
  };

  // Report all decl nodes as unimplemented until overridden.
#define ABSTRACT_DECL(DECL)
#define DECL(CLASS, BASE) \<commit_msg>Output: Fix compilation with VS 2012<commit_after>/*
  Copyright Kitware, 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 "Output.h"
#include "Options.h"
#include "Utils.h"

#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclOpenMP.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/Support/raw_ostream.h"

#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

//----------------------------------------------------------------------------
class ASTVisitorBase
{
protected:
  clang::CompilerInstance& CI;
  clang::ASTContext const& CTX;
  llvm::raw_ostream& OS;

  ASTVisitorBase(clang::CompilerInstance& ci,
                 clang::ASTContext const& ctx,
                 llvm::raw_ostream& os): CI(ci), CTX(ctx), OS(os) {}

  // Represent cv qualifier state of one dump node.
  struct DumpQual {
  private:
    typedef void (DumpQual::*bool_type)() const;
    void bool_true() const {}
  public:
    bool IsConst;
    bool IsVolatile;
    bool IsRestrict;
    DumpQual(): IsConst(false), IsVolatile(false), IsRestrict(false) {}
    operator bool_type() const {
      return (this->IsConst || this->IsVolatile || this->IsRestrict)?
        &DumpQual::bool_true : nullptr;
    }
    friend bool operator < (DumpQual const& l, DumpQual const& r) {
      if (!l.IsConst && r.IsConst) {
        return true;
      } else if (l.IsConst && !r.IsConst) {
        return false;
      } else if (!l.IsVolatile && r.IsVolatile) {
        return true;
      } else if (l.IsVolatile && !r.IsVolatile) {
        return false;
      } else if (!l.IsRestrict && r.IsRestrict) {
        return true;
      } else if (l.IsRestrict && !r.IsRestrict) {
        return false;
      } else {
        return false;
      }
    }
    friend llvm::raw_ostream& operator << (llvm::raw_ostream& os,
                                           DumpQual const& dq) {
      return os << (dq.IsConst? "c":"")
                << (dq.IsVolatile? "v":"")
                << (dq.IsRestrict? "r":"");
    }
  };

  // Represent id of one dump node.
  struct DumpId {
  private:
    typedef void (DumpId::*bool_type)() const;
    void bool_true() const {}
  public:
    unsigned int Id;
    DumpQual Qual;
    DumpId(): Id(0), Qual() {}
    DumpId(unsigned int id, DumpQual dq): Id(id), Qual(dq) {}
    operator bool_type() const {
      return this->Id != 0? &DumpId::bool_true : nullptr;
    }
    friend bool operator < (DumpId const& l, DumpId const& r) {
      if (l.Id < r.Id) {
        return true;
      } else if (l.Id > r.Id) {
        return false;
      } else {
        return l.Qual < r.Qual;
      }
    }
    friend llvm::raw_ostream& operator << (llvm::raw_ostream& os,
                                           DumpId const& id) {
      return os << id.Id << id.Qual;
    }
  };

  // Record status of one AST node to be dumped.
  struct DumpNode {
    DumpNode(): Index(), Complete(false) {}

    // Index in nodes ordered by first encounter.
    DumpId Index;

    // Whether the node is to be traversed completely.
    bool Complete;
  };

  // Report all decl nodes as unimplemented until overridden.
#define ABSTRACT_DECL(DECL)
#define DECL(CLASS, BASE) \
{'fraction_non_alphanumeric': 0.14195250659630607, 'fraction_numerical': 0.0021108179419525065, 'mean_word_length': 2.394984326018809, 'pattern_counts': {'":': 6, '<': 51, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7269830', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2368, 'n_words': 713}