@@ -56,10 +56,10 @@ namespace swift {
56
56
// / Swift name, this will be recorded as
57
57
class EffectiveClangContext {
58
58
public:
59
- enum Kind {
59
+ enum Kind : uint8_t {
60
60
DeclContext,
61
61
TypedefContext,
62
- UnresolvedContext,
62
+ UnresolvedContext, // must be last
63
63
};
64
64
65
65
private:
@@ -70,15 +70,19 @@ class EffectiveClangContext {
70
70
const char *Data;
71
71
} Unresolved;
72
72
};
73
- Kind TheKind;
74
- unsigned UnresolvedLength;
75
-
73
+
74
+ // / If KindOrBiasedLength < Kind::UnresolvedContext, this represents a Kind.
75
+ // / Otherwise it's (uintptr_t)Kind::UnresolvedContext plus the length of
76
+ // / Unresolved.Data.
77
+ uintptr_t KindOrBiasedLength;
78
+
76
79
public:
77
- EffectiveClangContext () : TheKind (DeclContext) {
80
+ EffectiveClangContext () : KindOrBiasedLength (DeclContext) {
78
81
DC = nullptr ;
79
82
}
80
83
81
- EffectiveClangContext (const clang::DeclContext *dc) : TheKind(DeclContext) {
84
+ EffectiveClangContext (const clang::DeclContext *dc)
85
+ : KindOrBiasedLength(DeclContext) {
82
86
assert (dc != nullptr && " use null constructor instead" );
83
87
if (auto tagDecl = dyn_cast<clang::TagDecl>(dc)) {
84
88
DC = tagDecl->getCanonicalDecl ();
@@ -99,14 +103,13 @@ class EffectiveClangContext {
99
103
}
100
104
101
105
EffectiveClangContext (const clang::TypedefNameDecl *typedefName)
102
- : TheKind(TypedefContext)
103
- {
106
+ : KindOrBiasedLength(TypedefContext) {
104
107
Typedef = typedefName->getCanonicalDecl ();
105
108
}
106
109
107
- EffectiveClangContext (StringRef unresolved) : TheKind(UnresolvedContext) {
110
+ EffectiveClangContext (StringRef unresolved)
111
+ : KindOrBiasedLength(UnresolvedContext + unresolved.size()) {
108
112
Unresolved.Data = unresolved.data ();
109
- UnresolvedLength = unresolved.size ();
110
113
}
111
114
112
115
// / Determine whether this effective Clang context was set.
@@ -115,7 +118,12 @@ class EffectiveClangContext {
115
118
}
116
119
117
120
// / Determine the kind of effective Clang context.
118
- Kind getKind () const { return TheKind; }
121
+ Kind getKind () const {
122
+ if (KindOrBiasedLength >= UnresolvedContext)
123
+ return UnresolvedContext;
124
+ return static_cast <Kind>(KindOrBiasedLength);
125
+
126
+ }
119
127
120
128
// / Retrieve the declaration context.
121
129
const clang::DeclContext *getAsDeclContext () const {
@@ -131,7 +139,7 @@ class EffectiveClangContext {
131
139
// / Retrieve the unresolved context name.
132
140
StringRef getUnresolvedName () const {
133
141
assert (getKind () == UnresolvedContext);
134
- return StringRef (Unresolved.Data , UnresolvedLength );
142
+ return StringRef (Unresolved.Data , KindOrBiasedLength - UnresolvedContext );
135
143
}
136
144
137
145
// / Compares two EffectiveClangContexts without resolving unresolved names.
@@ -149,13 +157,8 @@ class EffectiveClangContext {
149
157
}
150
158
};
151
159
152
- #if LLVM_PTR_SIZE == 4
153
- static_assert (sizeof (EffectiveClangContext) <= 4 * sizeof(void *),
154
- "should fit in four pointers");
155
- #else
156
160
static_assert (sizeof (EffectiveClangContext) <= 2 * sizeof (void *),
157
- "should fit in a couple pointers");
158
- #endif
161
+ " should be small" );
159
162
160
163
class SwiftLookupTableReader ;
161
164
class SwiftLookupTableWriter ;
0 commit comments