9#include "llvm/Support/raw_ostream.h"
15#define CONCRETE_NODE(Kind, Parent) \
16 case NodeKind::Kind: \
18#include "clang/Tooling/Syntax/Nodes.inc"
20 llvm_unreachable(
"unknown node kind");
25 case syntax::NodeRole::Detached:
26 return OS <<
"Detached";
27 case syntax::NodeRole::Unknown:
28 return OS <<
"Unknown";
29 case syntax::NodeRole::OpenParen:
30 return OS <<
"OpenParen";
31 case syntax::NodeRole::CloseParen:
32 return OS <<
"CloseParen";
33 case syntax::NodeRole::IntroducerKeyword:
34 return OS <<
"IntroducerKeyword";
35 case syntax::NodeRole::LiteralToken:
36 return OS <<
"LiteralToken";
37 case syntax::NodeRole::ArrowToken:
38 return OS <<
"ArrowToken";
39 case syntax::NodeRole::ExternKeyword:
40 return OS <<
"ExternKeyword";
41 case syntax::NodeRole::TemplateKeyword:
42 return OS <<
"TemplateKeyword";
43 case syntax::NodeRole::BodyStatement:
44 return OS <<
"BodyStatement";
45 case syntax::NodeRole::ListElement:
46 return OS <<
"ListElement";
47 case syntax::NodeRole::ListDelimiter:
48 return OS <<
"ListDelimiter";
49 case syntax::NodeRole::CaseValue:
50 return OS <<
"CaseValue";
51 case syntax::NodeRole::ReturnValue:
52 return OS <<
"ReturnValue";
53 case syntax::NodeRole::ThenStatement:
54 return OS <<
"ThenStatement";
55 case syntax::NodeRole::ElseKeyword:
56 return OS <<
"ElseKeyword";
57 case syntax::NodeRole::ElseStatement:
58 return OS <<
"ElseStatement";
59 case syntax::NodeRole::OperatorToken:
60 return OS <<
"OperatorToken";
61 case syntax::NodeRole::Operand:
62 return OS <<
"Operand";
63 case syntax::NodeRole::LeftHandSide:
64 return OS <<
"LeftHandSide";
65 case syntax::NodeRole::RightHandSide:
66 return OS <<
"RightHandSide";
67 case syntax::NodeRole::Expression:
68 return OS <<
"Expression";
69 case syntax::NodeRole::Statement:
70 return OS <<
"Statement";
71 case syntax::NodeRole::Condition:
72 return OS <<
"Condition";
73 case syntax::NodeRole::Message:
74 return OS <<
"Message";
75 case syntax::NodeRole::Declarator:
76 return OS <<
"Declarator";
77 case syntax::NodeRole::Declaration:
78 return OS <<
"Declaration";
79 case syntax::NodeRole::Size:
81 case syntax::NodeRole::Parameters:
82 return OS <<
"Parameters";
83 case syntax::NodeRole::TrailingReturn:
84 return OS <<
"TrailingReturn";
85 case syntax::NodeRole::UnqualifiedId:
86 return OS <<
"UnqualifiedId";
87 case syntax::NodeRole::Qualifier:
88 return OS <<
"Qualifier";
89 case syntax::NodeRole::SubExpression:
90 return OS <<
"SubExpression";
91 case syntax::NodeRole::Object:
92 return OS <<
"Object";
93 case syntax::NodeRole::AccessToken:
94 return OS <<
"AccessToken";
95 case syntax::NodeRole::Member:
96 return OS <<
"Member";
97 case syntax::NodeRole::Callee:
98 return OS <<
"Callee";
99 case syntax::NodeRole::Arguments:
100 return OS <<
"Arguments";
101 case syntax::NodeRole::Declarators:
102 return OS <<
"Declarators";
104 llvm_unreachable(
"invalid role");
109std::vector<syntax::NameSpecifier *>
112 std::vector<syntax::NameSpecifier *> Children;
113 for (
const auto &Element : SpecifiersAsNodes) {
114 Children.push_back(llvm::cast<syntax::NameSpecifier>(Element));
119std::vector<syntax::List::ElementAndDelimiter<syntax::NameSpecifier>>
121 auto SpecifiersAsNodesAndDoubleColons = getElementsAsNodesAndDelimiters();
122 std::vector<syntax::List::ElementAndDelimiter<syntax::NameSpecifier>>
124 for (
const auto &SpecifierAndDoubleColon : SpecifiersAsNodesAndDoubleColons) {
126 {llvm::cast<syntax::NameSpecifier>(SpecifierAndDoubleColon.element),
127 SpecifierAndDoubleColon.delimiter});
133 auto ArgumentsAsNodes = getElementsAsNodes();
134 std::vector<syntax::Expression *> Children;
135 for (
const auto &ArgumentAsNode : ArgumentsAsNodes) {
136 Children.push_back(llvm::cast<syntax::Expression>(ArgumentAsNode));
141std::vector<syntax::List::ElementAndDelimiter<syntax::Expression>>
143 auto ArgumentsAsNodesAndCommas = getElementsAsNodesAndDelimiters();
144 std::vector<syntax::List::ElementAndDelimiter<syntax::Expression>> Children;
145 for (
const auto &ArgumentAsNodeAndComma : ArgumentsAsNodesAndCommas) {
147 {llvm::cast<syntax::Expression>(ArgumentAsNodeAndComma.element),
148 ArgumentAsNodeAndComma.delimiter});
153std::vector<syntax::SimpleDeclaration *>
155 auto ParametersAsNodes = getElementsAsNodes();
156 std::vector<syntax::SimpleDeclaration *> Children;
157 for (
const auto &ParameterAsNode : ParametersAsNodes) {
158 Children.push_back(llvm::cast<syntax::SimpleDeclaration>(ParameterAsNode));
163std::vector<syntax::List::ElementAndDelimiter<syntax::SimpleDeclaration>>
165 auto ParametersAsNodesAndCommas = getElementsAsNodesAndDelimiters();
166 std::vector<syntax::List::ElementAndDelimiter<syntax::SimpleDeclaration>>
168 for (
const auto &ParameterAsNodeAndComma : ParametersAsNodesAndCommas) {
170 {llvm::cast<syntax::SimpleDeclaration>(ParameterAsNodeAndComma.element),
171 ParameterAsNodeAndComma.delimiter});
176std::vector<syntax::SimpleDeclarator *>
178 auto DeclaratorsAsNodes = getElementsAsNodes();
179 std::vector<syntax::SimpleDeclarator *> Children;
180 for (
const auto &DeclaratorAsNode : DeclaratorsAsNodes) {
181 Children.push_back(llvm::cast<syntax::SimpleDeclarator>(DeclaratorAsNode));
186std::vector<syntax::List::ElementAndDelimiter<syntax::SimpleDeclarator>>
188 auto DeclaratorsAsNodesAndCommas = getElementsAsNodesAndDelimiters();
189 std::vector<syntax::List::ElementAndDelimiter<syntax::SimpleDeclarator>>
191 for (
const auto &DeclaratorAsNodeAndComma : DeclaratorsAsNodesAndCommas) {
193 {llvm::cast<syntax::SimpleDeclarator>(DeclaratorAsNodeAndComma.element),
194 DeclaratorAsNodeAndComma.delimiter});
200 return cast_or_null<syntax::Expression>(
217 return cast_or_null<syntax::Expression>(
222 return cast_or_null<syntax::Leaf>(
227 return cast_or_null<syntax::Statement>(
232 return cast_or_null<syntax::Leaf>(
237 return cast_or_null<syntax::Expression>(
242 return cast_or_null<syntax::Statement>(
247 return cast_or_null<syntax::Leaf>(
252 return cast_or_null<syntax::Statement>(
257 return cast_or_null<syntax::Leaf>(
262 return cast_or_null<syntax::Statement>(
271 return cast_or_null<syntax::Statement>(
276 return cast_or_null<syntax::Leaf>(
281 return cast_or_null<syntax::Statement>(
286 return cast_or_null<syntax::Leaf>(
291 return cast_or_null<syntax::Statement>(
296 return cast_or_null<syntax::Leaf>(
301 return cast_or_null<syntax::Leaf>(
306 return cast_or_null<syntax::Leaf>(
311 return cast_or_null<syntax::Expression>(
316 return cast_or_null<syntax::Leaf>(
321 return cast_or_null<syntax::Statement>(
326 return cast_or_null<syntax::Expression>(
335 std::vector<syntax::Statement *> Children;
336 for (
auto *
C = getFirstChild();
C;
C =
C->getNextSibling()) {
338 Children.push_back(cast<syntax::Statement>(
C));
348 return cast_or_null<syntax::Expression>(
356std::vector<syntax::SimpleDeclarator *>
358 std::vector<syntax::SimpleDeclarator *> Children;
359 for (
auto *
C = getFirstChild();
C;
C =
C->getNextSibling()) {
361 Children.push_back(cast<syntax::SimpleDeclarator>(
C));
367 return cast_or_null<syntax::Leaf>(
372 return cast_or_null<syntax::Declaration>(
377 return cast_or_null<syntax::Leaf>(
386 return cast_or_null<syntax::Declaration>(
415 return cast_or_null<syntax::SimpleDeclarator>(
425 return cast_or_null<syntax::ParameterDeclarationList>(
435 return cast_or_null<syntax::TrailingReturnType>(
439#define NODE(Kind, Parent) \
440 static_assert(sizeof(syntax::Kind) > 0, "Missing Node subclass definition");
441#include "clang/Tooling/Syntax/Nodes.inc"
Leaf * getOperatorToken()
std::vector< List::ElementAndDelimiter< Expression > > getArgumentsAndCommas()
std::vector< Expression * > getArguments()
Expression * getCaseValue()
std::vector< Statement * > getStatements()
FIXME: use custom iterator instead of 'vector'.
Leaf * getContinueKeyword()
A declaration that can appear at the top-level.
std::vector< SimpleDeclarator * > getDeclarators()
std::vector< List::ElementAndDelimiter< syntax::SimpleDeclarator > > getDeclaratorsAndCommas()
Leaf * getDefaultKeyword()
Leaf * getExternKeyword()
Leaf * getTemplateKeyword()
Declaration * getDeclaration()
Expression * getExpression()
Statement * getThenStatement()
Statement * getElseStatement()
A leaf node points to a single token.
std::vector< Node * > getElementsAsNodes()
Returns the elements of the list.
std::vector< NameSpecifier * > getSpecifiers()
std::vector< List::ElementAndDelimiter< syntax::NameSpecifier > > getSpecifiersAndDoubleColons()
Models a parameter-declaration-list which appears within parameters-and-qualifiers.
std::vector< List::ElementAndDelimiter< syntax::SimpleDeclaration > > getParametersAndCommas()
std::vector< SimpleDeclaration * > getParameterDeclarations()
ParameterDeclarationList * getParameters()
TrailingReturnType * getTrailingReturn()
Leaf * getReturnKeyword()
Expression * getReturnValue()
std::vector< SimpleDeclarator * > getDeclarators()
FIXME: use custom iterator instead of 'vector'.
A top-level declarator without parentheses.
An abstract node for C++ statements, e.g.
Expression * getMessage()
Expression * getCondition()
Leaf * getSwitchKeyword()
Leaf * getTemplateKeyword()
Declaration * getDeclaration()
Trailing return type after the parameter list, including the arrow token.
SimpleDeclarator * getDeclarator()
Expression * getOperand()
Leaf * getOperatorToken()
NodeRole
A relation between a parent and child node, e.g.
@ CloseParen
A closing parenthesis in argument lists and blocks, e.g. '}', ')', etc.
@ IntroducerKeyword
A keywords that introduces some grammar construct, e.g. 'if', 'try', etc.
@ BodyStatement
An inner statement for those that have only a single child of kind statement, e.g.
@ OpenParen
An opening parenthesis in argument lists and blocks, e.g. '{', '(', etc.
@ ArrowToken
Tokens or Keywords.
NodeKind
A kind of a syntax node, used for implementing casts.
raw_ostream & operator<<(raw_ostream &OS, NodeKind K)
For debugging purposes.
The JSON file list parser is used to communicate input to InstallAPI.