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

Method createTokensForCXXRecord

lib/clangimport.cpp:1486–1529  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1484}
1485
1486void clangimport::AstNode::createTokensForCXXRecord(TokenList &tokenList)
1487{
1488 const bool isStruct = contains(mExtTokens, "struct");
1489 Token * const classToken = addtoken(tokenList, isStruct ? "struct" : "class");
1490 std::string className;
1491 if (mExtTokens[mExtTokens.size() - 2] == (isStruct?"struct":"class"))
1492 className = mExtTokens.back();
1493 else
1494 className = mExtTokens[mExtTokens.size() - 2];
1495 className += getTemplateParameters();
1496 /*Token *nameToken =*/ addtoken(tokenList, className);
1497 // base classes
1498 bool firstBase = true;
1499 for (const AstNodePtr &child: children) {
1500 if (child->nodeType == "public" || child->nodeType == "protected" || child->nodeType == "private") {
1501 addtoken(tokenList, firstBase ? ":" : ",");
1502 addtoken(tokenList, child->nodeType);
1503 addtoken(tokenList, unquote(child->mExtTokens.back()));
1504 firstBase = false;
1505 }
1506 }
1507 // definition
1508 if (isDefinition()) {
1509 std::vector<AstNodePtr> children2;
1510 std::copy_if(children.cbegin(), children.cend(), std::back_inserter(children2), [](const AstNodePtr& child) {
1511 return child->nodeType == CXXConstructorDecl ||
1512 child->nodeType == CXXDestructorDecl ||
1513 child->nodeType == CXXMethodDecl ||
1514 child->nodeType == FieldDecl ||
1515 child->nodeType == VarDecl ||
1516 child->nodeType == AccessSpecDecl ||
1517 child->nodeType == TypedefDecl;
1518 });
1519 Scope *scope = createScope(tokenList, isStruct ? ScopeType::eStruct : ScopeType::eClass, children2, classToken);
1520 const std::string addr = mExtTokens[0];
1521 mData->scopeDecl(addr, scope);
1522 scope->className = className;
1523 mData->mSymbolDatabase.typeList.emplace_back(classToken, scope, classToken->scope());
1524 scope->definedType = &mData->mSymbolDatabase.typeList.back();
1525 const_cast<Scope *>(classToken->scope())->definedTypesMap[className] = scope->definedType;
1526 }
1527 addtoken(tokenList, ";");
1528 tokenList.back()->scope(classToken->scope());
1529}
1530
1531Token * clangimport::AstNode::createTokensVarDecl(TokenList &tokenList)
1532{

Callers

nothing calls this directly

Calls 5

containsFunction · 0.85
scopeDeclMethod · 0.80
scopeMethod · 0.80
unquoteFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected