Skip to content

Commit af8a758

Browse files
committed
Fixed the generated C++ for symbols to be compatible with Clang.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 10748cb commit af8a758

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/Generator/Passes/SymbolsCodeGenerator.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private string GetWrapper(Module module)
6969

7070
private static string GetDerivedType(string @namespace, string wrapper)
7171
{
72-
return $@"class {wrapper}{@namespace} : public {@namespace} {{ public: ";
72+
return $"class {wrapper}{@namespace} : public {@namespace} {{ public: ";
7373
}
7474

7575
private void WrapConstructor(Method method)
@@ -135,7 +135,7 @@ private void WrapDestructor(Method method)
135135
bool isProtected = method.Access == AccessSpecifier.Protected;
136136
string @namespace = method.Namespace.Visit(cppTypePrinter);
137137
if (isProtected)
138-
Write($"{GetDerivedType(@namespace, wrapper)}");
138+
Write(GetDerivedType(@namespace, wrapper));
139139
else
140140
Write("extern \"C\" { ");
141141
Write($"void {wrapper}");
@@ -173,13 +173,17 @@ private void TakeFunctionAddress(Function function)
173173
Write($@"{returnType} ({(method != null && !method.IsStatic ?
174174
(@namespace + "::") : string.Empty)}*{wrapper}){signature}");
175175
else
176-
Write($@"auto {wrapper}");
177-
Write($@" = &{functionName};");
176+
Write($"auto {wrapper}");
178177
if (function.Access == AccessSpecifier.Protected)
179178
{
179+
Write($" = &{wrapper}{@namespace}::{functionName};");
180180
WriteLine(" };");
181181
Write($"auto {wrapper}protected = {wrapper}{@namespace}::{wrapper};");
182182
}
183+
else
184+
{
185+
Write($" = &{functionName};");
186+
}
183187
NewLine();
184188
}
185189

@@ -189,19 +193,19 @@ private string GetSignature(Function function)
189193

190194
var paramTypes = string.Join(", ", function.Parameters.Where(
191195
p => p.Kind == ParameterKind.Regular).Select(
192-
p => cppTypePrinter.VisitParameterDecl(p)));
196+
cppTypePrinter.VisitParameterDecl));
193197

194198
var variadicType = function.IsVariadic ?
195-
(function.Parameters.Where(
196-
p => p.Kind == ParameterKind.Regular).Any() ? ", ..." : "...") :
199+
(function.Parameters.Any(
200+
p => p.Kind == ParameterKind.Regular) ? ", ..." : "...") :
197201
string.Empty;
198202

199-
var @const = method != null && method.IsConst ? " const" : string.Empty;
203+
var @const = method?.IsConst == true ? " const" : string.Empty;
200204

201205
var refQualifier = method == null || method.RefQualifier == RefQualifier.None ?
202206
string.Empty : (method.RefQualifier == RefQualifier.LValue ? " &" : " &&");
203207

204-
return $@"({paramTypes}{variadicType}){@const}{refQualifier}";
208+
return $"({paramTypes}{variadicType}){@const}{refQualifier}";
205209
}
206210

207211
private string GetFunctionName(Function function, string @namespace)
@@ -219,16 +223,16 @@ private void WriteRedeclaration(Function function, string returnType,
219223
{
220224
Stack<string> parentsOpen = GenerateNamespace(function);
221225
var functionType = (FunctionType) function.FunctionType.Type;
222-
Write($@"{string.Join(string.Empty, parentsOpen)}");
226+
Write($"{string.Concat(parentsOpen)}");
223227
if (function.IsConstExpr)
224228
Write("constexpr ");
225229
Write(returnType);
226230
Write(" ");
227-
Write(parentsOpen.Any() ? function.OriginalName : functionName);
231+
Write(parentsOpen.Count > 0 ? function.OriginalName : functionName);
228232
Write(paramTypes);
229233
if (functionType.ExceptionSpecType == ExceptionSpecType.BasicNoexcept)
230234
Write(" noexcept");
231-
WriteLine($";{string.Join(string.Empty, parentsOpen.Select(p => " }"))}");
235+
WriteLine($";{string.Concat(parentsOpen.Select(p => " }"))}");
232236
}
233237

234238
private static Stack<string> GenerateNamespace(Function function)

0 commit comments

Comments
 (0)