Example #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);
            }
        }
Example #2
0
 public override void PrintPostIdentifierTo(ICodePrinter printer, PrintFlags flags)
 {
     if (fixedLength.HasValue)
     {
         printer.Print(OutputType.Operator, "[");
         printer.Print(OutputType.Literal, fixedLength.Value.ToString());
         printer.Print(OutputType.Operator, "]");
     }
 }
Example #3
0
        public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
        {
            Debug.Assert(printer != null && logPrinter != null);

            base.PrintTo(printer, logPrinter, flags);

            switch (arrayKind)
            {
            case ArrayKind.Invalid:
            {
                // void */PVOID
                PrimitiveNativeType.PrintNameTo(TypeName.Void, 1, printer, flags);
                break;
            }

            case ArrayKind.SafeArray:
            {
                // prefix with const if in-only
                if (isInOnly)
                {
                    printer.Print(OutputType.Keyword, "const");
                    printer.Print(OutputType.Other, " ");
                }

                // SAFEARRAY * or LPSAFEARRAY
                if ((flags & PrintFlags.UsePlainC) == PrintFlags.UsePlainC)
                {
                    TypeName.PrintTo(printer, TypeName.SafeArray.PlainC);
                    printer.Print(OutputType.Other, " ");
                    printer.Print(OutputType.Operator, "*");
                }
                else
                {
                    TypeName.PrintTo(printer, "LP" + TypeName.SafeArray.WinApi);
                }
                break;
            }

            default:
            {
                elementType.PrintTo(printer, logPrinter, flags);
                break;
            }
            }

            if (indirections > 0)
            {
                // We'll suppress the [] suffix in this case; one indirection will be provided by the
                // element itself because the ByRefParam flag has been inherited by it.
                int stars = indirections;

                while (stars-- > 0)
                {
                    printer.Print(OutputType.Operator, "*");
                }
            }
        }
Example #4
0
            public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
            {
                base.PrintTo(printer, logPrinter, flags);

                printer.Print(OutputType.Keyword, (definition.isUnion ? "union" : "struct"));
                printer.Print(OutputType.Other, " ");
                printer.Print(OutputType.Identifier, Name);
                printer.Print(OutputType.Operator, ";");
            }
Example #5
0
        public static void PrintTo(ICodePrinter printer, string typeNameStr)
        {
            // - words starting with upper-case letter are identifiers
            // - words starting with lower-case letter or underscore are keywords
            // - * is an operator
            // - space is 'other'

            StringBuilder sb   = new StringBuilder(typeNameStr.Length);
            OutputType    type = OutputType.Other;

            for (int i = 0; i < typeNameStr.Length; i++)
            {
                char ch = typeNameStr[i];

                OutputType new_type = type;
                switch (ch)
                {
                case ' ': new_type = OutputType.Other; break;

                case '*': new_type = OutputType.Operator; break;

                case '_': break;

                default:
                {
                    if (Char.IsLower(ch) && type != OutputType.TypeName)
                    {
                        new_type = OutputType.Keyword;
                    }
                    else if (Char.IsUpper(ch))
                    {
                        new_type = OutputType.TypeName;
                    }
                    break;
                }
                }

                if (new_type != type)
                {
                    if (sb.Length > 0)
                    {
                        printer.Print(type, sb.ToString());
                        sb.Length = 0;
                    }
                    type = new_type;
                }

                sb.Append(ch);
            }

            if (sb.Length > 0)
            {
                printer.Print(type, sb.ToString());
            }
        }
Example #6
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);
                }
            }
        }
