clang  14.0.0git
DynamicTypeInfo.h
Go to the documentation of this file.
1 //===- DynamicTypeInfo.h - Runtime type information -------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPEINFO_H
10 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPEINFO_H
11 
12 #include "clang/AST/Type.h"
13 
14 namespace clang {
15 namespace ento {
16 
17 /// Stores the currently inferred strictest bound on the runtime type
18 /// of a region in a given state along the analysis path.
20 public:
21  DynamicTypeInfo() : DynTy(QualType()) {}
22 
23  DynamicTypeInfo(QualType Ty, bool CanBeSub = true)
24  : DynTy(Ty), CanBeASubClass(CanBeSub) {}
25 
26  /// Returns false if the type information is precise (the type 'DynTy' is
27  /// the only type in the lattice), true otherwise.
28  bool canBeASubClass() const { return CanBeASubClass; }
29 
30  /// Returns true if the dynamic type info is available.
31  bool isValid() const { return !DynTy.isNull(); }
32 
33  /// Returns the currently inferred upper bound on the runtime type.
34  QualType getType() const { return DynTy; }
35 
36  operator bool() const { return isValid(); }
37 
38  bool operator==(const DynamicTypeInfo &RHS) const {
39  return DynTy == RHS.DynTy && CanBeASubClass == RHS.CanBeASubClass;
40  }
41 
42  void Profile(llvm::FoldingSetNodeID &ID) const {
43  ID.Add(DynTy);
44  ID.AddBoolean(CanBeASubClass);
45  }
46 
47 private:
48  QualType DynTy;
49  bool CanBeASubClass;
50 };
51 
52 } // namespace ento
53 } // namespace clang
54 
55 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPEINFO_H
clang::ento::DynamicTypeInfo::getType
QualType getType() const
Returns the currently inferred upper bound on the runtime type.
Definition: DynamicTypeInfo.h:34
clang::ento::DynamicTypeInfo::operator==
bool operator==(const DynamicTypeInfo &RHS) const
Definition: DynamicTypeInfo.h:38
clang::ento::DynamicTypeInfo
Stores the currently inferred strictest bound on the runtime type of a region in a given state along ...
Definition: DynamicTypeInfo.h:19
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
Type.h
bool
#define bool
Definition: stdbool.h:15
clang::ento::DynamicTypeInfo::isValid
bool isValid() const
Returns true if the dynamic type info is available.
Definition: DynamicTypeInfo.h:31
clang::ento::DynamicTypeInfo::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: DynamicTypeInfo.h:42
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:738
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang
Definition: CalledOnceCheck.h:17
clang::ento::DynamicTypeInfo::canBeASubClass
bool canBeASubClass() const
Returns false if the type information is precise (the type 'DynTy' is the only type in the lattice),...
Definition: DynamicTypeInfo.h:28
clang::ento::DynamicTypeInfo::DynamicTypeInfo
DynamicTypeInfo()
Definition: DynamicTypeInfo.h:21
clang::ento::DynamicTypeInfo::DynamicTypeInfo
DynamicTypeInfo(QualType Ty, bool CanBeSub=true)
Definition: DynamicTypeInfo.h:23