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
3 // found in the LICENSE file.
5 // This file defines the names used by GC infrastructure.
7 #ifndef TOOLS_BLINK_GC_PLUGIN_CONFIG_H_
8 #define TOOLS_BLINK_GC_PLUGIN_CONFIG_H_
10 #include "clang/AST/AST.h"
12 const char kNewOperatorName[] = "operator new";
13 const char kTraceName[] = "trace";
14 const char kTraceAfterDispatchName[] = "traceAfterDispatch";
15 const char kRegisterWeakMembersName[] = "registerWeakMembers";
16 const char kHeapAllocatorName[] = "HeapAllocator";
18 // TODO: Expand template aliases instead of using StartsWith/EndsWith patterns.
23 static bool IsMember(const std::string& name) {
24 return name == "Member"
25 || (oilpan_enabled() && EndsWith(name, "WillBeMember"));
28 static bool IsWeakMember(const std::string& name) {
29 return name == "WeakMember"
30 || (oilpan_enabled() && EndsWith(name, "WillBeWeakMember"));
33 static bool IsMemberHandle(const std::string& name) {
35 || IsWeakMember(name);
38 static bool IsPersistentHandle(const std::string& name) {
39 return name == "Persistent"
40 || (oilpan_enabled() && EndsWith(name, "WillBePersistent"));
43 static bool IsRefPtr(const std::string& name) {
44 return name == "RefPtr"
45 || (!oilpan_enabled() && StartsWith(name, "RefPtrWillBe"));
48 static bool IsOwnPtr(const std::string& name) {
49 return name == "OwnPtr"
50 || (!oilpan_enabled() && StartsWith(name, "OwnPtrWillBe"));
53 static bool IsWTFCollection(const std::string& name) {
54 return name == "Vector"
57 || name == "HashCountedSet"
58 || name == "ListHashSet"
60 || (!oilpan_enabled() && StartsWith(name, "WillBeHeap"));
63 static bool IsGCCollection(const std::string& name) {
64 return name == "HeapVector"
65 || name == "HeapHashMap"
66 || name == "HeapHashSet"
67 || (oilpan_enabled() && StartsWith(name, "WillBeHeap"));
70 static bool IsGCFinalizedBase(const std::string& name) {
71 return name == "GarbageCollectedFinalized"
72 || name == "RefCountedGarbageCollected"
74 && (EndsWith(name, "WillBeGarbageCollectedFinalized") ||
75 EndsWith(name, "WillBeRefCountedGarbageCollected")));
78 static bool IsGCBase(const std::string& name) {
79 return name == "GarbageCollected"
80 || IsGCFinalizedBase(name)
81 || (oilpan_enabled() && EndsWith(name, "WillBeGarbageCollected"));
84 static bool IsTraceMethod(clang::CXXMethodDecl* method,
85 bool* isTraceAfterDispatch = 0) {
86 const std::string& name = method->getNameAsString();
87 if (name == kTraceName || name == kTraceAfterDispatchName) {
88 if (isTraceAfterDispatch)
89 *isTraceAfterDispatch = (name == kTraceAfterDispatchName);
95 static bool StartsWith(const std::string& str, const std::string& prefix) {
96 if (prefix.size() > str.size())
98 return str.compare(0, prefix.size(), prefix) == 0;
101 static bool EndsWith(const std::string& str, const std::string& suffix) {
102 if (suffix.size() > str.size())
104 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
107 static void set_oilpan_enabled(bool enabled) { oilpan_enabled_ = enabled; }
108 static bool oilpan_enabled() { return oilpan_enabled_; }
111 static bool oilpan_enabled_;
114 #endif // TOOLS_BLINK_GC_PLUGIN_CONFIG_H_