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

📄 errmsg.cpp

📁 cppcheck is a static C/C++ code analyzer that checks for memory leaks, mismatching allocation-deallo
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    fout << "     * @param outmsg, E.g. \"Checking main.cpp...\"\n";    fout << "     */\n";    fout << "    virtual void reportOut(const std::string &outmsg) = 0;\n";    fout << "\n";    fout << "    /**\n";    fout << "     * Information about found errors and warnings is directed\n";    fout << "     * here. Override this to receive the errormessages.\n";    fout << "     *\n";    fout << "     * @param msg Location and other information about the found.\n";    fout << "     * error\n";    fout << "     */\n";    fout << "    virtual void reportErr(const ErrorLogger::ErrorMessage &msg) = 0;\n";    fout << "\n";    fout << "    /**\n";    fout << "     * Information about how many files have been checked\n";    fout << "     *\n";    fout << "     * @param index This many files have been checked.\n";    fout << "     * @param max This many files there are in total.\n";    fout << "     */\n";    fout << "    virtual void reportStatus(unsigned int index, unsigned int max) = 0;\n";    fout << "\n";    for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it)        it->generateCode(fout);    fout << "\n";    fout << "    static std::string callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack);\n";    fout << "\n";    fout << "private:\n";    fout << "    void _writemsg(const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string &msg, const std::string &id);\n";    fout << "    void _writemsg(const Tokenizer *tokenizer, const std::list<const Token *> &callstack, const char severity[], const std::string &msg, const std::string &id);\n";    fout << "    void _writemsg(const std::string &msg, const std::string &id);\n";    fout << "};\n";    fout << "#endif\n";    std::cout << std::endl;    // Generate documentation..    std::cout << "Generate doc.." << std::endl;    const unsigned int NUMSUITE = 5;    for (unsigned int i = 0; i < NUMSUITE; ++i)    {        const char *suite[NUMSUITE] = { "error", "all", "style", "all + style", "security" };        const Message::Settings settings[NUMSUITE] = { Message::error, Message::all, Message::style, Message::style_all, Message::security };        std::cout << "    =" << suite[i] << "=" << std::endl;        for (std::list<Message>::const_iterator it = err.begin(); it != err.end(); ++it)            it->generateDoc(std::cout, settings[i]);    }    std::cout << std::endl;    return 0;}Message::Message(std::string funcname, Settings settings, std::string msg)        : _funcname(funcname), _msg(msg), _par1(""), _par2(""), _settings(settings), _details(""){ }Message::Message(std::string funcname, Settings settings, std::string msg, std::string par1)        : _funcname(funcname), _msg(msg), _par1(par1), _par2(""), _settings(settings), _details(""){ }Message::Message(std::string funcname, Settings settings, std::string msg, std::string par1, std::string par2)        : _funcname(funcname), _msg(msg), _par1(par1), _par2(par2), _settings(settings), _details(""){ }Message::Message(std::string funcname, Settings settings, std::string msg, std::string par1, std::string par2, std::string details)        : _funcname(funcname), _msg(msg), _par1(par1), _par2(par2), _settings(settings), _details(details){ }std::string Message::msg(bool code) const{    const char *str = code ? "\"" : "";    std::string ret(str + _msg + str);    if (! _par1.empty())    {        std::string::size_type pos = 0;        while ((pos = ret.find("%1", pos)) != std::string::npos)        {            ret.erase(pos, 2);            if (code)                ret.insert(pos, "\" + " + _par1 + " + \"");            else                ret.insert(pos, _par1);        }    }    if (! _par2.empty())    {        std::string::size_type pos = 0;        while ((pos = ret.find("%2", pos)) != std::string::npos)        {            ret.erase(pos, 2);            if (code)                ret.insert(pos, "\" + " + _par2 + " + \"");            else                ret.insert(pos, _par2);        }    }    return ret;}void Message::generateCode(std::ostream &ostr) const{    bool loc = bool(_msg.substr(0, 4) != "[%1]");    // Error message..    ostr << "    void " << _funcname << "(";    if (loc)    {        ostr << "const Tokenizer *tokenizer, ";        if (_funcname == "mismatchAllocDealloc" ||            _funcname == "arrayIndexOutOfBounds")            ostr << "const std::list<const Token *> &Location";        else            ostr << "const Token *Location";    }    /*    if (_details.size())        ostr << ", const Settings &settings";    */    if (! _par1.empty())        ostr << (loc ? ", " : "") <<  "const std::string &" << _par1;    if (! _par2.empty())        ostr << ", const std::string &" << _par2;    ostr << ")\n";    ostr << "    {\n";    ostr << "        _writemsg(";    if (loc)        ostr << "tokenizer, Location, \"" << stringifySettings(true) << "\", ";    ostr << msg(true) << ", \"" << _funcname << "\");\n";    /*        ostr << "        return ";        if (loc)            ostr << "msg1(tokenizer, Location) + ";        ostr << " std::string(\"(" << stringifySettings(true) << ") \") + ";        ostr << msg(true);        if (_details.empty())            ostr << ";\n";        else        {            ostr << " + std::string(settings._verbose ? \"\\n";            for (std::string::size_type pos = 0; pos < _details.length(); ++pos)            {                if (_details[pos] == '\n')                    ostr << "\\n";                else                    ostr << _details[pos];            }            ostr << "\" : \"\");\n";        }    */    ostr << "    }\n";    // Settings..    ostr << "    static bool " << _funcname << "(";    if (_settings != error && _settings != never)        ostr << "const Settings &s";    ostr << ")" << std::endl;    ostr << "    {\n";    ostr << "        return " << stringifySettings(false) << ";\n";    ostr << "    }\n\n";}void Message::generateDoc(std::ostream &ostr, Message::Settings i) const{    if (_settings == i)    {        ostr << "    " << msg(false) << std::endl;    }}std::string Message::stringifySettings(bool text) const{    switch (_settings)    {    case error:        return text ? "error" : "true";    case all:        return text ? "all" : "s._showAll";    case style:        return text ? "style" : "s._checkCodingStyle";    case style_all:        return text ? "all style" : "s._checkCodingStyle || s._showAll";    case security:        return text ? "security" : "s._security";    case never:        return text ? "never" : "false";    }    return "";}

⌨️ 快捷键说明

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