Skip to content

Commit 942f06c

Browse files
committed
[NFC] ASTGen: Add Swift names to bridging functions for decls
1 parent d737c19 commit 942f06c

File tree

7 files changed

+261
-192
lines changed

7 files changed

+261
-192
lines changed

include/swift/AST/CASTBridging.h

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
// it causes importing the "Darwin"/"Glibc" overlay module. That violates
2323
// layering. i.e. Darwin overlay is created by Swift compiler.
2424

25+
#define SWIFT_NAME(NAME) __attribute__((swift_name(NAME)))
26+
2527
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
2628
SWIFT_BEGIN_ASSUME_NONNULL
2729

@@ -256,13 +258,18 @@ BridgedIdentifier ASTContext_getIdentifier(BridgedASTContext cContext,
256258
_Bool ASTContext_langOptsHasFeature(BridgedASTContext cContext,
257259
BridgedFeature feature);
258260

261+
SWIFT_NAME("TopLevelCodeDecl_createStmt(astContext:declContext:startLoc:"
262+
"statement:endLoc:)")
259263
void *TopLevelCodeDecl_createStmt(BridgedASTContext cContext,
260264
BridgedDeclContext cDeclContext,
261-
BridgedSourceLoc cStartLoc, void *element,
265+
BridgedSourceLoc cStartLoc, void *statement,
262266
BridgedSourceLoc cEndLoc);
267+
268+
SWIFT_NAME("TopLevelCodeDecl_createExpr(astContext:declContext:startLoc:"
269+
"expression:endLoc:)")
263270
void *TopLevelCodeDecl_createExpr(BridgedASTContext cContext,
264271
BridgedDeclContext cDeclContext,
265-
BridgedSourceLoc cStartLoc, void *element,
272+
BridgedSourceLoc cStartLoc, void *expression,
266273
BridgedSourceLoc cEndLoc);
267274

268275
void *ReturnStmt_create(BridgedASTContext cContext, BridgedSourceLoc cLoc,
@@ -288,13 +295,16 @@ void *IntegerLiteralExpr_create(BridgedASTContext cContext, BridgedString cStr,
288295
void *BooleanLiteralExpr_create(BridgedASTContext cContext, _Bool value,
289296
BridgedSourceLoc cTokenLoc);
290297

298+
SWIFT_NAME("NilLiteralExpr_create(astContext:nilKeywordLoc:)")
291299
void *NilLiteralExpr_create(BridgedASTContext cContext,
292300
BridgedSourceLoc cNilKeywordLoc);
293301

294302
void *ArrayExpr_create(BridgedASTContext cContext, BridgedSourceLoc cLLoc,
295303
BridgedArrayRef elements, BridgedArrayRef commas,
296304
BridgedSourceLoc cRLoc);
297305

306+
SWIFT_NAME("VarDecl_create(astContext:declContext:bindingKeywordLoc:nameExpr:"
307+
"initializer:isStatic:isLet:)")
298308
void *VarDecl_create(BridgedASTContext cContext,
299309
BridgedDeclContext cDeclContext,
300310
BridgedSourceLoc cBindingKeywordLoc, void *opaqueNameExpr,
@@ -313,15 +323,21 @@ void *BraceStmt_create(BridgedASTContext cContext, BridgedSourceLoc cLBLoc,
313323

314324
BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, SwiftInt len);
315325

326+
SWIFT_NAME("ParamDecl_create(astContext:declContext:specifierLoc:firstName:"
327+
"firstNameLoc:secondName:secondNameLoc:type:defaultValue:)")
316328
void *
317329
ParamDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext,
318330
BridgedSourceLoc cSpecifierLoc, BridgedIdentifier cFirstName,
319331
BridgedSourceLoc cFirstNameLoc, BridgedIdentifier cSecondName,
320332
BridgedSourceLoc cSecondNameLoc, void *_Nullable opaqueType,
321333
void *_Nullable opaqueDefaultValue);
322334

335+
SWIFT_NAME("AbstractFunctionDecl_setBody(_:ofDecl:)")
323336
void AbstractFunctionDecl_setBody(void *opaqueBody, void *opaqueDecl);
324337

338+
SWIFT_NAME("FuncDecl_create(astContext:declContext:staticLoc:funcKeywordLoc:"
339+
"name:nameLoc:genericParamList:parameterList:asyncSpecifierLoc:"
340+
"throwsSpecifierLoc:returnType:genericWhereClause:)")
325341
struct BridgedDeclContextAndDecl
326342
FuncDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext,
327343
BridgedSourceLoc cStaticLoc, BridgedSourceLoc cFuncKeywordLoc,
@@ -331,13 +347,17 @@ FuncDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext,
331347
BridgedSourceLoc cThrowsLoc, void *_Nullable opaqueReturnType,
332348
void *_Nullable opaqueGenericWhereClause);
333349

350+
SWIFT_NAME("ConstructorDecl_create(astContext:declContext:initKeywordLoc:"
351+
"failabilityMarkLoc:isIUO:genericParamList:parameterList:"
352+
"asyncSpecifierLoc:throwsSpecifierLoc:genericWhereClause:)")
334353
BridgedDeclContextAndDecl ConstructorDecl_create(
335354
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
336355
BridgedSourceLoc cInitKeywordLoc, BridgedSourceLoc cFailabilityMarkLoc,
337356
_Bool isIUO, void *_Nullable opaqueGenericParams, void *opaqueParameterList,
338357
BridgedSourceLoc cAsyncLoc, BridgedSourceLoc cThrowsLoc,
339358
void *_Nullable opaqueGenericWhereClause);
340359

360+
SWIFT_NAME("DestructorDecl_create(astContext:declContext:deinitKeywordLoc:)")
341361
BridgedDeclContextAndDecl
342362
DestructorDecl_create(BridgedASTContext cContext,
343363
BridgedDeclContext cDeclContext,
@@ -353,6 +373,9 @@ void *UnresolvedDotExpr_create(BridgedASTContext cContext, void *base,
353373
void *ClosureExpr_create(BridgedASTContext cContext, void *body,
354374
BridgedDeclContext cDeclContext);
355375

376+
SWIFT_NAME(
377+
"TypeAliasDecl_create(astContext:declContext:typealiasKeywordLoc:name:"
378+
"nameLoc:genericParamList:equalLoc:underlyingType:genericWhereClause:)")
356379
void *TypeAliasDecl_create(BridgedASTContext cContext,
357380
BridgedDeclContext cDeclContext,
358381
BridgedSourceLoc cAliasKeywordLoc,
@@ -362,48 +385,66 @@ void *TypeAliasDecl_create(BridgedASTContext cContext,
362385
void *opaqueUnderlyingType,
363386
void *_Nullable opaqueGenericWhereClause);
364387

388+
SWIFT_NAME("IterableDeclContext_setParsedMembers(_:ofDecl:)")
365389
void IterableDeclContext_setParsedMembers(BridgedArrayRef members,
366390
void *opaqueDecl);
367391

392+
SWIFT_NAME("EnumDecl_create(astContext:declContext:enumKeywordLoc:name:nameLoc:"
393+
"genericParamList:inheritedTypes:genericWhereClause:braceRange:)")
368394
BridgedDeclContextAndDecl EnumDecl_create(
369395
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
370396
BridgedSourceLoc cEnumKeywordLoc, BridgedIdentifier cName,
371397
BridgedSourceLoc cNameLoc, void *_Nullable opaqueGenericParamList,
372398
BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
373399
BridgedSourceRange cBraceRange);
374400

401+
SWIFT_NAME("EnumCaseDecl_create(declContext:caseKeywordLoc:elements:)")
375402
void *EnumCaseDecl_create(BridgedDeclContext cDeclContext,
376403
BridgedSourceLoc cCaseKeywordLoc,
377404
BridgedArrayRef cElements);
378405

406+
SWIFT_NAME("EnumElementDecl_create(astContext:declContext:name:nameLoc:"
407+
"parameterList:equalsLoc:rawValue:)")
379408
void *EnumElementDecl_create(BridgedASTContext cContext,
380409
BridgedDeclContext cDeclContext,
381410
BridgedIdentifier cName, BridgedSourceLoc cNameLoc,
382411
void *_Nullable opaqueParameterList,
383412
BridgedSourceLoc cEqualsLoc,
384413
void *_Nullable opaqueRawValue);
385414

415+
SWIFT_NAME(
416+
"StructDecl_create(astContext:declContext:structKeywordLoc:name:nameLoc:"
417+
"genericParamList:inheritedTypes:genericWhereClause:braceRange:)")
386418
BridgedDeclContextAndDecl StructDecl_create(
387419
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
388420
BridgedSourceLoc cStructKeywordLoc, BridgedIdentifier cName,
389421
BridgedSourceLoc cNameLoc, void *_Nullable opaqueGenericParamList,
390422
BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
391423
BridgedSourceRange cBraceRange);
392424

425+
SWIFT_NAME(
426+
"ClassDecl_create(astContext:declContext:classKeywordLoc:name:nameLoc:"
427+
"genericParamList:inheritedTypes:genericWhereClause:braceRange:isActor:)")
393428
BridgedDeclContextAndDecl ClassDecl_create(
394429
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
395430
BridgedSourceLoc cClassKeywordLoc, BridgedIdentifier cName,
396431
BridgedSourceLoc cNameLoc, void *_Nullable opaqueGenericParamList,
397432
BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
398433
BridgedSourceRange cBraceRange, _Bool isActor);
399434

435+
SWIFT_NAME("ProtocolDecl_create(astContext:declContext:protocolKeywordLoc:name:"
436+
"nameLoc:primaryAssociatedTypeNames:inheritedTypes:"
437+
"genericWhereClause:braceRange:)")
400438
BridgedDeclContextAndDecl ProtocolDecl_create(
401439
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
402440
BridgedSourceLoc cProtocolKeywordLoc, BridgedIdentifier cName,
403441
BridgedSourceLoc cNameLoc, BridgedArrayRef cPrimaryAssociatedTypeNames,
404442
BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
405443
BridgedSourceRange cBraceRange);
406444

445+
SWIFT_NAME(
446+
"AssociatedTypeDecl_create(astContext:declContext:associatedtypeKeywordLoc:"
447+
"name:nameLoc:inheritedTypes:defaultType:genericWhereClause:)")
407448
void *AssociatedTypeDecl_create(BridgedASTContext cContext,
408449
BridgedDeclContext cDeclContext,
409450
BridgedSourceLoc cAssociatedtypeKeywordLoc,
@@ -413,6 +454,8 @@ void *AssociatedTypeDecl_create(BridgedASTContext cContext,
413454
void *_Nullable opaqueDefaultType,
414455
void *_Nullable opaqueGenericWhereClause);
415456

457+
SWIFT_NAME("ExtensionDecl_create(astContext:declContext:extensionKeywordLoc:"
458+
"extendedType:inheritedTypes:genericWhereClause:braceRange:)")
416459
BridgedDeclContextAndDecl ExtensionDecl_create(
417460
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
418461
BridgedSourceLoc cExtensionKeywordLoc, void *opaqueExtendedType,
@@ -425,6 +468,9 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) {
425468
BridgedOperatorFixityPostfix,
426469
} BridgedOperatorFixity;
427470

471+
SWIFT_NAME(
472+
"OperatorDecl_create(astContext:declContext:fixity:operatorKeywordLoc:name:"
473+
"nameLoc:colonLoc:precedenceGroupName:PrecedenceGroupLoc:)")
428474
void *OperatorDecl_create(BridgedASTContext cContext,
429475
BridgedDeclContext cDeclContext,
430476
BridgedOperatorFixity cFixity,
@@ -440,6 +486,11 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) {
440486
BridgedAssociativityRight,
441487
} BridgedAssociativity;
442488

489+
SWIFT_NAME("PrecedenceGroupDecl_create(declContext:precedencegroupKeywordLoc:"
490+
"name:nameLoc:leftBraceLoc:associativityLabelLoc:"
491+
"associativityValueLoc:associativity:assignmentLabelLoc:"
492+
"assignmentValueLoc:isAssignment:higherThanKeywordLoc:"
493+
"higherThanNames:lowerThanKeywordLoc:lowerThanNames:rightBraceLoc:)")
443494
void *PrecedenceGroupDecl_create(
444495
BridgedDeclContext cDeclContext,
445496
BridgedSourceLoc cPrecedencegroupKeywordLoc, BridgedIdentifier cName,
@@ -463,19 +514,25 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) {
463514
BridgedImportKindFunc,
464515
} BridgedImportKind;
465516

517+
SWIFT_NAME("ImportDecl_create(astContext:declContext:importKeywordLoc:"
518+
"importKind:importKindLoc:path:)")
466519
void *ImportDecl_create(BridgedASTContext cContext,
467520
BridgedDeclContext cDeclContext,
468521
BridgedSourceLoc cImportKeywordLoc,
469522
BridgedImportKind cImportKind,
470523
BridgedSourceLoc cImportKindLoc,
471524
BridgedArrayRef cImportPathElements);
472525

526+
SWIFT_NAME("GenericParamList_create(astContext:leftAngleLoc:parameters:"
527+
"genericWhereClause:rightAngleLoc:)")
473528
void *GenericParamList_create(BridgedASTContext cContext,
474529
BridgedSourceLoc cLeftAngleLoc,
475530
BridgedArrayRef cParameters,
476531
void *_Nullable opaqueGenericWhereClause,
477532
BridgedSourceLoc cRightAngleLoc);
478533

534+
SWIFT_NAME("GenericTypeParamDecl_create(astContext:declContext:eachKeywordLoc:"
535+
"name:nameLoc:inheritedType:index:)")
479536
void *GenericTypeParamDecl_create(BridgedASTContext cContext,
480537
BridgedDeclContext cDeclContext,
481538
BridgedSourceLoc cEachLoc,
@@ -484,10 +541,14 @@ void *GenericTypeParamDecl_create(BridgedASTContext cContext,
484541
void *_Nullable opaqueInheritedType,
485542
SwiftInt index);
486543

544+
SWIFT_NAME(
545+
"TrailingWhereClause_create(astContext:whereKeywordLoc:requirements:)")
487546
void *TrailingWhereClause_create(BridgedASTContext cContext,
488547
BridgedSourceLoc cWhereKeywordLoc,
489548
BridgedArrayRef cRequirements);
490549

550+
SWIFT_NAME(
551+
"ParameterList_create(astContext:leftParenLoc:parameters:rightParenLoc:)")
491552
void *ParameterList_create(BridgedASTContext cContext,
492553
BridgedSourceLoc cLeftParenLoc,
493554
BridgedArrayRef cParameters,
@@ -600,4 +661,6 @@ _Bool Plugin_waitForNextMessage(PluginHandle handle, BridgedData *data);
600661
SWIFT_END_ASSUME_NONNULL
601662
SWIFT_END_NULLABILITY_ANNOTATIONS
602663

664+
#undef SWIFT_NAME
665+
603666
#endif // SWIFT_C_AST_ASTBRIDGING_H

lib/AST/CASTBridging.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, SwiftInt len) {
198198

199199
void *TopLevelCodeDecl_createStmt(BridgedASTContext cContext,
200200
BridgedDeclContext cDeclContext,
201-
BridgedSourceLoc cStartLoc, void *element,
201+
BridgedSourceLoc cStartLoc, void *statement,
202202
BridgedSourceLoc cEndLoc) {
203203
ASTContext &context = convertASTContext(cContext);
204204
DeclContext *declContext = convertDeclContext(cDeclContext);
205205

206-
auto *S = static_cast<Stmt *>(element);
206+
auto *S = static_cast<Stmt *>(statement);
207207
auto Brace = BraceStmt::create(context, convertSourceLoc(cStartLoc), {S},
208208
convertSourceLoc(cEndLoc),
209209
/*Implicit=*/true);
@@ -213,12 +213,12 @@ void *TopLevelCodeDecl_createStmt(BridgedASTContext cContext,
213213

214214
void *TopLevelCodeDecl_createExpr(BridgedASTContext cContext,
215215
BridgedDeclContext cDeclContext,
216-
BridgedSourceLoc cStartLoc, void *element,
216+
BridgedSourceLoc cStartLoc, void *expression,
217217
BridgedSourceLoc cEndLoc) {
218218
ASTContext &context = convertASTContext(cContext);
219219
DeclContext *declContext = convertDeclContext(cDeclContext);
220220

221-
auto *E = static_cast<Expr *>(element);
221+
auto *E = static_cast<Expr *>(expression);
222222
auto Brace = BraceStmt::create(context, convertSourceLoc(cStartLoc), {E},
223223
convertSourceLoc(cEndLoc),
224224
/*Implicit=*/true);

lib/ASTGen/Sources/ASTGen/ASTGen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ struct ASTGenVisitor: SyntaxTransformVisitor {
111111
case .decl(let d):
112112
out.append(d)
113113
case .stmt(let s):
114-
out.append(TopLevelCodeDecl_createStmt(ctx, declContext, loc, s, loc))
114+
out.append(TopLevelCodeDecl_createStmt(astContext: self.ctx, declContext: self.declContext, startLoc: loc, statement: s, endLoc: loc))
115115
case .expr(let e):
116-
out.append(TopLevelCodeDecl_createExpr(ctx, declContext, loc, e, loc))
116+
out.append(TopLevelCodeDecl_createExpr(astContext: self.ctx, declContext: self.declContext, startLoc: loc, expression: e, endLoc: loc))
117117
default:
118118
fatalError("Top level nodes must be decls, stmts, or exprs.")
119119
}

0 commit comments

Comments
 (0)