Cppcheck
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
Preprocessor Class Reference

The cppcheck preprocessor. More...

#include <preprocessor.h>

Public Types

enum  HeaderTypes { UserHeader = 1 , SystemHeader }
 Include file types. More...
 

Public Member Functions

 Preprocessor (const Settings &settings, ErrorLogger &errorLogger)
 
virtual ~Preprocessor ()
 
void inlineSuppressions (const simplecpp::TokenList &tokens, SuppressionList &suppressions)
 
std::list< DirectivecreateDirectives (const simplecpp::TokenList &tokens) const
 
std::set< std::string > getConfigs (const simplecpp::TokenList &tokens) const
 
void handleErrors (const simplecpp::OutputList &outputList, bool throwError)
 
bool loadFiles (const simplecpp::TokenList &rawtokens, std::vector< std::string > &files)
 
void removeComments ()
 
void setPlatformInfo (simplecpp::TokenList *tokens) const
 
simplecpp::TokenList preprocess (const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector< std::string > &files, bool throwError=false)
 
std::string getcode (const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector< std::string > &files, const bool writeLocations)
 
std::size_t calculateHash (const simplecpp::TokenList &tokens1, const std::string &toolinfo) const
 Calculate HASH. More...
 
void simplifyPragmaAsm (simplecpp::TokenList *tokenList) const
 
void dump (std::ostream &out) const
 dump all directives present in source file More...
 
void reportOutput (const simplecpp::OutputList &outputList, bool showerror)
 

Static Public Member Functions

static void getErrorMessages (ErrorLogger &errorLogger, const Settings &settings)
 
static bool hasErrors (const simplecpp::Output &output)
 

Static Public Attributes

static char macroChar = char(1)
 character that is inserted in expanded macros More...
 

Private Member Functions

void missingInclude (const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType)
 
void error (const std::string &filename, unsigned int linenr, const std::string &msg)
 

Static Private Member Functions

static void simplifyPragmaAsmPrivate (simplecpp::TokenList *tokenList)
 
static bool hasErrors (const simplecpp::OutputList &outputList)
 

Private Attributes

const SettingsmSettings
 
ErrorLoggermErrorLogger
 
std::map< std::string, simplecpp::TokenList * > mTokenLists
 list of all directives met while preprocessing file More...
 
std::string mFile0
 filename for cpp/c file - useful when reporting errors More...
 
std::list< simplecpp::MacroUsage > mMacroUsage
 simplecpp tracking info More...
 
std::list< simplecpp::IfCond > mIfCond
 

Friends

class PreprocessorHelper
 
class TestPreprocessor
 
class TestUnusedVar
 

Detailed Description

The cppcheck preprocessor.

The preprocessor has special functionality for extracting the various ifdef configurations that exist in a source file.

Definition at line 71 of file preprocessor.h.

Member Enumeration Documentation

◆ HeaderTypes

Include file types.

Enumerator
UserHeader 
SystemHeader 

Definition at line 82 of file preprocessor.h.

Constructor & Destructor Documentation

◆ Preprocessor()

Preprocessor::Preprocessor ( const Settings settings,
ErrorLogger errorLogger 
)
explicit

Definition at line 54 of file preprocessor.cpp.

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )
virtual

Definition at line 57 of file preprocessor.cpp.

References mTokenLists.

Member Function Documentation

◆ calculateHash()

std::size_t Preprocessor::calculateHash ( const simplecpp::TokenList &  tokens1,
const std::string &  toolinfo 
) const

Calculate HASH.

Using toolinfo, tokens1, filedata.

Parameters
tokens1Sourcefile tokens
toolinfoArbitrary extra toolinfo
Returns
HASH

Definition at line 936 of file preprocessor.cpp.

References mTokenLists.

Referenced by CppCheck::checkFile().

◆ createDirectives()

std::list< Directive > Preprocessor::createDirectives ( const simplecpp::TokenList &  tokens) const

Definition at line 298 of file preprocessor.cpp.

References emptyString, Directive::linenr, mTokenLists, and Directive::str.

Referenced by CppCheck::checkFile().

◆ dump()

void Preprocessor::dump ( std::ostream &  out) const

dump all directives present in source file

Definition at line 900 of file preprocessor.cpp.

References bool_to_string(), mIfCond, mMacroUsage, and ErrorLogger::toxml().

Referenced by CppCheck::checkFile().

◆ error()

void Preprocessor::error ( const std::string &  filename,
unsigned int  linenr,
const std::string &  msg 
)
private

◆ getcode()

std::string Preprocessor::getcode ( const simplecpp::TokenList &  tokens1,
const std::string &  cfg,
std::vector< std::string > &  files,
const bool  writeLocations 
)

Definition at line 797 of file preprocessor.cpp.

References cfg(), macroChar, and preprocess().

Referenced by CppCheck::checkFile().

◆ getConfigs()

std::set< std::string > Preprocessor::getConfigs ( const simplecpp::TokenList &  tokens) const

◆ getErrorMessages()

void Preprocessor::getErrorMessages ( ErrorLogger errorLogger,
const Settings settings 
)
static

