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 @@ @@ -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)
{

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

@ -371,8 +371,8 @@ namespace CppSharp.Generators.CLI @@ -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 @@ -494,8 +494,8 @@ 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);

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

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

16
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)
@ -1142,8 +1142,8 @@ namespace CppSharp.Generators.CSharp @@ -1142,8 +1142,8 @@ 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)
@ -1793,8 +1793,8 @@ namespace CppSharp.Generators.CSharp @@ -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);

3
src/Generator/Options.cs

@ -95,7 +95,8 @@ namespace CppSharp @@ -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

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)

6
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -74,9 +74,9 @@ namespace CppSharp.Passes @@ -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;

Loading…
Cancel
Save