Пример #1
0
        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
        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();
        }
Пример #3
0
 internal override void WriteTo(CCodeWriterBase c)
 {
     if (!this.SuppressEnding)
     {
         c.EndStatement();
     }
 }
Пример #4
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            this.Expression.WriteTo(c);
            c.TextSpan("->operator[](");

            if (this._indices.Count > 1)
            {
                c.TextSpan("{");
            }

            var any = false;

            foreach (var index in this._indices)
            {
                if (any)
                {
                    c.TextSpan(",");
                    c.WhiteSpace();
                }

                index.WriteTo(c);

                any = true;
            }

            if (this._indices.Count > 1)
            {
                c.TextSpan("}");
            }

            c.TextSpan(")");
        }
Пример #5
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            switch (this.OperatorKind & UnaryOperatorKind.OpMask)
            {
            case UnaryOperatorKind.UnaryPlus:
                c.TextSpan("+");
                break;

            case UnaryOperatorKind.UnaryMinus:
                c.TextSpan("-");
                break;

            case UnaryOperatorKind.LogicalNegation:
                c.TextSpan("!");
                break;

            case UnaryOperatorKind.BitwiseComplement:
                c.TextSpan("~");
                break;

            default:
                throw new NotImplementedException();
            }

            c.WriteExpressionInParenthesesIfNeeded(this.Operand);
        }
Пример #6
0
 internal override void WriteTo(CCodeWriterBase c)
 {
     this.Lambda.WriteTo(c);
     WriteCallArguments(c, this.Lambda.Locals.Select(l => new ParameterImpl {
         Type = l.Type
     }), this.arguments);
 }
Пример #7
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("if");
            c.WhiteSpace();
            c.TextSpan("(");

            if (!this.JumpIfTrue)
            {
                c.TextSpan("!");
                c.WriteWrappedExpressionIfNeeded(this.Condition);
            }
            else
            {
                this.Condition.WriteTo(c);
            }

            c.TextSpan(")");

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

            new GotoStatement {
                Label = this.Label
            }.WriteTo(c);

            c.EndBlock();

            c.Separate();
        }
Пример #8
0
        internal static void WriteCheckedOperator(CCodeWriterBase c, BinaryOperatorKind operatorKind)
        {
            switch (GetOperatorKind(operatorKind))
            {
            case BinaryOperatorKind.Multiplication:
                c.TextSpan("__mul_ovf");
                break;

            case BinaryOperatorKind.Addition:
                c.TextSpan("__add_ovf");
                break;

            case BinaryOperatorKind.Subtraction:
                c.TextSpan("__sub_ovf");
                break;

            default:
                throw new NotImplementedException();
            }

            switch (operatorKind & BinaryOperatorKind.TypeMask)
            {
            case BinaryOperatorKind.UInt:
            case BinaryOperatorKind.ULong:
                c.TextSpan("_un");
                break;
            }
        }
Пример #9
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("typedef");
            c.WhiteSpace();
            if (this.TypeExpressionOpt != null)
            {
                this.TypeExpressionOpt.WriteTo(c);
                c.WhiteSpace();
                this.Identifier.WriteTo(c);
            }
            else if (this.PointerToMemberOpt != null)
            {
                c.WriteType(this.PointerToMemberOpt.ReturnType, containingNamespace: MethodOwner?.ContainingNamespace);
                c.WhiteSpace();
                c.TextSpan("(");
                if (!this.PointerToMemberOpt.IsStatic)
                {
                    c.WriteType(this.PointerToMemberOpt.ContainingType, true, true, true, containingNamespace: MethodOwner?.ContainingNamespace);
                    c.TextSpan("::");
                }

                c.TextSpan("*");
                c.WhiteSpace();
                this.Identifier.WriteTo(c);
                c.TextSpan(")");
                c.WriteMethodParameters(this.PointerToMemberOpt, true, false, containingNamespace: MethodOwner?.ContainingNamespace);
            }

            base.WriteTo(c);
        }
Пример #10
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (!this.Method.IsStatic)
            {
                var receiverOpt = this.ReceiverOpt;
                if (receiverOpt is BaseReference)
                {
                    receiverOpt = new ThisReference();
                }

                c.WriteWrappedExpressionIfNeeded(receiverOpt);
                c.TextSpan(",");
                c.WhiteSpace();
            }

            new Parenthesis {
                Operand = new MethodPointer {
                    Method = this.Method
                }
            }.WriteTo(c);
            c.TextSpan("&");
            c.WriteTypeFullName(this.Method.ContainingType);
            c.TextSpan("::");
            c.WriteMethodNameNoTemplate(this.Method);

            if (this.TypeArgumentsOpt != null && this.TypeArgumentsOpt.Any())
            {
                c.WriteTypeArguments(this.TypeArgumentsOpt);
            }
        }
 public override void WriteTo(CCodeWriterBase c)
 {
     c.WriteType(Method.ContainingType, valueTypeAsClass: true);
     c.WhiteSpace();
     c.TextSpan("operator->()");
     MethodBodyOpt.WriteTo(c);
 }
