public override IEnumerable <StatementSyntax> Generate(TypePositionInfo info, StubCodeContext context)
        {
            switch (context.CurrentStage)
            {
            case StubCodeContext.Stage.Setup:
                if (TryGenerateSetupSyntax(info, context, out StatementSyntax conditionalAllocSetup))
                {
                    yield return(conditionalAllocSetup);
                }

                break;

            case StubCodeContext.Stage.Marshal:
                if (info.RefKind != RefKind.Out)
                {
                    if (TryGetConditionalBlockForStatements(
                            _windowsMarshaller.Generate(info, context),
                            _nonWindowsMarshaller.Generate(info, context),
                            out StatementSyntax marshal))
                    {
                        yield return(marshal);
                    }
                }
                break;

            case StubCodeContext.Stage.Pin:
                // [Compat] The built-in system could determine the platform at runtime and pin only on
                // the platform on which is is needed. In the generated source, if pinning is needed for
                // any platform, it is done on every platform.
                foreach (StatementSyntax s in _windowsMarshaller.Generate(info, context))
                {
                    yield return(s);
                }

                foreach (StatementSyntax s in _nonWindowsMarshaller.Generate(info, context))
                {
                    yield return(s);
                }

                break;

            case StubCodeContext.Stage.Unmarshal:
                if (info.IsManagedReturnPosition || (info.IsByRef && info.RefKind != RefKind.In))
                {
                    if (TryGetConditionalBlockForStatements(
                            _windowsMarshaller.Generate(info, context),
                            _nonWindowsMarshaller.Generate(info, context),
                            out StatementSyntax unmarshal))
                    {
                        yield return(unmarshal);
                    }
                }
                break;

            case StubCodeContext.Stage.Cleanup:
                yield return(GenerateConditionalAllocationFreeSyntax(info, context));

                break;
            }
        }
 public IEnumerable <StatementSyntax> Generate(TypePositionInfo info, StubCodeContext context)
 {
     if (IsPinningPathSupported(info, context))
     {
         return(GeneratePinningPath(info, context));
     }
     return(_manualMarshallingGenerator.Generate(info, context));
 }
Exemple #3
0
        public virtual IEnumerable <StatementSyntax> Generate(TypePositionInfo info, StubCodeContext context)
        {
            string argName = context.GetAdditionalIdentifier(info, "js_arg");

            if (context.CurrentStage == StubCodeContext.Stage.Setup)
            {
                if (!info.IsManagedReturnPosition)
                {
                    yield return(LocalDeclarationStatement(VariableDeclaration(RefType(IdentifierName(Constants.JSMarshalerArgumentGlobal)))
                                                           .WithVariables(SingletonSeparatedList(VariableDeclarator(Identifier(argName))
                                                                                                 .WithInitializer(EqualsValueClause(RefExpression(ElementAccessExpression(IdentifierName(Constants.ArgumentsBuffer))
                                                                                                                                                  .WithArgumentList(BracketedArgumentList(SingletonSeparatedList(
                                                                                                                                                                                              Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(info.ManagedIndex + 2)))))))))))));
                }
            }

            foreach (var x in _inner.Generate(info, context))
            {
                yield return(x);
            }
        }