示例#1
0
文件: Call.cs 项目: GabberBaby/cs2cpp
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.Method.IsStaticMethod())
            {
                c.WriteTypeFullName(this.Method.ContainingType);
                c.TextSpan("::");
                c.WriteMethodName(this.Method, addTemplate: true);
            }
            else
            {
                var receiverOpt = this.ReceiverOpt;
                if (receiverOpt != null)
                {
                    receiverOpt = this.PrepareMethodReceiver(receiverOpt, this.Method);
                    // if method name is empty then receiverOpt returns function pointer
                    if (!string.IsNullOrWhiteSpace(this.Method.Name))
                    {
                        c.WriteAccess(receiverOpt);
                    }
                    else
                    {
                        c.WriteExpressionInParenthesesIfNeeded(receiverOpt);
                    }
                }

                c.WriteMethodName(this.Method, addTemplate: true /*, methodSymbolForName: explicitMethod*/);
            }

            WriteCallArguments(this._arguments, this.Method != null ? this.Method.Parameters : (IEnumerable <IParameterSymbol>)null, c);
        }
示例#2
0
文件: Call.cs 项目: xydoublez/cs2cpp
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (!this.Method.ReturnsVoid && (this.Method.IsVirtualGenericMethod() || this.CallGenericMethodFromInterfaceMethod))
            {
                c.TextSpan("((");
                c.WriteType(this.Method.ReturnType, callGenericMethodFromInterfaceMethod: this.CallGenericMethodFromInterfaceMethod, containingNamespace: MethodOwner?.ContainingNamespace);
                c.TextSpan(")");
            }

            if (this.Method.IsStatic)
            {
                if (!this.Method.IsExternDeclaration())
                {
                    c.WriteTypeFullName(this.Method.ContainingType, containingNamespace: MethodOwner?.ContainingNamespace);
                    c.TextSpan("::");
                }
                else
                {
                    c.WriteNamespace(this.Method.ContainingType, containingNamespace: MethodOwner?.ContainingNamespace);
                }

                c.WriteMethodName(this.Method, addTemplate: true, containingNamespace: MethodOwner?.ContainingNamespace);
            }
            else
            {
                IMethodSymbol receiverIsNotInterfacesButAccessingExplicitInterfaceMethod = null;
                var           receiverOpt = this.ReceiverOpt;
                if (receiverOpt != null)
                {
                    receiverOpt = this.PrepareMethodReceiver(receiverOpt, this.Method);
                    // if method name is empty then receiverOpt returns function pointer
                    if (!string.IsNullOrWhiteSpace(this.Method.Name))
                    {
                        c.WriteAccess(receiverOpt);
                    }
                    else
                    {
                        c.WriteWrappedExpressionIfNeeded(receiverOpt);
                    }

                    if (receiverOpt.Type.TypeKind != TypeKind.Interface && this.Method.ReceiverType != null && this.Method.ReceiverType.TypeKind == TypeKind.Interface)
                    {
                        receiverIsNotInterfacesButAccessingExplicitInterfaceMethod = receiverOpt.Type.GetMembers().OfType <IMethodSymbol>().FirstOrDefault(m => m.ExplicitInterfaceImplementations.Any() && m.ExplicitInterfaceImplementations.First().CompareTo(this.Method) == 0);
                    }
                }

                c.WriteMethodName(receiverIsNotInterfacesButAccessingExplicitInterfaceMethod ?? this.Method, addTemplate: true, callGenericMethodFromInterfaceMethod: this.CallGenericMethodFromInterfaceMethod, containingNamespace: MethodOwner?.ContainingNamespace);
            }

            WriteCallArguments(c, this.Method != null ? this.Method.Parameters : (IEnumerable <IParameterSymbol>)null, this._arguments, this.Method, methodOwner: MethodOwner, specialCaseInterfaceWrapperCall: this.SpecialCaseInterfaceWrapperCall, specialCaseCreateInstanceNewObjectReplacement: this.SpecialCaseCreateInstanceNewObjectReplacement);

            if (!this.Method.ReturnsVoid && (this.Method.IsVirtualGenericMethod() || this.CallGenericMethodFromInterfaceMethod))
            {
                c.TextSpan(")");
            }
        }
示例#3
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (!this.Method.ReturnsVoid && this.Method.IsVirtualGenericMethod())
            {
                c.TextSpan("((");
                c.WriteType(this.Method.ReturnType, containingNamespace: MethodOwner?.ContainingNamespace);
                c.TextSpan(")");
            }

            if (this.Method.IsStaticMethod())
            {
                if (!this.Method.IsExternDeclaration())
                {
                    c.WriteTypeFullName(this.Method.ContainingType, containingNamespace: MethodOwner?.ContainingNamespace);
                    c.TextSpan("::");
                }
                else
                {
                    c.WriteNamespace(this.Method.ContainingType, containingNamespace: MethodOwner?.ContainingNamespace);
                    c.TextSpan("::");
                }

                c.WriteMethodName(this.Method, addTemplate: true, containingNamespace: MethodOwner?.ContainingNamespace);
            }
            else
            {
                var receiverOpt = this.ReceiverOpt;
                if (receiverOpt != null)
                {
                    receiverOpt = this.PrepareMethodReceiver(receiverOpt, this.Method);
                    // if method name is empty then receiverOpt returns function pointer
                    if (!string.IsNullOrWhiteSpace(this.Method.Name))
                    {
                        c.WriteAccess(receiverOpt);
                    }
                    else
                    {
                        c.WriteWrappedExpressionIfNeeded(receiverOpt);
                    }
                }

                c.WriteMethodName(this.Method, addTemplate: true /*, methodSymbolForName: explicitMethod*/, interfaceWrapperMethodSpecialCase: InterfaceWrapperSpecialCall, containingNamespace: MethodOwner?.ContainingNamespace);
            }

            WriteCallArguments(c, this.Method != null ? this.Method.Parameters : (IEnumerable <IParameterSymbol>)null, this._arguments, this.Method, methodOwner: MethodOwner);

            if (!this.Method.ReturnsVoid && this.Method.IsVirtualGenericMethod())
            {
                c.TextSpan(")");
            }
        }
示例#4
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.Field.IsStatic)
            {
                if (this.Field.ContainingType == null && this.Field.ContainingSymbol is ITypeSymbol)
                {
                    c.WriteTypeFullName((ITypeSymbol)this.Field.ContainingSymbol);
                }
                else
                {
                    c.WriteTypeFullName(this.Field.ContainingType);
                }

                c.TextSpan("::");
                c.WriteName(this.Field);
            }
            else
            {
                if (this.PointerAccess)
                {
                    var pointerIndirect = this.ReceiverOpt as PointerIndirectionOperator;
                    if (pointerIndirect != null)
                    {
                        c.WriteWrappedExpressionIfNeeded(pointerIndirect.Operand);
                        c.TextSpan("->");
                        c.WriteName(this.Field);
                        return;
                    }
                }

                if (this.ReceiverOpt != null && this.ReceiverOpt.Kind != Kinds.ConditionalReceiver)
                {
                    var primitiveValueAccess = this.Field.ContainingType != null &&
                                               this.Field.ContainingType.IsPrimitiveValueType() &&
                                               this.Field.Name == "m_value" && this.ReceiverOpt is Conversion &&
                                               ((Conversion)this.ReceiverOpt).ConversionKind == ConversionKind.Unboxing;
                    if (primitiveValueAccess)
                    {
                        c.WriteWrappedExpressionIfNeeded(this.ReceiverOpt);
                        return;
                    }
                    else
                    {
                        var effectiveReceiverOpt = PrepareFieldReceiver(this.ReceiverOpt, this.Field);
                        c.WriteAccess(effectiveReceiverOpt);
                    }
                }

                c.WriteName(this.Field);
            }
        }
示例#5
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.Field.IsStatic)
            {
                c.WriteTypeFullName(this.Field.ContainingType);
                c.TextSpan("::");
                c.WriteName(this.Field);
            }
            else
            {
                if (this.PointerAccess)
                {
                    var pointerIndirect = this.ReceiverOpt as PointerIndirectionOperator;
                    if (pointerIndirect != null)
                    {
                        c.WriteExpressionInParenthesesIfNeeded(pointerIndirect.Operand);
                        c.TextSpan("->");
                        c.WriteName(this.Field);
                        return;
                    }
                }

                if (this.ReceiverOpt != null)
                {
                    var primitiveValueAccess = this.Field.ContainingType != null &&
                                               this.Field.ContainingType.IsPrimitiveValueType() &&
                                               this.Field.Name == "m_value" && this.ReceiverOpt is Conversion &&
                                               ((Conversion)this.ReceiverOpt).ConversionKind == ConversionKind.Unboxing;
                    if (primitiveValueAccess)
                    {
                        c.WriteExpressionInParenthesesIfNeeded(this.ReceiverOpt);
                        return;
                    }
                    else
                    {
                        c.WriteAccess(this.ReceiverOpt);
                    }
                }

                c.WriteName(this.Field);
            }
        }