1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #ifndef LLVM_CLANG_AST_RAWCOMMENTLIST_H |
10 | #define |
11 | |
12 | #include "clang/Basic/CommentOptions.h" |
13 | #include "clang/Basic/SourceManager.h" |
14 | #include "llvm/ADT/ArrayRef.h" |
15 | |
16 | namespace clang { |
17 | |
18 | class ASTContext; |
19 | class ASTReader; |
20 | class Decl; |
21 | class Preprocessor; |
22 | |
23 | namespace comments { |
24 | class ; |
25 | } |
26 | |
27 | class { |
28 | public: |
29 | enum { |
30 | , |
31 | , |
32 | , |
33 | , |
34 | , |
35 | , |
36 | , |
37 | |
38 | }; |
39 | |
40 | RawComment() : Kind(RCK_Invalid), IsAlmostTrailingComment(false) { } |
41 | |
42 | RawComment(const SourceManager &SourceMgr, SourceRange SR, |
43 | const CommentOptions &, bool Merged); |
44 | |
45 | CommentKind () const LLVM_READONLY { |
46 | return (CommentKind) Kind; |
47 | } |
48 | |
49 | bool isInvalid() const LLVM_READONLY { |
50 | return Kind == RCK_Invalid; |
51 | } |
52 | |
53 | bool isMerged() const LLVM_READONLY { |
54 | return Kind == RCK_Merged; |
55 | } |
56 | |
57 | |
58 | bool isAttached() const LLVM_READONLY { |
59 | return IsAttached; |
60 | } |
61 | |
62 | void setAttached() { |
63 | IsAttached = true; |
64 | } |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | bool isTrailingComment() const LLVM_READONLY { |
72 | return IsTrailingComment; |
73 | } |
74 | |
75 | |
76 | |
77 | |
78 | bool isAlmostTrailingComment() const LLVM_READONLY { |
79 | return IsAlmostTrailingComment; |
80 | } |
81 | |
82 | |
83 | bool isOrdinary() const LLVM_READONLY { |
84 | return ((Kind == RCK_OrdinaryBCPL) || (Kind == RCK_OrdinaryC)); |
85 | } |
86 | |
87 | |
88 | bool isDocumentation() const LLVM_READONLY { |
89 | return !isInvalid() && !isOrdinary(); |
90 | } |
91 | |
92 | |
93 | StringRef getRawText(const SourceManager &SourceMgr) const { |
94 | if (RawTextValid) |
95 | return RawText; |
96 | |
97 | RawText = getRawTextSlow(SourceMgr); |
98 | RawTextValid = true; |
99 | return RawText; |
100 | } |
101 | |
102 | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
103 | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
104 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
105 | |
106 | const char *getBriefText(const ASTContext &Context) const { |
107 | if (BriefTextValid) |
108 | return BriefText; |
109 | |
110 | return extractBriefText(Context); |
111 | } |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | std::string getFormattedText(const SourceManager &SourceMgr, |
135 | DiagnosticsEngine &Diags) const; |
136 | |
137 | |
138 | comments::FullComment *(const ASTContext &Context, |
139 | const Preprocessor *PP, const Decl *D) const; |
140 | |
141 | private: |
142 | SourceRange ; |
143 | |
144 | mutable StringRef ; |
145 | mutable const char *; |
146 | |
147 | mutable bool : 1; |
148 | mutable bool : 1; |
149 | |
150 | unsigned : 3; |
151 | |
152 | |
153 | bool : 1; |
154 | |
155 | bool : 1; |
156 | bool : 1; |
157 | |
158 | |
159 | RawComment(SourceRange SR, CommentKind K, bool , |
160 | bool ) : |
161 | Range(SR), RawTextValid(false), BriefTextValid(false), Kind(K), |
162 | IsAttached(false), IsTrailingComment(IsTrailingComment), |
163 | IsAlmostTrailingComment(IsAlmostTrailingComment) |
164 | { } |
165 | |
166 | StringRef (const SourceManager &SourceMgr) const; |
167 | |
168 | const char *(const ASTContext &Context) const; |
169 | |
170 | friend class ASTReader; |
171 | }; |
172 | |
173 | |
174 | template<> |
175 | class BeforeThanCompare<RawComment> { |
176 | const SourceManager &SM; |
177 | |
178 | public: |
179 | explicit BeforeThanCompare(const SourceManager &SM) : SM(SM) { } |
180 | |
181 | bool operator()(const RawComment &LHS, const RawComment &RHS) { |
182 | return SM.isBeforeInTranslationUnit(LHS.getBeginLoc(), RHS.getBeginLoc()); |
183 | } |
184 | |
185 | bool operator()(const RawComment *LHS, const RawComment *RHS) { |
186 | return operator()(*LHS, *RHS); |
187 | } |
188 | }; |
189 | |
190 | |
191 | |
192 | class { |
193 | public: |
194 | RawCommentList(SourceManager &SourceMgr) : SourceMgr(SourceMgr) {} |
195 | |
196 | void (const RawComment &RC, const CommentOptions &, |
197 | llvm::BumpPtrAllocator &Allocator); |
198 | |
199 | ArrayRef<RawComment *> () const { |
200 | return Comments; |
201 | } |
202 | |
203 | private: |
204 | SourceManager &; |
205 | std::vector<RawComment *> ; |
206 | |
207 | void (ArrayRef<RawComment *> ); |
208 | |
209 | friend class ASTReader; |
210 | }; |
211 | |
212 | } |
213 | |
214 | #endif |
215 | |