Example #7
0
        protected internal static void PrintNameTo(TypeName typeName, int indirections, ICodePrinter printer, PrintFlags flags)
        {
            string output;

            if ((flags & PrintFlags.UsePlainC) == PrintFlags.UsePlainC)
            {
                output = typeName.PlainC;
            }
            else
            {
                output = typeName.WinApi;

                if (indirections > 0)
                {
                    switch (typeName.PointerPrefix)
                    {
                    case TypeName.PtrPrefix.P_Prefix:
                    {
                        output = "P" + output;
                        indirections--;
                        break;
                    }

                    case TypeName.PtrPrefix.LP_Prefix:
                    {
                        output = "LP" + output;
                        indirections--;
                        break;
                    }
                    }
                }
            }
            TypeName.PrintTo(printer, output);

            if (indirections > 0)
            {
                if (!output.EndsWith("*"))
                {
                    printer.Print(OutputType.Other, " ");
                }
                while (indirections-- > 0)
                {
                    printer.Print(OutputType.Operator, "*");
                }
            }
        }
Example #8
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, "};");
            }
        }
Example #9
0
            public void PrintPadding(int paddingSize, bool avoidLargerTypes)
            {
                Debug.Assert(paddingSize >= 0);

                if (paddingSize > 0)
                {
                    TypeName padding_type;

                    printer.PrintLn();

                    if (avoidLargerTypes)
                    {
                        padding_type = TypeName.I1;
                    }
                    else
                    {
                        switch (paddingSize)
                        {
                        case 2: padding_type = TypeName.I2; paddingSize = 1; break;

                        case 4: padding_type = TypeName.I4; paddingSize = 1; break;

                        case 8: padding_type = TypeName.I8; paddingSize = 1; break;

                        default:
                        {
                            padding_type = TypeName.I1;
                            break;
                        }
                        }
                    }

                    // {padding_type} _unused{paddingId}[{paddingSize}];
                    new PrimitiveNativeType(padding_type, false).PrintTo(printer, logPrinter, flags);

                    printer.Print(OutputType.Other, " ");
                    printer.Print(OutputType.Identifier, String.Format("_unused{0}", paddingId));

                    if (paddingSize > 1)
                    {
                        printer.Print(OutputType.Operator, "[");
                        printer.Print(OutputType.Literal, paddingSize.ToString());
                        printer.Print(OutputType.Operator, "]");
                    }

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

                    paddingId++;
                }
            }
Example #10
0
        public override void PrintPostIdentifierTo(ICodePrinter printer, PrintFlags flags)
        {
            switch (arrayKind)
            {
            case ArrayKind.Invalid:
            case ArrayKind.SafeArray:
            {
                // no post identifier output
                break;
            }

            case ArrayKind.NativeArray:
            {
                if (indirections == 0)
                {
                    // We can only use the [] suffix when this array is not indirected with a byref. In
                    // that case, we use two stars prefix instead, because
                    // <element_type> (*array)[] is NOT a pointer to array!

                    // empty brackets "[]"
                    printer.Print(OutputType.Operator, "[]");
                }
                break;
            }

            case ArrayKind.ByValArray:
            {
                // length-denoting brackets "[n]"
                printer.Print(OutputType.Operator, "[");
                printer.Print(OutputType.Literal, length.ToString());
                printer.Print(OutputType.Operator, "]");
                break;
            }
            }

            base.PrintPostIdentifierTo(printer, flags);
        }
Example #11
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, "};");
            }
        }
Example #12
0
            public void PrintTo(ICodePrinter printer, PrintFlags flags, ref decimal nextValue)
            {
                if ((flags & PrintFlags.MangleEnumFields) == PrintFlags.MangleEnumFields)
                {
                    printer.Print(OutputType.Identifier, "_" + Guid.NewGuid().ToString("N") + "_");
                }
                printer.Print(OutputType.Identifier, Name);

                if (Value != nextValue)
                {
                    printer.Print(OutputType.Other, " ");
                    printer.Print(OutputType.Operator, "=");
                    printer.Print(OutputType.Other, " ");

                    printer.Print(OutputType.Literal, Value.ToString());

                    nextValue = Value;
                }
                unchecked
                {
                    nextValue++;
                }
            }
