@@ -8277,3 +8277,34 @@ bool importer::isCxxConstReferenceType(const clang::Type *type) {
8277
8277
auto pointeeType = getCxxReferencePointeeTypeOrNone (type);
8278
8278
return pointeeType && pointeeType->isConstQualified ();
8279
8279
}
8280
+
8281
+ AccessLevel importer::convertClangAccess (clang::AccessSpecifier access) {
8282
+ switch (access) {
8283
+ case clang::AS_public:
8284
+ // C++ 'public' is actually closer to Swift 'open' than Swift 'public',
8285
+ // since C++ 'public' does not prevent users from subclassing a type or
8286
+ // overriding a method. However, subclassing and overriding are currently
8287
+ // unsupported across the interop boundary, so we conservatively map C++
8288
+ // 'public' to Swift 'public' in case there are other C++ subtleties that
8289
+ // are being missed at this time (e.g., C++ 'final' vs Swift 'final').
8290
+ return AccessLevel::Public;
8291
+
8292
+ case clang::AS_protected:
8293
+ // Swift does not have a notion of protected fields, so map C++ 'protected'
8294
+ // to Swift 'private'.
8295
+ return AccessLevel::Private;
8296
+
8297
+ case clang::AS_private:
8298
+ // N.B. Swift 'private' is more restrictive than C++ 'private' because it
8299
+ // also cares about what source file the member is accessed.
8300
+ return AccessLevel::Private;
8301
+
8302
+ case clang::AS_none:
8303
+ // The fictional 'none' specifier is given to top-level C++ declarations,
8304
+ // for which C++ lacks the syntax to give an access specifier. (It may also
8305
+ // be used in other cases I'm not aware of.) Those declarations are globally
8306
+ // visible and thus correspond to Swift 'public' (with the same caveats
8307
+ // about Swift 'public' vs 'open'; see above).
8308
+ return AccessLevel::Public;
8309
+ }
8310
+ }
0 commit comments