Merge pull request #257 from simartin/ticket_5373_2

Ticket #5373: delete can match %type% in C (take #2)
This commit is contained in:
Daniel Marjamäki 2014-03-09 08:26:06 +01:00
commit c7f09d4350
5 changed files with 25 additions and 3 deletions

View File

@ -29,6 +29,8 @@
#include <map>
#include <stack>
bool Token::_isCPP = true;
Token::Token(Token **t) :
tokensBack(t),
_next(0),
@ -600,7 +602,7 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
// Type (%type%)
{
p += 5;
multicompare(p,tok->isName() && tok->varId() == 0 && tok->str() != "delete",ismulticomp);
multicompare(p, tok->isName() && tok->varId() == 0 && (tok->str() != "delete" || !Token::isCPP()), ismulticomp);
}
break;
case 'a':

View File

@ -679,6 +679,8 @@ private:
// original name like size_t
std::string _originalName;
static bool _isCPP;
public:
void astOperand1(Token *tok);
void astOperand2(Token *tok);
@ -728,6 +730,8 @@ public:
void printAst(bool verbose) const;
void printValueFlow() const;
static void isCPP(bool isCPP) { _isCPP = isCPP; }
static bool isCPP() { return _isCPP; }
};
/// @}

View File

@ -1589,6 +1589,8 @@ bool Tokenizer::tokenize(std::istream &code,
return false;
}
Token::isCPP(isCPP());
if (simplifyTokenList1()) {
createSymbolDatabase();

View File

@ -263,6 +263,7 @@ private:
TEST_CASE(varid53); // #4172 - Template instantiation: T<&functionName> list[4];
TEST_CASE(varid54); // hang
TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varid_cpp_keywords_in_c_code2); // #5373: varid=0 for argument called "delete"
TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2);
TEST_CASE(varidFunctionCall3);
@ -3985,6 +3986,19 @@ private:
ASSERT_EQUALS(expected, tokenizeDebugListing(code,false,"test.c"));
}
void varid_cpp_keywords_in_c_code2() { // #5373
const char code[] = "int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, "
"unsigned long bits, int wake, int delete, struct extent_state **cached_state, "
"gfp_t mask) {\n"
" struct extent_state *state;\n"
"}"
"int clear_extent_dirty() {\n"
" return clear_extent_bit(tree, start, end, EXTENT_DIRTY | EXTENT_DELALLOC | "
" EXTENT_DO_ACCOUNTING, 0, 0, NULL, mask);\n"
"}";
tokenizeDebugListing(code, false, "test.c");
}
void varidFunctionCall1() {
const std::string code("void f() {\n"
" int x;\n"

View File

@ -113,8 +113,8 @@ class MatchCompiler:
return '(tok->type()==Token::eString)'
elif tok == '%type%':
return (
'(tok->isName() && tok->varId()==0U && tok->str() != ' +
self._insertMatchStr('delete') + '/* delete */)'
'(tok->isName() && tok->varId()==0U && (tok->str() != ' +
self._insertMatchStr('delete') + '/* delete */ || !Token::isCPP()))'
)
elif tok == '%var%':
return 'tok->isName()'