@@ -314,7 +314,16 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
314
314
}
315
315
316
316
fn write_struct ( out : & mut OutFile , strct : & Struct ) {
317
- write_include_guard_start ( out, & strct. ident ) ;
317
+ writeln ! (
318
+ out,
319
+ "#ifndef CXXBRIDGE03_STRUCT_{}{}" ,
320
+ out. namespace, strct. ident,
321
+ ) ;
322
+ writeln ! (
323
+ out,
324
+ "#define CXXBRIDGE03_STRUCT_{}{}" ,
325
+ out. namespace, strct. ident,
326
+ ) ;
318
327
for line in strct. doc . to_string ( ) . lines ( ) {
319
328
writeln ! ( out, "//{}" , line) ;
320
329
}
@@ -325,7 +334,11 @@ fn write_struct(out: &mut OutFile, strct: &Struct) {
325
334
writeln ! ( out, "{};" , field. ident) ;
326
335
}
327
336
writeln ! ( out, "}};" ) ;
328
- write_include_guard_end ( out, & strct. ident ) ;
337
+ writeln ! (
338
+ out,
339
+ "#endif // CXXBRIDGE03_STRUCT_{}{}" ,
340
+ out. namespace, strct. ident,
341
+ ) ;
329
342
}
330
343
331
344
fn write_struct_decl ( out : & mut OutFile , ident : & Ident ) {
@@ -336,31 +349,17 @@ fn write_struct_using(out: &mut OutFile, ident: &Ident) {
336
349
writeln ! ( out, "using {} = {};" , ident, ident) ;
337
350
}
338
351
339
- const INCLUDE_GUARD_PREFIX : & ' static str = "CXXBRIDGE03_TYPE_" ;
340
-
341
- fn write_include_guard_start ( out : & mut OutFile , ident : & Ident ) {
342
- writeln ! (
343
- out,
344
- "#ifndef {}{}{}" ,
345
- INCLUDE_GUARD_PREFIX , out. namespace, ident
346
- ) ;
352
+ fn write_struct_with_methods ( out : & mut OutFile , ety : & ExternType , methods : & [ & ExternFn ] ) {
347
353
writeln ! (
348
354
out,
349
- "#define {} {}{}" ,
350
- INCLUDE_GUARD_PREFIX , out. namespace, ident
355
+ "#ifndef CXXBRIDGE03_STRUCT_ {}{}" ,
356
+ out. namespace, ety . ident,
351
357
) ;
352
- }
353
-
354
- fn write_include_guard_end ( out : & mut OutFile , ident : & Ident ) {
355
358
writeln ! (
356
359
out,
357
- "#endif // {} {}{}" ,
358
- INCLUDE_GUARD_PREFIX , out. namespace, ident
360
+ "#define CXXBRIDGE03_STRUCT_ {}{}" ,
361
+ out. namespace, ety . ident,
359
362
) ;
360
- }
361
-
362
- fn write_struct_with_methods ( out : & mut OutFile , ety : & ExternType , methods : & [ & ExternFn ] ) {
363
- write_include_guard_start ( out, & ety. ident ) ;
364
363
for line in ety. doc . to_string ( ) . lines ( ) {
365
364
writeln ! ( out, "//{}" , line) ;
366
365
}
@@ -375,11 +374,24 @@ fn write_struct_with_methods(out: &mut OutFile, ety: &ExternType, methods: &[&Ex
375
374
writeln ! ( out, ";" ) ;
376
375
}
377
376
writeln ! ( out, "}};" ) ;
378
- write_include_guard_end ( out, & ety. ident ) ;
377
+ writeln ! (
378
+ out,
379
+ "#endif // CXXBRIDGE03_STRUCT_{}{}" ,
380
+ out. namespace, ety. ident,
381
+ ) ;
379
382
}
380
383
381
384
fn write_enum ( out : & mut OutFile , enm : & Enum ) {
382
- write_include_guard_start ( out, & enm. ident ) ;
385
+ writeln ! (
386
+ out,
387
+ "#ifndef CXXBRIDGE03_ENUM_{}{}" ,
388
+ out. namespace, enm. ident,
389
+ ) ;
390
+ writeln ! (
391
+ out,
392
+ "#define CXXBRIDGE03_ENUM_{}{}" ,
393
+ out. namespace, enm. ident,
394
+ ) ;
383
395
for line in enm. doc . to_string ( ) . lines ( ) {
384
396
writeln ! ( out, "//{}" , line) ;
385
397
}
@@ -390,7 +402,11 @@ fn write_enum(out: &mut OutFile, enm: &Enum) {
390
402
writeln ! ( out, " {} = {}," , variant. ident, variant. discriminant) ;
391
403
}
392
404
writeln ! ( out, "}};" ) ;
393
- write_include_guard_end ( out, & enm. ident ) ;
405
+ writeln ! (
406
+ out,
407
+ "#endif // CXXBRIDGE03_ENUM_{}{}" ,
408
+ out. namespace, enm. ident,
409
+ ) ;
394
410
}
395
411
396
412
fn check_enum ( out : & mut OutFile , enm : & Enum ) {
0 commit comments