<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><blockquote type="cite" class="">On May 18, 2018, at 11:48 AM, Eric Liu <<a href="mailto:ioeric@google.com" class="">ioeric@google.com</a>> wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">So I have reverted this with r<span style="color:rgb(33,33,33)" class="">332751</span><span style="color:rgb(33,33,33)" class="">.</span></div></div></blockquote><div><br class=""></div>Thanks!</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><font color="#212121" class="">I can't see how this introduced cyclic dependencies in module build, as the dependencies should be clangTooling -> clangFormat -> clangToolingInclusions. I'm wondering if there is any module configurations that I need to update to make this work. Right now, module doesn't seem to make any difference between </font><span style="color:rgb(33,33,33)" class="">clangTooling and </span><span style="color:rgb(33,33,33)" class="">clangToolingInclusions... I'd appreciate it if someone who knows how clang module build is set up could help take a look.</span></div></div></div></blockquote><div><br class=""></div><div>+ Bruno & David who have more experience in this area than I do.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><span style="color:rgb(33,33,33)" class="">Unfortunately, I couldn't reproduce this on my workstation as the module build seemed to be broken due to other errors.</span></div></div></div></blockquote><div><br class=""></div><div>The build is dependent on having a set of modularized system headers -- perhaps that's the issue.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><span style="color:rgb(33,33,33)" class=""> I was seeing a lot of warnings; the clang I used to build llvm was built near HEAD. Maybe my clang is too new?</span></div></div></div></blockquote><div><br class=""></div><div>This sounds a bit suspicious. Can new clang diagnostics land without clean stage2 builds? If so, we can look into enabling -Werror on our stage2 bots to catch this sort of thing earlier.</div><div><br class=""></div><div>vedant</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><span style="color:rgb(33,33,33)" class=""><br class=""></span></div><div class=""><span style="color:rgb(33,33,33)" class="">Thanks,</span></div><div class=""><span style="color:rgb(33,33,33)" class="">Eric</span></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, May 18, 2018 at 7:52 PM Eric Liu <<a href="mailto:ioeric@google.com" class="">ioeric@google.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sorry, I'll look into it right now. Will revert it if I can't find a quick fix.<br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, May 18, 2018, 19:49 Amara Emerson <<a href="mailto:aemerson@apple.com" target="_blank" class="">aemerson@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class="">Hi Eric,<div class=""><br class=""></div><div class="">Green dragon buildbots have started failing too, e.g.: <a href="http://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/10222/" target="_blank" class="">http://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/10222/</a></div><div class=""><br class=""></div><div class="">If you don’t have a quick fix can you please revert it.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Amara</div></div><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On May 18, 2018, at 7:46 PM, Eric Liu <<a href="mailto:ioeric@google.com" target="_blank" class="">ioeric@google.com</a>> wrote:</div><br class="m_-7212396939221590578m_7248784633998890000Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Vedant,<div class=""><br class=""></div><div class="">It seems that your build was not using cmake files in the source tree? lib<span style="color:rgb(33,33,33)" class="">/Tooling/Inclusions/ is a (new) standalone library (clangToolingInclusions, similar to clangToolingCore). You might need update your build to reflect this change. Let me know if you have any further question.</span></div><div class=""><span style="color:rgb(33,33,33)" class=""><br class=""></span></div><div class=""><font color="#212121" class="">Thanks,</font></div><div class=""><font color="#212121" class="">Eric</font></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, May 18, 2018 at 6:41 PM Vedant Kumar <<a href="mailto:vsk@apple.com" target="_blank" class="">vsk@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Eric,<br class="">
<br class="">
I think there might be a cyclic dependency issue here, possibly one that's only visible with LLVM_ENABLE_MODULES=On. I see:<br class="">
<br class="">
While building module 'Clang_Tooling' imported from /Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10:                             <br class="">
While building module 'Clang_Format' imported from /Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/include/clang/Tooling/Refactoring/AtomicChange.h:19:       <br class="">
In file included from <module-includes>:1:                                                                                                                   <br class="">
/Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/include/clang/Format/Format.h:20:10: fatal error: cyclic dependency in module 'Clang_Tooling': Clang_Tooling $> Clang_Format -> Clang_Tooling                                                                                                    <br class="">
#include "clang/Tooling/Inclusions/IncludeStyle.h"<br class="">
         ^                          <br class="">
While building module 'Clang_Tooling' imported from /Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10:<br class="">
In file included from <module-includes>:22:                                                          <br class="">
In file included from /Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringAction.h:14:<br class="">
In file included from /Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringActionRules.h:14:<br class="">
In file included from /Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringActionRulesInternal.h:16:<br class="">
In file included from /Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/include/clang/Tooling/Refactoring/RefactoringResultConsumer.h:14:<br class="">
/Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/include/clang/Tooling/Refactoring/AtomicChange.h:19:10: fatal error: could not build module 'Clang_Format'<br class="">
#include "clang/Format/Format.h"<br class="">
 ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~<br class="">
/Users/vsk/src/<a href="http://llvm.org/" target="_blank" class="">llvm.org</a>-master/llvm/tools/clang/lib/Tooling/Execution.cpp:10:10: fatal error: could not build module 'Clang_Tooling'<br class="">
#include "clang/Tooling/Execution.h"                                            <br class="">
 ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~                            <br class="">