Пример #12
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.clone)
            {
                new Cast
                {
                    Operand =
                        new Call
                    {
                        ReceiverOpt = this.cloneArgument,
                        Method      = new MethodImpl {
                            Name = "__clone", Parameters = ImmutableArray <IParameterSymbol> .Empty
                        }
                    },
                    Type  = Type,
                    CCast = true,
                }.WriteTo(c);
            }
            else
            {
                var methodGroup       = Arguments.First() as MethodGroup;
                var isStatic          = methodGroup != null && methodGroup.Method.IsStatic;
                var newDelegateMethod = new CCodeDelegateWrapperClass((INamedTypeSymbol)Type).GetNewMethod(isStatic, true);
                if (newDelegateMethod.ContainingNamespace != null)
                {
                    c.WriteNamespace(newDelegateMethod.ContainingNamespace);
                    c.TextSpan("::");
                }

                c.WriteMethodName(newDelegateMethod, addTemplate: true, containingNamespace: MethodOwner?.ContainingNamespace);
                WriteCallArguments(c, this.Method != null ? this.Method.Parameters : (IEnumerable <IParameterSymbol>)null, this.Arguments, methodOwner: MethodOwner);
            }
        }
Пример #13
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("[&]");
            c.TextSpan("(");

            var any = false;

            foreach (var local in this.Locals)
            {
                if (any)
                {
                    c.TextSpan(",");
                    c.WhiteSpace();
                }

                c.TextSpan("auto");
                c.WhiteSpace();
                c.WriteName(local);

                any = true;
            }

            c.TextSpan(")");
            c.WriteBlockOrStatementsAsBlock(this.Statements, true);
        }
Пример #14
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.Suppressed)
            {
                return;
            }

            if (this.Local != null)
            {
                c.WriteType(this.Local.Type);
                c.WhiteSpace();
                this.Local.WriteTo(c);
            }

            var any = false;

            foreach (var statement in this._statements)
            {
                if (any)
                {
                    c.TextSpan(",");
                    c.WhiteSpace();
                }

                PrintStatementAsExpression(c, statement);
                any = true;
            }

            base.WriteTo(c);
        }
Пример #15
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            // Finish it properly

            var localImpl = new LocalImpl {
                Name = "__MakeRef", Type = Type
            };
            var local = new Local {
                LocalSymbol = localImpl
            };

            var block = new Block();

            block.Statements.Add(new VariableDeclaration {
                Local = local
            });
            block.Statements.Add(
                new ExpressionStatement
            {
                Expression =
                    new AssignmentOperator
                {
                    Left  = local,
                    Right = new ObjectCreationExpression {
                        Type = Type
                    }
                }
            });
            block.Statements.Add(new ReturnStatement {
                ExpressionOpt = local
            });
            new LambdaExpression {
                Statements = block, Type = Type
            }.WriteTo(c);
        }
Пример #16
0
        private void ParseName(LocalSymbol local)
        {
            if (local.SynthesizedLocalKind != SynthesizedLocalKind.None)
            {
                this.SynthesizedLocalKind = local.SynthesizedLocalKind;

                var lbl = string.Empty;
                if (local.SynthesizedLocalKind > SynthesizedLocalKind.ForEachArrayIndex0 &&
                    local.SynthesizedLocalKind < SynthesizedLocalKind.ForEachArrayLimit0)
                {
                    lbl = string.Format("ForEachArrayIndex{0}", local.SynthesizedLocalKind - SynthesizedLocalKind.ForEachArrayIndex0);
                }
                else if (local.SynthesizedLocalKind > SynthesizedLocalKind.ForEachArrayLimit0 &&
                         local.SynthesizedLocalKind < SynthesizedLocalKind.FixedString)
                {
                    lbl = string.Format("ForEachArrayLimit{0}", local.SynthesizedLocalKind - SynthesizedLocalKind.ForEachArrayLimit0);
                }
                else
                {
                    lbl = local.SynthesizedLocalKind.ToString();
                    var firstTime = false;
                    lbl += string.Format("_{0}", CCodeWriterBase.GetIdLocal(local, out firstTime));
                }

                this.CustomName = lbl;
            }
        }
