From 343643b9798c8a6f0e236453bf61985dc5eb4438 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 13 Aug 2014 08:29:18 +0000 Subject: clang-format: Understand #defines defining system includes. Before: #define MY_IMPORT < a / b > After: #define MY_IMPORT llvm-svn: 215527 --- clang/lib/Format/TokenAnnotator.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'clang/lib/Format/TokenAnnotator.cpp') diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index b24573fffcd..a3662348736 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -497,7 +497,6 @@ private: } void parseIncludeDirective() { - next(); if (CurrentToken && CurrentToken->is(tok::less)) { next(); while (CurrentToken) { @@ -554,6 +553,7 @@ private: switch (CurrentToken->Tok.getIdentifierInfo()->getPPKeywordID()) { case tok::pp_include: case tok::pp_import: + next(); parseIncludeDirective(); break; case tok::pp_error: @@ -587,8 +587,18 @@ public: // should not break the line). IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo(); if (Info && Info->getPPKeywordID() == tok::pp_import && - CurrentToken->Next && CurrentToken->Next->is(tok::string_literal)) + CurrentToken->Next && CurrentToken->Next->is(tok::string_literal)) { + next(); parseIncludeDirective(); + return LT_Other; + } + + // If this line starts and ends in '<' and '>', respectively, it is likely + // part of "#define ". + if (CurrentToken->is(tok::less) && Line.Last->is(tok::greater)) { + parseIncludeDirective(); + return LT_Other; + } while (CurrentToken) { if (CurrentToken->is(tok::kw_virtual)) -- cgit v1.2.3