Skip to content

Commit d9ab70b

Browse files
cibuild-telliamsmaillet
authored andcommitted
* Removed use of using LlvmBindingsGenerator.CppSharpExtensions namespace for consistency
* Major re-work of type printer support to take full control of the mapping to managed code - Bypassed all the default conversion to CIL types that CppSharp would do during a parse so that only the real native types are in place and ToString() shows the underlying source type. * Code analysis cleanup * Bumped default range of VS to include VS2022 if available
1 parent 26a08db commit d9ab70b

30 files changed

+324
-244
lines changed

Build-All.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
.DESCRIPTION
2525
This script is used by the automated build to perform the actual build. The Ubiquity.NET
26-
family of projects all a PowerShell driven build that is generally divorced from the
26+
family of projects all employ a PowerShell driven build that is generally divorced from the
2727
automated build infrastructure used. This is done for several reasons, but the most
2828
important ones are the ability to reproduce the build locally for inner development and
2929
for flexibility in selecting the actual back end. The back ends have changed a few times

Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
44
<GlobalPackageReference Include="CSemVer.Build.Tasks" Version="2.0.5" />
5-
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3" Condition="'$(NoCommonAnalyzers)'!='true'" />
5+
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0" Condition="'$(NoCommonAnalyzers)'!='true'" />
66
<GlobalPackageReference Include="RefactoringEssentials" Version="5.6.0" Condition="'$(NoCommonAnalyzers)'!='true'" />
77
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" Condition="'$(NoCommonAnalyzers)'!='true'" />
88
<GlobalPackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3" Condition="'$(IsTestProject)' != 'true' and '$(SourceLinkEnabled)' != 'false'" />
99
</ItemGroup>
1010
<ItemGroup>
1111
<PackageReference Update="Ubiquity.ArgValidators" Version="6.0.1" />
1212
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.5.0" />
13-
<PackageReference Update="System.CodeDom" Version="5.0.0" />
13+
<PackageReference Update="System.CodeDom" Version="6.0.0" />
1414
<PackageReference Update="System.Collections.Immutable" Version="1.7.0" />
1515
<PackageReference Update="System.ComponentModel.Annotations" Version="5.0.0" />
1616
<PackageReference Update="System.Memory" Version="4.5.4" />

PsModules/CommonBuild/CommonBuild.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function Invoke-NuGet
219219
}
220220
}
221221

