Coverage Report

Created: 2021-01-23 06:44

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Tooling/Syntax/Nodes.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Nodes.cpp ----------------------------------------------*- C++ -*-=====//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
#include "clang/Tooling/Syntax/Nodes.h"
9
#include "clang/Basic/TokenKinds.h"
10
11
using namespace clang;
12
13
14.5k
raw_ostream &syntax::operator<<(raw_ostream &OS, NodeKind K) {
14
14.5k
  switch (K) {
15
0
#define CONCRETE_NODE(Kind, Parent)                                            \
16
14.5k
  case NodeKind::Kind:                                                         \
17
14.5k
    return OS << #Kind;
18
0
#include "clang/Tooling/Syntax/Nodes.inc"
19
14.5k
  }
20
14.5k
  
llvm_unreachable0
("unknown node kind");
21
14.5k
}
22
23
18.6k
raw_ostream &syntax::operator<<(raw_ostream &OS, NodeRole R) {
24
18.6k
  switch (R) {
25
768
  case syntax::NodeRole::Detached:
26
768
    return OS << "Detached";
27
0
  case syntax::NodeRole::Unknown:
28
0
    return OS << "Unknown";
29
1.81k
  case syntax::NodeRole::OpenParen:
30
1.81k
    return OS << "OpenParen";
31
1.82k
  case syntax::NodeRole::CloseParen:
32
1.82k
    return OS << "CloseParen";
33
442
  case syntax::NodeRole::IntroducerKeyword:
34
442
    return OS << "IntroducerKeyword";
35
1.77k
  case syntax::NodeRole::LiteralToken:
36
1.77k
    return OS << "LiteralToken";
37
24
  case syntax::NodeRole::ArrowToken:
38
24
    return OS << "ArrowToken";
39
10
  case syntax::NodeRole::ExternKeyword:
40
10
    return OS << "ExternKeyword";
41
35
  case syntax::NodeRole::TemplateKeyword:
42
35
    return OS << "TemplateKeyword";
43
78
  case syntax::NodeRole::BodyStatement:
44
78
    return OS << "BodyStatement";
45
2.38k
  case syntax::NodeRole::ListElement:
46
2.38k
    return OS << "ListElement";
47
543
  case syntax::NodeRole::ListDelimiter:
48
543
    return OS << "ListDelimiter";
49
14
  case syntax::NodeRole::CaseValue:
50
14
    return OS << "CaseValue";
51
74
  case syntax::NodeRole::ReturnValue:
52
74
    return OS << "ReturnValue";
53
98
  case syntax::NodeRole::ThenStatement:
54
98
    return OS << "ThenStatement";
55
70
  case syntax::NodeRole::ElseKeyword:
56
70
    return OS << "ElseKeyword";
57
70
  case syntax::NodeRole::ElseStatement:
58
70
    return OS << "ElseStatement";
59
736
  case syntax::NodeRole::OperatorToken:
60
736
    return OS << "OperatorToken";
61
252
  case syntax::NodeRole::Operand:
62
252
    return OS << "Operand";
63
498
  case syntax::NodeRole::LeftHandSide:
64
498
    return OS << "LeftHandSide";
65
498
  case syntax::NodeRole::RightHandSide:
66
498
    return OS << "RightHandSide";
67
1.47k
  case syntax::NodeRole::Expression:
68
1.47k
    return OS << "Expression";
69
472
  case syntax::NodeRole::Statement:
70
472
    return OS << "Statement";
71
12
  case syntax::NodeRole::Condition:
72
12
    return OS << "Condition";
73
8
  case syntax::NodeRole::Message:
74
8
    return OS << "Message";
75
16
  case syntax::NodeRole::Declarator:
76
16
    return OS << "Declarator";
77
134
  case syntax::NodeRole::Declaration:
78
134
    return OS << "Declaration";
79
58
  case syntax::NodeRole::Size:
80
58
    return OS << "Size";
81
318
  case syntax::NodeRole::Parameters:
82
318
    return OS << "Parameters";
83
24
  case syntax::NodeRole::TrailingReturn:
84
24
    return OS << "TrailingReturn";
85
1.21k
  case syntax::NodeRole::UnqualifiedId:
86
1.21k
    return OS << "UnqualifiedId";
87
93
  case syntax::NodeRole::Qualifier:
88
93
    return OS << "Qualifier";
89
118
  case syntax::NodeRole::SubExpression:
90
118
    return OS << "SubExpression";
91
210
  case syntax::NodeRole::Object:
92
210
    return OS << "Object";
93
210
  case syntax::NodeRole::AccessToken:
94
210
    return OS << "AccessToken";
95
210
  case syntax::NodeRole::Member:
96
210
    return OS << "Member";
97
451
  case syntax::NodeRole::Callee:
98
451
    return OS << "Callee";
99
130
  case syntax::NodeRole::Arguments:
100
130
    return OS << "Arguments";
101
1.45k
  case syntax::NodeRole::Declarators:
102
1.45k
    return OS << "Declarators";
103
0
  }
104
0
  llvm_unreachable("invalid role");
105
0
}
106
107
// We could have an interator in list to not pay memory costs of temporary
108
// vector
109
std::vector<syntax::NameSpecifier *>
110
0
syntax::NestedNameSpecifier::getSpecifiers() {
111
0
  auto SpecifiersAsNodes = getElementsAsNodes();
112
0
  std::vector<syntax::NameSpecifier *> Children;
113
0
  for (const auto &Element : SpecifiersAsNodes) {
114
0
    Children.push_back(llvm::cast<syntax::NameSpecifier>(Element));
115
0
  }
116
0
  return Children;
117
0
}
118
119
std::vector<syntax::List::ElementAndDelimiter<syntax::NameSpecifier>>
120
0
syntax::NestedNameSpecifier::getSpecifiersAndDoubleColons() {
121
0
  auto SpecifiersAsNodesAndDoubleColons = getElementsAsNodesAndDelimiters();
122
0
  std::vector<syntax::List::ElementAndDelimiter<syntax::NameSpecifier>>
123
0
      Children;
124
0
  for (const auto &SpecifierAndDoubleColon : SpecifiersAsNodesAndDoubleColons) {
125
0
    Children.push_back(
126
0
        {llvm::cast<syntax::NameSpecifier>(SpecifierAndDoubleColon.element),
127
0
         SpecifierAndDoubleColon.delimiter});
128
0
  }
129
0
  return Children;
130
0
}
131
132
0
std::vector<syntax::Expression *> syntax::CallArguments::getArguments() {
133
0
  auto ArgumentsAsNodes = getElementsAsNodes();
134
0
  std::vector<syntax::Expression *> Children;
135
0
  for (const auto &ArgumentAsNode : ArgumentsAsNodes) {
136
0
    Children.push_back(llvm::cast<syntax::Expression>(ArgumentAsNode));
137
0
  }
138
0
  return Children;
139
0
}
140
141
std::vector<syntax::List::ElementAndDelimiter<syntax::Expression>>
142
0
syntax::CallArguments::getArgumentsAndCommas() {
143
0
  auto ArgumentsAsNodesAndCommas = getElementsAsNodesAndDelimiters();
144
0
  std::vector<syntax::List::ElementAndDelimiter<syntax::Expression>> Children;
145
0
  for (const auto &ArgumentAsNodeAndComma : ArgumentsAsNodesAndCommas) {
146
0
    Children.push_back(
147
0
        {llvm::cast<syntax::Expression>(ArgumentAsNodeAndComma.element),
148
0
         ArgumentAsNodeAndComma.delimiter});
149
0
  }
150
0
  return Children;
151
0
}
152
153
std::vector<syntax::SimpleDeclaration *>
154
0
syntax::ParameterDeclarationList::getParameterDeclarations() {
155
0
  auto ParametersAsNodes = getElementsAsNodes();
156
0
  std::vector<syntax::SimpleDeclaration *> Children;
157
0
  for (const auto &ParameterAsNode : ParametersAsNodes) {
158
0
    Children.push_back(llvm::cast<syntax::SimpleDeclaration>(ParameterAsNode));
159
0
  }
160
0
  return Children;
161
0
}
162
163
std::vector<syntax::List::ElementAndDelimiter<syntax::SimpleDeclaration>>
164
0
syntax::ParameterDeclarationList::getParametersAndCommas() {
165
0
  auto ParametersAsNodesAndCommas = getElementsAsNodesAndDelimiters();
166
0
  std::vector<syntax::List::ElementAndDelimiter<syntax::SimpleDeclaration>>
167
0
      Children;
168
0
  for (const auto &ParameterAsNodeAndComma : ParametersAsNodesAndCommas) {
169
0
    Children.push_back(
170
0
        {llvm::cast<syntax::SimpleDeclaration>(ParameterAsNodeAndComma.element),
171
0
         ParameterAsNodeAndComma.delimiter});
172
0
  }
173
0
  return Children;
174
0
}
175
176
std::vector<syntax::SimpleDeclarator *>
177
0
syntax::DeclaratorList::getDeclarators() {
178
0
  auto DeclaratorsAsNodes = getElementsAsNodes();
179
0
  std::vector<syntax::SimpleDeclarator *> Children;
180
0
  for (const auto &DeclaratorAsNode : DeclaratorsAsNodes) {
181
0
    Children.push_back(llvm::cast<syntax::SimpleDeclarator>(DeclaratorAsNode));
182
0
  }
183
0
  return Children;
184
0
}
185
186
std::vector<syntax::List::ElementAndDelimiter<syntax::SimpleDeclarator>>
187
0
syntax::DeclaratorList::getDeclaratorsAndCommas() {
188
0
  auto DeclaratorsAsNodesAndCommas = getElementsAsNodesAndDelimiters();
189
0
  std::vector<syntax::List::ElementAndDelimiter<syntax::SimpleDeclarator>>
190
0
      Children;
191
0
  for (const auto &DeclaratorAsNodeAndComma : DeclaratorsAsNodesAndCommas) {
192
0
    Children.push_back(
193
0
        {llvm::cast<syntax::SimpleDeclarator>(DeclaratorAsNodeAndComma.element),
194
0
         DeclaratorAsNodeAndComma.delimiter});
195
0
  }
196
0
  return Children;
197
0
}
198
199
0
syntax::Expression *syntax::BinaryOperatorExpression::getLhs() {
200
0
  return cast_or_null<syntax::Expression>(
201
0
      findChild(syntax::NodeRole::LeftHandSide));
202
0
}
203
204
0
syntax::Leaf *syntax::UnaryOperatorExpression::getOperatorToken() {
205
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OperatorToken));
206
0
}
207
208
0
syntax::Expression *syntax::UnaryOperatorExpression::getOperand() {
209
0
  return cast_or_null<syntax::Expression>(findChild(syntax::NodeRole::Operand));
210
0
}
211
212
0
syntax::Leaf *syntax::BinaryOperatorExpression::getOperatorToken() {
213
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OperatorToken));
214
0
}
215
216
0
syntax::Expression *syntax::BinaryOperatorExpression::getRhs() {
217
0
  return cast_or_null<syntax::Expression>(
218
0
      findChild(syntax::NodeRole::RightHandSide));
219
0
}
220
221
0
syntax::Leaf *syntax::SwitchStatement::getSwitchKeyword() {
222
0
  return cast_or_null<syntax::Leaf>(
223
0
      findChild(syntax::NodeRole::IntroducerKeyword));
224
0
}
225
226
0
syntax::Statement *syntax::SwitchStatement::getBody() {
227
0
  return cast_or_null<syntax::Statement>(
228
0
      findChild(syntax::NodeRole::BodyStatement));
229
0
}
230
231
0
syntax::Leaf *syntax::CaseStatement::getCaseKeyword() {
232
0
  return cast_or_null<syntax::Leaf>(
233
0
      findChild(syntax::NodeRole::IntroducerKeyword));
234
0
}
235
236
0
syntax::Expression *syntax::CaseStatement::getCaseValue() {
237
0
  return cast_or_null<syntax::Expression>(
238
0
      findChild(syntax::NodeRole::CaseValue));
239
0
}
240
241
0
syntax::Statement *syntax::CaseStatement::getBody() {
242
0
  return cast_or_null<syntax::Statement>(
243
0
      findChild(syntax::NodeRole::BodyStatement));
244
0
}
245
246
0
syntax::Leaf *syntax::DefaultStatement::getDefaultKeyword() {
247
0
  return cast_or_null<syntax::Leaf>(
248
0
      findChild(syntax::NodeRole::IntroducerKeyword));
249
0
}
250
251
0
syntax::Statement *syntax::DefaultStatement::getBody() {
252
0
  return cast_or_null<syntax::Statement>(
253
0
      findChild(syntax::NodeRole::BodyStatement));
254
0
}
255
256
0
syntax::Leaf *syntax::IfStatement::getIfKeyword() {
257
0
  return cast_or_null<syntax::Leaf>(
258
0
      findChild(syntax::NodeRole::IntroducerKeyword));
259
0
}
260
261
0
syntax::Statement *syntax::IfStatement::getThenStatement() {
262
0
  return cast_or_null<syntax::Statement>(
263
0
      findChild(syntax::NodeRole::ThenStatement));
264
0
}
265
266
0
syntax::Leaf *syntax::IfStatement::getElseKeyword() {
267
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::ElseKeyword));
268
0
}
269
270
0
syntax::Statement *syntax::IfStatement::getElseStatement() {
271
0
  return cast_or_null<syntax::Statement>(
272
0
      findChild(syntax::NodeRole::ElseStatement));
273
0
}
274
275
0
syntax::Leaf *syntax::ForStatement::getForKeyword() {
276
0
  return cast_or_null<syntax::Leaf>(
277
0
      findChild(syntax::NodeRole::IntroducerKeyword));
278
0
}
279
280
0
syntax::Statement *syntax::ForStatement::getBody() {
281
0
  return cast_or_null<syntax::Statement>(
282
0
      findChild(syntax::NodeRole::BodyStatement));
283
0
}
284
285
0
syntax::Leaf *syntax::WhileStatement::getWhileKeyword() {
286
0
  return cast_or_null<syntax::Leaf>(
287
0
      findChild(syntax::NodeRole::IntroducerKeyword));
288
0
}
289
290
0
syntax::Statement *syntax::WhileStatement::getBody() {
291
0
  return cast_or_null<syntax::Statement>(
292
0
      findChild(syntax::NodeRole::BodyStatement));
293
0
}
294
295
0
syntax::Leaf *syntax::ContinueStatement::getContinueKeyword() {
296
0
  return cast_or_null<syntax::Leaf>(
297
0
      findChild(syntax::NodeRole::IntroducerKeyword));
298
0
}
299
300
0
syntax::Leaf *syntax::BreakStatement::getBreakKeyword() {
301
0
  return cast_or_null<syntax::Leaf>(
302
0
      findChild(syntax::NodeRole::IntroducerKeyword));
303
0
}
304
305
0
syntax::Leaf *syntax::ReturnStatement::getReturnKeyword() {
306
0
  return cast_or_null<syntax::Leaf>(
307
0
      findChild(syntax::NodeRole::IntroducerKeyword));
308
0
}
309
310
0
syntax::Expression *syntax::ReturnStatement::getReturnValue() {
311
0
  return cast_or_null<syntax::Expression>(
312
0
      findChild(syntax::NodeRole::ReturnValue));
313
0
}
314
315
0
syntax::Leaf *syntax::RangeBasedForStatement::getForKeyword() {
316
0
  return cast_or_null<syntax::Leaf>(
317
0
      findChild(syntax::NodeRole::IntroducerKeyword));
318
0
}
319
320
0
syntax::Statement *syntax::RangeBasedForStatement::getBody() {
321
0
  return cast_or_null<syntax::Statement>(
322
0
      findChild(syntax::NodeRole::BodyStatement));
323
0
}
324
325
0
syntax::Expression *syntax::ExpressionStatement::getExpression() {
326
0
  return cast_or_null<syntax::Expression>(
327
0
      findChild(syntax::NodeRole::Expression));
328
0
}
329
330
0
syntax::Leaf *syntax::CompoundStatement::getLbrace() {
331
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OpenParen));
332
0
}
333
334
0
std::vector<syntax::Statement *> syntax::CompoundStatement::getStatements() {
335
0
  std::vector<syntax::Statement *> Children;
336
0
  for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
337
0
    assert(C->getRole() == syntax::NodeRole::Statement);
338
0
    Children.push_back(cast<syntax::Statement>(C));
339
0
  }
