Skip to content

Commit f97ad43

Browse files
committed
Generate valid C# for base types with public fields of const char*
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 0d8b236 commit f97ad43

File tree

8 files changed

+130
-21
lines changed

8 files changed

+130
-21
lines changed

src/AST/ClassExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ public static bool HasDependentValueFieldInLayout(this Class @class)
242242
b => b.Class).Any(HasDependentValueFieldInLayout);
243243
}
244244

245+
public static IEnumerable<Property> GetConstCharFieldProperties(this Class @class) =>
246+
@class.Properties.Where(p => p.HasGetter && p.HasSetter &&
247+
p.Field?.QualifiedType.Type.IsConstCharString() == true);
248+
245249
private static bool IsValueDependent(Type type)
246250
{
247251
var desugared = type.Desugar();

src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16620,6 +16620,7 @@ public unsafe partial class LabelStmt : global::CppSharp.Parser.AST.Stmt, IDispo
1662016620
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
1662116621
}
1662216622

16623+
private bool __name_OwnsNativeMemory = false;
1662316624
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
1662416625
{
1662516626
return new LabelStmt(native.ToPointer(), skipVTables);
@@ -16677,6 +16678,8 @@ public LabelStmt(global::CppSharp.Parser.AST.LabelStmt _0)
1667716678
__ownsNativeInstance = true;
1667816679
NativeToManagedMap[__Instance] = this;
1667916680
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
16681+
if (_0.__name_OwnsNativeMemory)
16682+
this.Name = _0.Name;
1668016683
}
1668116684

1668216685
public global::CppSharp.Parser.SourceLocation IdentLoc
@@ -16715,6 +16718,9 @@ public string Name
1671516718

