Commit 08cc20e9 authored by Stefan Behnel's avatar Stefan Behnel

declare internal visitor functions 'final' to inject direct function calls

parent 95447d55
...@@ -9,6 +9,8 @@ import ExprNodes ...@@ -9,6 +9,8 @@ import ExprNodes
import Errors import Errors
import DebugFlags import DebugFlags
import cython
class TreeVisitor(object): class TreeVisitor(object):
""" """
Base class for writing visitors for a Cython tree, contains utilities for Base class for writing visitors for a Cython tree, contains utilities for
...@@ -132,6 +134,7 @@ class TreeVisitor(object): ...@@ -132,6 +134,7 @@ class TreeVisitor(object):
getattr(last_node, 'pos', None), self.__class__.__name__, getattr(last_node, 'pos', None), self.__class__.__name__,
u'\n'.join(trace), e, stacktrace) u'\n'.join(trace), e, stacktrace)
@cython.final
def find_handler(self, obj): def find_handler(self, obj):
# to resolve, try entire hierarchy # to resolve, try entire hierarchy
cls = type(obj) cls = type(obj)
...@@ -152,6 +155,7 @@ class TreeVisitor(object): ...@@ -152,6 +155,7 @@ class TreeVisitor(object):
def visit(self, obj): def visit(self, obj):
return self._visit(obj) return self._visit(obj)
@cython.final
def _visit(self, obj): def _visit(self, obj):
try: try:
handler_method = self.dispatch_table[type(obj)] handler_method = self.dispatch_table[type(obj)]
...@@ -160,6 +164,7 @@ class TreeVisitor(object): ...@@ -160,6 +164,7 @@ class TreeVisitor(object):
self.dispatch_table[type(obj)] = handler_method self.dispatch_table[type(obj)] = handler_method
return handler_method(obj) return handler_method(obj)
@cython.final
def _visitchild(self, child, parent, attrname, idx): def _visitchild(self, child, parent, attrname, idx):
self.access_path.append((parent, attrname, idx)) self.access_path.append((parent, attrname, idx))
try: try:
...@@ -183,6 +188,7 @@ class TreeVisitor(object): ...@@ -183,6 +188,7 @@ class TreeVisitor(object):
def visitchildren(self, parent, attrs=None): def visitchildren(self, parent, attrs=None):
return self._visitchildren(parent, attrs) return self._visitchildren(parent, attrs)
@cython.final
def _visitchildren(self, parent, attrs): def _visitchildren(self, parent, attrs):
""" """
Visits the children of the given parent. If parent is None, returns Visits the children of the given parent. If parent is None, returns
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment