Skip to content

Commit 4313048

Browse files
author
roman_yakovenko
committed
Adding "explicit" attribute to constructor_t class
1 parent 1940ffa commit 4313048

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

pygccxml/declarations/calldef.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,18 @@ class constructor_t( member_calldef_t ):
532532
"""describes constructor declaration"""
533533
def __init__( self, *args, **keywords ):
534534
member_calldef_t.__init__( self, *args, **keywords )
535+
self._explicit = True
536+
537+
def _get_explicit(self):
538+
return self._explicit
539+
def _set_explicit(self, explicit):
540+
if explicit in [True, '1']:
541+
self._explicit = True
542+
else:
543+
self._explicit = False
544+
explicit = property( _get_explicit, _set_explicit
545+
, doc="""True, if constructor has "explicit" keyword, False otherwise
546+
@type: bool""" )
535547

536548
def __str__(self):
537549
# Get the full name of the calldef...
@@ -568,7 +580,6 @@ def is_copy_constructor(self):
568580
def is_trivial_constructor(self):
569581
return not bool( self.arguments )
570582

571-
572583
class destructor_t( member_calldef_t ):
573584
"""describes deconstructor declaration"""
574585
def __init__( self, *args, **keywords ):

pygccxml/declarations/decl_printer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,11 @@ def visit_constructor( self ):
146146
self.print_decl_header()
147147
self.print_calldef_info()
148148

149+
indent = ' ' * (self.level+1) * self.INDENT_SIZE
150+
self.writer( indent + "explicit: " + str(self.__inst.explicit) + os.linesep)
151+
149152
if self.__print_details:
150-
self.writer( ' ' * ( self.level + 1 ) * self.INDENT_SIZE
153+
self.writer( indent
151154
+ 'copy constructor: ' + str(self.__inst.is_copy_constructor) + os.linesep)
152155

153156
def visit_destructor( self ):

pygccxml/parser/scanner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
XML_AN_CVS_REVISION = "cvs_revision"
3030
XML_AN_DEFAULT = "default"
3131
XML_AN_DEMANGLED = "demangled"
32+
XML_AN_EXPLICIT = "explicit"
3233
XML_AN_EXTERN = "extern"
3334
XML_AN_FILE = "file"
3435
XML_AN_ID = "id"
@@ -494,6 +495,7 @@ def __read_casting_operator(self, attrs ):
494495
def __read_constructor( self, attrs ):
495496
constructor = self.__decl_factory.create_constructor()
496497
self.__read_member_function( constructor, attrs, True )
498+
constructor.explicit = attrs.get( XML_AN_EXPLICIT, False )
497499
return constructor
498500

499501
def __read_function(self, attrs):

unittests/data/declarations_calldef.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ void calldef_with_throw() throw( some_exception_t, other_exception_t );
2727
struct calldefs_t{
2828
calldefs_t();
2929

30-
calldefs_t(char);
30+
explicit calldefs_t(char);
31+
32+
calldefs_t(some_exception_t);
3133

3234
calldefs_t(int,double);
3335

unittests/declarations_tester.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_constructors_destructors(self):
123123

124124
destructor = struct_calldefs.calldef( '~calldefs_t' )
125125
self._test_calldef_args( destructor, [] )
126-
self._test_calldef_return_type( destructor, None.__class__)
126+
self._test_calldef_return_type( destructor, None.__class__)
127127

128128
#well, now we have a few functions ( constructors ) with the same name, there is no easy way
129129
#to find the desired one. Well in my case I have only 4 constructors
@@ -132,14 +132,23 @@ def test_constructors_destructors(self):
132132
#3. default
133133
#4. copy constructor
134134
constructor_found = struct_calldefs.constructors( 'calldefs_t' )
135-
self.failUnless( len( constructor_found ) == 4
136-
, "struct 'calldefs_t' has 4 constructors, pygccxml parser reports only about %d." \
135+
self.failUnless( len( constructor_found ) == 5
136+
, "struct 'calldefs_t' has 5 constructors, pygccxml parser reports only about %d." \
137137
% len( constructor_found ) )
138138
self.failUnless( 1 == len( filter( lambda constructor: constructor.is_copy_constructor, constructor_found ) )
139139
, "copy constructor has not been found" )
140140
#there is nothing to check about constructors - I know the implementation of parser
141141
#In this case it doesn't different from any other function
142142

143+
c = struct_calldefs.constructor( 'calldefs_t', arg_types=['char'] )
144+
self.failUnless( c.explicit == True
145+
, "calldef_t constructor defined with 'explicit' keyword, for some reason the value is False ")
146+
147+
arg_type = declarated_t( self.global_ns.class_('some_exception_t') )
148+
c = struct_calldefs.constructor( 'calldefs_t', arg_types=[arg_type] )
149+
self.failUnless( c.explicit == False
150+
, "calldef_t constructor defined without 'explicit' keyword, for some reason the value is True ")
151+
143152
def test_operator_symbol(self):
144153
calldefs_operators = ['=', '==' ]
145154
calldefs_cast_operators = ['char *', 'double']

unittests/filters_tester.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def test_access_type( self ):
4040
public_members = declarations.matcher.find( criteria, self.global_ns )
4141
if '0.9' in public_members[0].compiler:
4242
public_members = filter( lambda d: not d.is_artificial, public_members )
43-
self.failUnless( 16 == len( public_members ) )
43+
self.failUnless( 17 == len( public_members ) )
4444
else:
45-
self.failUnless( 20 == len( public_members ) )
45+
self.failUnless( 21 == len( public_members ) )
4646

4747
def test_or_matcher( self ):
4848
criteria1 = declarations.regex_matcher_t( 'oper.*'

0 commit comments

Comments
 (0)