Browse Source

Fixed the inheritance of a linked class.

pull/395/head
Pyry Kontio 11 years ago committed by Joao Matos
parent
commit
50dff6288b
  1. 4
      src/AST/Class.cs
  2. 6
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 45
      tests/NamespacesBase/NamespacesBase.cs
  4. 49
      tests/NamespacesDerived/NamespacesDerived.cs

4
src/AST/Class.cs

@ -161,13 +161,13 @@ namespace CppSharp.AST @@ -161,13 +161,13 @@ namespace CppSharp.AST
}
}
public bool HasGeneratedBase
public bool HasNonIgnoredBase
{
get
{
return HasBaseClass && !IsValueType
&& !Bases[0].Class.IsValueType
&& Bases[0].Class.IsGenerated;
&& Bases[0].Class.GenerationKind != GenerationKind.None;
}
}

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

@ -116,7 +116,7 @@ namespace CppSharp.Generators.CSharp @@ -116,7 +116,7 @@ namespace CppSharp.Generators.CSharp
ctx = ctx.Namespace;
}
if (Options.GenerateLibraryNamespace)
if (decl.GenerationKind == GenerationKind.Generate && Options.GenerateLibraryNamespace)
names.Add(Options.OutputNamespace);
names.Reverse();
@ -744,7 +744,7 @@ namespace CppSharp.Generators.CSharp @@ -744,7 +744,7 @@ namespace CppSharp.Generators.CSharp
var bases = new List<string>();
var needsBase = @class.HasGeneratedBase && @class.IsGenerated;
var needsBase = @class.HasNonIgnoredBase && @class.IsGenerated;
if (needsBase)
{
@ -1912,7 +1912,7 @@ namespace CppSharp.Generators.CSharp @@ -1912,7 +1912,7 @@ namespace CppSharp.Generators.CSharp
{
PushBlock(CSharpBlockKind.Method);
WriteLine("public static {0}{1} {2}(global::System.IntPtr native)",
@class.HasGeneratedBase && !@class.BaseClass.IsAbstract ? "new " : string.Empty,
@class.HasNonIgnoredBase && !@class.BaseClass.IsAbstract ? "new " : string.Empty,
safeIdentifier, Helpers.CreateInstanceIdentifier);
WriteStartBraceIndent();
WriteLine("return new {0}(({1}.Internal*) native);", safeIdentifier, className);

45
tests/NamespacesBase/NamespacesBase.cs

@ -1,34 +1,10 @@ @@ -1,34 +1,10 @@
?using System;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Generators.CSharp;
using CppSharp.Passes;
using CppSharp.Types;
using CppSharp.Utils;
using Attribute = CppSharp.AST.Attribute;
using Type = CppSharp.AST.Type;
namespace CppSharp.Tests
{
public class TestAttributesPass : TranslationUnitPass
{
public override bool VisitFunctionDecl(Function function)
{
if (AlreadyVisited(function) || function.Name != "obsolete")
return false;
var attribute = new Attribute
{
Type = typeof(ObsoleteAttribute),
Value = string.Format("\"{0} is obsolete.\"", function.Name)
};
function.Attributes.Add(attribute);
return base.VisitFunctionDecl(function);
}
}
public class NamespacesBaseTests : GeneratorTest
{
@ -39,37 +15,18 @@ namespace CppSharp.Tests @@ -39,37 +15,18 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.GenerateAbstractImpls = true;
driver.Options.GenerateInterfacesForMultipleInheritance = true;
driver.Options.GeneratePropertiesAdvanced = true;
driver.Options.GenerateVirtualTables = 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;
driver.TranslationUnitPasses.AddPass(new TestAttributesPass());
driver.Options.MarshalCharAsManagedChar = true;
driver.Options.GenerateDefaultValuesForArguments = true;
driver.Options.GenerateSingleCSharpFile = true;
}
public override void Preprocess(Driver driver, ASTContext ctx)
{
ctx.SetClassAsValueType("TestCopyConstructorVal");
ctx.SetClassAsValueType("QGenericArgument");
ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor");
}
public override void Postprocess(Driver driver, ASTContext ctx)
{
new CaseRenamePass(
RenameTargets.Function | RenameTargets.Method | RenameTargets.Property | RenameTargets.Delegate,
RenameCasePattern.UpperCamelCase).VisitLibrary(driver.ASTContext);
}
}
public class Namespaces {
public class NamespacesBase {
public static void Main(string[] args)
{

49
tests/NamespacesDerived/NamespacesDerived.cs

@ -1,34 +1,10 @@ @@ -1,34 +1,10 @@
?using System;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Generators.CSharp;
using CppSharp.Passes;
using CppSharp.Types;
using CppSharp.Utils;
using Attribute = CppSharp.AST.Attribute;
using Type = CppSharp.AST.Type;
namespace CppSharp.Tests
{
public class TestAttributesPass : TranslationUnitPass
{
public override bool VisitFunctionDecl(Function function)
{
if (AlreadyVisited(function) || function.Name != "obsolete")
return false;
var attribute = new Attribute
{
Type = typeof(ObsoleteAttribute),
Value = string.Format("\"{0} is obsolete.\"", function.Name)
};
function.Attributes.Add(attribute);
return base.VisitFunctionDecl(function);
}
}
public class NamespacesDerivedTests : GeneratorTest
{
@ -39,19 +15,6 @@ namespace CppSharp.Tests @@ -39,19 +15,6 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.GenerateAbstractImpls = true;
driver.Options.GenerateInterfacesForMultipleInheritance = true;
driver.Options.GeneratePropertiesAdvanced = true;
driver.Options.GenerateVirtualTables = 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;
driver.TranslationUnitPasses.AddPass(new TestAttributesPass());
driver.Options.MarshalCharAsManagedChar = true;
driver.Options.GenerateDefaultValuesForArguments = true;
driver.Options.GenerateSingleCSharpFile = true;
driver.Options.DependentNameSpaces.Add("NamespacesBase");
}
public override void Preprocess(Driver driver, ASTContext ctx)
@ -60,26 +23,18 @@ namespace CppSharp.Tests @@ -60,26 +23,18 @@ namespace CppSharp.Tests
{
if (unit.FileName != "Derived.h")
{
unit.ExplicityIgnored = true;
unit.GenerationKind = GenerationKind.Link;
}
}
ctx.SetClassAsValueType("TestCopyConstructorVal");
ctx.SetClassAsValueType("QGenericArgument");
ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor");
}
public override void Postprocess(Driver driver, ASTContext ctx)
{
new CaseRenamePass(
RenameTargets.Function | RenameTargets.Method | RenameTargets.Property | RenameTargets.Delegate,
RenameCasePattern.UpperCamelCase).VisitLibrary(driver.ASTContext);
}
}
public class Namespaces {
public class NamespacesDerived {
public static void Main(string[] args)
{

Loading…
Cancel
Save