#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 |
Simple string comparator using strcmp as implementation. More... | |
class | File |
Helper class to read a file. More... | |
class | Lexer |
Lexer of a file. More... | |
Defines | |
#define | PATH_MAX 260 |
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 | |
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. |
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.
typedef std::map<const char*, Token, StringCompare> KeywordList |
Mapping from a C-style keyword representation to a Token.
Definition at line 153 of file depend.cpp.
typedef std::map<const char*, StringSet*, StringCompare> StringMap |
typedef std::pair<const char*, StringSet*> StringMapItem |
typedef std::set<const char*, StringCompare> StringSet |
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 596 of file depend.cpp.
enum Token |
A token returned by the tokenizer.
Definition at line 126 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 564 of file depend.cpp.
References ExpressionDefined(), Lexer::GetToken(), Lexer::Lex(), and TOKEN_AND.
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 534 of file depend.cpp.
References ExpressionNot(), Lexer::GetString(), Lexer::GetToken(), Lexer::Lex(), TOKEN_DEFINED, TOKEN_IDENTIFIER, and TOKEN_OPEN.
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 491 of file depend.cpp.
References ExpressionDefined(), ExpressionOr(), Lexer::GetToken(), Lexer::Lex(), TOKEN_IDENTIFIER, TOKEN_NOT, TOKEN_OPEN, TOKEN_UNKNOWN, and TOKEN_ZERO.
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 583 of file depend.cpp.
References ExpressionAnd(), Lexer::GetToken(), Lexer::Lex(), and TOKEN_OR.
Referenced by ExpressionNot(), and ScanFile().
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 422 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 823 of file depend.cpp.
References _defines, _files, _headers, _include_dirs, 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 609 of file depend.cpp.
References _defines, _files, _headers, ExpressionOr(), 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_IDENTIFIER, 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 64 of file depend.cpp.
Referenced by main(), and ScanFile().
Files that have been parsed/handled with their dependencies.
Definition at line 60 of file depend.cpp.
Referenced by main(), and ScanFile().
Dependencies of headers.
Definition at line 62 of file depend.cpp.
Referenced by main(), and ScanFile().
StringSet _include_dirs [static] |
Include directory to search in.
Definition at line 58 of file depend.cpp.
Referenced by GeneratePath(), and main().