Esempio n. 1
0
void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
                                     bool MunchSemi) {
  assert(FormatTok->Tok.is(tok::l_brace) && "'{' expected");
  unsigned InitialLevel = Line->Level;
  nextToken();

  addUnwrappedLine();

  ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                          MustBeDeclaration);
  if (AddLevel)
    ++Line->Level;
  parseLevel(/*HasOpeningBrace=*/true);

  if (!FormatTok->Tok.is(tok::r_brace)) {
    Line->Level = InitialLevel;
    StructuralError = true;
    return;
  }

  nextToken(); // Munch the closing brace.
  if (MunchSemi && FormatTok->Tok.is(tok::semi))
    nextToken();
  Line->Level = InitialLevel;
}
Esempio n. 2
0
void UnwrappedLineParser::parseParens() {
  assert(FormatTok->Tok.is(tok::l_paren) && "'(' expected.");
  nextToken();
  do {
    switch (FormatTok->Tok.getKind()) {
    case tok::l_paren:
      parseParens();
      break;
    case tok::r_paren:
      nextToken();
      return;
    case tok::l_brace: {
      if (!tryToParseBracedList()) {
        nextToken();
        ScopedLineState LineState(*this);
        ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                                /*MustBeDeclaration=*/ false);
        Line->Level += 1;
        parseLevel(/*HasOpeningBrace=*/ true);
        Line->Level -= 1;
      }
      break;
    }
    case tok::at:
      nextToken();
      if (FormatTok->Tok.is(tok::l_brace))
        parseBracedList();
      break;
    default:
      nextToken();
      break;
    }
  } while (!eof());
}
Esempio n. 3
0
void UnwrappedLineParser::parseFile() {
  ScopedDeclarationState DeclarationState(
      *Line, DeclarationScopeStack,
      /*MustBeDeclaration=*/ !Line->InPPDirective);
  parseLevel(/*HasOpeningBrace=*/false);
  // Make sure to format the remaining tokens.
  flushComments(true);
  addUnwrappedLine();
}
Esempio n. 4
0
void UnwrappedLineParser::parseChildBlock() {
  FormatTok->BlockKind = BK_Block;
  nextToken();
  {
    ScopedLineState LineState(*this);
    ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                            /*MustBeDeclaration=*/false);
    Line->Level += 1;
    parseLevel(/*HasOpeningBrace=*/true);
    Line->Level -= 1;
  }
  nextToken();
}
Esempio n. 5
0
void UnwrappedLineParser::parseChildBlock() {
  FormatTok->BlockKind = BK_Block;
  nextToken();
  {
    bool GoogScope =
        Style.Language == FormatStyle::LK_JavaScript && IsGoogScope(*Line);
    ScopedLineState LineState(*this);
    ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                            /*MustBeDeclaration=*/false);
    Line->Level += GoogScope ? 0 : 1;
    parseLevel(/*HasOpeningBrace=*/true);
    Line->Level -= GoogScope ? 0 : 1;
  }
  nextToken();
}
Esempio n. 6
0
void UnwrappedLineParser::parseBlock(bool MustBeDeclaration,
                                     unsigned AddLevels) {
  assert(FormatTok->Tok.is(tok::l_brace) && "'{' expected");
  nextToken();

  addUnwrappedLine();

  ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                          MustBeDeclaration);
  Line->Level += AddLevels;
  parseLevel(/*HasOpeningBrace=*/ true);

  if (!FormatTok->Tok.is(tok::r_brace)) {
    Line->Level -= AddLevels;
    StructuralError = true;
    return;
  }

  nextToken(); // Munch the closing brace.
  Line->Level -= AddLevels;
}