summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/clang/lib/Format/FormatToken.h
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2015-05-27 20:44:45 +0000
committerdim <dim@FreeBSD.org>2015-05-27 20:44:45 +0000
commitfae9061769fe2114f1a7875c781cc369ff303a11 (patch)
tree50a603f7e1932cd42f58e26687ce907933014db0 /contrib/llvm/tools/clang/lib/Format/FormatToken.h
parent5ef8fd3549d38e883a31881636be3dc2a275de20 (diff)
parent3191b2b32a96e1a6ee833fcca73e5c8e0c67ba65 (diff)
downloadFreeBSD-src-fae9061769fe2114f1a7875c781cc369ff303a11.zip
FreeBSD-src-fae9061769fe2114f1a7875c781cc369ff303a11.tar.gz
Merge clang trunk r238337 from ^/vendor/clang/dist, resolve conflicts,
and preserve our customizations, where necessary.
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Format/FormatToken.h')
-rw-r--r--contrib/llvm/tools/clang/lib/Format/FormatToken.h194
1 files changed, 99 insertions, 95 deletions
diff --git a/contrib/llvm/tools/clang/lib/Format/FormatToken.h b/contrib/llvm/tools/clang/lib/Format/FormatToken.h
index 4811e02..ec0fdf4 100644
--- a/contrib/llvm/tools/clang/lib/Format/FormatToken.h
+++ b/contrib/llvm/tools/clang/lib/Format/FormatToken.h
@@ -41,13 +41,19 @@ enum TokenType {
TT_CtorInitializerComma,
TT_DesignatedInitializerPeriod,
TT_DictLiteral,
+ TT_ForEachMacro,
+ TT_FunctionAnnotationRParen,
TT_FunctionDeclarationName,
TT_FunctionLBrace,
TT_FunctionTypeLParen,
TT_ImplicitStringLiteral,
TT_InheritanceColon,
+ TT_InlineASMBrace,
TT_InlineASMColon,
TT_JavaAnnotation,
+ TT_JsFatArrow,
+ TT_JsTypeColon,
+ TT_JsTypeOptionalQuestion,
TT_LambdaArrow,
TT_LambdaLSquare,
TT_LeadingJavaAnnotation,
@@ -59,6 +65,7 @@ enum TokenType {
TT_ObjCMethodExpr,
TT_ObjCMethodSpecifier,
TT_ObjCProperty,
+ TT_ObjCStringLiteral,
TT_OverloadedOperator,
TT_OverloadedOperatorLParen,
TT_PointerOrReference,
@@ -69,6 +76,7 @@ enum TokenType {
TT_StartOfName,
TT_TemplateCloser,
TT_TemplateOpener,
+ TT_TemplateString,
TT_TrailingAnnotation,
TT_TrailingReturnArrow,
TT_TrailingUnaryOperator,
@@ -102,21 +110,7 @@ class AnnotatedLine;
/// \brief A wrapper around a \c Token storing information about the
/// whitespace characters preceding it.
struct FormatToken {
- FormatToken()
- : NewlinesBefore(0), HasUnescapedNewline(false), LastNewlineOffset(0),
- ColumnWidth(0), LastLineColumnWidth(0), IsMultiline(false),
- IsFirst(false), MustBreakBefore(false), IsUnterminatedLiteral(false),
- BlockKind(BK_Unknown), Type(TT_Unknown), SpacesRequiredBefore(0),
- CanBreakBefore(false), ClosesTemplateDeclaration(false),
- ParameterCount(0), BlockParameterCount(0),
- PackingKind(PPK_Inconclusive), TotalLength(0), UnbreakableTailLength(0),
- BindingStrength(0), NestingLevel(0), SplitPenalty(0),
- LongestObjCSelectorName(0), FakeRParens(0),
- StartsBinaryExpression(false), EndsBinaryExpression(false),
- OperatorIndex(0), LastOperator(false),
- PartOfMultiVariableDeclStmt(false), IsForEachMacro(false),
- MatchingParen(nullptr), Previous(nullptr), Next(nullptr),
- Decision(FD_Unformatted), Finalized(false) {}
+ FormatToken() {}
/// \brief The \c Token.
Token Tok;
@@ -125,48 +119,39 @@ struct FormatToken {
///
/// 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;
+ unsigned NewlinesBefore = 0;
/// \brief Whether there is at least one unescaped newline before the \c
/// Token.
- bool HasUnescapedNewline;
+ bool HasUnescapedNewline = false;
/// \brief The range of the whitespace immediately preceding the \c Token.
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;
+ unsigned LastNewlineOffset = 0;
/// \brief The width of the non-whitespace parts of the token (or its first
/// line for multi-line tokens) in columns.
/// We need this to correctly measure number of columns a token spans.
- unsigned ColumnWidth;
+ unsigned ColumnWidth = 0;
/// \brief Contains the width in columns of the last line of a multi-line
/// token.
- unsigned LastLineColumnWidth;
+ unsigned LastLineColumnWidth = 0;
/// \brief Whether the token text contains newlines (escaped or not).
- bool IsMultiline;
+ bool IsMultiline = false;
/// \brief Indicates that this is the first token.
- bool IsFirst;
+ bool IsFirst = false;
/// \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();
- }
+ bool MustBreakBefore = false;
/// \brief The raw text of the token.
///
@@ -175,69 +160,74 @@ struct FormatToken {
StringRef TokenText;
/// \brief Set to \c true if this token is an unterminated literal.
- bool IsUnterminatedLiteral;
+ bool IsUnterminatedLiteral = 0;
/// \brief Contains the kind of block if this token is a brace.
- BraceBlockKind BlockKind;
+ BraceBlockKind BlockKind = BK_Unknown;
- TokenType Type;
+ TokenType Type = TT_Unknown;
/// \brief The number of spaces that should be inserted before this token.
- unsigned SpacesRequiredBefore;
+ unsigned SpacesRequiredBefore = 0;
/// \brief \c true if it is allowed to break before this token.
- bool CanBreakBefore;
+ bool CanBreakBefore = false;
- bool ClosesTemplateDeclaration;
+ /// \brief \c true if this is the ">" of "template<..>".
+ bool ClosesTemplateDeclaration = false;
/// \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;
+ unsigned ParameterCount = 0;
/// \brief Number of parameters that are nested blocks,
/// if this is "(", "[" or "<".
- unsigned BlockParameterCount;
+ unsigned BlockParameterCount = 0;
+
+ /// \brief If this is a bracket ("<", "(", "[" or "{"), contains the kind of
+ /// the surrounding bracket.
+ tok::TokenKind ParentBracket = tok::unknown;
/// \brief A token can have a special role that can carry extra information
/// about the token's formatting.
std::unique_ptr<TokenRole> Role;
/// \brief If this is an opening parenthesis, how are the parameters packed?
- ParameterPackingKind PackingKind;
+ ParameterPackingKind PackingKind = PPK_Inconclusive;
/// \brief The total length of the unwrapped line up to and including this
/// token.
- unsigned TotalLength;
+ unsigned TotalLength = 0;
/// \brief The original 0-based column of this token, including expanded tabs.
/// The configured TabWidth is used as tab width.
- unsigned OriginalColumn;
+ unsigned OriginalColumn = 0;
/// \brief The length of following tokens until the next natural split point,
/// or the next token that can be broken.
- unsigned UnbreakableTailLength;
+ unsigned UnbreakableTailLength = 0;
// 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;
+ unsigned BindingStrength = 0;
/// \brief The nesting level of this token, i.e. the number of surrounding (),
/// [], {} or <>.
- unsigned NestingLevel;
+ unsigned NestingLevel = 0;
/// \brief Penalty for inserting a line break before this token.
- unsigned SplitPenalty;
+ unsigned SplitPenalty = 0;
/// \brief If this is the first ObjC selector name in an ObjC method
/// definition or call, this contains the length of the longest name.
///
/// This being set to 0 means that the selectors should not be colon-aligned,
/// e.g. because several of them are block-type.
- unsigned LongestObjCSelectorName;
+ unsigned LongestObjCSelectorName = 0;
/// \brief Stores the number of required fake parentheses and the
/// corresponding operator precedence.
@@ -246,29 +236,47 @@ struct FormatToken {
/// 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;
+ unsigned FakeRParens = 0;
/// \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;
+ bool StartsBinaryExpression = false;
/// \brief \c true if this token ends a binary expression.
- bool EndsBinaryExpression;
+ bool EndsBinaryExpression = false;
/// \brief Is this is an operator (or "."/"->") in a sequence of operators
/// with the same precedence, contains the 0-based operator index.
- unsigned OperatorIndex;
+ unsigned OperatorIndex = 0;
/// \brief Is this the last operator (or "."/"->") in a sequence of operators
/// with the same precedence?
- bool LastOperator;
+ bool LastOperator = false;
/// \brief Is this token part of a \c DeclStmt defining multiple variables?
///
/// Only set if \c Type == \c TT_StartOfName.
- bool PartOfMultiVariableDeclStmt;
+ bool PartOfMultiVariableDeclStmt = false;
+
+ /// \brief If this is a bracket, this points to the matching one.
+ FormatToken *MatchingParen = nullptr;
+
+ /// \brief The previous token in the unwrapped line.
+ FormatToken *Previous = nullptr;
- /// \brief Is this a foreach macro?
- bool IsForEachMacro;
+ /// \brief The next token in the unwrapped line.
+ FormatToken *Next = nullptr;
+
+ /// \brief If this token starts a block, this contains all the unwrapped lines
+ /// in it.
+ SmallVector<AnnotatedLine *, 1> Children;
+
+ /// \brief Stores the formatting decision for the token once it was made.
+ FormatDecision Decision = FD_Unformatted;
+
+ /// \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 = false;
bool is(tok::TokenKind Kind) const { return Tok.is(Kind); }
bool is(TokenType TT) const { return Type == TT; }
@@ -278,27 +286,10 @@ struct FormatToken {
template <typename A, typename B> bool isOneOf(A K1, B K2) const {
return is(K1) || is(K2);
}
- template <typename A, typename B, typename C>
- bool isOneOf(A K1, B K2, C K3) const {
- return is(K1) || is(K2) || is(K3);
- }
- 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... Ts>
+ bool isOneOf(A K1, B K2, Ts... Ks) const {
+ return is(K1) || isOneOf(K2, Ks...);
}
- 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);
- }
- template <typename T>
- bool isOneOf(T K1, T K2, T K3, T K4, T K5, T K6, T K7 = tok::NUM_TOKENS,
- 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);
- }
-
template <typename T> bool isNot(T Kind) const { return !is(Kind); }
bool isStringLiteral() const { return tok::isStringLiteral(Tok.getKind()); }
@@ -336,7 +327,8 @@ struct FormatToken {
/// \brief Returns \c true if this is a "." or "->" accessing a member.
bool isMemberAccess() const {
return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
- !isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow);
+ !isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
+ TT_LambdaArrow);
}
bool isUnaryOperator() const {
@@ -385,6 +377,15 @@ struct FormatToken {
}
}
+ /// \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();
+ }
+
prec::Level getPrecedence() const {
return getBinOpPrecedence(Tok.getKind(), true, true);
}
@@ -419,25 +420,10 @@ struct FormatToken {
return MatchingParen && MatchingParen->opensBlockTypeList(Style);
}
- FormatToken *MatchingParen;
-
- FormatToken *Previous;
- FormatToken *Next;
-
- SmallVector<AnnotatedLine *, 1> Children;
-
- /// \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;
-
private:
// Disallow copying.
- FormatToken(const FormatToken &) LLVM_DELETED_FUNCTION;
- void operator=(const FormatToken &) LLVM_DELETED_FUNCTION;
+ FormatToken(const FormatToken &) = delete;
+ void operator=(const FormatToken &) = delete;
};
class ContinuationIndenter;
@@ -543,6 +529,7 @@ struct AdditionalKeywords {
kw_finally = &IdentTable.get("finally");
kw_function = &IdentTable.get("function");
+ kw_import = &IdentTable.get("import");
kw_var = &IdentTable.get("var");
kw_abstract = &IdentTable.get("abstract");
@@ -555,24 +542,33 @@ struct AdditionalKeywords {
kw_package = &IdentTable.get("package");
kw_synchronized = &IdentTable.get("synchronized");
kw_throws = &IdentTable.get("throws");
+ kw___except = &IdentTable.get("__except");
+
+ kw_mark = &IdentTable.get("mark");
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");
+
+ kw_signals = &IdentTable.get("signals");
+ kw_slots = &IdentTable.get("slots");
+ kw_qslots = &IdentTable.get("Q_SLOTS");
}
- // ObjC context sensitive keywords.
+ // Context sensitive keywords.
IdentifierInfo *kw_in;
IdentifierInfo *kw_CF_ENUM;
IdentifierInfo *kw_CF_OPTIONS;
IdentifierInfo *kw_NS_ENUM;
IdentifierInfo *kw_NS_OPTIONS;
+ IdentifierInfo *kw___except;
// JavaScript keywords.
IdentifierInfo *kw_finally;
IdentifierInfo *kw_function;
+ IdentifierInfo *kw_import;
IdentifierInfo *kw_var;
// Java keywords.
@@ -587,12 +583,20 @@ struct AdditionalKeywords {
IdentifierInfo *kw_synchronized;
IdentifierInfo *kw_throws;
+ // Pragma keywords.
+ IdentifierInfo *kw_mark;
+
// Proto keywords.
IdentifierInfo *kw_option;
IdentifierInfo *kw_optional;
IdentifierInfo *kw_repeated;
IdentifierInfo *kw_required;
IdentifierInfo *kw_returns;
+
+ // QT keywords.
+ IdentifierInfo *kw_signals;
+ IdentifierInfo *kw_slots;
+ IdentifierInfo *kw_qslots;
};
} // namespace format
OpenPOWER on IntegriCloud