File tree 3 files changed +75
-0
lines changed
src/generators/Silk.NET.SilkTouch.Symbols
tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests
3 files changed +75
-0
lines changed 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 . Collections . Immutable ;
5
+
6
+ namespace Silk . NET . SilkTouch . Symbols ;
7
+
8
+ /// <summary>
9
+ /// A <see cref="Symbol"/> representing a <c>namespace</c>
10
+ /// </summary>
11
+ public sealed record NamespaceSymbol ( IdentifierSymbol Identifier , ImmutableArray < TypeSymbol > Types ) : Symbol
12
+ {
13
+ }
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ public virtual Symbol Visit(Symbol symbol)
19
19
{
20
20
if ( symbol is TypeSymbol ts ) return VisitType ( ts ) ;
21
21
if ( symbol is MemberSymbol ms ) return VisitMember ( ms ) ;
22
+ if ( symbol is NamespaceSymbol ns ) return VisitNamespace ( ns ) ;
22
23
23
24
if ( symbol is IdentifierSymbol @is ) return VisitIdentifier ( @is ) ;
24
25
@@ -97,6 +98,20 @@ protected virtual IdentifierSymbol VisitIdentifier(IdentifierSymbol identifierSy
97
98
return identifierSymbol ;
98
99
}
99
100
101
+ /// <summary>
102
+ /// Visit a <see cref="NamespaceSymbol"/>.
103
+ /// </summary>
104
+ /// <param name="namespaceSymbol">The Namespace to Visit.</param>
105
+ /// <returns>The rewritten symbol</returns>
106
+ protected virtual NamespaceSymbol VisitNamespace ( NamespaceSymbol namespaceSymbol )
107
+ {
108
+ return namespaceSymbol with
109
+ {
110
+ Identifier = VisitIdentifier ( namespaceSymbol . Identifier ) ,
111
+ Types = namespaceSymbol . Types . Select ( VisitType ) . ToImmutableArray ( )
112
+ } ;
113
+ }
114
+
100
115
private static T ThrowUnknownSymbol < T > ( Symbol symbol )
101
116
{
102
117
throw new NotImplementedException ( $ "Unknown symbol of type { symbol . GetType ( ) . FullName } subclass of { typeof ( T ) . Name } ") ;
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 . Collections . Immutable ;
5
+ using Moq ;
6
+ using Moq . Protected ;
7
+ using Xunit ;
8
+
9
+ namespace Silk . NET . SilkTouch . Symbols . Tests . SymbolVisitorTests ;
10
+
11
+ public class NamespaceTests
12
+ {
13
+ [ Fact ]
14
+ public void NamespaceIdentifierIsVisited ( )
15
+ {
16
+ var symbol = new NamespaceSymbol ( new IdentifierSymbol ( "" ) , ImmutableArray < TypeSymbol > . Empty ) ;
17
+
18
+ var visitor = new Mock < SymbolVisitor >
19
+ {
20
+ CallBase = true
21
+ } ;
22
+
23
+ visitor . Object . Visit ( symbol ) ;
24
+
25
+ visitor . Protected ( )
26
+ . Verify < IdentifierSymbol > ( "VisitIdentifier" , Times . Once ( ) , ItExpr . IsAny < IdentifierSymbol > ( ) ) ;
27
+ }
28
+
29
+ [ Fact ]
30
+ public void NamespaceMemberIsVisited ( )
31
+ {
32
+ var symbol = new NamespaceSymbol ( new IdentifierSymbol ( "" ) , new [ ]
33
+ {
34
+ ( TypeSymbol ) new StructSymbol ( new IdentifierSymbol ( "" ) , StructLayout . Empty )
35
+ } . ToImmutableArray ( ) ) ;
36
+
37
+ var visitor = new Mock < SymbolVisitor >
38
+ {
39
+ CallBase = true
40
+ } ;
41
+
42
+ visitor . Object . Visit ( symbol ) ;
43
+
44
+ visitor . Protected ( )
45
+ . Verify < StructSymbol > ( "VisitStruct" , Times . Once ( ) , ItExpr . IsAny < StructSymbol > ( ) ) ;
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments