private bool PrintBracedBlockOrStmt(LNode stmt, Ambiguity flags, NewlineOpt beforeBrace = NewlineOpt.BeforeExecutableBrace) { var name = stmt.Name; if (name == S.Braces && !HasPAttrs(stmt) && HasSimpleHeadWPA(stmt)) { PrintBracedBlock(stmt, beforeBrace); return(true); } // Detect "else if (...)", and suppress newline/indent between "else" and "if". if (name == S.If && (flags & Ambiguity.ElseClause) != 0) { using (With(stmt)) if (EcsValidators.OtherBlockStmtType(_n, Pedantics) == S.If) { PrintStmt(flags & (Ambiguity.FinalStmt | Ambiguity.ElseClause)); return(false); } } using (Indented) { Newline(NewlineOpt.BeforeSingleSubstmt); PrintStmt(stmt, flags & (Ambiguity.FinalStmt | Ambiguity.NoIfWithoutElse)); return(false); } }
private void PrintExpressionsInBraces(LNode body, bool isInitializer, Ambiguity flags) { bool anyNewlines = false; using (Indented) { NewlineOpt nlo = isInitializer ? NewlineOpt.AfterOpenBraceInNewExpr : NewlineOpt.Minimal | NewlineOpt.BeforeEachEnumItem; NewlineOpt next_nlo = isInitializer ? NewlineOpt.AfterEachInitializer : NewlineOpt.BeforeEachEnumItem; for (int i = 0, c = body.ArgCount; i < c; i++) { var stmt = body.Args[i]; if (i != 0) { _out.Write(','); nlo = next_nlo; } if (NewlineOrSpace(nlo, IsDefaultNewlineSuppressed(stmt), SpaceOpt.AfterComma)) { anyNewlines = true; } PrintExpr(stmt, StartExpr, flags); } } NewlineOrSpace(isInitializer ? NewlineOpt.BeforeCloseBraceInExpr : NewlineOpt.Default, !anyNewlines); }
private void PrintExpressionsInBraces(LNode body, bool isInitializer) { bool anyNewlines = false; using (Indented) { int i = 0, c = body.ArgCount; if (isInitializer) { for (; i < c; i++) { var stmt = body.Args[i]; NewlineOpt nlo = NewlineOpt.AfterOpenBraceInNewExpr; if (i != 0) { _out.Write(',', true); nlo = NewlineOpt.AfterEachInitializer; } if (NewlineOrSpace(nlo, IsDefaultNewlineSuppressed(stmt), SpaceOpt.AfterComma)) { anyNewlines = true; } PrintExpr(stmt, StartExpr); } } else // enum body { for (; i < c; i++) { var stmt = body.Args[i]; NewlineOpt nlo = NewlineOpt.Minimal | NewlineOpt.BeforeEachEnumItem; if (i != 0) { _out.Write(',', true); nlo = NewlineOpt.BeforeEachEnumItem; } if (NewlineOrSpace(nlo, IsDefaultNewlineSuppressed(stmt), SpaceOpt.AfterComma)) { anyNewlines = true; } PrintExpr(stmt, StartExpr); } } } NewlineOrSpace(isInitializer ? NewlineOpt.BeforeCloseBraceInExpr : NewlineOpt.Default, !anyNewlines); }
private void PrintBracedBlock(LNode body, NewlineOpt beforeBrace, bool skipFirstStmt = false, Symbol spaceName = null) { if (beforeBrace != 0) { if (!Newline(beforeBrace)) { Space(SpaceOpt.Default); } } _out.Write('{', true); using (WithSpace(spaceName)) using (Indented) for (int i = (skipFirstStmt?1:0), c = body.ArgCount; i < c; i++) { PrintStmt(body.Args[i], i + 1 == c ? Ambiguity.FinalStmt : 0); } Newline(NewlineOpt.Default); _out.Write('}', true); }
private void PrintBracedBlock(LNode body, NewlineOpt beforeBrace, bool skipFirstStmt = false, Symbol spaceName = null, BraceMode mode = BraceMode.Normal) { using (WithFlags(CheckOneLiner(_flags, body))) { int oldLineNum = _out.LineNumber; if (mode != BraceMode.BlockStmt) { PrintTrivia(body, trailingTrivia: false); } else { G.Verify(PrintAttrs(AttrStyle.AllowKeywordAttrs) == 0); } if (oldLineNum == _out.LineNumber && beforeBrace != 0) { NewlineOrSpace(beforeBrace, IsDefaultNewlineSuppressed(body)); } _out.Write('{', true); // body.Target represents the opening brace. Injector adds trailing trivia only, not leading PrintTrivia(body.Target, trailingTrivia: true); using (WithSpace(spaceName)) { if (mode == BraceMode.Initializer || mode == BraceMode.Enum) { Debug.Assert(!skipFirstStmt); PrintExpressionsInBraces(body, mode == BraceMode.Initializer); } else { PrintStatementsInBraces(body, skipFirstStmt, newlinesByDefault: mode != BraceMode.AutoProp); } } _out.Write('}', true); if (mode != BraceMode.BlockStmt) { PrintTrivia(body, trailingTrivia: true); } } }
private void PrintBracedBlock(LNode body, NewlineOpt beforeBrace, bool skipFirstStmt = false, Symbol spaceName = null, BraceMode mode = BraceMode.Normal) { if (mode != BraceMode.BlockExpr) { if (mode != BraceMode.BlockStmt) { PrintTrivia(body, trailingTrivia: false); } else { G.Verify(PrintAttrs(AttrStyle.AllowKeywordAttrs) == 0); } if (!_out.LastCharWritten.IsOneOf('\n', ' ', '\t') && beforeBrace != 0) { NewlineOrSpace(beforeBrace, IsDefaultNewlineSuppressed(body)); } } _out.Write('{'); // body.Target represents the opening brace. Injector adds trailing trivia only, not leading PrintTrivia(body.Target, trailingTrivia: true); using (WithSpace(spaceName)) { if (mode == BraceMode.Initializer || mode == BraceMode.Enum || mode == BraceMode.SwitchExpression) { Debug.Assert(!skipFirstStmt); PrintExpressionsInBraces(body, mode == BraceMode.Initializer, mode == BraceMode.SwitchExpression ? Ambiguity.InSwitchExpr : 0); } else { PrintStatementsInBraces(body, skipFirstStmt, newlinesByDefault: mode != BraceMode.AutoProp); } } _out.Write('}'); if (mode != BraceMode.BlockStmt) { PrintTrivia(body, trailingTrivia: true); } }
// Prints a child statement that could be a braced block, or not private bool PrintBracedBlockOrStmt(LNode child, NewlineOpt beforeBrace = NewlineOpt.BeforeExecutableBrace) { var name = child.Name; if (name == S.Braces && !HasPAttrs(child) && HasSimpleHeadWPA(child)) { PrintBracedBlock(child, beforeBrace); return(true); } // Detect "else if (...)", and suppress newline/indent between "else" and "if". if (name == S.If && Flagged(Ambiguity.ElseClause)) { if (EcsValidators.OtherBlockStmtType(_n, Pedantics) == S.If) { PrintStmt(child, _flags & (Ambiguity.FinalStmt | Ambiguity.ElseClause | Ambiguity.OneLiner)); return(false); } } using (Indented) { PrintStmt(child, _flags & (Ambiguity.FinalStmt | Ambiguity.NoIfWithoutElse | Ambiguity.OneLiner) | Ambiguity.NewlineBeforeChildStmt); return(false); } }
private void PrintBracedBlock(LNode body, NewlineOpt beforeBrace, bool skipFirstStmt = false, Symbol spaceName = null, BraceMode mode = BraceMode.Normal) { using (WithFlags(CheckOneLiner(_flags, body))) { int oldLineNum = _out.LineNumber; if (mode != BraceMode.BlockStmt) PrintTrivia(body, trailingTrivia: false); else G.Verify(PrintAttrs(AttrStyle.AllowKeywordAttrs) == 0); if (oldLineNum == _out.LineNumber && beforeBrace != 0) NewlineOrSpace(beforeBrace, IsDefaultNewlineSuppressed(body)); _out.Write('{', true); // body.Target represents the opening brace. Injector adds trailing trivia only, not leading PrintTrivia(body.Target, trailingTrivia: true); using (WithSpace(spaceName)) { if (mode == BraceMode.Initializer || mode == BraceMode.Enum) { Debug.Assert(!skipFirstStmt); PrintExpressionsInBraces(body, mode == BraceMode.Initializer); } else PrintStatementsInBraces(body, skipFirstStmt, newlinesByDefault: mode != BraceMode.AutoProp); } _out.Write('}', true); if (mode != BraceMode.BlockStmt) PrintTrivia(body, trailingTrivia: true); } }
// Prints a child statement that could be a braced block, or not private bool PrintBracedBlockOrStmt(LNode child, NewlineOpt beforeBrace = NewlineOpt.BeforeExecutableBrace) { var name = child.Name; if (name == S.Braces && !HasPAttrs(child) && HasSimpleHeadWPA(child)) { PrintBracedBlock(child, beforeBrace); return true; } // Detect "else if (...)", and suppress newline/indent between "else" and "if". if (name == S.If && Flagged(Ambiguity.ElseClause)) { if (EcsValidators.OtherBlockStmtType(_n, Pedantics) == S.If) { PrintStmt(child, _flags & (Ambiguity.FinalStmt | Ambiguity.ElseClause | Ambiguity.OneLiner)); return false; } } using (Indented) { PrintStmt(child, _flags & (Ambiguity.FinalStmt | Ambiguity.NoIfWithoutElse | Ambiguity.OneLiner) | Ambiguity.NewlineBeforeChildStmt); return false; } }
private void PrintBracedBlock(LNode body, NewlineOpt beforeBrace, bool skipFirstStmt = false, Symbol spaceName = null) { if (beforeBrace != 0) if (!Newline(beforeBrace)) Space(SpaceOpt.Default); _out.Write('{', true); using (WithSpace(spaceName)) using (Indented) for (int i = (skipFirstStmt?1:0), c = body.ArgCount; i < c; i++) PrintStmt(body.Args[i], i + 1 == c ? Ambiguity.FinalStmt : 0); Newline(NewlineOpt.Default); _out.Write('}', true); }
private bool PrintBracedBlockOrStmt(LNode stmt, Ambiguity flags, NewlineOpt beforeBrace = NewlineOpt.BeforeExecutableBrace) { var name = stmt.Name; if (name == S.Braces && !HasPAttrs(stmt) && HasSimpleHeadWPA(stmt)) { PrintBracedBlock(stmt, beforeBrace); return true; } // Detect "else if (...)", and suppress newline/indent between "else" and "if". if (name == S.If && (flags & Ambiguity.ElseClause) != 0) { using (With(stmt)) if (OtherBlockStmtType() == S.If) { PrintStmt(flags & (Ambiguity.FinalStmt | Ambiguity.ElseClause)); return false; } } using (Indented) { Newline(NewlineOpt.BeforeSingleSubstmt); PrintStmt(stmt, flags & (Ambiguity.FinalStmt | Ambiguity.NoIfWithoutElse)); return false; } }