(&mut self, resolve: &Resolve, id: WorldId, files: &mut Files)
| 318 | } |
| 319 | |
| 320 | fn finish(&mut self, resolve: &Resolve, id: WorldId, files: &mut Files) -> Result<()> { |
| 321 | let linking_symbol = component_type_object::linking_symbol(&self.world); |
| 322 | self.c_include("<stdlib.h>"); |
| 323 | let snake = self.world.to_snake_case(); |
| 324 | uwriteln!( |
| 325 | self.src.c_adapters, |
| 326 | "\n// Ensure that the *_component_type.o object is linked in" |
| 327 | ); |
| 328 | uwrite!( |
| 329 | self.src.c_adapters, |
| 330 | " |
| 331 | extern void {linking_symbol}(void); |
| 332 | __attribute__((used)) |
| 333 | void {linking_symbol}_public_use_in_this_compilation_unit(void) {{ |
| 334 | {linking_symbol}(); |
| 335 | }} |
| 336 | ", |
| 337 | ); |
| 338 | |
| 339 | self.print_intrinsics(); |
| 340 | |
| 341 | if self.needs_string { |
| 342 | self.c_include("<string.h>"); |
| 343 | let (strlen, size) = match self.opts.string_encoding { |
| 344 | StringEncoding::UTF8 => (format!("strlen(s)"), 1), |
| 345 | StringEncoding::UTF16 => { |
| 346 | self.h_include("<uchar.h>"); |
| 347 | uwrite!( |
| 348 | self.src.h_helpers, |
| 349 | " |
| 350 | // Returns the length of the UTF-16 string `s` in code units |
| 351 | size_t {snake}_string_len(const char16_t* s); |
| 352 | ", |
| 353 | ); |
| 354 | uwrite!( |
| 355 | self.src.c_helpers, |
| 356 | " |
| 357 | size_t {snake}_string_len(const char16_t* s) {{ |
| 358 | char16_t* c = (char16_t*)s; |
| 359 | for (; *c; ++c); |
| 360 | return c-s; |
| 361 | }} |
| 362 | ", |
| 363 | ); |
| 364 | (format!("{snake}_string_len(s)"), 2) |
| 365 | } |
| 366 | StringEncoding::CompactUTF16 => unimplemented!(), |
| 367 | }; |
| 368 | let ty = self.char_type(); |
| 369 | let c_string_ty = match self.opts.string_encoding { |
| 370 | StringEncoding::UTF8 => "char", |
| 371 | StringEncoding::UTF16 => "char16_t", |
| 372 | StringEncoding::CompactUTF16 => panic!("Compact UTF16 unsupported"), |
| 373 | }; |
| 374 | uwrite!( |
| 375 | self.src.h_helpers, |
| 376 | " |
| 377 | // Sets the string `ret` to reference the input string `s` without copying it |
no test coverage detected