| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file provides a wrapper for CXXRecordDecl that accumulates GC related | 5 // This file provides a wrapper for CXXRecordDecl that accumulates GC related |
| 6 // information about a class. Accumulated information is memoized and the info | 6 // information about a class. Accumulated information is memoized and the info |
| 7 // objects are stored in a RecordCache. | 7 // objects are stored in a RecordCache. |
| 8 | 8 |
| 9 #ifndef TOOLS_BLINK_GC_PLUGIN_RECORD_INFO_H_ | 9 #ifndef TOOLS_BLINK_GC_PLUGIN_RECORD_INFO_H_ |
| 10 #define TOOLS_BLINK_GC_PLUGIN_RECORD_INFO_H_ | 10 #define TOOLS_BLINK_GC_PLUGIN_RECORD_INFO_H_ |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "Edge.h" | 15 #include "Edge.h" |
| 16 | 16 |
| 17 #include "clang/AST/AST.h" | 17 #include "clang/AST/AST.h" |
| 18 #include "clang/AST/CXXInheritance.h" | 18 #include "clang/AST/CXXInheritance.h" |
| 19 #include "clang/Frontend/CompilerInstance.h" | |
| 20 | 19 |
| 21 class RecordCache; | 20 class RecordCache; |
| 22 | 21 |
| 23 // A potentially tracable and/or lifetime affecting point in the object graph. | 22 // A potentially tracable and/or lifetime affecting point in the object graph. |
| 24 class GraphPoint { | 23 class GraphPoint { |
| 25 public: | 24 public: |
| 26 GraphPoint() : traced_(false) {} | 25 GraphPoint() : traced_(false) {} |
| 27 virtual ~GraphPoint() {} | 26 virtual ~GraphPoint() {} |
| 28 void MarkTraced() { traced_ = true; } | 27 void MarkTraced() { traced_ = true; } |
| 29 bool IsProperlyTraced() { return traced_ || !NeedsTracing().IsNeeded(); } | 28 bool IsProperlyTraced() { return traced_ || !NeedsTracing().IsNeeded(); } |
| 30 bool IsInproperlyTraced() { return traced_ && NeedsTracing().IsIllegal(); } | |
| 31 virtual const TracingStatus NeedsTracing() = 0; | 29 virtual const TracingStatus NeedsTracing() = 0; |
| 32 | 30 |
| 33 private: | 31 private: |
| 34 bool traced_; | 32 bool traced_; |
| 35 }; | 33 }; |
| 36 | 34 |
| 37 class BasePoint : public GraphPoint { | 35 class BasePoint : public GraphPoint { |
| 38 public: | 36 public: |
| 39 BasePoint(const clang::CXXBaseSpecifier& spec, | 37 BasePoint(const clang::CXXBaseSpecifier& spec, |
| 40 RecordInfo* info, | 38 RecordInfo* info, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 151 |
| 154 bool is_gc_derived_; | 152 bool is_gc_derived_; |
| 155 | 153 |
| 156 std::vector<std::string> gc_base_names_; | 154 std::vector<std::string> gc_base_names_; |
| 157 | 155 |
| 158 friend class RecordCache; | 156 friend class RecordCache; |
| 159 }; | 157 }; |
| 160 | 158 |
| 161 class RecordCache { | 159 class RecordCache { |
| 162 public: | 160 public: |
| 163 RecordCache(clang::CompilerInstance& instance) | |
| 164 : instance_(instance) | |
| 165 { | |
| 166 } | |
| 167 | |
| 168 RecordInfo* Lookup(clang::CXXRecordDecl* record); | 161 RecordInfo* Lookup(clang::CXXRecordDecl* record); |
| 169 | 162 |
| 170 RecordInfo* Lookup(const clang::CXXRecordDecl* record) { | 163 RecordInfo* Lookup(const clang::CXXRecordDecl* record) { |
| 171 return Lookup(const_cast<clang::CXXRecordDecl*>(record)); | 164 return Lookup(const_cast<clang::CXXRecordDecl*>(record)); |
| 172 } | 165 } |
| 173 | 166 |
| 174 RecordInfo* Lookup(clang::DeclContext* decl) { | 167 RecordInfo* Lookup(clang::DeclContext* decl) { |
| 175 return Lookup(clang::dyn_cast<clang::CXXRecordDecl>(decl)); | 168 return Lookup(clang::dyn_cast<clang::CXXRecordDecl>(decl)); |
| 176 } | 169 } |
| 177 | 170 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 188 if (!it->second.fields_) | 181 if (!it->second.fields_) |
| 189 continue; | 182 continue; |
| 190 for (RecordInfo::Fields::iterator fit = it->second.fields_->begin(); | 183 for (RecordInfo::Fields::iterator fit = it->second.fields_->begin(); |
| 191 fit != it->second.fields_->end(); | 184 fit != it->second.fields_->end(); |
| 192 ++fit) { | 185 ++fit) { |
| 193 fit->second.deleteEdge(); | 186 fit->second.deleteEdge(); |
| 194 } | 187 } |
| 195 } | 188 } |
| 196 } | 189 } |
| 197 | 190 |
| 198 clang::CompilerInstance& instance() const { return instance_; } | |
| 199 | |
| 200 private: | 191 private: |
| 201 clang::CompilerInstance& instance_; | |
| 202 | |
| 203 typedef std::map<clang::CXXRecordDecl*, RecordInfo> Cache; | 192 typedef std::map<clang::CXXRecordDecl*, RecordInfo> Cache; |
| 204 Cache cache_; | 193 Cache cache_; |
| 205 }; | 194 }; |
| 206 | 195 |
| 207 #endif // TOOLS_BLINK_GC_PLUGIN_RECORD_INFO_H_ | 196 #endif // TOOLS_BLINK_GC_PLUGIN_RECORD_INFO_H_ |
| OLD | NEW |