Browse Source

Extended the C# end with support for free constants and fixed their printing.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/681/head
Dimitar Dobrev 9 years ago
parent
commit
4b82838b54
  1. 15
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 4
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  3. 5
      tests/CSharp/AnotherUnit.cpp
  4. 5
      tests/CSharp/AnotherUnit.h
  5. 1
      tests/CSharp/CSharp.Tests.cs
  6. 4
      tests/CSharp/CSharp.cpp
  7. 1
      tests/CSharp/CSharp.h

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

@ -284,7 +284,8 @@ namespace CppSharp.Generators.CSharp @@ -284,7 +284,8 @@ namespace CppSharp.Generators.CSharp
GenerateClassTemplateSpecializationInternal(@class);
}
if (context.HasFunctions)
if (context.HasFunctions || (!(context is Class) && context.Variables.Any(
v => v.IsGenerated && v.Access == AccessSpecifier.Public)))
{
PushBlock(CSharpBlockKind.Functions);
var parentName = Helpers.SafeIdentifier(context.TranslationUnit.FileNameWithoutExtension);
@ -313,6 +314,10 @@ namespace CppSharp.Generators.CSharp @@ -313,6 +314,10 @@ namespace CppSharp.Generators.CSharp
GenerateFunction(function, parentName);
}
foreach (var variable in context.Variables.Where(
v => v.IsGenerated && v.Access == AccessSpecifier.Public))
GenerateVariable(null, variable);
WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -1250,9 +1255,7 @@ namespace CppSharp.Generators.CSharp @@ -1250,9 +1255,7 @@ namespace CppSharp.Generators.CSharp
if (variable.Access != AccessSpecifier.Public)
continue;
var type = variable.Type;
GenerateVariable(@class, type, variable);
GenerateVariable(@class, variable);
}
}
@ -1354,12 +1357,12 @@ namespace CppSharp.Generators.CSharp @@ -1354,12 +1357,12 @@ namespace CppSharp.Generators.CSharp
return string.Format("this[{0}]", FormatMethodParameters(@params));
}
private void GenerateVariable(Class @class, Type type, Variable variable)
private void GenerateVariable(Class @class, Variable variable)
{
PushBlock(CSharpBlockKind.Variable);
GenerateDeclarationCommon(variable);
WriteLine("public static {0} {1}", type, variable.Name);
WriteLine("public static {0} {1}", variable.Type, variable.Name);
WriteStartBraceIndent();
GeneratePropertyGetter(variable.QualifiedType, variable, @class);

4
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -671,6 +671,8 @@ namespace CppSharp.Generators.CSharp @@ -671,6 +671,8 @@ namespace CppSharp.Generators.CSharp
names.Add(decl.Name);
ctx = decl.Namespace;
}
if (decl is Variable && !(decl.Namespace is Class))
names.Add(decl.TranslationUnit.FileNameWithoutExtension);
while (!(ctx is TranslationUnit))
{
if (!string.IsNullOrWhiteSpace(ctx.Name))
@ -693,7 +695,7 @@ namespace CppSharp.Generators.CSharp @@ -693,7 +695,7 @@ namespace CppSharp.Generators.CSharp
public CSharpTypePrinterResult VisitVariableDecl(Variable variable)
{
return variable.Name;
return GetNestedQualifiedName(variable);
}
public CSharpTypePrinterResult VisitClassTemplateDecl(ClassTemplate template)

5
tests/CSharp/AnotherUnit.cpp

@ -3,3 +3,8 @@ @@ -3,3 +3,8 @@
void functionInAnotherUnit()
{
}
namespace HasFreeConstant
{
extern const int DLL_API FREE_CONSTANT_IN_NAMESPACE = 5;
}

5
tests/CSharp/AnotherUnit.h

@ -11,3 +11,8 @@ class TemplateInAnotherUnit @@ -11,3 +11,8 @@ class TemplateInAnotherUnit
class ForwardInOtherUnitButSameModule
{
};
namespace HasFreeConstant
{
extern const int DLL_API FREE_CONSTANT_IN_NAMESPACE;
}

1
tests/CSharp/CSharp.Tests.cs

@ -215,6 +215,7 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -215,6 +215,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
methodsWithDefaultValues.DefaultWithDirectIntConstant();
methodsWithDefaultValues.DefaultWithEnumInLowerCasedNameSpace();
methodsWithDefaultValues.DefaultWithCharFromInt();
methodsWithDefaultValues.DefaultWithFreeConstantInNameSpace();
}
}

4
tests/CSharp/CSharp.cpp

@ -587,6 +587,10 @@ void MethodsWithDefaultValues::defaultWithCharFromInt(char c) @@ -587,6 +587,10 @@ void MethodsWithDefaultValues::defaultWithCharFromInt(char c)
{
}
void MethodsWithDefaultValues::defaultWithFreeConstantInNameSpace(int c)
{
}
int MethodsWithDefaultValues::getA()
{
return m_foo.A;

1
tests/CSharp/CSharp.h

@ -412,6 +412,7 @@ public: @@ -412,6 +412,7 @@ public:
void defaultWithDirectIntConstant(int arg = intConstant);
void defaultWithEnumInLowerCasedNameSpace(lowerCaseNameSpace::Enum e = lowerCaseNameSpace::Enum::Item2);
void defaultWithCharFromInt(char c = 32);
void defaultWithFreeConstantInNameSpace(int c = HasFreeConstant::FREE_CONSTANT_IN_NAMESPACE);
int getA();
private:
Foo m_foo;

Loading…
Cancel
Save