forked from carbon-language/carbon-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast_kinds.h
161 lines (144 loc) · 7.5 KB
/
ast_kinds.h
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
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file defines a number of X-macros that can be used to walk the AST
// class hierarchy. The main entry points are:
//
// - `CARBON_AST_FOR_EACH_FINAL_CLASS(ACTION)`
// Invokes `ACTION` on each leaf class in the AST class hierarchy.
// - `CARBON_AST_FOR_EACH_ABSTRACT_CLASS(ACTION)`
// Invokes `ACTION` on each non-leaf class in the AST class hierarchy.
// - `CARBON_AST_FOR_EACH_FINAL_CLASS_BELOW(BASE, ACTION)`
// Invokes `ACTION` on each leaf class in the AST class hierarchy that
// derives from `BASE`.
// - `CARBON_AST_FOR_EACH_ABSTRACT_CLASS_BELOW(BASE, ACTION)`
// Invokes `ACTION` on each non-leaf class in the AST class hierarchy that
// derives from `BASE`.
//
// These macros are implemented in terms of `CARBON_Foo_KINDS` X-macros. Each of
// these macros takes two macro names as arguments:
//
// - `CARBON_Foo_KINDS(ABSTRACT, FINAL)`
// Invokes `ABSTRACT(Class)` for each abstract class that inherits from
// `Foo`.
// Invokes `FINAL(Class)` for each final class that inherits from `Foo`.
//
// A fake root class, `AST_RTTI`, is also provided, so that
// `CARBON_AST_RTTI_KINDS` can be used to walk all AST classes.
#ifndef CARBON_EXPLORER_AST_AST_KINDS_H_
#define CARBON_EXPLORER_AST_AST_KINDS_H_
#define CARBON_RTTI_NOOP_ACTION(X)
#define CARBON_AST_FOR_EACH_ABSTRACT_CLASS_BELOW(ROOT, ACTION) \
CARBON_##ROOT##_KINDS(ACTION, CARBON_RTTI_NOOP_ACTION)
#define CARBON_AST_FOR_EACH_FINAL_CLASS_BELOW(ROOT, ACTION) \
CARBON_##ROOT##_KINDS(CARBON_RTTI_NOOP_ACTION, ACTION)
#define CARBON_AST_FOR_EACH_ABSTRACT_CLASS(ACTION) \
CARBON_AST_FOR_EACH_ABSTRACT_CLASS_BELOW(AST_RTTI, ACTION)
#define CARBON_AST_FOR_EACH_FINAL_CLASS(ACTION) \
CARBON_AST_FOR_EACH_FINAL_CLASS_BELOW(AST_RTTI, ACTION)
// Class hierarchy description follows, with one _KINDS macro for each abstract
// base class.
#define CARBON_AST_RTTI_KINDS(ABSTRACT, FINAL) \
CARBON_AstNode_KINDS(ABSTRACT, FINAL) ABSTRACT(AstNode) \
CARBON_Element_KINDS(ABSTRACT, FINAL) ABSTRACT(Element)
#define CARBON_AstNode_KINDS(ABSTRACT, FINAL) \
CARBON_Pattern_KINDS(ABSTRACT, FINAL) ABSTRACT(Pattern) \
CARBON_Declaration_KINDS(ABSTRACT, FINAL) ABSTRACT(Declaration) \
FINAL(ImplBinding) \
FINAL(AlternativeSignature) \
CARBON_Statement_KINDS(ABSTRACT, FINAL) ABSTRACT(Statement) \
CARBON_Expression_KINDS(ABSTRACT, FINAL) ABSTRACT(Expression) \
CARBON_WhereClause_KINDS(ABSTRACT, FINAL) ABSTRACT(WhereClause)
#define CARBON_Pattern_KINDS(ABSTRACT, FINAL) \
FINAL(AutoPattern) \
FINAL(VarPattern) \
FINAL(AddrPattern) \
FINAL(BindingPattern) \
FINAL(GenericBinding) \
FINAL(TuplePattern) \
FINAL(AlternativePattern) \
FINAL(ExpressionPattern)
#define CARBON_Declaration_KINDS(ABSTRACT, FINAL) \
FINAL(NamespaceDeclaration) \
CARBON_CallableDeclaration_KINDS(ABSTRACT, FINAL) \
ABSTRACT(CallableDeclaration) \
FINAL(SelfDeclaration) \
FINAL(ClassDeclaration) \
FINAL(MixinDeclaration) \
FINAL(MixDeclaration) \
FINAL(ChoiceDeclaration) \
FINAL(VariableDeclaration) \
CARBON_ConstraintTypeDeclaration_KINDS(ABSTRACT, FINAL) \
ABSTRACT(ConstraintTypeDeclaration) \
FINAL(InterfaceExtendDeclaration) \
FINAL(InterfaceRequireDeclaration) \
FINAL(AssociatedConstantDeclaration) \
FINAL(ImplDeclaration) \
FINAL(MatchFirstDeclaration) \
FINAL(AliasDeclaration) \
FINAL(ExtendBaseDeclaration)
#define CARBON_CallableDeclaration_KINDS(ABSTRACT, FINAL) \
FINAL(FunctionDeclaration) \
FINAL(DestructorDeclaration)
#define CARBON_ConstraintTypeDeclaration_KINDS(ABSTRACT, FINAL) \
FINAL(InterfaceDeclaration) \
FINAL(ConstraintDeclaration)
#define CARBON_Statement_KINDS(ABSTRACT, FINAL) \
FINAL(ExpressionStatement) \
FINAL(Assign) \
FINAL(IncrementDecrement) \
FINAL(VariableDefinition) \
FINAL(If) \
CARBON_Return_KINDS(ABSTRACT, FINAL) ABSTRACT(Return) \
FINAL(Block) \
FINAL(While) \
FINAL(Break) \
FINAL(Continue) \
FINAL(Match) \
FINAL(For)
#define CARBON_Return_KINDS(ABSTRACT, FINAL) \
FINAL(ReturnVar) \
FINAL(ReturnExpression)
#define CARBON_Expression_KINDS(ABSTRACT, FINAL) \
FINAL(BoolTypeLiteral) \
FINAL(BoolLiteral) \
FINAL(CallExpression) \
CARBON_ConstantValueLiteral_KINDS(ABSTRACT, FINAL) \
ABSTRACT(ConstantValueLiteral) \
CARBON_MemberAccessExpression_KINDS(ABSTRACT, FINAL) \
ABSTRACT(MemberAccessExpression) \
FINAL(IndexExpression) \
FINAL(IntTypeLiteral) \
FINAL(IntLiteral) \
FINAL(OperatorExpression) \
FINAL(StringLiteral) \
FINAL(StringTypeLiteral) \
FINAL(TupleLiteral) \
FINAL(StructLiteral) \
FINAL(TypeTypeLiteral) \
FINAL(IdentifierExpression) \
FINAL(DotSelfExpression) \
FINAL(IntrinsicExpression) \
FINAL(IfExpression) \
FINAL(WhereExpression) \
FINAL(BuiltinConvertExpression) \
FINAL(UnimplementedExpression)
#define CARBON_ConstantValueLiteral_KINDS(ABSTRACT, FINAL) \
FINAL(FunctionTypeLiteral) \
FINAL(StructTypeLiteral) \
FINAL(ArrayTypeLiteral) \
FINAL(ValueLiteral)
#define CARBON_MemberAccessExpression_KINDS(ABSTRACT, FINAL) \
FINAL(SimpleMemberAccessExpression) \
FINAL(CompoundMemberAccessExpression) \
FINAL(BaseAccessExpression)
#define CARBON_WhereClause_KINDS(ABSTRACT, FINAL) \
FINAL(ImplsWhereClause) \
FINAL(EqualsWhereClause) \
FINAL(RewriteWhereClause)
#define CARBON_Element_KINDS(ABSTRACT, FINAL) \
FINAL(NamedElement) \
FINAL(PositionalElement) \
FINAL(BaseElement)
#endif // CARBON_EXPLORER_AST_AST_KINDS_H_