Data Structures | Defines | Typedefs | Enumerations | Functions | Variables

depend.cpp File Reference

Custom implementation of Makedepend. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <unistd.h>
#include <map>
#include <set>
#include <stack>

Go to the source code of this file.

Data Structures

struct  StringCompare
 Comparator for strings. More...
class  File
 Helper class to read a file. More...
class  Lexer
 Lexer of a file. More...

Defines

#define PATH_MAX   260
 The maximum length of paths, if we don't know it.

Typedefs

typedef std::set< const char
*, StringCompare
StringSet
 Set of C-style strings.
typedef std::map< const char
*, StringSet *, StringCompare
StringMap
 Mapping of C-style string to a set of C-style strings.
typedef std::pair< const char
*, StringSet * > 
StringMapItem
 Pair of C-style string and a set of C-style strings.
typedef std::map< const char
*, Token, StringCompare
KeywordList
 Mapping from a C-style keyword representation to a Token.

Enumerations

enum  Token {
  TOKEN_UNKNOWN, TOKEN_END, TOKEN_EOL, TOKEN_SHARP,
  TOKEN_LOCAL, TOKEN_GLOBAL, TOKEN_IDENTIFIER, TOKEN_DEFINE,
  TOKEN_IF, TOKEN_IFDEF, TOKEN_IFNDEF, TOKEN_ELIF,
  TOKEN_ELSE, TOKEN_ENDIF, TOKEN_UNDEF, TOKEN_OR,
  TOKEN_AND, TOKEN_DEFINED, TOKEN_OPEN, TOKEN_CLOSE,
  TOKEN_NOT, TOKEN_ZERO, TOKEN_INCLUDE
}
 

A token returned by the tokenizer.

More...
enum  Ignore { NOT_IGNORE, IGNORE_UNTIL_ELSE, IGNORE_UNTIL_ENDIF }
 

Enumerator to tell how long to ignore 'stuff'.

More...

Functions

static void free (const void *ptr)
 Version of the standard free that accepts const pointers.
const char * GeneratePath (const char *dirname, const char *filename, bool local)
 Generate a path from a directory name and a relative filename.
bool ExpressionDefined (Lexer *lexer, StringSet *defines, bool verbose)
 Try to parse a 'defined(expr)' expression.
bool ExpressionOr (Lexer *lexer, StringSet *defines, bool verbose)
 Try to parse a 'expr || expr' expression.
bool ExpressionNot (Lexer *lexer, StringSet *defines, bool verbose)
 Try to parse a '!expr' expression.
bool ExpressionAnd (Lexer *lexer, StringSet *defines, bool verbose)
 Try to parse a 'expr && expr' expression.
void ScanFile (const char *filename, const char *ext, bool header, bool verbose)
 Scan a file for includes, defines and the lot.
int main (int argc, char *argv[])
 Entry point.

Variables

static StringSet _include_dirs
 Include directory to search in.
static StringMap _files
 Files that have been parsed/handled with their dependencies.
static StringMap _headers
 Dependencies of headers.
static StringSet _defines
 The current 'active' defines.

Detailed Description

Custom implementation of Makedepend.

We previously used makedepend, but that could not handle the amount of files we have and does not handle conditional includes in a sane manner. This caused many link problems because not enough files were recompiled. This has lead to the development of our own dependency generator. It is meant to be a substitute to the (relatively slow) dependency generation via gcc. It thus helps speeding up compilation. It will also ignore system headers making it less error prone when system headers are moved or renamed.

Definition in file depend.cpp.


Define Documentation

#define PATH_MAX   260

The maximum length of paths, if we don't know it.

Definition at line 44 of file depend.cpp.


Typedef Documentation

typedef std::map<const char*, Token, StringCompare> KeywordList

Mapping from a C-style keyword representation to a Token.

Definition at line 163 of file depend.cpp.

typedef std::map<const char*, StringSet*, StringCompare> StringMap

Mapping of C-style string to a set of C-style strings.

Definition at line 63 of file depend.cpp.

typedef std::pair<const char*, StringSet*> StringMapItem

Pair of C-style string and a set of C-style strings.

Definition at line 65 of file depend.cpp.

typedef std::set<const char*, StringCompare> StringSet

Set of C-style strings.

Definition at line 61 of file depend.cpp.


Enumeration Type Documentation

enum Ignore

Enumerator to tell how long to ignore 'stuff'.

Enumerator:
NOT_IGNORE 

No ignoring.

IGNORE_UNTIL_ELSE 

Ignore till a else is reached.

IGNORE_UNTIL_ENDIF 

Ignore till a endif is reached.

Definition at line 606 of file depend.cpp.

enum Token

A token returned by the tokenizer.

Enumerator:
TOKEN_UNKNOWN 

Unknown token.

TOKEN_END 

End of document.

TOKEN_EOL 

End of line.

TOKEN_SHARP 

# character, usually telling something important comes.

TOKEN_LOCAL 

Read a local include.

TOKEN_GLOBAL 

Read a global include.

TOKEN_IDENTIFIER 

Identifier within the data.

TOKEN_DEFINE 

(#)define in code

TOKEN_IF 

(#)if in code

TOKEN_IFDEF 

(#)ifdef in code

TOKEN_IFNDEF 

(#)ifndef in code

TOKEN_ELIF 

(#)elif in code

TOKEN_ELSE 

(#)else in code

TOKEN_ENDIF 

(#)endif in code

TOKEN_UNDEF 

(#)undef in code

TOKEN_OR 

'||' within if expression

TOKEN_AND 

'&&' within if expression

TOKEN_DEFINED 

'defined' within if expression

TOKEN_OPEN 

'(' within if expression

TOKEN_CLOSE 

')' within if expression

TOKEN_NOT 

'!' within if expression

TOKEN_ZERO 

'0' within if expression

TOKEN_INCLUDE 

(#)include in code

Definition at line 136 of file depend.cpp.


Function Documentation

bool ExpressionAnd ( Lexer lexer,
StringSet defines,
bool  verbose 
)

Try to parse a 'expr && expr' expression.

Parameters:
lexer the lexer to get tokens from.
defines the set of known defines.
verbose whether to give verbose debugging information.
Returns:
the value of the expression.

Definition at line 574 of file depend.cpp.

References ExpressionDefined(), Lexer::GetToken(), and Lexer::Lex().

Referenced by ExpressionOr().

bool ExpressionDefined ( Lexer lexer,
StringSet defines,
bool  verbose 
)

Try to parse a 'defined(expr)' expression.

Parameters:
lexer the lexer to get tokens from.
defines the set of known defines.
verbose whether to give verbose debugging information.
Returns:
the value of the expression.

Definition at line 544 of file depend.cpp.

References ExpressionNot(), Lexer::GetString(), Lexer::GetToken(), and Lexer::Lex().

Referenced by ExpressionAnd(), and ExpressionNot().

bool ExpressionNot ( Lexer lexer,
StringSet defines,
bool  verbose 
)

Try to parse a '!expr' expression.

Also parses the '(expr)', '0' and identifiers. Finally it also consumes any unknown tokens.

Parameters:
lexer the lexer to get tokens from.
defines the set of known defines.
verbose whether to give verbose debugging information.
Returns:
the value of the expression.

Definition at line 501 of file depend.cpp.

References ExpressionDefined(), ExpressionOr(), Lexer::GetToken(), Lexer::Lex(), and TOKEN_UNKNOWN.

Referenced by ExpressionDefined().

bool ExpressionOr ( Lexer lexer,
StringSet defines,
bool  verbose 
)

Try to parse a 'expr || expr' expression.

Parameters:
lexer the lexer to get tokens from.
defines the set of known defines.
verbose whether to give verbose debugging information.
Returns:
the value of the expression.

Definition at line 593 of file depend.cpp.

References ExpressionAnd(), Lexer::GetToken(), and Lexer::Lex().

Referenced by ExpressionNot(), and ScanFile().

static void free ( const void *  ptr  )  [inline, static]

Version of the standard free that accepts const pointers.

Parameters:
ptr The data to free.

Definition at line 37 of file depend.cpp.

Referenced by ScriptText::_SetParam(), ScriptScanner::AddFile(), BaseMedia< Tbase_set >::AddFile(), AddGRFString(), AddGRFTextToList(), AfterLoadGRFs(), AirportChangeInfo(), ReusableBuffer< SpriteLoader::CommonPixel >::Allocate(), AllocateMap(), TileMatrix< uint32, 4 >::AllocateStorage(), ScriptConfig::Change(), NetworkChatWindow::ChatTabCompletion(), CheckCaches(), CleanIndustryTileTable(), Hash::Clear(), BinaryHeap::Clear(), GroupStatistics::Clear(), LoadCheckData::Clear(), AutoFreeSmallVector< byte *, 16 >::Clear(), PersistentStorageArray< int32, 16 >::ClearChanges(), ScriptConfig::ClearConfigList(), ClearSnowLine(), ClearTemporaryNewGRFData(), CmdRenameCompany(), CmdRenameDepot(), CmdRenameEngine(), CmdRenameGroup(), CmdRenamePresident(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdTownSetText(), CreateRivers(), DeallocateSpecFromStation(), DEF_CONSOLE_CMD(), DEFINE_POOL_METHOD(), Hash::Delete(), Hash::DeleteValue(), DeterminePaths(), DistributeQueue(), DoScanNewGRFFiles(), Blitter_32bppOptimized::Encode(), FeatureTownName(), FioCloseFile(), FormatString(), BinaryHeap::Free(), CommandQueue::Free(), FreeHeightMap(), ScriptLog::FreeLogPointer(), LangString::FreeTranslation(), GamelogGRFUpdate(), GamelogReset(), GetFontByFaceName(), HeightMapAdjustWaterLevel(), IConsoleHistoryAdd(), IConsolePrint(), IndustriesChangeInfo(), IniLoadSettings(), IniSaveSettings(), InitGRFTownGeneratorNames(), InitializeOldNames(), InitializeUnicodeGlyphMap(), InputLoop(), IsGoodGRFConfigList(), Lexer::Lex(), IniLoadFile::LoadFromDisk(), LoadHeightmap(), ScriptLog::Log(), CrashLogUnix::LogStacktrace(), CrashLogOSX::LogStacktrace(), AyStar::Loop(), main(), MakeBMPImage(), MakePCXImage(), MakePNGImage(), NetworkClose(), NetworkExecuteLocalCommandQueue(), NetworkGameListHandleDelayedInsert(), NetworkGameListRemoveItem(), NetworkHandleCommandQueue(), NetworkHTTPContentConnecter::OnFailure(), GRFText::operator delete(), ZeroedMemoryAllocator::operator delete(), ZeroedMemoryAllocator::operator delete[](), ByteBlob::RawFree(), ReadFileToMem(), Lexer::ReadIdentifier(), ReadLanguagePack(), Lexer::ReadString(), ReallocT(), ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO(), RemoveRailStation(), ReplaceChain(), SquirrelStd::require(), ScriptScanner::Reset(), SmallVector< RefitOption, 32 >::Reset(), ResetBridges(), ResetCustomAirports(), ResetCustomHouses(), ResetCustomIndustries(), ResetCustomObjects(), ResetCustomStations(), ResetGlyphCache(), ResetNewGRF(), ResetOldNames(), ScriptConfig::ResetSettings(), ScanFile(), GameOptionsWindow::SetMediaSet(), SetSettingValue(), IniItem::SetValue(), ShutdownGame(), SlError(), SlString(), StationChangeInfo(), VideoDriver_Dedicated::Stop(), MusicDriver_ExtMidi::Stop(), ScriptConfig::StringToSettings(), ContentInfo::TransferFrom(), UnInitWindowSystem(), UnloadWagonOverrides(), ScanProgressWindow::UpdateNewGRFScanStatus(), UpdateOSKOriginalText(), ReusableBuffer< SpriteLoader::CommonPixel >::ZeroAllocate(), BaseSet< GraphicsSet, MAX_GFT, true >::~BaseSet(), Case::~Case(), ContentInfo::~ContentInfo(), DriverFactoryBase::~DriverFactoryBase(), ErrorMessageData::~ErrorMessageData(), File::~File(), FileWriter::~FileWriter(), FixedSizeArray< SubArray, 1024 >::~FixedSizeArray(), FreeUnitIDGenerator::~FreeUnitIDGenerator(), Goal::~Goal(), GRFConfig::~GRFConfig(), IConsoleLine::~IConsoleLine(), IniGroup::~IniGroup(), IniItem::~IniItem(), IniLoadFile::~IniLoadFile(), LangString::~LangString(), LanguageStrings::~LanguageStrings(), Lexer::~Lexer(), NetworkHTTPContentConnecter::~NetworkHTTPContentConnecter(), NetworkHTTPSocketHandler::~NetworkHTTPSocketHandler(), OrderBackup::~OrderBackup(), OverrideManagerBase::~OverrideManagerBase(), Packet::~Packet(), PersistentStorage::~PersistentStorage(), PersistentStorageArray< int32, 16 >::~PersistentStorageArray(), QueryString::~QueryString(), ReusableBuffer< SpriteLoader::CommonPixel >::~ReusableBuffer(), ScanProgressWindow::~ScanProgressWindow(), ScriptConfig::~ScriptConfig(), ScriptController::~ScriptController(), Sign::~Sign(), StringData::~StringData(), StringReader::~StringReader(), Town::~Town(), UnmappedChoiceList::~UnmappedChoiceList(), Vehicle::~Vehicle(), and Window::~Window().

const char* GeneratePath ( const char *  dirname,
const char *  filename,
bool  local 
)

Generate a path from a directory name and a relative filename.

If the file is not local the include directory names will be used instead of the passed parameter with directory name. If the file is local both will be queried where the parameter takes precedence.

Parameters:
dirname the directory to look in.
filename the file to look for.
local whether to look locally (in dirname) for the file.
Returns:
the absolute path, or NULL if the file doesn't exist.

Definition at line 432 of file depend.cpp.

References _include_dirs.

Referenced by ScanFile().

int main ( int  argc,
char *  argv[] 
)

Entry point.

Arguably the most common function in all applications.

Parameters:
argc the number of arguments.
argv the actual arguments.
Returns:
return value for the caller to tell we succeed or not.

Definition at line 833 of file depend.cpp.

References _defines, _files, _headers, _include_dirs, free(), and ScanFile().

void ScanFile ( const char *  filename,
const char *  ext,
bool  header,
bool  verbose 
)

Scan a file for includes, defines and the lot.

Parameters:
filename the name of the file to scan.
ext the extension of the filename.
header whether the file is a header or not.
verbose whether to give verbose debugging information.

Definition at line 619 of file depend.cpp.

References _defines, _files, _headers, ExpressionOr(), free(), GeneratePath(), File::GetDirname(), Lexer::GetString(), Lexer::GetToken(), IGNORE_UNTIL_ELSE, IGNORE_UNTIL_ENDIF, Lexer::Lex(), NOT_IGNORE, TOKEN_DEFINE, TOKEN_ELIF, TOKEN_ELSE, TOKEN_END, TOKEN_ENDIF, TOKEN_EOL, TOKEN_GLOBAL, TOKEN_IF, TOKEN_IFDEF, TOKEN_IFNDEF, TOKEN_INCLUDE, TOKEN_LOCAL, TOKEN_SHARP, and TOKEN_UNDEF.

Referenced by main().


Variable Documentation

StringSet _defines [static]

The current 'active' defines.

Definition at line 74 of file depend.cpp.

Referenced by main(), and ScanFile().

StringMap _files [static]

Files that have been parsed/handled with their dependencies.

Definition at line 70 of file depend.cpp.

Referenced by main(), and ScanFile().

StringMap _headers [static]

Dependencies of headers.

Definition at line 72 of file depend.cpp.

Referenced by main(), and ScanFile().

Include directory to search in.

Definition at line 68 of file depend.cpp.

Referenced by GeneratePath(), and main().