TwoArgBlockStmtType() static private method

static private TwoArgBlockStmtType ( LNode _n, Pedantics p ) : Symbol
_n LNode
p Pedantics
return Symbol
示例#1
0
        public SPResult AutoPrintTwoArgBlockStmt()
        {
            // S.Do, S.Fixed, S.Lock, S.Switch, S.UsingStmt, S.While
            var type = EcsValidators.TwoArgBlockStmtType(_n, Pedantics);

            if (type == null)
            {
                return(SPResult.Fail);
            }

            var allowAttrs = (_name == S.UsingStmt ? AttrStyle.AllowKeywordAttrs : AttrStyle.AllowWordAttrs);

            G.Verify(0 == PrintAttrs(allowAttrs));

            if (type == S.DoWhile)
            {
                _out.Write("do", true);
                bool braces = PrintBracedBlockOrStmt(_n.Args[0], NewlineOpt.BeforeSimpleStmtBrace);

                // Print newline in front of "while" if appropriate and avoid printing
                // "while (\ncondition)" when condition has an explicit newline; use
                // "\nwhile (condition)" instead.
                LNode cond = _n.Args[1];
                LNode condWithoutNewline = cond.WithoutAttrNamed(S.TriviaNewline);
                if (cond != condWithoutNewline)
                {
                    _out.Newline();
                }
                else if (!Newline(braces ? NewlineOpt.BeforeExecutableBrace : NewlineOpt.Default))
                {
                    Space(SpaceOpt.Default);
                }

                _out.Write("while", true);
                PrintWithinParens(ParenFor.KeywordCall, condWithoutNewline);
                return(SPResult.NeedSemicolon);
            }
            else
            {
                WriteOperatorName(_name);
                Ambiguity argFlags = 0;
                if (_name == S.Fixed)
                {
                    argFlags |= Ambiguity.AllowPointer;
                }
                PrintWithinParens(ParenFor.KeywordCall, _n.Args[0], argFlags);
                PrintBracedBlockOrStmt(_n.Args[1]);
                return(SPResult.NeedSuffixTrivia);
            }
        }
示例#2
0
        public SPResult AutoPrintTwoArgBlockStmt(Ambiguity flags)
        {
            // S.Do, S.Fixed, S.Lock, S.Switch, S.UsingStmt, S.While
            var type = EcsValidators.TwoArgBlockStmtType(_n, Pedantics);

            if (type == null)
            {
                return(SPResult.Fail);
            }

            var allowAttrs = (_n.Name == S.UsingStmt ? AttrStyle.AllowKeywordAttrs : AttrStyle.AllowWordAttrs);

            G.Verify(0 == PrintAttrs(StartStmt, allowAttrs, flags));

            if (type == S.DoWhile)
            {
                _out.Write("do", true);
                bool braces = PrintBracedBlockOrStmt(_n.Args[0], flags, NewlineOpt.BeforeSimpleStmtBrace);
                if (!Newline(braces ? NewlineOpt.BeforeExecutableBrace : NewlineOpt.Default))
                {
                    Space(SpaceOpt.Default);
                }
                _out.Write("while", true);
                PrintWithinParens(ParenFor.KeywordCall, _n.Args[1]);
                return(SPResult.NeedSemicolon);
            }
            else
            {
                WriteOperatorName(_n.Name);
                Ambiguity argFlags = 0;
                if (_n.Name == S.Fixed)
                {
                    argFlags |= Ambiguity.AllowPointer;
                }
                PrintWithinParens(ParenFor.KeywordCall, _n.Args[0], argFlags);
                PrintBracedBlockOrStmt(_n.Args[1], flags);
                return(SPResult.NeedSuffixTrivia);
            }
        }