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

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

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

Powered by Google App Engine
This is Rietveld 408576698