[clang-format] Re-land: Fixup #include guard indents after parseFile()
authorMark Zeren <mzeren@vmware.com>
Mon, 5 Feb 2018 15:59:00 +0000 (15:59 +0000)
committerMark Zeren <mzeren@vmware.com>
Mon, 5 Feb 2018 15:59:00 +0000 (15:59 +0000)
commit1c3afaf50a0b6b96ab53740006b0bd99fd0eb1d5
treef902281dcd64e2a891338e859b1838332c71bcb3
parent45aa89eb7fb2d445ca55593f9a4b85933e52bc9c
[clang-format] Re-land: Fixup #include guard indents after parseFile()

Summary:
When a preprocessor indent closes after the last line of normal code we do not
correctly fixup include guard indents. For example:

  #ifndef HEADER_H
  #define HEADER_H
  #if 1
  int i;
  #  define A 0
  #endif
  #endif

incorrectly reformats to:

  #ifndef HEADER_H
  #define HEADER_H
  #if 1
  int i;
  #    define A 0
  #  endif
  #endif

To resolve this issue we must fixup levels after parseFile(). Delaying
the fixup introduces a new state, so consolidate include guard search
state into an enum.

Reviewers: krasimir, klimek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D42035

llvm-svn: 324246
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTest.cpp