Пример #1
0
        public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
        {
            Debug.Assert(printer != null && logPrinter != null && signature != null);

            if (hasForwardDeclaration)
            {
                printer.Print(OutputType.Keyword, "struct");
                printer.Print(OutputType.Other, " ");
                printer.PrintLn(OutputType.Identifier, Name);

                printer.Indent();
                printer.PrintLn(OutputType.Operator, "{");

                // will print "ret_type (call_conv *ptr)(params)"
                signature.PrintTo(printer, logPrinter, flags);

                printer.Unindent();
                printer.PrintLn();
                printer.Print(OutputType.Operator, "};");
            }
            else
            {
                printer.Print(OutputType.Keyword, "typedef");
                printer.Print(OutputType.Other, " ");

                // will print "ret_type (call_conv *name)(params)"
                signature.PrintTo(printer, logPrinter, flags);
            }
        }
Пример #2
0
        public void ReplayTo(ICodePrinter anotherPrinter)
        {
            Debug.Assert(anotherPrinter != null && anotherPrinter != this);

            foreach (PrintEntry entry in list)
            {
                if (entry.OutputType == OutputType.End__)
                {
                    if (ReferenceEquals(entry.String, IndentMarker))
                    {
                        anotherPrinter.Indent();
                    }
                    else if (ReferenceEquals(entry.String, UnindentMarker))
                    {
                        anotherPrinter.Unindent();
                    }
                    else
                    {
                        Debug.Assert(ReferenceEquals(entry.String, NewLineMarker));
                        anotherPrinter.PrintLn();
                    }
                }
                else
                {
                    anotherPrinter.Print(entry.OutputType, entry.String);
                }
            }
        }
Пример #3
0
        public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
        {
            Debug.Assert(printer != null && logPrinter != null && fields != null);

            printer.Print(OutputType.Keyword, "enum");
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.TypeName, name);
            printer.Print(OutputType.Other, " ");

            // always explicitly print the underlying type
            printer.Print(OutputType.Operator, ":");
            printer.Print(OutputType.Other, " ");

            underlyingType.PrintTo(printer, logPrinter, flags);

            printer.PrintLn();

            printer.Indent();
            printer.Print(OutputType.Operator, "{");
            try
            {
                decimal next_value = 0;
                for (int i = 0; i < fields.Length; i++)
                {
                    // field name [ = field value ][,]
                    printer.PrintLn();

                    if (isFlagsEnum)
                    {
                        // explicitly list all field values for [Flags] enums
                        next_value = Decimal.MaxValue;
                    }
                    fields[i].PrintTo(printer, flags, ref next_value);

                    if (i < fields.Length - 1)
                    {
                        // comma after all but the last field
                        printer.Print(OutputType.Operator, ",");
                    }
                }
            }
            finally
            {
                printer.Unindent();

                printer.PrintLn();
                printer.Print(OutputType.Operator, "};");
            }
        }
Пример #4
0
        public void ReplayTo(ICodePrinter anotherPrinter)
        {
            Debug.Assert(anotherPrinter != null && anotherPrinter != this);

            foreach (PrintEntry entry in list)
            {
                if (entry.OutputType == OutputType.End__)
                {
                    if (ReferenceEquals(entry.String, IndentMarker)) anotherPrinter.Indent();
                    else if (ReferenceEquals(entry.String, UnindentMarker)) anotherPrinter.Unindent();
                    else
                    {
                        Debug.Assert(ReferenceEquals(entry.String, NewLineMarker));
                        anotherPrinter.PrintLn();
                    }
                }
                else
                    anotherPrinter.Print(entry.OutputType, entry.String);
            }
        }
