clang  10.0.0svn
Classes | Public Types | Public Attributes | List of all members
clang::tooling::IncludeStyle Struct Reference

Style for sorting and grouping C++ #include directives. More...

#include "clang/Tooling/Inclusions/IncludeStyle.h"

Collaboration diagram for clang::tooling::IncludeStyle:
Collaboration graph
[legend]

Classes

struct  IncludeCategory
 See documentation of IncludeCategories. More...
 

Public Types

enum  IncludeBlocksStyle { IBS_Preserve, IBS_Merge, IBS_Regroup }
 Styles for sorting multiple #include blocks. More...
 

Public Attributes

IncludeBlocksStyle IncludeBlocks
 Dependent on the value, multiple #include blocks can be sorted as one and divided based on category. More...
 
std::vector< IncludeCategoryIncludeCategories
 Regular expressions denoting the different #include categories used for ordering #includes. More...
 
std::string IncludeIsMainRegex
 Specify a regular expression of suffixes that are allowed in the file-to-main-include mapping. More...
 

Detailed Description

Style for sorting and grouping C++ #include directives.

Definition at line 20 of file IncludeStyle.h.

Member Enumeration Documentation

◆ IncludeBlocksStyle

Styles for sorting multiple #include blocks.

Enumerator
IBS_Preserve 

Sort each #include block separately.

#include "b.h" into #include "b.h"
#include <lib/main.h> #include "a.h"
#include "a.h" #include <lib/main.h>
IBS_Merge 

Merge multiple #include blocks together and sort as one.

#include "b.h" into #include "a.h"
#include "b.h"
#include <lib/main.h> #include <lib/main.h>
#include "a.h"
IBS_Regroup 

Merge multiple #include blocks together and sort as one.

Then split into groups based on category priority. See IncludeCategories.

#include "b.h" into #include "a.h"
#include "b.h"
#include <lib/main.h>
#include "a.h" #include <lib/main.h>

Definition at line 22 of file IncludeStyle.h.

Member Data Documentation

◆ IncludeBlocks

IncludeBlocksStyle clang::tooling::IncludeStyle::IncludeBlocks

Dependent on the value, multiple #include blocks can be sorted as one and divided based on category.

Definition at line 53 of file IncludeStyle.h.

◆ IncludeCategories

std::vector<IncludeCategory> clang::tooling::IncludeStyle::IncludeCategories

Regular expressions denoting the different #include categories used for ordering #includes.

POSIX extended <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>_ regular expressions are supported.

These regular expressions are matched against the filename of an include (including the <> or "") in order. The value belonging to the first matching regular expression is assigned and #includes are sorted first according to increasing category number and then alphabetically within each category.

If none of the regular expressions match, INT_MAX is assigned as category. The main header for a source file automatically gets category 0. so that it is generally kept at the beginning of the #includes (https://llvm.org/docs/CodingStandards.html#include-style). However, you can also assign negative priorities if you have certain headers that always need to be first.

To configure this in the .clang-format file, use:

IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '<[[:alnum:].]+>'
Priority: 4
- Regex: '.*'
Priority: 1

Definition at line 100 of file IncludeStyle.h.

Referenced by clang::tooling::HeaderIncludes::HeaderIncludes(), and clang::tooling::IncludeCategoryManager::IncludeCategoryManager().

◆ IncludeIsMainRegex

std::string clang::tooling::IncludeStyle::IncludeIsMainRegex

Specify a regular expression of suffixes that are allowed in the file-to-main-include mapping.

When guessing whether a #include is the "main" include (to assign category 0, see above), use this regex of allowed suffixes to the header stem. A partial match is done, so that:

  • "" means "arbitrary suffix"
  • "$" means "no suffix"

For example, if configured to "(_test)?$", then a header a.h would be seen as the "main" include in both a.cc and a_test.cc.

Definition at line 113 of file IncludeStyle.h.


The documentation for this struct was generated from the following file: