Skip to content

Commit

Permalink
refactor(compiler): rename ConstantValue
Browse files Browse the repository at this point in the history
- I've renamed ConstantValue and all the related types to ConstantExpression to better match the
  parser grammar.

Issues: #8
  • Loading branch information
adamconnelly committed Jan 3, 2021
1 parent 01479b7 commit 20931e3
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/Thrift.Net.Compilation/Binding/BinderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BinderProvider : IBinderProvider
private static readonly SetTypeBinder SetTypeBinder;
private static readonly MapTypeBinder MapTypeBinder;
private static readonly ConstantBinder ConstantBinder;
private static readonly ConstantValueBinder ConstantValueBinder;
private static readonly ConstantExpressionBinder ConstantExpressionBinder;
private static readonly BinderProvider ProviderInstance;

static BinderProvider()
Expand All @@ -47,7 +47,7 @@ static BinderProvider()
MapTypeBinder = new MapTypeBinder(ProviderInstance);
SetTypeBinder = new SetTypeBinder(ProviderInstance);
ConstantBinder = new ConstantBinder(ProviderInstance);
ConstantValueBinder = new ConstantValueBinder();
ConstantExpressionBinder = new ConstantExpressionBinder();
}

private BinderProvider()
Expand Down Expand Up @@ -138,7 +138,7 @@ public IBinder GetBinder(IParseTree node)
}
else if (node is ConstExpressionContext)
{
return ConstantValueBinder;
return ConstantExpressionBinder;
}

throw new ArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace Thrift.Net.Compilation.Binding
using static Thrift.Net.Antlr.ThriftParser;

/// <summary>
/// Used to bind <see cref="IConstantValue" /> symbols from <see cref="ConstExpressionContext" />
/// Used to bind <see cref="IConstantExpression" /> symbols from <see cref="ConstExpressionContext" />
/// nodes.
/// </summary>
public class ConstantValueBinder : Binder<ConstExpressionContext, IConstantValue, IConstant>
public class ConstantExpressionBinder : Binder<ConstExpressionContext, IConstantExpression, IConstant>
{
/// <inheritdoc/>
protected override IConstantValue Bind(ConstExpressionContext node, IConstant parent)
protected override IConstantExpression Bind(ConstExpressionContext node, IConstant parent)
{
var type = GetExpressionType(node);

var builder = new ConstantValueBuilder()
var builder = new ConstantExpressionBuilder()
.SetNode(node)
.SetParent(parent)
.SetRawValue(node.value?.Text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Thrift.Net.Compilation.Symbols.Builders
/// <summary>
/// Used to build <see cref="Constant" /> objects.
/// </summary>
public class ConstantValueBuilder : SymbolBuilder<ConstExpressionContext, ConstantValue, IConstant, ConstantValueBuilder>
public class ConstantExpressionBuilder : SymbolBuilder<ConstExpressionContext, ConstantExpression, IConstant, ConstantExpressionBuilder>
{
private string rawValue;
private IFieldType type;
Expand All @@ -25,7 +25,7 @@ public class ConstantValueBuilder : SymbolBuilder<ConstExpressionContext, Consta
/// </summary>
/// <param name="rawValue">The string representation of the constant expression.</param>
/// <returns>The builder.</returns>
public ConstantValueBuilder SetRawValue(string rawValue)
public ConstantExpressionBuilder SetRawValue(string rawValue)
{
this.rawValue = rawValue;

Expand All @@ -37,17 +37,17 @@ public ConstantValueBuilder SetRawValue(string rawValue)
/// </summary>
/// <param name="type">The type of the expression.</param>
/// <returns>The builder.</returns>
public ConstantValueBuilder SetType(IFieldType type)
public ConstantExpressionBuilder SetType(IFieldType type)
{
this.type = type;

return this;
}

/// <inheritdoc/>
public override ConstantValue Build()
public override ConstantExpression Build()
{
return new ConstantValue(this.Node, this.Parent, this.RawValue, this.Type);
return new ConstantExpression(this.Node, this.Parent, this.RawValue, this.Type);
}
}
}
4 changes: 2 additions & 2 deletions src/Thrift.Net.Compilation/Symbols/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public IFieldType Type
}

/// <inheritdoc/>
public IConstantValue Value
public IConstantExpression Value
{
get
{
return this.binderProvider.GetBinder(this.Node.constExpression())
.Bind<IConstantValue>(this.Node.constExpression(), this);
.Bind<IConstantExpression>(this.Node.constExpression(), this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ namespace Thrift.Net.Compilation.Symbols
/// <summary>
/// Represents a constant expression value.
/// </summary>
public class ConstantValue : Symbol<ConstExpressionContext, IConstant>, IConstantValue
public class ConstantExpression : Symbol<ConstExpressionContext, IConstant>, IConstantExpression
{
/// <summary>
/// Initializes a new instance of the <see cref="ConstantValue" /> class.
/// Initializes a new instance of the <see cref="ConstantExpression" /> class.
/// </summary>
/// <param name="node">The parse tree node.</param>
/// <param name="parent">The constant that contains this value.</param>
/// <param name="rawValue">The raw value representing the constant expression.</param>
/// <param name="type">The type of the constant expression.</param>
public ConstantValue(
public ConstantExpression(
ConstExpressionContext node,
IConstant parent,
string rawValue,
Expand Down
2 changes: 1 addition & 1 deletion src/Thrift.Net.Compilation/Symbols/IConstant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public interface IConstant : INamedTypeSymbol
/// <summary>
/// Gets the value of the constant definition.
/// </summary>
IConstantValue Value { get; }
IConstantExpression Value { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Thrift.Net.Compilation.Symbols
{
/// <summary>
/// Represents a Thrift constant.
/// Represents the initialisation expression for a Thrift constant.
/// </summary>
public interface IConstantValue : ISymbol
public interface IConstantExpression : ISymbol
{
/// <summary>
/// Gets the type of the constant's expression. For example, the constant
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
namespace Thrift.Net.Tests.Compilation.Binding.ConstantValueBinder
namespace Thrift.Net.Tests.Compilation.Binding.ConstantExpressionBinder
{
using NSubstitute;
using Thrift.Net.Compilation.Symbols;
using Thrift.Net.Tests.Utility;
using Xunit;

using ConstantValueBinder = Thrift.Net.Compilation.Binding.ConstantValueBinder;
using ConstantExpressionBinder = Thrift.Net.Compilation.Binding.ConstantExpressionBinder;

public class RawValueTests
{
[Fact]
public void RawValueProvided_SetsRawValue()
{
// Arrange
var binder = new ConstantValueBinder();
var binder = new ConstantExpressionBinder();
var node = ParserInput.FromString("100")
.ParseInput(parser => parser.constExpression());
var parent = Substitute.For<IConstant>();

// Act
var value = binder.Bind<IConstantValue>(node, parent);
var value = binder.Bind<IConstantExpression>(node, parent);

// Assert
Assert.Equal("100", value.RawValue);
Expand All @@ -29,13 +29,13 @@ public void RawValueProvided_SetsRawValue()
public void RawValueNotProvided_Null()
{
// Arrange
var binder = new ConstantValueBinder();
var binder = new ConstantExpressionBinder();
var node = ParserInput.FromString(string.Empty)
.ParseInput(parser => parser.constExpression());
var parent = Substitute.For<IConstant>();

// Act
var value = binder.Bind<IConstantValue>(node, parent);
var value = binder.Bind<IConstantExpression>(node, parent);

// Assert
Assert.Null(value.RawValue);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace Thrift.Net.Tests.Compilation.Binding.ConstantValueBinder
namespace Thrift.Net.Tests.Compilation.Binding.ConstantExpressionBinder
{
using System.Collections.Generic;
using NSubstitute;
using Thrift.Net.Compilation.Symbols;
using Thrift.Net.Tests.Utility;
using Xunit;

using ConstantValueBinder = Thrift.Net.Compilation.Binding.ConstantValueBinder;
using ConstantExpressionBinder = Thrift.Net.Compilation.Binding.ConstantExpressionBinder;

public class TypeTests
{
Expand Down Expand Up @@ -38,13 +38,13 @@ public static IEnumerable<object[]> GetTestCases()
public void SetsCorrectTypeForValue(string input, BaseType expectedType)
{
// Arrange
var binder = new ConstantValueBinder();
var binder = new ConstantExpressionBinder();
var node = ParserInput.FromString(input)
.ParseInput(parser => parser.constExpression());
var parent = Substitute.For<IConstant>();

// Act
var value = binder.Bind<IConstantValue>(node, parent);
var value = binder.Bind<IConstantExpression>(node, parent);

// Assert
Assert.Same(expectedType, value.Type);
Expand Down

0 comments on commit 20931e3

Please sign in to comment.