Skip to content

Commit fec6538

Browse files
committed
---
yaml --- r: 348974 b: refs/heads/master c: 483bd5d h: refs/heads/master
1 parent 89e51af commit fec6538

File tree

4 files changed

+39
-33
lines changed

4 files changed

+39
-33
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a877fe6ee36b8475ebad8c488403bf05e62ae38c
2+
refs/heads/master: 483bd5dbc364cbe7cdfd6e3b1d92f1b3cd774be3
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/SourceFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ class SourceFile final : public FileUnit {
276276

277277
Identifier getDiscriminatorForPrivateValue(const ValueDecl *D) const override;
278278
Identifier getPrivateDiscriminator() const { return PrivateDiscriminator; }
279+
Optional<BasicDeclLocs> getBasicLocsForDecl(const Decl *D) const override;
279280

280281
virtual bool walk(ASTWalker &walker) override;
281282

trunk/lib/AST/Module.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,32 @@ TypeDecl *SourceFile::lookupLocalType(llvm::StringRef mangledName) const {
686686
return nullptr;
687687
}
688688

689+
Optional<BasicDeclLocs>
690+
SourceFile::getBasicLocsForDecl(const Decl *D) const {
691+
auto *FileCtx = D->getDeclContext()->getModuleScopeContext();
692+
assert(FileCtx == this && "D doesn't belong to this source file");
693+
if (FileCtx != this) {
694+
// D doesn't belong to this file. This shouldn't happen in practice.
695+
return None;
696+
}
697+
if (D->getLoc().isInvalid())
698+
return None;
699+
SourceManager &SM = getASTContext().SourceMgr;
700+
BasicDeclLocs Result;
701+
Result.SourceFilePath = SM.getDisplayNameForLoc(D->getLoc());
702+
auto setLineColumn = [&SM](LineColumn &Home, SourceLoc Loc) {
703+
if (Loc.isValid()) {
704+
std::tie(Home.Line, Home.Column) = SM.getLineAndColumn(Loc);
705+
}
706+
};
707+
#define SET(X) setLineColumn(Result.X, D->get##X());
708+
SET(Loc)
709+
SET(StartLoc)
710+
SET(EndLoc)
711+
#undef SET
712+
return Result;
713+
}
714+
689715
void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results) const {
690716
// FIXME: Should this do extra access control filtering?
691717
FORWARD(getDisplayDecls, (Results));

trunk/lib/Serialization/SerializeDoc.cpp

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -651,44 +651,23 @@ writer.write<uint32_t>(data.X.Column);
651651
return Result;
652652
}
653653

654-
Optional<DeclLocationsTableData> getLocDataFromSource(Decl *D, SourceFile *SF) {
655-
if (SF->getFilename().empty())
656-
return None;
657-
if (!SF->getBufferID().hasValue())
658-
return None;
659-
auto &SM = D->getASTContext().SourceMgr;
660-
DeclLocationsTableData Result;
661-
// Use getDisplayNameForLoc could give use file name specified by #sourceLocation
662-
SmallString<128> SourceFilePath = SM.getDisplayNameForLoc(D->getLoc());
663-
llvm::sys::fs::make_absolute(SourceFilePath);
664-
Result.SourceFileOffset = FWriter.getTextOffset(SourceFilePath);
665-
Result.Loc = getLineColumn(SM, D->getLoc());
666-
Result.StartLoc = getLineColumn(SM, D->getStartLoc());
667-
Result.EndLoc = getLineColumn(SM, D->getEndLoc());
668-
return Result;
669-
}
670-
671654
Optional<DeclLocationsTableData> getLocData(Decl *D) {
672655
auto *File = D->getDeclContext()->getModuleScopeContext();
673-
if (auto *SF = dyn_cast<SourceFile>(File)) {
674-
// Get location from source when we have access to the source.
675-
return getLocDataFromSource(D, SF);
676-
} else {
677-
// Merge modules.
678-
auto Locs = cast<FileUnit>(File)->getBasicLocsForDecl(D);
679-
if (!Locs.hasValue())
680-
return None;
681-
DeclLocationsTableData Result;
682-
Result.SourceFileOffset = FWriter.getTextOffset(Locs->SourceFilePath);
656+
auto Locs = cast<FileUnit>(File)->getBasicLocsForDecl(D);
657+
if (!Locs.hasValue())
658+
return None;
659+
DeclLocationsTableData Result;
660+
llvm::SmallString<128> AbsolutePath = Locs->SourceFilePath;
661+
llvm::sys::fs::make_absolute(AbsolutePath);
662+
Result.SourceFileOffset = FWriter.getTextOffset(AbsolutePath.str());
683663
#define COPY_LINE_COLUMN(X) \
684664
Result.X.Line = Locs->X.Line; \
685665
Result.X.Column = Locs->X.Column;
686-
COPY_LINE_COLUMN(Loc)
687-
COPY_LINE_COLUMN(StartLoc)
688-
COPY_LINE_COLUMN(EndLoc)
666+
COPY_LINE_COLUMN(Loc)
667+
COPY_LINE_COLUMN(StartLoc)
668+
COPY_LINE_COLUMN(EndLoc)
689669
#undef COPY_LINE_COLUMN
690-
return Result;
691-
}
670+
return Result;
692671
}
693672

694673
bool shouldSerializeSourceLoc(Decl *D) {

0 commit comments

Comments
 (0)