Tokenizer::setVarIdNew : use new setVarId function in TestTokenizer::varidReturn2.
This commit is contained in:
parent
95dafd30dd
commit
27c37896a0
|
@ -2863,13 +2863,20 @@ void Tokenizer::setVarIdNew()
|
||||||
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::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;
|
||||||
|
std::stack<bool> executableScope;
|
||||||
|
executableScope.push(false);
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
|
|
||||||
// scope info to handle shadow variables..
|
// scope info to handle shadow variables..
|
||||||
if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") {")) {
|
if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") {")) {
|
||||||
scopeInfo.push(variableId);
|
scopeInfo.push(variableId);
|
||||||
} else if (tok->str() == "{" && !Token::simpleMatch(tok->previous(), ")")) {
|
} else if (tok->str() == "{") {
|
||||||
|
if (Token::simpleMatch(tok->previous(), ")")) {
|
||||||
|
executableScope.push(true);
|
||||||
|
} else {
|
||||||
|
executableScope.push(executableScope.top());
|
||||||
scopeInfo.push(variableId);
|
scopeInfo.push(variableId);
|
||||||
|
}
|
||||||
} else if (tok->str() == "}") {
|
} else if (tok->str() == "}") {
|
||||||
if (scopeInfo.empty()) {
|
if (scopeInfo.empty()) {
|
||||||
variableId.clear();
|
variableId.clear();
|
||||||
|
@ -2877,9 +2884,15 @@ void Tokenizer::setVarIdNew()
|
||||||
variableId.swap(scopeInfo.top());
|
variableId.swap(scopeInfo.top());
|
||||||
scopeInfo.pop();
|
scopeInfo.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
executableScope.pop();
|
||||||
|
if (executableScope.empty()) { // should not possibly happen
|
||||||
|
executableScope.push(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok == _tokens || Token::Match(tok, "[;{}(,]")) {
|
if (tok == _tokens || Token::Match(tok, "[;{},]") ||
|
||||||
|
(tok->str()=="(" && (!executableScope.top() || Token::simpleMatch(tok->link(), ") {")))) {
|
||||||
// locate the variable name..
|
// locate the variable name..
|
||||||
const Token *tok2 = (tok == _tokens) ? tok : tok->next();
|
const Token *tok2 = (tok == _tokens) ? tok : tok->next();
|
||||||
if (!tok2)
|
if (!tok2)
|
||||||
|
@ -2896,7 +2909,7 @@ void Tokenizer::setVarIdNew()
|
||||||
tok = tok2->previous();
|
tok = tok2->previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decl && Token::Match(tok2->previous(), "%type% ( !!)")) {
|
else if (decl && Token::Match(tok2->previous(), "%type% ( !!)")) {
|
||||||
const Token *tok3 = tok2->next();
|
const Token *tok3 = tok2->next();
|
||||||
if (!setVarIdParseDeclaration(&tok3,variableId)) {
|
if (!setVarIdParseDeclaration(&tok3,variableId)) {
|
||||||
variableId[tok2->previous()->str()] = ++_varId;
|
variableId[tok2->previous()->str()] = ++_varId;
|
||||||
|
|
|
@ -2712,7 +2712,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" unsigned long mask = (1UL << size_) - 1;\n"
|
" unsigned long mask = (1UL << size_) - 1;\n"
|
||||||
" return (abits_val_ & mask);\n"
|
" return (abits_val_ & mask);\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 foo ( )\n"
|
"1: void foo ( )\n"
|
||||||
|
|
Loading…
Reference in New Issue