Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung committed Oct 9, 2020
1 parent 9d04790 commit 2d5dc68
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
2 changes: 0 additions & 2 deletions DllImportGenerator/DllImportGenerator/DllImportStub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public IEnumerable<ParameterSyntax> StubParameters

public MethodDeclarationSyntax DllImportDeclaration { get; private set; }

public IEnumerable<Diagnostic> Diagnostics { get; private set; }

/// <summary>
/// Flags used to indicate members on GeneratedDllImport attribute.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ internal interface IMarshallingGenerator
/// <param name="info">Object to marshal</param>
/// <param name="context">Code generation context</param>
/// <returns>If the marshaller uses an identifier for the native value, true; otherwise, false.</returns>
/// <remarks>
/// <see cref="StubCodeContext.CurrentStage" /> of <paramref name="context"/> may not be valid.
/// </remarks>
bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context);
}

Expand Down
7 changes: 6 additions & 1 deletion DllImportGenerator/DllImportGenerator/StubCodeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ internal abstract class StubCodeContext
/// </summary>
public enum Stage
{
/// <summary>
/// Invalid stage
/// </summary>
Invalid,

/// <summary>
/// Perform any setup required
/// </summary>
Expand Down Expand Up @@ -55,7 +60,7 @@ public enum Stage
GuaranteedUnmarshal
}

public Stage CurrentStage { get; protected set; }
public Stage CurrentStage { get; protected set; } = Stage.Invalid;

public abstract bool PinningSupported { get; }

Expand Down
18 changes: 2 additions & 16 deletions DllImportGenerator/DllImportGenerator/StubCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public StubCodeGenerator(
{
Debug.Assert(retTypeInfo.IsNativeReturnPosition);

this.CurrentStage = Stages[0];
this.stubMethod = stubMethod;
this.diagnostics = generatorDiagnostics;

Expand All @@ -81,19 +80,6 @@ public StubCodeGenerator(
this.retMarshaller = (retTypeInfo, retGenerator);
}

/// <summary>
/// Generate an identifier for the native return value and update the context with the new value
/// </summary>
/// <returns>Identifier for the native return value</returns>
public void GenerateReturnNativeIdentifier()
{
if (CurrentStage != Stage.Setup)
throw new InvalidOperationException();

// Update the native identifier for the return value
ReturnNativeIdentifier = $"{ReturnIdentifier}{GeneratedNativeIdentifierSuffix}";
}

public override (string managed, string native) GetIdentifiers(TypePositionInfo info)
{
if (info.IsManagedReturnPosition && !info.IsNativeReturnPosition)
Expand All @@ -119,13 +105,13 @@ public override (string managed, string native) GetIdentifiers(TypePositionInfo

public (BlockSyntax Code, MethodDeclarationSyntax DllImport) GenerateSyntax()
{
this.CurrentStage = Stages[0];
string dllImportName = stubMethod.Name + "__PInvoke__";
var statements = new List<StatementSyntax>();

if (retMarshaller.Generator.UsesNativeIdentifier(retMarshaller.TypeInfo, this))
{
this.GenerateReturnNativeIdentifier();
// Update the native identifier for the return value
ReturnNativeIdentifier = $"{ReturnIdentifier}{GeneratedNativeIdentifierSuffix}";
}

foreach (var marshaller in paramMarshallers)
Expand Down

0 comments on commit 2d5dc68

Please sign in to comment.