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

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

Issue 19662003: Refactor resolution code in the vm to properly handle ambiguity errors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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
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 "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/assembler.h" 6 #include "vm/assembler.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 // Now try to resolve and invoke the static function in this class. 96 // Now try to resolve and invoke the static function in this class.
97 { 97 {
98 const int kNumArguments = 2; 98 const int kNumArguments = 2;
99 const Function& function = Function::Handle( 99 const Function& function = Function::Handle(
100 Resolver::ResolveStatic(library, 100 Resolver::ResolveStatic(library,
101 class_name, 101 class_name,
102 static_function_name, 102 static_function_name,
103 kNumArguments, 103 kNumArguments,
104 Object::empty_array(), 104 Object::empty_array(),
105 kResolveType)); 105 kResolveType,
106 NULL)); // No ambiguity error expected.
106 EXPECT(!function.IsNull()); 107 EXPECT(!function.IsNull());
107 const Array& args = Array::Handle(Array::New(kNumArguments)); 108 const Array& args = Array::Handle(Array::New(kNumArguments));
108 const String& arg0 = String::Handle(String::New("junk")); 109 const String& arg0 = String::Handle(String::New("junk"));
109 args.SetAt(0, arg0); 110 args.SetAt(0, arg0);
110 const Smi& arg1 = Smi::Handle(Smi::New(kTestValue)); 111 const Smi& arg1 = Smi::Handle(Smi::New(kTestValue));
111 args.SetAt(1, arg1); 112 args.SetAt(1, arg1);
112 const Smi& retval = Smi::Handle( 113 const Smi& retval = Smi::Handle(
113 reinterpret_cast<RawSmi*>(DartEntry::InvokeFunction(function, args))); 114 reinterpret_cast<RawSmi*>(DartEntry::InvokeFunction(function, args)));
114 EXPECT_EQ(kTestValue, retval.Value()); 115 EXPECT_EQ(kTestValue, retval.Value());
115 } 116 }
116 117
117 // Now try to resolve a static function with invalid argument count. 118 // Now try to resolve a static function with invalid argument count.
118 { 119 {
119 const int kNumArguments = 1; 120 const int kNumArguments = 1;
120 const Function& bad_function = Function::Handle( 121 const Function& bad_function = Function::Handle(
121 Resolver::ResolveStatic(library, 122 Resolver::ResolveStatic(library,
122 class_name, 123 class_name,
123 static_function_name, 124 static_function_name,
124 kNumArguments, 125 kNumArguments,
125 Object::empty_array(), 126 Object::empty_array(),
126 kResolveType)); 127 kResolveType,
128 NULL)); // No ambiguity error expected.
127 EXPECT(bad_function.IsNull()); 129 EXPECT(bad_function.IsNull());
128 } 130 }
129 131
130 // Hierarchy walking. 132 // Hierarchy walking.
131 { 133 {
132 const String& super_static_function_name = 134 const String& super_static_function_name =
133 String::Handle(String::New("statCall")); 135 String::Handle(String::New("statCall"));
134 const String& super_class_name = String::Handle(String::New("Base")); 136 const String& super_class_name = String::Handle(String::New("Base"));
135 const int kNumArguments = 0; 137 const int kNumArguments = 0;
136 const Function& super_function = Function::Handle( 138 const Function& super_function = Function::Handle(
137 Resolver::ResolveStatic(library, 139 Resolver::ResolveStatic(library,
138 super_class_name, 140 super_class_name,
139 super_static_function_name, 141 super_static_function_name,
140 kNumArguments, 142 kNumArguments,
141 Object::empty_array(), 143 Object::empty_array(),
142 kResolveType)); 144 kResolveType,
145 NULL)); // No ambiguity error expected.
143 EXPECT(!super_function.IsNull()); 146 EXPECT(!super_function.IsNull());
144 } 147 }
145 } 148 }
146 149
147 150
148 TEST_CASE(DartDynamicResolve) { 151 TEST_CASE(DartDynamicResolve) {
149 const char* test_library_name = "ResolverApp"; 152 const char* test_library_name = "ResolverApp";
150 const char* test_class_name = "A"; 153 const char* test_class_name = "A";
151 const char* test_function_name = "foo"; 154 const char* test_function_name = "foo";
152 const int kTestValue = 42; 155 const int kTestValue = 42;
153 156
154 // Setup a function which can be invoked. 157 // Setup a function which can be invoked.
155 SetupInstanceFunction(test_library_name, 158 SetupInstanceFunction(test_library_name,
156 test_class_name, 159 test_class_name,
157 test_function_name); 160 test_function_name);
158 161
159 // Now create an instance object of the class and try to 162 // Now create an instance object of the class and try to
160 // resolve a function in it. 163 // resolve a function in it.
161 const String& lib_name = String::Handle(String::New(test_library_name)); 164 const String& lib_name = String::Handle(String::New(test_library_name));
162 const Library& lib = Library::Handle(Library::LookupLibrary(lib_name)); 165 const Library& lib = Library::Handle(Library::LookupLibrary(lib_name));
163 ASSERT(!lib.IsNull()); 166 ASSERT(!lib.IsNull());
164 const Class& cls = Class::Handle(lib.LookupClass( 167 const Class& cls = Class::Handle(lib.LookupClass(
165 String::Handle(Symbols::New(test_class_name)))); 168 String::Handle(Symbols::New(test_class_name)), NULL));
166 EXPECT(!cls.IsNull()); 169 EXPECT(!cls.IsNull());
167 170
168 Instance& receiver = Instance::Handle(Instance::New(cls)); 171 Instance& receiver = Instance::Handle(Instance::New(cls));
169 const String& function_name = String::Handle(String::New(test_function_name)); 172 const String& function_name = String::Handle(String::New(test_function_name));
170 173
171 // Now try to resolve and invoke the instance function in this class. 174 // Now try to resolve and invoke the instance function in this class.
172 { 175 {
173 const int kNumArguments = 3; 176 const int kNumArguments = 3;
174 ArgumentsDescriptor args_desc( 177 ArgumentsDescriptor args_desc(
175 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); 178 Array::Handle(ArgumentsDescriptor::New(kNumArguments)));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 String::Handle(String::New("dynCall")); 213 String::Handle(String::New("dynCall"));
211 const Function& super_function = Function::Handle( 214 const Function& super_function = Function::Handle(
212 Resolver::ResolveDynamic(receiver, 215 Resolver::ResolveDynamic(receiver,
213 super_function_name, 216 super_function_name,
214 args_desc)); 217 args_desc));
215 EXPECT(!super_function.IsNull()); 218 EXPECT(!super_function.IsNull());
216 } 219 }
217 } 220 }
218 221
219 } // namespace dart 222 } // namespace dart
OLDNEW
« runtime/vm/parser_test.cc ('K') | « runtime/vm/resolver.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698