@@ -36,6 +36,28 @@ void SILLocation::FilenameAndLocation::print(raw_ostream &OS) const {
36
36
OS << filename << ' :' << line << ' :' << column;
37
37
}
38
38
39
+ void SILLocation::pointToEnd () {
40
+ switch (getStorageKind ()) {
41
+ case ASTNodeKind:
42
+ return storage.ASTNodeLoc .setInt (1 );
43
+ case ExtendedASTNodeKind:
44
+ return storage.extendedASTNodeLoc ->primary .setInt (1 );
45
+ default :
46
+ assert (false && " only AST nodes can be pointed to end" );
47
+ }
48
+ }
49
+
50
+ bool SILLocation::pointsToEnd () const {
51
+ switch (getStorageKind ()) {
52
+ case ASTNodeKind:
53
+ return storage.ASTNodeLoc .getInt ();
54
+ case ExtendedASTNodeKind:
55
+ return storage.extendedASTNodeLoc ->primary .getInt ();
56
+ default :
57
+ return false ;
58
+ }
59
+ }
60
+
39
61
SourceLoc SILLocation::getSourceLoc () const {
40
62
if (isSILFile ())
41
63
return storage.sourceLoc ;
@@ -49,25 +71,24 @@ SourceLoc SILLocation::getSourceLoc() const {
49
71
}
50
72
51
73
SourceLoc SILLocation::getSourceLoc (ASTNodeTy N) const {
52
- if (N.isNull ())
74
+ auto P = N.getPointer ();
75
+ if (P.isNull ())
53
76
return SourceLoc ();
54
77
55
- if (alwaysPointsToEnd () ||
56
- is<CleanupLocation>() ||
57
- is<ImplicitReturnLocation>())
78
+ if (pointsToEnd () || is<CleanupLocation>() || is<ImplicitReturnLocation>())
58
79
return getEndSourceLoc (N);
59
80
60
81
// Use the start location for the ReturnKind.
61
82
if (is<ReturnLocation>())
62
83
return getStartSourceLoc (N);
63
84
64
- if (auto *decl = N .dyn_cast <Decl*>())
85
+ if (auto *decl = P .dyn_cast <Decl*>())
65
86
return decl->getLoc ();
66
- if (auto *expr = N .dyn_cast <Expr*>())
87
+ if (auto *expr = P .dyn_cast <Expr*>())
67
88
return expr->getLoc ();
68
- if (auto *stmt = N .dyn_cast <Stmt*>())
89
+ if (auto *stmt = P .dyn_cast <Stmt*>())
69
90
return stmt->getStartLoc ();
70
- if (auto *patt = N .dyn_cast <Pattern*>())
91
+ if (auto *patt = P .dyn_cast <Pattern*>())
71
92
return patt->getStartLoc ();
72
93
llvm_unreachable (" impossible SILLocation" );
73
94
}
@@ -94,13 +115,14 @@ SourceLoc SILLocation::getStartSourceLoc() const {
94
115
}
95
116
96
117
SourceLoc SILLocation::getStartSourceLoc (ASTNodeTy N) {
97
- if (auto *decl = N.dyn_cast <Decl*>())
118
+ auto P = N.getPointer ();
119
+ if (auto *decl = P.dyn_cast <Decl*>())
98
120
return decl->getStartLoc ();
99
- if (auto *expr = N .dyn_cast <Expr*>())
121
+ if (auto *expr = P .dyn_cast <Expr*>())
100
122
return expr->getStartLoc ();
101
- if (auto *stmt = N .dyn_cast <Stmt*>())
123
+ if (auto *stmt = P .dyn_cast <Stmt*>())
102
124
return stmt->getStartLoc ();
103
- if (auto *patt = N .dyn_cast <Pattern*>())
125
+ if (auto *patt = P .dyn_cast <Pattern*>())
104
126
return patt->getStartLoc ();
105
127
llvm_unreachable (" impossible SILLocation" );
106
128
}
@@ -114,13 +136,14 @@ SourceLoc SILLocation::getEndSourceLoc() const {
114
136
}
115
137
116
138
SourceLoc SILLocation::getEndSourceLoc (ASTNodeTy N) {
117
- if (auto decl = N.dyn_cast <Decl*>())
139
+ auto P = N.getPointer ();
140
+ if (auto decl = P.dyn_cast <Decl*>())
118
141
return decl->getEndLoc ();
119
- if (auto expr = N .dyn_cast <Expr*>())
142
+ if (auto expr = P .dyn_cast <Expr*>())
120
143
return expr->getEndLoc ();
121
- if (auto stmt = N .dyn_cast <Stmt*>())
144
+ if (auto stmt = P .dyn_cast <Stmt*>())
122
145
return stmt->getEndLoc ();
123
- if (auto patt = N .dyn_cast <Pattern*>())
146
+ if (auto patt = P .dyn_cast <Pattern*>())
124
147
return patt->getEndLoc ();
125
148
llvm_unreachable (" impossible SILLocation" );
126
149
}
@@ -186,10 +209,10 @@ void SILLocation::dump() const {
186
209
printSourceLoc (getSourceLoc (), llvm::dbgs ());
187
210
}
188
211
189
- if (isAutoGenerated ()) llvm::dbgs () << " :auto" ;
190
- if (alwaysPointsToEnd ()) llvm::dbgs () << " :end" ;
191
- if (isInPrologue ()) llvm::dbgs () << " :prologue" ;
192
- if (isSILFile ()) llvm::dbgs () << " :sil" ;
212
+ if (isAutoGenerated ()) llvm::dbgs () << " :auto" ;
213
+ if (pointsToEnd ()) llvm::dbgs () << " :end" ;
214
+ if (isInPrologue ()) llvm::dbgs () << " :prologue" ;
215
+ if (isSILFile ()) llvm::dbgs () << " :sil" ;
193
216
if (hasASTNodeForDebugging ()) {
194
217
llvm::dbgs () << " :debug[" ;
195
218
printSourceLoc (getSourceLocForDebugging (), llvm::dbgs ());
@@ -219,33 +242,35 @@ void SILLocation::print(raw_ostream &OS) const {
219
242
}
220
243
}
221
244
222
- RegularLocation::RegularLocation (Stmt *S, Pattern *P, SILModule &Module) :
223
- SILLocation(new (Module) ExtendedASTNodeLoc(S, P ), RegularKind) {}
245
+ RegularLocation::RegularLocation (Stmt *S, Pattern *P, SILModule &Module)
246
+ : SILLocation(new (Module) ExtendedASTNodeLoc({ S, 0 }, {P, 0 } ), RegularKind) {}
224
247
225
248
SILLocation::ExtendedASTNodeLoc *
226
249
RegularLocation::getDebugOnlyExtendedASTNodeLoc (SILLocation L,
227
250
SILModule &Module) {
251
+ ASTNodeTy Empty ({(Decl *)nullptr , 0 });
228
252
if (auto D = L.getAsASTNode <Decl>())
229
- return new (Module) ExtendedASTNodeLoc ((Decl *) nullptr , D );
253
+ return new (Module) ExtendedASTNodeLoc (Empty, {D, 0 } );
230
254
if (auto E = L.getAsASTNode <Expr>())
231
- return new (Module) ExtendedASTNodeLoc ((Decl *) nullptr , E );
255
+ return new (Module) ExtendedASTNodeLoc (Empty, {E, 0 } );
232
256
if (auto S = L.getAsASTNode <Stmt>())
233
- return new (Module) ExtendedASTNodeLoc ((Decl *) nullptr , S );
257
+ return new (Module) ExtendedASTNodeLoc (Empty, {S, 0 } );
234
258
auto P = L.getAsASTNode <Pattern>();
235
- return new (Module) ExtendedASTNodeLoc ((Decl *) nullptr , P );
259
+ return new (Module) ExtendedASTNodeLoc (Empty, {P, 0 } );
236
260
}
237
261
238
262
SILLocation::ExtendedASTNodeLoc *
239
263
RegularLocation::getDiagnosticOnlyExtendedASTNodeLoc (SILLocation L,
240
264
SILModule &Module) {
265
+ ASTNodeTy Empty ({(Decl *)nullptr , 0 });
241
266
if (auto D = L.getAsASTNode <Decl>())
242
- return new (Module) ExtendedASTNodeLoc (D, (Decl *) nullptr );
267
+ return new (Module) ExtendedASTNodeLoc ({ D, 0 }, Empty );
243
268
if (auto E = L.getAsASTNode <Expr>())
244
- return new (Module) ExtendedASTNodeLoc (E, (Decl *) nullptr );
269
+ return new (Module) ExtendedASTNodeLoc ({ E, 0 }, Empty );
245
270
if (auto S = L.getAsASTNode <Stmt>())
246
- return new (Module) ExtendedASTNodeLoc (S, (Decl *) nullptr );
271
+ return new (Module) ExtendedASTNodeLoc ({ S, 0 }, Empty );
247
272
auto P = L.getAsASTNode <Pattern>();
248
- return new (Module) ExtendedASTNodeLoc (P, (Decl *) nullptr );
273
+ return new (Module) ExtendedASTNodeLoc ({ P, 0 }, Empty );
249
274
}
250
275
251
276
RegularLocation::RegularLocation (SILLocation ForDebuggingOrDiagnosticsOnly,
0 commit comments