Skip to content

Commit

Permalink
Fixed the generation of internals for template specialisations.
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <[email protected]>
  • Loading branch information
ddobrev committed Oct 25, 2017
1 parent 5e39989 commit d0c8e15
Show file tree
Hide file tree
Showing 22 changed files with 5,954 additions and 2,545 deletions.
32 changes: 27 additions & 5 deletions src/AST/ClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ public static bool HasRefBase(this Class @class)
if (@class.HasBaseClass)
@base = @class.Bases[0].Class;

var hasRefBase = @base != null && @base.IsRefType && @base.IsGenerated;

return hasRefBase;
return @base?.IsRefType == true && @base.IsGenerated;
}

public static IEnumerable<TranslationUnit> GetGenerated(this IEnumerable<TranslationUnit> units)
Expand All @@ -150,8 +148,7 @@ public static IEnumerable<TranslationUnit> GetGenerated(this IEnumerable<Transla
public static List<ClassTemplateSpecialization> GetSpecializationsToGenerate(
this Class classTemplate)
{
if (classTemplate.Fields.Any(
f => f.Type.Desugar() is TemplateParameterType))
if (classTemplate.HasDependentValueFieldInLayout())
return classTemplate.Specializations;

var specializations = new List<ClassTemplateSpecialization>();
Expand All @@ -162,5 +159,30 @@ public static List<ClassTemplateSpecialization> GetSpecializationsToGenerate(
specializations.Add(specialization);
return specializations;
}

public static bool HasDependentValueFieldInLayout(this Class @class)
{
if (@class.Fields.Any(f => IsValueDependent(f.Type)))
return true;

return @class.Bases.Where(b => b.IsClass).Select(
b => b.Class).Any(HasDependentValueFieldInLayout);
}

private static bool IsValueDependent(Type type)
{
var desugared = type.Desugar();
if (desugared is TemplateParameterType)
return true;
var tagType = desugared as TagType;
if (tagType?.IsDependent == true)
return true;
var templateType = desugared as TemplateSpecializationType;
if (templateType?.Arguments.Any(
a => a.Type.Type?.Desugar().IsDependent == true) == true)
return true;
var arrayType = desugared as ArrayType;
return arrayType != null && IsValueDependent(arrayType.Type);
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <string>


template __attribute__((visibility("default"))) std::allocator<char>::allocator() noexcept;
template __attribute__((visibility("default"))) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(const std::basic_string<char, std::char_traits<char>, std::allocator<char>>::value_type*, const std::basic_string<char, std::char_traits<char>, std::allocator<char>>::allocator_type&);
template __attribute__((visibility("default"))) std::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() noexcept;
template __attribute__((visibility("default"))) const std::basic_string<char, std::char_traits<char>, std::allocator<char>>::value_type* std::basic_string<char, std::char_traits<char>, std::allocator<char>>::c_str() const noexcept;
template __attribute__((visibility("default"))) std::allocator<char>::allocator() noexcept;
Loading

0 comments on commit d0c8e15

Please sign in to comment.