The analysis package takes standard compiler.ast
nodes and annotates them with additional information which is then used
in subsequent activities such as code generation and documentation.
Below are tables showing the annotations used for various AST nodes:
Node | Annotation | Purpose |
---|---|---|
* | _contexts | Indicates the types that the node is considered to have, along with the context in which it has them. A dictionary mapping contexts to types/references. |
Node | Annotation | Purpose |
---|---|---|
Function Module Class Reference Stmt |
_namespace | A dictionary mapping names to lists of defining nodes for each name. Some Stmt nodes have _namespace annotations when employed by conditional or loop nodes. |
Function | _globals | Provides a list of globals used in the function. |
Name | _scope | Indicates which scope the name uses to refer to a variable. Examples: "local", "global". |
Name AssName Class Function Getattr |
_name_context | Indicates
the kind of local scope in which the name resides, or in the case of
Getattr the kind of scope from which the attribute was retrieved. (This
does not apply to AssAttr since the kind of scope can be inferred from
the type of node involved, whereas Getattr may involve either class or
instance attribute access.) Examples: "class", "instance". |
Module | _constants_table | A list of constants in the module. |
Module Name |
_module_name | The name of the module within which a name is defined. On Module nodes, this is the same as _qualified_name. |
Name AssName Module Class Function |
_qualified_name | Provides a qualified name for use in generated code (where appropriate) - see _name_context for additional guidance. |
Import | _names | Provides a list of name nodes referring to other modules. Each node contains an expr attribute referring to the module, along with module_name and as_name attributes referring to the naming details of the import operation. Additionally, a name attribute provides the resulting name to which the module is bound in the current namespace. |
Node | Annotation | Purpose |
---|---|---|
Reference | _class |
Indicates the class of a particular reference. |
Class | _instances | A list of instances (references) for a given class. |
CallFunc Const List Compare |
_instantiates | Indicates that the node instantiates a particular reference. |
Class | _inherited | A dictionary mapping names to superclasses which contain the definitions of such names for the annotated class. |
Node | Annotation | Purpose |
---|---|---|
Compare | _ops |
A list of operator objects summarising the binary operations employed in the comparison. |
If | _tests | A dictionary of helper nodes used to represent invocations of __true__ methods on tests associated with an if statement. The dictionary maps test nodes to their corresponding helper node. |
While | _test | A helper node used to represent invocations of __true__ methods on the continuation test of the while statement. |
And Or |
_nodes | A list of helper nodes, corresponding to elements in the nodes attribute of the affected node, where each represents invocations of __true__ methods on the corresponding original node. |
AssTuple | _next_call | A helper node used to represent invocations of next methods on any iterator found through its parent node. |
* | _ignored | Indicates that the block associated with a test in a conditional statement would be ignored due to the test always yielding a false value. |
* | _short_circuited | Indicates that the block associated with a test in a conditional statement would always be executed in preference to following blocks and that such following blocks and their associated test nodes need not be generated. |
* | _original | Indicates the original node used to produce a node within a specialisation. |
* | _parent | Indicates the parent node of a node - useful for adding sibling nodes (specialisations of functions) or for tracking the processing of expressions (assignment processing). |
Function | _specialisation | An attribute whose presence indicates that the node and its children represent a specialisation (as opposed to an original function). |
Function | _signatures | A list of signatures each corresponding to a specialisation in the _specialisations annotation; together, these annotations should be considered as a table. |
Function | _specialisations | A list of specialisations created for a particular function. |
CallFunc AssTuple AssList AssAttr AssName List For |
_targets | A list of specialisations that may be involved in a function or method invocation. |
CallFunc AssTuple AssList AssAttr AssName List For |
_args | A list of argument lists that are associated with each possible specialisation from _targets. |
CallFunc AssTuple AssList AssAttr AssName List For |
_refcontexts | A
list containing the meaning of references employed in the node's _args
attribute. This is used to generate code for parameters and also to
generate invocation target selection tests. Examples: "new" (used in instantiation), "context" (used in method calls), "top" (used to obtain the current subexpression). |
CallFunc AssTuple AssList AssAttr AssName List For |
_star_args | A list containing argument lists that are associated with each possible specialisation from _targets. |
CallFunc AssTuple AssList AssAttr AssName List For |
_dstar_args | A list containing argument lists that are associated with each possible specialisation from _targets. |