get the ty name with sized constraint: const int[size].
(&self, deopt: &crate::deopt::Deopt)
| 411 | |
| 412 | /// get the ty name with sized constraint: const int[size]. |
| 413 | pub fn get_sized_ty_name(&self, deopt: &crate::deopt::Deopt) -> String { |
| 414 | let raw_ty = self.get_type().get_type_name(); |
| 415 | if !raw_ty.contains('*') { |
| 416 | return raw_ty; |
| 417 | } |
| 418 | let src_content = loc::get_header_code_content(&self.range); |
| 419 | if src_content.is_err() { |
| 420 | return raw_ty; |
| 421 | } |
| 422 | let src_content = src_content.unwrap(); |
| 423 | let sized_ty = if let Some(left) = src_content.find('[') { |
| 424 | if let Some(right) = src_content.find(']') { |
| 425 | &src_content[left + 1..right] |
| 426 | } else { |
| 427 | return raw_ty; |
| 428 | } |
| 429 | } else { |
| 430 | return raw_ty; |
| 431 | }; |
| 432 | |
| 433 | if sized_ty.is_empty() { |
| 434 | return raw_ty; |
| 435 | } |
| 436 | if let Some(size) = Self::get_number(sized_ty) { |
| 437 | let raw_ty = raw_ty.trim_end_matches('*'); |
| 438 | let raw_ty = raw_ty.trim_end(); |
| 439 | let sized_ty: String = [raw_ty, "[", &size.to_string(), "]"].concat(); |
| 440 | return sized_ty; |
| 441 | } else if let Ok(Some(value)) = get_exact_value_of_macro(deopt, sized_ty) { |
| 442 | let raw_ty = raw_ty.trim_end_matches('*'); |
| 443 | let raw_ty = raw_ty.trim_end(); |
| 444 | let sized_ty: String = [raw_ty, "[", &value.to_string(), "]"].concat(); |
| 445 | return sized_ty; |
| 446 | } |
| 447 | unreachable!("Meet a sized ParamDecl but fail to get its exact value, please ban this function. Extracted src_content: {src_content}, ty: {raw_ty}, range: {0:#?}", self.range) |
| 448 | } |
| 449 | |
| 450 | fn get_number(s: &str) -> Option<usize> { |
| 451 | if let Ok(value) = s.parse::<usize>() { |
no test coverage detected