def implementExpectingClassFooter( self ):
     self._code.decreaseIndent()
     self._code.lineOut( "public:" )
     self._code.lineOut( "\tvirtual ~%s()" % self._identifier )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\t__voodooRemoveFromInstanceList();" )
     self._code.lineOut( '\t\tif ( __voodooInstanceName[ 0 ] != \'\\0\' ) {' );
     VoodooExpectFunction( self._code )._try( "\t\t" )
     self._code.lineOut( '\t\t\t__VoodooGrowingString growingString;' )
     self._code.lineOut( '\t\t\tgrowingString.append( "Destruction of " );' )
     self._code.lineOut( '\t\t\tgrowingString.append( __voodooInstanceName );' )
     self._code.lineOut( '\t\t\tVoodooCommon::Expect::Multiplexer multiplexer(' +
                     ' growingString.result() );' )
     self._code.lineOut( '\t\t\tconst void * unusedReturnValue = 0;' )
     self._code.lineOut( '\t\t\tmultiplexer.returnValue( 0, unusedReturnValue );' )
     VoodooExpectFunction( self._code )._catchVoodooErrorMessages( "\t\t" )
     self._code.lineOut( '\t\t\t__voodooSetInstanceName( "" );' )
     self._code.lineOut( "\t\t}" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     if self._constructorCount == 0:
         self._code.increaseIndent()
         decomposition = functiondecomposition.FunctionDecomposition( name = self._identifier, parameters = [],
                         text = self._identifier, returnRValue = False, returnType = None, static = False, const = False )
         self.constructor( decomposition )
         self._code.decreaseIndent()
     if self._implicitAssignmentOperator:
         self._code.increaseIndent()
         decomposition = functiondecomposition.FunctionDecomposition(
                         name = "operator=",
                         parameters = [ dict( name = "other", text = "const %s & other" % self._identifier ) ],
                         text = "%s & operator=" % self._identifier,
                         returnType = "%s &" % self._identifier,
                          returnRValue = False,
                         static = False,
                         const = False )
         self.method( decomposition )
         self._code.decreaseIndent()
     self._code.lineOut( "\t%s( const %s & other )%s" % (
                 self._identifier, self._identifier,
                 self._constructHeritage() ) )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\t__VoodooGrowingString growingString;" )
     self._code.lineOut( '\t\tgrowingString.append( "Copy of " );' )
     self._code.lineOut( '\t\tgrowingString.append( other.__voodooInstanceName );' )
     self._code.lineOut( "\t\t__voodooSetInstanceName( growingString.result() );" )
     self._code.lineOut( "\t\t__voodooInsertToInstanceList();" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     self._code.lineOut( "\tconst char * voodooInstanceName() const" )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\treturn __voodooInstanceName;" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     self._code.lineOut( "\tstatic %s * voodooInstanceByName( const char * name )" % self._identifier )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\tfor ( %s * i = __voodooHeadInstance(); i != 0 ; i = i->__voodooNextInstance )" % self._identifier )
     self._code.lineOut( "\t\t\tif ( strcmp( i->__voodooInstanceName, name ) == 0 )" )
     self._code.lineOut( "\t\t\t\treturn i;" )
     self._code.lineOut( "\t\treturn 0;" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     self._code.lineOut( "\tstatic %s & voodooConstructingInstance()" % self._identifier )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\tif ( __voodooConstructingInstance() == 0 ) {" )
     self._code.lineOut( '\t\t\tVOODOO_FAIL_TEST( "You called %s::voodooConstructingInstance() "' % self._identifier )
     self._code.lineOut( '\t\t\t\t\t"outside of constructor callback" );' )
     self._code.lineOut( '\t\t}' )
     self._code.lineOut( "\t\treturn * __voodooConstructingInstance();" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     self._code.lineOut( "protected:" )
     self._code.lineOut( "\t%s( __VoodooRedirectorConstruction )%s" %
                             ( self._identifier, self._constructHeritage() ) )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\t__voodooInsertToInstanceList();" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     self._code.lineOut( "\tvoid __voodooSetInstanceName( const char * instanceName )" )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\tstrncpy( __voodooInstanceName, instanceName, VOODOO_EXPECT_MAX_INSTANCE_NAME );" )
     for base in self._mockInherits():
         self._code.lineOut( "\t\t%s::__voodooSetInstanceName( instanceName );" % base )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     self._code.lineOut( "private:" )
     self._code.lineOut( "\tchar __voodooInstanceName[ VOODOO_EXPECT_MAX_INSTANCE_NAME + sizeof( '\\0' ) ];" )
     self._code.lineOut( "\t%s * * __voodooPreviousInstance;" % self._identifier )
     self._code.lineOut( "\t%s * __voodooNextInstance;" % self._identifier )
     self._code.lineOut( "" )
     self._code.lineOut( "\tstatic %s * & __voodooHeadInstance()" % self._identifier )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\tstatic %s * head = 0;" % self._identifier )
     self._code.lineOut( "\t\treturn head;" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     self._code.lineOut( "\tstatic %s * & __voodooConstructingInstance()" % self._identifier )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\tstatic %s * instance = 0;" % self._identifier )
     self._code.lineOut( "\t\treturn instance;" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     self._code.lineOut( "\tvoid __voodooInsertToInstanceList()" )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\t__voodooNextInstance = __voodooHeadInstance();" )
     self._code.lineOut( "\t\tif ( __voodooNextInstance != 0 )" )
     self._code.lineOut( "\t\t\t__voodooNextInstance->__voodooPreviousInstance = & __voodooNextInstance;" )
     self._code.lineOut( "\t\t__voodooPreviousInstance = & __voodooHeadInstance();" )
     self._code.lineOut( "\t\t__voodooHeadInstance() = this;" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "" )
     self._code.lineOut( "\tvoid __voodooRemoveFromInstanceList()" )
     self._code.lineOut( "\t{" )
     self._code.lineOut( "\t\tif ( __voodooPreviousInstance != 0 ) {" )
     self._code.lineOut( "\t\t\t* __voodooPreviousInstance = __voodooNextInstance;" )
     self._code.lineOut( "\t\t\tif ( __voodooNextInstance != 0 )" )
     self._code.lineOut( "\t\t\t\t__voodooNextInstance->__voodooPreviousInstance = __voodooPreviousInstance;" )
     self._code.lineOut( "\t\t}" )
     self._code.lineOut( "\t}" )
     self._code.lineOut( "}; // %s %s" % ( self._construct, self._identifier ) )
     self._code.lineOut( "" )
Example #2
0
 def __iterateNode(self, node):
     if node.kind == cindex.CursorKind.STRUCT_DECL and not node.is_definition(
     ):
         self.structForwardDeclaration(name=node.spelling,
                                       templatePrefix="")
     elif (node.kind == cindex.CursorKind.STRUCT_DECL
           and node.is_definition()
           or node.kind == cindex.CursorKind.CLASS_DECL
           and node.is_definition()):
         isClass = node.kind == cindex.CursorKind.CLASS_DECL
         templatePrefix, templateParametersList = self.__templatePrefixAndParametersForDefinitionNode(
             node)
         self.__enterConstruct(
             isClass=isClass,
             name=node.displayname,
             inheritance=self.__classInheritance(node),
             templatePrefix=templatePrefix,
             templateParametersList=templateParametersList,
             fullText=self.__nodeText(
                 node, removeEverythingAfterLastClosingBrace=True))
         for child in node.get_children():
             self.__iterateNode(child)
         self.__leaveConstruct(isClass)
     elif node.kind == cindex.CursorKind.CLASS_TEMPLATE and not node.is_definition(
     ):
         isClass = self.__isTemplateClass(node)
         self.__forwardDeclarationConstruct(
             isClass,
             name=node.spelling,
             templatePrefix=self.__templatePrefix(node))
     elif node.kind == cindex.CursorKind.CLASS_TEMPLATE and node.is_definition(
     ):
         isClass = self.__isTemplateClass(node)
         self.__enterConstruct(
             isClass,
             name=node.spelling,
             inheritance=self.__classInheritance(node),
             templatePrefix=self.__templatePrefix(node),
             templateParametersList=self.__templateParametersList(node),
             fullText=self.__nodeText(
                 node, removeEverythingAfterLastClosingBrace=True))
         for child in node.get_children():
             if child.kind in [
                     cindex.CursorKind.TEMPLATE_TYPE_PARAMETER,
                     cindex.CursorKind.TEMPLATE_NON_TYPE_PARAMETER
             ]:
                 continue
             self.__iterateNode(child)
         self.__leaveConstruct(isClass)
     elif node.kind == cindex.CursorKind.CLASS_DECL and not node.is_definition(
     ):
         self.classForwardDeclaration(name=node.spelling, templatePrefix="")
     elif node.kind == cindex.CursorKind.UNEXPOSED_DECL:  #extern "C"
         for child in node.get_children():
             self.__iterateNode(child)
     elif node.kind == cindex.CursorKind.VAR_DECL:
         if "static constexpr" in self.__nodeText(node):
             self.variableDeclaration(name=node.spelling,
                                      text=self.__nodeText(node))
         else:
             self.variableDeclaration(name=node.spelling,
                                      text=self.__nodeText(
                                          node,
                                          removePrefixKeywords=['static']))
     elif node.kind == cindex.CursorKind.FIELD_DECL:
         self.fieldDeclaration(name=node.spelling,
                               text=self.__nodeText(node))
     elif node.kind == cindex.CursorKind.TYPEDEF_DECL:
         self.typedef(name=node.spelling,
                      text=self.__nodeText(node, removeBraces=True))
     elif node.kind == cindex.CursorKind.TYPE_ALIAS_DECL:
         self.typedef(name=node.spelling,
                      text=self.__nodeText(node, removeBraces=True))
     elif node.kind == cindex.CursorKind.ENUM_DECL:
         self.enum(name=node.spelling, text=self.__nodeText(node))
     elif node.kind == cindex.CursorKind.FUNCTION_DECL and not node.is_definition(
     ):
         children = self.__functionParameters(node)
         parameters = [
             self.__parseParameter(children[i],
                                   lastParameter=i == len(children) - 1)
             for i in xrange(len(children))
         ]
         text = self.__nodeText(
             node,
             removeLastParenthesis=True,
             removePrefixKeywords=_PREFIX_KEYWORDS_TO_FUNCTIONS_TO_DISCARD,
             removeSuffixKeywords=['noexcept'])
         returnType = self.__removeSpaceInsensitive(text, node.spelling)
         decomposition = functiondecomposition.FunctionDecomposition(
             name=node.spelling,
             text=text,
             parameters=parameters,
             returnType=returnType,
             returnRValue=self.__returnRValue(node.result_type),
             static=node.is_static_method(),
             const=False)
         self.functionForwardDeclaration(decomposition=decomposition)
     elif (node.kind == cindex.CursorKind.FUNCTION_DECL
           and node.is_definition()
           or node.kind == cindex.CursorKind.FUNCTION_TEMPLATE
           and not self.__is_member(node)):
         children = self.__functionParameters(node)
         parameters = [
             self.__parseParameter(children[i],
                                   lastParameter=i == len(children) - 1)
             for i in xrange(len(children))
         ]
         text = self.__nodeText(
             node,
             removeBraces=True,
             removeLastParenthesis=True,
             removePrefixKeywords=_PREFIX_KEYWORDS_TO_FUNCTIONS_TO_DISCARD,
             removeOneNonPunctuationTokenFromTheEnd=True,
             removeSuffixKeywords=['noexcept'])
         returnType = self.__removeSpaceInsensitive(text, node.spelling)
         decomposition = functiondecomposition.FunctionDecomposition(
             name=node.spelling,
             text=text,
             parameters=parameters,
             returnType=returnType,
             returnRValue=self.__returnRValue(node.result_type),
             static=node.is_static_method(),
             const=False)
         self.functionDefinition(decomposition=decomposition)
     elif (node.kind == cindex.CursorKind.CONSTRUCTOR
           or (node.kind == cindex.CursorKind.FUNCTION_TEMPLATE
               and node.spelling == node.lexical_parent.spelling)):
         children = self.__functionParameters(node)
         parameters = [
             self.__parseParameter(children[i],
                                   lastParameter=i == len(children) - 1)
             for i in xrange(len(children))
         ]
         templatePrefix = ""
         if node.kind == cindex.CursorKind.FUNCTION_TEMPLATE:
             templatePrefix = self.__templatePrefix(node)
         decomposition = functiondecomposition.FunctionDecomposition(
             name=node.spelling,
             text=node.spelling,
             parameters=parameters,
             returnType=None,
             returnRValue=False,
             templatePrefix=templatePrefix,
             static=None,
             const=False)
         self.constructorDefinition(decomposition=decomposition)
     elif node.kind in [
             cindex.CursorKind.CXX_METHOD,
             cindex.CursorKind.FUNCTION_TEMPLATE
     ]:
         children = self.__functionParameters(node)
         parameters = [
             self.__parseParameter(children[i],
                                   lastParameter=i == len(children) - 1)
             for i in xrange(len(children))
         ]
         text = self.__nodeText(
             node,
             removeBraces=True,
             removeLastParenthesis=True,
             removePrefixKeywords=_PREFIX_KEYWORDS_TO_FUNCTIONS_TO_DISCARD,
             removeOneNonPunctuationTokenFromTheEnd=True,
             removeSuffixKeywords=[
                 'const', 'override', 'noexcept', 'final'
             ])
         returnType = self.__removeSpaceInsensitive(text, node.spelling)
         templatePrefix = ""
         if node.kind == cindex.CursorKind.FUNCTION_TEMPLATE:
             templatePrefix = self.__templatePrefix(node)
             assert returnType.startswith(
                 templatePrefix), "'%s' '%s'" % (returnType, templatePrefix)
             returnType = returnType[len(templatePrefix):].lstrip()
         decomposition = functiondecomposition.FunctionDecomposition(
             name=node.spelling,
             text=node.spelling,
             parameters=parameters,
             returnType=returnType,
             returnRValue=self.__returnRValue(node.result_type),
             static=node.is_static_method(),
             const=self.__isMethodConst(node),
             templatePrefix=templatePrefix,
             virtual=self.__methodIsVirtual(node))
         self.method(decomposition=decomposition)
     elif node.kind == cindex.CursorKind.CONVERSION_FUNCTION:
         assert node.spelling.startswith("operator")
         conversionType = node.spelling[len("operator"):].strip()
         self.conversionFunction(conversionType=conversionType,
                                 const=self.__isMethodConst(node))
     elif node.kind == cindex.CursorKind.DESTRUCTOR:
         pass
     elif node.kind == cindex.CursorKind.NAMESPACE:
         self.enterNamespace(name=node.spelling)
         for child in node.get_children():
             self.__iterateNode(child)
         self.leaveNamespace()
     elif node.kind == cindex.CursorKind.CXX_ACCESS_SPEC_DECL:
         access = node.get_tokens().next().spelling
         self.accessSpec(access=access)
     elif node.kind == cindex.CursorKind.USING_DIRECTIVE:
         text = self.__nodeText(node)
         self.using(text=text)
     elif node.kind == cindex.CursorKind.USING_DECLARATION:
         text = self.__nodeText(node)
         self.using(text=text)
     elif node.kind == cindex.CursorKind.NAMESPACE_ALIAS:
         text = self.__nodeText(node)
         self.using(text=text)
     elif node.kind == cindex.CursorKind.CXX_FINAL_ATTR:
         pass
     elif node.kind == cindex.CursorKind.CXX_BASE_SPECIFIER:
         pass
     elif node.kind in _POSSIBLE_TEMPLATE_SPECIALIZATION_NODE_TYPES:
         pass
     elif node.kind == cindex.CursorKind.UNION_DECL:
         if node.spelling == '':
             return
         self.union(name=node.spelling, text=self.__nodeText(node))
     else:
         try:
             nodeText = self.__nodeText(node)
         except Exception as e:
             nodeText = "Exception (%s)" % str(e)
         raise Exception(
             "Voodoo does not recognize the following node:\n%s\nNode text:\n%s"
             % (self.__traceNode(node), nodeText))
 def implementRedirectorClassFooter(self):
     self._code.decreaseIndent()
     self._code.lineOut("public:")
     self._code.lineOut("\tvirtual ~%s()" % self._identifier)
     self._code.lineOut("\t{")
     self._code.lineOut("\t\tif ( __voodooRedirectee ) {")
     self._code.lineOut("\t\t\t__voodooRedirectee->%s_Destructor();" %
                        self._identifier)
     self._code.lineOut("\t\t} else {")
     self._code.lineOut("\t\t\tif ( __voodooPrevious )")
     self._code.lineOut("\t\t\t\t* __voodooPrevious = __voodooNext;")
     self._code.lineOut("\t\t\tif ( __voodooNext )")
     self._code.lineOut(
         "\t\t\t\t__voodooNext->__voodooPrevious = __voodooPrevious;")
     self._code.lineOut("\t\t}")
     self._code.lineOut("\t}")
     self._code.lineOut("")
     self._code.lineOut(
         "\tbool voodooSameMockObject( const %s & other ) const" %
         self._identifier)
     self._code.lineOut("\t{")
     self._code.lineOut(
         "\t\tif ( __voodooRedirectee && other.__voodooRedirectee )")
     self._code.lineOut(
         "\t\t\treturn __voodooRedirectee == other.__voodooRedirectee;")
     self._code.lineOut(
         "\t\tif ( __voodooRedirectee && ! other.__voodooRedirectee )")
     self._code.lineOut("\t\t\treturn __voodooRedirectee == & other;")
     self._code.lineOut(
         "\t\tif ( ! __voodooRedirectee && other.__voodooRedirectee )")
     self._code.lineOut("\t\t\treturn this == other.__voodooRedirectee;")
     self._code.lineOut(
         "\t\tif ( ! __voodooRedirectee && ! other.__voodooRedirectee )")
     self._code.lineOut("\t\t\treturn this == & other;")
     self._code.lineOut("")
     self._code.lineOut("\t\treturn false;")
     self._code.lineOut("\t}")
     self._code.lineOut("")
     self._code.lineOut("\t%s * voodooLastRedirector() const" %
                        self._identifier)
     self._code.lineOut("\t{")
     self._code.lineOut("\t\treturn __voodooLastRedirector;")
     self._code.lineOut("\t}")
     self._code.lineOut("")
     if self._constructorCount == 0:
         self._code.increaseIndent()
         decomposition = functiondecomposition.FunctionDecomposition(
             name=self._identifier,
             parameters=[],
             text=self._identifier,
             returnRValue=False,
             returnType=None,
             static=False,
             const=False)
         self.implementConstructor(decomposition)
         self._code.decreaseIndent()
     inherits = ""
     construct = "( __VoodooRedirectorConstruction() )"
     if len(self._mockInherits()) > 0:
         inherits = " :\n\t\t" + ( construct + ",\n\t\t" ).join( self._mockInherits() ) + \
                     construct + "\n"
     self._code.lineOut("\t%s( const %s & other )%s" %
                        (self._identifier, self._identifier, inherits))
     self._code.lineOut("\t{")
     self._code.lineOut("\t\t%s * redirectee = other.__voodooRedirectee;" %
                        self._identifier)
     self._code.lineOut("\t\tif ( redirectee == 0 )")
     self._code.lineOut("\t\t\tredirectee = (%s *) & other;" %
                        self._identifier)
     self._code.lineOut("\t\t__voodooSetRedirectee( redirectee );")
     self._code.lineOut("\t\tif ( other.__voodooRedirectee )")
     self._code.lineOut(
         "\t\t\t__voodooRedirectee->%s_CopyConstructor( other );" %
         self._identifier)
     self._code.lineOut("\t}")
     self._code.lineOut("")
     self._code.lineOut("protected:")
     self._code.lineOut("\t%s( __VoodooRedirectorConstruction ) :" %
                        self._identifier)
     for base in self._mockInherits():
         self._code.lineOut(
             "\t\t\t%s( __VoodooRedirectorConstruction() )," % base)
     self._code.lineOut("\t\t\t__voodooMockName( 0 )")
     self._code.lineOut("\t{")
     self._code.lineOut("\t\t__voodooNext = 0;")
     self._code.lineOut("\t\t__voodooPrevious = 0;")
     self._code.lineOut("\t\t__voodooRedirectee = 0;")
     self._code.lineOut("\t\t__voodooLastRedirector = 0;")
     self._code.lineOut("\t}")
     self._code.lineOut("")
     self._code.lineOut(
         "\t%s( __VoodooMockConstruction, const char * mockName ) :" %
         self._identifier)
     for base in self._mockInherits():
         self._code.lineOut(
             "\t\t\t%s( __VoodooMockConstruction(), mockName )," % base)
     self._code.lineOut("\t\t\t__voodooMockName( mockName )")
     self._code.lineOut("\t{")
     self._code.lineOut("\t\t__voodooNext = __voodooTop();")
     self._code.lineOut("\t\tif ( __voodooNext )")
     self._code.lineOut(
         "\t\t\t__voodooNext->__voodooPrevious = & __voodooNext;")
     self._code.lineOut("\t\t__voodooPrevious = & __voodooTop();")
     self._code.lineOut("\t\t__voodooTop() = this;")
     self._code.lineOut("\t\t__voodooRedirectee = 0;")
     self._code.lineOut("\t\t__voodooLastRedirector = 0;")
     self._code.lineOut("\t}")
     self._code.lineOut("")
     self._code.lineOut("\tvirtual void %s_Destructor()" % self._identifier)
     self._code.lineOut("\t{")
     self._code.lineOut("\t}")
     self._code.lineOut("")
     self._code.lineOut("\tvirtual void %s_CopyConstructor( const %s & )" %
                        (self._identifier, self._identifier))
     self._code.lineOut("\t{")
     self._code.lineOut("\t}")
     self._code.lineOut("")
     self._code.lineOut("\tvoid __voodooSetRedirectee( %s * redirectee )" %
                        self._identifier)
     self._code.lineOut("\t{")
     self._code.lineOut("\t\t__voodooMockName = 0;")
     self._code.lineOut("\t\t__voodooRedirectee = redirectee;")
     self._code.lineOut("\t\tredirectee->__voodooLastRedirector = this;")
     for base in self._mockInherits():
         self._code.lineOut("\t\t%s::__voodooSetRedirectee( redirectee );" %
                            base)
     self._code.lineOut("\t}")
     self._code.lineOut("")
     self._code.lineOut("private:")
     self._code.lineOut("\t%s * __voodooNext;" % self._identifier)
     self._code.lineOut("\t%s * * __voodooPrevious;" % self._identifier)
     self._code.lineOut("\t%s * __voodooRedirectee;" % self._identifier)
     self._code.lineOut("\t%s * __voodooLastRedirector;" % self._identifier)
     self._code.lineOut("\tconst char * __voodooMockName;")
     self._code.lineOut("")
     self._code.lineOut("\tstatic %s * & __voodooTop()" % self._identifier)
     self._code.lineOut("\t{")
     self._code.lineOut("\t\tstatic %s * value = 0;" % self._identifier)
     self._code.lineOut("\t\treturn value;")
     self._code.lineOut("\t}")
     self._code.lineOut("}; // %s %s" % (self._construct, self._identifier))
     self._code.lineOut("")