From 4a98f69df52e6bb5295e67bf4a5e966de72044bc Mon Sep 17 00:00:00 2001 From: triton Date: Tue, 15 Apr 2014 15:42:41 +0100 Subject: [PATCH] Added an explicit option to generate copy constructors. --- src/Generator/AST/Utils.cs | 14 +++++++++----- .../Generators/CLI/CLIHeadersTemplate.cs | 10 +++++----- .../Generators/CLI/CLISourcesTemplate.cs | 4 ++-- .../Generators/CSharp/CSharpTextTemplate.cs | 16 ++++++++-------- src/Generator/Options.cs | 3 ++- src/Generator/Passes/CheckDuplicatedNamesPass.cs | 4 ++-- .../Passes/GetterSetterToPropertyPass.cs | 6 +++--- 7 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/Generator/AST/Utils.cs b/src/Generator/AST/Utils.cs index 221ec035..c3944128 100644 --- a/src/Generator/AST/Utils.cs +++ b/src/Generator/AST/Utils.cs @@ -1,22 +1,23 @@  using System; using System.Linq; - +using Mono.Options; + namespace CppSharp.AST { public static class ASTUtils - { - public static bool CheckIgnoreFunction(Function function) + { + public static bool CheckIgnoreFunction(Function function, DriverOptions options) { if (function.Ignore) return true; if (function is Method) - return CheckIgnoreMethod(function as Method); + return CheckIgnoreMethod(function as Method, options); return false; } - public static bool CheckIgnoreMethod(Method method) + public static bool CheckIgnoreMethod(Method method, DriverOptions options) { if (method.Ignore) return true; @@ -41,6 +42,9 @@ namespace CppSharp.AST //Ignore copy constructor if a base class don't has or has a private copy constructor if (method.IsCopyConstructor) { + if (!options.GenerateCopyConstructors) + return true; + var baseClass = @class; while (baseClass != null && baseClass.HasBaseClass) { diff --git a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs index 8dcd3a65..4654ab81 100644 --- a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs +++ b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs @@ -371,8 +371,8 @@ namespace CppSharp.Generators.CLI WriteLine("{0}({1} native);", @class.Name, "System::IntPtr"); foreach (var ctor in @class.Constructors) - { - if (ASTUtils.CheckIgnoreMethod(ctor)) + { + if (ASTUtils.CheckIgnoreMethod(ctor, Options)) continue; // C++/CLI does not allow special member funtions for value types. @@ -494,8 +494,8 @@ namespace CppSharp.Generators.CLI var staticMethods = new List(); foreach (var method in @class.Methods) - { - if (ASTUtils.CheckIgnoreMethod(method)) + { + if (ASTUtils.CheckIgnoreMethod(method, Options)) continue; if (method.IsConstructor) @@ -660,7 +660,7 @@ namespace CppSharp.Generators.CLI public void GenerateMethod(Method method) { - if (ASTUtils.CheckIgnoreMethod(method)) return; + if (ASTUtils.CheckIgnoreMethod(method, Options)) return; PushBlock(CLIBlockKind.Method, method); diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index a9ca519b..1102ff97 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -139,8 +139,8 @@ namespace CppSharp.Generators.CLI GenerateClassConstructors(@class); foreach (var method in @class.Methods) - { - if (ASTUtils.CheckIgnoreMethod(method)) + { + if (ASTUtils.CheckIgnoreMethod(method, Options)) continue; // C++/CLI does not allow special member funtions for value types. diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index c717a58b..c5aaebc4 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -417,8 +417,8 @@ namespace CppSharp.Generators.CSharp GenerateDeclContext(@class); - foreach (var method in @class.Methods.Where(m => !ASTUtils.CheckIgnoreMethod(m) && - m.Access == AccessSpecifier.Public)) + foreach (var method in @class.Methods.Where(m => + !ASTUtils.CheckIgnoreMethod(m, Options) && m.Access == AccessSpecifier.Public)) { PushBlock(CSharpBlockKind.Method); GenerateDeclarationCommon(method); @@ -490,7 +490,7 @@ namespace CppSharp.Generators.CSharp PopBlock(NewLineKind.BeforeNextBlock); } - private static ISet GatherClassInternalFunctions(Class @class) + private ISet GatherClassInternalFunctions(Class @class) { var functions = new HashSet(); @@ -522,7 +522,7 @@ namespace CppSharp.Generators.CSharp foreach (var method in @class.Methods) { - if (ASTUtils.CheckIgnoreMethod(method)) + if (ASTUtils.CheckIgnoreMethod(method, Options)) continue; if (method.IsConstructor) @@ -1142,8 +1142,8 @@ namespace CppSharp.Generators.CSharp { var staticMethods = new List(); foreach (var method in @class.Methods) - { - if (ASTUtils.CheckIgnoreMethod(method)) + { + if (ASTUtils.CheckIgnoreMethod(method, Options)) continue; if (method.IsConstructor) @@ -1793,8 +1793,8 @@ namespace CppSharp.Generators.CSharp GenerateNativeConstructor(@class); foreach (var ctor in @class.Constructors) - { - if (ASTUtils.CheckIgnoreMethod(ctor)) + { + if (ASTUtils.CheckIgnoreMethod(ctor, Options)) continue; GenerateMethod(ctor, @class); diff --git a/src/Generator/Options.cs b/src/Generator/Options.cs index e8494cb6..9edd8e50 100644 --- a/src/Generator/Options.cs +++ b/src/Generator/Options.cs @@ -95,7 +95,8 @@ namespace CppSharp public bool GenerateProperties; public bool GenerateInternalImports; public bool GenerateClassMarshals; - public bool GenerateInlines; + public bool GenerateInlines; + public bool GenerateCopyConstructors; public bool UseHeaderDirectories; //List of include directories that are used but not generated diff --git a/src/Generator/Passes/CheckDuplicatedNamesPass.cs b/src/Generator/Passes/CheckDuplicatedNamesPass.cs index fe3f8b6f..20fa8bea 100644 --- a/src/Generator/Passes/CheckDuplicatedNamesPass.cs +++ b/src/Generator/Passes/CheckDuplicatedNamesPass.cs @@ -123,7 +123,7 @@ namespace CppSharp.Passes if (!VisitDeclaration(decl)) return false; - if (ASTUtils.CheckIgnoreFunction(decl)) + if (ASTUtils.CheckIgnoreFunction(decl, Driver.Options)) return false; CheckDuplicate(decl); @@ -135,7 +135,7 @@ namespace CppSharp.Passes if (!VisitDeclaration(decl)) return false; - if (ASTUtils.CheckIgnoreMethod(decl)) + if (ASTUtils.CheckIgnoreMethod(decl, Driver.Options)) return false; if (decl.ExplicitInterfaceImpl == null) diff --git a/src/Generator/Passes/GetterSetterToPropertyPass.cs b/src/Generator/Passes/GetterSetterToPropertyPass.cs index e5322b1d..d6bc25d8 100644 --- a/src/Generator/Passes/GetterSetterToPropertyPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyPass.cs @@ -74,9 +74,9 @@ namespace CppSharp.Passes public override bool VisitMethodDecl(Method method) { if (!VisitDeclaration(method)) - return false; - - if (ASTUtils.CheckIgnoreMethod(method)) + return false; + + if (ASTUtils.CheckIgnoreMethod(method, Driver.Options)) return false; var @class = method.Namespace as Class;