def _generate_conversions_for_command(self, domain, command):
        lines = []
        if command.call_parameters:
            lines.append('')

        def in_param_expression(param_name, parameter):
            _type = parameter.type
            if isinstance(_type, AliasedType):
                _type = _type.aliased_type  # Fall through to enum or primitive.
            if isinstance(_type, EnumType):
                _type = _type.primitive_type  # Fall through to primitive.
            if isinstance(_type, PrimitiveType):
                return '*%s' % param_name if parameter.is_optional else param_name
            return '%s.copyRef()' % param_name

        for parameter in command.call_parameters:
            in_param_name = 'in_%s' % parameter.parameter_name
            objc_in_param_name = 'o_%s' % in_param_name
            objc_type = ObjCGenerator.objc_type_for_param(domain, command.command_name, parameter, False)
            param_expression = in_param_expression(in_param_name, parameter)
            import_expression = ObjCGenerator.objc_protocol_import_expression_for_parameter(param_expression, domain, command.command_name, parameter)
            if not parameter.is_optional:
                lines.append('    %s = %s;' % (join_type_and_name(objc_type, objc_in_param_name), import_expression))
            else:
                lines.append('    %s;' % join_type_and_name(objc_type, objc_in_param_name))
                lines.append('    if (%s)' % in_param_name)
                lines.append('        %s = %s;' % (objc_in_param_name, import_expression))

        if lines:
            lines.append('')
        return '\n'.join(lines)
    def _generate_event(self, domain, event):
        lines = []
        lines.append(self._generate_event_signature(domain, event))
        lines.append('{')
        lines.append('    const FrontendRouter& router = _controller->frontendRouter();')
        lines.append('')

        required_pointer_parameters = filter(lambda parameter: not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
        for parameter in required_pointer_parameters:
            var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
            lines.append('    THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name))
            objc_array_class = self.objc_class_for_array_type(parameter.type)
            if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
                lines.append('    THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))

        optional_pointer_parameters = filter(lambda parameter: parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
        for parameter in optional_pointer_parameters:
            var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
            lines.append('    THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name))
            objc_array_class = self.objc_class_for_array_type(parameter.type)
            if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
                lines.append('    THROW_EXCEPTION_FOR_BAD_TYPE_IN_OPTIONAL_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))

        if required_pointer_parameters or optional_pointer_parameters:
            lines.append('')

        lines.append('    Ref<InspectorObject> jsonMessage = InspectorObject::create();')
        lines.append('    jsonMessage->setString(ASCIILiteral("method"), ASCIILiteral("%s.%s"));' % (domain.domain_name, event.event_name))
        if event.event_parameters:
            lines.extend(self._generate_event_out_parameters(domain, event))
        lines.append('    router.sendEvent(jsonMessage->toJSONString());')
        lines.append('}')
        return '\n'.join(lines)
Example #3
0
    def generate_output(self):
        secondary_headers = [
            '"%sInternal.h"' % ObjCGenerator.OBJC_PREFIX,
            '"%sBackendDispatchers.h"' % ObjCGenerator.OBJC_PREFIX,
            '<JavaScriptCore/AlternateDispatchableAgent.h>',
            '<JavaScriptCore/AugmentableInspectorController.h>',
            '<JavaScriptCore/InspectorAlternateBackendDispatchers.h>',
            '<JavaScriptCore/InspectorBackendDispatchers.h>',
        ]

        header_args = {
            'primaryInclude':
            '"%sConfiguration.h"' % ObjCGenerator.OBJC_PREFIX,
            'secondaryIncludes':
            '\n'.join(['#import %s' % header for header in secondary_headers]),
        }

        self._command_filter = ObjCGenerator.should_generate_domain_command_handler_filter(
            self.model())
        self._event_filter = ObjCGenerator.should_generate_domain_event_dispatcher_filter(
            self.model())

        domains = self.domains_to_generate()
        sections = []
        sections.append(self.generate_license())
        sections.append(
            Template(ObjCTemplates.ImplementationPrelude).substitute(
                None, **header_args))
        sections.append(
            self._generate_configuration_implementation_for_domains(domains))
        sections.append(
            Template(ObjCTemplates.ImplementationPostlude).substitute(
                None, **header_args))
        return '\n\n'.join(sections)
Example #4
0
    def generate_output(self):
        headers = set([
            '<WebInspector/RWIProtocolJSONObject.h>',
        ])

        header_args = {
            'includes': '\n'.join(['#import ' + header for header in sorted(headers)]),
        }

        domains = self.domains_to_generate()
        type_domains = filter(ObjCGenerator.should_generate_domain_types_filter(self.model()), domains)
        command_domains = filter(ObjCGenerator.should_generate_domain_command_handler_filter(self.model()), domains)
        event_domains = filter(ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model()), domains)

        # FIXME: <https://webkit.org/b/138222> Web Inspector: Reduce unnecessary enums/types generated in ObjC Protocol Interfaces
        # Currently we generate enums/types for all types in the type_domains. For the built-in
        # JSC domains (Debugger, Runtime) this produces extra unused types. We only need to
        # generate these types if they are referenced by the command_domains or event_domains.

        sections = []
        sections.append(self.generate_license())
        sections.append(Template(ObjCTemplates.HeaderPrelude).substitute(None, **header_args))
        sections.append('\n'.join(filter(None, map(self._generate_forward_declarations, type_domains))))
        sections.append('\n'.join(filter(None, map(self._generate_enums, type_domains))))
        sections.append('\n'.join(filter(None, map(self._generate_types, type_domains))))
        sections.append('\n\n'.join(filter(None, map(self._generate_command_protocols, command_domains))))
        sections.append('\n\n'.join(filter(None, map(self._generate_event_interfaces, event_domains))))
        sections.append(Template(ObjCTemplates.HeaderPostlude).substitute(None))
        return '\n\n'.join(sections)
    def _generate_event(self, domain, event):
        lines = []
        lines.append(self._generate_event_signature(domain, event))
        lines.append('{')
        lines.append('    InspectorFrontendChannel* frontendChannel = _controller->frontendChannel();')
        lines.append('    if (!frontendChannel)')
        lines.append('        return;')
        lines.append('')

        required_pointer_parameters = filter(lambda parameter: not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
        for parameter in required_pointer_parameters:
            var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
            lines.append('    THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name))

        optional_pointer_parameters = filter(lambda parameter: parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
        for parameter in optional_pointer_parameters:
            var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
            lines.append('    THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name))

        if required_pointer_parameters or optional_pointer_parameters:
            lines.append('')

        lines.append('    RefPtr<InspectorObject> jsonMessage = InspectorObject::create();')
        lines.append('    jsonMessage->setString(ASCIILiteral("method"), ASCIILiteral("%s.%s"));' % (domain.domain_name, event.event_name))
        if event.event_parameters:
            lines.extend(self._generate_event_out_parameters(domain, event))
        lines.append('    frontendChannel->sendMessageToFrontend(jsonMessage->toJSONString());')
        lines.append('}')
        return '\n'.join(lines)
    def _generate_init_method_for_required_members(self, domain, declaration, required_members):
        pairs = []
        for member in required_members:
            objc_type = self.objc_type_for_member(declaration, member)
            var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
            pairs.append('%s:(%s)%s' % (var_name, objc_type, var_name))
        pairs[0] = ucfirst(pairs[0])
        lines = []
        lines.append('- (instancetype)initWith%s' % ' '.join(pairs))
        lines.append('{')
        lines.append('    if (!(self = [super init]))')
        lines.append('        return nil;')
        lines.append('')

        required_pointer_members = filter(lambda member: ObjCGenerator.is_type_objc_pointer_type(member.type), required_members)
        if required_pointer_members:
            for member in required_pointer_members:
                var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
                lines.append('    THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(%s, @"%s");' % (var_name, var_name))
                objc_array_class = self.objc_class_for_array_type(member.type)
                if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
                    lines.append('    THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
            lines.append('')

        for member in required_members:
            var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
            lines.append('    self.%s = %s;' % (var_name, var_name))

        lines.append('')
        lines.append('    return self;')
        lines.append('}')
        return '\n'.join(lines)
    def _generate_conversions_for_command(self, domain, command):
        lines = []
        if command.call_parameters:
            lines.append("")

        def in_param_expression(param_name, parameter):
            _type = parameter.type
            if isinstance(_type, AliasedType):
                _type = _type.aliased_type  # Fall through to enum or primitive.
            if isinstance(_type, EnumType):
                _type = _type.primitive_type  # Fall through to primitive.
            if isinstance(_type, PrimitiveType):
                if _type.raw_name() in ["array", "any", "object"]:
                    return "&%s" % param_name if not parameter.is_optional else param_name
                return "*%s" % param_name if parameter.is_optional else param_name
            return "&%s" % param_name if not parameter.is_optional else param_name

        for parameter in command.call_parameters:
            in_param_name = "in_%s" % parameter.parameter_name
            objc_in_param_name = "o_%s" % in_param_name
            objc_type = ObjCGenerator.objc_type_for_param(domain, command.command_name, parameter, False)
            param_expression = in_param_expression(in_param_name, parameter)
            import_expression = ObjCGenerator.objc_protocol_import_expression_for_parameter(
                param_expression, domain, command.command_name, parameter
            )
            if not parameter.is_optional:
                lines.append("    %s = %s;" % (join_type_and_name(objc_type, objc_in_param_name), import_expression))
            else:
                lines.append("    %s;" % join_type_and_name(objc_type, objc_in_param_name))
                lines.append("    if (%s)" % in_param_name)
                lines.append("        %s = %s;" % (objc_in_param_name, import_expression))

        if lines:
            lines.append("")
        return "\n".join(lines)
    def _generate_init_method_for_required_members(self, domain, declaration, required_members):
        pairs = []
        for member in required_members:
            objc_type = self.objc_type_for_member(declaration, member)
            var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
            pairs.append('%s:(%s)%s' % (var_name, objc_type, var_name))
        pairs[0] = ucfirst(pairs[0])
        lines = []
        lines.append('- (instancetype)initWith%s' % ' '.join(pairs))
        lines.append('{')
        lines.append('    if (!(self = [super init]))')
        lines.append('        return nil;')
        lines.append('')

        required_pointer_members = filter(lambda member: ObjCGenerator.is_type_objc_pointer_type(member.type), required_members)
        if required_pointer_members:
            for member in required_pointer_members:
                var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
                lines.append('    THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(%s, @"%s");' % (var_name, var_name))
                objc_array_class = self.objc_class_for_array_type(member.type)
                if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
                    lines.append('    THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
            lines.append('')

        for member in required_members:
            var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
            lines.append('    self.%s = %s;' % (var_name, var_name))

        lines.append('')
        lines.append('    return self;')
        lines.append('}')
        return '\n'.join(lines)
Example #9
0
    def generate_output(self):
        headers = set([
            '<WebInspector/%sJSONObject.h>' % ObjCGenerator.OBJC_PREFIX,
        ])

        header_args = {
            'includes': '\n'.join(['#import ' + header for header in sorted(headers)]),
        }

        domains = self.domains_to_generate()
        type_domains = list(filter(ObjCGenerator.should_generate_domain_types_filter(self.model()), domains))
        command_domains = list(filter(ObjCGenerator.should_generate_domain_command_handler_filter(self.model()), domains))
        event_domains = list(filter(ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model()), domains))

        # FIXME: <https://webkit.org/b/138222> Web Inspector: Reduce unnecessary enums/types generated in ObjC Protocol Interfaces
        # Currently we generate enums/types for all types in the type_domains. For the built-in
        # JSC domains (Debugger, Runtime) this produces extra unused types. We only need to
        # generate these types if they are referenced by the command_domains or event_domains.

        sections = []
        sections.append(self.generate_license())
        sections.append(Template(ObjCTemplates.HeaderPrelude).substitute(None, **header_args))
        sections.append('\n'.join([_f for _f in map(self._generate_forward_declarations, type_domains) if _f]))
        sections.append('\n'.join([_f for _f in map(self._generate_enums, type_domains) if _f]))
        sections.append('\n'.join([_f for _f in map(self._generate_types, type_domains) if _f]))
        sections.append('\n\n'.join([_f for _f in map(self._generate_command_protocols, command_domains) if _f]))
        sections.append('\n\n'.join([_f for _f in map(self._generate_event_interfaces, event_domains) if _f]))
        sections.append(Template(ObjCTemplates.HeaderPostlude).substitute(None))
        return '\n\n'.join(sections)
Example #10
0
 def _generate_getter_for_member(self, domain, declaration, member):
     objc_type = self.objc_type_for_member(declaration, member)
     var_name = ObjCGenerator.identifier_to_objc_identifier(
         member.member_name)
     getter_method = ObjCGenerator.objc_getter_method_for_member(
         declaration, member)
     basic_expression = '[super %s:@"%s"]' % (getter_method,
                                              member.member_name)
     category = ObjCTypeCategory.category_for_type(member.type)
     if category is ObjCTypeCategory.Object:
         lines = []
         lines.append('- (%s)%s' % (objc_type, var_name))
         lines.append('{')
         lines.append(
             self.protocol_to_objc_code_block_for_object_member(
                 declaration, member, basic_expression))
         lines.append('}')
     else:
         conversion_expression = self.protocol_to_objc_expression_for_member(
             declaration, member, basic_expression)
         lines = []
         lines.append('- (%s)%s' % (objc_type, var_name))
         lines.append('{')
         lines.append('    return %s;' % conversion_expression)
         lines.append('}')
     return '\n'.join(lines)
    def generate_output(self):
        secondary_headers = [
            '"%sInternal.h"' % ObjCGenerator.OBJC_PREFIX,
            '"%sBackendDispatchers.h"' % ObjCGenerator.OBJC_PREFIX,
            "<JavaScriptCore/AlternateDispatchableAgent.h>",
            "<JavaScriptCore/AugmentableInspectorController.h>",
            "<JavaScriptCore/InspectorAlternateBackendDispatchers.h>",
            "<JavaScriptCore/InspectorBackendDispatchers.h>",
        ]

        header_args = {
            "primaryInclude": '"%sConfiguration.h"' % ObjCGenerator.OBJC_PREFIX,
            "secondaryIncludes": "\n".join(["#import %s" % header for header in secondary_headers]),
        }

        self._command_filter = ObjCGenerator.should_generate_domain_command_handler_filter(self.model())
        self._event_filter = ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model())

        domains = self.domains_to_generate()
        sections = []
        sections.append(self.generate_license())
        sections.append(Template(ObjCTemplates.ImplementationPrelude).substitute(None, **header_args))
        sections.append(self._generate_configuration_implementation_for_domains(domains))
        sections.append(Template(ObjCTemplates.ImplementationPostlude).substitute(None, **header_args))
        return "\n\n".join(sections)
Example #12
0
    def generate_output(self):
        headers = [
            '<WebInspector/%s.h>' % self.objc_prefix(),
        ]

        header_args = {
            'includes': '\n'.join(['#import ' + header for header in headers]),
        }

        self._command_filter = ObjCGenerator.should_generate_domain_command_handler_filter(
            self.model())
        self._event_filter = ObjCGenerator.should_generate_domain_event_dispatcher_filter(
            self.model())

        domains = self.domains_to_generate()
        sections = []
        sections.append(self.generate_license())
        sections.append(
            Template(ObjCTemplates.GenericHeaderPrelude).substitute(
                None, **header_args))
        sections.append(
            self._generate_configuration_interface_for_domains(domains))
        sections.append(
            Template(ObjCTemplates.GenericHeaderPostlude).substitute(
                None, **header_args))
        return '\n\n'.join(sections)
    def _generate_event(self, domain, event):
        lines = []
        lines.append(self._generate_event_signature(domain, event))
        lines.append('{')
        lines.append('    InspectorFrontendChannel* frontendChannel = _controller->frontendChannel();')
        lines.append('    if (!frontendChannel)')
        lines.append('        return;')
        lines.append('')

        required_pointer_parameters = filter(lambda parameter: not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
        for parameter in required_pointer_parameters:
            var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
            lines.append('    THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name))
            objc_array_class = ObjCGenerator.objc_class_for_array_type(parameter.type)
            if objc_array_class and objc_array_class.startswith(ObjCGenerator.OBJC_PREFIX):
                lines.append('    THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))

        optional_pointer_parameters = filter(lambda parameter: parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
        for parameter in optional_pointer_parameters:
            var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
            lines.append('    THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name))
            objc_array_class = ObjCGenerator.objc_class_for_array_type(parameter.type)
            if objc_array_class and objc_array_class.startswith(ObjCGenerator.OBJC_PREFIX):
                lines.append('    THROW_EXCEPTION_FOR_BAD_TYPE_IN_OPTIONAL_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))

        if required_pointer_parameters or optional_pointer_parameters:
            lines.append('')

        lines.append('    Ref<InspectorObject> jsonMessage = InspectorObject::create();')
        lines.append('    jsonMessage->setString(ASCIILiteral("method"), ASCIILiteral("%s.%s"));' % (domain.domain_name, event.event_name))
        if event.event_parameters:
            lines.extend(self._generate_event_out_parameters(domain, event))
        lines.append('    frontendChannel->sendMessageToFrontend(jsonMessage->toJSONString());')
        lines.append('}')
        return '\n'.join(lines)
Example #14
0
    def _generate_event(self, domain, event):
        lines = []
        lines.append(self._generate_event_signature(domain, event))
        lines.append('{')
        lines.append(
            '    const FrontendRouter& router = _controller->frontendRouter();'
        )
        lines.append('')

        required_pointer_parameters = [
            parameter for parameter in event.event_parameters
            if not parameter.is_optional
            and ObjCGenerator.is_type_objc_pointer_type(parameter.type)
        ]
        for parameter in required_pointer_parameters:
            var_name = ObjCGenerator.identifier_to_objc_identifier(
                parameter.parameter_name)
            lines.append(
                '    THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' %
                (var_name, var_name))
            objc_array_class = self.objc_class_for_array_type(parameter.type)
            if objc_array_class and objc_array_class.startswith(
                    self.objc_prefix()):
                lines.append(
                    '    THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);'
                    % (var_name, objc_array_class))

        optional_pointer_parameters = [
            parameter for parameter in event.event_parameters
            if parameter.is_optional
            and ObjCGenerator.is_type_objc_pointer_type(parameter.type)
        ]
        for parameter in optional_pointer_parameters:
            var_name = ObjCGenerator.identifier_to_objc_identifier(
                parameter.parameter_name)
            lines.append(
                '    THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' %
                (var_name, var_name))
            objc_array_class = self.objc_class_for_array_type(parameter.type)
            if objc_array_class and objc_array_class.startswith(
                    self.objc_prefix()):
                lines.append(
                    '    THROW_EXCEPTION_FOR_BAD_TYPE_IN_OPTIONAL_ARRAY(%s, [%s class]);'
                    % (var_name, objc_array_class))

        if required_pointer_parameters or optional_pointer_parameters:
            lines.append('')

        lines.append('    auto protocol_jsonMessage = JSON::Object::create();')
        lines.append(
            '    protocol_jsonMessage->setString("method"_s, "%s.%s"_s);' %
            (domain.domain_name, event.event_name))
        if event.event_parameters:
            lines.extend(self._generate_event_out_parameters(domain, event))
        lines.append(
            '    router.sendEvent(protocol_jsonMessage->toJSONString());')
        lines.append('}')
        return self.wrap_with_guard_for_condition(event.condition,
                                                  '\n'.join(lines))
Example #15
0
 def _generate_init_method_for_required_members(self, domain, declaration, required_members):
     pairs = []
     for member in required_members:
         objc_type = ObjCGenerator.objc_type_for_member(declaration, member)
         var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
         pairs.append('%s:(%s)%s' % (var_name, objc_type, var_name))
     pairs[0] = ucfirst(pairs[0])
     return '- (instancetype)initWith%s;' % ' '.join(pairs)
Example #16
0
 def _generate_init_method_for_required_members(self, domain, declaration, required_members):
     pairs = []
     for member in required_members:
         objc_type = ObjCGenerator.objc_type_for_member(declaration, member)
         var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
         pairs.append('%s:(%s)%s' % (var_name, objc_type, var_name))
     pairs[0] = ucfirst(pairs[0])
     return '- (instancetype)initWith%s;' % ' '.join(pairs)
Example #17
0
 def _generate_member_property(self, declaration, member):
     accessor_type = ObjCGenerator.objc_accessor_type_for_member(member)
     objc_type = ObjCGenerator.objc_type_for_member(declaration, member)
     return '@property (nonatomic, %s) %s;' % (
         accessor_type,
         join_type_and_name(
             objc_type,
             ObjCGenerator.identifier_to_objc_identifier(
                 member.member_name)))
 def _generate_setter_for_member(self, domain, declaration, member):
     objc_type = ObjCGenerator.objc_type_for_member(declaration, member)
     var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
     setter_method = ObjCGenerator.objc_setter_method_for_member(declaration, member)
     conversion_expression = ObjCGenerator.objc_to_protocol_expression_for_member(declaration, member, var_name)
     lines = []
     lines.append('- (void)set%s:(%s)%s' % (ucfirst(var_name), objc_type, var_name))
     lines.append('{')
     lines.append('    [super %s:%s forKey:@"%s"];' % (setter_method, conversion_expression, member.member_name))
     lines.append('}')
     return '\n'.join(lines)
 def _generate_dealloc(self, domains):
     lines = []
     lines.append('- (void)dealloc')
     lines.append('{')
     for domain in domains:
         if domain.commands and self._command_filter(domain):
             lines.append('    [_%sHandler release];' % ObjCGenerator.variable_name_prefix_for_domain(domain))
         if domain.events and self._event_filter(domain):
             lines.append('    [_%sEventDispatcher release];' % ObjCGenerator.variable_name_prefix_for_domain(domain))
     lines.append('    [super dealloc];')
     lines.append('}')
     return lines
 def _generate_ivars(self, domains):
     lines = []
     for domain in domains:
         if domain.commands and self._command_filter(domain):
             objc_class_name = '%s%sDomainHandler' % (self.objc_prefix(), domain.domain_name)
             ivar_name = '_%sHandler' % ObjCGenerator.variable_name_prefix_for_domain(domain)
             lines.append('    id<%s> %s;' % (objc_class_name, ivar_name))
         if domain.events and self._event_filter(domain):
             objc_class_name = '%s%sDomainEventDispatcher' % (self.objc_prefix(), domain.domain_name)
             ivar_name = '_%sEventDispatcher' % ObjCGenerator.variable_name_prefix_for_domain(domain)
             lines.append('    %s *%s;' % (objc_class_name, ivar_name))
     return lines
 def _generate_ivars(self, domains):
     lines = []
     for domain in domains:
         if self.should_generate_commands_for_domain(domain):
             objc_class_name = '%s%sDomainHandler' % (self.objc_prefix(), domain.domain_name)
             ivar_name = '_%sHandler' % ObjCGenerator.variable_name_prefix_for_domain(domain)
             lines.append('    id<%s> %s;' % (objc_class_name, ivar_name))
         if self.should_generate_events_for_domain(domain):
             objc_class_name = '%s%sDomainEventDispatcher' % (self.objc_prefix(), domain.domain_name)
             ivar_name = '_%sEventDispatcher' % ObjCGenerator.variable_name_prefix_for_domain(domain)
             lines.append('    %s *%s;' % (objc_class_name, ivar_name))
     return lines
 def _generate_getter_for_member(self, domain, declaration, member):
     objc_type = self.objc_type_for_member(declaration, member)
     var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
     getter_method = ObjCGenerator.objc_getter_method_for_member(declaration, member)
     basic_expression = '[super %s:@"%s"]' % (getter_method, member.member_name)
     conversion_expression = self.protocol_to_objc_expression_for_member(declaration, member, basic_expression)
     lines = []
     lines.append('- (%s)%s' % (objc_type, var_name))
     lines.append('{')
     lines.append('    return %s;' % conversion_expression)
     lines.append('}')
     return '\n'.join(lines)
 def _generate_ivars(self, domains):
     lines = []
     for domain in domains:
         if domain.commands and self._command_filter(domain):
             objc_class_name = "%s%sDomainHandler" % (ObjCGenerator.OBJC_PREFIX, domain.domain_name)
             ivar_name = "_%sHandler" % ObjCGenerator.variable_name_prefix_for_domain(domain)
             lines.append("    id<%s> %s;" % (objc_class_name, ivar_name))
         if domain.events and self._event_filter(domain):
             objc_class_name = "%s%sDomainEventDispatcher" % (ObjCGenerator.OBJC_PREFIX, domain.domain_name)
             ivar_name = "_%sEventDispatcher" % ObjCGenerator.variable_name_prefix_for_domain(domain)
             lines.append("    %s *%s;" % (objc_class_name, ivar_name))
     return lines
 def _generate_setter_for_member(self, domain, declaration, member):
     objc_type = self.objc_type_for_member(declaration, member)
     var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
     setter_method = ObjCGenerator.objc_setter_method_for_member(declaration, member)
     conversion_expression = self.objc_to_protocol_expression_for_member(declaration, member, var_name)
     lines = []
     lines.append('- (void)set%s:(%s)%s' % (ucfirst(var_name), objc_type, var_name))
     lines.append('{')
     objc_array_class = self.objc_class_for_array_type(member.type)
     if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
         lines.append('    THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
     lines.append('    [super %s:%s forKey:@"%s"];' % (setter_method, conversion_expression, member.member_name))
     lines.append('}')
     return '\n'.join(lines)
 def _generate_setter_for_member(self, domain, declaration, member):
     objc_type = self.objc_type_for_member(declaration, member)
     var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
     setter_method = ObjCGenerator.objc_setter_method_for_member(declaration, member)
     conversion_expression = self.objc_to_protocol_expression_for_member(declaration, member, var_name)
     lines = []
     lines.append('- (void)set%s:(%s)%s' % (ucfirst(var_name), objc_type, var_name))
     lines.append('{')
     objc_array_class = self.objc_class_for_array_type(member.type)
     if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
         lines.append('    THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
     lines.append('    [super %s:%s forKey:@"%s"];' % (setter_method, conversion_expression, member.member_name))
     lines.append('}')
     return '\n'.join(lines)
 def _generate_ivars(self, domains):
     lines = []
     for domain in domains:
         domain_lines = []
         if self.should_generate_commands_for_domain(domain):
             objc_class_name = '%s%sDomainHandler' % (self.objc_prefix(), domain.domain_name)
             ivar_name = '_%sHandler' % ObjCGenerator.variable_name_prefix_for_domain(domain)
             domain_lines.append('    RetainPtr<id<%s>> %s;' % (objc_class_name, ivar_name))
         if self.should_generate_events_for_domain(domain):
             objc_class_name = '%s%sDomainEventDispatcher' % (self.objc_prefix(), domain.domain_name)
             ivar_name = '_%sEventDispatcher' % ObjCGenerator.variable_name_prefix_for_domain(domain)
             domain_lines.append('    RetainPtr<%s> %s;' % (objc_class_name, ivar_name))
         if len(domain_lines):
             lines.append(self.wrap_with_guard_for_condition(domain.condition, '\n'.join(domain_lines)))
     return lines
    def _generate_success_block_for_command(self, domain, command):
        lines = []

        if command.return_parameters:
            success_block_parameters = []
            for parameter in command.return_parameters:
                objc_type = self.objc_type_for_param(domain, command.command_name, parameter)
                var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
                success_block_parameters.append(join_type_and_name(objc_type, var_name))
            lines.append('    id successCallback = ^(%s) {' % ', '.join(success_block_parameters))
        else:
            lines.append('    id successCallback = ^{')

        if command.return_parameters:
            lines.append('        Ref<JSON::Object> resultObject = JSON::Object::create();')

            required_pointer_parameters = [parameter for parameter in command.return_parameters if not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type)]
            for parameter in required_pointer_parameters:
                var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
                lines.append('        THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name))
                objc_array_class = self.objc_class_for_array_type(parameter.type)
                if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
                    lines.append('        THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))

            optional_pointer_parameters = [parameter for parameter in command.return_parameters if parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type)]
            for parameter in optional_pointer_parameters:
                var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
                lines.append('        THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name))
                objc_array_class = self.objc_class_for_array_type(parameter.type)
                if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
                    lines.append('        THROW_EXCEPTION_FOR_BAD_TYPE_IN_OPTIONAL_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))

            for parameter in command.return_parameters:
                keyed_set_method = CppGenerator.cpp_setter_method_for_type(parameter.type)
                var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
                var_expression = '*%s' % var_name if parameter.is_optional else var_name
                export_expression = self.objc_protocol_export_expression_for_variable(parameter.type, var_expression)
                if not parameter.is_optional:
                    lines.append('        resultObject->%s("%s"_s, %s);' % (keyed_set_method, parameter.parameter_name, export_expression))
                else:
                    lines.append('        if (%s)' % var_name)
                    lines.append('            resultObject->%s("%s"_s, %s);' % (keyed_set_method, parameter.parameter_name, export_expression))
            lines.append('        backendDispatcher()->sendResponse(requestId, WTFMove(resultObject), false);')
        else:
            lines.append('        backendDispatcher()->sendResponse(requestId, JSON::Object::create(), false);')

        lines.append('    };')
        return '\n'.join(lines)
    def _generate_success_block_for_command(self, domain, command):
        lines = []

        if command.return_parameters:
            success_block_parameters = []
            for parameter in command.return_parameters:
                objc_type = self.objc_type_for_param(domain, command.command_name, parameter)
                var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
                success_block_parameters.append(join_type_and_name(objc_type, var_name))
            lines.append('    id successCallback = ^(%s) {' % ', '.join(success_block_parameters))
        else:
            lines.append('    id successCallback = ^{')

        if command.return_parameters:
            lines.append('        Ref<JSON::Object> resultObject = JSON::Object::create();')

            required_pointer_parameters = filter(lambda parameter: not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), command.return_parameters)
            for parameter in required_pointer_parameters:
                var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
                lines.append('        THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name))
                objc_array_class = self.objc_class_for_array_type(parameter.type)
                if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
                    lines.append('        THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))

            optional_pointer_parameters = filter(lambda parameter: parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), command.return_parameters)
            for parameter in optional_pointer_parameters:
                var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
                lines.append('        THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name))
                objc_array_class = self.objc_class_for_array_type(parameter.type)
                if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
                    lines.append('        THROW_EXCEPTION_FOR_BAD_TYPE_IN_OPTIONAL_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))

            for parameter in command.return_parameters:
                keyed_set_method = CppGenerator.cpp_setter_method_for_type(parameter.type)
                var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
                var_expression = '*%s' % var_name if parameter.is_optional else var_name
                export_expression = self.objc_protocol_export_expression_for_variable(parameter.type, var_expression)
                if not parameter.is_optional:
                    lines.append('        resultObject->%s(ASCIILiteral("%s"), %s);' % (keyed_set_method, parameter.parameter_name, export_expression))
                else:
                    lines.append('        if (%s)' % var_name)
                    lines.append('            resultObject->%s(ASCIILiteral("%s"), %s);' % (keyed_set_method, parameter.parameter_name, export_expression))
            lines.append('        backendDispatcher()->sendResponse(requestId, WTFMove(resultObject), false);')
        else:
            lines.append('        backendDispatcher()->sendResponse(requestId, JSON::Object::create(), false);')

        lines.append('    };')
        return '\n'.join(lines)
    def generate_output(self):
        headers = set([
            '"%s.h"' % ObjCGenerator.OBJC_PREFIX,
            '"%sJSONObjectInternal.h"' % ObjCGenerator.OBJC_PREFIX,
            '<JavaScriptCore/InspectorValues.h>',
            '<JavaScriptCore/AugmentableInspectorController.h>',
        ])

        header_args = {
            'includes':
            '\n'.join(['#import ' + header for header in sorted(headers)]),
        }

        domains = self.domains_to_generate()
        event_domains = filter(
            ObjCGenerator.should_generate_domain_event_dispatcher_filter(
                self.model()), domains)

        sections = []
        sections.append(self.generate_license())
        sections.append(
            Template(ObjCTemplates.GenericHeaderPrelude).substitute(
                None, **header_args))
        sections.append('\n\n'.join(
            filter(
                None,
                map(self._generate_event_dispatcher_private_interfaces,
                    event_domains))))
        sections.append(
            Template(ObjCTemplates.GenericHeaderPostlude).substitute(
                None, **header_args))
        return '\n\n'.join(sections)
 def _generate_getter_for_member(self, domain, declaration, member):
     objc_type = ObjCGenerator.objc_type_for_member(declaration, member)
     var_name = ObjCGenerator.identifier_to_objc_identifier(
         member.member_name)
     getter_method = ObjCGenerator.objc_getter_method_for_member(
         declaration, member)
     basic_expression = '[super %s:@"%s"]' % (getter_method,
                                              member.member_name)
     conversion_expression = ObjCGenerator.protocol_to_objc_expression_for_member(
         declaration, member, basic_expression)
     lines = []
     lines.append('- (%s)%s' % (objc_type, var_name))
     lines.append('{')
     lines.append('    return %s;' % conversion_expression)
     lines.append('}')
     return '\n'.join(lines)
    def _generate_properties_for_domain(self, domain):
        property_args = {
            'objcPrefix':
            self.objc_prefix(),
            'domainName':
            domain.domain_name,
            'variableNamePrefix':
            ObjCGenerator.variable_name_prefix_for_domain(domain),
        }

        lines = []
        if self.should_generate_commands_for_domain(domain):
            lines.append(
                Template(
                    ObjCTemplates.ConfigurationCommandProperty).substitute(
                        None, **property_args))
        if self.should_generate_events_for_domain(domain):
            lines.append(
                Template(ObjCTemplates.ConfigurationEventProperty).substitute(
                    None, **property_args))
        if not len(lines):
            return []
        return [
            self.wrap_with_guard_for_condition(domain.condition,
                                               '\n'.join(lines))
        ]
Example #32
0
 def _generate_forward_declarations(self, domain):
     lines = []
     for declaration in domain.type_declarations:
         if (isinstance(declaration.type, ObjectType)):
             objc_name = ObjCGenerator.objc_name_for_type(declaration.type)
             lines.append('@class %s;' % objc_name)
     return '\n'.join(lines)
    def _generate_init_method_for_payload(self, domain, declaration):
        lines = []
        lines.append('- (instancetype)initWithPayload:(nonnull NSDictionary<NSString *, id> *)payload')
        lines.append('{')
        lines.append('    if (!(self = [super init]))')
        lines.append('        return nil;')
        lines.append('')

        for member in declaration.type_members:
            member_name = member.member_name

            if not member.is_optional:
                lines.append('    THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"%s"], @"%s");' % (member_name, member_name))

            objc_type = self.objc_type_for_member(declaration, member)
            var_name = ObjCGenerator.identifier_to_objc_identifier(member_name)
            conversion_expression = self.payload_to_objc_expression_for_member(declaration, member)
            if isinstance(member.type, EnumType):
                lines.append('    std::optional<%s> %s = %s;' % (objc_type, var_name, conversion_expression))
                if not member.is_optional:
                    lines.append('    THROW_EXCEPTION_FOR_BAD_ENUM_VALUE(%s, @"%s");' % (var_name, member_name))
                    lines.append('    self.%s = %s.value();' % (var_name, var_name))
                else:
                    lines.append('    if (%s)' % var_name)
                    lines.append('        self.%s = %s.value();' % (var_name, var_name))
            else:
                lines.append('    self.%s = %s;' % (var_name, conversion_expression))

            lines.append('')

        lines.append('    return self;')
        lines.append('}')
        return '\n'.join(lines)
 def _generate_anonymous_enum_conversion_for_parameter(self, domain, event_or_command_name, parameter):
     objc_enum_name = ObjCGenerator.objc_enum_name_for_anonymous_enum_parameter(domain, event_or_command_name, parameter)
     enum_values = parameter.type.enum_values()
     lines = []
     lines.append(self._generate_enum_objc_to_protocol_string(objc_enum_name, enum_values))
     lines.append(self._generate_enum_from_protocol_string(objc_enum_name, enum_values))
     return '\n\n'.join(lines)
 def _generate_anonymous_enum_conversion_for_member(self, domain, declaration, member):
     objc_enum_name = ObjCGenerator.objc_enum_name_for_anonymous_enum_member(declaration, member)
     enum_values = member.type.enum_values()
     lines = []
     lines.append(self._generate_enum_objc_to_protocol_string(objc_enum_name, enum_values))
     lines.append(self._generate_enum_from_protocol_string(objc_enum_name, enum_values))
     return '\n\n'.join(lines)
 def _generate_event_dispatcher_getter_for_domain(self, domain):
     getter_args = {
         "objcPrefix": ObjCGenerator.OBJC_PREFIX,
         "domainName": domain.domain_name,
         "variableNamePrefix": ObjCGenerator.variable_name_prefix_for_domain(domain),
     }
     return Template(ObjCTemplates.ConfigurationGetterImplementation).substitute(None, **getter_args)
Example #37
0
 def _generate_forward_declarations(self, domain):
     lines = []
     for declaration in domain.type_declarations:
         if (isinstance(declaration.type, ObjectType)):
             objc_name = ObjCGenerator.objc_name_for_type(declaration.type)
             lines.append('@class %s;' % objc_name)
     return '\n'.join(lines)
Example #38
0
 def _generate_anonymous_enum_for_parameter(self, domain,
                                            event_or_command_name,
                                            parameter):
     objc_enum_name = ObjCGenerator.objc_enum_name_for_anonymous_enum_parameter(
         domain, event_or_command_name, parameter)
     return self._generate_enum(objc_enum_name,
                                parameter.type.enum_values())
Example #39
0
    def _generate_init_method_for_payload(self, domain, declaration):
        lines = []
        lines.append(
            '- (instancetype)initWithPayload:(nonnull NSDictionary<NSString *, id> *)payload'
        )
        lines.append('{')
        lines.append('    if (!(self = [super init]))')
        lines.append('        return nil;')
        lines.append('')

        for member in declaration.type_members:
            var_name = ObjCGenerator.identifier_to_objc_identifier(
                member.member_name)
            if not member.is_optional:
                lines.append(
                    '    THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(payload[@"%s"], @"%s");'
                    % (var_name, var_name))
            conversion_expression = self.payload_to_objc_expression_for_member(
                declaration, member)
            lines.append('    self.%s = %s;' %
                         (var_name, conversion_expression))
            lines.append('')

        lines.append('    return self;')
        lines.append('}')
        return '\n'.join(lines)
 def _generate_handler_setter_for_domain(self, domain):
     setter_args = {
         'objcPrefix': self.objc_prefix(),
         'domainName': domain.domain_name,
         'variableNamePrefix': ObjCGenerator.variable_name_prefix_for_domain(domain),
     }
     return Template(ObjCTemplates.ConfigurationCommandPropertyImplementation).substitute(None, **setter_args)
Example #41
0
 def _generate_event_out_parameters(self, domain, event):
     lines = []
     lines.append(
         '    Ref<InspectorObject> paramsObject = InspectorObject::create();'
     )
     for parameter in event.event_parameters:
         keyed_set_method = CppGenerator.cpp_setter_method_for_type(
             parameter.type)
         var_name = parameter.parameter_name
         safe_var_name = '(*%s)' % var_name if parameter.is_optional else var_name
         export_expression = ObjCGenerator.objc_protocol_export_expression_for_variable(
             parameter.type, safe_var_name)
         if not parameter.is_optional:
             lines.append('    paramsObject->%s(ASCIILiteral("%s"), %s);' %
                          (keyed_set_method, parameter.parameter_name,
                           export_expression))
         else:
             lines.append('    if (%s)' % (parameter.parameter_name))
             lines.append(
                 '        paramsObject->%s(ASCIILiteral("%s"), %s);' %
                 (keyed_set_method, parameter.parameter_name,
                  export_expression))
     lines.append(
         '    jsonMessage->setObject(ASCIILiteral("params"), WTFMove(paramsObject));'
     )
     return lines
 def _generate_handler_setter_for_domain(self, domain):
     setter_args = {
         "objcPrefix": ObjCGenerator.OBJC_PREFIX,
         "domainName": domain.domain_name,
         "variableNamePrefix": ObjCGenerator.variable_name_prefix_for_domain(domain),
     }
     return Template(ObjCTemplates.ConfigurationCommandPropertyImplementation).substitute(None, **setter_args)
 def _generate_event_dispatcher_getter_for_domain(self, domain):
     getter_args = {
         'objcPrefix': self.objc_prefix(),
         'domainName': domain.domain_name,
         'variableNamePrefix': ObjCGenerator.variable_name_prefix_for_domain(domain),
     }
     return Template(ObjCTemplates.ConfigurationGetterImplementation).substitute(None, **getter_args)
Example #44
0
 def _generate_single_command_protocol(self, domain, command):
     pairs = []
     pairs.append('ErrorCallback:(void(^)(NSString *error))errorCallback')
     pairs.append('successCallback:(%s)successCallback' % self._callback_block_for_command(domain, command))
     for parameter in command.call_parameters:
         param_name = parameter.parameter_name
         pairs.append('%s:(%s)%s' % (param_name, ObjCGenerator.objc_type_for_param(domain, command.command_name, parameter), param_name))
     return '- (void)%sWith%s;' % (command.command_name, ' '.join(pairs))
Example #45
0
 def _generate_single_command_protocol(self, domain, command):
     pairs = []
     pairs.append('ErrorCallback:(void(^)(NSString *error))errorCallback')
     pairs.append('successCallback:(%s)successCallback' % self._callback_block_for_command(domain, command))
     for parameter in command.call_parameters:
         param_name = parameter.parameter_name
         pairs.append('%s:(%s)%s' % (param_name, ObjCGenerator.objc_type_for_param(domain, command.command_name, parameter), param_name))
     return '- (void)%sWith%s;' % (command.command_name, ' '.join(pairs))
 def _generate_event_signature(self, domain, event):
     if not event.event_parameters:
         return '- (void)%s' % event.event_name
     pairs = []
     for parameter in event.event_parameters:
         param_name = parameter.parameter_name
         pairs.append('%s:(%s)%s' % (param_name, ObjCGenerator.objc_type_for_param(domain, event.event_name, parameter), param_name))
     pairs[0] = ucfirst(pairs[0])
     return '- (void)%sWith%s' % (event.event_name, ' '.join(pairs))
 def _generate_event_signature(self, domain, event):
     if not event.event_parameters:
         return '- (void)%s' % event.event_name
     pairs = []
     for parameter in event.event_parameters:
         param_name = parameter.parameter_name
         pairs.append('%s:(%s)%s' % (param_name, ObjCGenerator.objc_type_for_param(domain, event.event_name, parameter), param_name))
     pairs[0] = ucfirst(pairs[0])
     return '- (void)%sWith%s' % (event.event_name, ' '.join(pairs))
    def generate_output(self):
        headers = [
            '"%s.h"' % ObjCGenerator.OBJC_PREFIX,
        ]

        header_args = {
            'includes': '\n'.join(['#import ' + header for header in headers]),
        }

        self._command_filter = ObjCGenerator.should_generate_domain_command_handler_filter(self.model())
        self._event_filter = ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model())

        domains = self.domains_to_generate()
        sections = []
        sections.append(self.generate_license())
        sections.append(Template(ObjCTemplates.GenericHeaderPrelude).substitute(None, **header_args))
        sections.append(self._generate_configuration_interface_for_domains(domains))
        sections.append(Template(ObjCTemplates.GenericHeaderPostlude).substitute(None, **header_args))
        return '\n\n'.join(sections)
Example #49
0
 def _callback_block_for_command(self, domain, command):
     pairs = []
     for parameter in command.return_parameters:
         pairs.append(
             join_type_and_name(
                 ObjCGenerator.objc_type_for_param(domain,
                                                   command.command_name,
                                                   parameter),
                 parameter.parameter_name))
     return 'void(^)(%s)' % ', '.join(pairs)
    def _generate_conversions_for_command(self, domain, command):
        lines = []
        if command.call_parameters:
            lines.append('')

        for parameter in command.call_parameters:
            in_param_name = 'in_%s' % parameter.parameter_name
            objc_in_param_name = 'o_%s' % in_param_name
            objc_type = ObjCGenerator.objc_type_for_param(domain, command.command_name, parameter, False)
            in_param_optional_safe_name = '*%s' % in_param_name if parameter.is_optional else in_param_name
            import_expression = ObjCGenerator.objc_protocol_import_expression_for_parameter(in_param_optional_safe_name, domain, command.command_name, parameter)
            if not parameter.is_optional:
                lines.append('    %s = %s;' % (join_type_and_name(objc_type, objc_in_param_name), import_expression))
            else:
                lines.append('    %s;' % join_type_and_name(objc_type, objc_in_param_name))
                lines.append('    if (%s)' % in_param_name)
                lines.append('        %s = %s;' % (objc_in_param_name, import_expression))

        if lines:
            lines.append('')
        return '\n'.join(lines)
    def _generate_properties_for_domain(self, domain):
        property_args = {
            'objcPrefix': ObjCGenerator.OBJC_PREFIX,
            'domainName': domain.domain_name,
            'variableNamePrefix': ObjCGenerator.variable_name_prefix_for_domain(domain),
        }

        lines = []
        if domain.commands and self._command_filter(domain):
            lines.append(Template(ObjCTemplates.ConfigurationCommandProperty).substitute(None, **property_args))
        if domain.events and self._event_filter(domain):
            lines.append(Template(ObjCTemplates.ConfigurationEventProperty).substitute(None, **property_args))
        return lines
Example #52
0
    def _generate_properties_for_domain(self, domain):
        property_args = {
            'objcPrefix': ObjCGenerator.OBJC_PREFIX,
            'domainName': domain.domain_name,
            'variableNamePrefix': ObjCGenerator.variable_name_prefix_for_domain(domain),
        }

        lines = []
        if domain.commands and self._command_filter(domain):
            lines.append(Template(ObjCTemplates.ConfigurationCommandProperty).substitute(None, **property_args))
        if domain.events and self._event_filter(domain):
            lines.append(Template(ObjCTemplates.ConfigurationEventProperty).substitute(None, **property_args))
        return lines
    def _generate_conversions_for_command(self, domain, command):
        lines = []
        if command.call_parameters:
            lines.append('')

        def in_param_expression(param_name, parameter):
            _type = parameter.type
            if isinstance(_type, AliasedType):
                _type = _type.aliased_type  # Fall through to enum or primitive.
            if isinstance(_type, EnumType):
                _type = _type.primitive_type  # Fall through to primitive.
            if isinstance(_type, PrimitiveType):
                if _type.raw_name() in ['array', 'any', 'object']:
                    return '&%s' % param_name if not parameter.is_optional else param_name
                return '*%s' % param_name if parameter.is_optional else param_name
            return '&%s' % param_name if not parameter.is_optional else param_name

        for parameter in command.call_parameters:
            in_param_name = 'in_%s' % parameter.parameter_name
            objc_in_param_name = 'o_%s' % in_param_name
            objc_type = ObjCGenerator.objc_type_for_param(
                domain, command.command_name, parameter, False)
            param_expression = in_param_expression(in_param_name, parameter)
            import_expression = ObjCGenerator.objc_protocol_import_expression_for_parameter(
                param_expression, domain, command.command_name, parameter)
            if not parameter.is_optional:
                lines.append('    %s = %s;' % (join_type_and_name(
                    objc_type, objc_in_param_name), import_expression))
            else:
                lines.append('    %s;' %
                             join_type_and_name(objc_type, objc_in_param_name))
                lines.append('    if (%s)' % in_param_name)
                lines.append('        %s = %s;' %
                             (objc_in_param_name, import_expression))

        if lines:
            lines.append('')
        return '\n'.join(lines)
Example #54
0
 def _generate_type_interface(self, domain, declaration):
     lines = []
     objc_name = ObjCGenerator.objc_name_for_type(declaration.type)
     lines.append('@interface %s : %s' % (objc_name, ObjCGenerator.OBJC_JSON_OBJECT_BASE))
     required_members = filter(lambda member: not member.is_optional, declaration.type_members)
     optional_members = filter(lambda member: member.is_optional, declaration.type_members)
     if required_members:
         lines.append(self._generate_init_method_for_required_members(domain, declaration, required_members))
     for member in required_members:
         lines.append('/* required */ ' + self._generate_member_property(declaration, member))
     for member in optional_members:
         lines.append('/* optional */ ' + self._generate_member_property(declaration, member))
     lines.append('@end')
     return '\n'.join(lines)
    def _generate_properties_for_domain(self, domain):
        property_args = {
            'objcPrefix': self.objc_prefix(),
            'domainName': domain.domain_name,
            'variableNamePrefix': ObjCGenerator.variable_name_prefix_for_domain(domain),
        }

        lines = []

        if self.should_generate_commands_for_domain(domain):
            lines.append(Template(ObjCTemplates.ConfigurationCommandProperty).substitute(None, **property_args))
        if self.should_generate_events_for_domain(domain):
            lines.append(Template(ObjCTemplates.ConfigurationEventProperty).substitute(None, **property_args))
        return lines