コード例 #1
0
        public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context)
        {
            Debug.Assert(context != null);
            if (info.IsByRef || info.ByValueContentsMarshalKind != ByValueContentsMarshalKind.Default)
            {
                // out of scope for Net7.0
                throw new MarshallingNotSupportedException(info, context)
                      {
                          NotSupportedDetails = SR.InOutRefNotSupported
                      };
            }
            JSMarshallingInfo jsMarshalingInfo = info.MarshallingAttributeInfo as JSMarshallingInfo;

            Exception fail(string failReason)
            {
                return(new MarshallingNotSupportedException(info, context)
                {
                    NotSupportedDetails = failReason
                });
            }

            bool isToJs = info.ManagedIndex != TypePositionInfo.ReturnIndex ^ context is JSExportCodeContext;

            switch (info)
            {
            // invalid
            case { ManagedType: JSInvalidTypeInfo } :
 /// <summary>
 /// Create a <see cref="StubCodeContext"/> for marshalling elements of an collection.
 /// </summary>
 /// <param name="currentStage">The current marshalling stage.</param>
 /// <param name="indexerIdentifier">The indexer in the loop to get the element to marshal from the collection.</param>
 /// <param name="nativeSpanIdentifier">The identifier of the native value storage cast to the target element type.</param>
 /// <param name="parentContext">The parent context.</param>
 public ContiguousCollectionElementMarshallingCodeContext(
     Stage currentStage,
     string nativeSpanIdentifier,
     StubCodeContext parentContext)
 {
     CurrentStage          = currentStage;
     IndexerIdentifier     = CalculateIndexerIdentifierBasedOnParentContext(parentContext);
     _nativeSpanIdentifier = nativeSpanIdentifier;
     ParentContext         = parentContext;
 }
コード例 #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);
            }
        }
コード例 #4
0
ファイル: SpanJSGenerator.cs プロジェクト: mikem8361/runtime
 public override IEnumerable <ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context)
 {
     yield return(InvocationExpression(MarshalerTypeName(Type),
                                       ArgumentList(SingletonSeparatedList(Argument(MarshalerTypeName(_elementMarshalerType))))));
 }
コード例 #5
0
 public virtual IEnumerable <ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context)
 {
     yield return(MarshalerTypeName(Type));
 }
コード例 #6
0
 public bool SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) => _inner.SupportsByValueMarshalKind(marshalKind, context);
コード例 #7
0
 public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, StubCodeContext context) => _inner.GetValueBoundaryBehavior(info, context);
コード例 #8
0
 public IEnumerable <ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context) => Array.Empty <ExpressionSyntax>();
コード例 #9
0
ファイル: FuncJSGenerator.cs プロジェクト: mikem8361/runtime
        public override IEnumerable <ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context)
        {
            var args = _argumentMarshalerTypes.Select(x => Argument(MarshalerTypeName(x))).ToList();

            yield return(InvocationExpression(MarshalerTypeName(Type), ArgumentList(SeparatedList(args))));
        }
コード例 #10
0
ファイル: FuncJSGenerator.cs プロジェクト: mikem8361/runtime
        public override IEnumerable <StatementSyntax> Generate(TypePositionInfo info, StubCodeContext context)
        {
            var maxArgs = _isAction ? 3 : 4;

            if (_argumentMarshalerTypes.Length > maxArgs)
            {
                throw new MarshallingNotSupportedException(info, context)
                      {
                          NotSupportedDetails = SR.FuncTooManyArgs
                      };
            }

            string argName = context.GetAdditionalIdentifier(info, "js_arg");
            var    target  = info.IsManagedReturnPosition
                ? Constants.ArgumentReturn
                : argName;

            var source = info.IsManagedReturnPosition
                ? Argument(IdentifierName(context.GetIdentifiers(info).native))
                : _inner.AsArgument(info, context);

            var jsty        = (JSFunctionTypeInfo)info.ManagedType;
            var sourceTypes = jsty.ArgsTypeInfo
                              .Select(a => ParseTypeName(a.FullTypeName))
                              .ToArray();

            if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.In && info.IsManagedReturnPosition)
            {
                yield return(ToManagedMethod(target, source, jsty));
            }

            if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == CustomTypeMarshallingDirection.Out && info.IsManagedReturnPosition)
            {
                yield return(ToJSMethod(target, source, jsty));
            }

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

            if (context.CurrentStage == StubCodeContext.Stage.Invoke && context.Direction == CustomTypeMarshallingDirection.In && !info.IsManagedReturnPosition)
            {
                yield return(ToJSMethod(target, source, jsty));
            }

            if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.Out && !info.IsManagedReturnPosition)
            {
                yield return(ToManagedMethod(target, source, jsty));
            }
        }
