Lines Matching refs:typeobj

531 def _set_type_lifetime(typeobj, has_lifetime):  argument
532 typeobj.has_lifetime = has_lifetime
544 ensure_in(typeobj.ffi_iterator_type)
545 ensure_in(typeobj.rs_type)
546 ensure_in(typeobj.rs_iterator_type)
548 ensure_out(typeobj.ffi_iterator_type)
549 ensure_out(typeobj.rs_type)
550 ensure_out(typeobj.rs_iterator_type)
556 def _ffi_type_setup(typeobj, nametup, suffix=()): argument
565 typeobj.ffi_type = _ffi_type_name(nametup + suffix)
567 typeobj.ffi_iterator_type = _ffi_type_name(nametup + ('iterator',))
568 typeobj.ffi_next_fn = _ffi_name(nametup + ('next',))
569 typeobj.ffi_end_fn = _ffi_name(nametup + ('end',))
571 typeobj.ffi_request_fn = _ffi_name(nametup)
572 typeobj.ffi_checked_fn = _ffi_name(nametup + ('checked',))
573 typeobj.ffi_unchecked_fn = _ffi_name(nametup + ('unchecked',))
574 typeobj.ffi_reply_fn = _ffi_name(nametup + ('reply',))
575 typeobj.ffi_reply_type = _ffi_type_name(nametup + ('reply',))
576 typeobj.ffi_cookie_type = _ffi_type_name(nametup + ('cookie',))
577 typeobj.ffi_reply_fds_fn = _ffi_name(nametup + ('reply_fds',))
579 typeobj.ffi_need_aux = False
580 typeobj.ffi_need_serialize = False
581 typeobj.ffi_need_sizeof = False
583 typeobj.ffi_aux_fn = _ffi_name(nametup + ('aux',))
584 typeobj.ffi_aux_checked_fn = _ffi_name(nametup + ('aux', 'checked'))
585 typeobj.ffi_aux_unchecked_fn = _ffi_name(nametup + ('aux', 'unchecked'))
586 typeobj.ffi_serialize_fn = _ffi_name(nametup + ('serialize',))
587 typeobj.ffi_unserialize_fn = _ffi_name(nametup + ('unserialize',))
588 typeobj.ffi_unpack_fn = _ffi_name(nametup + ('unpack',))
589 typeobj.ffi_sizeof_fn = _ffi_name(nametup + ('sizeof',))
593 typeobj.ffi_var_followed_by_fixed_fields = False
595 if not typeobj.fixed_size():
596 if not typeobj in _types_uneligible_to_copy:
597 _types_uneligible_to_copy.append(typeobj)
598 if hasattr(typeobj, 'parents'):
599 for p in typeobj.parents:
603 if typeobj.is_container:
609 for field in typeobj.fields:
614 typeobj.ffi_need_sizeof = True
634 typeobj.ffi_need_sizeof = True
659 if not typeobj.is_union:
660 typeobj.ffi_need_serialize = True
661 typeobj.ffi_var_followed_by_fixed_fields = True
663 typeobj.last_varsized_field = field
667 if typeobj.ffi_var_followed_by_fixed_fields:
671 if typeobj.ffi_need_serialize:
674 typeobj.ffi_need_sizeof = True
676 if not typeobj.is_bitcase:
677 if typeobj.ffi_need_serialize:
678 if typeobj.ffi_serialize_fn not in finished_serializers:
679 finished_serializers.append(typeobj.ffi_serialize_fn)
686 if (typeobj.is_switch or
687 typeobj.ffi_var_followed_by_fixed_fields):
691 if typeobj.ffi_need_sizeof:
692 if typeobj.ffi_sizeof_fn not in finished_sizeof:
693 if not _ns.is_ext or typeobj.name[:2] == _ns.prefix:
694 finished_sizeof.append(typeobj.ffi_sizeof_fn)
706 def _ffi_struct(typeobj, must_pack=False): argument
714 for field in typeobj.fields:
716 and not typeobj.is_switch
717 and not typeobj.is_union):
724 _write_doc_brief_desc(_f, typeobj.doc)
726 _f('pub struct %s {', typeobj.ffi_type)
730 if not typeobj.is_switch:
731 for field in typeobj.fields:
734 for b in typeobj.bitcases:
746 if (field.type.fixed_size() or typeobj.is_union or
750 (typeobj.is_switch and field.type.is_switch)):
760 if not typeobj.is_switch:
762 for d in typeobj.doc.fields[field.field_name]:
766 for b in typeobj.bitcases:
771 _ffi_bitcase_name(typeobj, b))
778 if not typeobj in _types_uneligible_to_copy:
780 _f('impl Copy for %s {}', typeobj.ffi_type)
781 _f('impl Clone for %s {', typeobj.ffi_type)
782 _f(' fn clone(&self) -> %s { *self }', typeobj.ffi_type)
788 _f('pub struct %s {', _ffi_bitcase_name(typeobj, b))
800 def _ffi_accessors_list(typeobj, field): argument
809 ffi_type = typeobj.ffi_type
820 switch_obj = typeobj if typeobj.is_switch else None
821 if typeobj.is_bitcase:
822 switch_obj = typeobj.parents[-1]
827 parents = typeobj.parents if hasattr(typeobj, 'parents') else [typeobj]
876 def _ffi_accessors_field(typeobj, field): argument
881 ffi_type = typeobj.ffi_type
884 switch_obj = typeobj if typeobj.is_switch else None
885 if typeobj.is_bitcase:
886 switch_obj = typeobj.parents[-1]
906 def _ffi_accessors(typeobj, nametup): argument
907 for field in typeobj.fields:
910 _ffi_accessors_list(typeobj, field)
913 _ffi_accessors_field(typeobj, field)
916 def _ffi_iterator(typeobj, nametup): argument
918 has_lifetime = typeobj.ffi_iterator_type in types_with_lifetime
924 _f("pub struct %s%s {", typeobj.ffi_iterator_type, lifetime)
925 _f(' pub data: *mut %s,', typeobj.ffi_type)
929 _f(" _phantom: std::marker::PhantomData<&'a %s>,", typeobj.ffi_type)
934 _f('pub fn %s (i: *mut %s);', typeobj.ffi_next_fn,
935 typeobj.ffi_iterator_type)
938 _f('pub fn %s (i: *mut %s)', typeobj.ffi_end_fn,
939 typeobj.ffi_iterator_type)
986 def _rs_type_setup(typeobj, nametup, suffix=()): argument
989 typeobj.rs_type = _rs_type_name(nametup + suffix)
992 typeobj.rs_qualified_type = typeobj.rs_type
995 typeobj.rs_qualified_type = '%s::%s' % (module, typeobj.rs_type)
997 typeobj.rs_iterator_type = _rs_type_name(nametup+('iterator',))
998 typeobj.rs_request_fn = _rs_name(nametup)
999 typeobj.rs_checked_fn = _rs_name(nametup+('checked',))
1000 typeobj.rs_unchecked_fn = _rs_name(nametup+('unchecked',))
1002 typeobj.rs_aux_fn = _rs_name(nametup+('aux',))
1003 typeobj.rs_aux_checked_fn = _rs_name(nametup+('aux', 'checked'))
1004 typeobj.rs_aux_unchecked_fn = _rs_name(nametup+('aux', 'unchecked'))
1005 typeobj.rs_reply_type = _rs_type_name(nametup + ('reply',))
1006 typeobj.rs_cookie_type = _rs_type_name(nametup + ('cookie',))
1008 typeobj.rs_is_pod = False
1010 if typeobj.is_container:
1012 for field in typeobj.fields:
1026 typeobj.rs_only_has_simple = not has_complex
1028 typeobj.rs_is_pod = (
1030 (not typeobj.rs_qualified_type in _rs_typedef_exceptions) and
1031 (not typeobj.is_reply and not typeobj.is_union) and
1032 (not typeobj.is_switch))
1034 if typeobj.rs_is_pod:
1035 _set_type_lifetime(typeobj, False)
1039 def _rs_struct(typeobj): argument
1042 _write_doc_brief_desc(_r, typeobj.doc)
1043 if typeobj.rs_is_pod:
1045 _r('pub struct %s {', typeobj.rs_type)
1046 _r(' pub base: %s,', typeobj.ffi_type)
1049 has_lifetime = typeobj.rs_type in types_with_lifetime
1053 _r("pub type %s%s = base::StructPtr<%s%s>;", typeobj.rs_type, lifetime1,
1054 lifetime2, typeobj.ffi_type)
1057 def _rs_accessors(typeobj): argument
1059 has_lifetime = typeobj.rs_type in types_with_lifetime
1064 _r('impl%s %s%s {', lifetime, typeobj.rs_type, lifetime)
1066 if typeobj.rs_is_pod:
1071 for f in typeobj.fields:
1075 for f in typeobj.fields:
1087 _r(' -> %s {', typeobj.rs_type)
1090 _r('%s) -> %s {', fnstart, typeobj.rs_type)
1095 _r('%s {', typeobj.rs_type)
1097 _r('base: %s {', typeobj.ffi_type)
1099 for f in typeobj.fields:
1118 for (i, field) in enumerate(typeobj.fields):
1120 for d in typeobj.doc.fields[field.field_name]:
1122 if typeobj.is_union:
1123 _rs_union_accessor(typeobj, field)
1125 _rs_accessor(typeobj, field)
1183 def _rs_union_accessor(typeobj, field): argument
1197 field.rs_field_name, field.rs_field_type, typeobj.rs_type)
1204 _r('let mut res = %s { data: [0; %d] };', typeobj.rs_type,
1205 typeobj.union_num_bytes)
1214 assert (typeobj.union_num_bytes % field.type.size) == 0
1222 typeobj.union_num_bytes / field.type.size)
1227 typeobj.union_num_bytes / field.type.size,
1228 typeobj.rs_type)
1232 _r('%s { data: std::mem::transmute(%s) }', typeobj.rs_type,
1258 def _rs_accessor(typeobj, field, disable_pod_acc=False): argument
1264 if typeobj.rs_is_pod and not disable_pod_acc:
1282 has_lifetime = typeobj.rs_type in types_with_lifetime
1342 typeobj.rs_type in types_with_lifetime:
1377 % (typeobj.ffi_type, field.ffi_field_name))
1381 def _rs_iterator(typeobj): argument
1383 has_lifetime = typeobj.rs_iterator_type in types_with_lifetime
1387 if typeobj.rs_is_pod:
1389 elif typeobj.is_container and not typeobj.is_union:
1395 typeobj.rs_iterator_type, lifetime1, typeobj.ffi_iterator_type, lifetime1)
1398 _r("impl%s Iterator for %s%s {", lifetime1, typeobj.rs_iterator_type, lifetime1)
1399 _r(" type Item = %s%s;", typeobj.rs_type, lifetime1)
1401 typeobj.rs_type, lifetime1)
1406 typeobj.ffi_iterator_type)
1408 _r(' %s(iter);', typeobj.ffi_next_fn)
1428 def _prepare_doc(typeobj): argument
1439 if hasattr(typeobj, "doc_prepared"):
1440 assert typeobj.doc_prepared == True
1442 if hasattr(typeobj, "doc") and typeobj.doc:
1443 if typeobj.doc.brief:
1444 typeobj.doc.brief = [rework_phrase(p) for p in typeobj.doc.brief.split('\n')]
1446 typeobj.doc.brief = []
1447 if typeobj.doc.description:
1448typeobj.doc.description = [rework_phrase(p) for p in typeobj.doc.description.split('\n')]
1450 typeobj.doc.description = []
1451 if hasattr(typeobj, "fields"):
1452 if not hasattr(typeobj.doc, "fields"):
1453 typeobj.doc.fields = {}
1454 for f in typeobj.fields:
1455 if f.field_name in typeobj.doc.fields:
1456 typeobj.doc.fields[f.field_name] = \
1457 [rework_phrase(p) for p in typeobj.doc.fields[f.field_name].split('\n')]
1459 typeobj.doc.fields[f.field_name] = []
1462 typeobj.doc = Doc()
1463 typeobj.doc.brief = []
1464 typeobj.doc.description = []
1465 typeobj.doc.fields = {}
1466 if hasattr(typeobj, "fields"):
1467 for f in typeobj.fields:
1468 typeobj.doc.fields[f.field_name] = []
1470 typeobj.doc_prepared = True
2012 def _handle_switch(typeobj, nametup): argument
2013 if typeobj.is_switch and typeobj.ffi_type not in finished_switch:
2014 finished_switch.append(typeobj.ffi_type)
2016 for bitcase in typeobj.bitcases:
2025 _set_type_lifetime(typeobj, True)
2027 _ffi_struct(typeobj)
2028 _rs_struct(typeobj)
2030 for bitcase in typeobj.bitcases:
2034 if typeobj.is_container:
2035 for f in typeobj.fields:
2070 def rs_enum(typeobj, nametup): argument
2078 _prepare_doc(typeobj)
2080 ecg = EnumCodegen(nametup, typeobj.doc)
2083 for (enam, eval) in typeobj.values: