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

136 lines
5.5 KiB
C#

using System;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace ZapC.CSharp.Generator.CodeGen
{
static class SyntaxHelpers
{
public static string MakeUpperCamel(string name) => $"{char.ToUpperInvariant(name[0])}{name.Substring(1)}";
public static string MakeLowerCamel(string name) => $"{char.ToLowerInvariant(name[0])}{name.Substring(1)}";
public static readonly SyntaxToken Async = Token(SyntaxKind.AsyncKeyword);
public static readonly SyntaxToken Public = Token(SyntaxKind.PublicKeyword);
public static readonly SyntaxToken Private = Token(SyntaxKind.PrivateKeyword);
public static readonly SyntaxToken Readonly = Token(SyntaxKind.ReadOnlyKeyword);
public static readonly SyntaxToken Static = Token(SyntaxKind.StaticKeyword);
public static readonly SyntaxToken Override = Token(SyntaxKind.OverrideKeyword);
public static readonly SyntaxToken Partial = Token(SyntaxKind.PartialKeyword);
public static readonly SyntaxToken This = Token(SyntaxKind.ThisKeyword);
public static TypeSyntax NonNullableType(Type type)
{
switch (0)
{
case 0 when type == typeof(bool):
return PredefinedType(Token(SyntaxKind.BoolKeyword));
case 0 when type == typeof(sbyte):
return PredefinedType(Token(SyntaxKind.SByteKeyword));
case 0 when type == typeof(byte):
return PredefinedType(Token(SyntaxKind.ByteKeyword));
case 0 when type == typeof(short):
return PredefinedType(Token(SyntaxKind.ShortKeyword));
case 0 when type == typeof(ushort):
return PredefinedType(Token(SyntaxKind.UShortKeyword));
case 0 when type == typeof(int):
return PredefinedType(Token(SyntaxKind.IntKeyword));
case 0 when type == typeof(uint):
return PredefinedType(Token(SyntaxKind.UIntKeyword));
case 0 when type == typeof(long):
return PredefinedType(Token(SyntaxKind.LongKeyword));
case 0 when type == typeof(ulong):
return PredefinedType(Token(SyntaxKind.ULongKeyword));
case 0 when type == typeof(float):
return PredefinedType(Token(SyntaxKind.FloatKeyword));
case 0 when type == typeof(double):
return PredefinedType(Token(SyntaxKind.DoubleKeyword));
case 0 when type == typeof(string):
return PredefinedType(Token(SyntaxKind.StringKeyword));
case 0 when type == typeof(object):
return PredefinedType(Token(SyntaxKind.ObjectKeyword));
case 0 when type.IsGenericType:
return GenericName(type.Name.Substring(0, type.Name.IndexOf('`')))
.AddTypeArgumentListArguments(type.GetGenericArguments().Select(NonNullableType).ToArray());
default:
return ParseTypeName(type.Name);
}
}
public static TypeSyntax NonNullableType<T>() => NonNullableType(typeof(T));
public static ExpressionSyntax ValueOf(object value)
{
switch (value)
{
case bool x:
return LiteralExpression(x ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression);
case sbyte x:
return CastExpression(NonNullableType<sbyte>(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)));
case byte x:
return CastExpression(NonNullableType<byte>(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)));
case short x:
return CastExpression(NonNullableType<short>(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)));
case ushort x:
return CastExpression(NonNullableType<ushort>(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)));
case int x:
return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x));
case uint x:
return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x));
case long x:
return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x));
case ulong x:
return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x));
case float x:
return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x));
case double x:
return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x));
case string x:
return LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(x));
case null:
return LiteralExpression(SyntaxKind.NullLiteralExpression);
default:
throw new NotImplementedException();
}
}
public static TypeSyntax MakeNonNullableType(TypeSyntax type)
{
if (type is NullableTypeSyntax nts)
{
type = nts.ElementType;
}
return type;
}
}
}