clang: lib/Format/TokenAnnotator.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_CLANG_LIB_FORMAT_TOKENANNOTATOR_H
16#define LLVM_CLANG_LIB_FORMAT_TOKENANNOTATOR_H
17
19
21namespace format {
22
25
38};
39
41
43
45
47};
48
50public:
64 assert(.Tokens.empty());
65
66
67
68
73 if (Node.Tok->MacroParent)
75 Current->Next = Node.Tok;
76 Node.Tok->Previous = Current;
77 Current = Current->Next;
79
80
81
82 }
83 Last = Current;
85 }
86
88 Current->Children.clear();
89 for (const auto &Child : Node.Children) {
91 if (Children.back()->ContainsMacroCall)
93 Current->Children.push_back(Children.back());
94 }
95 }
96
98 size_t Size = 1;
99 for (const auto *Child : Children)
100 Size += Child->size();
101 return Size;
102 }
103
106 delete Child;
108 while (Current) {
109 Current->Children.clear();
110 Current->Role.reset();
111 Current = Current->Next;
112 }
113 }
114
117 }
118
119
120
121 template <typename... Ts> bool startsWith(Ts... Tokens) const {
123 }
124
125
126
127
128
129 template <typename... Ts> bool endsWith(Ts... Tokens) const {
131 }
132
133
134
137
138
139
140
141
142
143
144
145
146
148 }
149
150
153 startsWith(tok::kw_inline, tok::kw_namespace) ||
154 startsWith(tok::kw_export, tok::kw_namespace);
155 }
156
157
159 return startsWith(tok::kw_export, tok::l_brace);
160 }
161
165 }
166
168 assert(Last);
170 }
171
174
176
188
189
191
192
194
195
196
198
199
200
202
203
205
206
208
209
210
212
214
215private:
216
219};
220
221
222
224public:
226 : Style(Style), IsCpp(Style.isCpp()),
228 assert(IsCpp == LangOpts.CXXOperatorNames);
229 }
230
231
232
233
235
238
239private:
240
242 bool InFunctionDecl) const;
243
244 bool spaceRequiredBeforeParens(const FormatToken &Right) const;
245
248
251
254
257
259
261
263
264 void calculateArrayInitializerColumnList(AnnotatedLine &Line) const;
265
268 unsigned Depth) const;
270 getTokenReferenceAlignment(const FormatToken &PointerOrReference) const;
271
273 const FormatToken &PointerOrReference) const;
274
276
277 bool IsCpp;
279
281
283};
284
285}
286}
287
288#endif
This file contains the declaration of the UnwrappedLineParser, which turns a stream of tokens into Un...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
The base class of the type hierarchy.
void addChildren(const UnwrappedLineNode &Node, FormatToken *Current)
bool ReturnTypeWrapped
True if breaking after last attribute group in function return type.
FormatToken * getFirstNonComment() const
size_t MatchingClosingBlockLineIndex
bool Computed
True if calculateFormattingInformation() has been called on this line.
bool LeadingEmptyLinesAffected
True if the leading empty lines of this line intersect with one of the input ranges.
bool Affected
True if this line should be formatted, i.e.
AnnotatedLine(const UnwrappedLine &Line)
bool ContainsMacroCall
True if this line contains a macro call for which an expansion exists.
bool mightBeFunctionDefinition() const
true if this line looks like a function definition instead of a function declaration.
bool ChildrenAffected
True if one of this line's children intersects with an input range.
SmallVector< AnnotatedLine *, 0 > Children
bool startsWithNamespace() const
true if this line starts a namespace definition.
bool startsWithExportBlock() const
true if this line starts a C++ export block.
bool IsContinuation
True if this line should be indented by ContinuationIndent in addition to the normal indention level.
bool endsWith(Ts... Tokens) const
true if this line ends with the given tokens in reversed order, ignoring comments.
bool startsWith(Ts... Tokens) const
true if this line starts with the given tokens in order, ignoring comments.
bool IsMultiVariableDeclStmt
size_t MatchingOpeningBlockLineIndex
FormatToken * getLastNonComment() const
unsigned FirstStartColumn
Determines extra information about the tokens comprising an UnwrappedLine.
void calculateFormattingInformation(AnnotatedLine &Line) const
void annotate(AnnotatedLine &Line)
TokenAnnotator(const FormatStyle &Style, const AdditionalKeywords &Keywords)
void setCommentLineLevels(SmallVectorImpl< AnnotatedLine * > &Lines) const
Adapts the indent levels of comment lines to the indent of the subsequent line.
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
@ LT_CommentAbovePPDirective
@ LT_PreprocessorDirective
@ LT_ArrayOfStructInitializer
The JSON file list parser is used to communicate input to InstallAPI.
Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's l...
The FormatStyle is used to configure the formatting to follow specific guidelines.
PointerAlignmentStyle
The &, && and * alignment style.
A wrapper around a Token storing information about the whitespace characters preceding it.
bool startsSequence(A K1, Ts... Tokens) const
true if this token starts a sequence with the given tokens in order, following the Next pointers,...
FormatToken * getNextNonComment() const
Returns the next token ignoring comments.
FormatToken * getPreviousNonComment() const
Returns the previous token ignoring comments.
FormatToken * Next
The next token in the unwrapped line.
bool is(tok::TokenKind Kind) const
FormatToken * Previous
The previous token in the unwrapped line.
bool endsSequence(A K1, Ts... Tokens) const
true if this token ends a sequence with the given tokens in order, following the Previous pointers,...
An unwrapped line is a sequence of Token, that we would like to put on a single line if there was no ...