Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) { | |
|
Florian Schneider
2013/01/07 13:15:48
Maybe assert that name is a OneByteString?
Vyacheslav Egorov (Google)
2013/01/07 15:02:47
Done.
| |
| 221 if (name.Length() < n) { | |
| 222 return false; | |
| 223 } | |
| 224 | |
| 225 for (intptr_t i = 0; i < n; i++) { | |
| 226 if (name.CharAt(i) != prefix[i]) { | |
| 227 return false; | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 return true; | |
| 232 } | |
| 233 | |
| 234 | |
| 220 static bool CompareNames(const Library& lib, | 235 static bool CompareNames(const Library& lib, |
| 221 const char* test_name, | 236 const char* test_name, |
| 222 const String& name) { | 237 const String& name) { |
| 223 // If both names are private mangle test_name before comparison. | 238 static const intptr_t kPrefixLength = 5; |
|
Florian Schneider
2013/01/07 13:15:48
Do you really need static here? I'd omit it for lo
Florian Schneider
2013/01/07 13:15:48
Maybe rather use strlen(kPrefixGetter) and strlen(
Kevin Millikin (Google)
2013/01/07 13:26:36
You can also use the trick:
static const char kGe
Vyacheslav Egorov (Google)
2013/01/07 15:02:47
Done.
Vyacheslav Egorov (Google)
2013/01/07 15:02:47
Done.
| |
| 224 if ((name.CharAt(0) == '_') && (test_name[0] == '_')) { | 239 static const char* kGetterPrefix = "get:_"; |
|
Florian Schneider
2013/01/07 13:15:48
We have already kGetterPrefix in object.cc. Maybe
Vyacheslav Egorov (Google)
2013/01/07 15:02:47
Done.
| |
| 225 const String& test_name_symbol = String::Handle(Symbols::New(test_name)); | 240 static const char* kSetterPrefix = "set:_"; |
| 226 return String::Handle(lib.PrivateName(test_name_symbol)).Equals(name); | 241 |
| 242 if (test_name[0] == '_') { | |
| 243 if (name.CharAt(0) != '_') { | |
| 244 return false; | |
| 245 } | |
| 246 } else if (strncmp(test_name, kGetterPrefix, kPrefixLength) == 0) { | |
| 247 if (!StartsWith(name, kGetterPrefix, kPrefixLength)) { | |
| 248 return false; | |
| 249 } | |
| 250 } else if (strncmp(test_name, kSetterPrefix, kPrefixLength) == 0) { | |
| 251 if (!StartsWith(name, kSetterPrefix, kPrefixLength)) { | |
| 252 return false; | |
| 253 } | |
| 254 } else { | |
| 255 // Compare without mangling. | |
| 256 return name.Equals(test_name); | |
| 227 } | 257 } |
| 228 return name.Equals(test_name); | 258 |
| 259 // Both names are private. Mangle test_name before comparison. | |
| 260 const String& test_name_symbol = String::Handle(Symbols::New(test_name)); | |
| 261 return String::Handle(lib.PrivateName(test_name_symbol)).Equals(name); | |
| 229 } | 262 } |
| 230 | 263 |
| 231 | 264 |
| 232 static bool IsRecognizedLibrary(const Library& library) { | 265 static bool IsRecognizedLibrary(const Library& library) { |
| 233 // List of libraries where methods can be recognized. | 266 // List of libraries where methods can be recognized. |
| 234 return (library.raw() == Library::CoreLibrary()) | 267 return (library.raw() == Library::CoreLibrary()) |
| 235 || (library.raw() == Library::MathLibrary()) | 268 || (library.raw() == Library::MathLibrary()) |
| 236 || (library.raw() == Library::ScalarlistLibrary()); | 269 || (library.raw() == Library::ScalarlistLibrary()); |
| 237 } | 270 } |
| 238 | 271 |
| 272 | |
| 239 MethodRecognizer::Kind MethodRecognizer::RecognizeKind( | 273 MethodRecognizer::Kind MethodRecognizer::RecognizeKind( |
| 240 const Function& function) { | 274 const Function& function) { |
| 241 const Class& function_class = Class::Handle(function.Owner()); | 275 const Class& function_class = Class::Handle(function.Owner()); |
| 242 const Library& lib = Library::Handle(function_class.library()); | 276 const Library& lib = Library::Handle(function_class.library()); |
| 243 if (!IsRecognizedLibrary(lib)) { | 277 if (!IsRecognizedLibrary(lib)) { |
| 244 return kUnknown; | 278 return kUnknown; |
| 245 } | 279 } |
| 246 | 280 |
| 247 const String& function_name = String::Handle(function.name()); | 281 const String& function_name = String::Handle(function.name()); |
| 248 const String& class_name = String::Handle(function_class.Name()); | 282 const String& class_name = String::Handle(function_class.Name()); |
| (...skipping 2461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2710 default: | 2744 default: |
| 2711 UNREACHABLE(); | 2745 UNREACHABLE(); |
| 2712 return -1; | 2746 return -1; |
| 2713 } | 2747 } |
| 2714 } | 2748 } |
| 2715 | 2749 |
| 2716 | 2750 |
| 2717 #undef __ | 2751 #undef __ |
| 2718 | 2752 |
| 2719 } // namespace dart | 2753 } // namespace dart |
| OLD | NEW |