Skip to content

Commit 11b8549

Browse files
authored
Merge pull request #69229 from hamishknight/boxing-match
[ASTGen] Introduce wrapper types for AST nodes
2 parents 7e527b0 + 3639d86 commit 11b8549

16 files changed

+1858
-1488
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===--- ASTBridgingWrappers.def - Swift AST Metaprogramming ----*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines macros used for bridging macro-metaprogramming with AST
14+
// nodes.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
/// AST_BRIDGING_WRAPPER(Name)
19+
/// The default macro to define a bridging wrapper type.
20+
21+
/// AST_BRIDGING_WRAPPER_NULLABLE(Name)
22+
/// Specifies that the given bridging wrapper should have a
23+
/// nullable raw value.
24+
#ifndef AST_BRIDGING_WRAPPER_NULLABLE
25+
#define AST_BRIDGING_WRAPPER_NULLABLE(Name) AST_BRIDGING_WRAPPER(Name)
26+
#endif
27+
28+
/// AST_BRIDGING_WRAPPER_NONNULL(Name)
29+
/// Specifies that the given bridging wrapper should have a
30+
/// non-null raw value.
31+
#ifndef AST_BRIDGING_WRAPPER_NONNULL
32+
#define AST_BRIDGING_WRAPPER_NONNULL(Name) AST_BRIDGING_WRAPPER(Name)
33+
#endif
34+
35+
// Each AST node subclass stores a non-null raw value.
36+
#ifndef DECL
37+
#define DECL(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Decl)
38+
#endif
39+
#define ABSTRACT_DECL(Id, Parent) DECL(Id, Parent)
40+
#include "swift/AST/DeclNodes.def"
41+
42+
#ifndef EXPR
43+
#define EXPR(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Expr)
44+
#endif
45+
#define ABSTRACT_EXPR(Id, Parent) EXPR(Id, Parent)
46+
#include "swift/AST/ExprNodes.def"
47+
48+
#ifndef STMT
49+
#define STMT(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Stmt)
50+
#endif
51+
#define ABSTRACT_STMT(Id, Parent) STMT(Id, Parent)
52+
#include "swift/AST/StmtNodes.def"
53+
54+
#ifndef TYPEREPR
55+
#define TYPEREPR(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##TypeRepr)
56+
#endif
57+
#define ABSTRACT_TYPEREPR(Id, Parent) TYPEREPR(Id, Parent)
58+
#include "swift/AST/TypeReprNodes.def"
59+
60+
// Some of the base classes need to be nullable to allow them to be used as
61+
// optional parameters.
62+
AST_BRIDGING_WRAPPER_NONNULL(Decl)
63+
AST_BRIDGING_WRAPPER_NONNULL(DeclContext)
64+
AST_BRIDGING_WRAPPER_NULLABLE(Stmt)
65+
AST_BRIDGING_WRAPPER_NULLABLE(Expr)
66+
AST_BRIDGING_WRAPPER_NULLABLE(TypeRepr)
67+
68+
// Misc AST types to generate wrappers for.
69+
AST_BRIDGING_WRAPPER_NULLABLE(GenericParamList)
70+
AST_BRIDGING_WRAPPER_NULLABLE(TrailingWhereClause)
71+
AST_BRIDGING_WRAPPER_NULLABLE(ParameterList)
72+
73+
#undef AST_BRIDGING_WRAPPER_NONNULL
74+
#undef AST_BRIDGING_WRAPPER_NULLABLE
75+
#undef AST_BRIDGING_WRAPPER

0 commit comments

Comments
 (0)