| 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/assembler.h" | 5 #include "vm/assembler.h" |
| 6 #include "vm/bigint_operations.h" | 6 #include "vm/bigint_operations.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 3196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3207 | 3207 |
| 3208 | 3208 |
| 3209 static RawFunction* GetFunction(const Class& cls, const char* name) { | 3209 static RawFunction* GetFunction(const Class& cls, const char* name) { |
| 3210 const Function& result = Function::Handle(cls.LookupDynamicFunction( | 3210 const Function& result = Function::Handle(cls.LookupDynamicFunction( |
| 3211 String::Handle(String::New(name)))); | 3211 String::Handle(String::New(name)))); |
| 3212 EXPECT(!result.IsNull()); | 3212 EXPECT(!result.IsNull()); |
| 3213 return result.raw(); | 3213 return result.raw(); |
| 3214 } | 3214 } |
| 3215 | 3215 |
| 3216 | 3216 |
| 3217 static RawFunction* GetStaticFunction(const Class& cls, const char* name) { |
| 3218 const Function& result = Function::Handle(cls.LookupStaticFunction( |
| 3219 String::Handle(String::New(name)))); |
| 3220 EXPECT(!result.IsNull()); |
| 3221 return result.raw(); |
| 3222 } |
| 3223 |
| 3224 |
| 3217 static RawField* GetField(const Class& cls, const char* name) { | 3225 static RawField* GetField(const Class& cls, const char* name) { |
| 3218 const Field& field = | 3226 const Field& field = |
| 3219 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); | 3227 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); |
| 3220 EXPECT(!field.IsNull()); | 3228 EXPECT(!field.IsNull()); |
| 3221 return field.raw(); | 3229 return field.raw(); |
| 3222 } | 3230 } |
| 3223 | 3231 |
| 3224 | 3232 |
| 3225 static RawClass* GetClass(const Library& lib, const char* name) { | 3233 static RawClass* GetClass(const Library& lib, const char* name) { |
| 3226 String& ambiguity_error_msg = String::Handle(); | 3234 String& ambiguity_error_msg = String::Handle(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3318 field = lib.LookupLocalField(String::Handle(Symbols::New("gVar"))); | 3326 field = lib.LookupLocalField(String::Handle(Symbols::New("gVar"))); |
| 3319 EXPECT(!field.IsNull()); | 3327 EXPECT(!field.IsNull()); |
| 3320 res = lib.GetMetadata(field); | 3328 res = lib.GetMetadata(field); |
| 3321 PrintMetadata("gVar", res); | 3329 PrintMetadata("gVar", res); |
| 3322 } | 3330 } |
| 3323 | 3331 |
| 3324 | 3332 |
| 3325 TEST_CASE(FunctionSourceFingerprint) { | 3333 TEST_CASE(FunctionSourceFingerprint) { |
| 3326 const char* kScriptChars = | 3334 const char* kScriptChars = |
| 3327 "class A {\n" | 3335 "class A {\n" |
| 3328 " void test1(int a) {\n" | 3336 " static void test1(int a) {\n" |
| 3329 " return a > 1 ? a + 1 : a;\n" | 3337 " return a > 1 ? a + 1 : a;\n" |
| 3330 " }\n" | 3338 " }\n" |
| 3331 " void test2(int a) {\n" | 3339 " static void test2(a) {\n" |
| 3332 " return a > 1 ? a + 1 : a;\n" | 3340 " return a > 1 ? a + 1 : a;\n" |
| 3333 " }\n" | 3341 " }\n" |
| 3334 " void test3(a) {\n" | 3342 " static void test3(b) {\n" |
| 3343 " return b > 1 ? b + 1 : b;\n" |
| 3344 " }\n" |
| 3345 " static void test4(b) {\n" |
| 3346 " return b > 1 ? b - 1 : b;\n" |
| 3347 " }\n" |
| 3348 " static void test5(b) {\n" |
| 3349 " return b > 1 ? b - 2 : b;\n" |
| 3350 " }\n" |
| 3351 " void test6(int a) {\n" |
| 3335 " return a > 1 ? a + 1 : a;\n" | 3352 " return a > 1 ? a + 1 : a;\n" |
| 3336 " }\n" | 3353 " }\n" |
| 3337 " void test4(b) {\n" | 3354 "}\n" |
| 3338 " return b > 1 ? b + 1 : b;\n" | 3355 "class B {\n" |
| 3356 " static void /* Different declaration style. */\n" |
| 3357 " test1(int a) {\n" |
| 3358 " /* Returns a + 1 for a > 1, a otherwise. */\n" |
| 3359 " return a > 1 ?\n" |
| 3360 " a + 1 :\n" |
| 3361 " a;\n" |
| 3339 " }\n" | 3362 " }\n" |
| 3340 " void test5(b) {\n" | 3363 " static void test5(b) {\n" |
| 3341 " return b > 1 ? b - 1 : b;\n" | |
| 3342 " }\n" | |
| 3343 " void test6(b) {\n" | |
| 3344 " return b > 1 ? b - 2 : b;\n" | |
| 3345 " }\n" | |
| 3346 " void test7(b) {\n" | |
| 3347 " return b > 1 ?\n" | 3364 " return b > 1 ?\n" |
| 3348 " b - 2 : b;\n" | 3365 " b - 2 : b;\n" |
| 3349 " }\n" | 3366 " }\n" |
| 3367 " void test6(int a) {\n" |
| 3368 " return a > 1 ? a + 1 : a;\n" |
| 3369 " }\n" |
| 3350 "}"; | 3370 "}"; |
| 3351 TestCase::LoadTestScript(kScriptChars, NULL); | 3371 TestCase::LoadTestScript(kScriptChars, NULL); |
| 3352 EXPECT(ClassFinalizer::FinalizePendingClasses()); | 3372 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 3353 const String& name = String::Handle(String::New(TestCase::url())); | 3373 const String& name = String::Handle(String::New(TestCase::url())); |
| 3354 const Library& lib = Library::Handle(Library::LookupLibrary(name)); | 3374 const Library& lib = Library::Handle(Library::LookupLibrary(name)); |
| 3355 EXPECT(!lib.IsNull()); | 3375 EXPECT(!lib.IsNull()); |
| 3356 | 3376 |
| 3357 const Class& class_a = Class::Handle( | 3377 const Class& class_a = Class::Handle( |
| 3358 lib.LookupClass(String::Handle(Symbols::New("A")), NULL)); | 3378 lib.LookupClass(String::Handle(Symbols::New("A")), NULL)); |
| 3359 const Function& test1 = Function::Handle(GetFunction(class_a, "test1")); | 3379 const Class& class_b = Class::Handle( |
| 3360 const Function& test2 = Function::Handle(GetFunction(class_a, "test2")); | 3380 lib.LookupClass(String::Handle(Symbols::New("B")), NULL)); |
| 3361 const Function& test3 = Function::Handle(GetFunction(class_a, "test3")); | 3381 const Function& a_test1 = |
| 3362 const Function& test4 = Function::Handle(GetFunction(class_a, "test4")); | 3382 Function::Handle(GetStaticFunction(class_a, "test1")); |
| 3363 const Function& test5 = Function::Handle(GetFunction(class_a, "test5")); | 3383 const Function& b_test1 = |
| 3364 const Function& test6 = Function::Handle(GetFunction(class_a, "test6")); | 3384 Function::Handle(GetStaticFunction(class_b, "test1")); |
| 3365 const Function& test7 = Function::Handle(GetFunction(class_a, "test7")); | 3385 const Function& a_test2 = |
| 3366 EXPECT_EQ(test1.SourceFingerprint(), test2.SourceFingerprint()); | 3386 Function::Handle(GetStaticFunction(class_a, "test2")); |
| 3367 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); | 3387 const Function& a_test3 = |
| 3368 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); | 3388 Function::Handle(GetStaticFunction(class_a, "test3")); |
| 3369 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); | 3389 const Function& a_test4 = |
| 3370 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); | 3390 Function::Handle(GetStaticFunction(class_a, "test4")); |
| 3371 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); | 3391 const Function& a_test5 = |
| 3392 Function::Handle(GetStaticFunction(class_a, "test5")); |
| 3393 const Function& b_test5 = |
| 3394 Function::Handle(GetStaticFunction(class_b, "test5")); |
| 3395 const Function& a_test6 = |
| 3396 Function::Handle(GetFunction(class_a, "test6")); |
| 3397 const Function& b_test6 = |
| 3398 Function::Handle(GetFunction(class_b, "test6")); |
| 3399 |
| 3400 EXPECT_EQ(a_test1.SourceFingerprint(), b_test1.SourceFingerprint()); |
| 3401 EXPECT_NE(a_test1.SourceFingerprint(), a_test2.SourceFingerprint()); |
| 3402 EXPECT_NE(a_test2.SourceFingerprint(), a_test3.SourceFingerprint()); |
| 3403 EXPECT_NE(a_test3.SourceFingerprint(), a_test4.SourceFingerprint()); |
| 3404 EXPECT_NE(a_test4.SourceFingerprint(), a_test5.SourceFingerprint()); |
| 3405 EXPECT_EQ(a_test5.SourceFingerprint(), b_test5.SourceFingerprint()); |
| 3406 EXPECT_NE(a_test6.SourceFingerprint(), b_test6.SourceFingerprint()); |
| 3372 } | 3407 } |
| 3373 | 3408 |
| 3374 } // namespace dart | 3409 } // namespace dart |
| OLD | NEW |