Esempio n. 1
0
        public static Method?Create(Context cx, IMethodSymbol?methodDecl)
        {
            if (methodDecl is null)
            {
                return(null);
            }

            var methodKind = methodDecl.MethodKind;

            if (methodKind == MethodKind.ExplicitInterfaceImplementation)
            {
                // Retrieve the original method kind
                methodKind = methodDecl.ExplicitInterfaceImplementations.Select(m => m.MethodKind).FirstOrDefault();
            }

            switch (methodKind)
            {
            case MethodKind.StaticConstructor:
            case MethodKind.Constructor:
                return(Constructor.Create(cx, methodDecl));

            case MethodKind.ReducedExtension:
                if (SymbolEqualityComparer.Default.Equals(methodDecl, methodDecl.ConstructedFrom))
                {
                    return(OrdinaryMethod.Create(cx, methodDecl.ReducedFrom !));
                }
                return(OrdinaryMethod.Create(cx, methodDecl.ReducedFrom !.Construct(methodDecl.TypeArguments, methodDecl.TypeArgumentNullableAnnotations)));

            case MethodKind.Ordinary:
            case MethodKind.DelegateInvoke:
                return(OrdinaryMethod.Create(cx, methodDecl));

            case MethodKind.Destructor:
                return(Destructor.Create(cx, methodDecl));

            case MethodKind.PropertyGet:
            case MethodKind.PropertySet:
                return(Accessor.GetPropertySymbol(methodDecl) is null?OrdinaryMethod.Create(cx, methodDecl) : (Method)Accessor.Create(cx, methodDecl));

            case MethodKind.EventAdd:
            case MethodKind.EventRemove:
                return(EventAccessor.Create(cx, methodDecl));

            case MethodKind.UserDefinedOperator:
            case MethodKind.BuiltinOperator:
                return(UserOperator.Create(cx, methodDecl));

            case MethodKind.Conversion:
                return(Conversion.Create(cx, methodDecl));

            case MethodKind.AnonymousFunction:
                throw new InternalError(methodDecl, "Attempt to create a lambda");

            case MethodKind.LocalFunction:
                return(LocalFunction.Create(cx, methodDecl));

            default:
                throw new InternalError(methodDecl, $"Unhandled method '{methodDecl}' of kind '{methodDecl.MethodKind}'");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a method of the appropriate subtype.
        /// </summary>
        /// <param name="cx"></param>
        /// <param name="methodDecl"></param>
        /// <returns></returns>
        public static Method Create(Context cx, IMethodSymbol methodDecl)
        {
            if (methodDecl == null)
            {
                return(null);
            }

            var methodKind = methodDecl.MethodKind;

            if (methodKind == MethodKind.ExplicitInterfaceImplementation)
            {
                // Retrieve the original method kind
                methodKind = methodDecl.ExplicitInterfaceImplementations.Select(m => m.MethodKind).FirstOrDefault();
            }

            switch (methodKind)
            {
            case MethodKind.StaticConstructor:
            case MethodKind.Constructor:
                return(Constructor.Create(cx, methodDecl));

            case MethodKind.ReducedExtension:
            case MethodKind.Ordinary:
            case MethodKind.DelegateInvoke:
                return(OrdinaryMethod.Create(cx, methodDecl));

            case MethodKind.Destructor:
                return(Destructor.Create(cx, methodDecl));

            case MethodKind.PropertyGet:
            case MethodKind.PropertySet:
                return(methodDecl.AssociatedSymbol is null?OrdinaryMethod.Create(cx, methodDecl) : (Method)Accessor.Create(cx, methodDecl));

            case MethodKind.EventAdd:
            case MethodKind.EventRemove:
                return(EventAccessor.Create(cx, methodDecl));

            case MethodKind.UserDefinedOperator:
            case MethodKind.BuiltinOperator:
                return(UserOperator.Create(cx, methodDecl));

            case MethodKind.Conversion:
                return(Conversion.Create(cx, methodDecl));

            case MethodKind.AnonymousFunction:
                throw new InternalError(methodDecl, "Attempt to create a lambda");

            case MethodKind.LocalFunction:
                return(LocalFunction.Create(cx, methodDecl));

            default:
                throw new InternalError(methodDecl, "Unhandled method '{0}' of kind '{1}'", methodDecl, methodDecl.MethodKind);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// If the expression calls an operator, add an expr_call()
        /// to show the target of the call. Also note the dynamic method
        /// name if available.
        /// </summary>
        /// <param name="cx">Context</param>
        /// <param name="node">The expression.</param>
        public void OperatorCall(TextWriter trapFile, ExpressionSyntax node)
        {
            var @operator = cx.GetSymbolInfo(node);

            if (@operator.Symbol is IMethodSymbol method)
            {
                var callType = GetCallType(cx, node);
                if (callType == CallType.Dynamic)
                {
                    UserOperator.OperatorSymbol(method.Name, out var operatorName);
                    trapFile.dynamic_member_name(this, operatorName);
                    return;
                }

                trapFile.expr_call(this, Method.Create(cx, method));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// If the expression calls an operator, add an expr_call()
        /// to show the target of the call. Also note the dynamic method
        /// name if available.
        /// </summary>
        /// <param name="cx">Context</param>
        /// <param name="node">The expression.</param>
        public void OperatorCall(ExpressionSyntax node)
        {
            var @operator = cx.GetSymbolInfo(node);

            if (@operator.Symbol is IMethodSymbol method)
            {
                var callType = GetCallType(cx, node);
                if (callType == CallType.Dynamic)
                {
                    UserOperator.OperatorSymbol(method.Name, out string operatorName);
                    cx.Emit(Tuples.dynamic_member_name(this, operatorName));
                    return;
                }

                cx.Emit(Tuples.expr_call(this, Method.Create(cx, method)));
            }
        }