Browse Source

Use fixed c# statement when accessing fixed struct members

pull/821/head
Gilad Levi 8 years ago
parent
commit
5302f5870c
  1. 24
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 2
      tests/CSharp/CSharp.cs
  3. 8
      tests/CSharp/CSharp.h

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

@ -308,12 +308,12 @@ namespace CppSharp.Generators.CSharp @@ -308,12 +308,12 @@ namespace CppSharp.Generators.CSharp
}
PushBlock(BlockKind.Class);
GenerateDeclarationCommon(@class);
GenerateDeclarationCommon(@class);
GenerateClassSpecifier(@class);
NewLine();
WriteStartBraceIndent();
if (!@class.IsAbstractImpl)
GenerateClassInternals(@class);
@ -569,7 +569,7 @@ namespace CppSharp.Generators.CSharp @@ -569,7 +569,7 @@ namespace CppSharp.Generators.CSharp
// private classes must be visible to because the internal structs can be used in dependencies
// the proper fix is InternalsVisibleTo
var keywords = new List<string>();
keywords.Add(@class.Access == AccessSpecifier.Protected ? "protected internal" : "public");
keywords.Add("unsafe");
@ -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)
{
@ -1077,7 +1077,7 @@ namespace CppSharp.Generators.CSharp @@ -1077,7 +1077,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);
@ -1284,7 +1284,7 @@ namespace CppSharp.Generators.CSharp @@ -1284,7 +1284,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateVariable(Class @class, Variable variable)
{
PushBlock(BlockKind.Variable);
GenerateDeclarationCommon(variable);
WriteLine("public static {0} {1}", variable.Type, variable.Name);
WriteStartBraceIndent();
@ -1423,7 +1423,7 @@ namespace CppSharp.Generators.CSharp @@ -1423,7 +1423,7 @@ namespace CppSharp.Generators.CSharp
if (Context.ParserOptions.IsMicrosoftAbi)
WriteLine("__OriginalVTables = new void*[] {{ {0} }};",
string.Join(", ",
@class.Layout.VTablePointers.Select(v =>
@class.Layout.VTablePointers.Select(v =>
$"*(void**) ({Helpers.InstanceIdentifier} + {v.Offset})")));
else
WriteLine(
@ -1565,7 +1565,7 @@ namespace CppSharp.Generators.CSharp @@ -1565,7 +1565,7 @@ namespace CppSharp.Generators.CSharp
if (method.IsGenerated)
{
WriteLine("{0}.{1}({2});", Helpers.TargetIdentifier,
method.Name, string.Join(", ", marshals));
method.Name, string.Join(", ", marshals));
}
else
{
@ -2156,7 +2156,7 @@ namespace CppSharp.Generators.CSharp @@ -2156,7 +2156,7 @@ namespace CppSharp.Generators.CSharp
else if (method.ExplicitInterfaceImpl != null)
Write("{0} {1}.{2}(", method.OriginalReturnType,
method.ExplicitInterfaceImpl.Name, functionName);
else if (method.OperatorKind == CXXOperatorKind.Conversion ||
else if (method.OperatorKind == CXXOperatorKind.Conversion ||
method.OperatorKind == CXXOperatorKind.ExplicitConversion)
Write("{0} {1}(", functionName, method.OriginalReturnType);
else
@ -2277,7 +2277,7 @@ namespace CppSharp.Generators.CSharp @@ -2277,7 +2277,7 @@ namespace CppSharp.Generators.CSharp
Class @class;
return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue
? "ref param" + index++
: (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++
: (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++
: ExpressionPrinter.VisitParameter(p));
}
@ -2361,7 +2361,7 @@ namespace CppSharp.Generators.CSharp @@ -2361,7 +2361,7 @@ namespace CppSharp.Generators.CSharp
}
else
{
WriteLine("return {0}.GetHashCode();", Helpers.InstanceIdentifier);
WriteLine("return {0}.GetHashCode();", Helpers.InstanceIdentifier);
}
WriteCloseBraceIndent();
}
@ -2729,7 +2729,7 @@ namespace CppSharp.Generators.CSharp @@ -2729,7 +2729,7 @@ namespace CppSharp.Generators.CSharp
if (needsFixedThis && operatorParam == null)
WriteCloseBraceIndent();
var numFixedBlocks = @params.Count(param => param.HasUsingBlock);
for(var i = 0; i < numFixedBlocks; ++i)
WriteCloseBraceIndent();

2
tests/CSharp/CSharp.cs

@ -33,7 +33,7 @@ namespace CppSharp.Tests @@ -33,7 +33,7 @@ namespace CppSharp.Tests
ctx.SetClassAsValueType("QPoint");
ctx.SetClassAsValueType("QSize");
ctx.SetClassAsValueType("QRect");
ctx.SetClassAsValueType("StructTestArrayTypeFromTypedef");
ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor");
}

8
tests/CSharp/CSharp.h

@ -1169,4 +1169,10 @@ struct DLL_API ForwardDeclaredStruct { @@ -1169,4 +1169,10 @@ struct DLL_API ForwardDeclaredStruct {
};
DLL_API ForwardDeclaredStruct* createForwardDeclaredStruct(int i);
DLL_API int useForwardDeclaredStruct(ForwardDeclaredStruct* s);
DLL_API int useForwardDeclaredStruct(ForwardDeclaredStruct* s);
typedef char charsArrayType[13];
struct StructTestArrayTypeFromTypedef
{
charsArrayType arr;
};
Loading…
Cancel
Save