<commit_before>//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
// author:  <NAME> <<EMAIL>>
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------

#include "cling/Interpreter/Transaction.h"

#include "cling/Utils/AST.h"
#include "IncrementalExecutor.h"

#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Sema.h"

#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"

using namespace clang;

namespace cling {

  Transaction::Transaction(Sema& S) : m_Sema(S) {
    Initialize(S);
  }

  Transaction::Transaction(const CompilationOptions& Opts, Sema& S)
    : m_Sema(S) {
    Initialize(S);
    m_Opts = Opts; // intentional copy.
  }

  void Transaction::Initialize(Sema& S) {
    m_NestedTransactions.reset(0);
    m_Parent = 0;
    m_State = kCollecting;
    m_IssuedDiags = kNone;
    m_Opts = CompilationOptions();
    m_Module = 0;
    m_ExeUnload = {(void*)(size_t)-1};
    m_WrapperFD = 0;
    m_Next = 0;
    //m_Sema = S;
    m_BufferFID = FileID(); // sets it to invalid.
    m_Exe = 0;
  }

  Transaction::~Transaction() {
    if (hasNestedTransactions())
      for (size_t i = 0; i < m_NestedTransactions->size(); ++i) {
        assert(((*m_NestedTransactions)[i]->getState() == kCommitted
                || (*m_NestedTransactions)[i]->getState() == kRolledBack)
               && "All nested transactions must be committed!");
        delete (*m_NestedTransactions)[i];
      }
  }

  NamedDecl* Transaction::containsNamedDecl(llvm::StringRef name) const {
    for (auto I = decls_begin(), E = decls_end(); I < E; ++I) {
      for (auto DI : I->m_DGR) {
        if (NamedDecl* ND = dyn_cast<NamedDecl>(DI)) {
          if (name.equals(ND->getNameAsString()))
            return ND;
        }
        else if (LinkageSpecDecl* LSD = dyn_cast<LinkageSpecDecl>(DI)) {
          for (Decl* DI : LSD->decls()) {
            if (NamedDecl* ND = dyn_cast<NamedDecl>(DI)) {
              if (name.equals(ND->getNameAsString()))
                return ND;
            }
          }
        }
      }
    }
    return 0;
  }

  void Transaction::addNestedTransaction(Transaction* nested) {
    // Create lazily the list
    if (!m_NestedTransactions)
      m_NestedTransactions.reset(new NestedTransactions());
<commit_msg>Peek inside extern "C" declarations only after name hasn't been matched. Change initial for loop use != comparison rather than <<commit_after>//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
// author:  <NAME> <<EMAIL>>
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------

#include "cling/Interpreter/Transaction.h"

#include "cling/Utils/AST.h"
#include "IncrementalExecutor.h"

#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Sema.h"

#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"

using namespace clang;

namespace cling {

  Transaction::Transaction(Sema& S) : m_Sema(S) {
    Initialize(S);
  }

  Transaction::Transaction(const CompilationOptions& Opts, Sema& S)
    : m_Sema(S) {
    Initialize(S);
    m_Opts = Opts; // intentional copy.
  }

  void Transaction::Initialize(Sema& S) {
    m_NestedTransactions.reset(0);
    m_Parent = 0;
    m_State = kCollecting;
    m_IssuedDiags = kNone;
    m_Opts = CompilationOptions();
    m_Module = 0;
    m_ExeUnload = {(void*)(size_t)-1};
    m_WrapperFD = 0;
    m_Next = 0;
    //m_Sema = S;
    m_BufferFID = FileID(); // sets it to invalid.
    m_Exe = 0;
  }

  Transaction::~Transaction() {
    if (hasNestedTransactions())
      for (size_t i = 0; i < m_NestedTransactions->size(); ++i) {
        assert(((*m_NestedTransactions)[i]->getState() == kCommitted
                || (*m_NestedTransactions)[i]->getState() == kRolledBack)
               && "All nested transactions must be committed!");
        delete (*m_NestedTransactions)[i];
      }
  }

  NamedDecl* Transaction::containsNamedDecl(llvm::StringRef name) const {
    for (auto I = decls_begin(), E = decls_end(); I != E; ++I) {
      for (auto DI : I->m_DGR) {
        if (NamedDecl* ND = dyn_cast<NamedDecl>(DI)) {
          if (name.equals(ND->getNameAsString()))
            return ND;
        }
      }
    }
    // Not found yet, peek inside extern "C" declarations
    for (auto I = decls_begin(), E = decls_end(); I != E; ++I) {
      for (auto DI : I->m_DGR) {
        if (LinkageSpecDecl* LSD = dyn_cast<LinkageSpecDecl>(DI)) {
          for (Decl* DI : LSD->decls()) {
            if (NamedDecl* ND = dyn_cast<NamedDecl>(DI)) {
              if (name.equals(ND->getNameAsString()))
                return ND;
            }
          }
        }
      }
    }
    return nullptr;
  }

  void Transaction::addNestedTransaction(Transaction* nested) {
    // Create lazily the list
    if (!m_NestedTransactions)
      m_NestedTransactions.reset(new NestedTransactions());

{'fraction_non_alphanumeric': 0.1895910780669145, 'fraction_numerical': 0.0030093821915383252, 'mean_word_length': 2.319623971797885, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 30, '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': '5210415', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1803, 'n_words': 413}