コード例 #1
0
ファイル: AstExpression.cs プロジェクト: luozhiping1987/dot42
        /// <summary>
        /// Write human readable output.
        /// </summary>
        public override void WriteTo(ITextOutput output, FormattingOptions format)
        {
            if (format.HasFlag(FormattingOptions.ShowHasSeqPoint) && SourceLocation != NoSource)
            {
                output.Write(SourceLocation.IsSpecial ? "!" : "~");
            }

            if (Operand is AstVariable && ((AstVariable)Operand).IsGenerated)
            {
                if (Code == AstCode.Stloc && InferredType == null)
                {
                    output.Write(((AstVariable)Operand).Name);
                    output.Write(" = ");
                    Arguments.First().WriteTo(output, format);
                    return;
                }
                if (Code == AstCode.Ldloc)
                {
                    output.Write(((AstVariable)Operand).Name);
                    if (InferredType != null)
                    {
                        output.Write(':');
                        InferredType.WriteTo(output, AstNameSyntax.ShortTypeName);
                        if ((ExpectedType != null) && (ExpectedType.FullName != this.InferredType.FullName))
                        {
                            output.Write("[exp:");
                            ExpectedType.WriteTo(output, AstNameSyntax.ShortTypeName);
                            output.Write(']');
                        }
                    }
                    return;
                }
            }

            if (Prefixes != null)
            {
                foreach (var prefix in Prefixes)
                {
                    output.Write(prefix.Code.GetName());
                    output.Write(". ");
                }
            }

            output.Write(Code.GetName());
            if (InferredType != null)
            {
                output.Write(':');
                InferredType.WriteTo(output, AstNameSyntax.ShortTypeName);
                if ((ExpectedType != null) && (ExpectedType.FullName != InferredType.FullName))
                {
                    output.Write("[exp:");
                    ExpectedType.WriteTo(output, AstNameSyntax.ShortTypeName);
                    output.Write(']');
                }
            }
            else if (ExpectedType != null)
            {
                output.Write("[exp:");
                ExpectedType.WriteTo(output, AstNameSyntax.ShortTypeName);
                output.Write(']');
            }
            output.Write('(');

            var first = true;

            if (Operand != null)
            {
                if (Operand is AstLabel)
                {
                    output.WriteReference(((AstLabel)Operand).Name, Operand);
                }
                else if (Operand is AstLabel[])
                {
                    var labels = (AstLabel[])Operand;
                    for (var i = 0; i < labels.Length; i++)
                    {
                        if (i > 0)
                        {
                            output.Write(", ");
                        }
                        output.WriteReference(labels[i].Name, labels[i]);
                    }
                }
                else if (Operand is AstLabelKeyPair[])
                {
                    var pairs = (AstLabelKeyPair[])Operand;
                    for (var i = 0; i < pairs.Length; i++)
                    {
                        if (i > 0)
                        {
                            output.Write(", ");
                        }
                        output.Write("{0} -> ", pairs[i].Key);
                        output.WriteReference(pairs[i].Label.Name, pairs[i].Label);
                    }
                }
                else if (Operand is XMethodReference)
                {
                    var method = (XMethodReference)Operand;
                    if (method.DeclaringType != null)
                    {
                        method.DeclaringType.WriteTo(output, AstNameSyntax.ShortTypeName);
                        output.Write("::");
                    }
                    output.WriteReference(method.Name, method);
                }
                else if (Operand is XFieldReference)
                {
                    var field = (XFieldReference)Operand;
                    field.DeclaringType.WriteTo(output, AstNameSyntax.ShortTypeName);
                    output.Write("::");
                    output.WriteReference(field.Name, field);
                }
                else
                {
                    DisassemblerHelpers.WriteOperand(output, Operand);
                }
                first = false;
            }

            bool firstArg = true;

            foreach (var arg in Arguments)
            {
                if (!first)
                {
                    output.Write(", ");
                }

                if ((format & FormattingOptions.BreakExpressions) != 0)
                {
                    if (firstArg)
                    {
                        output.Indent();
                    }

                    output.WriteLine();
                }

                arg.WriteTo(output, format);
                first    = false;
                firstArg = false;
            }
            output.Write(')');

            if ((format & FormattingOptions.BreakExpressions) != 0 && !firstArg)
            {
                output.Unindent();
            }
        }
