summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Improved formatting of constructor initializersDaniel Jasper2013-01-111-32/+49
| | | | | | | | | Added option to put each constructor initializer on its own line if not all initializers fit on a single line. Enabling this for Google style now as the style guide (arguable) suggests it. Not sure whether we also want it for LLVM. llvm-svn: 172196
* Refactor IndentState into two classes.Daniel Jasper2013-01-111-80/+73
| | | | | | | | As we keep adding more stuff to it, this structure is easier to maintain. At one point we might think about making it an actual class with specific accessors, etc. llvm-svn: 172188
* Formatter: Put spaces in ObjC method decls in the right place for Google style.Nico Weber2013-01-101-7/+20
| | | | | | | | | | | | | | | | | | | | | | | Objective-C method declarations look like this: - (returntype)name:(type)argname anothername:(type)arg2name; In google style, there's no space after the leading '-' but one after "(returntype)" instead (but none after the argument types), see http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Method_Declarations_and_Definitions Not inserting the space after '-' is easy, but to insert the space after the return type, the formatter needs to know that a closing parenthesis ends the return type. To do this, I tweaked the code in parse() to check for this, which in turn required moving detection of TT_ObjCMethodSpecifier from annotate() to parse(), because parse() runs before annotate(). (To keep things interesting, the return type is optional, but it's almost always there in practice.) http://llvm-reviews.chandlerc.com/D280 llvm-svn: 172140
* Formatter: No spaces around '=' in @property lines.Nico Weber2013-01-101-1/+12
| | | | | | | | | | | | | Before: @property(assign, getter = isEditable) BOOL editable; Now: @property(assign, getter=isEditable) BOOL editable; It'd be nice if some Apple person could let me know if spaces are preferred around '=' in @synthesize lines (see FIXME in the test). llvm-svn: 172110
* Formatting: In @implementation etc lines, put a space before protocol lists.Nico Weber2013-01-101-1/+5
| | | | | | | | | | | | Don't do this in Google style though: http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Protocols Most other places (function declarations, variable declarations) still get this wrong, and since this looks very similiar to template instantiations to the lexer (`id <MyProtocol> a = ...`), it's going to be hard to fix in some places. llvm-svn: 172099
* Refactoring the outermost structure of the formatter.Manuel Klimek2013-01-101-37/+45
| | | | | | | This is the last step of pure shuffling stuff around, the next step will be the actual feature. llvm-svn: 172098
* Formatter: Don't put a space in ObjC number literals like @+50Nico Weber2013-01-101-2/+4
| | | | | | | | | | Before: @ -4.5 Now: @-4.5 llvm-svn: 172095
* Formatter: Add space before '(' in @implemenation, @interface, @protocol linesNico Weber2013-01-101-2/+16
| | | | | | | | The first token in @implementation, @interface, and @protocol lines is now marked TT_ObjCDecl, and lines starting with a TT_ObjCDecl token are now marked LT_ObjCMethodDecl. llvm-svn: 172093
* Pull calculation whether a line fits one level up.Manuel Klimek2013-01-101-29/+36
| | | | | | | This is the next step towards being able to configure multiple unwrapped lines into one. llvm-svn: 172092
* Pulling formatFirstToken one level up.Manuel Klimek2013-01-101-85/+91
| | | | | | | | | | | | This prepares the code for single line optimizations and changes the dependencies between single-line-formats to the indent of the first token. Conceptually, the first token is "between" the lines anyway, as the whitespace for the first token includes the previous end-of-line, which needs to be escaped when inside a preprocessor directive. llvm-svn: 172083
* Fixes layout of right braces.Manuel Klimek2013-01-101-3/+20
| | | | | | | | | | | | | | | | | | | | | | We now decide whether a newline should go before the closing brace depending on whether a newline was inserted after the opening brace. For example, we now insert a newline before '};' in: static SomeClass WithALoooooooooooooooooooongName = { 100000000, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" }; ... while not inserting a newline here: static SomeClass = { a, b, c, d, e, f, g, h, i, j, looooooooooooooooooooooooooooooooooongname, looooooooooooooooooooooooooooooong }; Also fixes the formating of (column limit 25): int x = { avariable, b(alongervariable) }; llvm-svn: 172076
* Basic support for diagnostics.Alexander Kornienko2013-01-103-12/+31
| | | | | | | | | | | | | | Summary: Uses DiagnosticsEngine to output diagnostics. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D278 llvm-svn: 172071
* Fixes formatting of function calls etc inside an initializer list.Manuel Klimek2013-01-101-10/+15
| | | | | | | | | | | | | | | | | | | | | We're now formatting (column limit 25): int x = { avariable, b(alongervariable) }; This also fixes: Aaa({ int i; }, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccc)); ... where we would previously break after the '},'. Putting the closing curly into an extra line when there's a break directly after the first curly will be done in a subsequent patch. Paired with djasper. llvm-svn: 172070
* Do not add newline in empty blocks.Manuel Klimek2013-01-102-6/+10
| | | | | | | void f() {} now gets formatted in one line. llvm-svn: 172067
* Improvements to function type and ObjC block formatting.Daniel Jasper2013-01-101-5/+18
| | | | | | | | | | | | | | | | | | | | | Before: int (^myBlock) (int) = ^(int num) {} A<void ()>; int (*b)(int); After: int (^myBlock)(int) = ^(int num) {} A<void()>; int(*b)(int); For function types and function pointer types, this patch only makes the behavior consistent (for types that are keywords and other types). For the latter function pointer type declarations, we'll probably want to add a space after "int". Also added LangOpts.Bool = 1, so we handle "A<bool()>" appropriately Moved the LangOpts-settings to a public place for use by tests and clang-format binary. llvm-svn: 172065
* Fix layout of blocks inside statements.Manuel Klimek2013-01-103-19/+76
| | | | | | | | | | | | | | | Previously, we would not indent: SOME_MACRO({ int i; }); correctly. This is fixed by adding the trailing }); to the unwrapped line starting with SOME_MACRO({, so the formatter can correctly match the braces and indent accordingly. Also fixes incorrect parsing of initializer lists, like: int a[] = { 1 }; llvm-svn: 172058
* Improve clang-format's understanding of casts.Daniel Jasper2013-01-101-12/+20
| | | | | | | | | | | | This fixes llvm.org/PR14684. Before: int *pa = (int *) & a; After: int *pa = (int *)&a; We still don't understand all kinds of casts. I added a FIXME to address that. llvm-svn: 172056
* Introduce a define to switch on debug output.Manuel Klimek2013-01-101-0/+17
| | | | | | | After re-writing the same loop multiple times, we deicided it's time to add this as an optional debugging help. llvm-svn: 172050
* Do more error checking for '{}'.Daniel Jasper2013-01-101-0/+24
| | | | | | | | | This fixes llvm.org/PR14883, where clang-format would run into an assertion on: void f() { return } 42 llvm-svn: 172049
* Formatter: Remove unused @-formatting code.Nico Weber2013-01-101-4/+0
| | | | | | | @optional @property is put on two different unwrapped lines now, so this is no longer necessary. llvm-svn: 172024
* Formatter: @optional and @required go on their own line.Nico Weber2013-01-102-0/+7
| | | | | | | | | | | | | | | | | | | | Previously: @protocol myProtocol - (void)mandatoryWithInt:(int)i; @optional - (void) optional; @required - (void) required; @end Now: @protocol myProtocol - (void)mandatoryWithInt:(int)i; @optional - (void)optional; @required - (void)required; @end llvm-svn: 172023
* Formatter: Add support for @implementation.Nico Weber2013-01-092-3/+4
| | | | | | | Just reuse the @interface code for this. It accepts slightly more than necessary (@implementation cannot have protocol lists), but that's ok. llvm-svn: 172019
* Formatter: Make parseObjCUntilAtEnd() actually work.Nico Weber2013-01-091-0/+2
| | | | llvm-svn: 172003
* Formatting: Add support for @protocol.Nico Weber2013-01-092-16/+43
| | | | | | Pull pieces of the @interface code into reusable methods. llvm-svn: 172001
* Formatter: Add support for @interface.Nico Weber2013-01-092-0/+43
| | | | | | | | | | | | | | Previously: @interface Foo + (id)init; @end Now: @interface Foo + (id)init; @end Some tweaking remains, but this is a good first step. llvm-svn: 171995
* Enables layouting unwrapped lines around preprocessor directives.Manuel Klimek2013-01-093-41/+69
| | | | | | | | | | | | | | | | | | | | | | | Previously, we'd always start at indent level 0 after a preprocessor directive, now we layout the following snippet (column limit 69) as follows: functionCallTo(someOtherFunction( withSomeParameters, whichInSequence, areLongerThanALine(andAnotherCall, B withMoreParamters, whichStronglyInfluenceTheLayout), andMoreParameters), trailing); Note that the different jumping indent is a different issue that will be addressed separately. This is the first step towards handling #ifdef->#else->#endif chains correctly. llvm-svn: 171974
* Only align after assignments on the top level.Daniel Jasper2013-01-091-1/+3
| | | | | | | | | | | | | This fixes llvm.org/PR14870 and we no longer mess up: template <typename T1, typename T2 = char, typename T3 = char, typename T4 = char> void f(); It removes the nice aligment for assignments inside other expressions, but I am not sure those are actually practically relevant. If so, we can fix those later. llvm-svn: 171966
* Don't simply give up when exceeding 80cols, choose an "ok" option.Daniel Jasper2013-01-091-3/+11
| | | | | | | | | | | | | | | This addresses llvm.org/PR14847. We can now format something like: int aaaaaaaaaaaaaaaaaaaaaaaaaaa = // aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; clang-format unavoidably exceeds the column limit, but does not just flush everything into a single line. Moreover, it tries to minimize the number of characters beyond the column limit. llvm-svn: 171964
* Correctly format wrapped function call parameters in templated functions.Daniel Jasper2013-01-091-1/+1
| | | | | | | | | | | | | | | | This fixes llvm.org/PR14846. Before: template <typename T> void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( int aaaaaaaaaaaaaaaaa); After: template <typename T> void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( int aaaaaaaaaaaaaaaaa); llvm-svn: 171963
* Allow comments in the middle of statements to be on their own line.Daniel Jasper2013-01-091-1/+3
| | | | | | | | | | | | This fixes llvm.org/PR14860. Before, we messed up the format of: if (DeclaratorInfo.isFunctionDeclarator() && //getDeclSpecContextFromDeclaratorContext(Context) == DSC_top_level && Tok.is(tok::semi) && NextToken().is(tok::l_brace)) { } llvm-svn: 171961
* Fix ObjC block declarations.Daniel Jasper2013-01-091-3/+4
| | | | | | Before: int ( ^ Block1) (int, int) = ^ (int i, int j) After: int (^Block1) (int, int) = ^(int i, int j) llvm-svn: 171959
* Improve formatting of conditional operators.Daniel Jasper2013-01-091-28/+36
| | | | | | | | | | | | This addresses llvm.org/PR14864. We used to completely mess this up and now format as: Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ? diag::ext_function_specialization_in_class : diag::err_function_specialization_in_class) << NewFD->getDeclName(); llvm-svn: 171957
* Don't break after unary operators.Daniel Jasper2013-01-081-2/+1
| | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa, * aaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 171890
* Formatter: Format @ literals better. Array and dictionary literals need more ↵Nico Weber2013-01-081-1/+4
| | | | | | work. llvm-svn: 171887
* Don't put spaces around ##.Daniel Jasper2013-01-081-2/+4
| | | | | | | | | | | | | | | | | In Clang/LLVM this seems to be the more common formatting for ##s. There might still be case that we miss, but we'll fix those as we go along. Before: #define A(X) void function ## X(); After: #define A(X) void function##X(); llvm-svn: 171862
* Change the data structure used in clang-format.Daniel Jasper2013-01-083-298/+315
| | | | | | | | | | | | This is a first step towards supporting more complex structures such as #ifs inside unwrapped lines. This patch mostly converts the array-based UnwrappedLine into a linked-list-based UnwrappedLine. Future changes will allow multiple children for each Token turning the UnwrappedLine into a tree. No functional changes intended. llvm-svn: 171856
* Formatter: Support @public/@protected/@package/@private.Nico Weber2013-01-072-2/+25
| | | | | | @package is an Objective-C 2 feature, so turn on ObjC2 as well. llvm-svn: 171766
* Fix parsing of variable declarations directly after a class / struct.Manuel Klimek2013-01-072-4/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previous indent: class A { } a; void f() { }; With this patch: class A { } a; void f() { } ; The patch introduces a production for classes and structs, and parses the rest of the line to the semicolon after the class scope. This allowed us to remove a long-standing wart in the parser that would just much the semicolon after any block. Due to this suboptimal formating some tests were broken. Some unrelated formatting tests broke; those hit a bug in the ast printing, and need to be fixed separately. llvm-svn: 171761
* Formatter: Add tests for try/catch. Let 'throw' start an expression.Nico Weber2013-01-071-3/+2
| | | | | | | | | | Before: throw a *b; Now: throw a * b; llvm-svn: 171754
* Formatter: Don't put spaces betwen @ and objc keywords.Nico Weber2013-01-071-0/+2
| | | | llvm-svn: 171753
* Small refactoring of the formatter code.Daniel Jasper2013-01-071-82/+84
| | | | | | | | This should make it slightly more readable as it more clearly separates what happens where. No intended functional changes. More of this to come.. llvm-svn: 171748
* Fix typo.Nico Weber2013-01-071-1/+1
| | | | llvm-svn: 171740
* s/parseStatement/parseStructuralElement/g in the UnwrappedLineParser.Manuel Klimek2013-01-072-9/+9
| | | | llvm-svn: 171737
* Reformat clang-formats source code.Daniel Jasper2013-01-073-23/+23
| | | | | | All changes done by clang-format itself. No functional changes. llvm-svn: 171732
* Prefer not to break after assignments.Daniel Jasper2013-01-071-7/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | This addresses llvm.org/PR14830. Before: unsigned Cost = TTI.getMemoryOpCost(I->getOpcode(), VectorTy, SI->getAlignment(), SI->getPointerAddressSpace()); CharSourceRange LineRange = CharSourceRange::getTokenRange(TheLine.Tokens.front().Tok.getLocation(), TheLine.Tokens.back().Tok.getLocation()); After: unsigned Cost = TTI.getMemoryOpCost(I->getOpcode(), VectorTy, SI->getAlignment(), SI->getPointerAddressSpace()); CharSourceRange LineRange = CharSourceRange::getTokenRange( TheLine.Tokens.front().Tok.getLocation(), TheLine.Tokens.back().Tok.getLocation()); This required rudimentary changes to static initializer lists, but we are not yet formatting them in a reasonable way. That will be done in a subsequent patch. llvm-svn: 171731
* Add style option for number of spaces before trailing comments.Daniel Jasper2013-01-071-1/+3
| | | | | | | In LLVM style, a single space should be enough. In Google style, two spaces are required. llvm-svn: 171725
* Do not break before "0" in pure virtual function declarations.Daniel Jasper2013-01-071-108/+138
| | | | | | | | | | | | | | | | | | | Before: virtual void write(ELFWriter *writer, OwningPtr<FileOutputBuffer> &buffer) = 0 After: virtual void write(ELFWriter *writerrr, OwningPtr<FileOutputBuffer> &buffer) = 0; This addresses llvm.org/PR14815. To implement this I introduced a line type during parsing and moved the definition of TokenType out of the struct for increased readability. Should have done the latter in a separate patch, but it would be hard to pull apart now. llvm-svn: 171724
* Fix incorrect FIXME.Manuel Klimek2013-01-071-2/+3
| | | | | | | | The case that we wanted to write a test for cannot happen, as the UnwrappedLineParser already protects against it. Added an assert to prevent regressions of that assumption. llvm-svn: 171720
* Remove outdated FIXME and add explanation for error handling strategyManuel Klimek2013-01-071-2/+6
| | | | | | while parsing #define's. llvm-svn: 171717
* Remove outdated fixme.Manuel Klimek2013-01-071-3/+0
| | | | llvm-svn: 171716
OpenPOWER on IntegriCloud