Package pygccxml :: Package msvc :: Module common_utils |

# Source Code for Module pygccxml.msvc.common_utils

     1  import ctypes
     2  import ctypes.wintypes
     3  import config as msvc_cfg
     4
     5 -class UNDECORATE_NAME_OPTIONS:
     6      UNDNAME_COMPLETE = 0x0000 #Enables full undecoration.
     7      UNDNAME_NO_LEADING_UNDERSCORES = 0x0001 #Removes leading underscores from Microsoft extended keywords.
     8      UNDNAME_NO_MS_KEYWORDS = 0x0002 #Disables expansion of Microsoft extended keywords.
     9      UNDNAME_NO_FUNCTION_RETURNS = 0x0004 #Disables expansion of return type for primary declaration.
    10      UNDNAME_NO_ALLOCATION_MODEL = 0x0008 #Disables expansion of the declaration model.
    11      UNDNAME_NO_ALLOCATION_LANGUAGE = 0x0010 #Disables expansion of the declaration language specifier.
    12      UNDNAME_RESERVED1 = 0x0020 #RESERVED.
    13      UNDNAME_RESERVED2 = 0x0040 #RESERVED.
    14      UNDNAME_NO_THISTYPE = 0x0060 #Disables all modifiers on the this type.
    15      UNDNAME_NO_ACCESS_SPECIFIERS = 0x0080 #Disables expansion of access specifiers for members.
    16      UNDNAME_NO_THROW_SIGNATURES = 0x0100 #Disables expansion of "throw-signatures" for functions and pointers to functions.
    17      UNDNAME_NO_MEMBER_TYPE = 0x0200 #Disables expansion of static or virtual members.
    18      UNDNAME_NO_RETURN_UDT_MODEL = 0x0400 #Disables expansion of the Microsoft model for UDT returns.
    19      UNDNAME_32_BIT_DECODE = 0x0800 #Undecorates 32-bit decorated names.
    20      UNDNAME_NAME_ONLY = 0x1000 #Gets only the name for primary declaration; returns just [scope::]name. Expands template params.
    21      UNDNAME_TYPE_ONLY = 0x2000 #Input is just a type encoding; composes an abstract declarator.
    22      UNDNAME_HAVE_PARAMETERS = 0x4000 #The real template parameters are available.
    23      UNDNAME_NO_ECSU = 0x8000 #Suppresses enum/class/struct/union.
    24      UNDNAME_NO_IDENT_CHAR_CHECK = 0x10000 #Suppresses check for valid identifier characters.
    25      UNDNAME_NO_PTR64 = 0x20000 #Does not include ptr64 in output.
    26
    27      UNDNAME_SCOPES_ONLY = UNDNAME_NO_LEADING_UNDERSCORES \
    28                            | UNDNAME_NO_MS_KEYWORDS \
    29                            | UNDNAME_NO_FUNCTION_RETURNS \
    30                            | UNDNAME_NO_ALLOCATION_MODEL \
    31                            | UNDNAME_NO_ALLOCATION_LANGUAGE \
    32                            | UNDNAME_NO_ACCESS_SPECIFIERS \
    33                            | UNDNAME_NO_THROW_SIGNATURES \
    34                            | UNDNAME_NO_MEMBER_TYPE \
    35                            | UNDNAME_NO_ECSU \
    36                            | UNDNAME_NO_IDENT_CHAR_CHECK
    37
    38  #__unDName definition was taken from:
    39  #http://www.tech-archive.net/Archive/VC/microsoft.public.vc.language/2006-02/msg00754.html
    40  msvcrxx = ctypes.CDLL( msvc_cfg.msvcr_path, mode=ctypes.RTLD_GLOBAL)
    41
    42  free_type = ctypes.CFUNCTYPE( None, ctypes.c_void_p ) #free type
    43  malloc_type = ctypes.CFUNCTYPE( ctypes.c_void_p, ctypes.c_uint ) #malloc type
    44
    45
    46  __unDName = msvcrxx.__unDName
    47  __unDName.argtypes = [ ctypes.c_char_p #undecorated name
    48                         , ctypes.c_char_p #decorated name
    49                         , ctypes.c_int #sizeof undecorated name
    50                         , malloc_type
    51                         , free_type
    52                         , ctypes.c_ushort #flags
    53                       ]
    54  __unDName.restype = ctypes.c_char_p
    55
    56
    57 -def undecorate_name( name, options=None ):
    58      if not name:
    59          return ''
    60      if options is None:
    61          options = UNDECORATE_NAME_OPTIONS.UNDNAME_NO_ECSU
    62      buffer_size = 1024 * 32
    63      undecorated_name = ctypes.create_string_buffer('\0' * buffer_size) #should be enouph for any symbol
    64      __unDName( undecorated_name
    65                 , name
    66                 , buffer_size
    67                 , malloc_type( msvcrxx.malloc )
    68                 , free_type( msvcrxx.free )
    69                 , options )
    70      return undecorated_name.value
    71