コード例 #11
0
 public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => false;
コード例 #12
0
 public bool SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) => false;
コード例 #13
0
 public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, StubCodeContext context) => ValueBoundaryBehavior.ManagedIdentifier;
コード例 #14
0
ファイル: TaskJSGenerator.cs プロジェクト: mikem8361/runtime
        public override IEnumerable <ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context)
        {
            var jsty = (JSTaskTypeInfo)info.ManagedType;

            if (jsty.ResultTypeInfo.FullTypeName == "void")
            {
                yield return(InvocationExpression(MarshalerTypeName(MarshalerType.Task), ArgumentList()));
            }
            else
            {
                yield return(InvocationExpression(MarshalerTypeName(MarshalerType.Task),
                                                  ArgumentList(SingletonSeparatedList(Argument(MarshalerTypeName(_resultMarshalerType))))));
            }
        }
コード例 #15
0
 public virtual bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => _inner.UsesNativeIdentifier(info, context);
コード例 #16
0
ファイル: TaskJSGenerator.cs プロジェクト: mikem8361/runtime
        public override IEnumerable <StatementSyntax> Generate(TypePositionInfo info, StubCodeContext context)
        {
            var jsty = (JSTaskTypeInfo)info.ManagedType;

            string argName = context.GetAdditionalIdentifier(info, "js_arg");
            var    target  = info.IsManagedReturnPosition
                ? Constants.ArgumentReturn
                : argName;

            var source = info.IsManagedReturnPosition
                ? Argument(IdentifierName(context.GetIdentifiers(info).native))
                : _inner.AsArgument(info, context);

            if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.In && info.IsManagedReturnPosition)
            {
                yield return(jsty.ResultTypeInfo.FullTypeName == "void"
                    ? ToManagedMethodVoid(target, source)
                    : ToManagedMethod(target, source, jsty.ResultTypeInfo.Syntax));
            }

            if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == CustomTypeMarshallingDirection.Out && info.IsManagedReturnPosition)
            {
                yield return(jsty.ResultTypeInfo.FullTypeName == "void"
                    ? ToJSMethodVoid(target, source)
                    : ToJSMethod(target, source, jsty.ResultTypeInfo.Syntax));
            }

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

            if (context.CurrentStage == StubCodeContext.Stage.Invoke && context.Direction == CustomTypeMarshallingDirection.In && !info.IsManagedReturnPosition)
            {
                yield return(jsty.ResultTypeInfo.FullTypeName == "void"
                    ? ToJSMethodVoid(target, source)
                    : ToJSMethod(target, source, jsty.ResultTypeInfo.Syntax));
            }

            if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.Out && !info.IsManagedReturnPosition)
            {
                yield return(jsty.ResultTypeInfo.FullTypeName == "void"
                    ? ToManagedMethodVoid(target, source)
                    : ToManagedMethod(target, source, jsty.ResultTypeInfo.Syntax));
            }
        }
コード例 #17
0
 public IEnumerable <StatementSyntax> Generate(TypePositionInfo info, StubCodeContext context) => Array.Empty <StatementSyntax>();