diff options
author | Daniel Jasper <djasper@google.com> | 2012-12-03 18:12:45 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-12-03 18:12:45 +0000 |
commit | bac016bd3f67ca2f4db1ddc619e611759352b84d (patch) | |
tree | 82232dd80409934344e3f0c259da493e5fc35b0e /include/clang/Format/Format.h | |
parent | 189f2e421d06526ea8b4a3dcd9f4a072e10a859c (diff) |
Initial version of formatting library.
This formatting library will be used by a stand-alone clang-format tool
and can also be used when writing other refactorings.
Manuel's original design document:
https://docs.google.com/a/google.com/document/d/1gpckL2U_6QuU9YW2L1ABsc4Fcogn5UngKk7fE5dDOoA/edit
The library can already successfully format itself.
Review: http://llvm-reviews.chandlerc.com/D80
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169137 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Format/Format.h')
-rw-r--r-- | include/clang/Format/Format.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h new file mode 100644 index 0000000000..c2deccfda2 --- /dev/null +++ b/include/clang/Format/Format.h @@ -0,0 +1,75 @@ +//===--- Format.h - Format C++ code -----------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Various functions to configurably format source code. +/// +/// This is EXPERIMENTAL code under heavy development. It is not in a state yet, +/// where it can be used to format real code. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_FORMAT_FORMAT_H_ +#define LLVM_CLANG_FORMAT_FORMAT_H + +#include "clang/Frontend/FrontendAction.h" +#include "clang/Tooling/Refactoring.h" + +namespace clang { + +class Lexer; +class SourceManager; + +namespace format { + +/// \brief The \c FormatStyle is used to configure the formatting to follow +/// specific guidelines. +struct FormatStyle { + /// \brief The column limit. + unsigned ColumnLimit; + + /// \brief The maximum number of consecutive empty lines to keep. + unsigned MaxEmptyLinesToKeep; + + /// \brief Set whether & and * bind to the type as opposed to the variable. + bool PointerAndReferenceBindToType; + + /// \brief The extra indent or outdent of access modifiers (e.g.: public:). + int AccessModifierOffset; + + /// \brief Split two consecutive closing '>' by a space, i.e. use + /// A<A<int> > instead of A<A<int>>. + bool SplitTemplateClosingGreater; +}; + +/// \brief Returns a format style complying with the LLVM coding standards: +/// http://llvm.org/docs/CodingStandards.html. +FormatStyle getLLVMStyle(); + +/// \brief Returns a format style complying with Google's C++ style guide: +/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. +FormatStyle getGoogleStyle(); + +/// \brief Reformats the given \p Ranges in the token stream coming out of +/// \c Lex. +/// +/// 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 \c Replacements necessary to make all \p Ranges comply with +/// \p Style. +tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, + SourceManager &SourceMgr, + std::vector<CharSourceRange> Ranges); + +} // end namespace format +} // end namespace clang + +#endif // LLVM_CLANG_FORMAT_FORMAT_H |