| 1 | use super::*; |
| 2 | |
| 3 | impl std::fmt::Debug for MethodDef { |
| 4 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 5 | f.debug_tuple(name:"MethodDef" ).field(&self.name()).finish() |
| 6 | } |
| 7 | } |
| 8 | |
| 9 | impl MethodDef { |
| 10 | pub fn flags(&self) -> MethodAttributes { |
| 11 | MethodAttributes(self.usize(2) as u16) |
| 12 | } |
| 13 | |
| 14 | pub fn name(&self) -> &'static str { |
| 15 | self.str(3) |
| 16 | } |
| 17 | |
| 18 | pub fn params(&self) -> RowIterator<Param> { |
| 19 | self.list(5) |
| 20 | } |
| 21 | |
| 22 | pub fn impl_map(&self) -> Option<ImplMap> { |
| 23 | self.file() |
| 24 | .equal_range(1, MemberForwarded::MethodDef(*self).encode()) |
| 25 | .next() |
| 26 | } |
| 27 | |
| 28 | pub fn module_name(&self) -> &'static str { |
| 29 | self.impl_map().map_or("" , |map| map.scope().name()) |
| 30 | } |
| 31 | |
| 32 | pub fn signature(&self, namespace: &str, generics: &[Type]) -> Signature { |
| 33 | let mut blob = self.blob(4); |
| 34 | let call_flags = MethodCallAttributes(blob.read_usize() as u8); |
| 35 | let _param_count = blob.read_usize(); |
| 36 | let mut return_type = Type::from_blob(&mut blob, None, generics); |
| 37 | let mut return_param = None; |
| 38 | |
| 39 | let params = self |
| 40 | .params() |
| 41 | .filter_map(|param| { |
| 42 | if param.sequence() == 0 { |
| 43 | if param.has_attribute("ConstAttribute" ) { |
| 44 | return_type = return_type.to_const_type(); |
| 45 | } |
| 46 | |
| 47 | return_param = Some(param); |
| 48 | None |
| 49 | } else { |
| 50 | let param_is_const = param.has_attribute("ConstAttribute" ); |
| 51 | let param_is_output = param.flags().contains(ParamAttributes::Out); |
| 52 | let mut ty = Type::from_blob(&mut blob, None, generics); |
| 53 | |
| 54 | if param_is_const || !param_is_output { |
| 55 | ty = ty.to_const_type(); |
| 56 | } |
| 57 | if !param_is_output { |
| 58 | ty = ty.to_const_ptr(); |
| 59 | } |
| 60 | |
| 61 | if !param_is_output { |
| 62 | if let Some(attribute) = param.find_attribute("AssociatedEnumAttribute" ) { |
| 63 | if let Some((_, Value::Str(name))) = attribute.args().first() { |
| 64 | let overload = param.reader().unwrap_full_name(namespace, name); |
| 65 | |
| 66 | ty = Type::PrimitiveOrEnum(Box::new(ty), Box::new(overload)); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | Some((ty, param)) |
| 72 | } |
| 73 | }) |
| 74 | .collect(); |
| 75 | |
| 76 | Signature { |
| 77 | call_flags, |
| 78 | return_type: (return_type, return_param), |
| 79 | params, |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |