clang
3.9.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
llvm.src
tools
clang
include
clang
AST
RawCommentList.h
Go to the documentation of this file.
1
//===--- RawCommentList.h - Classes for processing raw comments -*- C++ -*-===//
2
//
3
// The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLVM_CLANG_AST_RAWCOMMENTLIST_H
11
#define LLVM_CLANG_AST_RAWCOMMENTLIST_H
12
13
#include "
clang/Basic/CommentOptions.h
"
14
#include "
clang/Basic/SourceManager.h
"
15
#include "llvm/ADT/ArrayRef.h"
16
17
namespace
clang {
18
19
class
ASTContext
;
20
class
ASTReader;
21
class
Decl
;
22
class
Preprocessor;
23
24
namespace
comments {
25
class
FullComment;
26
}
// end namespace comments
27
28
class
RawComment
{
29
public
:
30
enum
CommentKind
{
31
RCK_Invalid
,
///< Invalid comment
32
RCK_OrdinaryBCPL
,
///< Any normal BCPL comments
33
RCK_OrdinaryC
,
///< Any normal C comment
34
RCK_BCPLSlash
,
///< \code /// stuff \endcode
35
RCK_BCPLExcl
,
///< \code //! stuff \endcode
36
RCK_JavaDoc
,
///< \code /** stuff */ \endcode
37
RCK_Qt
,
///< \code /*! stuff */ \endcode, also used by HeaderDoc
38
RCK_Merged
///< Two or more documentation comments merged together
39
};
40
41
RawComment
() :
Kind
(
RCK_Invalid
), IsAlmostTrailingComment(
false
) { }
42
43
RawComment
(
const
SourceManager
&SourceMgr,
SourceRange
SR,
44
bool
Merged,
bool
ParseAllComments);
45
46
CommentKind
getKind
() const LLVM_READONLY {
47
return
(
CommentKind
)
Kind
;
48
}
49
50
bool
isInvalid
() const LLVM_READONLY {
51
return
Kind
==
RCK_Invalid
;
52
}
53
54
bool
isMerged
() const LLVM_READONLY {
55
return
Kind
==
RCK_Merged
;
56
}
57
58
/// Is this comment attached to any declaration?
59
bool
isAttached
() const LLVM_READONLY {
60
return
IsAttached;
61
}
62
63
void
setAttached
() {
64
IsAttached =
true
;
65
}
66
67
/// Returns true if it is a comment that should be put after a member:
68
/// \code ///< stuff \endcode
69
/// \code //!< stuff \endcode
70
/// \code /**< stuff */ \endcode
71
/// \code /*!< stuff */ \endcode
72
bool
isTrailingComment
() const LLVM_READONLY {
73
assert(
isDocumentation
());
74
return
IsTrailingComment;
75
}
76
77
/// Returns true if it is a probable typo:
78
/// \code //< stuff \endcode
79
/// \code /*< stuff */ \endcode
80
bool
isAlmostTrailingComment
() const LLVM_READONLY {
81
return
IsAlmostTrailingComment;
82
}
83
84
/// Returns true if this comment is not a documentation comment.
85
bool
isOrdinary
() const LLVM_READONLY {
86
return
((
Kind
==
RCK_OrdinaryBCPL
) || (
Kind
==
RCK_OrdinaryC
)) &&
87
!ParseAllComments;
88
}
89
90
/// Returns true if this comment any kind of a documentation comment.
91
bool
isDocumentation
() const LLVM_READONLY {
92
return
!
isInvalid
() && !
isOrdinary
();
93
}
94
95
/// Returns whether we are parsing all comments.
96
bool
isParseAllComments
() const LLVM_READONLY {
97
return
ParseAllComments;
98
}
99
100
/// Returns raw comment text with comment markers.
101
StringRef
getRawText
(
const
SourceManager
&SourceMgr)
const
{
102
if
(RawTextValid)
103
return
RawText;
104
105
RawText = getRawTextSlow(SourceMgr);
106
RawTextValid =
true
;
107
return
RawText;
108
}
109
110
SourceRange
getSourceRange
() const LLVM_READONLY {
return
Range; }
111
SourceLocation
getLocStart
() const LLVM_READONLY {
return
Range.
getBegin
(); }
112
SourceLocation
getLocEnd
() const LLVM_READONLY {
return
Range.
getEnd
(); }
113
114
const
char
*
getBriefText
(
const
ASTContext
&
Context
)
const
{
115
if
(BriefTextValid)
116
return
BriefText;
117
118
return
extractBriefText(Context);
119
}
120
121
/// Parse the comment, assuming it is attached to decl \c D.
122
comments::FullComment
*
parse
(
const
ASTContext
&
Context
,
123
const
Preprocessor
*PP,
const
Decl
*D)
const
;
124
125
private
:
126
SourceRange
Range;
127
128
mutable
StringRef RawText;
129
mutable
const
char
*BriefText;
130
131
mutable
bool
RawTextValid : 1;
///< True if RawText is valid
132
mutable
bool
BriefTextValid : 1;
///< True if BriefText is valid
133
134
unsigned
Kind
: 3;
135
136
/// True if comment is attached to a declaration in ASTContext.
137
bool
IsAttached : 1;
138
139
bool
IsTrailingComment : 1;
140
bool
IsAlmostTrailingComment : 1;
141
142
/// When true, ordinary comments starting with "//" and "/*" will be
143
/// considered as documentation comments.
144
bool
ParseAllComments : 1;
145
146
/// \brief Constructor for AST deserialization.
147
RawComment
(
SourceRange
SR,
CommentKind
K,
bool
IsTrailingComment,
148
bool
IsAlmostTrailingComment,
149
bool
ParseAllComments) :
150
Range(SR), RawTextValid(
false
), BriefTextValid(
false
),
Kind
(K),
151
IsAttached(
false
), IsTrailingComment(IsTrailingComment),
152
IsAlmostTrailingComment(IsAlmostTrailingComment),
153
ParseAllComments(ParseAllComments)
154
{ }
155
156
StringRef getRawTextSlow(
const
SourceManager &SourceMgr)
const
;
157
158
const
char
*extractBriefText(
const
ASTContext
&
Context
)
const
;
159
160
friend
class
ASTReader
;
161
};
162
163
/// \brief Compare comments' source locations.
164
template
<>
165
class
BeforeThanCompare
<
RawComment
> {
166
const
SourceManager
&
SM
;
167
168
public
:
169
explicit
BeforeThanCompare
(
const
SourceManager
&
SM
) : SM(SM) { }
170
171
bool
operator()
(
const
RawComment
&LHS,
const
RawComment
&RHS) {
172
return
SM
.isBeforeInTranslationUnit(LHS.
getLocStart
(), RHS.
getLocStart
());
173
}
174
175
bool
operator()
(
const
RawComment
*LHS,
const
RawComment
*RHS) {
176
return
operator()(*LHS, *RHS);
177
}
178
};
179
180
/// \brief This class represents all comments included in the translation unit,
181
/// sorted in order of appearance in the translation unit.
182
class
RawCommentList
{
183
public
:
184
RawCommentList
(
SourceManager
&SourceMgr) : SourceMgr(SourceMgr) {}
185
186
void
addComment
(
const
RawComment
&RC, llvm::BumpPtrAllocator &
Allocator
);
187
188
ArrayRef<RawComment *>
getComments
()
const
{
189
return
Comments;
190
}
191
192
private
:
193
SourceManager
&SourceMgr;
194
std::vector<RawComment *> Comments;
195
196
void
addDeserializedComments(
ArrayRef<RawComment *>
DeserializedComments);
197
198
friend
class
ASTReader
;
199
};
200
201
}
// end namespace clang
202
203
#endif
clang::RawComment
Definition:
RawCommentList.h:28
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition:
SourceLocation.h:202
clang::BeforeThanCompare< RawComment >::operator()
bool operator()(const RawComment &LHS, const RawComment &RHS)
Definition:
RawCommentList.h:171
clang::RawComment::isInvalid
bool isInvalid() const LLVM_READONLY
Definition:
RawCommentList.h:50
clang::RawComment::getBriefText
const char * getBriefText(const ASTContext &Context) const
Definition:
RawCommentList.h:114
clang::RawComment::parse
comments::FullComment * parse(const ASTContext &Context, const Preprocessor *PP, const Decl *D) const
Parse the comment, assuming it is attached to decl D.
Definition:
RawCommentList.cpp:202
clang::RawCommentList::getComments
ArrayRef< RawComment * > getComments() const
Definition:
RawCommentList.h:188
clang::RawComment::getLocEnd
SourceLocation getLocEnd() const LLVM_READONLY
Definition:
RawCommentList.h:112
clang::RawCommentList::addComment
void addComment(const RawComment &RC, llvm::BumpPtrAllocator &Allocator)
Definition:
RawCommentList.cpp:272
SourceManager.h
Defines the SourceManager interface.
clang::RawComment::setAttached
void setAttached()
Definition:
RawCommentList.h:63
Decl
clang::RawComment::RCK_OrdinaryBCPL
Any normal BCPL comments.
Definition:
RawCommentList.h:32
clang::RawComment::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Definition:
RawCommentList.h:110
clang::RawComment::RCK_BCPLExcl
Definition:
RawCommentList.h:35
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition:
ASTContext.h:92
clang::RawCommentList
This class represents all comments included in the translation unit, sorted in order of appearance in...
Definition:
RawCommentList.h:182
clang::BeforeThanCompare< RawComment >::operator()
bool operator()(const RawComment *LHS, const RawComment *RHS)
Definition:
RawCommentList.h:175
clang::RawComment::getRawText
StringRef getRawText(const SourceManager &SourceMgr) const
Returns raw comment text with comment markers.
Definition:
RawCommentList.h:101
clang::RawComment::CommentKind
CommentKind
Definition:
RawCommentList.h:30
clang::BeforeThanCompare
Comparison function object.
Definition:
SourceManager.h:1688
llvm::ArrayRef
Definition:
LLVM.h:31
clang::RawCommentList::RawCommentList
RawCommentList(SourceManager &SourceMgr)
Definition:
RawCommentList.h:184
Context
ASTContext * Context
Definition:
ASTMatchFinder.cpp:709
clang::RawComment::isAttached
bool isAttached() const LLVM_READONLY
Is this comment attached to any declaration?
Definition:
RawCommentList.h:59
Allocator
llvm::SpecificBumpPtrAllocator< StateNode > Allocator
Definition:
UnwrappedLineFormatter.cpp:791
clang::RawComment::RCK_OrdinaryC
Any normal C comment.
Definition:
RawCommentList.h:33
clang::ASTContext
friend class ASTContext
Definition:
Type.h:4178
clang::RawComment::isAlmostTrailingComment
bool isAlmostTrailingComment() const LLVM_READONLY
Returns true if it is a probable typo:
Definition:
RawCommentList.h:80
CommentOptions.h
Defines the clang::CommentOptions interface.
clang::RawComment::RCK_BCPLSlash
Definition:
RawCommentList.h:34
SM
const SourceManager & SM
Definition:
Format.cpp:1184
clang::RawComment::isOrdinary
bool isOrdinary() const LLVM_READONLY
Returns true if this comment is not a documentation comment.
Definition:
RawCommentList.h:85
false
#define false
Definition:
stdbool.h:33
Kind
Kind
Definition:
ChrootChecker.cpp:30
clang::RawComment::RCK_Merged
Two or more documentation comments merged together.
Definition:
RawCommentList.h:38
clang::SourceLocation
Encodes a location in the source.
Definition:
SourceLocation.h:88
clang::RawComment::isParseAllComments
bool isParseAllComments() const LLVM_READONLY
Returns whether we are parsing all comments.
Definition:
RawCommentList.h:96
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition:
SourceLocation.h:201
clang::RawComment::RCK_Invalid
Invalid comment.
Definition:
RawCommentList.h:31
clang::BeforeThanCompare< RawComment >::BeforeThanCompare
BeforeThanCompare(const SourceManager &SM)
Definition:
RawCommentList.h:169
clang::RawComment::isTrailingComment
bool isTrailingComment() const LLVM_READONLY
Returns true if it is a comment that should be put after a member:
Definition:
RawCommentList.h:72
clang::RawComment::getLocStart
SourceLocation getLocStart() const LLVM_READONLY
Definition:
RawCommentList.h:111
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition:
ASTReader.h:312
clang::RawComment::isMerged
bool isMerged() const LLVM_READONLY
Definition:
RawCommentList.h:54
clang::RawComment::getKind
CommentKind getKind() const LLVM_READONLY
Definition:
RawCommentList.h:46
clang::RawComment::RCK_Qt
Definition:
RawCommentList.h:37
clang::RawComment::isDocumentation
bool isDocumentation() const LLVM_READONLY
Returns true if this comment any kind of a documentation comment.
Definition:
RawCommentList.h:91
clang::SourceRange
A trivial tuple used to represent a source range.
Definition:
SourceLocation.h:193
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition:
SourceManager.h:549
clang::RawComment::RawComment
RawComment()
Definition:
RawCommentList.h:41
clang::comments::FullComment
A full comment attached to a declaration, contains block content.
Definition:
Comment.h:1097
clang::RawComment::RCK_JavaDoc
Definition:
RawCommentList.h:36
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition:
Preprocessor.h:97
Generated on Wed Aug 31 2016 16:58:10 for clang by
1.8.6