diff --git a/pyste/src/ClassExporter.py b/pyste/src/ClassExporter.py index e36c9dda..275b5cbd 100644 --- a/pyste/src/ClassExporter.py +++ b/pyste/src/ClassExporter.py @@ -618,7 +618,7 @@ class _VirtualWrapperGenerator(object): def __init__(self, class_, bases, info): self.class_ = class_ - self.bases = deepcopy(bases) + self.bases = bases[:] self.info = info self.wrapper_name = makeid(class_.FullName()) + '_Wrapper' self.virtual_methods = None diff --git a/pyste/src/CppParser.py b/pyste/src/CppParser.py index 023889b7..6412082e 100644 --- a/pyste/src/CppParser.py +++ b/pyste/src/CppParser.py @@ -38,15 +38,17 @@ class CppParser: return ' '.join(defines) - def UpdateCache(self, include, tail, declarations, header): - self._cache.append((include, tail, declarations, header)) + def UpdateCache(self, include, tail, decl_name, declarations, header): + self._cache.append((include, tail, decl_name, declarations, header)) if len(self._cache) > self._CACHE_SIZE: self._cache.pop(0) - def Cache(self, include, tail): - for cache_include, cache_tail, declarations, header in self._cache: - if cache_include == include and cache_tail == tail: + def Cache(self, include, tail, decl_name): + for cache_include, cache_tail, cache_decl, declarations, header in self._cache: + if cache_include == include \ + and cache_tail == tail \ + and cache_decl == decl_name: return declarations, header return None @@ -62,7 +64,7 @@ class CppParser: raise RuntimeError, 'Header file "%s" not found!' % name - def parse(self, include, tail=None): + def parse(self, include, tail=None, decl_name=None): '''Parses the given filename, and returns (declaration, header). The header returned is normally the same as the given to this method, except if tail is not None: in this case, the header is copied to a temp @@ -70,7 +72,7 @@ class CppParser: This temp filename is then returned. ''' # check if this header was already parsed - cached = self.Cache(include, tail) + cached = self.Cache(include, tail, decl_name) if cached: return cached filename = self.FindFileName(include) @@ -92,13 +94,15 @@ class CppParser: # call gccxml cmd = 'gccxml %s %s %s -fxml=%s' \ % (includes, defines, infilename, xmlfile) + if decl_name is not None: + cmd += ' "-fxml-start=%s"' % decl_name status = os.system(cmd) if status != 0 or not os.path.isfile(xmlfile): raise CppParserError, 'Error executing gccxml' # parse the resulting xml declarations = ParseDeclarations(xmlfile) # cache the results - self.UpdateCache(include, tail, declarations, infilename) + self.UpdateCache(include, tail, decl_name, declarations, infilename) # return the declarations return declarations, infilename finally: diff --git a/pyste/src/Exporter.py b/pyste/src/Exporter.py index c0f2a69f..e98988c0 100644 --- a/pyste/src/Exporter.py +++ b/pyste/src/Exporter.py @@ -8,9 +8,10 @@ class Exporter: INDENT = ' ' * 4 - def __init__(self, info, parser_tail=None): + def __init__(self, info, parser_tail=None, parser_decl=None): self.info = info self.parser_tail = parser_tail + self.parser_decl = parser_decl def Name(self): @@ -21,7 +22,8 @@ class Exporter: self.parser = parser header = self.info.include tail = self.parser_tail - declarations, parser_header = parser.parse(header, tail=tail) + decl = self.parser_decl + declarations, parser_header = parser.parse(header, tail, decl) self.parser_header = parser_header self.SetDeclarations(declarations) diff --git a/pyste/src/GCCXMLParser.py b/pyste/src/GCCXMLParser.py index dd752c22..3e900627 100644 --- a/pyste/src/GCCXMLParser.py +++ b/pyste/src/GCCXMLParser.py @@ -99,7 +99,7 @@ class GCCXMLParser(object): restricted, id = Check(id, 'r') decl = self.GetDecl(id) if isinstance(decl, Type): - res = deepcopy(decl) + res = decl.Copy() if const: res.const = const if volatile: @@ -259,7 +259,9 @@ class GCCXMLParser(object): type_ = self.GetType(element.get('type')) min = element.get('min') max = element.get('max') - array = ArrayType(type_.name, min, max, type_.const) + array = ArrayType(type_.name, type_.const) + array.min = min + array.max = max self.Update(id, array) diff --git a/pyste/src/declarations.py b/pyste/src/declarations.py index 00c9ce79..d32b376a 100644 --- a/pyste/src/declarations.py +++ b/pyste/src/declarations.py @@ -8,6 +8,8 @@ Module declarations class Declaration(object): 'Represents a basic declaration.' + __slots__ = 'name namespace location incomplete'.split() + def __init__(self, name, namespace): # the declaration name self.name = name @@ -42,6 +44,7 @@ class Declaration(object): class Class(Declaration): 'The declaration of a class or struct.' + __slots__= 'members abstract bases _members_count'.split() def __init__(self, name, namespace, members, abstract, bases): Declaration.__init__(self, name, namespace) # list of members @@ -114,6 +117,8 @@ class Class(Declaration): class NestedClass(Class): 'The declaration of a class/struct inside another class/struct.' + __slots__= 'class_ visibility'.split() + def __init__(self, name, class_, visib, members, abstract, bases): Class.__init__(self, name, None, members, abstract, bases) self.class_ = class_ @@ -128,6 +133,8 @@ class NestedClass(Class): class Base: 'Represents a base class of another class.' + __slots__= 'name visibility'.split() + def __init__(self, name, visibility=None): # class_ is the full name of the base class self.name = name @@ -148,6 +155,8 @@ class Scope: class Function(Declaration): 'The declaration of a function.' + __slots__= 'result parameters'.split() + def __init__(self, name, namespace, result, params): Declaration.__init__(self, name, namespace) # the result type: instance of Type, or None (constructors) @@ -182,6 +191,7 @@ class Function(Declaration): class Operator(Function): 'The declaration of a custom operator.' + def FullName(self): namespace = self.namespace or '' if not namespace.endswith('::'): @@ -193,6 +203,8 @@ class Operator(Function): class Method(Function): 'The declaration of a method.' + __slots__= 'visibility virtual abstract static class_ const'.split() + def __init__(self, name, class_, result, params, visib, virtual, abstract, static, const): Function.__init__(self, name, None, result, params) self.visibility = visib @@ -273,6 +285,8 @@ class ConverterOperator(ClassOperator): class Type(Declaration): 'Represents a type.' + __slots__= 'const default volatile restricted incomplete'.split() + def __init__(self, name, const=False, default=None, incomplete=False): Declaration.__init__(self, name, None) # whatever the type is constant or not @@ -299,21 +313,37 @@ class Type(Declaration): return const + self.name + def Copy(self): + t = self.__class__(self.name, self.const, self.default, self.incomplete) + t.volatile = self.volatile + t.restricted = self.restricted + return t + class ArrayType(Type): 'Represents an array.' - def __init__(self, name, min, max, const=False): + __slots__= 'min max'.split() + + def __init__(self, name, const=False, default=None, incomplete=False): 'min and max can be None.' Type.__init__(self, name, const) - self.min = min - self.max = max + self.min = None + self.max = None + + def Copy(self): + t = Type.Copy(self) + t.min = self.min + t.max = self.max + return t class ReferenceType(Type): 'A reference type.' + __slots__= 'expand'.split() + def __init__(self, name, const=False, default=None, incomplete=False, expandRef=True): Type.__init__(self, name, const, default, incomplete) self.expand = expandRef @@ -327,10 +357,18 @@ class ReferenceType(Type): return Type.FullName(self) + expand + def Copy(self): + t = Type.Copy(self) + t.expand = self.expand + return t + + class PointerType(Type): 'A pointer type.' + __slots__= 'expand'.split() + def __init__(self, name, const=False, default=None, incomplete=False, expandPointer=False): Type.__init__(self, name, const, default, incomplete) self.expand = expandPointer @@ -342,24 +380,31 @@ class PointerType(Type): if not self.expand: expand = '' return Type.FullName(self) + expand + + def Copy(self): + t = Type.Copy(self) + t.expand = self.expand + return t class FundamentalType(Type): 'One of the fundamental types (int, void...).' - def __init__(self, name, const=False): - Type.__init__(self, name, const) + def __init__(self, name, const=False, default=None, incomplete=False): + Type.__init__(self, name, const, default, incomplete) class FunctionType(Type): 'A pointer to a function.' - def __init__(self, result, params): + __slots__= 'result parameters name'.split() + + def __init__(self, result, parameters): Type.__init__(self, '', False) self.result = result - self.parameters = params + self.parameters = parameters self.name = self.FullName() @@ -368,16 +413,21 @@ class FunctionType(Type): params = [x.FullName() for x in self.parameters] full += '(%s)' % ', '.join(params) return full - + + + def Copy(self): + return FunctionType(self.result, self.parameters[:]) class MethodType(FunctionType): 'A pointer to a member function of a class.' - def __init__(self, result, params, class_): + __slots__= 'result parameters class_ name'.split() + + def __init__(self, result, parameters, class_): Type.__init__(self, '', False) self.result = result - self.parameters = params + self.parameters = parameters self.class_ = class_ self.name = self.FullName() @@ -386,12 +436,16 @@ class MethodType(FunctionType): params = [x.FullName() for x in self.parameters] full += '(%s)' % ', '.join(params) return full - - + + def Copy(self): + return MethodType(self.result, self.parameters[:], self.class_) + class Variable(Declaration): 'Represents a global variable.' + __slots__= 'type'.split() + def __init__(self, type, name, namespace): Declaration.__init__(self, name, namespace) # instance of Type @@ -402,6 +456,8 @@ class Variable(Declaration): class ClassVariable(Variable): 'Represents a class variable.' + __slots__= 'visibility static class_'.split() + def __init__(self, type, name, class_, visib, static): Variable.__init__(self, type, name, None) self.visibility = visib @@ -416,6 +472,8 @@ class ClassVariable(Variable): class Enumeration(Declaration): + __slots__= 'values'.split() + def __init__(self, name, namespace): Declaration.__init__(self, name, namespace) self.values = {} # dict of str => int @@ -431,6 +489,8 @@ class Enumeration(Declaration): class ClassEnumeration(Enumeration): + __slots__= 'class_ visibility'.split() + def __init__(self, name, class_, visib): Enumeration.__init__(self, name, None) self.class_ = class_ @@ -449,6 +509,8 @@ class ClassEnumeration(Enumeration): class Typedef(Declaration): + __slots__= 'type visibility'.split() + def __init__(self, type, name, namespace): Declaration.__init__(self, name, namespace) self.type = type @@ -463,6 +525,8 @@ class Union(Declaration): class ClassUnion(Union): + __slots__= 'class_ visibility'.split() + def __init__(self, name, class_, visib): Union.__init__(self, name, None) self.class_ = class_ diff --git a/pyste/src/pyste.py b/pyste/src/pyste.py index 1ec994bc..f083601f 100644 --- a/pyste/src/pyste.py +++ b/pyste/src/pyste.py @@ -114,7 +114,7 @@ def ParseArguments(): def CreateContext(): - 'create the context where a interface file can be executed' + 'create the context where a interface file will be executed' context = {} # infos context['Function'] = infos.FunctionInfo