<commit_before>//
// Copyright (c) 2014-2015 <NAME> (<EMAIL>)
// This file is distributed under the MIT License. See LICENSE for details.
//

#include "chauffeur/Chauffeur.h"
#include "chauffeur/DriverType.h"
#include "chauffeur/FindEntryPointsVisitor.h"
#include "clang/AST/ASTContext.h"

namespace chauffeur
{
  using namespace std;

  bool FindEntryPointsVisitor::VisitVarDecl(VarDecl* varDecl)
  {
    if (!varDecl->getType()->isRecordType())
    {
      if (varDecl->getNameAsString() == "_whoop_init")
      {
        ImplicitCastExpr *implExpr = cast<ImplicitCastExpr>(varDecl->getInit());
        if (implExpr == NULL)
        {
          return true;
        }

        ImplicitCastExpr *implExpr2 = cast<ImplicitCastExpr>(implExpr->getSubExpr());
        DeclRefExpr *declExpr = cast<DeclRefExpr>(implExpr2->getSubExpr());
        DI->getInstance().AddEntryPointPair("whoop_driver_ops", "probe",
          declExpr->getFoundDecl()->getNameAsString());
        DI->getInstance().SetInitFunction(declExpr->getFoundDecl()->getNameAsString());
      }
      else if (varDecl->getNameAsString() == "_whoop_exit")
      {
        ImplicitCastExpr *implExpr = cast<ImplicitCastExpr>(varDecl->getInit());
        if (implExpr == NULL)
        {
          return true;
        }

        DeclRefExpr *declExpr = cast<DeclRefExpr>(implExpr->getSubExpr());

        list<string> func_params;
        func_params.push_back("void");
        DI->getInstance().AddEntryPoint(declExpr->getFoundDecl()->getNameAsString(), func_params);

        DI->getInstance().AddEntryPointPair("whoop_driver_ops", "remove",
          declExpr->getFoundDecl()->getNameAsString());
      }

      return true;
    }

    RecordDecl *baseRecDecl = varDecl->getType()->getAs<RecordType>()->getDecl();

    if (!DI->IsDriverModule(baseRecDecl->getNameAsString()))
    {
      return true;
    }

    if (baseRecDecl->getNameAsString() == "file_operations")
      DI->getInstance().SetType(CHAR_DRIVER);
    else if (baseRecDecl->getNameAsString() == "block_device_operations")
      DI->getInstance().SetType(BLOCK_DRIVER);
    else if (baseRecDecl->getNameAsString() == "net_device_ops")
      DI->getInstance().SetType(NETWORK_DRIVER);
    else if (baseRecDecl->getNameAsString() == "test_driver")
      DI->getInstance().SetType(TEST_DRIVER);

    if (varDecl->getInit() == NULL)
    {
      return true;
    }
    
    InitListExpr *initListExpr = cast<InitListExpr>(varDecl->getInit())->getSyntacticForm();

    for (auto range = initListExpr->children(); range; ++range)
    {
      DesignatedInitExpr *desExpr = cast<DesignatedInitExpr>(*range);
      if (desExpr->size() != 1) continue;

      string funcname;

      if (/* pci_driver */
          desExpr->getDesignator(0)->getFieldName()->getName() == "probe" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "remove" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "shutdown" ||
          /* file_operations */
          desExpr->getDesignator(0)->getFieldName()->getName() == "llseek" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "write" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "read" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ioctl" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "unlocked_ioctl" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "poll" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "open" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "release" ||
          /* block_device_operations */
          desExpr->getDesignator(0)->getFieldName()->getName() == "getgeo" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "revalidate_disk" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "media_changed" ||
          /* dev_pm_ops */
          desExpr->getDesignator(0)->getFieldName()->getName() == "suspend" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "resume" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "freeze" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "thaw" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "poweroff" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "restore" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "runtime_suspend" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "runtime_resume" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "runtime_idle" ||
          /* net_device_ops */
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_open" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_stop" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_get_stats64" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_start_xmit" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_tx_timeout" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_validate_addr" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_change_mtu" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_fix_features" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_set_features" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_set_mac_address" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_do_ioctl" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_set_rx_mode" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_poll_controller" ||
          /* ethtool_ops */
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_drvinfo" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_regs_len" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_link" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_settings" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "set_settings" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_msglevel" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "set_msglevel" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_regs" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_wol" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "set_wol" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_strings" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_sset_count" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_ethtool_stats" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_ts_info" ||
          /* test_driver */
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep1" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep2" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep3" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep4" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep5")
        funcname = desExpr->getDesignator(0)->getFieldName()->getName();
      else
        continue;
      llvm::errs() << "test 2" << "\n";
      Expr *expr = cast<ImplicitCastExpr>(desExpr->getInit())->getSubExpr();
      while (!isa<DeclRefExpr>(expr))
        expr = cast<ImplicitCastExpr>(expr)->getSubExpr();
      DeclRefExpr *declExpr = cast<DeclRefExpr>(expr);

      string fdFileWithExt = Context->getSourceManager().getFilename(declExpr->getDecl()->getLocation());
      string fdFile = fdFileWithExt.substr(0, fdFileWithExt.find_last_of("."));

      if ((fdFile.size() > 0) && (fdFile.find(FileName) != string::npos))
      {
        ValueDecl *value = declExpr->getDecl();
        if (!isa<FunctionDecl>(value))
          continue;

        if (funcname == "probe")
        {
          DI->getInstance().SetInitFunction(declExpr->getNameInfo().getName().getAsString());
        }<commit_msg>quick cleanup<commit_after>//
// Copyright (c) 2014-2015 <NAME> (<EMAIL>)
// This file is distributed under the MIT License. See LICENSE for details.
//

#include "chauffeur/Chauffeur.h"
#include "chauffeur/DriverType.h"
#include "chauffeur/FindEntryPointsVisitor.h"
#include "clang/AST/ASTContext.h"

namespace chauffeur
{
  using namespace std;

  bool FindEntryPointsVisitor::VisitVarDecl(VarDecl* varDecl)
  {
    if (!varDecl->getType()->isRecordType())
    {
      if (varDecl->getNameAsString() == "_whoop_init")
      {
        ImplicitCastExpr *implExpr = cast<ImplicitCastExpr>(varDecl->getInit());
        if (implExpr == NULL)
        {
          return true;
        }

        ImplicitCastExpr *implExpr2 = cast<ImplicitCastExpr>(implExpr->getSubExpr());
        DeclRefExpr *declExpr = cast<DeclRefExpr>(implExpr2->getSubExpr());
        DI->getInstance().AddEntryPointPair("whoop_driver_ops", "probe",
          declExpr->getFoundDecl()->getNameAsString());
        DI->getInstance().SetInitFunction(declExpr->getFoundDecl()->getNameAsString());
      }
      else if (varDecl->getNameAsString() == "_whoop_exit")
      {
        ImplicitCastExpr *implExpr = cast<ImplicitCastExpr>(varDecl->getInit());
        if (implExpr == NULL)
        {
          return true;
        }

        DeclRefExpr *declExpr = cast<DeclRefExpr>(implExpr->getSubExpr());

        list<string> func_params;
        func_params.push_back("void");
        DI->getInstance().AddEntryPoint(declExpr->getFoundDecl()->getNameAsString(), func_params);

        DI->getInstance().AddEntryPointPair("whoop_driver_ops", "remove",
          declExpr->getFoundDecl()->getNameAsString());
      }

      return true;
    }

    RecordDecl *baseRecDecl = varDecl->getType()->getAs<RecordType>()->getDecl();

    if (!DI->IsDriverModule(baseRecDecl->getNameAsString()))
    {
      return true;
    }

    if (baseRecDecl->getNameAsString() == "file_operations")
      DI->getInstance().SetType(CHAR_DRIVER);
    else if (baseRecDecl->getNameAsString() == "block_device_operations")
      DI->getInstance().SetType(BLOCK_DRIVER);
    else if (baseRecDecl->getNameAsString() == "net_device_ops")
      DI->getInstance().SetType(NETWORK_DRIVER);
    else if (baseRecDecl->getNameAsString() == "test_driver")
      DI->getInstance().SetType(TEST_DRIVER);

    if (varDecl->getInit() == NULL)
    {
      return true;
    }

    InitListExpr *initListExpr = cast<InitListExpr>(varDecl->getInit())->getSyntacticForm();

    for (auto range = initListExpr->children(); range; ++range)
    {
      DesignatedInitExpr *desExpr = cast<DesignatedInitExpr>(*range);
      if (desExpr->size() != 1) continue;

      string funcname;

      if (/* pci_driver */
          desExpr->getDesignator(0)->getFieldName()->getName() == "probe" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "remove" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "shutdown" ||
          /* file_operations */
          desExpr->getDesignator(0)->getFieldName()->getName() == "llseek" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "write" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "read" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ioctl" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "unlocked_ioctl" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "poll" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "open" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "release" ||
          /* block_device_operations */
          desExpr->getDesignator(0)->getFieldName()->getName() == "getgeo" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "revalidate_disk" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "media_changed" ||
          /* dev_pm_ops */
          desExpr->getDesignator(0)->getFieldName()->getName() == "suspend" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "resume" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "freeze" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "thaw" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "poweroff" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "restore" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "runtime_suspend" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "runtime_resume" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "runtime_idle" ||
          /* net_device_ops */
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_open" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_stop" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_get_stats64" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_start_xmit" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_tx_timeout" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_validate_addr" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_change_mtu" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_fix_features" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_set_features" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_set_mac_address" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_do_ioctl" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_set_rx_mode" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ndo_poll_controller" ||
          /* ethtool_ops */
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_drvinfo" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_regs_len" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_link" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_settings" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "set_settings" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_msglevel" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "set_msglevel" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_regs" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_wol" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "set_wol" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_strings" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_sset_count" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_ethtool_stats" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "get_ts_info" ||
          /* test_driver */
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep1" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep2" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep3" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep4" ||
          desExpr->getDesignator(0)->getFieldName()->getName() == "ep5")
        funcname = desExpr->getDesignator(0)->getFieldName()->getName();
      else
        continue;

      Expr *expr = cast<ImplicitCastExpr>(desExpr->getInit())->getSubExpr();
      while (!isa<DeclRefExpr>(expr))
        expr = cast<ImplicitCastExpr>(expr)->getSubExpr();
      DeclRefExpr *declExpr = cast<DeclRefExpr>(expr);

      string fdFileWithExt = Context->getSourceManager().getFilename(declExpr->getDecl()->getLocation());
      string fdFile = fdFileWithExt.substr(0, fdFileWithExt.find_last_of("."));

      if ((fdFile.size() > 0) && (fdFile.find(FileName) != string::npos))
      {
        ValueDecl *value = declExpr->getDecl();
        if (!isa<FunctionDecl>(value))
          continue;

        if (funcname == "probe")
        {
          DI->getInstance().SetInitFunction(declExpr->getNameInfo().getName().getAsString());
        }
{'fraction_non_alphanumeric': 0.18966037280569464, 'fraction_numerical': 0.00922965554684201, 'mean_word_length': 3.478119935170178, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 469, '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': '3940550', 'n_tokens_mistral': 5001, 'n_tokens_neox': 4960, 'n_words': 575}