clang 24.0.0git
Format.cpp File Reference

This file implements functions declared in Format.h. More...

#include "clang/Format/Format.h"
#include "DefinitionBlockSeparator.h"
#include "IntegerLiteralSeparatorFixer.h"
#include "NamespaceEndCommentsFixer.h"
#include "NumericLiteralCaseFixer.h"
#include "ObjCPropertyAttributeOrderFixer.h"
#include "QualifierAlignmentFixer.h"
#include "SortJavaScriptImports.h"
#include "UnwrappedLineFormatter.h"
#include "UsingDeclarationsSorter.h"
#include "clang/Tooling/Inclusions/HeaderIncludes.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/StringSet.h"
#include <functional>
#include <limits>
#include "clang/Basic/TokenKinds.def"

Go to the source code of this file.

Classes

struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BreakBeforeNoexceptSpecifierStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::AlignConsecutiveStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::ShortCaseStatementsAlignmentStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::AttributeBreakingStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ArrayInitializerAlignmentStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BinaryOperatorStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BinPackArgumentsStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BinPackParametersStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BinPackStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BitFieldColonSpacingStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BraceBreakingStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::BraceWrappingFlags >
struct  llvm::yaml::ScalarEnumerationTraits< BracketAlignmentStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BraceWrappingAfterControlStatementStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BreakBeforeConceptDeclarationsStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BreakBeforeInlineASMColonStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BreakBinaryOperationsStyle >
struct  llvm::yaml::ScalarTraits< clang::tok::TokenKind >
struct  llvm::yaml::MappingTraits< FormatStyle::BinaryOperationBreakRule >
struct  llvm::yaml::MappingTraits< FormatStyle::BreakBinaryOperationsOptions >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BreakConstructorInitializersStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BreakInheritanceListStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BreakTemplateDeclarationsStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BracedListStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::DAGArgStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::DefinitionReturnTypeBreakingStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::EscapedNewlineAlignmentStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::EmptyLineAfterAccessModifierStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::EmptyLineBeforeAccessModifierStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::EnumTrailingCommaStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::IndentExternBlockStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::IntegerLiteralSeparatorStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::JavaScriptQuoteStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::KeepEmptyLinesStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::LanguageKind >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::LanguageStandard >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::LambdaBodyIndentationKind >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::LineEndingStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::NamespaceIndentationKind >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::NumericLiteralComponentStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::NumericLiteralCaseStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::OperandAlignmentStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::PackParametersStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::PackConstructorInitializersStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::PackArgumentsStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::PointerAlignmentStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::PPDirectiveIndentStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::QualifierAlignmentStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::RawStringFormat >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ReflowCommentsStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ReferenceAlignmentStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::RemoveParenthesesStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::RequiresClausePositionStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::RequiresExpressionIndentationKind >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ReturnTypeBreakingStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BreakBeforeReturnTypeStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SeparateDefinitionStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ShortBlockStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::ShortFunctionStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ShortIfStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ShortLambdaStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ShortRecordStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::SortIncludesOptions >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SortJavaStaticImportOptions >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SortUsingDeclarationsOptions >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SpaceAroundPointerQualifiersStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::SpaceBeforeParensCustom >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SpaceBeforeParensStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SpaceInEmptyBracesStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SpacesInAnglesStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SpacesInBlockCommentsStyle >
struct  llvm::yaml::MappingTraits< FormatStyle::SpacesInLineComment >
struct  llvm::yaml::MappingTraits< FormatStyle::SpacesInParensCustom >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SpacesInParensStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::TrailingCommaStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::TrailingCommentsAlignmentKinds >
struct  llvm::yaml::MappingTraits< FormatStyle::TrailingCommentsAlignmentStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::UseTabStyle >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle >
struct  llvm::yaml::MappingTraits< FormatStyle >
struct  llvm::yaml::DocumentListTraits< std::vector< FormatStyle > >
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::IndentGotoLabelStyle >
struct  FormatStyle
 The FormatStyle is used to configure the formatting to follow specific guidelines. More...

Namespaces

namespace  llvm
 Diagnostic wrappers for TextAPI types for error reporting.
namespace  llvm::yaml
namespace  clang
 Top level wrappers for InstallAPI frontend operations.
namespace  clang::format
namespace  clang::format::internal

Macros

#define DEBUG_TYPE   "format-formatter"
#define PUNCTUATOR(Name, Spelling)

Enumerations

enum  BracketAlignmentStyle : int8_t {
  BAS_Align , BAS_DontAlign , BAS_AlwaysBreak , BAS_BlockIndent ,
  BAS_Ignore
}

Functions

const std::error_category & clang::format::getParseCategory ()
std::error_code clang::format::make_error_code (ParseError e)
llvm::Error clang::format::make_string_error (const Twine &Message)
static void clang::format::expandPresetsBraceWrapping (FormatStyle &Expanded)
static void clang::format::expandPresetsSpaceBeforeParens (FormatStyle &Expanded)
static void clang::format::expandPresetsSpacesInParens (FormatStyle &Expanded)
FormatStyle clang::format::getLLVMStyle (FormatStyle::LanguageKind Language=FormatStyle::LK_Cpp)
 Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards.html.
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.
FormatStyle clang::format::getChromiumStyle (FormatStyle::LanguageKind Language)
 Returns a format style complying with Chromium's style guide: http://www.chromium.org/developers/coding-style.
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.
FormatStyle clang::format::getWebKitStyle ()
 Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style.html.
FormatStyle clang::format::getGNUStyle ()
 Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standards.html.
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.
FormatStyle clang::format::getClangFormatStyle ()
FormatStyle clang::format::getNoStyle ()
 Returns style indicating formatting should be not applied at all.
bool clang::format::getPredefinedStyle (StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
 Gets a predefined style for the specified language by name.
ParseError clang::format::validateQualifierOrder (FormatStyle *Style)
std::error_code clang::format::parseConfiguration (llvm::MemoryBufferRef Config, FormatStyle *Style, bool AllowUnknownOptions=false, llvm::SourceMgr::DiagHandlerTy DiagHandler=nullptr, void *DiagHandlerCtx=nullptr, bool IsDotHFile=false)
 Parse configuration from YAML-formatted text.
std::string clang::format::configurationAsText (const FormatStyle &Style)
 Gets configuration in a YAML string.
static bool clang::format::affectsRange (ArrayRef< tooling::Range > Ranges, unsigned Start, unsigned End)
static std::pair< unsigned, unsignedclang::format::FindCursorIndex (const ArrayRef< IncludeDirective > &Includes, const ArrayRef< unsigned > &Indices, unsigned Cursor)
std::string clang::format::replaceCRLF (const std::string &Code)
static void clang::format::sortCppIncludes (const FormatStyle &Style, const ArrayRef< IncludeDirective > &Includes, ArrayRef< tooling::Range > Ranges, StringRef FileName, StringRef Code, tooling::Replacements &Replaces, unsigned *Cursor)
tooling::Replacements clang::format::sortCppIncludes (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, tooling::Replacements &Replaces, unsigned *Cursor)
static unsigned clang::format::findJavaImportGroup (const FormatStyle &Style, StringRef ImportIdentifier)
static void clang::format::sortJavaImports (const FormatStyle &Style, const ArrayRef< JavaImportDirective > &Imports, ArrayRef< tooling::Range > Ranges, StringRef FileName, StringRef Code, tooling::Replacements &Replaces)
tooling::Replacements clang::format::sortJavaImports (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, tooling::Replacements &Replaces)
bool clang::format::isMpegTS (StringRef Code)
bool clang::format::isLikelyXml (StringRef Code)
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.
template<typename T>
static Expected< tooling::Replacementsclang::format::processReplacements (T ProcessFunc, StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Expected< tooling::Replacementsclang::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.
Expected< tooling::Replacementsclang::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.
std::pair< tooling::Replacements, unsignedclang::format::internal::reformat (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, unsigned FirstStartColumn, unsigned NextStartColumn, unsigned LastStartColumn, StringRef FileName, FormattingAttemptStatus *Status)
 Reformats the given Ranges in the code fragment Code.
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.
tooling::Replacements clang::format::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.
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.
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.
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.
LangOptions clang::format::getFormattingLangOpts (const FormatStyle &Style=getLLVMStyle())
 Returns the LangOpts that the formatter expects you to set.
static FormatStyle::LanguageKind clang::format::getLanguageByFileName (StringRef &FileName)
static FormatStyle::LanguageKind clang::format::getLanguageByComment (const Environment &Env)
FormatStyle::LanguageKind clang::format::guessLanguage (StringRef FileName, StringRef Code)
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > clang::format::loadAndParseConfigFile (StringRef ConfigFile, llvm::vfs::FileSystem *FS, FormatStyle *Style, bool AllowUnknownOptions, llvm::SourceMgr::DiagHandlerTy DiagHandler, bool IsDotHFile)
Expected< FormatStyleclang::format::getStyle (StringRef StyleName, StringRef FileName, StringRef FallbackStyle, StringRef Code="", llvm::vfs::FileSystem *FS=nullptr, bool AllowUnknownOptions=false, llvm::SourceMgr::DiagHandlerTy DiagHandler=nullptr)
 Construct a FormatStyle based on StyleName.
static bool clang::format::isClangFormatOnOff (StringRef Comment, bool On)
bool clang::format::isClangFormatOn (StringRef Comment)
bool clang::format::isClangFormatOff (StringRef Comment)

Detailed Description

This file implements functions declared in Format.h.

This will be split into separate files as we go.

Definition in file Format.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "format-formatter"

Definition at line 31 of file Format.cpp.

◆ PUNCTUATOR

#define PUNCTUATOR ( Name,
Spelling )
Value:
if (Scalar == Spelling) { \
Value = clang::tok::Name; \
return {}; \
}

Enumeration Type Documentation

◆ BracketAlignmentStyle

Enumerator
BAS_Align 
BAS_DontAlign 
BAS_AlwaysBreak 
BAS_BlockIndent 
BAS_Ignore 

Definition at line 39 of file Format.cpp.