Пример #17
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();
        }
Пример #18
0
 internal override void WriteTo(CCodeWriterBase c)
 {
     c.WriteWrappedExpressionIfNeeded(this.Operand);
     c.TextSpan("[");
     this.Index.WriteTo(c);
     c.TextSpan("]");
 }
Пример #19
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("()");
        }
Пример #20
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);
            }
        }
Пример #21
0
 internal override void WriteTo(CCodeWriterBase c)
 {
     c.TextSpan("__reftype");
     c.TextSpan("(");
     this.Operand.WriteTo(c);
     c.TextSpan(")");
 }
Пример #22
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("for");
            c.WhiteSpace();
            c.TextSpan("(");

            PrintStatementAsExpression(c, this.InitializationOpt);

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

            if (this.ConditionOpt != null)
            {
                this.ConditionOpt.WriteTo(c);
            }

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

            PrintStatementAsExpression(c, this.IncrementingOpt);

            c.TextSpan(")");

            c.NewLine();
            base.WriteTo(c);
        }
Пример #23
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.locals.Count > 0)
            {
                c.OpenBlock();

                foreach (var statement in this.locals)

                {
                    statement.WriteTo(c);
                }
            }

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

            var block = this.Initialization as Block;

            if (block != null)
            {
                var any = false;
                foreach (var initializationItem in block.Statements)
                {
                    if (any)
                    {
                        c.TextSpan(",");
                        c.WhiteSpace();
                    }

                    PrintStatementAsExpression(c, initializationItem);
                    any = true;
                }
            }
            else
            {
                PrintStatementAsExpression(c, this.Initialization);
            }

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

            this.Condition.WriteTo(c);

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

            PrintStatementAsExpression(c, this.Incrementing);

            c.TextSpan(")");

            c.NewLine();
            base.WriteTo(c);

            if (this.locals.Count > 0)
            {
                c.EndBlock();
            }
        }
 public override void WriteTo(CCodeWriterBase c)
 {
     c.TextSpan("virtual operator");
     c.WhiteSpace();
     c.WriteType(this.interfaceSymbol);
     c.TextSpan("()");
     MethodBodyOpt.WriteTo(c);
 }
Пример #25
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("goto");
            c.WhiteSpace();

            this.Label.WriteTo(c);
            base.WriteTo(c);
        }
Пример #26
0
 internal override void WriteTo(CCodeWriterBase c)
 {
     new Local {
         LocalSymbol = new LocalImpl {
             Name = GetName(this.Id), Type = Type
         }
     }.SetOwner(MethodOwner).WriteTo(c);
 }
Пример #27
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();
        }
Пример #28
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (!(this.Operand is ThisReference))
            {
                c.TextSpan("&");
            }

            this.Operand.WriteTo(c);
        }
Пример #29
0
 internal override void WriteTo(CCodeWriterBase c)
 {
     c.TextSpan("reinterpret_cast<");
     c.WriteType(Type);
     c.TextSpan(">(alloca");
     c.TextSpan("(");
     this.Count.WriteTo(c);
     c.TextSpan("))");
 }
Пример #30
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            // Finish it properly

            var localImpl = new LocalImpl {
                Name = "__NullCoalescing", Type = Type
            };
            var local = new Local {
                LocalSymbol = localImpl, MethodOwner = MethodOwner
            };

            var block = new Block();

            block.Statements.Add(new VariableDeclaration {
                Local = local, MethodOwner = MethodOwner
            });
            block.Statements.Add(
                new ExpressionStatement
            {
                Expression =
                    new AssignmentOperator
                {
                    Left        = local,
                    Right       = this.LeftOperand,
                    MethodOwner = MethodOwner
                },
                MethodOwner = MethodOwner
            });
            block.Statements.Add(
                new ReturnStatement
            {
                ExpressionOpt =
                    new ConditionalOperator
                {
                    Condition =
                        new BinaryOperator
                    {
                        Left  = local,
                        Right = new Literal {
                            Value = ConstantValue.Create(null)
                        },
                        OperatorKind = BinaryOperatorKind.NotEqual,
                        MethodOwner  = MethodOwner
                    },
                    Consequence = local,
                    Alternative = this.RightOperand,
                    MethodOwner = MethodOwner
                },
                MethodOwner = MethodOwner
            });
            new LambdaCall
            {
                Lambda = new LambdaExpression {
                    Statements = block, Type = Type, MethodOwner = MethodOwner
                }
            }.WriteTo(c);
        }