clang: include/clang/Analysis/FlowSensitive/StorageLocation.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_STORAGELOCATION_H

15#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_STORAGELOCATION_H

16

19#include "llvm/ADT/DenseMap.h"

20#include "llvm/ADT/StringRef.h"

21#include "llvm/Support/Debug.h"

22#include

23

24#define DEBUG_TYPE "dataflow"

25

27namespace dataflow {

28

29

30

31

32

34public:

39

41 assert(Type.isNull() || !Type->isReferenceType());

42 }

43

44

45

46

49

51

53

55

56private:

57 Kind LocKind;

59};

60

61

62

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

96public:

97 using FieldToLoc = llvm::DenseMap<const ValueDecl *, StorageLocation *>;

99

103 SyntheticFields(std::move(TheSyntheticFields)) {

104 assert(!Type.isNull());

105 assert(Type->isRecordType());

106 assert([this] {

107 for (auto [Field, Loc] : Children) {

108 if (!Field->getType()->isReferenceType() && Loc == nullptr)

109 return false;

110 }

111 return true;

112 }());

113 }

114

118

119

120

121

122

123

124

125

127 auto It = Children.find(&D);

128 LLVM_DEBUG({

129 if (It == Children.end()) {

130 llvm::dbgs() << "Couldn't find child " << D.getNameAsString()

131 << " on StorageLocation " << this << " of type "

133 llvm::dbgs() << "Existing children:\n";

134 for (const auto &Field : Children.keys()) {

135 llvm::dbgs() << Field->getNameAsString() << "\n";

136 }

137 }

138 });

139 assert(It != Children.end());

140 return It->second;

141 }

142

143

144

147 LLVM_DEBUG({

148 if (Loc == nullptr) {

149 llvm::dbgs() << "Couldn't find synthetic field " << Name

150 << " on StorageLocation " << this << " of type "

152 llvm::dbgs() << "Existing synthetic fields:\n";

153 for ([[maybe_unused]] const auto &[Name, Loc] : SyntheticFields) {

154 llvm::dbgs() << Name << "\n";

155 }

156 }

157 });

158 assert(Loc != nullptr);

159 return *Loc;

160 }

161

162 llvm::iterator_rangeSyntheticFieldMap::const\_iterator

164 return {SyntheticFields.begin(), SyntheticFields.end()};

165 }

166

167

169 SyntheticFields.insert({Name, &Loc});

170 }

171

172

173

174

175

176

177

178

181 Children[&D] = Loc;

182 }

183

184

186 Children.insert({&D, Loc});

187 }

188

189 llvm::iterator_rangeFieldToLoc::const\_iterator children() const {

190 return {Children.begin(), Children.end()};

191 }

192

193private:

196};

197

198}

199}

200

201#undef DEBUG_TYPE

202

203#endif

SmallVector< AnnotatedLine *, 1 > Children

If this token starts a block, this contains all the unwrapped lines in it.

C Language Family Type Representation.

std::string getNameAsString() const

Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...

A (possibly-)qualified type.

The base class of the type hierarchy.

bool isReferenceType() const

Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...

llvm::iterator_range< SyntheticFieldMap::const_iterator > synthetic_fields() const

Definition StorageLocation.h:163

StorageLocation * getChild(const ValueDecl &D) const

Returns the child storage location for D.

Definition StorageLocation.h:126

llvm::DenseMap< const ValueDecl *, StorageLocation * > FieldToLoc

Definition StorageLocation.h:97

llvm::StringMap< StorageLocation * > SyntheticFieldMap

Definition StorageLocation.h:98

RecordStorageLocation(QualType Type, FieldToLoc TheChildren, SyntheticFieldMap TheSyntheticFields)

Definition StorageLocation.h:100

void setChild(const ValueDecl &D, StorageLocation *Loc)

Changes the child storage location for a field D of reference type.

Definition StorageLocation.h:179

StorageLocation & getSyntheticField(llvm::StringRef Name) const

Returns the storage location for the synthetic field Name.

Definition StorageLocation.h:145

void addSyntheticField(llvm::StringRef Name, StorageLocation &Loc)

Add a synthetic field, if none by that name is already present.

Definition StorageLocation.h:168

void addChild(const ValueDecl &D, StorageLocation *Loc)

Add a child storage location for a field D, if not already present.

Definition StorageLocation.h:185

static bool classof(const StorageLocation *Loc)

Definition StorageLocation.h:115

llvm::iterator_range< FieldToLoc::const_iterator > children() const

Definition StorageLocation.h:189

ScalarStorageLocation(QualType Type)

Definition StorageLocation.h:65

static bool classof(const StorageLocation *Loc)

Definition StorageLocation.h:68

QualType getType() const

Definition StorageLocation.h:54

virtual ~StorageLocation()=default

StorageLocation(Kind LocKind, QualType Type)

Definition StorageLocation.h:40

StorageLocation & operator=(const StorageLocation &)=delete

StorageLocation(const StorageLocation &)=delete

Kind

Definition StorageLocation.h:35

@ Record

Definition StorageLocation.h:37

@ Scalar

Definition StorageLocation.h:36

Kind getKind() const

Definition StorageLocation.h:52

The JSON file list parser is used to communicate input to InstallAPI.