Skip to content

Commit

Permalink
feat: Bind Scope and Filter symbols of a Query
Browse files Browse the repository at this point in the history
part of: Implement Logic in Symbol layer #44
  • Loading branch information
amis92 committed Mar 1, 2023
1 parent bb8c52a commit acb873a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
37 changes: 19 additions & 18 deletions src/WarHub.ArmouryModel.Concrete.Extensions/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ internal ICatalogueSymbol BindCatalogueSymbol(ForceNode node, BindingDiagnosticB
BindSimple<ICatalogueSymbol, ErrorSymbols.ErrorCatalogueSymbol>(
node, diagnostics, node.CatalogueId, LookupOptions.CatalogueOnly);

internal ICatalogueSymbol BindCatalogueSymbol(SourceNode node, string? symboldId, BindingDiagnosticBag diagnostics) =>
BindSimple<ICatalogueSymbol, ErrorSymbols.ErrorCatalogueSymbol>(
node, diagnostics, symboldId, LookupOptions.CatalogueOnly);

internal ICatalogueSymbol BindGamesystemSymbol(CatalogueNode node, BindingDiagnosticBag diagnostics) =>
BindSimple<ICatalogueSymbol, ErrorSymbols.ErrorGamesystemSymbol>(
node, diagnostics, node.GamesystemId, LookupOptions.CatalogueOnly);
Expand Down Expand Up @@ -112,30 +116,27 @@ internal ICategoryEntrySymbol BindCategoryEntrySymbol(CategoryNode node, Binding
BindSimple<ICategoryEntrySymbol, ErrorSymbols.ErrorCategoryEntrySymbol>(
node, diagnostics, node.EntryId, LookupOptions.CategoryEntryOnly);

[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Method is WIP")]
internal ISymbol? BindEntryMemberSymbol(SourceNode declaration, string? field, BindingDiagnosticBag diagnostics)
{
// TODO implement query/modifier field binding (constraint, cost, characteristic etc)
return null;
}
internal ICategoryEntrySymbol BindCategoryEntrySymbol(SourceNode node, string? symbolId, BindingDiagnosticBag diagnostics) =>
BindSimple<ICategoryEntrySymbol, ErrorSymbols.ErrorCategoryEntrySymbol>(
node, diagnostics, symbolId, LookupOptions.CategoryEntryOnly);

[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Method is WIP")]
internal ISymbol? BindFilterEntrySymbol(SourceNode node, string? symbolId, BindingDiagnosticBag diagnostics)
internal ISymbol BindEffectTargetMemberSymbol(SourceNode node, string? symbolId, BindingDiagnosticBag diagnostics)
{
// TODO implement query filter binding
return null;
// TODO implement modifier field binding (constraint, cost, characteristic etc)
return null!;
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Method is WIP")]
internal ISymbol? BindScopeEntrySymbol(SourceNode node, string? symbolId, BindingDiagnosticBag diagnostics)
{
// TODO implement query scope binding
return null;
}
internal ISymbol BindFilterEntrySymbol(SourceNode node, string? symbolId, QueryScopeKind scopeKind, BindingDiagnosticBag diagnostics)
=> scopeKind switch
{
QueryScopeKind.PrimaryCatalogue => BindCatalogueSymbol(node, symbolId, diagnostics),
QueryScopeKind.PrimaryCategory => BindCategoryEntrySymbol(node, symbolId, diagnostics),
_ => BindSimple<IContainerEntrySymbol, ErrorSymbols.ErrorContainerEntrySymbol>(node, diagnostics, symbolId, LookupOptions.ContainerEntryOnly)
};

internal ICategoryEntrySymbol BindCategoryEntrySymbol(SourceNode node, string? symbolId, BindingDiagnosticBag diagnostics) =>
BindSimple<ICategoryEntrySymbol, ErrorSymbols.ErrorCategoryEntrySymbol>(
node, diagnostics, symbolId, LookupOptions.CategoryEntryOnly);
internal ISymbol BindScopeEntrySymbol(SourceNode node, string? symbolId, BindingDiagnosticBag diagnostics) =>
BindSimple<IContainerEntrySymbol, ErrorSymbols.ErrorContainerEntrySymbol>(node, diagnostics, symbolId, LookupOptions.ContainerEntryOnly);

internal ISelectionEntryContainerSymbol BindSelectionEntryGroupDefaultEntrySymbol(
SelectionEntryGroupNode node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override void BindReferencesCore(Binder binder, BindingDiagnosticBag d
}
else if (TargetKind is EffectTargetKind.Member)
{
lazyTargetMember = binder.BindEntryMemberSymbol(Declaration, Declaration.Field, diagnostics);
lazyTargetMember = binder.BindEffectTargetMemberSymbol(Declaration, Declaration.Field, diagnostics);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected override void BindReferencesCore(Binder binder, BindingDiagnosticBag d
base.BindReferencesCore(binder, diagnostics);
if (ValueKind is QueryValueKind.MemberValue)
{
lazyValueType = binder.BindEntryMemberSymbol(Declaration, Declaration.Field, diagnostics);
lazyValueType = binder.BindCostTypeSymbol(Declaration, Declaration.Field, diagnostics);
}
else if (ValueKind is QueryValueKind.MemberValueLimit)
{
Expand All @@ -159,7 +159,7 @@ protected override void BindReferencesCore(Binder binder, BindingDiagnosticBag d
}
if (ValueFilterKind is QueryFilterKind.SpecifiedEntry)
{
lazyFilter = binder.BindFilterEntrySymbol(Declaration, Declaration.Scope, diagnostics);
lazyFilter = binder.BindFilterEntrySymbol(Declaration, ((QueryFilteredBaseNode)Declaration).ChildId, ScopeKind, diagnostics);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ public void Dataset_compiles_and_binds()
var convoyForceEntry = gamesystem.RootContainerEntries.First(x => x.Name == "Convoy");
convoyForce.SourceEntry.Should().Be(convoyForceEntry);

// force's constraint field (Cost) is bound
var convoyMaxPoints = convoyForceEntry.Constraints.First(x => x.Query.ValueKind == QueryValueKind.MemberValue);
convoyMaxPoints.Query.ValueTypeSymbol.Should().Be(gamesystem.ResourceDefinitions.First(x => x.Name == "Points"));

// force's modifier condition is fully bound
var convoySetMax100Modifier = convoyForceEntry.Effects.Single(x => x.OperandValue == "100.0");
// TODO when Binder.BindEffectTargetMemberSymbol is implemented
//convoySetMax100Modifier.TargetMember.Should().Be(convoyMaxPoints);
var convoyMaxCondition = convoySetMax100Modifier.Condition!.Children.Single();
convoyMaxCondition.Query.Should().NotBeNull();
convoyMaxCondition.Query!.ScopeSymbol.Should().Be(gamesystem.RootContainerEntries.First(x => x.Name == "Game Options"));
convoyMaxCondition.Query!.FilterSymbol.Should().Be(gameSizeGroup.ChildSelectionEntries.First(x => x.Name == "100 Points"));

// force's rule is bound
convoyForce.Resources.First(x => x.Name.Contains("Gold")).SourceEntry
.Should().Be(grannies.RootResourceEntries.First(x => x.Name.Contains("Gold")));
Expand Down

0 comments on commit acb873a

Please sign in to comment.