clang 19.0.0git
Classes | Public Types | Public Member Functions | Friends | List of all members
clang::RawComment Class Reference

#include "clang/AST/RawCommentList.h"

Classes

struct  CommentLine
 

Public Types

enum  CommentKind {
  RCK_Invalid , RCK_OrdinaryBCPL , RCK_OrdinaryC , RCK_BCPLSlash ,
  RCK_BCPLExcl , RCK_JavaDoc , RCK_Qt , RCK_Merged
}
 

Public Member Functions

 RawComment ()
 
 RawComment (const SourceManager &SourceMgr, SourceRange SR, const CommentOptions &CommentOpts, bool Merged)
 
CommentKind getKind () const LLVM_READONLY
 
bool isInvalid () const LLVM_READONLY
 
bool isMerged () const LLVM_READONLY
 
bool isAttached () const LLVM_READONLY
 Is this comment attached to any declaration?
 
void setAttached ()
 
bool isTrailingComment () const LLVM_READONLY
 Returns true if it is a comment that should be put after a member:
 
bool isAlmostTrailingComment () const LLVM_READONLY
 Returns true if it is a probable typo:
 
bool isOrdinary () const LLVM_READONLY
 Returns true if this comment is not a documentation comment.
 
bool isDocumentation () const LLVM_READONLY
 Returns true if this comment any kind of a documentation comment.
 
StringRef getRawText (const SourceManager &SourceMgr) const
 Returns raw comment text with comment markers.
 
SourceRange getSourceRange () const LLVM_READONLY
 
SourceLocation getBeginLoc () const LLVM_READONLY
 
SourceLocation getEndLoc () const LLVM_READONLY
 
const char * getBriefText (const ASTContext &Context) const
 
bool hasUnsupportedSplice (const SourceManager &SourceMgr) const
 
std::string getFormattedText (const SourceManager &SourceMgr, DiagnosticsEngine &Diags) const
 Returns sanitized comment text, suitable for presentation in editor UIs.
 
std::vector< CommentLinegetFormattedLines (const SourceManager &SourceMgr, DiagnosticsEngine &Diags) const
 Returns sanitized comment text as separated lines with locations in source, suitable for further processing and rendering requiring source locations.
 
comments::FullCommentparse (const ASTContext &Context, const Preprocessor *PP, const Decl *D) const
 Parse the comment, assuming it is attached to decl D.
 

Friends

class ASTReader
 

Detailed Description

Definition at line 32 of file RawCommentList.h.

Member Enumeration Documentation

◆ CommentKind

Enumerator
RCK_Invalid 

Invalid comment.

RCK_OrdinaryBCPL 

Any normal BCPL comments.

RCK_OrdinaryC 

Any normal C comment.

RCK_BCPLSlash 
/// stuff
RCK_BCPLExcl 
//! stuff
RCK_JavaDoc 
/** stuff */
RCK_Qt 
/*! stuff */

, also used by HeaderDoc

RCK_Merged 

Two or more documentation comments merged together.

Definition at line 34 of file RawCommentList.h.

Constructor & Destructor Documentation

◆ RawComment() [1/2]

clang::RawComment::RawComment ( )
inline

Definition at line 45 of file RawCommentList.h.

◆ RawComment() [2/2]

RawComment::RawComment ( const SourceManager SourceMgr,
SourceRange  SR,
const CommentOptions CommentOpts,
bool  Merged 
)

Member Function Documentation

◆ getBeginLoc()

SourceLocation clang::RawComment::getBeginLoc ( ) const
inline

Definition at line 108 of file RawCommentList.h.

References clang::SourceRange::getBegin().

Referenced by clang::RawCommentList::addComment().

◆ getBriefText()

const char * clang::RawComment::getBriefText ( const ASTContext Context) const
inline

Definition at line 111 of file RawCommentList.h.

◆ getEndLoc()

SourceLocation clang::RawComment::getEndLoc ( ) const
inline

Definition at line 109 of file RawCommentList.h.

References clang::SourceRange::getEnd().

Referenced by clang::RawCommentList::addComment().

◆ getFormattedLines()

std::vector< RawComment::CommentLine > RawComment::getFormattedLines ( const SourceManager SourceMgr,
DiagnosticsEngine Diags 
) const

Returns sanitized comment text as separated lines with locations in source, suitable for further processing and rendering requiring source locations.

Definition at line 378 of file RawCommentList.cpp.

References Begin, clang::comments::tok::eof, clang::PresumedLoc::getLine(), clang::comments::Token::getLocation(), clang::SourceLocation::getLocWithOffset(), clang::SourceManager::getPresumedLoc(), getRawText(), getSourceRange(), clang::comments::Lexer::getSpelling(), clang::SourceManager::getSpellingColumnNumber(), clang::comments::Token::is(), clang::comments::Token::isNot(), clang::comments::Lexer::lex(), clang::Line, clang::comments::tok::newline, and clang::Result.

Referenced by getFormattedText(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::recordEnumConstants(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::recordObjCInstanceVariables(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::recordObjCMethods(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::recordObjCProperties(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitClassTemplatePartialSpecializationDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitClassTemplateSpecializationDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitConceptDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitCXXConstructorDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitCXXConversionDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitCXXDestructorDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitCXXMethodDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitCXXRecordDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitEnumDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitFieldDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitFunctionDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitFunctionTemplateDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitNamespaceDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitObjCCategoryDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitObjCInterfaceDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitObjCProtocolDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitRecordDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitTypedefNameDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitVarDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitVarTemplateDecl(), clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitVarTemplatePartialSpecializationDecl(), and clang::extractapi::impl::ExtractAPIVisitorBase< Derived >::VisitVarTemplateSpecializationDecl().

◆ getFormattedText()

std::string RawComment::getFormattedText ( const SourceManager SourceMgr,
DiagnosticsEngine Diags 
) const

Returns sanitized comment text, suitable for presentation in editor UIs.

E.g. will transform: // This is a long multiline comment. // Parts of it might be indented. /* The comments styles might be mixed. *‍/ into "This is a long multiline comment.\n" " Parts of it might be indented.\n" "The comments styles might be mixed." Also removes leading indentation and sanitizes some common cases: /* This is a first line.

  • This is a second line. It is indented.
  • This is a third line. ‍/ and / This is a first line. This is a second line. It is indented. This is a third line. *‍/ will both turn into: "This is a first line.\n" " This is a second line. It is indented.\n" "This is a third line."

Definition at line 360 of file RawCommentList.cpp.

References getFormattedLines(), getRawText(), clang::Line, and clang::Result.

◆ getKind()

CommentKind clang::RawComment::getKind ( ) const
inline

◆ getRawText()

StringRef clang::RawComment::getRawText ( const SourceManager SourceMgr) const
inline

Returns raw comment text with comment markers.

Definition at line 98 of file RawCommentList.h.

Referenced by getFormattedLines(), getFormattedText(), hasUnsupportedSplice(), parse(), and RawComment().

◆ getSourceRange()

SourceRange clang::RawComment::getSourceRange ( ) const
inline

Definition at line 107 of file RawCommentList.h.

Referenced by clang::ASTContext::addComment(), getFormattedLines(), and parse().

◆ hasUnsupportedSplice()

bool clang::RawComment::hasUnsupportedSplice ( const SourceManager SourceMgr) const
inline

Definition at line 118 of file RawCommentList.h.

References getRawText(), isInvalid(), and Text.

Referenced by clang::Sema::ActOnComment().

◆ isAlmostTrailingComment()

bool clang::RawComment::isAlmostTrailingComment ( ) const
inline

Returns true if it is a probable typo:

//< stuff
/*< stuff */

Definition at line 83 of file RawCommentList.h.

Referenced by clang::Sema::ActOnComment().

◆ isAttached()

bool clang::RawComment::isAttached ( ) const
inline

Is this comment attached to any declaration?

Definition at line 63 of file RawCommentList.h.

◆ isDocumentation()

bool clang::RawComment::isDocumentation ( ) const
inline

Returns true if this comment any kind of a documentation comment.

Definition at line 93 of file RawCommentList.h.

References isInvalid(), and isOrdinary().

Referenced by clang::ASTContext::cacheRawCommentForDecl(), and clang::ASTContext::getRawCommentForDeclNoCacheImpl().

◆ isInvalid()

bool clang::RawComment::isInvalid ( ) const
inline

◆ isMerged()

bool clang::RawComment::isMerged ( ) const
inline

Definition at line 58 of file RawCommentList.h.

References RCK_Merged.

◆ isOrdinary()

bool clang::RawComment::isOrdinary ( ) const
inline

Returns true if this comment is not a documentation comment.

Definition at line 88 of file RawCommentList.h.

References RCK_OrdinaryBCPL, and RCK_OrdinaryC.

Referenced by clang::RawCommentList::addComment(), and isDocumentation().

◆ isTrailingComment()

bool clang::RawComment::isTrailingComment ( ) const
inline

Returns true if it is a comment that should be put after a member:

///< stuff
//!< stuff
/**< stuff */
/*!< stuff */

Definition at line 76 of file RawCommentList.h.

Referenced by clang::RawCommentList::addComment(), and clang::ASTContext::getRawCommentForDeclNoCacheImpl().

◆ parse()

comments::FullComment * RawComment::parse ( const ASTContext Context,
const Preprocessor PP,
const Decl D 
) const

◆ setAttached()

void clang::RawComment::setAttached ( )
inline

Definition at line 67 of file RawCommentList.h.

Friends And Related Function Documentation

◆ ASTReader

friend class ASTReader
friend

Definition at line 207 of file RawCommentList.h.


The documentation for this class was generated from the following files: