Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

string astyle::ASFormatter::nextLine (  ) [virtual]

get the next formatted line.

Returns:
formatted line.

Reimplemented from astyle::ASBeautifier.

Definition at line 387 of file ASFormatter.cpp.

References addBracketsToStatement(), appendSequence(), appendSpaceAfter(), appendSpacePad(), astyle::ASBeautifier::beautify(), breakLine(), astyle::ASEnhancer::enhance(), formatArrayBrackets(), formatClosingBracket(), formatCommentBody(), formatCommentOpener(), formatLineCommentBody(), formatLineCommentOpener(), formatOpeningBracket(), formatPointerOrReference(), formatQuoteBody(), formatQuoteOpener(), formatRunIn(), getBracketType(), getCurrentLineCommentAdjustment(), astyle::ASBeautifier::getIndentLength(), getNextChar(), getNextLineCommentAdjustment(), goForward(), isBeforeAnyComment(), isBeforeAnyLineEndComment(), isBracketType(), isDereferenceOrAddressOf(), isLineBreakBeforeClosingHeader(), isNextCharOpeningBracket(), isOkToBreakBlock(), isPointerOrReference(), padOperators(), padParens(), peekNextChar(), processPreprocessor(), and astyle::ASBeautifier::trim().

Referenced by commentAndHeaderFollows(), and peekNextText().

{
      const string *newHeader;
      bool isInVirginLine = isVirgin;
      isCharImmediatelyPostComment = false;
      isPreviousCharPostComment = false;
      isCharImmediatelyPostLineComment = false;
      isCharImmediatelyPostOpenBlock = false;
      isCharImmediatelyPostCloseBlock = false;
      isCharImmediatelyPostTemplate = false;
      traceLineNumber++;

      while (!isLineReady)
      {
            if (shouldReparseCurrentChar)
                  shouldReparseCurrentChar = false;
            else if (!getNextChar())
            {
                  breakLine();
                  return beautify(readyFormattedLine);
            }
            else // stuff to do when reading a new character...
            {
                  // make sure that a virgin '{' at the begining of the file will be treated as a block...
                  if (isInVirginLine && currentChar == '{' && currentLineBeginsWithBracket)     // lineBeginsWith('{')
                        previousCommandChar = '{';
                  if (isInHorstmannRunIn)
                        isInLineBreak = false;
                  if (!isWhiteSpace(currentChar))
                        isInHorstmannRunIn = false;
                  isPreviousCharPostComment = isCharImmediatelyPostComment;
                  isCharImmediatelyPostComment = false;
                  isCharImmediatelyPostTemplate = false;
                  isCharImmediatelyPostReturn = false;
                  isCharImmediatelyPostOperator = false;
                  isCharImmediatelyPostOpenBlock = false;
                  isCharImmediatelyPostCloseBlock = false;
            }

//          if (inLineNumber >= 7)
//                int x = 1;

            if (shouldBreakLineAtNextChar && !isWhiteSpace(currentChar))
            {
                  isInLineBreak = true;
                  shouldBreakLineAtNextChar = false;
            }

            if (isInLineComment)
            {
                  formatLineCommentBody();
                  continue;
            }
            else if (isInComment)
            {
                  formatCommentBody();
                  continue;
            }

            // not in line comment or comment

            else if (isInQuote)
            {
                  formatQuoteBody();
                  continue;
            }

            if (isSequenceReached("//"))
            {
                  formatLineCommentOpener();
                  continue;
            }
            else if (isSequenceReached("/*"))
            {
                  formatCommentOpener();
                  continue;
            }
            else if (currentChar == '"' || currentChar == '\'')
            {
                  formatQuoteOpener();
                  continue;
            }
            // treat these preprocessor statements as a line comment
            else if (currentChar =='#')
            {
                  if (isSequenceReached("#region")
                          || isSequenceReached("#endregion")
                          || isSequenceReached("#error")
                          || isSequenceReached("#warning"))
                  {
                        // check for horstmann run-in
                        if (formattedLine[0] == '{')
                        {
                              isInLineBreak = true;
                              isInHorstmannRunIn = false;
                        }
                        isInLineComment = true;
                        appendCurrentChar();
                        continue;
                  }
            }

            if (isInPreprocessor)
            {
                  appendCurrentChar();
                  continue;
            }

            // handle white space - needed to simplify the rest.
            if (isWhiteSpace(currentChar))
            {
                  appendCurrentChar();
                  continue;
            }

            /* not in MIDDLE of quote or comment or white-space of any type ... */

            // check if in preprocessor
            // ** isInPreprocessor will be automatically reset at the begining
            //    of a new line in getnextChar()
            if (currentChar == '#')
            {
                  isInPreprocessor = true;
                  // check for horstmann run-in
                  if (formattedLine[0] == '{')
                  {
                        isInLineBreak = true;
                        isInHorstmannRunIn = false;
                  }
                  processPreprocessor();
                  //  need to fall thru here to reset the variables
            }

            /* not in preprocessor ... */

            if (isImmediatelyPostComment)
            {
                  isImmediatelyPostComment = false;
                  isCharImmediatelyPostComment = true;
            }

            if (isImmediatelyPostLineComment)
            {
                  isImmediatelyPostLineComment = false;
                  isCharImmediatelyPostLineComment = true;
            }

            if (isImmediatelyPostReturn)
            {
                  isImmediatelyPostReturn = false;
                  isCharImmediatelyPostReturn = true;
            }

            if (isImmediatelyPostOperator)
            {
                  isImmediatelyPostOperator = false;
                  isCharImmediatelyPostOperator = true;
            }

            // reset isImmediatelyPostHeader information
            if (isImmediatelyPostHeader)
            {
                  if (currentChar != '{' && shouldAddBrackets)
                  {
                        addBracketsToStatement();
                        if (!shouldAddOneLineBrackets)
                              breakCurrentOneLineBlock = true;
                  }

                  isImmediatelyPostHeader = false;

                  // Make sure headers are broken from their succeeding blocks
                  // (e.g.
                  //     if (isFoo) DoBar();
                  //  should become
                  //     if (isFoo)
                  //         DoBar;
                  // )
                  // But treat else if() as a special case which should not be broken!
                  if (shouldBreakOneLineStatements
                          && isOkToBreakBlock(bracketTypeStack->back()))
                  {
                        // if may break 'else if()'s, then simply break the line
                        if (shouldBreakElseIfs)
                              isInLineBreak = true;
                  }
            }

            if (passedSemicolon)    // need to break the formattedLine
            {
                  passedSemicolon = false;
                  if (parenStack->back() == 0 && currentChar != ';') // allow ;;
                  {
                        // does a one-line statement have ending comments?
                        if (isBracketType(bracketTypeStack->back(), SINGLE_LINE_TYPE))
                        {
                              size_t blockEnd = currentLine.rfind(AS_CLOSE_BRACKET);
                              assert(blockEnd != string::npos);
                              // move ending comments to this formattedLine
                              if (isBeforeAnyLineEndComment(blockEnd))
                              {
                                    size_t commentStart = currentLine.find_first_not_of(" \t", blockEnd + 1);
                                    assert(commentStart != string::npos);
                                    assert((currentLine.compare(commentStart, 2, "//") == 0)
                                           || (currentLine.compare(commentStart, 2, "/*") == 0));
                                    size_t commentLength = currentLine.length() - commentStart;
                                    int tabCount = getIndentLength();
                                    appendSpacePad();
                                    for (int i=1; i<tabCount; i++)
                                          formattedLine.append(1, ' ');
                                    formattedLine.append(currentLine, commentStart, commentLength);
                                    currentLine.erase(commentStart, commentLength);
                              }
                        }
                        shouldReparseCurrentChar = true;
                        isInLineBreak = true;
                        if (needHeaderOpeningBracket)
                        {
                              isCharImmediatelyPostCloseBlock = true;
                              needHeaderOpeningBracket = false;
                        }
                        continue;
                  }
            }

            if (passedColon)
            {
                  passedColon = false;
                  if (parenStack->back() == 0 && !isBeforeAnyComment())
                  {
                        shouldReparseCurrentChar = true;
                        isInLineBreak = true;
                        continue;
                  }
            }

            // Check if in template declaration, e.g. foo<bar> or foo<bar,fig>
            // If so, set isInTemplate to true
            if (!isInTemplate && currentChar == '<')
            {
                  int maxTemplateDepth = 0;
                  templateDepth = 0;
                  for (size_t i = charNum;
                          i < currentLine.length();
                          i++)
                  {
                        char currentChar = currentLine[i];

                        if (currentChar == '<')
                        {
                              templateDepth++;
                              maxTemplateDepth++;
                        }
                        else if (currentChar == '>')
                        {
                              templateDepth--;
                              if (templateDepth == 0)
                              {
                                    // this is a template!
                                    isInTemplate = true;
                                    templateDepth = maxTemplateDepth;
                                    break;
                              }
                        }
                        else if (currentLine.compare(i, 2, "&&") == 0
                                 || currentLine.compare(i, 2, "||") == 0)
                        {
                              // this is not a template -> leave...
                              isInTemplate = false;
                              break;
                        }
                        else if (currentChar == ','       // comma,     e.g. A<int, char>
                                 || currentChar == '&'    // reference, e.g. A<int&>
                                 || currentChar == '*'    // pointer,   e.g. A<int*>
                                 || currentChar == ':'    // ::,        e.g. std::string
                                 || currentChar == '['    // []         e.g. string[]
                                 || currentChar == ']'    // []         e.g. string[]
                                 || currentChar == '('    // (...)      e.g. function definition
                                 || currentChar == ')')   // (...)      e.g. function definition
                        {
                              continue;
                        }
                        else if (!isLegalNameChar(currentChar) && !isWhiteSpace(currentChar))
                        {
                              // this is not a template -> leave...
                              isInTemplate = false;
                              break;
                        }
                  }
            }

            // handle parenthesies
            if (currentChar == '(' || currentChar == '[' || (isInTemplate && currentChar == '<'))
            {
                  parenStack->back()++;
                  if (currentChar == '[')
                        isInBlParen = true;
            }
            else if (currentChar == ')' || currentChar == ']' || (isInTemplate && currentChar == '>'))
            {
                  parenStack->back()--;
                  if (isInTemplate && currentChar == '>')
                  {
                        templateDepth--;
                        if (templateDepth == 0)
                        {
                              isInTemplate = false;
                              isCharImmediatelyPostTemplate = true;
                        }
                  }

                  // check if this parenthesis closes a header, e.g. if (...), while (...)
                  if (isInHeader && parenStack->back() == 0)
                  {
                        isInHeader = false;
                        isImmediatelyPostHeader = true;
                  }
                  if (currentChar == ']')
                        isInBlParen = false;
                  if (currentChar == ')')
                        foundCastOperator = false;
            }

            // handle brackets
            if (currentChar == '{' || currentChar == '}')
            {
                  // if appendOpeningBracket this was already done for the original bracket
                  if (currentChar == '{' && !appendOpeningBracket)
                  {
                        BracketType newBracketType = getBracketType();
                        foundNamespaceHeader = false;
                        foundClassHeader = false;
                        foundStructHeader = false;
                        foundInterfaceHeader = false;
                        foundPreDefinitionHeader = false;
                        foundPreCommandHeader = false;
                        isInPotentialCalculation = false;
                        isJavaStaticConstructor = false;
                        needHeaderOpeningBracket = false;

                        bracketTypeStack->push_back(newBracketType);
                        preBracketHeaderStack->push_back(currentHeader);
                        currentHeader = NULL;

                        isPreviousBracketBlockRelated = !isBracketType(newBracketType, ARRAY_TYPE);
                  }

                  // this must be done before the bracketTypeStack is popped
                  BracketType bracketType = bracketTypeStack->back();
                  bool isOpeningArrayBracket = (isBracketType(bracketType, ARRAY_TYPE)
                                                && bracketTypeStack->size() >= 2
                                                && !isBracketType((*bracketTypeStack)[bracketTypeStack->size()-2], ARRAY_TYPE)
                                               );

                  if (currentChar == '}')
                  {
                        // if a request has been made to append a post block empty line,
                        // but the block exists immediately before a closing bracket,
                        // then there is no need for the post block empty line.
                        isAppendPostBlockEmptyLineRequested = false;

                        if (bracketTypeStack->size() > 1)
                        {
                              previousBracketType = bracketTypeStack->back();
                              bracketTypeStack->pop_back();
                              isPreviousBracketBlockRelated = !isBracketType(bracketType, ARRAY_TYPE);
                        }
                        else
                        {
                              previousBracketType = NULL_TYPE;
                              isPreviousBracketBlockRelated = false;
                        }

                        if (!preBracketHeaderStack->empty())
                        {
                              currentHeader = preBracketHeaderStack->back();
                              preBracketHeaderStack->pop_back();
                        }
                        else
                              currentHeader = NULL;

                        if (isBracketType(bracketType, ARRAY_NIS_TYPE))
                              clearNonInStatement = true;

                  }

                  // format brackets
                  appendOpeningBracket = false;
                  if (isBracketType(bracketType, ARRAY_TYPE))
                  {
                        formatArrayBrackets(bracketType, isOpeningArrayBracket);
                  }
                  else
                  {
                        if (currentChar == '{')
                              formatOpeningBracket(bracketType);
                        else
                              formatClosingBracket(bracketType);
                  }
                  continue;
            }

            if ((((previousCommandChar == '{' && isPreviousBracketBlockRelated)
                    || ((previousCommandChar == '}'
                         && !isImmediatelyPostEmptyBlock
                         && isPreviousBracketBlockRelated
                         && !isPreviousCharPostComment       // Fixes wrongly appended newlines after '}' immediately after comments
                         && peekNextChar() != ' '
                         && !isBracketType(previousBracketType,  DEFINITION_TYPE))
                        && !isBracketType(bracketTypeStack->back(),  DEFINITION_TYPE)))
                    && isOkToBreakBlock(bracketTypeStack->back()))
                    // check for array
                    || (isBracketType(bracketTypeStack->back(), ARRAY_TYPE)
                        && !isBracketType(bracketTypeStack->back(), SINGLE_LINE_TYPE)
                        && isNonInStatementArray))
            {
                  isCharImmediatelyPostOpenBlock = (previousCommandChar == '{');
                  isCharImmediatelyPostCloseBlock = (previousCommandChar == '}');

                  if (isCharImmediatelyPostOpenBlock
                          && !isCharImmediatelyPostComment
                          && !isCharImmediatelyPostLineComment)
                  {
                        previousCommandChar = ' ';

                        if (bracketFormatMode == NONE_MODE)
                        {
                              if (shouldBreakOneLineBlocks
                                      && isBracketType(bracketTypeStack->back(),  SINGLE_LINE_TYPE))
                                    isInLineBreak = true;
                              else if (currentLineBeginsWithBracket)
                                    formatRunIn();
                              else
                                    breakLine();
                        }
                        else if (bracketFormatMode == HORSTMANN_MODE
                                 && currentChar != '#')
                              formatRunIn();
                        else
                              isInLineBreak = true;
                  }
                  else if (isCharImmediatelyPostCloseBlock
                           && shouldBreakOneLineStatements
                           && (isLegalNameChar(currentChar) && currentChar != '.')
                           && !isCharImmediatelyPostComment)
                  {
                        previousCommandChar = ' ';
                        breakCurrentOneLineBlock = false;
                        isInLineBreak = true;
                  }
            }

            // reset block handling flags
            isImmediatelyPostEmptyBlock = false;

            // look for headers
            bool isPotentialHeader = isCharPotentialHeader(currentLine, charNum);

            if (isPotentialHeader && !isInTemplate)
            {
                  isNonParenHeader = false;
                  foundClosingHeader = false;
                  newHeader = findHeader(headers);

                  if (newHeader != NULL)
                  {
                        char peekChar = ASBase::peekNextChar(currentLine, charNum + newHeader->length() - 1);

                        // is not a header if part of a definition
                        if (peekChar == ',' || peekChar == ')')
                              newHeader = NULL;
                        // the following accessor definitions are NOT headers
                        // goto default; is NOT a header
                        else if ((newHeader == &AS_GET || newHeader == &AS_SET || newHeader == &AS_DEFAULT)
                                 && peekChar == ';')
                        {
                              newHeader = NULL;
                        }
                  }

                  if (newHeader != NULL)
                  {
                        const string *previousHeader;

                        // recognize closing headers of do..while, if..else, try..catch..finally
                        if ((newHeader == &AS_ELSE && currentHeader == &AS_IF)
                                || (newHeader == &AS_WHILE && currentHeader == &AS_DO)
                                || (newHeader == &AS_CATCH && currentHeader == &AS_TRY)
                                || (newHeader == &AS_CATCH && currentHeader == &AS_CATCH)
                                || (newHeader == &AS_FINALLY && currentHeader == &AS_TRY)
                                || (newHeader == &AS_FINALLY && currentHeader == &AS_CATCH)
                                || (newHeader == &AS_SET && currentHeader == &AS_GET)
                                || (newHeader == &AS_REMOVE && currentHeader == &AS_ADD))
                              foundClosingHeader = true;

                        previousHeader = currentHeader;
                        currentHeader = newHeader;
                        needHeaderOpeningBracket = true;

                        if (foundClosingHeader && previousNonWSChar == '}')
                        {
                              if (isOkToBreakBlock(bracketTypeStack->back()))
                                    isLineBreakBeforeClosingHeader();

                              // get the adjustment for a comment following the closing header
                              if (isInLineBreak)
                                    nextLineSpacePadNum = getNextLineCommentAdjustment();
                              else
                                    spacePadNum = getCurrentLineCommentAdjustment();
                        }

                        // check if the found header is non-paren header
//                      isNonParenHeader = (find(nonParenHeaders.begin(), nonParenHeaders.end(),
//                                               newHeader) != nonParenHeaders.end());
                        isNonParenHeader = findHeader(nonParenHeaders) != NULL;

                        // join 'else if' statements
                        if (currentHeader == &AS_IF && previousHeader == &AS_ELSE && isInLineBreak && !shouldBreakElseIfs)
                        {
                              // 'else' must be last thing on the line, but must not be #else
                              size_t start = formattedLine.length() >= 6 ? formattedLine.length()-6 : 0;
                              if (formattedLine.find("else", start) != string::npos
                                      && formattedLine.find("#else", start) == string::npos)
                              {
                                    appendSpacePad();
                                    isInLineBreak = false;
                              }
                        }

                        appendSequence(*currentHeader);
                        goForward(currentHeader->length() - 1);
                        // if a paren-header is found add a space after it, if needed
                        // this checks currentLine, appendSpacePad() checks formattedLine
                        // in C# 'catch' can be either a paren or non-paren header
                        if (shouldPadHeader
                                && (!isNonParenHeader || (currentHeader == &AS_CATCH && peekNextChar() == '('))
                                && charNum < (int) currentLine.length() && !isWhiteSpace(currentLine[charNum+1]))
                              appendSpacePad();

                        // Signal that a header has been reached
                        // *** But treat a closing while() (as in do...while)
                        //     as if it were NOT a header since a closing while()
                        //     should never have a block after it!
                        if (!(foundClosingHeader && currentHeader == &AS_WHILE))
                        {
                              isInHeader = true;
                              // in C# 'catch' and 'delegate' can be a paren or non-paren header
                              if (isNonParenHeader && peekNextChar() != '(')
                              {
                                    isImmediatelyPostHeader = true;
                                    isInHeader = false;
                              }
                        }

                        if (shouldBreakBlocks
                                && isOkToBreakBlock(bracketTypeStack->back()))
                        {
                              if (previousHeader == NULL
                                      && !foundClosingHeader
                                      && !isCharImmediatelyPostOpenBlock
                                      && !isImmediatelyPostCommentOnly)
                              {
                                    isPrependPostBlockEmptyLineRequested = true;
                              }

                              if (currentHeader == &AS_ELSE
                                      || currentHeader == &AS_CATCH
                                      || currentHeader == &AS_FINALLY
                                      || foundClosingHeader)
                              {
                                    isPrependPostBlockEmptyLineRequested = false;
                              }

                              if (shouldBreakClosingHeaderBlocks
                                      && isCharImmediatelyPostCloseBlock
                                      && !isImmediatelyPostCommentOnly
                                      && currentHeader != &AS_WHILE)    // closing do-while block
                              {
                                    isPrependPostBlockEmptyLineRequested = true;
                              }

                        }

                        continue;
                  }
                  else if ((newHeader = findHeader(preDefinitionHeaders)) != NULL
                           && parenStack->back() == 0)
                  {
                        if (newHeader == &AS_NAMESPACE)
                              foundNamespaceHeader = true;
                        if (newHeader == &AS_CLASS)
                              foundClassHeader = true;
                        if (newHeader == &AS_STRUCT)
                              foundStructHeader = true;
                        if (newHeader == &AS_INTERFACE)
                              foundInterfaceHeader = true;
                        foundPreDefinitionHeader = true;
                        appendSequence(*newHeader);
                        goForward(newHeader->length() - 1);

                        continue;
                  }
                  else if ((newHeader = findHeader(preCommandHeaders)) != NULL)
                  {
                        if (!(*newHeader == AS_CONST && previousCommandChar != ')')) // 'const' member functions is a command bracket
                              foundPreCommandHeader = true;
                        appendSequence(*newHeader);
                        goForward(newHeader->length() - 1);

                        continue;
                  }
                  else if ((newHeader = findHeader(castOperators)) != NULL)
                  {
                        foundCastOperator = true;
                        appendSequence(*newHeader);
                        goForward(newHeader->length() - 1);
                        continue;
                  }
            }   // (isPotentialHeader &&  !isInTemplate)

            if (isInLineBreak)          // OK to break line here
                  breakLine();

            if (previousNonWSChar == '}' || currentChar == ';')
            {
                  if (shouldBreakOneLineStatements && currentChar == ';'
                          && (isOkToBreakBlock(bracketTypeStack->back()))
                     )
                  {
                        passedSemicolon = true;
                  }

                  // append post block empty line for unbracketed header
                  if (shouldBreakBlocks && currentChar == ';' && currentHeader != NULL && parenStack->back() == 0)
                  {
                        isAppendPostBlockEmptyLineRequested = true;
                  }

                  // end of block if a closing bracket was found
                  // or an opening bracket was not found (';' closes)
                  if (currentChar != ';'
                          || (needHeaderOpeningBracket && parenStack->back() == 0))
                        currentHeader = NULL;

                  foundQuestionMark = false;
                  foundNamespaceHeader = false;
                  foundClassHeader = false;
                  foundStructHeader = false;
                  foundInterfaceHeader = false;
                  foundPreDefinitionHeader = false;
                  foundPreCommandHeader = false;
                  foundCastOperator = false;
                  isInPotentialCalculation = false;
                  isSharpAccessor = false;
                  isSharpDelegate = false;
                  isInExtern = false;
                  isInEnum = false;
                  nonInStatementBracket = 0;
            }

            if (currentChar == ':' && shouldBreakOneLineStatements)
            {
                  if (isInCase
                          && previousChar != ':'          // not part of '::'
                          && peekNextChar() != ':')       // not part of '::'
                  {
                        isInCase = false;
                        passedColon = true;
                  }
                  else if (isCStyle()                     // for C/C++ only
                           && !foundQuestionMark          // not in a ... ? ... : ... sequence
                           && !foundPreDefinitionHeader   // not in a definition block (e.g. class foo : public bar
                           && previousCommandChar != ')'  // not immediately after closing paren of a method header, e.g. ASFormatter::ASFormatter(...) : ASBeautifier(...)
                           && previousChar != ':'         // not part of '::'
                           && peekNextChar() != ':'       // not part of '::'
                           && !isdigit(peekNextChar()))   // not a bit field
                  {
                        passedColon = true;
                  }
            }

            if (currentChar == '?')
                  foundQuestionMark = true;

            if (isPotentialHeader &&  !isInTemplate)
            {
                  if (findKeyword(currentLine, charNum, AS_CASE)
                          || findKeyword(currentLine, charNum, AS_DEFAULT))
                        isInCase = true;

                  if (findKeyword(currentLine, charNum, AS_NEW))
                        isInPotentialCalculation = false;

                  if (findKeyword(currentLine, charNum, AS_RETURN))
                  {
                        isInPotentialCalculation = true;    // return is the same as an = sign
                        isImmediatelyPostReturn = true;
                  }

                  if (findKeyword(currentLine, charNum, AS_OPERATOR))
                        isImmediatelyPostOperator = true;

                  if (isCStyle() && findKeyword(currentLine, charNum, AS_EXTERN))
                        isInExtern = true;

                  if (isCStyle() && findKeyword(currentLine, charNum, AS_ENUM))
                        isInEnum = true;

                  if (isJavaStyle()
                          && (findKeyword(currentLine, charNum, AS_STATIC)
                              && isNextCharOpeningBracket(charNum + 6)))
                        isJavaStaticConstructor = true;

                  if (isSharpStyle()
                          && (findKeyword(currentLine, charNum, AS_DELEGATE)
                              || findKeyword(currentLine, charNum, AS_UNCHECKED)))
                        isSharpDelegate = true;

                  // append the entire name
                  string name = getCurrentWord(currentLine, charNum);
                  appendSequence(name);
                  goForward(name.length() - 1);

                  continue;

            }   // (isPotentialHeader &&  !isInTemplate)

            // determine if this is a potential calculation

            bool isPotentialOperator = isCharPotentialOperator(currentChar);
            newHeader = NULL;

            if (isPotentialOperator)
            {
                  newHeader = findOperator(operators);

                  if (newHeader != NULL)
                  {
                        // correct mistake of two >> closing a template
                        if (isInTemplate && (newHeader == &AS_GR_GR || newHeader == &AS_GR_GR_GR))
                              newHeader = &AS_GR;

                        if (!isInPotentialCalculation)
                        {
                              // must determine if newHeader is an assignment operator
                              // do NOT use findOperator!!!
                              if (find(assignmentOperators.begin(), assignmentOperators.end(), newHeader)
                                      != assignmentOperators.end())
                              {
                                    char peekedChar = peekNextChar();
                                    isInPotentialCalculation = (!(newHeader == &AS_EQUAL && peekedChar == '*')
                                                                && !(newHeader == &AS_EQUAL && peekedChar == '&'));
                              }
                        }
                  }
            }

            // process pointers and references
            // check new header to elimnate things like '&&' sequence
            if (isCStyle()
                    && (newHeader == &AS_MULT || newHeader == &AS_BIT_AND)
                    && isPointerOrReference()
                    && !isDereferenceOrAddressOf())
            {
                  formatPointerOrReference();
                  continue;
            }

            if (shouldPadOperators && newHeader != NULL)
            {
                  padOperators(newHeader);
                  continue;
            }

            // pad commas and semi-colons
            if (currentChar == ';'
                    || (currentChar == ',' && shouldPadOperators))
            {
                  char nextChar = ' ';
                  if (charNum + 1 < (int) currentLine.length())
                        nextChar = currentLine[charNum+1];
                  if (!isWhiteSpace(nextChar)
                          && nextChar != '}'
                          && nextChar != ')'
                          && nextChar != ']'
                          && nextChar != '>'
                          && nextChar != ';'
                          && !isBeforeAnyComment()
                          /* && !(isBracketType(bracketTypeStack->back(), ARRAY_TYPE)) */
                     )
                  {
                        appendCurrentChar();
                        appendSpaceAfter();
                        continue;
                  }
            }

            if ((shouldPadParensOutside || shouldPadParensInside || shouldUnPadParens)
                    && (currentChar == '(' || currentChar == ')'))
            {
                  padParens();
                  continue;
            }

            appendCurrentChar();
      }   // end of while loop  *  end of while loop  *  end of while loop  *  end of while loop

      // return a beautified (i.e. correctly indented) line.

      string beautifiedLine;
      size_t readyFormattedLineLength = trim(readyFormattedLine).length();

      if (prependEmptyLine                // prepend a blank line before this formatted line
              && readyFormattedLineLength > 0
              && previousReadyFormattedLineLength > 0)
      {
            isLineReady = true;             // signal a waiting readyFormattedLine
            beautifiedLine = beautify("");
            previousReadyFormattedLineLength = 0;
      }
      else                                // format the current formatted line
      {
            isLineReady = false;
            horstmannIndentInStatement = horstmannIndentChars;
            beautifiedLine = beautify(readyFormattedLine);
            previousReadyFormattedLineLength = readyFormattedLineLength;
            horstmannIndentChars = 0;
            lineCommentNoBeautify = lineCommentNoIndent;
            lineCommentNoIndent = false;
            if (clearNonInStatement)
            {
                  isNonInStatementArray = false;
                  clearNonInStatement = false;
            }
      }

      prependEmptyLine = false;
      enhancer->enhance(beautifiedLine);
      return beautifiedLine;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index