diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-06 00:28:32 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-06 00:28:32 +0000 |
commit | ec92531c292e9c6961dd3e545c9fb031135b19bc (patch) | |
tree | 2c344abf5dbc2547b3b0159880de0196461572e2 /clang/lib/AST/ASTContext.cpp | |
parent | d5200f1bc4cb41329fd05a09d552e63705b294fc (diff) | |
download | bcm5719-llvm-ec92531c292e9c6961dd3e545c9fb031135b19bc.tar.gz bcm5719-llvm-ec92531c292e9c6961dd3e545c9fb031135b19bc.zip |
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.
llvm-svn: 159790
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 66096f34e23..f65f9c0afc3 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/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) { |