Skip to content

Commit

Permalink
Adding a differentiator between "LTS" (default) and "STS" (latest) co…
Browse files Browse the repository at this point in the history
…degen
  • Loading branch information
tannergooding committed Mar 3, 2023
1 parent c87aa6e commit 4bc909e
Show file tree
Hide file tree
Showing 62 changed files with 33,104 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ public void BeginStruct(in StructDesc desc)
Write(".Interface");
}

if ((desc.Uuid is not null) && _config.GenerateGuidMember && _config.GeneratePreviewCode)
if ((desc.Uuid is not null) && _config.GenerateGuidMember && _config.GenerateLatestCode)
{
Write(desc.HasVtbl ? ", " : " : ");
Write("INativeGuid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl)
ParentName = GetRemappedCursorName(parent),
Offset = null,
NeedsNewKeyword = false,
NeedsUnscopedRef = _config.GeneratePreviewCode && !fieldDecl.IsBitField,
NeedsUnscopedRef = _config.GenerateLatestCode && !fieldDecl.IsBitField,
Location = fieldDecl.Location,
HasBody = true,
WriteCustomAttrs = static context => {
Expand Down Expand Up @@ -2937,7 +2937,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co
}
else
{
_outputBuilder.BeginIndexer(AccessSpecifier.Public, isUnsafe: false, needsUnscopedRef: _config.GeneratePreviewCode);
_outputBuilder.BeginIndexer(AccessSpecifier.Public, isUnsafe: false, needsUnscopedRef: _config.GenerateLatestCode);
_outputBuilder.WriteIndexer($"ref {arrayTypeName}");
_outputBuilder.BeginIndexerParameters();
var param = new ParameterDesc {
Expand Down Expand Up @@ -2979,7 +2979,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co
ReturnType = $"Span<{arrayTypeName}>",
Location = constantOrIncompleteArray.Location,
HasBody = true,
NeedsUnscopedRef = _config.GeneratePreviewCode,
NeedsUnscopedRef = _config.GenerateLatestCode,
};

var isUnsafe = false;
Expand Down Expand Up @@ -3354,7 +3354,7 @@ private void VisitVarDecl(VarDecl varDecl)

case CX_CharacterKind.CX_CLK_UTF32:
{
if (_config.GeneratePreviewCode && flags.HasFlag(ValueFlags.Constant))
if (_config.GenerateLatestCode && flags.HasFlag(ValueFlags.Constant))
{
typeName = "ReadOnlySpan<uint>";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2472,7 +2472,7 @@ private void VisitStringLiteral(StringLiteral stringLiteral)
case CX_CharacterKind.CX_CLK_Ascii:
case CX_CharacterKind.CX_CLK_UTF8:
{
if (Config.GeneratePreviewCode)
if (Config.GenerateLatestCode)
{
outputBuilder.Write('"');
outputBuilder.Write(EscapeString(stringLiteral.String));
Expand Down
2 changes: 1 addition & 1 deletion sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void Close()

foreach (var entry in methodClassOutputBuilders)
{
var hasGuidMember = _config.GenerateGuidMember && _config.GeneratePreviewCode;
var hasGuidMember = _config.GenerateGuidMember && _config.GenerateLatestCode;
hasGuidMember &= _uuidsToGenerate.ContainsKey(entry.Value.Name) || _generatedUuids.Contains(entry.Value.Name);

CloseOutputBuilder(stream, entry.Value, isMethodClass: true, leaveStreamOpen, emitNamespaceDeclaration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public PInvokeGeneratorConfiguration(string defaultNamespace, string outputLocat
{
throw new ArgumentOutOfRangeException(nameof(options));
}
else if (options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode) && options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateLatestCode))
{
throw new ArgumentOutOfRangeException(nameof(options));
}
else if (options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateLatestCode) && options.HasFlag(PInvokeGeneratorConfigurationOptions.GeneratePreviewCode))
{
throw new ArgumentOutOfRangeException(nameof(options));
}

if (options.HasFlag(PInvokeGeneratorConfigurationOptions.GeneratePreviewCode))
{
// While users shouldn't have passed it in like this, we can simplify
// our own downstream checks be having preview also opt into "latest".
options |= PInvokeGeneratorConfigurationOptions.GenerateLatestCode;
}
_options = options;

if (!_options.HasFlag(PInvokeGeneratorConfigurationOptions.NoDefaultRemappings))
Expand Down Expand Up @@ -205,6 +220,8 @@ public IReadOnlyCollection<string> ExcludedNames

public bool GenerateHelperTypes => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateHelperTypes);

public bool GenerateLatestCode => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateLatestCode);

public bool GenerateMacroBindings => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateMacroBindings);

public bool GenerateMarkerInterfaces => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateMarkerInterfaces);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ public enum PInvokeGeneratorConfigurationOptions : ulong
GenerateDocIncludes = 1UL << 32,

GenerateGuidMember = 1UL << 33,

GenerateLatestCode = 1UL << 34,
}
26 changes: 19 additions & 7 deletions sources/ClangSharpPInvokeGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public class Program
// Codegen Options

new TwoColumnHelpRow("compatible-codegen", "Bindings should be generated with .NET Standard 2.0 compatibility. Setting this disables preview code generation."),
new TwoColumnHelpRow("latest-codegen", "Bindings should be generated for the latest stable version of .NET/C#. This is currently .NET 6/C# 10."),
new TwoColumnHelpRow("preview-codegen", "Bindings should be generated for the latest preview version of .NET/C#. This is currently .NET 7/C# 11."),
new TwoColumnHelpRow("default-codegen", "Bindings should be generated for the current LTS version of .NET/C#. This is currently .NET 6/C# 10."),
new TwoColumnHelpRow("latest-codegen", "Bindings should be generated for the current STS version of .NET/C#. This is currently .NET 7/C# 11."),
new TwoColumnHelpRow("preview-codegen", "Bindings should be generated for the preview version of .NET/C#. This is currently .NET 8/C# 12."),

// File Options

Expand Down Expand Up @@ -209,13 +210,13 @@ static Program()
public static IEnumerable<HelpSectionDelegate> GetExtendedHelp(HelpContext context)
{
foreach (var sectionDelegate in HelpBuilder.Default.GetLayout())
{
yield return sectionDelegate;
}

yield return _ =>
{
Console.WriteLine(
@"Wildcards:
You can use * as catch-all rule for remapping procedures. For example if you want make all of your generated code internal you can use --with-access-specifier *=Internal.");
yield return _ => {
Console.WriteLine("Wildcards:");
Console.WriteLine("You can use * as catch-all rule for remapping procedures. For example if you want make all of your generated code internal you can use --with-access-specifier *=Internal.");
};
}

Expand Down Expand Up @@ -339,20 +340,31 @@ public static void Run(InvocationContext context)
case "compatible-codegen":
{
configOptions |= PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode;
configOptions &= ~PInvokeGeneratorConfigurationOptions.GenerateLatestCode;
configOptions &= ~PInvokeGeneratorConfigurationOptions.GeneratePreviewCode;
break;
}

case "default-codegen":
{
configOptions &= ~PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode;
configOptions &= ~PInvokeGeneratorConfigurationOptions.GenerateLatestCode;
configOptions &= ~PInvokeGeneratorConfigurationOptions.GeneratePreviewCode;
break;
}

case "latest-codegen":
{
configOptions &= ~PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode;
configOptions |= PInvokeGeneratorConfigurationOptions.GenerateLatestCode;
configOptions &= ~PInvokeGeneratorConfigurationOptions.GeneratePreviewCode;
break;
}

case "preview-codegen":
{
configOptions &= ~PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode;
configOptions &= ~PInvokeGeneratorConfigurationOptions.GenerateLatestCode;
configOptions |= PInvokeGeneratorConfigurationOptions.GeneratePreviewCode;
break;
}
Expand Down
Loading

0 comments on commit 4bc909e

Please sign in to comment.