Browse Source

Added an explicit option to generate copy constructors.

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

10
src/Generator/AST/Utils.cs

@ -1,22 +1,23 @@ @@ -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 @@ -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)
{

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

@ -372,7 +372,7 @@ namespace CppSharp.Generators.CLI @@ -372,7 +372,7 @@ namespace CppSharp.Generators.CLI
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.
@ -495,7 +495,7 @@ namespace CppSharp.Generators.CLI @@ -495,7 +495,7 @@ namespace CppSharp.Generators.CLI
var staticMethods = new List<Method>();
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 @@ -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);

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

@ -140,7 +140,7 @@ namespace CppSharp.Generators.CLI @@ -140,7 +140,7 @@ namespace CppSharp.Generators.CLI
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.

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

@ -417,8 +417,8 @@ namespace CppSharp.Generators.CSharp @@ -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 @@ -490,7 +490,7 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
}
private static ISet<Function> GatherClassInternalFunctions(Class @class)
private ISet<Function> GatherClassInternalFunctions(Class @class)
{
var functions = new HashSet<Function>();
@ -522,7 +522,7 @@ namespace CppSharp.Generators.CSharp @@ -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)
@ -1143,7 +1143,7 @@ namespace CppSharp.Generators.CSharp @@ -1143,7 +1143,7 @@ namespace CppSharp.Generators.CSharp
var staticMethods = new List<Method>();
foreach (var method in @class.Methods)
{
if (ASTUtils.CheckIgnoreMethod(method))
if (ASTUtils.CheckIgnoreMethod(method, Options))
continue;
if (method.IsConstructor)
@ -1794,7 +1794,7 @@ namespace CppSharp.Generators.CSharp @@ -1794,7 +1794,7 @@ namespace CppSharp.Generators.CSharp
foreach (var ctor in @class.Constructors)
{
if (ASTUtils.CheckIgnoreMethod(ctor))
if (ASTUtils.CheckIgnoreMethod(ctor, Options))
continue;
GenerateMethod(ctor, @class);

1
src/Generator/Options.cs

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

4
src/Generator/Passes/CheckDuplicatedNamesPass.cs

@ -123,7 +123,7 @@ namespace CppSharp.Passes @@ -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 @@ -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)

2
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -76,7 +76,7 @@ namespace CppSharp.Passes @@ -76,7 +76,7 @@ namespace CppSharp.Passes
if (!VisitDeclaration(method))
return false;
if (ASTUtils.CheckIgnoreMethod(method))
if (ASTUtils.CheckIgnoreMethod(method, Driver.Options))
return false;
var @class = method.Namespace as Class;

Loading…
Cancel
Save