File tree 4 files changed +63
-17
lines changed
src/generators/Silk.NET.SilkTouch.Scraper
tests/Silk.NET.SilkTouch.Scraper.Tests
4 files changed +63
-17
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,7 @@ public IEnumerable<Symbol> ScrapeXML(XmlDocument document)
43
43
}
44
44
45
45
var visitor = new XmlVisitor ( ) ;
46
- visitor . Visit ( bindings ) ;
47
-
48
- return visitor . Symbols ;
46
+ return visitor . Visit ( bindings ) ;
49
47
}
50
48
51
49
/// <summary>
Original file line number Diff line number Diff line change 3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Collections . Immutable ;
6
7
using System . Linq ;
8
+ using System . Reflection . Metadata ;
7
9
using System . Xml ;
8
10
using Silk . NET . SilkTouch . Symbols ;
9
11
10
12
namespace Silk . NET . SilkTouch . Scraper ;
11
13
12
14
internal sealed class XmlVisitor
13
15
{
14
- private List < Symbol > _symbols = new ( ) ;
15
-
16
- public IEnumerable < Symbol > Symbols => _symbols ;
17
-
18
- public void Visit ( XmlNode node )
16
+ public IEnumerable < Symbol > Visit ( XmlNode node )
19
17
{
20
18
switch ( node )
21
19
{
22
20
case XmlElement { Name : "bindings" } bindings :
23
- {
24
- foreach ( var child in bindings . ChildNodes . Cast < XmlNode > ( ) )
25
- {
26
- if ( child is null ) continue ;
27
- Visit ( child ) ;
28
- }
29
- break ;
30
- }
21
+ return VisitBinding ( bindings ) ;
22
+ case XmlElement { Name : "namespace" } @namespace :
23
+ return VisitNamespace ( @namespace ) ;
31
24
default :
32
25
{
33
26
throw new NotImplementedException ( ) ;
34
27
}
35
28
}
36
29
}
30
+
31
+ private IEnumerable < Symbol > VisitBinding ( XmlElement bindings )
32
+ {
33
+ return bindings . ChildNodes . Cast < XmlNode > ( ) . Where ( x => x is not null ) . SelectMany ( Visit ) ;
34
+ }
35
+
36
+ private IEnumerable < Symbol > VisitNamespace ( XmlElement @namespace )
37
+ {
38
+ return new [ ]
39
+ {
40
+ new NamespaceSymbol
41
+ (
42
+ new IdentifierSymbol ( @namespace . Attributes ? [ "name" ] ? . Value ?? throw new InvalidOperationException ( ) ) ,
43
+ @namespace . ChildNodes . Cast < XmlNode > ( )
44
+ . Select ( Visit )
45
+ . Select
46
+ (
47
+ x =>
48
+ {
49
+ if ( x is not TypeSymbol ts ) throw new InvalidOperationException ( ) ;
50
+ return ts ;
51
+ }
52
+ )
53
+ . ToImmutableArray ( )
54
+ )
55
+ } ;
56
+ }
37
57
}
Original file line number Diff line number Diff line change
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
+ // The .NET Foundation licenses this file to you under the MIT license.
3
+
4
+ using System . Xml ;
5
+ using Silk . NET . SilkTouch . Symbols ;
6
+ using Xunit ;
7
+
8
+ namespace Silk . NET . SilkTouch . Scraper . Tests ;
9
+
10
+ public class NamespaceScrapingTests
11
+ {
12
+ [ Fact ]
13
+ public void NamespaceXMLGeneratesNamespaceSymbol ( )
14
+ {
15
+ var doc = new XmlDocument ( ) ;
16
+ doc . LoadXml ( @"<bindings>
17
+ <namespace name=""" + ClangScraper . LibraryNamespacePlaceholder + @""">
18
+ </namespace>
19
+ </bindings>
20
+ " ) ;
21
+
22
+ var symbols = new ClangScraper ( ) . ScrapeXML ( doc ) ;
23
+
24
+ var symbol = Assert . Single ( symbols ) ;
25
+ var @namespace = Assert . IsType < NamespaceSymbol > ( symbol ) ;
26
+ Assert . Equal ( ClangScraper . LibraryNamespacePlaceholder , @namespace . Identifier . Value ) ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,6 @@ public class StructScrapingTests
10
10
[ Fact ]
11
11
public void StructXMLGeneratesStructSymbol ( )
12
12
{
13
-
13
+
14
14
}
15
15
}
You can’t perform that action at this time.
0 commit comments