Skip to content

Commit 198f8e9

Browse files
committed
Run clang-format on the Print Availability and its related methods
1 parent ba52903 commit 198f8e9

File tree

1 file changed

+71
-64
lines changed

1 file changed

+71
-64
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -776,26 +776,26 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
776776
};
777777

778778
/// Returns \c true if anything was printed.
779-
bool printAvailability(
780-
const Decl *D,
781-
PrintLeadingSpace printLeadingSpace = PrintLeadingSpace::Yes) {
779+
bool printAvailability(const Decl *D, PrintLeadingSpace printLeadingSpace =
780+
PrintLeadingSpace::Yes) {
782781
bool hasPrintedAnything = false;
783782
auto maybePrintLeadingSpace = [&] {
784783
if (printLeadingSpace == PrintLeadingSpace::Yes || hasPrintedAnything)
785784
os << " ";
786785
hasPrintedAnything = true;
787786
};
788-
787+
789788
for (auto AvAttr : D->getAttrs().getAttributes<AvailableAttr>()) {
790789
if (AvAttr->Platform == PlatformKind::none) {
791-
if (AvAttr->PlatformAgnostic == PlatformAgnosticAvailabilityKind::Unavailable) {
790+
if (AvAttr->PlatformAgnostic ==
791+
PlatformAgnosticAvailabilityKind::Unavailable) {
792792
// Availability for *
793793
if (!AvAttr->Rename.empty() && isa<ValueDecl>(D)) {
794794
// rename
795795
maybePrintLeadingSpace();
796796
os << "SWIFT_UNAVAILABLE_MSG(\"'"
797-
<< cast<ValueDecl>(D)->getBaseName()
798-
<< "' has been renamed to '";
797+
<< cast<ValueDecl>(D)->getBaseName()
798+
<< "' has been renamed to '";
799799
printRenameForDecl(AvAttr, cast<ValueDecl>(D), false);
800800
os << '\'';
801801
if (!AvAttr->Message.empty()) {
@@ -831,46 +831,45 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
831831
}
832832
continue;
833833
}
834-
834+
835835
// Availability for a specific platform
836-
if (!AvAttr->Introduced.hasValue()
837-
&& !AvAttr->Deprecated.hasValue()
838-
&& !AvAttr->Obsoleted.hasValue()
839-
&& !AvAttr->isUnconditionallyDeprecated()
840-
&& !AvAttr->isUnconditionallyUnavailable()) {
836+
if (!AvAttr->Introduced.hasValue() && !AvAttr->Deprecated.hasValue() &&
837+
!AvAttr->Obsoleted.hasValue() &&
838+
!AvAttr->isUnconditionallyDeprecated() &&
839+
!AvAttr->isUnconditionallyUnavailable()) {
841840
continue;
842841
}
843-
842+
844843
const char *plat;
845844
switch (AvAttr->Platform) {
846-
case PlatformKind::OSX:
847-
plat = "macos";
848-
break;
849-
case PlatformKind::iOS:
850-
plat = "ios";
851-
break;
852-
case PlatformKind::tvOS:
853-
plat = "tvos";
854-
break;
855-
case PlatformKind::watchOS:
856-
plat = "watchos";
857-
break;
858-
case PlatformKind::OSXApplicationExtension:
859-
plat = "macos_app_extension";
860-
break;
861-
case PlatformKind::iOSApplicationExtension:
862-
plat = "ios_app_extension";
863-
break;
864-
case PlatformKind::tvOSApplicationExtension:
865-
plat = "tvos_app_extension";
866-
break;
867-
case PlatformKind::watchOSApplicationExtension:
868-
plat = "watchos_app_extension";
869-
break;
870-
case PlatformKind::none:
871-
llvm_unreachable("handled above");
845+
case PlatformKind::OSX:
846+
plat = "macos";
847+
break;
848+
case PlatformKind::iOS:
849+
plat = "ios";
850+
break;
851+
case PlatformKind::tvOS:
852+
plat = "tvos";
853+
break;
854+
case PlatformKind::watchOS:
855+
plat = "watchos";
856+
break;
857+
case PlatformKind::OSXApplicationExtension:
858+
plat = "macos_app_extension";
859+
break;
860+
case PlatformKind::iOSApplicationExtension:
861+
plat = "ios_app_extension";
862+
break;
863+
case PlatformKind::tvOSApplicationExtension:
864+
plat = "tvos_app_extension";
865+
break;
866+
case PlatformKind::watchOSApplicationExtension:
867+
plat = "watchos_app_extension";
868+
break;
869+
case PlatformKind::none:
870+
llvm_unreachable("handled above");
872871
}
873-
872+
874873
maybePrintLeadingSpace();
875874
os << "SWIFT_AVAILABILITY(" << plat;
876875
if (AvAttr->isUnconditionallyUnavailable()) {
@@ -896,7 +895,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
896895
}
897896
if (!AvAttr->Rename.empty() && isa<ValueDecl>(D)) {
898897
os << ",message=\"'" << cast<ValueDecl>(D)->getBaseName()
899-
<< "' has been renamed to '";
898+
<< "' has been renamed to '";
900899
printRenameForDecl(AvAttr, cast<ValueDecl>(D), false);
901900
os << '\'';
902901
if (!AvAttr->Message.empty()) {
@@ -913,46 +912,52 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
913912
return hasPrintedAnything;
914913
}
915914

916-
const ValueDecl *getRenameDecl(const ValueDecl *D, const ParsedDeclName renamedParsedDeclName) {
915+
const ValueDecl *getRenameDecl(const ValueDecl *D,
916+
const ParsedDeclName renamedParsedDeclName) {
917917
auto declContext = D->getDeclContext();
918918
ASTContext &astContext = D->getASTContext();
919919
auto renamedDeclName = renamedParsedDeclName.formDeclName(astContext);
920920

921921
if (isa<ClassDecl>(D) || isa<ProtocolDecl>(D)) {
922922
UnqualifiedLookup lookup(renamedDeclName.getBaseIdentifier(),
923-
declContext->getModuleScopeContext(),
924-
nullptr,
923+
declContext->getModuleScopeContext(), nullptr,
925924
SourceLoc(),
926925
UnqualifiedLookup::Flags::TypeLookup);
927926
return lookup.getSingleTypeResult();
928927
} else {
929928
TypeDecl *typeDecl = declContext->getSelfNominalTypeDecl();
930929

931930
if (!renamedParsedDeclName.ContextName.empty()) {
932-
auto contextIdentifier = astContext.getIdentifier(renamedParsedDeclName.ContextName);
933-
UnqualifiedLookup specificTypeLookup(contextIdentifier,
934-
declContext->getModuleScopeContext(),
935-
nullptr,
936-
SourceLoc(),
937-
UnqualifiedLookup::Flags::TypeLookup);
931+
auto contextIdentifier =
932+
astContext.getIdentifier(renamedParsedDeclName.ContextName);
933+
UnqualifiedLookup specificTypeLookup(
934+
contextIdentifier, declContext->getModuleScopeContext(), nullptr,
935+
SourceLoc(), UnqualifiedLookup::Flags::TypeLookup);
938936
if (!specificTypeLookup.getSingleTypeResult()) {
939937
return nullptr;
940938
}
941939

942-
if (typeDecl->getDeclaredInterfaceType()->matches(specificTypeLookup.getSingleTypeResult()->getDeclaredInterfaceType(), TypeMatchFlags::AllowOverride)) {
943-
// If the Context Name contain the name of the subclass then we would find the renamed in the superclass instead
940+
if (typeDecl->getDeclaredInterfaceType()->matches(
941+
specificTypeLookup.getSingleTypeResult()
942+
->getDeclaredInterfaceType(),
943+
TypeMatchFlags::AllowOverride)) {
944+
// If the Context Name contain the name of the subclass then we would
945+
// find the renamed in the superclass instead
944946
typeDecl = specificTypeLookup.getSingleTypeResult();
945-
} else if (!specificTypeLookup.getSingleTypeResult()->getDeclaredInterfaceType()->matches(typeDecl->getDeclaredInterfaceType(), TypeMatchFlags::AllowOverride)) {
946-
// Failed and print the raw renamed attributed when there is no relationship between those 2 types
947-
return nullptr;
948-
}
947+
} else if (!specificTypeLookup.getSingleTypeResult()
948+
->getDeclaredInterfaceType()
949+
->matches(typeDecl->getDeclaredInterfaceType(),
950+
TypeMatchFlags::AllowOverride)) {
951+
// Failed and print the raw renamed attributed when there is no
952+
// relationship between those 2 types
953+
return nullptr;
954+
}
949955
}
950956

951957
const ValueDecl *renamedDecl = nullptr;
952958
SmallVector<ValueDecl *, 4> lookupResults;
953-
declContext->lookupQualified(
954-
typeDecl,
955-
renamedDeclName, NL_QualifiedDefault, lookupResults);
959+
declContext->lookupQualified(typeDecl, renamedDeclName,
960+
NL_QualifiedDefault, lookupResults);
956961
for (auto candidate : lookupResults) {
957962
if (!shouldInclude(candidate))
958963
continue;
@@ -973,7 +978,8 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
973978
for (auto index : indices(*cParams)) {
974979
auto cParamsType = cParams->get(index)->getType();
975980
auto dParamsType = dParams->get(index)->getType();
976-
if (!cParamsType->matchesParameter(dParamsType, TypeMatchFlags::AllowOverride)) {
981+
if (!cParamsType->matchesParameter(dParamsType,
982+
TypeMatchFlags::AllowOverride)) {
977983
hasSameParameterTypes = false;
978984
break;
979985
}
@@ -999,12 +1005,13 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
9991005
bool includeQuotes) {
10001006
assert(!AvAttr->Rename.empty());
10011007

1002-
const swift::ValueDecl * renamedDecl = getRenameDecl(D, parseDeclName(AvAttr->Rename));
1008+
const swift::ValueDecl *renamedDecl =
1009+
getRenameDecl(D, parseDeclName(AvAttr->Rename));
10031010

10041011
if (renamedDecl) {
10051012
SmallString<128> scratch;
1006-
auto renamedObjCRuntimeName = renamedDecl->getObjCRuntimeName()
1007-
->getString(scratch);
1013+
auto renamedObjCRuntimeName =
1014+
renamedDecl->getObjCRuntimeName()->getString(scratch);
10081015
printEncodedString(renamedObjCRuntimeName, includeQuotes);
10091016
} else {
10101017
printEncodedString(AvAttr->Rename, includeQuotes);

0 commit comments

Comments
 (0)