Exemplo n.º 1
0
        public override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("class");
            c.WhiteSpace();
            this.Name(c);

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

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

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

            c.EndBlockWithoutNewLine();
        }
Exemplo n.º 2
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.DecrementIndent();

            foreach (var label in this.Labels)
            {
                if (label.Value != null)
                {
                    var skipCaseForNullableWhenNull = this.SwitchType.IsValueType && label.Value.IsNull;
                    if (!skipCaseForNullableWhenNull)
                    {
                        c.TextSpan("case");
                        c.WhiteSpace();
                        if (label.Value != null)
                        {
                            new Literal {
                                Value = label.Value, Type = label.Type
                            }.WriteTo(c);
                        }
                        else
                        {
                            label.WriteTo(c);
                        }

                        c.TextSpan(":");
                    }
                    else
                    {
                        label.GenerateLabel = this.IsNullableType;
                    }
                }
                else
                {
                    c.TextSpan("default:");
                    if (this.IsNullableType)
                    {
                        label.GenerateLabel = true;
                    }
                }

                c.NewLine();

                if (label.GenerateLabel)
                {
                    label.WriteTo(c);
                    c.TextSpan(":");
                    c.NewLine();
                }
            }

            c.IncrementIndent();

            NoParenthesis = true;
            base.WriteTo(c);
        }
Exemplo n.º 3
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.DecrementIndent();

            foreach (var label in this.Labels)
            {
                if (label.Value != null)
                {
                    var skipCaseForNullableWhenNull = this.SwitchType.IsValueType && label.Value.IsNull;
                    if (!skipCaseForNullableWhenNull)
                    {
                        c.TextSpan("case");
                        c.WhiteSpace();

                        if (this.SwitchType.TypeKind == TypeKind.Enum)
                        {
                            c.TextSpan("(");
                            c.WriteType(this.SwitchType, containingNamespace: MethodOwner?.ContainingNamespace);
                            c.TextSpan(")");
                        }

                        c.TextSpan(label.ToString());
                        c.TextSpan(":");
                    }
                    else
                    {
                        label.GenerateLabel = this.IsNullableType;
                    }
                }
                else
                {
                    c.TextSpan("default:");
                    if (this.IsNullableType)
                    {
                        label.GenerateLabel = true;
                    }
                }

                c.NewLine();

                if (label.GenerateLabel)
                {
                    label.WriteTo(c);
                    c.TextSpan(":");
                    c.NewLine();
                }
            }

            c.IncrementIndent();

            NoParenthesis = true;
            base.WriteTo(c);
        }
Exemplo n.º 4
0
        public override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("class");
            c.WhiteSpace();
            this.Name(c);

            c.WhiteSpace();
            c.TextSpan(":");
            c.WhiteSpace();
            c.TextSpan("public");
            c.WhiteSpace();
            c.WriteTypeFullName(this.@interface);
            c.NewLine();
            c.OpenBlock();

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

            // write default constructor
            this.Name(c);
            c.TextSpan("(");
            c.WriteType(Type, false, true, true);
            c.WhiteSpace();
            c.TextSpan("class_");
            c.TextSpan(")");
            c.WhiteSpace();
            c.TextSpan(":");
            c.WhiteSpace();
            c.TextSpan("_class{class_}");
            c.WhiteSpace();
            c.TextSpanNewLine("{}");

            // add new method
            var namedTypeSymbol = (INamedTypeSymbol)Type;

            // not needed as we use global normal allocator
            ////new CCodeNewOperatorDeclaration(@interface).WriteTo(c);
            new CCodeObjectCastOperatorDefinition(namedTypeSymbol).WriteTo(c);

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

            c.EndBlockWithoutNewLine();
        }
Exemplo n.º 5
0
        public override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("class");
            c.WhiteSpace();
            c.WriteTypeName((INamedTypeSymbol)this.Type);
            c.OpenBlock();

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

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

            c.EndBlock();
            c.Separate();
        }
        public override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("class");
            c.WhiteSpace();
            this.Name(c);

            c.WhiteSpace();
            c.TextSpan(":");
            c.WhiteSpace();
            c.TextSpan("public");
            c.WhiteSpace();
            c.WriteTypeFullName(this.@interface);
            c.NewLine();
            c.OpenBlock();

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

            // write default constructor
            this.Name(c);
            c.TextSpan("(");
            c.WriteType(Type, false, true, true);
            c.WhiteSpace();
            c.TextSpan("class_");
            c.TextSpan(")");
            c.WhiteSpace();
            c.TextSpan(":");
            c.WhiteSpace();
            c.TextSpan("_class{class_}");
            c.WhiteSpace();
            c.TextSpanNewLine("{}");

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

            c.EndBlockWithoutNewLine();
        }
Exemplo n.º 7
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);
        }