Пример #5
0
        public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
        {
            if (printer == null) throw new ArgumentNullException(nameof(printer));
            if (logPrinter == null) throw new ArgumentNullException(nameof(logPrinter));
            Debug.Assert(signature != null);

            if (hasForwardDeclaration)
            {
                printer.Print(OutputType.Keyword, "struct");
                printer.Print(OutputType.Other, " ");
                printer.PrintLn(OutputType.Identifier, Name);

                printer.Indent();
                printer.PrintLn(OutputType.Operator, "{");

                // will print "ret_type (call_conv *ptr)(params)"
                signature.PrintTo(printer, logPrinter, flags);

                printer.Unindent();
                printer.PrintLn();
                printer.Print(OutputType.Operator, "};");
            }
            else
            {
                printer.Print(OutputType.Keyword, "typedef");
                printer.Print(OutputType.Other, " ");

                // will print "ret_type (call_conv *name)(params)"
                signature.PrintTo(printer, logPrinter, flags);
            }
        }
Пример #6
0
        public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
        {
            Debug.Assert(printer != null && logPrinter != null);

            base.PrintTo(printer, logPrinter, flags);

            PrintContext context = new PrintContext(printer, logPrinter, flags);

            if (unalignedSizeOrOffsets)
            {
                // the size of the structure or field offsets is "odd" -> need to pragma pack (1) it
                context.SetPack(1, true);
            }
            else
            {
                context.SetPack(DefaultPack, true);
            }

            if (!isUnion)
            {
                printer.PrintLn();

                printer.Print(OutputType.Keyword, "struct");
                PrintIdentifierAndSize(context);

                printer.Print(OutputType.Operator, "{");

                printer.Indent();
            }

            try
            {
                if (!isInvalid)
                {
                    int current_offset = 0;

                    for (int i = 0; i < fields.Length; i++)
                    {
                        if (isExplicitLayout)
                        {
                            // this may in fact print more fields in a union, so i is passed byref
                            PrintExplicitlyLaidOutField(context, ref i, ref current_offset);
                        }
                        else
                        {
                            PrintSequentiallyLaidOutField(context, i, ref current_offset);
                        }
                    }

                    int tmp_offset = current_offset;
                    if (!context.UsedNonDefaultPack)
                    {
                        // if we never used a pack different from the default (8), we are sure
                        // about the implicit padding at the end of the structure
                        AlignSelf(ref tmp_offset);
                    }

                    if (size != tmp_offset)
                    {
                        // add final padding to the end of the structure to make its size exactly as requested
                        context.PrintPadding(size - current_offset, context.UsedNonDefaultPack);
                    }
                }
            }
            finally
            {
                if (!isUnion)
                {
                    printer.Unindent();
                    printer.PrintLn();

                    printer.Print(OutputType.Operator, "};");
                }

                context.SetDefaultPack();
            }
        }
Пример #7
0
        public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
        {
            if (printer == null) throw new ArgumentNullException(nameof(printer));
            if (logPrinter == null) throw new ArgumentNullException(nameof(logPrinter));
            Debug.Assert(fields != null);

            printer.Print(OutputType.Keyword, "enum");
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.TypeName, name);
            printer.Print(OutputType.Other, " ");

            // always explicitly print the underlying type
            printer.Print(OutputType.Operator, ":");
            printer.Print(OutputType.Other, " ");

            underlyingType.PrintTo(printer, logPrinter, flags);

            printer.PrintLn();

            printer.Indent();
            printer.Print(OutputType.Operator, "{");
            try
            {
                decimal next_value = 0;
                for (int i = 0; i < fields.Length; i++)
                {
                    // field name [ = field value ][,]
                    printer.PrintLn();

                    if (isFlagsEnum)
                    {
                        // explicitly list all field values for [Flags] enums
                        next_value = Decimal.MaxValue;
                    }
                    fields[i].PrintTo(printer, flags, ref next_value);

                    if (i < fields.Length - 1)
                    {
                        // comma after all but the last field
                        printer.Print(OutputType.Operator, ",");
                    }
                }
            }
            finally
            {
                printer.Unindent();

                printer.PrintLn();
                printer.Print(OutputType.Operator, "};");
            }
        }