summaryrefslogtreecommitdiffstats
path: root/clang/tools/clang-format
Commit message (Collapse)AuthorAgeFilesLines
* [clang-format] Add a default format style that can be used by users of ↵Eric Liu2018-06-251-10/+11
| | | | | | | | | | | | | | | | | | | | | | | | | `getStyle` Summary: Tools that reformat code often call `getStyle` to decide the format style to use on a certain source file. In practice, "file" style is widely used. As a result, many tools hardcode "file" when calling `getStyle`, which makes it hard to control the default style in tools across a codebase when needed. This change introduces a `DefaultFormatStyle` constant (default to "file" in upstream), which can be modified downstream if wanted, so that all users/tools built from the same source tree can have a consistent default format style. This also adds an DefaultFallbackStyle that is recommended to be used by tools and can be modified downstream. Reviewers: sammccall, djasper Reviewed By: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48492 llvm-svn: 335492
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-092-2/+2
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* Use InitLLVM in clang as well.Rui Ueyama2018-04-131-11/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D45634 llvm-svn: 330067
* Fix typos in clangAlexander Kornienko2018-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found via codespell -q 3 -I ../clang-whitelist.txt Where whitelist consists of: archtype cas classs checkk compres definit frome iff inteval ith lod methode nd optin ot pres statics te thru Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few files that have dubious fixes reverted.) Differential revision: https://reviews.llvm.org/D44188 llvm-svn: 329399
* [clang-format] Wildcard expansion on Windows.Alexander Kornienko2018-03-261-1/+10
| | | | | | | | | | | | | | | | | | Summary: Add support for wildcard expansion in command line arguments on Windows. See https://docs.microsoft.com/en-us/cpp/c-language/expanding-wildcard-arguments Fixes https://bugs.llvm.org/show_bug.cgi?id=17217 Reviewers: klimek, djasper, rnk Reviewed By: rnk Subscribers: rnk, smeenai, zturner, alexfh, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D44778 llvm-svn: 328495
* [clang-format] Fix bug where -dump-config failed on ObjC headerBen Hamilton2018-01-291-3/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: `clang-format -dump-config path/to/file.h` never passed anything for the Code parameter to clang::format::getStyle(). This meant the logic to guess Objective-C from the contents of a .h file never worked, because LibFormat didn't have the code to work with. With this fix, we now correctly read in the contents of the file if possible with -dump-config. I had to update the lit config for test/Format/ because the default config ignores .h files. Test Plan: make -j12 check-clang Reviewers: jolesiak, krasimir Reviewed By: jolesiak, krasimir Subscribers: Wizard, klimek, cfe-commits, djasper Differential Revision: https://reviews.llvm.org/D42395 llvm-svn: 323668
* [git-clang-format] Process CUDA filesJonas Hahnfeld2018-01-281-0/+1
| | | | | | | | | Clang supports compiling CUDA source files for some time, format them by default as well. Differential Revision: https://reviews.llvm.org/D42589 llvm-svn: 323615
* [CMake] Use PRIVATE in target_link_libraries for fuzzers.Matt Morehouse2017-12-061-0/+1
| | | | | | Several fuzzers were missed by r319840. llvm-svn: 319948
* [CMake] Use PRIVATE in target_link_libraries for executablesShoaib Meenai2017-12-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We currently use target_link_libraries without an explicit scope specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables. Dependencies added in this way apply to both the target and its dependencies, i.e. they become part of the executable's link interface and are transitive. Transitive dependencies generally don't make sense for executables, since you wouldn't normally be linking against an executable. This also causes issues for generating install export files when using LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM library dependencies, which are currently added as interface dependencies. If clang is in the distribution components but the LLVM libraries it depends on aren't (which is a perfectly legitimate use case if the LLVM libraries are being built static and there are therefore no run-time dependencies on them), CMake will complain about the LLVM libraries not being in export set when attempting to generate the install export file for clang. This is reasonable behavior on CMake's part, and the right thing is for LLVM's build system to explicitly use PRIVATE dependencies for executables. Unfortunately, CMake doesn't allow you to mix and match the keyword and non-keyword target_link_libraries signatures for a single target; i.e., if a single call to target_link_libraries for a particular target uses one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must also be updated to use those keywords. This means we must do this change in a single shot. I also fully expect to have missed some instances; I tested by enabling all the projects in the monorepo (except dragonegg), and configuring both with and without shared libraries, on both Darwin and Linux, but I'm planning to rely on the buildbots for other configurations (since it should be pretty easy to fix those). Even after this change, we still have a lot of target_link_libraries calls that don't specify a scope keyword, mostly for shared libraries. I'm thinking about addressing those in a follow-up, but that's a separate change IMO. Differential Revision: https://reviews.llvm.org/D40823 llvm-svn: 319840
* Fix assume-filename handling in clang-format.elPhilipp Stephani2017-12-021-16/+29
| | | | | | | | | | | | | | | | | | | | | Summary: When 'buffer-file-name' is nil 'call-process-region' returned a segmentation fault error. This was a problem when using clang-format-buffer on an orgmode source code editing buffer. I fixed this problem by excluding the '-assume-filename' argument when 'buffer-file-name' is nil. To make it a bit more flexible I also added an optional argument, 'assume-file-name', to specify an assume-filename that overrides 'buffer-file-name'. Reviewers: klimek, djasper, phst, phi Reviewed By: phst, phi Subscribers: phi, jholewinski, mgorny, javed.absar, eraman, cfe-commits Differential Revision: https://reviews.llvm.org/D37903 llvm-svn: 319621
* Fix clang-format CLion integration bug.Eric Liu2017-11-021-1/+1
| | | | | | | | | | | | | CLion's Sax parser threw this error: Failed to parse clang-format XML replacements. Input: <?xml version='1.0'?> <replacements xml:space='preserve' incomplete_format='true' line=89> [...] [org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 66; Open quote is expected for attribute "line" associated with an element type "replacements".] Patch by Justine Tunney (jart@google.com)! llvm-svn: 317205
* [cmake] Rename LIB_FUZZING_ENGINE to LLVM_LIB_FUZZING_ENGINE.Matt Morehouse2017-10-122-2/+2
| | | | llvm-svn: 315630
* [clang-format] Allow building fuzzer with OSS-Fuzz flags.Matt Morehouse2017-10-122-3/+7
| | | | | | | | | | | | Reviewers: kcc, bogner Reviewed By: kcc Subscribers: cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D38853 llvm-svn: 315603
* Update for llvm change.Rafael Espindola2017-09-081-1/+3
| | | | llvm-svn: 312766
* [clang-format] Fix lines=all case in clang-format.pyKrasimir Georgiev2017-09-051-1/+1
| | | | llvm-svn: 312536
* Fix ClangFormatFuzzer.George Karpenkov2017-08-241-2/+5
| | | | llvm-svn: 311621
* Update Clang fuzzers to use libFuzzer bundled with the toolchain.George Karpenkov2017-08-231-3/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D37043 llvm-svn: 311516
* [clang-format] Fix lines regression in clang-format.pyKrasimir Georgiev2017-08-221-1/+1
| | | | | | | | | | | | | | | | Summary: This patch fixes a regression after https://reviews.llvm.org/rL305665, which updates the structure of the `lines` variable. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D37011 llvm-svn: 311456
* clang-format: add an option -verbose to list the files being processedSylvestre Ledru2017-08-121-16/+16
| | | | | | | | | | | | | | Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D34824 llvm-svn: 310778
* clang-format: Add capability to format the diff on save in vim.Daniel Jasper2017-06-191-2/+13
| | | | | | | | | | | With this patch, one can configure a BufWrite hook that will make the clang-format integration compute a diff of the current buffer with the file that's on disk and format all changed lines. This should create a zero-overhead auto-format solution that doesn't require the file to already be clang-format clean to avoid spurious diffs. Review: https://reviews.llvm.org/D32429 llvm-svn: 305665
* [clang-format] Allow git-clang-format to handle empty extensions.Eric Fiselier2017-06-151-0/+2
| | | | | | | | | | | Most of libc++'s header files don't use extension. This prevents using git-clang-format on them, which is frustrating. This patch allows empty extensions to be passed using either the --extensions option, or the clangformat.extensions git-config value. llvm-svn: 305437
* Print registered targets in clang's version informationDimitry Andric2017-06-061-2/+1
| | | | | | | | | | | | | | | | | | | | | Summary: Other llvm tools display their registered targets when showing version information, but for some reason clang has never done this. To support this, D33899 adds the llvm parts, which make it possible to print version information to arbitrary raw_ostreams. This change adds a call to printRegisteredTargetsForVersion in clang's PrintVersion, and adds a raw_ostream parameter to two other PrintVersion functions. Reviewers: beanz, chandlerc, dberris, mehdi_amini, zturner Reviewed By: mehdi_amini Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33900 llvm-svn: 304836
* Make git-clang-format python 3 compatibleEric Fiselier2017-05-251-4/+30
| | | | | | | | | | | | | | Summary: This patch attempts to make `git-clang-format` both python2 and python3 compatible. Currently it only works in python2. Reviewers: modocache, compnerd, djasper, jbcoe, srhines, ddunbar Reviewed By: jbcoe Subscribers: kimgr, mgorny, llvm-commits, cfe-commits Differential Revision: https://reviews.llvm.org/D30773 llvm-svn: 303871
* [clang-format] Replace IncompleteFormat by a struct with LineKrasimir Georgiev2017-04-211-5/+12
| | | | | | | | | | | | | | Summary: This patch replaces the boolean IncompleteFormat that is used to notify the client if an unrecoverable syntax error occurred by a struct that also contains a line number. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D32298 llvm-svn: 300985
* Fix Python 2 vs 3 incompatability with dict.items() vs iteritems()Eric Fiselier2017-04-201-1/+6
| | | | llvm-svn: 300895
* Begin making git-clang-format python3 compatible.Eric Fiselier2017-04-201-21/+25
| | | | | | | | | | | | | | | | | | | | | | This patch fixes most of the python3 incompatabilities within git-clang-format while keeping the script python2 compatible. There is still one remaining incompatability that prevents using Python3 which is the `str` vs `byte` type change. I plan to put those fixes up for review separately. This patch contains fixes for the following incompatabilities: 1) Use the new style Python3 `print` function. This requires importing __future__.print_function. 2) Fix incompatability between the Python3 octal prefix and the octal prefix Git uses. 3) Replace use of dict.iteritems() with dict.viewitems() because iteritems() has been removed in Python3. viewitems() reviews python 2.7 but that is also what the script is documented as requiring. llvm-svn: 300891
* clang-format: Don't leave behind temp files in -i mode on Windows, PR26125, ↵Nico Weber2017-02-271-4/+9
| | | | | | | | | | | | | | | | | | reloaded Second attempt after http://llvm.org/viewvc/llvm-project?rev=296166&view=rev In the first attempt, Code (the memory buffer backing the input file) was reset before overwriteChangedFiles() was called, but overwriteChangedFiles() still reads from it. This time, load the whole input file into memory instead of using mmap when formatting in-place. (Since the test is identical to what was in the repo before chapuni's revert, svn diff doesn't show it – see the above link for the test.) https://reviews.llvm.org/D30385 llvm-svn: 296408
* Revert r296166, "clang-format: Don't leave behind temp files in -i mode on ↵NAKAMURA Takumi2017-02-251-1/+0
| | | | | | | | | | | | | | | | | | | | | Windows, PR26125", and r296171. (MemoryBuffer)Code.reset() was too early. ==26912== Invalid read of size 1 ==26912== at 0x437E1D: llvm::MemoryBuffer::init(char const*, char const*, bool) (MemoryBuffer.cpp:47) ==26912== by 0x438013: (anonymous namespace)::MemoryBufferMem::MemoryBufferMem(llvm::StringRef, bool) (MemoryBuffer.cpp:86) ==26912== by 0x438128: llvm::MemoryBuffer::getMemBuffer(llvm::StringRef, llvm::StringRef, bool) (MemoryBuffer.cpp:112) ==26912== by 0x4E189D: clang::vfs::detail::(anonymous namespace)::InMemoryFileAdaptor::getBuffer(llvm::Twine const&, long, bool, bool) (VirtualFileSystem.cpp:443) ==26912== by 0x4DF5BA: clang::vfs::FileSystem::getBufferForFile(llvm::Twine const&, long, bool, bool) (VirtualFileSystem.cpp:94) ==26912== by 0x4B72EC: clang::FileManager::getBufferForFile(clang::FileEntry const*, bool, bool) (FileManager.cpp:443) ==26912== by 0x4C1F81: clang::SrcMgr::ContentCache::getBuffer(clang::DiagnosticsEngine&, clang::SourceManager const&, clang::SourceLocation, bool*) const (SourceManager.cpp:98) ==26912== by 0x4C50E5: clang::SourceManager::getBufferData(clang::FileID, bool*) const (SourceManager.cpp:689) ==26912== by 0x58E794: clang::Rewriter::getEditBuffer(clang::FileID) (Rewriter.cpp:230) ==26912== by 0x407297: clang::format::format(llvm::StringRef) (ClangFormat.cpp:311) ==26912== by 0x4078D7: main (ClangFormat.cpp:363) llvm-svn: 296237
* clang-format: Don't leave behind temp files in -i mode on Windows, PR26125Nico Weber2017-02-241-0/+1
| | | | | | Fix and analysis by Wei Mao <weimao1@gmail.com> (see bug), test by me. llvm-svn: 296166
* clang-format: [JS] do not format MPEG transport streams.Martin Probst2017-01-271-0/+1
| | | | | | | | | | | | | | | Summary: The MPEG transport stream file format also uses ".ts" as its file extension. This change detects its specific framing format (0x47 every 189 bytes) and simply ignores MPEG TS files. Reviewers: djasper, sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D29186 llvm-svn: 293270
* Use UTF-8 for all communication with clang-formatPhilipp Stephani2017-01-202-21/+42
| | | | | | | | | | | | Summary: Instead of picking the buffer file coding system, always use utf-8-unix for communicating with clang-format. This is fine because clang-format never actually reads the file to be formatted, only standard input. This is a bit simpler (process coding system is now a constant) and potentially faster, as utf-8-unix is Emacs's internal coding system. Also add an end-to-end test that actually invokes clang-format. Reviewers: klimek Reviewed By: klimek Differential Revision: https://reviews.llvm.org/D28904 llvm-svn: 292593
* Make sure that clang-format input is in the right encodingPhilipp Stephani2017-01-172-1/+115
| | | | | | | | | | | | Summary: Add unit tests. Reviewers: klimek, massberg Reviewed By: massberg Differential Revision: https://reviews.llvm.org/D28800 llvm-svn: 292234
* clang-format: Make GetStyle return Expected<FormatStyle> instead of FormatStyleAntonio Maiorano2017-01-171-7/+17
| | | | | | | | | | Change the contract of GetStyle so that it returns an error when an error occurs (i.e. when it writes to stderr), and only returns the fallback style when it can't find a configuration file. Differential Revision: https://reviews.llvm.org/D28081 llvm-svn: 292174
* clang-format: Separate out a language kind for ObjC.Daniel Jasper2016-12-121-1/+2
| | | | | | | | | | | | | While C(++) and ObjC are generally formatted the same way and can be mixed, people might want to choose different styles based on the language. This patch recognizes .m and .mm files as ObjC and also implements a very crude detection of whether or not a .h file contains ObjC code. This can be improved over time. Also move most of the ObjC tests into their own test file to keep file size maintainable. llvm-svn: 289428
* [clang-format] Another attempt at python 3 compatibilityVedant Kumar2016-12-101-1/+7
| | | | | | | | | The entries in vim.current.buffer appear to be decoded strings, which means that python3 won't allow invoking 'decode' on them. Keep the old behavior when running under python2, but skip the error-inducing decode step with python3.. llvm-svn: 289308
* Add the --no-color option to the git call in the doc when using ↵Sylvestre Ledru2016-12-031-1/+1
| | | | | | clang-format-diff llvm-svn: 288605
* clang-format: Use git-ls-tree to get file mode in diff modeStephen Hines2016-11-081-1/+10
| | | | | | | | | | | | | | | | | | Summary: If a file has been renamed/deleted from the filesystem and --diff mode with two commits is active, attempting to get the file's mode will fail. This change uses git-ls-tree instead to get the correct permissions for the given revision. Patch by Luis Hector Chavez! Reviewers: djasper, lodato Subscribers: srhines, cfe-commits Differential Revision: https://reviews.llvm.org/D26287 llvm-svn: 286212
* Attempt to make clang-format.py python 3 - compatible.Alexander Kornienko2016-10-271-1/+1
| | | | llvm-svn: 285301
* Fix warnings from python difflib.Alexander Kornienko2016-10-271-3/+3
| | | | llvm-svn: 285291
* Fix clang-format vim integration issue with non-ascii charactersAlexander Kornienko2016-10-241-1/+1
| | | | | | | | | | | | | | | | clang-format.py currently seems to treat vim.current.buf as ascii-encoded data, which leads to an UnicodeDecodeError when trying to format any text containing non-ascii characters: Traceback (most recent call last): File "<string>", line 1, in <module> File ".../tools/clang/tools/clang-format/clang-format.py", line 110, in <module> main() File ".../tools/clang/tools/clang-format/clang-format.py", line 87, in main stdout, stderr = p.communicate(input=text.encode(encoding)) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 3996: ordinal not in range(128) llvm-svn: 284988
* Minor cleanups in clang-format.el.Manuel Klimek2016-10-041-41/+48
| | | | | | | | | | | | | | | | | | - Enable lexical binding - Formatting - Enable file name completion for the clang-format-executable variable - Add a missing docstring - When available, use bufferpos-to-filepos and filepos-to-bufferpos. These functions given more precise mapping than byte-to-position and position-bytes. - Rename arguments of clang-format-region to match the docstring - Instead of binding local variables to nil and then assigning them, bind them directly to their values - Make use of the fact that insert-file-contents returns the number of characters it inserted - Use cl-destructuring-bind to make the code a bit shorter - Use standard iteration (dolist) instead of mapc with a lambda, which is more common and shorter - Remove a message that was most likely only present for debugging purposes Patch by Philipp Stephani. llvm-svn: 283206
* clang-format: Add an option to git-clang-format to diff between to commitsStephen Hines2016-09-221-50/+97
| | | | | | | | | | | | | | | | | | | | | Summary: When building pre-upload hooks using git-clang-format, it is useful to limit the scope to a diff of two commits (instead of from a commit against the working tree) to allow for less false positives in dependent commits. This change adds the option of specifying two git commits to git-clang-format when using the `--diff` flag, which uses a different strategy to diff (using `git-diff-tree` instead of `git-diff-index`), and runs clang-format against the second commit instead of the working directory. There is a slight backwards-incompatibility introduced with this change: if a filename matches a branch name or other commit-ish, then `git clang-format <commit> <file>` will no longer work as expected; use `git clang-format <commit> -- <file>` instead. Patch by Luis Hector Chavez! Reviewers: djasper, lodato Subscribers: lodato, cfe-commits, srhines Projects: #clang-c Differential Revision: https://reviews.llvm.org/D24319 llvm-svn: 282136
* clang-format: Add Java detection to git-clang-format.Stephen Hines2016-09-131-0/+1
| | | | | | | | | | | | | | Summary: This change adds "java" to the list of known extensions that clang-format supports. Patch by Luis Hector Chavez Reviewers: djasper Subscribers: srhines, cfe-commits Differential Revision: https://reviews.llvm.org/D24401 llvm-svn: 281294
* clang-format: Make emacs integration work with narrowed buffers.Daniel Jasper2016-09-121-1/+1
| | | | | | | | | Use (call-process region nil ...) instead of (point-min) so that the call works in narrowed buffers. Patch by Philipp Stephani, thank you! llvm-svn: 281203
* [clang-format-vim] Support vim linked against py3Luke Drummond2016-08-311-7/+11
| | | | | | | | | | | | clang-format.py previously only worked in vim compiled against python2. This patch adds the necessary syntax changes to make this work with vim linked against python3, which is now shipped by default for at least Ubuntu16 and Arch. Differential Revision: https://reviews.llvm.org/D23319 Subscribers: cfe-commits llvm-svn: 280240
* Make clang-format remove duplicate headers when sorting #includes.Eric Liu2016-08-101-3/+2
| | | | | | | | | | | | Summary: When sorting #includes, #include directives that have the same text will be deduplicated when sorting #includes, and only the first #include in the duplicate #includes remains. If the `Cursor` is provided and put on a deleted #include, it will be put on the remaining #include in the duplicate #includes. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D23274 llvm-svn: 278206
* Implement tooling::Replacements as a class.Eric Liu2016-08-011-4/+4
| | | | | | | | | | | | | | | | | | | Summary: - Implement clang::tooling::Replacements as a class to provide interfaces to control how replacements for a single file are combined and provide guarantee on the order of replacements being applied. - tooling::Replacements only contains replacements for the same file now. Use std::map<std::string, tooling::Replacements> to represent multi-file replacements. - Error handling for the interface change will be improved in followup patches. Reviewers: djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D21748 llvm-svn: 277335
* [NFC] Header cleanupMehdi Amini2016-07-181-2/+0
| | | | | | | | | | Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
* Make tooling::applyAllReplacements return llvm::Expected<string> instead of ↵Eric Liu2016-07-111-3/+6
| | | | | | | | | | | | | | | | empty string to indicate potential error. Summary: return llvm::Expected<> to carry error status and error information. This is the first step towards introducing "Error" into tooling::Replacements. Reviewers: djasper, klimek Subscribers: ioeric, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21601 llvm-svn: 275062
* Update to match LLVM r272232.Richard Smith2016-06-091-1/+1
| | | | llvm-svn: 272233
OpenPOWER on IntegriCloud