Example #1
0
        public override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpanNewLine("inline static GC_descr __get_type_descriptor()");
            c.OpenBlock();
            c.TextSpan("typedef");
            c.WhiteSpace();
            c.WriteType(this.Type, true, true, true);
            c.WhiteSpace();
            c.TextSpanNewLine("__type;");
            c.TextSpanNewLine("GC_word bitmap[GC_BITMAP_SIZE(__type)] = {0};");

            // set fields
            foreach (var field in this.Type.EnumPossibleReferenceFields())
            {
                c.TextSpan("GC_set_bit(bitmap, GC_WORD_OFFSET(__type,");
                c.WhiteSpace();
                // TODO: fix it, replace with "base" type as generic types causing issues
                ////c.WriteFieldAccessAsStaticField(field);
                c.WriteName(field);
                c.TextSpanNewLine("));");
            }

            c.TextSpanNewLine("return GC_make_descriptor(bitmap, GC_WORD_LEN(__type));");

            c.EndBlock();
            c.Separate();
        }
Example #2
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            CCodeWriterBase.SetLocalObjectIDGenerator();

            // get actual statements
            var statements = Statements;

            if (statements.Count == 1 && statements.First().Kind == Kinds.BlockStatement)
            {
                var blockStatement = statements.First() as BlockStatement;
                if (blockStatement != null)
                {
                    var block = blockStatement.Statements as Block;
                    if (block != null)
                    {
                        statements = block.Statements;
                    }
                }
            }

            var extraLocalDecls = this.SanitizeCode(statements);

            var skip = 0;

            ////if (this.MethodSymbol.MethodKind == MethodKind.Constructor)
            ////{
            ////    skip = ConstructorInitializer(c, statements);
            ////}

            c.NewLine();
            c.OpenBlock();

            foreach (var localDecl in extraLocalDecls)
            {
                var loadState = localDecl.Suppressed;
                localDecl.Suppressed = false;
                localDecl.WriteTo(c);
                localDecl.Suppressed = loadState;
            }

            if (MethodSymbol.MethodKind == MethodKind.StaticConstructor)
            {
                c.TextSpanNewLine("_cctor_being_called = true;");
            }

            foreach (var statement in statements.Skip(skip))
            {
                if (MethodSymbol.MethodKind == MethodKind.StaticConstructor && statement.Kind == Kinds.ReturnStatement)
                {
                    c.TextSpanNewLine("_cctor_called = true;");
                    c.TextSpanNewLine("_cctor_being_called = false;");
                }

                statement.WriteTo(c);
            }

            c.EndBlock();
        }
        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();
        }
Example #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();
        }
        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();
        }
        public override void WriteTo(CCodeWriterBase c)
        {
            CCodeWriterBase.SetLocalObjectIDGenerator();

            c.Separate();
            c.TextSpanNewLine(string.Format("// Method : {0}", this.Method.ToDisplayString()));

            c.WriteMethodDeclaration(this.Method, false);

            if (this.MethodBodyOpt != null)
            {
                this.MethodBodyOpt.WriteTo(c);
            }
            else
            {
                c.WriteMethodBody(this.BoundBody, this.Method);
            }
        }
Example #7
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            CCodeWriterBase.SetLocalObjectIDGenerator();

            // get actual statements
            var statements = Statements;

            if (statements.Count == 1 && statements.First().Kind == Kinds.BlockStatement)
            {
                var blockStatement = statements.First() as BlockStatement;
                if (blockStatement != null)
                {
                    var block = blockStatement.Statements as Block;
                    if (block != null)
                    {
                        statements = block.Statements;
                    }
                }
            }

            this.SanitizeCaseLabelsAndSetReturnTypes(statements);

            var skip = 0;

            ////if (this.MethodSymbol.MethodKind == MethodKind.Constructor)
            ////{
            ////    skip = ConstructorInitializer(c, statements);
            ////}

            c.NewLine();
            c.OpenBlock();

            if (this.MethodSymbol.MethodKind == MethodKind.StaticConstructor)
            {
                c.TextSpanNewLine("_cctor_called = true;");
            }

            foreach (var statement in statements.Skip(skip))
            {
                statement.WriteTo(c);
            }

            c.EndBlock();
        }
Example #8
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();
        }
Example #9
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);
        }
Example #10
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            CCodeWriterBase.SetLocalObjectIDGenerator();

            // get actual statements
            var statements = Statements;

            if (statements.Count == 1 && statements.First().Kind == Kinds.BlockStatement)
            {
                var blockStatement = statements.First() as BlockStatement;
                if (blockStatement != null)
                {
                    var block = blockStatement.Statements as Block;
                    if (block != null)
                    {
                        statements = block.Statements;
                    }
                }
            }

            var extraLocalDecls = this.SanitizeCode(statements);

            var skip = 0;

            ////if (this.MethodSymbol.MethodKind == MethodKind.Constructor)
            ////{
            ////    skip = ConstructorInitializer(c, statements);
            ////}

            c.NewLine();
            c.OpenBlock();

            foreach (var localDecl in extraLocalDecls)
            {
                var loadState = localDecl.Suppressed;
                localDecl.Suppressed = false;
                localDecl.WriteTo(c);
                localDecl.Suppressed = loadState;
            }

            if (MethodSymbol.MethodKind == MethodKind.StaticConstructor)
            {
                c.TextSpanNewLine("_cctor_being_called = true;");
            }

            #region Virtual Generic methods support
            if (MethodSymbol.MethodKind == MethodKind.Constructor)
            {
                foreach (var typeParameter in MethodSymbol.ContainingType.GetTemplateParameters().Where(t => t.HasConstructorConstraint))
                {
                    c.TextSpanNewLine(string.Format("this->construct_{0} = construct_{0};", typeParameter.Name));
                }
            }
            #endregion

            foreach (var statement in statements.Skip(skip))
            {
                if (MethodSymbol.MethodKind == MethodKind.StaticConstructor && statement.Kind == Kinds.ReturnStatement)
                {
                    c.TextSpanNewLine("_cctor_called = true;");
                    c.TextSpanNewLine("_cctor_being_called = false;");
                }

                statement.WriteTo(c);
            }

            c.EndBlock();
        }