Skip to content

Commit

Permalink
Made the generation of templates optional and off by default.
Browse files Browse the repository at this point in the history
Templates are still experimental and we don't have automatic compilation of C++ symbols so it's risky to always have them enabled.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Aug 6, 2017
1 parent ff1abf3 commit 23e7dec
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/Generator/Options.cs
Expand Up @@ -92,6 +92,13 @@ public Module AddModule(string libraryName)

public bool OutputInteropIncludes;
public bool GenerateFunctionTemplates;
/// <summary>
/// C# only: gets or sets a value indicating whether to generate class templates.
/// </summary>
/// <value>
/// <c>true</c> to generate class templates; otherwise, <c>false</c>.
/// </value>
public bool GenerateClassTemplates { get; set; } = false;
public bool GenerateInternalImports;
public bool GenerateSequentialLayout { get; set; }
public bool UseHeaderDirectories;
Expand Down
38 changes: 24 additions & 14 deletions src/Generator/Passes/CheckIgnoredDecls.cs
Expand Up @@ -39,18 +39,12 @@ public override bool VisitClassDecl(Class @class)
if (!@class.IsDependent)
return false;

if (Options.IsCLIGenerator || @class.TranslationUnit.IsSystemHeader ||
@class.Specializations.Count == 0)
{
bool hasExplicitlyGeneratedSpecializations = false;
foreach (var specialization in @class.Specializations)
if (specialization.IsExplicitlyGenerated)
hasExplicitlyGeneratedSpecializations = true;
else
specialization.ExplicitlyIgnore();
if (!hasExplicitlyGeneratedSpecializations)
@class.ExplicitlyIgnore();
}
if (Options.GenerateClassTemplates)
IgnoreUnsupportedTemplates(@class);
else
foreach (var specialization in @class.Specializations.Where(
s => !s.IsExplicitlyGenerated))
specialization.ExplicitlyIgnore();

return true;
}
Expand Down Expand Up @@ -350,11 +344,11 @@ public override bool VisitASTContext(ASTContext c)

#region Helpers

/// <remarks>
/// <summary>
/// Checks if a given type is invalid, which can happen for a number of
/// reasons: incomplete definitions, being explicitly ignored, or also
/// by being a type we do not know how to handle.
/// </remarks>
/// </summary>
private bool HasInvalidType(Type type, Module module, out string msg)
{
if (type == null)
Expand Down Expand Up @@ -459,6 +453,22 @@ private bool IsDeclIgnored(Declaration decl)
return TypeMaps.FindTypeMap(decl, out typeMap) ? typeMap.IsIgnored : decl.Ignore;
}

private void IgnoreUnsupportedTemplates(Class @class)
{
if (!Options.IsCLIGenerator && !@class.TranslationUnit.IsSystemHeader &&
@class.Specializations.Count > 0)
return;

bool hasExplicitlyGeneratedSpecializations = false;
foreach (var specialization in @class.Specializations)
if (specialization.IsExplicitlyGenerated)
hasExplicitlyGeneratedSpecializations = true;
else
specialization.ExplicitlyIgnore();
if (!hasExplicitlyGeneratedSpecializations)
@class.ExplicitlyIgnore();
}

#endregion

private HashSet<Declaration> injectedClasses = new HashSet<Declaration>();
Expand Down
3 changes: 2 additions & 1 deletion src/Generator/Passes/ConstructorToConversionOperatorPass.cs
Expand Up @@ -26,7 +26,8 @@ public override bool VisitMethodDecl(Method method)
{
var nonDefaultParams = @params.Count(p => p.DefaultArgument == null ||
(p.DefaultArgument.Class == StatementClass.Call &&
p.DefaultArgument.Declaration.Ignore));
(p.DefaultArgument.Declaration == null ||
p.DefaultArgument.Declaration.Ignore)));
if (nonDefaultParams > 1)
return false;
}
Expand Down
1 change: 1 addition & 0 deletions tests/CSharp/CSharp.cs
Expand Up @@ -26,6 +26,7 @@ public override void SetupPasses(Driver driver)
driver.Context.TranslationUnitPasses.AddPass(new TestAttributesPass());
driver.Options.MarshalCharAsManagedChar = true;
driver.Options.GenerateDefaultValuesForArguments = true;
driver.Options.GenerateClassTemplates = true;
}

public override void Preprocess(Driver driver, ASTContext ctx)
Expand Down

0 comments on commit 23e7dec

Please sign in to comment.