private bool AutoPrintBracesOrBracks(ILNode node, Precedence context) { var name = node.Name; if (name == S.Array && node.IsCall() && !HasPAttrs(node.Target)) { PrintArgList(node.Args(), node.BaseStyle() == NodeStyle.StatementBlock, "[", ']', null, node.Target); return(true); } else if (name == S.Tuple && node.ArgCount() != 1 && node.IsCall() && !HasPAttrs(node.Target)) { PrintArgList(node.Args(), node.BaseStyle() == NodeStyle.StatementBlock, "(", ')', "; ", node.Target); return(true); } else if (name == S.Braces && node.IsCall() && !HasPAttrs(node.Target)) { if (context.Lo == StartStmt.Lo) { _out.Dedent(PrinterIndentHint.Subexpression).Indent(PrinterIndentHint.NoIndent); } PrintArgList(node.Args(), node.BaseStyle() != NodeStyle.Expression, "{", '}', null, node.Target); return(true); } return(false); }
internal void Print(ILNode node, Precedence context, string terminator = null) { bool old_isOneLiner = _isOneLiner; _isOneLiner |= (node.Style & NodeStyle.OneLiner) != 0; try { int parenCount = WriteAttrs(node, ref context); if (!node.IsCall() || node.BaseStyle() == NodeStyle.PrefixNotation) { PrintPrefixNotation(node, context); } else { do { if (AutoPrintBracesOrBracks(node)) { break; } if (!LesPrecedence.Primary.CanAppearIn(context)) { _out.Write("(@[] ", true); parenCount++; context = StartStmt; } int args = node.ArgCount(); if (args == 1 && AutoPrintPrefixOrSuffixOp(node, context)) { break; } if (args == 2 && AutoPrintInfixOp(node, context)) { break; } PrintPrefixNotation(node, context); } while (false); } PrintSuffixTrivia(node, parenCount, terminator); } finally { _isOneLiner = old_isOneLiner; } }
/// <summary>Top-level non-static printing method</summary> internal void Print(ILNode node, Precedence context, string terminator = null) { _out.BeginNode(node); int parenCount = WriteAttrs(node, ref context); _out.FlushIndent().Indent(PrinterIndentHint.Subexpression); if (!node.IsCall() || node.BaseStyle() == NodeStyle.PrefixNotation) { PrintPrefixNotation(node, context); } else { do { if (AutoPrintBracesOrBracks(node, context)) { break; } if (!LesPrecedence.Primary.CanAppearIn(context)) { _out.WriteOpening("(@[] "); parenCount++; context = StartSubexpr; } int args = node.ArgCount(); if (args == 1 && AutoPrintPrefixOrSuffixOp(node, context)) { break; } if (args == 2 && AutoPrintInfixOp(node, context)) { break; } PrintPrefixNotation(node, context); } while (false); } _out.Dedent(); PrintSuffixTrivia(node, parenCount, terminator); _out.EndNode(); }
private Precedence?GetPrecedenceIfOperator(ILNode node, Symbol opName, OperatorShape shape, Precedence context) { int ac = node.ArgCount(); if ((ac == (int)shape || ac == -(int)shape) && HasTargetIdWithoutPAttrs(node)) { var bs = node.BaseStyle(); bool naturalOp = Les2PrecedenceMap.IsNaturalOperator(opName.Name); if ((naturalOp && bs != NodeStyle.PrefixNotation) || (bs == NodeStyle.Operator && node.Name != null)) { var result = _prec.Find(shape, opName); if (!result.CanAppearIn(context) || !result.CanMixWith(context)) { return(null); } return(result); } } return(null); }