Borland C++: Minor updates so cppcheck compiles with Borland C++

This commit is contained in:
Daniel Marjamäki 2008-11-24 07:35:03 +00:00
parent 895b1d5561
commit e0027bef66
2 changed files with 262 additions and 255 deletions

View File

@ -18,45 +18,45 @@
<CfgParent>Base</CfgParent> <CfgParent>Base</CfgParent>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''"> <PropertyGroup Condition="'$(Base)'!=''">
<OutputExt>exe</OutputExt>
<BCC_OptimizeForSpeed>true</BCC_OptimizeForSpeed> <BCC_OptimizeForSpeed>true</BCC_OptimizeForSpeed>
<Defines>NO_STRICT</Defines> <OutputExt>exe</OutputExt>
<DCC_CBuilderOutput>JPHNE</DCC_CBuilderOutput> <DCC_CBuilderOutput>JPHNE</DCC_CBuilderOutput>
<Defines>NO_STRICT</Defines>
<DynamicRTL>true</DynamicRTL> <DynamicRTL>true</DynamicRTL>
<ILINK_SelectedWarnings>false</ILINK_SelectedWarnings> <ILINK_SelectedWarnings>false</ILINK_SelectedWarnings>
<ILINK_ObjectSearchPath>C:\cppcheck</ILINK_ObjectSearchPath>
<ILINK_AllWarnings>true</ILINK_AllWarnings> <ILINK_AllWarnings>true</ILINK_AllWarnings>
<NoVCL>true</NoVCL> <ILINK_ObjectSearchPath>C:\cppcheck</ILINK_ObjectSearchPath>
<ProjectType>CppConsoleApplication</ProjectType> <ProjectType>CppConsoleApplication</ProjectType>
<NoVCL>true</NoVCL>
<BCC_SelectedWarnings>false</BCC_SelectedWarnings> <BCC_SelectedWarnings>false</BCC_SelectedWarnings>
<PackageImports>vcl.bpi;rtl.bpi;bcbie.bpi;vclx.bpi;vclactnband.bpi;xmlrtl.bpi;bcbsmp.bpi;dbrtl.bpi;vcldb.bpi;vcldbx.bpi;bdertl.bpi;A407_R110.bpi;DreamEdit_C6.bpi</PackageImports>
<DCC_UNSAFE_CAST>true</DCC_UNSAFE_CAST> <DCC_UNSAFE_CAST>true</DCC_UNSAFE_CAST>
<PackageImports>vcl.bpi;rtl.bpi;bcbie.bpi;vclx.bpi;vclactnband.bpi;xmlrtl.bpi;bcbsmp.bpi;dbrtl.bpi;vcldb.bpi;vcldbx.bpi;bdertl.bpi;A407_R110.bpi;DreamEdit_C6.bpi</PackageImports>
<BCC_AllWarnings>true</BCC_AllWarnings> <BCC_AllWarnings>true</BCC_AllWarnings>
<BCC_wpar>false</BCC_wpar> <BCC_wpar>false</BCC_wpar>
<IncludePath>$(BDS)\include;$(BDS)\include\dinkumware;$(BDS)\include\vcl;C:\cppcheck</IncludePath> <IncludePath>$(BDS)\include;$(BDS)\include\dinkumware;$(BDS)\include\vcl;C:\cppcheck</IncludePath>
<ILINK_LibraryPath>$(BDS)\lib;$(BDS)\lib\obj;$(BDS)\lib\psdk;C:\cppcheck</ILINK_LibraryPath> <ILINK_LibraryPath>$(BDS)\lib;$(BDS)\lib\obj;$(BDS)\lib\psdk;C:\cppcheck</ILINK_LibraryPath>
<DCC_UNSAFE_TYPE>true</DCC_UNSAFE_TYPE>
<DCC_UNSAFE_CODE>true</DCC_UNSAFE_CODE> <DCC_UNSAFE_CODE>true</DCC_UNSAFE_CODE>
<DCC_UNSAFE_TYPE>true</DCC_UNSAFE_TYPE>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''"> <PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_Optimize>false</DCC_Optimize>
<BCC_OptimizeForSpeed>false</BCC_OptimizeForSpeed> <BCC_OptimizeForSpeed>false</BCC_OptimizeForSpeed>
<Defines>_DEBUG;$(Defines)</Defines> <DCC_Optimize>false</DCC_Optimize>
<DCC_DebugInfoInExe>true</DCC_DebugInfoInExe> <DCC_DebugInfoInExe>true</DCC_DebugInfoInExe>
<Defines>_DEBUG;$(Defines)</Defines>
<ILINK_FullDebugInfo>true</ILINK_FullDebugInfo> <ILINK_FullDebugInfo>true</ILINK_FullDebugInfo>
<BCC_InlineFunctionExpansion>false</BCC_InlineFunctionExpansion> <BCC_InlineFunctionExpansion>false</BCC_InlineFunctionExpansion>
<ILINK_DisableIncrementalLinking>true</ILINK_DisableIncrementalLinking> <ILINK_DisableIncrementalLinking>true</ILINK_DisableIncrementalLinking>
<BCC_UseRegisterVariables>None</BCC_UseRegisterVariables> <BCC_UseRegisterVariables>None</BCC_UseRegisterVariables>
<DCC_Define>DEBUG</DCC_Define> <DCC_Define>DEBUG</DCC_Define>
<BCC_DebugLineNumbers>true</BCC_DebugLineNumbers> <BCC_DebugLineNumbers>true</BCC_DebugLineNumbers>
<FinalOutputDir>bcb_debug</FinalOutputDir>
<BCC_SelectedWarnings>false</BCC_SelectedWarnings> <BCC_SelectedWarnings>false</BCC_SelectedWarnings>
<FinalOutputDir>bcb_debug</FinalOutputDir>
<IntermediateOutputDir>bcb_Debug</IntermediateOutputDir> <IntermediateOutputDir>bcb_Debug</IntermediateOutputDir>
<BCC_AllWarnings>true</BCC_AllWarnings> <BCC_AllWarnings>true</BCC_AllWarnings>
<TASM_DisplaySourceLines>true</TASM_DisplaySourceLines> <TASM_DisplaySourceLines>true</TASM_DisplaySourceLines>
<BCC_StackFrames>true</BCC_StackFrames> <BCC_StackFrames>true</BCC_StackFrames>
<ILINK_LibraryPath>$(BDS)\lib\debug;$(ILINK_LibraryPath)</ILINK_LibraryPath>
<BCC_DisableOptimizations>true</BCC_DisableOptimizations> <BCC_DisableOptimizations>true</BCC_DisableOptimizations>
<ILINK_LibraryPath>$(BDS)\lib\debug;$(ILINK_LibraryPath)</ILINK_LibraryPath>
<TASM_Debugging>Full</TASM_Debugging> <TASM_Debugging>Full</TASM_Debugging>
<BCC_SourceDebuggingOn>true</BCC_SourceDebuggingOn> <BCC_SourceDebuggingOn>true</BCC_SourceDebuggingOn>
</PropertyGroup> </PropertyGroup>
@ -84,6 +84,10 @@
<DependentOn>CheckClass.h</DependentOn> <DependentOn>CheckClass.h</DependentOn>
<BuildOrder>1</BuildOrder> <BuildOrder>1</BuildOrder>
</CppCompile> </CppCompile>
<CppCompile Include="CheckFunctionUsage.cpp">
<DependentOn>CheckFunctionUsage.h</DependentOn>
<BuildOrder>11</BuildOrder>
</CppCompile>
<CppCompile Include="CheckHeaders.cpp"> <CppCompile Include="CheckHeaders.cpp">
<DependentOn>CheckHeaders.h</DependentOn> <DependentOn>CheckHeaders.h</DependentOn>
<BuildOrder>2</BuildOrder> <BuildOrder>2</BuildOrder>
@ -96,29 +100,28 @@
<DependentOn>CheckOther.h</DependentOn> <DependentOn>CheckOther.h</DependentOn>
<BuildOrder>4</BuildOrder> <BuildOrder>4</BuildOrder>
</CppCompile> </CppCompile>
<CppCompile Include="CommonCheck.cpp">
<DependentOn>CommonCheck.h</DependentOn>
<BuildOrder>5</BuildOrder>
</CppCompile>
<CppCompile Include="cppcheck.cpp"> <CppCompile Include="cppcheck.cpp">
<BuildOrder>11</BuildOrder> <BuildOrder>10</BuildOrder>
</CppCompile> </CppCompile>
<CppCompile Include="FileLister.cpp"> <CppCompile Include="FileLister.cpp">
<BuildOrder>8</BuildOrder> <BuildOrder>7</BuildOrder>
</CppCompile> </CppCompile>
<CppCompile Include="main.cpp"> <CppCompile Include="main.cpp">
<BuildOrder>6</BuildOrder> <BuildOrder>5</BuildOrder>
</CppCompile> </CppCompile>
<CppCompile Include="preprocessor.cpp"> <CppCompile Include="preprocessor.cpp">
<DependentOn>preprocessor.h</DependentOn> <DependentOn>preprocessor.h</DependentOn>
<BuildOrder>9</BuildOrder> <BuildOrder>8</BuildOrder>
</CppCompile> </CppCompile>
<CppCompile Include="settings.cpp"> <CppCompile Include="settings.cpp">
<BuildOrder>10</BuildOrder> <BuildOrder>9</BuildOrder>
</CppCompile>
<CppCompile Include="token.cpp">
<BuildOrder>12</BuildOrder>
</CppCompile> </CppCompile>
<CppCompile Include="tokenize.cpp"> <CppCompile Include="tokenize.cpp">
<DependentOn>tokenize.h</DependentOn> <DependentOn>tokenize.h</DependentOn>
<BuildOrder>7</BuildOrder> <BuildOrder>6</BuildOrder>
</CppCompile> </CppCompile>
<BuildConfiguration Include="Debug"> <BuildConfiguration Include="Debug">
<Key>Cfg_1</Key> <Key>Cfg_1</Key>