Example #13
0
        protected internal static void PrintNameTo(TypeName typeName, int indirections, ICodePrinter printer, PrintFlags flags)
        {
            if (printer == null) throw new ArgumentNullException(nameof(printer));
            string output;

            if ((flags & PrintFlags.UsePlainC) == PrintFlags.UsePlainC)
            {
                output = typeName.PlainC;
            }
            else
            {
                output = typeName.WinApi;

                if (indirections > 0)
                {
                    switch (typeName.PointerPrefix)
                    {
                        case TypeName.PtrPrefix.P_Prefix:
                        {
                            output = "P" + output;
                            indirections--;
                            break;
                        }

                        case TypeName.PtrPrefix.LP_Prefix:
                        {
                            output = "LP" + output;
                            indirections--;
                            break;
                        }
                    }
                }
            }
            TypeName.PrintTo(printer, output);

            if (indirections > 0)
            {
                if (!output.EndsWith("*")) printer.Print(OutputType.Other, " ");
                while (indirections-- > 0)
                {
                    printer.Print(OutputType.Operator, "*");
                }
            }
        }
Example #14
0
        public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
        {
            printer.Print(OutputType.Identifier, "MIDL_INTERFACE");
            printer.Print(OutputType.Operator, "(");
            printer.Print(OutputType.Literal, Utility.StringToLiteral("FB6AB00F-5096-3AF8-A33D-D7885A5FA829"));
            printer.PrintLn(OutputType.Operator, ")");

            printer.Print(OutputType.TypeName, InterfaceName);
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Operator, ":");
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Keyword, "public");
            printer.Print(OutputType.Other, " ");
            printer.PrintLn(OutputType.TypeName, "IDispatch");

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

            printer.Print(OutputType.Keyword, "public");
            printer.PrintLn(OutputType.Operator, ":");

            printer.Print(OutputType.Other, "    ");
            printer.PrintLn(OutputType.Comment, "// methods omitted");

            printer.Print(OutputType.Other, "    ");
            printer.Print(OutputType.Keyword, "virtual");
            printer.Print(OutputType.Other, " ");

            new PrimitiveNativeType(TypeName.Error, platform64bit).PrintTo(printer, logPrinter, flags);
            printer.Print(OutputType.Other, " ");

            if ((flags & PrintFlags.UsePlainC) == PrintFlags.UsePlainC)
            {
                printer.Print(OutputType.Keyword, "__stdcall");
            }
            else
            {
                printer.Print(OutputType.TypeName, "STDMETHODCALLTYPE");
            }

            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Identifier, "DynamicInvoke");
            printer.Print(OutputType.Operator, "(");

            new PrimitiveNativeType(TypeName.SafeArray, 1, platform64bit).PrintTo(printer, logPrinter, flags);
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Identifier, "args");
            printer.Print(OutputType.Operator, ",");
            printer.Print(OutputType.Other, " ");

            new PrimitiveNativeType(TypeName.Variant, 1, platform64bit).PrintTo(printer, logPrinter, flags);
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Identifier, "pRetVal");
            printer.Print(OutputType.Operator, ")");

            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Operator, "=");
            printer.Print(OutputType.Other, " ");

            printer.Print(OutputType.Literal, "0");
            printer.PrintLn(OutputType.Operator, ";");

            printer.Print(OutputType.Operator, "};");
        }
Example #15
0
            public void PrintTo(ICodePrinter printer, PrintFlags flags, ref decimal nextValue)
            {
                if ((flags & PrintFlags.MangleEnumFields) == PrintFlags.MangleEnumFields)
                {
                    printer.Print(OutputType.Identifier, "_" + Guid.NewGuid().ToString("N") + "_");
                }
                printer.Print(OutputType.Identifier, Name);

                if (Value != nextValue)
                {
                    printer.Print(OutputType.Other, " ");
                    printer.Print(OutputType.Operator, "=");
                    printer.Print(OutputType.Other, " ");

                    printer.Print(OutputType.Literal, Value.ToString());

                    nextValue = Value;
                }
                unchecked
                {
                    nextValue++;
                }
            }
Example #16
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);
            }
        }
Example #17
0
            public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
            {
                if (printer == null) throw new ArgumentNullException(nameof(printer));
                base.PrintTo(printer, logPrinter, flags);

                printer.Print(OutputType.Keyword, "struct");
                printer.Print(OutputType.Other, " ");
                printer.Print(OutputType.Identifier, Name);
                printer.Print(OutputType.Operator, ";");
            }
Example #18
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);
            }
        }
Example #19
0
        public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
        {
            if (printer == null) throw new ArgumentNullException(nameof(printer));
            printer.Print(OutputType.Identifier, "MIDL_INTERFACE");
            printer.Print(OutputType.Operator, "(");
            printer.Print(OutputType.Literal, Utility.StringToLiteral("FB6AB00F-5096-3AF8-A33D-D7885A5FA829"));
            printer.PrintLn(OutputType.Operator, ")");

            printer.Print(OutputType.TypeName, InterfaceName);
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Operator, ":");
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Keyword, "public");
            printer.Print(OutputType.Other, " ");
            printer.PrintLn(OutputType.TypeName, "IDispatch");

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

            printer.Print(OutputType.Keyword, "public");
            printer.PrintLn(OutputType.Operator, ":");

            printer.Print(OutputType.Other, "    ");
            printer.PrintLn(OutputType.Comment, "// methods omitted");

            printer.Print(OutputType.Other, "    ");
            printer.Print(OutputType.Keyword, "virtual");
            printer.Print(OutputType.Other, " ");

            new PrimitiveNativeType(TypeName.Error, platform64bit).PrintTo(printer, logPrinter, flags);
            printer.Print(OutputType.Other, " ");

            if ((flags & PrintFlags.UsePlainC) == PrintFlags.UsePlainC)
                printer.Print(OutputType.Keyword, "__stdcall");
            else
                printer.Print(OutputType.TypeName, "STDMETHODCALLTYPE");

            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Identifier, "DynamicInvoke");
            printer.Print(OutputType.Operator, "(");

            new PrimitiveNativeType(TypeName.SafeArray, 1, platform64bit).PrintTo(printer, logPrinter, flags);
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Identifier, "args");
            printer.Print(OutputType.Operator, ",");
            printer.Print(OutputType.Other, " ");

            new PrimitiveNativeType(TypeName.Variant, 1, platform64bit).PrintTo(printer, logPrinter, flags);
            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Identifier, "pRetVal");
            printer.Print(OutputType.Operator, ")");

            printer.Print(OutputType.Other, " ");
            printer.Print(OutputType.Operator, "=");
            printer.Print(OutputType.Other, " ");

            printer.Print(OutputType.Literal, "0");
            printer.PrintLn(OutputType.Operator, ";");

            printer.Print(OutputType.Operator, "};");
        }
Example #20
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();
            }
        }
Example #21
0
        public override void PrintPostIdentifierTo(ICodePrinter printer, PrintFlags flags)
        {
            switch (arrayKind)
            {
                case ArrayKind.Invalid:
                case ArrayKind.SafeArray:
                {
                    // no post identifier output
                    break;
                }

                case ArrayKind.NativeArray:
                {
                    if (indirections == 0)
                    {
                        // We can only use the [] suffix when this array is not indirected with a byref. In
                        // that case, we use two stars prefix instead, because
                        // <element_type> (*array)[] is NOT a pointer to array!

                        // empty brackets "[]"
                        printer.Print(OutputType.Operator, "[]");
                    }
                    break;
                }

                case ArrayKind.ByValArray:
                {
                    // length-denoting brackets "[n]"
                    printer.Print(OutputType.Operator, "[");
                    printer.Print(OutputType.Literal, length.ToString());
                    printer.Print(OutputType.Operator, "]");
                    break;
                }
            }

            base.PrintPostIdentifierTo(printer, flags);
        }
