summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [VFS] Transition clang-format to use an in-memory FS.Benjamin Kramer2015-10-061-8/+7
| | | | | | | | | | | Apart from being cleaner this also means that clang-format no longer has access to the host file system. This isn't necessary because clang-format never reads includes :) Includes minor tweaks and bugfixes found in the VFS implementation while running clang-format tests. llvm-svn: 249385
* Add -f[no-]declspec to control recognition of __declspec as a keywordSaleem Abdulrasool2015-10-041-0/+1
| | | | | | | | | | | | | | | In versions of clang prior to r238238, __declspec was recognized as a keyword in all modes. It was then changed to only be enabled when Microsoft or Borland extensions were enabled (and for CUDA, as a temporary measure). There is a desire to support __declspec in Playstation code, and possibly other environments. This commit adds a command-line switch to allow explicit enabling/disabling of the recognition of __declspec as a keyword. Recognition is enabled by default in Microsoft, Borland, CUDA, and PS4 environments, and disabled in all other environments. Patch by Warren Ristow! llvm-svn: 249279
* [clang-format] Add support of consecutive declarations alignmentDaniel Jasper2015-10-011-0/+3
| | | | | | | | | | | | | | | | | | | This allows clang-format to align identifiers in consecutive declarations. This is useful for increasing the readability of the code in the same way the alignment of assignations is. The code is a slightly modified version of the consecutive assignment alignment code. Currently only the identifiers are aligned, and there is no support of alignment of the pointer star or reference symbol. The patch also solve the issue of alignments not being possible due to the ColumnLimit for both the existing AlignConsecutiveAligments and the new AlignConsecutiveDeclarations. Patch by Beren Minor, thank you. Review: http://reviews.llvm.org/D12362 llvm-svn: 248999
* clang-format: Add a new brace style "custom" as well as flags toDaniel Jasper2015-09-291-5/+73
| | | | | | | | | | | | | | | control the individual braces. The existing choices for brace wrapping are now merely presets for the different flags that get expanded upon calling the reformat function. All presets have been chose to keep the existing formatting, so there shouldn't be any difference in formatting behavior. Also change the dump_format_style.py to properly document the nested structs that are used to keep these flags discoverable among all the configuration flags. llvm-svn: 248802
* clang-format: Extend #include sorting functionalityDaniel Jasper2015-09-291-10/+42
| | | | | | | | | Recognize the main module header as well as different #include categories. This should now mimic the behavior of llvm/utils/sort_includes.py as well as clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp very closely. llvm-svn: 248782
* clang-format: Add initial #include sorting capabilities.Daniel Jasper2015-09-231-2/+102
| | | | | | | | | To implement this nicely, add a function that merges two sets of replacements that are meant to be done in sequence. This functionality will also be useful for other applications, e.g. formatting the result of clang-tidy fixes. llvm-svn: 248367
* clang-format: Remove ChromiumStyle.MacroBlockBegin.Nico Weber2015-09-211-2/+0
| | | | | | | | We prefer setting these in our .clang-format file as the macros change over time. (Also, the code was setting MacroBlockBegin twice and didn't set MacroBlockEnd, so it wasn't doing what it tried to do anyways.) llvm-svn: 248205
* Add WebKit brace style configuration option.Roman Kashitsyn2015-08-101-1/+2
| | | | | | | | | | | | | | | | | | Summary: Add brace style `BS_WebKit` as described on https://www.webkit.org/coding/coding-style.html: * Function definitions: place each brace on its own line. * Other braces: place the open brace on the line preceding the code block; place the close brace on its own line. Set brace style used in `getWebKitStyle()` to the newly added `BS_WebKit`. Reviewers: djasper, klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D11837 llvm-svn: 244446
* clang-format: Take nested lines into account when detection C++03Daniel Jasper2015-07-181-32/+46
| | | | | | compatibility and variable alignment. llvm-svn: 242611
* clang-format: Add Mozilla brace breaking styleBirunthan Mohanathas2015-07-121-0/+2
| | | | | | Differential Revision: http://reviews.llvm.org/D10883 llvm-svn: 241986
* clang-format: Add MacroBlock{Begin,End} optionsBirunthan Mohanathas2015-07-031-7/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The MacroBlockBegin and MacroBlockEnd options make matching macro identifiers behave like '{' and '}', respectively, in terms of indentation. Mozilla code, for example, uses several macros that begin and end a scope. Previously, Clang-Format removed the indentation resulting in: MACRO_BEGIN(...) MACRO_ENTRY(...) MACRO_ENTRY(...) MACRO_END Now, using the options MacroBlockBegin: "^[A-Z_]+_BEGIN$" MacroBlockEnd: "^[A-Z_]+_END$" will yield the expected result: MACRO_BEGIN(...) MACRO_ENTRY(...) MACRO_ENTRY(...) MACRO_END Differential Revision: http://reviews.llvm.org/D10840 llvm-svn: 241363
* clang-format: [JS] Treat regex literals like string literals.Daniel Jasper2015-07-021-0/+2
| | | | | | | Using the token type "unknown" can interfere badly with WhitespaceManager's way of handling multiline comments. llvm-svn: 241273
* clang-format: [JS] Skip comments when applying the regex-literal heuristicDaniel Jasper2015-07-021-5/+9
| | | | llvm-svn: 241264
* clang-format: [JS] Fix bug in regex literal parsing.Daniel Jasper2015-07-021-0/+1
| | | | | | The lexer wasn't properly reset leading to unexpected deletions. llvm-svn: 241262
* clang-format: [JS] Support regex literals at the start of a file.Daniel Jasper2015-07-021-5/+6
| | | | llvm-svn: 241259
* clang-format: [JS] Fix character counting in template strings.Daniel Jasper2015-07-021-5/+6
| | | | | | | Some counts were off, we don't need to take the leading newlines of the first ` into account and some tests were just wrong. llvm-svn: 241257
* clang-format: Add option to break after definition return type for top-level ↵Birunthan Mohanathas2015-06-291-2/+16
| | | | | | | | functions only Differential Revision: http://reviews.llvm.org/D10774 llvm-svn: 240959
* clang-format: Adjust Mozilla style defaultsBirunthan Mohanathas2015-06-291-3/+5
| | | | | | | | Summary: This makes the Mozilla style defaults more compliant with the Mozilla style guide. A few options were removed in order to use the LLVM style defaults. Differential Revision: http://reviews.llvm.org/D10771 llvm-svn: 240957
* clang-format: Stop old options from overriding new optionsBirunthan Mohanathas2015-06-281-10/+10
| | | | | | | | | | | | | | Summary: Depends on D10785. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D10786 llvm-svn: 240909
* clang-format: Alphabetize FormatStyle membersBirunthan Mohanathas2015-06-281-33/+33
| | | | | | | | | | | | Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D10784 llvm-svn: 240907
* clang-format: [JS] Support regex literals containing quotes (' and ").Daniel Jasper2015-06-241-3/+23
| | | | llvm-svn: 240548
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-2/+2
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-2/+2
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* clang-format: clang-format (NFC)Daniel Jasper2015-06-171-4/+5
| | | | llvm-svn: 239903
* clang-format: [JS] Fix corner case in template string parsing.Daniel Jasper2015-06-141-1/+2
| | | | | | | | | | Before, these would not properly detected because of the char/string literal found when re-lexing after the first `: var x = `'`; // comment with matching quote ' var x = `"`; // comment with matching quote " llvm-svn: 239693
* clang-format: Don't add spaces in foreach macro definition.Daniel Jasper2015-06-111-1/+4
| | | | | | | | | | | | Before clang-format would e.g. add a space into #define Q_FOREACH(x, y) which turns this into a non-function-like macro. Patch by Strager Neds, thank you! llvm-svn: 239513
* Remove error message when using the fallback style.Manuel Klimek2015-06-021-2/+0
| | | | llvm-svn: 238822
* clang-format: [JS] Better support for fat arrows.Manuel Klimek2015-05-211-7/+7
| | | | | | | | | | | | 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
* Refactor the formatter of clang-format.Manuel Klimek2015-05-111-3/+3
| | | | | | | | | | | | Pull various parts of the UnwrappedLineFormatter into their own abstractions. NFC. There are two things left for subsequent changes (to keep this reasonably small) - the UnwrappedLineFormatter now has a bad name - the UnwrappedLineFormatter::format function is still too large llvm-svn: 236974
* clang-format: Fix bug in escaped newline calculation.Daniel Jasper2015-05-101-1/+1
| | | | | | | This prevents clang-format from inadvertently joining stuff into macro definitions as reported in llvm.org/PR23466. llvm-svn: 236944
* clang-format: [JS] Fix regex literal detection.Daniel Jasper2015-05-081-1/+1
| | | | | | | | | | Before: var regex = /= / ; After: var regex = /=/; llvm-svn: 236811
* Implements a way to retrieve information about whether some lines were not ↵Manuel Klimek2015-05-071-8/+11
| | | | | | formatted due to syntax errors. llvm-svn: 236722
* Remove deprecated version of reformat.Manuel Klimek2015-05-061-9/+0
| | | | llvm-svn: 236594
* Remove all computation of structural errors in clang-format's line parser.Manuel Klimek2015-05-061-4/+3
| | | | | | We were already ignoring those already. llvm-svn: 236591
* clang-format: Fix another assertion discovered by the fuzzer.Daniel Jasper2015-05-061-10/+17
| | | | | | | | | In the process, fix an old todo that I don't really know how to write tests for. The problem is that Clang's lexer creates very strange token sequences for these. However, the new approach seems generally better and easier to read so I am submitting it nonetheless. llvm-svn: 236589
* clang-format: NFC: Delete FormatToken::IsForEachMacro. Use a TokenType instead.Daniel Jasper2015-05-041-3/+3
| | | | llvm-svn: 236415
* clang-format: [JS] Fix calculation of template string width.Daniel Jasper2015-05-021-4/+14
| | | | | | | | | | OriginalColumn might not be set, so fall back to Location and SourceMgr in case it is missing. Also initialize end column in case the token is multi line, but it's the ` token itself that starts the multi line. Patch by Martin Probst, thank you! llvm-svn: 236383
* clang-format: Add ability to align assignment operators.Daniel Jasper2015-04-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | In Objective-C some style guides use a style where assignment operators are aligned, in an effort to increase code readability. This patch adds an option to the format library which allows this functionality. It is disabled by default for all the included styles, so it must be explicitly enabled. The option will change code such as: - (void)method { NSNumber *one = @1; NSNumber *twentyFive = @25; } to: - (void)method { NSNumber *one = @1; NSNumber *twentyFive = @25; } Patch by Matt Oakes. Thank you! Accidentally reformatted all the tests... llvm-svn: 236100
* clang-format: [JS] handle comments in template strings.Daniel Jasper2015-04-161-2/+17
| | | | | | Patch by Martin Probst. Thank you. llvm-svn: 235078
* clang-format: [Proto] No alternate operator names.Daniel Jasper2015-04-031-2/+1
| | | | llvm-svn: 234055
* clang-format: Fix merging of _T macros.Daniel Jasper2015-03-261-0/+2
| | | | | | | NewlinesBefore and HasUnescapedNewline were not properly propagated leading to llvm.org/PR23032. llvm-svn: 233276
* clang-format: Recognize the .ts (TypeScript) extension as JavaScript.Daniel Jasper2015-03-111-1/+2
| | | | | | Patch by Martin Probst. Thank you. llvm-svn: 231926
* Make constant static variables const so they can go into a read-only sectionBenjamin Kramer2015-03-081-5/+6
| | | | | | NFC. llvm-svn: 231597
* clang-format: Change location of stashed tokenJacques Pienaar2015-02-241-2/+4
| | | | | | Commit of patch in http://reviews.llvm.org/D7871 llvm-svn: 230395
* Fix merging of << at end of input.Jacques Pienaar2015-02-201-20/+13
| | | | | | Commit of review http://reviews.llvm.org/D7766 llvm-svn: 230061
* clang-format: [js] Support template strings.Daniel Jasper2015-02-201-1/+65
| | | | | | | | | Merge template strings (marked by backticks ``). Do not format any contents of template strings. Patch by Martin Probst. Thank you. llvm-svn: 230011
* clang-format: Space and triple angle braces.Jacques Pienaar2015-02-181-32/+79
| | | | | | Committing patch http://reviews.llvm.org/D6800. llvm-svn: 229783
* clang-format: Fix assert triggering on carriage returns.Daniel Jasper2015-02-051-0/+3
| | | | llvm-svn: 228288
* clang-format: Add support for SEH __try / __except / __finally blocks.Nico Weber2015-02-041-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | This lets clang-format format __try { } __except(0) { } and __try { } __finally { } correctly. __try and __finally are keywords if `LangOpts.MicrosoftExt` is set, so this turns this on. This also enables a few other keywords, but it shouldn't overly perturb regular clang-format operation. __except is a context-sensitive keyword, so `AdditionalKeywords` needs to be passed around to a few more places. Fixes PR22321. llvm-svn: 228148
* clang-format: FIXME that led to access of uninitialized memory.Daniel Jasper2015-01-291-1/+2
| | | | | | | | | | I have so far not succeeded in finding a nicely reduced test case or an observable difference which could help me create a test failure without msan. Committing without test to unblock kcc's further fuzzing progress. llvm-svn: 227433
OpenPOWER on IntegriCloud