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 "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 Loading... | |
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 |
180 return true; | |
181 } | |
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* isTraceAfterDispatch = 0) { | |
Yuta Kitamura
2014/12/24 06:31:18
I know this is not from you, but...
Google style
kouhei (in TOK)
2014/12/24 09:03:04
Will fix this on separate CL.
| |
205 using namespace clang; | |
206 using namespace llvm; | |
kouhei (in TOK)
2014/12/24 05:53:19
FIXME: remove these.
kouhei (in TOK)
2014/12/24 09:03:04
Done.
| |
207 if (method->getNumParams() != 1) | |
208 return false; | |
209 | |
210 const std::string& name = method->getNameAsString(); | |
211 if (name != kTraceName && name != kTraceAfterDispatchName && | |
212 name != kTraceImplName) | |
213 return false; | |
214 | |
215 const clang::QualType& formal_type = method->getParamDecl(0)->getType(); | |
216 if (name == kTraceImplName) { | |
217 if (!IsVisitorDispatcherType(formal_type)) | |
218 return false; | |
219 } else if (!IsVisitorPtrType(formal_type)) | |
Yuta Kitamura
2014/12/24 06:31:18
If you put braces to "if", you need to do so in
co
kouhei (in TOK)
2014/12/24 09:03:04
Done.
| |
220 return false; | |
221 | |
187 if (isTraceAfterDispatch) | 222 if (isTraceAfterDispatch) |
188 *isTraceAfterDispatch = (name == kTraceAfterDispatchName); | 223 *isTraceAfterDispatch = (name == kTraceAfterDispatchName); |
224 | |
189 return true; | 225 return true; |
190 } | 226 } |
191 | 227 |
192 static bool StartsWith(const std::string& str, const std::string& prefix) { | 228 static bool StartsWith(const std::string& str, const std::string& prefix) { |
193 if (prefix.size() > str.size()) | 229 if (prefix.size() > str.size()) |
194 return false; | 230 return false; |
195 return str.compare(0, prefix.size(), prefix) == 0; | 231 return str.compare(0, prefix.size(), prefix) == 0; |
196 } | 232 } |
197 | 233 |
198 static bool EndsWith(const std::string& str, const std::string& suffix) { | 234 static bool EndsWith(const std::string& str, const std::string& suffix) { |
199 if (suffix.size() > str.size()) | 235 if (suffix.size() > str.size()) |
200 return false; | 236 return false; |
201 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; | 237 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; |
202 } | 238 } |
203 }; | 239 }; |
204 | 240 |
205 #endif // TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ | 241 #endif // TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ |
OLD | NEW |