Example #22
0
        public static void PrintTo(ICodePrinter printer, string typeNameStr)
        {
            if (printer == null) throw new ArgumentNullException(nameof(printer));
            if (typeNameStr == null) throw new ArgumentNullException(nameof(typeNameStr));
            // - words starting with upper-case letter are identifiers
            // - words starting with lower-case letter or underscore are keywords
            // - * is an operator
            // - space is 'other'

            var sb = new StringBuilder(typeNameStr.Length);
            OutputType type = OutputType.Other;

            for (int i = 0; i < typeNameStr.Length; i++)
            {
                char ch = typeNameStr[i];

                OutputType new_type = type;
                switch (ch)
                {
                    case ' ': new_type = OutputType.Other; break;
                    case '*': new_type = OutputType.Operator; break;
                    case '_': break;

                    default:
                    {
                        if (Char.IsLower(ch) && type != OutputType.TypeName) new_type = OutputType.Keyword;
                        else if (Char.IsUpper(ch)) new_type = OutputType.TypeName;
                        break;
                    }
                }

                if (new_type != type)
                {
                    if (sb.Length > 0)
                    {
                        printer.Print(type, sb.ToString());
                        sb.Length = 0;
                    }
                    type = new_type;
                }

                sb.Append(ch);
            }

            if (sb.Length > 0) printer.Print(type, sb.ToString());
        }
Example #23
0
 public override void PrintPostIdentifierTo(ICodePrinter printer, PrintFlags flags)
 {
     if (printer == null) throw new ArgumentNullException(nameof(printer));
     if (fixedLength.HasValue)
     {
         printer.Print(OutputType.Operator, "[");
         printer.Print(OutputType.Literal, fixedLength.Value.ToString());
         printer.Print(OutputType.Operator, "]");
     }
 }
Example #24
0
        public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags)
        {
            Debug.Assert(printer != null && logPrinter != null);

            base.PrintTo(printer, logPrinter, flags);

            switch (arrayKind)
            {
                case ArrayKind.Invalid:
                {
                    // void */PVOID
                    PrimitiveNativeType.PrintNameTo(TypeName.Void, 1, printer, flags);
                    break;
                }

                case ArrayKind.SafeArray:
                {
                    // prefix with const if in-only
                    if (isInOnly)
                    {
                        printer.Print(OutputType.Keyword, "const");
                        printer.Print(OutputType.Other, " ");
                    }

                    // SAFEARRAY * or LPSAFEARRAY
                    if ((flags & PrintFlags.UsePlainC) == PrintFlags.UsePlainC)
                    {
                        TypeName.PrintTo(printer, TypeName.SafeArray.PlainC);
                        printer.Print(OutputType.Other, " ");
                        printer.Print(OutputType.Operator, "*");
                    }
                    else
                    {
                        TypeName.PrintTo(printer, "LP" + TypeName.SafeArray.WinApi);
                    }
                    break;
                }

                default:
                {
                    elementType.PrintTo(printer, logPrinter, flags);
                    break;
                }
            }

            if (indirections > 0)
            {
                // We'll suppress the [] suffix in this case; one indirection will be provided by the
                // element itself because the ByRefParam flag has been inherited by it.
                int stars = indirections;

                while (stars-- > 0) printer.Print(OutputType.Operator, "*");
            }
        }
Example #25
0
 public override void PrintPostIdentifierTo(ICodePrinter printer, PrintFlags flags)
 {
     if (fixedLength.HasValue)
     {
         printer.Print(OutputType.Operator, "[");
         printer.Print(OutputType.Literal, fixedLength.Value.ToString());
         printer.Print(OutputType.Operator, "]");
     }
 }