3 errors generated.<br class="">
<br class="">
Could you take a look?<br class="">
<br class="">
thanks,<br class="">
vedant<br class="">
<br class="">
> On May 18, 2018, at 7:16 AM, Eric Liu via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank" class="">cfe-commits@lists.llvm.org</a>> wrote:<br class="">
> <br class="">
> Author: ioeric<br class="">
> Date: Fri May 18 07:16:37 2018<br class="">
> New Revision: 332720<br class="">
> <br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=332720&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=332720&view=rev</a><br class="">
> Log:<br class="">
> Move #include manipulation code to new lib/Tooling/Inclusions.<br class="">
> <br class="">
> Summary:<br class="">
> clangToolingCore is linked into almost everything (incl. clang), but<br class="">
> not few tools need #include manipulation at this point. So pull this into a<br class="">
> separate library in Tooling.<br class="">
> <br class="">
> Reviewers: ilya-biryukov<br class="">
> <br class="">
> Subscribers: klimek, mgorny, cfe-commits, thakis<br class="">
> <br class="">
> Differential Revision: <a href="https://reviews.llvm.org/D47068" rel="noreferrer" target="_blank" class="">https://reviews.llvm.org/D47068</a><br class="">
> <br class="">
> Added:<br class="">
>    cfe/trunk/include/clang/Tooling/Inclusions/<br class="">
>    cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h<br class="">
>      - copied, changed from r332717, cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h<br class="">
>    cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h<br class="">
>      - copied, changed from r332717, cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h<br class="">
>    cfe/trunk/lib/Tooling/Inclusions/<br class="">
>    cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt<br class="">
>      - copied, changed from r332717, cfe/trunk/lib/Tooling/Core/CMakeLists.txt<br class="">
>    cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp<br class="">
>      - copied, changed from r332717, cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp<br class="">
>    cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp<br class="">
>      - copied, changed from r332717, cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp<br class="">
> Removed:<br class="">
>    cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h<br class="">
>    cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h<br class="">
>    cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp<br class="">
>    cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp<br class="">
> Modified:<br class="">
>    cfe/trunk/include/clang/Format/Format.h<br class="">
>    cfe/trunk/lib/Format/CMakeLists.txt<br class="">
>    cfe/trunk/lib/Format/Format.cpp<br class="">
>    cfe/trunk/lib/Tooling/CMakeLists.txt<br class="">
>    cfe/trunk/lib/Tooling/Core/CMakeLists.txt<br class="">
>    cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp<br class="">
> <br class="">
> Modified: cfe/trunk/include/clang/Format/Format.h<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332720&r1=332719&r2=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=332720&r1=332719&r2=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/include/clang/Format/Format.h (original)<br class="">
> +++ cfe/trunk/include/clang/Format/Format.h Fri May 18 07:16:37 2018<br class="">
> @@ -16,8 +16,8 @@<br class="">
> #define LLVM_CLANG_FORMAT_FORMAT_H<br class="">
> <br class="">
> #include "clang/Basic/LangOptions.h"<br class="">
> -#include "clang/Tooling/Core/IncludeStyle.h"<br class="">
> #include "clang/Tooling/Core/Replacement.h"<br class="">
> +#include "clang/Tooling/Inclusions/IncludeStyle.h"<br class="">
> #include "llvm/ADT/ArrayRef.h"<br class="">
> #include "llvm/Support/Regex.h"<br class="">
> #include <system_error><br class="">
> <br class="">
> Removed: cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h?rev=332719&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h?rev=332719&view=auto</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h (original)<br class="">
> +++ cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h (removed)<br class="">
> @@ -1,137 +0,0 @@<br class="">
> -//===--- HeaderIncludes.h - Insert/Delete #includes for C++ code--*- C++-*-===//<br class="">
> -//<br class="">
> -//                     The LLVM Compiler Infrastructure<br class="">
> -//<br class="">
> -// This file is distributed under the University of Illinois Open Source<br class="">
> -// License. See LICENSE.TXT for details.<br class="">
> -//<br class="">
> -//===----------------------------------------------------------------------===//<br class="">
> -<br class="">
> -#ifndef LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H<br class="">
> -#define LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H<br class="">
> -<br class="">
> -#include "clang/Basic/SourceManager.h"<br class="">
> -#include "clang/Tooling/Core/Replacement.h"<br class="">
> -#include "clang/Tooling/Core/IncludeStyle.h"<br class="">
> -#include "llvm/Support/Path.h"<br class="">
> -#include "llvm/Support/Regex.h"<br class="">
> -#include <unordered_map><br class="">
> -<br class="">
> -namespace clang {<br class="">
> -namespace tooling {<br class="">
> -<br class="">
> -/// This class manages priorities of C++ #include categories and calculates<br class="">
> -/// priorities for headers.<br class="">
> -/// FIXME(ioeric): move this class into implementation file when clang-format's<br class="">
> -/// include sorting functions are also moved here.<br class="">
> -class IncludeCategoryManager {<br class="">
> -public:<br class="">
> -  IncludeCategoryManager(const IncludeStyle &Style, StringRef FileName);<br class="">
> -<br class="">
> -  /// Returns the priority of the category which \p IncludeName belongs to.<br class="">
> -  /// If \p CheckMainHeader is true and \p IncludeName is a main header, returns<br class="">
> -  /// 0. Otherwise, returns the priority of the matching category or INT_MAX.<br class="">
> -  /// NOTE: this API is not thread-safe!<br class="">
> -  int getIncludePriority(StringRef IncludeName, bool CheckMainHeader) const;<br class="">
> -<br class="">
> -private:<br class="">
> -  bool isMainHeader(StringRef IncludeName) const;<br class="">
> -<br class="">
> -  const IncludeStyle Style;<br class="">
> -  bool IsMainFile;<br class="">
> -  std::string FileName;<br class="">
> -  // This refers to a substring in FileName.<br class="">
> -  StringRef FileStem;<br class="">
> -  // Regex is not thread-safe.<br class="">
> -  mutable SmallVector<llvm::Regex, 4> CategoryRegexs;<br class="">
> -};<br class="">
> -<br class="">
> -/// Generates replacements for inserting or deleting #include directives in a<br class="">
> -/// file.<br class="">
> -class HeaderIncludes {<br class="">
> -public:<br class="">
> -  HeaderIncludes(llvm::StringRef FileName, llvm::StringRef Code,<br class="">
> -                 const IncludeStyle &Style);<br class="">
> -<br class="">
> -  /// Inserts an #include directive of \p Header into the code. If \p IsAngled<br class="">
> -  /// is true, \p Header will be quoted with <> in the directive; otherwise, it<br class="">
> -  /// will be quoted with "".<br class="">
> -  ///<br class="">
> -  /// When searching for points to insert new header, this ignores #include's<br class="">
> -  /// after the #include block(s) in the beginning of a file to avoid inserting<br class="">
> -  /// headers into code sections where new #include's should not be added by<br class="">
> -  /// default. These code sections include:<br class="">
> -  ///   - raw string literals (containing #include).<br class="">
> -  ///   - #if blocks.<br class="">
> -  ///   - Special #include's among declarations (e.g. functions).<br class="">
> -  ///<br class="">
> -  /// Returns a replacement that inserts the new header into a suitable #include<br class="">
> -  /// block of the same category. This respects the order of the existing<br class="">
> -  /// #includes in the block; if the existing #includes are not already sorted,<br class="">
> -  /// this will simply insert the #include in front of the first #include of the<br class="">
> -  /// same category in the code that should be sorted after \p IncludeName. If<br class="">
> -  /// \p IncludeName already exists (with exactly the same spelling), this<br class="">
> -  /// returns None.<br class="">
> -  llvm::Optional<tooling::Replacement> insert(llvm::StringRef Header,<br class="">
> -                                              bool IsAngled) const;<br class="">
> -<br class="">
> -  /// Removes all existing #includes of \p Header quoted with <> if \p IsAngled<br class="">
> -  /// is true or "" if \p IsAngled is false.<br class="">
> -  /// This doesn't resolve the header file path; it only deletes #includes with<br class="">
> -  /// exactly the same spelling.<br class="">
> -  tooling::Replacements remove(llvm::StringRef Header, bool IsAngled) const;<br class="">
> -<br class="">
> -private:<br class="">
> -  struct Include {<br class="">
> -    Include(StringRef Name, tooling::Range R) : Name(Name), R(R) {}<br class="">
> -<br class="">
> -    // An include header quoted with either <> or "".<br class="">
> -    std::string Name;<br class="">
> -    // The range of the whole line of include directive including any eading<br class="">
> -    // whitespaces and trailing comment.<br class="">
> -    tooling::Range R;<br class="">
> -  };<br class="">
> -<br class="">
> -  void addExistingInclude(Include IncludeToAdd, unsigned NextLineOffset);<br class="">
> -<br class="">
> -  std::string FileName;<br class="">
> -  std::string Code;<br class="">
> -<br class="">
> -  // Map from include name (quotation trimmed) to a list of existing includes<br class="">
> -  // (in case there are more than one) with the name in the current file. <x><br class="">
> -  // and "x" will be treated as the same header when deleting #includes.<br class="">
> -  llvm::StringMap<llvm::SmallVector<Include, 1>> ExistingIncludes;<br class="">
> -<br class="">
> -  /// Map from priorities of #include categories to all #includes in the same<br class="">
> -  /// category. This is used to find #includes of the same category when<br class="">
> -  /// inserting new #includes. #includes in the same categories are sorted in<br class="">
> -  /// in the order they appear in the source file.<br class="">
> -  /// See comment for "FormatStyle::IncludeCategories" for details about include<br class="">
> -  /// priorities.<br class="">
> -  std::unordered_map<int, llvm::SmallVector<const Include *, 8>><br class="">
> -      IncludesByPriority;<br class="">
> -<br class="">
> -  int FirstIncludeOffset;<br class="">
> -  // All new headers should be inserted after this offset (e.g. after header<br class="">
> -  // guards, file comment).<br class="">
> -  unsigned MinInsertOffset;<br class="">
> -  // Max insertion offset in the original code. For example, we want to avoid<br class="">
> -  // inserting new #includes into the actual code section (e.g. after a<br class="">
> -  // declaration).<br class="">
> -  unsigned MaxInsertOffset;<br class="">
> -  IncludeCategoryManager Categories;<br class="">
> -  // Record the offset of the end of the last include in each category.<br class="">
> -  std::unordered_map<int, int> CategoryEndOffsets;<br class="">
> -<br class="">
> -  // All possible priorities.<br class="">
> -  std::set<int> Priorities;<br class="">
> -<br class="">
> -  // Matches a whole #include directive.<br class="">
> -  llvm::Regex IncludeRegex;<br class="">
> -};<br class="">
> -<br class="">
> -<br class="">
> -} // namespace tooling<br class="">
> -} // namespace clang<br class="">
> -<br class="">
> -#endif // LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H<br class="">
> <br class="">
> Removed: cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h?rev=332719&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h?rev=332719&view=auto</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h (original)<br class="">
> +++ cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h (removed)<br class="">
> @@ -1,133 +0,0 @@<br class="">
> -//===--- IncludeStyle.h - Style of C++ #include directives -------*- C++-*-===//<br class="">
> -//<br class="">
> -//                     The LLVM Compiler Infrastructure<br class="">
> -//<br class="">
> -// This file is distributed under the University of Illinois Open Source<br class="">
> -// License. See LICENSE.TXT for details.<br class="">
> -//<br class="">
> -//===----------------------------------------------------------------------===//<br class="">
> -<br class="">
> -#ifndef LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H<br class="">
> -#define LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H<br class="">
> -<br class="">
> -#include "llvm/Support/YAMLTraits.h"<br class="">
> -#include <string><br class="">
> -#include <vector><br class="">
> -<br class="">
> -namespace clang {<br class="">
> -namespace tooling {<br class="">
> -<br class="">
> -/// Style for sorting and grouping C++ #include directives.<br class="">
> -struct IncludeStyle {<br class="">
> -  /// Styles for sorting multiple ``#include`` blocks.<br class="">
> -  enum IncludeBlocksStyle {<br class="">
> -    /// Sort each ``#include`` block separately.<br class="">
> -    /// \code<br class="">
> -    ///    #include "b.h"               into      #include "b.h"<br class="">
> -    ///<br class="">
> -    ///    #include <lib/main.h>                  #include "a.h"<br class="">
> -    ///    #include "a.h"                         #include <lib/main.h><br class="">
> -    /// \endcode<br class="">
> -    IBS_Preserve,<br class="">
> -    /// Merge multiple ``#include`` blocks together and sort as one.<br class="">
> -    /// \code<br class="">
> -    ///    #include "b.h"               into      #include "a.h"<br class="">
> -    ///                                           #include "b.h"<br class="">
> -    ///    #include <lib/main.h>                  #include <lib/main.h><br class="">
> -    ///    #include "a.h"<br class="">
> -    /// \endcode<br class="">
> -    IBS_Merge,<br class="">
> -    /// Merge multiple ``#include`` blocks together and sort as one.<br class="">
> -    /// Then split into groups based on category priority. See<br class="">
> -    /// ``IncludeCategories``.<br class="">
> -    /// \code<br class="">
> -    ///    #include "b.h"               into      #include "a.h"<br class="">
> -    ///                                           #include "b.h"<br class="">
> -    ///    #include <lib/main.h><br class="">
> -    ///    #include "a.h"                         #include <lib/main.h><br class="">
> -    /// \endcode<br class="">
> -    IBS_Regroup,<br class="">
> -  };<br class="">
> -<br class="">
> -  /// Dependent on the value, multiple ``#include`` blocks can be sorted<br class="">
> -  /// as one and divided based on category.<br class="">
> -  IncludeBlocksStyle IncludeBlocks;<br class="">
> -<br class="">
> -  /// See documentation of ``IncludeCategories``.<br class="">
> -  struct IncludeCategory {<br class="">
> -    /// The regular expression that this category matches.<br class="">
> -    std::string Regex;<br class="">
> -    /// The priority to assign to this category.<br class="">
> -    int Priority;<br class="">
> -    bool operator==(const IncludeCategory &Other) const {<br class="">
> -      return Regex == Other.Regex && Priority == Other.Priority;<br class="">
> -    }<br class="">
> -  };<br class="">
> -<br class="">
> -  /// Regular expressions denoting the different ``#include`` categories<br class="">
> -  /// used for ordering ``#includes``.<br class="">
> -  ///<br class="">
> -  /// These regular expressions are matched against the filename of an include<br class="">
> -  /// (including the <> or "") in order. The value belonging to the first<br class="">
> -  /// matching regular expression is assigned and ``#includes`` are sorted first<br class="">
> -  /// according to increasing category number and then alphabetically within<br class="">
> -  /// each category.<br class="">
> -  ///<br class="">
> -  /// If none of the regular expressions match, INT_MAX is assigned as<br class="">
> -  /// category. The main header for a source file automatically gets category 0.<br class="">
> -  /// so that it is generally kept at the beginning of the ``#includes``<br class="">
> -  /// (<a href="http://llvm.org/docs/CodingStandards.html#include-style" rel="noreferrer" target="_blank" class="">http://llvm.org/docs/CodingStandards.html#include-style</a>). However, you<br class="">
> -  /// can also assign negative priorities if you have certain headers that<br class="">
> -  /// always need to be first.<br class="">
> -  ///<br class="">
> -  /// To configure this in the .clang-format file, use:<br class="">
> -  /// \code{.yaml}<br class="">
> -  ///   IncludeCategories:<br class="">
> -  ///     - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'<br class="">
> -  ///       Priority:        2<br class="">
> -  ///     - Regex:           '^(<|"(gtest|gmock|isl|json)/)'<br class="">
> -  ///       Priority:        3<br class="">
> -  ///     - Regex:           '.*'<br class="">
> -  ///       Priority:        1<br class="">
> -  /// \endcode<br class="">
> -  std::vector<IncludeCategory> IncludeCategories;<br class="">
> -<br class="">
> -  /// Specify a regular expression of suffixes that are allowed in the<br class="">
> -  /// file-to-main-include mapping.<br class="">
> -  ///<br class="">
> -  /// When guessing whether a #include is the "main" include (to assign<br class="">
> -  /// category 0, see above), use this regex of allowed suffixes to the header<br class="">
> -  /// stem. A partial match is done, so that:<br class="">
> -  /// - "" means "arbitrary suffix"<br class="">
> -  /// - "$" means "no suffix"<br class="">
> -  ///<br class="">
> -  /// For example, if configured to "(_test)?$", then a header a.h would be seen<br class="">
> -  /// as the "main" include in both <a href="http://a.cc/" target="_blank" class="">a.cc</a> and <a href="http://a_test.cc/" target="_blank" class="">a_test.cc</a>.<br class="">
> -  std::string IncludeIsMainRegex;<br class="">
> -};<br class="">
> -<br class="">
> -} // namespace tooling<br class="">
> -} // namespace clang<br class="">
> -<br class="">
> -LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::IncludeStyle::IncludeCategory)<br class="">
> -<br class="">
> -namespace llvm {<br class="">
> -namespace yaml {<br class="">
> -<br class="">
> -template <><br class="">
> -struct MappingTraits<clang::tooling::IncludeStyle::IncludeCategory> {<br class="">
> -  static void mapping(IO &IO,<br class="">
> -                      clang::tooling::IncludeStyle::IncludeCategory &Category);<br class="">
> -};<br class="">
> -<br class="">
> -template <><br class="">
> -struct ScalarEnumerationTraits<<br class="">
> -    clang::tooling::IncludeStyle::IncludeBlocksStyle> {<br class="">
> -  static void<br class="">
> -  enumeration(IO &IO, clang::tooling::IncludeStyle::IncludeBlocksStyle &Value);<br class="">
> -};<br class="">
> -<br class="">
> -} // namespace yaml<br class="">
> -} // namespace llvm<br class="">
> -<br class="">
> -#endif // LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H<br class="">
> <br class="">
> Copied: cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h (from r332717, cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h)<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h?p2=cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h&p1=cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h&r1=332717&r2=332720&rev=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h?p2=cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h&p1=cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h&r1=332717&r2=332720&rev=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/include/clang/Tooling/Core/HeaderIncludes.h (original)<br class="">
> +++ cfe/trunk/include/clang/Tooling/Inclusions/HeaderIncludes.h Fri May 18 07:16:37 2018<br class="">
> @@ -7,12 +7,12 @@<br class="">
> //<br class="">
> //===----------------------------------------------------------------------===//<br class="">
> <br class="">
> -#ifndef LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H<br class="">
> -#define LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H<br class="">
> +#ifndef LLVM_CLANG_TOOLING_INCLUSIONS_HEADERINCLUDES_H<br class="">
> +#define LLVM_CLANG_TOOLING_INCLUSIONS_HEADERINCLUDES_H<br class="">
> <br class="">
> #include "clang/Basic/SourceManager.h"<br class="">
> #include "clang/Tooling/Core/Replacement.h"<br class="">
> -#include "clang/Tooling/Core/IncludeStyle.h"<br class="">
> +#include "clang/Tooling/Inclusions/IncludeStyle.h"<br class="">
> #include "llvm/Support/Path.h"<br class="">
> #include "llvm/Support/Regex.h"<br class="">
> #include <unordered_map><br class="">
> @@ -134,4 +134,4 @@ private:<br class="">
> } // namespace tooling<br class="">
> } // namespace clang<br class="">
> <br class="">
> -#endif // LLVM_CLANG_TOOLING_CORE_HEADERINCLUDES_H<br class="">
> +#endif // LLVM_CLANG_TOOLING_INCLUSIONS_HEADERINCLUDES_H<br class="">
> <br class="">
> Copied: cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h (from r332717, cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h)<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h?p2=cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h&p1=cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h&r1=332717&r2=332720&rev=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h?p2=cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h&p1=cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h&r1=332717&r2=332720&rev=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/include/clang/Tooling/Core/IncludeStyle.h (original)<br class="">
> +++ cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h Fri May 18 07:16:37 2018<br class="">
> @@ -7,8 +7,8 @@<br class="">
> //<br class="">
> //===----------------------------------------------------------------------===//<br class="">
> <br class="">
> -#ifndef LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H<br class="">
> -#define LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H<br class="">
> +#ifndef LLVM_CLANG_TOOLING_INCLUSIONS_INCLUDESTYLE_H<br class="">
> +#define LLVM_CLANG_TOOLING_INCLUSIONS_INCLUDESTYLE_H<br class="">
> <br class="">
> #include "llvm/Support/YAMLTraits.h"<br class="">
> #include <string><br class="">
> @@ -130,4 +130,4 @@ struct ScalarEnumerationTraits<<br class="">
> } // namespace yaml<br class="">
> } // namespace llvm<br class="">
> <br class="">
> -#endif // LLVM_CLANG_TOOLING_CORE_INCLUDESTYLE_H<br class="">
> +#endif // LLVM_CLANG_TOOLING_INCLUSIONS_INCLUDESTYLE_H<br class="">
> <br class="">
> Modified: cfe/trunk/lib/Format/CMakeLists.txt<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/CMakeLists.txt?rev=332720&r1=332719&r2=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/CMakeLists.txt?rev=332720&r1=332719&r2=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/lib/Format/CMakeLists.txt (original)<br class="">
> +++ cfe/trunk/lib/Format/CMakeLists.txt Fri May 18 07:16:37 2018<br class="">
> @@ -20,4 +20,5 @@ add_clang_library(clangFormat<br class="">
>   clangBasic<br class="">
>   clangLex<br class="">
>   clangToolingCore<br class="">
> +  clangToolingInclusions<br class="">
>   )<br class="">
> <br class="">
> Modified: cfe/trunk/lib/Format/Format.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=332720&r1=332719&r2=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=332720&r1=332719&r2=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/lib/Format/Format.cpp (original)<br class="">
> +++ cfe/trunk/lib/Format/Format.cpp Fri May 18 07:16:37 2018<br class="">
> @@ -31,7 +31,7 @@<br class="">
> #include "clang/Basic/SourceManager.h"<br class="">
> #include "clang/Basic/VirtualFileSystem.h"<br class="">
> #include "clang/Lex/Lexer.h"<br class="">
> -#include "clang/Tooling/Core/HeaderIncludes.h"<br class="">
> +#include "clang/Tooling/Inclusions/HeaderIncludes.h"<br class="">
> #include "llvm/ADT/STLExtras.h"<br class="">
> #include "llvm/ADT/StringRef.h"<br class="">
> #include "llvm/Support/Allocator.h"<br class="">
> <br class="">
> Modified: cfe/trunk/lib/Tooling/CMakeLists.txt<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CMakeLists.txt?rev=332720&r1=332719&r2=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CMakeLists.txt?rev=332720&r1=332719&r2=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/lib/Tooling/CMakeLists.txt (original)<br class="">
> +++ cfe/trunk/lib/Tooling/CMakeLists.txt Fri May 18 07:16:37 2018<br class="">
> @@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS<br class="">
>   )<br class="">
> <br class="">
> add_subdirectory(Core)<br class="">
> +add_subdirectory(Inclusions)<br class="">
> add_subdirectory(Refactoring)<br class="">
> add_subdirectory(ASTDiff)<br class="">
> <br class="">
> <br class="">
> Modified: cfe/trunk/lib/Tooling/Core/CMakeLists.txt<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/CMakeLists.txt?rev=332720&r1=332719&r2=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/CMakeLists.txt?rev=332720&r1=332719&r2=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/lib/Tooling/Core/CMakeLists.txt (original)<br class="">
> +++ cfe/trunk/lib/Tooling/Core/CMakeLists.txt Fri May 18 07:16:37 2018<br class="">
> @@ -2,8 +2,6 @@ set(LLVM_LINK_COMPONENTS support)<br class="">
> <br class="">
> add_clang_library(clangToolingCore<br class="">
>   Diagnostic.cpp<br class="">
> -  HeaderIncludes.cpp<br class="">
> -  IncludeStyle.cpp<br class="">
>   Lookup.cpp<br class="">
>   Replacement.cpp<br class="">
> <br class="">
> <br class="">
> Removed: cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp?rev=332719&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp?rev=332719&view=auto</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp (original)<br class="">
> +++ cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp (removed)<br class="">
> @@ -1,330 +0,0 @@<br class="">
> -//===--- HeaderIncludes.cpp - Insert/Delete #includes --*- C++ -*----------===//<br class="">
> -//<br class="">
> -//                     The LLVM Compiler Infrastructure<br class="">
> -//<br class="">
> -// This file is distributed under the University of Illinois Open Source<br class="">
> -// License. See LICENSE.TXT for details.<br class="">
> -//<br class="">
> -//===----------------------------------------------------------------------===//<br class="">
> -<br class="">
> -#include "clang/Tooling/Core/HeaderIncludes.h"<br class="">
> -#include "clang/Basic/SourceManager.h"<br class="">
> -#include "clang/Lex/Lexer.h"<br class="">
> -<br class="">
> -namespace clang {<br class="">
> -namespace tooling {<br class="">
> -namespace {<br class="">
> -<br class="">
> -LangOptions createLangOpts() {<br class="">
> -  LangOptions LangOpts;<br class="">
> -  LangOpts.CPlusPlus = 1;<br class="">
> -  LangOpts.CPlusPlus11 = 1;<br class="">
> -  LangOpts.CPlusPlus14 = 1;<br class="">
> -  LangOpts.LineComment = 1;<br class="">
> -  LangOpts.CXXOperatorNames = 1;<br class="">
> -  LangOpts.Bool = 1;<br class="">
> -  LangOpts.ObjC1 = 1;<br class="">
> -  LangOpts.ObjC2 = 1;<br class="">
> -  LangOpts.MicrosoftExt = 1;    // To get kw___try, kw___finally.<br class="">
> -  LangOpts.DeclSpecKeyword = 1; // To get __declspec.<br class="">
> -  LangOpts.WChar = 1;           // To get wchar_t<br class="">
> -  return LangOpts;<br class="">
> -}<br class="">
> -<br class="">
> -// Returns the offset after skipping a sequence of tokens, matched by \p<br class="">
> -// GetOffsetAfterSequence, from the start of the code.<br class="">
> -// \p GetOffsetAfterSequence should be a function that matches a sequence of<br class="">
> -// tokens and returns an offset after the sequence.<br class="">
> -unsigned getOffsetAfterTokenSequence(<br class="">
> -    StringRef FileName, StringRef Code, const IncludeStyle &Style,<br class="">
> -    llvm::function_ref<unsigned(const SourceManager &, Lexer &, Token &)><br class="">
> -        GetOffsetAfterSequence) {<br class="">
> -  SourceManagerForFile VirtualSM(FileName, Code);<br class="">
> -  SourceManager &SM = VirtualSM.get();<br class="">
> -  Lexer Lex(SM.getMainFileID(), SM.getBuffer(SM.getMainFileID()), SM,<br class="">
> -            createLangOpts());<br class="">
> -  Token Tok;<br class="">
> -  // Get the first token.<br class="">
> -  Lex.LexFromRawLexer(Tok);<br class="">
> -  return GetOffsetAfterSequence(SM, Lex, Tok);<br class="">
> -}<br class="">
> -<br class="">
> -// Check if a sequence of tokens is like "#<Name> <raw_identifier>". If it is,<br class="">
> -// \p Tok will be the token after this directive; otherwise, it can be any token<br class="">
> -// after the given \p Tok (including \p Tok).<br class="">
> -bool checkAndConsumeDirectiveWithName(Lexer &Lex, StringRef Name, Token &Tok) {<br class="">
> -  bool Matched = <a href="http://tok.is/" target="_blank" class="">Tok.is</a>(tok::hash) && !Lex.LexFromRawLexer(Tok) &&<br class="">
> -                 <a href="http://tok.is/" target="_blank" class="">Tok.is</a>(tok::raw_identifier) &&<br class="">
> -                 Tok.getRawIdentifier() == Name && !Lex.LexFromRawLexer(Tok) &&<br class="">
> -                 <a href="http://tok.is/" target="_blank" class="">Tok.is</a>(tok::raw_identifier);<br class="">
> -  if (Matched)<br class="">
> -    Lex.LexFromRawLexer(Tok);<br class="">
> -  return Matched;<br class="">
> -}<br class="">
> -<br class="">
> -void skipComments(Lexer &Lex, Token &Tok) {<br class="">
> -  while (<a href="http://tok.is/" target="_blank" class="">Tok.is</a>(tok::comment))<br class="">
> -    if (Lex.LexFromRawLexer(Tok))<br class="">
> -      return;<br class="">
> -}<br class="">
> -<br class="">
> -// Returns the offset after header guard directives and any comments<br class="">
> -// before/after header guards. If no header guard presents in the code, this<br class="">
> -// will returns the offset after skipping all comments from the start of the<br class="">
> -// code.<br class="">
> -unsigned getOffsetAfterHeaderGuardsAndComments(StringRef FileName,<br class="">
> -                                               StringRef Code,<br class="">
> -                                               const IncludeStyle &Style) {<br class="">
> -  return getOffsetAfterTokenSequence(<br class="">
> -      FileName, Code, Style,<br class="">
> -      [](const SourceManager &SM, Lexer &Lex, Token Tok) {<br class="">
> -        skipComments(Lex, Tok);<br class="">
> -        unsigned InitialOffset = SM.getFileOffset(Tok.getLocation());<br class="">
> -        if (checkAndConsumeDirectiveWithName(Lex, "ifndef", Tok)) {<br class="">
> -          skipComments(Lex, Tok);<br class="">
> -          if (checkAndConsumeDirectiveWithName(Lex, "define", Tok))<br class="">
> -            return SM.getFileOffset(Tok.getLocation());<br class="">
> -        }<br class="">
> -        return InitialOffset;<br class="">
> -      });<br class="">
> -}<br class="">
> -<br class="">
> -// Check if a sequence of tokens is like<br class="">
> -//    "#include ("header.h" | <header.h>)".<br class="">
> -// If it is, \p Tok will be the token after this directive; otherwise, it can be<br class="">
> -// any token after the given \p Tok (including \p Tok).<br class="">
> -bool checkAndConsumeInclusiveDirective(Lexer &Lex, Token &Tok) {<br class="">
> -  auto Matched = [&]() {<br class="">
> -    Lex.LexFromRawLexer(Tok);<br class="">
> -    return true;<br class="">
> -  };<br class="">
> -  if (<a href="http://tok.is/" target="_blank" class="">Tok.is</a>(tok::hash) && !Lex.LexFromRawLexer(Tok) &&<br class="">
> -      <a href="http://tok.is/" target="_blank" class="">Tok.is</a>(tok::raw_identifier) && Tok.getRawIdentifier() == "include") {<br class="">
> -    if (Lex.LexFromRawLexer(Tok))<br class="">
> -      return false;<br class="">
> -    if (<a href="http://tok.is/" target="_blank" class="">Tok.is</a>(tok::string_literal))<br class="">
> -      return Matched();<br class="">
> -    if (<a href="http://tok.is/" target="_blank" class="">Tok.is</a>(tok::less)) {<br class="">
> -      while (!Lex.LexFromRawLexer(Tok) && Tok.isNot(tok::greater)) {<br class="">
> -      }<br class="">
> -      if (<a href="http://tok.is/" target="_blank" class="">Tok.is</a>(tok::greater))<br class="">
> -        return Matched();<br class="">
> -    }<br class="">
> -  }<br class="">
> -  return false;<br class="">
> -}<br class="">
> -<br class="">
> -// Returns the offset of the last #include directive after which a new<br class="">
> -// #include can be inserted. This ignores #include's after the #include block(s)<br class="">
> -// in the beginning of a file to avoid inserting headers into code sections<br class="">
> -// where new #include's should not be added by default.<br class="">
> -// These code sections include:<br class="">
> -//      - raw string literals (containing #include).<br class="">
> -//      - #if blocks.<br class="">
> -//      - Special #include's among declarations (e.g. functions).<br class="">
> -//<br class="">
> -// If no #include after which a new #include can be inserted, this returns the<br class="">
> -// offset after skipping all comments from the start of the code.<br class="">
> -// Inserting after an #include is not allowed if it comes after code that is not<br class="">
> -// #include (e.g. pre-processing directive that is not #include, declarations).<br class="">
> -unsigned getMaxHeaderInsertionOffset(StringRef FileName, StringRef Code,<br class="">
> -                                     const IncludeStyle &Style) {<br class="">
> -  return getOffsetAfterTokenSequence(<br class="">
> -      FileName, Code, Style,<br class="">
> -      [](const SourceManager &SM, Lexer &Lex, Token Tok) {<br class="">
> -        skipComments(Lex, Tok);<br class="">
> -        unsigned MaxOffset = SM.getFileOffset(Tok.getLocation());<br class="">
> -        while (checkAndConsumeInclusiveDirective(Lex, Tok))<br class="">
> -          MaxOffset = SM.getFileOffset(Tok.getLocation());<br class="">
> -        return MaxOffset;<br class="">
> -      });<br class="">
> -}<br class="">
> -<br class="">
> -inline StringRef trimInclude(StringRef IncludeName) {<br class="">
> -  return IncludeName.trim("\"<>");<br class="">
> -}<br class="">
> -<br class="">
> -const char IncludeRegexPattern[] =<br class="">
> -    R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";<br class="">
> -<br class="">
> -} // anonymous namespace<br class="">
> -<br class="">
> -IncludeCategoryManager::IncludeCategoryManager(const IncludeStyle &Style,<br class="">
> -                                               StringRef FileName)<br class="">
> -    : Style(Style), FileName(FileName) {<br class="">
> -  FileStem = llvm::sys::path::stem(FileName);<br class="">
> -  for (const auto &Category : Style.IncludeCategories)<br class="">
> -    CategoryRegexs.emplace_back(Category.Regex, llvm::Regex::IgnoreCase);<br class="">
> -  IsMainFile = FileName.endswith(".c") || FileName.endswith(".cc") ||<br class="">
> -               FileName.endswith(".cpp") || FileName.endswith(".c++") ||<br class="">
> -               FileName.endswith(".cxx") || FileName.endswith(".m") ||<br class="">
> -               FileName.endswith(".mm");<br class="">
> -}<br class="">
> -<br class="">
> -int IncludeCategoryManager::getIncludePriority(StringRef IncludeName,<br class="">
> -                                               bool CheckMainHeader) const {<br class="">
> -  int Ret = INT_MAX;<br class="">
> -  for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i)<br class="">
> -    if (CategoryRegexs[i].match(IncludeName)) {<br class="">
> -      Ret = Style.IncludeCategories[i].Priority;<br class="">
> -      break;<br class="">
> -    }<br class="">
> -  if (CheckMainHeader && IsMainFile && Ret > 0 && isMainHeader(IncludeName))<br class="">
> -    Ret = 0;<br class="">
> -  return Ret;<br class="">
> -}<br class="">
> -<br class="">
> -bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {<br class="">
> -  if (!IncludeName.startswith("\""))<br class="">
> -    return false;<br class="">
> -  StringRef HeaderStem =<br class="">
> -      llvm::sys::path::stem(IncludeName.drop_front(1).drop_back(1));<br class="">
> -  if (FileStem.startswith(HeaderStem) ||<br class="">
> -      FileStem.startswith_lower(HeaderStem)) {<br class="">
> -    llvm::Regex MainIncludeRegex((HeaderStem + Style.IncludeIsMainRegex).str(),<br class="">
> -                                 llvm::Regex::IgnoreCase);<br class="">
> -    if (MainIncludeRegex.match(FileStem))<br class="">
> -      return true;<br class="">
> -  }<br class="">
> -  return false;<br class="">
> -}<br class="">
> -<br class="">
> -HeaderIncludes::HeaderIncludes(StringRef FileName, StringRef Code,<br class="">
> -                               const IncludeStyle &Style)<br class="">
> -    : FileName(FileName), Code(Code), FirstIncludeOffset(-1),<br class="">
> -      MinInsertOffset(<br class="">
> -          getOffsetAfterHeaderGuardsAndComments(FileName, Code, Style)),<br class="">
> -      MaxInsertOffset(MinInsertOffset +<br class="">
> -                      getMaxHeaderInsertionOffset(<br class="">
> -                          FileName, Code.drop_front(MinInsertOffset), Style)),<br class="">
> -      Categories(Style, FileName),<br class="">
> -      IncludeRegex(llvm::Regex(IncludeRegexPattern)) {<br class="">
> -  // Add 0 for main header and INT_MAX for headers that are not in any<br class="">
> -  // category.<br class="">
> -  Priorities = {0, INT_MAX};<br class="">
> -  for (const auto &Category : Style.IncludeCategories)<br class="">
> -    Priorities.insert(Category.Priority);<br class="">
> -  SmallVector<StringRef, 32> Lines;<br class="">
> -  Code.drop_front(MinInsertOffset).split(Lines, "\n");<br class="">
> -<br class="">
> -  unsigned Offset = MinInsertOffset;<br class="">
> -  unsigned NextLineOffset;<br class="">
> -  SmallVector<StringRef, 4> Matches;<br class="">
> -  for (auto Line : Lines) {<br class="">
> -    NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);<br class="">
> -    if (IncludeRegex.match(Line, &Matches)) {<br class="">
> -      // If this is the last line without trailing newline, we need to make<br class="">
> -      // sure we don't delete across the file boundary.<br class="">
> -      addExistingInclude(<br class="">
> -          Include(Matches[2],<br class="">
> -                  tooling::Range(<br class="">
> -                      Offset, std::min(Line.size() + 1, Code.size() - Offset))),<br class="">
> -          NextLineOffset);<br class="">
> -    }<br class="">
> -    Offset = NextLineOffset;<br class="">
> -  }<br class="">
> -<br class="">
> -  // Populate CategoryEndOfssets:<br class="">
> -  // - Ensure that CategoryEndOffset[Highest] is always populated.<br class="">
> -  // - If CategoryEndOffset[Priority] isn't set, use the next higher value<br class="">
> -  // that is set, up to CategoryEndOffset[Highest].<br class="">
> -  auto Highest = Priorities.begin();<br class="">
> -  if (CategoryEndOffsets.find(*Highest) == CategoryEndOffsets.end()) {<br class="">
> -    if (FirstIncludeOffset >= 0)<br class="">
> -      CategoryEndOffsets[*Highest] = FirstIncludeOffset;<br class="">
> -    else<br class="">
> -      CategoryEndOffsets[*Highest] = MinInsertOffset;<br class="">
> -  }<br class="">
> -  // By this point, CategoryEndOffset[Highest] is always set appropriately:<br class="">
> -  //  - to an appropriate location before/after existing #includes, or<br class="">
> -  //  - to right after the header guard, or<br class="">
> -  //  - to the beginning of the file.<br class="">
> -  for (auto I = ++Priorities.begin(), E = Priorities.end(); I != E; ++I)<br class="">
> -    if (CategoryEndOffsets.find(*I) == CategoryEndOffsets.end())<br class="">
> -      CategoryEndOffsets[*I] = CategoryEndOffsets[*std::prev(I)];<br class="">
> -}<br class="">
> -<br class="">
> -// \p Offset: the start of the line following this include directive.<br class="">
> -void HeaderIncludes::addExistingInclude(Include IncludeToAdd,<br class="">
> -                                        unsigned NextLineOffset) {<br class="">
> -  auto Iter =<br class="">
> -      ExistingIncludes.try_emplace(trimInclude(IncludeToAdd.Name)).first;<br class="">
> -  Iter->second.push_back(std::move(IncludeToAdd));<br class="">
> -  auto &CurInclude = Iter->second.back();<br class="">
> -  // The header name with quotes or angle brackets.<br class="">
> -  // Only record the offset of current #include if we can insert after it.<br class="">
> -  if (CurInclude.R.getOffset() <= MaxInsertOffset) {<br class="">
> -    int Priority = Categories.getIncludePriority(<br class="">
> -        CurInclude.Name, /*CheckMainHeader=*/FirstIncludeOffset < 0);<br class="">
> -    CategoryEndOffsets[Priority] = NextLineOffset;<br class="">
> -    IncludesByPriority[Priority].push_back(&CurInclude);<br class="">
> -    if (FirstIncludeOffset < 0)<br class="">
> -      FirstIncludeOffset = CurInclude.R.getOffset();<br class="">
> -  }<br class="">
> -}<br class="">
> -<br class="">
> -llvm::Optional<tooling::Replacement><br class="">
> -HeaderIncludes::insert(llvm::StringRef IncludeName, bool IsAngled) const {<br class="">
> -  assert(IncludeName == trimInclude(IncludeName));<br class="">
> -  // If a <header> ("header") already exists in code, "header" (<header>) with<br class="">
> -  // different quotation will still be inserted.<br class="">
> -  // FIXME: figure out if this is the best behavior.<br class="">
> -  auto It = ExistingIncludes.find(IncludeName);<br class="">
> -  if (It != ExistingIncludes.end())<br class="">
> -    for (const auto &Inc : It->second)<br class="">
> -      if ((IsAngled && StringRef(Inc.Name).startswith("<")) ||<br class="">
> -          (!IsAngled && StringRef(Inc.Name).startswith("\"")))<br class="">
> -        return llvm::None;<br class="">
> -  std::string Quoted = IsAngled ? ("<" + IncludeName + ">").str()<br class="">
> -                                : ("\"" + IncludeName + "\"").str();<br class="">
> -  StringRef QuotedName = Quoted;<br class="">
> -  int Priority = Categories.getIncludePriority(<br class="">
> -      QuotedName, /*CheckMainHeader=*/FirstIncludeOffset < 0);<br class="">
> -  auto CatOffset = CategoryEndOffsets.find(Priority);<br class="">
> -  assert(CatOffset != CategoryEndOffsets.end());<br class="">
> -  unsigned InsertOffset = CatOffset->second; // Fall back offset<br class="">
> -  auto Iter = IncludesByPriority.find(Priority);<br class="">
> -  if (Iter != IncludesByPriority.end()) {<br class="">
> -    for (const auto *Inc : Iter->second) {<br class="">
> -      if (QuotedName < Inc->Name) {<br class="">
> -        InsertOffset = Inc->R.getOffset();<br class="">
> -        break;<br class="">
> -      }<br class="">
> -    }<br class="">
> -  }<br class="">
> -  assert(InsertOffset <= Code.size());<br class="">
> -  std::string NewInclude = ("#include " + QuotedName + "\n").str();<br class="">
> -  // When inserting headers at end of the code, also append '\n' to the code<br class="">
> -  // if it does not end with '\n'.<br class="">
> -  // FIXME: when inserting multiple #includes at the end of code, only one<br class="">
> -  // newline should be added.<br class="">
> -  if (InsertOffset == Code.size() && (!Code.empty() && Code.back() != '\n'))<br class="">
> -    NewInclude = "\n" + NewInclude;<br class="">
> -  return tooling::Replacement(FileName, InsertOffset, 0, NewInclude);<br class="">
> -}<br class="">
> -<br class="">
> -tooling::Replacements HeaderIncludes::remove(llvm::StringRef IncludeName,<br class="">
> -                                             bool IsAngled) const {<br class="">
> -  assert(IncludeName == trimInclude(IncludeName));<br class="">
> -  tooling::Replacements Result;<br class="">
> -  auto Iter = ExistingIncludes.find(IncludeName);<br class="">
> -  if (Iter == ExistingIncludes.end())<br class="">
> -    return Result;<br class="">
> -  for (const auto &Inc : Iter->second) {<br class="">
> -    if ((IsAngled && StringRef(Inc.Name).startswith("\"")) ||<br class="">
> -        (!IsAngled && StringRef(Inc.Name).startswith("<")))<br class="">
> -      continue;<br class="">
> -    llvm::Error Err = Result.add(tooling::Replacement(<br class="">
> -        FileName, Inc.R.getOffset(), Inc.R.getLength(), ""));<br class="">
> -    if (Err) {<br class="">
> -      auto ErrMsg = "Unexpected conflicts in #include deletions: " +<br class="">
> -                    llvm::toString(std::move(Err));<br class="">
> -      llvm_unreachable(ErrMsg.c_str());<br class="">
> -    }<br class="">
> -  }<br class="">
> -  return Result;<br class="">
> -}<br class="">
> -<br class="">
> -<br class="">
> -} // namespace tooling<br class="">
> -} // namespace clang<br class="">
> <br class="">
> Removed: cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp?rev=332719&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp?rev=332719&view=auto</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp (original)<br class="">
> +++ cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp (removed)<br class="">
> @@ -1,32 +0,0 @@<br class="">
> -//===--- IncludeStyle.cpp - Style of C++ #include directives -----*- C++-*-===//<br class="">
> -//<br class="">
> -//                     The LLVM Compiler Infrastructure<br class="">
> -//<br class="">
> -// This file is distributed under the University of Illinois Open Source<br class="">
> -// License. See LICENSE.TXT for details.<br class="">
> -//<br class="">
> -//===----------------------------------------------------------------------===//<br class="">
> -<br class="">
> -#include "clang/Tooling/Core/IncludeStyle.h"<br class="">
> -<br class="">
> -<br class="">
> -using clang::tooling::IncludeStyle;<br class="">
> -<br class="">
> -namespace llvm {<br class="">
> -namespace yaml {<br class="">
> -<br class="">
> -void MappingTraits<IncludeStyle::IncludeCategory>::mapping(<br class="">
> -    IO &IO, IncludeStyle::IncludeCategory &Category) {<br class="">
> -  IO.mapOptional("Regex", Category.Regex);<br class="">
> -  IO.mapOptional("Priority", Category.Priority);<br class="">
> -}<br class="">
> -<br class="">
> -void ScalarEnumerationTraits<IncludeStyle::IncludeBlocksStyle>::enumeration(<br class="">
> -    IO &IO, IncludeStyle::IncludeBlocksStyle &Value) {<br class="">
> -  IO.enumCase(Value, "Preserve", IncludeStyle::IBS_Preserve);<br class="">
> -  IO.enumCase(Value, "Merge", IncludeStyle::IBS_Merge);<br class="">
> -  IO.enumCase(Value, "Regroup", IncludeStyle::IBS_Regroup);<br class="">
> -}<br class="">
> -<br class="">
> -} // namespace yaml<br class="">
> -} // namespace llvm<br class="">
> <br class="">
> Copied: cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt (from r332717, cfe/trunk/lib/Tooling/Core/CMakeLists.txt)<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt?p2=cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt&p1=cfe/trunk/lib/Tooling/Core/CMakeLists.txt&r1=332717&r2=332720&rev=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt?p2=cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt&p1=cfe/trunk/lib/Tooling/Core/CMakeLists.txt&r1=332717&r2=332720&rev=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/lib/Tooling/Core/CMakeLists.txt (original)<br class="">
> +++ cfe/trunk/lib/Tooling/Inclusions/CMakeLists.txt Fri May 18 07:16:37 2018<br class="">
> @@ -1,15 +1,12 @@<br class="">
> set(LLVM_LINK_COMPONENTS support)<br class="">
> <br class="">
> -add_clang_library(clangToolingCore<br class="">
> -  Diagnostic.cpp<br class="">
> +add_clang_library(clangToolingInclusions<br class="">
>   HeaderIncludes.cpp<br class="">
>   IncludeStyle.cpp<br class="">
> -  Lookup.cpp<br class="">
> -  Replacement.cpp<br class="">
> <br class="">
>   LINK_LIBS<br class="">
> -  clangAST<br class="">
>   clangBasic<br class="">
>   clangLex<br class="">
>   clangRewrite<br class="">
> +  clangToolingCore<br class="">
>   )<br class="">
> <br class="">
> Copied: cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp (from r332717, cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp)<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp?p2=cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp&p1=cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp&r1=332717&r2=332720&rev=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp?p2=cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp&p1=cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp&r1=332717&r2=332720&rev=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/lib/Tooling/Core/HeaderIncludes.cpp (original)<br class="">
> +++ cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp Fri May 18 07:16:37 2018<br class="">
> @@ -7,7 +7,7 @@<br class="">
> //<br class="">
> //===----------------------------------------------------------------------===//<br class="">
> <br class="">
> -#include "clang/Tooling/Core/HeaderIncludes.h"<br class="">
> +#include "clang/Tooling/Inclusions/HeaderIncludes.h"<br class="">
> #include "clang/Basic/SourceManager.h"<br class="">
> #include "clang/Lex/Lexer.h"<br class="">
> <br class="">
> <br class="">
> Copied: cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp (from r332717, cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp)<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp?p2=cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp&p1=cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp&r1=332717&r2=332720&rev=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp?p2=cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp&p1=cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp&r1=332717&r2=332720&rev=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/lib/Tooling/Core/IncludeStyle.cpp (original)<br class="">
> +++ cfe/trunk/lib/Tooling/Inclusions/IncludeStyle.cpp Fri May 18 07:16:37 2018<br class="">
> @@ -7,8 +7,7 @@<br class="">
> //<br class="">
> //===----------------------------------------------------------------------===//<br class="">
> <br class="">
> -#include "clang/Tooling/Core/IncludeStyle.h"<br class="">
> -<br class="">
> +#include "clang/Tooling/Inclusions/IncludeStyle.h"<br class="">
> <br class="">
> using clang::tooling::IncludeStyle;<br class="">
> <br class="">
> <br class="">
> Modified: cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp?rev=332720&r1=332719&r2=332720&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp?rev=332720&r1=332719&r2=332720&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp (original)<br class="">
> +++ cfe/trunk/unittests/Tooling/HeaderIncludesTest.cpp Fri May 18 07:16:37 2018<br class="">
> @@ -7,7 +7,7 @@<br class="">
> //<br class="">
> //===----------------------------------------------------------------------===//<br class="">
> <br class="">
> -#include "clang/Tooling/Core/HeaderIncludes.h"<br class="">
> +#include "clang/Tooling/Inclusions/HeaderIncludes.h"<br class="">
> #include "../Tooling/ReplacementTest.h"<br class="">
> #include "../Tooling/RewriterTestContext.h"<br class="">
> #include "clang/Format/Format.h"<br class="">
> <br class="">
> <br class="">
> _______________________________________________<br class="">
> cfe-commits mailing list<br class="">
> <a href="mailto:cfe-commits@lists.llvm.org" target="_blank" class="">cfe-commits@lists.llvm.org</a><br class="">
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br class="">
<br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></blockquote></div></blockquote></div>
</div></blockquote></div><br class=""></body></html>