Browse Source

Fixed default args with enum values when the enum is in a dependency.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/476/head
Dimitar Dobrev 10 years ago
parent
commit
277a6f5ac7
  1. 8
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  2. 4
      tests/NamespacesDerived/NamespacesDerived.cpp
  3. 2
      tests/NamespacesDerived/NamespacesDerived.cs
  4. 2
      tests/NamespacesDerived/NamespacesDerived.h

8
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -167,16 +167,14 @@ namespace CppSharp.Passes @@ -167,16 +167,14 @@ namespace CppSharp.Passes
return decl.IsValueType ? true : (bool?) null;
}
private static bool CheckForEnumValue(Expression arg, Type desugared)
private bool CheckForEnumValue(Expression arg, Type desugared)
{
var enumItem = arg.Declaration as Enumeration.Item;
if (enumItem != null)
{
arg.String = string.Format("{0}{1}{2}.{3}",
arg.String = string.Format("{0}{1}.{2}",
desugared.IsPrimitiveType() ? "(int) " : string.Empty,
string.IsNullOrEmpty(enumItem.Namespace.Namespace.Name)
? string.Empty
: enumItem.Namespace.Namespace.Name + ".", enumItem.Namespace.Name, enumItem.Name);
new CSharpTypePrinter(Driver).VisitEnumDecl((Enumeration) enumItem.Namespace), enumItem.Name);
return true;
}

4
tests/NamespacesDerived/NamespacesDerived.cpp

@ -58,3 +58,7 @@ void Derived2::setNestedNSComponent(OverlappingNamespace::InDerivedLib c) @@ -58,3 +58,7 @@ void Derived2::setNestedNSComponent(OverlappingNamespace::InDerivedLib c)
{
nestedNSComponent = c;
}
void Derived2::defaultEnumValueFromDependency(OverlappingNamespace::ColorsEnum c)
{
}

2
tests/NamespacesDerived/NamespacesDerived.cs

@ -1,4 +1,3 @@ @@ -1,4 +1,3 @@
using System;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Utils;
@ -15,6 +14,7 @@ namespace CppSharp.Tests @@ -15,6 +14,7 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.GenerateDefaultValuesForArguments = true;
}
public override void Preprocess(Driver driver, ASTContext ctx)

2
tests/NamespacesDerived/NamespacesDerived.h

@ -56,5 +56,5 @@ public: @@ -56,5 +56,5 @@ public:
OverlappingNamespace::InDerivedLib nestedNSComponent;
OverlappingNamespace::InDerivedLib getNestedNSComponent();
void setNestedNSComponent(OverlappingNamespace::InDerivedLib);
void defaultEnumValueFromDependency(OverlappingNamespace::ColorsEnum c = OverlappingNamespace::ColorsEnum::black);
};

Loading…
Cancel
Save