Browse Source

Exported entire specialisations when they only have valid functions.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1026/head
Dimitar Dobrev 8 years ago
parent
commit
3dba1eb594
  1. 2
      src/AST/Declaration.cs
  2. 6
      src/Generator/Passes/CheckIgnoredDecls.cs
  3. 14
      src/Generator/Passes/GenerateSymbolsPass.cs
  4. 23
      src/Generator/Passes/SymbolsCodeGenerator.cs
  5. 3
      src/Parser/ASTConverter.cs

2
src/AST/Declaration.cs

@ -206,6 +206,8 @@ namespace CppSharp.AST @@ -206,6 +206,8 @@ namespace CppSharp.AST
// Comment associated with declaration.
public RawComment Comment;
public bool IsInvalid { get; set; }
private GenerationKind? generationKind;
public GenerationKind GenerationKind

6
src/Generator/Passes/CheckIgnoredDecls.cs

@ -81,6 +81,12 @@ namespace CppSharp.Passes @@ -81,6 +81,12 @@ namespace CppSharp.Passes
if (decl.GenerationKind == GenerationKind.None)
return true;
if (decl.IsInvalid)
{
decl.ExplicitlyIgnore();
return true;
}
if (!CheckDeclarationAccess(decl))
{
Diagnostics.Debug("Decl '{0}' was ignored due to invalid access",

14
src/Generator/Passes/GenerateSymbolsPass.cs

@ -50,10 +50,16 @@ namespace CppSharp.Passes @@ -50,10 +50,16 @@ namespace CppSharp.Passes
{
symbolsCodeGenerator.NewLine();
foreach (var specialization in specializations[module])
foreach (var method in specialization.Methods.Where(
m => m.IsGenerated && !m.IsDependent && !m.IsImplicit &&
!m.IsDeleted && !m.IsDefaulted))
symbolsCodeGenerator.VisitMethodDecl(method);
{
Func<Method, bool> exportable = m => !m.IsDependent &&
!m.IsImplicit && !m.IsDeleted && !m.IsDefaulted;
if (specialization.Methods.Any(m => m.IsInvalid && exportable(m)))
foreach (var method in specialization.Methods.Where(
m => m.IsGenerated && exportable(m)))
symbolsCodeGenerator.VisitMethodDecl(method);
else
symbolsCodeGenerator.VisitClassTemplateSpecializationDecl(specialization);
}
}
var cpp = $"{module.SymbolsLibraryName}.{symbolsCodeGenerator.FileExtension}";

23
src/Generator/Passes/SymbolsCodeGenerator.cs

@ -27,16 +27,17 @@ namespace CppSharp.Passes @@ -27,16 +27,17 @@ namespace CppSharp.Passes
NewLine();
}
public override bool VisitClassTemplateSpecializationDecl(ClassTemplateSpecialization specialization)
{
WriteLine($"template class {GetExporting()}{specialization.Visit(cppTypePrinter)};");
return true;
}
public override bool VisitMethodDecl(Method method)
{
if (method.Namespace is ClassTemplateSpecialization)
{
var exporting = string.Empty;
if (Context.ParserOptions.IsMicrosoftAbi)
exporting = "__declspec(dllexport) ";
else if (TargetTriple.IsMacOS(Context.ParserOptions.TargetTriple))
exporting = "__attribute__((visibility(\"default\"))) ";
WriteLine($"template {exporting}{method.Visit(cppTypePrinter)};");
WriteLine($"template {GetExporting()}{method.Visit(cppTypePrinter)};");
return true;
}
if (method.IsConstructor)
@ -58,6 +59,16 @@ namespace CppSharp.Passes @@ -58,6 +59,16 @@ namespace CppSharp.Passes
return true;
}
private string GetExporting()
{
var exporting = string.Empty;
if (Context.ParserOptions.IsMicrosoftAbi)
exporting = "__declspec(dllexport) ";
else if (TargetTriple.IsMacOS(Context.ParserOptions.TargetTriple))
exporting = "__attribute__((visibility(\"default\"))) ";
return exporting;
}
private string GetWrapper(Module module)
{
var symbolsLibraryName = new StringBuilder(module.SymbolsLibraryName);

3
src/Parser/ASTConverter.cs

@ -945,8 +945,7 @@ namespace CppSharp @@ -945,8 +945,7 @@ namespace CppSharp
_decl.IsIncomplete = decl.IsIncomplete;
_decl.IsDependent = decl.IsDependent;
_decl.IsImplicit = decl.IsImplicit;
if (decl.IsInvalid)
_decl.GenerationKind = AST.GenerationKind.None;
_decl.IsInvalid = decl.IsInvalid;
_decl.DefinitionOrder = decl.DefinitionOrder;
_decl.MaxFieldAlignment = decl.MaxFieldAlignment;

Loading…
Cancel
Save