Captures the #include graph of a preprocessed file.
In the graph the line number is ignored for dummy roots and this one used instead
The file ID for a ‘dummy’ file. This is used as the artificial root node for all the pre-includes and the ITU
Simple specialisation of an exception class for the FileincludeGraph classes.
Exception for issues for dummy file ID’s.
Exception for issues for token counters.
Base class for visitors, see FigVisitorTreeNodeBase for base class for tree visitors.
Hierarchical visitor pattern. This is given a FileIncludeGraph as a graph node. theDepth is the current depth in the graph as an integer, theLine the line that is a non-monotonic sibling node ordinal.
Simple visitor that just collects the set of file IDs in the include graph and a count of how often they are seen.
Dictionary of number of times each file is seen: {file : count, ...}.
The set of file names seen.
Hierarchical visitor pattern. This is given a FileIncludeGraph as a graph node. theDepth is the current depth in the graph as an integer, theLine the line that is a non-monotonic sibling node ordinal.
This visitor can visit a graph of FileIncludeGraphRoot and FileIncludeGraph that recreates a tree of Node(s) the type of which are supplied by the user. Each node instance will be constructed with either an instance of a FileIncludeGraphRoot or FileIncludeGraph or, in the case of a pseudo root node then None.
Returns the current depth in this graph representation. Changes to this determine if the node is a child, sibling or ancestor.
Returns the top level node object as the only copy. This also finalises the tree.
Visit the give node.
Base class for nodes created by a tree visitor. See FigVisitorBase for the base class for non-tree visitors.
Add the object as a child.
This will be called on finalisation. This is an opportunity for the root (None) not to accumulate properties from its immediate children for example. For depth first finalisation the child class should call finalise on each child first as this function does.
The line number of the parent file that included me.
Recursive class that holds a graph of include files and and line numbers of the file that included them.
This class builds up a graph (actually a tree) of file includes. The insertion order is significant in that it is expected to be the order experienced by a translation unit processor. addBranch() is the way to add to the data structure.
theFile - a file ID (e.g. a path)
theState - a boolean conditional compilation state.
theCondition - a conditional compilation condition string e.g. “a >= b+2”.
thelogic - a string explanation of how that the file was found.
If theLogic is taken from an IncludeHandler as a list of items. e.g. [‘<foo.h>, CP=None, sys=None, usr=include/foo.h’] Each string after item[0] is of the form: key=value Where:
key is a key in self.INCLUDE_ORIGIN_CODES = is the ‘=’ character. value is the result, or ‘None’ if not found.
[0] is the invocation [-1] is the final resolution.
The intermediate ones are various tries in order. So [‘<foo.h>’, ‘CP=None’, ‘sys=None’, ‘usr=include/foo.h’] would mean:
This class does not distinguish between conditional compilation states that are True or False. Nor does this class evaluate theCondition in any way, it is merely stored for representation.
Hierarchical visitor pattern. This accepts a visitor object and calls visitor.visitGraph(self, depth, line) on that object where depth is the current depth in the graph as an integer and line the line that is a non-monotonic sibling node ordinal.
Adds a branch to the graph.
theFileS is a list of files that form the branch.
theLine is an integer value of the line number of the #include statement of the last named file in theFileS.
theIncFile is the file that is included.
theState is a boolean that describes the conditional compilation state.
theCondition is the conditional compilation test e.g. ‘1>0’
theLogic is a string representing how the branch was obtained.
May raise ExceptionFileIncludeGraph if:
Returns the condition, as a string, under which this file was included e.g. "(a > b) && (1 > 0)".
Returns the recorded conditional compilation state as a boolean.
Writes out the graph to a stream.
Returns the current file name.
Returns the findLogic string passed in in the constructor.
Yields each child node as a FileIncludeGraph object.
The total number of tokens seen by the PpLexer. Returns None if not initialised. Note: This is the number of tokens for this file only, it does not include the tokens that this file might include.
The total number of tokens seen by the PpLexer including tokens from files included by this one. Returns None if not initialised.
May raise ExceptionFileIncludeGraphTokenCounter is the token counters have been loaded inconsistently (i.e. the children have not been loaded).
The number of significant tokens seen by the PpLexer. A significant token is a non-whitespace, non-conditionally compiled token. Returns None if not initialised.
Note
This is the number of tokens for this file only, it does not include the tokens that this file might include.
The number of significant tokens seen by the PpLexer including tokens from files included by this one. A significant token is a non-whitespace, non-conditionally compiled token. Returns None if not initialised.
May raise ExceptionFileIncludeGraphTokenCounter is the token counters have been loaded inconsistently (i.e. the children have not been loaded).
Returns a list of lists of the branches with ‘#’ then the line number.
Returns the branch to the last inserted leaf as a list of branch strings.
Walks the graph and returns an integer that is the depth of the latest branch.
Returns the branch to the last inserted leaf as a list of pairs (filename, integer_line).
Returns the last inserted leaf, a FileIncludeGraph object.
Returns the last inserted node, a FileIncludeGraph object on the supplied branch.
This is generally used during dynamic construction by a caller that understands the state of the file include branch.
Sets the token counter for this node which is a PpTokenCount object. The PpLexer sets this as the token count for this file only. This files #includes are a separate token counter.
Gets the token counter for this node, a PpTokenCount object.
Root class of the file include graph. This is used when there is a virtual or dummy root. It contains a list of FileIncludeGraph objects. In this way it can represent the list of graphs that would result from a list of pre-includes followed by the ITU itself.
In practice this is used by the PpLexer for this purpose where the dummy root is represented by None.
Hierarchical visitor pattern. This accepts a visitor object and calls visitor.visitGraph(self, depth, line) on that object where depth is the current depth in the graph as an integer and line the line that is a non-monotonic sibling node ordinal.
Add a FileIncludeGraph object.
Dump the node for debug/trace.
The latest FileIncludeGraph object I have. Will raise a ExceptionFileIncludeGraphRoot if nothing there.
Returns the number of FileIncludeGraph objects.