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; }
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); } }
public override IEnumerable <ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context) { yield return(InvocationExpression(MarshalerTypeName(Type), ArgumentList(SingletonSeparatedList(Argument(MarshalerTypeName(_elementMarshalerType)))))); }
public virtual IEnumerable <ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context) { yield return(MarshalerTypeName(Type)); }
public bool SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) => _inner.SupportsByValueMarshalKind(marshalKind, context);
public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, StubCodeContext context) => _inner.GetValueBoundaryBehavior(info, context);
public IEnumerable <ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context) => Array.Empty <ExpressionSyntax>();
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)))); }
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)); } }
public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => false;
public bool SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) => false;
public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, StubCodeContext context) => ValueBoundaryBehavior.ManagedIdentifier;
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)))))); } }
public virtual bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => _inner.UsesNativeIdentifier(info, context);
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)); } }
public IEnumerable <StatementSyntax> Generate(TypePositionInfo info, StubCodeContext context) => Array.Empty <StatementSyntax>();