@@ -194,33 +194,21 @@ static const char *getFilenameFromDC(const DeclContext *DC) {
194
194
return nullptr ;
195
195
}
196
196
197
-
198
- Location getDeserializedLoc (Pattern*) { return {}; }
199
- Location getDeserializedLoc (Expr*) { return {}; }
200
- Location getDeserializedLoc (Stmt*) { return {}; }
201
- Location getDeserializedLoc (Decl* D) {
202
- Location L = {};
197
+ SILLocation::DebugLoc getDeserializedLoc (Pattern *) { return {}; }
198
+ SILLocation::DebugLoc getDeserializedLoc (Expr *) { return {}; }
199
+ SILLocation::DebugLoc getDeserializedLoc (Stmt *) { return {}; }
200
+ SILLocation::DebugLoc getDeserializedLoc (Decl *D) {
201
+ SILLocation::DebugLoc L;
203
202
const DeclContext *DC = D->getDeclContext ()->getModuleScopeContext ();
204
- if (const char *Filename = getFilenameFromDC (DC)) {
203
+ if (const char *Filename = getFilenameFromDC (DC))
205
204
L.Filename = Filename;
206
- L.Line = 0 ;
207
- }
208
- return L;
209
- }
210
-
211
- Location getLoc (SourceManager &SM, SourceLoc Loc) {
212
- Location L = {};
213
- if (Loc.isValid ()) {
214
- L.Filename = SM.getBufferIdentifierForLoc (Loc);
215
- std::tie (L.Line , L.Col ) = SM.getLineAndColumn (Loc);
216
- }
217
205
return L;
218
206
}
219
207
220
208
// / Use the SM to figure out the actual line/column of a SourceLoc.
221
209
template <typename WithLoc>
222
- Location getLoc (SourceManager &SM, WithLoc *S, bool End = false ) {
223
- Location L = {} ;
210
+ SILLocation::DebugLoc getDebugLoc (SourceManager &SM, WithLoc *S, bool End = false ) {
211
+ SILLocation::DebugLoc L ;
224
212
if (S == nullptr )
225
213
return L;
226
214
@@ -231,37 +219,38 @@ Location getLoc(SourceManager &SM, WithLoc *S, bool End = false) {
231
219
// the module.
232
220
return getDeserializedLoc (S);
233
221
234
- return getLoc (SM, Loc );
222
+ return SILLocation::decode (Loc, SM );
235
223
}
236
224
237
- // / \brief Return the start of the location's source range.
238
- static Location getStartLocation (SourceManager &SM ,
239
- Optional<SILLocation> OptLoc ) {
225
+ // / Return the start of the location's source range.
226
+ static SILLocation::DebugLoc getStartLocation (Optional<SILLocation> OptLoc ,
227
+ SourceManager &SM ) {
240
228
if (!OptLoc) return {};
241
- return getLoc (SM, OptLoc->getStartSourceLoc ());
229
+ return SILLocation::decode ( OptLoc->getStartSourceLoc (), SM );
242
230
}
243
231
244
- // / \brief Return the debug location from a SILLocation.
245
- static Location getDebugLocation (SourceManager &SM ,
246
- Optional<SILLocation> OptLoc ) {
232
+ // / Return the debug location from a SILLocation.
233
+ static SILLocation::DebugLoc getDebugLocation (Optional<SILLocation> OptLoc ,
234
+ SourceManager &SM ) {
247
235
if (!OptLoc || OptLoc->isInPrologue ())
248
236
return {};
249
- return getLoc (SM, OptLoc->getDebugSourceLoc () );
237
+ return OptLoc->decodeDebugLoc (SM );
250
238
}
251
239
252
240
253
- // / \brief Extract the start location from a SILLocation.
241
+ // / Extract the start location from a SILLocation.
254
242
// /
255
243
// / This returns a FullLocation, which contains the location that
256
244
// / should be used for the linetable and the "true" AST location (used
257
245
// / for, e.g., variable declarations).
258
- static FullLocation getLocation (SourceManager &SM,
259
- Optional<SILLocation> OptLoc) {
260
- if (!OptLoc) return {};
246
+ static FullLocation getFullLocation (Optional<SILLocation> OptLoc,
247
+ SourceManager &SM) {
248
+ if (!OptLoc)
249
+ return {};
261
250
262
251
SILLocation Loc = OptLoc.getValue ();
263
- return { getLoc (SM, Loc.getDebugSourceLoc () ),
264
- getLoc (SM, Loc.getSourceLoc ()) };
252
+ return { Loc.decodeDebugLoc (SM ),
253
+ SILLocation::decode ( Loc.getSourceLoc (), SM) };
265
254
}
266
255
267
256
// / Determine whether this debug scope belongs to an explicit closure.
@@ -295,7 +284,7 @@ llvm::MDNode *IRGenDebugInfo::createInlinedAt(const SILDebugScope *DS) {
295
284
// SIL scope to a location means skipping the inlined-at scope.
296
285
auto *Parent = CS->Parent .get <const SILDebugScope *>();
297
286
auto *ParentScope = getOrCreateScope (Parent);
298
- auto L = getLoc (SM, CS->Loc .getDebugSourceLoc () );
287
+ auto L = CS->Loc .decodeDebugLoc (SM );
299
288
InlinedAt = llvm::DebugLoc::get (L.Line , L.Col , ParentScope, InlinedAt);
300
289
}
301
290
}
@@ -337,7 +326,7 @@ void IRGenDebugInfo::setCurrentLoc(IRBuilder &Builder, const SILDebugScope *DS,
337
326
if (!Scope)
338
327
return ;
339
328
340
- Location L = getDebugLocation (SM, Loc );
329
+ auto L = getDebugLocation (Loc, SM );
341
330
auto *File = getOrCreateFile (L.Filename );
342
331
if (File->getFilename () != Scope->getFilename ()) {
343
332
// We changed files in the middle of a scope. This happens, for
@@ -425,7 +414,7 @@ llvm::DIScope *IRGenDebugInfo::getOrCreateScope(const SILDebugScope *DS) {
425
414
return Parent;
426
415
427
416
assert (DS->Parent && " lexical block must have a parent subprogram" );
428
- Location L = getStartLocation (SM, DS->Loc );
417
+ auto L = getStartLocation (DS->Loc , SM );
429
418
llvm::DIFile *File = getOrCreateFile (L.Filename );
430
419
auto *DScope = DBuilder.createLexicalBlock (Parent, File, L.Line , L.Col );
431
420
@@ -572,7 +561,7 @@ llvm::DIScope *IRGenDebugInfo::getOrCreateContext(DeclContext *DC) {
572
561
573
562
// Create a Forward-declared type.
574
563
auto *TyDecl = cast<NominalTypeDecl>(DC);
575
- auto Loc = getLoc (SM, TyDecl);
564
+ auto Loc = getDebugLoc (SM, TyDecl);
576
565
auto File = getOrCreateFile (Loc.Filename );
577
566
auto Line = Loc.Line ;
578
567
auto FwdDecl = DBuilder.createForwardDecl (
@@ -663,14 +652,14 @@ llvm::DISubprogram *IRGenDebugInfo::emitFunction(
663
652
Name = getName (DS->Loc );
664
653
}
665
654
666
- Location L = {} ;
655
+ SILLocation::DebugLoc L ;
667
656
unsigned ScopeLine = 0 ; // / The source line used for the function prologue.
668
657
// Bare functions and thunks should not have any line numbers. This
669
658
// is especially important for shared functions like reabstraction
670
- // thunk helpers, where getLocation () returns an arbitrary location
659
+ // thunk helpers, where getFullLocation () returns an arbitrary location
671
660
// of whichever use was emitted first.
672
661
if (DS && (!SILFn || (!SILFn->isBare () && !SILFn->isThunk ()))) {
673
- auto FL = getLocation (SM, DS->Loc );
662
+ auto FL = getFullLocation ( DS->Loc , SM );
674
663
L = FL.Loc ;
675
664
ScopeLine = FL.LocForLinetable .Line ;
676
665
}
@@ -770,7 +759,7 @@ void IRGenDebugInfo::emitImport(ImportDecl *D) {
770
759
return ;
771
760
}
772
761
auto DIMod = getOrCreateModule ({D->getModulePath (), M});
773
- Location L = getLoc (SM, D);
762
+ auto L = getDebugLoc (SM, D);
774
763
DBuilder.createImportedModule (getOrCreateFile (L.Filename ), DIMod, L.Line );
775
764
}
776
765
@@ -979,7 +968,7 @@ void IRGenDebugInfo::emitVariableDeclaration(
979
968
980
969
auto *Scope = dyn_cast<llvm::DILocalScope>(getOrCreateScope (DS));
981
970
assert (Scope && " variable has no local scope" );
982
- Location Loc = getLoc (SM, DbgTy.getDecl ());
971
+ auto Loc = getDebugLoc (SM, DbgTy.getDecl ());
983
972
984
973
// FIXME: this should be the scope of the type's declaration.
985
974
// If this is an argument, attach it to the current function scope.
@@ -1113,7 +1102,7 @@ void IRGenDebugInfo::emitGlobalVariableDeclaration(llvm::GlobalValue *Var,
1113
1102
// would confuse both the user and LLDB.
1114
1103
return ;
1115
1104
1116
- Location L = getStartLocation (SM, Loc );
1105
+ auto L = getStartLocation (Loc, SM );
1117
1106
auto File = getOrCreateFile (L.Filename );
1118
1107
1119
1108
// Emit it as global variable of the current module.
@@ -1455,7 +1444,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1455
1444
case TypeKind::Struct: {
1456
1445
auto *StructTy = BaseTy->castTo <StructType>();
1457
1446
auto *Decl = StructTy->getDecl ();
1458
- Location L = getLoc (SM, Decl);
1447
+ auto L = getDebugLoc (SM, Decl);
1459
1448
return createStructType (DbgTy, Decl, StructTy, Scope,
1460
1449
getOrCreateFile (L.Filename ), L.Line , SizeInBits,
1461
1450
AlignInBits, Flags,
@@ -1469,7 +1458,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1469
1458
// used to differentiate them from C++ and ObjC classes.
1470
1459
auto *ClassTy = BaseTy->castTo <ClassType>();
1471
1460
auto *Decl = ClassTy->getDecl ();
1472
- Location L = getLoc (SM, Decl);
1461
+ auto L = getDebugLoc (SM, Decl);
1473
1462
if (auto *ClangDecl = Decl->getClangDecl ()) {
1474
1463
auto ClangSrcLoc = ClangDecl->getLocStart ();
1475
1464
clang::SourceManager &ClangSM =
@@ -1506,7 +1495,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1506
1495
auto *ProtocolTy = BaseTy->castTo <ProtocolType>();
1507
1496
auto *Decl = ProtocolTy->getDecl ();
1508
1497
// FIXME: (LLVM branch) This should probably be a DW_TAG_interface_type.
1509
- Location L = getLoc (SM, Decl);
1498
+ auto L = getDebugLoc (SM, Decl);
1510
1499
auto File = getOrCreateFile (L.Filename );
1511
1500
return createPointerSizedStruct (Scope,
1512
1501
Decl ? Decl->getNameStr () : MangledName,
@@ -1515,7 +1504,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1515
1504
1516
1505
case TypeKind::ProtocolComposition: {
1517
1506
auto *Decl = DbgTy.getDecl ();
1518
- Location L = getLoc (SM, Decl);
1507
+ auto L = getDebugLoc (SM, Decl);
1519
1508
auto File = getOrCreateFile (L.Filename );
1520
1509
1521
1510
// FIXME: emit types
@@ -1528,7 +1517,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1528
1517
case TypeKind::UnboundGeneric: {
1529
1518
auto *UnboundTy = BaseTy->castTo <UnboundGenericType>();
1530
1519
auto *Decl = UnboundTy->getDecl ();
1531
- Location L = getLoc (SM, Decl);
1520
+ auto L = getDebugLoc (SM, Decl);
1532
1521
return createPointerSizedStruct (Scope,
1533
1522
Decl ? Decl->getNameStr () : MangledName,
1534
1523
File, L.Line , Flags, MangledName);
@@ -1537,7 +1526,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1537
1526
case TypeKind::BoundGenericStruct: {
1538
1527
auto *StructTy = BaseTy->castTo <BoundGenericStructType>();
1539
1528
auto *Decl = StructTy->getDecl ();
1540
- Location L = getLoc (SM, Decl);
1529
+ auto L = getDebugLoc (SM, Decl);
1541
1530
return createPointerSizedStruct (Scope,
1542
1531
Decl ? Decl->getNameStr () : MangledName,
1543
1532
File, L.Line , Flags, MangledName);
@@ -1546,7 +1535,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1546
1535
case TypeKind::BoundGenericClass: {
1547
1536
auto *ClassTy = BaseTy->castTo <BoundGenericClassType>();
1548
1537
auto *Decl = ClassTy->getDecl ();
1549
- Location L = getLoc (SM, Decl);
1538
+ auto L = getDebugLoc (SM, Decl);
1550
1539
// TODO: We may want to peek at Decl->isObjC() and set this
1551
1540
// attribute accordingly.
1552
1541
return createPointerSizedStruct (Scope,
@@ -1593,7 +1582,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1593
1582
1594
1583
case TypeKind::Archetype: {
1595
1584
auto *Archetype = BaseTy->castTo <ArchetypeType>();
1596
- Location L = getLoc (SM, Archetype->getAssocType ());
1585
+ auto L = getDebugLoc (SM, Archetype->getAssocType ());
1597
1586
auto Superclass = Archetype->getSuperclass ();
1598
1587
auto DerivedFrom = Superclass.isNull ()
1599
1588
? nullptr
@@ -1628,7 +1617,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1628
1617
case TypeKind::Metatype: {
1629
1618
// Metatypes are (mostly) singleton type descriptors, often without storage.
1630
1619
Flags |= llvm::DINode::FlagArtificial;
1631
- Location L = getLoc (SM, DbgTy.getDecl ());
1620
+ auto L = getDebugLoc (SM, DbgTy.getDecl ());
1632
1621
auto File = getOrCreateFile (L.Filename );
1633
1622
return DBuilder.createStructType (
1634
1623
Scope, MangledName, File, L.Line , SizeInBits, AlignInBits, Flags,
@@ -1680,15 +1669,15 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1680
1669
case TypeKind::Enum: {
1681
1670
auto *EnumTy = BaseTy->castTo <EnumType>();
1682
1671
auto *Decl = EnumTy->getDecl ();
1683
- Location L = getLoc (SM, Decl);
1672
+ auto L = getDebugLoc (SM, Decl);
1684
1673
return createEnumType (DbgTy, Decl, MangledName, Scope,
1685
1674
getOrCreateFile (L.Filename ), L.Line , Flags);
1686
1675
}
1687
1676
1688
1677
case TypeKind::BoundGenericEnum: {
1689
1678
auto *EnumTy = BaseTy->castTo <BoundGenericEnumType>();
1690
1679
auto *Decl = EnumTy->getDecl ();
1691
- Location L = getLoc (SM, Decl);
1680
+ auto L = getDebugLoc (SM, Decl);
1692
1681
return createEnumType (DbgTy, Decl, MangledName, Scope,
1693
1682
getOrCreateFile (L.Filename ), L.Line , Flags);
1694
1683
}
@@ -1711,7 +1700,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1711
1700
case TypeKind::WeakStorage: {
1712
1701
auto *ReferenceTy = cast<ReferenceStorageType>(BaseTy);
1713
1702
auto CanTy = ReferenceTy->getReferentType ();
1714
- Location L = getLoc (SM, DbgTy.getDecl ());
1703
+ auto L = getDebugLoc (SM, DbgTy.getDecl ());
1715
1704
auto File = getOrCreateFile (L.Filename );
1716
1705
return DBuilder.createTypedef (getOrCreateDesugaredType (CanTy, DbgTy),
1717
1706
MangledName, File, L.Line , File);
@@ -1723,7 +1712,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
1723
1712
1724
1713
auto *NameAliasTy = cast<NameAliasType>(BaseTy);
1725
1714
auto *Decl = NameAliasTy->getDecl ();
1726
- Location L = getLoc (SM, Decl);
1715
+ auto L = getDebugLoc (SM, Decl);
1727
1716
auto AliasedTy = Decl->getUnderlyingType ();
1728
1717
auto File = getOrCreateFile (L.Filename );
1729
1718
// For NameAlias types, the DeclContext for the aliasED type is
0 commit comments