[pygccxml-commit] SF.net SVN: pygccxml: [1255] pygccxml_dev/pygccxml/pdb_parser/reader.py
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-02-23 21:13:40
|
Revision: 1255 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1255&view=rev Author: roman_yakovenko Date: 2008-02-23 13:13:42 -0800 (Sat, 23 Feb 2008) Log Message: ----------- checkpoint Modified Paths: -------------- pygccxml_dev/pygccxml/pdb_parser/reader.py Modified: pygccxml_dev/pygccxml/pdb_parser/reader.py =================================================================== --- pygccxml_dev/pygccxml/pdb_parser/reader.py 2008-02-23 19:22:19 UTC (rev 1254) +++ pygccxml_dev/pygccxml/pdb_parser/reader.py 2008-02-23 21:13:42 UTC (rev 1255) @@ -21,25 +21,7 @@ def AsDiaSymbol( x ): return ctypes.cast( x, ctypes.POINTER( msdia.IDiaSymbol ) ) -def print_enums( smb ): - enums = smb.findChildren( SymTagEnum, None, 0 ) - for enum in iter( enums ): - enum = AsDiaSymbol( enum ) - print 'name: ', enum.name - if enum.container: - print 'container: ', enum.container.name - if enum.classParent: - print 'parent: ', enum.classParent.name - if enum.lexicalParent: - print 'lexical parent: ', enum.lexicalParent.Name - values = enum.findChildren( msdia.SymTagData, None, 0 ) - for v in iter(values): - v = AsDiaSymbol(v) - if v.classParent.symIndexId != enum.symIndexId: - continue - print ' value %s(%d): ' % ( v.name, v.value ) - def print_files( session ): files = iter( session.findFile( None, '', 0 ) ) for f in files: @@ -91,7 +73,7 @@ #~ print details.guess_class_type(s.udtKind) else: self.logger.debug( 'name( "%s" ) is **NOT** UDT symbol' % name ) - return False + return None def __list_main_classes( self ): #in this context main classes, are classes that were defined within a namespace @@ -120,9 +102,10 @@ return classes def __add_inner_classes( self, parent_class ): - self.logger.debug( 'adding inner classes to "%s"' % parent_class.dia_symbols[0].name ) - for dia_symbol in parent_class.dia_symbols: - self.logger.debug( '\tdia symbol id: %d' % dia_symbol.symIndexId ) + self.logger.debug( 'adding inner classes to "%s"' % parent_class.decl_string ) + for symbol_id in parent_class.dia_symbols: + self.logger.debug( '\tdia symbol id: %d' % symbol_id ) + dia_symbol = self.__dia_session.symbolById( symbol_id ) found = dia_symbol.findChildren( msdia.SymTagUDT, None, 0 ) for inner_dia_class in iter(found): inner_dia_class = AsDiaSymbol( inner_dia_class ) @@ -130,15 +113,57 @@ inner_name_splitter = details.get_name_splitter( inner_dia_class.name ) try: inner_klass = parent_class.class_( inner_name_splitter.name, recursive=False ) - inner_klass.dia_symbols.append( inner_dia_class ) + inner_klass.dia_symbols.add( inner_dia_class.symIndexId ) except parent_class.declaration_not_found_t: inner_klass = self.__create_class( inner_dia_class ) parent_class.adopt_declaration( inner_klass , details.guess_access_type( inner_dia_class.access ) ) self.__classes[ inner_dia_class.name ] = inner_klass - self.logger.debug( 'adding inner classes to "%s" - done' % parent_class.dia_symbols[0].name ) + self.logger.debug( 'adding inner classes to "%s" - done' % parent_class.decl_string ) - + def __create_enum( self, enum_smbl ): + name_splitter = details.get_name_splitter( enum_smbl.name ) + enum_decl = declarations.enumeration_t( name_splitter.name ) + values = enum_smbl.findChildren( msdia.SymTagData, None, 0 ) + for v in iter(values): + v = AsDiaSymbol(v) + if v.classParent.symIndexId != enum_smbl.symIndexId: + continue + enum_decl.append_value( v.name, v.value ) + if enum_decl.values: + return enum_decl + else: + #for some reason same enum could appear under global namespace and + #under the class, it was defined in. This is a criteria I use to distinguish + #between those cases + return None + + def __add_enums( self, parent_symbol_id ): + parent_symbol = self.__dia_session.symbolById( parent_symbol_id ) + self.logger.debug( 'adding enums to "%s" ' % parent_symbol.name ) + for enum_smbl in iter( parent_symbol.findChildren( SymTagEnum, None, 0 ) ): + enum_smbl = AsDiaSymbol( enum_smbl ) + enum_decl = self.__create_enum( enum_smbl ) + if not enum_decl: + continue + self.logger.debug( '\tfound %s' % str(enum_decl) ) + name_splitter = details.get_name_splitter( enum_smbl.name ) + if not name_splitter.scope_names: + self.global_ns.adopt_declaration( enum_decl ) + self.logger.debug( '\tenum "%s" was added to global namespace' % enum_decl.name ) + else: + try: + self.logger.debug( '\tadding enum "%s" to a namespace' % enum_decl.name ) + ns = self.__namespaces[ name_splitter.scope_names[-1] ] + ns.adopt_declaration( enum_decl ) + self.logger.debug( '\tadding enum "%s" to a namespace - done' % enum_decl.name ) + except KeyError: + self.logger.debug( '\tadding enum "%s" to a class' % enum_decl.name ) + klass = self.__classes[ name_splitter.scope_names[-1] ] + klass.adopt_declaration( enum_decl, details.guess_access_type( enum_smbl.access ) ) + self.logger.debug( '\tadding enum "%s" to a class - done' % enum_decl.name ) + self.logger.debug( 'adding enums to "%s" - done' % parent_symbol.name ) + def __create_nss( self ): nss = self.__namespaces.keys() nss.sort() @@ -157,7 +182,7 @@ name_splitter = details.get_name_splitter( dia_class.name ) klass = declarations.class_t( name_splitter.name ) klass.class_type = details.guess_class_type(dia_class.udtKind) - klass.dia_symbols = [ dia_class ] + klass.dia_symbols = set([dia_class.symIndexId]) return klass def __populate_scopes(self): @@ -166,24 +191,33 @@ for dia_class in main_classes: name_splitter = details.get_name_splitter( dia_class.name ) - parent_ns = self.global_ns - if name_splitter.scope_names: + if not name_splitter.scope_names: + parent_ns = self.global_ns + else: parent_ns = self.__namespaces[ name_splitter.scope_names[-1] ] - try: + + try: klass = parent_ns.class_( name_splitter.name, recursive=False ) - klass.dia_symbols.append( dia_class ) + klass.dia_symbols.add( dia_class.symIndexId ) except parent_ns.declaration_not_found_t: klass = self.__create_class( dia_class ) parent_ns.adopt_declaration( klass ) self.__classes[ dia_class.name ] = klass map( self.__add_inner_classes, self.__classes.values() ) + + self.__add_enums( self.dia_global_scope.symIndexId ) + for klass in self.__classes.itervalues(): + map( self.__add_enums, klass.dia_symbols ) + + #declarations.print_declarations( self.global_ns )#.namespace( 'ns1' ) ) + #declarations.print_declarations( self.global_ns.namespace( 'std' ) ) - declarations.print_declarations( self.global_ns.namespace( 'ns1' ) ) - declarations.print_declarations( self.global_ns.namespace( 'std' ) ) - if __name__ == '__main__': control_pdb = r'C:\dev\produce_pdb\Debug\produce_pdb.pdb' #control_pdb = r'xxx.pdb' reader = pdb_reader_t( control_pdb ) reader.read() + f = file( 'decls.cpp', 'w+' ) + declarations.print_declarations( reader.global_ns, writer=f.write ) + f.close() \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |