diff options
author | Daniel Jasper <djasper@google.com> | 2014-04-01 12:55:11 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-04-01 12:55:11 +0000 |
commit | e1e4319ab796b457ecd98ae27793d57ce1236f8f (patch) | |
tree | 0e3b9a353584a13ff17153ef0c069156c23f645b /clang/lib/Format/TokenAnnotator.cpp | |
parent | 1087f2980dd96ca4db2df1416020957cf0e3bfbc (diff) | |
download | bcm5719-llvm-e1e4319ab796b457ecd98ae27793d57ce1236f8f.tar.gz bcm5719-llvm-e1e4319ab796b457ecd98ae27793d57ce1236f8f.zip |
clang-format: Support configurable list of foreach-macros.
This fixes llvm.org/PR17242.
Patch by Brian Green, thank you!
llvm-svn: 205307
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6a0e03461ee..709e0b856d4 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -120,6 +120,10 @@ private: Contexts.back().IsExpression = false; } else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) { Left->Type = TT_AttributeParen; + } else if (Left->Previous && Left->Previous->IsForEachMacro) { + // The first argument to a foreach macro is a declaration. + Contexts.back().IsForEachMacro = true; + Contexts.back().IsExpression = false; } if (StartsObjCMethodExpr) { @@ -464,6 +468,8 @@ private: Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true; if (Contexts.back().InCtorInitializer) Tok->Type = TT_CtorInitializerComma; + if (Contexts.back().IsForEachMacro) + Contexts.back().IsExpression = true; break; default: break; @@ -625,7 +631,7 @@ private: ColonIsObjCMethodExpr(false), FirstObjCSelectorName(NULL), FirstStartOfName(NULL), IsExpression(IsExpression), CanBeExpression(true), InTemplateArgument(false), - InCtorInitializer(false), CaretFound(false) {} + InCtorInitializer(false), CaretFound(false), IsForEachMacro(false) {} tok::TokenKind ContextKind; unsigned BindingStrength; @@ -641,6 +647,7 @@ private: bool InTemplateArgument; bool InCtorInitializer; bool CaretFound; + bool IsForEachMacro; }; /// \brief Puts a new \c Context onto the stack \c Contexts for the lifetime @@ -1408,8 +1415,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, Left.isOneOf(tok::kw_return, tok::kw_new, tok::kw_delete, tok::semi) || (Style.SpaceBeforeParens != FormatStyle::SBPO_Never && - Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while, tok::kw_switch, - tok::kw_catch)) || + (Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while, + tok::kw_switch, tok::kw_catch) || + Left.IsForEachMacro)) || (Style.SpaceBeforeParens == FormatStyle::SBPO_Always && Left.isOneOf(tok::identifier, tok::kw___attribute) && Line.Type != LT_PreprocessorDirective); |