Skip to content

Commit 711d421

Browse files
committed
added some bailout debug messages [skip ci]
1 parent 981c9b5 commit 711d421

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

lib/astutils.cpp

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ const Token* findExpression(const nonneg int exprid,
6565
return nullptr;
6666
}
6767

68-
static int findArgumentPosRecursive(const Token* tok, const Token* tokToFind, bool &found, nonneg int depth=0)
68+
static int findArgumentPosRecursive(const Token* tok, const Token* tokToFind, bool &found, nonneg int depth=0)
6969
{
7070
++depth;
71-
if (!tok || depth >= 100)
72-
return -1; // TODO: add bailout message
71+
if (!tok)
72+
return -1;
73+
if (depth >= 100) {
74+
tok->debugMsg("depthBailout", "maximum depth of findArgumentPosRecursive() exceeded");
75+
return -1;
76+
}
7377
if (tok->str() == ",") {
7478
int res = findArgumentPosRecursive(tok->astOperand1(), tokToFind, found, depth);
7579
if (res == -1)
@@ -111,8 +115,12 @@ template<class T, class OuputIterator, REQUIRES("T must be a Token class", std::
111115
static void astFlattenCopy(T* tok, const char* op, OuputIterator out, int depth = 100)
112116
{
113117
--depth;
114-
if (!tok || depth < 0)
115-
return; // TODO: add bailout message
118+
if (!tok)
119+
return;
120+
if (depth < 0) {
121+
tok->debugMsg("depthBailout", "maximum depth of astFlattenCopy() exceeded");
122+
return;
123+
}
116124
if (strcmp(tok->str().c_str(), op) == 0) {
117125
astFlattenCopy(tok->astOperand1(), op, out, depth);
118126
astFlattenCopy(tok->astOperand2(), op, out, depth);
@@ -139,8 +147,12 @@ std::vector<Token*> astFlatten(Token* tok, const char* op)
139147
nonneg int astCount(const Token* tok, const char* op, int depth)
140148
{
141149
--depth;
142-
if (!tok || depth < 0)
143-
return 0; // TODO: add bailout message
150+
if (!tok)
151+
return 0;
152+
if (depth < 0) {
153+
tok->debugMsg("depthBailout", "maixmum depth of astCount() excedded");
154+
return 0;
155+
}
144156
if (strcmp(tok->str().c_str(), op) == 0)
145157
return astCount(tok->astOperand1(), op, depth) + astCount(tok->astOperand2(), op, depth);
146158
return 1;
@@ -1127,10 +1139,11 @@ bool exprDependsOnThis(const Token* expr, bool onVar, nonneg int depth)
11271139
return false;
11281140
if (expr->str() == "this")
11291141
return true;
1130-
if (depth >= 1000)
1142+
if (depth >= 1000) {
11311143
// Abort recursion to avoid stack overflow
1132-
// TODO: add bailout message
1144+
expr->debugMsg("depthBailout", "maximum depth of exprDependsOnThis() exceeded");
11331145
return true;
1146+
}
11341147
++depth;
11351148

11361149
// calling nonstatic method?
@@ -1274,7 +1287,7 @@ static SmallVector<ReferenceToken> followAllReferencesInternal(const Token* tok,
12741287
if (!tok)
12751288
return {};
12761289
if (depth < 0) {
1277-
// TODO: add bailout message
1290+
tok->debugMsg("depthBailout", "maximum depth of followAllReferencesInternal() exceeded");
12781291
SmallVector<ReferenceToken> refs_result;
12791292
refs_result.emplace_back(tok, std::move(errors));
12801293
return refs_result;
@@ -2932,8 +2945,10 @@ static bool isExpressionChangedAt(const F& getExprTok,
29322945
const Settings& settings,
29332946
int depth)
29342947
{
2935-
if (depth < 0)
2936-
return true; // TODO: add bailout message
2948+
if (depth < 0) {
2949+
tok->debugMsg("depthBailout", "maximum depth of isExpressionChangedAt() exceeded");
2950+
return true;
2951+
}
29372952
if (!tok)
29382953
return false;
29392954
if (!tok->isMutableExpr())
@@ -2991,8 +3006,10 @@ Token* findVariableChanged(Token *start, const Token *end, int indirect, const n
29913006
{
29923007
if (!precedes(start, end))
29933008
return nullptr;
2994-
if (depth < 0)
2995-
return start; // TODO: add bailout message
3009+
if (depth < 0) {
3010+
start->debugMsg("depthBailout", "maximum depth of findVariableChanged() exceeded");
3011+
return start;
3012+
}
29963013
auto getExprTok = utils::memoize([&] {
29973014
return findExpression(start, exprid);
29983015
});
@@ -3090,8 +3107,10 @@ static const Token* findExpressionChangedImpl(const Token* expr,
30903107
int depth,
30913108
Find find)
30923109
{
3093-
if (depth < 0)
3094-
return start; // TODO: add bailout message
3110+
if (depth < 0) {
3111+
expr->debugMsg("depthBailout", "maxmimum depth of findExpressionChangedImpl() exceeded");
3112+
return start;
3113+
}
30953114
if (!precedes(start, end))
30963115
return nullptr;
30973116
const Token* result = nullptr;

0 commit comments

Comments
 (0)