예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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();
        }
예제 #6
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();
        }
예제 #7
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();
            }
        }
예제 #8
0
        private static int ConstructorInitializer(CCodeWriterBase c, IList <Statement> statements)
        {
            var skip = 0;
            // call constructors
            var constructorsOrAssignments =
                statements.TakeWhile(IsConstructorCallOrAssignment).Select(GetCallOrAssignment).ToArray();

            if (constructorsOrAssignments.Length > 0)
            {
                c.WhiteSpace();
                c.TextSpan(":");
                c.WhiteSpace();

                var any = false;
                foreach (var constructorAsAssignment in constructorsOrAssignments)
                {
                    skip++;

                    if (any)
                    {
                        c.TextSpan(",");
                        c.WhiteSpace();
                    }

                    if (constructorAsAssignment.Kind == Kinds.Call)
                    {
                        constructorAsAssignment.WriteTo(c);
                        break;
                    }
                    else if (constructorAsAssignment.Kind == Kinds.AssignmentOperator)
                    {
                        // convert
                        var assignmentOperator = constructorAsAssignment as AssignmentOperator;
                        var fieldAccess        = assignmentOperator.Left as FieldAccess;
                        if (fieldAccess != null && fieldAccess.ReceiverOpt.Kind == Kinds.ThisReference)
                        {
                            c.WriteName(fieldAccess.Field);
                            c.TextSpan("(");
                            assignmentOperator.Right.WriteTo(c);
                            c.TextSpan(")");
                        }
                    }
                    else
                    {
                        Debug.Assert(false);
                    }

                    any = true;
                }
            }

            return(skip);
        }
예제 #9
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            bool changedLeft;

            this.Left = AdjustEnumType(this.Left, out changedLeft);
            bool changedRight;

            this.Right = AdjustEnumType(this.Right, out changedRight);

            var castOfResult = (changedRight || changedLeft) && Type.TypeKind == TypeKind.Enum;

            if (castOfResult)
            {
                c.TextSpan("((");
                c.WriteType(Type);
                c.TextSpan(")(");
            }

            var reminder = this.IsRealRemainder;

            if (reminder)
            {
                c.TextSpan("std::fmod(");
                c.WriteWrappedExpressionIfNeeded(this.Left);
                c.TextSpan(",");
                c.WhiteSpace();
                c.WriteWrappedExpressionIfNeeded(this.Right);
                c.TextSpan(")");
            }
            else if (IsChecked(this.OperatorKind))
            {
                WriteCheckedOperator(c, this.OperatorKind);
                c.TextSpan("(");
                c.WriteWrappedExpressionIfNeeded(this.Left);
                c.TextSpan(",");
                c.WhiteSpace();
                c.WriteWrappedExpressionIfNeeded(this.Right);
                c.TextSpan(")");
            }
            else
            {
                c.WriteWrappedExpressionIfNeeded(this.Left);
                c.WhiteSpace();
                this.WriteOperator(c);
                c.WhiteSpace();
                c.WriteWrappedExpressionIfNeeded(this.Right);
            }

            if (castOfResult)
            {
                c.TextSpan("))");
            }
        }
예제 #10
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);
        }
 public override void WriteTo(CCodeWriterBase c)
 {
     // write boxing function
     c.TextSpan("inline");
     c.WhiteSpace();
     c.WriteType(this.type, valueTypeAsClass: true);
     c.WhiteSpace();
     c.TextSpan("__box(");
     c.WriteType(this.type);
     c.WhiteSpace();
     c.TextSpan("value)");
     MethodBodyOpt.WriteTo(c);
 }
예제 #12
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(")");
        }
예제 #13
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("()");
        }
 public override void WriteTo(CCodeWriterBase c)
 {
     c.WriteType(Method.ContainingType, valueTypeAsClass: true);
     c.WhiteSpace();
     c.TextSpan("operator->()");
     MethodBodyOpt.WriteTo(c);
 }
예제 #15
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);
            }
        }
예제 #16
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.WriteWrappedExpressionIfNeeded(this.Condition);

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

            c.WriteWrappedExpressionIfNeeded(this.Consequence);

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

            c.WriteWrappedExpressionIfNeeded(this.Alternative);
        }
예제 #17
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.WriteExpressionInParenthesesIfNeeded(this.Condition);

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

            this.Consequence.WriteTo(c);

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

            this.Alternative.WriteTo(c);
        }
예제 #18
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();
        }
예제 #19
0
파일: Call.cs 프로젝트: GabberBaby/cs2cpp
        internal static void WriteCallArguments(IEnumerable <Expression> arguments, IEnumerable <IParameterSymbol> parameterSymbols, CCodeWriterBase c)
        {
            c.TextSpan("(");
            var anyArgs = false;

            var paramEnum = parameterSymbols != null?parameterSymbols.GetEnumerator() : null;

            foreach (var expression in arguments)
            {
                var hasParameter = false;
                if (paramEnum != null)
                {
                    hasParameter = paramEnum.MoveNext();
                }

                if (anyArgs)
                {
                    c.TextSpan(",");
                    c.WhiteSpace();
                }

                PreprocessParameter(expression, hasParameter ? paramEnum.Current : null).WriteTo(c);
                anyArgs = true;
            }

            c.TextSpan(")");
        }
