Browse Source

Generated the symbols for templates by separate functions instead.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/816/head 0.8.8
Dimitar Dobrev 8 years ago
parent
commit
1174800cff
  1. 20
      src/AST/CppTypePrinter.cs
  2. 1
      src/AST/Function.cs
  3. 3
      src/Generator/Passes/ConstructorToConversionOperatorPass.cs
  4. 5
      src/Generator/Passes/FunctionToInstanceMethodPass.cs
  5. 11
      src/Generator/Passes/GenerateSymbolsPass.cs
  6. 11
      src/Generator/Passes/SymbolsCodeGenerator.cs

20
src/AST/CppTypePrinter.cs

@ -362,7 +362,25 @@ namespace CppSharp.AST @@ -362,7 +362,25 @@ namespace CppSharp.AST
public virtual string VisitMethodDecl(Method method)
{
return VisitDeclaration(method);
// HACK: this should never happen but there's an inexplicable crash with the 32-bit Windows CI - I have no time to fix it right now
var functionType = method.FunctionType.Type as FunctionType;
if (functionType == null)
return string.Empty;
var returnType = method.IsConstructor || method.IsDestructor ||
method.OperatorKind == CXXOperatorKind.Conversion ||
method.OperatorKind == CXXOperatorKind.ExplicitConversion ?
string.Empty : $"{method.OriginalReturnType.Visit(this)} ";
var @class = method.Namespace.Visit(this);
var @params = string.Join(", ", method.Parameters.Select(p => p.Visit(this)));
var @const = (method.IsConst ? " const" : string.Empty);
var name = method.OperatorKind == CXXOperatorKind.Conversion ||
method.OperatorKind == CXXOperatorKind.ExplicitConversion ?
$"operator {method.OriginalReturnType.Visit(this)}" :
method.OriginalName;
var exceptionType =
functionType.ExceptionSpecType == ExceptionSpecType.BasicNoexcept ?
" noexcept" : string.Empty;
return $@"{returnType}{@class}::{name}({@params}){@const}{exceptionType}";
}
public virtual string VisitParameterDecl(Parameter parameter)

1
src/AST/Function.cs

@ -165,6 +165,7 @@ namespace CppSharp.AST @@ -165,6 +165,7 @@ namespace CppSharp.AST
Mangled = function.Mangled;
Index = function.Index;
Signature = function.Signature;
FunctionType = function.FunctionType;
if (function.SpecializationInfo != null)
{
SpecializationInfo = new FunctionTemplateSpecialization(function.SpecializationInfo);

3
src/Generator/Passes/ConstructorToConversionOperatorPass.cs

@ -67,7 +67,8 @@ namespace CppSharp.Passes @@ -67,7 +67,8 @@ namespace CppSharp.Passes
ConversionType = qualifiedCastToType,
ReturnType = qualifiedCastToType,
OperatorKind = operatorKind,
IsExplicit = method.IsExplicit
IsExplicit = method.IsExplicit,
FunctionType = method.FunctionType
};
conversionOperator.Parameters.Add(new Parameter(parameter)
{

5
src/Generator/Passes/FunctionToInstanceMethodPass.cs

@ -35,7 +35,7 @@ namespace CppSharp.Passes @@ -35,7 +35,7 @@ namespace CppSharp.Passes
// This means we can change the function to be an instance method.
// Clean up the name of the function now that it will be an instance method.
if (!function.Name.StartsWith(@class.Name))
if (!function.Name.StartsWith(@class.Name, System.StringComparison.Ordinal))
return false;
function.Name = function.Name.Substring(@class.Name.Length);
@ -56,7 +56,8 @@ namespace CppSharp.Passes @@ -56,7 +56,8 @@ namespace CppSharp.Passes
CallingConvention = function.CallingConvention,
IsVariadic = function.IsVariadic,
IsInline = function.IsInline,
Conversion = MethodConversionKind.FunctionToInstanceMethod
Conversion = MethodConversionKind.FunctionToInstanceMethod,
FunctionType = function.FunctionType
};
if (Options.GeneratorKind == GeneratorKind.CSharp)

11
src/Generator/Passes/GenerateSymbolsPass.cs

@ -47,6 +47,7 @@ namespace CppSharp.Passes @@ -47,6 +47,7 @@ namespace CppSharp.Passes
where symbolsCodeGenerators.ContainsKey(module)
select module).ToList();
remainingCompilationTasks = modules.Count;
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
foreach (var module in modules.Where(symbolsCodeGenerators.ContainsKey))
{
var symbolsCodeGenerator = symbolsCodeGenerators[module];
@ -54,7 +55,9 @@ namespace CppSharp.Passes @@ -54,7 +55,9 @@ namespace CppSharp.Passes
{
symbolsCodeGenerator.NewLine();
foreach (var specialization in specializations[module])
symbolsCodeGenerator.VisitClassTemplateSpecializationDecl(specialization);
foreach (var method in specialization.Methods.Where(
m => m.IsGenerated && !m.IsDependent && !m.IsImplicit))
symbolsCodeGenerator.VisitMethodDecl(method);
}
var cpp = $"{module.SymbolsLibraryName}.{symbolsCodeGenerator.FileExtension}";
@ -86,9 +89,9 @@ namespace CppSharp.Passes @@ -86,9 +89,9 @@ namespace CppSharp.Passes
if (function.IsGenerated)
{
CheckTypeForSpecialization(function.OriginalReturnType.Type);
CheckTypeForSpecialization(function, function.OriginalReturnType.Type);
foreach (var parameter in function.Parameters)
CheckTypeForSpecialization(parameter.Type);
CheckTypeForSpecialization(function, parameter.Type);
}
if (!NeedsSymbol(function))
@ -98,7 +101,7 @@ namespace CppSharp.Passes @@ -98,7 +101,7 @@ namespace CppSharp.Passes
return function.Visit(symbolsCodeGenerator);
}
private void CheckTypeForSpecialization(AST.Type type)
private void CheckTypeForSpecialization(Function function, AST.Type type)
{
type = type.Desugar();
ClassTemplateSpecialization specialization;

11
src/Generator/Passes/SymbolsCodeGenerator.cs

@ -25,6 +25,11 @@ namespace CppSharp.Passes @@ -25,6 +25,11 @@ namespace CppSharp.Passes
public override bool VisitMethodDecl(Method method)
{
if (method.Namespace is ClassTemplateSpecialization)
{
WriteLine($"template {method.Visit(cppTypePrinter)};");
return true;
}
if (method.IsConstructor)
{
WrapConstructor(method);
@ -44,12 +49,6 @@ namespace CppSharp.Passes @@ -44,12 +49,6 @@ namespace CppSharp.Passes
return true;
}
public override bool VisitClassTemplateSpecializationDecl(ClassTemplateSpecialization specialization)
{
WriteLine($"template class {specialization.Visit(cppTypePrinter)};");
return true;
}
private string GetWrapper(Module module)
{
var symbolsLibraryName = new StringBuilder(module.SymbolsLibraryName);

Loading…
Cancel
Save