Browse Source

Removed the option for copy ctors and prevented usage of ignored ones.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/573/head
Dimitar Dobrev 10 years ago
parent
commit
b9e3efbf0c
  1. 3
      src/CppParser/Bindings/ParserGen.cs
  2. 3
      src/Generator/AST/Utils.cs
  3. 14
      src/Generator/Generators/CLI/CLITypePrinter.cs
  4. 11
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  5. 1
      src/Generator/Options.cs
  6. 12
      src/Generator/Passes/FindSymbolsPass.cs
  7. 1
      tests/CSharp/CSharp.cs
  8. 1
      tests/Common/Common.cs
  9. 1
      tests/TypeMaps/TypeMaps.cs
  10. 4
      tests/VTables/VTables.cpp
  11. 1
      tests/VTables/VTables.h

3
src/CppParser/Bindings/ParserGen.cs

@ -53,8 +53,7 @@ namespace CppSharp @@ -53,8 +53,7 @@ namespace CppSharp
options.Abi = Abi;
options.LibraryName = "CppSharp.CppParser.dll";
options.GeneratorKind = Kind;
options.GenerateCopyConstructors = true;
options.Headers.AddRange(new string[]
options.Headers.AddRange(new[]
{
"AST.h",
"Sources.h",

3
src/Generator/AST/Utils.cs

@ -41,9 +41,6 @@ namespace CppSharp.AST @@ -41,9 +41,6 @@ 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)
{

14
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -319,15 +319,25 @@ namespace CppSharp.Generators.CLI @@ -319,15 +319,25 @@ namespace CppSharp.Generators.CLI
{
var names = new List<string>();
string rootNamespace = null;
if (Options.GenerateLibraryNamespace)
names.Add(Driver.Options.OutputNamespace);
names.Add(rootNamespace = Driver.Options.OutputNamespace);
if (!string.IsNullOrEmpty(decl.Namespace.QualifiedName))
{
names.Add(decl.Namespace.QualifiedName);
if (string.IsNullOrEmpty(rootNamespace))
rootNamespace = decl.Namespace.QualifiedName;
}
names.Add(decl.Visit(this));
return string.Join("::", names);
var result = string.Join("::", names);
var translationUnit = decl.Namespace as TranslationUnit;
if (translationUnit != null && translationUnit.HasFunctions &&
rootNamespace == translationUnit.FileNameWithoutExtension)
return "::" + result;
return result;
}
public string VisitClassDecl(Class @class)

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

@ -553,7 +553,7 @@ namespace CppSharp.Generators.CSharp @@ -553,7 +553,7 @@ namespace CppSharp.Generators.CSharp
if (@class.IsStatic || ctor.IsMoveConstructor)
continue;
if (!ctor.IsGenerated && !(Options.GenerateCopyConstructors && ctor.IsCopyConstructor))
if (!ctor.IsGenerated)
continue;
if (ctor.IsDefaultConstructor && !@class.HasNonTrivialDefaultConstructor)
@ -1971,15 +1971,10 @@ namespace CppSharp.Generators.CSharp @@ -1971,15 +1971,10 @@ namespace CppSharp.Generators.CSharp
PushBlock(CSharpBlockKind.Method);
WriteLine("private static {0}.Internal* __CopyValue({0}.Internal native)", className);
WriteStartBraceIndent();
if (@class.HasNonTrivialCopyConstructor && Options.GenerateCopyConstructors)
{
// Find a valid copy constructor overload.
var copyCtorMethod = @class.Methods.FirstOrDefault(method =>
method.IsCopyConstructor);
if (copyCtorMethod == null)
throw new NotSupportedException("Expected a valid copy constructor");
if (@class.HasNonTrivialCopyConstructor && copyCtorMethod != null && copyCtorMethod.IsGenerated)
{
// Allocate memory for a new native object and call the ctor.
WriteLine("var ret = Marshal.AllocHGlobal({0});", @class.Layout.Size);
WriteLine("{0}.Internal.{1}(ret, new global::System.IntPtr(&native));",

1
src/Generator/Options.cs

@ -96,7 +96,6 @@ namespace CppSharp @@ -96,7 +96,6 @@ namespace CppSharp
public bool GenerateInternalImports;
public bool GenerateClassMarshals;
public bool GenerateInlines;
public bool GenerateCopyConstructors;
public bool UseHeaderDirectories;
/// <summary>

12
src/Generator/Passes/FindSymbolsPass.cs

@ -4,6 +4,18 @@ namespace CppSharp.Passes @@ -4,6 +4,18 @@ namespace CppSharp.Passes
{
public class FindSymbolsPass : TranslationUnitPass
{
public FindSymbolsPass()
{
Options.VisitClassBases = false;
Options.VisitFunctionParameters = false;
Options.VisitFunctionReturnType = false;
Options.VisitNamespaceEnums = false;
Options.VisitNamespaceTemplates = false;
Options.VisitNamespaceTypedefs = false;
Options.VisitTemplateArguments = false;
Options.VisitClassFields = false;
}
public override bool VisitDeclaration(Declaration decl)
{
if (!base.VisitDeclaration(decl))

1
tests/CSharp/CSharp.cs

@ -128,7 +128,6 @@ namespace CppSharp.Tests @@ -128,7 +128,6 @@ namespace CppSharp.Tests
{
driver.Options.GenerateInterfacesForMultipleInheritance = true;
driver.Options.GeneratePropertiesAdvanced = true;
driver.Options.GenerateCopyConstructors = true;
// To ensure that calls to constructors in conversion operators
// are not ambiguous with multiple inheritance pass enabled.
driver.Options.GenerateConversionOperators = true;

1
tests/Common/Common.cs

@ -23,7 +23,6 @@ namespace CppSharp.Tests @@ -23,7 +23,6 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.GenerateCopyConstructors = true;
driver.Options.MarshalCharAsManagedChar = true;
driver.Options.GenerateProperties = true;
driver.Options.GenerateConversionOperators = true;

1
tests/TypeMaps/TypeMaps.cs

@ -15,7 +15,6 @@ namespace CppSharp.Tests @@ -15,7 +15,6 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.GenerateCopyConstructors = true;
driver.Options.MarshalCharAsManagedChar = true;
driver.Options.GenerateProperties = true;
driver.Options.GenerateConversionOperators = true;

4
tests/VTables/VTables.cpp

@ -38,6 +38,10 @@ BaseClassVirtual::BaseClassVirtual() @@ -38,6 +38,10 @@ BaseClassVirtual::BaseClassVirtual()
{
}
BaseClassVirtual::BaseClassVirtual(const BaseClassVirtual& other)
{
}
int BaseClassVirtual::virtualCallRetInt(BaseClassVirtual* base)
{
return base->retInt();

1
tests/VTables/VTables.h

@ -23,6 +23,7 @@ class DLL_API BaseClassVirtual @@ -23,6 +23,7 @@ class DLL_API BaseClassVirtual
{
public:
BaseClassVirtual();
BaseClassVirtual(const BaseClassVirtual& other);
static int virtualCallRetInt(BaseClassVirtual* base);
virtual int retInt();
static BaseClassVirtual getBase();

Loading…
Cancel
Save