clang-tools 6.0.0

Public Types | Public Member Functions | Static Public Member Functions | List of all members
clang::tidy::utils::IncludeSorter Class Reference

Class used by `IncludeInserterCallback` to record the names of the inclusions in a given source file being processed and generate the necessary commands to sort the inclusions according to the precedence encoded in `IncludeKinds`. More...

`#include <IncludeSorter.h>`

## Public Types
enum | IncludeStyle { IS_LLVM = 0, IS_Google = 1 }
| Supported include styles. More...
enum | IncludeKinds { IK_MainTUInclude = 0, IK_CSystemInclude = 1, IK_CXXSystemInclude = 2, IK_NonSystemInclude = 3, IK_InvalidInclude = 4 }
| The classifications of inclusions, in the order they should be sorted. More...

## Public Member Functions
| IncludeSorter (const SourceManager *SourceMgr, const LangOptions *LangOpts, const FileID FileID, StringRef FileName, IncludeStyle Style)
| `IncludeSorter` constructor; takes the FileID and name of the file to be processed by the sorter. More...
const FileID | current_FileID () const
| Returns the `SourceManager`-specific file ID for the file being handled by the sorter. More...
void | AddInclude (StringRef FileName, bool IsAngled, SourceLocation HashLocation, SourceLocation EndLocation)
| Adds the given include directive to the sorter. More...
std::vector< FixItHint > | GetEdits ()
| Returns the edits needed to sort the current set of includes and reset the internal state (so that different blocks of includes are sorted separately within the same file). More...
Optional< FixItHint > | CreateIncludeInsertion (StringRef FileName, bool IsAngled)
| Creates a quoted inclusion directive in the right sort order. More...

## Static Public Member Functions
static IncludeStyle | parseIncludeStyle (const std::string &Value)
| Converts "llvm" to `IS_LLVM`, otherwise returns `IS_Google`. More...
static StringRef | toString (IncludeStyle Style)
| Converts `IncludeStyle` to string representation. More...

## Detailed Description

Class used by `IncludeInserterCallback` to record the names of the inclusions in a given source file being processed and generate the necessary commands to sort the inclusions according to the precedence encoded in `IncludeKinds`.

Definition at line 24 of file IncludeSorter.h.

## Member Enumeration Documentation

## ◆ IncludeKinds

enum clang::tidy::utils::IncludeSorter::IncludeKinds

The classifications of inclusions, in the order they should be sorted.

Enumerator
IK_MainTUInclude | e.g. `#include "foo.h"` when editing foo.cc
IK_CSystemInclude | e.g. `#include <stdio.h>`
IK_CXXSystemInclude | e.g. `#include <vector>`
IK_NonSystemInclude | e.g. `#include "bar.h"`
IK_InvalidInclude | total number of valid `IncludeKind`s

Definition at line 36 of file IncludeSorter.h.

## ◆ IncludeStyle

enum clang::tidy::utils::IncludeSorter::IncludeStyle

Supported include styles.

Enumerator
IS_LLVM |
IS_Google |

Definition at line 27 of file IncludeSorter.h.

## Constructor & Destructor Documentation

## ◆ IncludeSorter()

clang::tidy::utils::IncludeSorter::IncludeSorter | ( | const SourceManager * | SourceMgr,
|  | const LangOptions * | LangOpts,
|  | const FileID | FileID,
|  | StringRef | FileName,
|  | IncludeStyle | Style
| ) |  |

`IncludeSorter` constructor; takes the FileID and name of the file to be processed by the sorter.

Definition at line 86 of file IncludeSorter.cpp.

## Member Function Documentation

## ◆ AddInclude()

void clang::tidy::utils::IncludeSorter::AddInclude | ( | StringRef | FileName,
|  | bool | IsAngled,
|  | SourceLocation | HashLocation,
|  | SourceLocation | EndLocation
| ) |  |

Adds the given include directive to the sorter.

Definition at line 93 of file IncludeSorter.cpp.

References IK_InvalidInclude, and Kind.

Referenced by current_FileID().

## ◆ CreateIncludeInsertion()

Optional< FixItHint > clang::tidy::utils::IncludeSorter::CreateIncludeInsertion | ( | StringRef | FileName,
|  | bool | IsAngled
| ) |  |

Creates a quoted inclusion directive in the right sort order.

Returns None on error or if header inclusion directive for header already exists.

Definition at line 114 of file IncludeSorter.cpp.

References IK_InvalidInclude.

Referenced by current_FileID().

## ◆ current_FileID()

const FileID clang::tidy::utils::IncludeSorter::current_FileID | ( |  | ) | const
| inline

Returns the `SourceManager`-specific file ID for the file being handled by the sorter.

Definition at line 51 of file IncludeSorter.h.

References AddInclude(), CreateIncludeInsertion(), GetEdits(), IK_InvalidInclude, and IsAngled.

## ◆ GetEdits()

std::vector< FixItHint > clang::tidy::utils::IncludeSorter::GetEdits | ( |  | ) |

Returns the edits needed to sort the current set of includes and reset the internal state (so that different blocks of includes are sorted separately within the same file).

Definition at line 179 of file IncludeSorter.cpp.

References IK_InvalidInclude.

Referenced by current_FileID().

## ◆ parseIncludeStyle()

IncludeSorter::IncludeStyle clang::tidy::utils::IncludeSorter::parseIncludeStyle | ( | const std::string & | Value | ) |
| static

Converts "llvm" to `IS_LLVM`, otherwise returns `IS_Google`.

Definition at line 280 of file IncludeSorter.cpp.

References IS_Google, and IS_LLVM.

## ◆ toString()

StringRef clang::tidy::utils::IncludeSorter::toString | ( | IncludeStyle | Style | ) |
| static

Converts `IncludeStyle` to string representation.

Definition at line 284 of file IncludeSorter.cpp.

References IS_LLVM.

Referenced by clang::tidy::modernize::PassByValueCheck::storeOptions(), clang::tidy::modernize::ReplaceRandomShuffleCheck::storeOptions(), clang::tidy::performance::UnnecessaryValueParamCheck::storeOptions(), clang::tidy::performance::MoveConstructorInitCheck::storeOptions(), and clang::tidy::performance::TypePromotionInMathFnCheck::storeOptions().

The documentation for this class was generated from the following files:

- IncludeSorter.h
- IncludeSorter.cpp