Lines Matching refs:self

88         def __enter__(self):  argument
89 self.dir = tempfile.mkdtemp()
90 return self.dir
92 def __exit__(self, *args): argument
93 shutil.rmtree(self.dir)
164 def __init__(self, parts = ()): argument
169 self.parts = tuple(parts)
171 def __str__(self): argument
172 return '_'.join(self.parts)
174 def __add__(self, other): argument
176 return Names(self.parts + (other,))
178 return Names(self.parts + other.parts)
180 return Names(self.parts + other)
184 def __eq__(self, other): argument
185 return isinstance(other, Names) and self.parts == other.parts
187 def __lt__(self, other): argument
190 return str(self) < str(other)
215 def __init__(self, value = 0, symbols = [], declarations = [], required_defines = []): argument
217 self.value = value.value
218 self.symbols = value.symbols
219 self.declarations = value.declarations
220 self.required_defines = value.required_defines
222 self.symbols = [str(value)]
223 self.value = 0
224 self.declarations = []
225 self.required_defines = [str(value)]
227 self.value = value
228 self.symbols = symbols
229 self.declarations = declarations
230 self.required_defines = required_defines
232 def __add__(self, other): argument
234 … return EncodedSize(self.value + other, self.symbols, self.declarations, self.required_defines)
236 …return EncodedSize(self.value, self.symbols + [str(other)], self.declarations, self.required_defin…
238 return EncodedSize(self.value + other.value, self.symbols + other.symbols,
239self.declarations + other.declarations, self.required_defines + other.required_defines)
243 def __mul__(self, other): argument
245 return EncodedSize(self.value * other, [str(other) + '*' + s for s in self.symbols],
246 self.declarations, self.required_defines)
250 def __str__(self): argument
251 if not self.symbols:
252 return str(self.value)
254 return '(' + str(self.value) + ' + ' + ' + '.join(self.symbols) + ')'
256 def get_declarations(self): argument
259 return '\n'.join(self.declarations)
261 def get_cpp_guard(self, local_defines): argument
263 needed = [x for x in self.required_defines if x not in local_defines]
269 def upperlimit(self): argument
270 if not self.symbols:
271 return self.value
288 def __init__(self, path, index, comments): argument
297 self.path = path
298 self.index = index
299 self.comments = comments
301 def element_path(self): argument
303 return [self.path, self.index]
305 def member_path(self, member_index): argument
313 return self.element_path() + [FIELD_PATH, member_index]
315 def get_comments(self, path, leading_indent=True): argument
324 comment = self.comments.get(str(path))
343 def __init__(self, names, desc, enum_options, index, comments): argument
350 super(Enum, self).__init__(ENUM_PATH, index, comments)
352 self.options = enum_options
353 self.names = names
359 self.values = [(names + x.name, x.number) for x in desc.value]
361 self.values = [(base_name + x.name, x.number) for x in desc.value]
363 self.value_longnames = [self.names + x.name for x in desc.value]
364 self.packed = enum_options.packed_enum
366 def has_negative(self): argument
367 for n, v in self.values:
372 def encoded_size(self): argument
373 return max([varint_max_size(v) for n,v in self.values])
375 def __str__(self): argument
376 enum_path = self.element_path()
377 leading_comment, trailing_comment = self.get_comments(enum_path, leading_indent=False)
383 result += 'typedef enum _%s { %s\n' % (self.names, trailing_comment)
385 enum_length = len(self.values)
387 for index, (name, value) in enumerate(self.values):
388 member_path = self.member_path(index)
389 leading_comment, trailing_comment = self.get_comments(member_path)
404 if self.packed:
407 result += ' %s;' % self.names
410 def auxiliary_defines(self): argument
412 sorted_values = sorted(self.values, key = lambda x: (x[1], x[0]))
413 result = '#define _%s_MIN %s\n' % (self.names, sorted_values[0][0])
414 result += '#define _%s_MAX %s\n' % (self.names, sorted_values[-1][0])
415 … result += '#define _%s_ARRAYSIZE ((%s)(%s+1))\n' % (self.names, self.names, sorted_values[-1][0])
417 if not self.options.long_names:
420 for i, x in enumerate(self.values):
421 result += '#define %s %s\n' % (self.value_longnames[i], x[0])
423 if self.options.enum_to_string:
424 result += 'const char *%s_name(%s v);\n' % (self.names, self.names)
428 def enum_to_string_definition(self): argument
429 if not self.options.enum_to_string:
432 result = 'const char *%s_name(%s v) {\n' % (self.names, self.names)
435 for ((enumname, _), strname) in zip(self.values, self.value_longnames):
437 strval = str(strname)[len(str(self.names)) + 1:]
447 def __init__(self, worst = 0, checks = [], field_name = 'undefined'): argument
449 self.worst = max(i for i in worst if i is not None)
451 self.worst = worst
453 self.worst_field = field_name
454 self.checks = list(checks)
456 def extend(self, extend, field_name = None): argument
457 self.worst = max(self.worst, extend.worst)
459 if self.worst == extend.worst:
460 self.worst_field = extend.worst_field
462 self.checks.extend(extend.checks)
468 def __init__(self, struct_name, desc, field_options): argument
470 self.tag = desc.number
471 self.struct_name = struct_name
472 self.union_name = None
473 self.name = desc.name
474 self.default = None
475 self.max_size = None
476 self.max_count = None
477 self.array_decl = ""
478 self.enc_size = None
479 self.data_item_size = None
480 self.ctype = None
481 self.fixed_count = False
482 self.callback_datatype = field_options.callback_datatype
483 self.math_include_required = False
484 self.sort_by_tag = field_options.sort_by_tag
495 self.max_size = field_options.max_size
497 self.default_has = field_options.default_has
501 self.max_size = field_options.max_length + 1
504 self.max_count = field_options.max_count
507 self.default = desc.default_value
512 self.rules = 'REPEATED'
513 if self.max_count is None:
516 self.array_decl = '[%d]' % self.max_count
518 self.rules = 'FIXARRAY'
524 self.rules = 'OPTIONAL'
527 self.rules = 'OPTIONAL'
530 self.rules = 'SINGULAR'
532 self.rules = 'REQUIRED'
534 self.rules = 'OPTIONAL'
540 if desc.type == FieldD.TYPE_STRING and self.max_size is None:
543 if desc.type == FieldD.TYPE_BYTES and self.max_size is None:
555 "max_count is not given." % self.name)
557 if field_options.fixed_count and self.max_count is None:
559 "but max_count is not given." % self.name)
562 self.allocation = 'STATIC'
564 self.allocation = 'POINTER'
566 self.allocation = 'CALLBACK'
575 self.ctype, self.pbtype, self.enc_size, self.data_item_size = datatypes[desc.type]
579self.ctype, self.pbtype, self.enc_size, self.data_item_size = datatypes[(desc.type, field_options.…
581 self.pbtype = 'ENUM'
582 self.data_item_size = 4
583 self.ctype = names_from_type_name(desc.type_name)
584 if self.default is not None:
585 self.default = self.ctype + self.default
586 self.enc_size = None # Needs to be filled in when enum values are known
588 self.pbtype = 'STRING'
589 self.ctype = 'char'
590 if self.allocation == 'STATIC':
591 self.ctype = 'char'
592 self.array_decl += '[%d]' % self.max_size
595 self.enc_size = varint_max_size(self.max_size) + self.max_size - 1
598 self.pbtype = 'FIXED_LENGTH_BYTES'
600 if self.max_size is None:
602 "but max_size is not given." % self.name)
604 self.enc_size = varint_max_size(self.max_size) + self.max_size
605 self.ctype = 'pb_byte_t'
606 self.array_decl += '[%d]' % self.max_size
608 self.pbtype = 'BYTES'
609 self.ctype = 'pb_bytes_array_t'
610 if self.allocation == 'STATIC':
611 self.ctype = self.struct_name + self.name + 't'
612 self.enc_size = varint_max_size(self.max_size) + self.max_size
614 self.pbtype = 'MESSAGE'
615 self.ctype = self.submsgname = names_from_type_name(desc.type_name)
616 self.enc_size = None # Needs to be filled in after the message type is available
617 if field_options.submsg_callback and self.allocation == 'STATIC':
618 self.pbtype = 'MSG_W_CB'
622 if self.default and self.pbtype in ['FLOAT', 'DOUBLE']:
623 if 'inf' in self.default or 'nan' in self.default:
624 self.math_include_required = True
626 def __lt__(self, other): argument
627 return self.tag < other.tag
629 def __str__(self): argument
631 if self.allocation == 'POINTER':
632 if self.rules == 'REPEATED':
633 if self.pbtype == 'MSG_W_CB':
634 result += ' pb_callback_t cb_' + self.name + ';\n'
635 result += ' pb_size_t ' + self.name + '_count;\n'
637 if self.pbtype in ['MESSAGE', 'MSG_W_CB']:
639 result += ' struct _%s *%s;' % (self.ctype, self.name)
640 elif self.pbtype == 'FIXED_LENGTH_BYTES' or self.rules == 'FIXARRAY':
642 result += ' %s (*%s)%s;' % (self.ctype, self.name, self.array_decl)
643 elif self.rules in ['REPEATED', 'FIXARRAY'] and self.pbtype in ['STRING', 'BYTES']:
645 result += ' %s **%s;' % (self.ctype, self.name)
647 result += ' %s *%s;' % (self.ctype, self.name)
648 elif self.allocation == 'CALLBACK':
649 result += ' %s %s;' % (self.callback_datatype, self.name)
651 if self.pbtype == 'MSG_W_CB' and self.rules in ['OPTIONAL', 'REPEATED']:
652 result += ' pb_callback_t cb_' + self.name + ';\n'
654 if self.rules == 'OPTIONAL':
655 result += ' bool has_' + self.name + ';\n'
656 elif self.rules == 'REPEATED':
657 result += ' pb_size_t ' + self.name + '_count;\n'
658 result += ' %s %s%s;' % (self.ctype, self.name, self.array_decl)
661 def types(self): argument
663 if self.pbtype == 'BYTES' and self.allocation == 'STATIC':
664 result = 'typedef PB_BYTES_ARRAY_T(%d) %s;\n' % (self.max_size, self.ctype)
669 def get_dependencies(self): argument
671 if self.allocation == 'STATIC':
672 return [str(self.ctype)]
676 def get_initializer(self, null_init, inner_init_only = False): argument
683 if self.pbtype in ['MESSAGE', 'MSG_W_CB']:
685 inner_init = '%s_init_zero' % self.ctype
687 inner_init = '%s_init_default' % self.ctype
688 elif self.default is None or null_init:
689 if self.pbtype == 'STRING':
691 elif self.pbtype == 'BYTES':
693 elif self.pbtype == 'FIXED_LENGTH_BYTES':
695 elif self.pbtype in ('ENUM', 'UENUM'):
696 inner_init = '_%s_MIN' % self.ctype
700 if self.pbtype == 'STRING':
701 data = codecs.escape_encode(self.default.encode('utf-8'))[0]
703 elif self.pbtype == 'BYTES':
704 data = codecs.escape_decode(self.default)[0]
710 elif self.pbtype == 'FIXED_LENGTH_BYTES':
711 data = codecs.escape_decode(self.default)[0]
717 elif self.pbtype in ['FIXED32', 'UINT32']:
718 inner_init = str(self.default) + 'u'
719 elif self.pbtype in ['FIXED64', 'UINT64']:
720 inner_init = str(self.default) + 'ull'
721 elif self.pbtype in ['SFIXED64', 'INT64']:
722 inner_init = str(self.default) + 'll'
723 elif self.pbtype in ['FLOAT', 'DOUBLE']:
724 inner_init = str(self.default)
729 elif (not '.' in inner_init) and self.pbtype == 'FLOAT':
731 elif self.pbtype == 'FLOAT':
734 inner_init = str(self.default)
740 if self.allocation == 'STATIC':
741 if self.rules == 'REPEATED':
742 outer_init = '0, {' + ', '.join([inner_init] * self.max_count) + '}'
743 elif self.rules == 'FIXARRAY':
744 outer_init = '{' + ', '.join([inner_init] * self.max_count) + '}'
745 elif self.rules == 'OPTIONAL':
746 if null_init or not self.default_has:
752 elif self.allocation == 'POINTER':
753 if self.rules == 'REPEATED':
757 elif self.allocation == 'CALLBACK':
758 if self.pbtype == 'EXTENSION':
763 if self.pbtype == 'MSG_W_CB' and self.rules in ['REPEATED', 'OPTIONAL']:
768 def tags(self): argument
770 identifier = '%s_%s_tag' % (self.struct_name, self.name)
771 return '#define %-40s %d\n' % (identifier, self.tag)
773 def fieldlist(self): argument
777 name = self.name
779 if self.rules == "ONEOF":
782 if not self.anonymous:
783 name = '(%s,%s,%s)' % (self.union_name, self.name, self.union_name + '.' + self.name)
785 name = '(%s,%s,%s)' % (self.union_name, self.name, self.name)
787 return '%s(%s, %-9s %-9s %-9s %-16s %3d)' % (self.macro_x_param,
788 self.macro_a_param,
789 self.allocation + ',',
790 self.rules + ',',
791 self.pbtype + ',',
793 self.tag)
795 def data_size(self, dependencies): argument
801 if self.allocation == 'POINTER' or self.pbtype == 'EXTENSION':
804 elif self.allocation == 'CALLBACK':
807 elif self.pbtype in ['MESSAGE', 'MSG_W_CB']:
809 if str(self.submsgname) in dependencies:
810 … other_dependencies = dict(x for x in dependencies.items() if x[0] != str(self.struct_name))
811 size = dependencies[str(self.submsgname)].data_size(other_dependencies)
815 if self.pbtype == 'MSG_W_CB':
817 elif self.pbtype in ['STRING', 'FIXED_LENGTH_BYTES']:
818 size = self.max_size
820 elif self.pbtype == 'BYTES':
821 size = self.max_size + 4
823 elif self.data_item_size is not None:
824 size = self.data_item_size
826 if self.data_item_size >= 8:
829 raise Exception("Unhandled field type: %s" % self.pbtype)
831 if self.rules in ['REPEATED', 'FIXARRAY'] and self.allocation == 'STATIC':
832 size *= self.max_count
834 if self.rules not in ('REQUIRED', 'SINGULAR'):
843 def encoded_size(self, dependencies): argument
848 if self.allocation != 'STATIC':
851 if self.pbtype in ['MESSAGE', 'MSG_W_CB']:
853 if str(self.submsgname) in dependencies:
854 submsg = dependencies[str(self.submsgname)]
855 … other_dependencies = dict(x for x in dependencies.items() if x[0] != str(self.struct_name))
858 my_msg = dependencies.get(str(self.struct_name))
882 encsize = EncodedSize(self.submsgname + 'size')
888 elif self.pbtype in ['ENUM', 'UENUM']:
889 if str(self.ctype) in dependencies:
890 enumtype = dependencies[str(self.ctype)]
896 elif self.enc_size is None:
898 % (self.struct_name, self.name))
900 encsize = EncodedSize(self.enc_size)
902 encsize += varint_max_size(self.tag << 3) # Tag + wire type
904 if self.rules in ['REPEATED', 'FIXARRAY']:
910 encsize *= self.max_count
912 if self.max_count == 1:
917 def has_callbacks(self): argument
918 return self.allocation == 'CALLBACK'
920 def requires_custom_field_callback(self): argument
921 return self.allocation == 'CALLBACK' and self.callback_datatype != 'pb_callback_t'
924 def __init__(self, struct_name, range_start, field_options): argument
930 self.tag = range_start
931 self.struct_name = struct_name
932 self.name = 'extensions'
933 self.pbtype = 'EXTENSION'
934 self.rules = 'OPTIONAL'
935 self.allocation = 'CALLBACK'
936 self.ctype = 'pb_extension_t'
937 self.array_decl = ''
938 self.default = None
939 self.max_size = 0
940 self.max_count = 0
941 self.data_item_size = 0
942 self.fixed_count = False
943 self.callback_datatype = 'pb_extension_t*'
945 def requires_custom_field_callback(self): argument
948 def __str__(self): argument
951 def types(self): argument
954 def tags(self): argument
957 def encoded_size(self, dependencies): argument
964 def __init__(self, fullname, desc, field_options): argument
965 self.fullname = fullname
966 self.extendee_name = names_from_type_name(desc.extendee)
967 Field.__init__(self, self.fullname + "extmsg", desc, field_options)
969 if self.rules != 'OPTIONAL':
970 self.skip = True
972 self.skip = False
973 self.rules = 'REQUIRED' # We don't really want the has_field for extensions
975 self.msg = Message(self.fullname + "extmsg", None, field_options, 0, {})
976 self.msg.fields.append(self)
978 def tags(self): argument
980 identifier = '%s_tag' % self.fullname
981 return '#define %-40s %d\n' % (identifier, self.tag)
983 def extension_decl(self): argument
985 if self.skip:
986 msg = '/* Extension field %s was skipped because only "optional"\n' % self.fullname
991 (self.fullname, str(self).strip()))
993 def extension_def(self, dependencies): argument
996 if self.skip:
999 result = "/* Definition for extension field %s */\n" % self.fullname
1000 result += str(self.msg)
1001 result += self.msg.fields_declaration(dependencies)
1002 result += 'pb_byte_t %s_default[] = {0x00};\n' % self.msg.name
1003 result += self.msg.fields_definition(dependencies)
1004 result += 'const pb_extension_type_t %s = {\n' % self.fullname
1007 result += ' &%s_msg\n' % self.msg.name
1017 def __init__(self, struct_name, oneof_desc, oneof_options): argument
1018 self.struct_name = struct_name
1019 self.name = oneof_desc.name
1020 self.ctype = 'union'
1021 self.pbtype = 'oneof'
1022 self.fields = []
1023 self.allocation = 'ONEOF'
1024 self.default = None
1025 self.rules = 'ONEOF'
1026 self.anonymous = oneof_options.anonymous_oneof
1027 self.sort_by_tag = oneof_options.sort_by_tag
1028 self.has_msg_cb = False
1030 def add_field(self, field): argument
1031 field.union_name = self.name
1033 field.anonymous = self.anonymous
1034 self.fields.append(field)
1036 if self.sort_by_tag:
1037 self.fields.sort()
1040 self.has_msg_cb = True
1043 self.tag = min([f.tag for f in self.fields])
1045 def __str__(self): argument
1047 if self.fields:
1048 if self.has_msg_cb:
1049 result += ' pb_callback_t cb_' + self.name + ';\n'
1051 result += ' pb_size_t which_' + self.name + ";\n"
1053 for f in self.fields:
1055 if self.anonymous:
1058 result += ' } ' + self.name + ';'
1061 def types(self): argument
1062 return ''.join([f.types() for f in self.fields])
1064 def get_dependencies(self): argument
1066 for f in self.fields:
1070 def get_initializer(self, null_init): argument
1071 if self.has_msg_cb:
1072 return '{{NULL}, NULL}, 0, {' + self.fields[0].get_initializer(null_init) + '}'
1074 return '0, {' + self.fields[0].get_initializer(null_init) + '}'
1076 def tags(self): argument
1077 return ''.join([f.tags() for f in self.fields])
1079 def data_size(self, dependencies): argument
1080 return max(f.data_size(dependencies) for f in self.fields)
1082 def encoded_size(self, dependencies): argument
1086 for f in self.fields:
1111 union_name = "%s_%s_size_union" % (self.struct_name, self.name)
1116 def has_callbacks(self): argument
1117 return bool([f for f in self.fields if f.has_callbacks()])
1119 def requires_custom_field_callback(self): argument
1120 return bool([f for f in self.fields if f.requires_custom_field_callback()])
1128 def __init__(self, names, desc, message_options, index, comments): argument
1129 super(Message, self).__init__(MESSAGE_PATH, index, comments)
1130 self.name = names
1131 self.fields = []
1132 self.oneofs = {}
1133 self.desc = desc
1134 self.math_include_required = False
1135 self.packed = message_options.packed_struct
1136 self.descriptorsize = message_options.descriptorsize
1139 self.msgid = message_options.msgid
1142 self.load_fields(desc, message_options)
1144 self.callback_function = message_options.callback_function
1148 for field in self.fields:
1150 self.callback_function = "%s_callback" % self.name
1153 def load_fields(self, desc, message_options): argument
1160 oneof_options = get_nanopb_suboptions(desc, message_options, self.name + f.name)
1166 oneof = OneOf(self.name, f, oneof_options)
1167 self.oneofs[i] = oneof
1172 field_options = get_nanopb_suboptions(f, message_options, self.name + f.name)
1176 if field_options.descriptorsize > self.descriptorsize:
1177 self.descriptorsize = field_options.descriptorsize
1179 field = Field(self.name, f, field_options)
1185 self.fields.append(field)
1186 elif f.oneof_index in self.oneofs:
1187 self.oneofs[f.oneof_index].add_field(field)
1189 if self.oneofs[f.oneof_index] not in self.fields:
1190 self.fields.append(self.oneofs[f.oneof_index])
1192 self.fields.append(field)
1195 self.math_include_required = True
1198 field_options = get_nanopb_suboptions(desc, message_options, self.name + 'extensions')
1201 self.fields.append(ExtensionRange(self.name, range_start, field_options))
1204 self.fields.sort()
1206 def get_dependencies(self): argument
1209 for f in self.fields:
1213 def __str__(self): argument
1214 message_path = self.element_path()
1215 leading_comment, trailing_comment = self.get_comments(message_path, leading_indent=False)
1221 result += 'typedef struct _%s { %s\n' % (self.name, trailing_comment)
1223 if not self.fields:
1229 for index, field in enumerate(self.fields):
1230 member_path = self.member_path(index)
1231 leading_comment, trailing_comment = self.get_comments(member_path)
1241 result += '\n/* @@protoc_insertion_point(struct:%s) */' % self.name
1245 if self.packed:
1248 result += ' %s;' % self.name
1250 if self.packed:
1256 def types(self): argument
1257 return ''.join([f.types() for f in self.fields])
1259 def get_initializer(self, null_init): argument
1260 if not self.fields:
1264 for field in self.fields:
1268 def count_required_fields(self): argument
1271 for f in self.fields:
1277 def all_fields(self): argument
1279 for f in self.fields:
1287 def field_for_tag(self, tag): argument
1289 for field in self.all_fields():
1294 def count_all_fields(self): argument
1297 for f in self.fields:
1304 def fields_declaration(self, dependencies): argument
1308 while any(field.name == Field.macro_x_param for field in self.all_fields()):
1310 while any(field.name == Field.macro_a_param for field in self.all_fields()):
1314 sorted_fields = list(self.all_fields())
1317 result = '#define %s_FIELDLIST(%s, %s) \\\n' % (self.name,
1323 has_callbacks = bool([f for f in self.fields if f.has_callbacks()])
1325 if self.callback_function != 'pb_default_field_callback':
1326 …pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_t *field);\n" % self.callback_function
1327 result += "#define %s_CALLBACK %s\n" % (self.name, self.callback_function)
1329 result += "#define %s_CALLBACK NULL\n" % self.name
1331 defval = self.default_value(dependencies)
1334 result += '#define %s_DEFAULT (const pb_byte_t*)"%s\\x00"\n' % (self.name, hexcoded)
1336 result += '#define %s_DEFAULT NULL\n' % self.name
1341 … result += "#define %s_%s_%s_MSGTYPE %s\n" % (self.name, field.union_name, field.name, field.ctype)
1343 result += "#define %s_%s_MSGTYPE %s\n" % (self.name, field.name, field.ctype)
1347 def fields_declaration_cpp_lookup(self): argument
1349 result += 'struct MessageDescriptor<%s> {\n' % (self.name)
1350 …static PB_INLINE_CONSTEXPR const pb_size_t fields_array_length = %d;\n' % (self.count_all_fields())
1352 result += ' return &%s_msg;\n' % (self.name)
1357 def fields_definition(self, dependencies): argument
1359 width = self.required_descriptor_width(dependencies)
1363 result = 'PB_BIND(%s, %s, %s)\n' % (self.name, self.name, width)
1366 def required_descriptor_width(self, dependencies): argument
1368 if self.descriptorsize != nanopb_pb2.DS_AUTO:
1369 return int(self.descriptorsize)
1371 if not self.fields:
1374 max_tag = max(field.tag for field in self.all_fields())
1375 max_offset = self.data_size(dependencies)
1376 max_arraysize = max((field.max_count or 0) for field in self.all_fields())
1377 max_datasize = max(field.data_size(dependencies) for field in self.all_fields())
1393 def data_size(self, dependencies): argument
1395 return sum(f.data_size(dependencies) for f in self.fields)
1397 def encoded_size(self, dependencies): argument
1402 for field in self.fields:
1410 def default_value(self, dependencies): argument
1414 if not self.desc:
1417 if self.desc.options.map_entry:
1420 optional_only = copy.deepcopy(self.desc)
1426 parsed_field = self.field_for_tag(field.number)
1441 …ion("Could not find enum type %s while generating default values for %s.\n" % (enumname, self.name)
1557 def __init__(self, fdesc, file_options): argument
1559 self.fdesc = fdesc
1560 self.file_options = file_options
1561 self.dependencies = {}
1562 self.math_include_required = False
1563 self.parse()
1564 for message in self.messages:
1566 self.math_include_required = True
1571 self.add_dependency(self)
1573 def parse(self): argument
1574 self.enums = []
1575 self.messages = []
1576 self.extensions = []
1578 mangle_names = self.file_options.mangle_names
1583 strip_prefix = "." + self.fdesc.package
1585 strip_prefix = "." + self.fdesc.package
1587 for part in self.fdesc.package.split("."):
1589 elif self.file_options.package:
1590 strip_prefix = "." + self.fdesc.package
1591 replacement_prefix = self.file_options.package
1612 if self.file_options.package:
1618 elif self.fdesc.package:
1619 base_name = Names(self.fdesc.package.split('.'))
1625 self.comment_locations = {
1627 for location in self.fdesc.source_code_info.location
1631 for index, enum in enumerate(self.fdesc.enum_type):
1633 enum_options = get_nanopb_suboptions(enum, self.file_options, name)
1634 self.enums.append(Enum(name, enum, enum_options, index, self.comment_locations))
1636 for index, (names, message) in enumerate(iterate_messages(self.fdesc, flatten)):
1638 message_options = get_nanopb_suboptions(message, self.file_options, name)
1648self.messages.append(Message(name, message, message_options, index, self.comment_locations))
1652 self.enums.append(Enum(name, enum, enum_options, index, self.comment_locations))
1654 for names, extension in iterate_extensions(self.fdesc, flatten):
1656 field_options = get_nanopb_suboptions(extension, self.file_options, name)
1663 self.extensions.append(ExtensionField(name, extension, field_options))
1665 def add_dependency(self, other): argument
1667 self.dependencies[str(enum.names)] = enum
1671 self.dependencies[str(msg.name)] = msg
1677 for message in self.messages:
1686 for message in self.messages:
1691 def generate_header(self, includes, headername, options): argument
1702 if self.fdesc.package:
1703 symbol = make_identifier(self.fdesc.package + '_' + headername)
1708 if self.math_include_required:
1717 for incfile in self.file_options.include:
1740 if self.enums:
1742 for enum in self.enums:
1745 if self.messages:
1747 for msg in sort_dependencies(self.messages):
1752 if self.extensions:
1754 for extension in self.extensions:
1758 if self.enums:
1760 for enum in self.enums:
1768 if self.messages:
1770 for msg in self.messages:
1773 for msg in self.messages:
1779 for msg in sort_dependencies(self.messages):
1782 for extension in self.extensions:
1787 for msg in self.messages:
1788 yield msg.fields_declaration(self.dependencies) + '\n'
1789 for msg in self.messages:
1794 for msg in self.messages:
1800 for msg in self.messages:
1802 messagesizes.append((identifier, msg.encoded_size(self.dependencies)))
1828 if [msg for msg in self.messages if hasattr(msg,'msgid')]:
1830 for msg in self.messages:
1838 for msg in self.messages:
1840 msize = msg.encoded_size(self.dependencies)
1847 for msg in self.messages:
1861 for msg in self.messages:
1874 def generate_source(self, headername, options): argument
1893 for msg in self.messages:
1894 yield msg.fields_definition(self.dependencies) + '\n\n'
1896 for ext in self.extensions:
1897 yield ext.extension_def(self.dependencies) + '\n'
1899 for enum in self.enums:
1903 if self.messages:
1904 largest_msg = max(self.messages, key = lambda m: m.count_required_fields())
1915 for msg in self.messages: