Browse Source

Merge branch 'master' of https://github.com/giladlevi/CppSharp

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/829/head
Dimitar Dobrev 9 years ago
parent
commit
0b858668d2
  1. 1
      build/Tests.lua
  2. 4
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 2
      src/Generator/Library.cs
  4. 8
      tests/CSharp/CSharp.Tests.cs
  5. 19
      tests/CSharp/CSharp.cs
  6. 9
      tests/CSharp/CSharp.h

1
build/Tests.lua

@ -55,6 +55,7 @@ function SetupTestGeneratorProject(name, depends) @@ -55,6 +55,7 @@ function SetupTestGeneratorProject(name, depends)
dependson { name .. ".Native" }
linktable = {
"System",
"System.Core",
"CppSharp",
"CppSharp.AST",

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

@ -833,7 +833,7 @@ namespace CppSharp.Generators.CSharp @@ -833,7 +833,7 @@ namespace CppSharp.Generators.CSharp
var marshal = new CSharpMarshalManagedToNativePrinter(ctx);
ctx.Declaration = field;
var arrayType = field.Type as ArrayType;
var arrayType = field.Type as ArrayType ?? field.QualifiedType.Type.Desugar() as ArrayType;
if (arrayType != null && @class.IsValueType)
{
@ -1078,7 +1078,7 @@ namespace CppSharp.Generators.CSharp @@ -1078,7 +1078,7 @@ namespace CppSharp.Generators.CSharp
TypePrinter.PopContext();
var arrayType = field.Type as ArrayType;
var arrayType = field.Type as ArrayType ?? field.QualifiedType.Type.Desugar() as ArrayType;
if (arrayType != null && @class.IsValueType)
ctx.ReturnVarName = HandleValueArray(arrayType, field);

2
src/Generator/Library.cs

@ -117,6 +117,8 @@ namespace CppSharp @@ -117,6 +117,8 @@ namespace CppSharp
static ulong ParseMacroExpression(string expression)
{
// TODO: Handle string expressions
if (expression.Length == 3 && expression[0] == '\'' && expression[2] == '\'') // '0' || 'A'
return expression[1]; // return the ASCI code of this character
long val;
return ParseToNumber(expression, out val) ? (ulong)val : 0;

8
tests/CSharp/CSharp.Tests.cs

@ -722,4 +722,12 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -722,4 +722,12 @@ public unsafe class CSharpTests : GeneratorTestFixture
var i = CSharp.CSharp.UseDuplicateDeclaredStruct(duplicateDeclaredIncompleteStruct);
Assert.AreEqual(10, i);
}
[Test]
public void TestMyMacroTestEnum()
{
var a = (MyMacroTestEnum)'1';
var b = (MyMacroTestEnum)'2';
Assert.IsTrue(a == MyMacroTestEnum.MY_MACRO_TEST_1 && b == MyMacroTestEnum.MY_MACRO_TEST_2);
}
}

19
tests/CSharp/CSharp.cs

@ -1,4 +1,7 @@ @@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
@ -33,8 +36,22 @@ namespace CppSharp.Tests @@ -33,8 +36,22 @@ namespace CppSharp.Tests
ctx.SetClassAsValueType("QPoint");
ctx.SetClassAsValueType("QSize");
ctx.SetClassAsValueType("QRect");
ctx.SetClassAsValueType("StructTestArrayTypeFromTypedef");
ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor");
var macroRegex = new Regex(@"(MY_MACRO_TEST_.*)");
List<string> list = new List<string>();
foreach (TranslationUnit unit in ctx.TranslationUnits)
{
if (unit.FilePath == "<invalid>" || unit.FileName == "CSharp.h")
foreach (var macro in unit.PreprocessedEntities.OfType<MacroDefinition>())
{
Match match = macroRegex.Match(macro.Name);
if (match.Success) list.Add(macro.Name);
}
}
var enumTest = ctx.GenerateEnumFromMacros("MyMacroTestEnum", list.ToArray());
enumTest.Namespace = new Namespace() {Name = "MacroTest"};
}
public override void Postprocess(Driver driver, ASTContext ctx)

9
tests/CSharp/CSharp.h

@ -1170,3 +1170,12 @@ struct DLL_API ForwardDeclaredStruct { @@ -1170,3 +1170,12 @@ struct DLL_API ForwardDeclaredStruct {
DLL_API ForwardDeclaredStruct* createForwardDeclaredStruct(int i);
DLL_API int useForwardDeclaredStruct(ForwardDeclaredStruct* s);
typedef char charsArrayType[13];
struct StructTestArrayTypeFromTypedef
{
charsArrayType arr;
};
#define MY_MACRO_TEST_1 '1'
#define MY_MACRO_TEST_2 '2'

Loading…
Cancel
Save