C/C++ preprocessor for finding dependencies
Reasons for using the Waf preprocessor by default
Regarding the speed concerns:
Now if you do not want the Waf preprocessor, the tool +gccdeps* uses the .d files produced during the compilation to track the dependencies (useful when used with the boost libraries). It only works with gcc >= 4.4 though.
A dumb preprocessor is also available in the tool c_dumbpreproc
Constant representing a special token used in waflib.Tools.c_preproc.c_parser.start() iteration to switch to a header read previously
Limit on the amount of files to read in the dependency scanner
Set to True to track headers on files in /usr/include, else absolute paths are ignored (but it becomes very slow)
Apply trigraph rules (False by default)
Reserve the “#include <>” quotes for system includes (do not search for those includes). False by default.
Operators such as and/or/xor for c++. Set an empty dict to disable.
Match #include lines
Match macro definitions
Match macro functions
Match #pragma once statements
Match newlines
Filter C/C++ comments
Trigraph definitions
Escape characters
Number token
Operator token
Identifier token
String token
Character token
Token types
Expression types
Match expressions into tokens
Parser state is accepted
Parser state is ignored, for example preprocessor lines in an #if 0 block
Parser state is undefined at the moment
Parser state is skipped, for example preprocessor lines in a #elif 0 block
Replace function used with waflib.Tools.c_preproc.re_cpp
Filter the comments from a c/h file, and return the preprocessor lines. The regexps waflib.Tools.c_preproc.re_cpp, waflib.Tools.c_preproc.re_nl and waflib.Tools.c_preproc.re_lines are used internally.
Returns: | the preprocessor directives as a list of (keyword, line) |
---|---|
Return type: | a list of string pairs |
Operator precendence rules required for parsing expressions of the form:
#if 1 && 2 != 0
Remove the single quotes around an expression:
trimquotes("'test'") == "test"
Parameters: | s (string) – expression to transform |
---|---|
Return type: | string |
Apply arithmetic rules to compute a result
Parameters: |
|
---|---|
Return type: | int |
Try to obtain a number from a list of tokens. The token types are defined in waflib.Tools.ccroot.tok_types.
Parameters: | lst (list of tuple (tokentype, value)) – list of preprocessor tokens |
---|---|
Returns: | a pair containing the number and the rest of the list |
Return type: | tuple(value, list) |
Evaluate an expression recursively, for example:
1+1+1 -> 2+1 -> 3
Parameters: | lst (list of tuple(token, value)) – list of tokens |
---|---|
Returns: | the value and the remaining tokens |
Return type: | value, list |
Take a list of tokens and output true or false for #if/#elif conditions.
Parameters: | lst (list of tuple(token, value)) – a list of tokens |
---|---|
Returns: | a token |
Return type: | tuple(NUM, int) |
Wrap logging.errors, display the origin of the message when ‘-vv’ is set
Wrap logging.debug, the output is filtered for performance reasons
Merge a list of tokens into a string
Parameters: | lst (list of tuple(token, value)) – a list of tokens |
---|---|
Return type: | string |
Token pasting works between identifiers, particular operators, and identifiers and numbers:
a ## b -> ab
> ## = -> >=
a ## 2 -> a2
Parameters: |
|
---|
Replace the tokens in lst, using the macros provided in defs, and a list of macros that cannot be re-applied
Parameters: |
|
---|---|
Returns: | the new list of tokens |
Return type: | value, list |
Reduce the tokens by waflib.Tools.c_preproc.reduce_tokens() and try to return a 0/1 result by waflib.Tools.c_preproc.reduce_eval().
Parameters: |
|
---|---|
Return type: | int |
into a function or a simple macro without arguments
Parameters: | txt (string) – expression to exact a macro definition from |
---|---|
Returns: | a tuple containing the name, the list of arguments and the replacement |
Return type: | tuple(string, [list, list]) |
Process a line in the form:
#include foo
Parameters: |
|
---|---|
Returns: | the file name |
Return type: | string |
Parse a c character
Parameters: | txt (string) – character to parse |
---|---|
Returns: | a character literal |
Return type: | string |
Bases: object
Used by waflib.Tools.c_preproc.scan() to parse c/h files. Note that by default, only project headers are parsed.
list of lines read
Include paths
List of waflib.Node.Node found so far
List of file names that could not be matched by any file
Current file
Includes that must not be read (#pragma once)
Find a file from the input directory
Parameters: |
|
---|---|
Returns: | the node if found, or None |
Return type: |
Try to obtain a node from the filename based from the include paths. Will add the node found to waflib.Tools.c_preproc.c_parser.nodes or the file name to waflib.Tools.c_preproc.c_parser.names if no corresponding file is found. Called by waflib.Tools.c_preproc.c_parser.start.
Parameters: | filename (string) – header to find |
---|---|
Returns: | the node if found |
Return type: | waflib.Node.Node |
Add the lines from a header in the list of preprocessor lines to parse
Parameters: | node (waflib.Node.Node) – header |
---|
Preprocess a source file to obtain the dependencies, which are accumulated to waflib.Tools.c_preproc.c_parser.nodes and waflib.Tools.c_preproc.c_parser.names.
Parameters: |
|
---|
Get the dependencies using a c/c++ preprocessor, this is required for finding dependencies of the kind:
#include some_macro()
This function is bound as a task method on waflib.Tools.c.c and waflib.Tools.cxx.cxx for example