| 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" |
| 19 | 20 |
| 20 class RecordCache; | 21 class RecordCache; |
| 21 | 22 |
| 22 // A potentially tracable and/or lifetime affecting point in the object graph. | 23 // A potentially tracable and/or lifetime affecting point in the object graph. |
| 23 class GraphPoint { | 24 class GraphPoint { |
| 24 public: | 25 public: |
| 25 GraphPoint() : traced_(false) {} | 26 GraphPoint() : traced_(false) {} |
| 26 virtual ~GraphPoint() {} | 27 virtual ~GraphPoint() {} |
| 27 void MarkTraced() { traced_ = true; } | 28 void MarkTraced() { traced_ = true; } |
| 28 bool IsProperlyTraced() { return traced_ || !NeedsTracing().IsNeeded(); } | 29 bool IsProperlyTraced() { return traced_ || !NeedsTracing().IsNeeded(); } |
| 30 bool IsInproperlyTraced() { return traced_ && NeedsTracing().IsIllegal(); } |
| 29 virtual const TracingStatus NeedsTracing() = 0; | 31 virtual const TracingStatus NeedsTracing() = 0; |
| 30 | 32 |
| 31 private: | 33 private: |
| 32 bool traced_; | 34 bool traced_; |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 class BasePoint : public GraphPoint { | 37 class BasePoint : public GraphPoint { |
| 36 public: | 38 public: |
| 37 BasePoint(const clang::CXXBaseSpecifier& spec, | 39 BasePoint(const clang::CXXBaseSpecifier& spec, |
| 38 RecordInfo* info, | 40 RecordInfo* info, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 153 |
| 152 bool is_gc_derived_; | 154 bool is_gc_derived_; |
| 153 | 155 |
| 154 std::vector<std::string> gc_base_names_; | 156 std::vector<std::string> gc_base_names_; |
| 155 | 157 |
| 156 friend class RecordCache; | 158 friend class RecordCache; |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 class RecordCache { | 161 class RecordCache { |
| 160 public: | 162 public: |
| 163 RecordCache(clang::CompilerInstance& instance) |
| 164 : instance_(instance) |
| 165 { |
| 166 } |
| 167 |
| 161 RecordInfo* Lookup(clang::CXXRecordDecl* record); | 168 RecordInfo* Lookup(clang::CXXRecordDecl* record); |
| 162 | 169 |
| 163 RecordInfo* Lookup(const clang::CXXRecordDecl* record) { | 170 RecordInfo* Lookup(const clang::CXXRecordDecl* record) { |
| 164 return Lookup(const_cast<clang::CXXRecordDecl*>(record)); | 171 return Lookup(const_cast<clang::CXXRecordDecl*>(record)); |
| 165 } | 172 } |
| 166 | 173 |
| 167 RecordInfo* Lookup(clang::DeclContext* decl) { | 174 RecordInfo* Lookup(clang::DeclContext* decl) { |
| 168 return Lookup(clang::dyn_cast<clang::CXXRecordDecl>(decl)); | 175 return Lookup(clang::dyn_cast<clang::CXXRecordDecl>(decl)); |
| 169 } | 176 } |
| 170 | 177 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 181 if (!it->second.fields_) | 188 if (!it->second.fields_) |
| 182 continue; | 189 continue; |
| 183 for (RecordInfo::Fields::iterator fit = it->second.fields_->begin(); | 190 for (RecordInfo::Fields::iterator fit = it->second.fields_->begin(); |
| 184 fit != it->second.fields_->end(); | 191 fit != it->second.fields_->end(); |
| 185 ++fit) { | 192 ++fit) { |
| 186 fit->second.deleteEdge(); | 193 fit->second.deleteEdge(); |
| 187 } | 194 } |
| 188 } | 195 } |
| 189 } | 196 } |
| 190 | 197 |
| 198 clang::CompilerInstance& instance() const { return instance_; } |
| 199 |
| 191 private: | 200 private: |
| 201 clang::CompilerInstance& instance_; |
| 202 |
| 192 typedef std::map<clang::CXXRecordDecl*, RecordInfo> Cache; | 203 typedef std::map<clang::CXXRecordDecl*, RecordInfo> Cache; |
| 193 Cache cache_; | 204 Cache cache_; |
| 194 }; | 205 }; |
| 195 | 206 |
| 196 #endif // TOOLS_BLINK_GC_PLUGIN_RECORD_INFO_H_ | 207 #endif // TOOLS_BLINK_GC_PLUGIN_RECORD_INFO_H_ |
| OLD | NEW |