예제 #20
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.WriteType(this.Method.ReturnType);
            c.WhiteSpace();
            c.TextSpan("(");
            if (!this.Method.IsStatic)
            {
                c.WriteType(this.Method.ContainingType, true, true, true);
                c.TextSpan("::");
            }

            c.TextSpan("*");
            c.WhiteSpace();
            c.TextSpan(")");
            c.WriteMethodParameters(this.Method, true, false);
        }
예제 #21
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.WriteType(this.Method.ReturnType, containingNamespace: MethodOwner?.ContainingNamespace);
            c.WhiteSpace();
            c.TextSpan("(");
            if (!this.Method.IsStatic)
            {
                c.WriteType(this.Method.ContainingType, true, true, true, containingNamespace: MethodOwner?.ContainingNamespace);
                c.TextSpan("::");
            }

            c.TextSpan("*");
            c.WhiteSpace();
            c.TextSpan(")");
            c.WriteMethodParameters(this.Method, true, false, noDefaultParameterValues: true, containingNamespace: MethodOwner?.ContainingNamespace);
        }
예제 #22
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("goto");
            c.WhiteSpace();

            this.Label.WriteTo(c);
            base.WriteTo(c);
        }
 public override void WriteTo(CCodeWriterBase c)
 {
     c.TextSpan("virtual operator");
     c.WhiteSpace();
     c.WriteType(this.interfaceSymbol);
     c.TextSpan("()");
     MethodBodyOpt.WriteTo(c);
 }
예제 #24
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.TypeNameRequred)
            {
                c.TextSpan("typename");
                c.WhiteSpace();
            }

            c.WriteType(Type, valueTypeAsClass: IsReference);
        }
예제 #25
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.TypeNameRequred)
            {
                c.TextSpan("typename");
                c.WhiteSpace();
            }

            c.WriteType(Type, suppressReference: this.SuppressReference, valueTypeAsClass: IsReference, containingNamespace: MethodOwner?.ContainingNamespace);
        }
예제 #26
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            bool changedLeft;

            this.Left = AdjustEnumType(this.Left, out changedLeft);
            bool changedRight;

            this.Right = AdjustEnumType(this.Right, out changedRight);

            var castOfResult = (changedRight || changedLeft) && Type.TypeKind == TypeKind.Enum;

            if (castOfResult)
            {
                c.TextSpan("((");
                c.WriteType(Type);
                c.TextSpan(")(");
            }

            var reminder = GetOperatorKind(this.OperatorKind) == BinaryOperatorKind.Remainder && (this.Left.Type.IsRealValueType() || this.Right.Type.IsRealValueType());

            if (reminder)
            {
                c.TextSpan("std::remainder(");
                c.WriteExpressionInParenthesesIfNeeded(this.Left);
                c.TextSpan(",");
                c.WhiteSpace();
                c.WriteExpressionInParenthesesIfNeeded(this.Right);
                c.TextSpan(")");
            }
            else
            {
                c.WriteExpressionInParenthesesIfNeeded(this.Left);
                c.WhiteSpace();
                this.WriteOperator(c);
                c.WhiteSpace();
                c.WriteExpressionInParenthesesIfNeeded(this.Right);
            }

            if (castOfResult)
            {
                c.TextSpan("))");
            }
        }
예제 #27
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);
        }
예제 #28
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            if (this.Suppressed)
            {
                return;
            }

            if (this.Local != null)
            {
                c.WriteType(this.Local.Type, containingNamespace: MethodOwner?.ContainingNamespace);
                c.WhiteSpace();
                this.Local.WriteTo(c);
            }

            // fix issue with using * in C++ declarations where "," is used
            var firstAssignmentExpression = (this._statements.FirstOrDefault() as ExpressionStatement)?.Expression as AssignmentOperator;

            if (firstAssignmentExpression != null && !firstAssignmentExpression.ApplyAutoType && firstAssignmentExpression.TypeDeclaration && !firstAssignmentExpression.TypeDeclarationSplit)
            {
                // mark all AssignmentOperator to put "*" if type is reference
                foreach (var assignmentExpression in this._statements.Skip(1).OfType <ExpressionStatement>().Select(s => s.Expression).OfType <AssignmentOperator>().Where(a => a.IsReference))
                {
                    assignmentExpression.ApplyCppReference = true;
                }
            }

            var any = false;

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

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

            base.WriteTo(c);
        }
예제 #29
0
        internal override void WriteTo(CCodeWriterBase c)
        {
            c.TextSpan("throw");
            if (this.ExpressionOpt != null)
            {
                c.WhiteSpace();
                this.ExpressionOpt.WriteTo(c);
            }

            base.WriteTo(c);
        }
예제 #30
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("(");

            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);

            if (this.locals.Count > 0)
            {
                c.EndBlock();
            }
        }