Blame lib/check.cpp

Packit 2035a7
/*
Packit 2035a7
 * Cppcheck - A tool for static C/C++ code analysis
Packit 2035a7
 * Copyright (C) 2007-2017 Cppcheck team.
Packit 2035a7
 *
Packit 2035a7
 * This program is free software: you can redistribute it and/or modify
Packit 2035a7
 * it under the terms of the GNU General Public License as published by
Packit 2035a7
 * the Free Software Foundation, either version 3 of the License, or
Packit 2035a7
 * (at your option) any later version.
Packit 2035a7
 *
Packit 2035a7
 * This program is distributed in the hope that it will be useful,
Packit 2035a7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 2035a7
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 2035a7
 * GNU General Public License for more details.
Packit 2035a7
 *
Packit 2035a7
 * You should have received a copy of the GNU General Public License
Packit 2035a7
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 2035a7
 */
Packit 2035a7
Packit 2035a7
//---------------------------------------------------------------------------
Packit 2035a7
Packit 2035a7
#include "check.h"
Packit 2035a7
Packit 2035a7
#include <iostream>
Packit 2035a7
Packit 2035a7
//---------------------------------------------------------------------------
Packit 2035a7
Packit 2035a7
Check::Check(const std::string &aname)
Packit 2035a7
    : _tokenizer(nullptr), _settings(nullptr), _errorLogger(nullptr), _name(aname)
Packit 2035a7
{
Packit 2035a7
    for (std::list<Check*>::iterator i = instances().begin(); i != instances().end(); ++i) {
Packit 2035a7
        if ((*i)->name() > aname) {
Packit 2035a7
            instances().insert(i, this);
Packit 2035a7
            return;
Packit 2035a7
        }
Packit 2035a7
    }
Packit 2035a7
    instances().push_back(this);
Packit 2035a7
}
Packit 2035a7
Packit 2035a7
void Check::reportError(const ErrorLogger::ErrorMessage &errmsg)
Packit 2035a7
{
Packit 2035a7
    std::cout << errmsg.toXML() << std::endl;
Packit 2035a7
}
Packit 2035a7
Packit 2035a7
bool Check::wrongData(const Token *tok, bool condition, const char *str)
Packit 2035a7
{
Packit 2035a7
#if defined(DACA2) || defined(UNSTABLE)
Packit 2035a7
    if (condition) {
Packit 2035a7
        reportError(tok, Severity::debug, "DacaWrongData", "Wrong data detected by condition " + std::string(str));
Packit 2035a7
    }
Packit 2035a7
#else
Packit 2035a7
    (void)tok;
Packit 2035a7
    (void)str;
Packit 2035a7
#endif
Packit 2035a7
    return condition;
Packit 2035a7
}
Packit 2035a7
Packit 2035a7
std::list<Check *> &Check::instances()
Packit 2035a7
{
Packit 2035a7
#ifdef __SVR4
Packit 2035a7
    // Under Solaris, destructors are called in wrong order which causes a segmentation fault.
Packit 2035a7
    // This fix ensures pointer remains valid and reachable until program terminates.
Packit 2035a7
    static std::list<Check *> *_instances= new std::list<Check *>;
Packit 2035a7
    return *_instances;
Packit 2035a7
#else
Packit 2035a7
    static std::list<Check *> _instances;
Packit 2035a7
    return _instances;
Packit 2035a7
#endif
Packit 2035a7
}