Skip to content

Commit a215d72

Browse files
committed
[NFC] AST: Add StorageImpl.cpp.
And move a couple of StorageImplInfo member functions into it. In preparation for making them use an ASTContext, to avoid importing that header into StorageImpl.h, a lightweight header.
1 parent 6bc2013 commit a215d72

File tree

3 files changed

+48
-16
lines changed

3 files changed

+48
-16
lines changed

include/swift/AST/StorageImpl.h

+10-16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#define SWIFT_STORAGEIMPL_H
2020

2121
#include "swift/Basic/Range.h"
22+
#include "llvm/ADT/StringRef.h"
23+
24+
namespace llvm {
25+
class StringRef;
26+
class raw_ostream;
27+
} // namespace llvm
2228

2329
namespace swift {
2430

@@ -108,7 +114,7 @@ static inline IntRange<AccessorKind> allAccessorKinds() {
108114
}
109115

110116
/// \returns a user-readable string name for the accessor kind
111-
static inline StringRef accessorKindName(AccessorKind ak) {
117+
static inline llvm::StringRef accessorKindName(AccessorKind ak) {
112118
switch(ak) {
113119

114120
#define ACCESSOR(ID) ID
@@ -400,10 +406,7 @@ class StorageImplInfo {
400406
}
401407

402408
/// Describe the implementation of a mutable property implemented opaquely.
403-
static StorageImplInfo getMutableOpaque(OpaqueReadOwnership ownership) {
404-
return { getOpaqueReadImpl(ownership), WriteImplKind::Set,
405-
ReadWriteImplKind::Modify };
406-
}
409+
static StorageImplInfo getMutableOpaque(OpaqueReadOwnership ownership);
407410

408411
static StorageImplInfo getComputed(StorageIsMutable_t isMutable) {
409412
return (isMutable ? getMutableComputed()
@@ -451,19 +454,10 @@ class StorageImplInfo {
451454
}
452455

453456
private:
454-
static ReadImplKind getOpaqueReadImpl(OpaqueReadOwnership ownership) {
455-
switch (ownership) {
456-
case OpaqueReadOwnership::Owned:
457-
return ReadImplKind::Get;
458-
case OpaqueReadOwnership::OwnedOrBorrowed:
459-
case OpaqueReadOwnership::Borrowed:
460-
return ReadImplKind::Read;
461-
}
462-
llvm_unreachable("bad read-ownership kind");
463-
}
457+
static ReadImplKind getOpaqueReadImpl(OpaqueReadOwnership ownership);
464458
};
465459

466-
StringRef getAccessorLabel(AccessorKind kind);
460+
llvm::StringRef getAccessorLabel(AccessorKind kind);
467461
void simple_display(llvm::raw_ostream &out, AccessorKind kind);
468462

469463
} // end namespace swift

lib/AST/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ add_swift_host_library(swiftAST STATIC
117117
SearchPathOptions.cpp
118118
SILLayout.cpp
119119
Stmt.cpp
120+
StorageImpl.cpp
120121
SubstitutionMap.cpp
121122
SwiftNameTranslation.cpp
122123
Type.cpp

lib/AST/StorageImpl.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- StorageImpl.cpp - Storage declaration access impl ------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines types for describing the implementation of an
14+
// AbstractStorageDecl.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#include "swift/AST/StorageImpl.h"
19+
20+
using namespace swift;
21+
22+
StorageImplInfo
23+
StorageImplInfo::getMutableOpaque(OpaqueReadOwnership ownership) {
24+
return {getOpaqueReadImpl(ownership), WriteImplKind::Set,
25+
ReadWriteImplKind::Modify};
26+
}
27+
28+
ReadImplKind StorageImplInfo::getOpaqueReadImpl(OpaqueReadOwnership ownership) {
29+
switch (ownership) {
30+
case OpaqueReadOwnership::Owned:
31+
return ReadImplKind::Get;
32+
case OpaqueReadOwnership::OwnedOrBorrowed:
33+
case OpaqueReadOwnership::Borrowed:
34+
return ReadImplKind::Read;
35+
}
36+
llvm_unreachable("bad read-ownership kind");
37+
}

0 commit comments

Comments
 (0)