[registrar] Make some API from the registrar public so that the managed static registrar step can access them.

There are no functional changes here, just refactoring to make code easier to re-use.
This commit is contained in:
Rolf Bjarne Kvinge 2023-01-25 16:23:12 +01:00
Родитель e39c6fb1b2
Коммит a1e0e305e5
3 изменённых файлов: 44 добавлений и 35 удалений

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

@ -219,12 +219,12 @@ namespace Registrar {
return assembly.GetTypes ();
}
protected override BindAsAttribute GetBindAsAttribute (PropertyInfo property)
public override BindAsAttribute GetBindAsAttribute (PropertyInfo property)
{
return property?.GetCustomAttribute<BindAsAttribute> (false);
}
protected override BindAsAttribute GetBindAsAttribute (MethodBase method, int parameter_index)
public override BindAsAttribute GetBindAsAttribute (MethodBase method, int parameter_index)
{
ICustomAttributeProvider provider;
@ -343,7 +343,7 @@ namespace Registrar {
return type.MakeByRefType ();
}
protected override CategoryAttribute GetCategoryAttribute (Type type)
public override CategoryAttribute GetCategoryAttribute (Type type)
{
return SharedDynamic.GetOneAttribute<CategoryAttribute> (type);
}
@ -374,7 +374,7 @@ namespace Registrar {
return ((MethodInfo) method).GetBaseDefinition ();
}
protected override Type GetElementType (Type type)
public override Type GetElementType (Type type)
{
return type.GetElementType ();
}
@ -460,7 +460,7 @@ namespace Registrar {
return type.FullName;
}
protected override bool VerifyIsConstrainedToNSObject (Type type, out Type constrained_type)
public override bool VerifyIsConstrainedToNSObject (Type type, out Type constrained_type)
{
constrained_type = null;
@ -523,7 +523,7 @@ namespace Registrar {
return type.AssemblyQualifiedName;
}
protected override bool HasReleaseAttribute (MethodBase method)
public override bool HasReleaseAttribute (MethodBase method)
{
var mi = method as MethodInfo;
if (mi is null)
@ -539,7 +539,7 @@ namespace Registrar {
return mi.IsDefined (typeof (System.Runtime.CompilerServices.ExtensionAttribute), false);
}
protected override bool HasThisAttribute (MethodBase method)
public override bool HasThisAttribute (MethodBase method)
{
return HasThisAttributeImpl (method);
}
@ -554,7 +554,7 @@ namespace Registrar {
return type.IsDefined (typeof (ModelAttribute), false);
}
protected override bool IsArray (Type type, out int rank)
public override bool IsArray (Type type, out int rank)
{
if (!type.IsArray) {
rank = 0;
@ -594,7 +594,7 @@ namespace Registrar {
return type.IsSubclassOf (typeof (System.Delegate));
}
protected override bool IsNullable (Type type)
public override bool IsNullable (Type type)
{
if (!type.IsGenericType)
return false;

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

@ -1094,9 +1094,9 @@ namespace Registrar {
protected abstract bool IsStatic (TField field);
protected abstract bool IsStatic (TMethod method);
protected abstract TType MakeByRef (TType type);
protected abstract bool HasThisAttribute (TMethod method);
public abstract bool HasThisAttribute (TMethod method);
protected abstract bool IsConstructor (TMethod method);
protected abstract TType GetElementType (TType type);
public abstract TType GetElementType (TType type);
protected abstract TType GetReturnType (TMethod method);
protected abstract void GetNamespaceAndName (TType type, out string @namespace, out string name);
protected abstract bool TryGetAttribute (TType type, string attributeNamespace, string attributeType, out object attribute);
@ -1104,23 +1104,23 @@ namespace Registrar {
protected abstract ExportAttribute GetExportAttribute (TMethod method); // Return null if no attribute is found. Must check the base method (i.e. if method is overriding a method in a base class, must check the overridden method for the attribute).
protected abstract Dictionary<TMethod, List<TMethod>> PrepareMethodMapping (TType type);
public abstract RegisterAttribute GetRegisterAttribute (TType type); // Return null if no attribute is found. Do not consider base types.
protected abstract CategoryAttribute GetCategoryAttribute (TType type); // Return null if no attribute is found. Do not consider base types.
public abstract CategoryAttribute GetCategoryAttribute (TType type); // Return null if no attribute is found. Do not consider base types.
protected abstract ConnectAttribute GetConnectAttribute (TProperty property); // Return null if no attribute is found. Do not consider inherited properties.
public abstract ProtocolAttribute GetProtocolAttribute (TType type); // Return null if no attribute is found. Do not consider base types.
protected abstract IEnumerable<ProtocolMemberAttribute> GetProtocolMemberAttributes (TType type); // Return null if no attributes found. Do not consider base types.
protected virtual Version GetSdkIntroducedVersion (TType obj, out string message) { message = null; return null; } // returns the sdk version when the type was introduced for the current platform (null if all supported versions)
protected abstract Version GetSDKVersion ();
protected abstract TType GetProtocolAttributeWrapperType (TType type); // Return null if no attribute is found. Do not consider base types.
protected abstract BindAsAttribute GetBindAsAttribute (TMethod method, int parameter_index); // If parameter_index = -1 then get the attribute for the return type. Return null if no attribute is found. Must consider base method.
protected abstract BindAsAttribute GetBindAsAttribute (TProperty property);
public abstract BindAsAttribute GetBindAsAttribute (TMethod method, int parameter_index); // If parameter_index = -1 then get the attribute for the return type. Return null if no attribute is found. Must consider base method.
public abstract BindAsAttribute GetBindAsAttribute (TProperty property);
protected abstract IList<AdoptsAttribute> GetAdoptsAttributes (TType type);
public abstract TType GetNullableType (TType type); // For T? returns T. For T returns null.
protected abstract bool HasReleaseAttribute (TMethod method); // Returns true of the method's return type/value has a [Release] attribute.
public abstract bool HasReleaseAttribute (TMethod method); // Returns true of the method's return type/value has a [Release] attribute.
protected abstract bool IsINativeObject (TType type);
protected abstract bool IsValueType (TType type);
protected abstract bool IsArray (TType type, out int rank);
public abstract bool IsArray (TType type, out int rank);
protected abstract bool IsEnum (TType type, out bool isNativeEnum);
protected abstract bool IsNullable (TType type);
public abstract bool IsNullable (TType type);
protected abstract bool IsDelegate (TType type);
protected abstract bool IsGenericType (TType type);
protected abstract bool IsGenericMethod (TMethod method);
@ -1128,7 +1128,7 @@ namespace Registrar {
protected abstract bool IsAbstract (TType type);
protected abstract bool IsPointer (TType type);
protected abstract TType GetGenericTypeDefinition (TType type);
protected abstract bool VerifyIsConstrainedToNSObject (TType type, out TType constrained_type);
public abstract bool VerifyIsConstrainedToNSObject (TType type, out TType constrained_type);
protected abstract TType GetEnumUnderlyingType (TType type);
protected abstract IEnumerable<TField> GetFields (TType type); // Must return all instance fields. May return static fields (they are filtered out automatically).
protected abstract TType GetFieldType (TField field);
@ -1160,7 +1160,7 @@ namespace Registrar {
{
}
protected bool IsArray (TType type)
public bool IsArray (TType type)
{
int rank;
return IsArray (type, out rank);

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

@ -767,13 +767,13 @@ namespace Registrar {
return GetValueTypeSize (type.Resolve (), Is64Bits);
}
protected override bool HasReleaseAttribute (MethodDefinition method)
public override bool HasReleaseAttribute (MethodDefinition method)
{
method = GetBaseMethodInTypeHierarchy (method);
return HasAttribute (method.MethodReturnType, ObjCRuntime, StringConstants.ReleaseAttribute);
}
protected override bool HasThisAttribute (MethodDefinition method)
public override bool HasThisAttribute (MethodDefinition method)
{
return HasAttribute (method, "System.Runtime.CompilerServices", "ExtensionAttribute");
}
@ -966,7 +966,7 @@ namespace Registrar {
return false;
}
protected override TypeReference GetElementType (TypeReference type)
public override TypeReference GetElementType (TypeReference type)
{
var ts = type as TypeSpecification;
if (ts is not null) {
@ -1065,7 +1065,7 @@ namespace Registrar {
return HasAttribute (td, ObjCRuntime, StringConstants.NativeAttribute);
}
protected override bool IsNullable (TypeReference type)
public override bool IsNullable (TypeReference type)
{
return GetNullableType (type) is not null;
}
@ -1081,7 +1081,7 @@ namespace Registrar {
return type.IsEnum;
}
protected override bool IsArray (TypeReference type, out int rank)
public override bool IsArray (TypeReference type, out int rank)
{
var arrayType = type as ArrayType;
if (arrayType is null) {
@ -1166,7 +1166,7 @@ namespace Registrar {
return TypeMatch (a, b);
}
protected override bool VerifyIsConstrainedToNSObject (TypeReference type, out TypeReference constrained_type)
public override bool VerifyIsConstrainedToNSObject (TypeReference type, out TypeReference constrained_type)
{
constrained_type = null;
@ -1349,7 +1349,7 @@ namespace Registrar {
return rv;
}
protected override CategoryAttribute GetCategoryAttribute (TypeReference type)
public override CategoryAttribute GetCategoryAttribute (TypeReference type)
{
string name = null;
@ -1912,7 +1912,7 @@ namespace Registrar {
}
}
protected override BindAsAttribute GetBindAsAttribute (PropertyDefinition property)
public override BindAsAttribute GetBindAsAttribute (PropertyDefinition property)
{
if (property is null)
return null;
@ -1925,7 +1925,7 @@ namespace Registrar {
return CreateBindAsAttribute (attrib, property);
}
protected override BindAsAttribute GetBindAsAttribute (MethodDefinition method, int parameter_index)
public override BindAsAttribute GetBindAsAttribute (MethodDefinition method, int parameter_index)
{
if (method is null)
return null;
@ -2809,7 +2809,7 @@ namespace Registrar {
public ObjCType Protocol;
}
class SkippedType {
public class SkippedType {
public TypeReference Skipped;
public ObjCType Actual;
public uint SkippedTokenReference;
@ -2822,6 +2822,10 @@ namespace Registrar {
skipped_types.Add (new SkippedType { Skipped = type, Actual = registered_type });
}
public List<SkippedType> SkippedTypes {
get => skipped_types;
}
public string GetInitializationMethodName (string single_assembly)
{
if (!string.IsNullOrEmpty (single_assembly)) {
@ -4424,7 +4428,7 @@ namespace Registrar {
return nativeObjType;
}
TypeDefinition GetDelegateProxyType (ObjCMethod obj_method)
public TypeDefinition GetDelegateProxyType (ObjCMethod obj_method)
{
// A mirror of this method is also implemented in BlockLiteral:GetDelegateProxyType
// If this method is changed, that method will probably have to be updated too (tests!!!)
@ -4471,7 +4475,12 @@ namespace Registrar {
return null;
}
MethodDefinition GetBlockWrapperCreator (ObjCMethod obj_method, int parameter)
//
// Returns a MethodInfo that represents the method that can be used to turn
// a the block in the given method at the given parameter into a strongly typed
// delegate
//
public MethodDefinition GetBlockWrapperCreator (ObjCMethod obj_method, int parameter)
{
// A mirror of this method is also implemented in Runtime:GetBlockWrapperCreator
// If this method is changed, that method will probably have to be updated too (tests!!!)
@ -4652,7 +4661,7 @@ namespace Registrar {
return false;
}
string GetManagedToNSNumberFunc (TypeReference managedType, TypeReference inputType, TypeReference outputType, string descriptiveMethodName)
public string GetManagedToNSNumberFunc (TypeReference managedType, TypeReference inputType, TypeReference outputType, string descriptiveMethodName)
{
var typeName = managedType.FullName;
switch (typeName) {
@ -4680,7 +4689,7 @@ namespace Registrar {
}
}
string GetNSNumberToManagedFunc (TypeReference managedType, TypeReference inputType, TypeReference outputType, string descriptiveMethodName, out string nativeType)
public string GetNSNumberToManagedFunc (TypeReference managedType, TypeReference inputType, TypeReference outputType, string descriptiveMethodName, out string nativeType)
{
var typeName = managedType.FullName;
switch (typeName) {
@ -4710,7 +4719,7 @@ namespace Registrar {
}
}
string GetNSValueToManagedFunc (TypeReference managedType, TypeReference inputType, TypeReference outputType, string descriptiveMethodName, out string nativeType)
public string GetNSValueToManagedFunc (TypeReference managedType, TypeReference inputType, TypeReference outputType, string descriptiveMethodName, out string nativeType)
{
var underlyingTypeName = managedType.FullName;
@ -4739,7 +4748,7 @@ namespace Registrar {
}
}
string GetManagedToNSValueFunc (TypeReference managedType, TypeReference inputType, TypeReference outputType, string descriptiveMethodName)
public string GetManagedToNSValueFunc (TypeReference managedType, TypeReference inputType, TypeReference outputType, string descriptiveMethodName)
{
var underlyingTypeName = managedType.FullName;