21
21
#include " llvm/ADT/DenseMap.h"
22
22
#include " llvm/ADT/FoldingSet.h"
23
23
#include " llvm/Support/Casting.h"
24
+ #include " llvm/ADT/StringRef.h"
24
25
#include < cassert>
25
26
#include < utility>
27
+ #include < string>
26
28
27
29
namespace clang {
28
30
29
- class LocationContext ;
30
31
class AnalysisContext ;
31
32
class FunctionDecl ;
32
-
33
+ class LocationContext ;
34
+ class ProgramPointTag ;
35
+
33
36
class ProgramPoint {
34
37
public:
35
38
enum Kind { BlockEdgeKind,
@@ -58,15 +61,17 @@ class ProgramPoint {
58
61
// The LocationContext could be NULL to allow ProgramPoint to be used in
59
62
// context insensitive analysis.
60
63
const LocationContext *L;
61
- const void *Tag;
64
+ const ProgramPointTag *Tag;
62
65
66
+ ProgramPoint ();
67
+
63
68
protected:
64
69
ProgramPoint (const void * P, Kind k, const LocationContext *l,
65
- const void *tag = 0 )
70
+ const ProgramPointTag *tag = 0 )
66
71
: Data(P, static_cast <const void *>(NULL )), K(k), L(l), Tag(tag) {}
67
72
68
73
ProgramPoint (const void * P1, const void * P2, Kind k, const LocationContext *l,
69
- const void *tag = 0 )
74
+ const ProgramPointTag *tag = 0 )
70
75
: Data(P1, P2), K(k), L(l), Tag(tag) {}
71
76
72
77
protected:
@@ -76,7 +81,7 @@ class ProgramPoint {
76
81
public:
77
82
Kind getKind () const { return K; }
78
83
79
- const void *getTag () const { return Tag; }
84
+ const ProgramPointTag *getTag () const { return Tag; }
80
85
81
86
const LocationContext *getLocationContext () const { return L; }
82
87
@@ -109,7 +114,7 @@ class ProgramPoint {
109
114
class BlockEntrance : public ProgramPoint {
110
115
public:
111
116
BlockEntrance (const CFGBlock* B, const LocationContext *L,
112
- const void *tag = 0 )
117
+ const ProgramPointTag *tag = 0 )
113
118
: ProgramPoint(B, BlockEntranceKind, L, tag) {}
114
119
115
120
const CFGBlock* getBlock () const {
@@ -123,7 +128,7 @@ class BlockEntrance : public ProgramPoint {
123
128
124
129
// / Create a new BlockEntrance object that is the same as the original
125
130
// / except for using the specified tag value.
126
- BlockEntrance withTag (const void *tag) {
131
+ BlockEntrance withTag (const ProgramPointTag *tag) {
127
132
return BlockEntrance (getBlock (), getLocationContext (), tag);
128
133
}
129
134
@@ -153,7 +158,7 @@ class BlockExit : public ProgramPoint {
153
158
class StmtPoint : public ProgramPoint {
154
159
public:
155
160
StmtPoint (const Stmt *S, const void *p2, Kind k, const LocationContext *L,
156
- const void *tag)
161
+ const ProgramPointTag *tag)
157
162
: ProgramPoint(S, p2, k, L, tag) {}
158
163
159
164
const Stmt *getStmt () const { return (const Stmt*) getData1 (); }
@@ -170,7 +175,7 @@ class StmtPoint : public ProgramPoint {
170
175
171
176
class PreStmt : public StmtPoint {
172
177
public:
173
- PreStmt (const Stmt *S, const LocationContext *L, const void *tag,
178
+ PreStmt (const Stmt *S, const LocationContext *L, const ProgramPointTag *tag,
174
179
const Stmt *SubStmt = 0 )
175
180
: StmtPoint(S, SubStmt, PreStmtKind, L, tag) {}
176
181
@@ -184,15 +189,16 @@ class PreStmt : public StmtPoint {
184
189
class PostStmt : public StmtPoint {
185
190
protected:
186
191
PostStmt (const Stmt* S, const void * data, Kind k, const LocationContext *L,
187
- const void *tag =0 )
192
+ const ProgramPointTag *tag =0 )
188
193
: StmtPoint(S, data, k, L, tag) {}
189
194
190
195
public:
191
196
explicit PostStmt (const Stmt* S, Kind k,
192
- const LocationContext *L, const void *tag = 0 )
197
+ const LocationContext *L, const ProgramPointTag *tag = 0 )
193
198
: StmtPoint(S, NULL , k, L, tag) {}
194
199
195
- explicit PostStmt (const Stmt* S, const LocationContext *L,const void *tag = 0 )
200
+ explicit PostStmt (const Stmt* S, const LocationContext *L,
201
+ const ProgramPointTag *tag = 0 )
196
202
: StmtPoint(S, NULL , PostStmtKind, L, tag) {}
197
203
198
204
static bool classof (const ProgramPoint* Location) {
@@ -225,7 +231,8 @@ class PostStmtCustom : public PostStmt {
225
231
// PostCondition represents the post program point of a branch condition.
226
232
class PostCondition : public PostStmt {
227
233
public:
228
- PostCondition (const Stmt* S, const LocationContext *L, const void *tag = 0 )
234
+ PostCondition (const Stmt* S, const LocationContext *L,
235
+ const ProgramPointTag *tag = 0 )
229
236
: PostStmt(S, PostConditionKind, L, tag) {}
230
237
231
238
static bool classof (const ProgramPoint* Location) {
@@ -236,7 +243,7 @@ class PostCondition : public PostStmt {
236
243
class LocationCheck : public StmtPoint {
237
244
protected:
238
245
LocationCheck (const Stmt *S, const LocationContext *L,
239
- ProgramPoint::Kind K, const void *tag)
246
+ ProgramPoint::Kind K, const ProgramPointTag *tag)
240
247
: StmtPoint(S, NULL , K, L, tag) {}
241
248
242
249
static bool classof (const ProgramPoint *location) {
@@ -247,7 +254,8 @@ class LocationCheck : public StmtPoint {
247
254
248
255
class PreLoad : public LocationCheck {
249
256
public:
250
- PreLoad (const Stmt *S, const LocationContext *L, const void *tag = 0 )
257
+ PreLoad (const Stmt *S, const LocationContext *L,
258
+ const ProgramPointTag *tag = 0 )
251
259
: LocationCheck(S, L, PreLoadKind, tag) {}
252
260
253
261
static bool classof (const ProgramPoint *location) {
@@ -257,7 +265,8 @@ class PreLoad : public LocationCheck {
257
265
258
266
class PreStore : public LocationCheck {
259
267
public:
260
- PreStore (const Stmt *S, const LocationContext *L, const void *tag = 0 )
268
+ PreStore (const Stmt *S, const LocationContext *L,
269
+ const ProgramPointTag *tag = 0 )
261
270
: LocationCheck(S, L, PreStoreKind, tag) {}
262
271
263
272
static bool classof (const ProgramPoint *location) {
@@ -267,7 +276,8 @@ class PreStore : public LocationCheck {
267
276
268
277
class PostLoad : public PostStmt {
269
278
public:
270
- PostLoad (const Stmt* S, const LocationContext *L, const void *tag = 0 )
279
+ PostLoad (const Stmt* S, const LocationContext *L,
280
+ const ProgramPointTag *tag = 0 )
271
281
: PostStmt(S, PostLoadKind, L, tag) {}
272
282
273
283
static bool classof (const ProgramPoint* Location) {
@@ -277,7 +287,8 @@ class PostLoad : public PostStmt {
277
287
278
288
class PostStore : public PostStmt {
279
289
public:
280
- PostStore (const Stmt* S, const LocationContext *L, const void *tag = 0 )
290
+ PostStore (const Stmt* S, const LocationContext *L,
291
+ const ProgramPointTag *tag = 0 )
281
292
: PostStmt(S, PostStoreKind, L, tag) {}
282
293
283
294
static bool classof (const ProgramPoint* Location) {
@@ -287,7 +298,8 @@ class PostStore : public PostStmt {
287
298
288
299
class PostLValue : public PostStmt {
289
300
public:
290
- PostLValue (const Stmt* S, const LocationContext *L, const void *tag = 0 )
301
+ PostLValue (const Stmt* S, const LocationContext *L,
302
+ const ProgramPointTag *tag = 0 )
291
303
: PostStmt(S, PostLValueKind, L, tag) {}
292
304
293
305
static bool classof (const ProgramPoint* Location) {
@@ -298,7 +310,7 @@ class PostLValue : public PostStmt {
298
310
class PostPurgeDeadSymbols : public PostStmt {
299
311
public:
300
312
PostPurgeDeadSymbols (const Stmt* S, const LocationContext *L,
301
- const void *tag = 0 )
313
+ const ProgramPointTag *tag = 0 )
302
314
: PostStmt(S, PostPurgeDeadSymbolsKind, L, tag) {}
303
315
304
316
static bool classof (const ProgramPoint* Location) {
@@ -365,6 +377,28 @@ class CallExit : public StmtPoint {
365
377
}
366
378
};
367
379
380
+ // / ProgramPoints can be "tagged" as representing points specific to a given
381
+ // / analysis entity. Tags are abstract annotations, with an associated
382
+ // / description and potentially other information.
383
+ class ProgramPointTag {
384
+ public:
385
+ ProgramPointTag (void *tagKind = 0 ) : TagKind(tagKind) {}
386
+ virtual ~ProgramPointTag ();
387
+ virtual StringRef getTagDescription () const = 0;
388
+
389
+ protected:
390
+ const void *getTagKind () { return TagKind; }
391
+
392
+ private:
393
+ const void *TagKind;
394
+ };
395
+
396
+ class SimpleProgramPointTag : public ProgramPointTag {
397
+ std::string desc;
398
+ public:
399
+ SimpleProgramPointTag (StringRef description);
400
+ StringRef getTagDescription () const ;
401
+ };
368
402
369
403
} // end namespace clang
370
404
0 commit comments