@shapeshift-labs/frontier-lang-compiler 0.2.30 → 0.2.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -439,6 +439,32 @@ export const NativeParserAstFormatProfiles = Object.freeze([
439
439
  supportsErrorRecovery: true,
440
440
  notes: ['Java compiler/parser ASTs expose package/import/type/member declarations and source ranges; classpath/module-path, bindings, annotation processors, generated sources, Lombok expansion, comments/trivia, and control-flow evidence remain host-owned.']
441
441
  }),
442
+ nativeParserAstFormatProfile('roslyn-csharp', {
443
+ aliases: ['roslyn', 'csharp-roslyn', 'c#-roslyn', 'microsoft-codeanalysis-csharp', 'csharp-syntax'],
444
+ kind: 'compiler-ast',
445
+ languages: ['csharp'],
446
+ parserAdapters: ['roslyn', 'microsoft.codeanalysis.csharp', 'csharp-roslyn'],
447
+ exactness: 'exact-parser-ast',
448
+ sourceRangeModel: 'text-span-line-position-span',
449
+ preservesTokens: true,
450
+ preservesTrivia: true,
451
+ supportsIncremental: true,
452
+ supportsErrorRecovery: true,
453
+ notes: ['Roslyn C# syntax trees expose immutable nodes, tokens, trivia, spans, diagnostics, directives, and skipped text; SemanticModel symbols, nullable analysis, generated sources, partial type stitching, analyzer results, and project references remain host-owned evidence.']
454
+ }),
455
+ nativeParserAstFormatProfile('swift-syntax', {
456
+ aliases: ['swiftsyntax', 'swiftparser', 'swift-parser', 'swift-syntax-json'],
457
+ kind: 'concrete-syntax-tree',
458
+ languages: ['swift'],
459
+ parserAdapters: ['swift-syntax', 'swiftparser'],
460
+ exactness: 'parser-tree',
461
+ sourceRangeModel: 'absolute-position-source-location',
462
+ preservesTokens: true,
463
+ preservesTrivia: true,
464
+ supportsIncremental: false,
465
+ supportsErrorRecovery: true,
466
+ notes: ['SwiftSyntax exposes a source-accurate syntax tree with missing/unexpected nodes and token/trivia structure; SourceKit symbols, macro expansion, conditional compilation branch resolution, type checking, generated sources, and package/module dependency resolution remain host-owned evidence.']
467
+ }),
442
468
  nativeParserAstFormatProfile('tree-sitter', {
443
469
  kind: 'concrete-syntax-tree',
444
470
  languages: ['mixed'],
@@ -2932,6 +2958,134 @@ export function createJavaAstNativeImporterAdapter(options = {}) {
2932
2958
  };
2933
2959
  }
2934
2960
 
2961
+ export function createCSharpRoslynNativeImporterAdapter(options = {}) {
2962
+ return {
2963
+ id: options.id ?? 'frontier.csharp-roslyn-native-importer',
2964
+ language: options.language ?? 'csharp',
2965
+ parser: options.parser ?? 'roslyn',
2966
+ version: options.version,
2967
+ capabilities: uniqueStrings(['nativeAst', 'semanticIndex', 'sourceMaps', 'diagnostics', ...(options.capabilities ?? [])]),
2968
+ coverage: nativeImporterAdapterCoverage({
2969
+ exactness: 'exact-parser-ast',
2970
+ exactAst: true,
2971
+ tokens: true,
2972
+ trivia: true,
2973
+ diagnostics: true,
2974
+ sourceRanges: true,
2975
+ generatedRanges: false,
2976
+ semanticCoverage: declarationSemanticCoverage(),
2977
+ notes: [
2978
+ 'Normalizes caller-owned Roslyn C# SyntaxTree/SyntaxNode-shaped objects into native AST nodes and declaration-level semantic index records.',
2979
+ 'Roslyn syntax imports do not resolve SemanticModel symbols, overloads, nullable flow, source generators, partial types, project references, or analyzer results by themselves; attach host evidence for those claims.'
2980
+ ]
2981
+ }, options.coverage),
2982
+ supportedExtensions: options.supportedExtensions ?? ['.cs'],
2983
+ diagnostics: options.diagnostics,
2984
+ parse(input) {
2985
+ const parsed = input.options?.ast
2986
+ ?? input.options?.nativeAst
2987
+ ?? input.options?.syntaxTree
2988
+ ?? input.options?.tree
2989
+ ?? input.options?.root
2990
+ ?? input.options?.compilationUnit
2991
+ ?? options.ast
2992
+ ?? options.syntaxTree
2993
+ ?? options.tree
2994
+ ?? options.root
2995
+ ?? options.compilationUnit
2996
+ ?? parseCSharpRoslynSource(input, options);
2997
+ const root = csharpRoslynRoot(parsed);
2998
+ if (!root) {
2999
+ return missingInjectedParserResult(input, {
3000
+ parser: options.parser ?? 'roslyn',
3001
+ adapterId: options.id ?? 'frontier.csharp-roslyn-native-importer',
3002
+ message: 'createCSharpRoslynNativeImporterAdapter requires an injected Roslyn SyntaxTree/SyntaxNode object, parserModule.parse function, parse function, or adapterOptions.ast.'
3003
+ });
3004
+ }
3005
+ const parseDiagnostics = normalizeParserErrors(parsed?.errors ?? parsed?.diagnostics ?? parsed?.parseDiagnostics, input, {
3006
+ parser: options.parser ?? 'roslyn'
3007
+ });
3008
+ return createNativeImportFromCSharpRoslyn(root, input, {
3009
+ parser: options.parser ?? 'roslyn',
3010
+ astFormat: 'roslyn-csharp',
3011
+ maxNodes: options.maxNodes,
3012
+ diagnostics: parseDiagnostics,
3013
+ csharpVersion: options.csharpVersion ?? input.options?.csharpVersion ?? parsed?.csharpVersion,
3014
+ languageVersion: options.languageVersion ?? input.options?.languageVersion ?? parsed?.languageVersion,
3015
+ nullableContext: input.options?.nullableContext ?? options.nullableContext ?? parsed?.nullableContext,
3016
+ generated: input.options?.generated ?? options.generated ?? parsed?.generated ?? csharpGeneratedSourcePath(input.sourcePath),
3017
+ projectReferences: input.options?.projectReferences ?? options.projectReferences ?? parsed?.projectReferences,
3018
+ analyzerDiagnostics: input.options?.analyzerDiagnostics ?? options.analyzerDiagnostics ?? parsed?.analyzerDiagnostics,
3019
+ semanticModelEvidence: input.options?.semanticModelEvidence ?? options.semanticModelEvidence ?? parsed?.semanticModelEvidence,
3020
+ sourceGeneratorEvidence: input.options?.sourceGeneratorEvidence ?? options.sourceGeneratorEvidence ?? parsed?.sourceGeneratorEvidence,
3021
+ positionResolver: input.options?.positionResolver ?? options.positionResolver,
3022
+ lineMap: input.options?.lineMap ?? options.lineMap ?? parsed?.lineMap
3023
+ });
3024
+ }
3025
+ };
3026
+ }
3027
+
3028
+ export function createSwiftSyntaxNativeImporterAdapter(options = {}) {
3029
+ return {
3030
+ id: options.id ?? 'frontier.swift-syntax-native-importer',
3031
+ language: options.language ?? 'swift',
3032
+ parser: options.parser ?? 'swift-syntax',
3033
+ version: options.version,
3034
+ capabilities: uniqueStrings(['nativeAst', 'semanticIndex', 'sourceMaps', 'diagnostics', ...(options.capabilities ?? [])]),
3035
+ coverage: nativeImporterAdapterCoverage({
3036
+ exactness: 'parser-tree',
3037
+ exactAst: true,
3038
+ tokens: true,
3039
+ trivia: true,
3040
+ diagnostics: true,
3041
+ sourceRanges: true,
3042
+ generatedRanges: false,
3043
+ semanticCoverage: declarationSemanticCoverage(),
3044
+ notes: [
3045
+ 'Normalizes caller-owned SwiftSyntax/SwiftParser-shaped SourceFileSyntax trees into native AST nodes and declaration-level semantic index records.',
3046
+ 'SwiftSyntax imports do not resolve SourceKit symbols, type checking, macro expansions, conditional compilation branches, Objective-C bridging, generated sources, package/module dependencies, or control flow by themselves; attach host evidence for those claims.'
3047
+ ]
3048
+ }, options.coverage),
3049
+ supportedExtensions: options.supportedExtensions ?? ['.swift'],
3050
+ diagnostics: options.diagnostics,
3051
+ parse(input) {
3052
+ const parsed = input.options?.ast
3053
+ ?? input.options?.nativeAst
3054
+ ?? input.options?.sourceFile
3055
+ ?? input.options?.sourceFileSyntax
3056
+ ?? input.options?.root
3057
+ ?? options.ast
3058
+ ?? options.sourceFile
3059
+ ?? options.sourceFileSyntax
3060
+ ?? options.root
3061
+ ?? parseSwiftSyntaxSource(input, options);
3062
+ const root = swiftSyntaxRoot(parsed);
3063
+ if (!root) {
3064
+ return missingInjectedParserResult(input, {
3065
+ parser: options.parser ?? 'swift-syntax',
3066
+ adapterId: options.id ?? 'frontier.swift-syntax-native-importer',
3067
+ message: 'createSwiftSyntaxNativeImporterAdapter requires an injected SwiftSyntax SourceFileSyntax-shaped object, parserModule.parse function, parse function, or adapterOptions.ast.'
3068
+ });
3069
+ }
3070
+ const parseDiagnostics = normalizeParserErrors(parsed?.errors ?? parsed?.diagnostics ?? parsed?.parseDiagnostics, input, {
3071
+ parser: options.parser ?? 'swift-syntax'
3072
+ });
3073
+ return createNativeImportFromSwiftSyntax(root, input, {
3074
+ parser: options.parser ?? 'swift-syntax',
3075
+ astFormat: 'swift-syntax',
3076
+ maxNodes: options.maxNodes,
3077
+ diagnostics: parseDiagnostics,
3078
+ swiftVersion: options.swiftVersion ?? input.options?.swiftVersion ?? parsed?.swiftVersion,
3079
+ languageMode: options.languageMode ?? input.options?.languageMode ?? parsed?.languageMode,
3080
+ generated: input.options?.generated ?? options.generated ?? parsed?.generated ?? swiftGeneratedSourcePath(input.sourcePath),
3081
+ sourceKitEvidence: input.options?.sourceKitEvidence ?? options.sourceKitEvidence ?? parsed?.sourceKitEvidence,
3082
+ macroExpansionEvidence: input.options?.macroExpansionEvidence ?? options.macroExpansionEvidence ?? parsed?.macroExpansionEvidence,
3083
+ packageResolutionEvidence: input.options?.packageResolutionEvidence ?? options.packageResolutionEvidence ?? parsed?.packageResolutionEvidence
3084
+ });
3085
+ }
3086
+ };
3087
+ }
3088
+
2935
3089
  export function createTreeSitterNativeImporterAdapter(options = {}) {
2936
3090
  return {
2937
3091
  id: options.id ?? `frontier.tree-sitter-${idFragment(options.language ?? 'source')}-native-importer`,
@@ -7375,6 +7529,8 @@ function parserAstFormatIdForParser(parser) {
7375
7529
  if (text.includes('clang') || text.includes('libclang')) return 'clang-ast-json';
7376
7530
  if (text === 'go' || text.includes('go-parser') || text.includes('go-ast') || text.includes('go/parser') || text.includes('go/ast')) return 'go-ast';
7377
7531
  if (text === 'java' || text.includes('javac') || text.includes('jdt') || text.includes('javaparser') || text.includes('java-parser') || text.includes('java-ast')) return 'java-ast';
7532
+ if (text === 'csharp' || text === 'c#' || text === 'cs' || text.includes('roslyn') || text.includes('microsoft-codeanalysis-csharp') || text.includes('csharp-syntax')) return 'roslyn-csharp';
7533
+ if (text.includes('swift-syntax') || text.includes('swiftsyntax') || text.includes('swiftparser') || text.includes('swift-parser')) return 'swift-syntax';
7378
7534
  if (text.includes('tree-sitter') || text.includes('treesitter')) return 'tree-sitter';
7379
7535
  if (text.includes('babel')) return 'babel';
7380
7536
  if (text.includes('estree')) return 'estree';
@@ -8473,6 +8629,38 @@ function parseJavaAstSource(input, options) {
8473
8629
  return parse(input.sourceText, parserOptions);
8474
8630
  }
8475
8631
 
8632
+ function parseCSharpRoslynSource(input, options) {
8633
+ const parse = options.parse ?? options.parserModule?.parse ?? options.roslyn?.parse ?? options.csharpRoslyn?.parse;
8634
+ if (typeof parse !== 'function') return undefined;
8635
+ const parserOptions = {
8636
+ sourcePath: input.sourcePath,
8637
+ filename: input.sourcePath,
8638
+ languageVersion: options.languageVersion ?? input.options?.languageVersion,
8639
+ csharpVersion: options.csharpVersion ?? input.options?.csharpVersion,
8640
+ nullableContext: options.nullableContext ?? input.options?.nullableContext,
8641
+ kind: options.sourceCodeKind ?? input.options?.sourceCodeKind,
8642
+ ...(options.parserOptions ?? {}),
8643
+ ...(input.options?.parserOptions ?? {})
8644
+ };
8645
+ return parse(input.sourceText, parserOptions);
8646
+ }
8647
+
8648
+ function parseSwiftSyntaxSource(input, options) {
8649
+ const parse = options.parse ?? options.parserModule?.parse ?? options.swiftSyntax?.parse ?? options.swiftParser?.parse;
8650
+ if (typeof parse !== 'function') return undefined;
8651
+ const parserOptions = {
8652
+ sourcePath: input.sourcePath,
8653
+ filename: input.sourcePath,
8654
+ swiftVersion: options.swiftVersion ?? input.options?.swiftVersion,
8655
+ languageMode: options.languageMode ?? input.options?.languageMode,
8656
+ enableBareSlashRegex: options.enableBareSlashRegex ?? input.options?.enableBareSlashRegex,
8657
+ parseTransition: options.parseTransition ?? input.options?.parseTransition,
8658
+ ...(options.parserOptions ?? {}),
8659
+ ...(input.options?.parserOptions ?? {})
8660
+ };
8661
+ return parse(input.sourceText, parserOptions);
8662
+ }
8663
+
8476
8664
  function createNativeImportFromSyntaxAst(ast, input, options) {
8477
8665
  const root = normalizeSyntaxAstRoot(ast, options.astFormat);
8478
8666
  if (!root) {
@@ -8703,6 +8891,82 @@ function createNativeImportFromJavaAst(root, input, options) {
8703
8891
  };
8704
8892
  }
8705
8893
 
8894
+ function createNativeImportFromCSharpRoslyn(root, input, options) {
8895
+ const context = createAstNormalizationContext(input, options);
8896
+ visitCSharpRoslynNode(root, context, 'root');
8897
+ if (context.truncated) {
8898
+ context.losses.push(truncatedAstLoss(input, context, options));
8899
+ }
8900
+ if (options.generated && !context.losses.some((loss) => loss.kind === 'generatedCode')) {
8901
+ context.losses.push(csharpGeneratedCodeLoss(input, context.rootId, undefined, options));
8902
+ }
8903
+ const semantic = semanticIndexFromNativeDeclarations(context.declarations, input, options);
8904
+ return {
8905
+ rootId: context.rootId,
8906
+ nodes: context.nodes,
8907
+ semanticIndex: semantic.semanticIndex,
8908
+ mappings: semantic.mappings,
8909
+ losses: mergeNativeLosses(context.losses, options.diagnostics?.map((diagnostic, index) => adapterDiagnosticToLoss(diagnostic, index, {
8910
+ id: input.adapterId,
8911
+ version: input.adapterVersion
8912
+ }, input)) ?? []),
8913
+ evidence: semantic.evidence,
8914
+ diagnostics: options.diagnostics,
8915
+ metadata: {
8916
+ astFormat: options.astFormat,
8917
+ parser: options.parser,
8918
+ csharpVersion: options.csharpVersion,
8919
+ languageVersion: options.languageVersion,
8920
+ nullableContext: options.nullableContext,
8921
+ generated: options.generated,
8922
+ projectReferences: csharpEvidenceSummary(options.projectReferences),
8923
+ analyzerDiagnostics: csharpEvidenceSummary(options.analyzerDiagnostics),
8924
+ semanticModelEvidence: csharpEvidenceSummary(options.semanticModelEvidence),
8925
+ sourceGeneratorEvidence: csharpEvidenceSummary(options.sourceGeneratorEvidence),
8926
+ normalizedNodeCount: Object.keys(context.nodes).length,
8927
+ declarationCount: context.declarations.length,
8928
+ truncated: context.truncated
8929
+ }
8930
+ };
8931
+ }
8932
+
8933
+ function createNativeImportFromSwiftSyntax(root, input, options) {
8934
+ const context = createAstNormalizationContext(input, options);
8935
+ visitSwiftSyntaxNode(root, context, 'root');
8936
+ if (context.truncated) {
8937
+ context.losses.push(truncatedAstLoss(input, context, options));
8938
+ }
8939
+ if (options.generated && !context.losses.some((loss) => loss.kind === 'generatedCode')) {
8940
+ context.losses.push(swiftGeneratedCodeLoss(input, context.rootId, undefined, options));
8941
+ }
8942
+ const semantic = semanticIndexFromNativeDeclarations(context.declarations, input, options);
8943
+ return {
8944
+ rootId: context.rootId,
8945
+ nodes: context.nodes,
8946
+ semanticIndex: semantic.semanticIndex,
8947
+ mappings: semantic.mappings,
8948
+ losses: mergeNativeLosses(context.losses, options.diagnostics?.map((diagnostic, index) => adapterDiagnosticToLoss(diagnostic, index, {
8949
+ id: input.adapterId,
8950
+ version: input.adapterVersion
8951
+ }, input)) ?? []),
8952
+ evidence: semantic.evidence,
8953
+ diagnostics: options.diagnostics,
8954
+ metadata: {
8955
+ astFormat: options.astFormat,
8956
+ parser: options.parser,
8957
+ swiftVersion: options.swiftVersion,
8958
+ languageMode: options.languageMode,
8959
+ generated: options.generated,
8960
+ sourceKitEvidence: swiftEvidenceSummary(options.sourceKitEvidence),
8961
+ macroExpansionEvidence: swiftEvidenceSummary(options.macroExpansionEvidence),
8962
+ packageResolutionEvidence: swiftEvidenceSummary(options.packageResolutionEvidence),
8963
+ normalizedNodeCount: Object.keys(context.nodes).length,
8964
+ declarationCount: context.declarations.length,
8965
+ truncated: context.truncated
8966
+ }
8967
+ };
8968
+ }
8969
+
8706
8970
  function createNativeImportFromTreeSitter(root, input, options) {
8707
8971
  const context = createAstNormalizationContext(input, options);
8708
8972
  visitTreeSitterNode(root, context, 'root');
@@ -9178,109 +9442,297 @@ function visitJavaAstNode(node, context, propertyPath) {
9178
9442
  return id;
9179
9443
  }
9180
9444
 
9181
- function visitTreeSitterNode(node, context, propertyPath) {
9182
- if (!node || typeof node !== 'object' || context.truncated) return undefined;
9445
+ function visitCSharpRoslynNode(node, context, propertyPath) {
9446
+ if (!isCSharpRoslynNode(node) || context.truncated) return undefined;
9183
9447
  if (context.objectIds.has(node)) return context.objectIds.get(node);
9184
9448
  if (context.counter >= context.maxNodes) {
9185
9449
  context.truncated = true;
9186
9450
  return undefined;
9187
9451
  }
9188
- const kind = String(node.type ?? node.kind ?? 'node');
9189
- const span = spanFromTreeSitterNode(node, context.input);
9452
+ const kind = csharpRoslynKind(node);
9453
+ const span = spanFromCSharpRoslynNode(node, context.input, context.options);
9190
9454
  const id = nativeNodeId(context, kind, { start: { line: span?.startLine, column: span?.startColumn } }, propertyPath);
9191
9455
  context.objectIds.set(node, id);
9192
9456
  if (!context.rootId) context.rootId = id;
9193
9457
  const children = [];
9194
- const rawChildren = Array.isArray(node.namedChildren)
9195
- ? node.namedChildren
9196
- : Array.isArray(node.children)
9197
- ? node.children
9198
- : [];
9199
- rawChildren.forEach((child, index) => {
9200
- const childId = visitTreeSitterNode(child, context, `${propertyPath}.children[${index}]`);
9201
- if (childId) children.push(childId);
9202
- });
9203
- const declaration = treeSitterDeclaration(node, kind, id, context.input, context.options);
9458
+ for (const [field, value] of csharpRoslynChildEntries(node, kind)) {
9459
+ if (Array.isArray(value)) {
9460
+ value.forEach((entry, index) => {
9461
+ const childId = visitCSharpRoslynNode(entry, context, `${propertyPath}.${field}[${index}]`);
9462
+ if (childId) children.push(childId);
9463
+ });
9464
+ } else {
9465
+ const childId = visitCSharpRoslynNode(value, context, `${propertyPath}.${field}`);
9466
+ if (childId) children.push(childId);
9467
+ }
9468
+ }
9469
+ const declarations = csharpRoslynDeclarations(node, kind, id, context.input);
9470
+ const declaration = declarations[0];
9204
9471
  const nativeNode = {
9205
9472
  id,
9206
9473
  kind,
9207
9474
  languageKind: `${context.input.language}.${kind}`,
9208
9475
  span,
9209
- value: declaration?.name ?? shortNodeText(node),
9210
- fields: {
9211
- named: Boolean(node.isNamed ?? node.named),
9212
- missing: Boolean(node.isMissing),
9213
- error: Boolean(node.hasError || kind === 'ERROR')
9214
- },
9476
+ value: declaration?.name ?? csharpRoslynNodeValue(node),
9477
+ fields: primitiveCSharpRoslynFields(node, kind),
9215
9478
  children,
9216
9479
  metadata: {
9217
9480
  astFormat: context.options.astFormat,
9218
9481
  propertyPath,
9219
- startIndex: numberOrUndefined(node.startIndex),
9220
- endIndex: numberOrUndefined(node.endIndex)
9482
+ rawKind: numberOrUndefined(node.rawKind ?? node.RawKind),
9483
+ positionKind: csharpRoslynPositionKind(node),
9484
+ parser: context.options.parser
9221
9485
  }
9222
9486
  };
9223
9487
  context.nodes[id] = nativeNode;
9224
- if (declaration) context.declarations.push({ ...declaration, nativeNode });
9225
- if (node.hasError || kind === 'ERROR') {
9488
+ for (const entry of declarations) {
9489
+ context.declarations.push({ ...entry, nativeNode });
9490
+ }
9491
+ if (csharpRoslynRecoveredKind(kind) || csharpRoslynProblemNode(node, kind)) {
9226
9492
  context.losses.push({
9227
- id: `loss_${idFragment(id)}_tree_sitter_error`,
9493
+ id: `loss_${idFragment(id)}_csharp_roslyn_recovered_node`,
9228
9494
  severity: 'error',
9229
9495
  phase: 'parse',
9230
9496
  sourceFormat: context.input.language,
9231
9497
  kind: 'unsupportedSyntax',
9232
- message: 'Tree-sitter reported a parse error node.',
9498
+ message: 'Roslyn reported skipped text, missing syntax, or syntax diagnostics; semantic import is partial until syntax errors are resolved.',
9233
9499
  span,
9234
- nodeId: id
9500
+ nodeId: id,
9501
+ metadata: {
9502
+ parser: context.options.parser,
9503
+ astFormat: context.options.astFormat,
9504
+ nodeKind: kind
9505
+ }
9235
9506
  });
9236
9507
  }
9237
- return id;
9238
- }
9239
-
9240
- function semanticIndexFromNativeDeclarations(declarations, input, options) {
9241
- const documentId = `doc_${idFragment(input.sourcePath ?? input.language)}_${idFragment(input.sourceHash)}`;
9242
- const evidenceId = `evidence_${idFragment(input.sourcePath ?? input.language)}_${idFragment(options.astFormat ?? options.parser)}_import`;
9243
- const symbols = [];
9244
- const occurrences = [];
9245
- const relations = [];
9246
- const facts = [];
9247
- const mappings = [];
9248
- for (const declaration of declarations) {
9249
- const symbolId = declaration.symbolId ?? `symbol:${input.language}:${declaration.role === 'import' ? 'import:' : ''}${idFragment(declaration.name)}`;
9250
- const occurrenceId = `occ_${idFragment(declaration.nativeNode.id)}_${declaration.role ?? 'definition'}`;
9251
- const ownershipRegion = semanticOwnershipRegionForDeclaration(input, {
9252
- ...declaration,
9253
- nodeId: declaration.nativeNode.id,
9254
- kind: declaration.nativeNode.kind,
9255
- languageKind: declaration.nativeNode.languageKind,
9256
- span: declaration.nativeNode.span,
9257
- symbolId
9258
- }, documentId);
9259
- declaration.nativeNode.metadata = {
9260
- ...declaration.nativeNode.metadata,
9261
- ownershipRegionId: ownershipRegion.id,
9262
- ownershipRegionKey: ownershipRegion.key,
9263
- ownershipRegionKind: ownershipRegion.regionKind
9264
- };
9265
- symbols.push({
9266
- id: symbolId,
9267
- scheme: 'frontier',
9268
- name: declaration.name,
9269
- kind: declaration.symbolKind,
9270
- language: input.language,
9271
- nativeAstNodeId: declaration.nativeNode.id,
9272
- signatureHash: hashSemanticValue([input.language, declaration.nativeNode.kind, declaration.name, declaration.nativeNode.fields ?? {}]),
9273
- definitionSpan: declaration.nativeNode.span,
9508
+ if (csharpRoslynDirectiveKind(kind)) {
9509
+ context.losses.push({
9510
+ id: `loss_${idFragment(id)}_csharp_preprocessor`,
9511
+ severity: 'warning',
9512
+ phase: 'parse',
9513
+ sourceFormat: context.input.language,
9514
+ kind: 'preprocessor',
9515
+ message: 'C# preprocessor directive was imported as syntax; conditional compilation state and inactive branches require host evidence.',
9516
+ span,
9517
+ nodeId: id,
9274
9518
  metadata: {
9275
- ownershipRegionId: ownershipRegion.id,
9276
- ownershipRegionKey: ownershipRegion.key,
9277
- ownershipRegionKind: ownershipRegion.regionKind
9519
+ parser: context.options.parser,
9520
+ astFormat: context.options.astFormat,
9521
+ nodeKind: kind
9278
9522
  }
9279
9523
  });
9280
- occurrences.push({
9281
- id: occurrenceId,
9282
- documentId,
9283
- symbolId,
9524
+ }
9525
+ if (csharpGeneratedCodeMarker(node, kind)) {
9526
+ context.losses.push(csharpGeneratedCodeLoss(context.input, id, span, context.options, { nodeKind: kind }));
9527
+ }
9528
+ return id;
9529
+ }
9530
+
9531
+ function visitSwiftSyntaxNode(node, context, propertyPath) {
9532
+ if (!isSwiftSyntaxNode(node) || context.truncated) return undefined;
9533
+ if (context.objectIds.has(node)) return context.objectIds.get(node);
9534
+ if (context.counter >= context.maxNodes) {
9535
+ context.truncated = true;
9536
+ return undefined;
9537
+ }
9538
+ const kind = swiftSyntaxKind(node);
9539
+ const span = spanFromSwiftSyntaxNode(node, context.input, context.options);
9540
+ const id = nativeNodeId(context, kind, { start: { line: span?.startLine, column: span?.startColumn } }, propertyPath);
9541
+ context.objectIds.set(node, id);
9542
+ if (!context.rootId) context.rootId = id;
9543
+ const children = [];
9544
+ for (const [field, value] of swiftSyntaxChildEntries(node, kind)) {
9545
+ if (Array.isArray(value)) {
9546
+ value.forEach((entry, index) => {
9547
+ const childId = visitSwiftSyntaxNode(entry, context, `${propertyPath}.${field}[${index}]`);
9548
+ if (childId) children.push(childId);
9549
+ });
9550
+ } else {
9551
+ const childId = visitSwiftSyntaxNode(value, context, `${propertyPath}.${field}`);
9552
+ if (childId) children.push(childId);
9553
+ }
9554
+ }
9555
+ const declarations = swiftSyntaxDeclarations(node, kind, id, context.input);
9556
+ const declaration = declarations[0];
9557
+ const nativeNode = {
9558
+ id,
9559
+ kind,
9560
+ languageKind: `${context.input.language}.${kind}`,
9561
+ span,
9562
+ value: declaration?.name ?? swiftSyntaxNodeValue(node),
9563
+ fields: primitiveSwiftSyntaxFields(node, kind),
9564
+ children,
9565
+ metadata: {
9566
+ astFormat: context.options.astFormat,
9567
+ propertyPath,
9568
+ positionKind: swiftSyntaxPositionKind(node),
9569
+ parser: context.options.parser
9570
+ }
9571
+ };
9572
+ context.nodes[id] = nativeNode;
9573
+ for (const entry of declarations) {
9574
+ context.declarations.push({ ...entry, nativeNode });
9575
+ }
9576
+ if (swiftSyntaxRecoveredKind(kind) || swiftSyntaxProblemNode(node, kind)) {
9577
+ context.losses.push({
9578
+ id: `loss_${idFragment(id)}_swift_syntax_recovered_node`,
9579
+ severity: 'error',
9580
+ phase: 'parse',
9581
+ sourceFormat: context.input.language,
9582
+ kind: 'unsupportedSyntax',
9583
+ message: 'SwiftSyntax reported missing, unexpected, skipped, or error syntax; semantic import is partial until syntax errors are resolved.',
9584
+ span,
9585
+ nodeId: id,
9586
+ metadata: {
9587
+ parser: context.options.parser,
9588
+ astFormat: context.options.astFormat,
9589
+ nodeKind: kind
9590
+ }
9591
+ });
9592
+ }
9593
+ if (swiftSyntaxConditionalCompilationKind(kind)) {
9594
+ context.losses.push({
9595
+ id: `loss_${idFragment(id)}_swift_conditional_compilation`,
9596
+ severity: 'warning',
9597
+ phase: 'parse',
9598
+ sourceFormat: context.input.language,
9599
+ kind: 'conditionalCompilation',
9600
+ message: 'Swift conditional compilation syntax was imported; active branch selection and inactive branch source ownership require host build-setting evidence.',
9601
+ span,
9602
+ nodeId: id,
9603
+ metadata: {
9604
+ parser: context.options.parser,
9605
+ astFormat: context.options.astFormat,
9606
+ nodeKind: kind
9607
+ }
9608
+ });
9609
+ }
9610
+ if (swiftSyntaxMacroKind(kind)) {
9611
+ context.losses.push({
9612
+ id: `loss_${idFragment(id)}_swift_macro_expansion`,
9613
+ severity: 'warning',
9614
+ phase: 'parse',
9615
+ sourceFormat: context.input.language,
9616
+ kind: 'macroExpansion',
9617
+ message: 'Swift macro syntax was imported, but expansion, generated declarations, and binding effects require host macro-expansion evidence.',
9618
+ span,
9619
+ nodeId: id,
9620
+ metadata: {
9621
+ parser: context.options.parser,
9622
+ astFormat: context.options.astFormat,
9623
+ nodeKind: kind
9624
+ }
9625
+ });
9626
+ }
9627
+ if (swiftGeneratedCodeMarker(node, kind)) {
9628
+ context.losses.push(swiftGeneratedCodeLoss(context.input, id, span, context.options, { nodeKind: kind }));
9629
+ }
9630
+ return id;
9631
+ }
9632
+
9633
+ function visitTreeSitterNode(node, context, propertyPath) {
9634
+ if (!node || typeof node !== 'object' || context.truncated) return undefined;
9635
+ if (context.objectIds.has(node)) return context.objectIds.get(node);
9636
+ if (context.counter >= context.maxNodes) {
9637
+ context.truncated = true;
9638
+ return undefined;
9639
+ }
9640
+ const kind = String(node.type ?? node.kind ?? 'node');
9641
+ const span = spanFromTreeSitterNode(node, context.input);
9642
+ const id = nativeNodeId(context, kind, { start: { line: span?.startLine, column: span?.startColumn } }, propertyPath);
9643
+ context.objectIds.set(node, id);
9644
+ if (!context.rootId) context.rootId = id;
9645
+ const children = [];
9646
+ const rawChildren = Array.isArray(node.namedChildren)
9647
+ ? node.namedChildren
9648
+ : Array.isArray(node.children)
9649
+ ? node.children
9650
+ : [];
9651
+ rawChildren.forEach((child, index) => {
9652
+ const childId = visitTreeSitterNode(child, context, `${propertyPath}.children[${index}]`);
9653
+ if (childId) children.push(childId);
9654
+ });
9655
+ const declaration = treeSitterDeclaration(node, kind, id, context.input, context.options);
9656
+ const nativeNode = {
9657
+ id,
9658
+ kind,
9659
+ languageKind: `${context.input.language}.${kind}`,
9660
+ span,
9661
+ value: declaration?.name ?? shortNodeText(node),
9662
+ fields: {
9663
+ named: Boolean(node.isNamed ?? node.named),
9664
+ missing: Boolean(node.isMissing),
9665
+ error: Boolean(node.hasError || kind === 'ERROR')
9666
+ },
9667
+ children,
9668
+ metadata: {
9669
+ astFormat: context.options.astFormat,
9670
+ propertyPath,
9671
+ startIndex: numberOrUndefined(node.startIndex),
9672
+ endIndex: numberOrUndefined(node.endIndex)
9673
+ }
9674
+ };
9675
+ context.nodes[id] = nativeNode;
9676
+ if (declaration) context.declarations.push({ ...declaration, nativeNode });
9677
+ if (node.hasError || kind === 'ERROR') {
9678
+ context.losses.push({
9679
+ id: `loss_${idFragment(id)}_tree_sitter_error`,
9680
+ severity: 'error',
9681
+ phase: 'parse',
9682
+ sourceFormat: context.input.language,
9683
+ kind: 'unsupportedSyntax',
9684
+ message: 'Tree-sitter reported a parse error node.',
9685
+ span,
9686
+ nodeId: id
9687
+ });
9688
+ }
9689
+ return id;
9690
+ }
9691
+
9692
+ function semanticIndexFromNativeDeclarations(declarations, input, options) {
9693
+ const documentId = `doc_${idFragment(input.sourcePath ?? input.language)}_${idFragment(input.sourceHash)}`;
9694
+ const evidenceId = `evidence_${idFragment(input.sourcePath ?? input.language)}_${idFragment(options.astFormat ?? options.parser)}_import`;
9695
+ const symbols = [];
9696
+ const occurrences = [];
9697
+ const relations = [];
9698
+ const facts = [];
9699
+ const mappings = [];
9700
+ for (const declaration of declarations) {
9701
+ const symbolId = declaration.symbolId ?? `symbol:${input.language}:${declaration.role === 'import' ? 'import:' : ''}${idFragment(declaration.name)}`;
9702
+ const occurrenceId = `occ_${idFragment(declaration.nativeNode.id)}_${declaration.role ?? 'definition'}`;
9703
+ const ownershipRegion = semanticOwnershipRegionForDeclaration(input, {
9704
+ ...declaration,
9705
+ nodeId: declaration.nativeNode.id,
9706
+ kind: declaration.nativeNode.kind,
9707
+ languageKind: declaration.nativeNode.languageKind,
9708
+ span: declaration.nativeNode.span,
9709
+ symbolId
9710
+ }, documentId);
9711
+ declaration.nativeNode.metadata = {
9712
+ ...declaration.nativeNode.metadata,
9713
+ ownershipRegionId: ownershipRegion.id,
9714
+ ownershipRegionKey: ownershipRegion.key,
9715
+ ownershipRegionKind: ownershipRegion.regionKind
9716
+ };
9717
+ symbols.push({
9718
+ id: symbolId,
9719
+ scheme: 'frontier',
9720
+ name: declaration.name,
9721
+ kind: declaration.symbolKind,
9722
+ language: input.language,
9723
+ nativeAstNodeId: declaration.nativeNode.id,
9724
+ signatureHash: hashSemanticValue([input.language, declaration.nativeNode.kind, declaration.name, declaration.nativeNode.fields ?? {}]),
9725
+ definitionSpan: declaration.nativeNode.span,
9726
+ metadata: {
9727
+ ownershipRegionId: ownershipRegion.id,
9728
+ ownershipRegionKey: ownershipRegion.key,
9729
+ ownershipRegionKind: ownershipRegion.regionKind
9730
+ }
9731
+ });
9732
+ occurrences.push({
9733
+ id: occurrenceId,
9734
+ documentId,
9735
+ symbolId,
9284
9736
  role: declaration.role ?? 'definition',
9285
9737
  span: declaration.nativeNode.span,
9286
9738
  nativeAstNodeId: declaration.nativeNode.id
@@ -11896,6 +12348,1013 @@ function javaBindingEvidenceSummary(value) {
11896
12348
  return Object.keys(summary).length ? summary : { present: true };
11897
12349
  }
11898
12350
 
12351
+ function csharpRoslynRoot(value) {
12352
+ if (!value || typeof value !== 'object') return undefined;
12353
+ if (isCSharpRoslynNode(value)) return value;
12354
+ if (isCSharpRoslynNode(value.ast)) return value.ast;
12355
+ if (isCSharpRoslynNode(value.root)) return value.root;
12356
+ if (isCSharpRoslynNode(value.rootNode)) return value.rootNode;
12357
+ if (isCSharpRoslynNode(value.compilationUnit)) return value.compilationUnit;
12358
+ if (isCSharpRoslynNode(value.syntaxTree)) return csharpRoslynRoot(value.syntaxTree);
12359
+ if (isCSharpRoslynNode(value.tree)) return csharpRoslynRoot(value.tree);
12360
+ if (Array.isArray(value.members) || Array.isArray(value.usings) || Array.isArray(value.externs)) {
12361
+ return { kind: 'CompilationUnit', ...value };
12362
+ }
12363
+ return undefined;
12364
+ }
12365
+
12366
+ function isCSharpRoslynNode(value) {
12367
+ return Boolean(value && typeof value === 'object' && typeof csharpRoslynKind(value) === 'string');
12368
+ }
12369
+
12370
+ function csharpRoslynKind(node) {
12371
+ if (!node || typeof node !== 'object') return undefined;
12372
+ const declared = node.kind ?? node.Kind ?? node._type ?? node.type ?? node.nodeType ?? node.syntaxKind ?? node.SyntaxKind;
12373
+ if (typeof declared === 'string') return normalizeCSharpRoslynKind(declared);
12374
+ if (Array.isArray(node.members) || Array.isArray(node.usings) || Array.isArray(node.externs)) return 'CompilationUnit';
12375
+ if (node.identifier && (node.members || node.baseList || node.parameterList || node.modifiers)) return 'ClassDeclaration';
12376
+ if (node.declaration && (node.eventKeyword || node.eventField)) return 'EventFieldDeclaration';
12377
+ if (node.declaration && Array.isArray(node.declaration.variables)) return 'FieldDeclaration';
12378
+ return undefined;
12379
+ }
12380
+
12381
+ function normalizeCSharpRoslynKind(kind) {
12382
+ const text = String(kind)
12383
+ .replace(/^(?:Microsoft\.CodeAnalysis\.CSharp\.Syntax\.|Microsoft\.CodeAnalysis\.CSharp\.)/, '')
12384
+ .replace(/Syntax$/, '');
12385
+ const compact = text.replace(/[_\s.-]+/g, '').toLowerCase();
12386
+ if (compact === 'compilationunit') return 'CompilationUnit';
12387
+ if (compact === 'usingdirective') return 'UsingDirective';
12388
+ if (compact === 'namespacedeclaration') return 'NamespaceDeclaration';
12389
+ if (compact === 'filescopednamespacedeclaration') return 'FileScopedNamespaceDeclaration';
12390
+ if (compact === 'classdeclaration') return 'ClassDeclaration';
12391
+ if (compact === 'interfacedeclaration') return 'InterfaceDeclaration';
12392
+ if (compact === 'structdeclaration') return 'StructDeclaration';
12393
+ if (compact === 'recorddeclaration') return 'RecordDeclaration';
12394
+ if (compact === 'recordstructdeclaration') return 'RecordStructDeclaration';
12395
+ if (compact === 'enumdeclaration') return 'EnumDeclaration';
12396
+ if (compact === 'methoddeclaration') return 'MethodDeclaration';
12397
+ if (compact === 'constructordeclaration') return 'ConstructorDeclaration';
12398
+ if (compact === 'destructordeclaration') return 'DestructorDeclaration';
12399
+ if (compact === 'operatordeclaration') return 'OperatorDeclaration';
12400
+ if (compact === 'conversionoperatordeclaration') return 'ConversionOperatorDeclaration';
12401
+ if (compact === 'propertydeclaration') return 'PropertyDeclaration';
12402
+ if (compact === 'indexerdeclaration') return 'IndexerDeclaration';
12403
+ if (compact === 'fielddeclaration') return 'FieldDeclaration';
12404
+ if (compact === 'variabledeclarator') return 'VariableDeclarator';
12405
+ if (compact === 'eventdeclaration') return 'EventDeclaration';
12406
+ if (compact === 'eventfielddeclaration') return 'EventFieldDeclaration';
12407
+ if (compact === 'delegatedeclaration') return 'DelegateDeclaration';
12408
+ if (compact === 'enummemberdeclaration') return 'EnumMemberDeclaration';
12409
+ if (compact === 'attributelist') return 'AttributeList';
12410
+ if (compact === 'attribute') return 'Attribute';
12411
+ if (compact === 'parameter') return 'Parameter';
12412
+ if (compact === 'incompletemember') return 'IncompleteMember';
12413
+ if (compact === 'skippedtokenstrivia' || compact === 'skippedtokens') return 'SkippedTokensTrivia';
12414
+ if (compact.endsWith('directivetrivia')) return `${upperFirst(compact.slice(0, -'directivetrivia'.length))}DirectiveTrivia`;
12415
+ if (/^[A-Z0-9_]+$/.test(text)) return text.toLowerCase().split('_').map(upperFirst).join('');
12416
+ return text;
12417
+ }
12418
+
12419
+ function ignoredCSharpRoslynField(key) {
12420
+ return key === '_type'
12421
+ || key === 'type'
12422
+ || key === 'kind'
12423
+ || key === 'Kind'
12424
+ || key === 'nodeType'
12425
+ || key === 'syntaxKind'
12426
+ || key === 'SyntaxKind'
12427
+ || key === 'rawKind'
12428
+ || key === 'RawKind'
12429
+ || key === 'parent'
12430
+ || key === 'parentKind'
12431
+ || key === 'parentField'
12432
+ || key === 'span'
12433
+ || key === 'Span'
12434
+ || key === 'fullSpan'
12435
+ || key === 'FullSpan'
12436
+ || key === 'lineSpan'
12437
+ || key === 'location'
12438
+ || key === 'locations'
12439
+ || key === 'identifier'
12440
+ || key === 'name'
12441
+ || key === 'simpleName'
12442
+ || key === 'qualifiedName'
12443
+ || key === 'semanticModel'
12444
+ || key === 'symbol'
12445
+ || key === 'declaredSymbol'
12446
+ || key === 'typeInfo'
12447
+ || key === 'conversion'
12448
+ || key === 'constantValue';
12449
+ }
12450
+
12451
+ function primitiveCSharpRoslynFields(node, kind) {
12452
+ const fields = { kind };
12453
+ const name = csharpRoslynDeclarationName(node);
12454
+ if (name) fields.name = name;
12455
+ const importPath = csharpRoslynUsingPath(node);
12456
+ if (importPath) fields.importPath = importPath;
12457
+ const type = csharpRoslynTypeName(node.type ?? node.Type ?? node.returnType ?? node.ReturnType);
12458
+ if (type) fields.type = type;
12459
+ const modifiers = csharpRoslynModifierNames(node);
12460
+ if (modifiers.length) fields.modifiers = modifiers.join(',');
12461
+ const alias = csharpRoslynName(node.alias ?? node.Alias);
12462
+ if (alias) fields.alias = alias;
12463
+ if (node.static === true || node.isStatic === true) fields.static = true;
12464
+ if (node.global === true || node.isGlobal === true) fields.global = true;
12465
+ if (node.generated === true || node.Generated === true) fields.generated = true;
12466
+ if (node.containsDiagnostics === true || node.ContainsDiagnostics === true) fields.containsDiagnostics = true;
12467
+ if (node.containsSkippedText === true || node.ContainsSkippedText === true) fields.containsSkippedText = true;
12468
+ if (node.isMissing === true || node.IsMissing === true) fields.isMissing = true;
12469
+ if (Array.isArray(node.parameterList?.parameters ?? node.parameters)) fields.parameterCount = (node.parameterList?.parameters ?? node.parameters).length;
12470
+ if (Array.isArray(node.attributeLists)) fields.attributeListCount = node.attributeLists.length;
12471
+ return fields;
12472
+ }
12473
+
12474
+ function spanFromCSharpRoslynNode(node, input, options = {}) {
12475
+ const lineSpan = node.lineSpan ?? node.location?.lineSpan ?? node.location?.LineSpan ?? node.FileLinePositionSpan;
12476
+ const fromLineSpan = spanFromCSharpLineSpan(lineSpan, input);
12477
+ if (fromLineSpan) return fromLineSpan;
12478
+ const direct = spanFromCSharpLineFields(node, input);
12479
+ if (direct) return direct;
12480
+ const start = csharpRoslynPosition(node.start ?? node.Start ?? node.span?.start ?? node.Span?.Start ?? node.position, options);
12481
+ const end = csharpRoslynPosition(node.end ?? node.End ?? node.span?.end ?? node.Span?.End, options);
12482
+ if (!start) return undefined;
12483
+ return {
12484
+ sourceId: input.sourceHash,
12485
+ path: start.path ?? end?.path ?? input.sourcePath,
12486
+ startLine: start.line,
12487
+ startColumn: start.column,
12488
+ endLine: end?.line,
12489
+ endColumn: end?.column
12490
+ };
12491
+ }
12492
+
12493
+ function spanFromCSharpLineSpan(lineSpan, input) {
12494
+ if (!lineSpan || typeof lineSpan !== 'object') return undefined;
12495
+ const start = lineSpan.startLinePosition ?? lineSpan.StartLinePosition ?? lineSpan.start ?? lineSpan.Start;
12496
+ const end = lineSpan.endLinePosition ?? lineSpan.EndLinePosition ?? lineSpan.end ?? lineSpan.End;
12497
+ const line = start?.line ?? start?.Line;
12498
+ if (typeof line !== 'number') return undefined;
12499
+ const character = start.character ?? start.Character ?? start.column ?? start.Column;
12500
+ const endLine = end?.line ?? end?.Line;
12501
+ const endCharacter = end?.character ?? end?.Character ?? end?.column ?? end?.Column;
12502
+ return {
12503
+ sourceId: input.sourceHash,
12504
+ path: lineSpan.path ?? lineSpan.filePath ?? lineSpan.FilePath ?? input.sourcePath,
12505
+ startLine: line + 1,
12506
+ startColumn: typeof character === 'number' ? character + 1 : undefined,
12507
+ endLine: typeof endLine === 'number' ? endLine + 1 : undefined,
12508
+ endColumn: typeof endCharacter === 'number' ? endCharacter + 1 : undefined
12509
+ };
12510
+ }
12511
+
12512
+ function spanFromCSharpLineFields(node, input) {
12513
+ const startLine = node.startLine ?? node.line ?? node.beginLine;
12514
+ if (typeof startLine !== 'number') return undefined;
12515
+ return {
12516
+ sourceId: input.sourceHash,
12517
+ path: node.path ?? node.filePath ?? node.file ?? input.sourcePath,
12518
+ startLine,
12519
+ startColumn: node.startColumn ?? node.column ?? node.beginColumn,
12520
+ endLine: node.endLine,
12521
+ endColumn: node.endColumn
12522
+ };
12523
+ }
12524
+
12525
+ function csharpRoslynPosition(value, options = {}) {
12526
+ if (value === undefined || value === null) return undefined;
12527
+ if (typeof value === 'object') {
12528
+ const position = value.position ?? value.Position ?? value;
12529
+ const line = position.line ?? position.Line;
12530
+ const column = position.column ?? position.Column ?? position.character ?? position.Character;
12531
+ if (typeof line === 'number') {
12532
+ return {
12533
+ path: position.path ?? position.filePath ?? position.FilePath ?? position.file,
12534
+ line,
12535
+ column: typeof column === 'number' ? column : undefined
12536
+ };
12537
+ }
12538
+ }
12539
+ const resolver = typeof options.positionResolver === 'function'
12540
+ ? options.positionResolver
12541
+ : typeof options.lineMap?.position === 'function'
12542
+ ? options.lineMap.position.bind(options.lineMap)
12543
+ : typeof options.lineMap?.getLinePosition === 'function'
12544
+ ? options.lineMap.getLinePosition.bind(options.lineMap)
12545
+ : undefined;
12546
+ if (resolver) {
12547
+ const resolved = resolver(value);
12548
+ if (resolved !== value) return csharpRoslynPosition(resolved, options);
12549
+ }
12550
+ return undefined;
12551
+ }
12552
+
12553
+ function csharpRoslynPositionKind(node) {
12554
+ if (node.lineSpan || node.location?.lineSpan) return 'line-position-span';
12555
+ if (node.span || node.Span) return 'text-span';
12556
+ if (typeof node.startLine === 'number' || typeof node.line === 'number') return 'line-column-fields';
12557
+ return undefined;
12558
+ }
12559
+
12560
+ function csharpRoslynDeclarations(node, kind, nativeNodeId, input) {
12561
+ if (kind === 'UsingDirective') {
12562
+ const name = csharpRoslynUsingPath(node);
12563
+ return name ? [declarationRecord(input, nativeNodeId, name, 'module', 'import')] : [];
12564
+ }
12565
+ if (kind === 'NamespaceDeclaration' || kind === 'FileScopedNamespaceDeclaration') {
12566
+ const name = csharpRoslynDeclarationName(node);
12567
+ return name ? [declarationRecord(input, nativeNodeId, name, 'namespace', 'definition')] : [];
12568
+ }
12569
+ if (csharpRoslynTypeDeclarationKind(kind)) {
12570
+ const name = csharpRoslynDeclarationName(node);
12571
+ return name ? [declarationRecord(input, nativeNodeId, name, csharpRoslynTypeDeclarationSymbolKind(kind), 'definition')] : [];
12572
+ }
12573
+ if (kind === 'DelegateDeclaration') {
12574
+ const name = csharpRoslynDeclarationName(node);
12575
+ return name ? [declarationRecord(input, nativeNodeId, name, 'type', 'definition')] : [];
12576
+ }
12577
+ if (csharpRoslynMethodLikeKind(kind)) {
12578
+ const name = csharpRoslynDeclarationName(node) ?? csharpRoslynOperatorName(node, kind);
12579
+ return name ? [declarationRecord(input, nativeNodeId, name, 'method', csharpRoslynHasBody(node) ? 'definition' : 'declaration')] : [];
12580
+ }
12581
+ if (kind === 'PropertyDeclaration' || kind === 'IndexerDeclaration') {
12582
+ const name = csharpRoslynDeclarationName(node) ?? (kind === 'IndexerDeclaration' ? 'this[]' : undefined);
12583
+ return name ? [declarationRecord(input, nativeNodeId, name, 'property', 'definition')] : [];
12584
+ }
12585
+ if (kind === 'FieldDeclaration') {
12586
+ return csharpRoslynVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'property', 'definition'));
12587
+ }
12588
+ if (kind === 'EventDeclaration') {
12589
+ const name = csharpRoslynDeclarationName(node);
12590
+ return name ? [declarationRecord(input, nativeNodeId, name, 'event', 'definition')] : [];
12591
+ }
12592
+ if (kind === 'EventFieldDeclaration') {
12593
+ return csharpRoslynVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'event', 'definition'));
12594
+ }
12595
+ if (kind === 'VariableDeclarator') {
12596
+ if (node.parentKind === 'FieldDeclaration') {
12597
+ const name = csharpRoslynDeclarationName(node);
12598
+ return name ? [declarationRecord(input, nativeNodeId, name, 'property', 'definition')] : [];
12599
+ }
12600
+ if (node.parentKind === 'EventFieldDeclaration') {
12601
+ const name = csharpRoslynDeclarationName(node);
12602
+ return name ? [declarationRecord(input, nativeNodeId, name, 'event', 'definition')] : [];
12603
+ }
12604
+ return [];
12605
+ }
12606
+ if (kind === 'EnumMemberDeclaration') {
12607
+ const name = csharpRoslynDeclarationName(node);
12608
+ return name ? [declarationRecord(input, nativeNodeId, name, 'enumMember', 'definition')] : [];
12609
+ }
12610
+ return [];
12611
+ }
12612
+
12613
+ function csharpRoslynChildEntries(node, kind = csharpRoslynKind(node)) {
12614
+ const fieldNames = Object.keys(node).filter((key) => !ignoredCSharpRoslynField(key));
12615
+ const entries = [];
12616
+ for (const field of fieldNames) {
12617
+ const value = node[field];
12618
+ if (Array.isArray(value)) {
12619
+ entries.push([field, value.map((entry) => csharpRoslynChildWithParent(entry, kind, field))]);
12620
+ continue;
12621
+ }
12622
+ if (value && typeof value === 'object') {
12623
+ entries.push([field, csharpRoslynChildWithParent(value, kind, field)]);
12624
+ }
12625
+ }
12626
+ return entries.filter(([, value]) => Array.isArray(value)
12627
+ ? value.some(isCSharpRoslynNode)
12628
+ : isCSharpRoslynNode(value));
12629
+ }
12630
+
12631
+ function csharpRoslynChildWithParent(entry, parentKind, parentField) {
12632
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return entry;
12633
+ if (!isCSharpRoslynNode(entry)) return entry;
12634
+ return { parentKind, parentField, ...entry };
12635
+ }
12636
+
12637
+ function csharpRoslynNodeValue(node) {
12638
+ return csharpRoslynDeclarationName(node)
12639
+ ?? csharpRoslynUsingPath(node)
12640
+ ?? csharpRoslynTypeName(node.type ?? node.returnType)
12641
+ ?? csharpRoslynLiteralValue(node);
12642
+ }
12643
+
12644
+ function csharpRoslynDeclarationName(node) {
12645
+ if (!node || typeof node !== 'object') return undefined;
12646
+ for (const key of ['identifier', 'name', 'simpleName', 'qualifiedName', 'id']) {
12647
+ const value = node[key];
12648
+ const name = csharpRoslynName(value);
12649
+ if (name) return name;
12650
+ }
12651
+ if (node.declaration && typeof node.declaration === 'object') return csharpRoslynDeclarationName(node.declaration);
12652
+ return undefined;
12653
+ }
12654
+
12655
+ function csharpRoslynName(value) {
12656
+ if (!value) return undefined;
12657
+ if (typeof value === 'string') return value;
12658
+ if (typeof value.text === 'string') return value.text;
12659
+ if (typeof value.valueText === 'string') return value.valueText;
12660
+ if (typeof value.identifier === 'string') return value.identifier;
12661
+ if (typeof value.name === 'string') return value.name;
12662
+ if (typeof value.qualifiedName === 'string') return value.qualifiedName;
12663
+ if (typeof value.value === 'string') return value.value;
12664
+ if (value.identifier && value.identifier !== value) return csharpRoslynName(value.identifier);
12665
+ if (value.name && value.name !== value) return csharpRoslynName(value.name);
12666
+ return undefined;
12667
+ }
12668
+
12669
+ function csharpRoslynUsingPath(node) {
12670
+ if (!node || typeof node !== 'object') return undefined;
12671
+ return csharpRoslynName(node.name ?? node.Name ?? node.qualifiedName ?? node.path);
12672
+ }
12673
+
12674
+ function csharpRoslynVariableNames(node) {
12675
+ const variables = node.variables
12676
+ ?? node.declaration?.variables
12677
+ ?? node.Declaration?.Variables
12678
+ ?? node.variableDeclarators;
12679
+ if (Array.isArray(variables)) return variables.map(csharpRoslynDeclarationName).filter(Boolean);
12680
+ const name = csharpRoslynDeclarationName(node);
12681
+ return name ? [name] : [];
12682
+ }
12683
+
12684
+ function csharpRoslynTypeName(value) {
12685
+ if (!value) return undefined;
12686
+ if (typeof value === 'string') return value;
12687
+ if (typeof value.name === 'string') return value.name;
12688
+ if (typeof value.text === 'string') return value.text;
12689
+ if (typeof value.valueText === 'string') return value.valueText;
12690
+ if (typeof value.qualifiedName === 'string') return value.qualifiedName;
12691
+ if (value.elementType) {
12692
+ const inner = csharpRoslynTypeName(value.elementType);
12693
+ return inner ? `${inner}[]` : '[]';
12694
+ }
12695
+ if (Array.isArray(value.typeArgumentList?.arguments ?? value.typeArguments)) {
12696
+ const base = csharpRoslynName(value.name) ?? csharpRoslynName(value);
12697
+ const args = (value.typeArgumentList?.arguments ?? value.typeArguments).map(csharpRoslynTypeName).filter(Boolean);
12698
+ return base ? `${base}<${args.join(', ')}>` : undefined;
12699
+ }
12700
+ return csharpRoslynName(value);
12701
+ }
12702
+
12703
+ function csharpRoslynModifierNames(node) {
12704
+ const modifiers = node.modifiers ?? node.Modifiers;
12705
+ if (!modifiers) return [];
12706
+ if (Array.isArray(modifiers)) {
12707
+ return uniqueStrings(modifiers.map((entry) => typeof entry === 'string' ? entry : csharpRoslynName(entry) ?? entry.kind).filter(Boolean));
12708
+ }
12709
+ if (typeof modifiers === 'string') return uniqueStrings(modifiers.split(/\s+/).filter(Boolean));
12710
+ if (typeof modifiers === 'object') {
12711
+ return uniqueStrings(Object.entries(modifiers)
12712
+ .filter(([, enabled]) => enabled === true)
12713
+ .map(([key]) => key));
12714
+ }
12715
+ return [];
12716
+ }
12717
+
12718
+ function csharpRoslynTypeDeclarationKind(kind) {
12719
+ return kind === 'ClassDeclaration'
12720
+ || kind === 'InterfaceDeclaration'
12721
+ || kind === 'StructDeclaration'
12722
+ || kind === 'RecordDeclaration'
12723
+ || kind === 'RecordStructDeclaration'
12724
+ || kind === 'EnumDeclaration';
12725
+ }
12726
+
12727
+ function csharpRoslynTypeDeclarationSymbolKind(kind) {
12728
+ if (kind === 'ClassDeclaration' || kind === 'RecordDeclaration') return 'class';
12729
+ if (kind === 'InterfaceDeclaration') return 'interface';
12730
+ return 'type';
12731
+ }
12732
+
12733
+ function csharpRoslynMethodLikeKind(kind) {
12734
+ return kind === 'MethodDeclaration'
12735
+ || kind === 'ConstructorDeclaration'
12736
+ || kind === 'DestructorDeclaration'
12737
+ || kind === 'OperatorDeclaration'
12738
+ || kind === 'ConversionOperatorDeclaration';
12739
+ }
12740
+
12741
+ function csharpRoslynHasBody(node) {
12742
+ return Boolean(node.body || node.expressionBody || node.accessorList || Array.isArray(node.statements));
12743
+ }
12744
+
12745
+ function csharpRoslynOperatorName(node, kind) {
12746
+ if (kind === 'ConstructorDeclaration') return csharpRoslynDeclarationName(node);
12747
+ if (kind === 'DestructorDeclaration') return `~${csharpRoslynDeclarationName(node) ?? 'destructor'}`;
12748
+ if (kind === 'OperatorDeclaration') return `operator ${csharpRoslynName(node.operatorToken) ?? csharpRoslynName(node.operatorKeyword) ?? 'operator'}`;
12749
+ if (kind === 'ConversionOperatorDeclaration') return `operator ${csharpRoslynTypeName(node.type) ?? 'conversion'}`;
12750
+ return undefined;
12751
+ }
12752
+
12753
+ function csharpRoslynLiteralValue(node) {
12754
+ const value = node.value ?? node.literal;
12755
+ if (value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return value;
12756
+ return undefined;
12757
+ }
12758
+
12759
+ function csharpRoslynRecoveredKind(kind) {
12760
+ return kind === 'IncompleteMember'
12761
+ || kind === 'SkippedTokensTrivia'
12762
+ || /Skipped|Missing|Bad|Incomplete/.test(String(kind));
12763
+ }
12764
+
12765
+ function csharpRoslynProblemNode(node, kind) {
12766
+ return Boolean(
12767
+ node.containsDiagnostics
12768
+ || node.ContainsDiagnostics
12769
+ || node.containsSkippedText
12770
+ || node.ContainsSkippedText
12771
+ || node.isMissing
12772
+ || node.IsMissing
12773
+ || node.hasDiagnostics
12774
+ || node.HasDiagnostics
12775
+ || kind === 'IncompleteMember'
12776
+ || kind === 'SkippedTokensTrivia'
12777
+ );
12778
+ }
12779
+
12780
+ function csharpRoslynDirectiveKind(kind) {
12781
+ return /DirectiveTrivia$/.test(String(kind)) || /^(IfDirective|ElifDirective|ElseDirective|EndIfDirective|DefineDirective|UndefDirective|NullableDirective|RegionDirective|EndRegionDirective|PragmaWarningDirective|LineDirective|ErrorDirective|WarningDirective|LoadDirective|ReferenceDirective)/.test(String(kind));
12782
+ }
12783
+
12784
+ function csharpGeneratedCodeMarker(node, kind) {
12785
+ if (node.generated || node.Generated || node.isGenerated) return true;
12786
+ const path = String(node.filePath ?? node.path ?? node.sourcePath ?? '');
12787
+ if (csharpGeneratedSourcePath(path)) return true;
12788
+ if (kind === 'Attribute') {
12789
+ const name = csharpRoslynDeclarationName(node);
12790
+ if (name && /(^|\.)(GeneratedCode|CompilerGenerated|DebuggerNonUserCode)Attribute?$/.test(name)) return true;
12791
+ }
12792
+ const attributes = node.attributeLists ?? node.attributes;
12793
+ if (Array.isArray(attributes)) {
12794
+ return JSON.stringify(attributes).includes('GeneratedCode')
12795
+ || JSON.stringify(attributes).includes('CompilerGenerated');
12796
+ }
12797
+ return false;
12798
+ }
12799
+
12800
+ function csharpGeneratedSourcePath(path) {
12801
+ return typeof path === 'string' && /\.(g|generated|designer)\.cs$/i.test(path);
12802
+ }
12803
+
12804
+ function csharpGeneratedCodeLoss(input, nodeId, span, options = {}, metadata = {}) {
12805
+ return {
12806
+ id: `loss_${idFragment(nodeId ?? input.sourcePath ?? 'csharp')}_csharp_generated_code`,
12807
+ severity: 'warning',
12808
+ phase: 'parse',
12809
+ sourceFormat: input.language,
12810
+ kind: 'generatedCode',
12811
+ message: 'C# generated-source or source-generator marker was imported; generated member provenance and source ownership require host evidence.',
12812
+ span,
12813
+ nodeId,
12814
+ metadata: {
12815
+ parser: options.parser,
12816
+ astFormat: options.astFormat,
12817
+ sourceGeneratorEvidence: csharpEvidenceSummary(options.sourceGeneratorEvidence),
12818
+ ...metadata
12819
+ }
12820
+ };
12821
+ }
12822
+
12823
+ function csharpEvidenceSummary(value) {
12824
+ if (!value) return undefined;
12825
+ if (Array.isArray(value)) return { entryCount: value.length };
12826
+ if (typeof value === 'string') return { value };
12827
+ if (typeof value === 'object') {
12828
+ const summary = {};
12829
+ if (typeof value.hash === 'string') summary.hash = value.hash;
12830
+ if (typeof value.solver === 'string') summary.solver = value.solver;
12831
+ if (Array.isArray(value.entries)) summary.entryCount = value.entries.length;
12832
+ if (Array.isArray(value.references)) summary.referenceCount = value.references.length;
12833
+ if (Array.isArray(value.symbols)) summary.symbolCount = value.symbols.length;
12834
+ if (Array.isArray(value.diagnostics)) summary.diagnosticCount = value.diagnostics.length;
12835
+ if (Array.isArray(value.generators)) summary.generatorCount = value.generators.length;
12836
+ if (Array.isArray(value.projects)) summary.projectCount = value.projects.length;
12837
+ return Object.keys(summary).length ? summary : { present: true };
12838
+ }
12839
+ return { present: true };
12840
+ }
12841
+
12842
+ function swiftSyntaxRoot(value) {
12843
+ if (!value || typeof value !== 'object') return undefined;
12844
+ if (isSwiftSyntaxNode(value)) return value;
12845
+ if (isSwiftSyntaxNode(value.ast)) return value.ast;
12846
+ if (isSwiftSyntaxNode(value.root)) return value.root;
12847
+ if (isSwiftSyntaxNode(value.rootNode)) return value.rootNode;
12848
+ if (isSwiftSyntaxNode(value.sourceFile)) return value.sourceFile;
12849
+ if (isSwiftSyntaxNode(value.sourceFileSyntax)) return value.sourceFileSyntax;
12850
+ if (isSwiftSyntaxNode(value.tree)) return swiftSyntaxRoot(value.tree);
12851
+ if (Array.isArray(value.statements) || Array.isArray(value.members) || Array.isArray(value.declarations)) {
12852
+ return { kind: 'SourceFile', ...value };
12853
+ }
12854
+ return undefined;
12855
+ }
12856
+
12857
+ function isSwiftSyntaxNode(value) {
12858
+ return Boolean(value && typeof value === 'object' && typeof swiftSyntaxKind(value) === 'string');
12859
+ }
12860
+
12861
+ function swiftSyntaxKind(node) {
12862
+ if (!node || typeof node !== 'object') return undefined;
12863
+ const declared = node.kind ?? node.syntaxKind ?? node.SyntaxKind ?? node._syntaxKind ?? node._type ?? node.type ?? node.nodeType;
12864
+ if (typeof declared === 'string') return normalizeSwiftSyntaxKind(declared);
12865
+ if (Array.isArray(node.statements) || Array.isArray(node.members) || Array.isArray(node.declarations)) return 'SourceFile';
12866
+ if (node.identifier && (node.memberBlock || node.members || node.genericParameterClause || node.inheritanceClause)) return 'ClassDecl';
12867
+ if (node.signature && node.body) return 'FunctionDecl';
12868
+ if (node.importPath || node.path) return 'ImportDecl';
12869
+ return undefined;
12870
+ }
12871
+
12872
+ function normalizeSwiftSyntaxKind(kind) {
12873
+ const text = String(kind)
12874
+ .replace(/^SwiftSyntax\./, '')
12875
+ .replace(/Syntax$/, '');
12876
+ const compact = text.replace(/[_\s.-]+/g, '').toLowerCase();
12877
+ const known = {
12878
+ sourcefile: 'SourceFile',
12879
+ importdecl: 'ImportDecl',
12880
+ classdecl: 'ClassDecl',
12881
+ structdecl: 'StructDecl',
12882
+ enumdecl: 'EnumDecl',
12883
+ protocoldecl: 'ProtocolDecl',
12884
+ actordecl: 'ActorDecl',
12885
+ extensiondecl: 'ExtensionDecl',
12886
+ typealiasdecl: 'TypeAliasDecl',
12887
+ associatedtypedecl: 'AssociatedTypeDecl',
12888
+ functiondecl: 'FunctionDecl',
12889
+ initializerdecl: 'InitializerDecl',
12890
+ initdecl: 'InitializerDecl',
12891
+ deinitializerdecl: 'DeinitializerDecl',
12892
+ deinitdecl: 'DeinitializerDecl',
12893
+ subscriptdecl: 'SubscriptDecl',
12894
+ operatordecl: 'OperatorDecl',
12895
+ precedencegroupdecl: 'PrecedenceGroupDecl',
12896
+ variabledecl: 'VariableDecl',
12897
+ patternbinding: 'PatternBinding',
12898
+ enumcasedecl: 'EnumCaseDecl',
12899
+ enumcaseelement: 'EnumCaseElement',
12900
+ macrodecl: 'MacroDecl',
12901
+ macroexpansiondecl: 'MacroExpansionDecl',
12902
+ freestandingmacroexpansion: 'FreestandingMacroExpansion',
12903
+ freestandingmacroexpansionsyntax: 'FreestandingMacroExpansion',
12904
+ attributemacroexpansion: 'AttributeMacroExpansion',
12905
+ ifconfigdecl: 'IfConfigDecl',
12906
+ ifconfigexpr: 'IfConfigExpr',
12907
+ unexpectednodes: 'UnexpectedNodes',
12908
+ missingtoken: 'MissingToken',
12909
+ skippedtoken: 'SkippedToken',
12910
+ error: 'Error'
12911
+ };
12912
+ if (known[compact]) return known[compact];
12913
+ if (/^[A-Z0-9_]+$/.test(text)) return text.toLowerCase().split('_').map(upperFirst).join('');
12914
+ return text;
12915
+ }
12916
+
12917
+ function ignoredSwiftSyntaxField(key) {
12918
+ return key === '_type'
12919
+ || key === 'type'
12920
+ || key === 'kind'
12921
+ || key === 'syntaxKind'
12922
+ || key === 'SyntaxKind'
12923
+ || key === '_syntaxKind'
12924
+ || key === 'nodeType'
12925
+ || key === 'parent'
12926
+ || key === 'parentKind'
12927
+ || key === 'parentField'
12928
+ || key === 'position'
12929
+ || key === 'absolutePosition'
12930
+ || key === 'endPosition'
12931
+ || key === 'location'
12932
+ || key === 'sourceRange'
12933
+ || key === 'range'
12934
+ || key === 'span'
12935
+ || key === 'identifier'
12936
+ || key === 'name'
12937
+ || key === 'simpleName'
12938
+ || key === 'typeName'
12939
+ || key === 'sourceKitSymbol'
12940
+ || key === 'semanticModel'
12941
+ || key === 'resolvedSymbol'
12942
+ || key === 'typeInfo';
12943
+ }
12944
+
12945
+ function primitiveSwiftSyntaxFields(node, kind) {
12946
+ const fields = { kind };
12947
+ const name = swiftSyntaxDeclarationName(node, kind);
12948
+ if (name) fields.name = name;
12949
+ const importPath = swiftSyntaxImportPath(node);
12950
+ if (importPath) fields.importPath = importPath;
12951
+ const type = swiftSyntaxTypeName(node.type ?? node.typeAnnotation?.type ?? node.returnClause?.type ?? node.extendedType);
12952
+ if (type) fields.type = type;
12953
+ const modifiers = swiftSyntaxModifierNames(node);
12954
+ if (modifiers.length) fields.modifiers = modifiers.join(',');
12955
+ const attributes = swiftSyntaxAttributeNames(node);
12956
+ if (attributes.length) fields.attributes = attributes.join(',');
12957
+ if (node.generated === true || node.isGenerated === true) fields.generated = true;
12958
+ if (node.isMissing === true || node.presence === 'missing') fields.isMissing = true;
12959
+ if (node.hasError === true || node.containsDiagnostics === true) fields.hasError = true;
12960
+ if (Array.isArray(node.genericParameterClause?.parameters ?? node.genericParameters)) fields.genericParameterCount = (node.genericParameterClause?.parameters ?? node.genericParameters).length;
12961
+ if (Array.isArray(node.inheritanceClause?.inheritedTypes ?? node.inheritedTypes)) fields.inheritedTypeCount = (node.inheritanceClause?.inheritedTypes ?? node.inheritedTypes).length;
12962
+ if (Array.isArray(node.signature?.parameterClause?.parameters ?? node.parameters)) fields.parameterCount = (node.signature?.parameterClause?.parameters ?? node.parameters).length;
12963
+ return fields;
12964
+ }
12965
+
12966
+ function spanFromSwiftSyntaxNode(node, input, options = {}) {
12967
+ const direct = spanFromSwiftLineFields(node, input);
12968
+ if (direct) return direct;
12969
+ const range = node.sourceRange ?? node.range ?? node.span;
12970
+ const fromRange = spanFromSwiftRange(range, input);
12971
+ if (fromRange) return fromRange;
12972
+ const start = swiftSyntaxPosition(node.position ?? node.absolutePosition ?? node.start ?? range?.start, options);
12973
+ const end = swiftSyntaxPosition(node.endPosition ?? node.end ?? range?.end, options);
12974
+ if (!start) return undefined;
12975
+ return {
12976
+ sourceId: input.sourceHash,
12977
+ path: start.path ?? end?.path ?? input.sourcePath,
12978
+ startLine: start.line,
12979
+ startColumn: start.column,
12980
+ endLine: end?.line,
12981
+ endColumn: end?.column
12982
+ };
12983
+ }
12984
+
12985
+ function spanFromSwiftLineFields(node, input) {
12986
+ const startLine = node.startLine ?? node.line ?? node.beginLine;
12987
+ if (typeof startLine !== 'number') return undefined;
12988
+ return {
12989
+ sourceId: input.sourceHash,
12990
+ path: node.path ?? node.filePath ?? node.file ?? input.sourcePath,
12991
+ startLine,
12992
+ startColumn: node.startColumn ?? node.column ?? node.beginColumn,
12993
+ endLine: node.endLine,
12994
+ endColumn: node.endColumn
12995
+ };
12996
+ }
12997
+
12998
+ function spanFromSwiftRange(range, input) {
12999
+ if (!range || typeof range !== 'object') return undefined;
13000
+ const start = range.start ?? range.lowerBound ?? range.begin;
13001
+ const end = range.end ?? range.upperBound;
13002
+ const line = start?.line ?? start?.Line;
13003
+ if (typeof line !== 'number') return undefined;
13004
+ const column = start.column ?? start.character ?? start.utf8Column ?? start.Column;
13005
+ const endLine = end?.line ?? end?.Line;
13006
+ const endColumn = end?.column ?? end?.character ?? end?.utf8Column ?? end?.Column;
13007
+ return {
13008
+ sourceId: input.sourceHash,
13009
+ path: range.path ?? range.filePath ?? range.file ?? input.sourcePath,
13010
+ startLine: line,
13011
+ startColumn: typeof column === 'number' ? column : undefined,
13012
+ endLine: typeof endLine === 'number' ? endLine : undefined,
13013
+ endColumn: typeof endColumn === 'number' ? endColumn : undefined
13014
+ };
13015
+ }
13016
+
13017
+ function swiftSyntaxPosition(value, options = {}) {
13018
+ if (value === undefined || value === null) return undefined;
13019
+ if (typeof value === 'object') {
13020
+ const position = value.position ?? value.location ?? value;
13021
+ const line = position.line ?? position.Line;
13022
+ const column = position.column ?? position.character ?? position.utf8Column ?? position.Column;
13023
+ if (typeof line === 'number') {
13024
+ return {
13025
+ path: position.path ?? position.filePath ?? position.file,
13026
+ line,
13027
+ column: typeof column === 'number' ? column : undefined
13028
+ };
13029
+ }
13030
+ }
13031
+ const resolver = typeof options.positionResolver === 'function'
13032
+ ? options.positionResolver
13033
+ : typeof options.lineMap?.position === 'function'
13034
+ ? options.lineMap.position.bind(options.lineMap)
13035
+ : typeof options.sourceLocationConverter?.location === 'function'
13036
+ ? options.sourceLocationConverter.location.bind(options.sourceLocationConverter)
13037
+ : undefined;
13038
+ if (resolver) {
13039
+ const resolved = resolver(value);
13040
+ if (resolved !== value) return swiftSyntaxPosition(resolved, options);
13041
+ }
13042
+ return undefined;
13043
+ }
13044
+
13045
+ function swiftSyntaxPositionKind(node) {
13046
+ if (node.sourceRange || node.range) return 'source-range';
13047
+ if (node.position || node.absolutePosition) return 'absolute-position';
13048
+ if (typeof node.startLine === 'number' || typeof node.line === 'number') return 'line-column-fields';
13049
+ return undefined;
13050
+ }
13051
+
13052
+ function swiftSyntaxDeclarations(node, kind, nativeNodeId, input) {
13053
+ if (kind === 'ImportDecl') {
13054
+ const name = swiftSyntaxImportPath(node);
13055
+ return name ? [declarationRecord(input, nativeNodeId, name, 'module', 'import')] : [];
13056
+ }
13057
+ if (swiftSyntaxTypeDeclarationKind(kind)) {
13058
+ const name = swiftSyntaxDeclarationName(node, kind);
13059
+ return name ? [declarationRecord(input, nativeNodeId, name, swiftSyntaxTypeDeclarationSymbolKind(kind), 'definition')] : [];
13060
+ }
13061
+ if (kind === 'ExtensionDecl') {
13062
+ const name = swiftSyntaxDeclarationName(node, kind);
13063
+ return name ? [declarationRecord(input, nativeNodeId, name, 'type', 'definition')] : [];
13064
+ }
13065
+ if (kind === 'TypeAliasDecl' || kind === 'AssociatedTypeDecl') {
13066
+ const name = swiftSyntaxDeclarationName(node, kind);
13067
+ return name ? [declarationRecord(input, nativeNodeId, name, 'type', 'definition')] : [];
13068
+ }
13069
+ if (swiftSyntaxFunctionLikeKind(kind)) {
13070
+ const name = swiftSyntaxDeclarationName(node, kind) ?? swiftSyntaxOperatorName(node, kind);
13071
+ return name ? [declarationRecord(input, nativeNodeId, name, kind === 'FunctionDecl' ? 'function' : 'method', swiftSyntaxHasBody(node) ? 'definition' : 'declaration')] : [];
13072
+ }
13073
+ if (kind === 'VariableDecl') {
13074
+ return swiftSyntaxVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'property', 'definition'));
13075
+ }
13076
+ if (kind === 'PatternBinding' && node.parentKind === 'VariableDecl') {
13077
+ const name = swiftSyntaxDeclarationName(node, kind);
13078
+ return name ? [declarationRecord(input, nativeNodeId, name, 'property', 'definition')] : [];
13079
+ }
13080
+ if (kind === 'EnumCaseDecl') {
13081
+ return swiftSyntaxEnumCaseNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'enumMember', 'definition'));
13082
+ }
13083
+ if (kind === 'EnumCaseElement') {
13084
+ const name = swiftSyntaxDeclarationName(node, kind);
13085
+ return name ? [declarationRecord(input, nativeNodeId, name, 'enumMember', 'definition')] : [];
13086
+ }
13087
+ return [];
13088
+ }
13089
+
13090
+ function swiftSyntaxChildEntries(node, kind = swiftSyntaxKind(node)) {
13091
+ const fieldNames = Object.keys(node).filter((key) => !ignoredSwiftSyntaxField(key));
13092
+ const entries = [];
13093
+ for (const field of fieldNames) {
13094
+ const value = node[field];
13095
+ if (Array.isArray(value)) {
13096
+ entries.push([field, value.map((entry) => swiftSyntaxChildWithParent(entry, kind, field))]);
13097
+ continue;
13098
+ }
13099
+ if (value && typeof value === 'object') {
13100
+ entries.push([field, swiftSyntaxChildWithParent(value, kind, field)]);
13101
+ }
13102
+ }
13103
+ return entries.filter(([, value]) => Array.isArray(value)
13104
+ ? value.some(isSwiftSyntaxNode)
13105
+ : isSwiftSyntaxNode(value));
13106
+ }
13107
+
13108
+ function swiftSyntaxChildWithParent(entry, parentKind, parentField) {
13109
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return entry;
13110
+ if (!isSwiftSyntaxNode(entry)) return entry;
13111
+ return { parentKind, parentField, ...entry };
13112
+ }
13113
+
13114
+ function swiftSyntaxNodeValue(node) {
13115
+ return swiftSyntaxDeclarationName(node, swiftSyntaxKind(node))
13116
+ ?? swiftSyntaxImportPath(node)
13117
+ ?? swiftSyntaxTypeName(node.type ?? node.returnClause?.type ?? node.extendedType)
13118
+ ?? swiftSyntaxLiteralValue(node);
13119
+ }
13120
+
13121
+ function swiftSyntaxDeclarationName(node, kind = swiftSyntaxKind(node)) {
13122
+ if (!node || typeof node !== 'object') return undefined;
13123
+ if (kind === 'InitializerDecl') return 'init';
13124
+ if (kind === 'DeinitializerDecl') return 'deinit';
13125
+ if (kind === 'SubscriptDecl') return 'subscript';
13126
+ if (kind === 'ExtensionDecl') {
13127
+ const extended = swiftSyntaxTypeName(node.extendedType ?? node.type ?? node.name);
13128
+ return extended ? `extension ${extended}` : undefined;
13129
+ }
13130
+ if (kind === 'OperatorDecl') return swiftSyntaxOperatorName(node, kind);
13131
+ for (const key of ['identifier', 'name', 'simpleName', 'typeName', 'id']) {
13132
+ const name = swiftSyntaxName(node[key]);
13133
+ if (name) return name;
13134
+ }
13135
+ const patternName = swiftSyntaxPatternName(node.pattern);
13136
+ if (patternName) return patternName;
13137
+ return undefined;
13138
+ }
13139
+
13140
+ function swiftSyntaxName(value) {
13141
+ if (!value) return undefined;
13142
+ if (typeof value === 'string') return value;
13143
+ if (typeof value.text === 'string') return value.text;
13144
+ if (typeof value.trimmedDescription === 'string') return value.trimmedDescription;
13145
+ if (typeof value.description === 'string' && !value.description.includes('[object Object]')) return value.description.trim();
13146
+ if (typeof value.identifier === 'string') return value.identifier;
13147
+ if (typeof value.name === 'string') return value.name;
13148
+ if (typeof value.value === 'string') return value.value;
13149
+ if (value.tokenKind && typeof value.tokenKind === 'object') return swiftSyntaxName(value.tokenKind);
13150
+ if (value.identifier && value.identifier !== value) return swiftSyntaxName(value.identifier);
13151
+ if (value.name && value.name !== value) return swiftSyntaxName(value.name);
13152
+ return undefined;
13153
+ }
13154
+
13155
+ function swiftSyntaxImportPath(node) {
13156
+ if (!node || typeof node !== 'object') return undefined;
13157
+ const path = node.importPath ?? node.path ?? node.modulePath ?? node.name;
13158
+ if (typeof path === 'string') return path;
13159
+ if (Array.isArray(path)) {
13160
+ return path.map((entry) => swiftSyntaxName(entry.name ?? entry.identifier ?? entry)).filter(Boolean).join('.');
13161
+ }
13162
+ if (path && typeof path === 'object') {
13163
+ if (Array.isArray(path.components)) return path.components.map((entry) => swiftSyntaxName(entry.name ?? entry.identifier ?? entry)).filter(Boolean).join('.');
13164
+ return swiftSyntaxName(path);
13165
+ }
13166
+ return undefined;
13167
+ }
13168
+
13169
+ function swiftSyntaxTypeName(value) {
13170
+ if (!value) return undefined;
13171
+ if (typeof value === 'string') return value;
13172
+ if (typeof value.trimmedDescription === 'string') return value.trimmedDescription;
13173
+ if (typeof value.description === 'string' && !value.description.includes('[object Object]')) return value.description.trim();
13174
+ if (typeof value.name === 'string') return value.name;
13175
+ if (typeof value.text === 'string') return value.text;
13176
+ if (value.baseType) {
13177
+ const base = swiftSyntaxTypeName(value.baseType);
13178
+ return base && value.name ? `${base}.${swiftSyntaxName(value.name)}` : base;
13179
+ }
13180
+ if (value.argumentList && Array.isArray(value.argumentList)) {
13181
+ const base = swiftSyntaxName(value.name) ?? swiftSyntaxTypeName(value.baseName);
13182
+ const args = value.argumentList.map((entry) => swiftSyntaxTypeName(entry.type ?? entry)).filter(Boolean);
13183
+ return base ? `${base}<${args.join(', ')}>` : undefined;
13184
+ }
13185
+ return swiftSyntaxName(value);
13186
+ }
13187
+
13188
+ function swiftSyntaxModifierNames(node) {
13189
+ const modifiers = node.modifiers ?? node.Modifiers;
13190
+ if (!modifiers) return [];
13191
+ if (Array.isArray(modifiers)) {
13192
+ return uniqueStrings(modifiers.map((entry) => typeof entry === 'string' ? entry : swiftSyntaxName(entry.name ?? entry.modifier ?? entry)).filter(Boolean));
13193
+ }
13194
+ if (typeof modifiers === 'string') return uniqueStrings(modifiers.split(/\s+/).filter(Boolean));
13195
+ if (typeof modifiers === 'object') {
13196
+ return uniqueStrings(Object.entries(modifiers)
13197
+ .filter(([, enabled]) => enabled === true)
13198
+ .map(([key]) => key));
13199
+ }
13200
+ return [];
13201
+ }
13202
+
13203
+ function swiftSyntaxAttributeNames(node) {
13204
+ const attributes = node.attributes ?? node.attributeList;
13205
+ if (!attributes) return [];
13206
+ if (Array.isArray(attributes)) {
13207
+ return uniqueStrings(attributes.map((entry) => typeof entry === 'string' ? entry : swiftSyntaxName(entry.attributeName ?? entry.name ?? entry)).filter(Boolean));
13208
+ }
13209
+ return [];
13210
+ }
13211
+
13212
+ function swiftSyntaxVariableNames(node) {
13213
+ const bindings = node.bindings ?? node.bindingSpecifier?.bindings ?? node.patternBindings;
13214
+ if (Array.isArray(bindings)) return bindings.map((binding) => swiftSyntaxPatternName(binding.pattern ?? binding)).filter(Boolean);
13215
+ const name = swiftSyntaxPatternName(node.pattern) ?? swiftSyntaxDeclarationName(node);
13216
+ return name ? [name] : [];
13217
+ }
13218
+
13219
+ function swiftSyntaxEnumCaseNames(node) {
13220
+ const elements = node.elements ?? node.caseElements ?? node.cases;
13221
+ if (Array.isArray(elements)) return elements.map((entry) => swiftSyntaxDeclarationName(entry, 'EnumCaseElement')).filter(Boolean);
13222
+ const name = swiftSyntaxDeclarationName(node);
13223
+ return name ? [name] : [];
13224
+ }
13225
+
13226
+ function swiftSyntaxPatternName(pattern) {
13227
+ if (!pattern) return undefined;
13228
+ if (typeof pattern === 'string') return pattern;
13229
+ return swiftSyntaxName(pattern.identifier ?? pattern.name ?? pattern.boundName ?? pattern.pattern ?? pattern);
13230
+ }
13231
+
13232
+ function swiftSyntaxTypeDeclarationKind(kind) {
13233
+ return kind === 'ClassDecl'
13234
+ || kind === 'StructDecl'
13235
+ || kind === 'EnumDecl'
13236
+ || kind === 'ProtocolDecl'
13237
+ || kind === 'ActorDecl';
13238
+ }
13239
+
13240
+ function swiftSyntaxTypeDeclarationSymbolKind(kind) {
13241
+ if (kind === 'ClassDecl') return 'class';
13242
+ if (kind === 'StructDecl') return 'struct';
13243
+ if (kind === 'EnumDecl') return 'enum';
13244
+ if (kind === 'ProtocolDecl') return 'protocol';
13245
+ if (kind === 'ActorDecl') return 'class';
13246
+ return 'type';
13247
+ }
13248
+
13249
+ function swiftSyntaxFunctionLikeKind(kind) {
13250
+ return kind === 'FunctionDecl'
13251
+ || kind === 'InitializerDecl'
13252
+ || kind === 'DeinitializerDecl'
13253
+ || kind === 'SubscriptDecl'
13254
+ || kind === 'OperatorDecl'
13255
+ || kind === 'PrecedenceGroupDecl';
13256
+ }
13257
+
13258
+ function swiftSyntaxHasBody(node) {
13259
+ return Boolean(node.body || node.accessorBlock || node.memberBlock || Array.isArray(node.statements));
13260
+ }
13261
+
13262
+ function swiftSyntaxOperatorName(node, kind) {
13263
+ if (kind === 'PrecedenceGroupDecl') return swiftSyntaxDeclarationName(node) ?? 'precedencegroup';
13264
+ const operatorToken = swiftSyntaxName(node.operatorIdentifier ?? node.operatorToken ?? node.name);
13265
+ return operatorToken ? `operator ${operatorToken}` : undefined;
13266
+ }
13267
+
13268
+ function swiftSyntaxLiteralValue(node) {
13269
+ const value = node.value ?? node.literal;
13270
+ if (value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return value;
13271
+ return undefined;
13272
+ }
13273
+
13274
+ function swiftSyntaxRecoveredKind(kind) {
13275
+ return kind === 'UnexpectedNodes'
13276
+ || kind === 'MissingToken'
13277
+ || kind === 'SkippedToken'
13278
+ || kind === 'Error'
13279
+ || /Unexpected|Missing|Skipped|Error/.test(String(kind));
13280
+ }
13281
+
13282
+ function swiftSyntaxProblemNode(node, kind) {
13283
+ return Boolean(
13284
+ node.isMissing
13285
+ || node.hasError
13286
+ || node.containsDiagnostics
13287
+ || node.containsSkippedText
13288
+ || node.presence === 'missing'
13289
+ || kind === 'UnexpectedNodes'
13290
+ || kind === 'MissingToken'
13291
+ || kind === 'SkippedToken'
13292
+ || kind === 'Error'
13293
+ );
13294
+ }
13295
+
13296
+ function swiftSyntaxConditionalCompilationKind(kind) {
13297
+ return /IfConfig|ConditionalCompilation|PoundIf|PoundElse|PoundElseif|PoundEndif/i.test(String(kind));
13298
+ }
13299
+
13300
+ function swiftSyntaxMacroKind(kind) {
13301
+ return /Macro/i.test(String(kind));
13302
+ }
13303
+
13304
+ function swiftGeneratedCodeMarker(node, kind) {
13305
+ if (node.generated || node.isGenerated) return true;
13306
+ const path = String(node.filePath ?? node.path ?? node.sourcePath ?? '');
13307
+ if (swiftGeneratedSourcePath(path)) return true;
13308
+ if (kind === 'Attribute') {
13309
+ const name = swiftSyntaxDeclarationName(node);
13310
+ if (name && /(^|\.)(Generated|CompilerGenerated|_spi)Attribute?$/.test(name)) return true;
13311
+ }
13312
+ return false;
13313
+ }
13314
+
13315
+ function swiftGeneratedSourcePath(path) {
13316
+ return typeof path === 'string' && /\.(g|generated)\.swift$/i.test(path);
13317
+ }
13318
+
13319
+ function swiftGeneratedCodeLoss(input, nodeId, span, options = {}, metadata = {}) {
13320
+ return {
13321
+ id: `loss_${idFragment(nodeId ?? input.sourcePath ?? 'swift')}_swift_generated_code`,
13322
+ severity: 'warning',
13323
+ phase: 'parse',
13324
+ sourceFormat: input.language,
13325
+ kind: 'generatedCode',
13326
+ message: 'Swift generated-source marker was imported; generated member provenance and source ownership require host evidence.',
13327
+ span,
13328
+ nodeId,
13329
+ metadata: {
13330
+ parser: options.parser,
13331
+ astFormat: options.astFormat,
13332
+ macroExpansionEvidence: swiftEvidenceSummary(options.macroExpansionEvidence),
13333
+ ...metadata
13334
+ }
13335
+ };
13336
+ }
13337
+
13338
+ function swiftEvidenceSummary(value) {
13339
+ if (!value) return undefined;
13340
+ if (Array.isArray(value)) return { entryCount: value.length };
13341
+ if (typeof value === 'string') return { value };
13342
+ if (typeof value === 'object') {
13343
+ const summary = {};
13344
+ if (typeof value.hash === 'string') summary.hash = value.hash;
13345
+ if (typeof value.solver === 'string') summary.solver = value.solver;
13346
+ if (Array.isArray(value.entries)) summary.entryCount = value.entries.length;
13347
+ if (Array.isArray(value.symbols)) summary.symbolCount = value.symbols.length;
13348
+ if (Array.isArray(value.references)) summary.referenceCount = value.references.length;
13349
+ if (Array.isArray(value.types)) summary.typeCount = value.types.length;
13350
+ if (Array.isArray(value.diagnostics)) summary.diagnosticCount = value.diagnostics.length;
13351
+ if (Array.isArray(value.macros)) summary.macroCount = value.macros.length;
13352
+ if (Array.isArray(value.packages)) summary.packageCount = value.packages.length;
13353
+ return Object.keys(summary).length ? summary : { present: true };
13354
+ }
13355
+ return { present: true };
13356
+ }
13357
+
11899
13358
  function declarationRecord(input, nativeNodeId, name, symbolKind, role = 'definition') {
11900
13359
  return {
11901
13360
  name: String(name),