[pygccxml-commit] SF.net SVN: pygccxml:[1486] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-12-23 08:45:17
|
Revision: 1486 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1486&view=rev Author: roman_yakovenko Date: 2008-12-23 08:45:12 +0000 (Tue, 23 Dec 2008) Log Message: ----------- adding functionality which maps decorated and undecorated names between gccxml and MSVC Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/calldef.py pygccxml_dev/pygccxml/msvc/__init__.py pygccxml_dev/pygccxml/msvc/common_utils.py pygccxml_dev/unittests/data/msvc/mydll.cpp pygccxml_dev/unittests/data/msvc/mydll.h pygccxml_dev/unittests/mspdb_playground.py pygccxml_dev/unittests/test_all.py Added Paths: ----------- pygccxml_dev/unittests/data/msvc/mydll.80.vcproj pygccxml_dev/unittests/undname_creator_tester.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2008-12-22 22:52:20 UTC (rev 1485) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2008-12-23 08:45:12 UTC (rev 1486) @@ -104,9 +104,7 @@ from calldef import casting_operator_t from calldef import free_function_t from calldef import free_operator_t -from calldef import create_undecorated_name - from decl_visitor import decl_visitor_t from type_visitor import type_visitor_t Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2008-12-22 22:52:20 UTC (rev 1485) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2008-12-23 08:45:12 UTC (rev 1486) @@ -560,56 +560,3 @@ if decl: self.__class_types.append( decl ) return self.__class_types - - -def __remove_leading_scope( s ): - if s and s.startswith( '::' ): - return s[2:] - else: - return s - -def __format_type_as_undecorated( type_ ): - result = [] - type_ = type_traits.remove_alias( type_ ) - base_type_ = type_traits.base_type( type_ ) - base_type_ = type_traits.remove_declarated( base_type_ ) - if type_traits.is_class( base_type_ ) and base_type_.class_type == "struct": - result.append('struct ') - result.append( __remove_leading_scope( type_.decl_string ) ) - return ' '.join( result ) - -def __format_args_as_undecorated( argtypes ): - if not argtypes: - return 'void' - else: - return ','.join( map( __format_type_as_undecorated, argtypes ) ) - -def create_undecorated_name(calldef): - """returns string, which contains full function name formatted exactly as - result of dbghelp.UnDecorateSymbolName, with UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ACCESS_SPECIFIERS | UNDNAME_NO_ECSU - options. - """ - calldef_type = calldef.function_type() - - result = [] - is_mem_fun = isinstance( calldef, member_calldef_t ) - if is_mem_fun and calldef.virtuality != VIRTUALITY_TYPES.NOT_VIRTUAL: - result.append( 'virtual ' ) - if calldef_type.return_type: - result.append( __format_type_as_undecorated( calldef.return_type ) ) - result.append( ' ' ) - if isinstance( calldef, member_calldef_t ): - result.append( __remove_leading_scope( calldef.parent.decl_string ) + '::') - - result.append( calldef.name ) - if isinstance( calldef, ( constructor_t, destructor_t) ) \ - and templates.is_instantiation( calldef.parent.name ): - result.append( '<%s>' % ','.join( templates.args( calldef.parent.name ) ) ) - - result.append( '(%s)' % __format_args_as_undecorated( calldef_type.arguments_types ) ) - if is_mem_fun and calldef.has_const: - result.append( 'const' ) - return ''.join( result ) - - - Modified: pygccxml_dev/pygccxml/msvc/__init__.py =================================================================== --- pygccxml_dev/pygccxml/msvc/__init__.py 2008-12-22 22:52:20 UTC (rev 1485) +++ pygccxml_dev/pygccxml/msvc/__init__.py 2008-12-23 08:45:12 UTC (rev 1486) @@ -0,0 +1,9 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +from common_utils import undecorate_blob +from common_utils import undecorate_decl +from common_utils import exported_symbols +from common_utils import UNDECORATE_NAME_OPTIONS Modified: pygccxml_dev/pygccxml/msvc/common_utils.py =================================================================== --- pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-22 22:52:20 UTC (rev 1485) +++ pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-23 08:45:12 UTC (rev 1486) @@ -1,23 +1,34 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import re import ctypes +import ctypes.wintypes +from .. import declarations class UNDECORATE_NAME_OPTIONS: - 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_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 \ @@ -26,18 +37,135 @@ | UNDNAME_NO_ALLOCATION_LANGUAGE \ | UNDNAME_NO_ACCESS_SPECIFIERS \ | UNDNAME_NO_THROW_SIGNATURES \ - | UNDNAME_NO_MEMBER_TYPE + | UNDNAME_NO_MEMBER_TYPE \ + | UNDNAME_NO_ECSU \ + | UNDNAME_NO_IDENT_CHAR_CHECK + SHORT_UNIQUE_NAME = UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ACCESS_SPECIFIERS | UNDNAME_NO_ECSU -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] +#~ The following code doesn't work - access violation -def undecorate_name( name, options=None ): - if options is None: - 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 +#~__unDName definition was taken from: +#~http://www.tech-archive.net/Archive/VC/microsoft.public.vc.language/2006-02/msg00754.html + +#~ msvcrxx = ctypes.windll.msvcr90 +#~ free_type = ctypes.CFUNCTYPE( None, ctypes.c_void_p ) #free type +#~ malloc_type = ctypes.CFUNCTYPE( ctypes.c_void_p, ctypes.c_uint ) #malloc type +#~ __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.SHORT_UNIQUE_NAME + #~ buffer_size = 1024 * 32 + #~ undecorated_name = ctypes.create_string_buffer('\0' * buffer_size) #should be enouph for any symbol + #~ __unDName( undecorated_name + #~ , str(name) + #~ , buffer_size + #~ , malloc_type( msvcrxx.malloc ) + #~ , free_type( msvcrxx.free ) + #~ , options ) + #~ return undecorated_name.value + +class undname_creator: + __undname = ctypes.windll.dbghelp.UnDecorateSymbolName + __undname.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_uint, ctypes.c_uint] + __clean_ecsu = re.compile( r'(?:(^|\W))(?:(class|enum|struct|union))' ) + + def undecorate_blob( self, name, options=None ): + if options is None: + options = UNDECORATE_NAME_OPTIONS.SHORT_UNIQUE_NAME + buffer = ctypes.create_string_buffer(1024*16) + res = self.__undname( str(name), buffer, ctypes.sizeof(buffer), options) + if res: + undname = str(buffer[:res]) + if UNDECORATE_NAME_OPTIONS.UNDNAME_NO_ECSU & options: + undname = self.__clean_ecsu.sub( '', undname ) + return undname.strip() + else: + return name + + def __remove_leading_scope( self, s ): + if s and s.startswith( '::' ): + return s[2:] + else: + return s + + def __format_type_as_undecorated( self, type_ ): + result = [] + type_ = declarations.remove_alias( type_ ) + result.append( self.__remove_leading_scope( type_.decl_string ) ) + return ' '.join( result ) + + def __format_args_as_undecorated( self, argtypes ): + if not argtypes: + return 'void' + else: + return ','.join( map( self.__format_type_as_undecorated, argtypes ) ) + + def undecorated_decl(self, calldef): + """returns string, which contains full function name formatted exactly as + result of dbghelp.UnDecorateSymbolName, with UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ACCESS_SPECIFIERS | UNDNAME_NO_ECSU + options. + """ + calldef_type = calldef.function_type() + + result = [] + is_mem_fun = isinstance( calldef, declarations.member_calldef_t ) + if is_mem_fun and calldef.virtuality != declarations.VIRTUALITY_TYPES.NOT_VIRTUAL: + result.append( 'virtual ' ) + if calldef_type.return_type: + result.append( self.__format_type_as_undecorated( calldef.return_type ) ) + result.append( ' ' ) + if is_mem_fun: + result.append( self.__remove_leading_scope( calldef.parent.decl_string ) + '::') + + result.append( calldef.name ) + if isinstance( calldef, ( declarations.constructor_t, declarations.destructor_t) ) \ + and declarations.templates.is_instantiation( calldef.parent.name ): + result.append( '<%s>' % ','.join( declarations.templates.args( calldef.parent.name ) ) ) + + result.append( '(%s)' % self.__format_args_as_undecorated( calldef_type.arguments_types ) ) + if is_mem_fun and calldef.has_const: + result.append( 'const' ) + return ''.join( result ) + +undecorate_blob = undname_creator().undecorate_blob +undecorate_decl = undname_creator().undecorated_decl + +class exported_symbols: + map_file_re = re.compile( r' +\d+ (?P<decorated>.+) \((?P<undecorated>.+)\)$' ) + @staticmethod + def load_from_map_file( fname ): + """returns dictionary { decorated symbol : orignal declaration name }""" + result = {} + f = open( fname ) + exports_started = False + for line in f: + if not exports_started: + exports_started = bool( 'Exports' == line.strip() ) + if not exports_started: + continue + line = line.rstrip() + found = exported_symbols.map_file_re.match( line ) + if found: + result[ found.group( 'decorated' ) ] = found.group( 'undecorated' ) + return result + +#~ quick & dirty test +#~ symbols = exported_symbols.load_from_map_file( r'D:\dev\language-binding\sources\pygccxml_dev\unittests\data\msvc\Release\mydll.map' ) +#~ for decorated, undecorated in symbols.iteritems(): + #~ print '---------------------------------------------------------------------' + #~ print decorated + #~ print undecorated + #~ print undecorate_blob( decorated ) + #~ print '=====================================================================' + Added: pygccxml_dev/unittests/data/msvc/mydll.80.vcproj =================================================================== --- pygccxml_dev/unittests/data/msvc/mydll.80.vcproj (rev 0) +++ pygccxml_dev/unittests/data/msvc/mydll.80.vcproj 2008-12-23 08:45:12 UTC (rev 1486) @@ -0,0 +1,186 @@ +<?xml version="1.0" encoding="windows-1255"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="mydll" + ProjectGUID="{0B9466BC-60F8-4FC2-A1A9-6A01577690E5}" + RootNamespace="mydll" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + BrowseInformation="1" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + GenerateMapFile="true" + MapExports="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <File + RelativePath=".\mydll.cpp" + > + </File> + <File + RelativePath=".\mydll.h" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Modified: pygccxml_dev/unittests/data/msvc/mydll.cpp =================================================================== --- pygccxml_dev/unittests/data/msvc/mydll.cpp 2008-12-22 22:52:20 UTC (rev 1485) +++ pygccxml_dev/unittests/data/msvc/mydll.cpp 2008-12-23 08:45:12 UTC (rev 1486) @@ -2,15 +2,15 @@ #include "windows.h" #include <iostream> -number_t::number_t() -: m_value(0) -{ +number_t::number_t() +: m_value(0) +{ // std::cout << "{C++} number_t( 0 )" << std::endl; } -number_t::number_t(int value) -: m_value(value) +number_t::number_t(int value) +: m_value(value) { // std::cout << "{C++} number_t( " << value << " )" << std::endl; } @@ -19,7 +19,7 @@ // std::cout << "{C++} ~number_t()" << std::endl; } void number_t::print_it() const { - std::cout << "{C++} value: " << m_value << std::endl; + std::cout << "{C++} value: " << m_value << std::endl; } int number_t::get_value() const{ @@ -57,3 +57,72 @@ return TRUE; } + +/* +static int myclass::myStaticMember +const int myclass::myconstStaticMember +volatile int myclass::myvolatileStaticMember +x myfnptr; +int myglobal; +volatile int myvolatile; +int myarray[10]; +void **Fv_PPv(void) +void *Fv_Pv(void) +int FA10_i_i(int a[10]) +int FPi_i(int *a) +int Fc_i(char bar) +int Ff_i(float bar) +int Fg_i(double bar) +int Fi_i(int bar) +int Fie_i(int bar, ...) +int Fii_i(int bar, int goo) +int Fiii_i(int bar, int goo, int hoo) +void Fmxmx_v(myclass arg1, x arg2, myclass arg3, x arg4) +void Fmyclass_v(myclass m) +const int Fv_Ci(void) +long double Fv_Lg(void) +int& Fv_Ri(void) +signed char Fv_Sc(void) +unsigned char Fv_Uc(void) +unsigned int Fv_Ui(void) +unsigned long Fv_Ul(void) +unsigned short Fv_Us(void) +volatile int Fv_Vi(void) +char Fv_c(void) +float Fv_f(void) +double Fv_g(void) +int Fv_i(void) +long Fv_l(void) +short Fv_s(void) +void Fv_v(void) +void __cdecl Fv_v_cdecl(void) +void __fastcall Fv_v_fastcall(void) +void __stdcall Fv_v_stdcall(void) +int Fx_i(x fnptr) +int Fxix_i(x fnptr, int i, x fnptr3) +int Fxx_i(x fnptr, x fnptr2) +int Fxxi_i(x fnptr, x fnptr2, x fnptr3, int i) +int Fxxx_i(x fnptr, x fnptr2, x fnptr3) +int Fxyxy_i(x fnptr, y fnptr2, x fnptr3, y fnptr4) +void myclass::operator delete(void *p) +int myclass::Fi_i(int bar) +static int myclass::Fis_i(int bar) +void __cdecl myclass::Fv_v_cdecl(void) +void __fastcall myclass::Fv_v_fastcall(void) +void __stdcall myclass::Fv_v_stdcall(void) +myclass::myclass(int x) +myclass::myclass(void) +int myclass::nested::Fi_i(int bar) +myclass::nested::nested(void) +myclass::nested::~nested() +myclass myclass::operator+(int x) +myclass myclass::operator++() +myclass myclass::operator++(int) +myclass& myclass::operator=(const myclass& from) +myclass::~myclass() +int nested::Fi_i(int bar) +nested::nested(void) +nested::~nested() +void* myclass::operator new(size_t size) +*/ + Modified: pygccxml_dev/unittests/data/msvc/mydll.h =================================================================== --- pygccxml_dev/unittests/data/msvc/mydll.h 2008-12-22 22:52:20 UTC (rev 1485) +++ pygccxml_dev/unittests/data/msvc/mydll.h 2008-12-23 08:45:12 UTC (rev 1486) @@ -22,4 +22,6 @@ typedef std::auto_ptr< number_t > number_aptr_t; -void __declspec(dllexport) do_smth( number_aptr_t& ); \ No newline at end of file +enum{ auto_ptr_size = sizeof( number_aptr_t ) }; + +void __declspec(dllexport) do_smth( number_aptr_t& ); Modified: pygccxml_dev/unittests/mspdb_playground.py =================================================================== --- pygccxml_dev/unittests/mspdb_playground.py 2008-12-22 22:52:20 UTC (rev 1485) +++ pygccxml_dev/unittests/mspdb_playground.py 2008-12-23 08:45:12 UTC (rev 1486) @@ -8,7 +8,7 @@ from pygccxml.msvc import common_utils as msvc_utils pdb_file = r'E:\development\language-binding\pyplusplus_dev\pyplusplus\cpptypes\mydll\release\mydll.pdb' - +pdb_file = r'D:\AC_SERVER_4_VS2005\libs\Debug\SPDBLib_d.pdb' reader = mspdb.decl_loader_t( pdb_file ) opt = mspdb.enums.UNDECORATE_NAME_OPTIONS.UNDNAME_SHORT_UNIQUE opt = 0 Modified: pygccxml_dev/unittests/test_all.py =================================================================== --- pygccxml_dev/unittests/test_all.py 2008-12-22 22:52:20 UTC (rev 1485) +++ pygccxml_dev/unittests/test_all.py 2008-12-23 08:45:12 UTC (rev 1486) @@ -52,6 +52,7 @@ import function_traits_tester import better_templates_matcher_tester import declaration_matcher_tester +import undname_creator_tester testers = [ decl_string_tester @@ -100,6 +101,7 @@ , function_traits_tester , better_templates_matcher_tester , declaration_matcher_tester + , undname_creator_tester ] def create_suite(): Added: pygccxml_dev/unittests/undname_creator_tester.py =================================================================== --- pygccxml_dev/unittests/undname_creator_tester.py (rev 0) +++ pygccxml_dev/unittests/undname_creator_tester.py 2008-12-23 08:45:12 UTC (rev 1486) @@ -0,0 +1,82 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import os +import sys +import unittest +import autoconfig +import parser_test_case + +import pprint +from pygccxml import msvc +from pygccxml import utils +from pygccxml import parser +from pygccxml import declarations + +class tester_t( parser_test_case.parser_test_case_t ): + + global_ns = None + + def __init__(self, *args ): + parser_test_case.parser_test_case_t.__init__( self, *args ) + self.header = r'msvc\mydll.h' + + def setUp(self): + if not tester_t.global_ns: + decls = parser.parse( [self.header], self.config ) + tester_t.global_ns = declarations.get_global_namespace( decls ) + tester_t.global_ns.init_optimizer() + + def is_included( self, decl ): + for suffix in [ self.header, 'memory' ]: + if decl.location.file_name.endswith( suffix ): + return True + else: + return False + + + def test( self ): + map_file = os.path.join( autoconfig.data_directory, 'msvc', 'release', 'mydll.map' ) + symbols = msvc.exported_symbols.load_from_map_file( map_file ) + + undecorated_blob_names = set() + for blob in symbols.iterkeys(): + undname = msvc.undecorate_blob( blob ) + if "`" in undname: + continue + undecorated_blob_names.add( undname ) + + undecorated_decl_names = set() + for f in self.global_ns.calldefs(self.is_included): + undecorated_decl_names.add( msvc.undecorate_decl( f ) ) + + issuperset = undecorated_decl_names.issuperset( undecorated_blob_names ) + if not issuperset: + common = undecorated_decl_names.intersection( undecorated_blob_names ) + + undecorated_decl_names.difference_update(common) + undecorated_blob_names.difference_update(common) + + msg = [ "undecorate_decl - failed" ] + msg.append( "undecorated_decl_names :" ) + for i in undecorated_decl_names: + msg.append( '\t==>%s<==' % i ) + msg.append( "undecorated_blob_names :" ) + for i in undecorated_blob_names: + msg.append( '\t==>%s<==' % i ) + + self.fail( os.linesep.join(msg) ) + +def create_suite(): + suite = unittest.TestSuite() + if 'win' in sys.platform: + suite.addTest( unittest.makeSuite(tester_t)) + return suite + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run( create_suite() ) + +if __name__ == "__main__": + run_suite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |