[Generator] Refactor marshal info and enable nullability. (#17413)
This commit is contained in:
Родитель
47a387f670
Коммит
98faaf35b6
|
@ -31,7 +31,11 @@
|
|||
<Compile Include="$(RepositoryPath)\src\generator-attributes.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\generator-attribute-manager.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\generator-enums.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\generator-extension-methods.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\generator-filters.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\generator-marshal-info.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\generator-namespace-manager.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\generator-nullability-info-context.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\generator-typemanager.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\ObjCRuntime\Stret.cs" />
|
||||
<Compile Include="$(RepositoryPath)\tools\common\ApplePlatform.cs" />
|
||||
|
@ -60,15 +64,6 @@
|
|||
<Compile Include="$(RepositoryPath)\tools\common\Execution.cs">
|
||||
<Link>Execution.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\generator-namespace-manager.cs">
|
||||
<Link>src\generator-namespace-manager.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\generator-extension-methods.cs">
|
||||
<Link>src\generator-extension-methods.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\generator-nullability-info-context.cs">
|
||||
<Link>src\generator-nullability-info-context.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Resources.Designer.cs">
|
||||
<DependentUpon>..\Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
#nullable enable
|
||||
|
||||
//
|
||||
// Used to encapsulate flags about types in either the parameter or the return value
|
||||
// For now, it only supports the [PlainString] attribute on strings.
|
||||
//
|
||||
public class MarshalInfo {
|
||||
public Generator Generator { get; }
|
||||
public bool PlainString { get; }
|
||||
public Type Type { get; }
|
||||
public bool IsOut { get; }
|
||||
|
||||
// This is set on a string parameter if the argument parameters are set to
|
||||
// Copy. This means that we can do fast string passing.
|
||||
public bool ZeroCopyStringMarshal { get; set; }
|
||||
|
||||
public bool IsAligned;
|
||||
|
||||
// Used for parameters
|
||||
public MarshalInfo (Generator generator, MethodInfo mi, ParameterInfo pi)
|
||||
{
|
||||
this.Generator = generator;
|
||||
PlainString = Generator.AttributeManager.HasAttribute<PlainStringAttribute> (pi);
|
||||
Type = pi.ParameterType;
|
||||
ZeroCopyStringMarshal = (Type == Generator.TypeManager.System_String) && PlainString == false && !Generator.AttributeManager.HasAttribute<DisableZeroCopyAttribute> (pi) && generator.type_wants_zero_copy;
|
||||
if (ZeroCopyStringMarshal && Generator.AttributeManager.HasAttribute<DisableZeroCopyAttribute> (mi))
|
||||
ZeroCopyStringMarshal = false;
|
||||
IsOut = TypeManager.IsOutParameter (pi);
|
||||
}
|
||||
|
||||
// Used to return values
|
||||
public MarshalInfo (Generator generator, MethodInfo mi)
|
||||
{
|
||||
this.Generator = generator;
|
||||
PlainString = Generator.AttributeManager.HasAttribute<PlainStringAttribute> (AttributeManager.GetReturnTypeCustomAttributes (mi));
|
||||
Type = mi.ReturnType;
|
||||
}
|
||||
}
|
|
@ -54,43 +54,6 @@ using ObjCRuntime;
|
|||
using Foundation;
|
||||
using Xamarin.Utils;
|
||||
|
||||
//
|
||||
// Used to encapsulate flags about types in either the parameter or the return value
|
||||
// For now, it only supports the [PlainString] attribute on strings.
|
||||
//
|
||||
public class MarshalInfo {
|
||||
public Generator Generator;
|
||||
public bool PlainString;
|
||||
public Type Type;
|
||||
public bool IsOut;
|
||||
|
||||
// This is set on a string parameter if the argument parameters are set to
|
||||
// Copy. This means that we can do fast string passing.
|
||||
public bool ZeroCopyStringMarshal;
|
||||
|
||||
public bool IsAligned;
|
||||
|
||||
// Used for parameters
|
||||
public MarshalInfo (Generator generator, MethodInfo mi, ParameterInfo pi)
|
||||
{
|
||||
this.Generator = generator;
|
||||
PlainString = Generator.AttributeManager.HasAttribute<PlainStringAttribute> (pi);
|
||||
Type = pi.ParameterType;
|
||||
ZeroCopyStringMarshal = (Type == Generator.TypeManager.System_String) && PlainString == false && !Generator.AttributeManager.HasAttribute<DisableZeroCopyAttribute> (pi) && generator.type_wants_zero_copy;
|
||||
if (ZeroCopyStringMarshal && Generator.AttributeManager.HasAttribute<DisableZeroCopyAttribute> (mi))
|
||||
ZeroCopyStringMarshal = false;
|
||||
IsOut = TypeManager.IsOutParameter (pi);
|
||||
}
|
||||
|
||||
// Used to return values
|
||||
public MarshalInfo (Generator generator, MethodInfo mi)
|
||||
{
|
||||
this.Generator = generator;
|
||||
PlainString = Generator.AttributeManager.HasAttribute<PlainStringAttribute> (AttributeManager.GetReturnTypeCustomAttributes (mi));
|
||||
Type = mi.ReturnType;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Encapsulates the information necessary to create a block delegate
|
||||
//
|
||||
|
|
|
@ -98,7 +98,11 @@
|
|||
<Compile Include="..\src\generator-attributes.cs" />
|
||||
<Compile Include="..\src\generator-attribute-manager.cs" />
|
||||
<Compile Include="..\src\generator-enums.cs" />
|
||||
<Compile Include="..\src\generator-extension-methods.cs" />
|
||||
<Compile Include="..\src\generator-filters.cs" />
|
||||
<Compile Include="..\src\generator-marshal-info.cs" />
|
||||
<Compile Include="..\src\generator-namespace-manager.cs" />
|
||||
<Compile Include="..\src\generator-nullability-info-context.cs" />
|
||||
<Compile Include="..\src\generator-typemanager.cs" />
|
||||
<Compile Include="..\src\ObjCRuntime\Stret.cs" />
|
||||
<Compile Include="..\tools\common\ApplePlatform.cs" />
|
||||
|
@ -128,9 +132,6 @@
|
|||
<Compile Include="..\tools\common\Execution.cs">
|
||||
<Link>Execution.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="generator-namespace-manager.cs" />
|
||||
<Compile Include="generator-extension-methods.cs" />
|
||||
<Compile Include="generator-nullability-info-context.cs" />
|
||||
<Compile Include="Resources.Designer.cs">
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
|
|
Загрузка…
Ссылка в новой задаче