11using System ;
22using System . Collections . Generic ;
33using System . Globalization ;
4+ using System . IO ;
45using System . Linq ;
56using CppSharp . AST ;
67using CppSharp . AST . Extensions ;
910
1011namespace CppSharp . Generators . Cpp
1112{
12- public class NAPICodeGenerator : CCodeGenerator
13+ public class MethodGroupCodeGenerator : CCodeGenerator
1314 {
14- public override string FileExtension => "cpp" ;
15-
16- public NAPICodeGenerator ( BindingContext context , IEnumerable < TranslationUnit > units )
15+ protected MethodGroupCodeGenerator ( BindingContext context , IEnumerable < TranslationUnit > units )
1716 : base ( context , units )
1817 {
1918 }
@@ -43,9 +42,9 @@ public override bool VisitClassDecl(Class @class)
4342 return VisitClassDeclContext ( @class ) ;
4443 }
4544
46- public override void VisitClassConstructors ( Class @class )
45+ public override void VisitClassConstructors ( IEnumerable < Method > ctors )
4746 {
48- var constructors = @class . Constructors . Where ( c => c . IsGenerated && ! c . IsCopyConstructor )
47+ var constructors = ctors . Where ( c => c . IsGenerated && ! c . IsCopyConstructor )
4948 . ToList ( ) ;
5049
5150 if ( ! constructors . Any ( ) )
@@ -59,7 +58,7 @@ public static bool ShouldGenerate(Function function)
5958 if ( ! function . IsGenerated )
6059 return false ;
6160
62- if ( ! ( function is Method method ) )
61+ if ( function is not Method method )
6362 return true ;
6463
6564 if ( method . IsConstructor || method . IsDestructor )
@@ -88,10 +87,27 @@ public virtual void GenerateMethodGroup(List<Method> @group)
8887 foreach ( var method in @group )
8988 {
9089 method . Visit ( this ) ;
91- return ;
9290 }
9391 }
9492
93+ public static string GetTranslationUnitName ( TranslationUnit unit )
94+ {
95+ var paths = unit . FileRelativePath . Split ( '/' ) . ToList ( ) ;
96+ paths = paths . Select ( p => Path . GetFileNameWithoutExtension ( p . ToLowerInvariant ( ) ) ) . ToList ( ) ;
97+ var name = string . Join ( '_' , paths ) ;
98+ return name ;
99+ }
100+ }
101+
102+ public class NAPICodeGenerator : MethodGroupCodeGenerator
103+ {
104+ public override string FileExtension => "cpp" ;
105+
106+ public NAPICodeGenerator ( BindingContext context , IEnumerable < TranslationUnit > units )
107+ : base ( context , units )
108+ {
109+ }
110+
95111 public virtual MarshalPrinter < MarshalContext , CppTypePrinter > GetMarshalManagedToNativePrinter ( MarshalContext ctx )
96112 {
97113 return new NAPIMarshalManagedToNativePrinter ( ctx ) ;
0 commit comments