clang  3.9.0
Classes | Namespaces | Macros | Functions
Format.cpp File Reference

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

#include "clang/Format/Format.h"
#include "AffectedRangeManager.h"
#include "ContinuationIndenter.h"
#include "FormatTokenLexer.h"
#include "SortJavaScriptImports.h"
#include "TokenAnalyzer.h"
#include "TokenAnnotator.h"
#include "UnwrappedLineFormatter.h"
#include "UnwrappedLineParser.h"
#include "WhitespaceManager.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/VirtualFileSystem.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/YAMLTraits.h"
#include <algorithm>
#include <memory>
#include <queue>
#include <string>
Include dependency graph for Format.cpp:

Go to the source code of this file.

Classes

struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::LanguageKind >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::LanguageStandard >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::UseTabStyle >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::JavaScriptQuoteStyle >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ShortFunctionStyle >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BinaryOperatorStyle >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BraceBreakingStyle >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::ReturnTypeBreakingStyle >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::DefinitionReturnTypeBreakingStyle >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::NamespaceIndentationKind >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::BracketAlignmentStyle >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::PointerAlignmentStyle >
 
struct  llvm::yaml::ScalarEnumerationTraits< FormatStyle::SpaceBeforeParensOptions >
 
struct  llvm::yaml::MappingTraits< FormatStyle >
 
struct  llvm::yaml::MappingTraits< FormatStyle::BraceWrappingFlags >
 
struct  llvm::yaml::MappingTraits< FormatStyle::IncludeCategory >
 
struct  llvm::yaml::DocumentListTraits< std::vector< FormatStyle > >
 

Namespaces

 llvm
 DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterators.
 
 llvm::yaml
 
 clang
 Dataflow Directional Tag Classes.
 
 clang::format
 

Macros

#define DEBUG_TYPE   "format-formatter"
 

Functions

const std::error_category & clang::format::getParseCategory ()
 
std::error_code clang::format::make_error_code (ParseError e)
 
static FormatStyle clang::format::expandPresets (const FormatStyle &Style)
 
FormatStyle clang::format::getLLVMStyle ()
 Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards.html. More...
 
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. More...
 
FormatStyle clang::format::getChromiumStyle (FormatStyle::LanguageKind Language)
 Returns a format style complying with Chromium's style guide: http://www.chromium.org/developers/coding-style. More...
 
FormatStyle clang::format::getMozillaStyle ()
 Returns a format style complying with Mozilla's style guide: https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style. More...
 
FormatStyle clang::format::getWebKitStyle ()
 Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style.html. More...
 
FormatStyle clang::format::getGNUStyle ()
 Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standards.html. More...
 
FormatStyle clang::format::getNoStyle ()
 Returns style indicating formatting should be not applied at all. More...
 
bool clang::format::getPredefinedStyle (StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
 Gets a predefined style for the specified language by name. More...
 
std::error_code clang::format::parseConfiguration (StringRef Text, FormatStyle *Style)
 Parse configuration from YAML-formatted text. More...
 
std::string clang::format::configurationAsText (const FormatStyle &Style)
 Gets configuration in a YAML string. More...
 
static bool clang::format::affectsRange (ArrayRef< tooling::Range > Ranges, unsigned Start, unsigned End)
 
static void clang::format::sortCppIncludes (const FormatStyle &Style, const SmallVectorImpl< IncludeDirective > &Includes, ArrayRef< tooling::Range > Ranges, StringRef FileName, 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)
 
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. More...
 
template<typename T >
static llvm::Expected
< tooling::Replacements > 
clang::format::processReplacements (T ProcessFunc, StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
 
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. More...
 
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. More...
 
tooling::Replacements clang::format::reformat (const FormatStyle &Style, SourceManager &SourceMgr, FileID ID, ArrayRef< CharSourceRange > Ranges, bool *IncompleteFormat=nullptr)
 Reformats the given Ranges in the file ID. More...
 
tooling::Replacements clang::format::reformat (const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>", bool *IncompleteFormat=nullptr)
 Reformats the given Ranges in Code. More...
 
tooling::Replacements clang::format::cleanup (const FormatStyle &Style, SourceManager &SourceMgr, FileID ID, ArrayRef< CharSourceRange > Ranges)
 Clean up any erroneous/redundant code in the given Ranges in the file ID. More...
 
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. More...
 
LangOptions clang::format::getFormattingLangOpts (const FormatStyle &Style=getLLVMStyle())
 Returns the LangOpts that the formatter expects you to set. More...
 
static FormatStyle::LanguageKind clang::format::getLanguageByFileName (StringRef FileName)
 
FormatStyle clang::format::getStyle (StringRef StyleName, StringRef FileName, StringRef FallbackStyle, vfs::FileSystem *FS=nullptr)
 Construct a FormatStyle based on StyleName. More...
 

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

#define DEBUG_TYPE   "format-formatter"

Definition at line 42 of file Format.cpp.

Variable Documentation

bool BinPackInconclusiveFunctions

Definition at line 978 of file Format.cpp.

int Category
SmallVector<llvm::Regex, 4> CategoryRegexs

Definition at line 1315 of file Format.cpp.

std::set<unsigned> DeletedLines

Definition at line 1190 of file Format.cpp.

std::set<FormatToken *, FormatTokenLess> DeletedTokens

Definition at line 1188 of file Format.cpp.

StringRef Filename
StringRef FileName
StringRef FileStem

Definition at line 1314 of file Format.cpp.

bool* IncompleteFormat

Definition at line 979 of file Format.cpp.

bool IsMainFile

Definition at line 1312 of file Format.cpp.

Definition at line 1196 of file Format.cpp.

const SourceManager& SM

Definition at line 1184 of file Format.cpp.

Referenced by clang::ASTUnit::addFileLevelDecl(), addFixitForObjCARCConversion(), clang::arcmt::trans::MigrationContext::addPropertyAttribute(), clang::GCCAsmStmt::AnalyzeAsmString(), clang::tooling::Replacement::apply(), applyCocoaAPICheck(), applyEditsToTemp(), clang::CodeGen::CodeGenPGO::assignRegionCounters(), clang::ento::ProgramState::assumeInBound(), clang::CFGStmtMap::Build(), clang::ObjCMethodCall::canBeOverridenInSubclass(), checkAndSanitizeDiags(), checkObjCUnusedIvar(), compare(), comparePiece(), clang::ento::PathDiagnosticCallPiece::construct(), clang::Lexer::Create_PragmaLexer(), clang::ento::PathDiagnosticLocation::createBegin(), clang::ento::PathDiagnosticLocation::createConditionalColonLoc(), clang::ento::PathDiagnosticLocation::createEndOfPath(), clang::ento::PathDiagnosticLocation::createMemberLoc(), clang::ento::PathDiagnosticLocation::createOperatorLoc(), clang::DoRewriteTest(), clang::CodeGen::CodeGenModule::EmitAnnotationLineNo(), clang::CodeGen::CodeGenModule::EmitAnnotationUnit(), clang::DiagnosticNoteRenderer::emitBuildingModuleLocation(), clang::CodeGen::CoverageMappingGen::emitCounterMapping(), clang::DiagnosticRenderer::emitDiagnostic(), clang::CodeGen::CoverageMappingGen::emitEmptyMapping(), clang::DiagnosticNoteRenderer::emitImportLocation(), clang::DiagnosticNoteRenderer::emitIncludeLocation(), clang::markup::EmitLocation(), clang::CodeGenAction::ExecuteAction(), clang::DumpRawTokensAction::ExecuteAction(), clang::PrintPreprocessedAction::ExecuteAction(), clang::arcmt::trans::findSemiAfterLocation(), clang::tooling::formatAndApplyAllReplacements(), GCRewriteFinalize(), GenerateAlternateExtensivePathDiagnostic(), clang::ento::GRBugReporter::generatePathDiagnostic(), clang::Lexer::getAsCharRange(), getAsmSrcLocInfo(), getAsPointeeSymbol(), clang::CFGStmtMap::getBlock(), clang::ento::LikelyFalsePositiveSuppressionBRVisitor::getEndPath(), clang::ASTUnit::getLocation(), getLocationForCaller(), clang::ento::ProgramState::getLValue(), GetMappedTokenLoc(), clang::Preprocessor::getModuleHeaderToIncludeForDiagnostics(), clang::FunctionDecl::getReturnTypeSourceRange(), getTargetEntryUniqueInfo(), clang::VerifyDiagnosticConsumer::HandleComment(), clang::LogDiagnosticPrinter::HandleDiagnostic(), clang::html::HighlightMacros(), clang::html::HighlightRange(), clang::index::IndexingContext::importedModule(), clang::TokenLexer::Init(), isEmptyARCMTMacroStatement(), isExpandedFromConfigurationMacro(), clang::CodeGen::CodeGenModule::isInSanitizerBlacklist(), clang::ento::CallEvent::isInSystemHeader(), clang::TokenLexer::Lex(), LexRawTokensFromMainFile(), clang::LLVM_ALIGNAS(), clang::SrcMgr::LLVM_ALIGNAS(), LocPropertyAttribute(), makeStandaloneDiagnostic(), clang::BeforeThanCompare< RawComment >::operator()(), clang::BeforeThanCompare< SourceLocation >::operator()(), clang::BeforeThanCompare< SourceRange >::operator()(), ReadLineMarkerFlags(), ReportEvent(), clang::RewriteIncludesInInput(), clang::RewriteMacrosInInput(), clang::arcmt::trans::MigrationContext::rewritePropertyAttribute(), clang::ento::PathDiagnosticCallPiece::setCallee(), clang::CodeGen::CGDebugInfo::setLocation(), clang::Rewriter::setSourceMgr(), clang::html::SyntaxHighlight(), and clang::arcmt::trans::BlockObjCVariableTraverser::traverseBody().

const FormatStyle& Style
StringRef Text