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

Method createTokensFunctionDecl

lib/clangimport.cpp:1365–1484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1363}
1364
1365void clangimport::AstNode::createTokensFunctionDecl(TokenList &tokenList)
1366{
1367 const bool prev = contains(mExtTokens, "prev");
1368 const bool hasBody = !children.empty() && children.back()->nodeType == CompoundStmt;
1369 const bool isStatic = contains(mExtTokens, "static");
1370 const bool isInline = contains(mExtTokens, "inline");
1371
1372 const Token *startToken = nullptr;
1373
1374 SymbolDatabase &symbolDatabase = mData->mSymbolDatabase;
1375 if (nodeType != CXXConstructorDecl && nodeType != CXXDestructorDecl) {
1376 if (isStatic)
1377 addtoken(tokenList, "static");
1378 if (isInline)
1379 addtoken(tokenList, "inline");
1380 const Token * const before = tokenList.back();
1381 addTypeTokens(tokenList, '\'' + getType() + '\'');
1382 startToken = before ? before->next() : tokenList.front();
1383 }
1384
1385 if (mExtTokens.size() > 4 && mExtTokens[1] == "parent")
1386 addFullScopeNameTokens(tokenList, mData->getScope(mExtTokens[2]));
1387
1388 Token *nameToken = addtoken(tokenList, getSpelling() + getTemplateParameters());
1389 auto *nestedIn = const_cast<Scope *>(nameToken->scope());
1390
1391 if (prev) {
1392 const std::string addr = *(std::find(mExtTokens.cbegin(), mExtTokens.cend(), "prev") + 1);
1393 mData->ref(addr, nameToken);
1394 }
1395 if (!nameToken->function()) {
1396 nestedIn->functionList.emplace_back(nameToken, unquote(getFullType()));
1397 mData->funcDecl(mExtTokens.front(), nameToken, &nestedIn->functionList.back());
1398 if (nodeType == CXXConstructorDecl)
1399 nestedIn->functionList.back().type = FunctionType::eConstructor;
1400 else if (nodeType == CXXDestructorDecl)
1401 nestedIn->functionList.back().type = FunctionType::eDestructor;
1402 else
1403 nestedIn->functionList.back().retDef = startToken;
1404 }
1405
1406 auto * const function = const_cast<Function*>(nameToken->function());
1407
1408 if (!prev) {
1409 auto accessControl = mData->scopeAccessControl.find(tokenList.back()->scope());
1410 if (accessControl != mData->scopeAccessControl.end())
1411 function->access = accessControl->second;
1412 }
1413
1414 Scope *scope = nullptr;
1415 if (hasBody) {
1416 symbolDatabase.scopeList.emplace_back(symbolDatabase, nullptr, nestedIn);
1417 scope = &symbolDatabase.scopeList.back();
1418 scope->function = function;
1419 scope->classDef = nameToken; // TODO: pass into ctor
1420 scope->type = ScopeType::eFunction;
1421 scope->className = nameToken->str();
1422 nestedIn->nestedList.push_back(scope);

Callers

nothing calls this directly

Calls 15

containsFunction · 0.85
nextMethod · 0.80
frontMethod · 0.80
getScopeMethod · 0.80
scopeMethod · 0.80
funcDeclMethod · 0.80
getSpellingMethod · 0.80
varDeclMethod · 0.80
isConstMethod · 0.80
unquoteFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected