Skip to content

Commit d8f6d12

Browse files
author
roman_yakovenko
committed
small set of improvements
1 parent 28e539d commit d8f6d12

File tree

9 files changed

+79
-37
lines changed

9 files changed

+79
-37
lines changed

pygccxml/msvc/pdb/loader.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ def __clear_symbols(self):
274274
msdia.SymTagAnnotation
275275
, msdia.SymTagPublicSymbol
276276
, msdia.SymTagBlock
277+
, msdia.SymTagFuncDebugStart
278+
, msdia.SymTagFuncDebugEnd
277279
)
278280
for smbl_id, smbl in self.symbols.iteritems():
279281
if smbl.symTag in useless_tags \
@@ -367,9 +369,10 @@ def __update_decl( self, decl, smbl ):
367369
if not isinstance( decl, declarations.typedef_t ):
368370
decl.byte_size = smbl.length
369371
decl.byte_offset = smbl.offset
370-
decl.mangled = iif( smbl.name, smbl.name, '' )
372+
decl.mangled = iif( smbl.get_undecoratedNameEx(0), smbl.name, '' )
371373
decl.demangled = iif( smbl.uname, smbl.uname, '' )
372374
decl.is_artificial = bool( smbl.compilerGenerated )
375+
decl.location = declarations.location_t( smbl.lexicalParent.sourceFileName )
373376

374377

375378
def __load_classes( self ):
@@ -504,7 +507,8 @@ def __load_calldefs( self ):
504507
is_function = lambda smbl: smbl.symTag == msdia.SymTagFunction
505508
for functions_count, function_smbl in enumerate( itertools.ifilter( is_function, self.symbols.itervalues() ) ):
506509
function_decl = self.__create_calldef(function_smbl)
507-
self.__update_decls_tree( function_decl )
510+
if function_decl:
511+
self.__update_decls_tree( function_decl )
508512
self.logger.info( 'building function objects(%d) - done', functions_count )
509513

510514
def __guess_operator_type( self, smbl, operator_type ):
@@ -540,21 +544,31 @@ def __create_calldef( self, smbl ):
540544
calldef_type = self.create_type( smbl.type ) #what does happen with constructor?
541545
decl = None
542546
if isinstance( calldef_type, declarations.member_function_type_t ):
547+
could_be_static = False
548+
could_be_const = False
543549
if smbl.uname.startswith( '~' ):
544550
decl = declarations.destructor_t()
545551
if not decl: #may be operator
546552
decl = self.__guess_operator_type(smbl, calldef_type)
553+
could_be_static = True
554+
could_be_const = True
547555
if not decl: #may be constructor
548556
decl = self.__guess_constructor( smbl, calldef_type )
549557
if not decl:
550558
decl = declarations.member_function_t()
559+
could_be_static = True
560+
could_be_const = True
551561
if smbl.virtual:
552562
decl.virtuality = iif( smbl.pure
553563
, declarations.VIRTUALITY_TYPES.PURE_VIRTUAL
554564
, declarations.VIRTUALITY_TYPES.VIRTUAL )
565+
decl.has_const = bool( could_be_const and smbl.constType )
566+
decl.has_static = bool( could_be_static and smbl.isStatic )
555567
else:
556568
decl = self.__guess_operator_type(smbl, calldef_type)
557569
if not decl:
570+
if 'instantiate::`dynamic initializer for' in smbl.uname:
571+
return #in this case we deal with initializer of some global variable
558572
decl = declarations.free_function_t()
559573
decl.name = smbl.uname
560574
decl.arguments = map( lambda t: declarations.argument_t( type=t )

unittests/autoconfig.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,22 @@
4141
pygccxml.declarations.class_t.USE_DEMANGLED_AS_NAME = True
4242

4343
class cxx_parsers_cfg:
44-
gccxml = pygccxml.parser.gccxml_configuration_t( gccxml_path=gccxml_path
45-
, working_directory=data_directory
46-
, define_symbols=[ gccxml_version ]
47-
, compiler=compiler )
48-
44+
gccxml = None
45+
if os.path.exists( os.path.join( gccxml_path, 'gccxml' ) ) \
46+
or os.path.exists( os.path.join( gccxml_path, 'gccxml.exe' ) ):
47+
gccxml = pygccxml.parser.gccxml_configuration_t( gccxml_path=gccxml_path
48+
, working_directory=data_directory
49+
, define_symbols=[ gccxml_version ]
50+
, compiler=compiler )
4951
pdb_loader = None
50-
51-
@staticmethod
52-
def get_pdb_loader():
53-
if not cxx_parsers_cfg.pdb_loader and sys.platform == 'win32':
54-
from pygccxml.msvc import pdb
55-
pdb_file = os.path.join( data_directory, 'msvc_build', 'Debug', 'msvc_build.pdb' )
56-
cxx_parsers_cfg.pdb_loader = pdb.decl_loader_t( pdb_file )
57-
cxx_parsers_cfg.pdb_loader.read()
58-
return cxx_parsers_cfg.pdb_loader
59-
52+
if sys.platform == 'win32':
53+
from pygccxml.msvc import pdb
54+
pdb_file = os.path.join( data_directory, 'msvc_build', 'Debug', 'msvc_build.pdb' )
55+
pdb_loader = pdb.decl_loader_t( pdb_file )
56+
pdb_loader.read()
6057

6158
def get_pdb_global_ns():
62-
return cxx_parsers_cfg.get_pdb_loader().global_ns
63-
59+
return cxx_parsers_cfg.pdb_loader.global_ns
6460

6561
#~ try:
6662
#~ import pydsc

unittests/core_tester.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ def test_member_function_type(self):
256256
if self.global_ns.compiler != compilers.MSVC_PDB_9:
257257
self.failUnless( function_type.has_const, " 'member_function_ptr_t' should be const function." )
258258

259+
sf = self.glo
260+
members_pointers_t
259261
def test_member_variable_type(self):
260262
if self.global_ns.compiler == compilers.MSVC_PDB_9:
261263
return
@@ -379,13 +381,13 @@ def __init__(self, *args):
379381

380382
def create_suite():
381383
suite = unittest.TestSuite()
382-
#~ suite.addTest( unittest.makeSuite(core_all_at_once_t))
383-
#~ suite.addTest( unittest.makeSuite(core_all_at_once_no_opt_t))
384-
#~ suite.addTest( unittest.makeSuite(core_file_by_file_t))
385-
#~ suite.addTest( unittest.makeSuite(core_file_by_file_no_opt_t))
386-
if sys.platform == 'win32':
384+
if autoconfig.cxx_parsers_cfg.gccxml:
385+
suite.addTest( unittest.makeSuite(core_all_at_once_t))
386+
suite.addTest( unittest.makeSuite(core_all_at_once_no_opt_t))
387+
suite.addTest( unittest.makeSuite(core_file_by_file_t))
388+
suite.addTest( unittest.makeSuite(core_file_by_file_no_opt_t))
389+
if autoconfig.cxx_parsers_cfg.pdb_loader:
387390
suite.addTest( unittest.makeSuite(pdb_based_core_tester_t))
388-
389391
return suite
390392

391393
def run_suite():

unittests/data/core_overloads_1.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
#ifndef __core_overloads_1_hpp__
77
#define __core_overloads_1_hpp__
88

9+
#include <string>
10+
911
namespace core{ namespace overloads{
1012

11-
void do_nothing( int );
12-
void do_nothing( double );
13+
void do_nothing( std::string );
14+
void do_nothing( std::wstring );
1315

1416
} }
1517

unittests/data/core_overloads_2.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
#ifndef __core_overloads_2_hpp__
77
#define __core_overloads_2_hpp__
8-
8+
#include <string>
9+
#include <set>
910
namespace core{ namespace overloads{
1011

11-
void do_nothing( bool );
12-
void do_nothing( float );
12+
void do_nothing( std::set< std::string > );
13+
void do_nothing( std::set< std::wstring > );
1314

1415
} }
1516

unittests/data/msvc_build/all.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@
4444
#include "vector_traits.hpp"
4545
#include "core_types.hpp"
4646

47+
48+
namespace core{ namespace overloads{
49+
50+
void do_nothing( std::string d){ std::cout << d; }
51+
void do_nothing( std::wstring d){ std::wcout << d; }
52+
void do_nothing( std::set< std::string > d ){ std::set< std::string >::size_type t = d.size(); }
53+
void do_nothing( std::set< std::wstring > d ){ std::set< std::wstring >::size_type t = d.size(); }
54+
55+
} }
56+
4757
namespace declarations{ namespace variables{
4858

4959
int static_var = 0;
@@ -56,8 +66,12 @@ void use_decls(){
5666
sizeof(core::types::exception );
5767
}
5868

69+
void use_core_overloads(){
70+
namespace co = core::overloads;
71+
}
5972

6073
void use_core_types(){
74+
use_core_overloads();
6175
core::types::members_pointers_t mem_ptrs;
6276
core::types::typedef_const_int typedef_const_int_ = 0;
6377
core::types::typedef_pointer_int typedef_pointer_int_ = 0;

unittests/data/msvc_build/msvc_build.vcproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
/>
4242
<Tool
4343
Name="VCCLCompilerTool"
44+
AdditionalOptions="/Iu /n "
4445
Optimization="0"
4546
InlineFunctionExpansion="0"
4647
AdditionalIncludeDirectories="..\"
@@ -85,6 +86,7 @@
8586
/>
8687
<Tool
8788
Name="VCBscMakeTool"
89+
AdditionalOptions="/Iu /n "
8890
/>
8991
<Tool
9092
Name="VCFxCopTool"

unittests/parser_test_case.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
from pygccxml.declarations import *
1515

1616
class parser_test_case_t( unittest.TestCase ):
17-
17+
1818
CXX_PARSER_CFG = None
19-
19+
2020
def __init__(self, *args):
2121
unittest.TestCase.__init__(self, *args)
2222
if self.CXX_PARSER_CFG:
2323
self.config = self.CXX_PARSER_CFG.clone()
24-
else:
24+
elif autoconfig.cxx_parsers_cfg.gccxml:
2525
self.config = autoconfig.cxx_parsers_cfg.gccxml.clone()
26+
else:
27+
pass
2628

2729
def _test_type_composition( self, type, expected_compound, expected_base ):
2830
self.failUnless( isinstance( type, expected_compound)

unittests/pdb_tester.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ def test_create_nss(self):
3838
reader = pdb.decl_loader_t( self.pdb_file )
3939
print reader.symbols_table.name
4040
reader.read()
41-
x = []
42-
declarations.print_declarations( reader.global_ns, writer=x.append )
43-
x = filter( None, map( lambda l: l.rstrip(), x ) )
4441
f = file( 'decls.cpp', 'w+' )
45-
f.write( os.linesep.join( x ) )
42+
declarations.print_declarations( reader.global_ns, writer=lambda line: f.write(line+'\n') )
4643
f.close()
4744

4845
f = file( 'symbols.txt', 'w+')
@@ -76,6 +73,18 @@ def test_undecorate_name(self):
7673
#~ print undecorated
7774
self.failUnless( msvc_utils.undecorate_name( decorated ) == undecorated )
7875

76+
#todo: move to GUI
77+
def test_pdbs( self ):
78+
for f in filter( lambda f: f.endswith( 'pdb' ), os.listdir( r'E:\pdbs' ) ):
79+
try:
80+
reader = pdb.decl_loader_t( f )
81+
reader.read()
82+
f = file( d + '.txt', 'w+' )
83+
declarations.print_declarations( reader.global_ns, writer=lambda line: f.write(line+'\n') )
84+
f.close()
85+
except Exception, error:
86+
print 'unable to load pdb file ', f, ' Error: ', str(error)
87+
7988

8089
def create_suite():
8190
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)