summaryrefslogtreecommitdiff
path: root/codegen/override.py
diff options
context:
space:
mode:
Diffstat (limited to 'codegen/override.py')
-rw-r--r--codegen/override.py144
1 files changed, 72 insertions, 72 deletions
diff --git a/codegen/override.py b/codegen/override.py
index 0e916b71..dda70338 100644
--- a/codegen/override.py
+++ b/codegen/override.py
@@ -18,20 +18,20 @@ def class2cname(klass, method):
else:
c_name += c
return c_name[1:] + '_' + method
-
+
import_pat = re.compile(r'\s*import\s+(\S+)\.([^\s.]+)\s+as\s+(\S+)')
class Overrides:
def __init__(self, filename=None):
self.modulename = None
- self.ignores = {}
- self.glob_ignores = []
- self.overrides = {}
+ self.ignores = {}
+ self.glob_ignores = []
+ self.overrides = {}
self.overridden = {}
- self.kwargs = {}
+ self.kwargs = {}
self.noargs = {}
self.onearg = {}
- self.staticmethod = {}
+ self.staticmethod = {}
self.classmethod = {}
self.startlines = {}
self.override_attrs = {}
@@ -43,19 +43,19 @@ class Overrides:
self.defines = {}
self.functions = {}
self.newstyle_constructors = {}
- if filename:
+ if filename:
self.handle_file(filename)
def handle_file(self, filename):
oldpath = os.getcwd()
-
+
fp = open(filename, 'r')
dirname = os.path.dirname(os.path.abspath(filename))
if dirname != oldpath:
os.chdir(dirname)
-
- # read all the components of the file ...
+
+ # read all the components of the file ...
bufs = []
startline = 1
lines = []
@@ -73,53 +73,53 @@ class Overrides:
linenum = linenum + 1
if lines:
bufs.append((string.join(lines, ''), startline))
- if not bufs: return
+ if not bufs: return
- for buf, startline in bufs:
- self.__parse_override(buf, startline, filename)
+ for buf, startline in bufs:
+ self.__parse_override(buf, startline, filename)
os.chdir(oldpath)
-
+
def __parse_override(self, buffer, startline, filename):
- pos = string.find(buffer, '\n')
- if pos >= 0:
- line = buffer[:pos]
- rest = buffer[pos+1:]
- else:
- line = buffer ; rest = ''
- words = string.split(line)
+ pos = string.find(buffer, '\n')
+ if pos >= 0:
+ line = buffer[:pos]
+ rest = buffer[pos+1:]
+ else:
+ line = buffer ; rest = ''
+ words = string.split(line)
command = words[0]
- if (command == 'ignore' or
+ if (command == 'ignore' or
command == 'ignore-' + sys.platform):
"ignore/ignore-platform [functions..]"
- for func in words[1:]:
+ for func in words[1:]:
self.ignores[func] = 1
- for func in string.split(rest):
+ for func in string.split(rest):
self.ignores[func] = 1
- elif (command == 'ignore-glob' or
+ elif (command == 'ignore-glob' or
command == 'ignore-glob-' + sys.platform):
- "ignore-glob/ignore-glob-platform [globs..]"
- for func in words[1:]:
+ "ignore-glob/ignore-glob-platform [globs..]"
+ for func in words[1:]:
self.glob_ignores.append(func)
- for func in string.split(rest):
- self.glob_ignores.append(func)
- elif command == 'override':
+ for func in string.split(rest):
+ self.glob_ignores.append(func)
+ elif command == 'override':
"override function/method [kwargs|noargs|onearg] [staticmethod|classmethod]"
- func = words[1]
- if 'kwargs' in words[1:]:
- self.kwargs[func] = 1
+ func = words[1]
+ if 'kwargs' in words[1:]:
+ self.kwargs[func] = 1
elif 'noargs' in words[1:]:
- self.noargs[func] = 1
+ self.noargs[func] = 1
elif 'onearg' in words[1:]:
- self.onearg[func] = True
+ self.onearg[func] = True
if 'staticmethod' in words[1:]:
- self.staticmethod[func] = True
+ self.staticmethod[func] = True
elif 'classmethod' in words[1:]:
- self.classmethod[func] = True
+ self.classmethod[func] = True
if func in self.overrides:
raise RuntimeError("Function %s is being overridden more than once" % (func,))
- self.overrides[func] = rest
+ self.overrides[func] = rest
self.startlines[func] = (startline + 1, filename)
elif command == 'override-attr':
"override-slot Class.attr"
@@ -148,9 +148,9 @@ class Overrides:
self.modulename = words[1]
elif command == 'include':
"include filename"
- for filename in words[1:]:
+ for filename in words[1:]:
self.handle_file(filename)
- for filename in string.split(rest):
+ for filename in string.split(rest):
self.handle_file(filename)
elif command == 'import':
"import module1 [\n module2, \n module3 ...]"
@@ -161,7 +161,7 @@ class Overrides:
elif command == 'define':
"define funcname [kwargs|noargs|onearg] [classmethod|staticmethod]"
"define Class.method [kwargs|noargs|onearg] [classmethod|staticmethod]"
- func = words[1]
+ func = words[1]
klass = None
if func.find('.') != -1:
klass, func = func.split('.', 1)
@@ -172,17 +172,17 @@ class Overrides:
else:
self.functions[func] = rest
- if 'kwargs' in words[1:]:
- self.kwargs[func] = 1
+ if 'kwargs' in words[1:]:
+ self.kwargs[func] = 1
elif 'noargs' in words[1:]:
- self.noargs[func] = 1
+ self.noargs[func] = 1
elif 'onearg' in words[1:]:
- self.onearg[func] = 1
+ self.onearg[func] = 1
if 'staticmethod' in words[1:]:
- self.staticmethod[func] = True
+ self.staticmethod[func] = True
elif 'classmethod' in words[1:]:
- self.classmethod[func] = True
+ self.classmethod[func] = True
self.startlines[func] = (startline + 1, filename)
@@ -190,21 +190,21 @@ class Overrides:
"new-constructor GType"
gtype, = words[1:]
self.newstyle_constructors[gtype] = True
-
+
def is_ignored(self, name):
- if self.ignores.has_key(name):
- return 1
- for glob in self.glob_ignores:
- if fnmatch.fnmatchcase(name, glob):
- return 1
- return 0
-
+ if self.ignores.has_key(name):
+ return 1
+ for glob in self.glob_ignores:
+ if fnmatch.fnmatchcase(name, glob):
+ return 1
+ return 0
+
def is_overriden(self, name):
- return self.overrides.has_key(name)
-
+ return self.overrides.has_key(name)
+
def is_already_included(self, name):
return self.overridden.has_key(name)
-
+
def override(self, name):
self.overridden[name] = 1
return self.overrides[name]
@@ -215,51 +215,51 @@ class Overrides:
def function(self, name):
return self.functions[name]
-
+
def getstartline(self, name):
return self.startlines[name]
def wants_kwargs(self, name):
- return self.kwargs.has_key(name)
-
+ return self.kwargs.has_key(name)
+
def wants_noargs(self, name):
- return self.noargs.has_key(name)
+ return self.noargs.has_key(name)
def wants_onearg(self, name):
- return self.onearg.has_key(name)
+ return self.onearg.has_key(name)
def is_staticmethod(self, name):
- return self.staticmethod.has_key(name)
+ return self.staticmethod.has_key(name)
def is_classmethod(self, name):
- return self.classmethod.has_key(name)
+ return self.classmethod.has_key(name)
def attr_is_overriden(self, attr):
return self.override_attrs.has_key(attr)
-
+
def attr_override(self, attr):
return self.override_attrs[attr]
-
+
def slot_is_overriden(self, slot):
return self.override_slots.has_key(slot)
-
+
def slot_override(self, slot):
return self.override_slots[slot]
-
+
def get_headers(self):
return self.headers
def get_body(self):
return self.body
-
+
def get_init(self):
return self.init
-
+
def get_imports(self):
return self.imports
def get_defines_for(self, klass):
return self.defines.get(klass, {})
-
+
def get_functions(self):
return self.functions