diff --git a/src/Generator/Passes/CheckMacrosPass.cs b/src/Generator/Passes/CheckMacrosPass.cs index 4eebb2a7..2d78dede 100644 --- a/src/Generator/Passes/CheckMacrosPass.cs +++ b/src/Generator/Passes/CheckMacrosPass.cs @@ -20,6 +20,9 @@ namespace CppSharp.Passes /// CS_IGNORE_GEN (declarations) /// Used to ignore declaration from being generated. /// + /// CS_IGNORE_FILE (.h) + /// Used to ignore all declarations of one header. + /// /// CS_VALUE_TYPE (classes and structs) /// Used to flag that a class or struct is a value type. /// @@ -36,6 +39,9 @@ namespace CppSharp.Passes /// Used to flag method as representing the .NET Equals or /// Hashcode methods. /// + /// CS_CONSTRAINT(TYPE [, TYPE]*) (templates) + /// Used to define constraint of generated generic type or generic method. + /// /// There isn't a standardized header provided by CppSharp so you will /// have to define these on your own. /// @@ -183,5 +189,50 @@ namespace CppSharp.Passes return base.VisitProperty(property); } + + public override bool VisitClassTemplateDecl(ClassTemplate template) + { + var expansions = template.PreprocessedEntities.OfType(); + + var expansion = expansions.FirstOrDefault(e => e.Text.StartsWith(Prefix + "_CONSTRAINT")); + if (expansion != null) + { + var args = GetArguments(expansion.Text); + for (var i = 0; i < template.Parameters.Count && i < args.Length; ++i) + { + var param = template.Parameters[i]; + param.Constraint = args[i]; + template.Parameters[i] = param; + } + } + + return base.VisitClassTemplateDecl(template); + } + + public override bool VisitFunctionTemplateDecl(FunctionTemplate template) + { + var expansions = template.PreprocessedEntities.OfType(); + + var expansion = expansions.FirstOrDefault(e => e.Text.StartsWith(Prefix + "_CONSTRAINT")); + if (expansion != null) + { + var args = GetArguments(expansion.Text); + for (var i = 0; i < template.Parameters.Count && i < args.Length; ++i) + { + var param = template.Parameters[i]; + param.Constraint = args[i]; + template.Parameters[i] = param; + } + } + + return base.VisitFunctionTemplateDecl(template); + } + + private static string[] GetArguments(string str) + { + str = str.Substring(str.LastIndexOf('(')); + str = str.Trim('(', ')'); + return str.Split(','); + } } }