コード例 #1
0
 /// <summary>
 /// Increments the indentation level. Nothing is added to the output stream.
 /// </summary>
 public virtual void IncreaseIndent() => indenter.IncreaseIndent();
コード例 #2
0
 public void IncreaseIndent()
 {
     VerifyState(State.GeneratingContent);
     indenter.IncreaseIndent();
 }
コード例 #3
0
 void IDecompilerOutput.IncreaseIndent() => indenter.IncreaseIndent();
コード例 #4
0
        public static bool Fits(
            PrintCommand nextCommand,
            Stack <PrintCommand> remainingCommands,
            int remainingWidth,
            Dictionary <string, PrintMode> groupModeMap,
            Indenter indenter
            )
        {
            var returnFalseIfMoreStringsFound = false;
            var newCommands = new Stack <PrintCommand>();

            newCommands.Push(nextCommand);

            void Push(Doc doc, PrintMode printMode, Indent indent)
            {
                newCommands.Push(new PrintCommand(indent, printMode, doc));
            }

            var output = new StringBuilder();

            for (var x = 0; x < remainingCommands.Count || newCommands.Count > 0;)
            {
                if (remainingWidth < 0)
                {
                    return(false);
                }

                PrintCommand command;
                if (newCommands.Count > 0)
                {
                    command = newCommands.Pop();
                }
                else
                {
                    command = remainingCommands.ElementAt(x);
                    x++;
                }

                var(currentIndent, currentMode, currentDoc) = command;

                if (currentDoc is StringDoc stringDoc)
                {
                    if (stringDoc.Value == null)
                    {
                        continue;
                    }

                    if (returnFalseIfMoreStringsFound)
                    {
                        return(false);
                    }

                    output.Append(stringDoc.Value);
                    remainingWidth -= stringDoc.Value.GetPrintedWidth();
                }
                else if (currentDoc != Doc.Null)
                {
                    switch (currentDoc)
                    {
                    case LeadingComment:
                    case TrailingComment:
                        if (output.Length > 0)
                        {
                            returnFalseIfMoreStringsFound = true;
                        }
                        break;

                    case Concat concat:
                        for (var i = concat.Contents.Count - 1; i >= 0; i--)
                        {
                            Push(concat.Contents[i], currentMode, currentIndent);
                        }
                        break;

                    case IndentDoc indent:
                        Push(
                            indent.Contents,
                            currentMode,
                            indenter.IncreaseIndent(currentIndent)
                            );
                        break;

                    case Trim:
                        remainingWidth += output.TrimTrailingWhitespace();
                        break;

                    case Group group:
                        var groupMode = group.Break ? PrintMode.Break : currentMode;

                        // when determining if something fits, use the last option from a conditionalGroup, which should be the most expanded one
                        var groupContents = groupMode == PrintMode.Break &&
                                            group
                                            is ConditionalGroup conditionalGroup
                                ? conditionalGroup.Options.Last()
                                : group.Contents;

                        Push(groupContents, groupMode, currentIndent);

                        if (group.GroupId != null)
                        {
                            groupModeMap ![group.GroupId] = groupMode;