| 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/globals.h" | 6 #include "vm/globals.h" |
| 7 #include "vm/ast.h" | 7 #include "vm/ast.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/code_generator.h" | 10 #include "vm/code_generator.h" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 ASSERT(!core_lib.IsNull()); | 265 ASSERT(!core_lib.IsNull()); |
| 266 const Namespace& core_ns = Namespace::Handle( | 266 const Namespace& core_ns = Namespace::Handle( |
| 267 Namespace::New(core_lib, Array::Handle(), Array::Handle())); | 267 Namespace::New(core_lib, Array::Handle(), Array::Handle())); |
| 268 lib.AddImport(core_ns); | 268 lib.AddImport(core_ns); |
| 269 return lib; | 269 return lib; |
| 270 } | 270 } |
| 271 | 271 |
| 272 | 272 |
| 273 static RawClass* LookupClass(const Library& lib, const char* name) { | 273 static RawClass* LookupClass(const Library& lib, const char* name) { |
| 274 const String& cls_name = String::ZoneHandle(Symbols::New(name)); | 274 const String& cls_name = String::ZoneHandle(Symbols::New(name)); |
| 275 return lib.LookupClass(cls_name); | 275 String& ambiguity_error_msg = String::Handle(); |
| 276 return lib.LookupClass(cls_name, &ambiguity_error_msg); |
| 276 } | 277 } |
| 277 | 278 |
| 278 | 279 |
| 279 CODEGEN_TEST_GENERATE(StaticCallCodegen, test) { | 280 CODEGEN_TEST_GENERATE(StaticCallCodegen, test) { |
| 280 const char* kScriptChars = | 281 const char* kScriptChars = |
| 281 "class A {\n" | 282 "class A {\n" |
| 282 " static bar() { return 42; }\n" | 283 " static bar() { return 42; }\n" |
| 283 " static fly() { return 5; }\n" | 284 " static fly() { return 5; }\n" |
| 284 "}\n"; | 285 "}\n"; |
| 285 | 286 |
| 286 String& url = String::Handle(String::New("dart-test:CompileScript")); | 287 String& url = String::Handle(String::New("dart-test:CompileScript")); |
| 287 String& source = String::Handle(String::New(kScriptChars)); | 288 String& source = String::Handle(String::New(kScriptChars)); |
| 288 Script& script = Script::Handle(Script::New(url, | 289 Script& script = Script::Handle(Script::New(url, |
| 289 source, | 290 source, |
| 290 RawScript::kScriptTag)); | 291 RawScript::kScriptTag)); |
| 291 Library& lib = MakeTestLibrary("TestLib"); | 292 Library& lib = MakeTestLibrary("TestLib"); |
| 292 EXPECT(CompilerTest::TestCompileScript(lib, script)); | 293 EXPECT(CompilerTest::TestCompileScript(lib, script)); |
| 293 EXPECT(ClassFinalizer::FinalizePendingClasses()); | 294 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 294 Class& cls = Class::Handle(LookupClass(lib, "A")); | 295 Class& cls = Class::Handle(LookupClass(lib, "A")); |
| 295 EXPECT(!cls.IsNull()); | 296 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
| 296 | 297 |
| 297 // 'bar' will not be compiled. | 298 // 'bar' will not be compiled. |
| 298 String& function_bar_name = String::Handle(String::New("bar")); | 299 String& function_bar_name = String::Handle(String::New("bar")); |
| 299 Function& function_bar = | 300 Function& function_bar = |
| 300 Function::ZoneHandle(cls.LookupStaticFunction(function_bar_name)); | 301 Function::ZoneHandle(cls.LookupStaticFunction(function_bar_name)); |
| 301 EXPECT(!function_bar.IsNull()); | 302 EXPECT(!function_bar.IsNull()); |
| 302 EXPECT(!function_bar.HasCode()); | 303 EXPECT(!function_bar.HasCode()); |
| 303 | 304 |
| 304 // 'fly' will be compiled. | 305 // 'fly' will be compiled. |
| 305 String& function_fly_name = String::Handle(String::New("fly")); | 306 String& function_fly_name = String::Handle(String::New("fly")); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 332 | 333 |
| 333 String& url = String::Handle(String::New("dart-test:CompileScript")); | 334 String& url = String::Handle(String::New("dart-test:CompileScript")); |
| 334 String& source = String::Handle(String::New(kScriptChars)); | 335 String& source = String::Handle(String::New(kScriptChars)); |
| 335 Script& script = Script::Handle(Script::New(url, | 336 Script& script = Script::Handle(Script::New(url, |
| 336 source, | 337 source, |
| 337 RawScript::kScriptTag)); | 338 RawScript::kScriptTag)); |
| 338 Library& lib = MakeTestLibrary("TestLib"); | 339 Library& lib = MakeTestLibrary("TestLib"); |
| 339 EXPECT(CompilerTest::TestCompileScript(lib, script)); | 340 EXPECT(CompilerTest::TestCompileScript(lib, script)); |
| 340 EXPECT(ClassFinalizer::FinalizePendingClasses()); | 341 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 341 Class& cls = Class::ZoneHandle(LookupClass(lib, "A")); | 342 Class& cls = Class::ZoneHandle(LookupClass(lib, "A")); |
| 342 EXPECT(!cls.IsNull()); | 343 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
| 343 | 344 |
| 344 String& constructor_name = String::Handle(String::New("A.")); | 345 String& constructor_name = String::Handle(String::New("A.")); |
| 345 Function& constructor = | 346 Function& constructor = |
| 346 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); | 347 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); |
| 347 EXPECT(!constructor.IsNull()); | 348 EXPECT(!constructor.IsNull()); |
| 348 | 349 |
| 349 // The unit test creates an instance of class A and calls function 'bar'. | 350 // The unit test creates an instance of class A and calls function 'bar'. |
| 350 String& function_bar_name = String::ZoneHandle(Symbols::New("bar")); | 351 String& function_bar_name = String::ZoneHandle(Symbols::New("bar")); |
| 351 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); | 352 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); |
| 352 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); | 353 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 519 |
| 519 String& url = String::Handle(String::New("dart-test:CompileScript")); | 520 String& url = String::Handle(String::New("dart-test:CompileScript")); |
| 520 String& source = String::Handle(String::New(kScriptChars)); | 521 String& source = String::Handle(String::New(kScriptChars)); |
| 521 Script& script = Script::Handle(Script::New(url, | 522 Script& script = Script::Handle(Script::New(url, |
| 522 source, | 523 source, |
| 523 RawScript::kScriptTag)); | 524 RawScript::kScriptTag)); |
| 524 Library& lib = MakeTestLibrary("TestLib"); | 525 Library& lib = MakeTestLibrary("TestLib"); |
| 525 EXPECT(CompilerTest::TestCompileScript(lib, script)); | 526 EXPECT(CompilerTest::TestCompileScript(lib, script)); |
| 526 EXPECT(ClassFinalizer::FinalizePendingClasses()); | 527 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 527 Class& cls = Class::ZoneHandle(LookupClass(lib, "A")); | 528 Class& cls = Class::ZoneHandle(LookupClass(lib, "A")); |
| 528 EXPECT(!cls.IsNull()); | 529 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
| 529 | 530 |
| 530 String& constructor_name = String::Handle(String::New("A.")); | 531 String& constructor_name = String::Handle(String::New("A.")); |
| 531 Function& constructor = | 532 Function& constructor = |
| 532 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); | 533 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); |
| 533 EXPECT(!constructor.IsNull()); | 534 EXPECT(!constructor.IsNull()); |
| 534 | 535 |
| 535 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); | 536 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); |
| 536 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); | 537 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); |
| 537 test->node_sequence()->Add(new ReturnNode(kPos, new ConstructorCallNode( | 538 test->node_sequence()->Add(new ReturnNode(kPos, new ConstructorCallNode( |
| 538 kPos, no_type_arguments, constructor, no_arguments))); | 539 kPos, no_type_arguments, constructor, no_arguments))); |
| 539 } | 540 } |
| 540 | 541 |
| 541 | 542 |
| 542 CODEGEN_TEST_RAW_RUN(AllocateNewObjectCodegen, function) { | 543 CODEGEN_TEST_RAW_RUN(AllocateNewObjectCodegen, function) { |
| 543 const Object& result = Object::Handle( | 544 const Object& result = Object::Handle( |
| 544 DartEntry::InvokeFunction(function, Object::empty_array())); | 545 DartEntry::InvokeFunction(function, Object::empty_array())); |
| 545 EXPECT(!result.IsError()); | 546 EXPECT(!result.IsError()); |
| 546 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 547 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 547 Isolate::Current()->object_store()->libraries()); | 548 Isolate::Current()->object_store()->libraries()); |
| 548 ASSERT(!libs.IsNull()); | 549 ASSERT(!libs.IsNull()); |
| 549 // App lib is the last one that was loaded. | 550 // App lib is the last one that was loaded. |
| 550 intptr_t num_libs = libs.Length(); | 551 intptr_t num_libs = libs.Length(); |
| 551 Library& app_lib = Library::Handle(); | 552 Library& app_lib = Library::Handle(); |
| 552 app_lib ^= libs.At(num_libs - 1); | 553 app_lib ^= libs.At(num_libs - 1); |
| 553 ASSERT(!app_lib.IsNull()); | 554 ASSERT(!app_lib.IsNull()); |
| 555 String& ambiguity_error_msg = String::Handle(); |
| 554 const Class& cls = Class::Handle( | 556 const Class& cls = Class::Handle( |
| 555 app_lib.LookupClass(String::Handle(Symbols::New("A")))); | 557 app_lib.LookupClass(String::Handle(Symbols::New("A")), |
| 556 EXPECT_EQ(cls.raw(), result.clazz()); | 558 &ambiguity_error_msg)); |
| 559 EXPECT_EQ(cls.raw(), result.clazz()); // No ambiguity error expected. |
| 557 } | 560 } |
| 558 | 561 |
| 559 } // namespace dart | 562 } // namespace dart |
| OLD | NEW |