474
token.cpp
View File

@ -1,235 +1,239 @@
/* /*
* c++check - c/c++ syntax checking * c++check - c/c++ syntax checking
* Copyright (C) 2007-2008 Daniel Marjamäki and Reijo Tomperi * Copyright (C) 2007-2008 Daniel Marjamäki and Reijo Tomperi
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/ * along with this program. If not, see <http://www.gnu.org/licenses/
*/ */
#include "token.h" #include "token.h"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <string> #include <string>
TOKEN::TOKEN() #ifdef __BORLANDC__
{ #include <ctype.h> // isalpha, isdigit
FileIndex = 0; #endif
_str = 0;
linenr = 0; TOKEN::TOKEN()
next = 0; {
_isName = false; FileIndex = 0;
_isNumber = false; _str = 0;
} linenr = 0;
next = 0;
TOKEN::~TOKEN() _isName = false;
{ _isNumber = false;
std::free(_str); }
}
TOKEN::~TOKEN()
void TOKEN::setstr( const char s[] ) {
{ std::free(_str);
std::free(_str); }
#ifndef _MSC_VER
_str = strdup(s); void TOKEN::setstr( const char s[] )
#else {
_str = _strdup(s); std::free(_str);
#endif #ifndef _MSC_VER
str = _str ? _str : ""; _str = strdup(s);
#else
_isName = bool(str[0]=='_' || isalpha(str[0])); _str = _strdup(s);
_isNumber = bool(isdigit(str[0]) != 0); #endif
} str = _str ? _str : "";
void TOKEN::combineWithNext(const char str1[], const char str2[]) _isName = bool(str[0]=='_' || isalpha(str[0]));
{ _isNumber = bool(isdigit(str[0]) != 0);
if (!(next)) }
return;
if (strcmp(str,str1) || strcmp(next->str,str2)) void TOKEN::combineWithNext(const char str1[], const char str2[])
return; {
if (!(next))
std::string newstr(std::string(str1) + std::string(str2)); return;
setstr( newstr.c_str() ); if (strcmp(str,str1) || strcmp(next->str,str2))
deleteNext(); return;
}
std::string newstr(std::string(str1) + std::string(str2));
void TOKEN::deleteNext() setstr( newstr.c_str() );
{ deleteNext();
TOKEN *n = next; }
next = n->next;
delete n; void TOKEN::deleteNext()
} {
TOKEN *n = next;
const TOKEN *TOKEN::tokAt(int index) const next = n->next;
{ delete n;
const TOKEN *tok = this; }
while (index>0 && tok)
{ const TOKEN *TOKEN::tokAt(int index) const
tok = tok->next; {
index--; const TOKEN *tok = this;
} while (index>0 && tok)
return tok; {
} tok = tok->next;
index--;
const char *TOKEN::strAt(int index) const }
{ return tok;
const TOKEN *tok = this->tokAt(index); }
return tok ? tok->str : "";
} const char *TOKEN::strAt(int index) const
{
bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[]) const TOKEN *tok = this->tokAt(index);
{ return tok ? tok->str : "";
if (!tok) }
return false;
bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[])
const char *p = pattern; {
while (*p) if (!tok)
{ return false;
// Skip spaces in pattern..
while ( *p == ' ' ) const char *p = pattern;
p++; while (*p)
{
// Extract token from pattern.. // Skip spaces in pattern..
char str[50]; while ( *p == ' ' )
char *s = str; p++;
while (*p && *p!=' ')
{ // Extract token from pattern..
*s = *p; char str[50];
s++; char *s = str;
p++; while (*p && *p!=' ')
} {
*s = 0; *s = *p;
s++;
// No token => Success! p++;
if (str[0] == 0) }
return true; *s = 0;
// Any symbolname.. // No token => Success!
if (strcmp(str,"%var%")==0 || strcmp(str,"%type%")==0) if (str[0] == 0)
{ return true;
if (!tok->isName())
return false; // Any symbolname..
} if (strcmp(str,"%var%")==0 || strcmp(str,"%type%")==0)
{
// Variable name.. if (!tok->isName())
else if (strcmp(str,"%var1%")==0 || strcmp(str,"%var2%")==0) return false;
{ }
const char **varname = (strcmp(str,"%var1%")==0) ? varname1 : varname2;
// Variable name..
if ( ! varname ) else if (strcmp(str,"%var1%")==0 || strcmp(str,"%var2%")==0)
return false; {
const char **varname = (strcmp(str,"%var1%")==0) ? varname1 : varname2;
if (strcmp(tok->str, varname[0]) != 0)
return false; if ( ! varname )
return false;
for ( int i = 1; varname[i]; i++ )
{ if (strcmp(tok->str, varname[0]) != 0)
if ( !(tok->tokAt(2)) ) return false;
return false;
for ( int i = 1; varname[i]; i++ )
if ( strcmp(tok->strAt( 1), ".") ) {
return false; if ( !(tok->tokAt(2)) )
return false;
if ( strcmp(tok->strAt( 2), varname[i]) )
return false; if ( strcmp(tok->strAt( 1), ".") )
return false;
tok = tok->tokAt(2);
} if ( strcmp(tok->strAt( 2), varname[i]) )
} return false;
else if (strcmp(str,"%num%")==0) tok = tok->tokAt(2);
{ }
if ( ! tok->isNumber() ) }
return false;
} else if (strcmp(str,"%num%")==0)
{
if ( ! tok->isNumber() )
else if (strcmp(str,"%str%")==0) return false;
{ }
if ( tok->str[0] != '\"' )
return false;
} else if (strcmp(str,"%str%")==0)
{
// [.. => search for a one-character token.. if ( tok->str[0] != '\"' )
else if (str[0]=='[' && strchr(str, ']') && tok->str[1] == 0) return false;
{ }
*strrchr(str, ']') = 0;
if ( strchr( str + 1, tok->str[0] ) == 0 ) // [.. => search for a one-character token..
return false; else if (str[0]=='[' && strchr(str, ']') && tok->str[1] == 0)
} {
*strrchr(str, ']') = 0;
else if (strcmp(str, tok->str) != 0) if ( strchr( str + 1, tok->str[0] ) == 0 )
return false; return false;
}
tok = tok->next;
if (!tok && *p) else if (strcmp(str, tok->str) != 0)
return false; return false;
}
tok = tok->next;
// The end of the pattern has been reached and nothing wrong has been found if (!tok && *p)
return true; return false;
} }
bool TOKEN::isName() const // The end of the pattern has been reached and nothing wrong has been found
{ return true;
return _isName; }
}
bool TOKEN::isName() const
bool TOKEN::isNumber() const {
{ return _isName;
return _isNumber; }
}
bool TOKEN::isNumber() const
{
bool TOKEN::IsStandardType(const char str[]) return _isNumber;
{ }
if (!str)
return false;
bool Ret = false; bool TOKEN::IsStandardType(const char str[])
const char *type[] = {"bool","char","short","int","long","float","double",0}; {
for (int i = 0; type[i]; i++) if (!str)
Ret |= (strcmp(str,type[i])==0); return false;
return Ret; bool Ret = false;
} const char *type[] = {"bool","char","short","int","long","float","double",0};
for (int i = 0; type[i]; i++)
//--------------------------------------------------------------------------- Ret |= (strcmp(str,type[i])==0);
return Ret;
const TOKEN *TOKEN::findmatch(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[]) }
{
for ( ; tok; tok = tok->next) //---------------------------------------------------------------------------
{
if ( TOKEN::Match(tok, pattern, varname1, varname2) ) const TOKEN *TOKEN::findmatch(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[])
return tok; {
} for ( ; tok; tok = tok->next)
return 0; {
} if ( TOKEN::Match(tok, pattern, varname1, varname2) )
return tok;
const TOKEN *TOKEN::findtoken(const TOKEN *tok1, const char *tokenstr[]) }
{ return 0;
for (const TOKEN *ret = tok1; ret; ret = ret->next) }
{
unsigned int i = 0; const TOKEN *TOKEN::findtoken(const TOKEN *tok1, const char *tokenstr[])
const TOKEN *tok = ret; {
while (tokenstr[i]) for (const TOKEN *ret = tok1; ret; ret = ret->next)
{ {
if (!tok) unsigned int i = 0;
return NULL; const TOKEN *tok = ret;
if (*(tokenstr[i]) && strcmp(tokenstr[i],tok->str)) while (tokenstr[i])
break; {
tok = tok->next; if (!tok)
i++; return NULL;
} if (*(tokenstr[i]) && strcmp(tokenstr[i],tok->str))
if (!tokenstr[i]) break;
return ret; tok = tok->next;
} i++;
return NULL; }
} if (!tokenstr[i])
return ret;
}
return NULL;
}