Skip to content

Commit e37b287

Browse files
author
Balazs Benics
committed
[analyzer][NFC] Use idiomatic classof instead of isKind
- Rename `isKind()` to `classof()` to follow the llvm style RTTI. - Take SVal by-value instead of reference. - Mark `classof` public. Reviewed By: martong, xazax.hun Differential Revision: https://reviews.llvm.org/D125706
1 parent 3606da5 commit e37b287

File tree

1 file changed

+74
-120
lines changed
  • clang/include/clang/StaticAnalyzer/Core/PathSensitive

1 file changed

+74
-120
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h

Lines changed: 74 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ class SVal {
100100
/// the desired type.
101101
template<typename T>
102102
T castAs() const {
103-
assert(T::isKind(*this));
103+
assert(T::classof(*this));
104104
return *static_cast<const T *>(this);
105105
}
106106

107107
/// Convert to the specified SVal type, returning None if this SVal is
108108
/// not of the desired type.
109109
template<typename T>
110110
Optional<T> getAs() const {
111-
if (!T::isKind(*this))
111+
if (!T::classof(*this))
112112
return None;
113113
return *static_cast<const T *>(this);
114114
}
@@ -124,13 +124,11 @@ class SVal {
124124
ID.AddPointer(Data);
125125
}
126126

127-
bool operator==(const SVal &R) const {
127+
bool operator==(SVal R) const {
128128
return getRawKind() == R.getRawKind() && Data == R.Data;
129129
}
130130

131-
bool operator!=(const SVal &R) const {
132-
return !(*this == R);
133-
}
131+
bool operator!=(SVal R) const { return !(*this == R); }
134132

135133
bool isUnknown() const {
136134
return getRawKind() == UnknownValKind;
@@ -221,12 +219,10 @@ class UndefinedVal : public SVal {
221219
public:
222220
UndefinedVal() : SVal(UndefinedValKind) {}
223221

222+
static bool classof(SVal V) { return V.getBaseKind() == UndefinedValKind; }
223+
224224
private:
225225
friend class SVal;
226-
227-
static bool isKind(const SVal& V) {
228-
return V.getBaseKind() == UndefinedValKind;
229-
}
230226
};
231227

232228
class DefinedOrUnknownSVal : public SVal {
@@ -236,6 +232,8 @@ class DefinedOrUnknownSVal : public SVal {
236232
bool isUndef() const = delete;
237233
bool isValid() const = delete;
238234

235+
static bool classof(SVal V) { return !V.isUndef(); }
236+
239237
protected:
240238
DefinedOrUnknownSVal() = default;
241239
explicit DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind)
@@ -244,22 +242,16 @@ class DefinedOrUnknownSVal : public SVal {
244242

245243
private:
246244
friend class SVal;
247-
248-
static bool isKind(const SVal& V) {
249-
return !V.isUndef();
250-
}
251245
};
252246

253247
class UnknownVal : public DefinedOrUnknownSVal {
254248
public:
255249
explicit UnknownVal() : DefinedOrUnknownSVal(UnknownValKind) {}
256250

251+
static bool classof(SVal V) { return V.getBaseKind() == UnknownValKind; }
252+
257253
private:
258254
friend class SVal;
259-
260-
static bool isKind(const SVal &V) {
261-
return V.getBaseKind() == UnknownValKind;
262-
}
263255
};
264256

265257
class DefinedSVal : public DefinedOrUnknownSVal {
@@ -270,32 +262,26 @@ class DefinedSVal : public DefinedOrUnknownSVal {
270262
bool isUnknownOrUndef() const = delete;
271263
bool isValid() const = delete;
272264

265+
static bool classof(SVal V) { return !V.isUnknownOrUndef(); }
266+
273267
protected:
274268
DefinedSVal() = default;
275269
explicit DefinedSVal(const void *d, bool isLoc, unsigned ValKind)
276270
: DefinedOrUnknownSVal(d, isLoc, ValKind) {}
277271

278272
private:
279273
friend class SVal;
280-
281-
static bool isKind(const SVal& V) {
282-
return !V.isUnknownOrUndef();
283-
}
284274
};
285275

286276
/// Represents an SVal that is guaranteed to not be UnknownVal.
287277
class KnownSVal : public SVal {
288278
friend class SVal;
289-
290279
KnownSVal() = default;
291280

292-
static bool isKind(const SVal &V) {
293-
return !V.isUnknown();
294-
}
295-
296281
public:
297282
KnownSVal(const DefinedSVal &V) : SVal(V) {}
298283
KnownSVal(const UndefinedVal &V) : SVal(V) {}
284+
static bool classof(SVal V) { return !V.isUnknown(); }
299285
};
300286

301287
class NonLoc : public DefinedSVal {
@@ -312,12 +298,10 @@ class NonLoc : public DefinedSVal {
312298
T->isAnyComplexType() || T->isVectorType();
313299
}
314300

301+
static bool classof(SVal V) { return V.getBaseKind() == NonLocKind; }
302+
315303
private:
316304
friend class SVal;
317-
318-
static bool isKind(const SVal& V) {
319-
return V.getBaseKind() == NonLocKind;
320-
}
321305
};
322306

323307
class Loc : public DefinedSVal {
@@ -334,12 +318,10 @@ class Loc : public DefinedSVal {
334318
T->isReferenceType() || T->isNullPtrType();
335319
}
336320

321+
static bool classof(SVal V) { return V.getBaseKind() == LocKind; }
322+
337323
private:
338324
friend class SVal;
339-
340-
static bool isKind(const SVal& V) {
341-
return V.getBaseKind() == LocKind;
342-
}
343325
};
344326

345327
//==------------------------------------------------------------------------==//
@@ -365,17 +347,14 @@ class SymbolVal : public NonLoc {
365347
return !isa<SymbolData>(getSymbol());
366348
}
367349

368-
private:
369-
friend class SVal;
370-
371-
static bool isKind(const SVal& V) {
372-
return V.getBaseKind() == NonLocKind &&
373-
V.getSubKind() == SymbolValKind;
350+
static bool classof(SVal V) {
351+
return V.getBaseKind() == NonLocKind && V.getSubKind() == SymbolValKind;
374352
}
375353

376-
static bool isKind(const NonLoc& V) {
377-
return V.getSubKind() == SymbolValKind;
378-
}
354+
static bool classof(NonLoc V) { return V.getSubKind() == SymbolValKind; }
355+
356+
private:
357+
friend class SVal;
379358
};
380359

381360
/// Value representing integer constant.
@@ -392,19 +371,15 @@ class ConcreteInt : public NonLoc {
392371

393372
ConcreteInt evalMinus(SValBuilder &svalBuilder) const;
394373

374+
static bool classof(SVal V) {
375+
return V.getBaseKind() == NonLocKind && V.getSubKind() == ConcreteIntKind;
376+
}
377+
378+
static bool classof(NonLoc V) { return V.getSubKind() == ConcreteIntKind; }
379+
395380
private:
396381
friend class SVal;
397-
398382
ConcreteInt() = default;
399-
400-
static bool isKind(const SVal& V) {
401-
return V.getBaseKind() == NonLocKind &&
402-
V.getSubKind() == ConcreteIntKind;
403-
}
404-
405-
static bool isKind(const NonLoc& V) {
406-
return V.getSubKind() == ConcreteIntKind;
407-
}
408383
};
409384

410385
class LocAsInteger : public NonLoc {
@@ -432,19 +407,15 @@ class LocAsInteger : public NonLoc {
432407
return D->second;
433408
}
434409

410+
static bool classof(SVal V) {
411+
return V.getBaseKind() == NonLocKind && V.getSubKind() == LocAsIntegerKind;
412+
}
413+
414+
static bool classof(NonLoc V) { return V.getSubKind() == LocAsIntegerKind; }
415+
435416
private:
436417
friend class SVal;
437-
438418
LocAsInteger() = default;
439-
440-
static bool isKind(const SVal& V) {
441-
return V.getBaseKind() == NonLocKind &&
442-
V.getSubKind() == LocAsIntegerKind;
443-
}
444-
445-
static bool isKind(const NonLoc& V) {
446-
return V.getSubKind() == LocAsIntegerKind;
447-
}
448419
};
449420

450421
class CompoundVal : public NonLoc {
@@ -462,18 +433,15 @@ class CompoundVal : public NonLoc {
462433
iterator begin() const;
463434
iterator end() const;
464435

465-
private:
466-
friend class SVal;
467-
468-
CompoundVal() = default;
469-
470-
static bool isKind(const SVal& V) {
436+
static bool classof(SVal V) {
471437
return V.getBaseKind() == NonLocKind && V.getSubKind() == CompoundValKind;
472438
}
473439

474-
static bool isKind(const NonLoc& V) {
475-
return V.getSubKind() == CompoundValKind;
476-
}
440+
static bool classof(NonLoc V) { return V.getSubKind() == CompoundValKind; }
441+
442+
private:
443+
friend class SVal;
444+
CompoundVal() = default;
477445
};
478446

479447
class LazyCompoundVal : public NonLoc {
@@ -490,19 +458,18 @@ class LazyCompoundVal : public NonLoc {
490458
const void *getStore() const;
491459
const TypedValueRegion *getRegion() const;
492460

493-
private:
494-
friend class SVal;
495-
496-
LazyCompoundVal() = default;
497-
498-
static bool isKind(const SVal& V) {
461+
static bool classof(SVal V) {
499462
return V.getBaseKind() == NonLocKind &&
500463
V.getSubKind() == LazyCompoundValKind;
501464
}
502465

503-
static bool isKind(const NonLoc& V) {
466+
static bool classof(NonLoc V) {
504467
return V.getSubKind() == LazyCompoundValKind;
505468
}
469+
470+
private:
471+
friend class SVal;
472+
LazyCompoundVal() = default;
506473
};
507474

508475
/// Value representing pointer-to-member.
@@ -540,21 +507,21 @@ class PointerToMember : public NonLoc {
540507
iterator begin() const;
541508
iterator end() const;
542509

543-
private:
544-
friend class SVal;
545-
546-
PointerToMember() = default;
547-
explicit PointerToMember(const PTMDataType D)
548-
: NonLoc(PointerToMemberKind, D.getOpaqueValue()) {}
549-
550-
static bool isKind(const SVal& V) {
510+
static bool classof(SVal V) {
551511
return V.getBaseKind() == NonLocKind &&
552512
V.getSubKind() == PointerToMemberKind;
553513
}
554514

555-
static bool isKind(const NonLoc& V) {
515+
static bool classof(NonLoc V) {
556516
return V.getSubKind() == PointerToMemberKind;
557517
}
518+
519+
private:
520+
friend class SVal;
521+
522+
PointerToMember() = default;
523+
explicit PointerToMember(const PTMDataType D)
524+
: NonLoc(PointerToMemberKind, D.getOpaqueValue()) {}
558525
};
559526

560527
} // namespace nonloc
@@ -575,18 +542,15 @@ class GotoLabel : public Loc {
575542
return static_cast<const LabelDecl *>(Data);
576543
}
577544

578-
private:
579-
friend class SVal;
580-
581-
GotoLabel() = default;
582-
583-
static bool isKind(const SVal& V) {
545+
static bool classof(SVal V) {
584546
return V.getBaseKind() == LocKind && V.getSubKind() == GotoLabelKind;
585547
}
586548

587-
static bool isKind(const Loc& V) {
588-
return V.getSubKind() == GotoLabelKind;
589-
}
549+
static bool classof(Loc V) { return V.getSubKind() == GotoLabelKind; }
550+
551+
private:
552+
friend class SVal;
553+
GotoLabel() = default;
590554
};
591555

592556
class MemRegionVal : public Loc {
@@ -616,19 +580,15 @@ class MemRegionVal : public Loc {
616580
return getRegion() != R.getRegion();
617581
}
618582

583+
static bool classof(SVal V) {
584+
return V.getBaseKind() == LocKind && V.getSubKind() == MemRegionValKind;
585+
}
586+
587+
static bool classof(Loc V) { return V.getSubKind() == MemRegionValKind; }
588+
619589
private:
620590
friend class SVal;
621-
622591
MemRegionVal() = default;
623-
624-
static bool isKind(const SVal& V) {
625-
return V.getBaseKind() == LocKind &&
626-
V.getSubKind() == MemRegionValKind;
627-
}
628-
629-
static bool isKind(const Loc& V) {
630-
return V.getSubKind() == MemRegionValKind;
631-
}
632592
};
633593

634594
class ConcreteInt : public Loc {
@@ -639,25 +599,19 @@ class ConcreteInt : public Loc {
639599
return *static_cast<const llvm::APSInt *>(Data);
640600
}
641601

602+
static bool classof(SVal V) {
603+
return V.getBaseKind() == LocKind && V.getSubKind() == ConcreteIntKind;
604+
}
605+
606+
static bool classof(Loc V) { return V.getSubKind() == ConcreteIntKind; }
607+
642608
private:
643609
friend class SVal;
644-
645610
ConcreteInt() = default;
646-
647-
static bool isKind(const SVal& V) {
648-
return V.getBaseKind() == LocKind &&
649-
V.getSubKind() == ConcreteIntKind;
650-
}
651-
652-
static bool isKind(const Loc& V) {
653-
return V.getSubKind() == ConcreteIntKind;
654-
}
655611
};
656612

657613
} // namespace loc
658-
659614
} // namespace ento
660-
661615
} // namespace clang
662616

663617
#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H

0 commit comments

Comments
 (0)