コード例 #1
0
def generate_check_version(out: FileGenerator, namespace_name: str,
                           shared_library_name: str):
    out.put_line('const int major_version = {ns}_get_major_version();'.format(
        ns=get_c_name(namespace_name)))
    out.put_line('const int minor_version = {ns}_get_minor_version();'.format(
        ns=get_c_name(namespace_name)))
    out.put_line('const int patch_version = {ns}_get_patch_version();'.format(
        ns=get_c_name(namespace_name)))
    expected_major = '{ns}_MAJOR_VERSION'.format(ns=namespace_name.upper())
    expected_minor = '{ns}_MINOR_VERSION'.format(ns=namespace_name.upper())
    expected_patch = '{ns}_PATCH_VERSION'.format(ns=namespace_name.upper())
    major_compare = 'major_version != {expected_major}'.format(
        expected_major=expected_major)
    minor_compare = 'minor_version != {expected_minor}'.format(
        expected_minor=expected_minor)
    patch_compare = 'patch_version != {expected_patch}'.format(
        expected_patch=expected_patch)
    out.put_line('if ({major} || {minor} || {patch})'.format(
        major=major_compare, minor=minor_compare, patch=patch_compare))
    with IndentScope(out):
        out.put_line('std::stringstream error_message;')
        if shared_library_name:
            out.put_line(
                'error_message << "Incorrect version of " << {0} << " library. ";'
                .format(shared_library_name))
        else:
            out.put_line('error_message << "Incorrect version of library. ";')
        out.put_line(
            'error_message << "Expected version is " << {0} << "." << {1} << "." << {2} << ". ";'
            .format(expected_major, expected_minor, expected_patch))
        out.put_line(
            'error_message << "Found version is " << {0} << "." << {1} << "." << {2} << ".";'
            .format('major_version', 'minor_version', 'patch_version'))
        out.put_line('throw std::runtime_error(error_message.str());')
コード例 #2
0
 def __generate_capi_impl(self, out: FileGenerator):
     plain_functions_list = []
     for namespace_name, namespace_info in self.sorted_by_ns.items():
         for c_function in namespace_info.c_functions:
             plain_functions_list.append((namespace_name, namespace_info, c_function))
     if not self.params.open_api:
         random.shuffle(plain_functions_list)
     first_function = True
     for namespace_name, namespace_info, c_function in plain_functions_list:
         self.cur_namespace_name = namespace_name
         self.cur_namespace_info = namespace_info
         first_function = if_required_then_add_empty_line(first_function, out)
         generated_name = c_function.name
         if not self.params.open_api:
             generated_name = get_c_name('fx' + str(uuid.uuid4()))
             if namespace_name not in self.api_keys:
                 self.api_keys.update({namespace_name: {}})
             self.api_keys[namespace_name][c_function.name] = generated_name
         out.put_line('{api} {return_type} {convention} {name}({arguments})'.format(
             api=self.cur_api_define,
             return_type=c_function.return_type,
             convention=self.cur_api_convention,
             name=generated_name,
             arguments=c_function.arguments))
         out.put_file(c_function.body)
コード例 #3
0
    def process_class(self, cur_class: TClass):
        top = self.properties_stack.pop()

        for cur_property in cur_class.properties:
            cur_set_prefix = cur_property.set_prefix if cur_property.set_prefix_filled else top.set_prefix_value
            cur_get_prefix = cur_property.get_prefix if cur_property.get_prefix_filled else top.get_prefix_value
            cur_get_const = cur_property.get_const if cur_property.get_const_filled else top.get_const_value
            cur_argument_name = cur_property.set_argument_name if cur_property.set_argument_name \
                else get_c_name(cur_property.name)
            new_get_method = TMethod()
            new_get_method.name = cur_get_prefix + cur_property.name
            new_get_method.const = cur_get_const
            new_get_method.return_type = cur_property.return_type if cur_property.return_type_filled \
                else cur_property.type_name
            new_get_method.documentations = copy.deepcopy(
                cur_property.documentations)
            new_get_method.impl_2_c = cur_property.get_impl_2_c
            new_get_method.impl_2_c_filled = cur_property.get_impl_2_c_filled
            new_get_method.return_is_builtin = cur_property.is_builtin
            new_get_method.return_is_builtin_filled = cur_property.is_builtin_filled
            new_get_method.return_copy_or_add_ref = cur_property.return_copy_or_add_ref
            new_get_method.return_copy_or_add_ref_filled = True
            if cur_property.field_name_filled:
                new_get_method.getter_field_name = cur_property.field_name
                new_get_method.getter_field_name_filled = True
            PropertiesProcessor.__process_documentations(new_get_method, True)
            cur_class.methods.append(new_get_method)
            new_set_method = TMethod()
            new_set_method.name = cur_set_prefix + cur_property.name
            set_input_argument = TArgument()
            set_input_argument.name = cur_argument_name
            set_input_argument.type_name = cur_property.set_argument_type if cur_property.set_argument_type_filled \
                else cur_property.type_name
            set_input_argument.c_2_impl = cur_property.set_c_2_impl
            set_input_argument.c_2_impl_filled = cur_property.set_c_2_impl_filled
            set_input_argument.c_2_impl_mode = cur_property.set_c_2_impl_mode
            set_input_argument.c_2_impl_mode_filled = cur_property.set_c_2_impl_mode_filled
            set_input_argument.is_builtin = cur_property.is_builtin
            set_input_argument.is_builtin_filled = cur_property.is_builtin_filled
            new_set_method.arguments.append(set_input_argument)
            if cur_property.field_name_filled:
                new_set_method.setter_field_name = cur_property.field_name
                new_set_method.setter_field_name_filled = True
            new_set_method.documentations = copy.deepcopy(
                cur_property.documentations)
            PropertiesProcessor.__process_documentations(new_set_method, False)
            cur_class.methods.append(new_set_method)

            if self.unittest_generator:
                self.unittest_generator.add_property(cur_class, cur_property,
                                                     new_set_method,
                                                     new_get_method)
        self.properties_stack.append(top)
コード例 #4
0
 def full_c_name(self) -> str:
     return get_c_name(self.parent_class_generator.full_c_name + '_' +
                       self.constructor_object.name)
コード例 #5
0
 def full_c_name(self) -> str:
     return get_c_name(self.parent_namespace_generator.full_c_name + '_' +
                       self.c_name)
コード例 #6
0
 def c_name(self) -> str:
     return get_c_name(self.name + '_' +
                       self.function_object.overload_suffix if self.
                       function_object.overload_suffix else self.name)
コード例 #7
0
 def c_name(self) -> str:
     compound_name = get_full_method_name(self.method_object)
     return get_c_name('_'.join(compound_name))
コード例 #8
0
 def full_c_name(self) -> str:
     return get_c_name(self.full_name)
コード例 #9
0
 def c_name(self) -> str:
     return get_c_name(self.name)