<commit_before>/* ***** BEGIN LICENSE BLOCK *****
;;
;; Copyright (c) 2012 <NAME> <<EMAIL>>
;;
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
   ***** END LICENSE BLOCK *****
*/

#ifndef COR_PSOURCEMANAGER_H_
#define COR_PSOURCEMANAGER_H_

#include "corvus/pTypes.h"
#include "corvus/pSourceModule.h"
#include "corvus/pConfig.h"

#include <ostream>
#include <map>
#include <string>

class sqlite3;

namespace corvus {

class pPassManager;
class pModel;

class pSourceManager {
public:
    typedef std::vector<pSourceModule*> DiagModuleListType;

private:
    typedef std::map<std::string, pSourceModule*> ModuleListType;
    typedef std::map<pSourceModule*, bool> DiagTrackerType;

    bool debugParse_, debugModel_, debugDiags_;
    int verbosity_;    
    ModuleListType moduleList_;

    // the source modules from moduleList_ which have diagnostics waiting
    // note that moduleList_ is the owner of these pointers, not diagModuleList_
    DiagTrackerType diagModuleTracker_;

    sqlite3 *db_;
    pModel *model_;
    std::string dbName_;
    std::ostream *logStream_;

    void log(llvm::Twine msg, int verbosity = 1) {
        if (logStream_ && verbosity_ >= verbosity) {
            *logStream_ << msg.str() << std::endl;
        }
    }

    void runPasses(pPassManager *pm);
    void openModel();

public:

    pSourceManager(std::ostream *logStream = 0): debugParse_(false),
        debugModel_(false),
        debugDiags_(false),
        verbosity_(0),
        db_(NULL),
        model_(NULL),
        logStream_(logStream),
        dbName_() { }
    ~pSourceManager();

    void setModelDBName(pStringRef db)  { dbName_ = db; }

    void configure(const pConfig& config);

    void printAST();
    void printToks();

    void addSourceFile(pStringRef name);
    void addSourceDir(pStringRef name, pStringRef exts);
    void addIncludeDir(pStringRef name, pStringRef exts);

    void refreshModel(pStringRef graphFileName="");<commit_msg>add setLogStream<commit_after>/* ***** BEGIN LICENSE BLOCK *****
;;
;; Copyright (c) 2012 <NAME> <<EMAIL>>
;;
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
   ***** END LICENSE BLOCK *****
*/

#ifndef COR_PSOURCEMANAGER_H_
#define COR_PSOURCEMANAGER_H_

#include "corvus/pTypes.h"
#include "corvus/pSourceModule.h"
#include "corvus/pConfig.h"

#include <ostream>
#include <map>
#include <string>

class sqlite3;

namespace corvus {

class pPassManager;
class pModel;

class pSourceManager {
public:
    typedef std::vector<pSourceModule*> DiagModuleListType;

private:
    typedef std::map<std::string, pSourceModule*> ModuleListType;
    typedef std::map<pSourceModule*, bool> DiagTrackerType;

    bool debugParse_, debugModel_, debugDiags_;
    int verbosity_;    
    ModuleListType moduleList_;

    // the source modules from moduleList_ which have diagnostics waiting
    // note that moduleList_ is the owner of these pointers, not diagModuleList_
    DiagTrackerType diagModuleTracker_;

    sqlite3 *db_;
    pModel *model_;
    std::string dbName_;
    std::ostream *logStream_;

    void log(llvm::Twine msg, int verbosity = 1) {
        if (logStream_ && verbosity_ >= verbosity) {
            *logStream_ << msg.str() << std::endl;
        }
    }

    void runPasses(pPassManager *pm);
    void openModel();

public:

    pSourceManager(std::ostream *logStream = 0): debugParse_(false),
        debugModel_(false),
        debugDiags_(false),
        verbosity_(0),
        db_(NULL),
        model_(NULL),
        logStream_(logStream),
        dbName_() { }
    ~pSourceManager();

    void setLogStream(std::ostream *logStream) { logStream_ = logStream; }
    void setModelDBName(pStringRef db)  { dbName_ = db; }

    void configure(const pConfig& config);

    void printAST();
    void printToks();

    void addSourceFile(pStringRef name);
    void addSourceDir(pStringRef name, pStringRef exts);
    void addIncludeDir(pStringRef name, pStringRef exts);

    void refreshModel(pStringRef graphFileName="");
{'fraction_non_alphanumeric': 0.11486486486486487, 'fraction_numerical': 0.0060577819198508855, 'mean_word_length': 3.636069114470842, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, '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': '625343', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1330, 'n_words': 371}