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

Method createLinks2

lib/tokenize.cpp:5532–5648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5530}
5531
5532void Tokenizer::createLinks2()
5533{
5534 if (isC())
5535 return;
5536
5537 bool isStruct = false;
5538
5539 std::stack<Token*> type;
5540 std::stack<Token*> templateTokens;
5541 for (Token *token = list.front(); token; token = token->next()) {
5542 if (Token::Match(token, "%name%|> %name% [:<]"))
5543 isStruct = true;
5544 else if (Token::Match(token, "[;{}]"))
5545 isStruct = false;
5546
5547 if (token->link()) {
5548 if (Token::Match(token, "{|[|("))
5549 type.push(token);
5550 else if (!type.empty() && Token::Match(token, "}|]|)")) {
5551 while (type.top()->str() == "<") {
5552 if (!templateTokens.empty() && templateTokens.top()->next() == type.top())
5553 templateTokens.pop();
5554 type.pop();
5555 }
5556 type.pop();
5557 }
5558 } else if (templateTokens.empty() && !isStruct && Token::Match(token, "%oror%|&&|;")) {
5559 if (Token::Match(token, "&& [,>]"))
5560 continue;
5561 // If there is some such code: A<B||C>..
5562 // Then this is probably a template instantiation if either "B" or "C" has comparisons
5563 if (token->tokType() == Token::eLogicalOp && !type.empty() && type.top()->str() == "<") {
5564 const Token *prev = token->previous();
5565 bool foundComparison = false;
5566 while (Token::Match(prev, "%name%|%num%|%str%|%cop%|)|]") && prev != type.top()) {
5567 if (prev->str() == ")" || prev->str() == "]")
5568 prev = prev->link();
5569 else if (prev->tokType() == Token::eLogicalOp)
5570 break;
5571 else if (prev->isComparisonOp())
5572 foundComparison = true;
5573 prev = prev->previous();
5574 }
5575 if (prev == type.top() && foundComparison)
5576 continue;
5577 const Token *next = token->next();
5578 foundComparison = false;
5579 while (Token::Match(next, "%name%|%num%|%str%|%cop%|(|[") && next->str() != ">") {
5580 if (next->str() == "(" || next->str() == "[")
5581 next = next->link();
5582 else if (next->tokType() == Token::eLogicalOp)
5583 break;
5584 else if (next->isComparisonOp())
5585 foundComparison = true;
5586 next = next->next();
5587 }
5588 if (next && next->str() == ">" && foundComparison)
5589 continue;

Callers

nothing calls this directly

Calls 10

frontMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
isCFunction · 0.70
emptyMethod · 0.45
strMethod · 0.45
findClosingBracketMethod · 0.45
tokAtMethod · 0.45
isKeywordMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected