]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / StaticAnalyzer / Core / PathSensitive / DynamicTypeMap.h
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
17 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
19 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
20 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
21 #include "llvm/ADT/ImmutableMap.h"
22 #include "clang/AST/Type.h"
23
24 namespace clang {
25 namespace ento {
26
27 class MemRegion;
28
29 /// The GDM component containing the dynamic type info. This is a map from a
30 /// symbol to its most likely type.
31 struct DynamicTypeMap {};
32
33 using DynamicTypeMapImpl =
34     llvm::ImmutableMap<const MemRegion *, DynamicTypeInfo>;
35
36 template <>
37 struct ProgramStateTrait<DynamicTypeMap>
38     : public ProgramStatePartialTrait<DynamicTypeMapImpl> {
39   static void *GDMIndex() {
40     static int index = 0;
41     return &index;
42   }
43 };
44
45 /// Get dynamic type information for a region.
46 DynamicTypeInfo getDynamicTypeInfo(ProgramStateRef State,
47                                    const MemRegion *Reg);
48
49 /// Set dynamic type information of the region; return the new state.
50 ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *Reg,
51                                    DynamicTypeInfo NewTy);
52
53 /// Set dynamic type information of the region; return the new state.
54 inline ProgramStateRef setDynamicTypeInfo(ProgramStateRef State,
55                                           const MemRegion *Reg, QualType NewTy,
56                                           bool CanBeSubClassed = true) {
57   return setDynamicTypeInfo(State, Reg,
58                             DynamicTypeInfo(NewTy, CanBeSubClassed));
59 }
60
61 void printDynamicTypeInfo(ProgramStateRef State, raw_ostream &Out,
62                           const char *NL, const char *Sep);
63
64 } // namespace ento
65 } // namespace clang
66
67 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPEMAP_H