diff options
author | Aleksandr Mishchenko <AMishchenko@luxoft.com> | 2020-03-02 00:37:16 +0100 |
---|---|---|
committer | Aleksandr Mishchenko <AMishchenko@luxoft.com> | 2020-03-02 00:37:16 +0100 |
commit | b2831fb0732b283e19b17eb6117dd74e0921a4df (patch) | |
tree | 7ea7bb41132d81db72ec47c9eea37be7c611373e | |
parent | 6276035234e13b585372bc52b79362649f02b014 (diff) | |
download | sdl_ios-b2831fb0732b283e19b17eb6117dd74e0921a4df.tar.gz |
changing according to review comments
-rw-r--r-- | generator/generator.py | 1 | ||||
-rw-r--r-- | generator/templates/base_struct_function.h | 50 | ||||
-rw-r--r-- | generator/templates/description.jinja | 23 | ||||
-rw-r--r-- | generator/templates/description_param.jinja | 20 | ||||
-rw-r--r-- | generator/templates/enums/template.h | 41 | ||||
-rw-r--r-- | generator/templates/enums/template_numeric.h | 11 | ||||
-rw-r--r-- | generator/transformers/common_producer.py | 4 | ||||
-rw-r--r-- | generator/transformers/enums_producer.py | 2 |
8 files changed, 66 insertions, 86 deletions
diff --git a/generator/generator.py b/generator/generator.py index 9200652f0..d9c91ac61 100644 --- a/generator/generator.py +++ b/generator/generator.py @@ -373,6 +373,7 @@ class Generator: return if overwrite: self.logger.info('Overriding %s', file_with_suffix.name) + file_with_suffix.unlink() self.write_file(file_with_suffix, templates, data) else: while True: diff --git a/generator/templates/base_struct_function.h b/generator/templates/base_struct_function.h index c8a99cfd1..c4ee1d142 100644 --- a/generator/templates/base_struct_function.h +++ b/generator/templates/base_struct_function.h @@ -10,30 +10,9 @@ @class {{import}}; {%- endfor %} {%- endblock %} -{%- if deprecated and deprecated is sameas true -%} -{%- set ending = ' __deprecated' -%} -{%- elif deprecated and deprecated is string -%} -{%- set ending = ' __deprecated_msg("{}")'.format(deprecated) -%} -{%- endif %} NS_ASSUME_NONNULL_BEGIN -{% if description or since %} -/** - {%- if description %} - {%- for d in description %} - * {{d}} - {%- endfor %}{% endif -%} - {%- if description and since %} - * - {%- endif %} - {%- if deprecated %} - * @deprecated - {%- endif %} - {%- if since %} - * @since SDL {{since}} - {%- endif %} - */ -{%- endif %} +{% include 'description.jinja' %} @interface {{name}} : {{extends_class}}{{ending}} {%- block constructors %} {% for c in constructors %} @@ -61,31 +40,8 @@ NS_ASSUME_NONNULL_BEGIN {%- endblock -%} {%- block methods %} {%- for param in params %} -/** - {%- if param.description %} - {%- for d in param.description %} - * {{d}} - {%- endfor %}{% endif -%} - {%- if param.description and param.since %} - * - {%- endif %} - {%- if param.deprecated %} - * @deprecated - {%- endif %} - {%- if param.since %} - * @since SDL {{param.since}} - {%- endif %} - {%- if param.description or param.since %} - * - {%- endif %} - * {{'Required, ' if param.mandatory else 'Optional, '}}{{param.type_native}} - */ -{%- if param.deprecated and param.deprecated is sameas true -%} -{%- set ending = ' __deprecated' -%} -{%- elif param.deprecated and param.deprecated is string -%} -{%- set ending = ' __deprecated_msg("{}")'.format(param.deprecated) -%} -{%- endif %} -@property ({{'nullable, ' if not param.mandatory}}{{param.modifier}}, nonatomic) {{param.type_sdl}}{{param.origin}}{{ending}}; +{%- include 'description_param.jinja' %} +@property ({{'nullable, ' if not param.mandatory}}{{param.modifier}}, nonatomic) {{param.type_sdl}}{{param.origin}}{{' __deprecated' if param.deprecated and param.deprecated is sameas true }}; {% endfor -%} {%- endblock %} @end diff --git a/generator/templates/description.jinja b/generator/templates/description.jinja new file mode 100644 index 000000000..4eff1614e --- /dev/null +++ b/generator/templates/description.jinja @@ -0,0 +1,23 @@ +{% if description or since or history %} +/** + {%- if description %} + {%- for d in description %} + * {{d}} + {%- endfor %}{% endif -%} + {%- if description and ( since or history ) %} + * + {%- endif %} + {%- if deprecated %} + * @deprecated + {%- endif %} + {%- if history %} + * @history SDL {{ history }} + {%- endif %} + {%- if since %} + * @since SDL {{ since }} + {%- endif %} + */ +{%- endif -%} +{%- if deprecated and deprecated is sameas true %} +__deprecated +{%- endif -%} diff --git a/generator/templates/description_param.jinja b/generator/templates/description_param.jinja new file mode 100644 index 000000000..c2926a1f1 --- /dev/null +++ b/generator/templates/description_param.jinja @@ -0,0 +1,20 @@ +{% if param.description or param.since or param.history %} +/** + {%- if param.description %} + {%- for d in param.description %} + * {{d}} + {%- endfor %}{% endif -%} + {%- if param.description and ( param.since or param.history ) %} + * + {%- endif %} + {%- if param.deprecated %} + * @deprecated + {%- endif %} + {%- if param.history %} + * @history SDL {{ param.history }} + {%- endif %} + {%- if param.since %} + * @since SDL {{ param.since }} + {%- endif %} + */ +{%- endif %} diff --git a/generator/templates/enums/template.h b/generator/templates/enums/template.h index f3ee55c9d..7c7ec3eeb 100644 --- a/generator/templates/enums/template.h +++ b/generator/templates/enums/template.h @@ -5,48 +5,11 @@ #import "{{import}}.h" {%- endfor %} {%- endblock -%} -{%- if deprecated and deprecated is sameas true -%} -{%- set ending = ' __deprecated' -%} -{%- elif deprecated and deprecated is string -%} -{%- set ending = ' __deprecated_msg("{}")'.format(deprecated) -%} -{%- endif %} {%- block body %} -{% if description or since %} -/** - {%- if description %} - {%- for d in description %} - * {{d}} - {%- endfor %}{% endif -%} - {%- if description and since %} - * - {%- endif %} - {%- if deprecated %} - * @deprecated - {%- endif %} - {%- if since %} - * @since SDL {{since}} - {%- endif %} - */ -{%- endif %} +{% include 'description.jinja' %} typedef SDLEnum {{ name }} SDL_SWIFT_ENUM{{ending}}; {% for param in params %} -{%- if param.description or param.since %} -/** - {%- if param.description %} - {%- for d in param.description %} - * {{d}} - {%- endfor %}{% endif -%} - {%- if param.description and param.since %} - * - {%- endif %} - {%- if param.deprecated %} - * @deprecated - {%- endif %} - {%- if param.since %} - * @since SDL {{param.since}} - {%- endif %} - */ -{%- endif %} +{% include 'description_param.jinja' %} extern {{ name }} const {{ name }}{{param.name}}{{ ' %s%s%s'|format('NS_SWIFT_NAME(', param.name|lower, ')') if NS_SWIFT_NAME is defined}}; {% endfor -%} {% endblock -%}
\ No newline at end of file diff --git a/generator/templates/enums/template_numeric.h b/generator/templates/enums/template_numeric.h new file mode 100644 index 000000000..bfa24aa32 --- /dev/null +++ b/generator/templates/enums/template_numeric.h @@ -0,0 +1,11 @@ +{% extends "template.h" %} +{%- block body %} +{% include 'description.jinja' %} +typedef NS_ENUM(NSUInteger, SDL{{ name }}){ +{% for param in params %} +{%- macro someop() -%}{% include 'description_param.jinja' %}{%- endmacro -%} +{{ someop()|indent(4, True) }} + SDL{{ name }}{{ param.name }} = {{ param.value }}{{ ' %s%s%s'|format('NS_SWIFT_NAME(', param.name|lower, ')') if NS_SWIFT_NAME is defined}}; +{% endfor -%} +}; +{% endblock -%}
\ No newline at end of file diff --git a/generator/transformers/common_producer.py b/generator/transformers/common_producer.py index 8fd48ec49..c056d14f8 100644 --- a/generator/transformers/common_producer.py +++ b/generator/transformers/common_producer.py @@ -56,12 +56,16 @@ class InterfaceProducerCommon(ABC): render['description'] = self.extract_description(item.description) if item.since: render['since'] = item.since + if item.history: + render['history'] = item.history.pop().since if item.deprecated and item.deprecated.lower() == 'true': render['deprecated'] = True render['params'] = OrderedDict() for param in getattr(item, self.container_name).values(): + if param.name.lower() in ['id']: + param.name = self.minimize_first(item.name) + self.title(param.name) render['params'][param.name] = self.extract_param(param) if isinstance(item, (Struct, Function)): self.extract_imports(param, render['imports']) diff --git a/generator/transformers/enums_producer.py b/generator/transformers/enums_producer.py index 92b72b283..dd072544a 100644 --- a/generator/transformers/enums_producer.py +++ b/generator/transformers/enums_producer.py @@ -38,6 +38,8 @@ class EnumsProducer(InterfaceProducerCommon): render['name'] = name render['imports'] = imports super(EnumsProducer, self).transform(item, render) + if any(map(lambda p: p.value, render['params'])): + render['template'] = 'enums/template_numeric' return render def extract_param(self, param: EnumElement): |