Use enum for header file types

This commit is contained in:
Kimmo Varis 2010-07-21 12:50:04 +03:00
parent f2f5b3ebf0
commit 9d29ee6edd
3 changed files with 31 additions and 16 deletions

View File

@ -1300,14 +1300,14 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
return expandMacros(ret.str(), filename, errorLogger);
}
int Preprocessor::getHeaderFileName(std::string &str)
Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str)
{
std::string result;
std::string::size_type i = str.find_first_of("<\"");
if (i == std::string::npos)
{
str = "";
return 0;
return NoHeader;
}
unsigned char c = str[i];
@ -1324,9 +1324,9 @@ int Preprocessor::getHeaderFileName(std::string &str)
str = result;
if (c == '"')
return 1;
return UserHeader;
else
return 2;
return SystemHeader;
}
@ -1373,8 +1373,8 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
// Remove #include clause
code.erase(pos, end - pos);
int headerType = getHeaderFileName(filename);
if (headerType == 0)
HeaderTypes headerType = getHeaderFileName(filename);
if (headerType == NoHeader)
continue;
// filename contains now a file name e.g. "menu.h"
@ -1394,7 +1394,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
fin.clear();
}
if (headerType == 1 && !fileOpened)
if (headerType == UserHeader && !fileOpened)
{
filename = paths.back() + filename;
@ -1445,7 +1445,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
}
else if (!fileOpened)
{
if (headerType == 1 && _errorLogger && _settings && _settings->_verbose)
if (headerType == UserHeader && _errorLogger && _settings && _settings->_verbose)
{
_errorLogger->reportOut("Include file: \"" + filename + "\" not found.");
}

View File

@ -31,10 +31,25 @@
/// @addtogroup Core
/// @{
/** @brief The cppcheck preprocessor. It has special functionality for extracting the various ifdef configurations that exist in a source file. */
/**
* @brief The cppcheck preprocessor.
* The preprocessor has special functionality for extracting the various ifdef
* configurations that exist in a source file.
*/
class Preprocessor
{
public:
/**
* Include file types.
*/
enum HeaderTypes
{
NoHeader = 0,
UserHeader,
SystemHeader
};
Preprocessor(Settings *settings = 0, ErrorLogger *errorLogger = 0);
/**
@ -147,11 +162,11 @@ protected:
* Returns the string between double quote characters or \< \> characters.
* @param str e.g. \code#include "menu.h"\endcode or \code#include <menu.h>\endcode
* After function call it will contain e.g. "menu.h" without double quotes.
* @return 0 empty string if double quotes or \< \> were not found.
* 1 if file surrounded with "" was found
* 2 if file surrounded with \<\> was found
* @return NoHeader empty string if double quotes or \< \> were not found.
* UserHeader if file surrounded with "" was found
* SystemHeader if file surrounded with \<\> was found
*/
static int getHeaderFileName(std::string &str);
static Preprocessor::HeaderTypes getHeaderFileName(std::string &str);
private:
/**

View File

@ -2015,19 +2015,19 @@ private:
{
{
std::string src = "#include a.h";
ASSERT_EQUALS(0, OurPreprocessor::getHeaderFileName(src));
ASSERT_EQUALS(OurPreprocessor::NoHeader, OurPreprocessor::getHeaderFileName(src));
ASSERT_EQUALS("", src);
}
{
std::string src = "#include \"b.h\"";
ASSERT_EQUALS(1, OurPreprocessor::getHeaderFileName(src));
ASSERT_EQUALS(OurPreprocessor::UserHeader, OurPreprocessor::getHeaderFileName(src));
ASSERT_EQUALS("b.h", src);
}
{
std::string src = "#include <c.h>";
ASSERT_EQUALS(2, OurPreprocessor::getHeaderFileName(src));
ASSERT_EQUALS(OurPreprocessor::SystemHeader, OurPreprocessor::getHeaderFileName(src));
ASSERT_EQUALS("c.h", src);
}
}