Fix another Borlad-specific test by setting Windows platform type

Refactoring: make CheckIO::ArgumentInfo aware of language (C vs. C++) to perform some optimizations
This commit is contained in:
amai2012 2015-06-16 23:11:34 +02:00
parent a8db00b4bf
commit 33d7631ee3
3 changed files with 15 additions and 10 deletions

View File

@ -685,7 +685,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
} }
// Perform type checks // Perform type checks
ArgumentInfo argInfo(argListTok, _settings); ArgumentInfo argInfo(argListTok, _settings, _tokenizer->isCPP());
if (argInfo.typeToken && !argInfo.isLibraryType(_settings)) { if (argInfo.typeToken && !argInfo.isLibraryType(_settings)) {
if (scan) { if (scan) {
@ -1375,7 +1375,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
// We currently only support string literals, variables, and functions. // We currently only support string literals, variables, and functions.
/// @todo add non-string literals, and generic expressions /// @todo add non-string literals, and generic expressions
CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings) CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings, bool isCPP)
: variableInfo(0) : variableInfo(0)
, typeToken(0) , typeToken(0)
, functionInfo(0) , functionInfo(0)
@ -1383,6 +1383,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings)
, _template(false) , _template(false)
, address(false) , address(false)
, tempToken(0) , tempToken(0)
, isCPP(isCPP)
{ {
if (tok) { if (tok) {
if (tok->type() == Token::eString) { if (tok->type() == Token::eString) {
@ -1443,8 +1444,8 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings)
tok1 = tok1->link(); tok1 = tok1->link();
// check for some common well known functions // check for some common well known functions
else if ((Token::Match(tok1->previous(), "%var% . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous())) || else if (isCPP && ((Token::Match(tok1->previous(), "%var% . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous())) ||
(Token::Match(tok1->previous(), "] . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous()->link()->previous()))) { (Token::Match(tok1->previous(), "] . size|empty|c_str ( ) [,)]") && isStdContainer(tok1->previous()->link()->previous())))) {
tempToken = new Token(0); tempToken = new Token(0);
tempToken->fileIndex(tok1->fileIndex()); tempToken->fileIndex(tok1->fileIndex());
tempToken->linenr(tok1->linenr()); tempToken->linenr(tok1->linenr());
@ -1529,7 +1530,8 @@ namespace {
bool CheckIO::ArgumentInfo::isStdVectorOrString() bool CheckIO::ArgumentInfo::isStdVectorOrString()
{ {
if (!isCPP)
return false;
if (variableInfo->isStlType(stl_vector)) { if (variableInfo->isStlType(stl_vector)) {
typeToken = variableInfo->typeStartToken()->tokAt(4); typeToken = variableInfo->typeStartToken()->tokAt(4);
_template = true; _template = true;
@ -1593,7 +1595,8 @@ namespace {
bool CheckIO::ArgumentInfo::isStdContainer(const Token *tok) bool CheckIO::ArgumentInfo::isStdContainer(const Token *tok)
{ {
if (!isCPP)
return false;
if (tok && tok->variable()) { if (tok && tok->variable()) {
const Variable* variable = tok->variable(); const Variable* variable = tok->variable();
if (variable->isStlType(stl_container)) { if (variable->isStlType(stl_container)) {

View File

@ -70,7 +70,7 @@ public:
private: private:
class ArgumentInfo { class ArgumentInfo {
public: public:
ArgumentInfo(const Token *arg, const Settings *settings); ArgumentInfo(const Token *arg, const Settings *settings, bool isCPP);
~ArgumentInfo(); ~ArgumentInfo();
bool isArrayOrPointer() const; bool isArrayOrPointer() const;
@ -86,6 +86,7 @@ private:
bool element; bool element;
bool _template; bool _template;
bool address; bool address;
bool isCPP;
Token *tempToken; Token *tempToken;
private: private:

View File

@ -75,12 +75,13 @@ private:
} }
void check(const char code[]) { void check(const char code[], Settings::PlatformType platform = Settings::Unspecified) {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("style");
settings.platform(platform);
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
@ -517,7 +518,7 @@ private:
"public:\n" "public:\n"
" Foo() { }\n" " Foo() { }\n"
" __property int x = {read=getx}\n" " __property int x = {read=getx}\n"
"};"); "};", Settings::Win32A);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -530,7 +531,7 @@ private:
" }\n" " }\n"
"public:\n" "public:\n"
" Foo() { }\n" " Foo() { }\n"
"};"); "};", Settings::Win32A);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }