[pygccxml-commit] SF.net SVN: pygccxml: [1251] pygccxml_dev/pygccxml
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-02-21 06:50:53
|
Revision: 1251 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1251&view=rev Author: roman_yakovenko Date: 2008-02-20 22:50:59 -0800 (Wed, 20 Feb 2008) Log Message: ----------- small restructuring Modified Paths: -------------- pygccxml_dev/pygccxml/utils/__init__.py Added Paths: ----------- pygccxml_dev/pygccxml/pdb_parser/ pygccxml_dev/pygccxml/pdb_parser/msdia_details.py pygccxml_dev/pygccxml/pdb_parser/pdb_reader.py Removed Paths: ------------- pygccxml_dev/pygccxml/parser/msdia_details.py pygccxml_dev/pygccxml/parser/pdb_reader.py Deleted: pygccxml_dev/pygccxml/parser/msdia_details.py =================================================================== --- pygccxml_dev/pygccxml/parser/msdia_details.py 2008-02-21 06:47:58 UTC (rev 1250) +++ pygccxml_dev/pygccxml/parser/msdia_details.py 2008-02-21 06:50:59 UTC (rev 1251) @@ -1,91 +0,0 @@ -import os -import comtypes -import comtypes.client -import _winreg as win_registry -from distutils import msvccompiler - -class msdia_searcher_t: - def __init__( self ): - self.root_reg_key = win_registry.HKEY_LOCAL_MACHINE - - def find_path( self ): - vss_installed = self.__get_installed_vs_dirs() - msdia_dlls = self.__get_msdia_dll_paths( vss_installed ) - #D:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\ - #D:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\Debugger\msdia71.dll - #C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\msdia90.dll - if 1 == len(msdia_dlls): - return msdia_dlls[0] - else: - #TODO find the highest version and use it. - pass - - def __get_msdia_dll_paths( self, vss_installed ): - msdia_dlls = [] - for vs in vss_installed: - vs = os.path.split( vs )[0] - debug_dir = os.path.join( vs, 'Packages', 'Debugger' ) - files = filter( lambda f: f.startswith( 'msdia' ) and f.endswith( '.dll' ) - , os.listdir( debug_dir ) ) - if not files: - continue - msdia_dlls.extend([ os.path.join( debug_dir, f ) for f in files ]) - if not msdia_dlls: - raise RuntimeError( 'pygccxml unable to find out msdiaXX.dll location' ) - return msdia_dlls - - def __get_installed_vs_dirs( self ): - vs_reg_path = 'Software\Microsoft\VisualStudio' - vss = self.read_keys( self.root_reg_key, vs_reg_path ) - vs_installed_and_exist = [] - - for vs_installed in vss: - values = self.read_values( self.root_reg_key, vs_reg_path + '\\' + vs_installed ) - try: - vs_installed_and_exist.append( os.path.realpath( values['installdir'] ) ) - except KeyError: - pass - - if not vs_installed_and_exist: - raise RuntimeError( 'pygccxml unable to find out a Visual Studio installation directory' ) - return vs_installed_and_exist - - - def read_keys(self, base, key): - return msvccompiler.read_keys(base, key) - - def read_values(self, base, key): - return msvccompiler.read_values(base, key) - -msdia_path = msdia_searcher_t().find_path() - -comtypes_client_gen_dir = comtypes.client.gen_dir -try: - comtypes.client.gen_dir = None - msdia = comtypes.client.GetModule( msdia_path ) -finally: - comtypes.client.gen_dir = comtypes_client_gen_dir - -#Adding code, that was not generated for some reason. - -class UdtKind: - UdtStruct, UdtClass, UdtUnion = ( 0, 1, 2 ) - -msdia.UdtKind = UdtKind - -class NameSearchOptions: - nsNone = 0 - nsfCaseSensitive = 0x1 - nsfCaseInsensitive = 0x2 - nsfFNameExt = 0x4 - nsfRegularExpression = 0x8 - nsfUndecoratedName = 0x10 - - # For backward compabibility: - nsCaseSensitive = nsfCaseSensitive - nsCaseInsensitive = nsfCaseInsensitive - nsFNameExt = nsfFNameExt - nsRegularExpression = nsfRegularExpression | nsfCaseSensitive - nsCaseInRegularExpression = nsfRegularExpression | nsfCaseInsensitive - -msdia.NameSearchOptions = NameSearchOptions Deleted: pygccxml_dev/pygccxml/parser/pdb_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/pdb_reader.py 2008-02-21 06:47:58 UTC (rev 1250) +++ pygccxml_dev/pygccxml/parser/pdb_reader.py 2008-02-21 06:50:59 UTC (rev 1251) @@ -1,164 +0,0 @@ -import os -import sys -import ctypes -import comtypes -import comtypes.client -from msdia_details import msdia - -sys.path.append( r'../..' ) -#sys.path.append( r'C:\dev\language-binding\pygccxml_dev' ) - -from pygccxml import utils -from pygccxml import declarations - - - -SymTagEnum = 12 - -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: - f = ctypes.cast( f, ctypes.POINTER(msdia.IDiaSourceFile) ) - print 'File: ', f.fileName - -#~ print_files( session ) -#print_enums( root_symbol ) -def guess_class_type( udt_kind ): - if msdia.UdtKind.UdtStruct == udt_kind: - return declarations.CLASS_TYPES.STRUCT - elif msdia.UdtKind.UdtClass == udt_kind: - return declarations.CLASS_TYPES.CLASS - else: - return declarations.CLASS_TYPES.UNION - -class pdb_reader_t(object): - def __init__(self, pdb_file_path ): - self.logger = utils.loggers.gccxml - self.logger.debug( 'creating DiaSource object' ) - self.__dia_source = comtypes.client.CreateObject( msdia.DiaSource ) - self.logger.debug( 'loading pdb file: %s' % pdb_file_path ) - self.__dia_source.loadDataFromPdb(pdb_file_path) - self.logger.debug( 'opening session' ) - self.__dia_session = self.__dia_source.openSession() - self.__global_ns = declarations.namespace_t( '::' ) - self.__id2decl = {} #hash table unique symbol id : pygccxml declaration - - def read(self): - self.__populate_scopes() - - files = iter( self.__dia_session.findFile( None, '', 0 ) ) - for f in files: - f = ctypes.cast( f, ctypes.POINTER(msdia.IDiaSourceFile) ) - print 'File: ', f.fileName - - @property - def dia_global_scope(self): - return self.__dia_session.globalScope - - @property - def global_ns(self): - return self.__global_ns - - def __split_scope_identifiers( self, name ): - result = [] - tmp = name.split( '::' ) - tmp.reverse() - while tmp: - token = tmp.pop() - less_count = token.count( '<' ) - greater_count = token.count( '>' ) - if less_count != greater_count: - while less_count != greater_count: - next_token = tmp.pop() - token = token + '::' + next_token - less_count += next_token.count( '<' ) - greater_count += next_token.count( '>' ) - result.append( token ) - return result - - def __scope_identifie - - def __found_udt( self, name ): - self.logger.debug( 'testing whether name( "%s" ) is UDT symbol' % name ) - flags = msdia.NameSearchOptions.nsfCaseSensitive - found = self.dia_global_scope.findChildren( msdia.SymTagUDT, name, flags ) - if found.Count == 1: - self.logger.debug( 'name( "%s" ) is UDT symbol' % name ) - return AsDiaSymbol( fount.Item[0] ) - elif 1 < found.Count: - raise RuntimeError( "duplicated UDTs with name '%s', were found" % name ) - #~ self.logger.debug( 'name( "%s" ) is UDT symbol' % name ) - #~ return [AsDiaSymbol( s ) for s in iter(found)] - #~ for s in iter(found): - #~ s = - #~ print s.name - #~ print guess_class_type(s.udtKind) - else: - self.logger.debug( 'name( "%s" ) is **NOT** UDT symbol' % name ) - return False - - def __populate_scopes(self): - classes = {} #full name to list of symbols - dia_classes = self.dia_global_scope.findChildren( msdia.SymTagUDT, None, 0 ) - for dia_class in iter( dia_classes ): - dia_class = AsDiaSymbol( dia_class ) - if not classes.has_key( dia_class.name ): - classes[ dia_class.name ] = [ dia_class ] - else: - classes[ dia_class.name ].append( dia_class ) - for name, class_list in classes.iteritems(): - if len( class_list ) != 1: - print len( class_list ), name - - #~ klass = declarations.class_t(dia_class.name) - #~ klass.class_type = guess_class_type( dia_class.udtKind ) - #~ scope_identifiers = self.__split_scope_identifiers( dia_class.name ) - #~ if 1 == len(scope_identifiers): - #~ classes.append( klass ) - #~ else: - #~ ns_ref = self.global_ns - #~ for i in range( len(scope_identifiers) - 1): - #~ full_identifier = '::'.join( scope_identifiers[0:i+1] ) - #~ if not self.__is_udt( full_identifier ): - #~ #we have namespace - #~ try: - #~ ns_ref = ns_ref.namespace( scope_identifiers[i], recursive=False) - #~ except ns_ref.declaration_not_found_t: - #~ new_ns = declarations.namespace_t( scope_identifiers[i] ) - #~ ns_ref.adopt_declaration( new_ns ) - #~ ns_ref = new_ns - #~ else: - #~ classes.append( klass ) - #~ break - #~ classes.sort( lambda klass1, klass2: cmp( klass1.name, klass2.name ) ) - #~ for i in classes: - #~ print str(i) - #~ declarations.print_declarations( self.global_ns ) - -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() Copied: pygccxml_dev/pygccxml/pdb_parser/msdia_details.py (from rev 1249, pygccxml_dev/pygccxml/parser/msdia_details.py) =================================================================== --- pygccxml_dev/pygccxml/pdb_parser/msdia_details.py (rev 0) +++ pygccxml_dev/pygccxml/pdb_parser/msdia_details.py 2008-02-21 06:50:59 UTC (rev 1251) @@ -0,0 +1,91 @@ +import os +import comtypes +import comtypes.client +import _winreg as win_registry +from distutils import msvccompiler + +class msdia_searcher_t: + def __init__( self ): + self.root_reg_key = win_registry.HKEY_LOCAL_MACHINE + + def find_path( self ): + vss_installed = self.__get_installed_vs_dirs() + msdia_dlls = self.__get_msdia_dll_paths( vss_installed ) + #D:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\ + #D:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\Debugger\msdia71.dll + #C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\msdia90.dll + if 1 == len(msdia_dlls): + return msdia_dlls[0] + else: + #TODO find the highest version and use it. + pass + + def __get_msdia_dll_paths( self, vss_installed ): + msdia_dlls = [] + for vs in vss_installed: + vs = os.path.split( vs )[0] + debug_dir = os.path.join( vs, 'Packages', 'Debugger' ) + files = filter( lambda f: f.startswith( 'msdia' ) and f.endswith( '.dll' ) + , os.listdir( debug_dir ) ) + if not files: + continue + msdia_dlls.extend([ os.path.join( debug_dir, f ) for f in files ]) + if not msdia_dlls: + raise RuntimeError( 'pygccxml unable to find out msdiaXX.dll location' ) + return msdia_dlls + + def __get_installed_vs_dirs( self ): + vs_reg_path = 'Software\Microsoft\VisualStudio' + vss = self.read_keys( self.root_reg_key, vs_reg_path ) + vs_installed_and_exist = [] + + for vs_installed in vss: + values = self.read_values( self.root_reg_key, vs_reg_path + '\\' + vs_installed ) + try: + vs_installed_and_exist.append( os.path.realpath( values['installdir'] ) ) + except KeyError: + pass + + if not vs_installed_and_exist: + raise RuntimeError( 'pygccxml unable to find out a Visual Studio installation directory' ) + return vs_installed_and_exist + + + def read_keys(self, base, key): + return msvccompiler.read_keys(base, key) + + def read_values(self, base, key): + return msvccompiler.read_values(base, key) + +msdia_path = msdia_searcher_t().find_path() + +comtypes_client_gen_dir = comtypes.client.gen_dir +try: + comtypes.client.gen_dir = None + msdia = comtypes.client.GetModule( msdia_path ) +finally: + comtypes.client.gen_dir = comtypes_client_gen_dir + +#Adding code, that was not generated for some reason. + +class UdtKind: + UdtStruct, UdtClass, UdtUnion = ( 0, 1, 2 ) + +msdia.UdtKind = UdtKind + +class NameSearchOptions: + nsNone = 0 + nsfCaseSensitive = 0x1 + nsfCaseInsensitive = 0x2 + nsfFNameExt = 0x4 + nsfRegularExpression = 0x8 + nsfUndecoratedName = 0x10 + + # For backward compabibility: + nsCaseSensitive = nsfCaseSensitive + nsCaseInsensitive = nsfCaseInsensitive + nsFNameExt = nsfFNameExt + nsRegularExpression = nsfRegularExpression | nsfCaseSensitive + nsCaseInRegularExpression = nsfRegularExpression | nsfCaseInsensitive + +msdia.NameSearchOptions = NameSearchOptions Copied: pygccxml_dev/pygccxml/pdb_parser/pdb_reader.py (from rev 1250, pygccxml_dev/pygccxml/parser/pdb_reader.py) =================================================================== --- pygccxml_dev/pygccxml/pdb_parser/pdb_reader.py (rev 0) +++ pygccxml_dev/pygccxml/pdb_parser/pdb_reader.py 2008-02-21 06:50:59 UTC (rev 1251) @@ -0,0 +1,164 @@ +import os +import sys +import ctypes +import comtypes +import comtypes.client +from msdia_details import msdia + +sys.path.append( r'../..' ) +#sys.path.append( r'C:\dev\language-binding\pygccxml_dev' ) + +from pygccxml import utils +from pygccxml import declarations + + + +SymTagEnum = 12 + +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: + f = ctypes.cast( f, ctypes.POINTER(msdia.IDiaSourceFile) ) + print 'File: ', f.fileName + +#~ print_files( session ) +#print_enums( root_symbol ) +def guess_class_type( udt_kind ): + if msdia.UdtKind.UdtStruct == udt_kind: + return declarations.CLASS_TYPES.STRUCT + elif msdia.UdtKind.UdtClass == udt_kind: + return declarations.CLASS_TYPES.CLASS + else: + return declarations.CLASS_TYPES.UNION + +class pdb_reader_t(object): + def __init__(self, pdb_file_path ): + self.logger = utils.loggers.gccxml + self.logger.debug( 'creating DiaSource object' ) + self.__dia_source = comtypes.client.CreateObject( msdia.DiaSource ) + self.logger.debug( 'loading pdb file: %s' % pdb_file_path ) + self.__dia_source.loadDataFromPdb(pdb_file_path) + self.logger.debug( 'opening session' ) + self.__dia_session = self.__dia_source.openSession() + self.__global_ns = declarations.namespace_t( '::' ) + self.__id2decl = {} #hash table unique symbol id : pygccxml declaration + + def read(self): + self.__populate_scopes() + + files = iter( self.__dia_session.findFile( None, '', 0 ) ) + for f in files: + f = ctypes.cast( f, ctypes.POINTER(msdia.IDiaSourceFile) ) + print 'File: ', f.fileName + + @property + def dia_global_scope(self): + return self.__dia_session.globalScope + + @property + def global_ns(self): + return self.__global_ns + + def __split_scope_identifiers( self, name ): + result = [] + tmp = name.split( '::' ) + tmp.reverse() + while tmp: + token = tmp.pop() + less_count = token.count( '<' ) + greater_count = token.count( '>' ) + if less_count != greater_count: + while less_count != greater_count: + next_token = tmp.pop() + token = token + '::' + next_token + less_count += next_token.count( '<' ) + greater_count += next_token.count( '>' ) + result.append( token ) + return result + + def __scope_identifie + + def __found_udt( self, name ): + self.logger.debug( 'testing whether name( "%s" ) is UDT symbol' % name ) + flags = msdia.NameSearchOptions.nsfCaseSensitive + found = self.dia_global_scope.findChildren( msdia.SymTagUDT, name, flags ) + if found.Count == 1: + self.logger.debug( 'name( "%s" ) is UDT symbol' % name ) + return AsDiaSymbol( fount.Item[0] ) + elif 1 < found.Count: + raise RuntimeError( "duplicated UDTs with name '%s', were found" % name ) + #~ self.logger.debug( 'name( "%s" ) is UDT symbol' % name ) + #~ return [AsDiaSymbol( s ) for s in iter(found)] + #~ for s in iter(found): + #~ s = + #~ print s.name + #~ print guess_class_type(s.udtKind) + else: + self.logger.debug( 'name( "%s" ) is **NOT** UDT symbol' % name ) + return False + + def __populate_scopes(self): + classes = {} #full name to list of symbols + dia_classes = self.dia_global_scope.findChildren( msdia.SymTagUDT, None, 0 ) + for dia_class in iter( dia_classes ): + dia_class = AsDiaSymbol( dia_class ) + if not classes.has_key( dia_class.name ): + classes[ dia_class.name ] = [ dia_class ] + else: + classes[ dia_class.name ].append( dia_class ) + for name, class_list in classes.iteritems(): + if len( class_list ) != 1: + print len( class_list ), name + + #~ klass = declarations.class_t(dia_class.name) + #~ klass.class_type = guess_class_type( dia_class.udtKind ) + #~ scope_identifiers = self.__split_scope_identifiers( dia_class.name ) + #~ if 1 == len(scope_identifiers): + #~ classes.append( klass ) + #~ else: + #~ ns_ref = self.global_ns + #~ for i in range( len(scope_identifiers) - 1): + #~ full_identifier = '::'.join( scope_identifiers[0:i+1] ) + #~ if not self.__is_udt( full_identifier ): + #~ #we have namespace + #~ try: + #~ ns_ref = ns_ref.namespace( scope_identifiers[i], recursive=False) + #~ except ns_ref.declaration_not_found_t: + #~ new_ns = declarations.namespace_t( scope_identifiers[i] ) + #~ ns_ref.adopt_declaration( new_ns ) + #~ ns_ref = new_ns + #~ else: + #~ classes.append( klass ) + #~ break + #~ classes.sort( lambda klass1, klass2: cmp( klass1.name, klass2.name ) ) + #~ for i in classes: + #~ print str(i) + #~ declarations.print_declarations( self.global_ns ) + +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() Modified: pygccxml_dev/pygccxml/utils/__init__.py =================================================================== --- pygccxml_dev/pygccxml/utils/__init__.py 2008-02-21 06:47:58 UTC (rev 1250) +++ pygccxml_dev/pygccxml/utils/__init__.py 2008-02-21 06:50:59 UTC (rev 1251) @@ -19,7 +19,7 @@ handler = logging.StreamHandler() handler.setFormatter( logging.Formatter( os.linesep + '%(levelname)s %(message)s' ) ) logger.addHandler(handler) - logger.setLevel(logging.INFO) + logger.setLevel(logging.DEBUG) return logger class loggers: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |