clang-tools  12.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 }
 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 FileID FileID, StringRef FileName, IncludeStyle Style)
 IncludeSorter constructor; takes the FileID and name of the file to be processed by the sorter. More...
 
void AddInclude (StringRef FileName, bool IsAngled, SourceLocation HashLocation, SourceLocation EndLocation)
 Adds the given include directive to the sorter. More...
 
Optional< FixItHint > CreateIncludeInsertion (StringRef FileName, bool IsAngled)
 Creates a quoted inclusion directive in the right sort order. 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 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_InvalidInclude 

total number of valid IncludeKinds

Definition at line 29 of file IncludeSorter.h.

◆ IncludeStyle

Supported include styles.

Enumerator
IS_LLVM 
IS_Google 

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 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 92 of file IncludeSorter.cpp.

References FileName, IK_InvalidInclude, Kind, and Offset.

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

◆ 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 113 of file IncludeSorter.cpp.

References IK_InvalidInclude.

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


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