-
-
Notifications
You must be signed in to change notification settings - Fork 435
Fields #880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fields #880
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6baa978
Add Member Symbol & Field Symbol
HurricanKai f496592
Change Visitor to return the same type as it's visiting
HurricanKai d3328ad
Fix visibility of visitor methods
HurricanKai 6b14641
Add Field visiting tests
HurricanKai 0a79945
Reorganize Tests
HurricanKai 6f580bd
Add Identifier Tests
HurricanKai 02c3e26
Correctly visit IdentifierSymbol
HurricanKai 9b6af3b
Add Field Emission
HurricanKai e89b149
Merge branch 'develop/3.0' into dev/3/struct-members
HurricanKai 78b4856
Rename EmitterFieldTests to match develop/3.0
HurricanKai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Silk.NET.SilkTouch.Symbols; | ||
|
||
/// <summary> | ||
/// A <see cref="FieldSymbol"/>. A field is simply a named location that can hold some type. | ||
/// </summary> | ||
/// <seealso cref="MemberSymbol"/> | ||
public sealed class FieldSymbol : MemberSymbol | ||
{ | ||
/// <summary> | ||
/// Create a field symbol from the parent <see cref="TypeSymbol"/>, the type of the field and it's identifier | ||
/// </summary> | ||
/// <param name="type">The type of the data stored in this field</param> | ||
/// <param name="identifier">The identifier of this field</param> | ||
public FieldSymbol(TypeSymbol type, IdentifierSymbol identifier) | ||
{ | ||
Type = type; | ||
Identifier = identifier; | ||
} | ||
|
||
/// <summary> | ||
/// The <see cref="TypeSymbol"/> of the data stored in this field | ||
/// </summary> | ||
public TypeSymbol Type { get; } | ||
|
||
/// <summary> | ||
/// The Identifier of this field | ||
/// </summary> | ||
public IdentifierSymbol Identifier { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Silk.NET.SilkTouch.Symbols; | ||
|
||
/// <summary> | ||
/// A <see cref="MemberSymbol"/>, representing a generic member of some <see cref="TypeSymbol"/> | ||
/// </summary> | ||
/// <seealso cref="FieldSymbol"/> | ||
public abstract class MemberSymbol : Symbol | ||
{ | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterFieldTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Silk.NET.SilkTouch.Symbols; | ||
using Xunit; | ||
|
||
namespace Silk.NET.SilkTouch.Emitter.Tests; | ||
|
||
public sealed class EmitterFieldIntegrationTests : EmitterTest | ||
{ | ||
[Fact] | ||
public void StructHasStructKeyword() | ||
{ | ||
var emitter = CreateEmitter(); | ||
|
||
var symbol = new FieldSymbol(new StructSymbol(new IdentifierSymbol("int")), new IdentifierSymbol("Test")); | ||
|
||
var syntax = emitter.Transform(symbol); | ||
|
||
var result = syntax.ToFullString(); | ||
Assert.Equal("public int Test;", result); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/FieldTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Moq; | ||
using Moq.Protected; | ||
using Xunit; | ||
|
||
namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests; | ||
|
||
public class FieldTests | ||
{ | ||
[Fact] | ||
public void FieldIsVisitedAsField() | ||
{ | ||
var symbol = new FieldSymbol(new StructSymbol(new IdentifierSymbol("")), new IdentifierSymbol("")); | ||
var visitor = new Mock<SymbolVisitor> | ||
{ | ||
CallBase = true | ||
}; | ||
|
||
visitor.Object.Visit(symbol); | ||
|
||
visitor.Protected() | ||
.Verify<FieldSymbol>("VisitField", Times.Once(), ItExpr.IsAny<FieldSymbol>()); | ||
} | ||
|
||
[Fact] | ||
public void FieldIsVisitedAsMember() | ||
{ | ||
var symbol = new FieldSymbol(new StructSymbol(new IdentifierSymbol("")), new IdentifierSymbol("")); | ||
var visitor = new Mock<SymbolVisitor> | ||
{ | ||
CallBase = true | ||
}; | ||
|
||
visitor.Object.Visit(symbol); | ||
|
||
visitor.Protected() | ||
.Verify<MemberSymbol>("VisitMember", Times.Once(), ItExpr.IsAny<MemberSymbol>()); | ||
} | ||
|
||
[Fact] | ||
public void FieldTypeIsVisited() | ||
{ | ||
var symbol = new FieldSymbol(new StructSymbol(new IdentifierSymbol("")), new IdentifierSymbol("")); | ||
var visitor = new Mock<SymbolVisitor> | ||
{ | ||
CallBase = true | ||
}; | ||
|
||
visitor.Object.Visit(symbol); | ||
|
||
visitor.Protected() | ||
.Verify<TypeSymbol>("VisitType", Times.Once(), ItExpr.IsAny<TypeSymbol>()); | ||
} | ||
|
||
[Fact] | ||
public void FieldIdentifierIsVisited() | ||
{ | ||
var symbol = new FieldSymbol(new StructSymbol(new IdentifierSymbol("")), new IdentifierSymbol("")); | ||
var visitor = new Mock<SymbolVisitor> | ||
{ | ||
CallBase = true | ||
}; | ||
|
||
visitor.Object.Visit(symbol); | ||
|
||
// note that this also tests whether the struct identifier is visited, there's just no good way of testing JUST the field identifier | ||
visitor.Protected() | ||
.Verify<IdentifierSymbol>("VisitIdentifier", Times.Exactly(2), ItExpr.IsAny<IdentifierSymbol>()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/IdentifierTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Moq; | ||
using Moq.Protected; | ||
using Xunit; | ||
|
||
namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests; | ||
|
||
public class IdentifierTests | ||
{ | ||
[Fact] | ||
public void IdentifierIsVisitedAsIdentifier() | ||
{ | ||
var symbol = new IdentifierSymbol(""); | ||
var visitor = new Mock<SymbolVisitor> | ||
{ | ||
CallBase = true | ||
}; | ||
|
||
visitor.Object.Visit(symbol); | ||
|
||
visitor.Protected() | ||
.Verify<IdentifierSymbol>("VisitIdentifier", Times.Once(), ItExpr.IsAny<IdentifierSymbol>()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.