cppcheck/lib/executionpath.h

119 lines
3.4 KiB
C
Raw Normal View History

2009-12-14 20:30:31 +01:00
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki and 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 executionpathH
#define executionpathH
#include <list>
class Token;
2009-12-21 18:17:35 +01:00
class Check;
2009-12-14 20:30:31 +01:00
/**
* Base class for Execution Paths checking
* An execution path is a linear list of statements. There are no "if"/.. to worry about.
**/
class ExecutionPath
{
private:
/** No implementation */
void operator=(const ExecutionPath &);
protected:
2009-12-21 18:17:35 +01:00
const unsigned int varId;
Check * const owner;
2009-12-14 20:30:31 +01:00
public:
ExecutionPath(Check *c, unsigned int id) : varId(id), owner(c), ifinfo(0)
2009-12-14 20:30:31 +01:00
{ }
virtual ~ExecutionPath()
{ }
2009-12-25 20:50:23 +01:00
/** Implement this in each derived class. This function must create a copy of the current instance */
2009-12-14 20:30:31 +01:00
virtual ExecutionPath *copy() = 0;
2009-12-25 20:50:23 +01:00
/** Some kind of if-information */
unsigned int ifinfo;
2009-12-14 20:30:31 +01:00
/**
* bail out all execution paths
* @param checks the execution paths to bail out on
**/
static void bailOut(std::list<ExecutionPath *> &checks)
2009-12-14 20:30:31 +01:00
{
while (!checks.empty())
{
delete checks.back();
checks.pop_back();
}
2009-12-14 20:30:31 +01:00
}
2009-12-21 18:17:35 +01:00
/**
* bail out execution paths with given variable id
* @param checks the execution paths to bail out on
* @param varid the specific variable id
**/
static void bailOutVar(std::list<ExecutionPath *> &checks, const unsigned int varid)
2009-12-21 18:17:35 +01:00
{
if (varid == 0)
return;
std::list<ExecutionPath *>::iterator it = checks.begin();
while (it != checks.end())
{
if ((*it)->varId == varid)
{
delete *it;
checks.erase(it++);
}
else
{
++it;
}
}
2009-12-21 18:17:35 +01:00
}
2009-12-14 20:30:31 +01:00
/**
* Parse tokens at given location
* @param tok token to parse
2009-12-25 19:45:21 +01:00
* @param foundError If an error is found this is set to true
2009-12-14 20:30:31 +01:00
* @param checks The execution paths. All execution paths in the list are executed in the current scope.
2009-12-25 19:45:21 +01:00
* @return the token before the "next" token.
2009-12-14 20:30:31 +01:00
**/
virtual const Token *parse(const Token &tok, bool &foundError, std::list<ExecutionPath *> &checks) const = 0;
2009-12-25 19:45:21 +01:00
/**
* Parse condition
* @param tok first token in condition.
* @param checks The execution paths. All execution paths in the list are executed in the current scope
* @return true => bail out all checking
**/
2009-12-25 20:50:23 +01:00
virtual bool parseCondition(const Token &tok, std::list<ExecutionPath *> &checks);
/** going out of scope - all execution paths end */
virtual void end(const std::list<ExecutionPath *> & /*checks*/, const Token * /*tok*/) const
{ }
2009-12-14 20:30:31 +01:00
};
void checkExecutionPaths(const Token *tok, ExecutionPath *c);
2009-12-14 20:30:31 +01:00
#endif