Skip to content

Commit 5ad0a8a

Browse files
committed
Remove assumptions of AccessLevel::Public from SwiftDeclSynth
1 parent bd82933 commit 5ad0a8a

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ SwiftDeclSynthesizer::createDefaultConstructor(NominalTypeDecl *structDecl) {
509509
/*GenericParams=*/nullptr, structDecl,
510510
/*LifetimeDependentTypeRepr*/ nullptr);
511511

512-
constructor->setAccess(AccessLevel::Public);
512+
constructor->copyFormalAccessFrom(structDecl);
513513

514514
// Mark the constructor transparent so that we inline it away completely.
515515
constructor->getAttrs().add(new (context) TransparentAttr(/*implicit*/ true));
@@ -640,7 +640,7 @@ ConstructorDecl *SwiftDeclSynthesizer::createValueConstructor(
640640
/*GenericParams=*/nullptr, structDecl,
641641
/*LifetimeDependentTypeRepr*/ nullptr);
642642

643-
constructor->setAccess(AccessLevel::Public);
643+
constructor->copyFormalAccessFrom(structDecl);
644644

645645
// Make the constructor transparent so we inline it away completely.
646646
constructor->getAttrs().add(new (context) TransparentAttr(/*implicit*/ true));
@@ -750,7 +750,7 @@ void SwiftDeclSynthesizer::makeStructRawValuedWithBridge(
750750
computedVarName, structDecl);
751751
computedVar->setInterfaceType(bridgedType);
752752
computedVar->setImplicit();
753-
computedVar->setAccess(AccessLevel::Public);
753+
computedVar->copyFormalAccessFrom(structDecl);
754754
computedVar->setSetterAccess(AccessLevel::Private);
755755

756756
// Create the getter for the computed value variable.
@@ -1364,7 +1364,7 @@ void SwiftDeclSynthesizer::makeEnumRawValueGetter(EnumDecl *enumDecl,
13641364
getterDecl->setIsDynamic(false);
13651365
getterDecl->setIsTransparent(false);
13661366

1367-
getterDecl->setAccess(AccessLevel::Public);
1367+
getterDecl->copyFormalAccessFrom(enumDecl);
13681368
getterDecl->setBodySynthesizer(synthesizeEnumRawValueGetterBody, enumDecl);
13691369
ImporterImpl.makeComputed(rawValueDecl, getterDecl, nullptr);
13701370
}
@@ -1428,7 +1428,7 @@ AccessorDecl *SwiftDeclSynthesizer::makeStructRawValueGetter(
14281428
getterDecl->setIsDynamic(false);
14291429
getterDecl->setIsTransparent(false);
14301430

1431-
getterDecl->setAccess(AccessLevel::Public);
1431+
getterDecl->copyFormalAccessFrom(structDecl);
14321432
getterDecl->setBodySynthesizer(synthesizeStructRawValueGetterBody, storedVar);
14331433
return getterDecl;
14341434
}
@@ -1708,15 +1708,15 @@ SubscriptDecl *SwiftDeclSynthesizer::makeSubscript(FuncDecl *getter,
17081708
ctx, name, getterImpl->getLoc(), bodyParams, getterImpl->getLoc(),
17091709
elementTy, dc, getterImpl->getGenericParams(),
17101710
getterImpl->getClangNode());
1711-
subscript->setAccess(AccessLevel::Public);
1711+
subscript->copyFormalAccessFrom(getterImpl);
17121712

