Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: tools/clang/blink_gc_plugin/Config.h

Issue 940263004: BlinkGCPlugin: Add support for traceAfterDispatchImpl(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust switch-case order. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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";
28 const char kAdjustAndMarkName[] = "adjustAndMark"; 31 const char kAdjustAndMarkName[] = "adjustAndMark";
29 const char kIsHeapObjectAliveName[] = "isHeapObjectAlive"; 32 const char kIsHeapObjectAliveName[] = "isHeapObjectAlive";
30 33
31 class Config { 34 class Config {
32 public: 35 public:
33 static bool IsMember(const std::string& name) { 36 static bool IsMember(const std::string& name) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 formal_type.getTypePtr())) { 198 formal_type.getTypePtr())) {
196 if (parm_type->getDecl()->getName() == kVisitorDispatcherName) { 199 if (parm_type->getDecl()->getName() == kVisitorDispatcherName) {
197 // Unresolved, but its parameter name is VisitorDispatcher. 200 // Unresolved, but its parameter name is VisitorDispatcher.
198 return true; 201 return true;
199 } 202 }
200 } 203 }
201 204
202 return IsVisitorPtrType(formal_type); 205 return IsVisitorPtrType(formal_type);
203 } 206 }
204 207
205 static bool IsTraceMethod(clang::FunctionDecl* method, 208 enum TraceMethodType {
206 bool* is_trace_after_dispatch) { 209 NOT_TRACE_METHOD,
210 TRACE_METHOD,
211 TRACE_AFTER_DISPATCH_METHOD,
212 TRACE_IMPL_METHOD,
213 TRACE_AFTER_DISPATCH_IMPL_METHOD
214 };
215
216 static TraceMethodType GetTraceMethodType(clang::FunctionDecl* method) {
207 if (method->getNumParams() != 1) 217 if (method->getNumParams() != 1)
208 return false; 218 return NOT_TRACE_METHOD;
209 219
210 const std::string& name = method->getNameAsString(); 220 const std::string& name = method->getNameAsString();
211 if (name != kTraceName && name != kTraceAfterDispatchName && 221 if (name != kTraceName && name != kTraceAfterDispatchName &&
212 name != kTraceImplName) 222 name != kTraceImplName && name != kTraceAfterDispatchImplName)
213 return false; 223 return NOT_TRACE_METHOD;
214 224
215 const clang::QualType& formal_type = method->getParamDecl(0)->getType(); 225 const clang::QualType& formal_type = method->getParamDecl(0)->getType();
216 if (name == kTraceImplName) { 226 if (name == kTraceImplName || name == kTraceAfterDispatchImplName) {
217 if (!IsVisitorDispatcherType(formal_type)) 227 if (!IsVisitorDispatcherType(formal_type))
218 return false; 228 return NOT_TRACE_METHOD;
219 } else if (!IsVisitorPtrType(formal_type)) { 229 } else if (!IsVisitorPtrType(formal_type)) {
220 return false; 230 return NOT_TRACE_METHOD;
221 } 231 }
222 232
223 if (is_trace_after_dispatch) 233 if (name == kTraceName)
224 *is_trace_after_dispatch = (name == kTraceAfterDispatchName); 234 return TRACE_METHOD;
235 if (name == kTraceAfterDispatchName)
236 return TRACE_AFTER_DISPATCH_METHOD;
237 if (name == kTraceImplName)
238 return TRACE_AFTER_DISPATCH_METHOD;
239 if (name == kTraceAfterDispatchImplName)
240 return TRACE_AFTER_DISPATCH_IMPL_METHOD;
225 241
226 return true; 242 assert(false && "Should not reach here");
243 return NOT_TRACE_METHOD;
244 }
245
246 static bool IsTraceMethod(clang::FunctionDecl* method) {
247 return GetTraceMethodType(method) != NOT_TRACE_METHOD;
248 }
249
250 static bool IsTraceImplName(const std::string& name) {
251 return name == kTraceImplName || name == kTraceAfterDispatchImplName;
227 } 252 }
228 253
229 static bool StartsWith(const std::string& str, const std::string& prefix) { 254 static bool StartsWith(const std::string& str, const std::string& prefix) {
230 if (prefix.size() > str.size()) 255 if (prefix.size() > str.size())
231 return false; 256 return false;
232 return str.compare(0, prefix.size(), prefix) == 0; 257 return str.compare(0, prefix.size(), prefix) == 0;
233 } 258 }
234 259
235 static bool EndsWith(const std::string& str, const std::string& suffix) { 260 static bool EndsWith(const std::string& str, const std::string& suffix) {
236 if (suffix.size() > str.size()) 261 if (suffix.size() > str.size())
237 return false; 262 return false;
238 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; 263 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
239 } 264 }
240 }; 265 };
241 266
242 #endif // TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ 267 #endif // TOOLS_BLINK_GC_PLUGIN_CONFIG_H_
OLDNEW
« no previous file with comments | « tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp ('k') | tools/clang/blink_gc_plugin/RecordInfo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698