Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 1 | //===--- UnwrappedLineParser.cpp - Format C++ code ------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// \brief This file contains the implementation of the UnwrappedLineParser, |
| 12 | /// which turns a stream of tokens into UnwrappedLines. |
| 13 | /// |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Manuel Klimek | 8fa3799 | 2013-01-16 12:31:12 +0000 | [diff] [blame] | 16 | #define DEBUG_TYPE "format-parser" |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 17 | |
Chandler Carruth | b1ba0ef | 2013-01-19 08:09:44 +0000 | [diff] [blame] | 18 | #include "UnwrappedLineParser.h" |
Manuel Klimek | 8fa3799 | 2013-01-16 12:31:12 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Diagnostic.h" |
| 20 | #include "llvm/Support/Debug.h" |
Manuel Klimek | 8fa3799 | 2013-01-16 12:31:12 +0000 | [diff] [blame] | 21 | |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 22 | namespace clang { |
| 23 | namespace format { |
| 24 | |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 25 | class ScopedDeclarationState { |
| 26 | public: |
| 27 | ScopedDeclarationState(UnwrappedLine &Line, std::vector<bool> &Stack, |
| 28 | bool MustBeDeclaration) |
| 29 | : Line(Line), Stack(Stack) { |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 30 | Line.MustBeDeclaration = MustBeDeclaration; |
Manuel Klimek | 836b58f | 2013-01-23 11:03:04 +0000 | [diff] [blame] | 31 | Stack.push_back(MustBeDeclaration); |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 32 | } |
| 33 | ~ScopedDeclarationState() { |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 34 | Stack.pop_back(); |
Manuel Klimek | a32a7fd | 2013-01-23 14:08:21 +0000 | [diff] [blame] | 35 | if (!Stack.empty()) |
| 36 | Line.MustBeDeclaration = Stack.back(); |
| 37 | else |
| 38 | Line.MustBeDeclaration = true; |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 39 | } |
| 40 | private: |
| 41 | UnwrappedLine &Line; |
| 42 | std::vector<bool> &Stack; |
| 43 | }; |
| 44 | |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 45 | class ScopedMacroState : public FormatTokenSource { |
| 46 | public: |
| 47 | ScopedMacroState(UnwrappedLine &Line, FormatTokenSource *&TokenSource, |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 48 | FormatToken &ResetToken, bool &StructuralError) |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 49 | : Line(Line), TokenSource(TokenSource), ResetToken(ResetToken), |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 50 | PreviousLineLevel(Line.Level), PreviousTokenSource(TokenSource), |
| 51 | StructuralError(StructuralError), |
| 52 | PreviousStructuralError(StructuralError) { |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 53 | TokenSource = this; |
Manuel Klimek | c37b4d6 | 2013-01-05 22:14:16 +0000 | [diff] [blame] | 54 | Line.Level = 0; |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 55 | Line.InPPDirective = true; |
| 56 | } |
| 57 | |
| 58 | ~ScopedMacroState() { |
| 59 | TokenSource = PreviousTokenSource; |
| 60 | ResetToken = Token; |
| 61 | Line.InPPDirective = false; |
Manuel Klimek | c37b4d6 | 2013-01-05 22:14:16 +0000 | [diff] [blame] | 62 | Line.Level = PreviousLineLevel; |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 63 | StructuralError = PreviousStructuralError; |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | virtual FormatToken getNextToken() { |
Manuel Klimek | dd5b101 | 2013-01-07 10:03:37 +0000 | [diff] [blame] | 67 | // The \c UnwrappedLineParser guards against this by never calling |
| 68 | // \c getNextToken() after it has encountered the first eof token. |
| 69 | assert(!eof()); |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 70 | Token = PreviousTokenSource->getNextToken(); |
| 71 | if (eof()) |
| 72 | return createEOF(); |
| 73 | return Token; |
| 74 | } |
| 75 | |
| 76 | private: |
Alexander Kornienko | 3d713a7 | 2013-04-08 22:16:06 +0000 | [diff] [blame] | 77 | bool eof() { return Token.HasUnescapedNewline; } |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 78 | |
| 79 | FormatToken createEOF() { |
| 80 | FormatToken FormatTok; |
| 81 | FormatTok.Tok.startToken(); |
| 82 | FormatTok.Tok.setKind(tok::eof); |
| 83 | return FormatTok; |
| 84 | } |
| 85 | |
| 86 | UnwrappedLine &Line; |
| 87 | FormatTokenSource *&TokenSource; |
| 88 | FormatToken &ResetToken; |
Manuel Klimek | c37b4d6 | 2013-01-05 22:14:16 +0000 | [diff] [blame] | 89 | unsigned PreviousLineLevel; |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 90 | FormatTokenSource *PreviousTokenSource; |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 91 | bool &StructuralError; |
| 92 | bool PreviousStructuralError; |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 93 | |
| 94 | FormatToken Token; |
| 95 | }; |
| 96 | |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 97 | class ScopedLineState { |
| 98 | public: |
Manuel Klimek | 525fe16 | 2013-01-18 14:04:34 +0000 | [diff] [blame] | 99 | ScopedLineState(UnwrappedLineParser &Parser, |
| 100 | bool SwitchToPreprocessorLines = false) |
| 101 | : Parser(Parser), SwitchToPreprocessorLines(SwitchToPreprocessorLines) { |
| 102 | if (SwitchToPreprocessorLines) |
| 103 | Parser.CurrentLines = &Parser.PreprocessorDirectives; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 104 | PreBlockLine = Parser.Line.take(); |
Daniel Jasper | cbb6c41 | 2013-01-16 09:10:19 +0000 | [diff] [blame] | 105 | Parser.Line.reset(new UnwrappedLine()); |
| 106 | Parser.Line->Level = PreBlockLine->Level; |
| 107 | Parser.Line->InPPDirective = PreBlockLine->InPPDirective; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | ~ScopedLineState() { |
Daniel Jasper | cbb6c41 | 2013-01-16 09:10:19 +0000 | [diff] [blame] | 111 | if (!Parser.Line->Tokens.empty()) { |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 112 | Parser.addUnwrappedLine(); |
| 113 | } |
Daniel Jasper | cbb6c41 | 2013-01-16 09:10:19 +0000 | [diff] [blame] | 114 | assert(Parser.Line->Tokens.empty()); |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 115 | Parser.Line.reset(PreBlockLine); |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 116 | Parser.MustBreakBeforeNextToken = true; |
Manuel Klimek | 525fe16 | 2013-01-18 14:04:34 +0000 | [diff] [blame] | 117 | if (SwitchToPreprocessorLines) |
| 118 | Parser.CurrentLines = &Parser.Lines; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | private: |
| 122 | UnwrappedLineParser &Parser; |
Manuel Klimek | 525fe16 | 2013-01-18 14:04:34 +0000 | [diff] [blame] | 123 | const bool SwitchToPreprocessorLines; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 124 | |
| 125 | UnwrappedLine *PreBlockLine; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Alexander Kornienko | 3048aea | 2013-01-10 15:05:09 +0000 | [diff] [blame] | 128 | UnwrappedLineParser::UnwrappedLineParser( |
| 129 | clang::DiagnosticsEngine &Diag, const FormatStyle &Style, |
| 130 | FormatTokenSource &Tokens, UnwrappedLineConsumer &Callback) |
Manuel Klimek | 525fe16 | 2013-01-18 14:04:34 +0000 | [diff] [blame] | 131 | : Line(new UnwrappedLine), MustBreakBeforeNextToken(false), |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 132 | CurrentLines(&Lines), StructuralError(false), Diag(Diag), Style(Style), |
| 133 | Tokens(&Tokens), Callback(Callback) {} |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 134 | |
Alexander Kornienko | cff563c | 2012-12-04 17:27:50 +0000 | [diff] [blame] | 135 | bool UnwrappedLineParser::parse() { |
Manuel Klimek | 8fa3799 | 2013-01-16 12:31:12 +0000 | [diff] [blame] | 136 | DEBUG(llvm::dbgs() << "----\n"); |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 137 | readToken(); |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 138 | parseFile(); |
Daniel Jasper | f9955d3 | 2013-03-20 12:37:50 +0000 | [diff] [blame] | 139 | for (std::vector<UnwrappedLine>::iterator I = Lines.begin(), E = Lines.end(); |
Manuel Klimek | 525fe16 | 2013-01-18 14:04:34 +0000 | [diff] [blame] | 140 | I != E; ++I) { |
| 141 | Callback.consumeUnwrappedLine(*I); |
| 142 | } |
Daniel Jasper | 516fb31 | 2013-03-01 18:11:39 +0000 | [diff] [blame] | 143 | |
| 144 | // Create line with eof token. |
| 145 | pushToken(FormatTok); |
| 146 | Callback.consumeUnwrappedLine(*Line); |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 147 | return StructuralError; |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 150 | void UnwrappedLineParser::parseFile() { |
Daniel Jasper | 627707b | 2013-03-22 16:55:40 +0000 | [diff] [blame] | 151 | ScopedDeclarationState DeclarationState( |
| 152 | *Line, DeclarationScopeStack, |
| 153 | /*MustBeDeclaration=*/ !Line->InPPDirective); |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 154 | parseLevel(/*HasOpeningBrace=*/ false); |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 155 | // Make sure to format the remaining tokens. |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 156 | flushComments(true); |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 157 | addUnwrappedLine(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 160 | void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) { |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 161 | do { |
| 162 | switch (FormatTok.Tok.getKind()) { |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 163 | case tok::comment: |
Daniel Jasper | 05b1ac8 | 2012-12-17 11:29:41 +0000 | [diff] [blame] | 164 | nextToken(); |
| 165 | addUnwrappedLine(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 166 | break; |
| 167 | case tok::l_brace: |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 168 | // FIXME: Add parameter whether this can happen - if this happens, we must |
| 169 | // be in a non-declaration context. |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 170 | parseBlock(/*MustBeDeclaration=*/ false); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 171 | addUnwrappedLine(); |
| 172 | break; |
| 173 | case tok::r_brace: |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 174 | if (HasOpeningBrace) |
| 175 | return; |
| 176 | Diag.Report(FormatTok.Tok.getLocation(), |
| 177 | Diag.getCustomDiagID(clang::DiagnosticsEngine::Error, |
| 178 | "unexpected '}'")); |
| 179 | StructuralError = true; |
| 180 | nextToken(); |
| 181 | addUnwrappedLine(); |
Manuel Klimek | a5342db | 2013-01-06 20:07:31 +0000 | [diff] [blame] | 182 | break; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 183 | default: |
Manuel Klimek | f0ab0a3 | 2013-01-07 14:56:16 +0000 | [diff] [blame] | 184 | parseStructuralElement(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 185 | break; |
| 186 | } |
| 187 | } while (!eof()); |
| 188 | } |
| 189 | |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 190 | void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, |
Nico Weber | d74fcdb | 2013-02-10 20:35:35 +0000 | [diff] [blame] | 191 | unsigned AddLevels) { |
Alexander Kornienko | a3a2b3a | 2012-12-06 17:49:17 +0000 | [diff] [blame] | 192 | assert(FormatTok.Tok.is(tok::l_brace) && "'{' expected"); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 193 | nextToken(); |
| 194 | |
Manuel Klimek | 2f1ac41 | 2013-01-21 16:42:44 +0000 | [diff] [blame] | 195 | addUnwrappedLine(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 196 | |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 197 | ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack, |
| 198 | MustBeDeclaration); |
Manuel Klimek | 2f1ac41 | 2013-01-21 16:42:44 +0000 | [diff] [blame] | 199 | Line->Level += AddLevels; |
Daniel Jasper | f9955d3 | 2013-03-20 12:37:50 +0000 | [diff] [blame] | 200 | parseLevel(/*HasOpeningBrace=*/ true); |
Alexander Kornienko | 1575731 | 2012-12-06 18:03:27 +0000 | [diff] [blame] | 201 | |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 202 | if (!FormatTok.Tok.is(tok::r_brace)) { |
| 203 | Line->Level -= AddLevels; |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 204 | StructuralError = true; |
| 205 | return; |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 206 | } |
Alexander Kornienko | 393b008 | 2012-12-04 15:40:36 +0000 | [diff] [blame] | 207 | |
Daniel Jasper | f9955d3 | 2013-03-20 12:37:50 +0000 | [diff] [blame] | 208 | nextToken(); // Munch the closing brace. |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 209 | Line->Level -= AddLevels; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void UnwrappedLineParser::parsePPDirective() { |
Manuel Klimek | a080a18 | 2013-01-02 16:30:12 +0000 | [diff] [blame] | 213 | assert(FormatTok.Tok.is(tok::hash) && "'#' expected"); |
Manuel Klimek | 67d080d | 2013-04-12 14:13:36 +0000 | [diff] [blame] | 214 | ScopedMacroState MacroState(*Line, Tokens, FormatTok, StructuralError); |
Manuel Klimek | a080a18 | 2013-01-02 16:30:12 +0000 | [diff] [blame] | 215 | nextToken(); |
| 216 | |
Manuel Klimek | a080a18 | 2013-01-02 16:30:12 +0000 | [diff] [blame] | 217 | if (FormatTok.Tok.getIdentifierInfo() == NULL) { |
Manuel Klimek | bd04f2a | 2013-01-31 15:58:48 +0000 | [diff] [blame] | 218 | parsePPUnknown(); |
Manuel Klimek | a080a18 | 2013-01-02 16:30:12 +0000 | [diff] [blame] | 219 | return; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 220 | } |
Manuel Klimek | a080a18 | 2013-01-02 16:30:12 +0000 | [diff] [blame] | 221 | |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 222 | switch (FormatTok.Tok.getIdentifierInfo()->getPPKeywordID()) { |
| 223 | case tok::pp_define: |
| 224 | parsePPDefine(); |
| 225 | break; |
| 226 | default: |
| 227 | parsePPUnknown(); |
| 228 | break; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | void UnwrappedLineParser::parsePPDefine() { |
| 233 | nextToken(); |
| 234 | |
| 235 | if (FormatTok.Tok.getKind() != tok::identifier) { |
| 236 | parsePPUnknown(); |
| 237 | return; |
| 238 | } |
| 239 | nextToken(); |
Manuel Klimek | 7ccbc21 | 2013-01-23 14:37:36 +0000 | [diff] [blame] | 240 | if (FormatTok.Tok.getKind() == tok::l_paren && |
| 241 | FormatTok.WhiteSpaceLength == 0) { |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 242 | parseParens(); |
| 243 | } |
| 244 | addUnwrappedLine(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 245 | Line->Level = 1; |
Manuel Klimek | c3d0c82 | 2013-01-07 09:34:28 +0000 | [diff] [blame] | 246 | |
| 247 | // Errors during a preprocessor directive can only affect the layout of the |
| 248 | // preprocessor directive, and thus we ignore them. An alternative approach |
| 249 | // would be to use the same approach we use on the file level (no |
| 250 | // re-indentation if there was a structural error) within the macro |
| 251 | // definition. |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 252 | parseFile(); |
| 253 | } |
| 254 | |
| 255 | void UnwrappedLineParser::parsePPUnknown() { |
Manuel Klimek | a080a18 | 2013-01-02 16:30:12 +0000 | [diff] [blame] | 256 | do { |
Manuel Klimek | a080a18 | 2013-01-02 16:30:12 +0000 | [diff] [blame] | 257 | nextToken(); |
| 258 | } while (!eof()); |
| 259 | addUnwrappedLine(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Alexander Kornienko | 99b0e14 | 2013-04-09 16:15:19 +0000 | [diff] [blame] | 262 | // Here we blacklist certain tokens that are not usually the first token in an |
| 263 | // unwrapped line. This is used in attempt to distinguish macro calls without |
| 264 | // trailing semicolons from other constructs split to several lines. |
| 265 | bool tokenCanStartNewLine(clang::Token Tok) { |
| 266 | // Semicolon can be a null-statement, l_square can be a start of a macro or |
| 267 | // a C++11 attribute, but this doesn't seem to be common. |
| 268 | return Tok.isNot(tok::semi) && Tok.isNot(tok::l_brace) && |
| 269 | Tok.isNot(tok::l_square) && |
| 270 | // Tokens that can only be used as binary operators and a part of |
| 271 | // overloaded operator names. |
| 272 | Tok.isNot(tok::period) && Tok.isNot(tok::periodstar) && |
| 273 | Tok.isNot(tok::arrow) && Tok.isNot(tok::arrowstar) && |
| 274 | Tok.isNot(tok::less) && Tok.isNot(tok::greater) && |
| 275 | Tok.isNot(tok::slash) && Tok.isNot(tok::percent) && |
| 276 | Tok.isNot(tok::lessless) && Tok.isNot(tok::greatergreater) && |
| 277 | Tok.isNot(tok::equal) && Tok.isNot(tok::plusequal) && |
| 278 | Tok.isNot(tok::minusequal) && Tok.isNot(tok::starequal) && |
| 279 | Tok.isNot(tok::slashequal) && Tok.isNot(tok::percentequal) && |
| 280 | Tok.isNot(tok::ampequal) && Tok.isNot(tok::pipeequal) && |
| 281 | Tok.isNot(tok::caretequal) && Tok.isNot(tok::greatergreaterequal) && |
| 282 | Tok.isNot(tok::lesslessequal) && |
| 283 | // Colon is used in labels, base class lists, initializer lists, |
| 284 | // range-based for loops, ternary operator, but should never be the |
| 285 | // first token in an unwrapped line. |
| 286 | Tok.isNot(tok::colon); |
| 287 | } |
| 288 | |
Manuel Klimek | f0ab0a3 | 2013-01-07 14:56:16 +0000 | [diff] [blame] | 289 | void UnwrappedLineParser::parseStructuralElement() { |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 290 | assert(!FormatTok.Tok.is(tok::l_brace)); |
Alexander Kornienko | a166e73 | 2012-12-04 14:46:19 +0000 | [diff] [blame] | 291 | switch (FormatTok.Tok.getKind()) { |
Nico Weber | 6092d4e | 2013-01-07 19:05:19 +0000 | [diff] [blame] | 292 | case tok::at: |
| 293 | nextToken(); |
Nico Weber | d74fcdb | 2013-02-10 20:35:35 +0000 | [diff] [blame] | 294 | if (FormatTok.Tok.is(tok::l_brace)) { |
| 295 | parseBracedList(); |
| 296 | break; |
| 297 | } |
Nico Weber | 6092d4e | 2013-01-07 19:05:19 +0000 | [diff] [blame] | 298 | switch (FormatTok.Tok.getObjCKeywordID()) { |
| 299 | case tok::objc_public: |
| 300 | case tok::objc_protected: |
| 301 | case tok::objc_package: |
| 302 | case tok::objc_private: |
| 303 | return parseAccessSpecifier(); |
Nico Weber | 27d1367 | 2013-01-09 20:25:35 +0000 | [diff] [blame] | 304 | case tok::objc_interface: |
Nico Weber | 50767d8 | 2013-01-09 23:25:37 +0000 | [diff] [blame] | 305 | case tok::objc_implementation: |
| 306 | return parseObjCInterfaceOrImplementation(); |
Nico Weber | 1abe6ea | 2013-01-09 21:15:03 +0000 | [diff] [blame] | 307 | case tok::objc_protocol: |
| 308 | return parseObjCProtocol(); |
Nico Weber | 049c447 | 2013-01-09 21:42:32 +0000 | [diff] [blame] | 309 | case tok::objc_end: |
| 310 | return; // Handled by the caller. |
Nico Weber | b530fa3 | 2013-01-10 00:25:19 +0000 | [diff] [blame] | 311 | case tok::objc_optional: |
| 312 | case tok::objc_required: |
| 313 | nextToken(); |
| 314 | addUnwrappedLine(); |
| 315 | return; |
Nico Weber | 6092d4e | 2013-01-07 19:05:19 +0000 | [diff] [blame] | 316 | default: |
| 317 | break; |
| 318 | } |
| 319 | break; |
Alexander Kornienko | 1575731 | 2012-12-06 18:03:27 +0000 | [diff] [blame] | 320 | case tok::kw_namespace: |
| 321 | parseNamespace(); |
| 322 | return; |
Dmitri Gribenko | 1f94f2b | 2012-12-30 21:27:25 +0000 | [diff] [blame] | 323 | case tok::kw_inline: |
| 324 | nextToken(); |
Dmitri Gribenko | 1f94f2b | 2012-12-30 21:27:25 +0000 | [diff] [blame] | 325 | if (FormatTok.Tok.is(tok::kw_namespace)) { |
| 326 | parseNamespace(); |
| 327 | return; |
| 328 | } |
| 329 | break; |
Alexander Kornienko | a166e73 | 2012-12-04 14:46:19 +0000 | [diff] [blame] | 330 | case tok::kw_public: |
| 331 | case tok::kw_protected: |
| 332 | case tok::kw_private: |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 333 | parseAccessSpecifier(); |
| 334 | return; |
Alexander Kornienko | a166e73 | 2012-12-04 14:46:19 +0000 | [diff] [blame] | 335 | case tok::kw_if: |
| 336 | parseIfThenElse(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 337 | return; |
Alexander Kornienko | 2e97cfc | 2012-12-05 15:06:06 +0000 | [diff] [blame] | 338 | case tok::kw_for: |
| 339 | case tok::kw_while: |
| 340 | parseForOrWhileLoop(); |
| 341 | return; |
Alexander Kornienko | a166e73 | 2012-12-04 14:46:19 +0000 | [diff] [blame] | 342 | case tok::kw_do: |
| 343 | parseDoWhile(); |
| 344 | return; |
| 345 | case tok::kw_switch: |
| 346 | parseSwitch(); |
| 347 | return; |
| 348 | case tok::kw_default: |
| 349 | nextToken(); |
| 350 | parseLabel(); |
| 351 | return; |
| 352 | case tok::kw_case: |
| 353 | parseCaseLabel(); |
| 354 | return; |
Manuel Klimek | c44ee89 | 2013-01-21 10:07:49 +0000 | [diff] [blame] | 355 | case tok::kw_return: |
| 356 | parseReturn(); |
| 357 | return; |
Manuel Klimek | d19dc2d | 2013-01-21 14:32:05 +0000 | [diff] [blame] | 358 | case tok::kw_extern: |
| 359 | nextToken(); |
| 360 | if (FormatTok.Tok.is(tok::string_literal)) { |
| 361 | nextToken(); |
| 362 | if (FormatTok.Tok.is(tok::l_brace)) { |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 363 | parseBlock(/*MustBeDeclaration=*/ true, 0); |
Manuel Klimek | d19dc2d | 2013-01-21 14:32:05 +0000 | [diff] [blame] | 364 | addUnwrappedLine(); |
| 365 | return; |
| 366 | } |
| 367 | } |
| 368 | // In all other cases, parse the declaration. |
| 369 | break; |
Alexander Kornienko | a166e73 | 2012-12-04 14:46:19 +0000 | [diff] [blame] | 370 | default: |
| 371 | break; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 372 | } |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 373 | do { |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 374 | switch (FormatTok.Tok.getKind()) { |
Nico Weber | d74fcdb | 2013-02-10 20:35:35 +0000 | [diff] [blame] | 375 | case tok::at: |
| 376 | nextToken(); |
| 377 | if (FormatTok.Tok.is(tok::l_brace)) |
| 378 | parseBracedList(); |
| 379 | break; |
Alexander Kornienko | a166e73 | 2012-12-04 14:46:19 +0000 | [diff] [blame] | 380 | case tok::kw_enum: |
| 381 | parseEnum(); |
Manuel Klimek | 308232c | 2013-01-21 19:17:52 +0000 | [diff] [blame] | 382 | break; |
Alexander Kornienko | d881875 | 2013-01-16 11:43:46 +0000 | [diff] [blame] | 383 | case tok::kw_struct: |
| 384 | case tok::kw_union: |
Manuel Klimek | de76854 | 2013-01-07 18:10:23 +0000 | [diff] [blame] | 385 | case tok::kw_class: |
Manuel Klimek | 47ea7f6 | 2013-01-15 13:38:33 +0000 | [diff] [blame] | 386 | parseRecord(); |
| 387 | // A record declaration or definition is always the start of a structural |
| 388 | // element. |
| 389 | break; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 390 | case tok::semi: |
| 391 | nextToken(); |
| 392 | addUnwrappedLine(); |
| 393 | return; |
Alexander Kornienko | d881875 | 2013-01-16 11:43:46 +0000 | [diff] [blame] | 394 | case tok::r_brace: |
| 395 | addUnwrappedLine(); |
| 396 | return; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 397 | case tok::l_paren: |
| 398 | parseParens(); |
| 399 | break; |
| 400 | case tok::l_brace: |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 401 | // A block outside of parentheses must be the last part of a |
| 402 | // structural element. |
| 403 | // FIXME: Figure out cases where this is not true, and add projections for |
| 404 | // them (the one we know is missing are lambdas). |
Manuel Klimek | 44135b8 | 2013-05-13 12:51:40 +0000 | [diff] [blame^] | 405 | if (Style.BreakBeforeBraces == FormatStyle::BS_Linux || |
| 406 | Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup) |
| 407 | addUnwrappedLine(); |
| 408 | |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 409 | parseBlock(/*MustBeDeclaration=*/ false); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 410 | addUnwrappedLine(); |
| 411 | return; |
Alexander Kornienko | a166e73 | 2012-12-04 14:46:19 +0000 | [diff] [blame] | 412 | case tok::identifier: |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 413 | nextToken(); |
Alexander Kornienko | 3d713a7 | 2013-04-08 22:16:06 +0000 | [diff] [blame] | 414 | if (Line->Tokens.size() == 1) { |
| 415 | if (FormatTok.Tok.is(tok::colon)) { |
| 416 | parseLabel(); |
| 417 | return; |
| 418 | } |
Alexander Kornienko | 99b0e14 | 2013-04-09 16:15:19 +0000 | [diff] [blame] | 419 | // Recognize function-like macro usages without trailing semicolon. |
Alexander Kornienko | 3d713a7 | 2013-04-08 22:16:06 +0000 | [diff] [blame] | 420 | if (FormatTok.Tok.is(tok::l_paren)) { |
| 421 | parseParens(); |
Alexander Kornienko | 99b0e14 | 2013-04-09 16:15:19 +0000 | [diff] [blame] | 422 | if (FormatTok.HasUnescapedNewline && |
| 423 | tokenCanStartNewLine(FormatTok.Tok)) { |
Alexander Kornienko | 3d713a7 | 2013-04-08 22:16:06 +0000 | [diff] [blame] | 424 | addUnwrappedLine(); |
| 425 | return; |
| 426 | } |
| 427 | } |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 428 | } |
| 429 | break; |
Daniel Jasper | 05b1ac8 | 2012-12-17 11:29:41 +0000 | [diff] [blame] | 430 | case tok::equal: |
| 431 | nextToken(); |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 432 | if (FormatTok.Tok.is(tok::l_brace)) { |
| 433 | parseBracedList(); |
| 434 | } |
Daniel Jasper | 05b1ac8 | 2012-12-17 11:29:41 +0000 | [diff] [blame] | 435 | break; |
Alexander Kornienko | a166e73 | 2012-12-04 14:46:19 +0000 | [diff] [blame] | 436 | default: |
| 437 | nextToken(); |
| 438 | break; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 439 | } |
| 440 | } while (!eof()); |
| 441 | } |
| 442 | |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 443 | void UnwrappedLineParser::parseBracedList() { |
| 444 | nextToken(); |
| 445 | |
Manuel Klimek | 423dd93 | 2013-04-10 09:52:05 +0000 | [diff] [blame] | 446 | // FIXME: Once we have an expression parser in the UnwrappedLineParser, |
| 447 | // replace this by using parseAssigmentExpression() inside. |
| 448 | bool StartOfExpression = true; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 449 | do { |
Manuel Klimek | 423dd93 | 2013-04-10 09:52:05 +0000 | [diff] [blame] | 450 | // FIXME: When we start to support lambdas, we'll want to parse them away |
| 451 | // here, otherwise our bail-out scenarios below break. The better solution |
| 452 | // might be to just implement a more or less complete expression parser. |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 453 | switch (FormatTok.Tok.getKind()) { |
| 454 | case tok::l_brace: |
Manuel Klimek | 423dd93 | 2013-04-10 09:52:05 +0000 | [diff] [blame] | 455 | if (!StartOfExpression) { |
| 456 | // Probably a missing closing brace. Bail out. |
| 457 | addUnwrappedLine(); |
| 458 | return; |
| 459 | } |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 460 | parseBracedList(); |
Manuel Klimek | 423dd93 | 2013-04-10 09:52:05 +0000 | [diff] [blame] | 461 | StartOfExpression = false; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 462 | break; |
| 463 | case tok::r_brace: |
| 464 | nextToken(); |
| 465 | return; |
Manuel Klimek | 423dd93 | 2013-04-10 09:52:05 +0000 | [diff] [blame] | 466 | case tok::semi: |
| 467 | // Probably a missing closing brace. Bail out. |
| 468 | return; |
| 469 | case tok::comma: |
| 470 | nextToken(); |
| 471 | StartOfExpression = true; |
| 472 | break; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 473 | default: |
| 474 | nextToken(); |
Manuel Klimek | 423dd93 | 2013-04-10 09:52:05 +0000 | [diff] [blame] | 475 | StartOfExpression = false; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 476 | break; |
| 477 | } |
| 478 | } while (!eof()); |
| 479 | } |
| 480 | |
Manuel Klimek | c44ee89 | 2013-01-21 10:07:49 +0000 | [diff] [blame] | 481 | void UnwrappedLineParser::parseReturn() { |
| 482 | nextToken(); |
| 483 | |
| 484 | do { |
| 485 | switch (FormatTok.Tok.getKind()) { |
| 486 | case tok::l_brace: |
| 487 | parseBracedList(); |
Manuel Klimek | 423dd93 | 2013-04-10 09:52:05 +0000 | [diff] [blame] | 488 | if (FormatTok.Tok.isNot(tok::semi)) { |
| 489 | // Assume missing ';'. |
| 490 | addUnwrappedLine(); |
| 491 | return; |
| 492 | } |
Manuel Klimek | c44ee89 | 2013-01-21 10:07:49 +0000 | [diff] [blame] | 493 | break; |
| 494 | case tok::l_paren: |
| 495 | parseParens(); |
| 496 | break; |
| 497 | case tok::r_brace: |
| 498 | // Assume missing ';'. |
| 499 | addUnwrappedLine(); |
| 500 | return; |
| 501 | case tok::semi: |
| 502 | nextToken(); |
| 503 | addUnwrappedLine(); |
| 504 | return; |
| 505 | default: |
| 506 | nextToken(); |
| 507 | break; |
| 508 | } |
| 509 | } while (!eof()); |
| 510 | } |
| 511 | |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 512 | void UnwrappedLineParser::parseParens() { |
| 513 | assert(FormatTok.Tok.is(tok::l_paren) && "'(' expected."); |
| 514 | nextToken(); |
| 515 | do { |
| 516 | switch (FormatTok.Tok.getKind()) { |
| 517 | case tok::l_paren: |
| 518 | parseParens(); |
| 519 | break; |
| 520 | case tok::r_paren: |
| 521 | nextToken(); |
| 522 | return; |
Nico Weber | 2afbe52 | 2013-02-10 04:38:23 +0000 | [diff] [blame] | 523 | case tok::l_brace: { |
| 524 | nextToken(); |
| 525 | ScopedLineState LineState(*this); |
| 526 | ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack, |
| 527 | /*MustBeDeclaration=*/ false); |
| 528 | Line->Level += 1; |
| 529 | parseLevel(/*HasOpeningBrace=*/ true); |
| 530 | Line->Level -= 1; |
Manuel Klimek | bb42bf1 | 2013-01-10 11:52:21 +0000 | [diff] [blame] | 531 | break; |
Nico Weber | 2afbe52 | 2013-02-10 04:38:23 +0000 | [diff] [blame] | 532 | } |
Nico Weber | d74fcdb | 2013-02-10 20:35:35 +0000 | [diff] [blame] | 533 | case tok::at: |
| 534 | nextToken(); |
| 535 | if (FormatTok.Tok.is(tok::l_brace)) |
| 536 | parseBracedList(); |
| 537 | break; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 538 | default: |
| 539 | nextToken(); |
| 540 | break; |
| 541 | } |
| 542 | } while (!eof()); |
| 543 | } |
| 544 | |
| 545 | void UnwrappedLineParser::parseIfThenElse() { |
| 546 | assert(FormatTok.Tok.is(tok::kw_if) && "'if' expected"); |
| 547 | nextToken(); |
Manuel Klimek | d465843 | 2013-01-11 18:28:36 +0000 | [diff] [blame] | 548 | if (FormatTok.Tok.is(tok::l_paren)) |
| 549 | parseParens(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 550 | bool NeedsUnwrappedLine = false; |
| 551 | if (FormatTok.Tok.is(tok::l_brace)) { |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 552 | parseBlock(/*MustBeDeclaration=*/ false); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 553 | NeedsUnwrappedLine = true; |
| 554 | } else { |
| 555 | addUnwrappedLine(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 556 | ++Line->Level; |
Manuel Klimek | f0ab0a3 | 2013-01-07 14:56:16 +0000 | [diff] [blame] | 557 | parseStructuralElement(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 558 | --Line->Level; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 559 | } |
| 560 | if (FormatTok.Tok.is(tok::kw_else)) { |
| 561 | nextToken(); |
| 562 | if (FormatTok.Tok.is(tok::l_brace)) { |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 563 | parseBlock(/*MustBeDeclaration=*/ false); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 564 | addUnwrappedLine(); |
| 565 | } else if (FormatTok.Tok.is(tok::kw_if)) { |
| 566 | parseIfThenElse(); |
| 567 | } else { |
| 568 | addUnwrappedLine(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 569 | ++Line->Level; |
Manuel Klimek | f0ab0a3 | 2013-01-07 14:56:16 +0000 | [diff] [blame] | 570 | parseStructuralElement(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 571 | --Line->Level; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 572 | } |
| 573 | } else if (NeedsUnwrappedLine) { |
| 574 | addUnwrappedLine(); |
| 575 | } |
| 576 | } |
| 577 | |
Alexander Kornienko | 1575731 | 2012-12-06 18:03:27 +0000 | [diff] [blame] | 578 | void UnwrappedLineParser::parseNamespace() { |
| 579 | assert(FormatTok.Tok.is(tok::kw_namespace) && "'namespace' expected"); |
| 580 | nextToken(); |
| 581 | if (FormatTok.Tok.is(tok::identifier)) |
| 582 | nextToken(); |
| 583 | if (FormatTok.Tok.is(tok::l_brace)) { |
Manuel Klimek | 44135b8 | 2013-05-13 12:51:40 +0000 | [diff] [blame^] | 584 | if (Style.BreakBeforeBraces == FormatStyle::BS_Linux) |
| 585 | addUnwrappedLine(); |
| 586 | |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 587 | parseBlock(/*MustBeDeclaration=*/ true, 0); |
Manuel Klimek | 7fc2db0 | 2013-02-06 16:08:09 +0000 | [diff] [blame] | 588 | // Munch the semicolon after a namespace. This is more common than one would |
| 589 | // think. Puttin the semicolon into its own line is very ugly. |
| 590 | if (FormatTok.Tok.is(tok::semi)) |
| 591 | nextToken(); |
Alexander Kornienko | 1575731 | 2012-12-06 18:03:27 +0000 | [diff] [blame] | 592 | addUnwrappedLine(); |
| 593 | } |
| 594 | // FIXME: Add error handling. |
| 595 | } |
| 596 | |
Alexander Kornienko | 2e97cfc | 2012-12-05 15:06:06 +0000 | [diff] [blame] | 597 | void UnwrappedLineParser::parseForOrWhileLoop() { |
| 598 | assert((FormatTok.Tok.is(tok::kw_for) || FormatTok.Tok.is(tok::kw_while)) && |
| 599 | "'for' or 'while' expected"); |
| 600 | nextToken(); |
Manuel Klimek | 6eca03f | 2013-01-11 19:23:05 +0000 | [diff] [blame] | 601 | if (FormatTok.Tok.is(tok::l_paren)) |
| 602 | parseParens(); |
Alexander Kornienko | 2e97cfc | 2012-12-05 15:06:06 +0000 | [diff] [blame] | 603 | if (FormatTok.Tok.is(tok::l_brace)) { |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 604 | parseBlock(/*MustBeDeclaration=*/ false); |
Alexander Kornienko | 2e97cfc | 2012-12-05 15:06:06 +0000 | [diff] [blame] | 605 | addUnwrappedLine(); |
| 606 | } else { |
| 607 | addUnwrappedLine(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 608 | ++Line->Level; |
Manuel Klimek | f0ab0a3 | 2013-01-07 14:56:16 +0000 | [diff] [blame] | 609 | parseStructuralElement(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 610 | --Line->Level; |
Alexander Kornienko | 2e97cfc | 2012-12-05 15:06:06 +0000 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 614 | void UnwrappedLineParser::parseDoWhile() { |
| 615 | assert(FormatTok.Tok.is(tok::kw_do) && "'do' expected"); |
| 616 | nextToken(); |
| 617 | if (FormatTok.Tok.is(tok::l_brace)) { |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 618 | parseBlock(/*MustBeDeclaration=*/ false); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 619 | } else { |
| 620 | addUnwrappedLine(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 621 | ++Line->Level; |
Manuel Klimek | f0ab0a3 | 2013-01-07 14:56:16 +0000 | [diff] [blame] | 622 | parseStructuralElement(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 623 | --Line->Level; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Alexander Kornienko | 393b008 | 2012-12-04 15:40:36 +0000 | [diff] [blame] | 626 | // FIXME: Add error handling. |
| 627 | if (!FormatTok.Tok.is(tok::kw_while)) { |
| 628 | addUnwrappedLine(); |
| 629 | return; |
| 630 | } |
| 631 | |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 632 | nextToken(); |
Manuel Klimek | f0ab0a3 | 2013-01-07 14:56:16 +0000 | [diff] [blame] | 633 | parseStructuralElement(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | void UnwrappedLineParser::parseLabel() { |
Daniel Jasper | 89a0daa | 2013-02-12 20:17:17 +0000 | [diff] [blame] | 637 | if (FormatTok.Tok.isNot(tok::colon)) |
| 638 | return; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 639 | nextToken(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 640 | unsigned OldLineLevel = Line->Level; |
Daniel Jasper | bcca7e4 | 2013-03-20 10:23:53 +0000 | [diff] [blame] | 641 | if (Line->Level > 1 || (!Line->InPPDirective && Line->Level > 0)) |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 642 | --Line->Level; |
Daniel Jasper | c30eb51 | 2013-03-19 18:33:58 +0000 | [diff] [blame] | 643 | if (CommentsBeforeNextToken.empty() && FormatTok.Tok.is(tok::l_brace)) { |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 644 | parseBlock(/*MustBeDeclaration=*/ false); |
Nico Weber | 94fb729 | 2013-01-18 05:50:57 +0000 | [diff] [blame] | 645 | if (FormatTok.Tok.is(tok::kw_break)) |
| 646 | parseStructuralElement(); // "break;" after "}" goes on the same line. |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 647 | } |
| 648 | addUnwrappedLine(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 649 | Line->Level = OldLineLevel; |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void UnwrappedLineParser::parseCaseLabel() { |
| 653 | assert(FormatTok.Tok.is(tok::kw_case) && "'case' expected"); |
| 654 | // FIXME: fix handling of complex expressions here. |
| 655 | do { |
| 656 | nextToken(); |
| 657 | } while (!eof() && !FormatTok.Tok.is(tok::colon)); |
| 658 | parseLabel(); |
| 659 | } |
| 660 | |
| 661 | void UnwrappedLineParser::parseSwitch() { |
| 662 | assert(FormatTok.Tok.is(tok::kw_switch) && "'switch' expected"); |
| 663 | nextToken(); |
Manuel Klimek | 6eca03f | 2013-01-11 19:23:05 +0000 | [diff] [blame] | 664 | if (FormatTok.Tok.is(tok::l_paren)) |
| 665 | parseParens(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 666 | if (FormatTok.Tok.is(tok::l_brace)) { |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 667 | parseBlock(/*MustBeDeclaration=*/ false, Style.IndentCaseLabels ? 2 : 1); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 668 | addUnwrappedLine(); |
| 669 | } else { |
| 670 | addUnwrappedLine(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 671 | Line->Level += (Style.IndentCaseLabels ? 2 : 1); |
Manuel Klimek | f0ab0a3 | 2013-01-07 14:56:16 +0000 | [diff] [blame] | 672 | parseStructuralElement(); |
Manuel Klimek | 526ed11 | 2013-01-09 15:25:02 +0000 | [diff] [blame] | 673 | Line->Level -= (Style.IndentCaseLabels ? 2 : 1); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
| 677 | void UnwrappedLineParser::parseAccessSpecifier() { |
| 678 | nextToken(); |
Alexander Kornienko | 56e49c5 | 2012-12-10 16:34:48 +0000 | [diff] [blame] | 679 | // Otherwise, we don't know what it is, and we'd better keep the next token. |
| 680 | if (FormatTok.Tok.is(tok::colon)) |
| 681 | nextToken(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 682 | addUnwrappedLine(); |
| 683 | } |
| 684 | |
| 685 | void UnwrappedLineParser::parseEnum() { |
Manuel Klimek | 308232c | 2013-01-21 19:17:52 +0000 | [diff] [blame] | 686 | nextToken(); |
| 687 | if (FormatTok.Tok.is(tok::identifier) || |
| 688 | FormatTok.Tok.is(tok::kw___attribute) || |
| 689 | FormatTok.Tok.is(tok::kw___declspec)) { |
| 690 | nextToken(); |
| 691 | // We can have macros or attributes in between 'enum' and the enum name. |
| 692 | if (FormatTok.Tok.is(tok::l_paren)) { |
Alexander Kornienko | a166e73 | 2012-12-04 14:46:19 +0000 | [diff] [blame] | 693 | parseParens(); |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 694 | } |
Manuel Klimek | 308232c | 2013-01-21 19:17:52 +0000 | [diff] [blame] | 695 | if (FormatTok.Tok.is(tok::identifier)) |
| 696 | nextToken(); |
| 697 | } |
| 698 | if (FormatTok.Tok.is(tok::l_brace)) { |
| 699 | nextToken(); |
| 700 | addUnwrappedLine(); |
| 701 | ++Line->Level; |
| 702 | do { |
| 703 | switch (FormatTok.Tok.getKind()) { |
Manuel Klimek | 308232c | 2013-01-21 19:17:52 +0000 | [diff] [blame] | 704 | case tok::l_paren: |
| 705 | parseParens(); |
| 706 | break; |
| 707 | case tok::r_brace: |
| 708 | addUnwrappedLine(); |
| 709 | nextToken(); |
| 710 | --Line->Level; |
| 711 | return; |
| 712 | case tok::comma: |
| 713 | nextToken(); |
| 714 | addUnwrappedLine(); |
| 715 | break; |
| 716 | default: |
| 717 | nextToken(); |
| 718 | break; |
| 719 | } |
| 720 | } while (!eof()); |
| 721 | } |
| 722 | // We fall through to parsing a structural element afterwards, so that in |
| 723 | // enum A {} n, m; |
| 724 | // "} n, m;" will end up in one unwrapped line. |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Manuel Klimek | 47ea7f6 | 2013-01-15 13:38:33 +0000 | [diff] [blame] | 727 | void UnwrappedLineParser::parseRecord() { |
Manuel Klimek | de76854 | 2013-01-07 18:10:23 +0000 | [diff] [blame] | 728 | nextToken(); |
Manuel Klimek | 47ea7f6 | 2013-01-15 13:38:33 +0000 | [diff] [blame] | 729 | if (FormatTok.Tok.is(tok::identifier) || |
| 730 | FormatTok.Tok.is(tok::kw___attribute) || |
| 731 | FormatTok.Tok.is(tok::kw___declspec)) { |
| 732 | nextToken(); |
| 733 | // We can have macros or attributes in between 'class' and the class name. |
| 734 | if (FormatTok.Tok.is(tok::l_paren)) { |
| 735 | parseParens(); |
Manuel Klimek | de76854 | 2013-01-07 18:10:23 +0000 | [diff] [blame] | 736 | } |
Manuel Klimek | b8b1ce1 | 2013-02-06 15:57:54 +0000 | [diff] [blame] | 737 | // The actual identifier can be a nested name specifier, and in macros |
| 738 | // it is often token-pasted. |
Manuel Klimek | 7f5b025 | 2013-01-21 10:17:14 +0000 | [diff] [blame] | 739 | while (FormatTok.Tok.is(tok::identifier) || |
Daniel Jasper | f9955d3 | 2013-03-20 12:37:50 +0000 | [diff] [blame] | 740 | FormatTok.Tok.is(tok::coloncolon) || FormatTok.Tok.is(tok::hashhash)) |
Manuel Klimek | 47ea7f6 | 2013-01-15 13:38:33 +0000 | [diff] [blame] | 741 | nextToken(); |
| 742 | |
Manuel Klimek | 3a3408c | 2013-01-21 13:58:54 +0000 | [diff] [blame] | 743 | // Note that parsing away template declarations here leads to incorrectly |
| 744 | // accepting function declarations as record declarations. |
| 745 | // In general, we cannot solve this problem. Consider: |
| 746 | // class A<int> B() {} |
| 747 | // which can be a function definition or a class definition when B() is a |
| 748 | // macro. If we find enough real-world cases where this is a problem, we |
| 749 | // can parse for the 'template' keyword in the beginning of the statement, |
| 750 | // and thus rule out the record production in case there is no template |
| 751 | // (this would still leave us with an ambiguity between template function |
| 752 | // and class declarations). |
| 753 | if (FormatTok.Tok.is(tok::colon) || FormatTok.Tok.is(tok::less)) { |
Daniel Jasper | 6fe554e | 2013-03-20 15:12:38 +0000 | [diff] [blame] | 754 | while (!eof() && FormatTok.Tok.isNot(tok::l_brace)) { |
Manuel Klimek | 47ea7f6 | 2013-01-15 13:38:33 +0000 | [diff] [blame] | 755 | if (FormatTok.Tok.is(tok::semi)) |
| 756 | return; |
| 757 | nextToken(); |
| 758 | } |
| 759 | } |
| 760 | } |
Manuel Klimek | 44135b8 | 2013-05-13 12:51:40 +0000 | [diff] [blame^] | 761 | if (FormatTok.Tok.is(tok::l_brace)) { |
| 762 | if (Style.BreakBeforeBraces == FormatStyle::BS_Linux) |
| 763 | addUnwrappedLine(); |
| 764 | |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 765 | parseBlock(/*MustBeDeclaration=*/ true); |
Manuel Klimek | 44135b8 | 2013-05-13 12:51:40 +0000 | [diff] [blame^] | 766 | } |
Manuel Klimek | 3a3408c | 2013-01-21 13:58:54 +0000 | [diff] [blame] | 767 | // We fall through to parsing a structural element afterwards, so |
| 768 | // class A {} n, m; |
| 769 | // will end up in one unwrapped line. |
Manuel Klimek | de76854 | 2013-01-07 18:10:23 +0000 | [diff] [blame] | 770 | } |
| 771 | |
Nico Weber | 1abe6ea | 2013-01-09 21:15:03 +0000 | [diff] [blame] | 772 | void UnwrappedLineParser::parseObjCProtocolList() { |
| 773 | assert(FormatTok.Tok.is(tok::less) && "'<' expected."); |
| 774 | do |
| 775 | nextToken(); |
| 776 | while (!eof() && FormatTok.Tok.isNot(tok::greater)); |
| 777 | nextToken(); // Skip '>'. |
| 778 | } |
| 779 | |
| 780 | void UnwrappedLineParser::parseObjCUntilAtEnd() { |
| 781 | do { |
| 782 | if (FormatTok.Tok.isObjCAtKeyword(tok::objc_end)) { |
| 783 | nextToken(); |
| 784 | addUnwrappedLine(); |
| 785 | break; |
| 786 | } |
| 787 | parseStructuralElement(); |
| 788 | } while (!eof()); |
| 789 | } |
| 790 | |
Nico Weber | 50767d8 | 2013-01-09 23:25:37 +0000 | [diff] [blame] | 791 | void UnwrappedLineParser::parseObjCInterfaceOrImplementation() { |
Nico Weber | 27d1367 | 2013-01-09 20:25:35 +0000 | [diff] [blame] | 792 | nextToken(); |
Daniel Jasper | f9955d3 | 2013-03-20 12:37:50 +0000 | [diff] [blame] | 793 | nextToken(); // interface name |
Nico Weber | 27d1367 | 2013-01-09 20:25:35 +0000 | [diff] [blame] | 794 | |
| 795 | // @interface can be followed by either a base class, or a category. |
| 796 | if (FormatTok.Tok.is(tok::colon)) { |
| 797 | nextToken(); |
Daniel Jasper | f9955d3 | 2013-03-20 12:37:50 +0000 | [diff] [blame] | 798 | nextToken(); // base class name |
Nico Weber | 27d1367 | 2013-01-09 20:25:35 +0000 | [diff] [blame] | 799 | } else if (FormatTok.Tok.is(tok::l_paren)) |
| 800 | // Skip category, if present. |
| 801 | parseParens(); |
| 802 | |
Nico Weber | 1abe6ea | 2013-01-09 21:15:03 +0000 | [diff] [blame] | 803 | if (FormatTok.Tok.is(tok::less)) |
| 804 | parseObjCProtocolList(); |
Nico Weber | 27d1367 | 2013-01-09 20:25:35 +0000 | [diff] [blame] | 805 | |
| 806 | // If instance variables are present, keep the '{' on the first line too. |
| 807 | if (FormatTok.Tok.is(tok::l_brace)) |
Manuel Klimek | 70b03f4 | 2013-01-23 09:32:48 +0000 | [diff] [blame] | 808 | parseBlock(/*MustBeDeclaration=*/ true); |
Nico Weber | 27d1367 | 2013-01-09 20:25:35 +0000 | [diff] [blame] | 809 | |
| 810 | // With instance variables, this puts '}' on its own line. Without instance |
| 811 | // variables, this ends the @interface line. |
| 812 | addUnwrappedLine(); |
| 813 | |
Nico Weber | 1abe6ea | 2013-01-09 21:15:03 +0000 | [diff] [blame] | 814 | parseObjCUntilAtEnd(); |
| 815 | } |
Nico Weber | 27d1367 | 2013-01-09 20:25:35 +0000 | [diff] [blame] | 816 | |
Nico Weber | 1abe6ea | 2013-01-09 21:15:03 +0000 | [diff] [blame] | 817 | void UnwrappedLineParser::parseObjCProtocol() { |
| 818 | nextToken(); |
Daniel Jasper | f9955d3 | 2013-03-20 12:37:50 +0000 | [diff] [blame] | 819 | nextToken(); // protocol name |
Nico Weber | 1abe6ea | 2013-01-09 21:15:03 +0000 | [diff] [blame] | 820 | |
| 821 | if (FormatTok.Tok.is(tok::less)) |
| 822 | parseObjCProtocolList(); |
| 823 | |
| 824 | // Check for protocol declaration. |
| 825 | if (FormatTok.Tok.is(tok::semi)) { |
| 826 | nextToken(); |
| 827 | return addUnwrappedLine(); |
| 828 | } |
| 829 | |
| 830 | addUnwrappedLine(); |
| 831 | parseObjCUntilAtEnd(); |
Nico Weber | 27d1367 | 2013-01-09 20:25:35 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 834 | void UnwrappedLineParser::addUnwrappedLine() { |
Daniel Jasper | cbb6c41 | 2013-01-16 09:10:19 +0000 | [diff] [blame] | 835 | if (Line->Tokens.empty()) |
Daniel Jasper | 26f7e78 | 2013-01-08 14:56:18 +0000 | [diff] [blame] | 836 | return; |
Manuel Klimek | 8fa3799 | 2013-01-16 12:31:12 +0000 | [diff] [blame] | 837 | DEBUG({ |
Manuel Klimek | a28fc06 | 2013-02-11 12:33:24 +0000 | [diff] [blame] | 838 | llvm::dbgs() << "Line(" << Line->Level << ")" |
| 839 | << (Line->InPPDirective ? " MACRO" : "") << ": "; |
Manuel Klimek | 8fa3799 | 2013-01-16 12:31:12 +0000 | [diff] [blame] | 840 | for (std::list<FormatToken>::iterator I = Line->Tokens.begin(), |
| 841 | E = Line->Tokens.end(); |
| 842 | I != E; ++I) { |
| 843 | llvm::dbgs() << I->Tok.getName() << " "; |
Daniel Jasper | cbb6c41 | 2013-01-16 09:10:19 +0000 | [diff] [blame] | 844 | |
Manuel Klimek | 8fa3799 | 2013-01-16 12:31:12 +0000 | [diff] [blame] | 845 | } |
| 846 | llvm::dbgs() << "\n"; |
| 847 | }); |
Manuel Klimek | 525fe16 | 2013-01-18 14:04:34 +0000 | [diff] [blame] | 848 | CurrentLines->push_back(*Line); |
Daniel Jasper | cbb6c41 | 2013-01-16 09:10:19 +0000 | [diff] [blame] | 849 | Line->Tokens.clear(); |
Manuel Klimek | 525fe16 | 2013-01-18 14:04:34 +0000 | [diff] [blame] | 850 | if (CurrentLines == &Lines && !PreprocessorDirectives.empty()) { |
Daniel Jasper | 516fb31 | 2013-03-01 18:11:39 +0000 | [diff] [blame] | 851 | for (std::vector<UnwrappedLine>::iterator |
| 852 | I = PreprocessorDirectives.begin(), |
| 853 | E = PreprocessorDirectives.end(); |
Manuel Klimek | 525fe16 | 2013-01-18 14:04:34 +0000 | [diff] [blame] | 854 | I != E; ++I) { |
| 855 | CurrentLines->push_back(*I); |
| 856 | } |
| 857 | PreprocessorDirectives.clear(); |
| 858 | } |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Daniel Jasper | f9955d3 | 2013-03-20 12:37:50 +0000 | [diff] [blame] | 861 | bool UnwrappedLineParser::eof() const { return FormatTok.Tok.is(tok::eof); } |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 862 | |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 863 | void UnwrappedLineParser::flushComments(bool NewlineBeforeNext) { |
| 864 | bool JustComments = Line->Tokens.empty(); |
| 865 | for (SmallVectorImpl<FormatToken>::const_iterator |
| 866 | I = CommentsBeforeNextToken.begin(), |
| 867 | E = CommentsBeforeNextToken.end(); |
| 868 | I != E; ++I) { |
Manuel Klimek | b3507cd | 2013-02-06 16:40:56 +0000 | [diff] [blame] | 869 | if (I->NewlinesBefore && JustComments) { |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 870 | addUnwrappedLine(); |
| 871 | } |
| 872 | pushToken(*I); |
| 873 | } |
| 874 | if (NewlineBeforeNext && JustComments) { |
| 875 | addUnwrappedLine(); |
| 876 | } |
| 877 | CommentsBeforeNextToken.clear(); |
| 878 | } |
| 879 | |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 880 | void UnwrappedLineParser::nextToken() { |
| 881 | if (eof()) |
| 882 | return; |
Manuel Klimek | b3507cd | 2013-02-06 16:40:56 +0000 | [diff] [blame] | 883 | flushComments(FormatTok.NewlinesBefore > 0); |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 884 | pushToken(FormatTok); |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 885 | readToken(); |
| 886 | } |
| 887 | |
| 888 | void UnwrappedLineParser::readToken() { |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 889 | bool CommentsInCurrentLine = true; |
| 890 | do { |
| 891 | FormatTok = Tokens->getNextToken(); |
| 892 | while (!Line->InPPDirective && FormatTok.Tok.is(tok::hash) && |
Alexander Kornienko | 3d713a7 | 2013-04-08 22:16:06 +0000 | [diff] [blame] | 893 | (FormatTok.HasUnescapedNewline || FormatTok.IsFirst)) { |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 894 | // If there is an unfinished unwrapped line, we flush the preprocessor |
| 895 | // directives only after that unwrapped line was finished later. |
Daniel Jasper | f9955d3 | 2013-03-20 12:37:50 +0000 | [diff] [blame] | 896 | bool SwitchToPreprocessorLines = |
| 897 | !Line->Tokens.empty() && CurrentLines == &Lines; |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 898 | ScopedLineState BlockState(*this, SwitchToPreprocessorLines); |
Alexander Kornienko | 4128e19 | 2013-04-03 12:38:53 +0000 | [diff] [blame] | 899 | // Comments stored before the preprocessor directive need to be output |
| 900 | // before the preprocessor directive, at the same level as the |
| 901 | // preprocessor directive, as we consider them to apply to the directive. |
| 902 | flushComments(FormatTok.NewlinesBefore > 0); |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 903 | parsePPDirective(); |
| 904 | } |
| 905 | if (!FormatTok.Tok.is(tok::comment)) |
| 906 | return; |
Manuel Klimek | b3507cd | 2013-02-06 16:40:56 +0000 | [diff] [blame] | 907 | if (FormatTok.NewlinesBefore > 0 || FormatTok.IsFirst) { |
Manuel Klimek | 86721d2 | 2013-01-22 16:31:55 +0000 | [diff] [blame] | 908 | CommentsInCurrentLine = false; |
| 909 | } |
| 910 | if (CommentsInCurrentLine) { |
| 911 | pushToken(FormatTok); |
| 912 | } else { |
| 913 | CommentsBeforeNextToken.push_back(FormatTok); |
| 914 | } |
| 915 | } while (!eof()); |
| 916 | } |
| 917 | |
| 918 | void UnwrappedLineParser::pushToken(const FormatToken &Tok) { |
| 919 | Line->Tokens.push_back(Tok); |
| 920 | if (MustBreakBeforeNextToken) { |
| 921 | Line->Tokens.back().MustBreakBefore = true; |
| 922 | MustBreakBeforeNextToken = false; |
Manuel Klimek | d4397b9 | 2013-01-04 23:34:14 +0000 | [diff] [blame] | 923 | } |
Daniel Jasper | bac016b | 2012-12-03 18:12:45 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Daniel Jasper | cd16238 | 2013-01-07 13:26:07 +0000 | [diff] [blame] | 926 | } // end namespace format |
| 927 | } // end namespace clang |