def visit_CompilerDirectivesNode(self, node): directives = node.directives if 'test_assert_path_exists' in directives: for path in directives['test_assert_path_exists']: if TreePath.find_first(node, path) is None: Errors.error( node.pos, "Expected path '%s' not found in result tree" % path) if 'test_fail_if_path_exists' in directives: for path in directives['test_fail_if_path_exists']: if TreePath.find_first(node, path) is not None: Errors.error( node.pos, "Unexpected path '%s' found in result tree" % path) self.visitchildren(node) return node
def __init__(self, output_dir): if etree is None: raise Errors.NoElementTreeInstalledException() self.output_dir = os.path.join(output_dir or os.curdir, 'cython_debug') self.tb = etree.TreeBuilder() # set by Cython.Compiler.ParseTreeTransforms.DebugTransform self.module_name = None self.start('cython_debug', attrs=dict(version='1.0'))
def _raise_compiler_error(self, child, e): import sys trace = [''] for parent, attribute, index in self.access_path: node = getattr(parent, attribute) if index is None: index = '' else: node = node[index] index = u'[%d]' % index trace.append(u'%s.%s%s = %s' % (parent.__class__.__name__, attribute, index, self.dump_node(node))) stacktrace, called_nodes = self._find_node_path(sys.exc_info()[2]) last_node = child for node, method_name, pos in called_nodes: last_node = node trace.append(u"File '%s', line %d, in %s: %s" % (pos[0], pos[1], method_name, self.dump_node(node))) raise Errors.CompilerCrash(getattr(last_node, 'pos', None), self.__class__.__name__, u'\n'.join(trace), e, stacktrace)