<commit_before>//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// version: $Id$
// author:  <NAME> <<EMAIL>>
//------------------------------------------------------------------------------

#ifndef CLING_TRANSACTION_H
#define CLING_TRANSACTION_H

#include "clang/AST/DeclGroup.h"

#include "llvm/ADT/SmallVector.h"

namespace clang {
  class Decl;
}

namespace cling {
  ///\brief Contains information about the consumed input at once.
  ///
  class Transaction {
  private:

    typedef llvm::SmallVector<clang::DeclGroupRef, 64> DeclQueue;
    typedef llvm::SmallVector<Transaction*, 2> NestedTransactions;

    ///\brief All seen declarations. If we collect the declarations by walking
    /// the clang::DeclContext we will miss the injected onces (eg. template 
    /// instantiations).
    ///
    DeclQueue m_DeclQueue;

    ///\brief Shows whether the transaction was commited or not.
    ///
    bool m_Completed;

    ///\brief The enclosing transaction if nested. 
    ///
    Transaction* m_Parent;

    ///\brief List of nested transactions if any.
    ///
    NestedTransactions m_NestedTransactions;

    unsigned m_State : 2;

    unsigned m_IssuedDiags : 2;

  public:

    Transaction() : m_Completed(false), m_Parent(0), m_State(kUnknown), 
                    m_IssuedDiags(kNone) {}

    ~Transaction();

    enum State {
      kUnknown,
      kRolledBack,
      kRolledBackWithErrors,
      kCommitted
    };

    enum IssuedDiags {
      kErrors,
      kWarnings,
      kNone
    };

    /// \{
    /// \name Iteration

    typedef DeclQueue::const_iterator const_iterator;
    typedef DeclQueue::const_reverse_iterator const_reverse_iterator;
    const_iterator decls_begin() const { return m_DeclQueue.begin(); }
    const_iterator decls_end() const { return m_DeclQueue.end(); }
    const_reverse_iterator rdecls_begin() const { return m_DeclQueue.rbegin(); }
    const_reverse_iterator rdecls_end() const { return m_DeclQueue.rend(); }

    typedef NestedTransactions::const_iterator const_nested_iterator;
    typedef NestedTransactions::const_reverse_iterator const_reverse_nested_iterator;
    const_nested_iterator nested_decls_begin() const {
      return m_NestedTransactions.begin();
    }
    const_nested_iterator nested_decls_end() const {
      return m_NestedTransactions.end();
    }
    const_reverse_nested_iterator rnested_decls_begin() const {
      return m_NestedTransactions.rbegin();
    }
    const_reverse_nested_iterator rnested_decls_end() const {
      return m_NestedTransactions.rend();
    }

    /// \}

    State getState() const { return static_cast<State>(m_State); }
    void setState(State val) { m_State = val; }

    IssuedDiags getIssuedDiags() const { 
      return static_cast<IssuedDiags>(m_IssuedDiags); 
    }
    void setIssuedDiags(IssuedDiags val) { m_IssuedDiags = val; }

    ///\brief Returns the first declaration of the transaction.
    ///
    clang::DeclGroupRef getFirstDecl() const {
      if (!empty())
        return m_DeclQueue.front();
      return clang::DeclGroupRef();
    }

    ///\brief Returns the last declaration of a completed transaction.
    ///
    clang::DeclGroupRef getLastDecl() const {
      if (!empty() && isCompleted())
        return m_DeclQueue.back();
      return clang::DeclGroupRef();
    }

    ///\brief Returns the current last transaction. Useful when the transaction
    /// in still incomplete.<commit_msg>Embed the compilation options in the transaction. By definition they are specific to a transaction.<commit_after>//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// version: $Id$
// author:  <NAME> <<EMAIL>>
//------------------------------------------------------------------------------

#ifndef CLING_TRANSACTION_H
#define CLING_TRANSACTION_H

#include "cling/Interpreter/CompilationOptions.h"

#include "clang/AST/DeclGroup.h"

#include "llvm/ADT/SmallVector.h"

namespace clang {
  class Decl;
}

namespace cling {
  ///\brief Contains information about the consumed input at once.
  ///
  class Transaction {
  private:

    typedef llvm::SmallVector<clang::DeclGroupRef, 64> DeclQueue;
    typedef llvm::SmallVector<Transaction*, 2> NestedTransactions;

    ///\brief All seen declarations. If we collect the declarations by walking
    /// the clang::DeclContext we will miss the injected onces (eg. template 
    /// instantiations).
    ///
    DeclQueue m_DeclQueue;

    ///\brief Shows whether the transaction was commited or not.
    ///
    bool m_Completed;

    ///\brief The enclosing transaction if nested. 
    ///
    Transaction* m_Parent;

    ///\brief List of nested transactions if any.
    ///
    NestedTransactions m_NestedTransactions;

    unsigned m_State : 2;

    unsigned m_IssuedDiags : 2;

    ///\brief Options controlling the transformers and code generator.
    ///
    CompilationOptions m_Opts;

  public:

    Transaction(const CompilationOptions& Opts) 
      : m_Completed(false), m_Parent(0), m_State(kUnknown), m_IssuedDiags(kNone),
        m_Opts(Opts)
    { }

    ~Transaction();

    enum State {
      kUnknown,
      kRolledBack,
      kRolledBackWithErrors,
      kCommitted
    };

    enum IssuedDiags {
      kErrors,
      kWarnings,
      kNone
    };

    /// \{
    /// \name Iteration

    typedef DeclQueue::const_iterator const_iterator;
    typedef DeclQueue::const_reverse_iterator const_reverse_iterator;
    const_iterator decls_begin() const { return m_DeclQueue.begin(); }
    const_iterator decls_end() const { return m_DeclQueue.end(); }
    const_reverse_iterator rdecls_begin() const { return m_DeclQueue.rbegin(); }
    const_reverse_iterator rdecls_end() const { return m_DeclQueue.rend(); }

    typedef NestedTransactions::const_iterator const_nested_iterator;
    typedef NestedTransactions::const_reverse_iterator const_reverse_nested_iterator;
    const_nested_iterator nested_decls_begin() const {
      return m_NestedTransactions.begin();
    }
    const_nested_iterator nested_decls_end() const {
      return m_NestedTransactions.end();
    }
    const_reverse_nested_iterator rnested_decls_begin() const {
      return m_NestedTransactions.rbegin();
    }
    const_reverse_nested_iterator rnested_decls_end() const {
      return m_NestedTransactions.rend();
    }

    /// \}

    State getState() const { return static_cast<State>(m_State); }
    void setState(State val) { m_State = val; }

    IssuedDiags getIssuedDiags() const { 
      return static_cast<IssuedDiags>(m_IssuedDiags); 
    }
    void setIssuedDiags(IssuedDiags val) { m_IssuedDiags = val; }

    const CompilationOptions& getCompilationOpts() const { return m_Opts; }

    ///\brief Returns the first declaration of the transaction.
    ///
    clang::DeclGroupRef getFirstDecl() const {
      if (!empty())
        return m_DeclQueue.front();
      return clang::DeclGroupRef();
    }

    ///\brief Returns the last declaration of a completed transaction.
    ///
    clang::DeclGroupRef getLastDecl() const {
      if (!empty() && isCompleted())
        return m_DeclQueue.back();
      return clang::DeclGroupRef();
    }

    ///\brief Returns the current last transaction. Useful when the transaction
    /// in still incomplete.
{'fraction_non_alphanumeric': 0.1389265383572784, 'fraction_numerical': 0.001626457034426674, 'mean_word_length': 2.638560157790927, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '7544614', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2097, 'n_words': 524}