Browse Source

Added an explicit option to generate copy constructors.

pull/225/head
triton 12 years ago
parent
commit
4a98f69df5
  1. 14
      src/Generator/AST/Utils.cs
  2. 10
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  3. 4
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  4. 16
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  5. 3
      src/Generator/Options.cs
  6. 4
      src/Generator/Passes/CheckDuplicatedNamesPass.cs
  7. 6
      src/Generator/Passes/GetterSetterToPropertyPass.cs

14
src/Generator/AST/Utils.cs

@ -1,22 +1,23 @@
 
using System; using System;
using System.Linq; using System.Linq;
using Mono.Options;
namespace CppSharp.AST namespace CppSharp.AST
{ {
public static class ASTUtils 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.Ignore) return true;
if (function is Method) if (function is Method)
return CheckIgnoreMethod(function as Method); return CheckIgnoreMethod(function as Method, options);
return false; return false;
} }
public static bool CheckIgnoreMethod(Method method) public static bool CheckIgnoreMethod(Method method, DriverOptions options)
{ {
if (method.Ignore) return true; 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 //Ignore copy constructor if a base class don't has or has a private copy constructor
if (method.IsCopyConstructor) if (method.IsCopyConstructor)
{ {
if (!options.GenerateCopyConstructors)
return true;
var baseClass = @class; var baseClass = @class;
while (baseClass != null && baseClass.HasBaseClass) while (baseClass != null && baseClass.HasBaseClass)
{ {

10
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -371,8 +371,8 @@ namespace CppSharp.Generators.CLI
WriteLine("{0}({1} native);", @class.Name, "System::IntPtr"); WriteLine("{0}({1} native);", @class.Name, "System::IntPtr");
foreach (var ctor in @class.Constructors) foreach (var ctor in @class.Constructors)
{ {
if (ASTUtils.CheckIgnoreMethod(ctor)) if (ASTUtils.CheckIgnoreMethod(ctor, Options))
continue; continue;
// C++/CLI does not allow special member funtions for value types. // C++/CLI does not allow special member funtions for value types.
@ -494,8 +494,8 @@ namespace CppSharp.Generators.CLI
var staticMethods = new List<Method>(); var staticMethods = new List<Method>();
foreach (var method in @class.Methods) foreach (var method in @class.Methods)
{ {
if (ASTUtils.CheckIgnoreMethod(method)) if (ASTUtils.CheckIgnoreMethod(method, Options))
continue; continue;
if (method.IsConstructor) if (method.IsConstructor)
@ -660,7 +660,7 @@ namespace CppSharp.Generators.CLI
public void GenerateMethod(Method method) public void GenerateMethod(Method method)
{ {
if (ASTUtils.CheckIgnoreMethod(method)) return; if (ASTUtils.CheckIgnoreMethod(method, Options)) return;
PushBlock(CLIBlockKind.Method, method); PushBlock(CLIBlockKind.Method, method);

4
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -139,8 +139,8 @@ namespace CppSharp.Generators.CLI
GenerateClassConstructors(@class); GenerateClassConstructors(@class);
foreach (var method in @class.Methods) foreach (var method in @class.Methods)
{ {
if (ASTUtils.CheckIgnoreMethod(method)) if (ASTUtils.CheckIgnoreMethod(method, Options))
continue; continue;
// C++/CLI does not allow special member funtions for value types. // C++/CLI does not allow special member funtions for value types.

16
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -417,8 +417,8 @@ namespace CppSharp.Generators.CSharp
GenerateDeclContext(@class); GenerateDeclContext(@class);
foreach (var method in @class.Methods.Where(m => !ASTUtils.CheckIgnoreMethod(m) && foreach (var method in @class.Methods.Where(m =>
m.Access == AccessSpecifier.Public)) !ASTUtils.CheckIgnoreMethod(m, Options) && m.Access == AccessSpecifier.Public))
{ {
PushBlock(CSharpBlockKind.Method); PushBlock(CSharpBlockKind.Method);
GenerateDeclarationCommon(method); GenerateDeclarationCommon(method);
@ -490,7 +490,7 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
private static ISet<Function> GatherClassInternalFunctions(Class @class) private ISet<Function> GatherClassInternalFunctions(Class @class)
{ {
var functions = new HashSet<Function>(); var functions = new HashSet<Function>();
@ -522,7 +522,7 @@ namespace CppSharp.Generators.CSharp
foreach (var method in @class.Methods) foreach (var method in @class.Methods)
{ {
if (ASTUtils.CheckIgnoreMethod(method)) if (ASTUtils.CheckIgnoreMethod(method, Options))
continue; continue;
if (method.IsConstructor) if (method.IsConstructor)
@ -1142,8 +1142,8 @@ namespace CppSharp.Generators.CSharp
{ {
var staticMethods = new List<Method>(); var staticMethods = new List<Method>();
foreach (var method in @class.Methods) foreach (var method in @class.Methods)
{ {
if (ASTUtils.CheckIgnoreMethod(method)) if (ASTUtils.CheckIgnoreMethod(method, Options))
continue; continue;
if (method.IsConstructor) if (method.IsConstructor)
@ -1793,8 +1793,8 @@ namespace CppSharp.Generators.CSharp
GenerateNativeConstructor(@class); GenerateNativeConstructor(@class);
foreach (var ctor in @class.Constructors) foreach (var ctor in @class.Constructors)
{ {
if (ASTUtils.CheckIgnoreMethod(ctor)) if (ASTUtils.CheckIgnoreMethod(ctor, Options))
continue; continue;
GenerateMethod(ctor, @class); GenerateMethod(ctor, @class);

3
src/Generator/Options.cs

@ -95,7 +95,8 @@ namespace CppSharp
public bool GenerateProperties; public bool GenerateProperties;
public bool GenerateInternalImports; public bool GenerateInternalImports;
public bool GenerateClassMarshals; public bool GenerateClassMarshals;
public bool GenerateInlines; public bool GenerateInlines;
public bool GenerateCopyConstructors;
public bool UseHeaderDirectories; public bool UseHeaderDirectories;
//List of include directories that are used but not generated //List of include directories that are used but not generated

4
src/Generator/Passes/CheckDuplicatedNamesPass.cs

@ -123,7 +123,7 @@ namespace CppSharp.Passes
if (!VisitDeclaration(decl)) if (!VisitDeclaration(decl))
return false; return false;
if (ASTUtils.CheckIgnoreFunction(decl)) if (ASTUtils.CheckIgnoreFunction(decl, Driver.Options))
return false; return false;
CheckDuplicate(decl); CheckDuplicate(decl);
@ -135,7 +135,7 @@ namespace CppSharp.Passes
if (!VisitDeclaration(decl)) if (!VisitDeclaration(decl))
return false; return false;
if (ASTUtils.CheckIgnoreMethod(decl)) if (ASTUtils.CheckIgnoreMethod(decl, Driver.Options))
return false; return false;
if (decl.ExplicitInterfaceImpl == null) if (decl.ExplicitInterfaceImpl == null)

6
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -74,9 +74,9 @@ namespace CppSharp.Passes
public override bool VisitMethodDecl(Method method) public override bool VisitMethodDecl(Method method)
{ {
if (!VisitDeclaration(method)) if (!VisitDeclaration(method))
return false; return false;
if (ASTUtils.CheckIgnoreMethod(method)) if (ASTUtils.CheckIgnoreMethod(method, Driver.Options))
return false; return false;
var @class = method.Namespace as Class; var @class = method.Namespace as Class;

Loading…
Cancel
Save