Tokenizer::setVarIdNew : enable more testcases. better handling of unions and struct members.
This commit is contained in:
parent
a420a36606
commit
95dafd30dd
|
@ -2815,7 +2815,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
|
||||||
bool hasstruct = false; // Is there a "struct" or "class"?
|
bool hasstruct = false; // Is there a "struct" or "class"?
|
||||||
while (tok2) {
|
while (tok2) {
|
||||||
if (tok2->isName()) {
|
if (tok2->isName()) {
|
||||||
if (tok2->str() == "class" || tok2->str() == "struct") {
|
if (tok2->str() == "class" || tok2->str() == "struct" || tok2->str() == "union") {
|
||||||
hasstruct = true;
|
hasstruct = true;
|
||||||
} else if (!hasstruct && variableId.find(tok2->str()) != variableId.end()) {
|
} else if (!hasstruct && variableId.find(tok2->str()) != variableId.end()) {
|
||||||
++typeCount;
|
++typeCount;
|
||||||
|
@ -2861,6 +2861,7 @@ void Tokenizer::setVarIdNew()
|
||||||
// variable id
|
// variable id
|
||||||
_varId = 0;
|
_varId = 0;
|
||||||
std::map<std::string, unsigned int> variableId;
|
std::map<std::string, unsigned int> variableId;
|
||||||
|
std::map<unsigned int, std::map<std::string, unsigned int> > structMembers;
|
||||||
std::stack< std::map<std::string, unsigned int> > scopeInfo;
|
std::stack< std::map<std::string, unsigned int> > scopeInfo;
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
|
|
||||||
|
@ -2906,8 +2907,34 @@ void Tokenizer::setVarIdNew()
|
||||||
|
|
||||||
if (tok->isName()) {
|
if (tok->isName()) {
|
||||||
const std::map<std::string, unsigned int>::const_iterator it = variableId.find(tok->str());
|
const std::map<std::string, unsigned int>::const_iterator it = variableId.find(tok->str());
|
||||||
if (it != variableId.end())
|
if (it != variableId.end()) {
|
||||||
tok->varId(it->second);
|
tok->varId(it->second);
|
||||||
|
while (Token::Match(tok->next(), ". %var% !!(")) {
|
||||||
|
const unsigned int struct_varid = it->second;
|
||||||
|
tok = tok->tokAt(2);
|
||||||
|
if (struct_varid == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::map<unsigned int, std::map<std::string,unsigned int> >::iterator structIterator;
|
||||||
|
structIterator = structMembers.find(struct_varid);
|
||||||
|
if (structIterator == structMembers.end()) {
|
||||||
|
std::map<std::string,unsigned int> members;
|
||||||
|
members[tok->str()] = ++_varId;
|
||||||
|
structMembers[struct_varid] = members;
|
||||||
|
tok->varId(_varId);
|
||||||
|
} else {
|
||||||
|
std::map<std::string,unsigned int> &members = structIterator->second;
|
||||||
|
std::map<std::string,unsigned int>::const_iterator memberIterator;
|
||||||
|
memberIterator = members.find(tok->str());
|
||||||
|
if (memberIterator == members.end()) {
|
||||||
|
members[tok->str()] = ++_varId;
|
||||||
|
tok->varId(_varId);
|
||||||
|
} else {
|
||||||
|
tok->varId(memberIterator->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (Token::Match(tok, "::|. %var%")) {
|
} else if (Token::Match(tok, "::|. %var%")) {
|
||||||
// Don't set varid after a :: or . token
|
// Don't set varid after a :: or . token
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
|
@ -2585,7 +2585,7 @@ private:
|
||||||
" struct ABC abc;\n"
|
" struct ABC abc;\n"
|
||||||
" abc.a = 3;\n"
|
" abc.a = 3;\n"
|
||||||
" i = abc.a;\n"
|
" i = abc.a;\n"
|
||||||
"}\n");
|
"}\n", false, "test.c");
|
||||||
|
|
||||||
const std::string expected("\n\n##file 0\n"
|
const std::string expected("\n\n##file 0\n"
|
||||||
"1: void f ( )\n"
|
"1: void f ( )\n"
|
||||||
|
@ -3083,7 +3083,7 @@ private:
|
||||||
"3: EventPtr event@3 ; event@3 = * eventP@1 ;\n"
|
"3: EventPtr event@3 ; event@3 = * eventP@1 ;\n"
|
||||||
"4: * actionsP@2 = & event@3 . actions@4 ;\n"
|
"4: * actionsP@2 = & event@3 . actions@4 ;\n"
|
||||||
"5: }\n");
|
"5: }\n");
|
||||||
ASSERT_EQUALS(expected1, tokenizeDebugListing(code1));
|
ASSERT_EQUALS(expected1, tokenizeDebugListing(code1, false, "test.c"));
|
||||||
|
|
||||||
const std::string code2("void f(int b, int c) {\n"
|
const std::string code2("void f(int b, int c) {\n"
|
||||||
" x(a*b*c,10);\n"
|
" x(a*b*c,10);\n"
|
||||||
|
@ -3228,12 +3228,12 @@ private:
|
||||||
const std::string code1("union evt; void f(const evt & event);");
|
const std::string code1("union evt; void f(const evt & event);");
|
||||||
ASSERT_EQUALS("\n\n##file 0\n"
|
ASSERT_EQUALS("\n\n##file 0\n"
|
||||||
"1: union evt ; void f ( const evt & event@1 ) ;\n",
|
"1: union evt ; void f ( const evt & event@1 ) ;\n",
|
||||||
tokenizeDebugListing(code1));
|
tokenizeDebugListing(code1, false, "test.c"));
|
||||||
|
|
||||||
const std::string code2("struct evt; void f(const evt & event);");
|
const std::string code2("struct evt; void f(const evt & event);");
|
||||||
ASSERT_EQUALS("\n\n##file 0\n"
|
ASSERT_EQUALS("\n\n##file 0\n"
|
||||||
"1: struct evt ; void f ( const evt & event@1 ) ;\n",
|
"1: struct evt ; void f ( const evt & event@1 ) ;\n",
|
||||||
tokenizeDebugListing(code2));
|
tokenizeDebugListing(code2, false, "test.c"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void varid42() {
|
void varid42() {
|
||||||
|
|
Loading…
Reference in New Issue