MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / findExpressionStartEndTokens

Method findExpressionStartEndTokens

lib/token.cpp:1499–1539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1497}
1498
1499std::pair<const Token *, const Token *> Token::findExpressionStartEndTokens() const
1500{
1501 const Token * const top = this;
1502
1503 // find start node in AST tree
1504 const Token *start = top;
1505 while (start->astOperand1() && precedes(start->astOperand1(), start))
1506 start = start->astOperand1();
1507
1508 // find end node in AST tree
1509 const Token *end = top;
1510 while (end->astOperand1() && (end->astOperand2() || end->isUnaryPreOp())) {
1511 // lambda..
1512 if (end->str() == "[") {
1513 const Token *lambdaEnd = findLambdaEndToken(end);
1514 if (lambdaEnd) {
1515 end = lambdaEnd;
1516 break;
1517 }
1518 }
1519 if (Token::Match(end,"(|[|{") &&
1520 !(Token::Match(end, "( ::| %type%") && !end->astOperand2())) {
1521 end = end->link();
1522 break;
1523 }
1524 end = end->astOperand2() ? end->astOperand2() : end->astOperand1();
1525 }
1526
1527 // skip parentheses
1528 start = goToLeftParenthesis(start, end);
1529 end = goToRightParenthesis(start, end);
1530 if (Token::simpleMatch(end, "{"))
1531 end = end->link();
1532
1533 if (precedes(top, start))
1534 throw InternalError(start, "Cannot find start of expression");
1535 if (succeeds(top, end))
1536 throw InternalError(end, "Cannot find end of expression");
1537
1538 return std::pair<const Token *, const Token *>(start,end);
1539}
1540
1541bool Token::isCalculation() const
1542{

Callers 9

checkRecursiveMethod · 0.80
checkBadBitmaskCheckMethod · 0.80
checkInnerScopeMethod · 0.80
getUnsafeFunctionFunction · 0.80
reentersLoopFunction · 0.80

Calls 10

precedesFunction · 0.85
findLambdaEndTokenFunction · 0.85
goToLeftParenthesisFunction · 0.85
goToRightParenthesisFunction · 0.85
succeedsFunction · 0.85
astOperand1Method · 0.80
astOperand2Method · 0.80
isUnaryPreOpMethod · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected