def _VAR_DECL_value(self, cursor, _type):
        """Handles Variable value initialization."""
        # always expect list [(k,v)] as init value.from list(cursor.get_children())
        # get the init_value and special cases
        init_value = self._get_var_decl_init_value(cursor.type,
                                                   list(cursor.get_children()))
        _ctype = cursor.type.get_canonical()
        if self.is_unexposed_type(_ctype):
            # string are not exposed
            init_value = '%s # UNEXPOSED TYPE. PATCH NEEDED.' % (init_value)
        elif (self.is_pointer_type(_ctype) and
                      _ctype.get_pointee().kind == TypeKind.FUNCTIONPROTO):
            # Function pointers argument are handled at type creation time
            # but we need to put a CFUNCTYPE as a value of the name variable
            init_value = _type
        elif self.is_array_type(_ctype):
            # an integer litteral will be the size
            # an string litteral will be the value
            # any list member will be children of a init_list_expr
            # FIXME Move that code into typedesc
            def countof(k, l):
                return [item[0] for item in l].count(k)

            if (countof(CursorKind.INIT_LIST_EXPR, init_value) == 1):
                init_value = dict(init_value)[CursorKind.INIT_LIST_EXPR]
            elif (countof(CursorKind.STRING_LITERAL, init_value) == 1):
                # we have a initialised c_array
                init_value = dict(init_value)[CursorKind.STRING_LITERAL]
            else:
                # ignore size alone
                init_value = []
            # check the array size versus elements.
            if _type.size < len(init_value):
                _type.size = len(init_value)
        elif init_value == []:
            # catch case.
            init_value = None
        else:
            log.debug('VAR_DECL: default init_value: %s', init_value)
            if len(init_value) > 0:
                init_value = init_value[0][1]
        return init_value
def _VAR_DECL_value ( self , cursor , _type ) : init_value = self . _get_var_decl_init_value ( cursor . type , list ( cursor . get_children ( ) ) ) _ctype = cursor . type . get_canonical ( ) if self . is_unexposed_type ( _ctype ) : init_value = '%s # UNEXPOSED TYPE. PATCH NEEDED.' % ( init_value ) elif ( self . is_pointer_type ( _ctype ) and _ctype . get_pointee ( ) . kind == TypeKind . FUNCTIONPROTO ) : init_value = _type elif self . is_array_type ( _ctype ) : def countof ( k , l ) : return [ item [ 0 ] for item in l ] . count ( k ) if ( countof ( CursorKind . INIT_LIST_EXPR , init_value ) == 1 ) : init_value = dict ( init_value ) [ CursorKind . INIT_LIST_EXPR ] elif ( countof ( CursorKind . STRING_LITERAL , init_value ) == 1 ) : init_value = dict ( init_value ) [ CursorKind . STRING_LITERAL ] else : init_value = [ ] if _type . size < len ( init_value ) : _type . size = len ( init_value ) elif init_value == [ ] : init_value = None else : log . debug ( 'VAR_DECL: default init_value: %s' , init_value ) if len ( init_value ) > 0 : init_value = init_value [ 0 ] [ 1 ] return init_value
Handles Variable value initialization.