[PATCH] D31334: [clang-format] Add options for indenting preprocessor directives

Marek Kurdej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 24 08:31:55 PDT 2017


curdeius created this revision.
Herald added subscribers: mgorny, klimek.

This concerns bug #17362 (https://bugs.llvm.org//show_bug.cgi?id=17362).

2 styles for indenting are added: before and after hash.
3 methods:

- None (default): equivalent to current behaviour of clang-format
- All: indents all directives
- Inner: recognizes include guards and ignores them during indentation

Indentation level uses `IndentWidth` style parameter.

For instance, and indented code with include guards:

  #ifndef INCLUDE_GUARD
  #define INCLUDE_GUARD
  #define A // not indented with Inner method
  #ifdef B
  # undef B
  #else
  # define C
  #endif
  #endif // INCLUDE_GUARD

I've tried to make the detection of include guards as correct as possible, but if you know of any edge cases that are not taken into account, I'm all ears.


Repository:
  rL LLVM

https://reviews.llvm.org/D31334

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  tools/clang-format/ClangFormat.cpp
  unittests/Format/CMakeLists.txt
  unittests/Format/FormatPreprocessorTest.cpp
  unittests/Format/FormatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31334.92949.patch
Type: text/x-patch
Size: 1245931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170324/846255de/attachment-0001.bin>


More information about the cfe-commits mailing list