示例#1
0
 def handle_node_description(self, child_node):
     """Replaces an anonymous node description with a reference to a fresh node variable.
     
     The node description is stored for later reference.
     """
     variable = NodeVariable(self.get_anon_nodevar(), False)
     self.node_defs[variable] = child_node
     self.node_vars[variable.name] = variable
     return self.REPLACE(create_varref(variable.name))
示例#2
0
 def _get_variable(self, variable):
     """Returns a node variable object associated with the AST fragment `variable`.
     
     If `variable` is seen the first time, a new node variable is created using
     `NodeVariable.from_node`.
     """
     try:
         return self.node_vars[variable.name]
     except KeyError:
         node_variable = self.node_vars[variable.name] = NodeVariable.from_node(variable)
         self.node_defs[node_variable] = ast.NodeDescription(ast.Nop())
         return node_variable
示例#3
0
 def _get_variable(self, variable):
     """Returns a node variable object associated with the AST fragment `variable`.
     
     If `variable` is seen the first time, a new node variable is created using
     `NodeVariable.from_node`.
     """
     try:
         return self.node_vars[variable.name]
     except KeyError:
         node_variable = self.node_vars[
             variable.name] = NodeVariable.from_node(variable)
         self.node_defs[node_variable] = ast.NodeDescription(ast.Nop())
         return node_variable
示例#4
0
 def handle_node_variable_def(self, child_node):
     """Replaces a node variable definition with a reference, and stores it.
     
     If the variable has already been defined, the node descriptions are merged.
     """
     assert child_node.variable.type == ast.VariableTypes.NodeIdentifier
     node_variable = NodeVariable.from_node(child_node.variable)
     self.node_vars[child_node.variable.name] = node_variable
     
     if node_variable in self.node_defs:
         self.node_defs[node_variable] = ast.NodeDescription(
             ast.Conjunction([self.node_defs[node_variable].expression, 
                              child_node.expression.expression]))
     else:
         self.node_defs[node_variable] = child_node.expression
     
     return self.REPLACE(create_varref(child_node.variable.name, 
                                       container_type = child_node.variable.container))
示例#5
0
    def handle_node_variable_def(self, child_node):
        """Replaces a node variable definition with a reference, and stores it.
        
        If the variable has already been defined, the node descriptions are merged.
        """
        assert child_node.variable.type == ast.VariableTypes.NodeIdentifier
        node_variable = NodeVariable.from_node(child_node.variable)
        self.node_vars[child_node.variable.name] = node_variable

        if node_variable in self.node_defs:
            self.node_defs[node_variable] = ast.NodeDescription(
                ast.Conjunction([
                    self.node_defs[node_variable].expression,
                    child_node.expression.expression
                ]))
        else:
            self.node_defs[node_variable] = child_node.expression

        return self.REPLACE(
            create_varref(child_node.variable.name,
                          container_type=child_node.variable.container))
示例#6
0
 def _pad_nodesets(self):
     if all(var.is_set for var in self._node_vars):
         self._node_cursors.append(
             (NodeVariable("", False),
              self._query_compiler.get_padding_cursor(), self._node_tips))