Skip to content
Snippets Groups Projects
  1. Nov 27, 2017
  2. Nov 17, 2017
  3. Nov 09, 2017
  4. Oct 12, 2017
  5. Sep 15, 2017
  6. Sep 07, 2017
  7. Aug 30, 2017
    • Krasimir Georgiev's avatar
      clang-format: Add preprocessor directive indentation · 31c7a3b6
      Krasimir Georgiev authored
      Summary:
      This is an implementation for [bug 17362](https://bugs.llvm.org/attachment.cgi?bugid=17362) which adds support for indenting preprocessor statements inside if/ifdef/endif. This takes previous work from fmauch (https://github.com/fmauch/clang/tree/preprocessor_indent) and makes it into a full feature.
      The context of this patch is that I'm a VMware intern, and I implemented this because VMware needs the feature. As such, some decisions were made based on what VMware wants, and I would appreciate suggestions on expanding this if necessary to use-cases other people may want.
      
      This adds a new enum config option, `IndentPPDirectives`. Values are:
      
      * `PPDIS_None` (in config: `None`):
      ```
          #if FOO
          #if BAR
          #include <foo>
          #endif
          #endif
      ```
      * `PPDIS_AfterHash` (in config: `AfterHash`):
      ```
          #if FOO
          #  if BAR
          #    include <foo>
          #  endif
          #endif
      ```
      This is meant to work whether spaces or tabs are used for indentation. Preprocessor indentation is independent of indentation for non-preprocessor lines.
      
      Preprocessor indentation also attempts to ignore include guards with the checks:
      1. Include guards cover the entire file
      2. Include guards don't have `#else`
      3. Include guards begin with
      ```
      #ifndef <var>
      #define <var>
      ```
      
      This patch allows `UnwrappedLineParser::PPBranchLevel` to be decremented to -1 (the initial value is -1) so the variable can be used for indent tracking.
      
      Defects:
      * This patch does not handle the case where there's code between the `#ifndef` and `#define` but all other conditions hold. This is because when the #define line is parsed, `UnwrappedLineParser::Lines` doesn't hold the previous code line yet, so we can't detect it. This is out of the scope of this patch.
      
      * This patch does not handle cases where legitimate lines may be outside an include guard. Examples are `#pragma once` and `#pragma GCC diagnostic`, or anything else that does not change the meaning of the file if it's included multiple times.
      
      * This does not detect when there is a single non-preprocessor line in front of an include-guard-like structure where other conditions hold because `ScopedLineState` hides the line.
      
      * Preprocessor indentation throws off `TokenAnnotator::setCommentLineLevels` so the indentation of comments immediately before indented preprocessor lines is toggled on each run. Fixing this issue appears to be a major change and too much complexity for this patch.
      
      Contributed by @euhlmann!
      
      Reviewers: djasper, klimek, krasimir
      
      Reviewed By: djasper, krasimir
      
      Subscribers: krasimir, mzeren-vmw, cfe-commits
      
      Tags: #clang
      
      Differential Revision: https://reviews.llvm.org/D35955
      
      git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312125 91177308-0d34-0410-b5e6-96231b3b80d8
      31c7a3b6
  8. Jun 23, 2017
  9. Jun 15, 2017
  10. Jun 06, 2017
  11. May 08, 2017
  12. Apr 11, 2017
  13. Apr 05, 2017
  14. Mar 20, 2017
  15. Mar 13, 2017
  16. Mar 10, 2017
  17. Mar 09, 2017
  18. Mar 08, 2017
  19. Mar 06, 2017
  20. Mar 01, 2017
  21. Aug 09, 2016
  22. Mar 21, 2016
  23. Feb 27, 2016
  24. Feb 23, 2016
  25. Feb 14, 2016
  26. Dec 18, 2015
  27. Oct 27, 2015
  28. Oct 07, 2015
  29. Oct 06, 2015
  30. Oct 05, 2015
Loading