Files
zeekay 2aa8261f86 rebrand: complete capnp → ZAP across all C# source/build files
Finishes the in-flight capnp→ZAP rebrand on this branch. The prior commits
renamed identifiers/namespaces/files/projects (Capnp.Net.Runtime→Zap.Net.Runtime,
CapnpC→ZapC, .capnp→.zap) but left the human-readable brand name "Cap'n Proto"
throughout doc-comments, .csproj/.nuspec descriptions, README, MSBuild .xaml
rule display names, and the generated XML doc. This completes brand neutrality:

- Replace 154 "Cap'n Proto" / 4 "Cap'n-Proto" / 1 "Cap'n'p" prose occurrences
  with "ZAP" across 32 first-party files (runtime, generator, zapc-csharp,
  MSBuild integration, chocolatey nuspecs, README, docs, XML doc).
- Revert the LICENSE provenance URL to the real upstream fork
  (c80k/capnproto-dotnetcore) — upstream-fork license headers must stay.
- Canonicalize project/repo URLs to github.com/zap-proto/cs (were fabricated
  c80k/zap-dotnetcore) in csproj/nuspec/VERIFICATION/README badges.
- Canonicalize docs URLs zap-protocol(.github.io|/zap-cs|/zap-cpp-core)
  → zap-proto.dev / github.com/zap-proto/{cs,cpp-core}.
- Collapse redundant "zap \"ZAP\"" PackageTags to "zap".

Verified consistent (no toolchain on host): every .sln/.csproj ProjectReference
resolves; all namespaces are Zap*/ZapC*; MSBuild task chain
(GenerateZapFileCodeBehindTask, ZapFiles ItemGroup, _ZapcCsharp_TaskAssembly)
is uniformly renamed; props/targets/xaml/coverage/chocolatey carry no capnp.

Deliberately preserved as upstream-derived test data (not first-party source):
upstream Cap'n Proto schema fixtures (rpc.zap, rpc-twoparty.zap, json.zap,
rpc-csharp.zap), golden compiler-error outputs (errors.txt), and the
machine-generated DO-NOT-EDIT test.zap.{c++,h}. Their "Cap'n Proto" strings are
the literal output of the external schema compiler the compat test matches.
2026-06-19 23:46:57 -07:00

68 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace ZapC.CSharp.Generator.Model
{
class DefinitionManager
{
readonly Dictionary<ulong, IDefinition> _id2def = new Dictionary<ulong, IDefinition>();
public GenFile CreateFile(ulong id, bool isGenerated)
=> CreateId<GenFile>(id, () => new GenFile(id, isGenerated));
public GenFile GetExistingFile(ulong id)
=> GetId<GenFile>(id, TypeTag.File);
public TypeDefinition CreateTypeDef(ulong id, TypeTag tag, IHasNestedDefinitions decl)
=> CreateId<TypeDefinition>(id, () => new TypeDefinition(tag, id, decl));
public TypeDefinition GetExistingTypeDef(ulong id, TypeTag tag)
{
var def = GetId<TypeDefinition>(id, tag);
if (def.Tag == TypeTag.Unknown) def.Tag = tag;
return def;
}
public Annotation CreateAnnotation(ulong id, IHasNestedDefinitions decl)
=> CreateId<Annotation>(id, () => new Annotation(id, decl));
public Annotation GetExistingAnnotation(ulong id)
=> GetId<Annotation>(id, TypeTag.Annotation);
public Constant CreateConstant(ulong id, IHasNestedDefinitions decl)
=> CreateId<Constant>(id, () => new Constant(id, decl));
public Constant GetExistingConstant(ulong id)
=> GetId<Constant>(id, TypeTag.Const);
public IDefinition GetExistingDef(ulong id, TypeTag tag)
=> GetId<IDefinition>(id, tag);
public IEnumerable<GenFile> Files
{
get => _id2def.Values.Where(d => d.Tag == TypeTag.File).Select(f => f as GenFile);
}
T CreateId<T>(ulong id, Func<IDefinition> creator) where T : class, IDefinition
{
if (_id2def.TryGetValue(id, out var d))
{
throw new ArgumentException(nameof(id), $"Attempting to redefine {d.Tag.ToString()} {id.StrId()} (as {nameof(T)}).");
}
var def = creator();
_id2def.Add(id, def);
return def as T;
}
T GetId<T>(ulong id, TypeTag tag) where T : IDefinition
{
if (!_id2def.TryGetValue(id, out var anyDef))
{
throw new ArgumentOutOfRangeException($"Attempting to retrieve nonexistent node {id.StrId()}.");
}
if (!(anyDef is T def) || (tag != TypeTag.Unknown && def.Tag != tag))
{
throw new ArgumentOutOfRangeException($"Attempting to retrieve {tag.ToString()} {id.StrId()}, but found {anyDef.Tag.ToString()} instead.");
}
return def;
}
}
}