Browse Source

Fixed the generated C++ for symbols to be compatible with Clang.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1005/head
Dimitar Dobrev 8 years ago
parent
commit
af8a758744
  1. 28
      src/Generator/Passes/SymbolsCodeGenerator.cs

28
src/Generator/Passes/SymbolsCodeGenerator.cs

@ -69,7 +69,7 @@ namespace CppSharp.Passes
private static string GetDerivedType(string @namespace, string wrapper) private static string GetDerivedType(string @namespace, string wrapper)
{ {
return $@"class {wrapper}{@namespace} : public {@namespace} {{ public: "; return $"class {wrapper}{@namespace} : public {@namespace} {{ public: ";
} }
private void WrapConstructor(Method method) private void WrapConstructor(Method method)
@ -135,7 +135,7 @@ namespace CppSharp.Passes
bool isProtected = method.Access == AccessSpecifier.Protected; bool isProtected = method.Access == AccessSpecifier.Protected;
string @namespace = method.Namespace.Visit(cppTypePrinter); string @namespace = method.Namespace.Visit(cppTypePrinter);
if (isProtected) if (isProtected)
Write($"{GetDerivedType(@namespace, wrapper)}"); Write(GetDerivedType(@namespace, wrapper));
else else
Write("extern \"C\" { "); Write("extern \"C\" { ");
Write($"void {wrapper}"); Write($"void {wrapper}");
@ -173,13 +173,17 @@ namespace CppSharp.Passes
Write($@"{returnType} ({(method != null && !method.IsStatic ? Write($@"{returnType} ({(method != null && !method.IsStatic ?
(@namespace + "::") : string.Empty)}*{wrapper}){signature}"); (@namespace + "::") : string.Empty)}*{wrapper}){signature}");
else else
Write($@"auto {wrapper}"); Write($"auto {wrapper}");
Write($@" = &{functionName};");
if (function.Access == AccessSpecifier.Protected) if (function.Access == AccessSpecifier.Protected)
{ {
Write($" = &{wrapper}{@namespace}::{functionName};");
WriteLine(" };"); WriteLine(" };");
Write($"auto {wrapper}protected = {wrapper}{@namespace}::{wrapper};"); Write($"auto {wrapper}protected = {wrapper}{@namespace}::{wrapper};");
} }
else
{
Write($" = &{functionName};");
}
NewLine(); NewLine();
} }
@ -189,19 +193,19 @@ namespace CppSharp.Passes
var paramTypes = string.Join(", ", function.Parameters.Where( var paramTypes = string.Join(", ", function.Parameters.Where(
p => p.Kind == ParameterKind.Regular).Select( p => p.Kind == ParameterKind.Regular).Select(
p => cppTypePrinter.VisitParameterDecl(p))); cppTypePrinter.VisitParameterDecl));
var variadicType = function.IsVariadic ? var variadicType = function.IsVariadic ?
(function.Parameters.Where( (function.Parameters.Any(
p => p.Kind == ParameterKind.Regular).Any() ? ", ..." : "...") : p => p.Kind == ParameterKind.Regular) ? ", ..." : "...") :
string.Empty; string.Empty;
var @const = method != null && method.IsConst ? " const" : string.Empty; var @const = method?.IsConst == true ? " const" : string.Empty;
var refQualifier = method == null || method.RefQualifier == RefQualifier.None ? var refQualifier = method == null || method.RefQualifier == RefQualifier.None ?
string.Empty : (method.RefQualifier == RefQualifier.LValue ? " &" : " &&"); string.Empty : (method.RefQualifier == RefQualifier.LValue ? " &" : " &&");
return $@"({paramTypes}{variadicType}){@const}{refQualifier}"; return $"({paramTypes}{variadicType}){@const}{refQualifier}";
} }
private string GetFunctionName(Function function, string @namespace) private string GetFunctionName(Function function, string @namespace)
@ -219,16 +223,16 @@ namespace CppSharp.Passes
{ {
Stack<string> parentsOpen = GenerateNamespace(function); Stack<string> parentsOpen = GenerateNamespace(function);
var functionType = (FunctionType) function.FunctionType.Type; var functionType = (FunctionType) function.FunctionType.Type;
Write($@"{string.Join(string.Empty, parentsOpen)}"); Write($"{string.Concat(parentsOpen)}");
if (function.IsConstExpr) if (function.IsConstExpr)
Write("constexpr "); Write("constexpr ");
Write(returnType); Write(returnType);
Write(" "); Write(" ");
Write(parentsOpen.Any() ? function.OriginalName : functionName); Write(parentsOpen.Count > 0 ? function.OriginalName : functionName);
Write(paramTypes); Write(paramTypes);
if (functionType.ExceptionSpecType == ExceptionSpecType.BasicNoexcept) if (functionType.ExceptionSpecType == ExceptionSpecType.BasicNoexcept)
Write(" noexcept"); Write(" noexcept");
WriteLine($";{string.Join(string.Empty, parentsOpen.Select(p => " }"))}"); WriteLine($";{string.Concat(parentsOpen.Select(p => " }"))}");
} }
private static Stack<string> GenerateNamespace(Function function) private static Stack<string> GenerateNamespace(Function function)

Loading…
Cancel
Save