⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generate.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* * =========================================================================== * PRODUCTION $Log: generate.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:43:12  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.59 * PRODUCTION * =========================================================================== *//*  $Id: generate.cpp,v 1000.1 2004/06/01 19:43:12 gouriano Exp $* ===========================================================================**                            PUBLIC DOMAIN NOTICE*               National Center for Biotechnology Information**  This software/database is a "United States Government Work" under the*  terms of the United States Copyright Act.  It was written as part of*  the author's official duties as a United States Government employee and*  thus cannot be copyrighted.  This software/database is freely available*  to the public for use. The National Library of Medicine and the U.S.*  Government have not placed any restriction on its use or reproduction.**  Although all reasonable efforts have been taken to ensure the accuracy*  and reliability of the software and data, the NLM and the U.S.*  Government do not and cannot warrant the performance or results that*  may be obtained by using this software or data. The NLM and the U.S.*  Government disclaim all warranties, express or implied, including*  warranties of performance, merchantability or fitness for any particular*  purpose.**  Please cite the author in any work or product based on this material.** ===========================================================================** Author: Eugene Vasilchenko** File Description:*   Main generator: collects all types, classes and files.*/#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbifile.hpp>#include <algorithm>#include <typeinfo>#include <serial/datatool/moduleset.hpp>#include <serial/datatool/module.hpp>#include <serial/datatool/type.hpp>#include <serial/datatool/statictype.hpp>#include <serial/datatool/reftype.hpp>#include <serial/datatool/unitype.hpp>#include <serial/datatool/enumtype.hpp>#include <serial/datatool/blocktype.hpp>#include <serial/datatool/choicetype.hpp>#include <serial/datatool/filecode.hpp>#include <serial/datatool/generate.hpp>#include <serial/datatool/exceptions.hpp>#include <serial/datatool/fileutil.hpp>#include <serial/datatool/rpcgen.hpp>#include <serial/datatool/code.hpp>BEGIN_NCBI_SCOPECCodeGenerator::CCodeGenerator(void)    : m_ExcludeRecursion(false), m_FileNamePrefixSource(eFileName_FromNone){    m_MainFiles.SetModuleContainer(this);    m_ImportFiles.SetModuleContainer(this);     m_UseQuotedForm = false;    m_CreateCvsignore = false;}CCodeGenerator::~CCodeGenerator(void){}const CNcbiRegistry& CCodeGenerator::GetConfig(void) const{    return m_Config;}string CCodeGenerator::GetFileNamePrefix(void) const{    return m_FileNamePrefix;}void CCodeGenerator::UseQuotedForm(bool use){    m_UseQuotedForm = use;}void CCodeGenerator::CreateCvsignore(bool create){    m_CreateCvsignore = create;}void CCodeGenerator::SetFileNamePrefix(const string& prefix){    m_FileNamePrefix = prefix;}EFileNamePrefixSource CCodeGenerator::GetFileNamePrefixSource(void) const{    return m_FileNamePrefixSource;}void CCodeGenerator::SetFileNamePrefixSource(EFileNamePrefixSource source){    m_FileNamePrefixSource =        EFileNamePrefixSource(m_FileNamePrefixSource | source);}CDataType* CCodeGenerator::InternalResolve(const string& module,                                           const string& name) const{    return ExternalResolve(module, name);}const CNamespace& CCodeGenerator::GetNamespace(void) const{    return m_DefaultNamespace;}void CCodeGenerator::SetDefaultNamespace(const string& ns){    m_DefaultNamespace = ns;}void CCodeGenerator::LoadConfig(CNcbiIstream& in){    m_Config.Read(in);}void CCodeGenerator::LoadConfig(const string& fileName,    bool ignoreAbsense, bool warningAbsense){    m_DefFile.erase();    // load descriptions from registry file    if ( fileName == "stdin" || fileName == "-" ) {        LoadConfig(NcbiCin);    }    else {        CNcbiIfstream in(fileName.c_str());        if ( !in ) {            if ( ignoreAbsense ) {                return;            } else if (warningAbsense) {                ERR_POST(Warning << "cannot open file " << fileName);            } else {                ERR_POST(Fatal << "cannot open file " << fileName);            }        }        else {            m_DefFile = fileName;            LoadConfig(in);        }    }}void CCodeGenerator::AddConfigLine(const string& line){    SIZE_TYPE bra = line.find('[');    SIZE_TYPE ket = line.find(']');    SIZE_TYPE eq = line.find('=', ket + 1);    if ( bra != 0 || ket == NPOS || eq == NPOS )        ERR_POST(Fatal << "bad config line: " << line);        m_Config.Set(line.substr(bra + 1, ket - bra - 1),                 line.substr(ket + 1, eq - ket - 1),                 line.substr(eq + 1));}CDataType* CCodeGenerator::ExternalResolve(const string& module,                                           const string& name,                                           bool exported) const{    string loc("CCodeGenerator::ExternalResolve: failed");    try {        return m_MainFiles.ExternalResolve(module, name, exported);    }    catch ( CAmbiguiousTypes& exc) {        _TRACE(exc.what());        NCBI_RETHROW_SAME(exc,loc);    }    catch ( CNotFoundException& _DEBUG_ARG(exc)) {        _TRACE(exc.what());        return m_ImportFiles.ExternalResolve(module, name, exported);    }    return NULL;  // Eliminate "return value expected" warning}CDataType* CCodeGenerator::ResolveInAnyModule(const string& name,                                              bool exported) const{    string loc("CCodeGenerator::ResolveInAnyModule: failed");    try {        return m_MainFiles.ResolveInAnyModule(name, exported);    }    catch ( CAmbiguiousTypes& exc) {        _TRACE(exc.what());        NCBI_RETHROW_SAME(exc,loc);    }    catch ( CNotFoundException& _DEBUG_ARG(exc)) {        _TRACE(exc.what());        return m_ImportFiles.ResolveInAnyModule(name, exported);    }    return NULL;  // Eliminate "return value expected" warning}CDataType* CCodeGenerator::ResolveMain(const string& fullName) const{    SIZE_TYPE dot = fullName.find('.');    if ( dot != NPOS ) {        // module specified        return m_MainFiles.ExternalResolve(fullName.substr(0, dot),                                           fullName.substr(dot + 1),                                           true);    }    else {        // module not specified - we'll scan all modules for type        return m_MainFiles.ResolveInAnyModule(fullName, true);    }}const string& CCodeGenerator::ResolveFileName(const string& name) const{    TOutputFiles::const_iterator i = m_Files.find(name);    if (i != m_Files.end()) {        return i->second->GetFileBaseName();    }    return name;}void CCodeGenerator::IncludeAllMainTypes(void){    ITERATE ( CFileSet::TModuleSets, msi, m_MainFiles.GetModuleSets() ) {        ITERATE ( CFileModules::TModules, mi, (*msi)->GetModules() ) {            const CDataTypeModule* module = mi->get();            ITERATE ( CDataTypeModule::TDefinitions, ti,                      module->GetDefinitions() ) {                const string& name = ti->first;                const CDataType* type = ti->second.get();                if ( !name.empty() && !type->Skipped() ) {                    m_GenerateTypes.insert(module->GetName() + '.' + name);                }            }        }    }}void CCodeGenerator::GetTypes(TTypeNames& typeSet, const string& types){    SIZE_TYPE pos = 0;    SIZE_TYPE next = types.find(',');    while ( next != NPOS ) {        typeSet.insert(types.substr(pos, next - pos));        pos = next + 1;        next = types.find(',', pos);    }    typeSet.insert(types.substr(pos));}bool CCodeGenerator::Check(void) const{    return m_MainFiles.CheckNames() && m_ImportFiles.CheckNames() &&        m_MainFiles.Check();}void CCodeGenerator::ExcludeTypes(const string& typeList){    TTypeNames typeNames;    GetTypes(typeNames, typeList);    ITERATE ( TTypeNames, i, typeNames ) {        m_Config.Set(*i, "_class", "-");        m_GenerateTypes.erase(*i);    }}void CCodeGenerator::IncludeTypes(const string& typeList){    GetTypes(m_GenerateTypes, typeList);}struct string_nocase_less{    bool operator()(const string& s1, const string& s2) const    {        return (NStr::CompareNocase(s1, s2) < 0);    }};void CCodeGenerator::GenerateCode(void){    // collect types    ITERATE ( TTypeNames, ti, m_GenerateTypes ) {        CollectTypes(ResolveMain(*ti), eRoot);    }    {        set<string,string_nocase_less> names;        ITERATE ( TOutputFiles, filei, m_Files ) {            CFileCode* code = filei->second.get();            string fname;            for ( fname = code->GetFileBaseName();                  names.find(fname) != names.end();) {                fname = code->ChangeFileBaseName();            }            names.insert(fname);        }    }    // generate output files    string outdir_cpp, outdir_hpp;    list<string> listGenerated, listUntouched;    map<string,string> module_names;    ITERATE ( TOutputFiles, filei, m_Files ) {        CFileCode* code = filei->second.get();        code->GetModuleNames( module_names);        code->UseQuotedForm(m_UseQuotedForm);        code->GenerateCode();        string fileName;        code->GenerateHPP(m_HPPDir, fileName);        if (outdir_hpp.empty()) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -