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

Side by Side Diff: runtime/vm/intermediate_language.cc

Issue 11779018: Fix Intrinsifier and MethodRecognizer to correctly match private getters and setters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address Florian's comments Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/intrinsifier.cc » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/flow_graph_allocator.h" 9 #include "vm/flow_graph_allocator.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 ASSERT(initial_definitions_.length() > 0); 210 ASSERT(initial_definitions_.length() > 0);
211 for (intptr_t i = 0; i < initial_definitions_.length(); ++i) { 211 for (intptr_t i = 0; i < initial_definitions_.length(); ++i) {
212 ConstantInstr* defn = initial_definitions_[i]->AsConstant(); 212 ConstantInstr* defn = initial_definitions_[i]->AsConstant();
213 if (defn != NULL && defn->value().IsNull()) return defn; 213 if (defn != NULL && defn->value().IsNull()) return defn;
214 } 214 }
215 UNREACHABLE(); 215 UNREACHABLE();
216 return NULL; 216 return NULL;
217 } 217 }
218 218
219 219
220 static bool StartsWith(const String& name, const char* prefix, intptr_t n) {
221 ASSERT(name.IsOneByteString());
222
223 if (name.Length() < n) {
224 return false;
225 }
226
227 for (intptr_t i = 0; i < n; i++) {
228 if (name.CharAt(i) != prefix[i]) {
229 return false;
230 }
231 }
232
233 return true;
234 }
235
236
220 static bool CompareNames(const Library& lib, 237 static bool CompareNames(const Library& lib,
221 const char* test_name, 238 const char* test_name,
222 const String& name) { 239 const String& name) {
223 // If both names are private mangle test_name before comparison. 240 const char* kPrivateGetterPrefix = "get:_";
224 if ((name.CharAt(0) == '_') && (test_name[0] == '_')) { 241 const char* kPrivateSetterPrefix = "set:_";
225 const String& test_name_symbol = String::Handle(Symbols::New(test_name)); 242
226 return String::Handle(lib.PrivateName(test_name_symbol)).Equals(name); 243 if (test_name[0] == '_') {
244 if (name.CharAt(0) != '_') {
245 return false;
246 }
247 } else if (strncmp(test_name,
248 kPrivateGetterPrefix,
249 strlen(kPrivateGetterPrefix)) == 0) {
250 if (!StartsWith(name, kPrivateGetterPrefix, strlen(kPrivateGetterPrefix))) {
251 return false;
252 }
253 } else if (strncmp(test_name,
254 kPrivateSetterPrefix,
255 strlen(kPrivateSetterPrefix)) == 0) {
256 if (!StartsWith(name, kPrivateSetterPrefix, strlen(kPrivateSetterPrefix))) {
257 return false;
258 }
259 } else {
260 // Compare without mangling.
261 return name.Equals(test_name);
227 } 262 }
228 return name.Equals(test_name); 263
264 // Both names are private. Mangle test_name before comparison.
265 const String& test_name_symbol = String::Handle(Symbols::New(test_name));
266 return String::Handle(lib.PrivateName(test_name_symbol)).Equals(name);
229 } 267 }
230 268
231 269
232 static bool IsRecognizedLibrary(const Library& library) { 270 static bool IsRecognizedLibrary(const Library& library) {
233 // List of libraries where methods can be recognized. 271 // List of libraries where methods can be recognized.
234 return (library.raw() == Library::CoreLibrary()) 272 return (library.raw() == Library::CoreLibrary())
235 || (library.raw() == Library::MathLibrary()) 273 || (library.raw() == Library::MathLibrary())
236 || (library.raw() == Library::ScalarlistLibrary()); 274 || (library.raw() == Library::ScalarlistLibrary());
237 } 275 }
238 276
277
239 MethodRecognizer::Kind MethodRecognizer::RecognizeKind( 278 MethodRecognizer::Kind MethodRecognizer::RecognizeKind(
240 const Function& function) { 279 const Function& function) {
241 const Class& function_class = Class::Handle(function.Owner()); 280 const Class& function_class = Class::Handle(function.Owner());
242 const Library& lib = Library::Handle(function_class.library()); 281 const Library& lib = Library::Handle(function_class.library());
243 if (!IsRecognizedLibrary(lib)) { 282 if (!IsRecognizedLibrary(lib)) {
244 return kUnknown; 283 return kUnknown;
245 } 284 }
246 285
247 const String& function_name = String::Handle(function.name()); 286 const String& function_name = String::Handle(function.name());
248 const String& class_name = String::Handle(function_class.Name()); 287 const String& class_name = String::Handle(function_class.Name());
(...skipping 2461 matching lines...) Expand 10 before | Expand all | Expand 10 after
2710 default: 2749 default:
2711 UNREACHABLE(); 2750 UNREACHABLE();
2712 return -1; 2751 return -1;
2713 } 2752 }
2714 } 2753 }
2715 2754
2716 2755
2717 #undef __ 2756 #undef __
2718 2757
2719 } // namespace dart 2758 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/intrinsifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698