340
0
  return Children;
341
0
}
342
343
0
syntax::Leaf *syntax::CompoundStatement::getRbrace() {
344
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::CloseParen));
345
0
}
346
347
0
syntax::Expression *syntax::StaticAssertDeclaration::getCondition() {
348
0
  return cast_or_null<syntax::Expression>(
349
0
      findChild(syntax::NodeRole::Condition));
350
0
}
351
352
0
syntax::Expression *syntax::StaticAssertDeclaration::getMessage() {
353
0
  return cast_or_null<syntax::Expression>(findChild(syntax::NodeRole::Message));
354
0
}
355
356
std::vector<syntax::SimpleDeclarator *>
357
0
syntax::SimpleDeclaration::getDeclarators() {
358
0
  std::vector<syntax::SimpleDeclarator *> Children;
359
0
  for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
360
0
    if (C->getRole() == syntax::NodeRole::Declarator)
361
0
      Children.push_back(cast<syntax::SimpleDeclarator>(C));
362
0
  }
363
0
  return Children;
364
0
}
365
366
0
syntax::Leaf *syntax::TemplateDeclaration::getTemplateKeyword() {
367
0
  return cast_or_null<syntax::Leaf>(
368
0
      findChild(syntax::NodeRole::IntroducerKeyword));
369
0
}
370
371
0
syntax::Declaration *syntax::TemplateDeclaration::getDeclaration() {
372
0
  return cast_or_null<syntax::Declaration>(
373
0
      findChild(syntax::NodeRole::Declaration));
374
0
}
375
376
0
syntax::Leaf *syntax::ExplicitTemplateInstantiation::getTemplateKeyword() {
377
0
  return cast_or_null<syntax::Leaf>(
378
0
      findChild(syntax::NodeRole::IntroducerKeyword));
379
0
}
380
381
0
syntax::Leaf *syntax::ExplicitTemplateInstantiation::getExternKeyword() {
382
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::ExternKeyword));
383
0
}
384
385
0
syntax::Declaration *syntax::ExplicitTemplateInstantiation::getDeclaration() {
386
0
  return cast_or_null<syntax::Declaration>(
387
0
      findChild(syntax::NodeRole::Declaration));
388
0
}
389
390
0
syntax::Leaf *syntax::ParenDeclarator::getLparen() {
391
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OpenParen));
392
0
}
393
394
0
syntax::Leaf *syntax::ParenDeclarator::getRparen() {
395
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::CloseParen));
396
0
}
397
398
0
syntax::Leaf *syntax::ArraySubscript::getLbracket() {
399
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OpenParen));
400
0
}
401
402
0
syntax::Expression *syntax::ArraySubscript::getSize() {
403
0
  return cast_or_null<syntax::Expression>(findChild(syntax::NodeRole::Size));
404
0
}
405
406
0
syntax::Leaf *syntax::ArraySubscript::getRbracket() {
407
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::CloseParen));
408
0
}
409
410
0
syntax::Leaf *syntax::TrailingReturnType::getArrowToken() {
411
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::ArrowToken));
412
0
}
413
414
0
syntax::SimpleDeclarator *syntax::TrailingReturnType::getDeclarator() {
415
0
  return cast_or_null<syntax::SimpleDeclarator>(
416
0
      findChild(syntax::NodeRole::Declarator));
417
0
}
418
419
0
syntax::Leaf *syntax::ParametersAndQualifiers::getLparen() {
420
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OpenParen));
421
0
}
422
423
syntax::ParameterDeclarationList *
424
0
syntax::ParametersAndQualifiers::getParameters() {
425
0
  return cast_or_null<syntax::ParameterDeclarationList>(
426
0
      findChild(syntax::NodeRole::Parameters));
427
0
}
428
429
0
syntax::Leaf *syntax::ParametersAndQualifiers::getRparen() {
430
0
  return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::CloseParen));
431
0
}
432
433
syntax::TrailingReturnType *
434
0
syntax::ParametersAndQualifiers::getTrailingReturn() {
435
0
  return cast_or_null<syntax::TrailingReturnType>(
436
0
      findChild(syntax::NodeRole::TrailingReturn));
437
0
}
438
439
#define NODE(Kind, Parent)                                                     \
440
  static_assert(sizeof(syntax::Kind) > 0, "Missing Node subclass definition");
441
#include "clang/Tooling/Syntax/Nodes.inc"