222-
function Find-VSInstance([switch]$PreRelease, $Version = '[15.0, 17.0)', [string[]]$requiredComponents = @('Microsoft.Component.MSBuild'))
222+
function Find-VSInstance([switch]$PreRelease, $Version = '[15.0, 18.0)', [string[]]$requiredComponents = @('Microsoft.Component.MSBuild'))
223223
{
224224
<#
225225
.SYNOPSIS
@@ -229,7 +229,7 @@ function Find-VSInstance([switch]$PreRelease, $Version = '[15.0, 17.0)', [string
229229
Indicates if the search should include pre-release versions of Visual Studio
230230
231231
.PARAMETER version
232-
The version range to search for. [Default is '[15.0, 17.0)']
232+
The version range to search for. [Default is '[15.0, 18.0)']
233233
234234
.PARAMETER requiredComponents
235235
The set of required components to search for. [Default is an empty array]

src/Interop/LlvmBindingsGenerator/Configuration/Yaml/YamlArrayMarshalInfo.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
using CppSharp.AST;
1313

14-
using LlvmBindingsGenerator.CppSharpExtensions;
15-
1614
namespace LlvmBindingsGenerator.Configuration
1715
{
1816
[SuppressMessage( "Performance", "CA1812:Avoid uninstantiated internal classes", Justification = "De-serialized from YAML" )]

src/Interop/LlvmBindingsGenerator/Configuration/Yaml/YamlBindingTransform.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
using CppSharp.AST;
1111

12-
using LlvmBindingsGenerator.CppSharpExtensions;
13-
1412
using YamlDotNet.Core;
1513
using YamlDotNet.Serialization;
1614

src/Interop/LlvmBindingsGenerator/Configuration/Yaml/YamlConfiguration.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
using System;
88
using System.Collections.Generic;
99
using System.Diagnostics.CodeAnalysis;
10-
using System.Globalization;
1110
using System.IO;
1211
using System.Linq;
13-
using System.Runtime.Serialization;
1412

1513
using LlvmBindingsGenerator.Templates;
1614

@@ -19,7 +17,6 @@
1917
using YamlDotNet.Serialization;
2018
using YamlDotNet.Serialization.NamingConventions;
2119
using YamlDotNet.Serialization.NodeDeserializers;
22-
using YamlDotNet.Serialization.Utilities;
2320

2421
namespace LlvmBindingsGenerator.Configuration
2522
{

src/Interop/LlvmBindingsGenerator/Configuration/Yaml/YamlStringMarshalInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
using CppSharp.AST;
1414

15-
using LlvmBindingsGenerator.CppSharpExtensions;
1615
using LlvmBindingsGenerator.Templates;
1716

1817
namespace LlvmBindingsGenerator.Configuration

src/Interop/LlvmBindingsGenerator/CppSharpExtensions/ASTContextExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
using System;
88
using System.Collections.Generic;
9+
using System.Diagnostics.CodeAnalysis;
910
using System.Linq;
1011
using System.Text;
1112

1213
using CppSharp.AST;
1314

14-
using LlvmBindingsGenerator.CppSharpExtensions;
15-
1615
namespace LlvmBindingsGenerator
1716
{
1817
internal static class ASTContextExtensions
@@ -86,10 +85,11 @@ public static bool IsOpaquHandleTypeDef( this TypedefNameDecl td )
8685
return td.Type is TagType tt2 && tt2.IsOpaqueStruct();
8786
}
8887

88+
[SuppressMessage( "Style", "IDE0046:Convert to conditional expression", Justification = "Result is anything but simplified!" )]
8989
public static bool IsCannonicalHandleTypeDef( this TypedefNameDecl td )
9090
{
9191
// Canonical form, declaration is a pointer to an opaque struct
92-
if( !(td.Type is PointerType pt) )
92+
if( td.Type is not PointerType pt )
9393
{
9494
return false;
9595
}
@@ -108,15 +108,15 @@ public static string AsString( this CppSharp.AST.Attribute attr, bool useFullNam
108108
bldr.Append( ": " );
109109
}
110110

111-
bldr.Append( useFullNamespace ? attr.Type.FullName : attr.Type.Name.Substring( 0, attr.Type.Name.Length - 9 /*Len(Attribute)*/ ) );
111+
bldr.Append( useFullNamespace ? attr.Type.FullName : attr.Type.Name[ 0..^9 ] );
112112
if( !string.IsNullOrWhiteSpace( attr.Value ) )
113113
{
114114
bldr.Append( "( " );
115115
bldr.Append( attr.Value );
116116
bldr.Append( " )" );
117117
}
118118

119-
bldr.Append( "]" );
119+
bldr.Append( ']' );
120120
return bldr.ToString();
121121
}
122122

src/Interop/LlvmBindingsGenerator/CppSharpExtensions/Driver.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ public Driver( DriverOptions options )
5252

5353
public BindingContext Context { get; private set; }
5454

55-
public ITypePrinter TypePrinter
56-
{
57-
get => InternalTypePrinter;
58-
set
59-
{
60-
InternalTypePrinter = value;
61-
CppSharp.AST.Type.TypePrinterDelegate = InternalTypePrinter.ToString;
62-
}
63-
}
64-
6555
public void SetupTypeMaps() =>
6656
Context.TypeMaps = new TypeMapDatabase( Context );
6757

@@ -86,7 +76,7 @@ public bool ParseCode()
8676

8777
Context.ASTContext = ClangParser.ConvertASTContext( ParserOptions.ASTContext );
8878
ClangParser.SourcesParsed -= OnSourceFileParsed;
89-
return !hasParsingErrors;
79+
return !HasParsingErrors;
9080
}
9181

9282
public void SortModulesByDependencies()
@@ -222,6 +212,11 @@ public static void Run( ILibrary library )
222212

223213
library.Preprocess( driver.Context.ASTContext );
224214

215+
if( CppSharp.AST.Type.TypePrinterDelegate is null)
216+
{
217+
throw new InvalidOperationException("Type.TypePrinterDelegate is null; Library must configure it to a non-null value to prevent null reference crashes");
218+
}
219+
225220
driver.ProcessCode();
226221
library.Postprocess( driver.Context.ASTContext );
227222

@@ -302,38 +297,38 @@ private void OnFileParsed( IEnumerable<string> files, CppSharp.Parser.ParserResu
302297
{
303298
switch( result.Kind )
304299
{
305-
case CppSharp.Parser.ParserResultKind.Success:
300+
case ParserResultKind.Success:
306301
if( !Options.Quiet )
307302
{
308303
Diagnostics.Message( "Parsed '{0}'", string.Join( ", ", files ) );
309304
}
310305

311306
break;
312307

313-
case CppSharp.Parser.ParserResultKind.Error:
308+
case ParserResultKind.Error:
314309
Diagnostics.Error( "Error parsing '{0}'", string.Join( ", ", files ) );
315-
hasParsingErrors = true;
310+
HasParsingErrors = true;
316311
break;
317312

318-
case CppSharp.Parser.ParserResultKind.FileNotFound:
313+
case ParserResultKind.FileNotFound:
319314
Diagnostics.Error( "File{0} not found: '{1}'"
320315
, ( files.Count() > 1 ) ? "s" : string.Empty
321316
, string.Join( ",", files )
322317
);
323-
hasParsingErrors = true;
318+
HasParsingErrors = true;
324319
break;
325320
}
326321

327322
for( uint i = 0; i < result.DiagnosticsCount; ++i )
328323
{
329324
var diag = result.GetDiagnostics( i );
330325

331-
if( diag.Level == CppSharp.Parser.ParserDiagnosticLevel.Warning && !Options.Verbose )
326+
if( diag.Level == ParserDiagnosticLevel.Warning && !Options.Verbose )
332327
{
333328
continue;
334329
}
335330

336-
if( diag.Level == CppSharp.Parser.ParserDiagnosticLevel.Note )
331+
if( diag.Level == ParserDiagnosticLevel.Note )
337332
{
338333
continue;
339334
}
@@ -348,7 +343,6 @@ private void OnFileParsed( IEnumerable<string> files, CppSharp.Parser.ParserResu
348343
}
349344
}
350345

351-
private ITypePrinter InternalTypePrinter;
352-
private bool hasParsingErrors;
346+
private bool HasParsingErrors;
353347
}
354348
}

src/Interop/LlvmBindingsGenerator/CppSharpExtensions/IDriver.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System;
88

99
using CppSharp;
10-
using CppSharp.AST;
1110
using CppSharp.Generators;
1211
using CppSharp.Parser;
1312
using CppSharp.Passes;
@@ -22,8 +21,6 @@ internal interface IDriver
2221
ParserOptions ParserOptions { get; }
2322

2423
BindingContext Context { get; }
25-
26-
ITypePrinter TypePrinter { get; set; }
2724
}
2825

2926
internal static class DriverExtensions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="ITypePrinter2.cs" company="Ubiquity.NET Contributors">
3+
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
using CppSharp.AST;
8+
9+
namespace LlvmBindingsGenerator
10+
{
11+
internal enum TypeNameKind
12+
{
13+
Native,
14+
Managed,
15+
}
16+
17+
internal interface ITypePrinter2
18+
: ITypePrinter
19+
{
20+
string GetName( CppSharp.AST.Type t, TypeNameKind kind = TypeNameKind.Native );
21+
}
22+
}

0 commit comments

Comments
 (0)