[pygccxml-commit] SF.net SVN: pygccxml:[1478] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2008-12-19 22:50:38
|
Revision: 1478
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1478&view=rev
Author: roman_yakovenko
Date: 2008-12-19 22:50:32 +0000 (Fri, 19 Dec 2008)
Log Message:
-----------
commit few changes, which allow to extract all public(exported) symbols
Modified Paths:
--------------
pygccxml_dev/pygccxml/msvc/common_utils.py
pygccxml_dev/pygccxml/msvc/mspdb/enums.py
pygccxml_dev/pygccxml/msvc/mspdb/loader.py
pygccxml_dev/unittests/autoconfig.py
Added Paths:
-----------
pygccxml_dev/unittests/mspdb_playground.py
Property Changed:
----------------
pygccxml_dev/pygccxml/msvc/
Property changes on: pygccxml_dev/pygccxml/msvc
___________________________________________________________________
Added: svn:ignore
+ *.pyc
Modified: pygccxml_dev/pygccxml/msvc/common_utils.py
===================================================================
--- pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-18 06:51:01 UTC (rev 1477)
+++ pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-19 22:50:32 UTC (rev 1478)
@@ -1,28 +1,23 @@
import ctypes
-import ctypes.wintypes
-import config as msvc_cfg
class UNDECORATE_NAME_OPTIONS:
- UNDNAME_COMPLETE = 0x0000 #Enables full undecoration.
- UNDNAME_NO_LEADING_UNDERSCORES = 0x0001 #Removes leading underscores from Microsoft extended keywords.
- UNDNAME_NO_MS_KEYWORDS = 0x0002 #Disables expansion of Microsoft extended keywords.
- UNDNAME_NO_FUNCTION_RETURNS = 0x0004 #Disables expansion of return type for primary declaration.
- UNDNAME_NO_ALLOCATION_MODEL = 0x0008 #Disables expansion of the declaration model.
- UNDNAME_NO_ALLOCATION_LANGUAGE = 0x0010 #Disables expansion of the declaration language specifier.
- UNDNAME_RESERVED1 = 0x0020 #RESERVED.
- UNDNAME_RESERVED2 = 0x0040 #RESERVED.
- UNDNAME_NO_THISTYPE = 0x0060 #Disables all modifiers on the this type.
- UNDNAME_NO_ACCESS_SPECIFIERS = 0x0080 #Disables expansion of access specifiers for members.
- UNDNAME_NO_THROW_SIGNATURES = 0x0100 #Disables expansion of "throw-signatures" for functions and pointers to functions.
- UNDNAME_NO_MEMBER_TYPE = 0x0200 #Disables expansion of static or virtual members.
- UNDNAME_NO_RETURN_UDT_MODEL = 0x0400 #Disables expansion of the Microsoft model for UDT returns.
- UNDNAME_32_BIT_DECODE = 0x0800 #Undecorates 32-bit decorated names.
- UNDNAME_NAME_ONLY = 0x1000 #Gets only the name for primary declaration; returns just [scope::]name. Expands template params.
- UNDNAME_TYPE_ONLY = 0x2000 #Input is just a type encoding; composes an abstract declarator.
- UNDNAME_HAVE_PARAMETERS = 0x4000 #The real template parameters are available.
- UNDNAME_NO_ECSU = 0x8000 #Suppresses enum/class/struct/union.
- UNDNAME_NO_IDENT_CHAR_CHECK = 0x10000 #Suppresses check for valid identifier characters.
- UNDNAME_NO_PTR64 = 0x20000 #Does not include ptr64 in output.
+ UNDNAME_COMPLETE = 0
+ UNDNAME_NO_LEADING_UNDERSCORES = 1
+ UNDNAME_NO_MS_KEYWORDS = 2
+ UNDNAME_NO_FUNCTION_RETURNS = 4
+ UNDNAME_NO_ALLOCATION_MODEL = 8
+ UNDNAME_NO_ALLOCATION_LANGUAGE = 16
+ UNDNAME_NO_MS_THISTYPE = 32
+ UNDNAME_NO_CV_THISTYPE = 64
+ UNDNAME_NO_THISTYPE = 96
+ UNDNAME_NO_ACCESS_SPECIFIERS = 128
+ UNDNAME_NO_THROW_SIGNATURES = 256
+ UNDNAME_NO_MEMBER_TYPE = 512
+ UNDNAME_NO_RETURN_UDT_MODEL = 1024
+ UNDNAME_32_BIT_DECODE = 2048
+ UNDNAME_NAME_ONLY = 4096
+ UNDNAME_NO_ARGUMENTS = 8192
+ UNDNAME_NO_SPECIAL_SYMS = 16384
UNDNAME_SCOPES_ONLY = UNDNAME_NO_LEADING_UNDERSCORES \
| UNDNAME_NO_MS_KEYWORDS \
@@ -31,40 +26,18 @@
| UNDNAME_NO_ALLOCATION_LANGUAGE \
| UNDNAME_NO_ACCESS_SPECIFIERS \
| UNDNAME_NO_THROW_SIGNATURES \
- | UNDNAME_NO_MEMBER_TYPE \
- | UNDNAME_NO_ECSU \
- | UNDNAME_NO_IDENT_CHAR_CHECK
+ | UNDNAME_NO_MEMBER_TYPE
-#__unDName definition was taken from:
-#http://www.tech-archive.net/Archive/VC/microsoft.public.vc.language/2006-02/msg00754.html
-msvcrxx = ctypes.windll.msvcr71 #ctypes.CDLL( msvc_cfg.msvcr_path, mode=ctypes.RTLD_GLOBAL)
-free_type = ctypes.CFUNCTYPE( None, ctypes.c_void_p ) #free type
-malloc_type = ctypes.CFUNCTYPE( ctypes.c_void_p, ctypes.c_uint ) #malloc type
+undecorate_name_impl = ctypes.windll.dbghelp.UnDecorateSymbolName
+undecorate_name_impl.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_uint, ctypes.c_uint]
-
-__unDName = msvcrxx.__unDName
-__unDName.argtypes = [ ctypes.c_char_p #undecorated name
- , ctypes.c_char_p #decorated name
- , ctypes.c_int #sizeof undecorated name
- , malloc_type
- , free_type
- , ctypes.c_ushort #flags
- ]
-__unDName.restype = ctypes.c_char_p
-
-
def undecorate_name( name, options=None ):
- if not name:
- return ''
if options is None:
- options = UNDECORATE_NAME_OPTIONS.UNDNAME_NO_ECSU
- buffer_size = 1024 * 32
- undecorated_name = ctypes.create_string_buffer('\0' * buffer_size) #should be enouph for any symbol
- __unDName( undecorated_name
- , name
- , buffer_size
- , malloc_type( msvcrxx.malloc )
- , free_type( msvcrxx.free )
- , options )
- return undecorated_name.value
+ options = UNDECORATE_NAME_OPTIONS.UNDNAME_COMPLETE
+ buffer = ctypes.create_string_buffer(1024*16)
+ res = undecorate_name_impl(name, buffer, ctypes.sizeof(buffer), options)
+ if res:
+ return str(buffer[:res])
+ else:
+ return name
Modified: pygccxml_dev/pygccxml/msvc/mspdb/enums.py
===================================================================
--- pygccxml_dev/pygccxml/msvc/mspdb/enums.py 2008-12-18 06:51:01 UTC (rev 1477)
+++ pygccxml_dev/pygccxml/msvc/mspdb/enums.py 2008-12-19 22:50:32 UTC (rev 1478)
@@ -58,3 +58,46 @@
DataIsStaticMember = 8
DataIsConstant = 9
+
+class UNDECORATE_NAME_OPTIONS:
+ UNDNAME_COMPLETE = 0x0000 #Enables full undecoration.
+ UNDNAME_NO_LEADING_UNDERSCORES = 0x0001 #Removes leading underscores from Microsoft extended keywords.
+ UNDNAME_NO_MS_KEYWORDS = 0x0002 #Disables expansion of Microsoft extended keywords.
+ UNDNAME_NO_FUNCTION_RETURNS = 0x0004 #Disables expansion of return type for primary declaration.
+ UNDNAME_NO_ALLOCATION_MODEL = 0x0008 #Disables expansion of the declaration model.
+ UNDNAME_NO_ALLOCATION_LANGUAGE = 0x0010 #Disables expansion of the declaration language specifier.
+ UNDNAME_RESERVED1 = 0x0020 #RESERVED.
+ UNDNAME_RESERVED2 = 0x0040 #RESERVED.
+ UNDNAME_NO_THISTYPE = 0x0060 #Disables all modifiers on the this type.
+ UNDNAME_NO_ACCESS_SPECIFIERS = 0x0080 #Disables expansion of access specifiers for members.
+ UNDNAME_NO_THROW_SIGNATURES = 0x0100 #Disables expansion of "throw-signatures" for functions and pointers to functions.
+ UNDNAME_NO_MEMBER_TYPE = 0x0200 #Disables expansion of static or virtual members.
+ UNDNAME_NO_RETURN_UDT_MODEL = 0x0400 #Disables expansion of the Microsoft model for UDT returns.
+ UNDNAME_32_BIT_DECODE = 0x0800 #Undecorates 32-bit decorated names.
+ UNDNAME_NAME_ONLY = 0x1000 #Gets only the name for primary declaration; returns just [scope::]name. Expands template params.
+ UNDNAME_TYPE_ONLY = 0x2000 #Input is just a type encoding; composes an abstract declarator.
+ UNDNAME_HAVE_PARAMETERS = 0x4000 #The real template parameters are available.
+ UNDNAME_NO_ECSU = 0x8000 #Suppresses enum/class/struct/union.
+ UNDNAME_NO_IDENT_CHAR_CHECK = 0x10000 #Suppresses check for valid identifier characters.
+ UNDNAME_NO_PTR64 = 0x20000 #Does not include ptr64 in output.
+
+ UNDNAME_SCOPES_ONLY = UNDNAME_NO_LEADING_UNDERSCORES \
+ | UNDNAME_NO_MS_KEYWORDS \
+ | UNDNAME_NO_FUNCTION_RETURNS \
+ | UNDNAME_NO_ALLOCATION_MODEL \
+ | UNDNAME_NO_ALLOCATION_LANGUAGE \
+ | UNDNAME_NO_ACCESS_SPECIFIERS \
+ | UNDNAME_NO_THROW_SIGNATURES \
+ | UNDNAME_NO_MEMBER_TYPE \
+ | UNDNAME_NO_ECSU \
+ | UNDNAME_NO_IDENT_CHAR_CHECK
+
+ UNDNAME_SHORT_UNIQUE = UNDNAME_NO_LEADING_UNDERSCORES \
+ | UNDNAME_NO_MS_KEYWORDS \
+ | UNDNAME_NO_ALLOCATION_MODEL \
+ | UNDNAME_NO_ALLOCATION_LANGUAGE \
+ | UNDNAME_NO_ACCESS_SPECIFIERS \
+ | UNDNAME_NO_THROW_SIGNATURES \
+ | UNDNAME_NO_MEMBER_TYPE \
+ | UNDNAME_NO_ECSU \
+ | UNDNAME_NO_IDENT_CHAR_CHECK
Modified: pygccxml_dev/pygccxml/msvc/mspdb/loader.py
===================================================================
--- pygccxml_dev/pygccxml/msvc/mspdb/loader.py 2008-12-18 06:51:01 UTC (rev 1477)
+++ pygccxml_dev/pygccxml/msvc/mspdb/loader.py 2008-12-19 22:50:32 UTC (rev 1478)
@@ -83,13 +83,37 @@
smbls = {}
for smbl in itertools.imap( as_symbol, as_enum_variant( self.symbols_table._NewEnum ) ):
smbl.uname = msvc_utils.undecorate_name( smbl.name, msvc_utils.UNDECORATE_NAME_OPTIONS.UNDNAME_SCOPES_ONLY )
- def smbl_undecorate_name( options = None ):
+ def smbl_undecorate_name( options=None ):
return msvc_utils.undecorate_name( smbl.name, options )
smbl.undecorate_name = smbl_undecorate_name
smbls[ smbl.symIndexId ] = smbl
self.logger.info( 'loading symbols(%d) from the file - done', len( smbls ) )
return smbls
+ @utils.cached
+ def public_symbols( self ):
+ self.logger.info( 'loading public symbols from the file' )
+ smbls = {}
+ for smbl in self.symbols.itervalues():
+ if not smbl.function:
+ continue
+ if not smbl.name:
+ continue
+ undecorated_name = smbl.get_undecoratedNameEx( enums.UNDECORATE_NAME_OPTIONS.UNDNAME_SCOPES_ONLY )
+ if not undecorated_name:
+ continue
+ if smbl.name.startswith( '__' ):
+ continue
+ if undecorated_name.startswith( '__' ):
+ continue
+ if undecorated_name.startswith( '@' ):
+ continue
+ if undecorated_name.startswith( 'type_info::' ):
+ continue
+ smbls[ smbl.symIndexId ] = smbl
+ self.logger.info( 'loading public symbols(%d) from the file - done', len( smbls ) )
+ return smbls
+
def __load_nss(self):
def ns_filter( smbl ):
self.logger.debug( '__load_ns.ns_filter, %s', smbl.uname )
@@ -701,3 +725,4 @@
if not isinstance( my_type, declarations.volatile_t ):
my_type = declarations.volatile_t( my_type )
return my_type
+
Modified: pygccxml_dev/unittests/autoconfig.py
===================================================================
--- pygccxml_dev/unittests/autoconfig.py 2008-12-18 06:51:01 UTC (rev 1477)
+++ pygccxml_dev/unittests/autoconfig.py 2008-12-19 22:50:32 UTC (rev 1478)
@@ -44,13 +44,13 @@
keywd[ 'gccxml_path'] = gccxml_path
gccxml = pygccxml.parser.gccxml_configuration_t( **keywd )
- pdb_loader = None
- if sys.platform == 'win32':
- from pygccxml.msvc import mspdb
- pdb_file = os.path.join( data_directory, 'msvc_build', 'Debug', 'msvc_build.pdb' )
- if os.path.exists( pdb_file ):
- pdb_loader = mspdb.decl_loader_t( pdb_file )
- pdb_loader.read()
+ #~ pdb_loader = None
+ #~ if sys.platform == 'win32':
+ #~ from pygccxml.msvc import mspdb
+ #~ pdb_file = os.path.join( data_directory, 'msvc_build', 'Debug', 'msvc_build.pdb' )
+ #~ if os.path.exists( pdb_file ):
+ #~ pdb_loader = mspdb.decl_loader_t( pdb_file )
+ #~ pdb_loader.read()
def get_pdb_global_ns():
if cxx_parsers_cfg.pdb_loader:
Added: pygccxml_dev/unittests/mspdb_playground.py
===================================================================
--- pygccxml_dev/unittests/mspdb_playground.py (rev 0)
+++ pygccxml_dev/unittests/mspdb_playground.py 2008-12-19 22:50:32 UTC (rev 1478)
@@ -0,0 +1,37 @@
+import os
+import unittest
+import autoconfig
+
+import pprint
+from pygccxml.msvc import mspdb
+from pygccxml import declarations
+from pygccxml.msvc import common_utils as msvc_utils
+
+pdb_file = r'E:\development\language-binding\pyplusplus_dev\pyplusplus\cpptypes\mydll\release\mydll.pdb'
+
+reader = mspdb.decl_loader_t( pdb_file )
+opt = mspdb.enums.UNDECORATE_NAME_OPTIONS.UNDNAME_SHORT_UNIQUE
+
+d = {}
+for smbl in reader.public_symbols.itervalues():
+ name = smbl.name
+ undecorated_name = smbl.get_undecoratedNameEx(opt).strip()
+ if undecorated_name.endswith( ')const' ):
+ undecorated_name = undecorated_name[ : -len('const')]
+ d[ name ] = undecorated_name
+ d[ undecorated_name ] = name
+
+pprint.pprint( d )
+
+#~ reader.read()
+#~ f = file( 'decls.cpp', 'w+' )
+#~ declarations.print_declarations( reader.global_ns, writer=lambda line: f.write(line+'\n') )
+#~ f.close()
+
+#~ f = file( 'symbols.txt', 'w+')
+#~ for smbl in reader.symbols.itervalues():
+ #~ f.write( smbl.uname )
+ #~ f.write( os.linesep )
+ #~ f.write( '\t' + str(smbl.name) )
+#~ f.close()
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|