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

Method addTypeTokens

lib/clangimport.cpp:600–653  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

598}
599
600const ::Type * clangimport::AstNode::addTypeTokens(TokenList &tokenList, const std::string &str, const Scope *scope)
601{
602 if (str.find("\':\'") != std::string::npos) {
603 return addTypeTokens(tokenList, str.substr(0, str.find("\':\'") + 1), scope);
604 }
605
606 if (startsWith(str, "'enum (anonymous"))
607 return nullptr;
608
609 std::string type;
610 if (str.find(" (") != std::string::npos) {
611 if (str.find('<') != std::string::npos)
612 type = str.substr(1, str.find('<')) + "...>";
613 else
614 type = str.substr(1,str.find(" (")-1);
615 } else
616 type = unquote(str);
617
618 if (type.find("(*)(") != std::string::npos) {
619 type.erase(type.find("(*)("));
620 type += "*";
621 }
622 if (type.find('(') != std::string::npos)
623 type.erase(type.find('('));
624
625 // TODO: put in a helper?
626 std::stack<Token *> lpar;
627 for (const std::string &s: splitString(type)) {
628 Token *tok = addtoken(tokenList, s, false);
629 if (tok->str() == "(")
630 lpar.push(tok);
631 else if (tok->str() == ")") {
632 Token::createMutualLinks(tok, lpar.top());
633 lpar.pop();
634 }
635 }
636
637 // Set Type
638 if (!scope) {
639 scope = tokenList.back() ? tokenList.back()->scope() : nullptr;
640 if (!scope)
641 return nullptr;
642 }
643 for (const Token *typeToken = tokenList.back(); Token::Match(typeToken, "&|*|%name%"); typeToken = typeToken->previous()) {
644 if (!typeToken->isName())
645 continue;
646 const ::Type *recordType = scope->symdb.findVariableType(scope, typeToken);
647 if (recordType) {
648 const_cast<Token*>(typeToken)->type(recordType);
649 return recordType;
650 }
651 }
652 return nullptr;
653}
654
655void clangimport::AstNode::addFullScopeNameTokens(TokenList &tokenList, const Scope *recordScope)
656{

Callers

nothing calls this directly

Calls 9

scopeMethod · 0.80
findVariableTypeMethod · 0.80
typeMethod · 0.80
startsWithFunction · 0.70
unquoteFunction · 0.70
splitStringFunction · 0.70
findMethod · 0.45
eraseMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected