Skip to content

Commit ae83632

Browse files
committed
[NFC] ASTGen: Add Swift names to bridging functions for decls
1 parent a1ba72c commit ae83632

File tree

7 files changed

+261
-194
lines changed

7 files changed

+261
-194
lines changed

include/swift/AST/CASTBridging.h

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

25+
#if __has_attribute(swift_name)
26+
#define SWIFT_NAME(NAME) __attribute__((swift_name(NAME)))
27+
#else
28+
#define SWIFT_NAME(NAME)
29+
#endif
30+
2531
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
2632
SWIFT_BEGIN_ASSUME_NONNULL
2733

@@ -256,13 +262,18 @@ BridgedIdentifier ASTContext_getIdentifier(BridgedASTContext cContext,
256262
_Bool ASTContext_langOptsHasFeature(BridgedASTContext cContext,
257263
BridgedFeature feature);
258264

265+
SWIFT_NAME("TopLevelCodeDecl_createStmt(astContext:declContext:startLoc:"
266+
"statement:endLoc:)")
259267
void *TopLevelCodeDecl_createStmt(BridgedASTContext cContext,
260268
BridgedDeclContext cDeclContext,
261-
BridgedSourceLoc cStartLoc, void *element,
269+
BridgedSourceLoc cStartLoc, void *statement,
262270
BridgedSourceLoc cEndLoc);
271+
272+
SWIFT_NAME("TopLevelCodeDecl_createExpr(astContext:declContext:startLoc:"
273+
"expression:endLoc:)")
263274
void *TopLevelCodeDecl_createExpr(BridgedASTContext cContext,
264275
BridgedDeclContext cDeclContext,
265-
BridgedSourceLoc cStartLoc, void *element,
276+
BridgedSourceLoc cStartLoc, void *expression,
266277
BridgedSourceLoc cEndLoc);
267278

268279
void *ReturnStmt_create(BridgedASTContext cContext, BridgedSourceLoc cLoc,
@@ -288,13 +299,16 @@ void *IntegerLiteralExpr_create(BridgedASTContext cContext, BridgedString cStr,
288299
void *BooleanLiteralExpr_create(BridgedASTContext cContext, _Bool value,
289300
BridgedSourceLoc cTokenLoc);
290301

302+
SWIFT_NAME("NilLiteralExpr_create(astContext:nilKeywordLoc:)")
291303
void *NilLiteralExpr_create(BridgedASTContext cContext,
292304
BridgedSourceLoc cNilKeywordLoc);
293305

294306
void *ArrayExpr_create(BridgedASTContext cContext, BridgedSourceLoc cLLoc,
295307
BridgedArrayRef elements, BridgedArrayRef commas,
296308
BridgedSourceLoc cRLoc);
297309

310+
SWIFT_NAME("VarDecl_create(astContext:declContext:bindingKeywordLoc:nameExpr:"
311+
"initializer:isStatic:isLet:)")
298312
void *VarDecl_create(BridgedASTContext cContext,
299313
BridgedDeclContext cDeclContext,
300314
BridgedSourceLoc cBindingKeywordLoc, void *opaqueNameExpr,
@@ -313,15 +327,21 @@ void *BraceStmt_create(BridgedASTContext cContext, BridgedSourceLoc cLBLoc,
313327

314328
BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, SwiftInt len);
315329

330+
SWIFT_NAME("ParamDecl_create(astContext:declContext:specifierLoc:firstName:"
331+
"firstNameLoc:secondName:secondNameLoc:type:defaultValue:)")
316332
void *
317333
ParamDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext,
318334
BridgedSourceLoc cSpecifierLoc, BridgedIdentifier cFirstName,
319335
BridgedSourceLoc cFirstNameLoc, BridgedIdentifier cSecondName,
320336
BridgedSourceLoc cSecondNameLoc, void *_Nullable opaqueType,
321337
void *_Nullable opaqueDefaultValue);
322338

339+
SWIFT_NAME("AbstractFunctionDecl_setBody(_:ofDecl:)")
323340
void AbstractFunctionDecl_setBody(void *opaqueBody, void *opaqueDecl);
324341

342+
SWIFT_NAME("FuncDecl_create(astContext:declContext:staticLoc:funcKeywordLoc:"
343+
"name:nameLoc:genericParamList:parameterList:asyncSpecifierLoc:"
344+
"throwsSpecifierLoc:returnType:genericWhereClause:)")
325345
struct BridgedDeclContextAndDecl
326346
FuncDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext,
327347
BridgedSourceLoc cStaticLoc, BridgedSourceLoc cFuncKeywordLoc,
@@ -331,13 +351,17 @@ FuncDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext,
331351
BridgedSourceLoc cThrowsLoc, void *_Nullable opaqueReturnType,
332352
void *_Nullable opaqueGenericWhereClause);
333353

354+
SWIFT_NAME("ConstructorDecl_create(astContext:declContext:initKeywordLoc:"
355+
"failabilityMarkLoc:isIUO:genericParamList:parameterList:"
356+
"asyncSpecifierLoc:throwsSpecifierLoc:genericWhereClause:)")
334357
BridgedDeclContextAndDecl ConstructorDecl_create(
335358
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
336359
BridgedSourceLoc cInitKeywordLoc, BridgedSourceLoc cFailabilityMarkLoc,
337360
_Bool isIUO, void *_Nullable opaqueGenericParams, void *opaqueParameterList,
338361
BridgedSourceLoc cAsyncLoc, BridgedSourceLoc cThrowsLoc,
339362
void *_Nullable opaqueGenericWhereClause);
340363

364+
SWIFT_NAME("DestructorDecl_create(astContext:declContext:deinitKeywordLoc:)")
341365
BridgedDeclContextAndDecl
342366
DestructorDecl_create(BridgedASTContext cContext,
343367
BridgedDeclContext cDeclContext,
@@ -353,6 +377,9 @@ void *UnresolvedDotExpr_create(BridgedASTContext cContext, void *base,
353377
void *ClosureExpr_create(BridgedASTContext cContext, void *body,
354378
BridgedDeclContext cDeclContext);
355379

380+
SWIFT_NAME(
381+
"TypeAliasDecl_create(astContext:declContext:typealiasKeywordLoc:name:"
382+
"nameLoc:genericParamList:equalLoc:underlyingType:genericWhereClause:)")
356383
void *TypeAliasDecl_create(BridgedASTContext cContext,
357384
BridgedDeclContext cDeclContext,
358385
BridgedSourceLoc cAliasKeywordLoc,
@@ -362,48 +389,66 @@ void *TypeAliasDecl_create(BridgedASTContext cContext,
362389
void *opaqueUnderlyingType,
363390
void *_Nullable opaqueGenericWhereClause);
364391

392+
SWIFT_NAME("IterableDeclContext_setParsedMembers(_:ofDecl:)")
365393
void IterableDeclContext_setParsedMembers(BridgedArrayRef members,
366394
void *opaqueDecl);
367395

396+
SWIFT_NAME("EnumDecl_create(astContext:declContext:enumKeywordLoc:name:nameLoc:"
397+
"genericParamList:inheritedTypes:genericWhereClause:braceRange:)")
368398
BridgedDeclContextAndDecl EnumDecl_create(
369399
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
370400
BridgedSourceLoc cEnumKeywordLoc, BridgedIdentifier cName,
371401
BridgedSourceLoc cNameLoc, void *_Nullable opaqueGenericParamList,
372402
BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
373403
BridgedSourceRange cBraceRange);
374404

405+
SWIFT_NAME("EnumCaseDecl_create(declContext:caseKeywordLoc:elements:)")
375406
void *EnumCaseDecl_create(BridgedDeclContext cDeclContext,
376407
BridgedSourceLoc cCaseKeywordLoc,
377408
BridgedArrayRef cElements);
378409

410+
SWIFT_NAME("EnumElementDecl_create(astContext:declContext:name:nameLoc:"
411+
"parameterList:equalsLoc:rawValue:)")
379412
void *EnumElementDecl_create(BridgedASTContext cContext,
380413
BridgedDeclContext cDeclContext,
381414
BridgedIdentifier cName, BridgedSourceLoc cNameLoc,
382415
void *_Nullable opaqueParameterList,
383416
BridgedSourceLoc cEqualsLoc,
384417
void *_Nullable opaqueRawValue);
385418

419+
SWIFT_NAME(
420+
"StructDecl_create(astContext:declContext:structKeywordLoc:name:nameLoc:"
421+
"genericParamList:inheritedTypes:genericWhereClause:braceRange:)")
386422
BridgedDeclContextAndDecl StructDecl_create(
387423
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
388424
BridgedSourceLoc cStructKeywordLoc, BridgedIdentifier cName,
389425
BridgedSourceLoc cNameLoc, void *_Nullable opaqueGenericParamList,
390426
BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
391427
BridgedSourceRange cBraceRange);
392428

429+
SWIFT_NAME(
430+
"ClassDecl_create(astContext:declContext:classKeywordLoc:name:nameLoc:"
431+
"genericParamList:inheritedTypes:genericWhereClause:braceRange:isActor:)")
393432
BridgedDeclContextAndDecl ClassDecl_create(
394433
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
395434
BridgedSourceLoc cClassKeywordLoc, BridgedIdentifier cName,
396435
BridgedSourceLoc cNameLoc, void *_Nullable opaqueGenericParamList,
397436
BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
398437
BridgedSourceRange cBraceRange, _Bool isActor);
399438

439+
SWIFT_NAME("ProtocolDecl_create(astContext:declContext:protocolKeywordLoc:name:"
440+
"nameLoc:primaryAssociatedTypeNames:inheritedTypes:"
441+
"genericWhereClause:braceRange:)")
400442
BridgedDeclContextAndDecl ProtocolDecl_create(
401443
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
402444
BridgedSourceLoc cProtocolKeywordLoc, BridgedIdentifier cName,
403445
BridgedSourceLoc cNameLoc, BridgedArrayRef cPrimaryAssociatedTypeNames,
404446
BridgedArrayRef cInheritedTypes, void *_Nullable opaqueGenericWhereClause,
405447
BridgedSourceRange cBraceRange);
406448

449+
SWIFT_NAME(
450+
"AssociatedTypeDecl_create(astContext:declContext:associatedtypeKeywordLoc:"
451+
"name:nameLoc:inheritedTypes:defaultType:genericWhereClause:)")
407452
void *AssociatedTypeDecl_create(BridgedASTContext cContext,
408453
BridgedDeclContext cDeclContext,
409454
BridgedSourceLoc cAssociatedtypeKeywordLoc,
@@ -413,6 +458,8 @@ void *AssociatedTypeDecl_create(BridgedASTContext cContext,
413458
void *_Nullable opaqueDefaultType,
414459
void *_Nullable opaqueGenericWhereClause);
415460

461+
SWIFT_NAME("ExtensionDecl_create(astContext:declContext:extensionKeywordLoc:"
462+
"extendedType:inheritedTypes:genericWhereClause:braceRange:)")
416463
BridgedDeclContextAndDecl ExtensionDecl_create(
417464
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
418465
BridgedSourceLoc cExtensionKeywordLoc, void *opaqueExtendedType,
@@ -425,6 +472,9 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(closed) {
425472
BridgedOperatorFixityPostfix,
426473
} BridgedOperatorFixity;
427474

475+
SWIFT_NAME(
476+
"OperatorDecl_create(astContext:declContext:fixity:operatorKeywordLoc:name:"
477+
"nameLoc:colonLoc:precedenceGroupName:PrecedenceGroupLoc:)")
428478
void *OperatorDecl_create(BridgedASTContext cContext,
429479
BridgedDeclContext cDeclContext,
430480
BridgedOperatorFixity cFixity,
@@ -440,6 +490,11 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(closed) {
440490
BridgedAssociativityRight,
441491
} BridgedAssociativity;
442492

493+
SWIFT_NAME("PrecedenceGroupDecl_create(declContext:precedencegroupKeywordLoc:"
494+
"name:nameLoc:leftBraceLoc:associativityLabelLoc:"
495+
"associativityValueLoc:associativity:assignmentLabelLoc:"
496+
"assignmentValueLoc:isAssignment:higherThanKeywordLoc:"
497+
"higherThanNames:lowerThanKeywordLoc:lowerThanNames:rightBraceLoc:)")
443498
void *PrecedenceGroupDecl_create(
444499
BridgedDeclContext cDeclContext,
445500
BridgedSourceLoc cPrecedencegroupKeywordLoc, BridgedIdentifier cName,
@@ -463,19 +518,25 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) {
463518
BridgedImportKindFunc,
464519
} BridgedImportKind;
465520

521+
SWIFT_NAME("ImportDecl_create(astContext:declContext:importKeywordLoc:"
522+
"importKind:importKindLoc:path:)")
466523
void *ImportDecl_create(BridgedASTContext cContext,
467524
BridgedDeclContext cDeclContext,
468525
BridgedSourceLoc cImportKeywordLoc,
469526
BridgedImportKind cImportKind,
470527
BridgedSourceLoc cImportKindLoc,
471528
BridgedArrayRef cImportPathElements);
472529

530+
SWIFT_NAME("GenericParamList_create(astContext:leftAngleLoc:parameters:"
531+
"genericWhereClause:rightAngleLoc:)")
473532
void *GenericParamList_create(BridgedASTContext cContext,
474533
BridgedSourceLoc cLeftAngleLoc,
475534
BridgedArrayRef cParameters,
476535
void *_Nullable opaqueGenericWhereClause,
477536
BridgedSourceLoc cRightAngleLoc);
478537

538+
SWIFT_NAME("GenericTypeParamDecl_create(astContext:declContext:eachKeywordLoc:"
539+
"name:nameLoc:inheritedType:index:)")
479540
void *GenericTypeParamDecl_create(BridgedASTContext cContext,
480541
BridgedDeclContext cDeclContext,
481542
BridgedSourceLoc cEachLoc,
@@ -484,10 +545,14 @@ void *GenericTypeParamDecl_create(BridgedASTContext cContext,
484545
void *_Nullable opaqueInheritedType,
485546
SwiftInt index);
486547

548+
SWIFT_NAME(
549+
"TrailingWhereClause_create(astContext:whereKeywordLoc:requirements:)")
487550
void *TrailingWhereClause_create(BridgedASTContext cContext,
488551
BridgedSourceLoc cWhereKeywordLoc,
489552
BridgedArrayRef cRequirements);
490553

554+
SWIFT_NAME(
555+
"ParameterList_create(astContext:leftParenLoc:parameters:rightParenLoc:)")
491556
void *ParameterList_create(BridgedASTContext cContext,
492557
BridgedSourceLoc cLeftParenLoc,
493558
BridgedArrayRef cParameters,
@@ -600,4 +665,6 @@ _Bool Plugin_waitForNextMessage(PluginHandle handle, BridgedData *data);
600665
SWIFT_END_ASSUME_NONNULL
601666
SWIFT_END_NULLABILITY_ANNOTATIONS
602667

668+
#undef SWIFT_NAME
669+
603670
#endif // SWIFT_C_AST_ASTBRIDGING_H

lib/AST/CASTBridging.cpp

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

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

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

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

222-
auto *E = static_cast<Expr *>(element);
222+
auto *E = static_cast<Expr *>(expression);
223223
auto Brace = BraceStmt::create(context, convertSourceLoc(cStartLoc), {E},
224224
convertSourceLoc(cEndLoc),
225225
/*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)