Skip to content

[ASTGen] Introduce wrapper types for AST nodes #69229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions include/swift/AST/ASTBridgingWrappers.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//===--- ASTBridgingWrappers.def - Swift AST Metaprogramming ----*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines macros used for bridging macro-metaprogramming with AST
// nodes.
//
//===----------------------------------------------------------------------===//

/// AST_BRIDGING_WRAPPER(Name)
/// The default macro to define a bridging wrapper type.

/// AST_BRIDGING_WRAPPER_NULLABLE(Name)
/// Specifies that the given bridging wrapper should have a
/// nullable raw value.
#ifndef AST_BRIDGING_WRAPPER_NULLABLE
#define AST_BRIDGING_WRAPPER_NULLABLE(Name) AST_BRIDGING_WRAPPER(Name)
#endif

/// AST_BRIDGING_WRAPPER_NONNULL(Name)
/// Specifies that the given bridging wrapper should have a
/// non-null raw value.
#ifndef AST_BRIDGING_WRAPPER_NONNULL
#define AST_BRIDGING_WRAPPER_NONNULL(Name) AST_BRIDGING_WRAPPER(Name)
#endif

// Each AST node subclass stores a non-null raw value.
#ifndef DECL
#define DECL(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Decl)
#endif
#define ABSTRACT_DECL(Id, Parent) DECL(Id, Parent)
#include "swift/AST/DeclNodes.def"

#ifndef EXPR
#define EXPR(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Expr)
#endif
#define ABSTRACT_EXPR(Id, Parent) EXPR(Id, Parent)
#include "swift/AST/ExprNodes.def"

#ifndef STMT
#define STMT(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Stmt)
#endif
#define ABSTRACT_STMT(Id, Parent) STMT(Id, Parent)
#include "swift/AST/StmtNodes.def"

#ifndef TYPEREPR
#define TYPEREPR(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##TypeRepr)
#endif
#define ABSTRACT_TYPEREPR(Id, Parent) TYPEREPR(Id, Parent)
#include "swift/AST/TypeReprNodes.def"

// Some of the base classes need to be nullable to allow them to be used as
// optional parameters.
AST_BRIDGING_WRAPPER_NONNULL(Decl)
AST_BRIDGING_WRAPPER_NONNULL(DeclContext)
AST_BRIDGING_WRAPPER_NULLABLE(Stmt)
AST_BRIDGING_WRAPPER_NULLABLE(Expr)
AST_BRIDGING_WRAPPER_NULLABLE(TypeRepr)

// Misc AST types to generate wrappers for.
AST_BRIDGING_WRAPPER_NULLABLE(GenericParamList)
AST_BRIDGING_WRAPPER_NULLABLE(TrailingWhereClause)
AST_BRIDGING_WRAPPER_NULLABLE(ParameterList)

#undef AST_BRIDGING_WRAPPER_NONNULL
#undef AST_BRIDGING_WRAPPER_NULLABLE
#undef AST_BRIDGING_WRAPPER
Loading