2018-12-25 21:11:23 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
|
|
|
* Copyright (C) 2007-2018 Cppcheck team.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#ifndef ctuH
|
|
|
|
#define ctuH
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "check.h"
|
|
|
|
#include "valueflow.h"
|
|
|
|
|
|
|
|
/// @addtogroup Core
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Whole program analysis (ctu=Cross Translation Unit) */
|
|
|
|
namespace CTU {
|
2018-12-28 23:09:44 +01:00
|
|
|
class CPPCHECKLIB FileInfo : public Check::FileInfo {
|
2018-12-25 21:11:23 +01:00
|
|
|
public:
|
2018-12-30 16:23:25 +01:00
|
|
|
enum InvalidValueType { null, uninit };
|
|
|
|
|
2019-01-12 07:37:42 +01:00
|
|
|
std::string toString() const OVERRIDE;
|
2018-12-25 21:11:23 +01:00
|
|
|
|
|
|
|
struct Location {
|
|
|
|
Location() = default;
|
|
|
|
Location(const Tokenizer *tokenizer, const Token *tok);
|
|
|
|
Location(const std::string &fileName, unsigned int linenr) : fileName(fileName), linenr(linenr) {}
|
|
|
|
std::string fileName;
|
|
|
|
unsigned int linenr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UnsafeUsage {
|
|
|
|
UnsafeUsage() = default;
|
2018-12-30 11:55:39 +01:00
|
|
|
UnsafeUsage(const std::string &myId, unsigned int myArgNr, const std::string &myArgumentName, const Location &location) : myId(myId), myArgNr(myArgNr), myArgumentName(myArgumentName), location(location) {}
|
|
|
|
std::string myId;
|
|
|
|
unsigned int myArgNr;
|
|
|
|
std::string myArgumentName;
|
2018-12-25 21:11:23 +01:00
|
|
|
Location location;
|
|
|
|
std::string toString() const;
|
|
|
|
};
|
|
|
|
|
2018-12-30 11:55:39 +01:00
|
|
|
class CallBase {
|
|
|
|
public:
|
|
|
|
CallBase() = default;
|
|
|
|
CallBase(const std::string &callId, int callArgNr, const std::string &callFunctionName, const Location &loc)
|
|
|
|
: callId(callId), callArgNr(callArgNr), callFunctionName(callFunctionName), location(loc)
|
|
|
|
{}
|
|
|
|
CallBase(const Tokenizer *tokenizer, const Token *callToken);
|
2018-12-30 16:23:25 +01:00
|
|
|
virtual ~CallBase() {}
|
2018-12-30 11:55:39 +01:00
|
|
|
std::string callId;
|
|
|
|
int callArgNr;
|
|
|
|
std::string callFunctionName;
|
2018-12-25 21:11:23 +01:00
|
|
|
Location location;
|
2018-12-30 11:55:39 +01:00
|
|
|
protected:
|
|
|
|
std::string toBaseXmlString() const;
|
|
|
|
bool loadBaseFromXml(const tinyxml2::XMLElement *xmlElement);
|
2018-12-25 21:11:23 +01:00
|
|
|
};
|
|
|
|
|
2018-12-30 11:55:39 +01:00
|
|
|
class FunctionCall : public CallBase {
|
|
|
|
public:
|
|
|
|
std::string callArgumentExpression;
|
2018-12-30 18:31:37 +01:00
|
|
|
MathLib::bigint callArgValue;
|
2018-12-30 11:55:39 +01:00
|
|
|
ValueFlow::Value::ValueType callValueType;
|
2018-12-30 18:31:37 +01:00
|
|
|
std::vector<ErrorLogger::ErrorMessage::FileLocation> callValuePath;
|
|
|
|
bool warning;
|
2018-12-30 11:55:39 +01:00
|
|
|
|
|
|
|
std::string toXmlString() const;
|
|
|
|
bool loadFromXml(const tinyxml2::XMLElement *xmlElement);
|
|
|
|
};
|
|
|
|
|
|
|
|
class NestedCall : public CallBase {
|
|
|
|
public:
|
2018-12-25 21:11:23 +01:00
|
|
|
NestedCall() = default;
|
|
|
|
|
2018-12-30 11:55:39 +01:00
|
|
|
NestedCall(const std::string &myId, unsigned int myArgNr, const std::string &callId, unsigned int callArgnr, const std::string &callFunctionName, const Location &location)
|
|
|
|
: CallBase(callId, callArgnr, callFunctionName, location),
|
|
|
|
myId(myId),
|
|
|
|
myArgNr(myArgNr) {
|
2018-12-25 21:11:23 +01:00
|
|
|
}
|
|
|
|
|
2018-12-30 11:55:39 +01:00
|
|
|
NestedCall(const Tokenizer *tokenizer, const Function *myFunction, const Token *callToken);
|
2018-12-25 21:11:23 +01:00
|
|
|
|
2018-12-30 11:55:39 +01:00
|
|
|
std::string toXmlString() const;
|
|
|
|
bool loadFromXml(const tinyxml2::XMLElement *xmlElement);
|
|
|
|
|
|
|
|
std::string myId;
|
|
|
|
unsigned int myArgNr;
|
2018-12-25 21:11:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
std::list<FunctionCall> functionCalls;
|
|
|
|
std::list<NestedCall> nestedCalls;
|
|
|
|
|
|
|
|
void loadFromXml(const tinyxml2::XMLElement *xmlElement);
|
2018-12-30 16:23:25 +01:00
|
|
|
std::map<std::string, std::list<const CallBase *>> getCallsMap() const;
|
2018-12-26 15:56:10 +01:00
|
|
|
|
|
|
|
std::list<ErrorLogger::ErrorMessage::FileLocation> getErrorPath(InvalidValueType invalidValue,
|
2018-12-26 11:36:26 +01:00
|
|
|
const UnsafeUsage &unsafeUsage,
|
2018-12-30 16:23:25 +01:00
|
|
|
const std::map<std::string, std::list<const CallBase *>> &callsMap,
|
2018-12-26 15:56:10 +01:00
|
|
|
const char info[],
|
2018-12-30 18:31:37 +01:00
|
|
|
const FunctionCall * * const functionCallPtr,
|
|
|
|
bool warning) const;
|
2018-12-25 21:11:23 +01:00
|
|
|
};
|
|
|
|
|
2018-12-28 23:09:44 +01:00
|
|
|
CPPCHECKLIB std::string toString(const std::list<FileInfo::UnsafeUsage> &unsafeUsage);
|
2018-12-26 15:56:10 +01:00
|
|
|
|
2018-12-28 23:09:44 +01:00
|
|
|
CPPCHECKLIB std::string getFunctionId(const Tokenizer *tokenizer, const Function *function);
|
2018-12-25 21:11:23 +01:00
|
|
|
|
|
|
|
/** @brief Parse current TU and extract file info */
|
2018-12-28 23:09:44 +01:00
|
|
|
CPPCHECKLIB FileInfo *getFileInfo(const Tokenizer *tokenizer);
|
2018-12-25 21:11:23 +01:00
|
|
|
|
2018-12-28 23:09:44 +01:00
|
|
|
CPPCHECKLIB std::list<FileInfo::UnsafeUsage> getUnsafeUsage(const Tokenizer *tokenizer, const Settings *settings, const Check *check, bool (*isUnsafeUsage)(const Check *check, const Token *argtok));
|
2018-12-26 19:17:49 +01:00
|
|
|
|
2018-12-28 23:09:44 +01:00
|
|
|
CPPCHECKLIB std::list<FileInfo::UnsafeUsage> loadUnsafeUsageListFromXml(const tinyxml2::XMLElement *xmlElement);
|
2018-12-25 21:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif // ctuH
|