Definition at line 892 of file preprocessor.cpp.

References emptyString, error(), missingInclude(), SystemHeader, and UserHeader.

Referenced by CppCheck::getErrorMessages().

◆ handleErrors()

void Preprocessor::handleErrors ( const simplecpp::OutputList &  outputList,
bool  throwError 
)

Definition at line 726 of file preprocessor.cpp.

References Settings::force, mSettings, reportOutput(), and Settings::userDefines.

Referenced by loadFiles(), and preprocess().

◆ hasErrors() [1/2]

bool Preprocessor::hasErrors ( const simplecpp::Output &  output)
static

Definition at line 700 of file preprocessor.cpp.

Referenced by loadFiles().

◆ hasErrors() [2/2]

bool Preprocessor::hasErrors ( const simplecpp::OutputList &  outputList)
staticprivate

Definition at line 718 of file preprocessor.cpp.

◆ inlineSuppressions()

void Preprocessor::inlineSuppressions ( const simplecpp::TokenList &  tokens,
SuppressionList suppressions 
)

◆ loadFiles()

bool Preprocessor::loadFiles ( const simplecpp::TokenList &  rawtokens,
std::vector< std::string > &  files 
)

Definition at line 740 of file preprocessor.cpp.

References createDUI(), emptyString, handleErrors(), hasErrors(), mSettings, and mTokenLists.

Referenced by CppCheck::checkFile().

◆ missingInclude()

void Preprocessor::missingInclude ( const std::string &  filename,
unsigned int  linenr,
const std::string &  header,
HeaderTypes  headerType 
)
private

◆ preprocess()

simplecpp::TokenList Preprocessor::preprocess ( const simplecpp::TokenList &  tokens1,
const std::string &  cfg,
std::vector< std::string > &  files,
bool  throwError = false 
)

Definition at line 778 of file preprocessor.cpp.

References cfg(), createDUI(), handleErrors(), mIfCond, mMacroUsage, mSettings, and mTokenLists.

Referenced by CppCheck::checkFile(), and getcode().

◆ removeComments()

void Preprocessor::removeComments ( )

Definition at line 750 of file preprocessor.cpp.

References mTokenLists.

Referenced by CppCheck::checkFile().

◆ reportOutput()

void Preprocessor::reportOutput ( const simplecpp::OutputList &  outputList,
bool  showerror 
)

Definition at line 824 of file preprocessor.cpp.

References emptyString, error(), missingInclude(), startsWith(), SystemHeader, and UserHeader.

Referenced by handleErrors().

◆ setPlatformInfo()

void Preprocessor::setPlatformInfo ( simplecpp::TokenList *  tokens) const

◆ simplifyPragmaAsm()

void Preprocessor::simplifyPragmaAsm ( simplecpp::TokenList *  tokenList) const

Definition at line 952 of file preprocessor.cpp.

References mTokenLists, and simplifyPragmaAsmPrivate().

Referenced by CppCheck::checkFile().

◆ simplifyPragmaAsmPrivate()

void Preprocessor::simplifyPragmaAsmPrivate ( simplecpp::TokenList *  tokenList)
staticprivate

Definition at line 960 of file preprocessor.cpp.

References sameline().

Referenced by simplifyPragmaAsm().

Friends And Related Function Documentation

◆ PreprocessorHelper

friend class PreprocessorHelper
friend

Definition at line 73 of file preprocessor.h.

◆ TestPreprocessor

friend class TestPreprocessor
friend

Definition at line 74 of file preprocessor.h.

◆ TestUnusedVar

friend class TestUnusedVar
friend

Definition at line 75 of file preprocessor.h.

Member Data Documentation

◆ macroChar

char Preprocessor::macroChar = char(1)
static

character that is inserted in expanded macros

Definition at line 88 of file preprocessor.h.

Referenced by CppCheck::checkFile(), and getcode().

◆ mErrorLogger

ErrorLogger& Preprocessor::mErrorLogger
private

Definition at line 142 of file preprocessor.h.

Referenced by error(), and missingInclude().

◆ mFile0

std::string Preprocessor::mFile0
private

filename for cpp/c file - useful when reporting errors

Definition at line 149 of file preprocessor.h.

Referenced by error(), and missingInclude().

◆ mIfCond

std::list<simplecpp::IfCond> Preprocessor::mIfCond
private

Definition at line 153 of file preprocessor.h.

Referenced by dump(), and preprocess().

◆ mMacroUsage

std::list<simplecpp::MacroUsage> Preprocessor::mMacroUsage
private

simplecpp tracking info

Definition at line 152 of file preprocessor.h.

Referenced by dump(), and preprocess().

◆ mSettings

const Settings& Preprocessor::mSettings
private

◆ mTokenLists

std::map<std::string, simplecpp::TokenList *> Preprocessor::mTokenLists
private

list of all directives met while preprocessing file

Definition at line 146 of file preprocessor.h.

Referenced by calculateHash(), createDirectives(), getConfigs(), inlineSuppressions(), loadFiles(), preprocess(), removeComments(), simplifyPragmaAsm(), and ~Preprocessor().


The documentation for this class was generated from the following files: