Skip to content

Commit 394d064

Browse files
CodaFiDougGregor
authored andcommitted
Tidy Up The C AST Bridging File A Bit
1 parent 822fd47 commit 394d064

File tree

6 files changed

+47
-32
lines changed

6 files changed

+47
-32
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4906,11 +4906,13 @@ class ConstraintSystem {
49064906
ConstraintLocator *locator,
49074907
OpenedTypeMap *replacements = nullptr);
49084908

4909+
#if SWIFT_SWIFT_PARSER
49094910
/// Retrieve the opened type of a macro with the given name.
49104911
///
49114912
/// \returns The opened type of the macro with this name, or the null \c Type
49124913
/// if no such macro exists.
49134914
Type getTypeOfMacroReference(StringRef macro, Expr *anchor);
4915+
#endif
49144916

49154917
/// Retrieve a list of generic parameter types solver has "opened" (replaced
49164918
/// with a type variable) at the given location.

lib/AST/CASTBridging.cpp

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ void *SimpleIdentTypeRepr_create(void *ctx, void *loc, BridgedIdentifier id) {
226226
DeclNameRef(Identifier::getFromOpaquePointer(id)));
227227
}
228228

229-
230-
void *GenericIdentTypeRepr_create(void *ctx, BridgedIdentifier name, void *nameLoc, BridgedArrayRef genericArgs, void *lAngle, void *rAngle) {
229+
void *GenericIdentTypeRepr_create(void *ctx, BridgedIdentifier name,
230+
void *nameLoc, BridgedArrayRef genericArgs,
231+
void *lAngle, void *rAngle) {
231232
ASTContext &Context = *static_cast<ASTContext *>(ctx);
232233
auto Loc = DeclNameLoc(getSourceLocFromPointer(nameLoc));
233234
auto Name = DeclNameRef(Identifier::getFromOpaquePointer(name));
@@ -268,8 +269,9 @@ void NominalTypeDecl_setMembers(void *decl, BridgedArrayRef members) {
268269
((NominalTypeDecl *)decl)->addMember(m);
269270
}
270271

271-
DeclContextAndDecl StructDecl_create(
272-
void *ctx, void *loc, BridgedIdentifier name, void *nameLoc, void *_Nullable genericParams, void *dc) {
272+
DeclContextAndDecl StructDecl_create(void *ctx, void *loc,
273+
BridgedIdentifier name, void *nameLoc,
274+
void *_Nullable genericParams, void *dc) {
273275
ASTContext &Context = *static_cast<ASTContext *>(ctx);
274276
auto *out = new (Context) StructDecl(getSourceLocFromPointer(loc),
275277
Identifier::getFromOpaquePointer(name),
@@ -310,7 +312,9 @@ void *ArrayTypeRepr_create(void *ctx, void *base, void *lsquareLoc, void *rsquar
310312
return new (Context) ArrayTypeRepr((TypeRepr *)base, SourceRange{lSquareLoc, rSquareLoc});
311313
}
312314

313-
void *DictionaryTypeRepr_create(void *ctx, void *keyType, void *valueType, void *lsquareLoc, void *colonloc, void *rsquareLoc) {
315+
void *DictionaryTypeRepr_create(void *ctx, void *keyType, void *valueType,
316+
void *lsquareLoc, void *colonloc,
317+
void *rsquareLoc) {
314318
ASTContext &Context = *static_cast<ASTContext *>(ctx);
315319
SourceLoc lSquareLoc = getSourceLocFromPointer(lsquareLoc);
316320
SourceLoc colonLoc = getSourceLocFromPointer(colonloc);
@@ -367,7 +371,9 @@ void *CompositionTypeRepr_create(void *ctx, BridgedArrayRef types, void *firstTy
367371
return CompositionTypeRepr::create(Context, getArrayRef<TypeRepr *>(types), firstType, SourceRange{});
368372
}
369373

370-
void *FunctionTypeRepr_create(void *ctx, void *argsTy, void *_Nullable asyncLoc, void *_Nullable throwsLoc, void *arrowLoc, void *returnType) {
374+
void *FunctionTypeRepr_create(void *ctx, void *argsTy, void *_Nullable asyncLoc,
375+
void *_Nullable throwsLoc, void *arrowLoc,
376+
void *returnType) {
371377
ASTContext &Context = *static_cast<ASTContext *>(ctx);
372378
return new (Context) FunctionTypeRepr(nullptr,
373379
(TupleTypeRepr *)argsTy,
@@ -391,25 +397,27 @@ void *ExistentialTypeRepr_create(void *ctx, void *anyLoc, void *baseTy) {
391397
return new (Context) ExistentialTypeRepr(getSourceLocFromPointer(anyLoc), (TypeRepr *)baseTy);
392398
}
393399

394-
void *GenericParamList_create(void *ctx, void *lAngleLoc, BridgedArrayRef params, void *_Nullable whereLoc, BridgedArrayRef reqs, void *rAngleLoc) {
400+
void *GenericParamList_create(void *ctx, void *lAngleLoc,
401+
BridgedArrayRef params, void *_Nullable whereLoc,
402+
BridgedArrayRef reqs, void *rAngleLoc) {
395403
ASTContext &Context = *static_cast<ASTContext *>(ctx);
396404
SmallVector<RequirementRepr> requirements;
397405
for (auto req : getArrayRef<BridgedRequirementRepr>(reqs)) {
398406
switch (req.Kind) {
399407
case BridgedRequirementReprKindTypeConstraint:
400-
requirements.push_back(
401-
RequirementRepr::getTypeConstraint((TypeRepr *)req.FirstType,
402-
getSourceLocFromPointer(req.SeparatorLoc),
403-
(TypeRepr *)req.SecondType));
404-
break;
408+
requirements.push_back(
409+
RequirementRepr::getTypeConstraint((TypeRepr *)req.FirstType,
410+
getSourceLocFromPointer(req.SeparatorLoc),
411+
(TypeRepr *)req.SecondType));
412+
break;
405413
case BridgedRequirementReprKindSameType:
406-
requirements.push_back(
407-
RequirementRepr::getSameType((TypeRepr *)req.FirstType,
408-
getSourceLocFromPointer(req.SeparatorLoc),
409-
(TypeRepr *)req.SecondType));
410-
break;
414+
requirements.push_back(
415+
RequirementRepr::getSameType((TypeRepr *)req.FirstType,
416+
getSourceLocFromPointer(req.SeparatorLoc),
417+
(TypeRepr *)req.SecondType));
418+
break;
411419
case BridgedRequirementReprKindLayoutConstraint:
412-
llvm_unreachable("cannot handle layout constraints!");
420+
llvm_unreachable("cannot handle layout constraints!");
413421
}
414422
}
415423
return GenericParamList::create(Context,
@@ -420,7 +428,10 @@ void *GenericParamList_create(void *ctx, void *lAngleLoc, BridgedArrayRef params
420428
getSourceLocFromPointer(rAngleLoc));
421429
}
422430

423-
void *GenericTypeParamDecl_create(void *ctx, void *declContext, BridgedIdentifier name, void *nameLoc, void *_Nullable ellipsisLoc, long index, bool isParameterPack) {
431+
void *GenericTypeParamDecl_create(void *ctx, void *declContext,
432+
BridgedIdentifier name, void *nameLoc,
433+
void *_Nullable ellipsisLoc, long index,
434+
bool isParameterPack) {
424435
return GenericTypeParamDecl::createParsed(static_cast<DeclContext *>(declContext),
425436
Identifier::getFromOpaquePointer(name),
426437
getSourceLocFromPointer(nameLoc),
@@ -437,8 +448,10 @@ void GenericTypeParamDecl_setInheritedType(void *ctx, void *Param, void *ty) {
437448
((GenericTypeParamDecl *)Param)->setInherited(entries);
438449
}
439450

440-
441-
DeclContextAndDecl TypeAliasDecl_create(void *ctx, void *declContext, void *aliasLoc, void *equalLoc, BridgedIdentifier name, void *nameLoc, void *_Nullable genericParams) {
451+
DeclContextAndDecl TypeAliasDecl_create(void *ctx, void *declContext,
452+
void *aliasLoc, void *equalLoc,
453+
BridgedIdentifier name, void *nameLoc,
454+
void *_Nullable genericParams) {
442455
ASTContext &Context = *static_cast<ASTContext *>(ctx);
443456
auto *out = new (Context) TypeAliasDecl(getSourceLocFromPointer(aliasLoc),
444457
getSourceLocFromPointer(equalLoc),

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3630,7 +3630,7 @@ namespace {
36303630
Type visitMacroExpansionExpr(MacroExpansionExpr *expr) {
36313631
#if SWIFT_SWIFT_PARSER
36323632
auto &ctx = CS.getASTContext();
3633-
if (ctx.LangOpts.hasFeature(Feature::BuiltinMacros)) {
3633+
if (ctx.LangOpts.hasFeature(Feature::Macros)) {
36343634
auto *UDRE = dyn_cast<UnresolvedDeclRefExpr>(expr->getMacro());
36353635
if (!UDRE)
36363636
return Type();

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,6 +2471,7 @@ ConstraintSystem::getTypeOfMemberReference(
24712471
return { origOpenedType, openedType, origType, type };
24722472
}
24732473

2474+
#if SWIFT_SWIFT_PARSER
24742475
Type ConstraintSystem::getTypeOfMacroReference(StringRef macroName,
24752476
Expr *anchor) {
24762477
auto macroCtx = swift::macro_context::lookup(macroName, DC);
@@ -2480,17 +2481,17 @@ Type ConstraintSystem::getTypeOfMacroReference(StringRef macroName,
24802481
auto *locator = getConstraintLocator(anchor);
24812482
// Dig through to __MacroEvaluationContext.SignatureType
24822483
auto sig = getASTContext().getIdentifier("SignatureType");
2483-
auto *signature = macroCtx->lookupDirect(sig).front();
2484-
auto type = cast<TypeAliasDecl>(signature)->getUnderlyingType();
2484+
auto *signature = cast<TypeAliasDecl>(macroCtx->lookupDirect(sig).front());
2485+
auto type = signature->getUnderlyingType();
24852486

2486-
// Open up the generic type.
2487+
// Open any the generic types.
24872488
OpenedTypeMap replacements;
2488-
openGeneric(cast<TypeAliasDecl>(signature)->getParent(),
2489-
cast<TypeAliasDecl>(signature)->getGenericSignature(), locator,
2490-
replacements);
2489+
openGeneric(signature->getParent(), signature->getGenericSignature(),
2490+
locator, replacements);
24912491

24922492
return openType(type, replacements);
24932493
}
2494+
#endif
24942495

24952496
Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
24962497
const OverloadChoice &overload,

lib/Sema/TypeCheckMacros.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ swift::macro_context::lookup(StringRef macroName, DeclContext *DC) {
8888
});
8989
}
9090

91-
#endif // SWIFT_SWIFT_PARSER
92-
9391
Expr *swift::expandMacroExpr(
9492
DeclContext *dc, Expr *expr, StringRef macroName, Type expandedType
9593
) {
@@ -182,3 +180,5 @@ Expr *swift::expandMacroExpr(
182180
"Type checking changed the result type?");
183181
return expandedExpr;
184182
}
183+
184+
#endif // SWIFT_SWIFT_PARSER

lib/Sema/TypeCheckMacros.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ namespace macro_context {
4949
StructDecl *lookup(StringRef macroName, DeclContext *useDC);
5050
}
5151

52-
#endif
53-
5452
/// Expands the given macro expression and type-check the result with
5553
/// the given expanded type.
5654
///
@@ -61,5 +59,6 @@ Expr *expandMacroExpr(
6159

6260
} // end namespace swift
6361

62+
#endif // SWIFT_SWIFT_PARSER
6463
#endif /* SWIFT_SEMA_TYPECHECKMACROS_H */
6564

0 commit comments

Comments
 (0)