@@ -532,9 +532,14 @@ impl WorldGenerator for Cpp {
532532 let binding = Some ( name) ;
533533 let mut r#gen = self . interface ( resolve, binding, true , Some ( wasm_import_module) ) ;
534534 r#gen. interface = Some ( id) ;
535- r#gen. types ( id) ;
536535 let namespace =
537536 namespace ( resolve, & TypeOwner :: Interface ( id) , false , & r#gen. r#gen . opts ) ;
537+ let docs = resolve. interfaces [ id] . docs . contents . as_deref ( ) ;
538+ r#gen
539+ . r#gen
540+ . h_src
541+ . change_namespace_with_docs ( & namespace, docs) ;
542+ r#gen. types ( id) ;
538543
539544 for ( _name, func) in resolve. interfaces [ id] . functions . iter ( ) {
540545 if matches ! ( func. kind, FunctionKind :: Freestanding ) {
@@ -583,8 +588,13 @@ impl WorldGenerator for Cpp {
583588 let binding = Some ( name) ;
584589 let mut r#gen = self . interface ( resolve, binding, false , Some ( wasm_import_module) ) ;
585590 r#gen. interface = Some ( id) ;
586- r#gen. types ( id) ;
587591 let namespace = namespace ( resolve, & TypeOwner :: Interface ( id) , true , & r#gen. r#gen . opts ) ;
592+ let docs = resolve. interfaces [ id] . docs . contents . as_deref ( ) ;
593+ r#gen
594+ . r#gen
595+ . h_src
596+ . change_namespace_with_docs ( & namespace, docs) ;
597+ r#gen. types ( id) ;
588598
589599 for ( _name, func) in resolve. interfaces [ id] . functions . iter ( ) {
590600 if matches ! ( func. kind, FunctionKind :: Freestanding ) {
@@ -791,6 +801,10 @@ fn namespace(resolve: &Resolve, owner: &TypeOwner, guest_export: bool, opts: &Op
791801
792802impl SourceWithState {
793803 fn change_namespace ( & mut self , target : & [ String ] ) {
804+ self . change_namespace_with_docs ( target, None ) ;
805+ }
806+
807+ fn change_namespace_with_docs ( & mut self , target : & [ String ] , docs : Option < & str > ) {
794808 let mut same = 0 ;
795809 // itertools::fold_while?
796810 for ( a, b) in self . namespace . iter ( ) . zip ( target. iter ( ) ) {
@@ -804,9 +818,17 @@ impl SourceWithState {
804818 uwrite ! ( self . src, "}}\n " ) ;
805819 }
806820 self . namespace . truncate ( same) ;
807- for i in target. iter ( ) . skip ( same) {
808- uwrite ! ( self . src, "namespace {} {{\n " , i) ;
809- self . namespace . push ( i. clone ( ) ) ;
821+ let new_namespaces: Vec < _ > = target. iter ( ) . skip ( same) . collect ( ) ;
822+ if !new_namespaces. is_empty ( ) {
823+ if let Some ( content) = docs {
824+ for line in content. trim ( ) . lines ( ) {
825+ uwriteln ! ( self . src, "/// {}" , line) ;
826+ }
827+ }
828+ for i in & new_namespaces {
829+ uwrite ! ( self . src, "namespace {} {{\n " , i) ;
830+ self . namespace . push ( i. to_string ( ) ) ;
831+ }
810832 }
811833 }
812834
@@ -1289,6 +1311,10 @@ impl CppInterfaceGenerator<'_> {
12891311 AbiVariant :: GuestExportAsync => todo ! ( ) ,
12901312 AbiVariant :: GuestExportAsyncStackful => todo ! ( ) ,
12911313 } ;
1314+ if func. docs . contents . is_some ( ) && !self . r#gen . h_src . src . ends_with ( '\n' ) {
1315+ uwriteln ! ( self . r#gen. h_src. src, "" ) ;
1316+ }
1317+ Self :: docs ( & mut self . r#gen . h_src . src , & func. docs ) ;
12921318 let params = self . print_signature ( func, variant, !export) ;
12931319 let special = is_special_method ( func) ;
12941320 if !matches ! ( special, SpecialMethod :: Allocate ) {
0 commit comments