Skip to content

Commit 2f06546

Browse files
authored
Merge pull request #61426 from DougGregor/astgen
2 parents 75156b1 + aed4f74 commit 2f06546

File tree

19 files changed

+973
-0
lines changed

19 files changed

+973
-0
lines changed

include/swift/AST/CASTBridging.h

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
//===--- ASTBridging.h - header for the swift SILBridging module ----------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2022 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+
#ifndef SWIFT_C_AST_ASTBRIDGING_H
14+
#define SWIFT_C_AST_ASTBRIDGING_H
15+
16+
#include <inttypes.h>
17+
18+
#if __clang__
19+
// Provide macros to temporarily suppress warning about the use of
20+
// _Nullable and _Nonnull.
21+
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
22+
_Pragma("clang diagnostic push") \
23+
_Pragma("clang diagnostic ignored \"-Wnullability-extension\"") \
24+
_Pragma("clang assume_nonnull begin")
25+
26+
#define SWIFT_END_NULLABILITY_ANNOTATIONS \
27+
_Pragma("clang diagnostic pop") _Pragma("clang assume_nonnull end")
28+
#else
29+
#define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
30+
#define SWIFT_END_NULLABILITY_ANNOTATIONS
31+
#define _Nullable
32+
#endif
33+
34+
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
35+
36+
typedef long SwiftInt;
37+
typedef unsigned long SwiftUInt;
38+
39+
typedef struct {
40+
const void *_Nullable data;
41+
long numElements;
42+
} BridgedArrayRef;
43+
44+
typedef struct {
45+
void *start;
46+
SwiftInt byteLength;
47+
} BridgedCharSourceRange;
48+
49+
typedef void *BridgedIdentifier;
50+
51+
#ifdef __cplusplus
52+
extern "C" {
53+
54+
#define _Bool bool
55+
56+
#endif
57+
58+
BridgedIdentifier
59+
SwiftASTContext_getIdentifier(
60+
void *ctx, const uint8_t * _Nullable str, long len);
61+
62+
void *SwiftImportDecl_create(void *, void *, void *, char, void *,
63+
BridgedArrayRef, BridgedArrayRef);
64+
65+
void *SwiftTopLevelCodeDecl_createStmt(void *ctx, void *DC, void *startLoc,
66+
void *element, void *endLoc);
67+
void *SwiftTopLevelCodeDecl_createExpr(void *ctx, void *DC, void *startLoc,
68+
void *element, void *endLoc);
69+
70+
void *SwiftSequenceExpr_create(void *ctx, BridgedArrayRef exprs);
71+
72+
void *SwiftTupleExpr_create(void *ctx, void *lparen, BridgedArrayRef subs,
73+
void *rparen);
74+
75+
void *SwiftFunctionCallExpr_create(void *ctx, void *fn, void *args);
76+
77+
void *SwiftIdentifierExpr_create(void *ctx, BridgedIdentifier base, void *loc);
78+
79+
void *SwiftStringLiteralExpr_create(void *ctx, const uint8_t * _Nullable string,
80+
long len, void *TokenLoc);
81+
82+
void *SwiftIntegerLiteralExpr_create(void *ctx, const uint8_t * _Nullable string,
83+
long len, void *TokenLoc);
84+
85+
void *SwiftBooleanLiteralExpr_create(void *ctx, _Bool value, void *TokenLoc);
86+
87+
void *SwiftVarDecl_create(void *ctx, BridgedIdentifier _Nullable name,
88+
void *loc, _Bool isStatic, _Bool isLet, void *dc);
89+
90+
void *IfStmt_create(void *ctx, void *ifLoc, void *cond, void *_Nullable then, void *_Nullable elseLoc,
91+
void *_Nullable elseStmt);
92+
93+
void *BraceStmt_createExpr(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc);
94+
void *BraceStmt_createStmt(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc);
95+
96+
void *BridgedSourceLoc_advanced(void *loc, long len);
97+
98+
void *ParamDecl_create(void *ctx, void *loc,
99+
void *_Nullable argLoc, void *_Nullable argName,
100+
void *_Nullable paramLoc, void *_Nullable paramName,
101+
void *declContext);
102+
103+
void *FuncDecl_create(void *ctx, void *staticLoc, _Bool isStatic, void *funcLoc,
104+
BridgedIdentifier name, void *nameLoc,
105+
_Bool isAsync, void *_Nullable asyncLoc,
106+
_Bool throws, void *_Nullable throwsLoc,
107+
void *paramLLoc, BridgedArrayRef params, void *paramRLoc,
108+
void *_Nullable body, void *_Nullable returnType,
109+
void *declContext);
110+
111+
void *SimpleIdentTypeRepr_create(void *ctx, void *loc, BridgedIdentifier id);
112+
113+
void *UnresolvedDotExpr_create(void *ctx, void *base, void *dotLoc, BridgedIdentifier name, void *nameLoc);
114+
115+
void *ClosureExpr_create(void *ctx, void *body, void *dc);
116+
117+
void NominalTypeDecl_setMembers(void *decl, BridgedArrayRef members);
118+
119+
struct DeclContextAndDecl {
120+
void *declContext;
121+
void *nominalDecl;
122+
void *decl;
123+
};
124+
125+
struct DeclContextAndDecl StructDecl_create(
126+
void *ctx, void *loc, BridgedIdentifier name, void *nameLoc, void *dc);
127+
struct DeclContextAndDecl ClassDecl_create(
128+
void *ctx, void *loc, BridgedIdentifier name, void *nameLoc, void *dc);
129+
130+
void TopLevelCodeDecl_dump(void *);
131+
void Expr_dump(void *);
132+
void Decl_dump(void *);
133+
void Stmt_dump(void *);
134+
135+
#ifdef __cplusplus
136+
}
137+
#endif
138+
139+
SWIFT_END_NULLABILITY_ANNOTATIONS
140+
141+
#undef SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
142+
#undef SWIFT_END_NULLABILITY_ANNOTATIONS
143+
144+
#endif // SWIFT_C_AST_ASTBRIDGING_H

include/swift/Basic/Features.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ EXPERIMENTAL_FEATURE(ParserSequenceFolding)
141141
/// Enables implicit some while also enabling existential `any`
142142
EXPERIMENTAL_FEATURE(ImplicitSome)
143143

144+
/// Parse using the Swift (swift-syntax) parser and use ASTGen to generate the
145+
/// corresponding syntax tree.
146+
EXPERIMENTAL_FEATURE(ParserASTGen)
147+
144148
#undef EXPERIMENTAL_FEATURE
145149
#undef UPCOMING_FEATURE
146150
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

include/swift/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ module ASTBridging {
1515
export *
1616
}
1717

18+
module CASTBridging {
19+
header "AST/CASTBridging.h"
20+
}
21+
1822
module SILBridging {
1923
header "SIL/SILBridging.h"
2024
header "SIL/SILLocation.h"

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,10 @@ static bool usesFeatureAdditiveArithmeticDerivedConformances(Decl *decl) {
30913091
return false;
30923092
}
30933093

3094+
static bool usesFeatureParserASTGen(Decl *decl) {
3095+
return false;
3096+
}
3097+
30943098
static void
30953099
suppressingFeatureNoAsyncAvailability(PrintOptions &options,
30963100
llvm::function_ref<void()> action) {

0 commit comments

Comments
 (0)