• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //== DynamicTypeMap.h - Dynamic type map ----------------------- -*- C++ -*--=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file provides APIs for tracking dynamic type information.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPEMAP_H
15 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPEMAP_H
16 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
17 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
19 #include "llvm/ADT/ImmutableMap.h"
20 
21 namespace clang {
22 namespace ento {
23 
24 /// The GDM component containing the dynamic type info. This is a map from a
25 /// symbol to its most likely type.
26 struct DynamicTypeMap {};
27 typedef llvm::ImmutableMap<const MemRegion *, DynamicTypeInfo>
28     DynamicTypeMapImpl;
29 template <>
30 struct ProgramStateTrait<DynamicTypeMap>
31     : public ProgramStatePartialTrait<DynamicTypeMapImpl> {
32   static void *GDMIndex() {
33     static int index = 0;
34     return &index;
35   }
36 };
37 
38 /// \brief Get dynamic type information for a region.
39 DynamicTypeInfo getDynamicTypeInfo(ProgramStateRef State,
40                                    const MemRegion *Reg);
41 
42 /// \brief Set dynamic type information of the region; return the new state.
43 ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *Reg,
44                                    DynamicTypeInfo NewTy);
45 
46 /// \brief Set dynamic type information of the region; return the new state.
47 inline ProgramStateRef setDynamicTypeInfo(ProgramStateRef State,
48                                           const MemRegion *Reg, QualType NewTy,
49                                           bool CanBeSubClassed = true) {
50   return setDynamicTypeInfo(State, Reg,
51                             DynamicTypeInfo(NewTy, CanBeSubClassed));
52 }
53 
54 } // ento
55 } // clang
56 
57 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPEMAP_H
58