Exemple #1
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("[&]()");

            c.NewLine();
            c.OpenBlock();
            foreach (var statement in this.Locals)
            {
                statement.WriteTo(c);
            }

            foreach (var expression in this.SideEffects)
            {
                expression.WriteTo(c);
                c.EndStatement();
            }

            c.TextSpan("return");
            c.WhiteSpace();
            this.Value.WriteTo(c);
            c.EndStatement();

            c.EndBlockWithoutNewLine();
            c.TextSpan("()");
        }
Exemple #2
0
        public override void WriteTo(CCodeWriterBase c)
        {
            c.Separate();

            c.TextSpan(string.Format("// adapter: {0}", Method));
            c.NewLine();

            foreach (var statement in this.typeDefs)
            {
                statement.WriteTo(c);
            }

            var namedTypeSymbol = (INamedTypeSymbol)this.type;

            if (namedTypeSymbol.IsGenericType)
            {
                c.WriteTemplateDeclaration(namedTypeSymbol);
                c.NewLine();
            }

            c.WriteMethodReturn(Method, true);
            c.WriteMethodNamespace(namedTypeSymbol);
            c.WriteMethodName(Method, false, interfaceWrapperMethodSpecialCase: true);
            c.WriteMethodParameters(Method, true, MethodBodyOpt != null);

            if (MethodBodyOpt == null)
            {
                c.EndStatement();
            }
            else
            {
                MethodBodyOpt.WriteTo(c);
            }
        }
Exemple #3
0
 internal override void WriteTo(CCodeWriterBase c)
 {
     if (!this.SuppressEnding)
     {
         c.EndStatement();
     }
 }
Exemple #4
0
 public override void WriteTo(CCodeWriterBase c)
 {
     c.WriteMethodDeclaration(this.Method, true, this.MethodBodyOpt != null, containingNamespace: containingType.ContainingNamespace);
     if (this.MethodBodyOpt == null)
     {
         c.EndStatement();
     }
     else
     {
         this.MethodBodyOpt.WriteTo(c);
     }
 }
 public override void WriteTo(CCodeWriterBase c)
 {
     c.WriteMethodDeclaration(this.Method, true, this.MethodBodyOpt != null);
     if (this.MethodBodyOpt == null)
     {
         c.EndStatement();
     }
     else
     {
         this.MethodBodyOpt.WriteTo(c);
     }
 }
Exemple #6
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.TypeDeclaration)
            {
                if (this.ApplyAutoType && !this.TypeDeclarationSplit)
                {
                    c.TextSpan("auto");
                }
                else if (Type != null)
                {
                    c.WriteType(Type, containingNamespace: MethodOwner?.ContainingNamespace);
                }

                if (this.IsRef || this.IsOut)
                {
                    c.TextSpan("&");
                }

                c.WhiteSpace();
                if (this.TypeDeclarationSplit && !this.IsRef && !this.IsOut)
                {
                    ////Debug.Assert(!this.IsRef && !this.IsOut, "reference initialization");
                    this.Left.WriteTo(c);
                    c.EndStatement();
                }
            }

            if (this.ApplyCppReference)
            {
                c.TextSpan("*");
            }

            var rightType = this.Right.Type;

            if (rightType != null && rightType.IsValueType && this.Left is ThisReference)
            {
                c.TextSpan("*");
            }

            this.Left.WriteTo(c);
            c.WhiteSpace();
            c.TextSpan("=");
            c.WhiteSpace();

            var leftType = this.Left.Type;

            if (leftType != null && leftType.IsValueType && this.Right is ThisReference)
            {
                c.TextSpan("*");
            }

            c.WriteWrappedExpressionIfNeeded(this.Right);
        }
Exemple #7
0
        /// <summary>
        /// </summary>
        /// <param name="c">
        /// </param>
        /// <param name="newNonStaticMethod">
        /// </param>
        /// <param name="nonStaticType">
        /// </param>
        private static void WriteNewMethod(CCodeWriterBase c, IMethodSymbol newNonStaticMethod, NamedTypeImpl nonStaticType)
        {
            c.WriteMethodDeclaration(newNonStaticMethod, true, true);
            c.NewLine();
            c.OpenBlock();

            var objectCreationExpression = new ObjectCreationExpression {
                Type = nonStaticType, NewOperator = true
            };

            foreach (var parameter in newNonStaticMethod.Parameters)
            {
                Expression parameterExpression = new Parameter {
                    ParameterSymbol = parameter
                };
                if (parameter.Name == "m")
                {
                    parameterExpression = new Cast
                    {
                        Operand        = parameterExpression,
                        MapPointerCast = true,
                        MapPointerCastTypeParameter1 =
                            new Access
                        {
                            AccessType  = Access.AccessTypes.DoubleColon,
                            ReceiverOpt = new TypeExpression {
                                Type = nonStaticType, TypeNameRequred = true
                            },
                            Expression = new Parameter {
                                ParameterSymbol = new ParameterImpl {
                                    Name = "_Memptr"
                                }
                            }
                        },
                        MapPointerCastTypeParameter2 = new TypeExpression {
                            Type = new TypeImpl {
                                TypeKind = TypeKind.TypeParameter, Name = "_Memptr"
                            }
                        },
                    };
                }

                objectCreationExpression.Arguments.Add(parameterExpression);
            }

            new ReturnStatement {
                ExpressionOpt = objectCreationExpression
            }.WriteTo(c);

            c.EndBlockWithoutNewLine();
            c.EndStatement();
        }
 public override void WriteTo(CCodeWriterBase c)
 {
     c.WriteMethodPrefixes(Method, true);
     c.TextSpan("operator object*");
     c.WriteMethodParameters(Method, true, MethodBodyOpt != null);
     c.WriteMethodSuffixes(Method, true);
     if (MethodBodyOpt == null)
     {
         c.EndStatement();
     }
     else
     {
         MethodBodyOpt.WriteTo(c);
     }
 }
Exemple #9
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("do");
            c.NewLine();
            NoSeparation = true;
            base.WriteTo(c);

            c.TextSpan("while");
            c.WhiteSpace();
            c.TextSpan("(");

            this.Condition.WriteTo(c);

            c.TextSpan(")");

            c.EndStatement();
        }
        public override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan(string.Format("// adapter: {0}", Method));
            c.NewLine();

            foreach (var statement in this.typeDefs)
            {
                statement.WriteTo(c);
            }

            c.WriteMethodReturn(Method, true);
            c.WriteMethodName(Method, allowKeywords: false, interfaceWrapperMethodSpecialCase: true);
            c.WriteMethodParameters(Method, true, MethodBodyOpt != null);

            if (MethodBodyOpt == null)
            {
                c.EndStatement();
            }
            else
            {
                MethodBodyOpt.WriteTo(c);
            }
        }
Exemple #11
0
        /// <summary>
        /// </summary>
        /// <param name="c">
        /// </param>
        public override void WriteTo(CCodeWriterBase c)
        {
            // non-static
            var nonStaticType = this.GetDelegateType();

            if (nonStaticType.IsGenericType)
            {
                c.WriteTemplateDeclaration(nonStaticType);
            }

            c.TextSpan("class");
            c.WhiteSpace();
            c.WriteTypeName(nonStaticType);

            c.WhiteSpace();
            c.TextSpan(":");
            c.WhiteSpace();
            c.TextSpan("public");
            c.WhiteSpace();
            c.WriteTypeFullName(Type);
            c.NewLine();
            c.OpenBlock();

            c.DecrementIndent();
            c.TextSpanNewLine("public:");
            c.IncrementIndent();

            // typedef
            c.TextSpanNewLine("typedef typename std::remove_pointer<_T>::type _Ty;");
            c.TextSpan("typedef ");
            c.WriteType(this.invoke.ReturnType);
            c.WhiteSpace();
            c.TextSpan("(_Ty::* _Memptr)");
            c.WriteMethodParameters(this.invoke, true, false);
            c.TextSpanNewLine(";");

            // fields
            c.TextSpanNewLine("_Ty* _t;");
            c.TextSpanNewLine("_Memptr _memptr;");

            // write default constructor
            c.WriteTypeName(nonStaticType);
            c.TextSpanNewLine("(_Ty* t, _Memptr memptr) : _t(t), _memptr(memptr) { CoreLib::System::Delegate::_target = object_cast(t); CoreLib::System::Delegate::_methodPtr = __init<CoreLib::System::IntPtr>(map_pointer_cast<void*, _Memptr>(memptr)); }");

            // write invoke
            this.CreateInvokeMethod().WriteTo(c);

            // write clonse
            this.CreateCloneMethod().WriteTo(c);

            foreach (var declaration in Declarations)
            {
                declaration.WriteTo(c);
            }

            c.EndBlockWithoutNewLine();
            c.EndStatement();

            var newNonStaticMethod = this.GetNewMethod();

            WriteNewMethod(c, newNonStaticMethod, nonStaticType);

            // static
            var staticType = this.GetDelegateType(true);

            if (staticType.IsGenericType)
            {
                c.WriteTemplateDeclaration(staticType);
            }

            c.TextSpan("class");
            c.WhiteSpace();
            c.WriteTypeName(staticType);

            c.WhiteSpace();
            c.TextSpan(":");
            c.WhiteSpace();
            c.TextSpan("public");
            c.WhiteSpace();
            c.WriteTypeFullName(Type);
            c.NewLine();
            c.OpenBlock();

            c.DecrementIndent();
            c.TextSpanNewLine("public:");
            c.IncrementIndent();

            // typedef
            c.TextSpan("typedef ");
            c.WriteType(this.invoke.ReturnType);
            c.WhiteSpace();
            c.TextSpan("(* _Memptr)");
            c.WriteMethodParameters(this.invoke, true, false);
            c.TextSpanNewLine(";");

            // fields
            c.TextSpanNewLine("_Memptr _memptr;");

            // write default constructor
            c.WriteTypeName(staticType);
            c.TextSpanNewLine("(_Memptr memptr) : _memptr(memptr) {  CoreLib::System::Delegate::_methodPtr = __init<CoreLib::System::IntPtr>(map_pointer_cast<void*, _Memptr>(memptr)); }");

            // write invoke
            this.CreateInvokeMethod(true).WriteTo(c);

            // write clonse
            this.CreateCloneMethod(true).WriteTo(c);

            foreach (var declaration in Declarations)
            {
                declaration.WriteTo(c);
            }

            c.EndBlockWithoutNewLine();
            c.EndStatement();

            var newStaticMethod = this.GetNewMethod(true);

            WriteNewMethod(c, newStaticMethod, staticType);
        }
Exemple #12
0
 public override void WriteTo(CCodeWriterBase c)
 {
     c.WriteFieldDefinition(this.Field, this.DoNotWrapStatic);
     c.EndStatement();
 }
 public override void WriteTo(CCodeWriterBase c)
 {
     this.CodeClass.WriteTo(c);
     c.EndStatement();
 }