This commit is contained in:
Rolf Bjarne Kvinge 2022-11-08 17:44:13 +01:00 коммит произвёл GitHub
Родитель 1cb4266ffa
Коммит bc95efb0ae
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
20 изменённых файлов: 71 добавлений и 82 удалений

Просмотреть файл

@ -5,10 +5,8 @@ using Clang;
using Clang.Ast;
using Mono.Cecil;
namespace Extrospection
{
public static class AttributeHelpers
{
namespace Extrospection {
public static class AttributeHelpers {
static bool Skip (ICustomAttributeProvider item)
{
// Before accessing CustomAttributes we must query HasCustomAttributes
@ -50,7 +48,7 @@ namespace Extrospection
static bool HasMatchingPlatformAttribute (string expectedAttributeName, CustomAttribute attribute, Platforms platform)
{
if (attribute.Constructor.DeclaringType.Name == expectedAttributeName) {
byte attrPlatform = (byte)attribute.ConstructorArguments[0].Value;
byte attrPlatform = (byte) attribute.ConstructorArguments [0].Value;
if (attrPlatform == Helpers.GetPlatformManagedValue (platform))
return true;
}
@ -88,10 +86,10 @@ namespace Extrospection
version = null;
return true;
case 5:
version = new Version ((int)attribute.ConstructorArguments[1].Value, (int)attribute.ConstructorArguments[2].Value);
version = new Version ((int) attribute.ConstructorArguments [1].Value, (int) attribute.ConstructorArguments [2].Value);
return true;
case 6:
version = new Version ((int)attribute.ConstructorArguments[1].Value, (int)attribute.ConstructorArguments[2].Value, (int)attribute.ConstructorArguments[3].Value);
version = new Version ((int) attribute.ConstructorArguments [1].Value, (int) attribute.ConstructorArguments [2].Value, (int) attribute.ConstructorArguments [3].Value);
return true;
default:
throw new InvalidOperationException ($"GetPlatformVersion with unexpected number of arguments {attribute.ConstructorArguments.Count} {attribute.Constructor.DeclaringType.Name}");
@ -137,7 +135,7 @@ namespace Extrospection
return true;
// The only related platforms for .NET is iOS for Mac Catalyst
if (Helpers.Platform == Platforms.MacCatalyst &&
if (Helpers.Platform == Platforms.MacCatalyst &&
(AttributeHelpers.HasObsoletedOSPlatform (attribute, Platforms.iOS) ||
AttributeHelpers.HasUnsupportedOSPlatform (attribute, Platforms.iOS)))
return true;
@ -165,18 +163,18 @@ namespace Extrospection
return false;
}
static Platforms[] GetRelatedPlatforms ()
static Platforms [] GetRelatedPlatforms ()
{
// TV and Watch also implictly accept iOS
switch (Helpers.Platform) {
case Platforms.macOS:
return new Platforms[] { Platforms.macOS };
return new Platforms [] { Platforms.macOS };
case Platforms.iOS:
return new Platforms[] { Platforms.iOS };
return new Platforms [] { Platforms.iOS };
case Platforms.tvOS:
return new Platforms[] { Platforms.iOS, Platforms.tvOS };
return new Platforms [] { Platforms.iOS, Platforms.tvOS };
case Platforms.watchOS:
return new Platforms[] { Platforms.iOS, Platforms.watchOS };
return new Platforms [] { Platforms.iOS, Platforms.watchOS };
case Platforms.MacCatalyst:
return new Platforms [] { Platforms.iOS, Platforms.MacCatalyst };
default:

Просмотреть файл

@ -5,10 +5,8 @@ using Clang;
using Clang.Ast;
using Mono.Cecil;
namespace Extrospection
{
public class DeprecatedCheck : BaseVisitor
{
namespace Extrospection {
public class DeprecatedCheck : BaseVisitor {
Dictionary<string, VersionTuple> ObjCDeprecatedItems = new Dictionary<string, VersionTuple> ();
Dictionary<string, VersionTuple> ObjCDeprecatedSelectors = new Dictionary<string, VersionTuple> ();
Dictionary<string, VersionTuple> PlainCDeprecatedFunctions = new Dictionary<string, VersionTuple> ();
@ -50,7 +48,7 @@ namespace Extrospection
void ProcessObjcEntry (string objcClassName, VersionTuple objcVersion)
{
TypeDefinition managedType = ManagedTypes.FirstOrDefault (x => Helpers.GetName (x) == objcClassName && x.IsPublic);
if (managedType != null) {
if (managedType != null) {
var framework = Helpers.GetFramework (managedType);
if (framework != null)
ProcessItem (managedType, Helpers.GetName (managedType), objcVersion, framework);
@ -61,7 +59,7 @@ namespace Extrospection
{
var class_method = fullname [0] == '+';
var n = fullname.IndexOf ("::");
string objcClassName = fullname.Substring (class_method ? 1: 0, n);
string objcClassName = fullname.Substring (class_method ? 1 : 0, n);
string selector = fullname.Substring (n + 2);
TypeDefinition managedType = ManagedTypes.FirstOrDefault (x => Helpers.GetName (x) == objcClassName);
@ -114,7 +112,7 @@ namespace Extrospection
// Don't version check us when Apple does __attribute__((availability(macos, introduced=10.0, deprecated=100000)));
// #define __API_TO_BE_DEPRECATED 100000
if (objcVersion.Major == 100000)
if (objcVersion.Major == 100000)
return;
// Some APIs have both a [Deprecated] and [Obsoleted]. Bias towards [Obsoleted].
@ -151,7 +149,7 @@ namespace Extrospection
// `(anonymous)` has a null name
var name = decl.Name;
if (name is not null)
ObjCDeprecatedItems[name] = version;
ObjCDeprecatedItems [name] = version;
}
}

Просмотреть файл

@ -22,8 +22,8 @@ namespace Extrospection {
public class DesignatedInitializerCheck : BaseVisitor {
static Dictionary<string,TypeDefinition> types = new Dictionary<string,TypeDefinition> ();
static Dictionary<string,MethodDefinition> methods = new Dictionary<string,MethodDefinition> ();
static Dictionary<string, TypeDefinition> types = new Dictionary<string, TypeDefinition> ();
static Dictionary<string, MethodDefinition> methods = new Dictionary<string, MethodDefinition> ();
static TypeDefinition GetType (ObjCInterfaceDecl decl)
{
@ -43,7 +43,7 @@ namespace Extrospection {
var key = method.GetName ();
if (key == null)
return;
// we still have one case to fix with duplicate selectors :|
if (!methods.ContainsKey (key))
methods.Add (key, method);

Просмотреть файл

@ -23,7 +23,7 @@ namespace Extrospection {
class DllImportCheck : BaseVisitor {
// dupes :|
Dictionary<string,MethodDefinition> dllimports = new Dictionary<string, MethodDefinition> ();
Dictionary<string, MethodDefinition> dllimports = new Dictionary<string, MethodDefinition> ();
public override void VisitManagedMethod (MethodDefinition method)
{
@ -33,7 +33,7 @@ namespace Extrospection {
var info = method.PInvokeInfo;
if (info.Module.Name == "__Internal")
return;
// there are duplicates declarations
// TODO: right now we only check the first one, as the priority is knowing if we have (or not) bindings for them
var name = info.EntryPoint;
@ -61,7 +61,7 @@ namespace Extrospection {
// check availability macros to see if the API is available on the OS and not deprecated
if (!decl.IsAvailable ())
return;
if (!dllimports.ContainsKey (name)) {
// if we find functions without matching DllImport then we report them
// but don't report deprecated functions

Просмотреть файл

@ -13,8 +13,8 @@ namespace Extrospection {
public EnumConstantDecl Decl;
}
Dictionary<string,TypeDefinition> enums = new Dictionary<string, TypeDefinition> (StringComparer.InvariantCultureIgnoreCase);
Dictionary<string,TypeDefinition> obsoleted_enums = new Dictionary<string,TypeDefinition> ();
Dictionary<string, TypeDefinition> enums = new Dictionary<string, TypeDefinition> (StringComparer.InvariantCultureIgnoreCase);
Dictionary<string, TypeDefinition> obsoleted_enums = new Dictionary<string, TypeDefinition> ();
Dictionary<object, ManagedValue> managed_values = new Dictionary<object, ManagedValue> ();
Dictionary<object, (string Name, EnumConstantDecl Decl)> native_values = new Dictionary<object, (string Name, EnumConstantDecl Decl)> ();
@ -23,7 +23,7 @@ namespace Extrospection {
// exclude non enum and nested enums, e.g. bunch of Selector enums in CTFont
if (!type.IsEnum || type.IsNested)
return;
var name = type.Name;
// exclude obsolete enums, presumably we already know there's something wrong with them if they've been obsoleted.
@ -71,7 +71,7 @@ namespace Extrospection {
var framework = Helpers.GetFramework (decl);
if (framework == null)
return;
var mname = Helpers.GetManagedName (name);
// If our enum is obsoleted, then don't process it.
@ -322,7 +322,7 @@ namespace Extrospection {
{
if (!type.HasCustomAttributes)
return false;
foreach (var ca in type.CustomAttributes) {
if (ca.Constructor.DeclaringType.Name == "NativeAttribute")
return true;

Просмотреть файл

@ -25,7 +25,7 @@ namespace Extrospection {
public class FieldCheck : BaseVisitor {
Dictionary<string,MemberReference> fields = new Dictionary<string, MemberReference> ();
Dictionary<string, MemberReference> fields = new Dictionary<string, MemberReference> ();
public override void VisitManagedType (TypeDefinition type)
{

Просмотреть файл

@ -9,8 +9,7 @@ using Clang.Ast;
namespace Extrospection {
public enum Platforms
{
public enum Platforms {
macOS,
iOS,
watchOS,
@ -61,8 +60,7 @@ namespace Extrospection {
}
// Clang.Ast.AvailabilityAttr.Platform.Name
public static string ClangPlatformName
{
public static string ClangPlatformName {
get {
switch (Helpers.Platform) {
case Platforms.macOS:
@ -140,7 +138,7 @@ namespace Extrospection {
result = category.ClassInterface.IsAvailable (Platform);
}
}
// but right now most frameworks consider tvOS, watchOS, and catalyst like iOS unless
// decorated otherwise so we must check again if we do not get a definitve answer
if ((result == null) && ((Platform == Platforms.tvOS) || (Platform == Platforms.watchOS) || (Platform == Platforms.MacCatalyst)))
@ -265,7 +263,7 @@ namespace Extrospection {
{
if (self == null)
return null;
var sb = new StringBuilder ();
if (self.IsClassMethod)
sb.Append ('+');
@ -438,7 +436,7 @@ namespace Extrospection {
var fxh = header_file.IndexOf (".framework/Headers/", StringComparison.Ordinal);
if (fxh <= 0)
return null;
var start = header_file.LastIndexOf ('/', fxh) + 1;
return MapFramework (header_file.Substring (start, fxh - start));
}

Просмотреть файл

@ -13,7 +13,7 @@ namespace Extrospection {
List<string> list;
if (!lists.TryGetValue (fx, out list)) {
list = new List<string> ();
lists.Add (fx, list);
lists.Add (fx, list);
}
return list;
}

Просмотреть файл

@ -115,7 +115,7 @@ namespace Extrospection {
return;
// don't process deprecated methods (or types)
if (decl.IsDeprecated () || (decl.DeclContext as Decl).IsDeprecated ())
if (decl.IsDeprecated () || (decl.DeclContext as Decl).IsDeprecated ())
return;
var method = GetMethod (decl);
@ -171,11 +171,11 @@ namespace Extrospection {
switch (nullability) {
case NullabilityKind.NonNull:
if (parameter_nullable == Null.Annotated)
Log.On (framework).Add ($"!extra-null-allowed! '{method.FullName}' has a extraneous [NullAllowed] on parameter #{i-1}");
Log.On (framework).Add ($"!extra-null-allowed! '{method.FullName}' has a extraneous [NullAllowed] on parameter #{i - 1}");
break;
case NullabilityKind.Nullable:
if (parameter_nullable != Null.Annotated)
Log.On (framework).Add ($"!missing-null-allowed! '{method.FullName}' is missing an [NullAllowed] on parameter #{i-1}");
Log.On (framework).Add ($"!missing-null-allowed! '{method.FullName}' is missing an [NullAllowed] on parameter #{i - 1}");
break;
case NullabilityKind.Unspecified:
break;

Просмотреть файл

@ -28,16 +28,16 @@ namespace Extrospection {
if (ca.HasConstructorArguments) {
rname = (ca.ConstructorArguments [0].Value as string);
if (ca.ConstructorArguments.Count > 1)
wrapper = (bool)ca.ConstructorArguments [1].Value;
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;
wrapper = (bool) arg.Argument.Value;
break;
case "SkipRegistration":
skip = (bool)arg.Argument.Value;
skip = (bool) arg.Argument.Value;
break;
}
}

Просмотреть файл

@ -31,7 +31,7 @@ using Mono.Cecil;
using Clang.Ast;
namespace Extrospection {
public class ObjCProtocolCheck : BaseVisitor {
Dictionary<string, TypeDefinition> protocol_map = new Dictionary<string, TypeDefinition> ();
@ -118,13 +118,13 @@ namespace Extrospection {
s_export = p.Argument.Value as string;
break;
case "IsRequired":
is_required = (bool)p.Argument.Value;
is_required = (bool) p.Argument.Value;
break;
case "IsProperty":
is_property = (bool)p.Argument.Value;
is_property = (bool) p.Argument.Value;
break;
case "IsStatic":
is_static = (bool)p.Argument.Value;
is_static = (bool) p.Argument.Value;
break;
}
}

Просмотреть файл

@ -6,8 +6,8 @@ using Mono.Options;
namespace Extrospection {
// this is used to be executed from a custom 64bits mono
class MainClass {
class MainClass {
static int Main (string [] arguments)
{
var outputDirectory = string.Empty;
@ -27,8 +27,7 @@ namespace Extrospection {
assemblies.Add (args [i]);
new Runner ().Execute (args [0], assemblies, outputDirectory);
return 0;
}
catch (Exception e) {
} catch (Exception e) {
Console.WriteLine (e);
return 1;
}

Просмотреть файл

@ -63,7 +63,7 @@ namespace Extrospection {
if (firstLetter == i && c == '_') {
// ... ignoring any leading underscores ...
firstLetter++;
} else if (c < 'a' || c > 'z') {
} else if (c < 'a' || c > 'z') {
firstNonLowercaseLetter = i;
break;
}

Просмотреть файл

@ -19,7 +19,7 @@ namespace Extrospection {
public class RequiresSuperCheck : BaseVisitor {
static Dictionary<string,MethodDefinition> methods = new Dictionary<string,MethodDefinition> ();
static Dictionary<string, MethodDefinition> methods = new Dictionary<string, MethodDefinition> ();
static MethodDefinition GetMethod (ObjCMethodDecl decl)
{

Просмотреть файл

@ -8,7 +8,7 @@ using Mono.Cecil;
using Clang.Ast;
namespace Extrospection {
public class Runner {
public Runner ()
@ -161,7 +161,7 @@ namespace Extrospection {
// debug
class ListNative : BaseVisitor {
public override void VisitDecl (Decl decl)
{
if (decl is FunctionDecl) {

Просмотреть файл

@ -37,7 +37,7 @@ namespace Extrospection {
if (!string.IsNullOrEmpty (methodDefinition)) {
var argumentSemantic = Helpers.ArgumentSemantic.Assign; // Default
if (ca.ConstructorArguments.Count > 1) {
argumentSemantic = (Helpers.ArgumentSemantic)ca.ConstructorArguments [1].Value;
argumentSemantic = (Helpers.ArgumentSemantic) ca.ConstructorArguments [1].Value;
if (!qualified_properties.TryGetValue (methodDefinition, out var list))
qualified_properties [methodDefinition] = list = new List<Tuple<MethodDefinition, Helpers.ArgumentSemantic>> ();
list.Add (new Tuple<MethodDefinition, Helpers.ArgumentSemantic> (method, argumentSemantic));
@ -98,7 +98,7 @@ namespace Extrospection {
return;
// don't process deprecated methods (or types)
if (decl.IsDeprecated () || (decl.DeclContext as Decl).IsDeprecated ())
if (decl.IsDeprecated () || (decl.DeclContext as Decl).IsDeprecated ())
return;
var framework = Helpers.GetFramework (decl);

Просмотреть файл

@ -6,17 +6,14 @@ using Mono.Cecil;
using Clang.Ast;
namespace Extrospection
{
namespace Extrospection {
class SimdCheck : BaseVisitor
{
class SimdCheck : BaseVisitor {
bool very_strict = false;
bool strict = false;
// A dictionary of native type -> managed type mapping.
class NativeSimdInfo
{
class NativeSimdInfo {
public string Managed;
public string InvalidManaged;
}
@ -93,8 +90,7 @@ namespace Extrospection
}
}
class ManagedSimdInfo
{
class ManagedSimdInfo {
public MethodDefinition Method;
public bool ContainsInvalidMappingForSimd;
}
@ -144,7 +140,8 @@ namespace Extrospection
}
} else {
managed_methods [key] = new ManagedSimdInfo {
Method = method, ContainsInvalidMappingForSimd = invalid_simd_type
Method = method,
ContainsInvalidMappingForSimd = invalid_simd_type
};
}
}
@ -218,10 +215,10 @@ namespace Extrospection
var framework = Helpers.GetFramework (decl);
Log.On (framework).Add ($"!unknown-simd-type! Could not detect that {typeName} is a Simd type, but its name contains 'simd'. Something needs fixing in SimdCheck.cs");
}
if (rv)
simd_type = typeName;
return rv;
}
@ -268,7 +265,7 @@ namespace Extrospection
const string _Nullable = " _Nullable";
if (native_name.EndsWith (_Nullable, StringComparison.Ordinal))
return Undecorate (native_name.Substring (0, native_name.Length - _Nullable.Length));
const string _star = " *";
if (native_name.EndsWith (_star, StringComparison.Ordinal))
return Undecorate (native_name.Substring (0, native_name.Length - _star.Length));
@ -404,7 +401,7 @@ namespace Extrospection
if (requires_marshal_directive)
CheckMarshalDirective (method, simd_type);
// We have a potentially broken managed method. This needs fixing/investigation.
Log.On (framework).Add ($"!unknown-simd-type-in-signature! {method}: the native signature has a simd type ({simd_type}), while the corresponding managed method is using an incorrect (non-simd) type.");
}

Просмотреть файл

@ -21,7 +21,7 @@ namespace Extrospection {
static HashSet<TypeDefinition> appearance_types = new HashSet<TypeDefinition> ();
static HashSet<MethodDefinition> appearance_methods = new HashSet<MethodDefinition> ();
static Dictionary<string,MethodDefinition> methods = new Dictionary<string,MethodDefinition> ();
static Dictionary<string, MethodDefinition> methods = new Dictionary<string, MethodDefinition> ();
static MethodDefinition GetMethod (ObjCMethodDecl decl)
{
@ -110,7 +110,7 @@ namespace Extrospection {
}
}
Log.On (framework).Add ($"!missing-ui-appearance-support! {method.GetName ()} is missing [Appearance]");
Log.On (framework).Add ($"!missing-ui-appearance-support! {method.GetName ()} is missing [Appearance]");
}
public override void End ()

Просмотреть файл

@ -2,18 +2,16 @@ using System;
using Clang;
using static Extrospection.Helpers;
namespace Extrospection
{
public static class VersionHelpers
{
namespace Extrospection {
public static class VersionHelpers {
public static Version Convert (VersionTuple version)
{
uint major = version.Major;
uint minor = version.Minor.HasValue ? version.Minor.Value : 0;
if (version.Subminor.HasValue)
return new Version ((int)major, (int)minor, (int)version.Subminor.Value);
return new Version ((int) major, (int) minor, (int) version.Subminor.Value);
else
return new Version ((int)major, (int)minor);
return new Version ((int) major, (int) minor);
}
public static bool VersionTooOldToCare (VersionTuple version)

Просмотреть файл

@ -34,6 +34,7 @@ dotnet format whitespace "$SRC_DIR/tests/xtro-sharpie/u2ignore/u2ignore.csproj"
dotnet format whitespace "$SRC_DIR/tests/xtro-sharpie/u2todo/u2todo.csproj"
dotnet format whitespace "$SRC_DIR/tests/xtro-sharpie/xtro-report/xtro-report.csproj"
dotnet format whitespace "$SRC_DIR/tests/xtro-sharpie/xtro-sanity/xtro-sanity.csproj"
dotnet format whitespace --folder "$SRC_DIR/tests/xtro-sharpie"
dotnet format whitespace --folder "$SRC_DIR/src/Accelerate"
dotnet format whitespace --folder "$SRC_DIR/src/Accessibility"