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

Method evaluate

lib/symboldatabase.cpp:2539–2649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2537}
2538
2539void Variable::evaluate(const Settings& settings)
2540{
2541 // Is there initialization in variable declaration
2542 const Token *initTok = mNameToken ? mNameToken->next() : nullptr;
2543 while (Token::Match(initTok, "[")) {
2544 initTok = initTok->link()->next();
2545 if (Token::simpleMatch(initTok, ")"))
2546 initTok = initTok->next();
2547 }
2548 if (Token::Match(initTok, "[={(]") || (initTok && initTok->isSplittedVarDeclEq()))
2549 setFlag(fIsInit, true);
2550
2551 const Library & lib = settings.library;
2552
2553 bool isContainer = false;
2554 if (mNameToken) {
2555 setFlag(fIsArray, arrayDimensions(settings, isContainer));
2556 setFlag(fIsMaybeUnused, mNameToken->isAttributeMaybeUnused());
2557 }
2558
2559
2560 if (mTypeStartToken)
2561 setValueType(ValueType::parseDecl(mTypeStartToken,settings));
2562
2563 const Token* tok = mTypeStartToken;
2564 while (tok && tok->previous() && tok->previous()->isName())
2565 tok = tok->previous();
2566 const Token* end = mTypeEndToken;
2567 if (end)
2568 end = end->next();
2569 while (tok != end) {
2570 if (tok->str() == "static")
2571 setFlag(fIsStatic, true);
2572 else if (tok->str() == "extern")
2573 setFlag(fIsExtern, true);
2574 else if (tok->str() == "volatile" || Token::simpleMatch(tok, "std :: atomic <"))
2575 setFlag(fIsVolatile, true);
2576 else if (tok->str() == "mutable")
2577 setFlag(fIsMutable, true);
2578 else if (tok->str() == "const")
2579 setFlag(fIsConst, true);
2580 else if (tok->str() == "constexpr") {
2581 setFlag(fIsConst, true);
2582 setFlag(fIsStatic, true);
2583 } else if (tok->str() == "*") {
2584 setFlag(fIsPointer, !isArray() || (isContainer && !Token::Match(tok->next(), "%name% [")) || Token::Match(tok, "* const| %name% )"));
2585 setFlag(fIsConst, false); // Points to const, isn't necessarily const itself
2586 } else if (tok->str() == "&") {
2587 if (isReference())
2588 setFlag(fIsRValueRef, true);
2589 setFlag(fIsReference, true);
2590 } else if (tok->str() == "&&") { // Before simplification, && isn't split up
2591 setFlag(fIsRValueRef, true);
2592 setFlag(fIsReference, true); // Set also fIsReference
2593 }
2594
2595 if (tok->str() == "<" && tok->link())
2596 tok = tok->link();

Callers 3

evalCondMethod · 0.80
evalCondFunction · 0.80
updateRangeFunction · 0.80

Calls 13

isArrayFunction · 0.85
isReferenceFunction · 0.85
isPointerFunction · 0.85
nextMethod · 0.80
isSmartPointerMethod · 0.80
simpleMatchFunction · 0.70
setFlagFunction · 0.70
isEnumTypeFunction · 0.70
isStlStringTypeFunction · 0.70
strMethod · 0.45
tokAtMethod · 0.45
podtypeMethod · 0.45

Tested by

no test coverage detected