11import speg
2- from ast import *
2+ from . ast import *
33
44def _transpose (m ):
55 return dict ((m [k ], k ) for k in m )
66
7- _noncv_member_funcs = frozenset ([n_constructor , n_destructor ])
8-
97_basic_type_map = {
8+ '@' : t_none ,
109 'X' : t_void ,
1110 '_N' : t_bool ,
1211 'D' : t_char ,
@@ -153,7 +152,7 @@ def _p_qname(p):
153152 return tuple (qname [::- 1 ])
154153
155154def _p_basic_type (p ):
156- c = p (r'[XDCEFGHIJKMNOZ]|_[NJKW]' )
155+ c = p (r'[@ XDCEFGHIJKMNOZ]|_[NJKW]' )
157156 return SimpleType (0 , _basic_type_map [c ]), len (c ) >= 2
158157
159158_cvs = [0 , cv_const , cv_volatile , cv_const | cv_volatile ]
@@ -177,17 +176,18 @@ def _p_type(p):
177176 # pointer to fn
178177 cv = _cvs [ord (p ('[PQRS]6' )[0 ]) - ord ('P' )]
179178 fn_type = p (_p_fn_type )
180- return PtrType (cv , fn_type , False ), True
179+ return PtrType (cv , fn_type , False , as_default ), True
181180
182181 with p :
183182 # pointer types
184- kind = p ('[APQRS]E?' )[0 ]
183+ kind = p ('[APQRS]' )
184+ addr_space = as_msvc_x64_absolute if p ('E?' ) else as_default
185185 target_cv = p ('[A-D]' )
186186 target , reg = p (_p_type )
187187 target .cv = _cvs [ord (target_cv ) - ord ('A' )]
188188
189189 cv = _cvs [ord (kind ) - ord ('P' )] if kind != 'A' else 0
190- return PtrType (cv , target , kind == 'A' ), True
190+ return PtrType (cv , target , kind == 'A' , addr_space ), True
191191
192192 return p (_p_basic_type )
193193
@@ -249,15 +249,21 @@ def _p_root(p):
249249 else :
250250 kind = fn_instance
251251
252- can_have_cv = kind in (fn_instance , fn_virtual ) and qname [- 1 ] not in _noncv_member_funcs
253- this_cv = ord (p ('[A-D]' )) - ord ('A' ) if can_have_cv else None
252+
253+ can_have_cv = kind in (fn_instance , fn_virtual )
254+ if can_have_cv :
255+ addr_space = as_msvc_x64_absolute if p ('E?' ) else as_default
256+ this_cv = ord (p ('[A-D]' )) - ord ('A' )
257+ else :
258+ addr_space = as_default
259+ this_cv = None
254260
255261 type = p (_p_fn_type )
256262 p (p .eof )
257263
258264 type .this_cv = this_cv
259265
260- return Function (qname , type , kind , access_class )
266+ return Function (qname , type , kind , access_class , addr_space )
261267
262268def msvc_demangle (s ):
263269 return speg .peg (s , _p_root )
@@ -317,7 +323,7 @@ def _m_type(type, nl, tl):
317323 if isinstance (type .target , FunctionType ):
318324 return '{}6{}' .format (kind , _m_fn_type (type .target , nl , tl ))
319325 else :
320- return '{}{}{}' .format (kind , 'ABCD' [type .target .cv ], _m_type (type .target , nl , tl ))
326+ return '{}{}{}{} ' .format (kind , 'E' if type . addr_space == as_msvc_x64_absolute else '' , 'ABCD' [type .target .cv ], _m_type (type .target , nl , tl ))
321327 if isinstance (type , ArrayType ):
322328 return 'Y{}{}{}' .format (_m_int (len (type .dims )), '' .join (_m_int (dim ) for dim in type .dims ), _m_type (type .target , nl , tl ))
323329 if isinstance (type , ClassType ):
@@ -379,9 +385,10 @@ def msvc_mangle(obj):
379385
380386 modif = chr (ord ('A' ) + modif )
381387
382- can_have_cv = obj .kind in (fn_instance , fn_virtual ) and obj .qname [- 1 ] not in _noncv_member_funcs
388+ addr_space = 'E' if obj .addr_space == as_msvc_x64_absolute else ''
389+ can_have_cv = obj .kind in (fn_instance , fn_virtual )
383390 this_cv = 'ABCD' [obj .type .this_cv ] if can_have_cv else ''
384391
385- return '?{}{}{}{}' .format (qname , modif , this_cv , type )
392+ return '?{}{}{}{}{} ' .format (qname , modif , addr_space , this_cv , type )
386393
387394 raise RuntimeError ('unknown obj' )
0 commit comments