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 defines the names used by GC infrastructure. | 5 // This file defines the names used by GC infrastructure. |
6 | 6 |
7 // TODO: Restructure the name determination to use fully qualified names (ala, | 7 // TODO: Restructure the name determination to use fully qualified names (ala, |
8 // blink::Foo) so that the plugin can be enabled for all of chromium. Doing so | 8 // blink::Foo) so that the plugin can be enabled for all of chromium. Doing so |
9 // would allow us to catch errors with structures outside of blink that might | 9 // would allow us to catch errors with structures outside of blink that might |
10 // have unsafe pointers to GC allocated blink structures. | 10 // have unsafe pointers to GC allocated blink structures. |
11 | 11 |
12 #ifndef TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ | 12 #ifndef TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ |
13 #define TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ | 13 #define TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ |
14 | 14 |
| 15 #include <cassert> |
| 16 |
15 #include "clang/AST/AST.h" | 17 #include "clang/AST/AST.h" |
16 #include "clang/AST/Attr.h" | 18 #include "clang/AST/Attr.h" |
17 | 19 |
18 const char kNewOperatorName[] = "operator new"; | 20 const char kNewOperatorName[] = "operator new"; |
19 const char kCreateName[] = "create"; | 21 const char kCreateName[] = "create"; |
20 const char kTraceName[] = "trace"; | 22 const char kTraceName[] = "trace"; |
21 const char kTraceImplName[] = "traceImpl"; | 23 const char kTraceImplName[] = "traceImpl"; |
22 const char kFinalizeName[] = "finalizeGarbageCollectedObject"; | 24 const char kFinalizeName[] = "finalizeGarbageCollectedObject"; |
23 const char kTraceAfterDispatchName[] = "traceAfterDispatch"; | 25 const char kTraceAfterDispatchName[] = "traceAfterDispatch"; |
| 26 const char kTraceAfterDispatchImplName[] = "traceAfterDispatchImpl"; |
24 const char kRegisterWeakMembersName[] = "registerWeakMembers"; | 27 const char kRegisterWeakMembersName[] = "registerWeakMembers"; |
25 const char kHeapAllocatorName[] = "HeapAllocator"; | 28 const char kHeapAllocatorName[] = "HeapAllocator"; |
26 const char kTraceIfNeededName[] = "TraceIfNeeded"; | 29 const char kTraceIfNeededName[] = "TraceIfNeeded"; |
27 const char kVisitorDispatcherName[] = "VisitorDispatcher"; | 30 const char kVisitorDispatcherName[] = "VisitorDispatcher"; |
| 31 const char kVisitorVarName[] = "visitor"; |
28 const char kAdjustAndMarkName[] = "adjustAndMark"; | 32 const char kAdjustAndMarkName[] = "adjustAndMark"; |
29 const char kIsHeapObjectAliveName[] = "isHeapObjectAlive"; | 33 const char kIsHeapObjectAliveName[] = "isHeapObjectAlive"; |
30 | 34 |
31 class Config { | 35 class Config { |
32 public: | 36 public: |
33 static bool IsMember(const std::string& name) { | 37 static bool IsMember(const std::string& name) { |
34 return name == "Member"; | 38 return name == "Member"; |
35 } | 39 } |
36 | 40 |
37 static bool IsWeakMember(const std::string& name) { | 41 static bool IsWeakMember(const std::string& name) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 formal_type.getTypePtr())) { | 199 formal_type.getTypePtr())) { |
196 if (parm_type->getDecl()->getName() == kVisitorDispatcherName) { | 200 if (parm_type->getDecl()->getName() == kVisitorDispatcherName) { |
197 // Unresolved, but its parameter name is VisitorDispatcher. | 201 // Unresolved, but its parameter name is VisitorDispatcher. |
198 return true; | 202 return true; |
199 } | 203 } |
200 } | 204 } |
201 | 205 |
202 return IsVisitorPtrType(formal_type); | 206 return IsVisitorPtrType(formal_type); |
203 } | 207 } |
204 | 208 |
205 static bool IsTraceMethod(clang::FunctionDecl* method, | 209 enum TraceMethodType { |
206 bool* is_trace_after_dispatch) { | 210 NOT_TRACE_METHOD, |
| 211 TRACE_METHOD, |
| 212 TRACE_AFTER_DISPATCH_METHOD, |
| 213 TRACE_IMPL_METHOD, |
| 214 TRACE_AFTER_DISPATCH_IMPL_METHOD |
| 215 }; |
| 216 |
| 217 static TraceMethodType GetTraceMethodType(clang::FunctionDecl* method) { |
207 if (method->getNumParams() != 1) | 218 if (method->getNumParams() != 1) |
208 return false; | 219 return NOT_TRACE_METHOD; |
209 | 220 |
210 const std::string& name = method->getNameAsString(); | 221 const std::string& name = method->getNameAsString(); |
211 if (name != kTraceName && name != kTraceAfterDispatchName && | 222 if (name != kTraceName && name != kTraceAfterDispatchName && |
212 name != kTraceImplName) | 223 name != kTraceImplName && name != kTraceAfterDispatchImplName) |
213 return false; | 224 return NOT_TRACE_METHOD; |
214 | 225 |
215 const clang::QualType& formal_type = method->getParamDecl(0)->getType(); | 226 const clang::QualType& formal_type = method->getParamDecl(0)->getType(); |
216 if (name == kTraceImplName) { | 227 if (name == kTraceImplName || name == kTraceAfterDispatchImplName) { |
217 if (!IsVisitorDispatcherType(formal_type)) | 228 if (!IsVisitorDispatcherType(formal_type)) |
218 return false; | 229 return NOT_TRACE_METHOD; |
219 } else if (!IsVisitorPtrType(formal_type)) { | 230 } else if (!IsVisitorPtrType(formal_type)) { |
220 return false; | 231 return NOT_TRACE_METHOD; |
221 } | 232 } |
222 | 233 |
223 if (is_trace_after_dispatch) | 234 if (name == kTraceName) |
224 *is_trace_after_dispatch = (name == kTraceAfterDispatchName); | 235 return TRACE_METHOD; |
| 236 if (name == kTraceAfterDispatchName) |
| 237 return TRACE_AFTER_DISPATCH_METHOD; |
| 238 if (name == kTraceImplName) |
| 239 return TRACE_AFTER_DISPATCH_METHOD; |
| 240 if (name == kTraceAfterDispatchImplName) |
| 241 return TRACE_AFTER_DISPATCH_IMPL_METHOD; |
225 | 242 |
226 return true; | 243 assert(false && "Should not reach here"); |
| 244 return NOT_TRACE_METHOD; |
| 245 } |
| 246 |
| 247 static bool IsTraceMethod(clang::FunctionDecl* method) { |
| 248 return GetTraceMethodType(method) != NOT_TRACE_METHOD; |
| 249 } |
| 250 |
| 251 static bool IsTraceImplName(const std::string& name) { |
| 252 return name == kTraceImplName || name == kTraceAfterDispatchImplName; |
227 } | 253 } |
228 | 254 |
229 static bool StartsWith(const std::string& str, const std::string& prefix) { | 255 static bool StartsWith(const std::string& str, const std::string& prefix) { |
230 if (prefix.size() > str.size()) | 256 if (prefix.size() > str.size()) |
231 return false; | 257 return false; |
232 return str.compare(0, prefix.size(), prefix) == 0; | 258 return str.compare(0, prefix.size(), prefix) == 0; |
233 } | 259 } |
234 | 260 |
235 static bool EndsWith(const std::string& str, const std::string& suffix) { | 261 static bool EndsWith(const std::string& str, const std::string& suffix) { |
236 if (suffix.size() > str.size()) | 262 if (suffix.size() > str.size()) |
237 return false; | 263 return false; |
238 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; | 264 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; |
239 } | 265 } |
240 }; | 266 }; |
241 | 267 |
242 #endif // TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ | 268 #endif // TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ |
OLD | NEW |