summaryrefslogtreecommitdiffstats
path: root/clang/tools/clang-format/ClangFormat.cpp
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: Make moving of the Cursor work properly when sorting #includes.Daniel Jasper2015-11-231-34/+33
| | | | llvm-svn: 253860
* clang-format: Enable #include sorting by default.Daniel Jasper2015-11-161-14/+13
| | | | | | | | | This has seen quite some usage and I am not aware of any issues. Also add a style option to enable/disable include sorting. The existing command line flag can from now on be used to override whatever is set in the style. llvm-svn: 253202
* Update list of languages advertised in OVERVIEW: A tool to format ↵Nico Weber2015-10-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | C/C++/Java/JavaScript/Objective-C/Protobuf code. If no arguments are specified, it formats the code from standard input and writes the result to the standard output. If <file>s are given, it reformats the files. If -i is specified together with <file>s, the files are edited in-place. Otherwise, the result is written to the standard output. USAGE: clang-format [options] [<file> ...] OPTIONS: -assume-filename=<string> - When reading from stdin, clang-format assumes this filename to look for a style config file (with -style=file) and to determine the language. -cursor=<uint> - The position of the cursor when invoking clang-format from an editor integration -dump-config - Dump configuration options to stdout and exit. Can be used with -style option. -fallback-style=<string> - The name of the predefined style used as a fallback in case clang-format is invoked with -style=file, but can not find the .clang-format file to use. Use -fallback-style=none to skip formatting. -help - Display available options (-help-hidden for more) -i - Inplace edit <file>s, if specified. -length=<uint> - Format a range of this length (in bytes). Multiple ranges can be formatted by specifying several -offset and -length pairs. When only a single -offset is specified without -length, clang-format will format up to the end of the file. Can only be used with one input file. -lines=<string> - <start line>:<end line> - format a range of lines (both 1-based). Multiple ranges can be formatted by specifying several -lines arguments. Can't be used with -offset and -length. Can only be used with one input file. -offset=<uint> - Format a range starting at this byte offset. Multiple ranges can be formatted by specifying several -offset and -length pairs. Can only be used with one input file. -output-replacements-xml - Output replacements as XML. -sort-includes - Sort touched include lines -style=<string> - Coding style, currently supports: LLVM, Google, Chromium, Mozilla, WebKit. Use -style=file to load style configuration from .clang-format file located in one of the parent directories of the source file (or current directory for stdin). Use -style="{key: value, ...}" to set specific parameters, e.g.: -style="{BasedOnStyle: llvm, IndentWidth: 8}" -version - Display the version of this program output. llvm-svn: 250671
* clang-format: Basic escaping when outputting XML.Daniel Jasper2015-10-151-1/+9
| | | | llvm-svn: 250440
* [VFS] Transition clang-format to use an in-memory FS.Benjamin Kramer2015-10-061-9/+15
| | | | | | | | | | | 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
* clang-format: Use Rewriter again to write the output files.Daniel Jasper2015-09-301-18/+18
| | | | | | | | This has two advantages: 1. Atomic writes. 2. Proper handling of line endings (hopefully solving llvm.org/PR24999 llvm-svn: 248904
* clang-format: Extend #include sorting functionalityDaniel Jasper2015-09-291-5/+5
| | | | | | | | | 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-31/+59
| | | | | | | | | 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
* Reapply r236854 and fixed r236867.Daniel Jasper2015-05-101-4/+10
| | | | | | | Makes emacs show a different message when clang-format encountered a syntax error. llvm-svn: 236943
* Revert "Make emacs show when clang-format encountered a syntax error."Tobias Grosser2015-05-081-11/+5
| | | | | | | | | | | This reverts commit 236854, which caused clang-format to always print '{ "IncompleteFormat": false }' at the top of an incompletely formatted file. This output causes problems e.g. in Polly's automatic formatting checks. Daniel tried to fix this in 236867, but this fix had to be reverted due to buildbot failures. I revert this change as well for now as it is Friday night and unlikely to be fixed immediately. llvm-svn: 236908
* Revert "clang-format: Only output IncompleteFormat if -cursor is given."Renato Golin2015-05-081-6/+6
| | | | | | | This reverts commit r236867, as it was breaking multiple buildbots. Daniel will look into it later. llvm-svn: 236882
* clang-format: Only output IncompleteFormat if -cursor is given.Daniel Jasper2015-05-081-6/+6
| | | | | | This is only for editor integrations. llvm-svn: 236867
* Make emacs show when clang-format encountered a syntax error.Manuel Klimek2015-05-081-5/+11
| | | | | | | Propagate the 'incomplete-format' state back through clang-format's command line interace and adapt the emacs integration to show a better result. llvm-svn: 236854
* clang-format: Don't allow -i when reading from stdin.Daniel Jasper2015-05-061-1/+3
| | | | llvm-svn: 236592
* Adopt new cl::HideUnrelatedOptions API added r226729.Chris Bieneman2015-01-211-9/+1
| | | | | | | | | | | | Summary: cl::HideUnrelatedOptions allows tools to hide all options not part of a specific OptionCategory. This is the common use case for cl::getRegisteredOptions, which should be deprecated in the future because it exposes implementation details of command line parsing. Reviewers: dexonsmith Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D7109 llvm-svn: 226741
* Add the shifted cursor position to XML output, so it can be used by editor ↵Manuel Klimek2015-01-091-0/+4
| | | | | | integrations. llvm-svn: 225516
* clang-format: Document that --assume-filename affects the language.Nico Weber2014-11-101-1/+1
| | | | llvm-svn: 221606
* clang-format: Cut more clangAST dependencies.Daniel Jasper2014-10-291-0/+1
| | | | | | Hopefully fixing windows builds. llvm-svn: 220878
* clang-format: [JS] Support regex literals with trailing escaped slash.Daniel Jasper2014-09-091-4/+1
| | | | | | | | | | | | | | | | | | Before: var regex = / a\//; int i; After: var regex = /a\//; int i; This required pushing the Lexer into its wrapper class and generating a new one in this specific case. Otherwise, the sequence get lexed as a //-comment. This is hacky, but I don't know a better way (short of supporting regex literals in the Lexer). Pushing the Lexer down seems to make all the call sites simpler. llvm-svn: 217444
* clang-format: [JS] Support alternative operator names as identifiers.Daniel Jasper2014-09-041-1/+1
| | | | | | | | | | Before: not. and . or . not_eq = 1; After: not.and.or.not_eq = 1; llvm-svn: 217179
* Update for llvm api change.Rafael Espindola2014-07-061-3/+5
| | | | llvm-svn: 212408
* Remove 'const' from MemoryBuffers used through the SourceManagerDavid Blaikie2014-06-271-1/+1
| | | | | | | | | | | | | | This removes a const_cast added in r211884 that occurred due to an inconsistency in how MemoryBuffers are handled between some parts of clang and LLVM. MemoryBuffers are immutable and the general convention in the LLVM project is to omit const from immutable types as it's simply redundant/verbose (see llvm::Type, for example). While this change doesn't remove "const" from /every/ MemoryBuffer, it at least makes this chain of ownership/usage consistent. llvm-svn: 211915
* Refer to error_code with the std prefix.Rafael Espindola2014-06-121-1/+1
| | | | llvm-svn: 210817
* clang-format: Introduce DisableFormat that prevents formatting.Daniel Jasper2014-05-221-1/+2
| | | | | | | | | | | | | | | | | And "none" pseudo-style indicating that formatting should be not applied. (1) Using .clang-format with "DisableFormat: true" effectively prevents formatting for all files within the folder containing such .clang-format file. (2) Using -fallback-style=none together with -style=file prevents formatting when .clang-format is not found, which can be used in on-save callback. Patch by Adam Strzelecki. Thank you! llvm-svn: 209446
* Enable alternative tokens by default for clang-format.Nikola Smiljanic2014-05-081-2/+2
| | | | | | Patch by Bobby Moretti. llvm-svn: 208269
* 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
* Add newlines to fallback-style description. Patch by Kamal Essoufi\!Alexander Kornienko2014-02-261-3/+4
| | | | llvm-svn: 202269
* Make the OptionCategory variable static.Alexander Kornienko2014-02-051-1/+1
| | | | llvm-svn: 200839
* Shorten the output of `clang-format --version`, include revision number.Nico Weber2014-01-071-0/+7
| | | | | | | | | | | | | | | | | Before: $ clang-format --version LLVM (http://llvm.org/): LLVM version 3.5svn Optimized build with assertions. Built Jan 3 2014 (14:28:46). Default target: x86_64-apple-darwin13.0.0 Host CPU: core-avx-i Now: $ bin/clang-format --version clang-format version 3.5 (198452) llvm-svn: 198694
* 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
* Preserve carriage return when using clang-format's XML interface.Manuel Klimek2013-12-031-2/+23
| | | | | | Patch by James Park. llvm-svn: 196265
* Added an option to specify fallback style.Alexander Kornienko2013-12-021-3/+10
| | | | | | | | | | | | | | | | Summary: Added -fallback-style option. Changed clang-format to stop searching for .clang-format when an invalid file is found. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2292 llvm-svn: 196108
* Use a StringRef. Saves 0.00000000000001s on execution time.Bill Wendling2013-11-091-1/+1
| | | | llvm-svn: 194301
* clang-format: Write files atomicallyAlp Toker2013-11-081-11/+1
| | | | | | | | | | | | | | | | | | | | | | Switch clang-format over to Rewriter::overwriteChangedFiles(). The previous implementation was attempting to stream back directly to the original file and failing if it was already memory mapped by MemoryBuffer, an operation unsupported by Windows. MemoryBuffer generally mmaps files larger than the physical page size so this will have been difficult to reproduce consistently. This change also reduces flicker in code editors and IDEs on all platforms when reformatting in-place. Note that other incorrect uses of MemoryBuffer exist in LLVM/clang and will need a similar fix. A test should be added for Windows when libFormat performance issues are fixed (it takes longer than a day to format a 1MB file at present!) llvm-svn: 194250
* clang-format: Don't exit with failure on empty files.Daniel Jasper2013-10-081-1/+1
| | | | | | | | | | Also let clang-format-diff.py detect errors based on clang-format's return code. Otherwise messages like "Can't find usable .clang-format, falling back to LLVM style" can make it fail, which might be undesired. Patch by Alp Toker. Thank you! llvm-svn: 192184
* Remove unused variable introduced in 191666David Blaikie2013-09-301-3/+0
| | | | llvm-svn: 191682
* Moving style option formatting to libFormatEdwin Vane2013-09-301-78/+6
| | | | | | | | | The help text for clang-format's -style option and the function that processes its value is moved to libFormat in this patch. The goal is to enable other tools that use libFormat and also have a -style option to behave consistently with clang-format. llvm-svn: 191666
* clang-format: Add -assume-filename option for editor integrations.Daniel Jasper2013-09-131-1/+13
| | | | | | | | | | | | | | With -style=file, clang-format now starts to search for a .clang-format file starting at the file given with -assume-filename if it reads from stdin. Otherwise, it would start searching from the current directory, which is not helpful for editor integrations. Also changed vim, emacs and sublime integrations to actually make use of this flag. This fixes llvm.org/PR17072. llvm-svn: 190691
* Allow _clang-format as alternative to .clang-format config filenameHans Wennborg2013-09-101-0/+10
| | | | | | | | | | | Dotfiles are impractical on Windows. This makes clang-format search for the style configuration file as '_clang-format' in addition to the usual '.clang-format'. This is similar to how VIM searches for '_vimrc' on Windows. Differential Revision: http://llvm-reviews.chandlerc.com/D1629 llvm-svn: 190413
* Added WebKit style to the BasedOnStyle handling and to the relevant help ↵Alexander Kornienko2013-09-021-1/+1
| | | | | | messages. llvm-svn: 189765
* Whitespace changes in help messages + updated help output in .rst file.Alexander Kornienko2013-09-021-4/+4
| | | | llvm-svn: 189762
* Switch the default mode for clang-format to '-file'. Make 'LLVM' theChandler Carruth2013-09-021-7/+7
| | | | | | | | | | | | | | | | | | | fallback syntax used when we fail to find a '.clang-format' file. Adjust variable names appropriately. Update the editor integration pieces that specify a '-style' option to specify it as '-style=file'. I left the functionality in place because even if the preferred method is to use '.clang-format' files, this way if someone needs to clobber the style in their editor we show how to do so in these examples. Also check in a '.clang-format' file for Clang to ensure that separate checkouts and builds of Clang from LLVM can still get the nice formatting. =] This unfortunately required nuking the test for the absence of a '.clang-format' file as now the directory happening to be under your clang source tree will cause there to always be a file. ;] llvm-svn: 189741
* Added -lines X:Y option to specify line range to process. This is a more ↵Alexander Kornienko2013-07-181-16/+67
| | | | | | | | human-friendly alternative to -offset and -length. Differential Revision: http://llvm-reviews.chandlerc.com/D1160 llvm-svn: 186625
* Update for llvm API change.Rafael Espindola2013-07-161-1/+1
| | | | llvm-svn: 186448
* Prevent error message when formatting an empty file.Daniel Jasper2013-07-031-0/+2
| | | | | | This fixes llvm.org/PR16514. llvm-svn: 185531
* Use lexing mode based on FormatStyle.Standard.Alexander Kornienko2013-06-281-3/+4
| | | | | | | | | | | | | | | | | | | | | Summary: Some valid pre-C++11 constructs change meaning when lexed in C++11 mode, e.g. #define x(_a) printf("foo"_a); (example from http://llvm.org/bugs/show_bug.cgi?id=16342). "foo"_a is treated as a user-defined string literal when parsed in C++11 mode. In order to deal with this correctly, we need to set lexing mode according to which standard the code conforms to. We already have a configuration value for this (FormatStyle.Standard), which seems to be appropriate to use in this case as well. Reviewers: klimek CC: cfe-commits, gribozavr Differential Revision: http://llvm-reviews.chandlerc.com/D1028 llvm-svn: 185149
* Fix behavior of clang-format's -cursor flag.Daniel Jasper2013-05-211-1/+1
| | | | llvm-svn: 182386
* Let clang-format move the cursor appropriately.Daniel Jasper2013-05-211-0/+8
| | | | | | | | | With this patch, clang-format will try to keep the cursor at the original code position in editor integrations (implemented for emacs and vim). This means, after formatting, clang-format will try to keep the cursor on the same character of the same token. llvm-svn: 182373
* Clang-format: allow -style="{yaml/json}" on command lineAlexander Kornienko2013-05-191-8/+30
| | | | | | | | | | | | | | Summary: + improved handling of default style and predefined styles. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D813 llvm-svn: 182205
* Reformat clang-format help strings, filter out irrelevant options.Alexander Kornienko2013-05-101-27/+52
| | | | | | | | | | | | | | Summary: +updated ClangFormat.rst Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D780 llvm-svn: 181617
OpenPOWER on IntegriCloud