Permalink
Browse files

Reduced the wrapped specialisations to ones used in public members.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Jun 7, 2017
1 parent 1f61f51 commit d487088f536ef1c29b0bd658ad10307ac592cd03
@@ -1,6 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using CppSharp.AST.Extensions;
using CppSharp.Types;
namespace CppSharp.AST
{
@@ -20,6 +22,9 @@ public static bool CheckIgnoreMethod(Method method)
{
if (!method.IsGenerated) return true;
if (method.IsDependent && UsesAdditionalTypeParam(method))
return true;
var isEmptyCtor = method.IsConstructor && method.Parameters.Count == 0;
var @class = method.Namespace as Class;
@@ -48,9 +53,10 @@ public static bool CheckIgnoreMethod(Method method)
if (!baseClass.IsInterface)
{
var copyConstructor = baseClass.Methods.FirstOrDefault(m => m.IsCopyConstructor);
if (copyConstructor == null
|| copyConstructor.Access == AccessSpecifier.Private
|| !copyConstructor.IsDeclared)
if (copyConstructor == null ||
copyConstructor.Access == AccessSpecifier.Private ||
(!copyConstructor.IsDeclared &&
!copyConstructor.TranslationUnit.IsSystemHeader))
return true;
}
}
@@ -61,7 +67,7 @@ public static bool CheckIgnoreMethod(Method method)
public static bool CheckIgnoreField(Field field, bool useInternals = false)
{
if (field.Access == AccessSpecifier.Private && !useInternals)
if (field.Access == AccessSpecifier.Private && !useInternals)
return true;
if (field.Class.IsValueType && field.IsDeclared)
@@ -80,6 +86,99 @@ public static bool CheckIgnoreProperty(Property prop)
return !prop.IsGenerated;
}
public static void CheckTypeForSpecialization(Type type, Declaration container,
Action<ClassTemplateSpecialization> addSpecialization,
ITypeMapDatabase typeMaps, bool internalOnly = false)
{
type = type.Desugar();
type = type.GetFinalPointee() ?? type;
ClassTemplateSpecialization specialization;
if (!type.TryGetDeclaration(out specialization) ||
specialization.IsExplicitlyGenerated)
return;
TypeMap typeMap;
typeMaps.FindTypeMap(specialization, out typeMap);
if ((!internalOnly && (((specialization.Ignore ||
specialization.TemplatedDecl.TemplatedClass.Ignore) && typeMap == null) ||
specialization.Arguments.Any(a => UnsupportedTemplateArgument(
specialization, a, typeMaps)))) ||
specialization.IsIncomplete ||
specialization.TemplatedDecl.TemplatedClass.IsIncomplete ||
specialization is ClassTemplatePartialSpecialization ||
container.Namespace == specialization)
return;
while (container.Namespace != null)
{
if (container.Namespace == specialization)
return;
container = container.Namespace;
}
if (!internalOnly && typeMaps.FindTypeMap(specialization, out typeMap))
{
var typePrinterContext = new TypePrinterContext { Type = type };
var mappedTo = typeMap.CSharpSignatureType(typePrinterContext);
mappedTo = mappedTo.Desugar();
mappedTo = (mappedTo.GetFinalPointee() ?? mappedTo);
if (mappedTo.IsPrimitiveType() || mappedTo.IsPointerToPrimitiveType() || mappedTo.IsEnum())
return;
}
addSpecialization(specialization);
}
public static bool IsTypeExternal(Module module, Type type)
{
Declaration declaration;
if (!(type.GetFinalPointee() ?? type).TryGetDeclaration(out declaration))
return false;
declaration = declaration.CompleteDeclaration ?? declaration;
if (declaration.Namespace == null || declaration.TranslationUnit.Module == null)
return false;
return declaration.TranslationUnit.Module.Dependencies.Contains(module);
}
private static bool UsesAdditionalTypeParam(Method method)
{
var specialization = method.Namespace as ClassTemplateSpecialization;
Class template;
if (specialization != null)
template = specialization.TemplatedDecl.TemplatedClass;
else
{
template = (Class) method.Namespace;
if (!template.IsDependent)
return false;
}
var typeParams = template.TemplateParameters.Select(t => t.Name).ToList();
return method.Parameters.Any(p =>
{
if (!p.IsDependent)
return false;
var desugared = p.Type.Desugar();
var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar()
as TemplateParameterType;
return finalType != null && !typeParams.Contains(finalType.Parameter.Name);
});
}
private static bool UnsupportedTemplateArgument(
ClassTemplateSpecialization specialization, TemplateArgument a, ITypeMapDatabase typeMaps)
{
if (a.Type.Type == null ||
IsTypeExternal(specialization.TranslationUnit.Module, a.Type.Type))
return true;
var typeIgnoreChecker = new TypeIgnoreChecker(typeMaps);
a.Type.Type.Visit(typeIgnoreChecker);
return typeIgnoreChecker.IsIgnored;
}
}
public static class Operators
@@ -368,7 +368,7 @@ private bool HasInvalidType(Type type, Module module, out string msg)
}
if (Options.DoAllModulesHaveLibraries() &&
module != Options.SystemModule && IsTypeExternal(module, type))
module != Options.SystemModule && ASTUtils.IsTypeExternal(module, type))
{
msg = "external";
return true;
@@ -433,19 +433,6 @@ private bool IsTypeComplete(Type type)
return !decl.IsIncomplete || decl.CompleteDeclaration != null;
}
public static bool IsTypeExternal(Module module, Type type)
{
Declaration declaration;
if (!(type.GetFinalPointee() ?? type).TryGetDeclaration(out declaration))
return false;
declaration = declaration.CompleteDeclaration ?? declaration;
if (declaration.Namespace == null || declaration.TranslationUnit.Module == null)
return false;
return declaration.TranslationUnit.Module.Dependencies.Contains(module);
}
private bool IsTypeIgnored(Type type)
{
var checker = new TypeIgnoreChecker(TypeMaps);
@@ -83,9 +83,21 @@ public override bool VisitFunctionDecl(Function function)
if (function.IsGenerated)
{
CheckTypeForSpecialization(function.OriginalReturnType.Type);
Action<ClassTemplateSpecialization> add =
s =>
{
ICollection<ClassTemplateSpecialization> specs;
if (specializations.ContainsKey(s.TranslationUnit.Module))
specs = specializations[s.TranslationUnit.Module];
else specs = specializations[s.TranslationUnit.Module] =
new HashSet<ClassTemplateSpecialization>();
specs.Add(s);
};
ASTUtils.CheckTypeForSpecialization(function.OriginalReturnType.Type,
function, add, Context.TypeMaps);
foreach (var parameter in function.Parameters)
CheckTypeForSpecialization(parameter.Type);
ASTUtils.CheckTypeForSpecialization(parameter.Type, function,
add, Context.TypeMaps);
}
if (!NeedsSymbol(function))
@@ -95,54 +107,6 @@ public override bool VisitFunctionDecl(Function function)
return function.Visit(symbolsCodeGenerator);
}
private void CheckTypeForSpecialization(AST.Type type)
{
type = type.Desugar();
ClassTemplateSpecialization specialization;
type = type.GetFinalPointee() ?? type;
if (!type.TryGetDeclaration(out specialization))
return;
if (specialization.Ignore ||
specialization.TemplatedDecl.TemplatedClass.Ignore ||
specialization.IsIncomplete ||
specialization.TemplatedDecl.TemplatedClass.IsIncomplete ||
specialization is ClassTemplatePartialSpecialization ||
specialization.Arguments.Any(a => UnsupportedTemplateArgument(specialization, a)))
return;
TypeMap typeMap;
if (Context.TypeMaps.FindTypeMap(specialization, out typeMap))
{
var typePrinterContext = new TypePrinterContext { Type = type };
var mappedTo = typeMap.CSharpSignatureType(typePrinterContext);
mappedTo = mappedTo.Desugar();
mappedTo = (mappedTo.GetFinalPointee() ?? mappedTo);
if (mappedTo.IsPrimitiveType() || mappedTo.IsPointerToPrimitiveType() || mappedTo.IsEnum())
return;
}
HashSet<ClassTemplateSpecialization> list;
if (specializations.ContainsKey(specialization.TranslationUnit.Module))
list = specializations[specialization.TranslationUnit.Module];
else
specializations[specialization.TranslationUnit.Module] =
list = new HashSet<ClassTemplateSpecialization>();
list.Add(specialization);
}
private bool UnsupportedTemplateArgument(ClassTemplateSpecialization specialization, TemplateArgument a)
{
if (a.Type.Type == null ||
CheckIgnoredDeclsPass.IsTypeExternal(
specialization.TranslationUnit.Module, a.Type.Type))
return true;
var typeIgnoreChecker = new TypeIgnoreChecker(Context.TypeMaps);
a.Type.Type.Visit(typeIgnoreChecker);
return typeIgnoreChecker.IsIgnored;
}
public class SymbolsCodeEventArgs : EventArgs
{
public SymbolsCodeEventArgs(Module module)
Oops, something went wrong.

0 comments on commit d487088

Please sign in to comment.