Skip to content

Commit 5773a73

Browse files
committed
Swift: slightly simplify a cppgen change
1 parent 93d06da commit 5773a73

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

swift/codegen/generators/cppgen.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import functools
1515
import pathlib
16-
import typing
1716
from typing import Dict
1817

1918
import inflection
@@ -35,25 +34,22 @@ def _get_type(t: str) -> str:
3534
return t
3635

3736

38-
def _get_fields(cls: schema.Class) -> typing.Iterable[cpp.Field]:
39-
for p in cls.properties:
40-
if "cpp_skip" in p.pragmas:
41-
continue
42-
trap_name = None
43-
if not p.is_single:
44-
trap_name = inflection.camelize(f"{cls.name}_{p.name}")
45-
if not p.is_predicate:
46-
trap_name = inflection.pluralize(trap_name)
47-
args = dict(
48-
field_name=p.name + ("_" if p.name in cpp.cpp_keywords else ""),
49-
type=_get_type(p.type),
50-
is_optional=p.is_optional,
51-
is_repeated=p.is_repeated,
52-
is_predicate=p.is_predicate,
53-
trap_name=trap_name,
54-
)
55-
args.update(cpp.get_field_override(p.name))
56-
yield cpp.Field(**args)
37+
def _get_field(cls: schema.Class, p: schema.Property) -> cpp.Field:
38+
trap_name = None
39+
if not p.is_single:
40+
trap_name = inflection.camelize(f"{cls.name}_{p.name}")
41+
if not p.is_predicate:
42+
trap_name = inflection.pluralize(trap_name)
43+
args = dict(
44+
field_name=p.name + ("_" if p.name in cpp.cpp_keywords else ""),
45+
type=_get_type(p.type),
46+
is_optional=p.is_optional,
47+
is_repeated=p.is_repeated,
48+
is_predicate=p.is_predicate,
49+
trap_name=trap_name,
50+
)
51+
args.update(cpp.get_field_override(p.name))
52+
return cpp.Field(**args)
5753

5854

5955
class Processor:
@@ -69,7 +65,7 @@ def _get_class(self, name: str) -> cpp.Class:
6965
return cpp.Class(
7066
name=name,
7167
bases=[self._get_class(b) for b in cls.bases],
72-
fields=list(_get_fields(cls)),
68+
fields=[_get_field(cls, p) for p in cls.properties if "cpp_skip" not in p.pragmas],
7369
final=not cls.derived,
7470
trap_name=trap_name,
7571
)

0 commit comments

Comments
 (0)