class documentation

class Variable: (source)

View In Hierarchy

A collection of possible bindings for a variable, along with their origins. A variable stores the bindings it can have as well as the CFG nodes at which the bindings occur. The bindings are stored in a list for determinicity; new bindings should be added via AddBinding or (FilterAnd)PasteVariable rather than appended to bindings directly to ensure that bindings and _data_id_to_bindings are updated together. We do this rather than making _data_id_to_binding a collections.OrderedDict because a CFG can easily have tens of thousands of variables, and it takes about 40x as long to create an OrderedDict instance as to create a list and a dict, while adding a binding to the OrderedDict takes 2-3x as long as adding it to both the list and the dict.

Method __init__ Initialize a new Variable. Called through Program.NewVariable.
Method __repr__ Undocumented
Method AddBinding Add another choice to this variable.
Method AssignToNewVariable Assign this variable to a new variable.
Method Bindings Filters down the possibilities of bindings for this variable.
Method Data Like Bindings(cfg_node), but only return the data.
Method Filter Filters down the possibilities of this variable.
Method FilteredData Like Filter(viewpoint), but only return the data.
Method PasteBinding Adds a binding from another variable to this one.
Method PasteVariable Adds all the bindings from another variable to this one.
Method RegisterBindingAtNode Undocumented
Class Variable __slots__ Undocumented
Instance Variable bindings Undocumented
Instance Variable id Undocumented
Instance Variable program Undocumented
Property data Undocumented
Property nodes Undocumented
Method _FindOrAddBinding Add a new binding if necessary, otherwise return existing binding.
Instance Variable _cfgnode_to_bindings Undocumented
Instance Variable _data_id_to_binding Undocumented
def __init__(self, program, variable_id): (source)

Initialize a new Variable. Called through Program.NewVariable.

def __repr__(self): (source)

Undocumented

def AddBinding(self, data, source_set=None, where=None): (source)

Add another choice to this variable. This will not overwrite this variable in the current CFG node. (It's legitimate to have multiple bindings for a variable on the same CFG node, e.g. if a union type is introduced at that node.) Arguments: data: A user specified object to uniquely identify this binding. source_set: An instance of SourceSet, i.e. a set of instances of Origin. where: Where in the CFG this variable was assigned to this binding. Returns: The new binding.

def AssignToNewVariable(self, where=None): (source)

Assign this variable to a new variable. This is essentially a copy: All entries in the Union will be copied to the new variable, but with the corresponding current variable binding as an origin. Arguments: where: CFG node where the assignment happens. Returns: A new variable.

def Bindings(self, viewpoint, strict=True): (source)

Filters down the possibilities of bindings for this variable. It determines this by analyzing the control flow graph. Any definition for this variable that is invisible from the current point in the CFG is filtered out. This function differs from Filter() in that it only honors the CFG, not the source sets. As such, it's much faster. Arguments: viewpoint: The CFG node at which to determine the possible bindings. strict: Whether to allow approximations for speed. Returns: A filtered list of bindings for this variable.

def Data(self, viewpoint): (source)

Like Bindings(cfg_node), but only return the data.

def Filter(self, viewpoint, strict=True): (source)

Filters down the possibilities of this variable. It analyzes the control flow graph. Any definition for this variable that is impossible at the current point in the CFG is filtered out. Arguments: viewpoint: The CFG node at which to determine the possible bindings. strict: Whether to allow approximations for speed. Returns: A filtered list of bindings for this variable.

def FilteredData(self, viewpoint, strict=True): (source)

Like Filter(viewpoint), but only return the data.

def PasteBinding(self, binding, where=None, additional_sources=None): (source)

Adds a binding from another variable to this one.

def PasteVariable(self, variable, where=None, additional_sources=None): (source)

Adds all the bindings from another variable to this one.

def RegisterBindingAtNode(self, binding, node): (source)

Undocumented

__slots__: tuple[str, ...] = (source)

Undocumented

bindings: list = (source)

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

def _FindOrAddBinding(self, data): (source)

Add a new binding if necessary, otherwise return existing binding.

_cfgnode_to_bindings: dict = (source)

Undocumented

_data_id_to_binding: dict = (source)

Undocumented