1671616719
set
1671716720
{
16721+
if (__name_OwnsNativeMemory)
16722+
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
16723+
__name_OwnsNativeMemory = true;
1671816724
if (value == null)
1671916725
{
1672016726
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@@ -25167,6 +25173,7 @@ public unsafe partial class CastExpr : global::CppSharp.Parser.AST.Expr, IDispos
2516725173
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
2516825174
}
2516925175

25176+
private bool __castKindName_OwnsNativeMemory = false;
2517025177
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
2517125178
{
2517225179
return new CastExpr(native.ToPointer(), skipVTables);
@@ -25233,6 +25240,8 @@ public CastExpr(global::CppSharp.Parser.AST.CastExpr _0)
2523325240
__ownsNativeInstance = true;
2523425241
NativeToManagedMap[__Instance] = this;
2523525242
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
25243+
if (_0.__castKindName_OwnsNativeMemory)
25244+
this.CastKindName = _0.CastKindName;
2523625245
}
2523725246

2523825247
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@@ -25276,6 +25285,9 @@ public string CastKindName
2527625285

2527725286
set
2527825287
{
25288+
if (__castKindName_OwnsNativeMemory)
25289+
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
25290+
__castKindName_OwnsNativeMemory = true;
2527925291
if (value == null)
2528025292
{
2528125293
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@@ -30958,6 +30970,7 @@ public unsafe partial class CXXNamedCastExpr : global::CppSharp.Parser.AST.Expli
3095830970
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
3095930971
}
3096030972

30973+
private bool __castName_OwnsNativeMemory = false;
3096130974
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
3096230975
{
3096330976
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@@ -31024,6 +31037,8 @@ public CXXNamedCastExpr(global::CppSharp.Parser.AST.CXXNamedCastExpr _0)
3102431037
__ownsNativeInstance = true;
3102531038
NativeToManagedMap[__Instance] = this;
3102631039
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
31040+
if (_0.__castName_OwnsNativeMemory)
31041+
this.CastName = _0.CastName;
3102731042
}
3102831043

3102931044
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@@ -31040,6 +31055,9 @@ public string CastName
3104031055

3104131056
set
3104231057
{
31058+
if (__castName_OwnsNativeMemory)
31059+
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
31060+
__castName_OwnsNativeMemory = true;
3104331061
if (value == null)
3104431062
{
3104531063
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16622,6 +16622,7 @@ public unsafe partial class LabelStmt : global::CppSharp.Parser.AST.Stmt, IDispo
1662216622
internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
1662316623
}
1662416624

16625+
private bool __name_OwnsNativeMemory = false;
1662516626
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
1662616627
{
1662716628
return new LabelStmt(native.ToPointer(), skipVTables);
@@ -16679,6 +16680,8 @@ public LabelStmt(global::CppSharp.Parser.AST.LabelStmt _0)
1667916680
__ownsNativeInstance = true;
1668016681
NativeToManagedMap[__Instance] = this;
1668116682
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
16683+
if (_0.__name_OwnsNativeMemory)
16684+
this.Name = _0.Name;
1668216685
}
1668316686

1668416687
public global::CppSharp.Parser.SourceLocation IdentLoc
@@ -16717,6 +16720,9 @@ public string Name
1671716720

1671816721
set
1671916722
{
16723+
if (__name_OwnsNativeMemory)
16724+
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
16725+
__name_OwnsNativeMemory = true;
1672016726
if (value == null)
1672116727
{
1672216728
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@@ -25171,6 +25177,7 @@ public unsafe partial class CastExpr : global::CppSharp.Parser.AST.Expr, IDispos
2517125177
internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
2517225178
}
2517325179

25180+
private bool __castKindName_OwnsNativeMemory = false;
2517425181
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
2517525182
{
2517625183
return new CastExpr(native.ToPointer(), skipVTables);
@@ -25237,6 +25244,8 @@ public CastExpr(global::CppSharp.Parser.AST.CastExpr _0)
2523725244
__ownsNativeInstance = true;
2523825245
NativeToManagedMap[__Instance] = this;
2523925246
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
25247+
if (_0.__castKindName_OwnsNativeMemory)
25248+
this.CastKindName = _0.CastKindName;
2524025249
}
2524125250

2524225251
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@@ -25280,6 +25289,9 @@ public string CastKindName
2528025289

2528125290
set
2528225291
{
25292+
if (__castKindName_OwnsNativeMemory)
25293+
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
25294+
__castKindName_OwnsNativeMemory = true;
2528325295
if (value == null)
2528425296
{
2528525297
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@@ -30963,6 +30975,7 @@ public unsafe partial class CXXNamedCastExpr : global::CppSharp.Parser.AST.Expli
3096330975
internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
3096430976
}
3096530977

30978+
private bool __castName_OwnsNativeMemory = false;
3096630979
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
3096730980
{
3096830981
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@@ -31029,6 +31042,8 @@ public CXXNamedCastExpr(global::CppSharp.Parser.AST.CXXNamedCastExpr _0)
3102931042
__ownsNativeInstance = true;
3103031043
NativeToManagedMap[__Instance] = this;
3103131044
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
31045+
if (_0.__castName_OwnsNativeMemory)
31046+
this.CastName = _0.CastName;
3103231047
}
3103331048

3103431049
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@@ -31045,6 +31060,9 @@ public string CastName
3104531060

3104631061
set
3104731062
{
31063+
if (__castName_OwnsNativeMemory)
31064+
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
31065+
__castName_OwnsNativeMemory = true;
3104831066
if (value == null)
3104931067
{
3105031068
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16619,6 +16619,7 @@ public unsafe partial class LabelStmt : global::CppSharp.Parser.AST.Stmt, IDispo
1661916619
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
1662016620
}
1662116621

16622+
private bool __name_OwnsNativeMemory = false;
1662216623
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
1662316624
{
1662416625
return new LabelStmt(native.ToPointer(), skipVTables);
@@ -16676,6 +16677,8 @@ public LabelStmt(global::CppSharp.Parser.AST.LabelStmt _0)
1667616677
__ownsNativeInstance = true;
1667716678
NativeToManagedMap[__Instance] = this;
1667816679
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
16680+
if (_0.__name_OwnsNativeMemory)
16681+
this.Name = _0.Name;
1667916682
}
1668016683

1668116684
public global::CppSharp.Parser.SourceLocation IdentLoc
@@ -16714,6 +16717,9 @@ public string Name
1671416717

1671516718
set
1671616719
{
16720+
if (__name_OwnsNativeMemory)
16721+
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
16722+
__name_OwnsNativeMemory = true;
1671716723
if (value == null)
1671816724
{
1671916725
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@@ -25166,6 +25172,7 @@ public unsafe partial class CastExpr : global::CppSharp.Parser.AST.Expr, IDispos
2516625172
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
2516725173
}
2516825174

25175+
private bool __castKindName_OwnsNativeMemory = false;
2516925176
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
2517025177
{
2517125178
return new CastExpr(native.ToPointer(), skipVTables);
@@ -25232,6 +25239,8 @@ public CastExpr(global::CppSharp.Parser.AST.CastExpr _0)
2523225239
__ownsNativeInstance = true;
2523325240
NativeToManagedMap[__Instance] = this;
2523425241
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
25242+
if (_0.__castKindName_OwnsNativeMemory)
25243+
this.CastKindName = _0.CastKindName;
2523525244
}
2523625245

2523725246
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@@ -25275,6 +25284,9 @@ public string CastKindName
2527525284

2527625285
set
2527725286
{
25287+
if (__castKindName_OwnsNativeMemory)
25288+
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
25289+
__castKindName_OwnsNativeMemory = true;
2527825290
if (value == null)
2527925291
{
2528025292
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@@ -30957,6 +30969,7 @@ public unsafe partial class CXXNamedCastExpr : global::CppSharp.Parser.AST.Expli
3095730969
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
3095830970
}
3095930971

30972+
private bool __castName_OwnsNativeMemory = false;
3096030973
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
3096130974
{
3096230975
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@@ -31023,6 +31036,8 @@ public CXXNamedCastExpr(global::CppSharp.Parser.AST.CXXNamedCastExpr _0)
3102331036
__ownsNativeInstance = true;
3102431037
NativeToManagedMap[__Instance] = this;
3102531038
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
31039+
if (_0.__castName_OwnsNativeMemory)
31040+
this.CastName = _0.CastName;
3102631041
}
3102731042

3102831043
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@@ -31039,6 +31054,9 @@ public string CastName
3103931054

3104031055
set
3104131056
{
31057+
if (__castName_OwnsNativeMemory)
31058+
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
31059+
__castName_OwnsNativeMemory = true;
3104231060
if (value == null)
3104331061
{
3104431062
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16619,6 +16619,7 @@ public unsafe partial class LabelStmt : global::CppSharp.Parser.AST.Stmt, IDispo
1661916619
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
1662016620
}
1662116621

16622+
private bool __name_OwnsNativeMemory = false;
1662216623
internal static new LabelStmt __CreateInstance(__IntPtr native, bool skipVTables = false)
1662316624
{
1662416625
return new LabelStmt(native.ToPointer(), skipVTables);
@@ -16676,6 +16677,8 @@ public LabelStmt(global::CppSharp.Parser.AST.LabelStmt _0)
1667616677
__ownsNativeInstance = true;
1667716678
NativeToManagedMap[__Instance] = this;
1667816679
*((global::CppSharp.Parser.AST.LabelStmt.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.LabelStmt.__Internal*) _0.__Instance);
16680+
if (_0.__name_OwnsNativeMemory)
16681+
this.Name = _0.Name;
1667916682
}
1668016683

1668116684
public global::CppSharp.Parser.SourceLocation IdentLoc
@@ -16714,6 +16717,9 @@ public string Name
1671416717

1671516718
set
1671616719
{
16720+
if (__name_OwnsNativeMemory)
16721+
Marshal.FreeHGlobal(((__Internal*)__Instance)->name);
16722+
__name_OwnsNativeMemory = true;
1671716723
if (value == null)
1671816724
{
1671916725
((__Internal*)__Instance)->name = global::System.IntPtr.Zero;
@@ -25166,6 +25172,7 @@ public unsafe partial class CastExpr : global::CppSharp.Parser.AST.Expr, IDispos
2516625172
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
2516725173
}
2516825174

25175+
private bool __castKindName_OwnsNativeMemory = false;
2516925176
internal static new CastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
2517025177
{
2517125178
return new CastExpr(native.ToPointer(), skipVTables);
@@ -25232,6 +25239,8 @@ public CastExpr(global::CppSharp.Parser.AST.CastExpr _0)
2523225239
__ownsNativeInstance = true;
2523325240
NativeToManagedMap[__Instance] = this;
2523425241
*((global::CppSharp.Parser.AST.CastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CastExpr.__Internal*) _0.__Instance);
25242+
if (_0.__castKindName_OwnsNativeMemory)
25243+
this.CastKindName = _0.CastKindName;
2523525244
}
2523625245

2523725246
public static implicit operator global::CppSharp.Parser.AST.CastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@@ -25275,6 +25284,9 @@ public string CastKindName
2527525284

2527625285
set
2527725286
{
25287+
if (__castKindName_OwnsNativeMemory)
25288+
Marshal.FreeHGlobal(((__Internal*)__Instance)->castKindName);
25289+
__castKindName_OwnsNativeMemory = true;
2527825290
if (value == null)
2527925291
{
2528025292
((__Internal*)__Instance)->castKindName = global::System.IntPtr.Zero;
@@ -30957,6 +30969,7 @@ public unsafe partial class CXXNamedCastExpr : global::CppSharp.Parser.AST.Expli
3095730969
internal static extern void cctor(__IntPtr __instance, __IntPtr _0);
3095830970
}
3095930971

30972+
private bool __castName_OwnsNativeMemory = false;
3096030973
internal static new CXXNamedCastExpr __CreateInstance(__IntPtr native, bool skipVTables = false)
3096130974
{
3096230975
return new CXXNamedCastExpr(native.ToPointer(), skipVTables);
@@ -31023,6 +31036,8 @@ public CXXNamedCastExpr(global::CppSharp.Parser.AST.CXXNamedCastExpr _0)
3102331036
__ownsNativeInstance = true;
3102431037
NativeToManagedMap[__Instance] = this;
3102531038
*((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) __Instance) = *((global::CppSharp.Parser.AST.CXXNamedCastExpr.__Internal*) _0.__Instance);
31039+
if (_0.__castName_OwnsNativeMemory)
31040+
this.CastName = _0.CastName;
3102631041
}
3102731042

3102831043
public static implicit operator global::CppSharp.Parser.AST.CXXNamedCastExpr(global::CppSharp.Parser.AST.StmtClass klass)
@@ -31039,6 +31054,9 @@ public string CastName
3103931054

3104031055
set
3104131056
{
31057+
if (__castName_OwnsNativeMemory)
31058+
Marshal.FreeHGlobal(((__Internal*)__Instance)->castName);
31059+
__castName_OwnsNativeMemory = true;
3104231060
if (value == null)
3104331061
{
3104431062
((__Internal*)__Instance)->castName = global::System.IntPtr.Zero;

0 commit comments

Comments
 (0)