clang  15.0.0git
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
clang::format Namespace Reference

Namespaces

 encoding
 
 internal
 

Classes

struct  AdditionalKeywords
 Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's lexer. More...
 
class  AffectedRangeManager
 
class  AnnotatedLine
 
class  BreakableBlockComment
 
class  BreakableComment
 
class  BreakableLineCommentSection
 
class  BreakableStringLiteral
 
class  BreakableToken
 Base class for tokens / ranges of tokens that can allow breaking within the tokens - for example, to avoid whitespace beyond the column limit, or to reflow text. More...
 
class  CommaSeparatedList
 
class  CompoundStatementIndenter
 
class  ContinuationIndenter
 
class  DefinitionBlockSeparator
 
class  Environment
 
class  FatalDiagnosticConsumer
 
struct  FormatStyle
 The FormatStyle is used to configure the formatting to follow specific guidelines. More...
 
struct  FormattingAttemptStatus
 Represents the status of a formatting attempt. More...
 
struct  FormatToken
 A wrapper around a Token storing information about the whitespace characters preceding it. More...
 
class  FormatTokenLexer
 
class  FormatTokenSource
 
class  JavaScriptImportSorter
 
struct  JsImportedSymbol
 
struct  JsModuleReference
 
class  LeftRightQualifierAlignmentFixer
 
struct  LineState
 The current state when indenting a unwrapped line. More...
 
class  MacroExpander
 Takes a set of macro definitions as strings and allows expanding calls to those macros. More...
 
struct  MacroExpansion
 Contains information on the token's role in a macro expansion. More...
 
class  NamespaceEndCommentsFixer
 
struct  ParenState
 
class  ParseErrorCategory
 
class  QualifierAlignmentFixer
 
struct  RawStringFormatStyleManager
 
class  ScopedLineState
 
class  TokenAnalyzer
 
class  TokenAnnotator
 Determines extra information about the tokens comprising an UnwrappedLine. More...
 
class  TokenRole
 
struct  UnwrappedLine
 An unwrapped line is a sequence of Token, that we would like to put on a single line if there was no column limit. More...
 
class  UnwrappedLineConsumer
 
class  UnwrappedLineFormatter
 
struct  UnwrappedLineNode
 
class  UnwrappedLineParser
 
class  UsingDeclarationsSorter
 
class  WhitespaceManager
 Manages the whitespaces around tokens and their replacements. More...
 

Typedefs

typedef std::function< std::pair< tooling::Replacements, unsigned > const Environment &)> AnalyzerPass
 

Enumerations

enum  ParseError {
  ParseError::Success = 0, ParseError::Error, ParseError::Unsuitable, ParseError::BinPackTrailingCommaConflict,
  ParseError::InvalidQualifierSpecified, ParseError::DuplicateQualifierSpecified, ParseError::MissingQualifierType, ParseError::MissingQualifierOrder
}
 
enum  TokenType : uint8_t { NUM_TOKEN_TYPES }
 Determines the semantic type of a syntactic token, e.g. More...
 
enum  BraceBlockKind { BK_Unknown, BK_Block, BK_BracedInit }
 
enum  ParameterPackingKind { PPK_BinPacked, PPK_OnePerLine, PPK_Inconclusive }
 
enum  FormatDecision { FD_Unformatted, FD_Continue, FD_Break }
 
enum  MacroRole { MR_ExpandedArg, MR_UnexpandedArg, MR_Hidden }
 Roles a token can take in a configured macro expansion. More...
 
enum  LexerState { NORMAL, TEMPLATE_STRING, TOKEN_STASHED }
 
enum  LineType {
  LT_Invalid, LT_ImportStatement, LT_ObjCDecl, LT_ObjCMethodDecl,
  LT_ObjCProperty, LT_Other, LT_PreprocessorDirective, LT_VirtualFunctionDecl,
  LT_ArrayOfStructInitializer
}
 

Functions

const std::error_category & getParseCategory ()
 
std::error_code make_error_code (ParseError e)
 
FormatStyle getLLVMStyle (FormatStyle::LanguageKind Language=FormatStyle::LanguageKind::LK_Cpp)
 Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards.html. More...
 
FormatStyle getGoogleStyle (FormatStyle::LanguageKind Language)
 Returns a format style complying with one of Google's style guides: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. More...
 
FormatStyle getChromiumStyle (FormatStyle::LanguageKind Language)
 Returns a format style complying with Chromium's style guide: http://www.chromium.org/developers/coding-style. More...
 
FormatStyle getMozillaStyle ()
 Returns a format style complying with Mozilla's style guide: https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html. More...
 
FormatStyle getWebKitStyle ()
 Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style.html. More...
 
FormatStyle getGNUStyle ()
 Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standards.html. More...
 
FormatStyle getMicrosoftStyle (FormatStyle::LanguageKind Language)
 Returns a format style complying with Microsoft style guide: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017. More...
 
FormatStyle getNoStyle ()
 Returns style indicating formatting should be not applied at all. More...
 
bool getPredefinedStyle (StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
 Gets a predefined style for the specified language by name. More...
 
std::error_code parseConfiguration (llvm::MemoryBufferRef Config, FormatStyle *Style, bool AllowUnknownOptions=false, llvm::SourceMgr::DiagHandlerTy DiagHandler=nullptr, void *DiagHandlerCtx=nullptr)
 Parse configuration from YAML-formatted text. More...
 
std::error_code parseConfiguration (StringRef Config, FormatStyle *Style, bool AllowUnknownOptions=false)
 Like above but accepts an unnamed buffer. More...
 
std::string configurationAsText (const FormatStyle &Style)
 Gets configuration in a YAML string. More...
 
tooling::Replacements sortIncludes (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, unsigned *Cursor=nullptr)
 Returns the replacements necessary to sort all #include blocks that are affected by Ranges. More...
 
llvm::Expected< tooling::ReplacementsformatReplacements (StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
 Returns the replacements corresponding to applying and formatting Replaces on success; otheriwse, return an llvm::Error carrying llvm::StringError. More...
 
llvm::Expected< tooling::ReplacementscleanupAroundReplacements (StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
 Returns the replacements corresponding to applying Replaces and cleaning up the code after that on success; otherwise, return an llvm::Error carrying llvm::StringError. More...
 
tooling::Replacements reformat (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>", FormattingAttemptStatus *Status=nullptr)
 Reformats the given Ranges in Code. More...
 
tooling::Replacements reformat (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, bool *IncompleteFormat)
 Same as above, except if IncompleteFormat is non-null, its value will be set to true if any of the affected ranges were not formatted due to a non-recoverable syntax error. More...
 
tooling::Replacements cleanup (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
 Clean up any erroneous/redundant code in the given Ranges in Code. More...
 
tooling::Replacements fixNamespaceEndComments (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
 Fix namespace end comments in the given Ranges in Code. More...
 
tooling::Replacements separateDefinitionBlocks (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
 Inserts or removes empty lines separating definition blocks including classes, structs, functions, namespaces, and enums in the given Ranges in Code. More...
 
tooling::Replacements sortUsingDeclarations (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
 Sort consecutive using declarations in the given Ranges in Code. More...
 
LangOptions getFormattingLangOpts (const FormatStyle &Style=getLLVMStyle())
 Returns the LangOpts that the formatter expects you to set. More...
 
llvm::Expected< FormatStylegetStyle (StringRef StyleName, StringRef FileName, StringRef FallbackStyle, StringRef Code="", llvm::vfs::FileSystem *FS=nullptr, bool AllowUnknownOptions=false)
 Construct a FormatStyle based on StyleName. More...
 
FormatStyle::LanguageKind guessLanguage (StringRef FileName, StringRef Code)
 
StringRef getLanguageName (FormatStyle::LanguageKind Language)
 
static bool IsBlank (char C)
 
static StringRef getLineCommentIndentPrefix (StringRef Comment, const FormatStyle &Style)
 
static BreakableToken::Split getCommentSplit (StringRef Text, unsigned ContentStartColumn, unsigned ColumnLimit, unsigned TabWidth, encoding::Encoding Encoding, const FormatStyle &Style, bool DecorationEndsWithStar=false)
 
static BreakableToken::Split getStringSplit (StringRef Text, unsigned UsedColumns, unsigned ColumnLimit, unsigned TabWidth, encoding::Encoding Encoding)
 
bool switchesFormatting (const FormatToken &Token)
 Checks if Token switches formatting, like /* clang-format off *‍/. More...
 
static bool mayReflowContent (StringRef Content)
 
static bool shouldIndentWrappedSelectorName (const FormatStyle &Style, LineType LineType)
 
static unsigned getLengthToMatchingParen (const FormatToken &Tok, const std::vector< ParenState > &Stack)
 
static unsigned getLengthToNextOperator (const FormatToken &Tok)
 
static bool startsSegmentOfBuilderTypeCall (const FormatToken &Tok)
 
static bool startsNextParameter (const FormatToken &Current, const FormatStyle &Style)
 
static bool opensProtoMessageField (const FormatToken &LessTok, const FormatStyle &Style)
 
static llvm::Optional< StringRef > getRawStringDelimiter (StringRef TokenText)
 
static StringRef getCanonicalRawStringDelimiter (const FormatStyle &Style, FormatStyle::LanguageKind Language)
 
static bool hasNestedBlockInlined (const FormatToken *Previous, const FormatToken &Current, const FormatStyle &Style)
 
static unsigned getLastLineEndColumn (StringRef Text, unsigned StartColumn, unsigned TabWidth, encoding::Encoding Encoding)
 
static StringRef getEnclosingFunctionName (const FormatToken &Current)
 
llvm::Error make_string_error (const llvm::Twine &Message)
 
static void expandPresetsBraceWrapping (FormatStyle &Expanded)
 
static void expandPresetsSpaceBeforeParens (FormatStyle &Expanded)
 
ParseError validateQualifierOrder (FormatStyle *Style)
 
static bool affectsRange (ArrayRef< tooling::Range > Ranges, unsigned Start, unsigned End)
 
static std::pair< unsigned, unsignedFindCursorIndex (const SmallVectorImpl< IncludeDirective > &Includes, const SmallVectorImpl< unsigned > &Indices, unsigned Cursor)
 
std::string replaceCRLF (const std::string &Code)
 
static void sortCppIncludes (const FormatStyle &Style, const SmallVectorImpl< IncludeDirective > &Includes, ArrayRef< tooling::Range > Ranges, StringRef FileName, StringRef Code, tooling::Replacements &Replaces, unsigned *Cursor)
 
tooling::Replacements sortCppIncludes (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, tooling::Replacements &Replaces, unsigned *Cursor)
 
static unsigned findJavaImportGroup (const FormatStyle &Style, StringRef ImportIdentifier)
 
static void sortJavaImports (const FormatStyle &Style, const SmallVectorImpl< JavaImportDirective > &Imports, ArrayRef< tooling::Range > Ranges, StringRef FileName, StringRef Code, tooling::Replacements &Replaces)
 
tooling::Replacements sortJavaImports (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, tooling::Replacements &Replaces)
 
bool isMpegTS (StringRef Code)
 
bool isLikelyXml (StringRef Code)
 
template<typename T >
static llvm::Expected< tooling::ReplacementsprocessReplacements (T ProcessFunc, StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
 
static FormatStyle::LanguageKind getLanguageByFileName (StringRef FileName)
 
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > loadAndParseConfigFile (StringRef ConfigFile, llvm::vfs::FileSystem *FS, FormatStyle *Style, bool AllowUnknownOptions)
 
const char * getTokenTypeName (TokenType Type)
 Determines the name of a token type. More...
 
static unsigned CodePointsBetween (const FormatToken *Begin, const FormatToken *End)
 
const FormatTokengetNamespaceToken (const AnnotatedLine *Line, const SmallVectorImpl< AnnotatedLine * > &AnnotatedLines)
 
StringRef getNamespaceTokenText (const AnnotatedLine *Line, const SmallVectorImpl< AnnotatedLine * > &AnnotatedLines)
 
static void replaceToken (const SourceManager &SourceMgr, tooling::Replacements &Fixes, const CharSourceRange &Range, std::string NewText)
 
static void removeToken (const SourceManager &SourceMgr, tooling::Replacements &Fixes, const FormatToken *First)
 
static void insertQualifierAfter (const SourceManager &SourceMgr, tooling::Replacements &Fixes, const FormatToken *First, const std::string &Qualifier)
 
static void insertQualifierBefore (const SourceManager &SourceMgr, tooling::Replacements &Fixes, const FormatToken *First, const std::string &Qualifier)
 
static bool endsWithSpace (const std::string &s)
 
static bool startsWithSpace (const std::string &s)
 
static void rotateTokens (const SourceManager &SourceMgr, tooling::Replacements &Fixes, const FormatToken *First, const FormatToken *Last, bool Left)
 
bool operator< (const JsModuleReference &LHS, const JsModuleReference &RHS)
 
tooling::Replacements sortJavaScriptImports (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName)
 
static unsigned maxNestingDepth (const AnnotatedLine &Line)
 
static bool isFunctionDeclarationName (bool IsCpp, const FormatToken &Current, const AnnotatedLine &Line)
 
static bool isAllmanBrace (const FormatToken &Tok)
 
static bool IsFunctionArgument (const FormatToken &Tok)
 
static bool isItAnEmptyLambdaAllowed (const FormatToken &Tok, FormatStyle::ShortLambdaStyle ShortLambdaOption)
 
static bool isAllmanLambdaBrace (const FormatToken &Tok)
 
static const FormatTokengetFirstNonComment (const AnnotatedLine &Line)
 
template<class T >
static void hash_combine (std::size_t &seed, const T &v)
 
static bool isGoogScope (const UnwrappedLine &Line)
 
static bool isIIFE (const UnwrappedLine &Line, const AdditionalKeywords &Keywords)
 
static bool ShouldBreakBeforeBrace (const FormatStyle &Style, const FormatToken &InitialToken)
 
static bool tokenCanStartNewLine (const FormatToken &Tok)
 
static bool mustBeJSIdent (const AdditionalKeywords &Keywords, const FormatToken *FormatTok)
 
static bool mustBeJSIdentOrValue (const AdditionalKeywords &Keywords, const FormatToken *FormatTok)
 
static bool isJSDeclOrStmt (const AdditionalKeywords &Keywords, const FormatToken *FormatTok)
 
static bool isC78Type (const FormatToken &Tok)
 
static bool isC78ParameterDecl (const FormatToken *Tok, const FormatToken *Next, const FormatToken *FuncName)
 
static FormatTokengetLastNonComment (const UnwrappedLine &Line)
 
static void markOptionalBraces (FormatToken *LeftBrace)
 
static bool isCOperatorFollowingVar (tok::TokenKind kind)
 
static LLVM_ATTRIBUTE_UNUSED void printDebugInfo (const UnwrappedLine &Line, StringRef Prefix="")
 
static bool continuesLineCommentSection (const FormatToken &FormatTok, const UnwrappedLine &Line, const llvm::Regex &CommentPragmasRegex)
 
template<typename F >
static void AlignTokenSequence (const FormatStyle &Style, unsigned Start, unsigned End, unsigned Column, bool RightJustify, F &&Matches, SmallVector< WhitespaceManager::Change, 16 > &Changes)
 
template<typename F >
static unsigned AlignTokens (const FormatStyle &Style, F &&Matches, SmallVector< WhitespaceManager::Change, 16 > &Changes, unsigned StartAt, const FormatStyle::AlignConsecutiveStyle &ACS={}, bool RightJustify=false)
 
static void AlignMacroSequence (unsigned &StartOfSequence, unsigned &EndOfSequence, unsigned &MinColumn, unsigned &MaxColumn, bool &FoundMatchOnLine, std::function< bool(const WhitespaceManager::Change &C)> AlignMacrosMatches, SmallVector< WhitespaceManager::Change, 16 > &Changes)
 

Variables

const char * StyleOptionHelpDescription
 Description to be used for help text for a llvm::cl option for specifying format style. More...
 
const char * DefaultFormatStyle = "file"
 The suggested format style to use by default. More...
 
const char * DefaultFallbackStyle = "LLVM"
 The suggested predefined style to use as the fallback style in getStyle. More...
 
static constexpr StringRef Blanks = " \t\v\f\r"
 

Typedef Documentation

◆ AnalyzerPass

typedef std::function<std::pair<tooling::Replacements, unsigned> const Environment &)> clang::format::AnalyzerPass

Definition at line 26 of file QualifierAlignmentFixer.h.

Enumeration Type Documentation

◆ BraceBlockKind

Enumerator
BK_Unknown 
BK_Block 
BK_BracedInit 

Definition at line 153 of file FormatToken.h.

◆ FormatDecision

Enumerator
FD_Unformatted 
FD_Continue 
FD_Break 

Definition at line 158 of file FormatToken.h.

◆ LexerState

Enumerator
NORMAL 
TEMPLATE_STRING 
TOKEN_STASHED 

Definition at line 33 of file FormatTokenLexer.h.

◆ LineType

Enumerator
LT_Invalid 
LT_ImportStatement 
LT_ObjCDecl 
LT_ObjCMethodDecl 
LT_ObjCProperty 
LT_Other 
LT_PreprocessorDirective 
LT_VirtualFunctionDecl 
LT_ArrayOfStructInitializer 

Definition at line 24 of file TokenAnnotator.h.

◆ MacroRole

Roles a token can take in a configured macro expansion.

Enumerator
MR_ExpandedArg 

The token was expanded from a macro argument when formatting the expanded token sequence.

MR_UnexpandedArg 

The token is part of a macro argument that was previously formatted as expansion when formatting the unexpanded macro call.

MR_Hidden 

The token was expanded from a macro definition, and is not visible as part of the macro call.

Definition at line 161 of file FormatToken.h.

◆ ParameterPackingKind

Enumerator
PPK_BinPacked 
PPK_OnePerLine 
PPK_Inconclusive 

Definition at line 156 of file FormatToken.h.

◆ ParseError

Enumerator
Success 
Error 
Unsuitable 
BinPackTrailingCommaConflict 
InvalidQualifierSpecified 
DuplicateQualifierSpecified 
MissingQualifierType 
MissingQualifierOrder 

Definition at line 34 of file Format.h.

◆ TokenType

enum clang::format::TokenType : uint8_t

Determines the semantic type of a syntactic token, e.g.

whether "<" is a template opener or binary operator.

Enumerator
NUM_TOKEN_TYPES 

Definition at line 142 of file FormatToken.h.

Function Documentation

◆ affectsRange()

static bool clang::format::affectsRange ( ArrayRef< tooling::Range Ranges,
unsigned  Start,
unsigned  End 
)
static

Definition at line 2569 of file Format.cpp.

References End.

◆ AlignMacroSequence()

static void clang::format::AlignMacroSequence ( unsigned StartOfSequence,
unsigned EndOfSequence,
unsigned MinColumn,
unsigned MaxColumn,
bool FoundMatchOnLine,
std::function< bool(const WhitespaceManager::Change &C)>  AlignMacrosMatches,
SmallVector< WhitespaceManager::Change, 16 > &  Changes 
)
static

Definition at line 653 of file WhitespaceManager.cpp.

References clang::prec::Shift, and UINT_MAX.

◆ AlignTokens()

template<typename F >
static unsigned clang::format::AlignTokens ( const FormatStyle Style,
F &&  Matches,
SmallVector< WhitespaceManager::Change, 16 > &  Changes,
unsigned  StartAt,
const FormatStyle::AlignConsecutiveStyle ACS = {},
bool  RightJustify = false 
)
static

Definition at line 484 of file WhitespaceManager.cpp.

◆ AlignTokenSequence()

template<typename F >
static void clang::format::AlignTokenSequence ( const FormatStyle Style,
unsigned  Start,
unsigned  End,
unsigned  Column,
bool  RightJustify,
F &&  Matches,
SmallVector< WhitespaceManager::Change, 16 > &  Changes 
)
static

Definition at line 275 of file WhitespaceManager.cpp.

◆ cleanup()

tooling::Replacements clang::format::cleanup ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName = "<stdin>" 
)

◆ cleanupAroundReplacements()

llvm::Expected< tooling::Replacements > clang::format::cleanupAroundReplacements ( StringRef  Code,
const tooling::Replacements Replaces,
const FormatStyle Style 
)

Returns the replacements corresponding to applying Replaces and cleaning up the code after that on success; otherwise, return an llvm::Error carrying llvm::StringError.

This also supports inserting/deleting C++ include directives:

  • If a replacement has offset UINT_MAX, length 0, and a replacement text that is an include directive, this will insert the include into the correct block in the Code.
  • If a replacement has offset UINT_MAX, length 1, and a replacement text that is the name of the header to be removed, the header will be removed from Code if it exists. The include manipulation is done via tooling::HeaderInclude, see its documentation for more details on how include insertion points are found and what edits are produced.

Definition at line 3156 of file Format.cpp.

Referenced by clang::tooling::applyAtomicChanges().

◆ CodePointsBetween()

static unsigned clang::format::CodePointsBetween ( const FormatToken Begin,
const FormatToken End 
)
static

Definition at line 166 of file FormatToken.cpp.

References Begin, and End.

Referenced by clang::format::CommaSeparatedList::precomputeFormattingInfos().

◆ configurationAsText()

std::string clang::format::configurationAsText ( const FormatStyle Style)

Gets configuration in a YAML string.

Definition at line 1783 of file Format.cpp.

◆ continuesLineCommentSection()

static bool clang::format::continuesLineCommentSection ( const FormatToken FormatTok,
const UnwrappedLine Line,
const llvm::Regex &  CommentPragmasRegex 
)
static

Definition at line 3938 of file UnwrappedLineParser.cpp.

References Line, and clang::format::FormatToken::TokenText.

◆ endsWithSpace()

static bool clang::format::endsWithSpace ( const std::string s)
static

Definition at line 152 of file QualifierAlignmentFixer.cpp.

References s.

Referenced by rotateTokens().

◆ expandPresetsBraceWrapping()

static void clang::format::expandPresetsBraceWrapping ( FormatStyle Expanded)
static

Definition at line 1040 of file Format.cpp.

References clang::format::FormatStyle::BraceWrappingFlags::AfterCaseLabel, clang::format::FormatStyle::BraceWrappingFlags::AfterClass, clang::format::FormatStyle::BraceWrappingFlags::AfterControlStatement, clang::format::FormatStyle::BraceWrappingFlags::AfterEnum, clang::format::FormatStyle::BraceWrappingFlags::AfterExternBlock, clang::format::FormatStyle::BraceWrappingFlags::AfterFunction, clang::format::FormatStyle::BraceWrappingFlags::AfterNamespace, clang::format::FormatStyle::BraceWrappingFlags::AfterObjCDeclaration, clang::format::FormatStyle::BraceWrappingFlags::AfterStruct, clang::format::FormatStyle::BraceWrappingFlags::AfterUnion, clang::format::FormatStyle::BraceWrappingFlags::BeforeCatch, clang::format::FormatStyle::BraceWrappingFlags::BeforeElse, clang::format::FormatStyle::BraceWrappingFlags::BeforeLambdaBody, clang::format::FormatStyle::BraceWrapping, clang::format::FormatStyle::BreakBeforeBraces, clang::format::FormatStyle::BS_Allman, clang::format::FormatStyle::BS_Custom, clang::format::FormatStyle::BS_GNU, clang::format::FormatStyle::BS_Linux, clang::format::FormatStyle::BS_Mozilla, clang::format::FormatStyle::BS_Stroustrup, clang::format::FormatStyle::BS_WebKit, clang::format::FormatStyle::BS_Whitesmiths, clang::format::FormatStyle::BWACS_Always, clang::format::FormatStyle::BWACS_Never, clang::format::FormatStyle::IEBS_AfterExternBlock, clang::format::FormatStyle::IndentExternBlock, clang::format::FormatStyle::BraceWrappingFlags::SplitEmptyFunction, and clang::format::FormatStyle::BraceWrappingFlags::SplitEmptyRecord.

◆ expandPresetsSpaceBeforeParens()

static void clang::format::expandPresetsSpaceBeforeParens ( FormatStyle Expanded)
static

◆ FindCursorIndex()

static std::pair<unsigned, unsigned> clang::format::FindCursorIndex ( const SmallVectorImpl< IncludeDirective > &  Includes,
const SmallVectorImpl< unsigned > &  Indices,
unsigned  Cursor 
)
static

Definition at line 2586 of file Format.cpp.

References End, Text, and UINT_MAX.

◆ findJavaImportGroup()

static unsigned clang::format::findJavaImportGroup ( const FormatStyle Style,
StringRef  ImportIdentifier 
)
static

Definition at line 2845 of file Format.cpp.

◆ fixNamespaceEndComments()

tooling::Replacements clang::format::fixNamespaceEndComments ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName = "<stdin>" 
)

Fix namespace end comments in the given Ranges in Code.

Returns the Replacements that fix the namespace comments in all Ranges in Code.

Definition at line 3334 of file Format.cpp.

◆ formatReplacements()

llvm::Expected< tooling::Replacements > clang::format::formatReplacements ( StringRef  Code,
const tooling::Replacements Replaces,
const FormatStyle Style 
)

Returns the replacements corresponding to applying and formatting Replaces on success; otheriwse, return an llvm::Error carrying llvm::StringError.

Definition at line 3046 of file Format.cpp.

◆ getCanonicalRawStringDelimiter()

static StringRef clang::format::getCanonicalRawStringDelimiter ( const FormatStyle Style,
FormatStyle::LanguageKind  Language 
)
static

Definition at line 176 of file ContinuationIndenter.cpp.

◆ getChromiumStyle()

FormatStyle clang::format::getChromiumStyle ( FormatStyle::LanguageKind  Language)

◆ getCommentSplit()

static BreakableToken::Split clang::format::getCommentSplit ( StringRef  Text,
unsigned  ContentStartColumn,
unsigned  ColumnLimit,
unsigned  TabWidth,
encoding::Encoding  Encoding,
const FormatStyle Style,
bool  DecorationEndsWithStar = false 
)
static

◆ getEnclosingFunctionName()

static StringRef clang::format::getEnclosingFunctionName ( const FormatToken Current)
static

Definition at line 1948 of file ContinuationIndenter.cpp.

◆ getFirstNonComment()

static const FormatToken* clang::format::getFirstNonComment ( const AnnotatedLine Line)
static

Definition at line 3926 of file TokenAnnotator.cpp.

◆ getFormattingLangOpts()

LangOptions clang::format::getFormattingLangOpts ( const FormatStyle Style = getLLVMStyle())

Returns the LangOpts that the formatter expects you to set.

Parameters
Styledetermines specific settings for lexing mode.

Definition at line 3364 of file Format.cpp.

◆ getGNUStyle()

FormatStyle clang::format::getGNUStyle ( )

Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standards.html.

Definition at line 1603 of file Format.cpp.

◆ getGoogleStyle()

FormatStyle clang::format::getGoogleStyle ( FormatStyle::LanguageKind  Language)

Returns a format style complying with one of Google's style guides: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.

http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml. https://developers.google.com/protocol-buffers/docs/style.

Definition at line 1354 of file Format.cpp.

References clang::format::FormatStyle::AccessModifierOffset, clang::format::FormatStyle::AlignAfterOpenBracket, clang::format::FormatStyle::AlignEscapedNewlines, clang::format::FormatStyle::AlignOperands, clang::format::FormatStyle::AlignTrailingComments, clang::format::FormatStyle::AllowShortFunctionsOnASingleLine, clang::format::FormatStyle::AllowShortIfStatementsOnASingleLine, clang::format::FormatStyle::AllowShortLambdasOnASingleLine, clang::format::FormatStyle::AllowShortLoopsOnASingleLine, clang::format::FormatStyle::AlwaysBreakBeforeMultilineStrings, clang::format::FormatStyle::AlwaysBreakTemplateDeclarations, clang::format::FormatStyle::BAS_AlwaysBreak, clang::format::FormatStyle::BAS_DontAlign, clang::format::FormatStyle::BOS_NonAssignment, clang::format::FormatStyle::BPS_Never, clang::format::FormatStyle::BreakBeforeBinaryOperators, clang::format::FormatStyle::BreakBeforeTernaryOperators, clang::format::FormatStyle::BreakStringLiterals, clang::format::FormatStyle::BTDS_Yes, clang::format::FormatStyle::ColumnLimit, clang::format::FormatStyle::CommentPragmas, clang::format::FormatStyle::Cpp11BracedListStyle, clang::format::FormatStyle::DerivePointerAlignment, clang::format::FormatStyle::ENAS_Left, getLLVMStyle(), clang::tooling::IncludeStyle::IBS_Preserve, clang::tooling::IncludeStyle::IBS_Regroup, clang::tooling::IncludeStyle::IncludeBlocks, clang::tooling::IncludeStyle::IncludeCategories, clang::tooling::IncludeStyle::IncludeIsMainRegex, clang::format::FormatStyle::IncludeStyle, clang::format::FormatStyle::IndentCaseLabels, clang::format::FormatStyle::JavaScriptQuotes, clang::format::FormatStyle::JavaScriptWrapImports, clang::format::FormatStyle::JSQS_Single, clang::format::FormatStyle::KeepEmptyLinesAtTheStartOfBlocks, clang::format::FormatStyle::Language, clang::format::FormatStyle::LK_Cpp, clang::format::FormatStyle::LK_CSharp, clang::format::FormatStyle::LK_Java, clang::format::FormatStyle::LK_JavaScript, clang::format::FormatStyle::LK_ObjC, clang::format::FormatStyle::LK_Proto, clang::format::FormatStyle::LK_TextProto, clang::format::FormatStyle::LS_Auto, clang::format::FormatStyle::MaxEmptyLinesToKeep, clang::format::FormatStyle::NamespaceIndentation, clang::format::FormatStyle::NI_All, clang::format::FormatStyle::OAS_DontAlign, clang::format::FormatStyle::ObjCBinPackProtocolList, clang::format::FormatStyle::ObjCSpaceAfterProperty, clang::format::FormatStyle::ObjCSpaceBeforeProtocolList, clang::format::FormatStyle::PackConstructorInitializers, clang::format::FormatStyle::PAS_Left, clang::format::FormatStyle::PCIS_NextLine, clang::format::FormatStyle::PenaltyBreakBeforeFirstCallParameter, clang::format::FormatStyle::PenaltyReturnTypeOnItsOwnLine, clang::format::FormatStyle::PointerAlignment, clang::format::FormatStyle::RawStringFormats, clang::format::FormatStyle::SFS_Empty, clang::format::FormatStyle::SIS_Never, clang::format::FormatStyle::SIS_WithoutElse, clang::format::FormatStyle::SLS_Empty, clang::format::FormatStyle::SpaceAfterCStyleCast, clang::format::FormatStyle::SpacesBeforeTrailingComments, clang::format::FormatStyle::SpacesInContainerLiterals, and clang::format::FormatStyle::Standard.

Referenced by getChromiumStyle().

◆ getLanguageByFileName()

static FormatStyle::LanguageKind clang::format::getLanguageByFileName ( StringRef  FileName)
static

◆ getLanguageName()

StringRef clang::format::getLanguageName ( FormatStyle::LanguageKind  Language)
inline

◆ getLastLineEndColumn()

static unsigned clang::format::getLastLineEndColumn ( StringRef  Text,
unsigned  StartColumn,
unsigned  TabWidth,
encoding::Encoding  Encoding 
)
static

◆ getLastNonComment()

static FormatToken* clang::format::getLastNonComment ( const UnwrappedLine Line)
static

Definition at line 2411 of file UnwrappedLineParser.cpp.

References clang::Token::isNot(), and Line.

◆ getLengthToMatchingParen()

static unsigned clang::format::getLengthToMatchingParen ( const FormatToken Tok,
const std::vector< ParenState > &  Stack 
)
static

Definition at line 39 of file ContinuationIndenter.cpp.

◆ getLengthToNextOperator()

static unsigned clang::format::getLengthToNextOperator ( const FormatToken Tok)
static

◆ getLineCommentIndentPrefix()

static StringRef clang::format::getLineCommentIndentPrefix ( StringRef  Comment,
const FormatStyle Style 
)
static

Definition at line 42 of file BreakableToken.cpp.

◆ getLLVMStyle()

FormatStyle clang::format::getLLVMStyle ( FormatStyle::LanguageKind  Language = FormatStyle::LanguageKind::LK_Cpp)

Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards.html.

Definition at line 1171 of file Format.cpp.

References clang::format::FormatStyle::AccessModifierOffset, clang::format::FormatStyle::AlignConsecutiveStyle::AcrossComments, clang::format::FormatStyle::AlignConsecutiveStyle::AcrossEmptyLines, clang::format::FormatStyle::SpaceBeforeParensCustom::AfterControlStatements, clang::format::FormatStyle::SpaceBeforeParensCustom::AfterForeachMacros, clang::format::FormatStyle::SpaceBeforeParensCustom::AfterIfMacros, clang::format::FormatStyle::AIAS_None, clang::format::FormatStyle::AlignAfterOpenBracket, clang::format::FormatStyle::AlignArrayOfStructures, clang::format::FormatStyle::AlignConsecutiveStyle::AlignCompound, clang::format::FormatStyle::AlignConsecutiveAssignments, clang::format::FormatStyle::AlignConsecutiveBitFields, clang::format::FormatStyle::AlignConsecutiveDeclarations, clang::format::FormatStyle::AlignConsecutiveMacros, clang::format::FormatStyle::AlignEscapedNewlines, clang::format::FormatStyle::AlignOperands, clang::format::FormatStyle::AlignTrailingComments, clang::format::FormatStyle::AllowAllArgumentsOnNextLine, clang::format::FormatStyle::AllowAllParametersOfDeclarationOnNextLine, clang::format::FormatStyle::AllowShortBlocksOnASingleLine, clang::format::FormatStyle::AllowShortCaseLabelsOnASingleLine, clang::format::FormatStyle::AllowShortEnumsOnASingleLine, clang::format::FormatStyle::AllowShortFunctionsOnASingleLine, clang::format::FormatStyle::AllowShortIfStatementsOnASingleLine, clang::format::FormatStyle::AllowShortLambdasOnASingleLine, clang::format::FormatStyle::AllowShortLoopsOnASingleLine, clang::format::FormatStyle::AlwaysBreakAfterDefinitionReturnType, clang::format::FormatStyle::AlwaysBreakAfterReturnType, clang::format::FormatStyle::AlwaysBreakBeforeMultilineStrings, clang::format::FormatStyle::AlwaysBreakTemplateDeclarations, clang::prec::Assignment, clang::format::FormatStyle::AttributeMacros, clang::format::FormatStyle::BAS_Align, clang::format::FormatStyle::BBCDS_Always, clang::format::FormatStyle::BCIS_BeforeColon, clang::format::FormatStyle::BFCS_Both, clang::format::FormatStyle::BILS_BeforeColon, clang::format::FormatStyle::BinPackArguments, clang::format::FormatStyle::BinPackParameters, clang::format::FormatStyle::BitFieldColonSpacing, clang::format::FormatStyle::BOS_None, clang::format::FormatStyle::BPS_Auto, clang::format::FormatStyle::BraceWrapping, clang::format::FormatStyle::BreakAfterJavaFieldAnnotations, clang::format::FormatStyle::BreakBeforeBinaryOperators, clang::format::FormatStyle::BreakBeforeBraces, clang::format::FormatStyle::BreakBeforeConceptDeclarations, clang::format::FormatStyle::BreakBeforeTernaryOperators, clang::format::FormatStyle::BreakConstructorInitializers, clang::format::FormatStyle::BreakInheritanceList, clang::format::FormatStyle::BreakStringLiterals, clang::format::FormatStyle::BS_Attach, clang::format::FormatStyle::BTDS_MultiLine, clang::format::FormatStyle::BWACS_Never, clang::format::FormatStyle::ColumnLimit, clang::format::FormatStyle::CommentPragmas, clang::format::FormatStyle::CompactNamespaces, clang::format::FormatStyle::ConstructorInitializerIndentWidth, clang::format::FormatStyle::ContinuationIndentWidth, clang::format::FormatStyle::Cpp11BracedListStyle, clang::format::FormatStyle::DeriveLineEnding, clang::format::FormatStyle::DerivePointerAlignment, clang::format::FormatStyle::DisableFormat, clang::format::FormatStyle::DRTBS_None, clang::format::FormatStyle::ELAAMS_Never, clang::format::FormatStyle::ELBAMS_LogicalBlock, clang::format::FormatStyle::EmptyLineAfterAccessModifier, clang::format::FormatStyle::EmptyLineBeforeAccessModifier, clang::format::FormatStyle::AlignConsecutiveStyle::Enabled, clang::format::FormatStyle::ENAS_Right, clang::format::FormatStyle::ExperimentalAutoDetectBinPacking, clang::format::FormatStyle::FixNamespaceComments, clang::format::FormatStyle::ForEachMacros, clang::tooling::IncludeStyle::IBS_Preserve, clang::format::FormatStyle::IEBS_AfterExternBlock, clang::format::FormatStyle::IfMacros, clang::tooling::IncludeStyle::IncludeBlocks, clang::tooling::IncludeStyle::IncludeCategories, clang::tooling::IncludeStyle::IncludeIsMainRegex, clang::format::FormatStyle::IncludeStyle, clang::format::FormatStyle::IndentAccessModifiers, clang::format::FormatStyle::IndentCaseBlocks, clang::format::FormatStyle::IndentCaseLabels, clang::format::FormatStyle::IndentExternBlock, clang::format::FormatStyle::IndentGotoLabels, clang::format::FormatStyle::IndentPPDirectives, clang::format::FormatStyle::IndentRequiresClause, clang::format::FormatStyle::IndentWidth, clang::format::FormatStyle::IndentWrappedFunctionNames, clang::format::FormatStyle::InheritsParentConfig, clang::format::FormatStyle::InsertBraces, clang::format::FormatStyle::InsertTrailingCommas, clang::format::FormatStyle::isJson(), clang::format::FormatStyle::JavaScriptQuotes, clang::format::FormatStyle::JavaScriptWrapImports, clang::format::FormatStyle::JSQS_Leave, clang::format::FormatStyle::KeepEmptyLinesAtTheStartOfBlocks, clang::format::FormatStyle::LambdaBodyIndentation, clang::format::FormatStyle::Language, clang::format::FormatStyle::LBI_Signature, clang::format::FormatStyle::LK_TableGen, clang::format::FormatStyle::LS_Latest, clang::format::FormatStyle::MaxEmptyLinesToKeep, clang::format::FormatStyle::NamespaceIndentation, clang::format::FormatStyle::NI_None, clang::format::FormatStyle::OAS_Align, clang::format::FormatStyle::ObjCBinPackProtocolList, clang::format::FormatStyle::ObjCBlockIndentWidth, clang::format::FormatStyle::ObjCBreakBeforeNestedBlockParam, clang::format::FormatStyle::ObjCSpaceAfterProperty, clang::format::FormatStyle::ObjCSpaceBeforeProtocolList, clang::format::FormatStyle::PackConstructorInitializers, clang::format::FormatStyle::AlignConsecutiveStyle::PadOperators, clang::format::FormatStyle::PAS_Right, clang::format::FormatStyle::PCIS_BinPack, clang::format::FormatStyle::PenaltyBreakAssignment, clang::format::FormatStyle::PenaltyBreakBeforeFirstCallParameter, clang::format::FormatStyle::PenaltyBreakComment, clang::format::FormatStyle::PenaltyBreakFirstLessLess, clang::format::FormatStyle::PenaltyBreakOpenParenthesis, clang::format::FormatStyle::PenaltyBreakString, clang::format::FormatStyle::PenaltyBreakTemplateDeclaration, clang::format::FormatStyle::PenaltyExcessCharacter, clang::format::FormatStyle::PenaltyIndentedWhitespace, clang::format::FormatStyle::PenaltyReturnTypeOnItsOwnLine, clang::format::FormatStyle::PointerAlignment, clang::format::FormatStyle::PPDIS_None, clang::format::FormatStyle::PPIndentWidth, clang::format::FormatStyle::QAS_Leave, clang::format::FormatStyle::QualifierAlignment, clang::format::FormatStyle::RAS_Pointer, clang::format::FormatStyle::RCPS_OwnLine, clang::format::FormatStyle::ReferenceAlignment, clang::format::FormatStyle::ReflowComments, clang::prec::Relational, clang::format::FormatStyle::RemoveBracesLLVM, clang::format::FormatStyle::RequiresClausePosition, clang::format::FormatStyle::RTBS_None, clang::format::FormatStyle::SAPQ_Default, clang::format::FormatStyle::SBPO_ControlStatements, clang::format::FormatStyle::SBS_Never, clang::format::FormatStyle::SDS_Leave, clang::format::FormatStyle::SeparateDefinitionBlocks, clang::format::FormatStyle::SFS_All, clang::format::FormatStyle::ShortNamespaceLines, clang::format::FormatStyle::SI_CaseSensitive, clang::format::FormatStyle::SIAS_Never, clang::format::FormatStyle::SIS_Never, clang::format::FormatStyle::SJSIO_Before, clang::format::FormatStyle::SLS_All, clang::format::FormatStyle::SortIncludes, clang::format::FormatStyle::SortJavaStaticImport, clang::format::FormatStyle::SortUsingDeclarations, clang::format::FormatStyle::SpaceAfterCStyleCast, clang::format::FormatStyle::SpaceAfterLogicalNot, clang::format::FormatStyle::SpaceAfterTemplateKeyword, clang::format::FormatStyle::SpaceAroundPointerQualifiers, clang::format::FormatStyle::SpaceBeforeAssignmentOperators, clang::format::FormatStyle::SpaceBeforeCaseColon, clang::format::FormatStyle::SpaceBeforeCpp11BracedList, clang::format::FormatStyle::SpaceBeforeCtorInitializerColon, clang::format::FormatStyle::SpaceBeforeInheritanceColon, clang::format::FormatStyle::SpaceBeforeParens, clang::format::FormatStyle::SpaceBeforeParensOptions, clang::format::FormatStyle::SpaceBeforeRangeBasedForLoopColon, clang::format::FormatStyle::SpaceBeforeSquareBrackets, clang::format::FormatStyle::SpaceInEmptyBlock, clang::format::FormatStyle::SpaceInEmptyParentheses, clang::format::FormatStyle::SpacesBeforeTrailingComments, clang::format::FormatStyle::SpacesInAngles, clang::format::FormatStyle::SpacesInConditionalStatement, clang::format::FormatStyle::SpacesInContainerLiterals, clang::format::FormatStyle::SpacesInCStyleCastParentheses, clang::format::FormatStyle::SpacesInLineCommentPrefix, clang::format::FormatStyle::SpacesInParentheses, clang::format::FormatStyle::SpacesInSquareBrackets, clang::format::FormatStyle::Standard, clang::format::FormatStyle::StatementAttributeLikeMacros, clang::format::FormatStyle::StatementMacros, clang::format::FormatStyle::TabWidth, clang::format::FormatStyle::TCS_None, clang::format::FormatStyle::UseCRLF, clang::format::FormatStyle::UseTab, clang::format::FormatStyle::UT_Never, and clang::format::FormatStyle::WhitespaceSensitiveMacros.

Referenced by getGoogleStyle(), getMozillaStyle(), getNoStyle(), guessLanguage(), and clang::format::RawStringFormatStyleManager::RawStringFormatStyleManager().

◆ getMicrosoftStyle()

FormatStyle clang::format::getMicrosoftStyle ( FormatStyle::LanguageKind  Language)

Returns a format style complying with Microsoft style guide: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017.

Definition at line 1618 of file Format.cpp.

◆ getMozillaStyle()

FormatStyle clang::format::getMozillaStyle ( )

Returns a format style complying with Mozilla's style guide: https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.

Definition at line 1554 of file Format.cpp.

References clang::format::FormatStyle::AllowAllParametersOfDeclarationOnNextLine, clang::format::FormatStyle::AllowShortFunctionsOnASingleLine, clang::format::FormatStyle::AlwaysBreakAfterDefinitionReturnType, clang::format::FormatStyle::AlwaysBreakAfterReturnType, clang::format::FormatStyle::AlwaysBreakTemplateDeclarations, clang::format::FormatStyle::BCIS_BeforeComma, clang::format::FormatStyle::BILS_BeforeComma, clang::format::FormatStyle::BinPackArguments, clang::format::FormatStyle::BinPackParameters, clang::format::FormatStyle::BreakBeforeBraces, clang::format::FormatStyle::BreakConstructorInitializers, clang::format::FormatStyle::BreakInheritanceList, clang::format::FormatStyle::BS_Mozilla, clang::format::FormatStyle::BTDS_Yes, clang::format::FormatStyle::ConstructorInitializerIndentWidth, clang::format::FormatStyle::ContinuationIndentWidth, clang::format::FormatStyle::Cpp11BracedListStyle, clang::format::FormatStyle::DRTBS_TopLevel, clang::format::FormatStyle::FixNamespaceComments, getLLVMStyle(), clang::format::FormatStyle::IndentCaseLabels, clang::format::FormatStyle::ObjCSpaceAfterProperty, clang::format::FormatStyle::ObjCSpaceBeforeProtocolList, clang::format::FormatStyle::PAS_Left, clang::format::FormatStyle::PenaltyReturnTypeOnItsOwnLine, clang::format::FormatStyle::PointerAlignment, clang::format::FormatStyle::RTBS_TopLevel, clang::format::FormatStyle::SFS_Inline, and clang::format::FormatStyle::SpaceAfterTemplateKeyword.

◆ getNamespaceToken()

const FormatToken * clang::format::getNamespaceToken ( const AnnotatedLine Line,
const SmallVectorImpl< AnnotatedLine * > &  AnnotatedLines 
)

Definition at line 248 of file NamespaceEndCommentsFixer.cpp.

◆ getNamespaceTokenText()

StringRef clang::format::getNamespaceTokenText ( const AnnotatedLine Line,
const SmallVectorImpl< AnnotatedLine * > &  AnnotatedLines 
)

Definition at line 271 of file NamespaceEndCommentsFixer.cpp.

◆ getNoStyle()

FormatStyle clang::format::getNoStyle ( )

◆ getParseCategory()

const std::error_category & clang::format::getParseCategory ( )

Definition at line 1001 of file Format.cpp.

Referenced by make_error_code().

◆ getPredefinedStyle()

bool clang::format::getPredefinedStyle ( StringRef  Name,
FormatStyle::LanguageKind  Language,
FormatStyle Style 
)

Gets a predefined style for the specified language by name.

Currently supported names: LLVM, Google, Chromium, Mozilla. Names are compared case-insensitively.

Returns true if the Style has been set.

Definition at line 1656 of file Format.cpp.

Referenced by clang::format::RawStringFormatStyleManager::RawStringFormatStyleManager().

◆ getRawStringDelimiter()

static llvm::Optional<StringRef> clang::format::getRawStringDelimiter ( StringRef  TokenText)
static

Definition at line 151 of file ContinuationIndenter.cpp.

◆ getStringSplit()

static BreakableToken::Split clang::format::getStringSplit ( StringRef  Text,
unsigned  UsedColumns,
unsigned  ColumnLimit,
unsigned  TabWidth,
encoding::Encoding  Encoding 
)
static

◆ getStyle()

llvm::Expected< FormatStyle > clang::format::getStyle ( StringRef  StyleName,
StringRef  FileName,
StringRef  FallbackStyle,
StringRef  Code = "",
llvm::vfs::FileSystem *  FS = nullptr,
bool  AllowUnknownOptions = false 
)

Construct a FormatStyle based on StyleName.

StyleName can take several forms:

  • "{<key>: <value>, ...}" - Set specic style parameters.
  • "<style name>" - One of the style names supported by getPredefinedStyle().
  • "file" - Load style configuration from a file called .clang-format located in one of the parent directories of FileName or the current directory if FileName is empty.
  • "file:<format_file_path>" to explicitly specify the configuration file to use.
Parameters
[in]StyleNameStyle name to interpret according to the description above.
[in]FileNamePath to start search for .clang-format if StyleName == "file".
[in]FallbackStyleThe name of a predefined style used to fallback to in case StyleName is "file" and no file can be found.
[in]CodeThe actual code to be formatted. Used to determine the language if the filename isn't sufficient.
[in]FSThe underlying file system, in which the file resides. By default, the file system is the real file system.
[in]AllowUnknownOptionsIf true, unknown format options only emit a warning. If false, errors are emitted on unknown format options.
Returns
FormatStyle as specified by StyleName. If StyleName is "file" and no file is found, returns FallbackStyle. If no style could be determined, returns an Error.

Definition at line 3467 of file Format.cpp.

◆ getTokenTypeName()

const char * clang::format::getTokenTypeName ( TokenType  Type)

Determines the name of a token type.

Definition at line 24 of file FormatToken.cpp.

References LIST_TOKEN_TYPES, NUM_TOKEN_TYPES, and TokNames.

◆ getWebKitStyle()

FormatStyle clang::format::getWebKitStyle ( )

Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style.html.

Definition at line 1580 of file Format.cpp.

◆ guessLanguage()

FormatStyle::LanguageKind clang::format::guessLanguage ( StringRef  FileName,
StringRef  Code 
)

◆ hash_combine()

template<class T >
static void clang::format::hash_combine ( std::size_t seed,
const T &  v 
)
inlinestatic

◆ hasNestedBlockInlined()

static bool clang::format::hasNestedBlockInlined ( const FormatToken Previous,
const FormatToken Current,
const FormatStyle Style 
)
static

Definition at line 1224 of file ContinuationIndenter.cpp.

◆ insertQualifierAfter()

static void clang::format::insertQualifierAfter ( const SourceManager SourceMgr,
tooling::Replacements Fixes,
const FormatToken First,
const std::string Qualifier 
)
static

Definition at line 124 of file QualifierAlignmentFixer.cpp.

◆ insertQualifierBefore()

static void clang::format::insertQualifierBefore ( const SourceManager SourceMgr,
tooling::Replacements Fixes,
const FormatToken First,
const std::string Qualifier 
)
static

◆ isAllmanBrace()

static bool clang::format::isAllmanBrace ( const FormatToken Tok)
static

◆ isAllmanLambdaBrace()

static bool clang::format::isAllmanLambdaBrace ( const FormatToken Tok)
static

◆ IsBlank()

static bool clang::format::IsBlank ( char  C)
static

Definition at line 29 of file BreakableToken.cpp.

Referenced by getStringSplit().

◆ isC78ParameterDecl()

static bool clang::format::isC78ParameterDecl ( const FormatToken Tok,
const FormatToken Next,
const FormatToken FuncName 
)
static

Definition at line 1291 of file UnwrappedLineParser.cpp.

◆ isC78Type()

static bool clang::format::isC78Type ( const FormatToken Tok)
static

Definition at line 1278 of file UnwrappedLineParser.cpp.

References clang::format::FormatToken::isOneOf().

◆ isCOperatorFollowingVar()

static bool clang::format::isCOperatorFollowingVar ( tok::TokenKind  kind)
static

Definition at line 2939 of file UnwrappedLineParser.cpp.

◆ IsFunctionArgument()

static bool clang::format::IsFunctionArgument ( const FormatToken Tok)
static

◆ isFunctionDeclarationName()

static bool clang::format::isFunctionDeclarationName ( bool  IsCpp,
const FormatToken Current,
const AnnotatedLine Line 
)
static

Definition at line 2595 of file TokenAnnotator.cpp.

◆ isGoogScope()

static bool clang::format::isGoogScope ( const UnwrappedLine Line)
static

Definition at line 929 of file UnwrappedLineParser.cpp.

References Line.

◆ isIIFE()

static bool clang::format::isIIFE ( const UnwrappedLine Line,
const AdditionalKeywords Keywords 
)
static

Definition at line 947 of file UnwrappedLineParser.cpp.

◆ isItAnEmptyLambdaAllowed()

static bool clang::format::isItAnEmptyLambdaAllowed ( const FormatToken Tok,
FormatStyle::ShortLambdaStyle  ShortLambdaOption 
)
static

◆ isJSDeclOrStmt()

static bool clang::format::isJSDeclOrStmt ( const AdditionalKeywords Keywords,
const FormatToken FormatTok 
)
static

Definition at line 1258 of file UnwrappedLineParser.cpp.

◆ isLikelyXml()

bool clang::format::isLikelyXml ( StringRef  Code)

Definition at line 3004 of file Format.cpp.

◆ isMpegTS()

bool clang::format::isMpegTS ( StringRef  Code)

Definition at line 2997 of file Format.cpp.

◆ loadAndParseConfigFile()

llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer> > clang::format::loadAndParseConfigFile ( StringRef  ConfigFile,
llvm::vfs::FileSystem *  FS,
FormatStyle Style,
bool  AllowUnknownOptions 
)

Definition at line 3456 of file Format.cpp.

◆ make_error_code()

std::error_code clang::format::make_error_code ( ParseError  e)

Definition at line 1005 of file Format.cpp.

References getParseCategory().

◆ make_string_error()

llvm::Error clang::format::make_string_error ( const llvm::Twine &  Message)
inline

Definition at line 1009 of file Format.cpp.

◆ markOptionalBraces()

static void clang::format::markOptionalBraces ( FormatToken LeftBrace)
static

◆ maxNestingDepth()

static unsigned clang::format::maxNestingDepth ( const AnnotatedLine Line)
static

◆ mayReflowContent()

static bool clang::format::mayReflowContent ( StringRef  Content)
static

◆ mustBeJSIdent()

static bool clang::format::mustBeJSIdent ( const AdditionalKeywords Keywords,
const FormatToken FormatTok 
)
static

Definition at line 1234 of file UnwrappedLineParser.cpp.

◆ mustBeJSIdentOrValue()

static bool clang::format::mustBeJSIdentOrValue ( const AdditionalKeywords Keywords,
const FormatToken FormatTok 
)
static

Definition at line 1249 of file UnwrappedLineParser.cpp.

◆ opensProtoMessageField()

static bool clang::format::opensProtoMessageField ( const FormatToken LessTok,
const FormatStyle Style 
)
static

Definition at line 138 of file ContinuationIndenter.cpp.

◆ operator<()

bool clang::format::operator< ( const JsModuleReference LHS,
const JsModuleReference RHS 
)

◆ parseConfiguration() [1/2]

std::error_code clang::format::parseConfiguration ( llvm::MemoryBufferRef  Config,
FormatStyle Style,
bool  AllowUnknownOptions = false,
llvm::SourceMgr::DiagHandlerTy  DiagHandler = nullptr,
void *  DiagHandlerCtx = nullptr 
)

Parse configuration from YAML-formatted text.

Style->Language is used to get the base style, if the BasedOnStyle option is present.

The FormatStyleSet of Style is reset.

When BasedOnStyle is not present, options not present in the YAML document, are retained in Style.

If AllowUnknownOptions is true, no errors are emitted if unknown format options are occurred.

If set all diagnostics are emitted through the DiagHandler.

Definition at line 1717 of file Format.cpp.

◆ parseConfiguration() [2/2]

std::error_code clang::format::parseConfiguration ( StringRef  Config,
FormatStyle Style,
bool  AllowUnknownOptions = false 
)
inline

Like above but accepts an unnamed buffer.

Definition at line 4096 of file Format.h.

◆ printDebugInfo()

static LLVM_ATTRIBUTE_UNUSED void clang::format::printDebugInfo ( const UnwrappedLine Line,
StringRef  Prefix = "" 
)
static

◆ processReplacements()

template<typename T >
static llvm::Expected<tooling::Replacements> clang::format::processReplacements ( ProcessFunc,
StringRef  Code,
const tooling::Replacements Replaces,
const FormatStyle Style 
)
static

Definition at line 3027 of file Format.cpp.

◆ reformat() [1/2]

tooling::Replacements clang::format::reformat ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName,
bool IncompleteFormat 
)

Same as above, except if IncompleteFormat is non-null, its value will be set to true if any of the affected ranges were not formatted due to a non-recoverable syntax error.

Definition at line 3324 of file Format.cpp.

◆ reformat() [2/2]

tooling::Replacements clang::format::reformat ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName = "<stdin>",
FormattingAttemptStatus Status = nullptr 
)

Reformats the given Ranges in Code.

Each range is extended on either end to its next bigger logic unit, i.e. everything that might influence its formatting or might be influenced by its formatting.

Returns the Replacements necessary to make all Ranges comply with Style.

If Status is non-null, its value will be populated with the status of this formatting attempt. See FormattingAttemptStatus.

Definition at line 3301 of file Format.cpp.

Referenced by clang::tooling::applyAtomicChanges().

◆ removeToken()

static void clang::format::removeToken ( const SourceManager SourceMgr,
tooling::Replacements Fixes,
const FormatToken First 
)
static

◆ replaceCRLF()

std::string clang::format::replaceCRLF ( const std::string Code)

Definition at line 2607 of file Format.cpp.

References string().

◆ replaceToken()

static void clang::format::replaceToken ( const SourceManager SourceMgr,
tooling::Replacements Fixes,
const CharSourceRange Range,
std::string  NewText 
)
static

◆ rotateTokens()

static void clang::format::rotateTokens ( const SourceManager SourceMgr,
tooling::Replacements Fixes,
const FormatToken First,
const FormatToken Last,
bool  Left 
)
static

◆ separateDefinitionBlocks()

tooling::Replacements clang::format::separateDefinitionBlocks ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName = "<stdin>" 
)

Inserts or removes empty lines separating definition blocks including classes, structs, functions, namespaces, and enums in the given Ranges in Code.

Returns the Replacements that inserts or removes empty lines separating definition blocks in all Ranges in Code.

Definition at line 3344 of file Format.cpp.

◆ ShouldBreakBeforeBrace()

static bool clang::format::ShouldBreakBeforeBrace ( const FormatStyle Style,
const FormatToken InitialToken 
)
static

Definition at line 965 of file UnwrappedLineParser.cpp.

◆ shouldIndentWrappedSelectorName()

static bool clang::format::shouldIndentWrappedSelectorName ( const FormatStyle Style,
LineType  LineType 
)
static

Definition at line 32 of file ContinuationIndenter.cpp.

◆ sortCppIncludes() [1/2]

static void clang::format::sortCppIncludes ( const FormatStyle Style,
const SmallVectorImpl< IncludeDirective > &  Includes,
ArrayRef< tooling::Range Ranges,
StringRef  FileName,
StringRef  Code,
tooling::Replacements Replaces,
unsigned Cursor 
)
static

Definition at line 2635 of file Format.cpp.

◆ sortCppIncludes() [2/2]

tooling::Replacements clang::format::sortCppIncludes ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName,
tooling::Replacements Replaces,
unsigned Cursor 
)

Definition at line 2735 of file Format.cpp.

◆ sortIncludes()

tooling::Replacements clang::format::sortIncludes ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName,
unsigned Cursor = nullptr 
)

Returns the replacements necessary to sort all #include blocks that are affected by Ranges.

Definition at line 3006 of file Format.cpp.

Referenced by clang::tooling::applyAtomicChanges().

◆ sortJavaImports() [1/2]

static void clang::format::sortJavaImports ( const FormatStyle Style,
const SmallVectorImpl< JavaImportDirective > &  Imports,
ArrayRef< tooling::Range Ranges,
StringRef  FileName,
StringRef  Code,
tooling::Replacements Replaces 
)
static

Definition at line 2865 of file Format.cpp.

◆ sortJavaImports() [2/2]

tooling::Replacements clang::format::sortJavaImports ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName,
tooling::Replacements Replaces 
)

Definition at line 2945 of file Format.cpp.

◆ sortJavaScriptImports()

tooling::Replacements clang::format::sortJavaScriptImports ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName 
)

Definition at line 566 of file SortJavaScriptImports.cpp.

◆ sortUsingDeclarations()

tooling::Replacements clang::format::sortUsingDeclarations ( const FormatStyle Style,
StringRef  Code,
ArrayRef< tooling::Range Ranges,
StringRef  FileName = "<stdin>" 
)

Sort consecutive using declarations in the given Ranges in Code.

Returns the Replacements that sort the using declarations in all Ranges in Code.

Definition at line 3354 of file Format.cpp.

◆ startsNextParameter()

static bool clang::format::startsNextParameter ( const FormatToken Current,
const FormatStyle Style 
)
static

Definition at line 122 of file ContinuationIndenter.cpp.

◆ startsSegmentOfBuilderTypeCall()

static bool clang::format::startsSegmentOfBuilderTypeCall ( const FormatToken Tok)
static

◆ startsWithSpace()

static bool clang::format::startsWithSpace ( const std::string s)
static

Definition at line 158 of file QualifierAlignmentFixer.cpp.

References s.

Referenced by rotateTokens().

◆ switchesFormatting()

bool clang::format::switchesFormatting ( const FormatToken Token)

Checks if Token switches formatting, like /* clang-format off *‍/.

Token must be a comment.

Definition at line 217 of file BreakableToken.cpp.

References clang::Token::is().

Referenced by clang::format::BreakableBlockComment::mayReflow(), and clang::format::BreakableLineCommentSection::mayReflow().

◆ tokenCanStartNewLine()

static bool clang::format::tokenCanStartNewLine ( const FormatToken Tok)
static

Definition at line 1208 of file UnwrappedLineParser.cpp.

References clang::format::FormatToken::isNot().

◆ validateQualifierOrder()

ParseError clang::format::validateQualifierOrder ( FormatStyle Style)

Definition at line 1683 of file Format.cpp.

Variable Documentation

◆ Blanks

constexpr StringRef clang::format::Blanks = " \t\v\f\r"
staticconstexpr

◆ DefaultFallbackStyle

const char * clang::format::DefaultFallbackStyle = "LLVM"

The suggested predefined style to use as the fallback style in getStyle.

Different builds can modify the value to the preferred styles.

Definition at line 3453 of file Format.cpp.

◆ DefaultFormatStyle

const char * clang::format::DefaultFormatStyle = "file"

The suggested format style to use by default.

This allows tools using getStyle to have a consistent default style. Different builds can modify the value to the preferred styles.

Definition at line 3451 of file Format.cpp.

◆ StyleOptionHelpDescription

const char * clang::format::StyleOptionHelpDescription
Initial value:
=
"Coding style, currently supports:\n"
" LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit.\n"
"Use -style=file to load style configuration from\n"
".clang-format file located in one of the parent\n"
"directories of the source file (or current\n"
"directory for stdin).\n"
"Use -style=file:<format_file_path> to explicitly specify\n"
"the configuration file.\n"
"Use -style=\"{key: value, ...}\" to set specific\n"
"parameters, e.g.:\n"
" -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\""

Description to be used for help text for a llvm::cl option for specifying format style.

The description is closely related to the operation of getStyle().

Definition at line 3394 of file Format.cpp.