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