18 #include "llvm/ADT/STLExtras.h"
20 using namespace clang;
24 std::pair<RawComment::CommentKind, bool> getCommentKind(StringRef Comment,
25 bool ParseAllComments) {
26 const size_t MinCommentLength = ParseAllComments ? 2 : 3;
27 if ((Comment.size() < MinCommentLength) || Comment[0] !=
'/')
31 if (Comment[1] ==
'/') {
32 if (Comment.size() < 3)
35 if (Comment[2] ==
'/')
37 else if (Comment[2] ==
'!')
42 assert(Comment.size() >= 4);
46 if (Comment[1] !=
'*' ||
47 Comment[Comment.size() - 2] !=
'*' ||
48 Comment[Comment.size() - 1] !=
'/')
51 if (Comment[2] ==
'*')
53 else if (Comment[2] ==
'!')
58 const bool TrailingComment = (Comment.size() > 3) && (Comment[3] ==
'<');
59 return std::make_pair(K, TrailingComment);
62 bool mergedCommentIsTrailingComment(StringRef Comment) {
63 return (Comment.size() > 3) && (Comment[3] ==
'<');
68 bool Merged,
bool ParseAllComments) :
69 Range(SR), RawTextValid(
false), BriefTextValid(
false),
70 IsAttached(
false), IsAlmostTrailingComment(
false),
71 ParseAllComments(ParseAllComments) {
80 std::pair<CommentKind, bool> K = getCommentKind(RawText, ParseAllComments);
82 IsTrailingComment = K.second;
84 IsAlmostTrailingComment = RawText.startswith(
"//<") ||
85 RawText.startswith(
"/*<");
88 IsTrailingComment = mergedCommentIsTrailingComment(RawText);
98 std::tie(BeginFileID, BeginOffset) =
102 const unsigned Length = EndOffset - BeginOffset;
107 assert(BeginFileID == EndFileID);
109 bool Invalid =
false;
110 const char *BufferStart = SourceMgr.
getBufferData(BeginFileID,
115 return StringRef(BufferStart + BeginOffset, Length);
130 RawText.begin(), RawText.end());
133 const std::string
Result =
P.Parse();
134 const unsigned BriefTextLength = Result.size();
135 char *BriefTextPtr =
new (
Context)
char[BriefTextLength + 1];
136 memcpy(BriefTextPtr, Result.c_str(), BriefTextLength + 1);
137 BriefText = BriefTextPtr;
138 BriefTextValid =
true;
145 const Decl *D)
const {
152 RawText.begin(), RawText.end());
162 return P.parseFullComment();
167 unsigned MaxNewlinesAllowed) {
172 if (Loc1Info.first != Loc2Info.first)
175 bool Invalid =
false;
176 const char *Buffer = SM.
getBufferData(Loc1Info.first, &Invalid).data();
180 unsigned NumNewlines = 0;
181 assert(Loc1Info.second <= Loc2Info.second &&
"Loc1 after Loc2!");
183 for (
unsigned I = Loc1Info.second; I != Loc2Info.second; ++I) {
198 if (NumNewlines > MaxNewlinesAllowed)
202 if (I + 1 != Loc2Info.second &&
203 (Buffer[I + 1] ==
'\n' || Buffer[I + 1] ==
'\r') &&
204 Buffer[I] != Buffer[I + 1])
214 llvm::BumpPtrAllocator &Allocator) {
219 while (!Comments.empty() &&
233 if (Comments.empty()) {
234 Comments.push_back(
new (Allocator)
RawComment(RC));
248 *Comments.back() =
RawComment(SourceMgr, MergedRange,
true,
251 Comments.push_back(
new (Allocator)
RawComment(RC));
256 std::vector<RawComment *> MergedComments;
257 MergedComments.reserve(Comments.size() + DeserializedComments.size());
259 std::merge(Comments.begin(), Comments.end(),
260 DeserializedComments.begin(), DeserializedComments.end(),
261 std::back_inserter(MergedComments),
263 std::swap(Comments, MergedComments);
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
comments::CommandTraits & getCommentCommandTraits() const
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
llvm::BumpPtrAllocator & getAllocator() const
DiagnosticsEngine & getDiagnostics() const
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
The result type of a method or function.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
SourceLocation getBegin() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
SourceManager & getSourceManager()
A trivial tuple used to represent a source range.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.