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