aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-07-06 18:19:34 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-07-06 18:19:34 +0000
commit811c820257746b1799b790b6adc7804f44154011 (patch)
treea96d9155255424ea05b15f5428216a507daa63bb /lib/AST/ASTContext.cpp
parent814e219fc6d5faeb48e4fd5375843346f2d4a7a7 (diff)
Don't store pointers into a std::vector (RawCommentList::Comments). Although
currently we take address of std::vector's contents only after we finished adding all comments (so no reallocation can happen), this will change in future. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159845 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r--lib/AST/ASTContext.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 99c5ff6d56..12f1d4de03 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -72,7 +72,7 @@ const RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const {
if (isa<ParmVarDecl>(D))
return NULL;
- ArrayRef<RawComment> RawComments = Comments.getComments();
+ ArrayRef<RawComment *> RawComments = Comments.getComments();
// If there are no comments anywhere, we won't find anything.
if (RawComments.empty())
@@ -85,10 +85,11 @@ const RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const {
return NULL;
// Find the comment that occurs just after this declaration.
- ArrayRef<RawComment>::iterator Comment
+ RawComment CommentAtDeclLoc(SourceMgr, SourceRange(DeclLoc));
+ ArrayRef<RawComment *>::iterator Comment
= std::lower_bound(RawComments.begin(),
RawComments.end(),
- RawComment(SourceMgr, SourceRange(DeclLoc)),
+ &CommentAtDeclLoc,
BeforeThanCompare<RawComment>(SourceMgr));
// Decompose the location for the declaration and find the beginning of the
@@ -97,17 +98,17 @@ const RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const {
// First check whether we have a trailing comment.
if (Comment != RawComments.end() &&
- Comment->isDocumentation() && Comment->isTrailingComment() &&
+ (*Comment)->isDocumentation() && (*Comment)->isTrailingComment() &&
!isa<TagDecl>(D) && !isa<NamespaceDecl>(D)) {
std::pair<FileID, unsigned> CommentBeginDecomp
- = SourceMgr.getDecomposedLoc(Comment->getSourceRange().getBegin());
+ = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getBegin());
// Check that Doxygen trailing comment comes after the declaration, starts
// on the same line and in the same file as the declaration.
if (DeclLocDecomp.first == CommentBeginDecomp.first &&
SourceMgr.getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second)
== SourceMgr.getLineNumber(CommentBeginDecomp.first,
CommentBeginDecomp.second)) {
- return &*Comment;
+ return *Comment;
}
}
@@ -118,12 +119,12 @@ const RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const {
--Comment;
// Check that we actually have a non-member Doxygen comment.
- if (!Comment->isDocumentation() || Comment->isTrailingComment())
+ if (!(*Comment)->isDocumentation() || (*Comment)->isTrailingComment())
return NULL;
// Decompose the end of the comment.
std::pair<FileID, unsigned> CommentEndDecomp
- = SourceMgr.getDecomposedLoc(Comment->getSourceRange().getEnd());
+ = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getEnd());
// If the comment and the declaration aren't in the same file, then they
// aren't related.
@@ -146,7 +147,7 @@ const RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const {
if (Text.find_first_of(",;{}#") != StringRef::npos)
return NULL;
- return &*Comment;
+ return *Comment;
}
const RawComment *ASTContext::getRawCommentForDecl(const Decl *D) const {