SymbolDatabase: New scope type eLambda
This commit is contained in:
parent
bfa788a329
commit
862b18e0e2
|
@ -756,7 +756,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
scopeList.push_back(Scope(this, tok, scope, Scope::eWhile, tok1));
|
scopeList.push_back(Scope(this, tok, scope, Scope::eWhile, tok1));
|
||||||
else if (tok->str() == "catch") {
|
else if (tok->str() == "catch") {
|
||||||
scopeList.push_back(Scope(this, tok, scope, Scope::eCatch, tok1));
|
scopeList.push_back(Scope(this, tok, scope, Scope::eCatch, tok1));
|
||||||
} else if (tok->str() == "switch")
|
} else // if (tok->str() == "switch")
|
||||||
scopeList.push_back(Scope(this, tok, scope, Scope::eSwitch, tok1));
|
scopeList.push_back(Scope(this, tok, scope, Scope::eSwitch, tok1));
|
||||||
|
|
||||||
scope->nestedList.push_back(&scopeList.back());
|
scope->nestedList.push_back(&scopeList.back());
|
||||||
|
@ -767,7 +767,11 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
scope->checkVariable(tok->tokAt(2), Throw); // check for variable declaration and add it to new scope if found
|
scope->checkVariable(tok->tokAt(2), Throw); // check for variable declaration and add it to new scope if found
|
||||||
tok = tok1;
|
tok = tok1;
|
||||||
} else if (tok->str() == "{" && !tok->previous()->varId()) {
|
} else if (tok->str() == "{" && !tok->previous()->varId()) {
|
||||||
if (!Token::Match(tok->previous(), "=|,")) {
|
if (tok->strAt(-1) == ")" && tok->linkAt(-1)->strAt(-1) == "]") {
|
||||||
|
scopeList.push_back(Scope(this, tok->linkAt(-1)->linkAt(-1), scope, Scope::eLambda, tok));
|
||||||
|
scope->nestedList.push_back(&scopeList.back());
|
||||||
|
scope = &scopeList.back();
|
||||||
|
} else if (!Token::Match(tok->previous(), "=|,")) {
|
||||||
scopeList.push_back(Scope(this, tok, scope, Scope::eUnconditional, tok));
|
scopeList.push_back(Scope(this, tok, scope, Scope::eUnconditional, tok));
|
||||||
scope->nestedList.push_back(&scopeList.back());
|
scope->nestedList.push_back(&scopeList.back());
|
||||||
scope = &scopeList.back();
|
scope = &scopeList.back();
|
||||||
|
@ -1798,6 +1802,7 @@ static std::ostream & operator << (std::ostream & s, Scope::ScopeType type)
|
||||||
type == Scope::eTry ? "Try" :
|
type == Scope::eTry ? "Try" :
|
||||||
type == Scope::eCatch ? "Catch" :
|
type == Scope::eCatch ? "Catch" :
|
||||||
type == Scope::eUnconditional ? "Unconditional" :
|
type == Scope::eUnconditional ? "Unconditional" :
|
||||||
|
type == Scope::eLambda ? "Lambda" :
|
||||||
"Unknown");
|
"Unknown");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -656,7 +656,7 @@ public:
|
||||||
const Scope *scope;
|
const Scope *scope;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ScopeType { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction, eIf, eElse, eFor, eWhile, eDo, eSwitch, eUnconditional, eTry, eCatch };
|
enum ScopeType { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction, eIf, eElse, eFor, eWhile, eDo, eSwitch, eUnconditional, eTry, eCatch, eLambda };
|
||||||
|
|
||||||
Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_);
|
Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_);
|
||||||
Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_);
|
Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_);
|
||||||
|
|
|
@ -250,6 +250,8 @@ private:
|
||||||
TEST_CASE(varTypesOther); // (un)known
|
TEST_CASE(varTypesOther); // (un)known
|
||||||
|
|
||||||
TEST_CASE(functionPrototype); // ticket #5867
|
TEST_CASE(functionPrototype); // ticket #5867
|
||||||
|
|
||||||
|
TEST_CASE(lambda); // ticket #5867
|
||||||
}
|
}
|
||||||
|
|
||||||
void array() const {
|
void array() const {
|
||||||
|
@ -2469,6 +2471,28 @@ private:
|
||||||
"}\n", true);
|
"}\n", true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lambda() {
|
||||||
|
GET_SYMBOL_DB("void func() {\n"
|
||||||
|
" float y = 0.0f;\n"
|
||||||
|
" auto lambda = [&]()\n"
|
||||||
|
" {\n"
|
||||||
|
" float x = 1.0f;\n"
|
||||||
|
" y += 10.0f - x;\n"
|
||||||
|
" }\n"
|
||||||
|
" lambda();\n"
|
||||||
|
"}");
|
||||||
|
|
||||||
|
ASSERT(db && db->scopeList.size() == 3);
|
||||||
|
if (db && db->scopeList.size() == 3) {
|
||||||
|
std::list<Scope>::const_iterator scope = db->scopeList.begin();
|
||||||
|
ASSERT_EQUALS(Scope::eGlobal, scope->type);
|
||||||
|
++scope;
|
||||||
|
ASSERT_EQUALS(Scope::eFunction, scope->type);
|
||||||
|
++scope;
|
||||||
|
ASSERT_EQUALS(Scope::eLambda, scope->type);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestSymbolDatabase)
|
REGISTER_TEST(TestSymbolDatabase)
|
||||||
|
|
Loading…
Reference in New Issue