<div dir="ltr">Should be fixed now. Sorry about that.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 7, 2015 at 3:00 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am now getting sphinx warnings from this commit:<br>
<br>
/opt/llvm/build-llvm/src/llvm/tools/clang/docs/ClangFormatStyleOptions.rst:159:<br>
ERROR: Error in "code-block" directive:<br>
maximum 1 argument(s) allowed, 3 supplied.<br>
<br>
.. code-block:: c++<br>
  someLongFunction(argument1,<br>
                   argument2);<br>
/opt/llvm/build-llvm/src/llvm/tools/clang/docs/ClangFormatStyleOptions.rst:169:<br>
ERROR: Error in "code-block" directive:<br>
maximum 1 argument(s) allowed, 13 supplied.<br>
<br>
.. code-block:: c++<br>
  int aaaa = 12;<br>
  int b    = 23;<br>
  int ccc  = 23;<br>
/opt/llvm/build-llvm/src/llvm/tools/clang/docs/ClangFormatStyleOptions.rst:180:<br>
ERROR: Error in "code-block" directive:<br>
maximum 1 argument(s) allowed, 13 supplied.<br>
<br>
.. code-block:: c++<br>
  int         aaaa = 12;<br>
  float       b = 23;<br>
<span class="">  std::string ccc = 23;<br>
</span>/opt/llvm/build-llvm/src/llvm/tools/clang/docs/ClangFormatStyleOptions.rst:396:<br>
ERROR: Error in "code-block" directive:<br>
maximum 1 argument(s) allowed, 4 supplied.<br>
<br>
.. code-block:: c++<br>
  FOREACH(<variable-declaration>, ...)<br>
    <loop-body><br>
/opt/llvm/build-llvm/src/llvm/tools/clang/docs/ClangFormatStyleOptions.rst:402:<br>
ERROR: Error in "code-block" directive:<br>
maximum 1 argument(s) allowed, 4 supplied.<br>
<br>
.. code-block:: c++<br>
  ForEachMacros: ['RANGES_FOR', 'FOREACH']<br>
/opt/llvm/build-llvm/src/llvm/tools/clang/docs/ClangFormatStyleOptions.rst:424:<br>
ERROR: Error in "code-block" directive:<br>
maximum 1 argument(s) allowed, 17 supplied.<br>
<br>
.. code-block:: c++<br>
  IncludeCategories:<br>
<span class="">    - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'<br>
</span>      Priority:        2<br>
<span class="">    - Regex:           '^(<|"(gtest|isl|json)/)'<br>
</span>      Priority:        3<br>
    - Regex:           '.\*'<br>
      Priority:        1<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Tue, Oct 6, 2015 at 7:54 AM, Daniel Jasper via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: djasper<br>
> Date: Tue Oct  6 06:54:18 2015<br>
> New Revision: 249392<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=249392&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=249392&view=rev</a><br>
> Log:<br>
> clang-format: Make IncludeCategories configurable in .clang-format file.<br>
><br>
> This was made much easier by introducing an IncludeCategory struct to<br>
> replace the previously used std::pair.<br>
><br>
> Also, cleaned up documentation and added examples.<br>
><br>
> Modified:<br>
>     cfe/trunk/docs/ClangFormatStyleOptions.rst<br>
>     cfe/trunk/docs/tools/dump_format_style.py<br>
>     cfe/trunk/include/clang/Format/Format.h<br>
>     cfe/trunk/lib/Format/Format.cpp<br>
>     cfe/trunk/unittests/Format/FormatTest.cpp<br>
><br>
> Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=249392&r1=249391&r2=249392&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=249392&r1=249391&r2=249392&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)<br>
> +++ cfe/trunk/docs/ClangFormatStyleOptions.rst Tue Oct  6 06:54:18 2015<br>
> @@ -155,21 +155,29 @@ the configuration (without a prefix: ``A<br>
><br>
>    This applies to round brackets (parentheses), angle brackets and square<br>
>    brackets. This will result in formattings like<br>
> -  \code<br>
> -  someLongFunction(argument1,<br>
> -  argument2);<br>
> -  \endcode<br>
> +  .. code-block:: c++<br>
> +    someLongFunction(argument1,<br>
> +                     argument2);<br>
><br>
>  **AlignConsecutiveAssignments** (``bool``)<br>
>    If ``true``, aligns consecutive assignments.<br>
><br>
>    This will align the assignment operators of consecutive lines. This<br>
>    will result in formattings like<br>
> -  \code<br>
> -  int aaaa = 12;<br>
> -  int b    = 23;<br>
> -  int ccc  = 23;<br>
> -  \endcode<br>
> +  .. code-block:: c++<br>
> +    int aaaa = 12;<br>
> +    int b    = 23;<br>
> +    int ccc  = 23;<br>
> +<br>
> +**AlignConsecutiveDeclarations** (``bool``)<br>
> +  If ``true``, aligns consecutive declarations.<br>
> +<br>
> +  This will align the declaration names of consecutive lines. This<br>
> +  will result in formattings like<br>
> +  .. code-block:: c++<br>
> +    int         aaaa = 12;<br>
> +    float       b = 23;<br>
> +    std::string ccc = 23;<br>
><br>
>  **AlignEscapedNewlinesLeft** (``bool``)<br>
>    If ``true``, aligns escaped newlines as far left as possible.<br>
> @@ -381,14 +389,17 @@ the configuration (without a prefix: ``A<br>
>    instead of as function calls.<br>
><br>
>    These are expected to be macros of the form:<br>
> -  \code<br>
> -  FOREACH(<variable-declaration>, ...)<br>
> -  <loop-body><br>
> -  \endcode<br>
> +  .. code-block:: c++<br>
> +    FOREACH(<variable-declaration>, ...)<br>
> +      <loop-body><br>
> +<br>
> +  In the .clang-format configuration file, this can be configured like:<br>
> +  .. code-block:: c++<br>
> +    ForEachMacros: ['RANGES_FOR', 'FOREACH']<br>
><br>
>    For example: BOOST_FOREACH.<br>
><br>
> -**IncludeCategories** (``std::vector<std::pair<std::string, unsigned>>``)<br>
> +**IncludeCategories** (``std::vector<IncludeCategory>``)<br>
>    Regular expressions denoting the different #include categories used<br>
>    for ordering #includes.<br>
><br>
> @@ -403,6 +414,16 @@ the configuration (without a prefix: ``A<br>
>    so that it is kept at the beginning of the #includes<br>
>    (<a href="http://llvm.org/docs/CodingStandards.html#include-style" rel="noreferrer" target="_blank">http://llvm.org/docs/CodingStandards.html#include-style</a>).<br>
><br>
> +  To configure this in the .clang-format file, use:<br>
> +  .. code-block:: c++<br>
> +    IncludeCategories:<br>
> +      - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'<br>
> +        Priority:        2<br>
> +      - Regex:           '^(<|"(gtest|isl|json)/)'<br>
> +        Priority:        3<br>
> +      - Regex:           '.\*'<br>
> +        Priority:        1<br>
> +<br>
>  **IndentCaseLabels** (``bool``)<br>
>    Indent case labels one level from the switch statement.<br>
><br>
><br>
> Modified: cfe/trunk/docs/tools/dump_format_style.py<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/tools/dump_format_style.py?rev=249392&r1=249391&r2=249392&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/tools/dump_format_style.py?rev=249392&r1=249391&r2=249392&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/docs/tools/dump_format_style.py (original)<br>
> +++ cfe/trunk/docs/tools/dump_format_style.py Tue Oct  6 06:54:18 2015<br>
> @@ -86,7 +86,11 @@ class EnumValue:<br>
>          doxygen2rst(indent(self.comment, 2)))<br>
><br>
>  def clean_comment_line(line):<br>
> -  return line[3:].strip() + '\n'<br>
> +  if line == '/// \\code':<br>
> +    return '.. code-block:: c++\n'<br>
> +  if line == '/// \\endcode':<br>
> +    return ''<br>
> +  return line[4:] + '\n'<br>
><br>
>  def read_options(header):<br>
>    class State:<br>
> @@ -139,8 +143,6 @@ def read_options(header):<br>
>        elif line == '};':<br>
>          state = State.InStruct<br>
>          nested_structs[<a href="http://nested_struct.name" rel="noreferrer" target="_blank">nested_struct.name</a>] = nested_struct<br>
> -      else:<br>
> -        raise Exception('Invalid format, expected struct field comment or };')<br>
>      elif state == State.InNestedFieldComent:<br>
>        if line.startswith('///'):<br>
>          comment += clean_comment_line(line)<br>
> @@ -168,7 +170,7 @@ def read_options(header):<br>
>    for option in options:<br>
>      if not option.type in ['bool', 'unsigned', 'int', 'std::string',<br>
>                             'std::vector<std::string>',<br>
> -                           'std::vector<std::pair<std::string, unsigned>>']:<br>
> +                           'std::vector<IncludeCategory>']:<br>
>        if enums.has_key(option.type):<br>
>          option.enum = enums[option.type]<br>
>        elif nested_structs.has_key(option.type):<br>
><br>
> Modified: cfe/trunk/include/clang/Format/Format.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=249392&r1=249391&r2=249392&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=249392&r1=249391&r2=249392&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Format/Format.h (original)<br>
> +++ cfe/trunk/include/clang/Format/Format.h Tue Oct  6 06:54:18 2015<br>
> @@ -48,8 +48,8 @@ struct FormatStyle {<br>
>    /// This applies to round brackets (parentheses), angle brackets and square<br>
>    /// brackets. This will result in formattings like<br>
>    /// \code<br>
> -  /// someLongFunction(argument1,<br>
> -  ///                  argument2);<br>
> +  ///   someLongFunction(argument1,<br>
> +  ///                    argument2);<br>
>    /// \endcode<br>
>    bool AlignAfterOpenBracket;<br>
><br>
> @@ -58,9 +58,9 @@ struct FormatStyle {<br>
>    /// This will align the assignment operators of consecutive lines. This<br>
>    /// will result in formattings like<br>
>    /// \code<br>
> -  /// int aaaa = 12;<br>
> -  /// int b    = 23;<br>
> -  /// int ccc  = 23;<br>
> +  ///   int aaaa = 12;<br>
> +  ///   int b    = 23;<br>
> +  ///   int ccc  = 23;<br>
>    /// \endcode<br>
>    bool AlignConsecutiveAssignments;<br>
><br>
> @@ -69,9 +69,9 @@ struct FormatStyle {<br>
>    /// This will align the declaration names of consecutive lines. This<br>
>    /// will result in formattings like<br>
>    /// \code<br>
> -  /// int         aaaa = 12;<br>
> -  /// float       b = 23;<br>
> -  /// std::string ccc = 23;<br>
> +  ///   int         aaaa = 12;<br>
> +  ///   float       b = 23;<br>
> +  ///   std::string ccc = 23;<br>
>    /// \endcode<br>
>    bool AlignConsecutiveDeclarations;<br>
><br>
> @@ -297,13 +297,29 @@ struct FormatStyle {<br>
>    ///<br>
>    /// These are expected to be macros of the form:<br>
>    /// \code<br>
> -  /// FOREACH(<variable-declaration>, ...)<br>
> -  ///   <loop-body><br>
> +  ///   FOREACH(<variable-declaration>, ...)<br>
> +  ///     <loop-body><br>
> +  /// \endcode<br>
> +  ///<br>
> +  /// In the .clang-format configuration file, this can be configured like:<br>
> +  /// \code<br>
> +  ///   ForEachMacros: ['RANGES_FOR', 'FOREACH']<br>
>    /// \endcode<br>
>    ///<br>
>    /// For example: BOOST_FOREACH.<br>
>    std::vector<std::string> ForEachMacros;<br>
><br>
> +  /// \brief See documentation of \c IncludeCategories.<br>
> +  struct IncludeCategory {<br>
> +    /// \brief The regular expression that this category matches.<br>
> +    std::string Regex;<br>
> +    /// \brief The priority to assign to this category.<br>
> +    unsigned Priority;<br>
> +    bool operator==(const IncludeCategory &Other) const {<br>
> +      return Regex == Other.Regex && Priority == Other.Priority;<br>
> +    }<br>
> +  };<br>
> +<br>
>    /// \brief Regular expressions denoting the different #include categories used<br>
>    /// for ordering #includes.<br>
>    ///<br>
> @@ -317,7 +333,18 @@ struct FormatStyle {<br>
>    /// category. The main header for a source file automatically gets category 0,<br>
>    /// so that it is kept at the beginning of the #includes<br>
>    /// (<a href="http://llvm.org/docs/CodingStandards.html#include-style" rel="noreferrer" target="_blank">http://llvm.org/docs/CodingStandards.html#include-style</a>).<br>
> -  std::vector<std::pair<std::string, unsigned>> IncludeCategories;<br>
> +  ///<br>
> +  /// To configure this in the .clang-format file, use:<br>
> +  /// \code<br>
> +  ///   IncludeCategories:<br>
> +  ///     - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'<br>
> +  ///       Priority:        2<br>
> +  ///     - Regex:           '^(<|"(gtest|isl|json)/)'<br>
> +  ///       Priority:        3<br>
> +  ///     - Regex:           '.*'<br>
> +  ///       Priority:        1<br>
> +  /// \endcode<br>
> +  std::vector<IncludeCategory> IncludeCategories;<br>
><br>
>    /// \brief Indent case labels one level from the switch statement.<br>
>    ///<br>
> @@ -546,6 +573,7 @@ struct FormatStyle {<br>
>             ExperimentalAutoDetectBinPacking ==<br>
>                 R.ExperimentalAutoDetectBinPacking &&<br>
>             ForEachMacros == R.ForEachMacros &&<br>
> +           IncludeCategories == R.IncludeCategories &&<br>
>             IndentCaseLabels == R.IndentCaseLabels &&<br>
>             IndentWidth == R.IndentWidth && Language == R.Language &&<br>
>             IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&<br>
><br>
> Modified: cfe/trunk/lib/Format/Format.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=249392&r1=249391&r2=249392&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=249392&r1=249391&r2=249392&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Format/Format.cpp (original)<br>
> +++ cfe/trunk/lib/Format/Format.cpp Tue Oct  6 06:54:18 2015<br>
> @@ -37,6 +37,7 @@<br>
>  using clang::format::FormatStyle;<br>
><br>
>  LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(std::string)<br>
> +LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)<br>
><br>
>  namespace llvm {<br>
>  namespace yaml {<br>
> @@ -247,6 +248,7 @@ template <> struct MappingTraits<FormatS<br>
>      IO.mapOptional("ExperimentalAutoDetectBinPacking",<br>
>                     Style.ExperimentalAutoDetectBinPacking);<br>
>      IO.mapOptional("ForEachMacros", Style.ForEachMacros);<br>
> +    IO.mapOptional("IncludeCategories", Style.IncludeCategories);<br>
>      IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);<br>
>      IO.mapOptional("IndentWidth", Style.IndentWidth);<br>
>      IO.mapOptional("IndentWrappedFunctionNames",<br>
> @@ -307,6 +309,13 @@ template <> struct MappingTraits<FormatS<br>
>    }<br>
>  };<br>
><br>
> +template <> struct MappingTraits<FormatStyle::IncludeCategory> {<br>
> +  static void mapping(IO &IO, FormatStyle::IncludeCategory &Category) {<br>
> +    IO.mapOptional("Regex", Category.Regex);<br>
> +    IO.mapOptional("Priority", Category.Priority);<br>
> +  }<br>
> +};<br>
> +<br>
>  // Allows to read vector<FormatStyle> while keeping default values.<br>
>  // IO.getContext() should contain a pointer to the FormatStyle structure, that<br>
>  // will be used to get default values for missing keys.<br>
> @@ -1737,8 +1746,8 @@ tooling::Replacements sortIncludes(const<br>
><br>
>    // Create pre-compiled regular expressions for the #include categories.<br>
>    SmallVector<llvm::Regex, 4> CategoryRegexs;<br>
> -  for (const auto &IncludeBlock : Style.IncludeCategories)<br>
> -    CategoryRegexs.emplace_back(IncludeBlock.first);<br>
> +  for (const auto &Category : Style.IncludeCategories)<br>
> +    CategoryRegexs.emplace_back(Category.Regex);<br>
><br>
>    for (;;) {<br>
>      auto Pos = Code.find('\n', SearchFrom);<br>
> @@ -1753,7 +1762,7 @@ tooling::Replacements sortIncludes(const<br>
>            Category = UINT_MAX;<br>
>            for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i) {<br>
>              if (CategoryRegexs[i].match(Matches[1])) {<br>
> -              Category = Style.IncludeCategories[i].second;<br>
> +              Category = Style.IncludeCategories[i].Priority;<br>
>                break;<br>
>              }<br>
>            }<br>
><br>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=249392&r1=249391&r2=249392&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=249392&r1=249391&r2=249392&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Oct  6 06:54:18 2015<br>
> @@ -9646,6 +9646,8 @@ TEST_F(FormatTest, ParsesConfiguration)<br>
>    CHECK_PARSE("NamespaceIndentation: All", NamespaceIndentation,<br>
>                FormatStyle::NI_All);<br>
><br>
> +  // FIXME: This is required because parsing a configuration simply overwrites<br>
> +  // the first N elements of the list instead of resetting it.<br>
>    Style.ForEachMacros.clear();<br>
>    std::vector<std::string> BoostForeach;<br>
>    BoostForeach.push_back("BOOST_FOREACH");<br>
> @@ -9655,6 +9657,16 @@ TEST_F(FormatTest, ParsesConfiguration)<br>
>    BoostAndQForeach.push_back("Q_FOREACH");<br>
>    CHECK_PARSE("ForEachMacros: [BOOST_FOREACH, Q_FOREACH]", ForEachMacros,<br>
>                BoostAndQForeach);<br>
> +<br>
> +  Style.IncludeCategories.clear();<br>
> +  std::vector<FormatStyle::IncludeCategory> ExpectedCategories = {{"abc/.*", 2},<br>
> +                                                                  {".*", 1}};<br>
> +  CHECK_PARSE("IncludeCategories:\n"<br>
> +              "  - Regex: abc/.*\n"<br>
> +              "    Priority: 2\n"<br>
> +              "  - Regex: .*\n"<br>
> +              "    Priority: 1",<br>
> +              IncludeCategories, ExpectedCategories);<br>
>  }<br>
><br>
>  TEST_F(FormatTest, ParsesConfigurationWithLanguages) {<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>