13
13
14
14
import functools
15
15
import pathlib
16
- import typing
17
16
from typing import Dict
18
17
19
18
import inflection
@@ -35,25 +34,22 @@ def _get_type(t: str) -> str:
35
34
return t
36
35
37
36
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 )
57
53
58
54
59
55
class Processor :
@@ -69,7 +65,7 @@ def _get_class(self, name: str) -> cpp.Class:
69
65
return cpp .Class (
70
66
name = name ,
71
67
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 ] ,
73
69
final = not cls .derived ,
74
70
trap_name = trap_name ,
75
71
)
0 commit comments