aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-07-06 00:28:32 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-07-06 00:28:32 +0000
commit8d3ba23f2d9e6c87794d059412a0808c9cbacb25 (patch)
treec72c618faeffa1c098c4df33857bd12a72c62fb1 /lib/AST/ASTContext.cpp
parent1838703fea568b394407b83d1055b4c7f52fb105 (diff)
Implement AST classes for comments, a real parser for Doxygen comments and a
very simple semantic analysis that just builds the AST; minor changes for lexer to pick up source locations I didn't think about before. Comments AST is modelled along the ideas of HTML AST: block and inline content. * Block content is a paragraph or a command that has a paragraph as an argument or verbatim command. * Inline content is placed within some block. Inline content includes plain text, inline commands and HTML as tag soup. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159790 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r--lib/AST/ASTContext.cpp40
1 files changed, 36 insertions, 4 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 66096f34e2..f65f9c0afc 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -13,6 +13,9 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/CharUnits.h"
+#include "clang/AST/CommentLexer.h"
+#include "clang/AST/CommentSema.h"
+#include "clang/AST/CommentParser.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
@@ -149,18 +152,47 @@ const RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const {
const RawComment *ASTContext::getRawCommentForDecl(const Decl *D) const {
// Check whether we have cached a comment string for this declaration
// already.
- llvm::DenseMap<const Decl *, const RawComment *>::iterator Pos
+ llvm::DenseMap<const Decl *, RawAndParsedComment>::iterator Pos
= DeclComments.find(D);
- if (Pos != DeclComments.end())
- return Pos->second;
+ if (Pos != DeclComments.end()) {
+ RawAndParsedComment C = Pos->second;
+ return C.first;
+ }
const RawComment *RC = getRawCommentForDeclNoCache(D);
// If we found a comment, it should be a documentation comment.
assert(!RC || RC->isDocumentation());
- DeclComments[D] = RC;
+ DeclComments[D] = RawAndParsedComment(RC, NULL);
return RC;
}
+comments::FullComment *ASTContext::getCommentForDecl(const Decl *D) const {
+ llvm::DenseMap<const Decl *, RawAndParsedComment>::iterator Pos
+ = DeclComments.find(D);
+ const RawComment *RC;
+ if (Pos != DeclComments.end()) {
+ RawAndParsedComment C = Pos->second;
+ if (comments::FullComment *FC = C.second)
+ return FC;
+ RC = C.first;
+ } else
+ RC = getRawCommentForDecl(D);
+
+ if (!RC)
+ return NULL;
+
+ const StringRef RawText = RC->getRawText(SourceMgr);
+ comments::Lexer L(RC->getSourceRange().getBegin(), comments::CommentOptions(),
+ RawText.begin(), RawText.end());
+
+ comments::Sema S(this->BumpAlloc);
+ comments::Parser P(L, S, this->BumpAlloc);
+
+ comments::FullComment *FC = P.parseFullComment();
+ DeclComments[D].second = FC;
+ return FC;
+}
+
void
ASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &ID,
TemplateTemplateParmDecl *Parm) {