コード例 #2
0
        public override void WriteTo(ITextOutput output)
        {
            if (Operand is ILVariable && ((ILVariable)Operand).IsGenerated)
            {
                if (Code == ILCode.Stloc && InferredType == null)
                {
                    output.Write(((ILVariable)Operand).Name);
                    output.Write(" = ");
                    Arguments.First().WriteTo(output);
                    return;
                }
                else if (Code == ILCode.Ldloc)
                {
                    output.Write(((ILVariable)Operand).Name);
                    if (InferredType != null)
                    {
                        output.Write(':');
                        InferredType.WriteTo(output, ILNameSyntax.ShortTypeName);
                        if (ExpectedType != null && ExpectedType.FullName != InferredType.FullName)
                        {
                            output.Write("[exp:");
                            ExpectedType.WriteTo(output, ILNameSyntax.ShortTypeName);
                            output.Write(']');
                        }
                    }
                    return;
                }
            }

            if (Prefixes != null)
            {
                foreach (var prefix in Prefixes)
                {
                    output.Write(prefix.Code.GetName());
                    output.Write(". ");
                }
            }

            output.Write(Code.GetName());
            if (InferredType != null)
            {
                output.Write(':');
                InferredType.WriteTo(output, ILNameSyntax.ShortTypeName);
                if (ExpectedType != null && ExpectedType.FullName != InferredType.FullName)
                {
                    output.Write("[exp:");
                    ExpectedType.WriteTo(output, ILNameSyntax.ShortTypeName);
                    output.Write(']');
                }
            }
            else if (ExpectedType != null)
            {
                output.Write("[exp:");
                ExpectedType.WriteTo(output, ILNameSyntax.ShortTypeName);
                output.Write(']');
            }
            output.Write('(');
            bool first = true;

            if (Operand != null)
            {
                if (Operand is ILLabel)
                {
                    output.WriteReference(((ILLabel)Operand).Name, Operand);
                }
                else if (Operand is ILLabel[])
                {
                    ILLabel[] labels = (ILLabel[])Operand;
                    for (int i = 0; i < labels.Length; i++)
                    {
                        if (i > 0)
                        {
                            output.Write(", ");
                        }
                        output.WriteReference(labels[i].Name, labels[i]);
                    }
                }
                else if (Operand is MethodReference)
                {
                    MethodReference method = (MethodReference)Operand;
                    if (method.DeclaringType != null)
                    {
                        method.DeclaringType.WriteTo(output, ILNameSyntax.ShortTypeName);
                        output.Write("::");
                    }
                    output.WriteReference(method.Name, method);
                }
                else if (Operand is FieldReference)
                {
                    FieldReference field = (FieldReference)Operand;
                    field.DeclaringType.WriteTo(output, ILNameSyntax.ShortTypeName);
                    output.Write("::");
                    output.WriteReference(field.Name, field);
                }
                else
                {
                    DisassemblerHelpers.WriteOperand(output, Operand);
                }
                first = false;
            }
            foreach (ILExpression arg in Arguments)
            {
                if (!first)
                {
                    output.Write(", ");
                }
                arg.WriteTo(output);
                first = false;
            }
            output.Write(')');
        }
コード例 #3
0
        /// <summary>
        /// Write human readable output.
        /// </summary>
        public override void WriteTo(ITextOutput output)
        {
            if (Operand is AstVariable && ((AstVariable)Operand).IsGenerated)
            {
                if (Code == AstCode.Stloc && InferredType == null)
                {
                    output.Write(((AstVariable)Operand).Name);
                    output.Write(" = ");
                    Arguments.First().WriteTo(output);
                    return;
                }
                if (Code == AstCode.Ldloc)
                {
                    output.Write(((AstVariable)Operand).Name);
                    if (InferredType != null)
                    {
                        output.Write(':');
                        InferredType.WriteTo(output, AstNameSyntax.ShortTypeName);
                        if ((ExpectedType != null) && (ExpectedType.FullName != this.InferredType.FullName))
                        {
                            output.Write("[exp:");
                            ExpectedType.WriteTo(output, AstNameSyntax.ShortTypeName);
                            output.Write(']');
                        }
                    }
                    return;
                }
            }

            if (Prefixes != null)
            {
                foreach (var prefix in Prefixes)
                {
                    output.Write(prefix.Code.GetName());
                    output.Write(". ");
                }
            }

            output.Write(Code.GetName());
            if (InferredType != null)
            {
                output.Write(':');
                InferredType.WriteTo(output, AstNameSyntax.ShortTypeName);
                if ((ExpectedType != null) && (ExpectedType.FullName != InferredType.FullName))
                {
                    output.Write("[exp:");
                    ExpectedType.WriteTo(output, AstNameSyntax.ShortTypeName);
                    output.Write(']');
                }
            }
            else if (ExpectedType != null)
            {
                output.Write("[exp:");
                ExpectedType.WriteTo(output, AstNameSyntax.ShortTypeName);
                output.Write(']');
            }
            output.Write('(');
            var first = true;

            if (Operand != null)
            {
                if (Operand is AstLabel)
                {
                    output.WriteReference(((AstLabel)Operand).Name, Operand);
                }
                else if (Operand is AstLabel[])
                {
                    var labels = (AstLabel[])Operand;
                    for (var i = 0; i < labels.Length; i++)
                    {
                        if (i > 0)
                        {
                            output.Write(", ");
                        }
                        output.WriteReference(labels[i].Name, labels[i]);
                    }
                }
                else if (Operand is AstLabelKeyPair[])
                {
                    var pairs = (AstLabelKeyPair[])Operand;
                    for (var i = 0; i < pairs.Length; i++)
                    {
                        if (i > 0)
                        {
                            output.Write(", ");
                        }
                        output.Write("{0} -> ", pairs[i].Key);
                        output.WriteReference(pairs[i].Label.Name, pairs[i].Label);
                    }
                }
                else if (Operand is XMethodReference)
                {
                    var method = (XMethodReference)Operand;
                    if (method.DeclaringType != null)
                    {
                        method.DeclaringType.WriteTo(output, AstNameSyntax.ShortTypeName);
                        output.Write("::");
                    }
                    output.WriteReference(method.Name, method);
                }
                else if (Operand is XFieldReference)
                {
                    var field = (XFieldReference)Operand;
                    field.DeclaringType.WriteTo(output, AstNameSyntax.ShortTypeName);
                    output.Write("::");
                    output.WriteReference(field.Name, field);
                }
                else
                {
                    DisassemblerHelpers.WriteOperand(output, Operand);
                }
                first = false;
            }
            foreach (var arg in Arguments)
            {
                if (!first)
                {
                    output.Write(", ");
                }
                arg.WriteTo(output);
                first = false;
            }
            output.Write(')');
        }