@@ -25,8 +25,33 @@ using namespace swift;
25
25
static_assert (sizeof (SILLocation) <= 2 * sizeof(void *),
26
26
"SILLocation must stay small");
27
27
28
- SILLocation::FilenameAndLocation *SILLocation::FilenameAndLocation::
29
- alloc (unsigned line, unsigned column, StringRef filename, SILModule &module ) {
28
+ SILLocation::SILLocation (Stmt *S) : SILLocation(ASTNodeTy(S), RegularKind) {
29
+ if (S->isImplicit ())
30
+ kindAndFlags.fields .implicit = true ;
31
+ }
32
+
33
+ SILLocation::SILLocation (Expr *E) : SILLocation(ASTNodeTy(E), RegularKind) {
34
+ if (E->isImplicit ())
35
+ kindAndFlags.fields .implicit = true ;
36
+ }
37
+ SILLocation::SILLocation (Decl *D) : SILLocation(ASTNodeTy(D), RegularKind) {
38
+ if (D && D->isImplicit ())
39
+ kindAndFlags.fields .implicit = true ;
40
+ }
41
+
42
+ SILLocation::SILLocation (Pattern *P) : SILLocation(ASTNodeTy(P), RegularKind) {
43
+ if (P->isImplicit ())
44
+ kindAndFlags.fields .implicit = true ;
45
+ }
46
+
47
+ SILLocation::SILLocation (SourceLoc L, LocationKind K)
48
+ : storage(L), kindAndFlags(K, SourceLocKind) {
49
+ kindAndFlags.fields .implicit = true ;
50
+ }
51
+
52
+ SILLocation::FilenameAndLocation *
53
+ SILLocation::FilenameAndLocation::alloc (unsigned line, unsigned column,
54
+ StringRef filename, SILModule &module ) {
30
55
return new (module ) FilenameAndLocation (line, column, filename);
31
56
}
32
57
@@ -36,6 +61,28 @@ void SILLocation::FilenameAndLocation::print(raw_ostream &OS) const {
36
61
OS << filename << ' :' << line << ' :' << column;
37
62
}
38
63
64
+ void SILLocation::pointToEnd () {
65
+ switch (getStorageKind ()) {
66
+ case ASTNodeKind:
67
+ return storage.ASTNodeLoc .setInt (1 );
68
+ case ExtendedASTNodeKind:
69
+ return storage.extendedASTNodeLoc ->primary .setInt (1 );
70
+ default :
71
+ assert (false && " only AST nodes can be pointed to end" );
72
+ }
73
+ }
74
+
75
+ bool SILLocation::pointsToEnd () const {
76
+ switch (getStorageKind ()) {
77
+ case ASTNodeKind:
78
+ return storage.ASTNodeLoc .getInt ();
79
+ case ExtendedASTNodeKind:
80
+ return storage.extendedASTNodeLoc ->primary .getInt ();
81
+ default :
82
+ return false ;
83
+ }
84
+ }
85
+
39
86
SourceLoc SILLocation::getSourceLoc () const {
40
87
if (isSILFile ())
41
88
return storage.sourceLoc ;
@@ -49,25 +96,24 @@ SourceLoc SILLocation::getSourceLoc() const {
49
96
}
50
97
51
98
SourceLoc SILLocation::getSourceLoc (ASTNodeTy N) const {
52
- if (N.isNull ())
99
+ auto P = N.getPointer ();
100
+ if (P.isNull ())
53
101
return SourceLoc ();
54
102
55
- if (alwaysPointsToEnd () ||
56
- is<CleanupLocation>() ||
57
- is<ImplicitReturnLocation>())
103
+ if (pointsToEnd () || is<CleanupLocation>() || is<ImplicitReturnLocation>())
58
104
return getEndSourceLoc (N);
59
105
60
106
// Use the start location for the ReturnKind.
61
107
if (is<ReturnLocation>())
62
108
return getStartSourceLoc (N);
63
109
64
- if (auto *decl = N .dyn_cast <Decl*>())
110
+ if (auto *decl = P .dyn_cast <Decl*>())
65
111
return decl->getLoc ();
66
- if (auto *expr = N .dyn_cast <Expr*>())
112
+ if (auto *expr = P .dyn_cast <Expr*>())
67
113
return expr->getLoc ();
68
- if (auto *stmt = N .dyn_cast <Stmt*>())
114
+ if (auto *stmt = P .dyn_cast <Stmt*>())
69
115
return stmt->getStartLoc ();
70
- if (auto *patt = N .dyn_cast <Pattern*>())
116
+ if (auto *patt = P .dyn_cast <Pattern*>())
71
117
return patt->getStartLoc ();
72
118
llvm_unreachable (" impossible SILLocation" );
73
119
}
@@ -94,13 +140,14 @@ SourceLoc SILLocation::getStartSourceLoc() const {
94
140
}
95
141
96
142
SourceLoc SILLocation::getStartSourceLoc (ASTNodeTy N) {
97
- if (auto *decl = N.dyn_cast <Decl*>())
143
+ auto P = N.getPointer ();
144
+ if (auto *decl = P.dyn_cast <Decl*>())
98
145
return decl->getStartLoc ();
99
- if (auto *expr = N .dyn_cast <Expr*>())
146
+ if (auto *expr = P .dyn_cast <Expr*>())
100
147
return expr->getStartLoc ();
101
- if (auto *stmt = N .dyn_cast <Stmt*>())
148
+ if (auto *stmt = P .dyn_cast <Stmt*>())
102
149
return stmt->getStartLoc ();
103
- if (auto *patt = N .dyn_cast <Pattern*>())
150
+ if (auto *patt = P .dyn_cast <Pattern*>())
104
151
return patt->getStartLoc ();
105
152
llvm_unreachable (" impossible SILLocation" );
106
153
}
@@ -114,13 +161,14 @@ SourceLoc SILLocation::getEndSourceLoc() const {
114
161
}
115
162
116
163
SourceLoc SILLocation::getEndSourceLoc (ASTNodeTy N) {
117
- if (auto decl = N.dyn_cast <Decl*>())
164
+ auto P = N.getPointer ();
165
+ if (auto decl = P.dyn_cast <Decl*>())
118
166
return decl->getEndLoc ();
119
- if (auto expr = N .dyn_cast <Expr*>())
167
+ if (auto expr = P .dyn_cast <Expr*>())
120
168
return expr->getEndLoc ();
121
- if (auto stmt = N .dyn_cast <Stmt*>())
169
+ if (auto stmt = P .dyn_cast <Stmt*>())
122
170
return stmt->getEndLoc ();
123
- if (auto patt = N .dyn_cast <Pattern*>())
171
+ if (auto patt = P .dyn_cast <Pattern*>())
124
172
return patt->getEndLoc ();
125
173
llvm_unreachable (" impossible SILLocation" );
126
174
}
@@ -186,10 +234,11 @@ void SILLocation::dump() const {
186
234
printSourceLoc (getSourceLoc (), llvm::dbgs ());
187
235
}
188
236
189
- if (isAutoGenerated ()) llvm::dbgs () << " :auto" ;
190
- if (alwaysPointsToEnd ()) llvm::dbgs () << " :end" ;
191
- if (isInPrologue ()) llvm::dbgs () << " :prologue" ;
192
- if (isSILFile ()) llvm::dbgs () << " :sil" ;
237
+ if (isAutoGenerated ()) llvm::dbgs () << " :auto" ;
238
+ if (isImplicit ()) llvm::dbgs () << " :implicit" ;
239
+ if (pointsToEnd ()) llvm::dbgs () << " :end" ;
240
+ if (isInPrologue ()) llvm::dbgs () << " :prologue" ;
241
+ if (isSILFile ()) llvm::dbgs () << " :sil" ;
193
242
if (hasASTNodeForDebugging ()) {
194
243
llvm::dbgs () << " :debug[" ;
195
244
printSourceLoc (getSourceLocForDebugging (), llvm::dbgs ());
@@ -219,33 +268,35 @@ void SILLocation::print(raw_ostream &OS) const {
219
268
}
220
269
}
221
270
222
- RegularLocation::RegularLocation (Stmt *S, Pattern *P, SILModule &Module) :
223
- SILLocation(new (Module) ExtendedASTNodeLoc(S, P ), RegularKind) {}
271
+ RegularLocation::RegularLocation (Stmt *S, Pattern *P, SILModule &Module)
272
+ : SILLocation(new (Module) ExtendedASTNodeLoc({ S, 0 }, {P, 0 } ), RegularKind) {}
224
273
225
274
SILLocation::ExtendedASTNodeLoc *
226
275
RegularLocation::getDebugOnlyExtendedASTNodeLoc (SILLocation L,
227
276
SILModule &Module) {
277
+ ASTNodeTy Empty ({(Decl *)nullptr , 0 });
228
278
if (auto D = L.getAsASTNode <Decl>())
229
- return new (Module) ExtendedASTNodeLoc ((Decl *) nullptr , D );
279
+ return new (Module) ExtendedASTNodeLoc (Empty, {D, 0 } );
230
280
if (auto E = L.getAsASTNode <Expr>())
231
- return new (Module) ExtendedASTNodeLoc ((Decl *) nullptr , E );
281
+ return new (Module) ExtendedASTNodeLoc (Empty, {E, 0 } );
232
282
if (auto S = L.getAsASTNode <Stmt>())
233
- return new (Module) ExtendedASTNodeLoc ((Decl *) nullptr , S );
283
+ return new (Module) ExtendedASTNodeLoc (Empty, {S, 0 } );
234
284
auto P = L.getAsASTNode <Pattern>();
235
- return new (Module) ExtendedASTNodeLoc ((Decl *) nullptr , P );
285
+ return new (Module) ExtendedASTNodeLoc (Empty, {P, 0 } );
236
286
}
237
287
238
288
SILLocation::ExtendedASTNodeLoc *
239
289
RegularLocation::getDiagnosticOnlyExtendedASTNodeLoc (SILLocation L,
240
290
SILModule &Module) {
291
+ ASTNodeTy Empty ({(Decl *)nullptr , 0 });
241
292
if (auto D = L.getAsASTNode <Decl>())
242
- return new (Module) ExtendedASTNodeLoc (D, (Decl *) nullptr );
293
+ return new (Module) ExtendedASTNodeLoc ({ D, 0 }, Empty );
243
294
if (auto E = L.getAsASTNode <Expr>())
244
- return new (Module) ExtendedASTNodeLoc (E, (Decl *) nullptr );
295
+ return new (Module) ExtendedASTNodeLoc ({ E, 0 }, Empty );
245
296
if (auto S = L.getAsASTNode <Stmt>())
246
- return new (Module) ExtendedASTNodeLoc (S, (Decl *) nullptr );
297
+ return new (Module) ExtendedASTNodeLoc ({ S, 0 }, Empty );
247
298
auto P = L.getAsASTNode <Pattern>();
248
- return new (Module) ExtendedASTNodeLoc (P, (Decl *) nullptr );
299
+ return new (Module) ExtendedASTNodeLoc ({ P, 0 }, Empty );
249
300
}
250
301
251
302
RegularLocation::RegularLocation (SILLocation ForDebuggingOrDiagnosticsOnly,
0 commit comments