aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/include/clang/Tooling/Syntax/Nodes.td
blob: 765710e3e72e353e15d68911ffe2899f7ea2cc23 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
//===- Nodes.td - Node types in the Syntax Tree grammar -------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines concrete nodes in the syntax tree.
// The archetypes they fall into (Sequence, List etc) are defined in Syntax.td.
//
// The C++ classes for the archetypes themselves are written by hand, and the
// concrete node classes will be generated. Migration to TableGen is not
// complete, so currently there is a mix of generated and hand-authored code.
//
//===----------------------------------------------------------------------===//

include "clang/Tooling/Syntax/Syntax.td"

def TranslationUnit : Unconstrained {
  let documentation = [{
    A root node for a translation unit. Parent is always null.
  }];
}

def UnqualifiedId : External<Tree> {}

// Lists
def List : External<Tree> {}
def DeclaratorList : External<List> {}
def ParameterDeclarationList : External<List> {}
def CallArguments : External<List> {}
def NestedNameSpecifier : External<List> {}

def Expression : Alternatives {
  let documentation = [{
    A base class for all expressions. Note that expressions are not statements,
    even though they are in clang.
  }];
}
def UnknownExpression : External<Expression> {}
def UnaryOperatorExpression : External<Tree> {}
def PrefixUnaryOperatorExpression : External<UnaryOperatorExpression> {}
def PostfixUnaryOperatorExpression : External<UnaryOperatorExpression> {}
def BinaryOperatorExpression : External<Expression> {}
def ParenExpression : Sequence<Expression> {
  let documentation = [{
    Models a parenthesized expression `(E)`. C++ [expr.prim.paren]
    e.g. `(3 + 2)` in `a = 1 + (3 + 2);`
  }];
  let children = [
    Role<"OpenParen", Token<"l_paren">>,
    Role<"SubExpression", Expression>,
    Role<"CloseParen", Token<"r_paren">>,
  ];
}
def LiteralExpression : Alternatives<Expression> {
  let documentation = [{
    Expression for literals. C++ [lex.literal]
  }];
}
def IntegerLiteralExpression : Sequence<LiteralExpression> {
  let documentation = [{
    Expression for integer literals. C++ [lex.icon]
  }];
  let children = [
    Role<"LiteralToken", Token<"numeric_constant">>,
  ];
}
defvar AnyCharacterLiteral = AnyToken<[
  "char_constant", "wide_char_constant", "utf8_char_constant",
  "utf16_char_constant", "utf32_char_constant"
]>;
def CharacterLiteralExpression : Sequence<LiteralExpression> {
  let documentation = [{
    Expression for character literals. C++ [lex.ccon]
  }];
  let children = [
    Role<"LiteralToken", AnyCharacterLiteral>,
  ];
}
def FloatingLiteralExpression : Sequence<LiteralExpression> {
  let documentation = [{
    Expression for floating-point literals. C++ [lex.fcon]
  }];
  let children = [
    Role<"LiteralToken", Token<"numeric_constant">>,
  ];
}
defvar AnyStringLiteral = AnyToken<[
  "string_literal", "wide_string_literal", "utf8_string_literal",
  "utf16_string_literal", "utf32_string_literal"
]>;
def StringLiteralExpression : Sequence<LiteralExpression> {
  let documentation = [{
    Expression for string-literals. C++ [lex.string]
  }];
  // FIXME: string literals may consist of multiple tokens.
  // These are merged in phase 6, but tokens are captured after phase 4.
  // The child here should be a list of literal tokens instead.
  let children = [
    Role<"LiteralToken", AnyStringLiteral>,
  ];
}
def BoolLiteralExpression : Sequence<LiteralExpression> {
  let documentation = [{
    Expression for boolean literals. C++ [lex.bool]
  }];
  let children = [
    Role<"LiteralToken", AnyToken<["kw_false","kw_true"]>>,
  ];
}
def CxxNullPtrExpression : Sequence<LiteralExpression> {
  let documentation = [{
    Expression for the `nullptr` literal. C++ [lex.nullptr]
  }];
  let children = [
    Role<"LiteralToken", Keyword<"nullptr">>,
  ];
}
def UserDefinedLiteralExpression : Alternatives<LiteralExpression> {
  let documentation = [{
    Expression for user-defined literal. C++ [lex.ext]
    user-defined-literal:
      user-defined-integer-literal
      user-defined-floating-point-literal
      user-defined-string-literal
      user-defined-character-literal
  }];
}
def IntegerUserDefinedLiteralExpression : Sequence<UserDefinedLiteralExpression> {
  let documentation = [{
    Expression for user-defined-integer-literal. C++ [lex.ext]
  }];
  let children = [
    Role<"LiteralToken", Keyword<"numeric_constant">>,
  ];
}
def FloatUserDefinedLiteralExpression : Sequence<UserDefinedLiteralExpression> {
  let documentation = [{
    Expression for user-defined-floating-point-literal. C++ [lex.ext]
  }];
  let children = [
    Role<"LiteralToken", Keyword<"numeric_constant">>,
  ];
}
def CharUserDefinedLiteralExpression : Sequence<UserDefinedLiteralExpression> {
  let documentation = [{
    Expression for user-defined-character-literal. C++ [lex.ext]
  }];
  let children = [
    Role<"LiteralToken", AnyCharacterLiteral>,
  ];
}
def StringUserDefinedLiteralExpression : Sequence<UserDefinedLiteralExpression> {
  let documentation = [{
    Expression for user-defined-string-literal. C++ [lex.ext]
  }];
  let children = [
    Role<"LiteralToken", AnyStringLiteral>,
  ];
}
def IdExpression : Sequence<Expression> {
  let documentation = [{
    Models an `id-expression`, e.g. `std::vector<int>::size`.
    C++ [expr.prim.id]
    id-expression:
      unqualified-id
      qualified-id
    qualified-id:
      nested-name-specifier template_opt unqualified-id
  }];
  let children = [
    Role<"Qualifier", Optional<NestedNameSpecifier>>,
    Role<"TemplateKeyword", Optional<Keyword<"template">>>,
    Role<"UnqualifiedId", UnqualifiedId>,
  ];
}
def MemberExpression : Sequence<Expression> {
  let documentation = [{
    Models a class member access. C++ [expr.ref]
    member-expression:
      expression -> template_opt id-expression
      expression .  template_opt id-expression
    e.g. `x.a`, `xp->a`

    Note: An implicit member access inside a class, i.e. `a` instead of
    `this->a`, is an `id-expression`.
  }];
  let children = [
    Role<"Object", Expression>,
    Role<"AccessToken", AnyToken<["period","arrow"]>>,
    Role<"TemplateKeyword", Optional<Keyword<"template">>>,
    Role<"Member", IdExpression>,
  ];
}
def ThisExpression : Sequence<Expression> {
  let documentation = [{
    Models a this expression `this`. C++ [expr.prim.this]
  }];
  let children = [
    Role<"IntroducerKeyword", Keyword<"this">>,
  ];
}
def CallExpression : Sequence<Expression> {
  let documentation = [{
    A function call. C++ [expr.call]
    call-expression:
      expression '(' call-arguments ')'
    e.g `f(1, '2')` or `this->Base::f()`
  }];
  let children = [
    Role<"Callee", Expression>,
    Role<"OpenParen", Token<"l_paren">>,
    Role<"Arguments", CallArguments>,
    Role<"CloseParen", Token<"r_paren">>,
  ];
}

// Statements.
def Statement : External<Tree> {}
def UnknownStatement : External<Statement> {}
def DeclarationStatement : External<Statement> {}
def EmptyStatement : External<Statement> {}
def SwitchStatement : External<Statement> {}
def CaseStatement : External<Statement> {}
def DefaultStatement : External<Statement> {}
def IfStatement : External<Statement> {}
def ForStatement : External<Statement> {}
def WhileStatement : External<Statement> {}
def ContinueStatement : External<Statement> {}
def BreakStatement : External<Statement> {}
def ReturnStatement : External<Statement> {}
def RangeBasedForStatement : External<Statement> {}
def ExpressionStatement : External<Statement> {}
def CompoundStatement : External<Statement> {}

// Declarations.
def Declaration : External<Tree> {}
def UnknownDeclaration : External<Declaration> {}
def EmptyDeclaration : External<Declaration> {}
def StaticAssertDeclaration : External<Declaration> {}
def LinkageSpecificationDeclaration : External<Declaration> {}
def SimpleDeclaration : External<Declaration> {}
def TemplateDeclaration : External<Declaration> {}
def ExplicitTemplateInstantiation : External<Declaration> {}
def NamespaceDefinition : External<Declaration> {}
def NamespaceAliasDefinition : External<Declaration> {}
def UsingNamespaceDirective : External<Declaration> {}
def UsingDeclaration : External<Declaration> {}
def TypeAliasDeclaration : External<Declaration> {}

// Declarators.
def Declarator : External<Tree> {}
def SimpleDeclarator : External<Declarator> {}
def ParenDeclarator : External<Declarator> {}

def ArraySubscript : External<Tree> {}
def TrailingReturnType : External<Tree> {}
def ParametersAndQualifiers : External<Tree> {}
def MemberPointer : External<Tree> {}

// Name Specifiers.
def NameSpecifier : Alternatives {
  let documentation = [{
    A sequence of these specifiers make a `nested-name-specifier`.
    e.g. the `std` or `vector<int>` in `std::vector<int>::size`.
  }];
}
def GlobalNameSpecifier : Unconstrained<NameSpecifier> {
  let documentation = [{
    The global namespace name specifier, this specifier doesn't correspond to a
    token instead an absence of tokens before a `::` characterizes it, in
    `::std::vector<int>` it would be characterized by the absence of a token
    before the first `::`
  }];
}
def DecltypeNameSpecifier : Unconstrained<NameSpecifier> {
  let documentation = [{
    A name specifier holding a decltype, of the form: `decltype ( expression ) `
    e.g. the `decltype(s)` in `decltype(s)::size`.
  }];
}
def IdentifierNameSpecifier : Unconstrained<NameSpecifier> {
  let documentation = [{
    A identifier name specifier, of the form `identifier`
    e.g. the `std` in `std::vector<int>::size`.
  }];
}
def SimpleTemplateNameSpecifier : Unconstrained<NameSpecifier> {
  let documentation = [{
    A name specifier with a simple-template-id, of the form `template_opt
    identifier < template-args >` e.g. the `vector<int>` in
    `std::vector<int>::size`.
  }];
}