C#: Consolidate namespace and compilation unit model#6981
Merged
Conversation
e30ad07 to
ed2565a
Compare
Merge `BlockScopeNamespaceDeclaration` and `FileScopeNamespaceDeclaration` into a single `NamespaceDeclaration` type. Remove redundant `externs`, `usings`, and `attributeLists` fields from `CompilationUnit` since these are already represented as members. Update visitor, printer, RPC sender/receiver, and tests on both Java and C# sides. Also increase `CSharpRpcTest` RPC timeout from 60s to 120s to fix a transient timeout flake in `parsePragmaWarningMultipleCodes`.
ed2565a to
77bf237
Compare
5 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Align the C# model, visitors, and RPC layer so that both sides (Java and C#/.NET) use identical shapes. This eliminates workarounds where the C# RPC sender/receiver had to split, merge, or fabricate fields to bridge structural differences.
Asymmetries fixed
Model consolidations (Cs.java)
BlockScopeNamespaceDeclaration+FileScopeNamespaceDeclaration→NamespaceDeclaration— Java had two separate types; C# had oneNamespaceDeclaration. Merged into a singleCs.NamespaceDeclarationon the Java side. Removed theRegisterJavaTypeNameoverride that mappedNamespaceDeclaration → Cs$BlockScopeNamespaceDeclaration.CompilationUnit.externs,.usings,.attributeListsremoved — These were redundant top-level fields; externs, usings, and attribute lists are already represented as statements withinCompilationUnit.members. The C# side never had these separate fields.NamespaceDeclaration.externsand.usingsremoved — Same redundancy as CompilationUnit: these were split out on the Java side but are just members on the C# side. The C# RPC sender/receiver had workaround code to filterUsingDirectivevs non-UsingDirectivemembers and merge them back — now removed.UsingDirective.unsafefield removed — Java modeled anunsafeleft-padded boolean that the C# side never had. The C# sender fabricated aJLeftPadded<bool>(Space.Empty, false)dummy, and the receiver consumed and discarded it. Both workarounds removed.Cs.TryandCs.Try.Catchremoved — These were Java-only duplicates ofJ.Try/J.Try.Catch. The C# side uses the standardJ.Trytree. Removed the redundant Cs types along with their visitor methods, RPC sender/receiver, and iso-visitor overrides.J model alignment (J.cs on the C# side)
J.Package.Expression:JRightPadded<Expression>→Expression— Java side uses a plainExpression; C# had an extra right-padding wrapper. Parser, printer, visitor, and RPC updated.J.EnumValue.Initializer:JLeftPadded<Expression>?→NewClass?— Java side uses a directNewClass?; C# had an extra left-padding wrapper. Printer no longer manually prints=and spacing — delegates to theNewClassvisit.J.Try.Resources:JContainer<NameTree>?→JContainer<Try.Resource>?— Java side wraps try-with-resources in aTry.Resourcenode (holdingvariableDeclarations+terminatedWithSemicolon). Added the missingTry.Resourceclass to C#J.cs, plusVisitTryResourcein both JavaSender.cs and JavaReceiver.cs.J.NewClass.Clazz:TypeTree?→J?— Java side types this asJ?(since the clazz can be aJ.ParameterizedTypewhich doesn't implementTypeTreeon the C# side). Updated model, visitor, and RPC.RPC alignment
CSharpSender.VisitNamespaceDeclaration— Removed workaround that split members into separate externs/usings/non-using lists for transmission. Now sendsname,members,end— matching the Java receiver.CSharpReceiver.VisitNamespaceDeclaration— Removed workaround that received separate externs/usings/members lists and merged them back into a single members list.CSharpSender.VisitUsingDirective— Removed fabricatedJLeftPadded<bool>(false)for theunsafefield.CSharpReceiver.VisitUsingDirective— Removed consume-and-discard of theunsafefield.CSharpRpcTesttimeout — Increased RPC timeout from 60s to 120s to fix transient flake inparsePragmaWarningMultipleCodes.Location enum cleanup
CsSpace.Location/CsRightPadded.Location/CsLeftPadded.Locationentries for deleted types:BLOCK_SCOPE_NAMESPACE_DECLARATION_*,FILE_SCOPE_NAMESPACE_DECLARATION_*,COMPILATION_UNIT_EXTERNS_*,COMPILATION_UNIT_USINGS_*,USING_DIRECTIVE_UNSAFE. AddedNAMESPACE_DECLARATION_*replacements.Test plan
CSharpRpcTesttests pass (includingparsePragmaWarningMultipleCodeswith increased timeout)CSharpRecipeTestpasses with updated model references