|
4 | 4 | using NativeCodeGen.Core.Models; |
5 | 5 | using NativeCodeGen.Core.Parsing; |
6 | 6 | using NativeCodeGen.Core.Registry; |
| 7 | +using NativeCodeGen.Core.Utilities; |
7 | 8 | using NativeCodeGen.Lua; |
8 | 9 | using NativeCodeGen.TypeScript; |
9 | 10 |
|
@@ -263,6 +264,44 @@ static async Task Validate(string input, bool strict) |
263 | 264 | } |
264 | 265 | }); |
265 | 266 |
|
| 267 | + // Check for duplicate native names (globally, after normalization) |
| 268 | + var duplicateNames = allNatives |
| 269 | + .GroupBy(n => NameConverter.NormalizeNativeName(n.Name), StringComparer.OrdinalIgnoreCase) |
| 270 | + .Where(g => g.Count() > 1) |
| 271 | + .ToList(); |
| 272 | + |
| 273 | + foreach (var dup in duplicateNames) |
| 274 | + { |
| 275 | + var natives = dup.ToList(); |
| 276 | + var names = natives.Select(n => n.Name).Distinct().ToList(); |
| 277 | + var nameDisplay = names.Count > 1 ? $"'{string.Join("', '", names)}'" : $"'{names[0]}'"; |
| 278 | + allErrors.Add(new ParseError |
| 279 | + { |
| 280 | + FilePath = natives[0].SourceFile ?? "unknown", |
| 281 | + Line = 1, |
| 282 | + Column = 1, |
| 283 | + Message = $"Duplicate native name {nameDisplay} (normalized: '{dup.Key}'). Also defined in: {string.Join(", ", natives.Skip(1).Select(n => Path.GetFileName(n.SourceFile ?? "unknown")))}" |
| 284 | + }); |
| 285 | + } |
| 286 | + |
| 287 | + // Check for duplicate hashes |
| 288 | + var duplicateHashes = allNatives |
| 289 | + .GroupBy(n => n.Hash, StringComparer.OrdinalIgnoreCase) |
| 290 | + .Where(g => g.Count() > 1) |
| 291 | + .ToList(); |
| 292 | + |
| 293 | + foreach (var dup in duplicateHashes) |
| 294 | + { |
| 295 | + var natives = dup.ToList(); |
| 296 | + allErrors.Add(new ParseError |
| 297 | + { |
| 298 | + FilePath = natives[0].SourceFile ?? "unknown", |
| 299 | + Line = 1, |
| 300 | + Column = 1, |
| 301 | + Message = $"Duplicate hash '{dup.Key}'. Also defined in: {string.Join(", ", natives.Skip(1).Select(n => Path.GetFileName(n.SourceFile ?? "unknown")))}" |
| 302 | + }); |
| 303 | + } |
| 304 | + |
266 | 305 | // Group natives by namespace |
267 | 306 | var namespaceDict = allNatives |
268 | 307 | .GroupBy(n => n.Namespace, StringComparer.OrdinalIgnoreCase) |
|
0 commit comments