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

Method addEnum

lib/symboldatabase.cpp:5410–5485  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5408}
5409
5410const Token * Scope::addEnum(const Token * tok)
5411{
5412 const Token * tok2 = tok->next();
5413
5414 // skip over class if present
5415 if (tok2->isCpp() && tok2->str() == "class")
5416 tok2 = tok2->next();
5417
5418 // skip over name
5419 tok2 = tok2->next();
5420
5421 // save type if present
5422 if (tok2->str() == ":") {
5423 tok2 = tok2->next();
5424
5425 enumType = tok2;
5426 while (Token::Match(tok2, "%name%|::"))
5427 tok2 = tok2->next();
5428 }
5429
5430 // add enumerators
5431 if (tok2->str() == "{") {
5432 const Token * end = tok2->link();
5433 tok2 = tok2->next();
5434
5435 while (Token::Match(tok2, "%name% =|,|}") ||
5436 (Token::Match(tok2, "%name% (") && Token::Match(tok2->linkAt(1), ") ,|}"))) {
5437 Enumerator enumerator(this);
5438
5439 // save enumerator name
5440 enumerator.name = tok2;
5441
5442 // skip over name
5443 tok2 = tok2->next();
5444
5445 if (tok2->str() == "=") {
5446 // skip over "="
5447 tok2 = tok2->next();
5448
5449 if (tok2->str() == "}")
5450 return nullptr;
5451
5452 enumerator.start = tok2;
5453
5454 while (!Token::Match(tok2, ",|}")) {
5455 if (tok2->link())
5456 tok2 = tok2->link();
5457 enumerator.end = tok2;
5458 tok2 = tok2->next();
5459 }
5460 } else if (tok2->str() == "(") {
5461 // skip over unknown macro
5462 tok2 = tok2->link()->next();
5463 }
5464
5465 if (tok2->str() == ",") {
5466 enumeratorList.push_back(enumerator);
5467 tok2 = tok2->next();

Callers 1

Calls 4

nextMethod · 0.80
linkAtMethod · 0.80
strMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected