2013-06-04 00:45:03 +08:00
|
|
|
//===--- FormatToken.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
|
|
|
|
/// \brief This file contains the declaration of the FormatToken, a wrapper
|
|
|
|
/// around Token with additional information related to formatting.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_FORMAT_FORMATTOKEN_H
|
|
|
|
#define LLVM_CLANG_LIB_FORMAT_FORMATTOKEN_H
|
2013-06-04 00:45:03 +08:00
|
|
|
|
2014-11-04 20:41:02 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2013-06-04 00:45:03 +08:00
|
|
|
#include "clang/Basic/OperatorPrecedence.h"
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
#include "clang/Format/Format.h"
|
2013-06-04 00:45:03 +08:00
|
|
|
#include "clang/Lex/Lexer.h"
|
2014-03-09 19:36:40 +08:00
|
|
|
#include <memory>
|
2013-06-04 00:45:03 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace format {
|
|
|
|
|
|
|
|
enum TokenType {
|
2013-10-22 23:30:28 +08:00
|
|
|
TT_ArrayInitializerLSquare,
|
|
|
|
TT_ArraySubscriptLSquare,
|
2014-01-29 04:13:43 +08:00
|
|
|
TT_AttributeParen,
|
2013-06-04 00:45:03 +08:00
|
|
|
TT_BinaryOperator,
|
2013-10-10 21:36:20 +08:00
|
|
|
TT_BitFieldColon,
|
2013-06-04 00:45:03 +08:00
|
|
|
TT_BlockComment,
|
|
|
|
TT_CastRParen,
|
|
|
|
TT_ConditionalExpr,
|
2014-04-14 17:14:11 +08:00
|
|
|
TT_ConflictAlternative,
|
|
|
|
TT_ConflictEnd,
|
|
|
|
TT_ConflictStart,
|
2013-06-04 00:45:03 +08:00
|
|
|
TT_CtorInitializerColon,
|
2013-07-27 00:56:36 +08:00
|
|
|
TT_CtorInitializerComma,
|
2013-06-04 00:45:03 +08:00
|
|
|
TT_DesignatedInitializerPeriod,
|
2013-10-24 18:31:50 +08:00
|
|
|
TT_DictLiteral,
|
2014-07-09 15:50:33 +08:00
|
|
|
TT_FunctionDeclarationName,
|
2013-11-21 00:33:05 +08:00
|
|
|
TT_FunctionLBrace,
|
2013-06-04 00:45:03 +08:00
|
|
|
TT_FunctionTypeLParen,
|
2014-04-14 17:14:11 +08:00
|
|
|
TT_ImplicitStringLiteral,
|
|
|
|
TT_InheritanceColon,
|
|
|
|
TT_InlineASMColon,
|
2014-10-21 16:24:18 +08:00
|
|
|
TT_JavaAnnotation,
|
2014-11-21 20:14:12 +08:00
|
|
|
TT_LambdaArrow,
|
2013-09-05 17:29:45 +08:00
|
|
|
TT_LambdaLSquare,
|
2014-11-01 02:23:49 +08:00
|
|
|
TT_LeadingJavaAnnotation,
|
2013-06-04 00:45:03 +08:00
|
|
|
TT_LineComment,
|
2014-03-27 17:43:54 +08:00
|
|
|
TT_ObjCBlockLBrace,
|
2014-04-14 17:14:11 +08:00
|
|
|
TT_ObjCBlockLParen,
|
2013-06-04 00:45:03 +08:00
|
|
|
TT_ObjCDecl,
|
|
|
|
TT_ObjCForIn,
|
|
|
|
TT_ObjCMethodExpr,
|
|
|
|
TT_ObjCMethodSpecifier,
|
|
|
|
TT_ObjCProperty,
|
|
|
|
TT_OverloadedOperator,
|
|
|
|
TT_OverloadedOperatorLParen,
|
|
|
|
TT_PointerOrReference,
|
|
|
|
TT_PureVirtualSpecifier,
|
|
|
|
TT_RangeBasedForLoopColon,
|
2014-05-08 15:01:45 +08:00
|
|
|
TT_RegexLiteral,
|
2014-06-10 22:44:02 +08:00
|
|
|
TT_SelectorName,
|
2013-06-04 00:45:03 +08:00
|
|
|
TT_StartOfName,
|
|
|
|
TT_TemplateCloser,
|
|
|
|
TT_TemplateOpener,
|
2013-12-16 23:01:54 +08:00
|
|
|
TT_TrailingAnnotation,
|
2013-07-09 22:36:48 +08:00
|
|
|
TT_TrailingReturnArrow,
|
2013-06-04 00:45:03 +08:00
|
|
|
TT_TrailingUnaryOperator,
|
|
|
|
TT_UnaryOperator,
|
|
|
|
TT_Unknown
|
|
|
|
};
|
|
|
|
|
2013-07-09 17:06:29 +08:00
|
|
|
// Represents what type of block a set of braces open.
|
|
|
|
enum BraceBlockKind {
|
|
|
|
BK_Unknown,
|
|
|
|
BK_Block,
|
|
|
|
BK_BracedInit
|
|
|
|
};
|
|
|
|
|
2013-07-10 22:02:49 +08:00
|
|
|
// The packing kind of a function's parameters.
|
|
|
|
enum ParameterPackingKind {
|
|
|
|
PPK_BinPacked,
|
|
|
|
PPK_OnePerLine,
|
|
|
|
PPK_Inconclusive
|
|
|
|
};
|
|
|
|
|
2013-10-12 05:25:45 +08:00
|
|
|
enum FormatDecision {
|
|
|
|
FD_Unformatted,
|
|
|
|
FD_Continue,
|
|
|
|
FD_Break
|
|
|
|
};
|
|
|
|
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
class TokenRole;
|
2013-09-05 17:29:45 +08:00
|
|
|
class AnnotatedLine;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
/// \brief A wrapper around a \c Token storing information about the
|
2013-12-06 00:25:25 +08:00
|
|
|
/// whitespace characters preceding it.
|
2013-06-04 00:45:03 +08:00
|
|
|
struct FormatToken {
|
|
|
|
FormatToken()
|
2013-09-02 21:58:14 +08:00
|
|
|
: NewlinesBefore(0), HasUnescapedNewline(false), LastNewlineOffset(0),
|
2013-09-10 17:38:25 +08:00
|
|
|
ColumnWidth(0), LastLineColumnWidth(0), IsMultiline(false),
|
2013-09-02 21:58:14 +08:00
|
|
|
IsFirst(false), MustBreakBefore(false), IsUnterminatedLiteral(false),
|
2013-08-30 01:32:57 +08:00
|
|
|
BlockKind(BK_Unknown), Type(TT_Unknown), SpacesRequiredBefore(0),
|
|
|
|
CanBreakBefore(false), ClosesTemplateDeclaration(false),
|
2014-06-03 20:02:45 +08:00
|
|
|
ParameterCount(0), BlockParameterCount(0),
|
|
|
|
PackingKind(PPK_Inconclusive), TotalLength(0), UnbreakableTailLength(0),
|
|
|
|
BindingStrength(0), NestingLevel(0), SplitPenalty(0),
|
|
|
|
LongestObjCSelectorName(0), FakeRParens(0),
|
2013-09-06 16:08:14 +08:00
|
|
|
StartsBinaryExpression(false), EndsBinaryExpression(false),
|
2014-04-16 20:26:54 +08:00
|
|
|
OperatorIndex(0), LastOperator(false),
|
|
|
|
PartOfMultiVariableDeclStmt(false), IsForEachMacro(false),
|
2014-05-09 16:15:10 +08:00
|
|
|
MatchingParen(nullptr), Previous(nullptr), Next(nullptr),
|
2013-10-12 05:25:45 +08:00
|
|
|
Decision(FD_Unformatted), Finalized(false) {}
|
2013-06-04 00:45:03 +08:00
|
|
|
|
|
|
|
/// \brief The \c Token.
|
|
|
|
Token Tok;
|
|
|
|
|
|
|
|
/// \brief The number of newlines immediately before the \c Token.
|
|
|
|
///
|
|
|
|
/// This can be used to determine what the user wrote in the original code
|
|
|
|
/// and thereby e.g. leave an empty line between two function definitions.
|
|
|
|
unsigned NewlinesBefore;
|
|
|
|
|
|
|
|
/// \brief Whether there is at least one unescaped newline before the \c
|
|
|
|
/// Token.
|
|
|
|
bool HasUnescapedNewline;
|
|
|
|
|
2013-12-06 00:25:25 +08:00
|
|
|
/// \brief The range of the whitespace immediately preceding the \c Token.
|
2013-06-04 00:45:03 +08:00
|
|
|
SourceRange WhitespaceRange;
|
|
|
|
|
|
|
|
/// \brief The offset just past the last '\n' in this token's leading
|
|
|
|
/// whitespace (relative to \c WhiteSpaceStart). 0 if there is no '\n'.
|
|
|
|
unsigned LastNewlineOffset;
|
|
|
|
|
2013-09-10 17:38:25 +08:00
|
|
|
/// \brief The width of the non-whitespace parts of the token (or its first
|
|
|
|
/// line for multi-line tokens) in columns.
|
2013-06-05 22:09:10 +08:00
|
|
|
/// We need this to correctly measure number of columns a token spans.
|
2013-09-10 17:38:25 +08:00
|
|
|
unsigned ColumnWidth;
|
2013-06-04 00:45:03 +08:00
|
|
|
|
2013-09-10 17:38:25 +08:00
|
|
|
/// \brief Contains the width in columns of the last line of a multi-line
|
2013-09-02 21:58:14 +08:00
|
|
|
/// token.
|
2013-09-05 22:08:34 +08:00
|
|
|
unsigned LastLineColumnWidth;
|
2013-09-02 21:58:14 +08:00
|
|
|
|
2013-09-10 17:38:25 +08:00
|
|
|
/// \brief Whether the token text contains newlines (escaped or not).
|
|
|
|
bool IsMultiline;
|
2013-09-02 21:58:14 +08:00
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
/// \brief Indicates that this is the first token.
|
|
|
|
bool IsFirst;
|
|
|
|
|
|
|
|
/// \brief Whether there must be a line break before this token.
|
|
|
|
///
|
|
|
|
/// This happens for example when a preprocessor directive ended directly
|
|
|
|
/// before the token.
|
|
|
|
bool MustBreakBefore;
|
|
|
|
|
|
|
|
/// \brief Returns actual token start location without leading escaped
|
|
|
|
/// newlines and whitespace.
|
|
|
|
///
|
|
|
|
/// This can be different to Tok.getLocation(), which includes leading escaped
|
|
|
|
/// newlines.
|
|
|
|
SourceLocation getStartOfNonWhitespace() const {
|
|
|
|
return WhitespaceRange.getEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief The raw text of the token.
|
|
|
|
///
|
|
|
|
/// Contains the raw token text without leading whitespace and without leading
|
|
|
|
/// escaped newlines.
|
|
|
|
StringRef TokenText;
|
|
|
|
|
2013-07-17 04:28:33 +08:00
|
|
|
/// \brief Set to \c true if this token is an unterminated literal.
|
|
|
|
bool IsUnterminatedLiteral;
|
|
|
|
|
2013-07-09 17:06:29 +08:00
|
|
|
/// \brief Contains the kind of block if this token is a brace.
|
|
|
|
BraceBlockKind BlockKind;
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
TokenType Type;
|
|
|
|
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
/// \brief The number of spaces that should be inserted before this token.
|
2013-06-04 00:45:03 +08:00
|
|
|
unsigned SpacesRequiredBefore;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
|
|
|
|
/// \brief \c true if it is allowed to break before this token.
|
2013-06-04 00:45:03 +08:00
|
|
|
bool CanBreakBefore;
|
|
|
|
|
|
|
|
bool ClosesTemplateDeclaration;
|
|
|
|
|
|
|
|
/// \brief Number of parameters, if this is "(", "[" or "<".
|
|
|
|
///
|
|
|
|
/// This is initialized to 1 as we don't need to distinguish functions with
|
|
|
|
/// 0 parameters from functions with 1 parameter. Thus, we can simply count
|
|
|
|
/// the number of commas.
|
|
|
|
unsigned ParameterCount;
|
|
|
|
|
2014-06-03 20:02:45 +08:00
|
|
|
/// \brief Number of parameters that are nested blocks,
|
|
|
|
/// if this is "(", "[" or "<".
|
|
|
|
unsigned BlockParameterCount;
|
|
|
|
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
/// \brief A token can have a special role that can carry extra information
|
|
|
|
/// about the token's formatting.
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<TokenRole> Role;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
|
2013-07-10 22:02:49 +08:00
|
|
|
/// \brief If this is an opening parenthesis, how are the parameters packed?
|
|
|
|
ParameterPackingKind PackingKind;
|
|
|
|
|
2013-08-29 23:21:40 +08:00
|
|
|
/// \brief The total length of the unwrapped line up to and including this
|
|
|
|
/// token.
|
2013-06-04 00:45:03 +08:00
|
|
|
unsigned TotalLength;
|
|
|
|
|
2013-09-10 17:38:25 +08:00
|
|
|
/// \brief The original 0-based column of this token, including expanded tabs.
|
|
|
|
/// The configured TabWidth is used as tab width.
|
2013-08-29 23:21:40 +08:00
|
|
|
unsigned OriginalColumn;
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
/// \brief The length of following tokens until the next natural split point,
|
|
|
|
/// or the next token that can be broken.
|
|
|
|
unsigned UnbreakableTailLength;
|
|
|
|
|
|
|
|
// FIXME: Come up with a 'cleaner' concept.
|
|
|
|
/// \brief The binding strength of a token. This is a combined value of
|
|
|
|
/// operator precedence, parenthesis nesting, etc.
|
|
|
|
unsigned BindingStrength;
|
|
|
|
|
clang-format: Be more conservative about braced list column layout.
Specifically disable it for nested braced lists as it commonly can look
really weird. Eventually, we'll want to become smarter and format some of
the nested lists better.
Before:
SomeStruct my_struct_array = {
{ aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa,
aaaaaaaaaa, aaaaaaaaaa, aaaaaaa, aaa },
{ aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa },
{ aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaa, a, aaaaaaaaaa,
aaaaaaaaa, aaa },
};
After:
SomeStruct my_struct_array = {
{ aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa, aaaaaaaaaa,
aaaaaaaaaaaa, aaaaaaa, aaa },
{ aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa },
{ aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa },
};
llvm-svn: 196783
2013-12-09 22:40:19 +08:00
|
|
|
/// \brief The nesting level of this token, i.e. the number of surrounding (),
|
|
|
|
/// [], {} or <>.
|
|
|
|
unsigned NestingLevel;
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
/// \brief Penalty for inserting a line break before this token.
|
|
|
|
unsigned SplitPenalty;
|
|
|
|
|
|
|
|
/// \brief If this is the first ObjC selector name in an ObjC method
|
|
|
|
/// definition or call, this contains the length of the longest name.
|
2013-12-23 15:29:06 +08:00
|
|
|
///
|
|
|
|
/// This being set to 0 means that the selectors should not be colon-aligned,
|
|
|
|
/// e.g. because several of them are block-type.
|
2013-06-04 00:45:03 +08:00
|
|
|
unsigned LongestObjCSelectorName;
|
|
|
|
|
|
|
|
/// \brief Stores the number of required fake parentheses and the
|
|
|
|
/// corresponding operator precedence.
|
|
|
|
///
|
|
|
|
/// If multiple fake parentheses start at a token, this vector stores them in
|
|
|
|
/// reverse order, i.e. inner fake parenthesis first.
|
|
|
|
SmallVector<prec::Level, 4> FakeLParens;
|
|
|
|
/// \brief Insert this many fake ) after this token for correct indentation.
|
|
|
|
unsigned FakeRParens;
|
|
|
|
|
2013-09-06 16:08:14 +08:00
|
|
|
/// \brief \c true if this token starts a binary expression, i.e. has at least
|
|
|
|
/// one fake l_paren with a precedence greater than prec::Unknown.
|
|
|
|
bool StartsBinaryExpression;
|
|
|
|
/// \brief \c true if this token ends a binary expression.
|
|
|
|
bool EndsBinaryExpression;
|
|
|
|
|
2014-04-16 20:26:54 +08:00
|
|
|
/// \brief Is this is an operator (or "."/"->") in a sequence of operators
|
|
|
|
/// with the same precedence, contains the 0-based operator index.
|
|
|
|
unsigned OperatorIndex;
|
|
|
|
|
|
|
|
/// \brief Is this the last operator (or "."/"->") in a sequence of operators
|
|
|
|
/// with the same precedence?
|
|
|
|
bool LastOperator;
|
2013-06-04 00:45:03 +08:00
|
|
|
|
|
|
|
/// \brief Is this token part of a \c DeclStmt defining multiple variables?
|
|
|
|
///
|
|
|
|
/// Only set if \c Type == \c TT_StartOfName.
|
|
|
|
bool PartOfMultiVariableDeclStmt;
|
|
|
|
|
2014-04-01 20:55:11 +08:00
|
|
|
/// \brief Is this a foreach macro?
|
|
|
|
bool IsForEachMacro;
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
bool is(tok::TokenKind Kind) const { return Tok.is(Kind); }
|
2014-11-21 20:14:12 +08:00
|
|
|
bool is(TokenType TT) const { return Type == TT; }
|
2014-11-04 20:41:02 +08:00
|
|
|
bool is(const IdentifierInfo *II) const {
|
|
|
|
return II && II == Tok.getIdentifierInfo();
|
|
|
|
}
|
2014-11-25 18:05:17 +08:00
|
|
|
template <typename A, typename B> bool isOneOf(A K1, B K2) const {
|
2014-11-24 03:03:25 +08:00
|
|
|
return is(K1) || is(K2);
|
2013-06-04 00:45:03 +08:00
|
|
|
}
|
2014-11-25 18:05:17 +08:00
|
|
|
template <typename A, typename B, typename C>
|
|
|
|
bool isOneOf(A K1, B K2, C K3) const {
|
2014-11-24 23:42:34 +08:00
|
|
|
return is(K1) || is(K2) || is(K3);
|
|
|
|
}
|
2014-11-25 18:05:17 +08:00
|
|
|
template <typename A, typename B, typename C, typename D>
|
|
|
|
bool isOneOf(A K1, B K2, C K3, D K4) const {
|
|
|
|
return is(K1) || is(K2) || is(K3) || is(K4);
|
|
|
|
}
|
|
|
|
template <typename A, typename B, typename C, typename D, typename E>
|
|
|
|
bool isOneOf(A K1, B K2, C K3, D K4, E K5) const {
|
|
|
|
return is(K1) || is(K2) || is(K3) || is(K4) || is(K5);
|
|
|
|
}
|
2014-11-24 23:42:34 +08:00
|
|
|
template <typename T>
|
2014-11-25 18:05:17 +08:00
|
|
|
bool isOneOf(T K1, T K2, T K3, T K4, T K5, T K6, T K7 = tok::NUM_TOKENS,
|
2014-11-24 23:42:34 +08:00
|
|
|
T K8 = tok::NUM_TOKENS, T K9 = tok::NUM_TOKENS,
|
|
|
|
T K10 = tok::NUM_TOKENS, T K11 = tok::NUM_TOKENS,
|
|
|
|
T K12 = tok::NUM_TOKENS) const {
|
|
|
|
return is(K1) || is(K2) || is(K3) || is(K4) || is(K5) || is(K6) || is(K7) ||
|
|
|
|
is(K8) || is(K9) || is(K10) || is(K11) || is(K12);
|
|
|
|
}
|
|
|
|
|
2014-11-25 18:05:17 +08:00
|
|
|
template <typename T> bool isNot(T Kind) const { return !is(Kind); }
|
2014-11-04 20:41:02 +08:00
|
|
|
|
2013-12-20 14:22:01 +08:00
|
|
|
bool isStringLiteral() const { return tok::isStringLiteral(Tok.getKind()); }
|
2013-06-04 00:45:03 +08:00
|
|
|
|
|
|
|
bool isObjCAtKeyword(tok::ObjCKeywordKind Kind) const {
|
|
|
|
return Tok.isObjCAtKeyword(Kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAccessSpecifier(bool ColonRequired = true) const {
|
|
|
|
return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
|
|
|
|
(!ColonRequired || (Next && Next->is(tok::colon)));
|
|
|
|
}
|
|
|
|
|
2014-01-16 17:11:55 +08:00
|
|
|
/// \brief Determine whether the token is a simple-type-specifier.
|
|
|
|
bool isSimpleTypeSpecifier() const;
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
bool isObjCAccessSpecifier() const {
|
|
|
|
return is(tok::at) && Next && (Next->isObjCAtKeyword(tok::objc_public) ||
|
|
|
|
Next->isObjCAtKeyword(tok::objc_protected) ||
|
|
|
|
Next->isObjCAtKeyword(tok::objc_package) ||
|
|
|
|
Next->isObjCAtKeyword(tok::objc_private));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns whether \p Tok is ([{ or a template opening <.
|
|
|
|
bool opensScope() const {
|
2014-11-25 18:05:17 +08:00
|
|
|
return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
|
|
|
|
TT_TemplateOpener);
|
2013-06-04 00:45:03 +08:00
|
|
|
}
|
2013-06-26 03:25:12 +08:00
|
|
|
/// \brief Returns whether \p Tok is )]} or a template closing >.
|
2013-06-04 00:45:03 +08:00
|
|
|
bool closesScope() const {
|
2014-11-25 18:05:17 +08:00
|
|
|
return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
|
|
|
|
TT_TemplateCloser);
|
2013-06-04 00:45:03 +08:00
|
|
|
}
|
|
|
|
|
clang-format: Format segments of builder-type calls one per line.
This fixes llvm.org/PR14818.
Before:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT);
After:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT)
.StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH)
.Default(ORDER_TEXT);
llvm-svn: 189353
2013-08-27 22:24:43 +08:00
|
|
|
/// \brief Returns \c true if this is a "." or "->" accessing a member.
|
|
|
|
bool isMemberAccess() const {
|
2014-07-09 21:07:57 +08:00
|
|
|
return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
|
2014-11-25 18:05:17 +08:00
|
|
|
!isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow);
|
clang-format: Format segments of builder-type calls one per line.
This fixes llvm.org/PR14818.
Before:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT);
After:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT)
.StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH)
.Default(ORDER_TEXT);
llvm-svn: 189353
2013-08-27 22:24:43 +08:00
|
|
|
}
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
bool isUnaryOperator() const {
|
|
|
|
switch (Tok.getKind()) {
|
|
|
|
case tok::plus:
|
|
|
|
case tok::plusplus:
|
|
|
|
case tok::minus:
|
|
|
|
case tok::minusminus:
|
|
|
|
case tok::exclaim:
|
|
|
|
case tok::tilde:
|
|
|
|
case tok::kw_sizeof:
|
|
|
|
case tok::kw_alignof:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
clang-format: Format segments of builder-type calls one per line.
This fixes llvm.org/PR14818.
Before:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT);
After:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT)
.StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH)
.Default(ORDER_TEXT);
llvm-svn: 189353
2013-08-27 22:24:43 +08:00
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
bool isBinaryOperator() const {
|
|
|
|
// Comma is a binary operator, but does not behave as such wrt. formatting.
|
|
|
|
return getPrecedence() > prec::Comma;
|
|
|
|
}
|
clang-format: Format segments of builder-type calls one per line.
This fixes llvm.org/PR14818.
Before:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT);
After:
return llvm::StringSwitch<Reference::Kind>(name)
.StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
.StartsWith(".eh_frame", ORDER_EH_FRAME)
.StartsWith(".init", ORDER_INIT)
.StartsWith(".fini", ORDER_FINI)
.StartsWith(".hash", ORDER_HASH)
.Default(ORDER_TEXT);
llvm-svn: 189353
2013-08-27 22:24:43 +08:00
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
bool isTrailingComment() const {
|
2014-08-26 17:37:52 +08:00
|
|
|
return is(tok::comment) &&
|
2014-11-25 18:05:17 +08:00
|
|
|
(is(TT_LineComment) || !Next || Next->NewlinesBefore > 0);
|
2013-06-04 00:45:03 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 22:15:41 +08:00
|
|
|
/// \brief Returns \c true if this is a keyword that can be used
|
|
|
|
/// like a function call (e.g. sizeof, typeid, ...).
|
|
|
|
bool isFunctionLikeKeyword() const {
|
|
|
|
switch (Tok.getKind()) {
|
|
|
|
case tok::kw_throw:
|
|
|
|
case tok::kw_typeid:
|
|
|
|
case tok::kw_return:
|
|
|
|
case tok::kw_sizeof:
|
|
|
|
case tok::kw_alignof:
|
|
|
|
case tok::kw_alignas:
|
|
|
|
case tok::kw_decltype:
|
|
|
|
case tok::kw_noexcept:
|
|
|
|
case tok::kw_static_assert:
|
|
|
|
case tok::kw___attribute:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
prec::Level getPrecedence() const {
|
|
|
|
return getBinOpPrecedence(Tok.getKind(), true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the previous token ignoring comments.
|
2013-07-04 22:47:51 +08:00
|
|
|
FormatToken *getPreviousNonComment() const {
|
2013-06-04 00:45:03 +08:00
|
|
|
FormatToken *Tok = Previous;
|
2014-05-09 16:15:10 +08:00
|
|
|
while (Tok && Tok->is(tok::comment))
|
2013-06-04 00:45:03 +08:00
|
|
|
Tok = Tok->Previous;
|
|
|
|
return Tok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the next token ignoring comments.
|
2013-07-04 22:47:51 +08:00
|
|
|
const FormatToken *getNextNonComment() const {
|
2013-06-04 00:45:03 +08:00
|
|
|
const FormatToken *Tok = Next;
|
2014-05-09 16:15:10 +08:00
|
|
|
while (Tok && Tok->is(tok::comment))
|
2013-06-04 00:45:03 +08:00
|
|
|
Tok = Tok->Next;
|
|
|
|
return Tok;
|
|
|
|
}
|
|
|
|
|
2013-10-22 23:45:58 +08:00
|
|
|
/// \brief Returns \c true if this tokens starts a block-type list, i.e. a
|
|
|
|
/// list that should be indented with a block indent.
|
|
|
|
bool opensBlockTypeList(const FormatStyle &Style) const {
|
2014-11-25 18:05:17 +08:00
|
|
|
return is(TT_ArrayInitializerLSquare) ||
|
2014-12-12 17:40:58 +08:00
|
|
|
(is(tok::l_brace) &&
|
|
|
|
(BlockKind == BK_Block || is(TT_DictLiteral) ||
|
|
|
|
(!Style.Cpp11BracedListStyle && NestingLevel == 0)));
|
2013-10-22 23:45:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Same as opensBlockTypeList, but for the closing token.
|
2013-10-22 23:30:28 +08:00
|
|
|
bool closesBlockTypeList(const FormatStyle &Style) const {
|
2013-10-22 23:45:58 +08:00
|
|
|
return MatchingParen && MatchingParen->opensBlockTypeList(Style);
|
2013-10-22 23:30:28 +08:00
|
|
|
}
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
FormatToken *MatchingParen;
|
|
|
|
|
|
|
|
FormatToken *Previous;
|
|
|
|
FormatToken *Next;
|
|
|
|
|
2013-09-05 17:29:45 +08:00
|
|
|
SmallVector<AnnotatedLine *, 1> Children;
|
|
|
|
|
2013-10-12 05:25:45 +08:00
|
|
|
/// \brief Stores the formatting decision for the token once it was made.
|
|
|
|
FormatDecision Decision;
|
|
|
|
|
|
|
|
/// \brief If \c true, this token has been fully formatted (indented and
|
|
|
|
/// potentially re-formatted inside), and we do not allow further formatting
|
|
|
|
/// changes.
|
|
|
|
bool Finalized;
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
private:
|
|
|
|
// Disallow copying.
|
2013-07-01 12:07:34 +08:00
|
|
|
FormatToken(const FormatToken &) LLVM_DELETED_FUNCTION;
|
|
|
|
void operator=(const FormatToken &) LLVM_DELETED_FUNCTION;
|
2013-06-04 00:45:03 +08:00
|
|
|
};
|
|
|
|
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
class ContinuationIndenter;
|
|
|
|
struct LineState;
|
|
|
|
|
|
|
|
class TokenRole {
|
|
|
|
public:
|
|
|
|
TokenRole(const FormatStyle &Style) : Style(Style) {}
|
|
|
|
virtual ~TokenRole();
|
|
|
|
|
|
|
|
/// \brief After the \c TokenAnnotator has finished annotating all the tokens,
|
|
|
|
/// this function precomputes required information for formatting.
|
|
|
|
virtual void precomputeFormattingInfos(const FormatToken *Token);
|
|
|
|
|
|
|
|
/// \brief Apply the special formatting that the given role demands.
|
|
|
|
///
|
2014-01-09 21:42:56 +08:00
|
|
|
/// Assumes that the token having this role is already formatted.
|
|
|
|
///
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
/// Continues formatting from \p State leaving indentation to \p Indenter and
|
|
|
|
/// returns the total penalty that this formatting incurs.
|
2014-01-09 21:42:56 +08:00
|
|
|
virtual unsigned formatFromToken(LineState &State,
|
|
|
|
ContinuationIndenter *Indenter,
|
|
|
|
bool DryRun) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Same as \c formatFromToken, but assumes that the first token has
|
|
|
|
/// already been set thereby deciding on the first line break.
|
|
|
|
virtual unsigned formatAfterToken(LineState &State,
|
|
|
|
ContinuationIndenter *Indenter,
|
|
|
|
bool DryRun) {
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Notifies the \c Role that a comma was found.
|
|
|
|
virtual void CommaFound(const FormatToken *Token) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const FormatStyle &Style;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CommaSeparatedList : public TokenRole {
|
|
|
|
public:
|
2014-01-09 21:42:56 +08:00
|
|
|
CommaSeparatedList(const FormatStyle &Style)
|
|
|
|
: TokenRole(Style), HasNestedBracedList(false) {}
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
void precomputeFormattingInfos(const FormatToken *Token) override;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
unsigned formatAfterToken(LineState &State, ContinuationIndenter *Indenter,
|
|
|
|
bool DryRun) override;
|
2014-01-09 21:42:56 +08:00
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
unsigned formatFromToken(LineState &State, ContinuationIndenter *Indenter,
|
|
|
|
bool DryRun) override;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
|
|
|
|
/// \brief Adds \p Token as the next comma to the \c CommaSeparated list.
|
2014-05-09 21:11:16 +08:00
|
|
|
void CommaFound(const FormatToken *Token) override {
|
|
|
|
Commas.push_back(Token);
|
|
|
|
}
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// \brief A struct that holds information on how to format a given list with
|
|
|
|
/// a specific number of columns.
|
|
|
|
struct ColumnFormat {
|
|
|
|
/// \brief The number of columns to use.
|
|
|
|
unsigned Columns;
|
|
|
|
|
|
|
|
/// \brief The total width in characters.
|
|
|
|
unsigned TotalWidth;
|
|
|
|
|
|
|
|
/// \brief The number of lines required for this format.
|
|
|
|
unsigned LineCount;
|
|
|
|
|
|
|
|
/// \brief The size of each column in characters.
|
|
|
|
SmallVector<unsigned, 8> ColumnSizes;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Calculate which \c ColumnFormat fits best into
|
|
|
|
/// \p RemainingCharacters.
|
|
|
|
const ColumnFormat *getColumnFormat(unsigned RemainingCharacters) const;
|
|
|
|
|
|
|
|
/// \brief The ordered \c FormatTokens making up the commas of this list.
|
|
|
|
SmallVector<const FormatToken *, 8> Commas;
|
|
|
|
|
|
|
|
/// \brief The length of each of the list's items in characters including the
|
|
|
|
/// trailing comma.
|
|
|
|
SmallVector<unsigned, 8> ItemLengths;
|
|
|
|
|
|
|
|
/// \brief Precomputed formats that can be used for this list.
|
|
|
|
SmallVector<ColumnFormat, 4> Formats;
|
2014-01-09 21:42:56 +08:00
|
|
|
|
|
|
|
bool HasNestedBracedList;
|
clang-format: Add column layout formatting for braced lists
With this patch, braced lists (with more than 3 elements are formatted in a
column layout if possible). E.g.:
static const uint16_t CallerSavedRegs64Bit[] = {
X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI,
X86::R8, X86::R9, X86::R10, X86::R11, 0
};
Required other changes:
- FormatTokens can now have a special role that contains extra data and can do
special formattings. A comma separated list is currently the only
implementation.
- Move penalty calculation entirely into ContinuationIndenter (there was a last
piece still in UnwrappedLineFormatter).
Review: http://llvm-reviews.chandlerc.com/D1457
llvm-svn: 189018
2013-08-22 23:00:41 +08:00
|
|
|
};
|
|
|
|
|
2014-11-04 20:41:02 +08:00
|
|
|
/// \brief Encapsulates keywords that are context sensitive or for languages not
|
|
|
|
/// properly supported by Clang's lexer.
|
|
|
|
struct AdditionalKeywords {
|
|
|
|
AdditionalKeywords(IdentifierTable &IdentTable) {
|
|
|
|
kw_in = &IdentTable.get("in");
|
2014-12-05 18:42:21 +08:00
|
|
|
kw_CF_ENUM = &IdentTable.get("CF_ENUM");
|
|
|
|
kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
|
2014-11-04 20:41:02 +08:00
|
|
|
kw_NS_ENUM = &IdentTable.get("NS_ENUM");
|
2014-12-05 18:42:21 +08:00
|
|
|
kw_NS_OPTIONS = &IdentTable.get("NS_OPTIONS");
|
2014-11-04 20:41:02 +08:00
|
|
|
|
|
|
|
kw_finally = &IdentTable.get("finally");
|
|
|
|
kw_function = &IdentTable.get("function");
|
|
|
|
kw_var = &IdentTable.get("var");
|
|
|
|
|
2014-11-21 20:19:07 +08:00
|
|
|
kw_abstract = &IdentTable.get("abstract");
|
2014-11-04 20:41:02 +08:00
|
|
|
kw_extends = &IdentTable.get("extends");
|
2014-11-21 20:19:07 +08:00
|
|
|
kw_final = &IdentTable.get("final");
|
2014-11-04 20:41:02 +08:00
|
|
|
kw_implements = &IdentTable.get("implements");
|
2014-11-25 18:05:17 +08:00
|
|
|
kw_instanceof = &IdentTable.get("instanceof");
|
2014-11-11 00:30:02 +08:00
|
|
|
kw_interface = &IdentTable.get("interface");
|
2015-01-14 06:32:50 +08:00
|
|
|
kw_native = &IdentTable.get("native");
|
2014-11-27 02:03:42 +08:00
|
|
|
kw_package = &IdentTable.get("package");
|
2014-11-04 20:41:02 +08:00
|
|
|
kw_synchronized = &IdentTable.get("synchronized");
|
|
|
|
kw_throws = &IdentTable.get("throws");
|
|
|
|
|
|
|
|
kw_option = &IdentTable.get("option");
|
|
|
|
kw_optional = &IdentTable.get("optional");
|
|
|
|
kw_repeated = &IdentTable.get("repeated");
|
|
|
|
kw_required = &IdentTable.get("required");
|
|
|
|
kw_returns = &IdentTable.get("returns");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjC context sensitive keywords.
|
|
|
|
IdentifierInfo *kw_in;
|
2014-12-05 18:42:21 +08:00
|
|
|
IdentifierInfo *kw_CF_ENUM;
|
|
|
|
IdentifierInfo *kw_CF_OPTIONS;
|
2014-11-04 20:41:02 +08:00
|
|
|
IdentifierInfo *kw_NS_ENUM;
|
2014-12-05 18:42:21 +08:00
|
|
|
IdentifierInfo *kw_NS_OPTIONS;
|
2014-11-04 20:41:02 +08:00
|
|
|
|
|
|
|
// JavaScript keywords.
|
|
|
|
IdentifierInfo *kw_finally;
|
|
|
|
IdentifierInfo *kw_function;
|
|
|
|
IdentifierInfo *kw_var;
|
|
|
|
|
|
|
|
// Java keywords.
|
2014-11-21 20:19:07 +08:00
|
|
|
IdentifierInfo *kw_abstract;
|
2014-11-04 20:41:02 +08:00
|
|
|
IdentifierInfo *kw_extends;
|
2014-11-21 20:19:07 +08:00
|
|
|
IdentifierInfo *kw_final;
|
2014-11-04 20:41:02 +08:00
|
|
|
IdentifierInfo *kw_implements;
|
2014-11-25 18:05:17 +08:00
|
|
|
IdentifierInfo *kw_instanceof;
|
2014-11-11 00:30:02 +08:00
|
|
|
IdentifierInfo *kw_interface;
|
2015-01-14 06:32:50 +08:00
|
|
|
IdentifierInfo *kw_native;
|
2014-11-27 02:03:42 +08:00
|
|
|
IdentifierInfo *kw_package;
|
2014-11-04 20:41:02 +08:00
|
|
|
IdentifierInfo *kw_synchronized;
|
|
|
|
IdentifierInfo *kw_throws;
|
|
|
|
|
|
|
|
// Proto keywords.
|
|
|
|
IdentifierInfo *kw_option;
|
|
|
|
IdentifierInfo *kw_optional;
|
|
|
|
IdentifierInfo *kw_repeated;
|
|
|
|
IdentifierInfo *kw_required;
|
|
|
|
IdentifierInfo *kw_returns;
|
|
|
|
};
|
|
|
|
|
2013-06-04 00:45:03 +08:00
|
|
|
} // namespace format
|
|
|
|
} // namespace clang
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#endif
|