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

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

Issue 817653003: Update from https://crrev.com/309717 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp ('k') | tools/clang/blink_gc_plugin/RecordInfo.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "clang/AST/AST.h" 15 #include "clang/AST/AST.h"
16 #include "clang/AST/Attr.h" 16 #include "clang/AST/Attr.h"
17 17
18 const char kNewOperatorName[] = "operator new"; 18 const char kNewOperatorName[] = "operator new";
19 const char kCreateName[] = "create"; 19 const char kCreateName[] = "create";
20 const char kTraceName[] = "trace"; 20 const char kTraceName[] = "trace";
21 const char kTraceImplName[] = "traceImpl";
21 const char kFinalizeName[] = "finalizeGarbageCollectedObject"; 22 const char kFinalizeName[] = "finalizeGarbageCollectedObject";
22 const char kTraceAfterDispatchName[] = "traceAfterDispatch"; 23 const char kTraceAfterDispatchName[] = "traceAfterDispatch";
23 const char kRegisterWeakMembersName[] = "registerWeakMembers"; 24 const char kRegisterWeakMembersName[] = "registerWeakMembers";
24 const char kHeapAllocatorName[] = "HeapAllocator"; 25 const char kHeapAllocatorName[] = "HeapAllocator";
25 const char kTraceIfNeededName[] = "TraceIfNeeded"; 26 const char kTraceIfNeededName[] = "TraceIfNeeded";
27 const char kVisitorDispatcherName[] = "VisitorDispatcher";
26 28
27 class Config { 29 class Config {
28 public: 30 public:
29 static bool IsMember(const std::string& name) { 31 static bool IsMember(const std::string& name) {
30 return name == "Member"; 32 return name == "Member";
31 } 33 }
32 34
33 static bool IsWeakMember(const std::string& name) { 35 static bool IsWeakMember(const std::string& name) {
34 return name == "WeakMember"; 36 return name == "WeakMember";
35 } 37 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 158
157 static bool IsIgnoreCycleAnnotated(clang::Decl* decl) { 159 static bool IsIgnoreCycleAnnotated(clang::Decl* decl) {
158 return IsAnnotated(decl, "blink_gc_plugin_ignore_cycle") || 160 return IsAnnotated(decl, "blink_gc_plugin_ignore_cycle") ||
159 IsIgnoreAnnotated(decl); 161 IsIgnoreAnnotated(decl);
160 } 162 }
161 163
162 static bool IsVisitor(const std::string& name) { 164 static bool IsVisitor(const std::string& name) {
163 return name == "Visitor" || name == "VisitorHelper"; 165 return name == "Visitor" || name == "VisitorHelper";
164 } 166 }
165 167
166 static bool IsTraceMethod(clang::FunctionDecl* method, 168 static bool IsVisitorPtrType(const clang::QualType& formal_type) {
167 bool* isTraceAfterDispatch = 0) {
168 if (method->getNumParams() != 1)
169 return false;
170
171 const std::string& name = method->getNameAsString();
172 if (name != kTraceName && name != kTraceAfterDispatchName)
173 return false;
174
175 const clang::QualType& formal_type = method->getParamDecl(0)->getType();
176 if (!formal_type->isPointerType()) 169 if (!formal_type->isPointerType())
177 return false; 170 return false;
178 171
179 clang::CXXRecordDecl* pointee_type = 172 clang::CXXRecordDecl* pointee_type =
180 formal_type->getPointeeType()->getAsCXXRecordDecl(); 173 formal_type->getPointeeType()->getAsCXXRecordDecl();
181 if (!pointee_type) 174 if (!pointee_type)
182 return false; 175 return false;
183 176
184 if (!IsVisitor(pointee_type->getName())) 177 if (!IsVisitor(pointee_type->getName()))
185 return false; 178 return false;
186 179
187 if (isTraceAfterDispatch)
188 *isTraceAfterDispatch = (name == kTraceAfterDispatchName);
189 return true; 180 return true;
190 } 181 }
191 182
183 static bool IsVisitorDispatcherType(const clang::QualType& formal_type) {
184 if (const clang::SubstTemplateTypeParmType* subst_type =
185 clang::dyn_cast<clang::SubstTemplateTypeParmType>(
186 formal_type.getTypePtr())) {
187 if (IsVisitorPtrType(subst_type->getReplacementType())) {
188 // VisitorDispatcher template parameter substituted to Visitor*.
189 return true;
190 }
191 } else if (const clang::TemplateTypeParmType* parm_type =
192 clang::dyn_cast<clang::TemplateTypeParmType>(
193 formal_type.getTypePtr())) {
194 if (parm_type->getDecl()->getName() == kVisitorDispatcherName) {
195 // Unresolved, but its parameter name is VisitorDispatcher.
196 return false;
197 }
198 }
199
200 return IsVisitorPtrType(formal_type);
201 }
202
203 static bool IsTraceMethod(clang::FunctionDecl* method,
204 bool* is_trace_after_dispatch) {
205 if (method->getNumParams() != 1)
206 return false;
207
208 const std::string& name = method->getNameAsString();
209 if (name != kTraceName && name != kTraceAfterDispatchName &&
210 name != kTraceImplName)
211 return false;
212
213 const clang::QualType& formal_type = method->getParamDecl(0)->getType();
214 if (name == kTraceImplName) {
215 if (!IsVisitorDispatcherType(formal_type))
216 return false;
217 } else if (!IsVisitorPtrType(formal_type)) {
218 return false;
219 }
220
221 if (is_trace_after_dispatch)
222 *is_trace_after_dispatch = (name == kTraceAfterDispatchName);
223
224 return true;
225 }
226
192 static bool StartsWith(const std::string& str, const std::string& prefix) { 227 static bool StartsWith(const std::string& str, const std::string& prefix) {
193 if (prefix.size() > str.size()) 228 if (prefix.size() > str.size())
194 return false; 229 return false;
195 return str.compare(0, prefix.size(), prefix) == 0; 230 return str.compare(0, prefix.size(), prefix) == 0;
196 } 231 }
197 232
198 static bool EndsWith(const std::string& str, const std::string& suffix) { 233 static bool EndsWith(const std::string& str, const std::string& suffix) {
199 if (suffix.size() > str.size()) 234 if (suffix.size() > str.size())
200 return false; 235 return false;
201 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; 236 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
202 } 237 }
203 }; 238 };
204 239
205 #endif // TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ 240 #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.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698