|
4 | 4 | # http://www.boost.org/LICENSE_1_0.txt) |
5 | 5 |
|
6 | 6 | """ |
7 | | -provides functionality needed to undecorate\demangle compiler generated unique names |
| 7 | +provides low-level functionality, needed to undecorate\demangle compiler generated |
| 8 | +unique names and map them to the declarations |
| 9 | +
|
| 10 | +On Windows: |
| 11 | + ctypes package is used to call UnDecorateSymbolName function from dbghelp.dll |
| 12 | +
|
| 13 | +On Linux: |
| 14 | + "nm" utility is used. |
8 | 15 | """ |
9 | 16 |
|
10 | 17 | import os |
|
14 | 21 | from pygccxml import declarations |
15 | 22 |
|
16 | 23 | class UNDECORATE_NAME_OPTIONS: |
| 24 | + """defines few constants for UnDecorateSymbolName function""" |
| 25 | + |
17 | 26 | UNDNAME_COMPLETE = 0x0000 #Enables full undecoration. |
18 | 27 | UNDNAME_NO_LEADING_UNDERSCORES = 0x0001 #Removes leading underscores from Microsoft extended keywords. |
19 | 28 | UNDNAME_NO_MS_KEYWORDS = 0x0002 #Disables expansion of Microsoft extended keywords. |
@@ -48,39 +57,19 @@ class UNDECORATE_NAME_OPTIONS: |
48 | 57 |
|
49 | 58 | SHORT_UNIQUE_NAME = UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ACCESS_SPECIFIERS | UNDNAME_NO_ECSU |
50 | 59 |
|
51 | | -#~ The following code doesn't work - access violation |
52 | | - |
53 | | -#~__unDName definition was taken from: |
54 | | -#~http://www.tech-archive.net/Archive/VC/microsoft.public.vc.language/2006-02/msg00754.html |
55 | | - |
56 | | -#~ msvcrxx = ctypes.windll.msvcr90 |
57 | | -#~ free_type = ctypes.CFUNCTYPE( None, ctypes.c_void_p ) #free type |
58 | | -#~ malloc_type = ctypes.CFUNCTYPE( ctypes.c_void_p, ctypes.c_uint ) #malloc type |
59 | | -#~ __unDName = msvcrxx.__unDName |
60 | | -#~ __unDName.argtypes = [ ctypes.c_char_p #undecorated name |
61 | | - #~ , ctypes.c_char_p #decorated name |
62 | | - #~ , ctypes.c_int #sizeof undecorated name |
63 | | - #~ , malloc_type |
64 | | - #~ , free_type |
65 | | - #~ , ctypes.c_ushort #flags |
66 | | - #~ ] |
67 | | -#~ __unDName.restype = ctypes.c_char_p |
68 | | -#~ def undecorate_name( name, options=None ): |
69 | | - #~ if not name: |
70 | | - #~ return '' |
71 | | - #~ if options is None: |
72 | | - #~ options = UNDECORATE_NAME_OPTIONS.SHORT_UNIQUE_NAME |
73 | | - #~ buffer_size = 1024 * 32 |
74 | | - #~ undecorated_name = ctypes.create_string_buffer('\0' * buffer_size) #should be enouph for any symbol |
75 | | - #~ __unDName( undecorated_name |
76 | | - #~ , str(name) |
77 | | - #~ , buffer_size |
78 | | - #~ , malloc_type( msvcrxx.malloc ) |
79 | | - #~ , free_type( msvcrxx.free ) |
80 | | - #~ , options ) |
81 | | - #~ return undecorated_name.value |
82 | | - |
83 | 60 | class undname_creator_t: |
| 61 | + """formats declarations string representation and exported symbols, so they |
| 62 | + could be matched later. |
| 63 | +
|
| 64 | + The class formats variables, free and member functions, symbols exported from |
| 65 | + .dll, .map and .so files. |
| 66 | +
|
| 67 | + On Windows, the class works with unique name produced by MSVC compiler and |
| 68 | + with undecorated names produced by dbghelp.dll |
| 69 | +
|
| 70 | + On Linux, the class works with mangled names produced by GCC-XML ( GCC 4.2 ) |
| 71 | + compiler and demangled name produced by "nm" utility. |
| 72 | + """ |
84 | 73 | def __init__( self ): |
85 | 74 | if 'win32' in sys.platform: |
86 | 75 | import ctypes.wintypes |
@@ -147,7 +136,6 @@ def __format_type_as_undecorated( self, type_, is_argument, hint ): |
147 | 136 | result = result.replace( ' ' + x, x ) |
148 | 137 | return result |
149 | 138 |
|
150 | | - |
151 | 139 | def __normalize( self, name ): |
152 | 140 | for what, with_ in self.__fundamental_types: |
153 | 141 | name = name.replace( what, with_ ) |
|
0 commit comments