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
ArgumentInfo argInfo(argListTok, _settings);
ArgumentInfo argInfo(argListTok, _settings, _tokenizer->isCPP());
if (argInfo.typeToken && !argInfo.isLibraryType(_settings)) {
if (scan) {
@ -1375,7 +1375,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
// We currently only support string literals, variables, and functions.
/// @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)
, typeToken(0)
, functionInfo(0)
@ -1383,6 +1383,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings)
, _template(false)
, address(false)
, tempToken(0)
, isCPP(isCPP)
{
if (tok) {
if (tok->type() == Token::eString) {
@ -1443,8 +1444,8 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings)
tok1 = tok1->link();
// check for some common well known functions
else if ((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()))) {
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())))) {
tempToken = new Token(0);
tempToken->fileIndex(tok1->fileIndex());
tempToken->linenr(tok1->linenr());
@ -1529,7 +1530,8 @@ namespace {
bool CheckIO::ArgumentInfo::isStdVectorOrString()
{
if (!isCPP)
return false;
if (variableInfo->isStlType(stl_vector)) {
typeToken = variableInfo->typeStartToken()->tokAt(4);
_template = true;
@ -1593,7 +1595,8 @@ namespace {
bool CheckIO::ArgumentInfo::isStdContainer(const Token *tok)
{
if (!isCPP)
return false;
if (tok && tok->variable()) {
const Variable* variable = tok->variable();
if (variable->isStlType(stl_container)) {

View File

@ -70,7 +70,7 @@ public:
private:
class ArgumentInfo {
public:
ArgumentInfo(const Token *arg, const Settings *settings);
ArgumentInfo(const Token *arg, const Settings *settings, bool isCPP);
~ArgumentInfo();
bool isArrayOrPointer() const;
@ -86,6 +86,7 @@ private:
bool element;
bool _template;
bool address;
bool isCPP;
Token *tempToken;
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..
errout.str("");
Settings settings;
settings.addEnabled("style");
settings.platform(platform);
// Tokenize..
Tokenizer tokenizer(&settings, this);
@ -517,7 +518,7 @@ private:
"public:\n"
" Foo() { }\n"
" __property int x = {read=getx}\n"
"};");
"};", Settings::Win32A);
ASSERT_EQUALS("", errout.str());
}
@ -530,7 +531,7 @@ private:
" }\n"
"public:\n"
" Foo() { }\n"
"};");
"};", Settings::Win32A);
ASSERT_EQUALS("", errout.str());
}