Skip to content

Commit 7693579

Browse files
committed
restored some deleted code
1 parent 92cc469 commit 7693579

8 files changed

Lines changed: 61 additions & 1 deletion

File tree

lib/forwardanalyzer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ struct ForwardTraversal {
8989
return evalCond(tok, ctx).first;
9090
}
9191

92+
bool isConditionFalse(const Token* tok, const Token* ctx = nullptr) const {
93+
return evalCond(tok, ctx).second;
94+
}
95+
9296
template<class T, class F, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
9397
Progress traverseTok(T* tok, F f, bool traverseUnknown, T** out = nullptr) {
9498
if (Token::Match(tok, "asm|goto|setjmp|longjmp"))

lib/importproject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ class CPPCHECKLIB ImportProject {
104104
void ignorePaths(const std::vector<std::string> &ipaths);
105105
void ignoreOtherConfigs(const std::string &cfg);
106106

107-
108107
Type import(const std::string &filename, Settings *settings=nullptr);
109108
protected:
110109
bool importCompileCommands(std::istream &istr);

lib/library.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,28 @@ const Token* Library::getContainerFromYield(const Token* tok, Library::Container
15771577
}
15781578
return nullptr;
15791579
}
1580+
const Token* Library::getContainerFromAction(const Token* tok, Library::Container::Action action) const
1581+
{
1582+
if (!tok)
1583+
return nullptr;
1584+
if (Token::Match(tok->tokAt(-2), ". %name% (")) {
1585+
const Token* containerTok = tok->tokAt(-2)->astOperand1();
1586+
if (!astIsContainer(containerTok))
1587+
return nullptr;
1588+
if (containerTok->valueType()->container &&
1589+
containerTok->valueType()->container->getAction(tok->strAt(-1)) == action)
1590+
return containerTok;
1591+
if (Token::simpleMatch(tok->tokAt(-1), "empty ( )"))
1592+
return containerTok;
1593+
} else if (Token::Match(tok->previous(), "%name% (")) {
1594+
if (const Library::Function* f = this->getFunction(tok->previous())) {
1595+
if (f->containerAction == action) {
1596+
return tok->astOperand2();
1597+
}
1598+
}
1599+
}
1600+
return nullptr;
1601+
}
15801602

15811603
bool Library::isSmartPointer(const Token* tok) const
15821604
{

lib/library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ class CPPCHECKLIB Library {
459459
bool isimporter(const std::string& file, const std::string &importer) const;
460460

461461
const Token* getContainerFromYield(const Token* tok, Container::Yield yield) const;
462+
const Token* getContainerFromAction(const Token* tok, Container::Action action) const;
462463

463464
bool isreflection(const std::string &token) const {
464465
return mReflection.find(token) != mReflection.end();

lib/programmemory.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ const ValueFlow::Value* ProgramMemory::getValue(nonneg int exprid, bool impossib
2828
return nullptr;
2929
}
3030

31+
bool ProgramMemory::getIntValue(nonneg int exprid, MathLib::bigint* result) const
32+
{
33+
const ValueFlow::Value* value = getValue(exprid);
34+
if (value && value->isIntValue()) {
35+
*result = value->intvalue;
36+
return true;
37+
}
38+
return false;
39+
}
40+
3141
void ProgramMemory::setIntValue(nonneg int exprid, MathLib::bigint value, bool impossible)
3242
{
3343
ValueFlow::Value v(value);
@@ -46,6 +56,15 @@ bool ProgramMemory::getTokValue(nonneg int exprid, const Token** result) const
4656
return false;
4757
}
4858

59+
bool ProgramMemory::getContainerSizeValue(nonneg int exprid, MathLib::bigint* result) const
60+
{
61+
const ValueFlow::Value* value = getValue(exprid);
62+
if (value && value->isContainerSizeValue()) {
63+
*result = value->intvalue;
64+
return true;
65+
}
66+
return false;
67+
}
4968
bool ProgramMemory::getContainerEmptyValue(nonneg int exprid, MathLib::bigint* result) const
5069
{
5170
const ValueFlow::Value* value = getValue(exprid, true);

lib/programmemory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ struct ProgramMemory {
1717
void setValue(nonneg int exprid, const ValueFlow::Value& value);
1818
const ValueFlow::Value* getValue(nonneg int exprid, bool impossible = false) const;
1919

20+
bool getIntValue(nonneg int exprid, MathLib::bigint* result) const;
2021
void setIntValue(nonneg int exprid, MathLib::bigint value, bool impossible = false);
2122

23+
bool getContainerSizeValue(nonneg int exprid, MathLib::bigint* result) const;
2224
bool getContainerEmptyValue(nonneg int exprid, MathLib::bigint* result) const;
2325
void setContainerSizeValue(nonneg int exprid, MathLib::bigint value, bool isEqual = true);
2426

lib/token.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,14 @@ void Token::printOut(const char *title, const std::vector<std::string> &fileName
11851185
std::cout << stringifyList(stringifyOptions::forPrintOut(), &fileNames, nullptr) << std::endl;
11861186
}
11871187

1188+
void Token::printLines(int lines) const
1189+
{
1190+
const Token *end = this;
1191+
while (end && end->linenr() < lines + linenr())
1192+
end = end->next();
1193+
std::cout << stringifyList(stringifyOptions::forDebugExprId(), nullptr, end) << std::endl;
1194+
}
1195+
11881196
std::string Token::stringify(const stringifyOptions& options) const
11891197
{
11901198
std::string ret;

lib/token.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,11 @@ class CPPCHECKLIB Token {
862862
*/
863863
void printOut(const char *title, const std::vector<std::string> &fileNames) const;
864864

865+
/**
866+
* print out tokens - used for debugging
867+
*/
868+
void printLines(int lines=5) const;
869+
865870
/**
866871
* Replace token replaceThis with tokens between start and end,
867872
* including start and end. The replaceThis token is deleted.

0 commit comments

Comments
 (0)