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); } }
/// <summary> /// Prints preview of all methods under the specified node to the provided printers according to the current settings. /// </summary> private void PrintMethodPreview(TreeNode node, ICodePrinter printer, ILogPrinter logPrinter, bool printDefs, bool defsFirst) { // this can take some time - try to not appear hung int tick_count1 = Environment.TickCount; int tick_count2 = unchecked (tick_count1 + 1); Cursor original_cursor = Cursor.Current; // this is a node representing a type - get signatures of all its methods ILogPrinter mem_log = new LogMemoryPrinter(); bool first = true; try { foreach (TreeNode child in node.Nodes) { MethodDescriptor method_descr = child.Tag as MethodDescriptor; if (method_descr != null) { if (!first) { codePrinter.PrintLn(); codePrinter.PrintLn(); } else { first = false; } // print no messages and no definitions PrintMethod(method_descr, codePrinter, mem_log, printDefs, defsFirst); int ticks = Environment.TickCount; if (ticks != tick_count1 && ticks != tick_count2) { // it's taking too long tick_count1 = Environment.TickCount; tick_count2 = unchecked (tick_count1 + 1); Application.DoEvents(); // re-set the selection on rich text box controls because DoEvents may have // included some undesired user input richTextBoxCode.Select(richTextBoxCode.TextLength, 0); richTextBoxMessages.Select(richTextBoxMessages.TextLength, 0); Cursor.Current = Cursors.WaitCursor; } } } } finally { Cursor.Current = original_cursor; } logPrinter.PrintEntry( Severity.Info, 0, "Please select an individual method in the tree to view additional information."); }
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++; } }
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, "};"); } }
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); } } }
/// <summary> /// Prints a native signature to the provided printers according to the current settings. /// </summary> private void PrintSignature(SignatureGenerator.NativeSignature nativeSig, ICodePrinter printer, ILogPrinter logPrinter, bool printDefs, bool defsFirst) { PrintFlags p_flags = PrintFlags.None; if (plainCTypesToolStripMenuItem.Checked) { p_flags |= PrintFlags.UsePlainC; } if (marshalDirectionAnnotationsToolStripMenuItem.Checked) { p_flags |= PrintFlags.PrintMarshalDirection; } if (!defsFirst) { nativeSig.PrintTo(printer, logPrinter, p_flags); } if (printDefs) { foreach (NativeTypeDefinition def in nativeSig.GetDefinitions()) { if (defsFirst) { def.PrintTo(printer, logPrinter, p_flags); } printer.PrintLn(); printer.PrintLn(); if (!defsFirst) { def.PrintTo(printer, logPrinter, p_flags); } } } if (defsFirst) { nativeSig.PrintTo(printer, logPrinter, p_flags); } }
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); } }
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); } }
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, "};"); }
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(); } }
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, "};"); } }
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, "};"); }