(&self, node: &Node)
| 482 | } |
| 483 | |
| 484 | pub fn get_definition(&self, node: &Node) -> String { |
| 485 | let mut fields = vec![]; |
| 486 | let mut nested_record = None; |
| 487 | for child in node.inner.iter() { |
| 488 | if let Clang::FieldDecl(fd) = &child.kind { |
| 489 | let name = fd.get_name(); |
| 490 | let ty = fd.r#type.get_type_name(); |
| 491 | if ty.contains("(unnamed") { |
| 492 | if let Some(nested) = &nested_record { |
| 493 | let field = format!("{nested} {name};"); |
| 494 | fields.push(field); |
| 495 | continue; |
| 496 | } |
| 497 | } |
| 498 | let field = format!("\t{ty} {name}"); |
| 499 | fields.push(field); |
| 500 | } |
| 501 | if let Clang::RecordDecl(crd) = &child.kind { |
| 502 | if !crd.complete_definition { |
| 503 | continue; |
| 504 | } |
| 505 | let raw_def = crd.get_definition(child); |
| 506 | let mut def = String::new(); |
| 507 | for line in raw_def.lines() { |
| 508 | def.push('\t'); |
| 509 | def.push_str(line); |
| 510 | def.push('\n'); |
| 511 | } |
| 512 | def.pop(); |
| 513 | if let Some(name) = crd.get_name() { |
| 514 | let field = if let TagTypeKind::Union = &crd.tag_used { |
| 515 | format!("\tunion {name} {{\n{def}\n\t}}") |
| 516 | } else if let TagTypeKind::Struct = &crd.tag_used { |
| 517 | format!("\tstruct {name} {{\n{def}\n\t}}") |
| 518 | } else { |
| 519 | unreachable!("{child:#?}") |
| 520 | }; |
| 521 | fields.push(field); |
| 522 | nested_record = None; |
| 523 | } else { |
| 524 | let field = if let TagTypeKind::Union = &crd.tag_used { |
| 525 | format!("\tunion {{\n{def}\n\t}}") |
| 526 | } else if let TagTypeKind::Struct = &crd.tag_used { |
| 527 | format!("\tstruct {{\n{def}\n\t}}") |
| 528 | } else { |
| 529 | unreachable!("{child:#?}") |
| 530 | }; |
| 531 | nested_record = Some(field); |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | let mut fields = fields.join(";\n"); |
| 536 | fields.push(';'); |
| 537 | fields |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | #[derive(Deserialize, Debug, Clone)] |
no test coverage detected