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. |
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 PATH_MAX 260 |
The maximum length of paths, if we don't know it.
Definition at line 44 of file depend.cpp.
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.
enum Ignore |
Enumerator to tell how long to ignore 'stuff'.
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.
Definition at line 136 of file depend.cpp.
Try to parse a 'expr && expr' expression.
lexer | the lexer to get tokens from. | |
defines | the set of known defines. | |
verbose | whether to give verbose debugging information. |
Definition at line 574 of file depend.cpp.
References ExpressionDefined(), Lexer::GetToken(), and Lexer::Lex().
Referenced by ExpressionOr().
Try to parse a 'defined(expr)' expression.
lexer | the lexer to get tokens from. | |
defines | the set of known defines. | |
verbose | whether to give verbose debugging information. |
Definition at line 544 of file depend.cpp.
References ExpressionNot(), Lexer::GetString(), Lexer::GetToken(), and Lexer::Lex().
Referenced by ExpressionAnd(), and ExpressionNot().
Try to parse a '!expr' expression.
Also parses the '(expr)', '0' and identifiers. Finally it also consumes any unknown tokens.
lexer | the lexer to get tokens from. | |
defines | the set of known defines. | |
verbose | whether to give verbose debugging information. |
Definition at line 501 of file depend.cpp.
References ExpressionDefined(), ExpressionOr(), Lexer::GetToken(), Lexer::Lex(), and TOKEN_UNKNOWN.
Referenced by ExpressionDefined().
Try to parse a 'expr || expr' expression.
lexer | the lexer to get tokens from. | |
defines | the set of known defines. | |
verbose | whether to give verbose debugging information. |
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.
ptr | The data to free. |
Definition at line 37 of file depend.cpp.
Referenced by ScriptScanner::AddFile(), BaseMedia< Tbase_set >::AddFile(), AddGRFString(), AddGRFTextToList(), AfterLoadGRFs(), AirportChangeInfo(), ReusableBuffer< SpriteLoader::CommonPixel >::Allocate(), AllocateMap(), TileMatrix< uint32, 4 >::AllocateStorage(), SmallMatrix< EdgeAnnotation >::Assign(), AutoFreePtr< T >::Assign(), 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(), BaseConsist::CopyConsistPropertiesFrom(), ErrorMessageData::CopyOutDParams(), 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(), LangString::FreeTranslation(), GamelogFree(), GamelogGRFUpdate(), GetFontByFaceName(), HeightMapAdjustWaterLevel(), IConsoleHistoryAdd(), IConsolePrint(), IndustriesChangeInfo(), IniLoadSettings(), IniSaveSettings(), InitGRFTownGeneratorNames(), InitializeOldNames(), InitializeUnicodeGlyphMap(), InputLoop(), IsGoodGRFConfigList(), Lexer::Lex(), IniLoadFile::LoadFromDisk(), LoadHeightmap(), 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[](), Blitter_32bppAnim::PostResize(), ByteBlob::RawFree(), ReadFileToMem(), Lexer::ReadIdentifier(), ReadLanguagePack(), Lexer::ReadString(), ReallocT(), ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO(), RemoveRailStation(), ReplaceChain(), SquirrelStd::require(), ScriptScanner::Reset(), SmallVector< RefitOption, 32 >::Reset(), SmallMatrix< EdgeAnnotation >::Reset(), ResetBridges(), ResetCustomAirports(), ResetCustomHouses(), ResetCustomIndustries(), ResetCustomObjects(), ResetCustomStations(), ResetGlyphCache(), ResetOldNames(), ScriptConfig::ResetSettings(), SmallMatrix< EdgeAnnotation >::Resize(), ScanFile(), ErrorMessageData::SetDParamStr(), StringFilter::SetFilterTerm(), 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(), OverrideManagerBase::~OverrideManagerBase(), Packet::~Packet(), PersistentStorage::~PersistentStorage(), PersistentStorageArray< int32, 16 >::~PersistentStorageArray(), QueryString::~QueryString(), ReusableBuffer< SpriteLoader::CommonPixel >::~ReusableBuffer(), ScanProgressWindow::~ScanProgressWindow(), ScriptConfig::~ScriptConfig(), Sign::~Sign(), StringData::~StringData(), StringReader::~StringReader(), Town::~Town(), UnmappedChoiceList::~UnmappedChoiceList(), 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.
dirname | the directory to look in. | |
filename | the file to look for. | |
local | whether to look locally (in dirname) for the file. |
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.
argc | the number of arguments. | |
argv | the actual arguments. |
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.
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().
The current 'active' defines.
Definition at line 74 of file depend.cpp.
Referenced by main(), and ScanFile().
Files that have been parsed/handled with their dependencies.
Definition at line 70 of file depend.cpp.
Referenced by main(), and ScanFile().
Dependencies of headers.
Definition at line 72 of file depend.cpp.
Referenced by main(), and ScanFile().
StringSet _include_dirs [static] |
Include directory to search in.
Definition at line 68 of file depend.cpp.
Referenced by GeneratePath(), and main().