[clang-format] Revert e9e6e3b34a8e
authormydeveloperday <mydeveloperday@gmail.com>
Sun, 17 Jan 2021 11:07:31 +0000 (11:07 +0000)
committermydeveloperday <mydeveloperday@gmail.com>
Sun, 17 Jan 2021 11:07:31 +0000 (11:07 +0000)
Reverting {D92753} due to issues with #pragma indentation in #ifdef/endif structure

clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTest.cpp

index c58bb1a..8eee618 100644 (file)
@@ -2181,30 +2181,6 @@ the configuration (without a prefix: ``Auto``).
 
 
 
-**IndentPragmas** (``bool``)
-  Indent pragmas
-
-  When ``false``, pragmas are flushed left or follow IndentPPDirectives.
-  When ``true``, pragmas are indented to the current scope level.
-
-  .. code-block:: c++
-
-    false:                                  true:
-    #pragma once                   vs       #pragma once
-    void foo() {                            void foo() {
-    #pragma omp simd                          #pragma omp simd
-      for (int i=0;i<10;i++) {                for (int i=0;i<10;i++) {
-    #pragma omp simd                            #pragma omp simd
-        for (int i=0;i<10;i++) {                for (int i=0;i<10;i++) {
-        }                                       }
-    #if 1                                   #if 1
-    #pragma omp simd                            #pragma omp simd
-        for (int i=0;i<10;i++) {                for (int i=0;i<10;i++) {
-        }                                       }
-    #endif                                  #endif
-      }                                       }
-    }                                       }
-
 **IndentRequires** (``bool``)
   Indent the requires clause in a template
 
index c6a9818..6b3fb81 100644 (file)
@@ -1792,29 +1792,6 @@ struct FormatStyle {
   /// \endcode
   bool IndentGotoLabels;
 
-  /// Indent pragmas
-  ///
-  /// When ``false``, pragmas are flushed left or follow IndentPPDirectives.
-  /// When ``true``, pragmas are indented to the current scope level.
-  /// \code
-  ///   false:                                  true:
-  ///   #pragma once                   vs       #pragma once
-  ///   void foo() {                            void foo() {
-  ///   #pragma omp simd                          #pragma omp simd
-  ///     for (int i=0;i<10;i++) {                for (int i=0;i<10;i++) {
-  ///   #pragma omp simd                            #pragma omp simd
-  ///       for (int i=0;i<10;i++) {                for (int i=0;i<10;i++) {
-  ///       }                                       }
-  ///   #if 1                                   #if 1
-  ///   #pragma omp simd                            #pragma omp simd
-  ///       for (int i=0;i<10;i++) {                for (int i=0;i<10;i++) {
-  ///       }                                       }
-  ///   #endif                                  #endif
-  ///     }                                       }
-  ///   }                                       }
-  /// \endcode
-  bool IndentPragmas;
-
   /// Options for indenting preprocessor directives.
   enum PPDirectiveIndentStyle : unsigned char {
     /// Does not indent any directives.
@@ -2790,7 +2767,6 @@ struct FormatStyle {
            IndentCaseLabels == R.IndentCaseLabels &&
            IndentCaseBlocks == R.IndentCaseBlocks &&
            IndentGotoLabels == R.IndentGotoLabels &&
-           IndentPragmas == R.IndentPragmas &&
            IndentPPDirectives == R.IndentPPDirectives &&
            IndentExternBlock == R.IndentExternBlock &&
            IndentRequires == R.IndentRequires && IndentWidth == R.IndentWidth &&
index 9e15c87..9db42b6 100644 (file)
@@ -589,12 +589,6 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
        State.Line->Type == LT_ImportStatement)) {
     Spaces += State.FirstIndent;
 
-    bool isPragmaLine =
-        State.Line->First->startsSequence(tok::hash, tok::pp_pragma);
-    // If indenting pragmas remove the extra space for the #.
-    if (Style.IndentPragmas && isPragmaLine)
-      Spaces--;
-
     // For preprocessor indent with tabs, State.Column will be 1 because of the
     // hash. This causes second-level indents onward to have an extra space
     // after the tabs. We avoid this misalignment by subtracting 1 from the
index fc62a34..1207ac2 100644 (file)
@@ -557,7 +557,6 @@ template <> struct MappingTraits<FormatStyle> {
     IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
     IO.mapOptional("IndentCaseBlocks", Style.IndentCaseBlocks);
     IO.mapOptional("IndentGotoLabels", Style.IndentGotoLabels);
-    IO.mapOptional("IndentPragmas", Style.IndentPragmas);
     IO.mapOptional("IndentPPDirectives", Style.IndentPPDirectives);
     IO.mapOptional("IndentExternBlock", Style.IndentExternBlock);
     IO.mapOptional("IndentRequires", Style.IndentRequires);
@@ -926,7 +925,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
   LLVMStyle.IndentCaseLabels = false;
   LLVMStyle.IndentCaseBlocks = false;
   LLVMStyle.IndentGotoLabels = true;
-  LLVMStyle.IndentPragmas = false;
   LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
   LLVMStyle.IndentRequires = false;
   LLVMStyle.IndentWrappedFunctionNames = false;
index e39ee26..d8f7183 100644 (file)
@@ -1237,21 +1237,10 @@ void UnwrappedLineFormatter::formatFirstToken(
   }
 
   // Preprocessor directives get indented before the hash only if specified
-  if (Line.Type == LT_PreprocessorDirective ||
-      Line.Type == LT_ImportStatement) {
-    switch (Style.IndentPPDirectives) {
-    case FormatStyle::PPDIS_AfterHash:
-      Indent = 0;
-      break;
-    case FormatStyle::PPDIS_None:
-    case FormatStyle::PPDIS_BeforeHash: {
-      // If we want to indent pragmas.
-      bool isPragmaLine = RootToken.startsSequence(tok::hash, tok::pp_pragma);
-      if (!Style.IndentPragmas && isPragmaLine)
-        Indent = 0;
-    } break;
-    }
-  }
+  if (Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
+      (Line.Type == LT_PreprocessorDirective ||
+       Line.Type == LT_ImportStatement))
+    Indent = 0;
 
   Whitespaces->replaceWhitespace(RootToken, Newlines, Indent, Indent,
                                  /*IsAligned=*/false,
index 99b8c28..f689a63 100644 (file)
@@ -714,7 +714,7 @@ void UnwrappedLineParser::parseChildBlock() {
   nextToken();
 }
 
-void UnwrappedLineParser::parsePPDirective(unsigned Level) {
+void UnwrappedLineParser::parsePPDirective() {
   assert(FormatTok->Tok.is(tok::hash) && "'#' expected");
   ScopedMacroState MacroState(*Line, Tokens, FormatTok);
 
@@ -745,17 +745,6 @@ void UnwrappedLineParser::parsePPDirective(unsigned Level) {
   case tok::pp_endif:
     parsePPEndIf();
     break;
-  case tok::pp_pragma: {
-    bool IndentPPDirectives =
-        Style.IndentPPDirectives != FormatStyle::PPDIS_None;
-    unsigned CurrentLevel = Line->Level;
-    Line->Level =
-        Style.IndentPragmas
-            ? (IndentPPDirectives ? (Level - (PPBranchLevel + 1)) : Level)
-            : CurrentLevel;
-    parsePPUnknown();
-    Line->Level = CurrentLevel;
-  } break;
   default:
     parsePPUnknown();
     break;
@@ -3184,7 +3173,7 @@ void UnwrappedLineParser::readToken(int LevelDifference) {
           PPBranchLevel > 0)
         Line->Level += PPBranchLevel;
       flushComments(isOnNewLine(*FormatTok));
-      parsePPDirective(Line->Level);
+      parsePPDirective();
     }
     while (FormatTok->getType() == TT_ConflictStart ||
            FormatTok->getType() == TT_ConflictEnd ||
index 30604c0..02b328c 100644 (file)
@@ -88,7 +88,7 @@ private:
   void parseBlock(bool MustBeDeclaration, bool AddLevel = true,
                   bool MunchSemi = true);
   void parseChildBlock();
-  void parsePPDirective(unsigned Level);
+  void parsePPDirective();
   void parsePPDefine();
   void parsePPIf(bool IfDef);
   void parsePPElIf();
index bdf4abb..acfd229 100644 (file)
@@ -14282,7 +14282,6 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
   CHECK_PARSE_BOOL(IndentGotoLabels);
-  CHECK_PARSE_BOOL(IndentPragmas);
   CHECK_PARSE_BOOL(IndentRequires);
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
@@ -17739,129 +17738,6 @@ TEST_F(FormatTest, ConceptsAndRequires) {
                "struct constant;",
                Style);
 }
-
-TEST_F(FormatTest, IndentPragmas) {
-  FormatStyle Style = getLLVMStyle();
-  Style.IndentPPDirectives = FormatStyle::PPDIS_None;
-
-  Style.IndentPragmas = false;
-  verifyFormat("#pragma once", Style);
-  verifyFormat("#pragma omp simd\n"
-               "for (int i = 0; i < 10; i++) {\n"
-               "}",
-               Style);
-  verifyFormat("void foo() {\n"
-               "#pragma omp simd\n"
-               "  for (int i = 0; i < 10; i++) {\n"
-               "  }\n"
-               "}",
-               Style);
-  verifyFormat("void foo() {\n"
-               "// outer loop\n"
-               "#pragma omp simd\n"
-               "  for (int k = 0; k < 10; k++) {\n"
-               "// inner loop\n"
-               "#pragma omp simd\n"
-               "    for (int j = 0; j < 10; j++) {\n"
-               "    }\n"
-               "  }\n"
-               "}",
-               Style);
-
-  verifyFormat("void foo() {\n"
-               "// outer loop\n"
-               "#if 1\n"
-               "#pragma omp simd\n"
-               "  for (int k = 0; k < 10; k++) {\n"
-               "// inner loop\n"
-               "#pragma omp simd\n"
-               "    for (int j = 0; j < 10; j++) {\n"
-               "    }\n"
-               "  }\n"
-               "#endif\n"
-               "}",
-               Style);
-
-  Style.IndentPragmas = true;
-  verifyFormat("#pragma once", Style);
-  verifyFormat("#pragma omp simd\n"
-               "for (int i = 0; i < 10; i++) {\n"
-               "}",
-               Style);
-  verifyFormat("void foo() {\n"
-               "  #pragma omp simd\n"
-               "  for (int i = 0; i < 10; i++) {\n"
-               "  }\n"
-               "}",
-               Style);
-  verifyFormat("void foo() {\n"
-               "  #pragma omp simd\n"
-               "  for (int i = 0; i < 10; i++) {\n"
-               "    #pragma omp simd\n"
-               "    for (int j = 0; j < 10; j++) {\n"
-               "    }\n"
-               "  }\n"
-               "}",
-               Style);
-
-  verifyFormat("void foo() {\n"
-               "  #pragma omp simd\n"
-               "  for (...) {\n"
-               "    #pragma omp simd\n"
-               "    for (...) {\n"
-               "    }\n"
-               "  }\n"
-               "}",
-               Style);
-
-  Style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash;
-
-  verifyFormat("void foo() {\n"
-               "# pragma omp simd\n"
-               "  for (int i = 0; i < 10; i++) {\n"
-               "#   pragma omp simd\n"
-               "    for (int j = 0; j < 10; j++) {\n"
-               "    }\n"
-               "  }\n"
-               "}",
-               Style);
-
-  verifyFormat("void foo() {\n"
-               "#if 1\n"
-               "# pragma omp simd\n"
-               "  for (int k = 0; k < 10; k++) {\n"
-               "#   pragma omp simd\n"
-               "    for (int j = 0; j < 10; j++) {\n"
-               "    }\n"
-               "  }\n"
-               "#endif\n"
-               "}",
-               Style);
-
-  Style.IndentPPDirectives = FormatStyle::PPDIS_BeforeHash;
-  EXPECT_EQ("void foo() {\n"
-            "#if 1\n"
-            "  #pragma omp simd\n"
-            "  for (int k = 0; k < 10; k++) {\n"
-            "    #pragma omp simd\n"
-            "    for (int j = 0; j < 10; j++) {\n"
-            "    }\n"
-            "  }\n"
-            "#endif\n"
-            "}",
-            format("void foo() {\n"
-                   "#if 1\n"
-                   "  #pragma omp simd\n"
-                   "  for (int k = 0; k < 10; k++) {\n"
-                   "    #pragma omp simd\n"
-                   "    for (int j = 0; j < 10; j++) {\n"
-                   "    }\n"
-                   "  }\n"
-                   "#endif\n"
-                   "}",
-                   Style));
-}
-
 } // namespace
 } // namespace format
 } // namespace clang