mirror of https://github.com/mono/CppSharp.git
c-sharpdotnetmonobindingsbridgecclangcpluspluscppsharpglueinteropparserparsingpinvokeswigsyntax-treevisitorsxamarinxamarin-bindings
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.2 KiB
63 lines
2.2 KiB
using System.Linq; |
|
using CppSharp.AST; |
|
using CppSharp.AST.Extensions; |
|
|
|
namespace CppSharp.Passes |
|
{ |
|
public class MarkSupportedSpecializationsPass : TranslationUnitPass |
|
{ |
|
public override bool VisitClassDecl(Class @class) |
|
{ |
|
if (!base.VisitClassDecl(@class) || !@class.IsDependent) |
|
return false; |
|
|
|
foreach (var specialization in @class.Specializations) |
|
{ |
|
if (IsSupportedStdSpecialization(specialization)) |
|
{ |
|
MarkForGeneration(specialization); |
|
@class.GenerationKind = GenerationKind.Generate; |
|
} |
|
} |
|
|
|
return true; |
|
} |
|
|
|
private static bool IsSupportedStdSpecialization(ClassTemplateSpecialization specialization) |
|
{ |
|
return IsSupportedStdType(specialization) && |
|
specialization.Arguments[0].Type.Type.IsPrimitiveType(PrimitiveType.Char); |
|
} |
|
|
|
private static bool IsSupportedStdType(Declaration declaration) |
|
{ |
|
return declaration.Namespace != null && |
|
declaration.TranslationUnit.IsSystemHeader && |
|
IsNameSpaceStd(declaration.Namespace) && |
|
supportedStdTypes.Contains(declaration.OriginalName); |
|
} |
|
|
|
private static bool IsNameSpaceStd(DeclarationContext declarationContext) |
|
{ |
|
if (declarationContext == null) |
|
return false; |
|
var @namespace = declarationContext as Namespace; |
|
if (@namespace != null && @namespace.IsInline) |
|
return IsNameSpaceStd(declarationContext.Namespace); |
|
return declarationContext.OriginalName == "std"; |
|
} |
|
|
|
private static void MarkForGeneration(ClassTemplateSpecialization specialization) |
|
{ |
|
specialization.GenerationKind = GenerationKind.Generate; |
|
Declaration declaration = specialization.TemplatedDecl.TemplatedDecl; |
|
while (declaration != null) |
|
{ |
|
declaration.GenerationKind = GenerationKind.Generate; |
|
declaration = declaration.Namespace; |
|
} |
|
} |
|
|
|
private static string[] supportedStdTypes = { "basic_string", "allocator" }; |
|
} |
|
}
|
|
|