public override void VisitManagedType(TypeDefinition type) { // exclude non enum and nested enums, e.g. bunch of Selector enums in CTFont if (!type.IsEnum || type.IsNested) { return; } var name = type.Name; // e.g. WatchKit.WKErrorCode and WebKit.WKErrorCode :-( if (!enums.TryGetValue(name, out var td)) { enums.Add(name, type); } else { var(t1, t2) = Helpers.Sort(type, td); if (t1.Namespace.StartsWith("OpenTK.", StringComparison.Ordinal)) { // OpenTK duplicate a lots of enums between it's versions } else if (t1.IsNotPublic && String.IsNullOrEmpty(t1.Namespace)) { // ignore special, non exposed types } else { var framework = Helpers.GetFramework(t1); Log.On(framework).Add($"!duplicate-type-name! {name} enum exists as both {t1.FullName} and {t2.FullName}"); } } }
public override void VisitManagedType(TypeDefinition type) { // exclude non enum and nested enums, e.g. bunch of Selector enums in CTFont if (!type.IsEnum || type.IsNested) { return; } var name = type.Name; // e.g. WatchKit.WKErrorCode and WebKit.WKErrorCode :-( if (!enums.TryGetValue(name, out var td)) { enums.Add(name, type); } else if (td.Namespace.StartsWith("OpenTK.", StringComparison.Ordinal)) { // OpenTK duplicate a lots of enums between it's versions } else { var sorted = Helpers.Sort(type.FullName, td.FullName); var framework = Helpers.GetFramework(type); Log.On(framework).Add($"!duplicate-type-name! {name} enum exists as both {sorted.Item1} and {sorted.Item2}"); } }
public override void VisitManagedType(TypeDefinition type) { if (!type.HasCustomAttributes) { return; } string rname = null; bool wrapper = true; bool skip = false; foreach (var ca in type.CustomAttributes) { switch (ca.Constructor.DeclaringType.Name) { case "RegisterAttribute": rname = type.Name; if (ca.HasConstructorArguments) { rname = (ca.ConstructorArguments [0].Value as string); if (ca.ConstructorArguments.Count > 1) { wrapper = (bool)ca.ConstructorArguments [1].Value; } } if (ca.HasProperties) { foreach (var arg in ca.Properties) { switch (arg.Name) { case "Wrapper": wrapper = (bool)arg.Argument.Value; break; case "SkipRegistration": skip = (bool)arg.Argument.Value; break; } } } break; case "ProtocolAttribute": // exclude protocols return; } } if (!skip && wrapper && !String.IsNullOrEmpty(rname)) { TypeDefinition td; if (!type_map.TryGetValue(rname, out td)) { type_map.Add(rname, type); type_map_copy.Add(rname, type); } else { // always report in the same order (for unique error messages) var sorted = Helpers.Sort(type, td); var framework = Helpers.GetFramework(sorted.Item1); Log.On(framework).Add($"!duplicate-register! {rname} exists as both {sorted.Item1.FullName} and {sorted.Item2.FullName}"); } } }
public override void VisitManagedMethod(MethodDefinition method) { var type = method.DeclaringType; if (!type.IsNested && type.IsNotPublic) { return; } if (type.IsNested && (type.IsNestedPrivate || type.IsNestedAssembly || type.IsNestedFamilyAndAssembly)) { return; } if (method.IsPrivate || method.IsAssembly || method.IsFamilyAndAssembly) { return; // Don't care about non-visible types } if (type.Namespace == "Simd" || type.Namespace.StartsWith("OpenTK", StringComparison.Ordinal)) { return; // We're assuming everything in the Simd and OpenTK namespaces can be ignored (the former because it's correctly written, the latter because it doesn't map to native simd types). } if (method.HasCustomAttributes && method.CustomAttributes.Where((v) => v.Constructor.DeclaringType.Name == "ExtensionAttribute").Any()) { return; // Extension methods can't be mapped. } var invalid_simd_type = false; var contains_simd_types = ContainsSimdTypes(method, ref invalid_simd_type); var key = method.GetName(); if (key == null) { if (method.IsObsolete()) { return; // Don't care about obsolete API. } if (contains_simd_types && very_strict) { // We can't map this method to a native function. var framework = method.DeclaringType.Namespace; Log.On(framework).Add($"!missing-simd-native-signature! {method}"); } return; } ManagedSimdInfo existing; if (managed_methods.TryGetValue(key, out existing)) { if (very_strict) { var sorted = Helpers.Sort(existing.Method, method); var framework = sorted.Item1.DeclaringType.Namespace; Log.On(framework).Add($"!duplicate-type-mapping! same key '{key}' for both '{sorted.Item1.FullName}' and '{sorted.Item2.FullName}'"); } } else { managed_methods [key] = new ManagedSimdInfo { Method = method, ContainsInvalidMappingForSimd = invalid_simd_type }; } }