Skip to content

DocComment API: ensure LineList does not outlive MarkupContext it depends on. #8102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/IDE/CommentConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,10 @@ static void replaceObjcDeclarationsWithSwiftOnes(const Decl *D,
OS << Doc;
}

static LineList getLineListFromComment(const StringRef Text) {
static LineList getLineListFromComment(SourceManager &SourceMgr,
swift::markup::MarkupContext &MC,
const StringRef Text) {
LangOptions LangOpts;
SourceManager SourceMgr;
auto Tokens = swift::tokenize(LangOpts, SourceMgr,
SourceMgr.addMemBufferCopy(Text));
std::vector<SingleRawComment> Comments;
Expand All @@ -413,12 +414,13 @@ static LineList getLineListFromComment(const StringRef Text) {
return {};

RawComment Comment(Comments);
swift::markup::MarkupContext MC;
return MC.getLineList(Comment);
}

std::string ide::extractPlainTextFromComment(const StringRef Text) {
return getLineListFromComment(Text).str();
SourceManager SourceMgr;
swift::markup::MarkupContext MC;
return getLineListFromComment(SourceMgr, MC, Text).str();
}

bool ide::getDocumentationCommentAsXML(const Decl *D, raw_ostream &OS) {
Expand Down Expand Up @@ -467,8 +469,9 @@ bool ide::convertMarkupToXML(StringRef Text, raw_ostream &OS) {
llvm::raw_string_ostream OS(Comment);
OS << "/**\n" << Text << "\n" << "*/";
}
LineList LL = getLineListFromComment(Comment);
SourceManager SourceMgr;
MarkupContext MC;
LineList LL = getLineListFromComment(SourceMgr, MC, Comment);
if (auto *Doc = swift::markup::parseDocument(MC, LL)) {
CommentToXMLConverter Converter(OS);
Converter.visitCommentParts(extractCommentParts(MC, Doc));
Expand Down