Support varids in nested classes that are declared outside of outer class (#7127)
This commit is contained in:
parent
595f1e1a27
commit
f9bc229d4b
|
@ -2882,7 +2882,11 @@ void Tokenizer::setVarId()
|
|||
if (!isC()) {
|
||||
for (Token *tok2 = list.front(); tok2; tok2 = tok2->next()) {
|
||||
if (Token::Match(tok2, "%name% :: %name%")) {
|
||||
const std::string& str3 = tok2->strAt(3);
|
||||
const Token* tok3 = tok2->next();
|
||||
do {
|
||||
tok3 = tok3->tokAt(2);
|
||||
} while (Token::Match(tok3, ":: %name%"));
|
||||
const std::string& str3 = tok3->str();
|
||||
if (str3 == "(")
|
||||
allMemberFunctions.push_back(tok2);
|
||||
else if (str3 != "::" && tok2->strAt(-1) != "::") // Support only one depth
|
||||
|
@ -2894,10 +2898,17 @@ void Tokenizer::setVarId()
|
|||
// class members..
|
||||
std::map<std::string, std::map<std::string, unsigned int> > varsByClass;
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "namespace|class|struct %name% {|:")) {
|
||||
const std::string &classname(tok->next()->str());
|
||||
std::map<std::string, unsigned int>& thisClassVars = varsByClass[classname];
|
||||
if (Token::Match(tok, "namespace|class|struct %name% {|:|::")) {
|
||||
std::string classname(tok->next()->str());
|
||||
const Token* tokStart = tok->tokAt(2);
|
||||
unsigned int nestedCount = 1;
|
||||
while (Token::Match(tokStart, ":: %name%")) {
|
||||
classname += " :: " + tokStart->strAt(1);
|
||||
tokStart = tokStart->tokAt(2);
|
||||
nestedCount++;
|
||||
}
|
||||
|
||||
std::map<std::string, unsigned int>& thisClassVars = varsByClass[classname];
|
||||
while (tokStart && tokStart->str() != "{") {
|
||||
if (Token::Match(tokStart, "public|private|protected %name%"))
|
||||
tokStart = tokStart->next();
|
||||
|
@ -2951,7 +2962,7 @@ void Tokenizer::setVarId()
|
|||
// Found a class function..
|
||||
if (Token::Match(tok2, funcpattern.c_str())) {
|
||||
// Goto the end parentheses..
|
||||
tok2 = tok2->linkAt(3);
|
||||
tok2 = tok2->linkAt(nestedCount*2+1);
|
||||
if (!tok2)
|
||||
break;
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ private:
|
|||
TEST_CASE(varid_in_class15); // #5533 - functions
|
||||
TEST_CASE(varid_in_class16);
|
||||
TEST_CASE(varid_in_class17); // #6056 - no varid for member functions
|
||||
TEST_CASE(varid_in_class18); // #7127
|
||||
TEST_CASE(varid_initList);
|
||||
TEST_CASE(varid_initListWithBaseTemplate);
|
||||
TEST_CASE(varid_operator);
|
||||
|
@ -1740,6 +1741,30 @@ private:
|
|||
"5: SomeType someVar4@4 ( new bar ) ;\n", tokenize(code2, false, "test.cpp"));
|
||||
}
|
||||
|
||||
void varid_in_class18() {
|
||||
const char code[] = "class A {\n"
|
||||
" class B;\n"
|
||||
"};\n"
|
||||
"class A::B {\n"
|
||||
" B();\n"
|
||||
" int* i;\n"
|
||||
"};\n"
|
||||
"A::B::B() :\n"
|
||||
" i(0)\n"
|
||||
"{}";
|
||||
ASSERT_EQUALS("\n\n##file 0\n"
|
||||
"1: class A {\n"
|
||||
"2: class B ;\n"
|
||||
"3: } ;\n"
|
||||
"4: class A :: B {\n"
|
||||
"5: B ( ) ;\n"
|
||||
"6: int * i@1 ;\n"
|
||||
"7: } ;\n"
|
||||
"8: A :: B :: B ( ) :\n"
|
||||
"9: i@1 ( 0 )\n"
|
||||
"10: { }\n", tokenize(code, false, "test.cpp"));
|
||||
}
|
||||
|
||||
void varid_initList() {
|
||||
const char code1[] = "class A {\n"
|
||||
" A() : x(0) {}\n"
|
||||
|
|
Loading…
Reference in New Issue