Home | History | Annotate | Line # | Download | only in PathSensitive
      1 //===- DynamicCastInfo.h - Runtime cast 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_DYNAMICCASTINFO_H
     10 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICCASTINFO_H
     11 
     12 #include "clang/AST/Type.h"
     13 
     14 namespace clang {
     15 namespace ento {
     16 
     17 class DynamicCastInfo {
     18 public:
     19   enum CastResult { Success, Failure };
     20 
     21   DynamicCastInfo(QualType from, QualType to, CastResult resultKind)
     22       : From(from), To(to), ResultKind(resultKind) {}
     23 
     24   QualType from() const { return From; }
     25   QualType to() const { return To; }
     26 
     27   bool equals(QualType from, QualType to) const {
     28     return From == from && To == to;
     29   }
     30 
     31   bool succeeds() const { return ResultKind == CastResult::Success; }
     32   bool fails() const { return ResultKind == CastResult::Failure; }
     33 
     34   bool operator==(const DynamicCastInfo &RHS) const {
     35     return From == RHS.From && To == RHS.To;
     36   }
     37   bool operator<(const DynamicCastInfo &RHS) const {
     38     return From < RHS.From && To < RHS.To;
     39   }
     40 
     41   void Profile(llvm::FoldingSetNodeID &ID) const {
     42     ID.Add(From);
     43     ID.Add(To);
     44     ID.AddInteger(ResultKind);
     45   }
     46 
     47 private:
     48   QualType From, To;
     49   CastResult ResultKind;
     50 };
     51 
     52 } // namespace ento
     53 } // namespace clang
     54 
     55 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICCASTINFO_H
     56