예제 #1
0
def _convert_opaque_to_token(x):
    """
    convert either a string from re or a value from pygccxml to a struct token
    """

    if type(x) is str:
        return {
            "BOOL": "?",
            "UINT8_T": "B",
            "INT8_T": "b",
            "UINT16_T": "H",
            "INT16_T": "h",
            "UINT32_T": "I",
            "INT32_T": "i",
            "UINT64_T": "Q",
            "INT64_T": "q",
            "FLOAT": "f",
            "DOUBLE": "d"
        }[x.upper()]
    elif isinstance(x,
                    declarations.declarated_t) and not declarations.is_enum(x):
        return _convert_opaque_to_token(declarations.remove_alias(x))
    elif declarations.is_integral(x) or declarations.is_enum(x):
        basetoken = {1: "b", 2: "h", 4: "i", 8: "q"}[int(x.byte_size)]

        try:
            if "unsigned" in x.CPPNAME:
                basetoken = basetoken.upper()

            if "bool" in x.CPPNAME:
                basetoken = '?'
        except AttributeError:
            pass

        return basetoken
    elif declarations.is_floating_point(x):
        if isinstance(x, declarations.float_t):
            return "f"
        else:
            return "d"
    elif declarations.is_array(x):
        basetoken = _convert_opaque_to_token(declarations.array_item_type(x))
        return basetoken * x.size
    else:
        raise ValueError("unknown instance: " + repr(x))
예제 #2
0
    def prepare_special_cases():
        """
        Creates a map of special cases ( aliases ) for casting operator.
        """
        special_cases = {}
        const_t = declarations.const_t
        pointer_t = declarations.pointer_t
        for type_ in declarations.FUNDAMENTAL_TYPES.values():
            alias = None
            if declarations.is_same(type_, declarations.bool_t()):
                alias = "__int__"
            elif declarations.is_integral(type_):
                if "long" in type_.decl_string:
                    alias = "__long__"
                else:
                    alias = "__int__"
            elif declarations.is_floating_point(type_):
                alias = "__float__"
            else:
                continue  # void
            if alias:
                special_cases[type_] = alias
                special_cases[const_t(type_)] = alias
        special_cases[pointer_t(const_t(declarations.char_t()))] = "__str__"
        std_string = "::std::basic_string<char,std::char_traits<char>,std::allocator<char> >"
        std_wstring1 = "::std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >"
        std_wstring2 = "::std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >"
        special_cases[std_string] = "__str__"
        special_cases[std_wstring1] = "__str__"
        special_cases[std_wstring2] = "__str__"
        special_cases["::std::string"] = "__str__"
        special_cases["::std::wstring"] = "__str__"

        # TODO: add
        #          std::complex<SomeType> some type should be converted to double
        return special_cases
예제 #3
0
    def prepare_special_cases():
        """
        Creates a map of special cases ( aliases ) for casting operator.
        """
        special_cases = {}
        const_t = declarations.const_t
        pointer_t = declarations.pointer_t
        for type_ in declarations.FUNDAMENTAL_TYPES.values():
            alias = None
            if declarations.is_same( type_, declarations.bool_t() ):
                alias = '__int__'
            elif declarations.is_integral( type_ ):
                if 'long' in type_.decl_string:
                    alias = '__long__'
                else:
                    alias = '__int__'
            elif declarations.is_floating_point( type_ ):
                alias = '__float__'
            else:
                continue #void
            if alias:
                special_cases[ type_ ] = alias
                special_cases[ const_t( type_ ) ] = alias
        special_cases[ pointer_t( const_t( declarations.char_t() ) ) ] = '__str__'
        std_string = '::std::basic_string<char,std::char_traits<char>,std::allocator<char> >'
        std_wstring1 = '::std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >'
        std_wstring2 = '::std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >'
        special_cases[ std_string ] = '__str__'
        special_cases[ std_wstring1 ] = '__str__'
        special_cases[ std_wstring2 ] = '__str__'
        special_cases[ '::std::string' ] = '__str__'
        special_cases[ '::std::wstring' ] = '__str__'

        #TODO: add
        #          std::complex<SomeType> some type should be converted to double
        return special_cases