Skip to content

Commit 1408038

Browse files
committed
Fixed the generated C++ for symbols when protected classes need them.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent b22abfc commit 1408038

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/Generator/Passes/SymbolsCodeGenerator.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,23 @@ private void WrapConstructor(Method method)
106106
{
107107
Write(GetDerivedType(@namespace, wrapper));
108108
Write($"{wrapper}{@namespace}");
109-
Write($@"({(string.Join(", ", method.Parameters.Select(
110-
p => cppTypePrinter.VisitParameter(p))))})");
109+
Write($@"({string.Join(", ", method.Parameters.Select(
110+
p => cppTypePrinter.VisitParameter(p)))})");
111111
WriteLine($": {@namespace}({@params}) {{}} }};");
112112
Write($"extern \"C\" {{ void {wrapper}({signature}) ");
113113
WriteLine($"{{ new (instance) {wrapper}{@namespace}({@params}); }} }}");
114114
}
115115
else
116116
{
117-
Write($"extern \"C\" {{ void {wrapper}({signature}) ");
118-
WriteLine($"{{ new (instance) {@namespace}({@params}); }} }}");
117+
Write($"extern \"C\" ");
118+
if (method.Namespace.Access == AccessSpecifier.Protected)
119+
Write($@"{{ class {wrapper}{method.Namespace.Namespace.Name} : public {
120+
method.Namespace.Namespace.Visit(cppTypePrinter)} ");
121+
Write($"{{ void {wrapper}({signature}) ");
122+
Write($"{{ new (instance) {@namespace}({@params}); }} }}");
123+
if (method.Namespace.Access == AccessSpecifier.Protected)
124+
Write("; }");
125+
NewLine();
119126
}
120127

121128
foreach (var param in method.Parameters.Where(p =>
@@ -149,14 +156,23 @@ private void WrapDestructor(Method method)
149156
Write(GetDerivedType(@namespace, wrapper));
150157
else
151158
Write("extern \"C\" { ");
159+
if (method.Namespace.Access == AccessSpecifier.Protected)
160+
Write($@"class {wrapper}{method.Namespace.Namespace.Name} : public {
161+
method.Namespace.Namespace.Visit(cppTypePrinter)} {{ ");
152162
Write($"void {wrapper}");
153163
if (isProtected)
154164
Write("protected");
155-
WriteLine($@"({@namespace}* instance) {{ instance->~{
165+
Write($@"({@namespace}* instance) {{ instance->~{
156166
method.Namespace.OriginalName}(); }} }}");
157167
if (isProtected)
158-
WriteLine($@"void {wrapper}({@namespace} instance) {{ {
159-
wrapper}{@namespace}::{wrapper}protected(instance); }}");
168+
{
169+
NewLine();
170+
Write($@"void {wrapper}({@namespace} instance) {{ {
171+
wrapper}{@namespace}::{wrapper}protected(instance); }}");
172+
}
173+
if (method.Namespace.Access == AccessSpecifier.Protected)
174+
Write("; }");
175+
NewLine();
160176
}
161177

162178
private void TakeFunctionAddress(Function function)
@@ -177,6 +193,9 @@ private void TakeFunctionAddress(Function function)
177193
WriteRedeclaration(function, returnType, signature, functionName);
178194

179195
var method = function as Method;
196+
if (function.Namespace.Access == AccessSpecifier.Protected)
197+
Write($@"class {wrapper}{function.Namespace.Namespace.Name} : public {
198+
function.Namespace.Namespace.Visit(cppTypePrinter)} {{ ");
180199
Write($@"{returnType} ({(method != null && !method.IsStatic ?
181200
(@namespace + "::") : string.Empty)}*{wrapper}){signature}");
182201
if (function.Access == AccessSpecifier.Protected)
@@ -189,6 +208,8 @@ private void TakeFunctionAddress(Function function)
189208
{
190209
Write($" = &{functionName};");
191210
}
211+
if (function.Namespace.Access == AccessSpecifier.Protected)
212+
Write(" };");
192213
NewLine();
193214
}
194215

0 commit comments

Comments
 (0)