clang 19.0.0git
Classes | Namespaces | Enumerations | Functions | Variables
Format.h File Reference

Various functions to configurably format source code. More...

#include "clang/Basic/LangOptions.h"
#include "clang/Tooling/Core/Replacement.h"
#include "clang/Tooling/Inclusions/IncludeStyle.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/SourceMgr.h"
#include <optional>
#include <system_error>

Go to the source code of this file.

Classes

class  clang::format::ParseErrorCategory
 
struct  clang::format::FormatStyle
 The FormatStyle is used to configure the formatting to follow specific guidelines. More...
 
struct  clang::format::FormatStyle::AlignConsecutiveStyle
 Alignment options. More...
 
struct  clang::format::FormatStyle::ShortCaseStatementsAlignmentStyle
 Alignment options. More...
 
struct  clang::format::FormatStyle::TrailingCommentsAlignmentStyle
 Alignment options. More...
 
struct  clang::format::FormatStyle::BraceWrappingFlags
 Precise control over the wrapping of braces. More...
 
struct  clang::format::FormatStyle::IntegerLiteralSeparatorStyle
 Separator format of integer literals of different bases. More...
 
struct  clang::format::FormatStyle::KeepEmptyLinesStyle
 Options regarding which empty lines are kept. More...
 
struct  clang::format::FormatStyle::RawStringFormat
 See documentation of RawStringFormats. More...
 
struct  clang::format::FormatStyle::SpaceBeforeParensCustom
 Precise control over the spacing before parentheses. More...
 
struct  clang::format::FormatStyle::SpacesInLineComment
 If true, spaces may be inserted into C style casts. More...
 
struct  clang::format::FormatStyle::SpacesInParensCustom
 Precise control over the spacing in parentheses. More...
 
struct  clang::format::FormatStyle::FormatStyleSet
 
struct  clang::format::FormattingAttemptStatus
 Represents the status of a formatting attempt. More...
 
struct  std::is_error_code_enum< clang::format::ParseError >
 

Namespaces

namespace  llvm
 Diagnostic wrappers for TextAPI types for error reporting.
 
namespace  llvm::vfs
 
namespace  clang
 The JSON file list parser is used to communicate input to InstallAPI.
 
namespace  clang::format
 

Enumerations

enum class  clang::format::ParseError {
  clang::format::Success = 0 , clang::format::Error , clang::format::Unsuitable , clang::format::BinPackTrailingCommaConflict ,
  clang::format::InvalidQualifierSpecified , clang::format::DuplicateQualifierSpecified , clang::format::MissingQualifierType , clang::format::MissingQualifierOrder
}
 

Functions

const std::error_category & clang::format::getParseCategory ()
 
std::error_code clang::format::make_error_code (ParseError e)
 
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.
 
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.
 
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.
 
std::error_code clang::format::parseConfiguration (StringRef Config, FormatStyle *Style, bool AllowUnknownOptions=false)
 Like above but accepts an unnamed buffer.
 
std::string clang::format::configurationAsText (const FormatStyle &Style)
 Gets configuration in a YAML string.
 
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.
 
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.
 
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.
 
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::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::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::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::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.
 
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.
 
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.
 
FormatStyle::LanguageKind clang::format::guessLanguage (StringRef FileName, StringRef Code)
 
StringRef clang::format::getLanguageName (FormatStyle::LanguageKind Language)
 
bool clang::format::isClangFormatOn (StringRef Comment)
 
bool clang::format::isClangFormatOff (StringRef Comment)
 

Variables

const char * clang::format::StyleOptionHelpDescription
 Description to be used for help text for a llvm::cl option for specifying format style.
 
const char * clang::format::DefaultFormatStyle = "file"
 The suggested format style to use by default.
 
const char * clang::format::DefaultFallbackStyle = "LLVM"
 The suggested predefined style to use as the fallback style in getStyle.
 

Detailed Description

Various functions to configurably format source code.

Definition in file Format.h.