Fix layouting of tokens with a leading escaped newline.

If a token follows directly on an escaped newline, the escaped newline
is stored with the token. Since we re-layout escaped newlines, we need
to treat them just like normal whitespace - thus, we need to increase
the whitespace-length of the token, while decreasing the token length
(otherwise the token length contains the length of the escaped newline
and we double-count it while indenting).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171706 91177308-0d34-0410-b5e6-96231b3b80d8
Fix layouting of single-line-comments preceded by an escaped newline.

Previously, we'd format
  int i;\
  // comment
as
  int i; // comment

The problem is that the escaped newline is part of the next token, and
thus the raw token text of the comment doesn't start with "//".

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171713 91177308-0d34-0410-b5e6-96231b3b80d8
Do not ever allow using the full line in preprocessor directives.

We would format:
  #define A \
    int f(a); int i;
as
  #define A \
    int f(a);\
    int i

The fix will break up macro definitions that could fit a line, but hit
the last column; fixing that is more involved, though, as it requires
looking at the following line.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171715 91177308-0d34-0410-b5e6-96231b3b80d8
Remove outdated fixme.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171716 91177308-0d34-0410-b5e6-96231b3b80d8
Remove outdated FIXME and add explanation for error handling strategy
while parsing #define's.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171717 91177308-0d34-0410-b5e6-96231b3b80d8
CFG.cpp: Fix wrapping logic when printing block preds/succs.

First check only wrapped with i==8, second wrapped at i==2,8,18,28,...
This fix restores the intended behavior: i==8,18,28,...

Found with -fsanitize=integer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171718 91177308-0d34-0410-b5e6-96231b3b80d8
Fix incorrect FIXME.

The case that we wanted to write a test for cannot happen, as the
UnwrappedLineParser already protects against it. Added an assert to
prevent regressions of that assumption.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171720 91177308-0d34-0410-b5e6-96231b3b80d8
Do not break before "0" in pure virtual function declarations.

Before:
virtual void write(ELFWriter *writer, OwningPtr<FileOutputBuffer> &buffer) =
    0

After:
virtual void write(ELFWriter *writerrr,
                   OwningPtr<FileOutputBuffer> &buffer) = 0;

This addresses llvm.org/PR14815.

To implement this I introduced a line type during parsing and moved the
definition of TokenType out of the struct for increased readability.
Should have done the latter in a separate patch, but it would be hard to
pull apart now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171724 91177308-0d34-0410-b5e6-96231b3b80d8
Add style option for number of spaces before trailing comments.

In LLVM style, a single space should be enough. In Google style, two
spaces are required.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171725 91177308-0d34-0410-b5e6-96231b3b80d8
Prefer not to break after assignments.

This addresses llvm.org/PR14830.

Before:
unsigned Cost =
    TTI.getMemoryOpCost(I->getOpcode(), VectorTy, SI->getAlignment(),
                        SI->getPointerAddressSpace());
CharSourceRange LineRange =
    CharSourceRange::getTokenRange(TheLine.Tokens.front().Tok.getLocation(),
                                   TheLine.Tokens.back().Tok.getLocation());

After:
unsigned Cost = TTI.getMemoryOpCost(I->getOpcode(), VectorTy,
                                    SI->getAlignment(),
                                    SI->getPointerAddressSpace());
CharSourceRange LineRange = CharSourceRange::getTokenRange(
                                TheLine.Tokens.front().Tok.getLocation(),
                                TheLine.Tokens.back().Tok.getLocation());

This required rudimentary changes to static initializer lists, but we
are not yet formatting them in a reasonable way. That will be done in a
subsequent patch.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171731 91177308-0d34-0410-b5e6-96231b3b80d8
Reformat clang-formats source code.

All changes done by clang-format itself. No functional changes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171732 91177308-0d34-0410-b5e6-96231b3b80d8
s/parseStatement/parseStructuralElement/g in the UnwrappedLineParser.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171737 91177308-0d34-0410-b5e6-96231b3b80d8
Fix typo.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171740 91177308-0d34-0410-b5e6-96231b3b80d8
Add a test that checks that the formatter doesn't discard '@' with ObjC1 set.

Also set ObjC1 in the formatter tests.

The only effect of this flag in the lexer is that '@' now gets turned into
tok::at instead of tok::unknown.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171742 91177308-0d34-0410-b5e6-96231b3b80d8
Small refactoring of the formatter code.

This should make it slightly more readable as it more clearly separates
what happens where. No intended functional changes. More of this to
come..

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171748 91177308-0d34-0410-b5e6-96231b3b80d8
libclang/Makefile: Reorder USEDLIBS along driver/clang.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171750 91177308-0d34-0410-b5e6-96231b3b80d8
Slightly expand the @ test to cover whitespace between @ and keyword.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171751 91177308-0d34-0410-b5e6-96231b3b80d8
Test all @keywords. Turns out some of them are not formatted correctly yet.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171752 91177308-0d34-0410-b5e6-96231b3b80d8
Formatter: Don't put spaces betwen @ and objc keywords.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171753 91177308-0d34-0410-b5e6-96231b3b80d8
Formatter: Add tests for try/catch. Let 'throw' start an expression.

Before:
  throw a *b;

Now:
  throw a * b;



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171754 91177308-0d34-0410-b5e6-96231b3b80d8