summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Do not ever allow using the full line in preprocessor directives.Manuel Klimek2013-01-071-1/+1
| | | | | | | | | | | | | | | | We would format: #define A \ int f(a); int i; as #define A \ int f(a);\ int i The fix will break up macro definitions that could fit a line, but hit the last column; fixing that is more involved, though, as it requires looking at the following line. llvm-svn: 171715
* Fix layouting of single-line-comments preceded by an escaped newline.Manuel Klimek2013-01-071-7/+7
| | | | | | | | | | | | | Previously, we'd format int i;\ // comment as int i; // comment The problem is that the escaped newline is part of the next token, and thus the raw token text of the comment doesn't start with "//". llvm-svn: 171713
* Fix layouting of tokens with a leading escaped newline.Manuel Klimek2013-01-072-8/+22
| | | | | | | | | | | If a token follows directly on an escaped newline, the escaped newline is stored with the token. Since we re-layout escaped newlines, we need to treat them just like normal whitespace - thus, we need to increase the whitespace-length of the token, while decreasing the token length (otherwise the token length contains the length of the escaped newline and we double-count it while indenting). llvm-svn: 171706
* Put a higher penalty on breaking before "." or "->".Daniel Jasper2013-01-071-2/+2
| | | | | | | | | | | | | | This fixes llvm.org/PR14823. Before: local_state->SetString(prefs::kApplicationLocale, parent_local_state ->GetString(prefs::kApplicationLocale)); After: local_state->SetString( prefs::kApplicationLocale, parent_local_state->GetString(prefs::kApplicationLocale)); llvm-svn: 171705
* Fixes handling of unbalances braces.Manuel Klimek2013-01-062-6/+13
| | | | | | | | | | | | | If we find an unexpected closing brace, we must not stop parsing, as we'd otherwise not layout anything beyond that point. If we find a structural error on the highest level we'll not re-indent anyway, but we'll still want to format within unwrapped lines. Needed to introduce a differentiation between an expected and unexpected closing brace. llvm-svn: 171666
* Fixes parsing of hash tokens in the middle of a line.Manuel Klimek2013-01-053-7/+15
| | | | | | | | | | | To parse # correctly, we need to know whether it is the first token in a line - we can deduct this either from the whitespace or seeing that the token is the first in the file - we already calculate this information. This patch moves the identification of the first token into the getNextToken method and stores it inside the FormatToken, so the UnwrappedLineParser can stay independent of the SourceManager. llvm-svn: 171640
* Fixes PR14801 - preprocessor directives shouldn't be indentedManuel Klimek2013-01-052-3/+7
| | | | | | | Uses indent 0 for macros for now and resets the indent state to the level prior to the preprocessor directive. llvm-svn: 171639
* Fixes PR14811: Crash when formatting some macrosManuel Klimek2013-01-051-1/+1
| | | | | | A preprocessor directive cannot be started while we're parsing one. llvm-svn: 171635
* Various fixes to clang-format's macro handling.Manuel Klimek2013-01-043-30/+148
| | | | | | | | | | | | | | | | | | | Some of this is still pretty rough (note the load of FIXMEs), but it is strictly an improvement and fixes various bugs that were related to macro processing but are also imporant in non-macro use cases. Specific fixes: - correctly puts espaced newlines at the end of the line - fixes counting of white space before a token when escaped newlines are present - fixes parsing of "trailing" tokens when eof() is hit - puts macro parsing orthogonal to parsing other structure - general support for parsing of macro definitions Due to the fix to format trailing tokens, this change also includes a bunch of fixes to the c-index tests. llvm-svn: 171556
* Correctly format dereference and address of in array parameters.Daniel Jasper2013-01-041-2/+3
| | | | | | | | | Before: InvalidRegions[ &R] = 0; After: InvalidRegions[&R] = 0; This fixes llvm.org/PR14793 llvm-svn: 171522
* Let the formatter ignore UnwrappedLines containing errors.Daniel Jasper2013-01-041-17/+35
| | | | | | | | | | | | | | This prevents code like: namespace { class Foo { Foo( }; } // comment from causing segfaults (see llvm.org/PR14774). llvm-svn: 171495
* Fixes multiple formatting bugs.Manuel Klimek2013-01-021-8/+27
| | | | | | | | | | | Fixes: - incorrect handling of multiple consecutive preprocessor directives - crash when trying to right align the escpaed newline for a line that is longer than the column limit - using only ColumnLimit-1 columns when layouting with escaped newlines inside preprocessor directives llvm-svn: 171401
* Don't allow line breaks after template parameters.Daniel Jasper2013-01-021-0/+3
| | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR14786. We will need to split there as a last resort, but that should be done consistently independent of whether the type is a template type or not. Before: template <typename T> aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa<T> ::aaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: template <typename T> aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 171400
* Format */& as binary operator if followed by a unary operator.Daniel Jasper2013-01-021-5/+9
| | | | | | | | | | | | | | | This fixes llvm.org/PR14687. Also fixes segfault for lines starting with * or &. Before: a *~b; *a = 1; // <- this segfaulted After: a * ~b; *a = 1; // no segfault :-) llvm-svn: 171396
* Fixes use of unescaped newlines when formatting preprocessor directives.Manuel Klimek2013-01-023-10/+48
| | | | | | | | | | | This is the first step towards handling preprocessor directives. This patch only fixes the most pressing issue, namely correctly escaping newlines for tokens within a sequence of a preprocessor directive. The next step will be to fix incorrect format decisions on #define directives. llvm-svn: 171393
* Correctly format pointers and references in casts.Daniel Jasper2013-01-021-7/+11
| | | | | | | | This fixes llvm.org/PR14747. Before: Type *A = (Type * ) P; After: Type *A = (Type *) P; llvm-svn: 171390
* Understand unary operators after "return" and "case".Daniel Jasper2013-01-021-1/+2
| | | | | | | | This fixes llvm.org/PR14746. Before: return - 1; After: return -1; llvm-svn: 171389
* Prefer splitting after "template <...>" and fix indentation.Daniel Jasper2013-01-021-1/+22
| | | | | | | | | | | | | | | | | | | This addresses llvm.org/PR14699 Before: template <typename T> void looooooooooooooooooooooongFunction(int Param1, int Param2); template <typename T> void looooooooooooooooooooongFunction( int Paaaaaaaaaaaaaaaaaaaaram1, int Paaaaaaaaaaaaaaaaaaaaram2); After: template <typename T> void looooooooooooooooooooooongFunction(int Param1, int Param2); template <typename T> void looooooooooooooooooooongFunction(int Paaaaaaaaaaaaaaaaaaaaram1, int Paaaaaaaaaaaaaaaaaaaaram2); llvm-svn: 171388
* Prefer to break after operators over breaking after "(".Daniel Jasper2013-01-021-1/+1
| | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 171386
* Re-sort #include lines using the llvm/utils/sort_includes.py script.Chandler Carruth2013-01-021-2/+1
| | | | | | | Removes a duplicate #include as well as cleaning up some sort order regressions since I last ran the script over Clang. llvm-svn: 171364
* Understand * and & in ternary expressions.Daniel Jasper2013-01-021-0/+1
| | | | | | Before: "int a = b ? *c : * d;" After: "int a = b ? *c : *d; llvm-svn: 171358
* Don't break after pointer or reference specifier.Daniel Jasper2013-01-021-3/+8
| | | | | | | | | | | | | | | This fixes llvm.org/PR14717. Buggy format: TypeSpecDecl * TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *II, Type *T) { Now changed to: TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *II, Type *T) { llvm-svn: 171357
* Formatter: parse and format inline namespaces like regular namespacesDmitri Gribenko2012-12-301-1/+9
| | | | | | | | | | | | | | | | | | This changes formatting from: inline namespace X { class A { }; } to: inline namespace X { class A { }; } llvm-svn: 171266
* Let clang-format format itself.Daniel Jasper2012-12-243-24/+22
| | | | | | | | Apply all formatting changes that clang-format would apply to its own source code. All choices seem to improve readability (or at least not make it worse). No functional changes. llvm-svn: 171039
* Penalize tokens with a lower parenthesis level than the start of the line.Daniel Jasper2012-12-241-1/+15
| | | | | | | | | | | | | | | | This prevents formattings like this (assuming "parameter" doesn't fit the line): bool f = someFunction() && someFunctionWithParam( parameter) && someOtherFunction(); Here, "parameter" - the start of line 2 - has a parenthesis level of 2, but there are subsequent tokens ("&&" and "someOtherFunction") with a lower level. This is bad for readability as "parameter" hides "someOtherFunction". With this patch, this changes to: bool f = someFunction() && someFunctionWithParam(parameter) && someOtherFunction(); llvm-svn: 171038
* Align RHS after assignments and return statements.Daniel Jasper2012-12-241-6/+15
| | | | | | | | | | | | | | | | This changes: int Result = a + // force break b; return Result + // force break 5; To: int Result = a + // force break b; return Result + // force break 5; llvm-svn: 171032
* Fix formatting over overloaded operators.Daniel Jasper2012-12-241-2/+19
| | | | | | | | | | | | | | | | | | | This fixes llvm.org/pr14686. We used to add too many spaces for different versions of overloaded operator function declarations/definitions. This patch changes, e.g. operator *() {} operator >() {} operator () () {} to operator*() {} operator>() {} operator()() {} llvm-svn: 171028
* Take operator precedence into account when splitting lines.Daniel Jasper2012-12-241-3/+7
| | | | | | | | | | | | | | | With this patch, splitting after binary operators has a panelty corresponding to the operator's precedence. We used to ignore this and eagerly format like: if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) { .. } With this patch, this becomes: if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) { .. } llvm-svn: 171007
* libFormat: Teach the *& usage heuristic that "return" starts a rhs too.Nico Weber2012-12-231-5/+8
| | | | | | | | "return a*b;" was formatted as "return a *b;" and is now formatted as "return a * b;". Fixes PR14687 partially. llvm-svn: 170993
* format: Handle #import as include directive too.Nico Weber2012-12-211-0/+1
| | | | llvm-svn: 170914
* clang-format: No spaces around directory specifiersDaniel Jasper2012-12-211-2/+37
| | | | | | | | | | This fixes PR14683. We used to format like this: #include <a / b> And this patch changes this to: #include <a/b> llvm-svn: 170910
* Fix typo.Fariborz Jahanian2012-12-211-1/+1
| | | | llvm-svn: 170904
* Basic support for formatting for-loops.Daniel Jasper2012-12-211-7/+42
| | | | | | | | | | | | | We used to not really format them. Now we do: for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end(); SI != SE; ++SI) { This is just one example and I am sure we still mess some of them up, but it is a step forward. llvm-svn: 170899
* Use OperatorPrecedence.h in clang-formatDaniel Jasper2012-12-211-28/+14
| | | | | | | No indented functional changes other than handling more operators correctly. llvm-svn: 170875
* Formatting fixes for PR14680Daniel Jasper2012-12-211-62/+61
| | | | | | Also, some (automated) formatting fixes and slight cleanups. llvm-svn: 170873
* Add objective-C style formatting to clang format andFariborz Jahanian2012-12-201-6/+52
| | | | | | | use it to format xml declaration tags. // rdar://12378714 llvm-svn: 170727
* Better support for constructor initializers.Daniel Jasper2012-12-181-49/+44
| | | | | | | | | | | | | | | | | | | | We used to format initializers like this (with a sort of hacky implementation): Constructor() : Val1(A), Val2(B) { and now format like this (with a somewhat better solution): Constructor() : Val1(A), Val2(B) { assuming this would not fit on a single line. Also added tests. As a side effect we now first analyze whether an UnwrappedLine needs to be split at all. If not, not splitting it is the best solution by definition. As this should be a very common case in normal code, not exploring the entire solution space can provide significant speedup. llvm-svn: 170457
* Add basic support for splitting before function calls if it can't beDaniel Jasper2012-12-171-16/+29
| | | | | | | | | | | | avoided. This required a minor modification of the memoization as now the "CurrentPenalty" depends on whether or not we break before the current token. Therefore, the CurrentPenalty should not be memoized but added after retrieving a value from memory. This should not affect the runtime behavior. llvm-svn: 170337
* Fix several formatting problems.Daniel Jasper2012-12-173-17/+21
| | | | | | | | | More specifically: - Improve formatting of static initializers. - Fix formatting of lines comments in enums. - Fix formmating of trailing line comments. llvm-svn: 170316
* Addi formatting tests for pointer template parameters.Daniel Jasper2012-12-101-2/+2
| | | | | | Fix spacing before ",". llvm-svn: 169746
* Clang-format: error recovery for access specifiersAlexander Kornienko2012-12-102-3/+6
| | | | | | | | | | | | Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D198 llvm-svn: 169738
* Appease -Wnon-virtual-dtorMatt Beaumont-Gay2012-12-071-0/+2
| | | | llvm-svn: 169648
* Clang-format: extracted FormatTokenSource from UnwrappedLineParser.Alexander Kornienko2012-12-073-61/+76
| | | | | | | | | | | | | | Summary: FormatTokenLexer is here, FormatTokenBuffer is on the way. This will allow to re-parse unwrapped lines when needed. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D186 llvm-svn: 169605
* Small tweaks to clang-format.Daniel Jasper2012-12-071-3/+7
| | | | | | | Now not joining keywords with '::' and not putting a space between a pointer pointer. llvm-svn: 169594
* Clang-format: IndentCaseLabels option, proper namespace handlingAlexander Kornienko2012-12-063-15/+34
| | | | | | | | | | | | | | Summary: + tests arranged in groups, as their number is already quite large. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D185 llvm-svn: 169520
* Clang-format: detect unbalanced braces.Alexander Kornienko2012-12-061-2/+3
| | | | | | | | | | | | Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits, silvas Differential Revision: http://llvm-reviews.chandlerc.com/D176 llvm-svn: 169518
* Improve clang-format's handling of unary operators.Daniel Jasper2012-12-061-0/+12
| | | | llvm-svn: 169500
* "<<" alignment for clang-format.Daniel Jasper2012-12-061-7/+41
| | | | | | | Also, small fix for handling the first token correctly. Review: http://llvm-reviews.chandlerc.com/D177 llvm-svn: 169488
* Remove bad and useless enum to bool conversion.Daniel Jasper2012-12-051-5/+2
| | | | llvm-svn: 169390
* Clang-format: parse for and while loopsAlexander Kornienko2012-12-052-0/+21
| | | | | | | | | | | | | | Summary: Adds support for formatting for and while loops. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D174 llvm-svn: 169387
OpenPOWER on IntegriCloud