From 9dbeda6e78adf9d85e67bfa2e29876846038b2fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 3 Feb 2012 19:05:54 +0000 Subject: [PATCH] Support const methods. Also several enhancements to C decl parser. --- specs/scripts/cdecl.py | 20 ++++++++++++++++++-- specs/stdapi.py | 9 ++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/specs/scripts/cdecl.py b/specs/scripts/cdecl.py index d6ee058..940ce44 100755 --- a/specs/scripts/cdecl.py +++ b/specs/scripts/cdecl.py @@ -189,6 +189,11 @@ class DeclParser: value = 0 while self.lookahead() != '}': type, name = self.parse_named_type() + + if self.match(':'): + self.consume() + self.consume() + if self.match(','): self.consume(',') self.consume(';') @@ -205,6 +210,8 @@ class DeclParser: if self.match(';'): return self.consume(':') + if self.lookahead() in ('public', 'protected'): + self.consume() base = self.consume() self.consume('{') @@ -225,7 +232,7 @@ class DeclParser: ret = self.parse_type() - if self.match('__stdcall'): + if self.match('__stdcall', 'WINAPI'): self.consume() creator = 'StdFunction' @@ -244,7 +251,10 @@ class DeclParser: args.append(arg) if self.match(','): self.consume() - self.consume() == ')' + self.consume(')') + if self.lookahead() == 'const': + self.consume() + extra = ', const=True' + extra print ' %s(%s, "%s", [%s]%s),' % (creator, ret, name, ', '.join(args), extra) @@ -256,6 +266,12 @@ class DeclParser: arg = '(%s, "%s")' % (type, name) if 'out' in tags: arg = 'Out' + arg + + if self.match('='): + self.consume() + while not self.match(',', ')'): + self.consume() + return arg def parse_tags(self): diff --git a/specs/stdapi.py b/specs/stdapi.py index d9fd545..6aa4089 100644 --- a/specs/stdapi.py +++ b/specs/stdapi.py @@ -361,10 +361,17 @@ class Interface(Type): class Method(Function): - def __init__(self, type, name, args): + def __init__(self, type, name, args, const=False): Function.__init__(self, type, name, args, call = '__stdcall') for index in range(len(self.args)): self.args[index].index = index + 1 + self.const = const + + def prototype(self, name=None): + s = Function.prototype(self, name) + if self.const: + s += ' const' + return s class String(Type): -- 2.7.4