An Instruction represents an executable unit of a Python program.
Almost all simple statements correspond to Instructions, except for statements likes pass, continue, and break, whose effects are already represented in the structure of the control-flow graph.
In addition to simple statements, assignments that take place outside of simple statements such as implicitly in a function or class definition also correspond to Instructions.
The complete set of places where Instructions occur in source are listed here:
- <Instruction> (Any node in INSTRUCTION_AST_NODES used as a statement.)
2. if <Instruction>: ... (elif is the same.) 3+4. for <Instruction> in <Instruction>: ... 5. while <Instruction>: ... 6. try: ... except <Instruction>: ... 7. TODO(dbieber): Test for "with <Instruction>:"...
In the code:
@decorator def fn(args=defaults):
body
Outside of the function definition, we get the following instructions: 8. Each decorator is an Instruction. 9. Each default is an Instruction. 10. The assignment of the function def to the function name is an Instruction. Inside the function definition, we get the following instructions: 11. An Instruction for the assignment of values to the arguments. (1, again) And then the body can consist of multiple Instructions too.
Likewise in the code:
@decorator class C(object):
body
The following are Instructions: (8, again) Each decorator is an Instruction 12. The assignment of the class to the variable C is an Instruction. (1, again) And then the body can consist of multiple Instructions too. 13. TODO(dbieber): The base class (object) is an Instruction too.
Class |
|
Visitor that computes an ordered list of accesses. |
Class |
|
Represents an executable unit of a Python program. |
Function | access |
Undocumented |
Function | access |
Undocumented |
Function | access |
Undocumented |
Function | access |
Undocumented |
Function | access |
Undocumented |
Function | access |
Undocumented |
Function | create |
Undocumented |
Function | get |
Get all accesses for an AST node, in depth-first AST field order. |
Function | get |
Get all reads for an AST node, in depth-first AST field order. |
Function | get |
Get all writes for an AST node, in depth-first AST field order. |
Function | represent |
Whether AST nodes node1 and node2 represent the same program syntactically. |
Constant | ARGS |
Undocumented |
Constant | CLASS |
Undocumented |
Constant | EXCEPTION |
Undocumented |
Constant | FUNCTION |
Undocumented |
Constant | INSTRUCTION |
Undocumented |
Constant | ITERATOR |
Undocumented |
Constant | KWARG |
Undocumented |
Constant | KWONLYARGS |
Undocumented |
Constant | READ |
Undocumented |
Constant | READ |
Undocumented |
Constant | SIMPLE |
Undocumented |
Constant | VARARG |
Undocumented |
Constant | WRITE |
Undocumented |
Constant | WRITE |
Undocumented |
Function | _canonicalize |
Undocumented |
Get all reads for an AST node, in depth-first AST field order.
Parameters | |
ast | The AST node of interest. |
Returns | |
A list of writes performed by that AST node. |
Get all writes for an AST node, in depth-first AST field order.
Parameters | |
ast | The AST node of interest. |
Returns | |
A list of writes performed by that AST node. |
Whether AST nodes node1 and node2 represent the same program syntactically.
Two programs are the same syntactically is they have equivalent ASTs, up to some small changes. The context field of Name nodes can change without the syntax represented by the AST changing. This allows for example for the short program 'x' (a read) to match with a subprogram 'x' of 'x = 3' (in which x is a write), since these two programs are the same syntactically ('x' and 'x').
Except for the context field of Name nodes, the two nodes are recursively checked for exact equality.
Parameters | |
node1 | An AST node. This can be an ast.AST object, a primitive, or a list of AST nodes (primitives or ast.AST objects). |
node2 | An AST node. This can be an ast.AST object, a primitive, or a list of AST nodes (primitives or ast.AST objects). |
Returns | |
Whether the two nodes represent equivalent programs. |
Undocumented
Value |
|