17131713
AccessorDecl *getterDecl =
17141714
AccessorDecl::create(ctx, getterImpl->getLoc(), getterImpl->getLoc(),
17151715
AccessorKind::Get, subscript,
17161716
/*async*/ false, SourceLoc(),
17171717
/*throws*/ false, SourceLoc(),
17181718
/*ThrownType=*/TypeLoc(), bodyParams, elementTy, dc);
1719-
getterDecl->setAccess(AccessLevel::Public);
1719+
getterDecl->copyFormalAccessFrom(subscript);
17201720
getterDecl->setImplicit();
17211721
getterDecl->setIsDynamic(false);
17221722
getterDecl->setIsTransparent(true);
@@ -1744,7 +1744,7 @@ SubscriptDecl *SwiftDeclSynthesizer::makeSubscript(FuncDecl *getter,
17441744
/*async*/ false, SourceLoc(),
17451745
/*throws*/ false, SourceLoc(), /*ThrownType=*/TypeLoc(),
17461746
setterParamList, TupleType::getEmpty(ctx), dc);
1747-
setterDecl->setAccess(AccessLevel::Public);
1747+
setterDecl->copyFormalAccessFrom(subscript);
17481748
setterDecl->setImplicit();
17491749
setterDecl->setIsDynamic(false);
17501750
setterDecl->setIsTransparent(true);
@@ -1794,7 +1794,7 @@ SwiftDeclSynthesizer::makeDereferencedPointeeProperty(FuncDecl *getter,
17941794
VarDecl(/*isStatic*/ false, VarDecl::Introducer::Var,
17951795
getterImpl->getStartLoc(), ctx.getIdentifier("pointee"), dc);
17961796
result->setInterfaceType(elementTy);
1797-
result->setAccess(AccessLevel::Public);
1797+
result->copyFormalAccessFrom(getterImpl);
17981798

17991799
AccessorDecl *getterDecl = AccessorDecl::create(
18001800
ctx, getterImpl->getLoc(), getterImpl->getLoc(),
@@ -1803,7 +1803,7 @@ SwiftDeclSynthesizer::makeDereferencedPointeeProperty(FuncDecl *getter,
18031803
/*throws*/ false, SourceLoc(), /*ThrownType=*/TypeLoc(),
18041804
ParameterList::createEmpty(ctx),
18051805
useAddress ? elementTy->wrapInPointer(PTK_UnsafePointer) : elementTy, dc);
1806-
getterDecl->setAccess(AccessLevel::Public);
1806+
getterDecl->copyFormalAccessFrom(getterImpl);
18071807
if (isImplicit)
18081808
getterDecl->setImplicit();
18091809
getterDecl->setIsDynamic(false);
@@ -1842,7 +1842,7 @@ SwiftDeclSynthesizer::makeDereferencedPointeeProperty(FuncDecl *getter,
18421842
useAddress ? elementTy->wrapInPointer(PTK_UnsafeMutablePointer)
18431843
: TupleType::getEmpty(ctx),
18441844
dc);
1845-
setterDecl->setAccess(AccessLevel::Public);
1845+
setterDecl->copyFormalAccessFrom(setterImpl);
18461846
if (isImplicit)
18471847
setterDecl->setImplicit();
18481848
setterDecl->setIsDynamic(false);
@@ -1895,7 +1895,8 @@ synthesizeSuccessorFuncBody(AbstractFunctionDecl *afd, void *context) {
18951895
std::tie(copyDecl, patternDecl) = SwiftDeclSynthesizer::createVarWithPattern(
18961896
successorDecl, ctx.getIdentifier("__copy"), returnTy,
18971897
VarDecl::Introducer::Var,
1898-
/*isImplicit*/ true, AccessLevel::Public, AccessLevel::Public);
1898+
/*isImplicit*/ true, successorDecl->getFormalAccess(),
1899+
successorDecl->getFormalAccess());
18991900

19001901
auto copyRefLValueExpr = new (ctx) DeclRefExpr(copyDecl, DeclNameLoc(),
19011902
/*implicit*/ true);
@@ -1943,7 +1944,7 @@ FuncDecl *SwiftDeclSynthesizer::makeSuccessorFunc(FuncDecl *incrementFunc) {
19431944
/*Async*/ false, /*Throws*/ false, /*ThrownType=*/Type(),
19441945
/*GenericParams*/ nullptr, params, returnTy, dc);
19451946

1946-
result->setAccess(AccessLevel::Public);
1947+
result->copyFormalAccessFrom(incrementFunc);
19471948
result->setIsDynamic(false);
19481949
result->setBodySynthesizer(synthesizeSuccessorFuncBody, incrementFunc);
19491950

@@ -2246,7 +2247,7 @@ SwiftDeclSynthesizer::makeOperator(FuncDecl *operatorMethod,
22462247
genericParamList, ParameterList::create(ctx, newParams),
22472248
operatorMethod->getResultInterfaceType(), parentCtx);
22482249

2249-
topLevelStaticFuncDecl->setAccess(AccessLevel::Public);
2250+
topLevelStaticFuncDecl->copyFormalAccessFrom(operatorMethod);
22502251
topLevelStaticFuncDecl->setIsDynamic(false);
22512252
topLevelStaticFuncDecl->setStatic();
22522253
topLevelStaticFuncDecl->setBodySynthesizer(synthesizeOperatorMethodBody,
@@ -2356,7 +2357,7 @@ SwiftDeclSynthesizer::makeComputedPropertyFromCXXMethods(FuncDecl *getter,
23562357
new (ctx) VarDecl(false, VarDecl::Introducer::Var, getter->getStartLoc(),
23572358
ctx.getIdentifier(importedName), dc);
23582359
result->setInterfaceType(getter->getResultInterfaceType());
2359-
result->setAccess(AccessLevel::Public);
2360+
result->copyFormalAccessFrom(getter);
23602361
result->setImplInfo(StorageImplInfo::getMutableComputed());
23612362

23622363
AccessorDecl *getterDecl = AccessorDecl::create(
@@ -2365,7 +2366,7 @@ SwiftDeclSynthesizer::makeComputedPropertyFromCXXMethods(FuncDecl *getter,
23652366
/*throws*/ false, SourceLoc(), /*ThrownType=*/TypeLoc(),
23662367
ParameterList::createEmpty(ctx),
23672368
getter->getResultInterfaceType(), dc);
2368-
getterDecl->setAccess(AccessLevel::Public);
2369+
getterDecl->copyFormalAccessFrom(getter);
23692370
getterDecl->setImplicit();
23702371
getterDecl->setIsDynamic(false);
23712372
getterDecl->setIsTransparent(true);
@@ -2390,7 +2391,7 @@ SwiftDeclSynthesizer::makeComputedPropertyFromCXXMethods(FuncDecl *getter,
23902391
/*async*/ false, SourceLoc(),
23912392
/*throws*/ false, SourceLoc(), /*thrownType*/ TypeLoc(),
23922393
setterParamList, setter->getResultInterfaceType(), dc);
2393-
setterDecl->setAccess(AccessLevel::Public);
2394+
setterDecl->copyFormalAccessFrom(setter);
23942395
setterDecl->setImplicit();
23952396
setterDecl->setIsDynamic(false);
23962397
setterDecl->setIsTransparent(true);

0 commit comments

Comments
 (0)