Skip to content

Commit 29eb740

Browse files
committed
[Runtime] Style fixes in new ReflectionMirror code.
rdar://problem/20356017
1 parent 0cff498 commit 29eb740

File tree

2 files changed

+70
-59
lines changed

2 files changed

+70
-59
lines changed

stdlib/public/core/ReflectionMirror.swift

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,32 @@ internal func _getClassPlaygroundQuickLook(
8686
default:
8787
return .int(number.longLongValue)
8888
}
89-
} else if _is(object, kindOf: "NSAttributedString") {
89+
}
90+
91+
if _is(object, kindOf: "NSAttributedString") {
9092
return .attributedString(object)
91-
} else if _is(object, kindOf: "NSImage") ||
92-
_is(object, kindOf: "UIImage") ||
93-
_is(object, kindOf: "NSImageView") ||
94-
_is(object, kindOf: "UIImageView") ||
95-
_is(object, kindOf: "CIImage") ||
96-
_is(object, kindOf: "NSBitmapImageRep") {
93+
}
94+
95+
if _is(object, kindOf: "NSImage") ||
96+
_is(object, kindOf: "UIImage") ||
97+
_is(object, kindOf: "NSImageView") ||
98+
_is(object, kindOf: "UIImageView") ||
99+
_is(object, kindOf: "CIImage") ||
100+
_is(object, kindOf: "NSBitmapImageRep") {
97101
return .image(object)
98-
} else if _is(object, kindOf: "NSColor") ||
99-
_is(object, kindOf: "UIColor") {
102+
}
103+
104+
if _is(object, kindOf: "NSColor") ||
105+
_is(object, kindOf: "UIColor") {
100106
return .color(object)
101-
} else if _is(object, kindOf: "NSBezierPath") ||
102-
_is(object, kindOf: "UIBezierPath") {
107+
}
108+
109+
if _is(object, kindOf: "NSBezierPath") ||
110+
_is(object, kindOf: "UIBezierPath") {
103111
return .bezierPath(object)
104-
} else if _is(object, kindOf: "NSString") {
112+
}
113+
114+
if _is(object, kindOf: "NSString") {
105115
return .text(_forceBridgeFromObjectiveC(object, String.self))
106116
}
107117

@@ -125,24 +135,24 @@ extension Mirror {
125135
self.children = Children(children)
126136

127137
self._makeSuperclassMirror = {
128-
if let subjectClass = subjectType as? AnyClass,
129-
let superclass = _getSuperclass(subjectClass) {
130-
// Handle custom ancestors. If we've hit the custom ancestor's subject type,
131-
// or descendants are suppressed, return it. Otherwise continue reflecting.
132-
if let customAncestor = customAncestor {
133-
if superclass == customAncestor.subjectType {
134-
return customAncestor
135-
}
136-
if customAncestor._defaultDescendantRepresentation == .suppressed {
137-
return customAncestor
138-
}
139-
}
140-
return Mirror(internalReflecting: subject,
141-
subjectType: superclass,
142-
customAncestor: customAncestor)
143-
} else {
138+
guard let subjectClass = subjectType as? AnyClass,
139+
let superclass = _getSuperclass(subjectClass) else {
144140
return nil
145141
}
142+
143+
// Handle custom ancestors. If we've hit the custom ancestor's subject type,
144+
// or descendants are suppressed, return it. Otherwise continue reflecting.
145+
if let customAncestor = customAncestor {
146+
if superclass == customAncestor.subjectType {
147+
return customAncestor
148+
}
149+
if customAncestor._defaultDescendantRepresentation == .suppressed {
150+
return customAncestor
151+
}
152+
}
153+
return Mirror(internalReflecting: subject,
154+
subjectType: superclass,
155+
customAncestor: customAncestor)
146156
}
147157

148158
let rawDisplayStyle = _getDisplayStyle(subject)

stdlib/public/runtime/ReflectionMirror.mm

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ - (id)debugQuickLookObject;
7171
// really matter yet since we don't have any special mirror behavior for
7272
// concrete metatypes yet.
7373
while (T->getKind() == MetadataKind::Existential) {
74-
auto existential
74+
auto *existential
7575
= static_cast<const ExistentialTypeMetadata *>(T);
7676

7777
// Unwrap the existential container.
@@ -94,8 +94,8 @@ static bool loadSpecialReferenceStorage(OpaqueValue *fieldData,
9494
auto type = fieldType.getType();
9595
assert(type->getKind() == MetadataKind::Optional);
9696

97-
auto weakField = reinterpret_cast<WeakReference *>(fieldData);
98-
auto strongValue = swift_unknownWeakLoadStrong(weakField);
97+
auto *weakField = reinterpret_cast<WeakReference *>(fieldData);
98+
auto *strongValue = swift_unknownWeakLoadStrong(weakField);
9999

100100
// Now that we have a strong reference, we need to create a temporary buffer
101101
// from which to copy the whole value, which might be a native class-bound
@@ -108,15 +108,15 @@ static bool loadSpecialReferenceStorage(OpaqueValue *fieldData,
108108
// - the witness table for Protocol1
109109
// - the witness table for Protocol2
110110

111-
auto weakContainer =
111+
auto *weakContainer =
112112
reinterpret_cast<WeakClassExistentialContainer *>(fieldData);
113113

114114
// Create a temporary existential where we can put the strong reference.
115115
// The allocateBuffer value witness requires a ValueBuffer to own the
116116
// allocated storage.
117117
ValueBuffer temporaryBuffer;
118118

119-
auto temporaryValue = reinterpret_cast<ClassExistentialContainer *>(
119+
auto *temporaryValue = reinterpret_cast<ClassExistentialContainer *>(
120120
type->allocateBufferIn(&temporaryBuffer));
121121

122122
// Now copy the entire value out of the parent, which will include the
@@ -170,19 +170,19 @@ virtual AnyReturn subscript(intptr_t index, const char **outName,
170170

171171

172172
// Implementation for tuples.
173-
struct TupleImpl: ReflectionMirrorImpl {
173+
struct TupleImpl : ReflectionMirrorImpl {
174174
char displayStyle() {
175175
return 't';
176176
}
177177

178178
intptr_t count() {
179-
auto Tuple = static_cast<const TupleTypeMetadata *>(type);
179+
auto *Tuple = static_cast<const TupleTypeMetadata *>(type);
180180
return Tuple->NumElements;
181181
}
182182

183183
AnyReturn subscript(intptr_t i, const char **outName,
184184
void (**outFreeFunc)(const char *)) {
185-
auto Tuple = static_cast<const TupleTypeMetadata *>(type);
185+
auto *Tuple = static_cast<const TupleTypeMetadata *>(type);
186186

187187
if (i < 0 || (size_t)i > Tuple->NumElements)
188188
swift::crash("Swift mirror subscript bounds check failure");
@@ -214,8 +214,8 @@ AnyReturn subscript(intptr_t i, const char **outName,
214214

215215
// Get the nth element.
216216
auto &elt = Tuple->getElement(i);
217-
auto bytes = reinterpret_cast<const char*>(value);
218-
auto eltData = reinterpret_cast<const OpaqueValue *>(bytes + elt.Offset);
217+
auto *bytes = reinterpret_cast<const char *>(value);
218+
auto *eltData = reinterpret_cast<const OpaqueValue *>(bytes + elt.Offset);
219219

220220
Any result;
221221

@@ -230,19 +230,19 @@ AnyReturn subscript(intptr_t i, const char **outName,
230230

231231

232232
// Implementation for structs.
233-
struct StructImpl: ReflectionMirrorImpl {
233+
struct StructImpl : ReflectionMirrorImpl {
234234
char displayStyle() {
235235
return 's';
236236
}
237237

238238
intptr_t count() {
239-
auto Struct = static_cast<const StructMetadata *>(type);
239+
auto *Struct = static_cast<const StructMetadata *>(type);
240240
return Struct->Description->Struct.NumFields;
241241
}
242242

243243
AnyReturn subscript(intptr_t i, const char **outName,
244244
void (**outFreeFunc)(const char *)) {
245-
auto Struct = static_cast<const StructMetadata *>(type);
245+
auto *Struct = static_cast<const StructMetadata *>(type);
246246

247247
if (i < 0 || (size_t)i > Struct->Description->Struct.NumFields)
248248
swift::crash("Swift mirror subscript bounds check failure");
@@ -251,8 +251,8 @@ AnyReturn subscript(intptr_t i, const char **outName,
251251
auto fieldType = Struct->getFieldTypes()[i];
252252
auto fieldOffset = Struct->getFieldOffsets()[i];
253253

254-
auto bytes = reinterpret_cast<char*>(value);
255-
auto fieldData = reinterpret_cast<OpaqueValue *>(bytes + fieldOffset);
254+
auto *bytes = reinterpret_cast<char*>(value);
255+
auto *fieldData = reinterpret_cast<OpaqueValue *>(bytes + fieldOffset);
256256

257257
*outName = getFieldName(Struct->Description->Struct.FieldNames, i);
258258
*outFreeFunc = nullptr;
@@ -273,9 +273,9 @@ AnyReturn subscript(intptr_t i, const char **outName,
273273

274274

275275
// Implementation for enums.
276-
struct EnumImpl: ReflectionMirrorImpl {
276+
struct EnumImpl : ReflectionMirrorImpl {
277277
bool isReflectable() {
278-
const auto Enum = static_cast<const EnumMetadata *>(type);
278+
const auto *Enum = static_cast<const EnumMetadata *>(type);
279279
const auto &Description = Enum->Description->Enum;
280280

281281
// No metadata for C and @objc enums yet
@@ -286,7 +286,7 @@ bool isReflectable() {
286286
}
287287

288288
void getInfo(unsigned *tagPtr, const Metadata **payloadTypePtr, bool *indirectPtr) {
289-
const auto Enum = static_cast<const EnumMetadata *>(type);
289+
const auto *Enum = static_cast<const EnumMetadata *>(type);
290290
const auto &Description = Enum->Description->Enum;
291291

292292
unsigned payloadCases = Description.getNumPayloadCases();
@@ -330,7 +330,7 @@ intptr_t count() {
330330

331331
AnyReturn subscript(intptr_t i, const char **outName,
332332
void (**outFreeFunc)(const char *)) {
333-
const auto Enum = static_cast<const EnumMetadata *>(type);
333+
const auto *Enum = static_cast<const EnumMetadata *>(type);
334334
const auto &Description = Enum->Description->Enum;
335335

336336
unsigned tag;
@@ -375,7 +375,7 @@ AnyReturn subscript(intptr_t i, const char **outName,
375375
return nullptr;
376376
}
377377

378-
const auto Enum = static_cast<const EnumMetadata *>(type);
378+
const auto *Enum = static_cast<const EnumMetadata *>(type);
379379
const auto &Description = Enum->Description->Enum;
380380

381381
unsigned tag;
@@ -388,21 +388,21 @@ AnyReturn subscript(intptr_t i, const char **outName,
388388

389389

390390
// Implementation for classes.
391-
struct ClassImpl: ReflectionMirrorImpl {
391+
struct ClassImpl : ReflectionMirrorImpl {
392392
char displayStyle() {
393393
return 'c';
394394
}
395395

396396
intptr_t count() {
397-
auto Clas = static_cast<const ClassMetadata*>(type);
397+
auto *Clas = static_cast<const ClassMetadata*>(type);
398398
auto count = Clas->getDescription()->Class.NumFields;
399399

400400
return count;
401401
}
402402

403403
AnyReturn subscript(intptr_t i, const char **outName,
404404
void (**outFreeFunc)(const char *)) {
405-
auto Clas = static_cast<const ClassMetadata*>(type);
405+
auto *Clas = static_cast<const ClassMetadata*>(type);
406406

407407
if (i < 0 || (size_t)i > Clas->getDescription()->Class.NumFields)
408408
swift::crash("Swift mirror subscript bounds check failure");
@@ -428,8 +428,8 @@ AnyReturn subscript(intptr_t i, const char **outName,
428428
#endif
429429
}
430430

431-
auto bytes = *reinterpret_cast<char * const *>(value);
432-
auto fieldData = reinterpret_cast<OpaqueValue *>(bytes + fieldOffset);
431+
auto *bytes = *reinterpret_cast<char * const *>(value);
432+
auto *fieldData = reinterpret_cast<OpaqueValue *>(bytes + fieldOffset);
433433

434434
*outName = getFieldName(Clas->getDescription()->Class.FieldNames, i);
435435
*outFreeFunc = nullptr;
@@ -464,7 +464,7 @@ id quickLookObject() {
464464

465465
#if SWIFT_OBJC_INTEROP
466466
// Implementation for ObjC classes.
467-
struct ObjCClassImpl: ClassImpl {
467+
struct ObjCClassImpl : ClassImpl {
468468
intptr_t count() {
469469
// ObjC makes no guarantees about the state of ivars, so we can't safely
470470
// introspect them in the general case.
@@ -480,7 +480,7 @@ AnyReturn subscript(intptr_t i, const char **outName,
480480

481481

482482
// Implementation for metatypes.
483-
struct MetatypeImpl: ReflectionMirrorImpl {
483+
struct MetatypeImpl : ReflectionMirrorImpl {
484484
char displayStyle() {
485485
return '\0';
486486
}
@@ -497,7 +497,7 @@ AnyReturn subscript(intptr_t i, const char **outName,
497497

498498

499499
// Implementation for opaque types.
500-
struct OpaqueImpl: ReflectionMirrorImpl {
500+
struct OpaqueImpl : ReflectionMirrorImpl {
501501
char displayStyle() {
502502
return '\0';
503503
}
@@ -549,7 +549,7 @@ auto call(OpaqueValue *passedValue, const Metadata *T, const Metadata *passedTyp
549549
#if SWIFT_OBJC_INTEROP
550550
// If this is a pure ObjC class, reflect it using ObjC's runtime facilities.
551551
// ForeignClass (e.g. CF classes) manifests as a NULL class object.
552-
auto classObject = passedType->getClassObject();
552+
auto *classObject = passedType->getClassObject();
553553
if (classObject == nullptr || !classObject->isTypeMetadata()) {
554554
ObjCClassImpl impl;
555555
return call(&impl);
@@ -644,8 +644,9 @@ auto call(OpaqueValue *passedValue, const Metadata *T, const Metadata *passedTyp
644644
intptr_t swift_reflectionMirror_count(OpaqueValue *value,
645645
const Metadata *type,
646646
const Metadata *T) {
647-
auto c = call(value, T, type, [](ReflectionMirrorImpl *impl) { return impl->count(); });
648-
return c;
647+
return call(value, T, type, [](ReflectionMirrorImpl *impl) {
648+
return impl->count();
649+
});
649650
}
650651

651652
// We intentionally use a non-POD return type with this entry point to give

0 commit comments

Comments
 (0)