summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.h
Commit message (Collapse)AuthorAgeFilesLines
* [clang-format] Format raw string literalsKrasimir Georgiev2017-10-301-0/+7
| | | | | | | | | | | | | | | Summary: This patch adds raw string literal formatting. Reviewers: djasper, klimek Reviewed By: klimek Subscribers: klimek, mgorny Differential Revision: https://reviews.llvm.org/D35943 llvm-svn: 316903
* clang-format clang-format.Manuel Klimek2017-09-201-2/+3
| | | | llvm-svn: 313744
* Fix clang-format's detection of structured bindings.Manuel Klimek2017-09-201-1/+0
| | | | | | | | | | | | | | | | | | | Correctly determine when [ is part of a structured binding instead of a lambda. To be able to reuse the implementation already available, this patch also: - sets the Previous link of FormatTokens in the UnwrappedLineParser - moves the isCppStructuredBinding function into FormatToken Before: auto const const &&[x, y] { A *i }; After: auto const const && [x, y]{A * i}; Fixing formatting of the type of the structured binding is still missing. llvm-svn: 313742
* Fix formatting of lambda introducers with initializers.Manuel Klimek2017-09-191-1/+1
| | | | | | | | | | | | | | | | | | | | | Most of the work was already done when we introduced a look-behind based lambda introducer detection. This patch finishes the transition by completely relying on the simple lambda introducer detection and simply recursing into normal brace-parsing code to parse until the end of the introducer. This fixes initializers in lambdas, including nested lambdas. Before: auto a = [b = [c = 42]{}]{}; auto b = [c = &i + 23]{}; After: auto a = [b = [c = 42] {}] {}; auto b = [c = &i + 23] {}; llvm-svn: 313622
* clang-format: Add preprocessor directive indentationKrasimir Georgiev2017-08-301-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is an implementation for [bug 17362](https://bugs.llvm.org/attachment.cgi?bugid=17362) which adds support for indenting preprocessor statements inside if/ifdef/endif. This takes previous work from fmauch (https://github.com/fmauch/clang/tree/preprocessor_indent) and makes it into a full feature. The context of this patch is that I'm a VMware intern, and I implemented this because VMware needs the feature. As such, some decisions were made based on what VMware wants, and I would appreciate suggestions on expanding this if necessary to use-cases other people may want. This adds a new enum config option, `IndentPPDirectives`. Values are: * `PPDIS_None` (in config: `None`): ``` #if FOO #if BAR #include <foo> #endif #endif ``` * `PPDIS_AfterHash` (in config: `AfterHash`): ``` #if FOO # if BAR # include <foo> # endif #endif ``` This is meant to work whether spaces or tabs are used for indentation. Preprocessor indentation is independent of indentation for non-preprocessor lines. Preprocessor indentation also attempts to ignore include guards with the checks: 1. Include guards cover the entire file 2. Include guards don't have `#else` 3. Include guards begin with ``` #ifndef <var> #define <var> ``` This patch allows `UnwrappedLineParser::PPBranchLevel` to be decremented to -1 (the initial value is -1) so the variable can be used for indent tracking. Defects: * This patch does not handle the case where there's code between the `#ifndef` and `#define` but all other conditions hold. This is because when the #define line is parsed, `UnwrappedLineParser::Lines` doesn't hold the previous code line yet, so we can't detect it. This is out of the scope of this patch. * This patch does not handle cases where legitimate lines may be outside an include guard. Examples are `#pragma once` and `#pragma GCC diagnostic`, or anything else that does not change the meaning of the file if it's included multiple times. * This does not detect when there is a single non-preprocessor line in front of an include-guard-like structure where other conditions hold because `ScopedLineState` hides the line. * Preprocessor indentation throws off `TokenAnnotator::setCommentLineLevels` so the indentation of comments immediately before indented preprocessor lines is toggled on each run. Fixing this issue appears to be a major change and too much complexity for this patch. Contributed by @euhlmann! Reviewers: djasper, klimek, krasimir Reviewed By: djasper, krasimir Subscribers: krasimir, mzeren-vmw, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D35955 llvm-svn: 312125
* clang-format: fix block OpeningLineIndex around preprocessorFrancois Ferrand2017-07-281-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The current code would return an incorrect value when a preprocessor directive is present immediately after the opening brace: this causes the nanespace end comment fixer to break in some places, for exemple it would not add the comment in this case: namespace a { #define FOO } Fixing the computation is simple enough, but it was breaking a feature, as it would cause comments to be added also when the namespace declaration was dependant on conditional compilation. To fix this, a hash of the current preprocessor stack/branches is computed at the beginning of parseBlock(), so that we explicitely do not store the OpeningLineIndex when the beginning and end of the block are not in the same preprocessor conditions. Tthe hash is computed based on the line, but this could propbably be improved by using the actual condition, so that clang-format would be able to match multiple identical #ifdef blocks. Reviewers: krasimir, djasper Reviewed By: krasimir Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35483 llvm-svn: 309369
* [clang-format] Fix comment levels between '} else {' and PPDirective.Krasimir Georgiev2017-07-241-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This fixes a regression exposed by r307795 and rL308725 in which the level of a comment line between '} else {' and a preprocessor directive is incorrectly set as the level of the '} else {' line. For example, this : ``` int f(int i) { if (i) { ++i; } else { // comment #ifdef A --i; #endif } } ``` was formatted as: ``` int f(int i) { if (i) { ++i; } else { // comment #ifdef A --i; #endif } } ``` Reviewers: djasper, klimek Reviewed By: klimek Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35794 llvm-svn: 308882
* [clang-format] Support <>-style proto message fieldsKrasimir Georgiev2017-06-271-1/+2
| | | | | | | | | | | | | | | | | Summary: This patch adds support for <>-style proto message fields inside proto options. Previously these were wrongly treated as binary operators and as such were working only by chance for a limited number of cases. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D34621 llvm-svn: 306406
* [clang-format] Add a NamespaceEndCommentsFixerKrasimir Georgiev2017-02-271-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds a NamespaceEndCommentsFixer TokenAnalyzer for clang-format, which fixes end namespace comments. It currently supports inserting and updating existing wrong comments. Example source: ``` namespace A { int i; } namespace B { int j; } // namespace A ``` after formatting: ``` namespace A { int i; } // namespace A namespace B { int j; } // namespace B ``` Reviewers: klimek, djasper Reviewed By: djasper Subscribers: klimek, mgorny Differential Revision: https://reviews.llvm.org/D30269 llvm-svn: 296341
* [clang-format] Break before a sequence of line comments aligned with the ↵Krasimir Georgiev2017-02-081-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | next line. Summary: Make the comment alignment respect sections of line comments originally alinged with the next token. Until now the decision how to break a continuous sequence of line comments into sections was taken without reference to the next token. source: ``` class A { public: // comment about public // comment about a int a; } ``` format before: ``` class A { public: // comment about public // comment about a int a; } ``` format after: ``` class A { public: // comment about public // comment about a int a; } ``` Reviewers: djasper, klimek Reviewed By: klimek Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29626 llvm-svn: 294435
* clang-format: [JS] handle parenthesized class expressions.Martin Probst2017-02-071-2/+5
| | | | | | | | | | | | | | | | | | | | Summary: In JavaScript, classes are expressions, so they can appear e.g. in argument lists. var C = foo(class { bar() { return 1; } }; Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29635 llvm-svn: 294302
* [clang-format] Don't reflow across comment pragmas.Krasimir Georgiev2017-02-021-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The comment reflower wasn't taking comment pragmas as reflow stoppers. This patch fixes that. source: ``` // long long long long // IWYU pragma: ``` format with column limit = 20 before: ``` // long long long // long IWYU pragma: ``` format with column limit = 20 after: ``` // long long long // long // IWYU pragma: ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29450 llvm-svn: 293898
* clang-format: [JS] Handle certain cases of ASI.Daniel Jasper2016-03-141-0/+1
| | | | | | | | | | | | | | Automatic Semicolon Insertion can only be properly handled by parsing source code. However conservatively catching just a few, common situations prevents breaking code during development, which greatly improves usability. JS code should still use semicolons, and ASI code should be flagged by a compiler or linter. Patch by Martin Probst. Thank you. llvm-svn: 263470
* clang-format: [JS] Support semicolons in TypeScript's TypeMemberLists.Daniel Jasper2016-01-091-0/+1
| | | | | | | | | | | | | | Before: var x: { a: string; b: number; } = {}; After: var x: {a: string; b: number;} = {}; llvm-svn: 257255
* clang-format: [JS/TypeScript] Support "enum" as property name.Daniel Jasper2015-12-291-1/+1
| | | | | | | | | | | Before: enum: string []; After: enum: string[]; llvm-svn: 256546
* Roll-back r250822.Angel Garcia Gomez2015-10-201-1/+1
| | | | | | | | | | Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
* Apply modernize-use-default to clang.Angel Garcia Gomez2015-10-201-1/+1
| | | | | | | | | | | | Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 llvm-svn: 250822
* clang-format: NFC. Cleanup after r237895.Daniel Jasper2015-05-311-5/+0
| | | | | | | | | | | Specifically adhere to LLVM Coding Standards (no 'else' after return/break/continue) and remove yet another implementation of paren counting. We already have enough of those in the UnwrappedLineParser. No functional changes intended. llvm-svn: 238672
* clang-format: [JS] Better support for fat arrows.Manuel Klimek2015-05-211-0/+5
| | | | | | | | | | | | Assigns a token type (TT_JsFatArrow) to => tokens, and uses that to more easily recognize and format fat arrow functions. Improves function parsing to better recognize formal parameter lists and return type declarations. Recognizes arrow functions and parse function bodies as child blocks. Patch by Martin Probst. llvm-svn: 237895
* clang-format: Fix another regression caused by r237565.Daniel Jasper2015-05-181-2/+2
| | | | | | | | | | | | | | | | | | | | Before: class C : test { class D : test{void f(){int i{2}; } } ; } ; After: class C : test { class D : test { void f() { int i{2}; } }; }; llvm-svn: 237569
* clang-format: Allow braced initializers in template arguments of classDaniel Jasper2015-05-181-2/+2
| | | | | | | | | | | | | | specializations. Before: template <class T> struct S < std::is_arithmetic<T> { } > {}; After: template <class T> struct S<std::is_arithmetic<T>{}> {}; llvm-svn: 237565
* Remove all computation of structural errors in clang-format's line parser.Manuel Klimek2015-05-061-6/+1
| | | | | | We were already ignoring those already. llvm-svn: 236591
* clang-format: [Java] Support anonymous classes after = and return.Daniel Jasper2015-03-121-0/+1
| | | | | | | | | | | | | | | | | | | Before: A a = new A(){public String toString(){return "NotReallyA"; } } ; After: A a = return new A() { public String toString() { return "NotReallyA"; } }; This fixes llvm.org/PR22878. llvm-svn: 232042
* clang-format: [js] Support ES6 module exports.Daniel Jasper2015-02-191-1/+1
| | | | | | Patch by Martin Probst, thank you! llvm-svn: 229865
* clang-format: [js] Support ES6 module imports.Daniel Jasper2015-02-191-0/+1
| | | | | | Patch by Martin Probst. llvm-svn: 229863
* clang-format: [Java] Support Java enums.Daniel Jasper2014-11-131-0/+1
| | | | | | | In Java, enums can contain a class body and enum constants can have arguments as well as class bodies. Support most of that. llvm-svn: 221895
* clang-format: Use identifier table for keywords in other languages.Daniel Jasper2014-11-041-1/+5
| | | | | | | | | Slightly easier to write, more efficient and prevents bugs by misspelling them. No functional changes intended. llvm-svn: 221259
* Sink a #include while we're here. NFC.Hans Wennborg2014-10-291-0/+1
| | | | | | Format.h doesn't use stack. llvm-svn: 220879
* Header guard canonicalization, clang part.Benjamin Kramer2014-08-131-3/+3
| | | | | | Modifications made by clang-tidy with minor tweaks. llvm-svn: 215557
* clang-format: Fix bug introduced by r208392.Daniel Jasper2014-05-091-1/+1
| | | | | | Also run clang-format over clang-format's files. llvm-svn: 208409
* [C++11] Use 'nullptr'.Craig Topper2014-05-091-1/+1
| | | | llvm-svn: 208392
* clang-format: Initial support for try-catch.Daniel Jasper2014-05-081-0/+1
| | | | | | | | | | Most of this patch was created by Alexander Rojas in http://reviews.llvm.org/D2555 Thank you! Synced and addressed review comments. llvm-svn: 208302
* clang-format: [JS] support closures in container literals.Daniel Jasper2014-05-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Before: return {body: {setAttribute: function(key, val) {this[key] = val; } , getAttribute : function(key) { return this[key]; } , style : { direction: '' } } } ; After: return { body: { setAttribute: function(key, val) { this[key] = val; }, getAttribute: function(key) { return this[key]; }, style: {direction: ''} } }; llvm-svn: 208292
* Format code around VCS conflict markers.Manuel Klimek2014-04-141-1/+10
| | | | | | | | | | | | | | | | | | | | | Now correctly formats: { int a; void f() { callme(some(parameter1, <<<<<<< text by the vcs parameter2), ||||||| text by the vcs parameter2), parameter3, ======= text by the vcs parameter2, parameter3), >>>>>>> text by the vcs otherparameter); } } llvm-svn: 206157
* Correctly handle escaped newlines when the next token starts without a space.Manuel Klimek2014-04-111-0/+1
| | | | | | | We will need this to correctly handle conflict markers inside macro definitions. llvm-svn: 206029
* Replace OwningPtr with std::unique_ptr.Ahmed Charles2014-03-071-1/+1
| | | | | | This compiles cleanly with lldb/lld/clang-tools-extra/llvm. llvm-svn: 203279
* Get rid of special parsing for return statements.Manuel Klimek2014-01-241-1/+0
| | | | | | | | This was done when we were not able to parse lambdas to handle some edge cases for block formatting different in return statements, but is not necessary any more. llvm-svn: 199982
* Sort all the #include lines with LLVM's utils/sort_includes.py whichChandler Carruth2014-01-071-1/+1
| | | | | | | encodes the canonical rules for LLVM's style. I noticed this had drifted quite a bit when cleaning up LLVM, so wanted to clean up Clang as well. llvm-svn: 198686
* clang-format: Fix various problems in formatting ObjC blocks.Daniel Jasper2013-12-231-1/+2
| | | | | | Among other things, this fixes llvm.org/PR15269. llvm-svn: 197900
* Implemented GNU-style formatting for compound statements.Alexander Kornienko2013-12-121-0/+1
| | | | | | | | | | | | | | | | Summary: Added BraceBreakingStyle::BS_GNU. I'm not sure about the correctness of static initializer formatting, but compound statements should be fine. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2372 llvm-svn: 197138
* Automatically munch semicolons after blocks.Manuel Klimek2013-10-121-1/+2
| | | | | | | | While it is mostly a user error to have the extra semicolon, formatting it graciously will correctly format in the cases where we do not fully understand the code (macros). llvm-svn: 192543
* Support formatting of preprocessor branches.Manuel Klimek2013-10-111-2/+24
| | | | | | | | | | | | | | | | | | | | | We now correctly format: void SomeFunction(int param1, #ifdef X NoTemplate param2, #else template < #ifdef A MyType<Some> > #else Type1, Type2> #endif param2, #endif param3) { f(); } llvm-svn: 192503
* clang-format: Fix incorrect enum parsing / layouting.Daniel Jasper2013-09-131-1/+1
| | | | | | | | | | | | | | | Before: enum { Bar = Foo < int, int > ::value }; After: enum { Bar = Foo<int, int>::value }; llvm-svn: 190674
* Unbreak build with libc++, whose std::list<T> requires T to be complete.Douglas Gregor2013-09-051-1/+4
| | | | llvm-svn: 190075
* clang-format: Enable formatting of nested blocks.Daniel Jasper2013-09-051-4/+14
| | | | | | | | | | | | | | | | | | Among other things, this enables (better) formatting lambdas and constructs like: MACRO({ long_statement(); long_statement_2(); }, { long_statement(); long_statement_2(); }, { short_statement(); }, ""); This fixes llvm.org/PR15381. llvm-svn: 190038
* Implement parsing of blocks (^{ ... }) in the unwrapped line parser.Manuel Klimek2013-09-041-0/+1
| | | | | | | | | | | | | | | | | | | | | | This patch makes sure we produce the right number of unwrapped lines, a follow-up patch will make the whitespace formatting consistent. Before: void f() { int i = {[operation setCompletionBlock : ^{ [self onOperationDone]; }] } ; } After: void f() { int i = {[operation setCompletionBlock : ^{ [self onOperationDone]; }] }; } llvm-svn: 189932
* First step towards correctly formatting lambdas.Manuel Klimek2013-09-031-0/+2
| | | | | | | | | | Implements parsing of lambdas in the UnwrappedLineParser. This introduces the correct line breaks; the formatting of lambda captures are still incorrect, and the braces are also still formatted as if they were braced init lists instead of blocks. llvm-svn: 189818
* clang-format: Add more options to namespace indentation.Daniel Jasper2013-07-311-1/+1
| | | | | | | | | | | | | With this patch, clang-format can be configured to: * not indent in namespace at all (former behavior). * indent in namespace as in other blocks. * indent only in inner namespaces (as required by WebKit style). Also fix alignment of access specifiers in WebKit style. Patch started by Marek Kurdej. Thank you! llvm-svn: 187540
* Fix alignment of closing brace in braced initializers.Daniel Jasper2013-07-091-12/+0
| | | | | | | | | | | | | | | | | | | | | | Before: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); After: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); To do so, the UnwrappedLineParser now stores the information about the kind of brace in the FormatToken. llvm-svn: 185914
* Reformat clang-format's source files after r185822 and others.Daniel Jasper2013-07-081-6/+4
| | | | llvm-svn: 185823
OpenPOWER on IntegriCloud