clang-tools 20.0.0git
Public Types | 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 , IS_Google_ObjC }
 Supported include styles. More...
 
enum  IncludeKinds {
  IK_MainTUInclude = 0 , IK_CSystemInclude = 1 , IK_CXXSystemInclude = 2 , IK_NonSystemInclude = 3 ,
  IK_GeneratedInclude = 4 , IK_InvalidInclude = 5
}
 The classifications of inclusions, in the order they should be sorted. More...
 

Public Member Functions

 IncludeSorter (const SourceManager *SourceMgr, const FileID FileID, StringRef FileName, IncludeStyle Style)
 IncludeSorter constructor; takes the FileID and name of the file to be processed by the sorter.
 
void addInclude (StringRef FileName, bool IsAngled, SourceLocation HashLocation, SourceLocation EndLocation)
 Adds the given include directive to the sorter.
 
std::optional< FixItHint > createIncludeInsertion (StringRef FileName, bool IsAngled)
 Creates a quoted inclusion directive in the right sort order.
 

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 23 of file IncludeSorter.h.

Member Enumeration Documentation

◆ 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_GeneratedInclude 

e.g. #include "bar.proto.h"

IK_InvalidInclude 

total number of valid IncludeKinds

Definition at line 29 of file IncludeSorter.h.

◆ IncludeStyle

Supported include styles.

Enumerator
IS_LLVM 
IS_Google 
IS_Google_ObjC 

Definition at line 26 of file IncludeSorter.h.

Constructor & Destructor Documentation

◆ IncludeSorter()

clang::tidy::utils::IncludeSorter::IncludeSorter ( const SourceManager *  SourceMgr,
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 125 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 131 of file IncludeSorter.cpp.

References FileName, IK_InvalidInclude, IsAngled, Kind, and Offset.

◆ createIncludeInsertion()

std::optional< FixItHint > clang::tidy::utils::IncludeSorter::createIncludeInsertion ( StringRef  FileName,
bool  IsAngled 
)

Creates a quoted inclusion directive in the right sort order.

Returns std::nullopt on error or if header inclusion directive for header already exists.

Definition at line 154 of file IncludeSorter.cpp.

References FileName, IK_InvalidInclude, IS_Google_ObjC, and IsAngled.

Referenced by clang::tidy::utils::IncludeInserter::createIncludeInsertion().


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